ShuanghongS 10 mēneši atpakaļ
vecāks
revīzija
13ed78c9e8
4 mainītis faili ar 386 papildinājumiem un 46 dzēšanām
  1. 5 0
      include.ini.php
  2. 290 46
      service/ocean_order.class.php
  3. 10 0
      utils/common.class.php
  4. 81 0
      utils/utils.class.php

+ 5 - 0
include.ini.php

@@ -21,6 +21,11 @@ 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);
+
 if (preg_match("/(bot|crawl|spider|slurp)/i", $_SERVER['HTTP_USER_AGENT'])) {
     header('HTTP/1.1 403 Forbidden');
     exit;

+ 290 - 46
service/ocean_order.class.php

@@ -91,6 +91,7 @@ class ocean_order {
         * document upload
         */
         if ($operate == "document_upload"){
+            //只查询public,两边数据一样,不用去同步更新新加的Client_Upload ,Notify Station,Auto-sync to Station
             $transport_mode = $_POST['transport_mode'];
             if($transport_mode == 'sea'){
                 $document = _getViewDocType($_REQUEST["_schemas"]);
@@ -108,10 +109,10 @@ class ocean_order {
             }
             $file_serial_nos = implode(';',$file_serial_nos);
             if($transport_mode == 'sea'){
-                $sql = "select display_name,format_name as file_type,serial_no,m_h from ra_online_file_format where lower(serial_no) " . common::getInNotInSql($file_serial_nos) . " 
+                $sql = "select display_name,format_name as file_type,serial_no,m_h from public.ra_online_file_format where lower(serial_no) " . common::getInNotInSql($file_serial_nos) . " 
                         and active = true and client_upload = true";
             }else{
-                $sql = "select display_name,format_name as file_type,serial_no,m_h from air_file_format where lower(serial_no) " . common::getInNotInSql($file_serial_nos) . " 
+                $sql = "select display_name,format_name as file_type,serial_no,m_h from public.air_file_format where lower(serial_no) " . common::getInNotInSql($file_serial_nos) . " 
                     and active = true and client_upload = true";
             }
             $display_name = common::excuteListSql($sql);
@@ -127,54 +128,292 @@ class ocean_order {
             $_schemas = $_REQUEST["_schemas"];
             $transport_mode = $_POST['transport_mode'];
             $bol = $_POST['h_bol'];
-            $transport_mode = $_POST['file_type'];
             if ($transport_mode == "sea") {
-                $aaa = common::excuteObjectSql("select from_station, origin_station, destination_station from ocean where lower(h_bol) = '" . strtolower($bol) . "'");
+                $count = common::excuteObjectSql("select * from ocean where lower(h_bol) = '" . strtolower($bol) . "'");
+                
             } elseif ($transport_mode == "air") {
-                $aaa = common::excuteObjectSql("select from_station, origin_station, destination_station from air where lower(hawb) = '" . strtolower($bol) . "'");
-            }
-
-            // try {
-            //     $tmp_name = $_FILES['file']['tmp_name'];
-            //     $file_name = $_FILES['file']["name"];
-            //     $errorMsg = "";
-            //     $sql = "";
-            //     foreach ($file_name as $i => $v) {
-            //         if (empty($v)) {
-            //             continue;
-            //         }
-            //         $size = floor($_FILES ["file"]['size'][$i] / 1024 / 1024);
-            //         if ($size > 2) {
-            //             $errorMsg .= $_FILES['file']["name"][$i] . " larger than 2M.";
-            //             continue;
-            //         }
-            //         if ($_FILES["file"]["error"][$i] > 0) {
-            //             $errorMsg .= "File Upload Error(" . $_FILES ["file"]["error"][$i] . ").";
-            //             continue;
-            //         }
-    
-            //         $file_path = FILE_UPLOAD_PAHT . date("Ymd") . DS;
-            //         if (!is_dir($file_path)) {
-            //             common::mkdirs($file_path);
-            //         }
-    
-            //         $dest_file = $file_path . $path_parts['filename'] . "_" . common::uuid() . "." . $exten;
-            //         move_uploaded_file($tmp_name[$i], $dest_file);
+                $count = common::excuteObjectSql("select * from air where lower(hawb) = '" . strtolower($bol) . "'");
+            }
+            if (empty($count) || count($count) <= 0){
+                $data = array(
+                    'msg' => 'HBOL does not exist'
+                );
+                common::echo_json_encode(500,$data);
+                exit();
+            }
+
+            $file_type = $_POST['file_type'];
+            $_table =  $transport_mode == "sea" ? "ra_online_doc_upload" : "air_doc_upload";
+            $_table_format =  $transport_mode == "sea" ? "ra_online_file_format" : "air_file_format";
+            //格式配置只查询public
+            $format = common::excuteObjectSql("select serial_no,standard,client_upload,notify_station,auto_sync_to_station from public.$_table_format where format_name = '$file_type'");       
+            //查询存在的文件类型最大序号
+            $num = common::excuteOneSql("select count(*) from $_table where lower(bol) = '" . strtolower($bol) . "' and  format_serailno = '".$format['serial_no']."'");
+            try {
+                $allow_extend = "|.pdf|.xls|.xlsx|.doc|.docx|";
+                $file_name = $_FILES['file']["name"];
+                $errorMsg = "";
+                $sql = "";
+                
+                foreach ($file_name as $i => $v) {
+                    if (empty($v)) {
+                        continue;
+                    }
+                    $size = floor($_FILES ["file"]['size'][$i] / 1024 / 1024);
+                    if ($size > 2) {
+                        $errorMsg .= $_FILES['file']["name"][$i] . " larger than 2M.";
+                        continue;
+                    }
+                    if ($_FILES["file"]["error"][$i] > 0) {
+                        $errorMsg .= "File Upload Error(" . $_FILES ["file"]["error"][$i] . ").";
+                        continue;
+                    }
+                    $path_parts = pathinfo($file_name[$i]);
+                    $exten = $path_parts['extension'];
+                    if (stristr($allow_extend, "|." . $exten . "|") === FALSE) {
+                        $errorMsg .= 'Only can upload PDF/Excel/Doc/TXT/JPG/png/tif file.<br>';
+                    }
+
+                    //$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";
+                   
+                    $origin_station = $count["origin_station"];
+                    $destination_station = $count["destination_station"];
+
+                    $format_serialno = $format['serial_no'];
+                    $serial_no = utils::uuid();
+
+                    $from_station = $count["from_station"];
+                    if (strtolower($_schemas) == "public") {
+                        if ($transport_mode == "sea")
+                            $folder = DOCUMENT_OCEAN_UPLOAD_PATH . $from_station;
+                        elseif ($transport_mode == "air")
+                            $folder = DOCUMENT_AIR_UPLOAD_PATH . $from_station;
+                    }else {
+                        if ($transport_mode == "sea")
+                            $folder = DOCUMENT_SFSOCEAN_UPLOAD_PATH . $from_station;
+                        elseif ($transport_mode == "air")
+                            $folder = DOCUMENT_SFSAIR_UPLOAD_PATH . $from_station;
+                    }
     
-            //         $sql .= "INSERT INTO public.packing_attachment_list(serial_no, att_type,file_type, created_by, created_time, filename, sourcefilename, notes) VALUES "
-            //                 . "('$serial_no', 'EBooking','" . common::check_input($file_type[$i]) . "', '" . _getLoginName() . "', now(), '" . common::check_input($v) . "', '"
-            //                 . common::check_input($dest_file) . "', '" . common::check_input($file_note[$i]) . "');";
-            //     }
-            //     if (!empty($errorMsg)) {
-            //         $this->echoJson(array('status' => 'Failed', 'msg' => "Save Booking Failed $errorMsg"));
-            //     }
-            //    common::excuteUpdateSqlThrow($sql);
-            //    exit(json_encode("success"));
-            // } catch (Exception $e) {
-            //     error_log($e->getTraceAsString());
-            //     $this->echoJson(array('status' => 'Failed', 'msg' => "Save Booking Failed:Upload Filed Failed."));
-            // }
+                    $save_path = $folder . DS . date("Ymd") . DS;
+                    if (common::mkdirs($save_path) === FALSE){
+                        $errorMsg .= "Save folder create error";
+                    }
+                    $ppp =  $_FILES['file']['tmp_name'];
+                    $sss = $save_path . $filename;
+                    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) . "');";
+                    }
+                    //根据配置,看需要同步文件
+                    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)
+                                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)
+                                VALUES ('".$serial_no."', '" .common::check_input($origin_station) . "', now());";
+                        }
+                        if($format['auto_sync_to_station'] == "Origin and Destination Stations"){
+                            //这个都同步,不需要手动补充记录去阻止文件的同步
+                        }
+                    }
+                    
+                }
+                //根据配置发送通知邮件 相同文件类型只提醒一次
+                if(!empty($format['notify_station'])){
+                    $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");
+                    $ks_to = common::excuteOneSql("select ksmart_station from public.contract_region_mapping where overeas = '".$count["destination_station"]."' limit 1");
+                    $ks_from = empty($ks_from)? 'f' : $ks_from;
+                    $ks_from = 't';
+                    $ks_to = empty($ks_to)? 'f' : $ks_to;
+                    
+                    $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");
+                    $subject = "External Documentation Upload Notification"."_".$curr_date_config['d1_day'];
+                    $email_from = "US.KApex.Online@kerryapex.com";
+                    $upload_user_name = _getLoginName();
+                    $upload_user_email = _getLoginEamil();
+                    //如果有多個就留空,給Email信息就行
+                    if ($transport_mode == "sea") {
+                        $company =utils::getConpanyForNotify($_schemas,'ocean');  
+                    }else{
+                        $company =utils::getConpanyForNotify($_schemas,'air');
+                    }
 
+                    //Ksmart--> Ksmart
+                    if ($ks_from == "t" && $ks_to == "t"){
+                        if($format['notify_station'] == "Origin Station" || $format['notify_station'] == "Origin and Destination Stations"){
+                            if(!empty($origin_op_email)){
+                                //立即发送
+                                $content = utils::getKlnDocNotifyContent($bol,$file_type,$upload_user_name,$upload_user_email,$company,$curr_date_config['d2_day']);
+                                $sql .= "INSERT INTO email_record(type, title, from_email, to_email, content, insert_date, cc_email, attachment_path)
+                                    VALUES ('KLN_DOC_Notify', '" . pg_escape_string($subject) . "', '" . pg_escape_string($email_from) . "', '" .
+                                    pg_escape_string($origin_op_email) . "', '" . pg_escape_string($content) . "', now(), '', '');";
+                            }else{
+                                //加入队列状态
+                                $sql .=  "INSERT INTO public.kln_online_upload_file_notify(h_bol, file_type, upload_by, upload_time, email, company, 
+                                            is_send, checked_time, checked_type,origin_op,dest_op)
+                                    VALUES ('$bol','$file_type','$upload_user_name', now(),'$upload_user_email', '$company', 
+                                            false, now(), 'origin_op_email','".$count["origin_op_id"]."','".$count["dest_op"]."');";
+                                //做好加入队列时的日志记录
+                                $user_type = _isApexLogin() ? "Employee" : "Customer";
+                                $detail = $bol.": $file_type File upload,origin_op_email is null, Add Notification wait";       
+                                utils::single_operation_log_save($user_type,$upload_user_name,"Tracking","upload_file_pending",$detail);            
+                            }
+                        }
+                        if($format['notify_station'] == "Destination Station" || $format['notify_station'] == "Origin and Destination Stations"){
+                            if(!empty($dest_op_email)){
+                                //立即发送
+                                $content = utils::getKlnDocNotifyContent($bol,$file_type,$upload_user_name,$upload_user_email,$company,$curr_date_config['d2_day']);
+                                $sql .= "INSERT INTO email_record(type, title, from_email, to_email, content, insert_date, cc_email, attachment_path)
+                                    VALUES ('KLN_DOC_Notify', '" . pg_escape_string($subject) . "', '" . pg_escape_string($email_from) . "', '" .
+                                    pg_escape_string($dest_op_email) . "', '" . pg_escape_string($content) . "', now(), '', '');";
+                            }else{
+                                //加入队列状态
+                                $sql .=  "INSERT INTO public.kln_online_upload_file_notify(h_bol, file_type, upload_by, upload_time, email, company, 
+                                            is_send, checked_time, checked_type,origin_op,dest_op)
+                                    VALUES ('$bol','$file_type','$upload_user_name', now(),'$upload_user_email', '$company', 
+                                            false, now(), 'dest_op_email','".$count["origin_op_id"]."','".$count["dest_op"]."');";
+                                //做好加入队列时的日志记录
+                                $user_type = _isApexLogin() ? "Employee" : "Customer";
+                                $detail = $bol.": $file_type File upload,dest_op_email is null, Add Notification wait";       
+                                utils::single_operation_log_save($user_type,$upload_user_name,"Tracking","upload_file_pending",$detail);            
+                            }
+                        }
+                    }
+
+                    //Ksmart-->non Ksmart
+                    if ($ks_from == "t" && $ks_to == "f"){
+                        if($format['notify_station'] == "Destination Station" || $format['notify_station'] == "Origin and Destination Stations"){
+                            //避免重复邮件发给origin_op,  dest_op信息缺失的话,会发送给origin_op
+                            $dest_op_email_temp = empty($dest_op_email)? $origin_op_email:$dest_op_email;
+                            if(!empty($dest_op_email_temp)){
+                                //立即发送
+                                $content = utils::getKlnDocNotifyContent($bol,$file_type,$upload_user_name,$upload_user_email,$company,$curr_date_config['d2_day']);
+                                $sql .= "INSERT INTO email_record(type, title, from_email, to_email, content, insert_date, cc_email, attachment_path)
+                                    VALUES ('KLN_DOC_Notify', '" . pg_escape_string($subject) . "', '" . pg_escape_string($email_from) . "', '" .
+                                    pg_escape_string($dest_op_email_temp) . "', '" . pg_escape_string($content) . "', now(), '', '');";
+                            }else{
+                                //加入队列状态 如果缺失,用origin_op_email
+                                $sql .=  "INSERT INTO public.kln_online_upload_file_notify(h_bol, file_type, upload_by, upload_time, email, company, 
+                                            is_send, checked_time, checked_type,origin_op,dest_op)
+                                    VALUES ('$bol','$file_type','$upload_user_name', now(),'$upload_user_email', '$company', 
+                                            false, now(), 'origin_op_email','".$count["origin_op_id"]."','".$count["dest_op"]."');";
+                                //做好加入队列时的日志记录
+                                $user_type = _isApexLogin() ? "Employee" : "Customer";
+                                $detail = $bol.": $file_type File upload,origin_op_email is null, Add Notification wait";       
+                                utils::single_operation_log_save($user_type,$upload_user_name,"Tracking","upload_file_pending",$detail);             
+                            }
+                        }
+
+                        if($format['notify_station'] == "Origin Station" || $format['notify_station'] == "Origin and Destination Stations"){
+                            if(empty($dest_op_email) && $format['notify_station'] == "Origin and Destination Stations"){
+
+                            }else{
+                            if(!empty($origin_op_email)){
+                                //立即发送
+                                $content = utils::getKlnDocNotifyContent($bol,$file_type,$upload_user_name,$upload_user_email,$company,$curr_date_config['d2_day']);
+                                $sql .= "INSERT INTO email_record(type, title, from_email, to_email, content, insert_date, cc_email, attachment_path)
+                                    VALUES ('KLN_DOC_Notify', '" . pg_escape_string($subject) . "', '" . pg_escape_string($email_from) . "', '" .
+                                    pg_escape_string($origin_op_email) . "', '" . pg_escape_string($content) . "', now(), '', '');";
+                            }else{
+                                //加入队列状态
+                                $sql .=  "INSERT INTO public.kln_online_upload_file_notify(h_bol, file_type, upload_by, upload_time, email, company, 
+                                            is_send, checked_time, checked_type,origin_op,dest_op)
+                                    VALUES ('$bol','$file_type','$upload_user_name', now(),'$upload_user_email', '$company', 
+                                            false, now(), 'origin_op_email','".$count["origin_op_id"]."','".$count["dest_op"]."');";
+                                //做好加入队列时的日志记录
+                                $user_type = _isApexLogin() ? "Employee" : "Customer";
+                                $detail = $bol.": $file_type File upload,origin_op_email is null, Add Notification wait";       
+                                utils::single_operation_log_save($user_type,$upload_user_name,"Tracking","upload_file_pending",$detail);            
+                            }
+                            }
+                        }
+                    }
+
+                    //Non Ksmart-->Ksmart
+                    if ($ks_from == "f" && $ks_to == "t"){
+                        if($format['notify_station'] == "Origin Station" || $format['notify_station'] == "Origin and Destination Stations"){
+                            $origin_op_email_temp = empty($origin_op_email)? $dest_op_email:$origin_op_email;
+                            if(!empty($origin_op_email_temp)){
+                                //立即发送
+                                $content = utils::getKlnDocNotifyContent($bol,$file_type,$upload_user_name,$upload_user_email,$company,$curr_date_config['d2_day']);
+                                $sql .= "INSERT INTO email_record(type, title, from_email, to_email, content, insert_date, cc_email, attachment_path)
+                                    VALUES ('KLN_DOC_Notify', '" . pg_escape_string($subject) . "', '" . pg_escape_string($email_from) . "', '" .
+                                    pg_escape_string($origin_op_email_temp) . "', '" . pg_escape_string($content) . "', now(), '', '');";
+                            }else{
+                                //加入队列状态
+                                $sql .=  "INSERT INTO public.kln_online_upload_file_notify(h_bol, file_type, upload_by, upload_time, email, company, 
+                                            is_send, checked_time, checked_type,origin_op,dest_op)
+                                    VALUES ('$bol','$file_type','$upload_user_name', now(),'$upload_user_email', '$company', 
+                                            false, now(), 'dest_op_email','".$count["origin_op_id"]."','".$count["dest_op"]."');";
+                                //做好加入队列时的日志记录
+                                $user_type = _isApexLogin() ? "Employee" : "Customer";
+                                $detail = $bol.": $file_type File upload,dest_op_email is null, Add Notification wait";       
+                                utils::single_operation_log_save($user_type,$upload_user_name,"Tracking","upload_file_pending",$detail);             
+
+                            }
+                        }
+                        if($format['notify_station'] == "Destination Station" || $format['notify_station'] == "Origin and Destination Stations"){
+                            //避免重复邮件发给dest_op,  origin_op信息缺失的话,会发送给dest_op
+                            if(empty($origin_op_email) && $format['notify_station'] == "Origin and Destination Stations"){
+
+                            }else{
+                            if(!empty($dest_op_email)){
+                                //立即发送
+                                $content = utils::getKlnDocNotifyContent($bol,$file_type,$upload_user_name,$upload_user_email,$company,$curr_date_config['d2_day']);
+                                $sql .= "INSERT INTO email_record(type, title, from_email, to_email, content, insert_date, cc_email, attachment_path)
+                                    VALUES ('KLN_DOC_Notify', '" . pg_escape_string($subject) . "', '" . pg_escape_string($email_from) . "', '" .
+                                    pg_escape_string($dest_op_email) . "', '" . pg_escape_string($content) . "', now(), '', '');";
+                            }else{
+                                //加入队列状态
+                                $sql .=  "INSERT INTO public.kln_online_upload_file_notify(h_bol, file_type, upload_by, upload_time, email, company, 
+                                            is_send, checked_time, checked_type,origin_op,dest_op)
+                                    VALUES ('$bol','$file_type','$upload_user_name', now(),'$upload_user_email', '$company', 
+                                            false, now(), 'dest_op_email','".$count["origin_op_id"]."','".$count["dest_op"]."');";
+                                //做好加入队列时的日志记录
+                                $user_type = _isApexLogin() ? "Employee" : "Customer";
+                                $detail = $bol.": $file_type File upload,dest_op_email is null, Add Notification wait";       
+                                utils::single_operation_log_save($user_type,$upload_user_name,"Tracking","upload_file_pending",$detail);           
+                            }
+                            }
+                        }
+                    }
+
+                }
+
+                if (!empty($errorMsg)) {
+                    $data = array(
+                        'msg' => "Save Failed $errorMsg"
+                    );
+                    common::echo_json_encode(500,$data);
+                    exit();
+                }
+                common::excuteUpdateSql($sql);
+                $data = array(
+                    'msg' => "success"
+                );
+                common::echo_json_encode(200,$data);
+                exit();
+            } catch (Exception $e) {
+                error_log($e->getTraceAsString());
+                $data = array(
+                    'msg' => "Save Booking Failed:Upload Filed Failed."
+                );
+                common::echo_json_encode(500,$data);
+            }
         }
 
         if ($operate == "save_communication") {
@@ -2024,5 +2263,10 @@ class ocean_order {
         $data['marksAndDescription'] = $marksAndDescription;
         return $data;    
     }
+
+    private function getUploadFolder() {
+        $sql = "SELECT ra_value from ra_online_config where lower(ra_name) = 'upload_document'";
+        return common::excuteOneSql($sql);
+    }
 }
 ?>

