<?php

/*
=====================================================================

  프로젝트 이름 : 피리 카페 심플

  만든사람 : 피리 PIREE ( tosports@naver.com )

  홈페이지 : https://piree.kr/nett_dev

  작성날짜 : 2024년 04월 04일 목요일 오전 0시 22분 / 흐림, 12.6, 쾌적, 17, 8, 26%, 20%, 1.5ms / 양호, 30, 19

  저 작 권 : Copyright ⓒ 2024 피리 piree.kr All right reserved
              그누보드 외에 추가된 소스는~
              만든사람의 허락없이 무단으로 사용할수 없습니다.
              사용하고자 할 경우 만든사람의 허락을 받아야 합니다.
              http://.piree.kr 에 문의해 주세요.

=====================================================================
 피리 카페 심플 > 프로그램 > 피리 카페 관리 > 기본 정보 수정 > 처리하기
=====================================================================


*/

  IF ( !defined('_GNUBOARD_') )                             EXIT;

  include_once( piree__path($piree_prog_a[770000]['num'], 'save.lib.php') );

  $piree_cafe_name_modify_n = 0;

  $piree_cafe_code_modify_n = 0;

  $piree_cafe_code_2_c = '';

  $piree_cafe_image_old_file_s = $piree_cafe_a['cafe_image_face_s'];

  $piree_cafe_image_new_file_s = $piree_cafe_a['cafe_image_face_s'];

  $piree_cafe_image_new_path_s = '';

  $piree_cafe_image_c = '';

  $piree_cafe_image_field_c = 'profile_image_s';

  $piree_cafe_image_upload_n = 0;

  $piree_cafe_image_is_n = 0;

      IF ( !$piree_cafe_code_c || $piree_cafe_code_c == '' )
      {
        alert("[ 피리 카페 코드 ]을 입력해 주세요.");
      }

      IF ( !$piree_cafe_name_s || $piree_cafe_name_s == '' )
      {
        alert("[ 피리 카페 이름 ]을 입력해 주세요.");
      }

      $piree_cafe_code_c = save__str($piree_cafe_code_c);

      check__bad_code($piree_cafe_code_c, '카페 코드');

      IF ( !$piree_cafe_code_c )
      {

        alert("[ 카페 코드 ]을 입력해 주세요.");
      }

      IF ( $piree_cafe_code_c != $piree_cafe_code_c )
      {

        $piree_cafe_check_result_a = piree_cafe_code_check($piree_cafe_code_c, $piree_cafe_n);

        IF ( $piree_cafe_check_result_a['piree_cafe_error_n'] > 0 )
        {

          alert($piree_cafe_check_result_a['piree_cafe_result_s'], piree__url($piree_prog_a[770099]['num'], 'section.cafe.make.php'));
        }

        $piree_cafe_code_modify_n = 1;

      }

      $piree_cafe_name_s = save__str($piree_cafe_name_s);

      check__bad_code($piree_cafe_name_s, '피리 카페 이름');

      IF ( !$piree_cafe_name_s )
      {

        alert("[ 피리 카페 이름 ]을 입력해 주세요.");
      }

      IF ( $piree_cafe_name_s != $piree_cafe_name_s )
      {

        $piree_cafe_name_modify_n = 1;

      }

      $piree_cafe_code_2_c = substr($piree_cafe_code_c, 0, 2);

      $piree_cafe_code_c = $piree_cafe_code_c;

    IF ( $piree_cafe_image_delete_now_n == $piree_cafe_n)
    {

      IF ( file_exists($piree_cafe_profile_image_path) )
      {

        $piree_cafe_image_new_file_s = '';

        unlink($piree_cafe_profile_image_path);

      }

    }

    $image_regex = "/(\.(gif|jpg|jpe?g|png))$/i";

    IF ( isset($_FILES[$piree_cafe_image_field_c]) && is_uploaded_file($_FILES[$piree_cafe_image_field_c]['tmp_name']) )
    {

      IF ( preg_match($image_regex, $_FILES[$piree_cafe_image_field_c]['name']))
      {

        $piree_cafe_image_upload_n = 1;

      }

    }

    IF ( $piree_cafe_image_upload_n == 1 )
    {

      include_once( piree__path($piree_prog_a[770000]['num'], 'file.dir.lib.php') );

      include_once(G5_LIB_PATH.'/thumbnail.lib.php');

      $azAZ09_a = array_merge(range('a','z'), range('A','Z'), range(0,9));

      $temp_a = $azAZ09_a;

      shuffle($temp_a);

      $piree_cafe_image_s = implode('', $temp_a);
      $piree_cafe_image_c = substr($piree_cafe_image_s, 0, 20);

      $extension_s = '';

      IF ( $_FILES[$piree_cafe_image_field_c]['name'] )
      {

        $file_temp_a = explode(".", $_FILES[$piree_cafe_image_field_c]['name']);

        $file_ext_c = $file_temp_a[(count($file_temp_a)-1)];
        $file_ext_c = strtolower($file_ext_c);

      }

      $piree_cafe_image_new_file_s = $piree_cafe_n .'_'. $member['mb_id'] .'_'. $piree_cafe_image_c .'.'. $file_ext_c;

      $depth_path_a[0] = G5_DATA_PATH .'/piree_cafe';
      $depth_path_a[1] = $depth_path_a[0] .'/'. $piree_cafe_code_c;

      mkdir_chmod($depth_path_a[0]);
      mkdir_chmod($depth_path_a[1]);

      IF ( $depth_path_a[1] && is_dir($depth_path_a[1]) )
      {

        $piree_cafe_image_new_path_s = $depth_path_a[1] .'/'. $piree_cafe_image_new_file_s;

        move_uploaded_file($_FILES[$piree_cafe_image_field_c]['tmp_name'], $piree_cafe_image_new_path_s);

        chmod($piree_cafe_image_new_path_s, G5_FILE_PERMISSION);

        IF ( file_exists($piree_cafe_image_new_path_s) )
        {

          $file_size_a = @getimagesize($piree_cafe_image_new_path_s);

          IF ( $file_size_a[0] > 0 && $file_size_a[1] > 0 )
          {

            $thumb = null;

            IF ( $file_size_a[2] === 2 || $file_size_a[2] === 3 )
            {

              $thumb = thumbnail($piree_cafe_image_new_file_s,$depth_path_a[1],$depth_path_a[1], $piree_prog_a[$piree_prog_a[770099]['num']]['profile_image_width_n'], $piree_prog_a[$piree_prog_a[770099]['num']]['profile_image_height_n'], true, true);

              IF ( $thumb )
              {

                @unlink($piree_cafe_image_new_path_s);

                rename($depth_path_a[1] .'/'. $thumb, $piree_cafe_image_new_path_s);

              }

            }

            IF ( !$thumb )
            {

              @unlink($piree_cafe_image_new_path_s);

            }

          }

        }

      }

    }

    $sql_update  = "UPDATE `". $piree['cafe'] ."` SET ";
    $sql_update .= "`cafe_code_c`       = '". $piree_cafe_code_c ."', ";
    $sql_update .= "`cafe_name_s`       = '". $piree_cafe_name_s ."', ";
    $sql_update .= "`cafe_image_face_s` = '". $piree_cafe_image_new_file_s ."', ";
    $sql_update .= "`cafe_modi_time_n`  = '". $piree_cafe_modify_time_n ."' ";
    $sql_update .= "WHERE `cafe_row_n`  = '". $piree_cafe_n ."'";

    IF ( !sql_query($sql_update) )
    {
      $msg_s = "피리 카페 [ ". $piree_cafe_name_s ." ( ". $piree_cafe_code_c ." ) ]을 입력하지 못했습니다. >> ". $sql_update;
      alert($msg_s);
    }

?>