ShuanghongS 10 bulan lalu
induk
melakukan
31b41d8cc1
4 mengubah file dengan 261 tambahan dan 49 penghapusan
  1. 9 4
      include.ini.php
  2. 51 26
      service/ocean_order.class.php
  3. 69 0
      service/tools.class.php
  4. 132 19
      utils/utils.class.php

+ 9 - 4
include.ini.php

@@ -21,10 +21,15 @@ define('ADODB_PATH', ONLINE_ROOT . 'libs' . DS . 'ADOdb-5.20.17' . DS);
 define('C_PATH', ONLINE_ROOT . 'service' . DS);
 define('SERVER_PAHT', 'http://192.168.0.161/Customer_Service_Online/');
 
-define('DOCUMENT_AIR_UPLOAD_PATH', "D:" . DS . "DOC_AIR" . DS);
-define('DOCUMENT_OCEAN_UPLOAD_PATH', "D:" . DS . "DOC" . DS);
-define('DOCUMENT_SFSAIR_UPLOAD_PATH', "D:" . DS . "DOC_AIR" . DS);
-define('DOCUMENT_SFSOCEAN_UPLOAD_PATH', "D:" . DS . "DOC" . DS);
+// define('DOCUMENT_AIR_UPLOAD_PATH', "D:" . DS . "DOC_AIR" . DS);
+// define('DOCUMENT_OCEAN_UPLOAD_PATH', "D:" . DS . "DOC" . DS);
+// define('DOCUMENT_SFSAIR_UPLOAD_PATH', "D:" . DS . "DOC_AIR" . DS);
+// define('DOCUMENT_SFSOCEAN_UPLOAD_PATH', "D:" . DS . "DOC" . DS);
+
+define('DOCUMENT_AIR_UPLOAD_PATH', "DOC_AIR" . DS);
+define('DOCUMENT_OCEAN_UPLOAD_PATH', "DOC" . DS);
+define('DOCUMENT_SFSAIR_UPLOAD_PATH', "DOC_AIR" . DS);
+define('DOCUMENT_SFSOCEAN_UPLOAD_PATH', "DOC" . DS);
 
 if (preg_match("/(bot|crawl|spider|slurp)/i", $_SERVER['HTTP_USER_AGENT'])) {
     header('HTTP/1.1 403 Forbidden');

+ 51 - 26
service/ocean_order.class.php

@@ -138,7 +138,6 @@ class ocean_order {
             $bol = $_POST['h_bol'];
             if ($transport_mode == "sea") {
                 $count = common::excuteObjectSql("select * from ocean where lower(h_bol) = '" . strtolower($bol) . "'");
-                
             } elseif ($transport_mode == "air") {
                 $count = common::excuteObjectSql("select * from air where lower(hawb) = '" . strtolower($bol) . "'");
             }
@@ -170,7 +169,7 @@ class ocean_order {
                     }
                     $size = floor($_FILES ["file"]['size'][$i] / 1024 / 1024);
                     if ($size > 5) {
-                        $errorMsg = $_FILES['file']["name"][$i] . "is larger than 5M";
+                        $errorMsg = $_FILES['file']["name"][$i] . "is larger than 5M.";
                         continue;
                     }
                     if ($_FILES["file"]["error"][$i] > 0) {
@@ -185,10 +184,9 @@ class ocean_order {
                     $exten = $path_parts['extension'];
                     if (stristr($allow_extend, "|." . $exten . "|") === FALSE) {
                         //$errorMsg .= ' Only can upload PDF/Excel/Doc file;';
-                        $errorMsg = $_FILES['file']["name"][$i].' must PDF type';
+                        $errorMsg = $_FILES['file']["name"][$i].' must PDF Type.';
                     }
 
-                    //$filename = $file_name[$i];
                     $filename = $bol."_".$format['standard']."_V".($i+1+$num). "." . $exten;
                     $file_size = floor($_FILES ["file"]['size'][$i] / 1024) . "KB";
                     $order_type =  $transport_mode == "sea" ? "ocean" : "air";
@@ -214,26 +212,54 @@ class ocean_order {
     
                     $save_path = $folder . DS . date("Ymd") . DS;
                     if (common::mkdirs($save_path) === FALSE){
-                        $errorMsg = " Save folder create error";
-                    }
-                    if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $save_path . $filename)) {
-                        $sql .= "insert into $_schemas.$_table (file_name, file_path, upload_date, upload_ip, upload_by, bol, file_type, file_size, online_upload, 
-                            origin, destination, from_station, serial_no, 
-                            online_format,format_serailno,source_filename) 
-                        values ('" . common::check_input($filename) . "','" . common::check_input($save_path) . "', now(), '" . common::ip() . "', 
-                                '" . common::check_input(_getLoginName()) . "','" . common::check_input(strtoupper($bol)) . "', '$order_type', '" . common::check_input($file_size) . "',
-                                't', '" . common::check_input($origin_station) . "', '" .common::check_input($destination_station) . "',
-                                '" . common::check_input($from_station) . "', '" . $serial_no . "',
-                                '" . common::check_input($file_type) . "','" . common::check_input($format_serialno) . "','" . common::check_input($filename) . "');";
+                        $errorMsg = "Save Folder create error.";
+                        continue;
                     }
-                    //根据配置,看需要同步文件
+                    //pdf文件不需要处理宏,直接保存
+                    if($exten == "pdf"){
+                        if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $save_path . $filename)) {
+                            $sql .= "insert into $_schemas.$_table (file_name, file_path, upload_date, upload_ip, upload_by, bol, file_type, file_size, online_upload, 
+                                origin, destination, from_station, serial_no, 
+                                online_format,format_serailno,source_filename) 
+                            values ('" . common::check_input($filename) . "','" . common::check_input($save_path) . "', now(), '" . common::ip() . "', 
+                                    '" . common::check_input(_getLoginName()) . "','" . common::check_input(strtoupper($bol)) . "', '$order_type', '" . common::check_input($file_size) . "',
+                                    't', '" . common::check_input($origin_station) . "', '" .common::check_input($destination_station) . "',
+                                    '" . common::check_input($from_station) . "', '" . $serial_no . "',
+                                    '" . common::check_input($file_type) . "','" . common::check_input($format_serialno) . "','" . common::check_input($filename) . "');";        
+                        } else {
+                            $errorMsg = "Upload Filed Failed.";
+                            continue;
+                        }
+                    } else {
+                        //读取文件内容后,重新生成无宏版本文件,支持docx,xlsx 
+                        // $from_filename = $file_name[$i];
+                        // $inputFileName = $save_path . $from_filename;
+                        // $outputFileName = $save_path . $filename;
+                        // if(move_uploaded_file($_FILES['file']['tmp_name'][$i],$outputFileName)){
+                        //     $outputFileName = $save_path . $filename;
+                        //     //按outputFileName路径重新生成文件,并且删除旧文件(inputFileName)
+                        //     //utils::removeFIlemacro($inputFileName,$outputFileName,$exten);
+                        //     //utils::hasMacros($outputFileName);
+                        //     //utils::checkExcelMacros($outputFileName,$filename_no_exten);
+                        //     $sql .= "insert into $_schemas.$_table (file_name, file_path, upload_date, upload_ip, upload_by, bol, file_type, file_size, online_upload, 
+                        //             origin, destination, from_station, serial_no, 
+                        //             online_format,format_serailno,source_filename) 
+                        //         values ('" . common::check_input($filename) . "','" . common::check_input($save_path) . "', now(), '" . common::ip() . "', 
+                        //                 '" . common::check_input(_getLoginName()) . "','" . common::check_input(strtoupper($bol)) . "', '$order_type', '" . common::check_input($file_size) . "',
+                        //                 't', '" . common::check_input($origin_station) . "', '" .common::check_input($destination_station) . "',
+                        //                 '" . common::check_input($from_station) . "', '" . $serial_no . "',
+                        //                 '" . common::check_input($file_type) . "','" . common::check_input($format_serialno) . "','" . common::check_input($filename) . "');";
+                        // }
+                    } 
+                    //根据配置,看需要同步文件,
+                    $doc_upload_log_table =  $transport_mode == "sea" ? "ra_online_doc_upload_log" : "air_doc_upload_log";
                     if(!empty($format['auto_sync_to_station'])){
                         if($format['auto_sync_to_station'] == "Origin Station"){
-                            $sql .= "INSERT INTO public.ra_online_doc_upload_log(serial_no, station, download_time)
+                            $sql .= "INSERT INTO public.$doc_upload_log_table(serial_no, station, download_time)
                                 VALUES ('".$serial_no."', '" .common::check_input($destination_station) . "', now());";
                         }
                         if($format['auto_sync_to_station'] == "Destination Station"){
-                            $sql .= "INSERT INTO public.ra_online_doc_upload_log(serial_no, station, download_time)
+                            $sql .= "INSERT INTO public.$doc_upload_log_table(serial_no, station, download_time)
                                 VALUES ('".$serial_no."', '" .common::check_input($origin_station) . "', now());";
                         }
                         if($format['auto_sync_to_station'] == "Origin and Destination Stations"){
@@ -241,15 +267,16 @@ class ocean_order {
                         }
                     } else {
                         //如果没有配置。这代表不同步文件
-                        $sql .= "INSERT INTO public.ra_online_doc_upload_log(serial_no, station, download_time)
+                        $sql .= "INSERT INTO public.$doc_upload_log_table(serial_no, station, download_time)
                                 VALUES ('".$serial_no."', '" .common::check_input($destination_station) . "', now());";
-                        $sql .= "INSERT INTO public.ra_online_doc_upload_log(serial_no, station, download_time)
+                        $sql .= "INSERT INTO public.$doc_upload_log_table(serial_no, station, download_time)
                                 VALUES ('".$serial_no."', '" .common::check_input($origin_station) . "', now());";       
                     }
                     
+                    
                 }
                 //根据配置发送通知邮件 相同文件类型只提醒一次