+ 10 - 0
utils/common.class.php

@@ -1969,5 +1969,15 @@ class common {
     }
 
 
+    /*
+     *  Create Directory
+    */
+    public static function mkdirs($path, $mode = 0777) { //creates directory tree recursively
+        if (!file_exists($path)) {
+            if (!mkdir($path, $mode, TRUE))
+                return FALSE;
+        }
+        return TRUE;
+    }
 }
 ?>

+ 81 - 0
utils/utils.class.php

@@ -425,6 +425,8 @@ class utils {
             "ocean_order=ocean_vgm" => array("page" =>"Tracking","operate"=>"Enter VGM"),
             "ocean_order=save_ocean_vgm" => array("page" =>"Tracking","operate"=>"Save VGM"),
             "ocean_order=share_shipment" => array("page" =>"Tracking","operate"=>"Share shipment"),
+            "ocean_order=document_upload" => array("page" =>"Tracking","operate"=>"document_upload"),
+            "ocean_order=document_upload_do" => array("page" =>"Tracking","operate"=>"document_upload_do"),
 
             "tools=mark_save" => array("page" =>"Tools","operate"=>"Mark_Save"),
             "password=" => array("page" =>"Profile","operate"=>"Change password"));
@@ -542,6 +544,12 @@ class utils {
                 $detail = "Tracking Detail Attachment Download: $display_name";
             }
         }
