__call("shield.server.view",$param); $resultArr = $arr['list']; */ function checkDefaultVal($val, $default="1") { if ( trim($val) === "" ) { return $default; } return $val; } function checkDefaultNum($val, $default="1") { $val = checkDefaultVal($val, $default); if ( !is_numeric($val) ) { return $default; } return $val; } function generateRandomString($length = 10) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } return $randomString; } $stype = $_GET["stype"] ; //$stype = $_POST["stype"] ; error_log ("userExcel stype:" . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); if ($stype == "excel_sample") { $target_Dir = "/usr/local/apache/htdocs/mailfilter/"; $file = "user.xls"; $down = $target_Dir.$file; $filesize = filesize($down); error_log ("userExcel excel_sample:" . $down . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); if(file_exists($down)) { header( "Content-type: application/vnd.ms-excel" ); header( "Content-type: application/vnd.ms-excel; charset=utf-8"); header( "Content-Disposition: attachment; filename = user.xls" ); /* header("Content-Type:application/octet-stream"); header("Content-Disposition:attachment;filename=$file"); header("Content-Transfer-Encoding:binary"); header("Content-Length:".filesize($target_Dir.$file)); */ header("Cache-Control:cache,must-revalidate"); header("Pragma:no-cache"); header("Expires:0"); if(is_file($down)) { $fp = fopen($down,"r"); while(!feof($fp)){ $buf = fread($fp,8096); $read = strlen($buf); print($buf); flush(); } fclose($fp); } } exit; } if ( $stype == "excel" ) { if ( $stype == "excel" ) { $start = 0 ; $count = 20000 ; } $from_sql = " from COM_USER where 1 = 1 " ; $count_sql = " select count(*) as cnt $from_sql " ; $sql = " select * ". $from_sql . " order by USERNO asc LIMIT " . $start . ", " . $count . " " ; $count_result=mysql_query($count_sql, $connect) or die (mysql_error()); error_log ("userExcel excel_sample:" . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); if ($data=mysql_fetch_array($count_result)) { $total_count = $data[0]; //total_count } else { $total_count=0; } $result=mysql_query($sql, $connect) or die (mysql_error()); // excel 만들기 $excelTitleArray = array( array( 'col_name' => 'USERNM' , 'title' => 'USERNAME' , 'type' => 'string' ) , array( 'col_name' => 'USERID' , 'title' => 'EMAIL' , 'type' => 'string' ) , array( 'col_name' => 'USERPOS' , 'title' => 'POSTION' , 'type' => 'string' ) , array( 'col_name' => 'DEPTNO' , 'title' => 'DEPARTMENT' , 'type' => '' ) , ); $today = date("Y-m-d") ; $filename = "user_".$today ; exportExcelMysql($excelTitleArray, $filename, $result, true) ; exit; } if (isset($_FILES['xls_file'])) { $target_dir = "/usr/local/apache/htdocs/mailfilter/upload/"; $uploadOk = 1; $FileType = strtolower(pathinfo($_FILES["xls_file"]["name"],PATHINFO_EXTENSION)); error_log ("userExcel FileType:" . $FileType . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); $target_file = $target_dir . generateRandomString() .'.'.$FileType; error_log ("userExcel target_file:" . $target_file . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); if($FileType == "pdf") { $uploadOk = 1; } if (move_uploaded_file ($_FILES['xls_file']['tmp_name'], $target_file )) { if (!file_exists($target_file)) { echo ""; exit; } //파일 타입 설정 (확자자에 따른 구분) /* $inputFileType = 'Excel2007'; if($UpFileExt == "xls") { $inputFileType = 'Excel5'; } */ $inputFileType = 'Excel5'; $objReader = PHPExcel_IOFactory::createReader($inputFileType); //엑셀리더 초기화 $objReader->setReadDataOnly(true); //데이터만 읽기(서식을 모두 무시해서 속도 증가 시킴) //$objReader->setReadFilter($filterSubset); //범위 지정(위에 작성한 범위필터 적용) try { $objPHPExcel = $objReader->load($target_file); //업로드된 엑셀 파일 읽기 } catch(PHPExcel_Reader_Exception $e) { echo ""; exit; //die('Error loading file: '.$e->getMessage()); } $objPHPExcel->setActiveSheetIndex(0); //첫번째 시트로 고정 $objWorksheet = $objPHPExcel->getActiveSheet(); //고정된 시트 로드 $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); //시트의 지정된 범위 데이터를 모두 읽어 배열로 저장 $total_rows = count($sheetData); error_log ("userExcel excel_total_rows:" . $total_rows . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); $ok_cnt = 0; $tot_cnt = 0; $errMsg = ""; foreach($sheetData as $rows) { $tot_cnt++; if ( $tot_cnt == 1 ) { //첫라인 건너 뛰기. continue; } $USERNM = $rows["A"]; $USERID = $rows["B"]; $POS = $rows["C"]; $DEPT = $rows["D"]; $SIGN = $rows["E"]; $SIGN2 = $rows["F"]; //$NO = checkDefaultNum($rows["G"]); $USERROLE = $rows["G"]; error_log ("userExcel USERNM:" . $USERNM . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); error_log ("userExcel USERID:" . $USERID . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); error_log ("userExcel POS:" . $POS . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); error_log ("userExcel DEPT:" . $DEPT . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); error_log ("userExcel SIGN:" . $SIGN . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); error_log ("userExcel SIGN2:" . $SIGN2 . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); error_log ("userExcel USERROLE:" . $USERROLE . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); // *** 직위 처리 $pos_sql = "select CODECD from COM_CODE where CODENM = '" . $POS . "'"; $pos_result=mysql_query($pos_sql, $connect) or die (mysql_error()); error_log ("userExcel ##_직위 처리: pos_sql:" . $pos_sql . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); if ($data=mysql_fetch_array($pos_result)) { $userpos = $data[0]; error_log ("userExcel userpos:" . $userpos . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); } else { $userpos = "03"; error_log ("userExcel empty_userpos:" . $userpos . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); } // *** 부서 처리 $dept_explode = explode( '^', $DEPT ); $count = count($dept_explode); error_log ("userExcel dept_count:" . $count . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); $i = 0 ; foreach($dept_explode as $key) { $i++; if ($i == 1) { $current_deptnm = $dept_explode[$i - 1]; error_log ("userExcel dept_name_top:" . $i . " " . $current_deptnm . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); // 1. 부서가 이미 COM_DEPT 테이블에 있는지? 없으면 PARENTNO = NULL 로 생성 $count_sql = "select count(*) from COM_DEPT where DELETEFLAG = 'N' AND DEPTNM = '" . $current_deptnm . "'"; $count_result=mysql_query($count_sql, $connect) or die (mysql_error()); if ($data=mysql_fetch_array($count_result)) { $total_count = $data[0]; } if ($total_count == 0) { $sql = "userExcel delete from COM_DEPT where DEPTNM = '" . $current_deptnm . "'"; error_log ("userExcel @@@:" . $sql . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); $result = @mysql_query($sql, $connect); $insert_deptno_sql = "SELECT IFNULL(MAX(DEPTNO),0)+1 FROM COM_DEPT"; $insert_deptno_result=mysql_query($insert_deptno_sql, $connect) or die (mysql_error()); if ($data=mysql_fetch_array($insert_deptno_result)) { $insert_deptno = $data[0]; error_log ("userExcel insert_deptno:" . $insert_deptno . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); } $sql = " insert into COM_DEPT (DEPTNO, DEPTNM, PARENTNO, DELETEFLAG) values ('$insert_deptno', '$current_deptnm', NULL, 'N')"; error_log ("userExcel @@@:" . $sql . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); $result = @mysql_query($sql, $connect); } } else { $current_deptnm = $dept_explode[$i - 1]; error_log ("userExcel current_dept_name:" . $current_deptnm . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); // 이전 부서의 DEPTNO 값을 얻어서 parent_id 로 할당한다. $before_deptnm = $dept_explode[$i - 2]; error_log ("userExcel before_dept_name:" . $before_deptnm . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); $parent_sql = "select DEPTNO from COM_DEPT where DEPTNM = '" . $before_deptnm . "'"; $parent_result=mysql_query($parent_sql, $connect) or die (mysql_error()); error_log ("userExcel parent_sql:" . $parent_sql . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); if ($data=mysql_fetch_array($parent_result)) { $parent_id = $data[0]; error_log ("userExcel parent_id:" . $parent_id . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); } else { $parent_id = 1; error_log ("userExcel empty_parent_id:" . $parent_id . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); } // 1. 부서가 이미 COM_DEPT 테이블에 있는지? 없으면 PARENTNO 를 구해서 생성 $count_sql = "select count(*) from COM_DEPT where DELETEFLAG = 'N' AND DEPTNM = '" . $current_deptnm . "'"; error_log ("userExcel ###:" . $count_sql . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); $count_result=mysql_query($count_sql, $connect) or die (mysql_error()); if ($data=mysql_fetch_array($count_result)) { $total_count = $data[0]; } if ($total_count == 0) { error_log ("userExcel ###:" . $parent_sql . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); $sql = " delete from COM_DEPT where DEPTNM = '" . $current_deptnm . "'"; error_log ("userExcel ###:" . $sql . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); $result = @mysql_query($sql, $connect); $insert_deptno_sql = "SELECT IFNULL(MAX(DEPTNO),0)+1 FROM COM_DEPT"; $insert_deptno_result=mysql_query($insert_deptno_sql, $connect) or die (mysql_error()); if ($data=mysql_fetch_array($insert_deptno_result)) { $insert_deptno = $data[0]; error_log ("userExcel insert_deptno:" . $insert_deptno . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); } $sql = " insert into COM_DEPT (DEPTNO, DEPTNM, PARENTNO, DELETEFLAG) values ('$insert_deptno', '$current_deptnm', '$parent_id', 'N')"; error_log ("userExcel ###:" . $sql . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); $result = @mysql_query($sql, $connect); } } // 현 사용자의 부서번호는 마지막 부서임. if ($i == $count) { $last_deptnm = $dept_explode[$count - 1]; $deptno_sql = "select DEPTNO from COM_DEPT where DEPTNM = '" . $last_deptnm . "'"; $deptno_result=mysql_query($deptno_sql, $connect) or die (mysql_error()); error_log ("userExcel deptno_sql:" . $deptno_sql . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); if ($data=mysql_fetch_array($deptno_result)) { $deptno = $data[0]; error_log ("userExcel deptno:" . $deptno . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); } else { $deptno = 1; error_log ("userExcel empty_deptno:" . $deptno . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); } } } // COM_USER 테이블에 insert 한다. DEPTNO($deptno) , USERPOS($userpos) 값을 얻어서 넣는다. $sql = " insert into COM_USER (USERID, USERNM, USERPW, USERROLE, PHOTO, DEPTNO, DELETEFLAG, USERPOS) values ('$USERID', '$USERNM', NULL, '$USERROLE', NULL, '$deptno', 'N', '$userpos')"; error_log ("userExcel ###:" . $sql . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); $result = @mysql_query($sql, $connect); $sql = " insert into SGN_PATH (USERID ,SPSIGNPATH) value ('$USERID' , '$SIGN') " ; $result = @mysql_query($sql, $connect) or die(mysql_error()); //@@ 등록이 안되면 OK 가 오면 안됨.. 확인.... $ok_cnt++; } if($connect) mysql_close($connect); } } else { $viewtable_db_host="10.77.77.77"; $viewtable_db_id="root"; $viewtable_db_passwd="admin01"; $viewtable_db_name="proshield"; $viewtable_connect = mysql_connect($viewtable_db_host, $viewtable_db_id, $viewtable_db_passwd) or die (mysql_error()); mysql_select_db($viewtable_db_name, $viewtable_connect) or die (mysql_error()); /* $viewtable_query = "set session character_set_connection=utf8;"; mysql_query($viewtable_query, $viewtable_connect); $viewtable_query = "set session character_set_client=utf8;"; mysql_query($viewtable_query, $viewtable_connect); $viewtable_query = "set session character_set_results=utf8;"; mysql_query($viewtable_query, $viewtable_connect); $viewtable_query = "set collation_connection=utf8_general_ci;"; mysql_query($viewtable_query, $viewtable_connect); */ error_log ("DB start:" . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); $viewtable_sql = "select USER_ID, USER_EMAIL, USER_NAME, POSTIONNAME, USER_CUSTOM03, USER_CUSTOM04 from vwIMAGEOCR"; $viewtable_result=mysql_query($viewtable_sql, $viewtable_connect) or die (mysql_error()); $ok_cnt = 0; $tot_cnt = 0; while ($viewtable_data=mysql_fetch_array($viewtable_result)) { $viewtable_user_id = $viewtable_data[0]; $viewtable_user_email = $viewtable_data[1]; $viewtable_user_name = $viewtable_data[2]; $viewtable_positionname = $viewtable_data[3]; $viewtable_user_custom03 = $viewtable_data[4]; $viewtable_user_custom04 = $viewtable_data[5]; error_log ("## viewtable_user_id -->" . $viewtable_user_id . ", viewtable_user_name=" . $viewtable_user_name . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); // *** 직위 처리 $pos_sql = "select CODECD from COM_CODE where CODENM = '" . $POS . "'"; $pos_result=mysql_query($pos_sql, $connect) or die (mysql_error()); error_log ("userExcel ##_직위 처리: pos_sql:" . $pos_sql . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); if ($data=mysql_fetch_array($pos_result)) { $userpos = $data[0]; error_log ("userExcel userpos:" . $userpos . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); } else { $userpos = "03"; error_log ("userExcel empty_userpos:" . $userpos . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); } // *** 부서 처리 // db data 를 excel 처럼 ^ 로 합친다. $DEPT = $viewtable_user_custom03 . "^" . $viewtable_user_custom04; $dept_explode = explode( '^', $DEPT ); $count = count($dept_explode); error_log ("userExcel dept_count:" . $count . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); $i = 0 ; foreach($dept_explode as $key) { $i++; if ($i == 1) { $current_deptnm = $dept_explode[$i - 1]; error_log ("userExcel dept_name_top:" . $i . " " . $current_deptnm . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); // 1. 부서가 이미 COM_DEPT 테이블에 있는지? 없으면 PARENTNO = NULL 로 생성 $count_sql = "select count(*) from COM_DEPT where DELETEFLAG = 'N' AND DEPTNM = '" . $current_deptnm . "'"; $count_result=mysql_query($count_sql, $connect) or die (mysql_error()); if ($data=mysql_fetch_array($count_result)) { $total_count = $data[0]; } if ($total_count == 0) { $sql = "delete from COM_DEPT where DEPTNM = '" . $current_deptnm . "'"; error_log ("userExcel @@@:" . $sql . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); $result = @mysql_query($sql, $connect); $insert_deptno_sql = "SELECT IFNULL(MAX(DEPTNO),0)+1 FROM COM_DEPT"; $insert_deptno_result=mysql_query($insert_deptno_sql, $connect) or die (mysql_error()); if ($data=mysql_fetch_array($insert_deptno_result)) { $insert_deptno = $data[0]; error_log ("userExcel insert_deptno:" . $insert_deptno . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); } $sql = " insert into COM_DEPT (DEPTNO, DEPTNM, PARENTNO, DELETEFLAG) values ('$insert_deptno', '$current_deptnm', NULL, 'N')"; error_log ("userExcel @@@:" . $sql . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); $result = @mysql_query($sql, $connect); } } else { $current_deptnm = $dept_explode[$i - 1]; error_log ("userExcel current_dept_name:" . $current_deptnm . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); // 이전 부서의 DEPTNO 값을 얻어서 parent_id 로 할당한다. $before_deptnm = $dept_explode[$i - 2]; error_log ("userExcel before_dept_name:" . $before_deptnm . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); $parent_sql = "select DEPTNO from COM_DEPT where DEPTNM = '" . $before_deptnm . "'"; $parent_result=mysql_query($parent_sql, $connect) or die (mysql_error()); error_log ("userExcel parent_sql:" . $parent_sql . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); if ($data=mysql_fetch_array($parent_result)) { $parent_id = $data[0]; error_log ("userExcel parent_id:" . $parent_id . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); } else { $parent_id = 1; error_log ("userExcel empty_parent_id:" . $parent_id . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); } // 1. 부서가 이미 COM_DEPT 테이블에 있는지? 없으면 PARENTNO 를 구해서 생성 $count_sql = "select count(*) from COM_DEPT where DELETEFLAG = 'N' AND DEPTNM = '" . $current_deptnm . "'"; error_log ("userExcel ###:" . $count_sql . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); $count_result=mysql_query($count_sql, $connect) or die (mysql_error()); if ($data=mysql_fetch_array($count_result)) { $total_count = $data[0]; } if ($total_count == 0) { error_log ("userExcel ###:" . $parent_sql . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); $sql = " delete from COM_DEPT where DEPTNM = '" . $current_deptnm . "'"; error_log ("userExcel ###:" . $sql . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); $result = @mysql_query($sql, $connect); $insert_deptno_sql = "SELECT IFNULL(MAX(DEPTNO),0)+1 FROM COM_DEPT"; $insert_deptno_result=mysql_query($insert_deptno_sql, $connect) or die (mysql_error()); if ($data=mysql_fetch_array($insert_deptno_result)) { $insert_deptno = $data[0]; error_log ("userExcel insert_deptno:" . $insert_deptno . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); } $sql = " insert into COM_DEPT (DEPTNO, DEPTNM, PARENTNO, DELETEFLAG) values ('$insert_deptno', '$current_deptnm', '$parent_id', 'N')"; error_log ("userExcel ###:" . $sql . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); $result = @mysql_query($sql, $connect); } } // 현 사용자의 부서번호는 마지막 부서임. if ($i == $count) { $last_deptnm = $dept_explode[$count - 1]; $deptno_sql = "select DEPTNO from COM_DEPT where DEPTNM = '" . $last_deptnm . "'"; $deptno_result=mysql_query($deptno_sql, $connect) or die (mysql_error()); error_log ("userExcel deptno_sql:" . $deptno_sql . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); if ($data=mysql_fetch_array($deptno_result)) { $deptno = $data[0]; error_log ("userExcel deptno:" . $deptno . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); } else { $deptno = 1; error_log ("userExcel empty_deptno:" . $deptno . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); } } } // COM_USER 테이블에 insert 한다. DEPTNO($deptno) , USERPOS($userpos) 값을 얻어서 넣는다. $sql = " insert into COM_USER (USERID, USERNM, USERPW, USERROLE, PHOTO, DEPTNO, DELETEFLAG, USERPOS) values ('$USERID', '$USERNM', NULL, '$USERROLE', NULL, '$deptno', 'N', '$userpos')"; error_log ("userExcel ###:" . $sql . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); $result = @mysql_query($sql, $connect); $sql = " insert into SGN_PATH (USERID ,SPSIGNPATH) value ('$USERID' , '$SIGN') " ; $result = @mysql_query($sql, $connect) or die(mysql_error()); //@@ 등록이 안되면 OK 가 오면 안됨.. 확인.... $ok_cnt++; } if($viewtable_connect) mysql_close($viewtable_connect); exit; } $domain = $_SERVER["SERVER_NAME"]; $redirect_location = "'Location: https://" . $domain . ":8443/mu'"; error_log ("userExcel @@@:" . $redirect_location . "\n", 3, "/usr/local/imagefilter30/var/logs/php.log"); header($redirect_location); ?>