-                if(!empty($format['notify_station'])){
+                if(!empty($format['notify_station'])  && empty($errorMsg)){
                     $origin_op_email = common::excuteOneSql("select email from employee where employee_id = '".$count["origin_op_id"]."' limit 1");
                     $dest_op_email = common::excuteOneSql("select email from employee where employee_id = '".$count["dest_op"]."' limit 1");
                     $ks_from = common::excuteOneSql("select ksmart_station from public.contract_region_mapping where overeas = '".$count["from_station"]."' limit 1");
@@ -257,7 +284,7 @@ class ocean_order {
                     $ks_from = empty($ks_from)? 'f' : $ks_from;
                     $ks_to = empty($ks_to)? 'f' : $ks_to;
                     if($ks_from == "f" && $ks_to == "f"){
-                        $errorMsg = "Both Non Ksmart,pls checked Info";
+                        $errorMsg = "Both Non Ksmart,pls checked";
                     }
                     
                     $curr_date_config = common::excuteObjectSql("SELECT to_char(now()::date,'Mon_DD_YYYY') as d1_day,to_char(now()::date,'Mon_DD_YYYY HH:MM') as d2_day");
@@ -411,7 +438,6 @@ class ocean_order {
                             }
                         }
                     }
-
                 }
 
                 if (!empty($errorMsg)) {
@@ -430,7 +456,7 @@ class ocean_order {
             } catch (Exception $e) {
                 error_log($e->getTraceAsString());
                 $data = array(
-                    'msg' => "Save Booking Failed:Upload Filed Failed."
+                    'msg' => "Upload Filed Failed."
                 );
                 common::echo_json_encode(500,$data);
             }
@@ -1227,7 +1253,6 @@ class ocean_order {
                         'simplexData' =>$simplexData,
                         'containerStatusData' => $containerStatusData,
                         'document_info' => $document_info,
-                        'containers' => $containers,
                         'Milestones' => $Milestones,
                         'routes' => $routes,
                         'email' => $email,
@@ -1255,7 +1280,7 @@ class ocean_order {
         $_schemas = $_REQUEST["_schemas"];
         $air_milestone_status = common::excuteListSql("select code,
                 act_date,est_date,timezone 
-            from  ocean_milestone a 
+            from  air_milestone a 
 		 		where a.serial_no='$serial_no' and code in('IFFCPU','IFFREC','IFFONB','IFFARR','IFFDEL')
             order by id");
         $state = -1;

+ 69 - 0
service/tools.class.php

@@ -104,6 +104,75 @@ class tools {
         }
     }
 
+    public function user_system_setting(){
+        $operate = utils::_get('operate');
+        $operate = strtolower($operate);
+
+        if ($operate == "personal_profile_init") {
+            // get system config
+            $sql = "SELECT lower(ra_name) as ra_name, ra_value from ra_online_config where lower(ra_name) in ('employee_password_change_cycle', 'customer_password_change_cycle')";
+            $rs1s = common::excuteListSql($sql);
+            foreach ($rs1s as $rs1) {
+                if ($rs1['ra_name'] == 'employee_password_change_cycle')
+                    $EMPLOYEE_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
+                if ($rs1['ra_name'] == 'customer_password_change_cycle')
+                    $CUSTOMER_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
+            }
+            $sql="select item_value from config where item='passwordChangePeriod'";
+            $pcp = common::excuteObjectSql($sql);
+            $passwordChangePeriod = json_decode($pcp["item_value"],true);
+
+            if (_isApexLogin()) {
+                $PASSWORD_CHANGE_CYCLE = $EMPLOYEE_PASSWORD_CHANGE_CYCLE;
+                //如果有新配置,则采用新配置
+                if (!empty($pcp)) {
+                    $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Employee"]["days"];
+                }
+            } else {
+                $PASSWORD_CHANGE_CYCLE = $CUSTOMER_PASSWORD_CHANGE_CYCLE;
+                //如果有新配置,则采用新配置
+                if (!empty($pcp)) {
+                    $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Customer"]["days"];
+                }
+            }
+            
+            $sql = "select first_name,last_name,user_login,email,
+                EXTRACT(DAY from (now() - last_pwd_change)) as last_pwd_change_date from ra_online_user where user_login = '"._getLoginName()."' ";
+            $data = common::excuteObjectSql($sql);
+            $data["expire_day"] = $PASSWORD_CHANGE_CYCLE - $data['last_pwd_change_date'];
+            $data["date_fromat"] = "03/15/2024";
+            $data["numbers_format"] = "1,234.56(US/UK)";
+            common::echo_json_encode(200,$data);
+            exit();
+        }
+
+        if ($operate == "personal_profile_save") {
+            $save_model = common::check_input($_POST['save_model']);
+            if ($save_model == "profile"){
+                $user_name = common::check_input($_POST['user_name']);
+                $email = common::check_input($_POST['email']);
+                $sql = "update public.ra_online_user set user_login = '$user_name',email = '$email'  where user_login = '"._getLoginName()."'";
+            }else{
+                $date_fromat = common::check_input($_POST['date_fromat']);
+                $numbers_format = common::check_input($_POST['numbers_format']);
+                $sql = "update public.ra_online_user set date_fromat = '$date_fromat',numbers_format = '$numbers_format'  where user_login = '"._getLoginName()."'";
+            }
+            common::excuteUpdateSql($sql);
+            $data = array("msg" => "save Successful");
+            common::echo_json_encode(200,$data);
+            exit();
+        }
+
+        if ($operate == "subscribe_notification_init") {
+            $data =array();
+
+            //Milestone Update rule 
+
+            common::echo_json_encode(200,$data);
+            exit();
+        }
+    }
+
 }
 
 ?>

+ 132 - 19
utils/utils.class.php

@@ -719,27 +719,140 @@ class utils {
         return $result;
     }
 
-    public static function hasMacro($filename) {
-        $zip = new ZipArchive();
-        if ($zip->open($filename) === TRUE) {
-            if ($zip->locateName('word/vbaProject.bin') !== false) {
-                return true;
-            } else {
-                return false;
-            }
-            $zip->close();
-        }
-        return false; // 没有发现VBA宏
-    }
+    /**
+     * 读取文件内容后,重新生成无宏版本文件,支持docx,xlsx(这两个文件类型,被设计就是不能带宏的) 
+     * 估计废除了,除非转pdf去宏,没有其他办法。libreoffice可以通过软件里面的tools栏位按钮去点击去宏处理,但没有命令行。
+     * 使用unoconv转换文档,但是最新的unoconv,不支持unoconv -f docx --no-macro 命令,网上查询的命令有误
+     */
+    // public static function removeFIlemacro($inputFileName,$outputFileName,$file_type) {
+    //     include_once ONLINE_ROOT . 'thirdparty_vendors' . DS . 'vendor' . DS . 'autoload.php';  
+    //     if($file_type == "xlsx" || $file_type == "xls"){
+    //         // 读取文件
+    //         // $spreadsheet = PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);
+    //         // // 生成新文件
+    //         // $writerType = ucfirst($file_type);
+    //         // $writer = PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, $writerType); // 使用 Xlsx 格式保存
+    //         // $writer->save($outputFileName);
+    //         // // 删除来源文件
+    //         // unlink($inputFileName);
+    //         // LibreOffice 的命令行命令
+    //         // $command = "soffice --headless --convert-to pdf --outdir " . dirname($outputFileName) . " " . $inputFileName;
+    //         // // 执行命令
+    //         // exec($command, $output, $return_var);
+    //         // // 检查命令是否成功执行
+    //         // if ($return_var === 0) {
+    //         //     echo "文档转换成功,已保存为无宏版本:$outputFile\n";
+    //         // } else {
+    //         //     echo "文档转换失败,返回代码:$return_var\n";
+    //         //     echo "输出:\n" . implode("\n", $output);
+    //         // }   
+    //     }
+    //     if($file_type == "docx" || $file_type == "doc"){
+    //         //加载现有的 Word 文档
+    //         // $phpWord = PhpOffice\PhpWord\IOFactory::load($inputFileName);
+    //         // // 保存新的 Word 文档
+
+    //         // // $newPhpWord = new PhpOffice\PhpWord\PhpWord();
+    //         // // $newSection = $newPhpWord->addSection();
+    //         // // $newSection->addText('Hello World !');
+    //         // $writer = PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); // 使用 DOCX 格式保存
+    //         // $writer->save($outputFileName);
+    //         // //删除来源文件
+    //         // unlink($inputFileName);
+
+    //         // 使用unoconv转换文档
+    //         //$command = "unoconv -f docx --no-macro '$inputFileName' -o '$outputFileName'";
+            
+    //         // $command = "libreoffice --headless --convert-to pdf $inputFileName --outdir D:\DOC\APEXTAO\20250127";
+    //         // $output = shell_exec($command);
+ 
+    //         // if ($output) {
+    //         //     echo "文件转换成功!";
+    //         // } else {
+    //         //     echo "文件转换失败。";
+    //         // }
+
+    //         //LibreOffice 的命令行命令
+    //         $command = "soffice --headless --convert-to pdf --outdir " . dirname($outputFileName) . " " . $inputFileName;
+    //         // 执行命令
+    //         exec($command." 2>&1", $output, $return_var);
+    //         // 检查命令是否成功执行
+    //         if ($return_var === 0) {
+    //             echo "文档转换成功,已保存为无宏版本:$outputFile\n";
+    //         } else {
+    //             echo "文档转换失败,返回代码:$return_var\n";
+    //             echo "输出:\n" . implode("\n", $output);
+    //         }  
+
+            
+    //         // 移除宏的命令
+    //         //$command = "soffice --convert-to docx:writer_pdf_Export --infilter=MS Word 97 --outdir /path/to/output $inputFileName";
+    //         //exec($command);
+            
+    //         // 复制无宏的文档到新位置
+    //         //copy("/path/to/output/document.pdf", $outputFileName);
+    //     }
+    // }
+
 
-    // public static function hasMacro2($filename){
-    //     require 'D:\code\php\Customer_Service_Online\thirdparty_vendors\vendor\autoload.php';
-    //     require 'vendor/autoload.php';
-    //     $ole = new PhpOffice\PhpSpreadsheet\Shared\OLE($filename);
-    //     if ($ole->isFile('vbaProject.bin')) {
-    //         return true;
+    // public static function hasMacros($filePath) {
+    //     $extension = pathinfo($filePath, PATHINFO_EXTENSION);
+    //     if ($extension === 'xlsx') {
+    //         // 检查 .xlsx 文件
+    //         $zip = new ZipArchive();
+    //         if ($zip->open($filePath) === TRUE) {
+    //             // 检查是否存在 vbaProject.bin 文件
+    //             $hasMacros = $zip->locateName('xl/vbaProject.bin') !== false;
+    //             $zip->close();
+    //             return $hasMacros;
+    //         } else {
+    //             return false; // 无法打开文件
+    //         }
+    //     } elseif ($extension === 'docx') {
+    //         // 检查 .docx 文件
+    //         $zip = new ZipArchive();
+    //         if ($zip->open($filePath) === TRUE) {
+    //             // 检查是否存在 vbaProject.bin 文件
+    //             $hasMacros = $zip->locateName('word/vbaProject.bin') !== false;
+    //             $zip->close();
+    //             return $hasMacros;
+    //         } else {
+    //             return false; // 无法打开文件
+    //         }
+    //     } else {
+    //         return false; // 不是支持的文件类型
+    //     }
+    // }
+    //$command = "soffice --headless --convert-to pdf --outdir " . dirname($outputFileName) . " " . $inputFileName;
+
+    // public static function checkExcelMacros($filePath,$file_name) {
+    //     // Construct the command to execute LibreOffice in headless mode.
+    //     // Replace with the actual path to your LibreOffice executable if needed.
+    //     $libreofficePath = '"C:\Program Files\LibreOffice\program\soffice.exe"'; // Example path, adjust as needed.
+    //     //$command = "$libreofficePath --headless --convert-to txt:Text -o /tmp/output.txt \"$filePath\"";
+    //     $command = "$libreofficePath --headless --convert-to txt --outdir " . dirname($filePath) . " " . $filePath;
+    //     $convert_file = dirname($filePath)."\\".$file_name.".txt";
+    //     // Execute the command.
+    //     exec($command, $output, $returnCode);
+    
+    //     // Check for errors.
+    //     if ($returnCode !== 0) {
+    //         return "Error converting file: " . implode("\n", $output); // Or handle the error as needed.
+    //     }
+    
+    //     // Read the (now text) representation of the file. We do this because the macro information is sometimes embedded in the file structure in a way that directly parsing the spreadsheet file is very difficult.
+    //     $textFile = file_get_contents($convert_file);
+    
+    //     // Clean up the temporary file (important!).
+    //     //unlink($convert_file);
+    
+    //     // Search for indicators of macros.  These are not foolproof, but they are a good start.
+    //     // More sophisticated methods might involve inspecting the file's internal structure.
+    //     // Look for VBA project stream.
+    //     if (strpos($textFile, "VBA Project") !== false || strpos($textFile, "PROJECT") !== false || strpos($textFile, "ThisDocument") !== false || strpos($textFile, "Module") !== false || strpos($textFile, "Sub ") !== false || strpos($textFile, "Function ") !== false) {  // Common macro indicators
+    //         return true; // Macros found.
     //     } else {
-    //         return false;
+    //         return false; // No clear macro indicators found.
     //     }
     // }
 }