+
+        //Tracking詳情頁Upload Files(顯示file名稱)
+        if(($action == "ocean_order") && $operate == "document_upload"){
+            $detail = "Enter Upload Files page";
+        }
+        
         return $detail;
 
     }
@@ -601,6 +609,79 @@ class utils {
         return $flag;
     }
 
+    public static function getConpanyForNotify($_schemas,$type){
+        //如果有多個就留空
+        $company = "";
+        if($type == 'ocean'){
+            $company = $_SESSION['ONLINE_USER']['company_name'];
+            $company_arr =  explode(";",$company);
+            $temp = array();
+            foreach($company_arr as $v){
+                if(!empty($v)){
+                    $temp[] = $v;
+                }
+            }
+            if(count($temp) <= 1){
+                return $company;
+            }
+        }
+        if($type == 'air'){
+            $company_id =  $_SESSION['ONLINE_USER']['air_customers']; 
+            $company_id_arr =  explode(";",$company_id);
+            $temp = array();
+            foreach($company_id_arr as $v){
+                if(!empty($v)){
+                    $temp[] = $v;
+                }
+            }
+            if(count($temp) == 1){
+                if ($_schemas == "public") {//apex ocean和air 分开
+                    $sql = "SELECT company  from ocean.contacts where contact_id = '" . common::check_input($temp[0]) . "' ";
+                } else {
+                    $sql = "SELECT company  from $_schemas.contacts where contact_id = '" . common::check_input($temp[0]) . "' ";
+                }
+                $company = common::excuteOneSql($sql);
+            }
+            return $company;
+        }
+    }
+
+
+    public static function getKlnDocNotifyContent($bol,$file_type,$upload_user_name,$upload_user_email,$company,$date_time){
+        $report_setting = common::excuteObjectSql("select * from ra_online_auto_report_config where report_type = 'KLN_DOC_Notify' ");
+        $report_content = $report_setting['report_content'];
+        $columns = common::excuteListSql("select display_name,model_name,database_column_name,excel_width,order_by from public.ra_online_search_display_cso where model_name = 'KLN_DOC_Notify'");
+        $missing_packing_th = "<tr>";
+        foreach ($columns as $colk => $colvalue) {
+                $missing_packing_th.='<td style="width:'.$colvalue['excel_width'].'pt;border:solid black 1.0pt;background:#1F4E78;padding:0cm 5.4pt 0cm 5.4pt;height:14.25pt">
+                                        <p class="MsoNormal" align="left" style="text-align:left"><b><span lang="EN-US" style="font-size:8.0pt;font-family:&quot;Arial&quot;,sans-serif;color:white">'.$colvalue['display_name'].'</span></b></p>
+                            </td>';      
+        }
+        $missing_packing_th .= "</tr>";
+        $report_content = str_replace('<{missing_packing_th}>', $missing_packing_th, $report_content);
+        
+        $data = array(array("h_bol"=>$bol,"file_type"=>$file_type,"upload_by"=>$upload_user_name,"email"=>$upload_user_email,"company"=>$company,"upload_time"=>$date_time."(US/Pacific)"));
+        $missing_packing_tr = "";
+        foreach ($data as $rk => $rv) {
+            $missing_packing_tr .= "<tr>";
+            foreach ($columns as $ck => $cv) {
+                if(utils::endWith($cv['display_name'], "email")){
+                    $missing_packing_tr.='<td style="font-size:8.0pt;font-family:&quot;Arial&quot;,sans-serif;color:black;border-top:none;
+                        border-left:none;border-bottom:solid black 1.0pt;border-right:solid black 1.0pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.25pt">
+                            <a href="mailto:'.$rv[$cv['database_column_name']].'">'.$rv[$cv['database_column_name']].'</a>
+                    </td>';
+                }else{
+                    $missing_packing_tr.='<td  style="font-size:8.0pt;font-family:&quot;Arial&quot;,sans-serif;color:black;'
+                        . 'border-top:none;border-left:none;border-bottom:solid black 1.0pt;border-right:solid black 1.0pt;padding:0cm 5.4pt 0cm 5.4pt;height:14.25pt">'.$rv[$cv['database_column_name']].'</td>';
+                }
+            }
+            $missing_packing_tr .= "</tr>";
+        }
+        $report_content = str_replace('<{missing_packing_tr}>', $missing_packing_tr, $report_content);
+        return $report_content;
+    }
+    
+
     public static function _getSql($ids, $type,$shipment_mode,$sqlWhere) {
         $ids_arr = explode(',', $ids);
         $sql = "";