fork download
  1. <?php
  2. /**
  3.   * Hangang System inc.
  4.   *
  5.   * Customer Doc Class
  6.   * 고객 증빙 서류 upload 클래스 정보
  7.   * 2019.11.04
  8.   *
  9.   */
  10. class Customer_Doc
  11. {
  12. public static $instance ;
  13.  
  14. private $c_db = NULL ;
  15. private $results = NULL ;
  16. private $agent_id = NULL ;
  17. private $contract_kind = NULL ;
  18. private $current_password = NULL ;
  19. private $work_kind = NULL;
  20.  
  21. private $ContractInfo = NULL;
  22.  
  23. private $DocumentInfo = NULL;
  24.  
  25. public function __construct()
  26. {
  27. $this->c_db = DBController::getInstance() ;
  28. }
  29.  
  30. public static function getInstance()
  31. {
  32. if (!isset(self::$instance))
  33. {
  34. $c = __CLASS__;
  35. self::$instance = new $c;
  36. }
  37.  
  38. return self::$instance;
  39. }
  40.  
  41. public function check_login($market_code, $agent_id)
  42. {
  43. $results = $this->c_db->SQLGetRow("GET_GROUP_LOGIN_USER", array($market_code, $agent_id));
  44.  
  45. if( $results == false )
  46. {
  47. return false;
  48. }
  49. else
  50. {
  51. $this->makeSession($results);
  52. }
  53.  
  54. $this->c_db->disconn();
  55. return true ;
  56. }
  57.  
  58. public function getResult()
  59. {
  60. return $this->results;
  61. }
  62. public function makeSession($results)
  63. {
  64. @logHandler(PEAR_LOG_INFO, "Make Session : ". print_r($results, true), $PHP_SELF, __FILE__, __LINE__ ) ;
  65.  
  66. $this->results = $results;
  67. }
  68.  
  69. public function setContractInfo($con_info)
  70. {
  71. // Hangang_auto_start (autopay - upload)
  72. /* 작업 정보 */
  73. if ($con_info['contract_kind'] =="P")
  74. {
  75. if ($con_info['activity_code'] == "C84"){
  76. $this->ContractInfo = $this->c_db->SQLGetRow('GET_REC_PAYMENT_METHOD_HISTORY', array($con_info['market_code'], $con_info['work_group'])) ;
  77. }
  78. else{
  79. $this->ContractInfo = $this->c_db->SQLGetRow('GET_REC_CCM_WORK_GROUP', array($con_info['market_code'], $con_info['work_group'], CCM_WORK_STATUS_COMPLETE )) ;
  80. }
  81.  
  82. if(! is_array($this->ContractInfo))
  83. {
  84. throw new Exception (ERROR_CODE_NO_WORK_GROUP);
  85. }
  86. }
  87.  
  88. // Hangang_auto_end
  89.  
  90. // 2018.10.17 ==> for encryption password
  91. {
  92. $customerInfo = $this->c_db->SQLGetRow('GET_CUSTOMER_PASSWORD_INFO', array($con_info['market_code'], $con_info['cid'] )) ;
  93.  
  94. if(! is_array($customerInfo))
  95. {
  96. @logHandler(PEAR_LOG_ERR, "GET_CUSTOMER_PASSWORD_INFO FAILURE", $PHP_SELF, __FILE__, __LINE__ ) ;
  97. throw new Exception (ERROR_CODE_NO_WORK_GROUP);
  98. }
  99.  
  100. if( strlen($customerInfo['BIRTHDAY']) == 6)
  101. {
  102. $this->ContractInfo['CUSTYYMMDD'] = $customerInfo['BIRTHDAY'];
  103. }
  104. elseif( strlen($customerInfo['BIRTHDAY']) == 10 )
  105. {
  106. $this->ContractInfo['CUSTYYMMDD'] = substr($customerInfo['BIRTHDAY'],0,6);
  107. }
  108. else
  109. {
  110. $this->ContractInfo['CUSTYYMMDD'] = substr($customerInfo['REP_ID'],0,6);
  111. }
  112. }
  113. // 2018.10.17 ==> for encryption password
  114.  
  115. $this->ContractInfo['INFO'] = $con_info;
  116.  
  117. //폴더명과 파일명 세팅처리
  118. if (!$this->ContractInfo['INFO']['seq'])
  119. {
  120. $folder_name = $this->getPDFServerFolderName();
  121. $file_name = $this->getPDFServerFileName();
  122.  
  123. $this->ContractInfo['INFO']['seq'] = $this->c_db->SQLGetOne('GET_GROUP_CONTRACT_INFO_SEQ',array($this->ContractInfo['INFO']['market_code'], $this->ContractInfo['INFO']['cid']));
  124.  
  125. $file_name .= "_".$this->ContractInfo['INFO']['seq'].".pdf";
  126. $this->ContractInfo['INFO']['folder_name'] =$folder_name;
  127. $this->ContractInfo['INFO']['file_name'] =$file_name;
  128. }
  129.  
  130. @logHandler(PEAR_LOG_INFO, print_r($this->ContractInfo, true), $PHP_SELF, __FILE__, __LINE__ ) ;
  131. }
  132.  
  133. public function getContractInfo()
  134. {
  135. return $this->ContractInfo;
  136. }
  137.  
  138. //------------------------------------------------------------
  139.  
  140. // insert Document -- 이 부분 다시 수정해야 한다.
  141. public function insertDocumentInfo($doc_info) {
  142. $seq_cnt = $this->c_db->SQLGetOne('GET_CUSTOMER_DOCUMENT_SEQ', array($doc_info['market_code'], $doc_info['cid'], $doc_info['reg_date'] ));
  143.  
  144. if($seq_cnt = 2) {
  145. if( false == $this->c_db->SQLExecute('UPD_CUSTOMER_DOCUMENT', array($doc_info['market_code'], $doc_info['cid'], $doc_info['reg_date'], $seq_cnt - 1)) )
  146. throw new Exception(ERROR_CODE_DB_FAILURE);
  147. } else if($seq_cnt > 2) {
  148. if( false == $this->c_db->SQLExecute('INS_CUSTOMER_DOCUMENT', array($doc_info['market_code'], $doc_info['cid'], $doc_info['reg_date'], $seq_cnt)) )
  149. throw new Exception(ERROR_CODE_DB_FAILURE);
  150. }
  151. }
  152.  
  153. // set Document
  154. public function setDocumentInfo($doc_info, $ext) {
  155.  
  156. // Hangang_auto_end
  157.  
  158. // 2018.10.17 ==> for encryption password
  159. /*
  160.   {
  161.   $customerInfo = $this->c_db->SQLGetRow('GET_CUSTOMER_PASSWORD_INFO', array($con_info['market_code'], $con_info['cid'] )) ;
  162.  
  163.   if(! is_array($customerInfo))
  164.   {
  165.   @logHandler(PEAR_LOG_ERR, "GET_CUSTOMER_PASSWORD_INFO FAILURE", $PHP_SELF, __FILE__, __LINE__ ) ;
  166.   throw new Exception (ERROR_CODE_NO_WORK_GROUP);
  167.   }
  168.  
  169.   if( strlen($customerInfo['BIRTHDAY']) == 6)
  170.   {
  171.   $this->DocumentInfo['CUSTYYMMDD'] = $customerInfo['BIRTHDAY'];
  172.   }
  173.   elseif( strlen($customerInfo['BIRTHDAY']) == 10 )
  174.   {
  175.   $this->DocumentInfo['CUSTYYMMDD'] = substr($customerInfo['BIRTHDAY'],0,6);
  176.   }
  177.   else
  178.   {
  179.   $this->DocumentInfo['CUSTYYMMDD'] = substr($customerInfo['REP_ID'],0,6);
  180.   }
  181.   }
  182.   */
  183.  
  184. $seq_cnt = $this->c_db->SQLGetOne('GET_CUSTOMER_DOCUMENT_SEQ', array($doc_info['market_code'], $doc_info['cid'], $doc_info['reg_date'] ));
  185. $seq_cnt = $seq_cnt - 1;
  186.  
  187. $this->DocumentInfo = $this->c_db->SQLGetRow('GET_CUSTOMER_DOCUMENT_INFO', array($doc_info['market_code'], $doc_info['cid'], $doc_info['reg_date'], $seq_cnt));
  188.  
  189. if(! is_array($this->DocumentInfo)) {
  190. throw new Exception (ERROR_CODE_NO_WORK_GROUP);
  191. }
  192.  
  193.  
  194. $this->DocumentInfo['INFO'] = $doc_info;
  195.  
  196. //폴더명과 파일명 세팅처리
  197. if (!$this->DocumentInfo['INFO']['seq']) {
  198. $folder_name = $this->getDocumentFolderName();
  199. $file_name = $this->getDocumentFileName();
  200.  
  201. $this->DocumentInfo['INFO']['seq'] = $seq_cnt;
  202.  
  203. $file_name .= "_" . $this->DocumentInfo['INFO']['seq'] . "." . $ext;
  204. $this->DocumentInfo['INFO']['folder_name'] = $folder_name;
  205. $this->DocumentInfo['INFO']['file_name'] = $file_name;
  206. }
  207.  
  208. @logHandler(PEAR_LOG_INFO, print_r($this->DocumentInfo, true), $PHP_SELF, __FILE__, __LINE__ ) ;
  209.  
  210. }
  211.  
  212. public function getDocumentInfo() {
  213. return $this->DocumentInfo;
  214. }
  215.  
  216. //ftp 서버 접속
  217. public function _connect_ftpServer()
  218. {
  219. $msg = "";
  220.  
  221. $c_imgServer = ImageServer::getInstance() ;
  222. $imgServerInfo = $c_imgServer->getImageServerInfo();
  223.  
  224. if($imgServerInfo['SERVER_IP'] == "" || $imgServerInfo['SERVER_PORT'] == "" || $imgServerInfo['USER_ID'] == "")
  225. {
  226. @logHandler(PEAR_LOG_ERR, "No ImageServer FTP Server Connection Info", $PHP_SELF, __FILE__, __LINE__ ) ;
  227. @logHandler(PEAR_LOG_ERR, print_r($imgServerInfo, true), $PHP_SELF, __FILE__, __LINE__ ) ;
  228. throw new Exception (ERROR_CODE_NO_INF_INFO);
  229. }
  230.  
  231. $this->ftp_conn = @ftp_connect ($imgServerInfo['SERVER_IP'], $imgServerInfo['SERVER_PORT'] );
  232.  
  233. if(false == $this->ftp_conn)
  234. {
  235. @logHandler(PEAR_LOG_ERR, "FTP Server Connection Failure [{$imgServerInfo['SERVER_IP']}[{$imgServerInfo['SERVER_PORT']}]", $PHP_SELF, __FILE__, __LINE__ ) ;
  236. // throw new Exception (ERROR_CODE_ERR_INF_SERVER);
  237. }
  238.  
  239. if(false == @ftp_login($this->ftp_conn, $imgServerInfo['USER_ID'], $imgServerInfo['USER_PW']))
  240. {
  241. @logHandler(PEAR_LOG_ERR, "FTP Server Login Failure [{$imgServerInfo['USER_ID']}[{$imgServerInfo['USER_PW']}]", $PHP_SELF, __FILE__, __LINE__ ) ;
  242. ftp_close($this->ftp_conn);
  243. //throw new Exception (ERROR_CODE_ERR_INF_SERVER);
  244. }else{
  245. @logHandler(PEAR_LOG_INFO, "set ftp to passive mode.".FTP_MODE, $PHP_SELF, __FILE__, __LINE__ );
  246. ftp_pasv($this->ftp_conn, FTP_MODE=="PASSIVE" );
  247. }
  248.  
  249. if( $imgServerInfo['FOLDER'] )
  250. {
  251. @ftp_chdir($this->ftp_conn, $imgServerInfo['FOLDER']);
  252. }
  253. }
  254.  
  255. //계약서 upload
  256. // 2018.10.17 ==> for encryption password
  257. //public function _uploadImageServerPDF($contract_kind, $att_file_info = array())
  258. public function _uploadImageServerPDF($contract_kind, $att_file_info = array(), $enc_password)
  259. // 2018.10.17 ==> for encryption password
  260. {
  261. $this->_connect_ftpServer();
  262.  
  263. if( !is_file( $att_file_info['tmp_name'] ) )
  264. {
  265. @logHandler(PEAR_LOG_ERR, "NO FILE To FTP Put Attach : " . $att_file_info['tmp_name'], $PHP_SELF, __FILE__, __LINE__ ) ;
  266. throw new Exception (ERROR_CODE_ERR_ATT_PROCESS);
  267. }
  268.  
  269. try
  270. {
  271. // 2018.10.17 ==> for encryption password
  272. //$this->_saveImageServerPDF($att_file_info, $contract_kind);
  273. $this->_saveImageServerPDF($att_file_info, $contract_kind, $enc_password);
  274. // 2018.10.17 ==> for encryption password
  275. }
  276. catch (Exception $e)
  277. {
  278. ftp_close($this->ftp_conn);
  279. throw $e;
  280. }
  281.  
  282. ftp_close($this->ftp_conn);
  283. }
  284.  
  285. // 고객 증빙 서류 업로드
  286. public function _uploadDocumentServer($att_file_info = array()) {
  287.  
  288. $this->_connect_ftpServer();
  289.  
  290. if( !is_file( $att_file_info['tmp_name'] ) )
  291. {
  292. @logHandler(PEAR_LOG_ERR, "NO FILE To FTP Put Attach : " . $att_file_info['tmp_name'], $PHP_SELF, __FILE__, __LINE__ ) ;
  293. throw new Exception (ERROR_CODE_ERR_ATT_PROCESS);
  294. }
  295.  
  296. try
  297. {
  298. // 2018.10.17 ==> for encryption password
  299. //$this->_saveImageServerPDF($att_file_info, $contract_kind);
  300. //$this->_saveImageServerPDF($att_file_info, $contract_kind, $enc_password);
  301. $this->_saveDocumentServer($att_file_info);
  302.  
  303. }
  304. catch (Exception $e)
  305. {
  306. ftp_close($this->ftp_conn);
  307. throw $e;
  308. }
  309.  
  310. ftp_close($this->ftp_conn);
  311.  
  312. }
  313.  
  314. public function _saveDocumentServer($att_file_info) {
  315. if( !is_file( $att_file_info['tmp_name'] ) )
  316. {
  317. @logHandler(PEAR_LOG_ERR, "NO FILE To FTP Put Attach : " . $att_file_info['tmp_name'], $PHP_SELF, __FILE__, __LINE__ ) ;
  318. throw new Exception (ERROR_CODE_ERR_ATT_PROCESS);
  319. }
  320.  
  321. $folder = $this->DocumentInfo['INFO']['folder_name'];
  322. $file = $this->DocumentInfo['INFO']['file_name'];
  323.  
  324. $parts = explode('/',$folder); // SOID/YYYY/MMDD
  325. foreach($parts as $part)
  326. {
  327. @ftp_pwd($this->ftp_conn);
  328. if(!@ftp_chdir($this->ftp_conn, $part))
  329. {
  330. @ftp_pwd($this->ftp_conn);
  331. @ftp_mkdir($this->ftp_conn, $part);
  332. @ftp_chdir($this->ftp_conn, $part);
  333. }
  334. }
  335.  
  336. // $tmpfile = TMP_DIR . "/" . uniqid();
  337. $tmpfile = TMP_DIR . "/" . $file;
  338. move_uploaded_file($att_file_info['tmp_name'], $tmpfile);
  339.  
  340.  
  341. /* DRM 해지 처리 : 2018.08.28 */
  342. if(isDRMEncryptedFile($tmpfile))
  343. {
  344. $encfile = TMP_DIR . "/enc_" . $file;
  345. if(doDRMExtract($tmpfile, $encfile))
  346. {
  347. $tmpfile = $encfile;
  348. }
  349. }
  350.  
  351. /*
  352.   // 2018.10.17 ==> for encryption password
  353.   $exec_command = PDFSECURE_PROGRAM . " --encrypt '{$enc_password}' '' 128 --use-aes=y -- " . $tmpfile . " " . $tmpfile . "__enc_pass";
  354.   @logHandler(PEAR_LOG_INFO, $exec_command , $PHP_SELF, __FILE__, __LINE__ ) ;
  355.   exec( $exec_command );
  356.  
  357.   if( !is_file( $tmpfile . "__enc_pass" ) )
  358.   {
  359.   @logHandler(PEAR_LOG_ERR, "NO FILE Found (Secured Applied) : " . $tmpfile . "__enc_pass", $PHP_SELF, __FILE__, __LINE__ ) ;
  360.   throw new Exception (ERROR_CODE_ERR_PDF_PROCESS);
  361.   }
  362.   $tmpfile = $tmpfile . "__enc_pass";
  363.   // 2018.10.17 ==> for encryption password
  364. */
  365.  
  366. if(!@ftp_put($this->ftp_conn, $file, $tmpfile, FTP_BINARY))
  367. {
  368. @logHandler(PEAR_LOG_ERR, "FTP upload Failure : " . $tmpfile . " ===> $file ", $PHP_SELF, __FILE__, __LINE__ ) ;
  369. // throw new Exception (ERROR_CODE_ERR_ATT_PROCESS);
  370. }
  371.  
  372.  
  373. // Hangang_auto_start (autopay - upload)
  374. //개인 계약서 일 경우 cid_install_barcode 에 저장한다.
  375. /*
  376.   if (($this->ContractInfo['INFO']['contract_kind']=="P") && ($this->ContractInfo['INFO']['activity_code']!="C84"))
  377. // if ($this->ContractInfo['INFO']['contract_kind']=="P")
  378.   {
  379.   @logHandler(PEAR_LOG_INFO, "Insert into cid_install_barcode", $PHP_SELF, __FILE__, __LINE__ );
  380.   $this->insertBarcode();
  381.   }
  382.   */
  383.  
  384. // Hangang_auto_end
  385.  
  386.  
  387. //신규테이블에 계약서 upload 정보를 저장한다.
  388. //@logHandler(PEAR_LOG_INFO, "Insert into customer_document", $PHP_SELF, __FILE__, __LINE__ );
  389. /*
  390.   $this->insertGroupContract();
  391.  
  392.   //insert ccm_memo
  393.   @logHandler(PEAR_LOG_INFO, "Insert into ccm_memo", $PHP_SELF, __FILE__, __LINE__ );
  394.  
  395.   $sys_memo_text = $this->ContractInfo['INFO']['contract_kind'] =="P"? "작업내역:[개인 계약서 업로드]":"작업상태:[단체 계약서 업로드]";
  396.   $usr_memo_text = "1.파일명: [".$this->ContractInfo['INFO']['file_name']."], 2.작업자:[".$this->ContractInfo['INFO']['agent_name']."]";
  397.   $this->insertCCM_MEMO($sys_memo_text, $usr_memo_text);
  398.  
  399. // Hangang_auto_start : insertPaymentMethodHistory (autopay - upload)
  400.   //insert payment_method_history
  401.   @logHandler(PEAR_LOG_INFO, "Insert into payment_method_history", $PHP_SELF, __FILE__, __LINE__ );
  402.   $this->insertPaymentMethodHistory();
  403. // Hangang_auto_end
  404.  
  405.   $this->commit();
  406.  
  407.   */
  408.  
  409. // 파일 경로 업데이트 - check status = Y 로 바꾸어야 함 .
  410. // $this->updateDocumentFile();
  411.  
  412. }
  413.  
  414. /*
  415.   public function updateDocumentFile() {
  416.   if( false == $this->c_db->SQLExecute('UPD_CUSTOMER_DOCUMENT', array($doc_info['market_code'], $doc_info['cid'], $doc_info['reg_date'], $seq_cnt)) )
  417. throw new Exception(ERROR_CODE_DB_FAILURE);
  418.  
  419.   }
  420.   */
  421.  
  422. //계약서 서버 저장
  423. // 2018.10.17 ==> for encryption password
  424. //public function _saveImageServerPDF($att_file_info, $contract_kind)
  425. public function _saveImageServerPDF($att_file_info, $contract_kind, $enc_password)
  426. // 2018.10.17 ==> for encryption password
  427. {
  428. if( !is_file( $att_file_info['tmp_name'] ) )
  429. {
  430. @logHandler(PEAR_LOG_ERR, "NO FILE To FTP Put Attach : " . $att_file_info['tmp_name'], $PHP_SELF, __FILE__, __LINE__ ) ;
  431. throw new Exception (ERROR_CODE_ERR_ATT_PROCESS);
  432. }
  433.  
  434. $folder = $this->ContractInfo['INFO']['folder_name'];
  435. $file = $this->ContractInfo['INFO']['file_name'];
  436.  
  437. $parts = explode('/',$folder); // SOID/YYYY/MMDD
  438. foreach($parts as $part)
  439. {
  440. @ftp_pwd($this->ftp_conn);
  441. if(!@ftp_chdir($this->ftp_conn, $part))
  442. {
  443. @ftp_pwd($this->ftp_conn);
  444. @ftp_mkdir($this->ftp_conn, $part);
  445. @ftp_chdir($this->ftp_conn, $part);
  446. }
  447. }
  448.  
  449. $tmpfile = TMP_DIR . "/" . uniqid();
  450. move_uploaded_file($att_file_info['tmp_name'], $tmpfile);
  451.  
  452. /* DRM 해지 처리 : 2018.08.28 */
  453. if(isDRMEncryptedFile($tmpfile))
  454. {
  455. $encfile = TMP_DIR . "/enc_" . uniqid();
  456. if(doDRMExtract($tmpfile, $encfile))
  457. {
  458. $tmpfile = $encfile;
  459. }
  460. }
  461.  
  462.  
  463. // 2018.10.17 ==> for encryption password
  464. $exec_command = PDFSECURE_PROGRAM . " --encrypt '{$enc_password}' '' 128 --use-aes=y -- " . $tmpfile . " " . $tmpfile . "__enc_pass";
  465. @logHandler(PEAR_LOG_INFO, $exec_command , $PHP_SELF, __FILE__, __LINE__ ) ;
  466. exec( $exec_command );
  467.  
  468. if( !is_file( $tmpfile . "__enc_pass" ) )
  469. {
  470. @logHandler(PEAR_LOG_ERR, "NO FILE Found (Secured Applied) : " . $tmpfile . "__enc_pass", $PHP_SELF, __FILE__, __LINE__ ) ;
  471. throw new Exception (ERROR_CODE_ERR_PDF_PROCESS);
  472. }
  473. $tmpfile = $tmpfile . "__enc_pass";
  474. // 2018.10.17 ==> for encryption password
  475.  
  476.  
  477.  
  478. if(!@ftp_put($this->ftp_conn, $file, $tmpfile, FTP_BINARY))
  479. {
  480. @logHandler(PEAR_LOG_ERR, "FTP upload Failure : " . $tmpfile . " ===> $file ", $PHP_SELF, __FILE__, __LINE__ ) ;
  481. throw new Exception (ERROR_CODE_ERR_ATT_PROCESS);
  482. }
  483. // Hangang_auto_start (autopay - upload)
  484. //개인 계약서 일 경우 cid_install_barcode 에 저장한다.
  485. if (($this->ContractInfo['INFO']['contract_kind']=="P") && ($this->ContractInfo['INFO']['activity_code']!="C84"))
  486. // if ($this->ContractInfo['INFO']['contract_kind']=="P")
  487. {
  488. @logHandler(PEAR_LOG_INFO, "Insert into cid_install_barcode", $PHP_SELF, __FILE__, __LINE__ );
  489. $this->insertBarcode();
  490. }
  491. // Hangang_auto_end
  492.  
  493. //신규테이블에 계약서 upload 정보를 저장한다.
  494. @logHandler(PEAR_LOG_INFO, "Insert into group_contract_info", $PHP_SELF, __FILE__, __LINE__ );
  495. $this->insertGroupContract();
  496.  
  497. //insert ccm_memo
  498. @logHandler(PEAR_LOG_INFO, "Insert into ccm_memo", $PHP_SELF, __FILE__, __LINE__ );
  499.  
  500. $sys_memo_text = $this->ContractInfo['INFO']['contract_kind'] =="P"? "작업내역:[개인 계약서 업로드]":"작업상태:[단체 계약서 업로드]";
  501. $usr_memo_text = "1.파일명: [".$this->ContractInfo['INFO']['file_name']."], 2.작업자:[".$this->ContractInfo['INFO']['agent_name']."]";
  502. $this->insertCCM_MEMO($sys_memo_text, $usr_memo_text);
  503.  
  504. // Hangang_auto_start : insertPaymentMethodHistory (autopay - upload)
  505. //insert payment_method_history
  506. @logHandler(PEAR_LOG_INFO, "Insert into payment_method_history", $PHP_SELF, __FILE__, __LINE__ );
  507. $this->insertPaymentMethodHistory();
  508. // Hangang_auto_end
  509.  
  510. $this->commit();
  511. }
  512.  
  513. //파일 다운로드
  514. public function _downImageServerPDF($file_name)
  515. {
  516. $this->_connect_ftpServer();
  517.  
  518. $sys_memo_text = $this->ContractInfo['INFO']['contract_kind'] =="P"? "작업내역:[개인 계약서 다운로드]":"작업상태:[단체 계약서 다운로드]";
  519. $usr_memo_text = "1.파일명: [".$file_name."], 2.작업자:[".$this->ContractInfo['INFO']['agent_name']."]";
  520. $this->insertCCM_MEMO($sys_memo_text, $usr_memo_text);
  521.  
  522. $this->file = uniqid() . ".pdf";
  523.  
  524. if(0 < ftp_size($this->ftp_conn, $file_name))
  525. {
  526. if(!ftp_get($this->ftp_conn, TMP_DIR . "/" . $this->file, $file_name, FTP_BINARY))
  527. {
  528. @logHandler(PEAR_LOG_ERR, "FTP DownLoad Failure : " . $file_name, $PHP_SELF, __FILE__, __LINE__ ) ;
  529. throw new Exception (ERROR_CODE_ERR_PDF_PROCESS);
  530. }
  531. }
  532. else
  533. {
  534. @logHandler(PEAR_LOG_ERR, "FTP FILE NOT EXISTS : " . $file_name, $PHP_SELF, __FILE__, __LINE__ ) ;
  535. ftp_close($this->ftp_conn);
  536. prtErr("이미지 서버에 파일({$file_name})이 없습니다.");
  537. return "이미지 서버에 파일({$file_name})이 없습니다.";
  538. }
  539.  
  540. ftp_close($this->ftp_conn);
  541.  
  542. return TMP_DIR . "/" . $this->file ;
  543. }
  544.  
  545. // 파일 삭제
  546. public function _deleteImageServerPDF($file_name)
  547. {
  548. $this->_connect_ftpServer();
  549.  
  550. if(0 < ftp_size($this->ftp_conn, $file_name))
  551. {
  552. if(!ftp_delete($this->ftp_conn, $file_name))
  553. {
  554. @logHandler(PEAR_LOG_ERR, "FTP delete Failure : " . $file_name, $PHP_SELF, __FILE__, __LINE__ ) ;
  555. throw new Exception (ERROR_CODE_ERR_PDF_PROCESS);
  556. }
  557. }
  558.  
  559. ftp_close($this->ftp_conn);
  560. }
  561.  
  562. //insert cid_install_barcode
  563. public function insertBarcode()
  564. {
  565. @logHandler(PEAR_LOG_INFO, "Insert into cid_install_barcode start", $PHP_SELF, __FILE__, __LINE__ ) ;
  566. $exist = $this->c_db->SQLGetOne('GET_CID_INSTALL_BARCODE_COUNT',
  567. $this->ContractInfo['INFO']['market_code']
  568. ,$this->ContractInfo['INFO']['cid']
  569. ,$this->ContractInfo['INFO']['work_group']
  570. ));
  571.  
  572. if($exist){
  573. if(false == $this->c_db->SQLExecute('UPD_CID_INSTALL_BARCODE',
  574. "Y" // --scan_yn
  575. ,$this->ContractInfo['INFO']['agree_yn'] // -- agree_yn
  576. ,$this->ContractInfo['INFO']['agree_yn2'] // -- agree_yn2
  577. ,$this->ContractInfo['INFO']['agree_yn3'] // -- agree_yn3
  578. ,$this->ContractInfo['INFO']['agree_yn4'] // -- agree_yn4
  579. ,$this->ContractInfo['INFO']['agent_id'] // -- scan_agent
  580. ,""
  581. ,"" // -- post_gubun
  582. ,$this->ContractInfo['INFO']['market_code']
  583. ,$this->ContractInfo['INFO']['cid']
  584. ,$this->ContractInfo['INFO']['work_group']
  585. )))
  586. {
  587. throw new Exception (ERROR_CODE_DB_FAILURE);
  588. }
  589. }else{
  590. if(false == $this->c_db->SQLExecute('INS_CID_INSTALL_BARCODE',
  591. $this->ContractInfo['INFO']['market_code']
  592. ,$this->ContractInfo['INFO']['cid']
  593. ,$this->ContractInfo['INFO']['work_group']
  594. ,$this->ContractInfo['WORK_REG_DATE']
  595. ,$this->ContractInfo['ACTIVITY_CODE']
  596. ,"1"
  597. ,$this->ContractInfo['INFO']['agent_id']
  598. ,"FTP" // -- sys_application_id
  599. ,"INS" // -- dl_service_code
  600. ,"0" // -- dl_update_stamp
  601. ,$this->ContractInfo['FULL_NAME'] // -- full_name
  602. ,$this->ContractInfo['CID_STATUS'] // -- cid_status
  603. ,"W" // -- keep_status
  604. ,substr($this->ContractInfo['WORK_DATETIME'], 0, 8) // -- actv_date
  605. ,$this->ContractInfo['INFO']['agent_id'] // -- actv_agent
  606. ,"Y" // -- scan_yn
  607. ,$this->ContractInfo['INFO']['agree_yn'] // -- agree_yn
  608. ,$this->ContractInfo['INFO']['agree_yn2'] // -- agree_yn2
  609. ,$this->ContractInfo['INFO']['agree_yn3'] // -- agree_yn3
  610. ,$this->ContractInfo['INFO']['agree_yn4'] // -- agree_yn4
  611. ,"" // -- doc_type
  612. ,$this->ContractInfo['INFO']['agent_id'] // -- scan_agent
  613. ,"" // -- post_gubun
  614. ,""
  615. )))
  616. {
  617. throw new Exception (ERROR_CODE_DB_FAILURE);
  618. }
  619. }
  620.  
  621. @logHandler(PEAR_LOG_INFO, "Insert into cid_install_barcode end", $PHP_SELF, __FILE__, __LINE__ ) ;
  622. }
  623.  
  624. //install group_contract_info
  625. public function insertGroupContract()
  626. {
  627. @logHandler(PEAR_LOG_INFO, "Insert into group_contract_info start", $PHP_SELF, __FILE__, __LINE__ ) ;
  628. $exist = $this->c_db->SQLGetOne('GET_GROUP_CONTRACT_INFO_COUNT',
  629. $this->ContractInfo['INFO']['market_code']
  630. ,$this->ContractInfo['INFO']['cid']
  631. ,$this->ContractInfo['INFO']['seq']
  632. ));
  633. if($exist){
  634. //기존 이력 저장
  635. $this->insertGroupHistory();
  636.  
  637. if(false == $this->c_db->SQLExecute('UPD_GROUP_CONTRACT_INFO',
  638. $this->ContractInfo['INFO']['agent_id'] // --sys_operator_id
  639. ,$this->ContractInfo['INFO']['agent_id'] // --reg_agent_id
  640. ,$this->ContractInfo['INFO']['remark'] // --remark
  641. ,$this->ContractInfo['INFO']['market_code']
  642. ,$this->ContractInfo['INFO']['cid']
  643. ,$this->ContractInfo['INFO']['seq']
  644. )))
  645. {
  646. throw new Exception (ERROR_CODE_DB_FAILURE);
  647. }
  648. }
  649. else
  650. { //신규저장
  651. if(false == $this->c_db->SQLExecute('INS_GROUP_CONTRACT_INFO',
  652. $this->ContractInfo['INFO']['market_code'] // --market_code
  653. ,$this->ContractInfo['INFO']['cid'] // --cid
  654. ,$this->ContractInfo['INFO']['seq'] // --seq
  655. ,date('Ymd') // --reg_date
  656. ,$this->ContractInfo['INFO']['agent_id'] // --reg_agent_id
  657. ,$this->ContractInfo['INFO']['contract_kind'] // --contract_kind
  658. ,$this->ContractInfo['INFO']['contract_type'] // --contract_type
  659. ,$this->ContractInfo['INFO']['work_group'] // --work_group
  660. ,$this->ContractInfo['ACTIVITY_CODE'] // --activity_code
  661. ,$this->ContractInfo['INFO']['agent_id'] // --sys_operator_id
  662. ,$this->ContractInfo['INFO']['folder_name'] // --folder_name
  663. ,$this->ContractInfo['INFO']['file_name'] // --file_name
  664. ,"Y" // --flag
  665. ,$this->ContractInfo['INFO']['remark'] // --remark
  666. )))
  667. {
  668. throw new Exception (ERROR_CODE_DB_FAILURE);
  669. }
  670. }
  671.  
  672. //$this->commit();
  673. @logHandler(PEAR_LOG_INFO, "Insert into group_contract_info end", $PHP_SELF, __FILE__, __LINE__ ) ;
  674. }
  675.  
  676. //install customer_document
  677. public function insertCustomerDocument()
  678. {
  679. @logHandler(PEAR_LOG_INFO, "Insert into customer_document start", $PHP_SELF, __FILE__, __LINE__ ) ;
  680. $exist = $this->c_db->SQLGetOne('GET_GROUP_CONTRACT_INFO_COUNT',
  681. $this->DocumentInfo['INFO']['market_code']
  682. ,$this->DocumentInfo['INFO']['cid']
  683. ,$this->DocumentInfo['INFO']['seq']
  684. ));
  685. if($exist){
  686. //기존 이력 저장
  687. $this->insertDocumentHistory();
  688.  
  689. if(false == $this->c_db->SQLExecute('UPD_GROUP_CONTRACT_INFO',
  690. $this->ContractInfo['INFO']['agent_id'] // --sys_operator_id
  691. ,$this->ContractInfo['INFO']['agent_id'] // --reg_agent_id
  692. ,$this->ContractInfo['INFO']['remark'] // --remark
  693. ,$this->ContractInfo['INFO']['market_code']
  694. ,$this->ContractInfo['INFO']['cid']
  695. ,$this->ContractInfo['INFO']['seq']
  696. )))
  697. {
  698. throw new Exception (ERROR_CODE_DB_FAILURE);
  699. }
  700. }
  701. else
  702. { //신규저장
  703. if(false == $this->c_db->SQLExecute('INS_GROUP_CONTRACT_INFO',
  704. $this->ContractInfo['INFO']['market_code'] // --market_code
  705. ,$this->ContractInfo['INFO']['cid'] // --cid
  706. ,$this->ContractInfo['INFO']['seq'] // --seq
  707. ,date('Ymd') // --reg_date
  708. ,$this->ContractInfo['INFO']['agent_id'] // --reg_agent_id
  709. ,$this->ContractInfo['INFO']['contract_kind'] // --contract_kind
  710. ,$this->ContractInfo['INFO']['contract_type'] // --contract_type
  711. ,$this->ContractInfo['INFO']['work_group'] // --work_group
  712. ,$this->ContractInfo['ACTIVITY_CODE'] // --activity_code
  713. ,$this->ContractInfo['INFO']['agent_id'] // --sys_operator_id
  714. ,$this->ContractInfo['INFO']['folder_name'] // --folder_name
  715. ,$this->ContractInfo['INFO']['file_name'] // --file_name
  716. ,"Y" // --flag
  717. ,$this->ContractInfo['INFO']['remark'] // --remark
  718. )))
  719. {
  720. throw new Exception (ERROR_CODE_DB_FAILURE);
  721. }
  722. }
  723.  
  724. //$this->commit();
  725. @logHandler(PEAR_LOG_INFO, "Insert into group_contract_info end", $PHP_SELF, __FILE__, __LINE__ ) ;
  726. }
  727.  
  728. //insert group_contract_info_his
  729. public function insertGroupHistory()
  730. {
  731. if(false == $this->c_db->SQLExecute('INS_GROUP_CONTRACT_INFO_HIS',
  732. $this->ContractInfo['INFO']['agent_id'] // --sys_operator_id
  733. ,$this->ContractInfo['INFO']['market_code'] // --market_code
  734. ,$this->ContractInfo['INFO']['cid'] // --cid
  735. ,$this->ContractInfo['INFO']['seq'] // --seq
  736. )))
  737. {
  738. throw new Exception (ERROR_CODE_DB_FAILURE);
  739. }
  740. }
  741.  
  742. //insert customer_document_his
  743. public function insertDocumentHistory()
  744. {
  745. if(false == $this->c_db->SQLExecute('INS_GROUP_CONTRACT_INFO_HIS',
  746. $this->ContractInfo['INFO']['agent_id'] // --sys_operator_id
  747. ,$this->ContractInfo['INFO']['market_code'] // --market_code
  748. ,$this->ContractInfo['INFO']['cid'] // --cid
  749. ,$this->ContractInfo['INFO']['seq'] // --seq
  750. )))
  751. {
  752. throw new Exception (ERROR_CODE_DB_FAILURE);
  753. }
  754. }
  755.  
  756. //비고항목및 동의항목 수정
  757. public function editContract()
  758. {
  759. //기존 이력 저장
  760. $this->insertGroupHistory();
  761.  
  762. if(false == $this->c_db->SQLExecute('UPD_GROUP_CONTRACT_INFO_DATA',
  763. $this->ContractInfo['INFO']['agent_id'] // --sys_operator_id
  764. ,$this->ContractInfo['INFO']['contract_type']
  765. ,$this->ContractInfo['INFO']['reg_agent_id']
  766. ,$this->ContractInfo['INFO']['remark']
  767. ,$this->ContractInfo['INFO']['market_code']
  768. ,$this->ContractInfo['INFO']['cid']
  769. ,$this->ContractInfo['INFO']['seq']
  770. )))
  771. {
  772. throw new Exception (ERROR_CODE_DB_FAILURE);
  773. }
  774.  
  775. if ($this->ContractInfo['INFO']['contract_kind'] == "P")
  776. {
  777. $sys_memo_text = "작업내역:[개인 계약서 정보 수정]";
  778. $usr_memo_text = "1.변경사항:[비고 - ".$this->ContractInfo['INFO']['remark']."],3.작업그룹:[".$this->ContractInfo['INFO']['work_group']."] 3.작업자:[".$this->ContractInfo['INFO']['agent_name']."]";
  779. }
  780. else
  781. {
  782. $sys_memo_text = "작업내역:[단체 계약서 정보 수정]";
  783. $usr_memo_text = "1.변경사항:[비고 - ".$this->ContractInfo['INFO']['remark']."],2.SEQ_NO:[".$this->ContractInfo['INFO']['seq']."] 3.작업자:[".$this->ContractInfo['INFO']['agent_name']."]";
  784. }
  785.  
  786. $this->insertCCM_MEMO($sys_memo_text, $usr_memo_text);
  787.  
  788. $this->commit();
  789. }
  790.  
  791. // Hangang_auto_start : insertPaymentMethodHistory (autopay - upload)
  792. //insert payment_method_history
  793. public function insertPaymentMethodHistory()
  794. {
  795. @logHandler(PEAR_LOG_INFO, "Insert into payment_method_history start", $PHP_SELF, __FILE__, __LINE__ ) ;
  796.  
  797. $agree_name = $this->ContractInfo['INFO']['folder_name']."/".$this->ContractInfo['INFO']['file_name'];
  798.  
  799. if(false == $this->c_db->SQLExecute('UPD_PAYMENT_METHOD_HISTORY',
  800. $agree_name // agree_name
  801. ,'SCAN' // agree_type
  802. ,$this->ContractInfo['INFO']['market_code']
  803. ,$this->ContractInfo['INFO']['cid']
  804. ,$this->ContractInfo['INFO']['work_group']
  805. )))
  806. {
  807. throw new Exception (ERROR_CODE_DB_FAILURE);
  808. }
  809.  
  810. //$this->commit();
  811. @logHandler(PEAR_LOG_INFO, "Insert into payment_method_history end", $PHP_SELF, __FILE__, __LINE__ ) ;
  812. }
  813. // Hangang_auto_end
  814.  
  815. //단체계약서 저장이력 삭제
  816. public function deleteContract($file_name)
  817. {
  818. $this->_deleteImageServerPDF($file_name);
  819.  
  820. //이력삭제
  821. if(false == $this->c_db->SQLExecute('DELETE_GROUP_CONTRACT_INFO_HIS',
  822. $this->ContractInfo['INFO']['market_code']
  823. ,$this->ContractInfo['INFO']['cid']
  824. ,$this->ContractInfo['INFO']['seq']
  825. )))
  826. {
  827. throw new Exception(ERROR_CODE_DB_FAILURE);
  828. }
  829.  
  830. //정보삭제
  831. if(false == $this->c_db->SQLExecute('DELETE_GROUP_CONTRACT_INFO',
  832. $this->ContractInfo['INFO']['market_code']
  833. ,$this->ContractInfo['INFO']['cid']
  834. ,$this->ContractInfo['INFO']['seq']
  835. )))
  836. {
  837. throw new Exception(ERROR_CODE_DB_FAILURE);
  838. }
  839.  
  840. $sys_memo_text = "작업냐역:[단체 계약서 삭제처리]";
  841. $usr_memo_text = "1.삭제파일명:[".$file_name."],2.작업자:[".$this->ContractInfo['INFO']['agent_name']."]";
  842.  
  843. $this->insertCCM_MEMO($sys_memo_text, $usr_memo_text);
  844.  
  845. $this->commit();
  846. }
  847.  
  848. public function insertCCM_MEMO($sys_memo_text, $usr_memo_text)
  849. {
  850. if(false == $this->c_db->SQLExecute('INS_CCM_MEMO',
  851. $this->ContractInfo['INFO']['market_code']
  852. ,$this->ContractInfo['INFO']['cid']
  853. ,$this->ContractInfo['INFO']['agent_id']
  854. ,"0038"
  855. ,$sys_memo_text
  856. ,$usr_memo_text
  857. ,$this->ContractInfo['INFO']['market_code']
  858. ,$this->ContractInfo['INFO']['cid'])) )
  859. {
  860. throw new Exception (ERROR_CODE_DB_FAILURE);
  861. }
  862. // $this->commit();
  863. }
  864.  
  865. //PDF 저장 폴더
  866. public function getPDFServerFolderName()
  867. {
  868. $yyyymmdd = str_replace(".","", date('Y.m.d'));
  869. $yyyymmdd = substr($yyyymmdd, 0, 8);
  870.  
  871. $folder = $this->ContractInfo['INFO']['market_code'] . "/" . substr($yyyymmdd, 0, 4) . "/" . substr($yyyymmdd, -4) ;
  872.  
  873. return $folder;
  874. }
  875.  
  876. // 서류 저장 폴더
  877. public function getDocumentFolderName()
  878. {
  879. $yyyymmdd = str_replace(".","", date('Y.m.d'));
  880. $yyyymmdd = substr($yyyymmdd, 0, 8);
  881.  
  882. $folder = $this->DocumentInfo['INFO']['market_code'] . "/" . substr($yyyymmdd, 0, 4) . "/" . substr($yyyymmdd, -4) ;
  883.  
  884. return $folder;
  885. }
  886.  
  887. //PDF 파일명
  888. public function getPDFServerFileName()
  889. {
  890. $yyyymmdd = str_replace(".","", date('Y.m.d'));
  891. $yyyymmdd = substr($yyyymmdd, 0, 8);
  892. $file_name = $this->ContractInfo['INFO']['market_code'] ."_". $this->ContractInfo['INFO']['cid'];
  893.  
  894. $file_name = ($this->ContractInfo['INFO']['contract_kind'] =="P") ? $file_name ."_". $this->ContractInfo['INFO']['work_group'] ."_". $yyyymmdd : $file_name."_".$yyyymmdd ;
  895.  
  896. return $file_name ;
  897. }
  898.  
  899. // 서류 파일명
  900. public function getDocumentFileName()
  901. {
  902. $yyyymmdd = str_replace(".","", date('Y.m.d'));
  903. $yyyymmdd = substr($yyyymmdd, 0, 8);
  904.  
  905. $file_name = $this->DocumentInfo['INFO']['market_code'] ."_". $this->DocumentInfo['INFO']['cid'] ."_". $yyyymmdd ;
  906.  
  907. //$file_name = ($this->DocumentInfo['INFO']['contract_kind'] =="P") ? $file_name ."_". $this->DocumentInfo['INFO']['work_group'] ."_". $yyyymmdd : $file_name."_".$yyyymmdd ;
  908.  
  909. return $file_name ;
  910. }
  911.  
  912.  
  913. //계약서 종류 가져오기
  914. public function get_contract_type($market_code)
  915. {
  916. $this->c_db = DBController::getInstance();
  917. $_list = $this->c_db->SQLQuery("GET_CONTRACT_TYPE_LIST", array($market_code));
  918.  
  919. $arr = array();
  920.  
  921. for($i=0; $i < count($_list); $i++)
  922. {
  923. $arr[$_list[$i]['CODE_VAL'] ] = $_list[$i]['CODE_STR'];
  924. }
  925.  
  926. return $arr;
  927. }
  928.  
  929. public function commit()
  930. {
  931. $this->c_db->commit();
  932. }
  933.  
  934. public function rollback()
  935. {
  936. $this->c_db->rollback();
  937. }
  938.  
  939. public function disconn($flag=FALSE)
  940. {
  941. $this->c_db->disconn($flag);
  942. }
  943.  
  944. //파일정보 재배열 처리
  945. public function multiple(array $_files, $top = TRUE)
  946. {
  947. $files = array();
  948. foreach($_files as $name=>$file){
  949. if($top) $sub_name = $file['name'];
  950. else $sub_name = $name;
  951.  
  952. if(is_array($sub_name)){
  953. foreach(array_keys($sub_name) as $key){
  954. $files[$name][$key] = array(
  955. 'name' => $file['name'][$key],
  956. 'type' => $file['type'][$key],
  957. 'tmp_name' => $file['tmp_name'][$key],
  958. 'error' => $file['error'][$key],
  959. 'size' => $file['size'][$key],
  960. );
  961. $files[$name] = $this->multiple($files[$name], FALSE);
  962. }
  963. }else{
  964. $files[$name] = $file;
  965. }
  966. }
  967. return $files;
  968. }
  969.  
  970. public function login_chk()
  971. {
  972. if (!$_SESSION['fromSMS'])
  973. {
  974. header("Location: /group_contract/index.php");
  975. die();
  976. }
  977. }
  978.  
  979. public function prt_return($str, $url, array $data)
  980. {
  981. echo "<script type=\"text/javascript\">alert(\"$str\");</script>";
  982. _user_reaction($url, $data);
  983. }
  984.  
  985. }
Success #stdin #stdout 0.02s 24452KB
stdin
Standard input is empty
stdout
Standard output is empty