| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099 |
- <?php
- if (!defined('IN_ONLINE')) {
- exit('Access Denied');
- }
- /**
- * Description of utilsclass
- *
- * @author Administrator
- */
- class utils {
- public static function checkPassword($password,$rule="",$user_login="") {
- $str ="";
- if (!empty($rule)) {
- //是否校验大小写
- if (!empty($rule["hasOneUpperChar"])&&$rule["hasOneUpperChar"]) {
- if (!preg_match('/[A-Z]/',$password)) {
- $str ="Password must contain uppercase letters";
- }
- }
- //是否校验小写
- if (!empty($rule["hasOneLowerChar"])&&$rule["hasOneLowerChar"]) {
- if (!preg_match('/[a-z]/',$password)) {
- $str ="Password must contain lowercase letters";
- }
- }
- //是否存在数字
- if (!empty($rule["hasOneNumberChar"])&&$rule["hasOneNumberChar"]) {
- if (!preg_match('/[0-9]/',$password)) {
- $str ="Password must contain numbers";
- }
- }
- $sql = "select user_type from ra_online_user_roles_rel where upper(user_login)=upper('".$user_login."') and exists(select count(0) from ra_online_user where upper(user_login)=upper('".$user_login."') and is_desktop=true) order by id desc limit 1;";
- $user_type = common::excuteOneSql($sql);
- if (!empty($user_type)&&$user_type=="Super User") {
- if (strlen($password)<$rule["SuperMinLen"]||strlen($password)>$rule["SuperMaxLen"]) {
- $str ="Super user password length between ".$rule["SuperMinLen"]." and ".$rule["SuperMaxLen"];
- }
- }else{
- //校验密码长度
- if (strlen($password)<$rule["MinLen"]||strlen($password)>$rule["MaxLen"]) {
- $str ="Password length between ".$rule["MinLen"]." and ".$rule["MaxLen"];
- }
- }
- return $str;
- }else{
- if (preg_match('/^\d*$/', $password) || preg_match('/^[a-zA-Z]+$/', $password)) {
- $str ="Must include letters and numbers";
- }
- $len = strlen($password);
- $t = substr($password, 0, 1);
- for ($i = 1; $i < $len; $i++) {
- $t1 = substr($password, $i, 1);
- if ($t != $t1) {
- return "";
- }
- }
- return "error";
- }
- }
- //隐藏邮箱地址
- public static function maskEmail($email) {
- $idex = strlen($email) - strrpos($email, ".");
- $mask = substr($email, 0, 1) . str_repeat('*', 6) . "@" . str_repeat('*', 3) . substr($email, -$idex);
- return $mask;
- }
- public static function getInSql($str, $not = false, $sep = ";") {
- $str = trim($str);
- $str = trim($str, $sep);
- $str = trim($str);
- if (empty($str) && $str !== "0" && $str !== 0)
- return "1<>1";
- $str = strtolower($str);
- if (utils::checkExist($str, $sep)) {
- $aa = explode($sep, $str);
- $msg = "";
- foreach ($aa as $value) {
- $value = trim($value);
- if (empty($value))
- continue;
- if (empty($msg))
- $msg = "'" . common::check_input($value) . "'";
- else
- $msg .= ",'" . common::check_input($value) . "'";
- }
- if ($not !== FALSE)
- return " not in (" . $msg . ")";
- else
- return " in (" . $msg . ")";
- } else {
- if ($not !== FALSE)
- return " != '" . common::check_input(trim($str)) . "'";
- else
- return " = '" . common::check_input(trim($str)) . "'";
- }
- }
- public static function checkExist($string, $search, $u = TRUE) {
- if ($u === TRUE) {
- if (stripos($string, $search) !== false)
- return TRUE;
- }else {
- if (strpos($string, $search) !== false)
- return TRUE;
- }
- return FALSE;
- }
- public static function endWith($string, $end, $u = TRUE) {
- if ($u === TRUE) {
- $string = strtolower($string);
- $end = strtolower($end);
- return strrchr($string, $end) == $end;
- }
- return strrchr($string, $end) == $end;
- }
- public static function _get($str) {
- $rs = isset($_POST[$str]) ? $_POST[$str] : null;
- if (empty($rs))
- $rs = isset($_GET[$str]) ? $_GET[$str] : null;
- return $rs;
- }
- public static function startWith($string, $start, $u = TRUE) {
- if ($u === TRUE)
- return stripos($string, $start) === 0;
- return strpos($string, $start) === 0;
- }
- public static function outDisplay($content, $is_time = 'f', $is_first = 'f', $is_boolean = 'f', $excel_export = FALSE) {
- if (empty($content) && $content !== 0 && $content !== "0")
- return "";
- if (strtolower($is_time) == 't')
- return utils::dealTimeDisplay($content);
- if (strtolower($is_first) == 't') {
- if ($excel_export !== FALSE)
- return utils::getCompanyName($content);
- else
- return '<span title="' . $content . '">' . utils::getCompanyName($content) . '</span>';
- }
- if (strtolower($is_boolean) == 't')
- return utils::outTrue($content);
- return nl2br($content);
- }
- public static function _output($value) {
- if (empty($value))
- return " ";
- else
- return $value;
- }
- public static function dealTimeDisplay($date) {
- if (empty($date))
- return "";
- if (strlen($date) > 10)
- return date("m/d/Y H:i:s", strtotime($date));
- return date("m/d/Y", strtotime($date));
- }
- public static function outDisplayForMerge($frist,$last,$split = "/") {
- if($frist == $last){
- return $frist;
- }
- if (!empty($frist)){
- if(!empty($last)){
- return $frist.$split.$last;
- }else{
- return $frist;
- }
- }else{
- return $last;
- }
- }
- public static function outTrue($r) {
- if (empty($r))
- return "No";
- $r = strtolower($r);
- if ($r == "t")
- return "Yes";
- elseif ($r == "f")
- return "No";
- else
- return $r;
- }
- public static function getCompanyName($detail) {
- $detail = nl2br($detail);
- if (strpos($detail, '<br />') === FALSE)
- return $detail;
- return substr($detail, 0, strpos($detail, '<br />'));
- }
- public static function getEmail($serial_no) {
- $ocean = common::excuteObjectSql("select sales_rep, last_user, created_by, order_from, h_bol, consignee, dest_op, agent from public.kln_ocean where md5(serial_no)=md5('$serial_no') "
- . "order by schem_not_display nulls last limit 1");
- $schema = $ocean["order_from"] . ".";
- $dest_op_from_agent = common::excuteOneSql("select dest_op_from_agent from " . $schema . "ocean where md5(serial_no)=md5('$serial_no')");
- if ($ocean["agent"] == "KYMTL" || $ocean["agent"] == "KYYYZ") {
- $email = array();
- $email["email"] = "";
- if (!empty($dest_op_from_agent)) {
- $so_email = common::excuteOneSql("select email from " . $schema . "employee where employee_id='" . $dest_op_from_agent . "' and active=true");
- }
- if (!empty($so_email)) {
- if (empty($email["email"])) {
- $email["email"] = $so_email;
- } else {
- $email["email"] .= ";" . $so_email;
- }
- }
- if (!empty($ocean["sales_rep"])) {
- $rep_email = common::excuteOneSql("select email from " . $schema . "employee where lower(salesopcode)='" . strtolower($ocean["sales_rep"]) . "' and active=true");
- if (!empty($rep_email)) {
- if (empty($email["email"])) {
- $email["email"] = $rep_email;
- } else {
- $email["email"] .= ";" . $rep_email;
- }
- }
- }
- } else {
- $email = common::excuteObjectSql("select string_agg(e.email, ';') as email, string_agg(e.first_name, ';') as name from " . $schema . "ra_online_user u, " . $schema . "employee e WHERE u.employee_id = e.employee_id and "
- . "lower(u.user_login) in ('" . strtolower($ocean["created_by"]) . "', '" . strtolower($ocean["last_user"]) . "')");
- if (empty($dest_op_from_agent)) {
- if (!empty($ocean["dest_op"])) {
- $so_email = common::excuteOneSql("select email from " . $schema . "employee where employee_id='" . $ocean["dest_op"] . "' and active=true");
- }
- } else {
- $so_email = common::excuteOneSql("select email from " . $schema . "employee where employee_id='" . $dest_op_from_agent . "' and active=true");
- }
- if (empty($so_email)) {
- if ($ocean["agent"] == "APEXSFO") {
- $so_email = "oid2@apexshipping.com";
- }
- if ($ocean["agent"] == "APEXLAX") {
- $so_email = "laxoid@apexshipping.com";
- }
- if ($ocean["agent"] == "APEXNYC") {
- $so_email = "NYCOID@APEXSHIPPING.COM";
- }
- if ($ocean["agent"] == "APEXPNW") {
- $so_email = "pnwoid@apexshipping.com";
- }
- if ($ocean["agent"] == "STLUTA") {
- $so_email = "starlinkOID@apexshipping.com ";
- }
- if ($ocean["agent"] == "APEXORD") {
- $so_email = "ordoid@apexshipping.com";
- }
- }
- if (!empty($so_email)) {
- if (empty($email["email"])) {
- $email["email"] = $so_email;
- } else {
- $email["email"] .= ";" . $so_email;
- }
- }
- if (!empty($ocean["sales_rep"])) {
- $rep_email = common::excuteOneSql("select email from " . $schema . "employee where lower(salesopcode)='" . strtolower($ocean["sales_rep"]) . "' and active=true");
- if (!empty($rep_email)) {
- if (empty($email["email"])) {
- $email["email"] = $rep_email;
- } else {
- $email["email"] .= ";" . $rep_email;
- }
- }
- }
- }
- $email["h_bol"] = $ocean["h_bol"];
- $email["consignee"] = $ocean["consignee"];
- return $email;
- }
- /***
- * 过滤json中的某个数据
- * @param unknown $json
- * @param unknown $search
- * @param unknown $replace
- * @return mixed
- */
- public static function jsonFiltration($search,$replace,$json){
- //处理json中将斜杠转义问题
- $json = str_replace("\\/", "/", $json);
- return str_replace($search, $replace, $json);
- }
- /*
- * calculate eta destination by etd port
- */
- public static function calculate_ETA_Des($serial_no) {
- $sql = "SELECT m_eta as eat, mport_of_discharge as poul, place_of_delivery as pod,service from ocean where lower(serial_no) = '" . strtolower($serial_no) . "'";
- $rs = common::excuteObjectSql($sql);
- $date = "";
- if (!empty($rs['eat'])) {
- $date = utils::calculate_ETA_Dest($rs['eat'], $rs['poul'], $rs['pod'], $rs['service']);
- }
- return $date;
- }
- public static function calculate_ETA_Dest($eta, $poul, $pod, $service) {
- if (empty($poul) || empty($pod))
- return $eta;
- $sql = "SELECT door_days, cy_days
- FROM eta_dest
- WHERE eta_dest.state::text = ((( SELECT unlocode.state
- FROM ports, unlocode
- WHERE ports.uncode::text = unlocode.uncode::text AND ports.code::text = '" . common::check_input($pod) . "'
- LIMIT 1))::text) AND (','::text || eta_dest.pod::text) ~~* (('%,'::text || '" . common::check_input($poul) . "') || '%'::text)
- LIMIT 1";
- //$sql = "select door_days, cy_days from eta_dest where state = (select state from ports where code = '" . common::check_input($poul) . "' limit 1) and ','||pod ilike '%," . common::check_input($pod) . "%'";
- $rs = common::excuteObjectSql($sql);
- if (empty($rs))
- return $eta;
- if (utils::endWith($service, "cy"))
- return common::addDays($eta, $rs['cy_days']);
- else
- return common::addDays($eta, $rs['door_days']);
- }
- /*
- * password change, email alert
- */
- public static function sendEmailByPassword($username, $password, $email, $companyname='') {
- $sql = "select subject, ra_content as content from ra_online_email_tpl where lower(ra_type) = 'forgotpw'";
- $rs = common::excuteObjectSql($sql);
- if (!empty($rs)) {
- $subject = $rs['subject'];
- $content = $rs['content'];
- }
- if (!empty($subject) && !empty($content)) {
- $content = str_replace('<{username}>', $username, $content);
- $content = str_replace('<{password}>', $password, $content);
- $content = str_replace('<{companyname}>', $companyname, $content);
- global $db;
- common::excuteUpdateSql("INSERT INTO public.email_record_forgotpassword(type, title, from_email, to_email, content, insert_date,
- cc_email) VALUES ('forgot_password', '" . common::check_input($subject) . "', 'US.KApex.Online@kerryapex.com', '" .
- common::check_input($email) . "', '" . common::check_input($content) . "', now(), '');");
- return "success";
- //return Mail::sendMail($email, $subject, $content);
- } else
- return null;
- }
- public static function operation_log_records(){
- //排除opreation_log操作
- if( empty($_REQUEST["operate"])
- || ($_REQUEST["action"] == "login" && $_REQUEST["operate"] == "verifcation_code")
- || ($_REQUEST["action"] == "login" && $_REQUEST["operate"] == "check_uname")
- || ($_REQUEST["action"] == "ocean_order" && $_REQUEST["operate"] == "setting_ocean_order_display")
- || ($_REQUEST["action"] == "ocean_booking" && $_REQUEST["operate"] == "setting_display")){
- return;
- }
- if($_REQUEST["action"] == "login" && $_REQUEST["operate"] == "tracking_checked"){
- //public tracking_checked 的user name 记录对应IP 地址
- $user_type = "Customer";
- $user_name = common::ip();
- } elseif($_REQUEST["action"] == "login" && $_REQUEST["operate"] == "do_login"){
- //移除do_login 因为在登录的过程中,是没有用户信息的
- $user_name = $_REQUEST["uname"];
- } else{
- $user_name = _getLoginName();
- }
- $user_type = _isApexLogin() ? "Employee" : "Customer";
- //如果在没有登录前,没有登录信息,指定用户
- if(!isset($_SESSION['ONLINE_USER'])){
- $user_type = common::excuteOneSql("select user_type from public.ra_online_user u where lower(user_login) = '" . strtolower($user_name) . "'");
- }
-
- $operateInfo = utils::getPageByAction($_REQUEST["action"],$_REQUEST["operate"]);
- $page = $operateInfo["page"];
- $operation = $operateInfo["operate"];
- $operation_detail = utils::analyzeOperationDetail($_REQUEST["action"],$_REQUEST["operate"]);
- if(empty($operation_detail)){
- $operation_detail = common::check_input(utils::jsonFiltration("null", "\"\"", json_encode($_REQUEST)));
- }
- //过滤一分钟以内,相同用户的重复请求
- $exist_sql = "select count(1) from public.customer_service_operation_log
- where user_name = '$user_name'
- and page = '$page' and operation = '$operation' and operation_detail = '$operation_detail'
- and operation_time > NOW() - INTERVAL '1 minute' limit 1;";
- $exist_obj = common::excuteOneSql($exist_sql);
- if(empty($exist_obj)){
- $sql = "INSERT INTO public.customer_service_operation_log(user_type, user_name, page, operation, operation_detail,
- operation_time)
- VALUES ('$user_type', '$user_name', '$page', '$operation', '$operation_detail', now())";
- common::excuteUpdateSql($sql);
- }
- }
- public static function getPageByAction($action,$operate){
- //取消
- $operationConvertName = array(
- "login=do_login" => array("page" =>"Login","operate"=>"Login"),
- "login=forgot_password" => array("page" =>"Login","operate"=>"Forgot_PPassword"),
- "login=logout" => array("page" =>"logout","operate"=>"logout"),
- "login=update_pwd_expires" => array("page" =>"Login","operate"=>"Reset password"),
- "ocean_booking=search" => array("page" =>"Booking","operate"=>"Search"),
- "Booking_Search=save_setting_display" => array("page" =>"Booking","operate"=>"Customize Coulumns"),
- "booking=autody" => array("page" =>"Booking","operate"=>"More Filter"),
- "booking=autoport" => array("page" =>"Booking","operate"=>"More Filter"),
- "ocean_booking=detail" => array("page" =>"Booking","operate"=>"Open Detailed Page"),
- "ocean_booking=excel" => array("page" =>"Booking","operate"=>"Download"),
- "ocean_booking=save_communication" => array("page" =>"Booking","operate"=>"Send Email"),
- "opreation_log=search" => array("page" =>"Opreation_log","operate"=>"Search"),
- "login=tracking_checked" => array("page" =>"Tracking","operate"=>"Public tracking"),
- "ocean_order=search" => array("page" =>"Tracking","operate"=>"Search"),
- "Ocean_Search=save_setting_display" => array("page" =>"Tracking","operate"=>"Customize Coulumns"),
- "tracking=autody" => array("page" =>"Tracking","operate"=>"More Filter"),
- "tracking=autoport" => array("page" =>"Tracking","operate"=>"More Filter"),
- "ocean_order=detail" => array("page" =>"Tracking","operate"=>"Open Detailed Page"),
- "ocean_order=excel" => array("page" =>"Tracking","operate"=>"Download"),
- "ocean_order=download" => array("page" =>"Tracking","operate"=>"Download"),
- "ocean_order=save_communication" => array("page" =>"Booking","operate"=>"Send Email"),
- "ocean_order=ams_isf_log" => array("page" =>"Tracking","operate"=>"AMS/ISF"),
- "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"));
- if($action == "ajax" && $operate == "save_setting_display"){
- $model_name = $_REQUEST['model_name'];
- return $operationConvertName[$model_name."=".$operate];
- }
- if($action == "ajax" && ($operate == "autody" || $operate == "autoport")){
- $model_name = $_REQUEST['search_mode'];
- return $operationConvertName[$model_name."=".$operate];
- }
- return $operationConvertName[$action."=".$operate];
- }
- public static function analyzeOperationDetail($action,$operate){
- if($action == "login" && $operate == "do_login"){
- $detail = 'System Account';
- if($_REQUEST['token']){
- $detail = 'From Apex Online';
- }
- }
- if($action == "login" && $operate == "logout"){
- $detail = 'User Logout';
- }
- if($action == "login" && $operate == "tracking_checked"){
- $detail = 'Join public tracking action,Public tracking number:'.$_POST['reference_number'];
- }
- if($action == "password"){
- $detail = 'User Change password';
- }
- if(($action == "ocean_booking" || $action == "ocean_order") && $operate == "search"){
- $detail = "";
- //还有一个同以分钟内,不记录相同的查询 这个需要建表查询
- //{"action":"ocean_booking","operate":"search","_ntype":"ocean_booking","cp":"1","ps":"100","rc":"-1","other_filed":"","uname":"ra.admin","psw":"abc123456789"}
- $filter_common_field = array("action","operate","_ntype","cp","ps","rc","other_filed","uname","psw");
- foreach($_REQUEST as $selected_key => $selected){
- if(!utils::in_array($selected_key, $filter_common_field)){
- if(is_array($selected)){
- $selected = utils::implode(",",$selected);
- }
- $detail .="$selected_key:".$selected."; ";
- }
- }
- if(empty($detail)){
- $detail .="No search condition";
- }
- }
- if($action == "ajax" && $operate == "save_setting_display"){
- $detail = "";
- $type = $_REQUEST['model_name'] == "Booking_Search" ? "Booking_Search" : "Ocean_Search";
- //记录最终save 和 default 字段相比的结果
- // $default_ids = common::excuteListSql("select id,display_name from public.ra_online_search_display_cso where model_name = '$type'
- // and display_name in('Booking No.','MBL No.','HBL No.','Mode','Status',
- // 'Shipper','Consignee','Origin Agent','Destination Agent','Creation Time','ETD','ETA',
- // 'Voyage','Vessel','Week','Created by') order by default_order");
- $default_ids = common::excuteListSql("select id,display_name from public.ra_online_search_display_cso where model_name = '$type'
- and default_display = true order by default_order");
- $ids = utils::implode(";", $_POST['ids']);
- $save_ids = common::excuteListSql("select id,display_name from public.ra_online_search_display_cso where model_name = '$type'
- and id::text = any(regexp_split_to_array('$ids', ';')) order by default_order");
- $detele_detail = "";
- foreach($default_ids as $did){
- if(!utils::exist_array($did['id'],$save_ids)){
- $detele_detail .=$did['display_name']."/";
- }
- }
- $add_detail = "";
- foreach($save_ids as $sid){
- if(!utils::exist_array($sid['id'],$default_ids)){
- $add_detail .=$sid['display_name']."/";
- }
- }
- if(!empty($detele_detail)){
- $detail.="Detele fields: (".$detele_detail."). ";
- }
- if(!empty($add_detail)){
- $detail.="Add fields: (".$add_detail."). ";
- }
- if(empty($detail)){
- $detail = "The default field has not changed";
- }
- }
- if(($action == "ocean_booking" || $action == "ocean_order") && $operate == "detail"){
- $tabel = $action == "ocean_booking" ? "kln_booking" : "kln_ocean";
- $serial_no = common::deCode($_GET['a'], 'D');
- $sql = "SELECT booking_no,h_bol from public.$tabel where serial_no = '$serial_no' limit 1";
- $data = common::excuteObjectSql($sql);
- if(!empty($data['booking_no'])){
- $detail = 'Booking No.: '.$data['booking_no'];
- }else{
- $detail = 'HBOL: '.$data['h_bol'];
- }
- }
- if(($action == "ocean_booking" || $action == "ocean_order") && $operate == "save_communication"){
- $text = $_POST["text"];
- $detail = urldecode($text);
- }
- if(($action == "ocean_order") && $operate == "ams_isf_log"){
- $detail = "Enter AMS/ISF Page";
- }
- if(($action == "ocean_booking" || $action == "ocean_order") && $operate == "excel"){
- $detail = "Filter_condition:" . $_REQUEST['excel_filter_condition']." Selected Fields:". $_REQUEST['selected_fields'];
- }
- //Tracking詳情頁download的file(顯示file名稱)
- if(($action == "ocean_order") && $operate == "download"){
- $filename = common::deCode($_GET['url'], 'D');
- $filename = str_replace("/", DIRECTORY_SEPARATOR, $filename);
- $filename = str_replace("\\", DIRECTORY_SEPARATOR, $filename);
- $display_name = basename($filename);
- if (!file_exists($filename)){
- $detail = "Tracking Detail Attachment Download But File Not Exist : $display_name";
- }else{
- $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;
- }
- public static function calculateTicks($minValue, $maxValue, $targetTickCount = 10) {
- $tickSpacing = ($maxValue - $minValue);
- $tickSpacing = intval($tickSpacing);
- $interval = ceil($tickSpacing / $targetTickCount);
- $len = strlen($interval);
- if ($len >1){
- $interval = ceil($interval/pow(10,$len-1)) *pow(10,$len-1);
- }
- return $interval;
- }
- //只记录Public tracking
- public static function single_operation_log_save($user_type,$user_name,$page,$operation,$operation_detail){
- $sql = "INSERT INTO public.customer_service_operation_log(user_type, user_name, page, operation, operation_detail,
- operation_time)
- VALUES ('$user_type', '$user_name', '$page', '$operation', '$operation_detail', now())";
- common::excuteUpdateSql($sql);
- }
- public static function uuid() {
- return strtoupper(md5(uniqid("", TRUE) . mt_rand()));
- }
- public static function count($variable){
- if (is_array($variable)) {
- $count = count($variable);
- } else {
- $count = 0;
- }
- return $count;
- }
- public static function implode($sp,$variable){
- $variable = isset($variable) && is_array($variable) ? $variable : array();
- return implode($sp, $variable);
- }
- public static function in_array($str, $arr){
- if (is_array($arr)) {
- return in_array($str, $arr);
- } else {
- return false;
- }
- }
- public static function exist_array($key,$arr){
- $flag = false;
- foreach($arr as $v){
- if($v['id'] == $key ){
- $flag = true;
- }
- }
- 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(utils::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(utils::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:"Arial",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:"Arial",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:"Arial",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 = "";
- if($type == "co2e_orgin"){
- $str = "SUM(COALESCE(carbon_emission,0)) as catnum ";
- $filed = "shippr_uncode";
- } else {
- $str = "SUM(COALESCE(carbon_emission,0)) as catnum ";
- $filed = "consignee_uncode";
- }
- $shipment_mode_where = " 1=1 ";
- //这里处理为空,目前没有数据
- $shipment_mode_where = " transport_mode = '$shipment_mode' ";
- $shipment_mode_where .= $sqlWhere;
- foreach ($ids_arr as $value) {
- if (!empty($value)) {
- if (empty($sql)) {
- $sql .= "SELECT $str FROM public.kln_ocean where $shipment_mode_where and $filed = '$value'";
- } else {
- $sql .= " union all SELECT $str from public.kln_ocean where $shipment_mode_where and $filed = '$value'";
- }
- }
- }
- return $sql;
- }
- public static function removeDuplicateArray($array){
- $result = array();
- foreach ($array as $value) {
- //过滤可能的空值,会引起前端页面有数据但无法显示
- if(!empty($value)){
- if (!utils::in_array($value, $result)) {
- $result[] = $value;
- }
- }
- }
- return $result;
- }
- 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; // 不是支持的文件类型
- }
- }
- public static function arrayKeyToInt($arr){
- $ret = array();
- foreach($arr as $key => $val){
- $ret[] = $val;
- }
- return $ret;
- }
- public static function getDailyAndweeklyFrist($arr){
- $numericRecords = count($arr);
- $ret = array();
- $numericRecords_one = 0;
- $numericRecords_two = 0;
- foreach($arr as $key => $val){
- if($key == 0){
- $val["numericRecords"] = $numericRecords;
- $ret = $val;
- }
- if($val["notifiation_type"] == "Departure/Arrival_Delay"){
- if(utils::checkExist($val["delay_name"],"Departure_Delay")){
- $numericRecords_one +=1;
- }
- if(utils::checkExist($val["delay_name"],"Arrival_Delay")){
- $numericRecords_two +=1;
- }
- }
- if($val["notifiation_type"] == "ETD/ETA_Change"){
- if(utils::checkExist($val["date_change_name"],"ETD Change")){
- $numericRecords_one +=1;
- }
- if(utils::checkExist($val["date_change_name"],"ETA Change")){
- $numericRecords_two +=1;
- }
- }
- }
- //对Delay and change 特殊处理
- $ret["numericRecords_one"]= $numericRecords_one;
- $ret["numericRecords_two"]= $numericRecords_two;
- return $ret;
- }
- /**
- * ocean ->sea
- */
- public static function converModeToDB($shipment_transport_mode_arr){
- $converMode = array();
- foreach($shipment_transport_mode_arr as $model){
- if (strtolower($model) == "ocean"){
- $converMode[] = 'sea';
- }else{
- $converMode[] = strtolower($model);
- }
- }
- return utils::implode(";",$converMode);
- }
- /**
- * sea ->ocean
- */
- public static function converModeToDisplay($shipment_transport_mode){
- //数据转换前端需要的
- $converMode = array();
- $shipment_transport_mode_arr = explode(";", $shipment_transport_mode);
- foreach($shipment_transport_mode_arr as $model){
- if (strtolower($model) == "sea"){
- $converMode[] = 'Ocean';
- }else{
- $converMode[] = ucfirst($model);
- }
- }
- return utils::implode(";",$converMode);
- }
- public static function compareArrayEq($array1,$array2){
- $array1 = empty($array1) ? array():$array1;
- $array2 = empty($array2) ? array():$array2;
- // 使用array_diff比较并重置键名
- $diff1 = array_diff($array1, $array2);
- $diff2 = array_diff($array2, $array1);
-
- // 如果结果为空,说明两个数组一样
- if (empty($diff1) && empty($diff2)) {
- return true;
- } else {
- return false;
- }
- }
- public static function comvertutcinfo($time_zone){
- if(!empty($time_zone)){
- if(utils::checkExist($time_zone,"+")){
- $time_zone = str_replace('+', '-', $time_zone);
- }else{
- $time_zone = str_replace('-', '+', $time_zone);
- }
- }
- return $time_zone;
- }
- public static function arrayOrderBykeys($order,$data_kd,$key){
- $orderedData = []; // 用于存储按$order排序后的数据
- foreach ($order as $name) {
- foreach ($data_kd as $item) {
- if ($item[$key] == $name) {
- $orderedData[] = $item; // 将找到的元素添加到新数组中
- break; // 找到后跳出内层循环,继续外层循环处理下一个id
- }
- }
- }
- return $orderedData;
- }
- /**
- * 数组去掉null
- */
- public static function arrayRemoveNull($array){
- foreach ($array as &$value) {
- if (is_null($value)) {
- $value = '';
- }
- }
- unset($value); // 断开 $value 的引用
- return $array;
- }
- /**
- * public.kln_ocean 和 WHERE 的位置关系,进行条件拼接
- */
- public static function modifyString($input,$sqlWhere) {
- $search = 'public.kln_ocean';
- $pos = strpos($input, $search);
-
- if ($pos !== false) {
- $afterSearch = substr($input, $pos + strlen($search));
- $hasWhere = (stripos($afterSearch, 'WHERE') !== false);
-
- if ($hasWhere) {
- // 在 WHERE 后插入 1=1
- $wherePos = stripos($input, 'WHERE', $pos);
- $insertPos = $wherePos + strlen('WHERE');
- $sqlWhere =' ' .$sqlWhere.' and ';
- return substr_replace($input, $sqlWhere, $insertPos, 0);
- } else {
- // 在 public.kln_ocean 后插入 1=1
- $insertPos = $pos + strlen($search);
- $sqlWhere =' where ' .$sqlWhere.' ';
- return substr_replace($input, $sqlWhere, $insertPos, 0);
- }
- }
- return $input;
- }
- /**
- * LIMIT的处理,或者超过10
- */
- public static function processLimitClause($sql) {
- // 查找不区分大小写的 LIMIT 位置
- $limitPos = stripos($sql, 'LIMIT');
-
- if ($limitPos !== false) {
- // 截取 LIMIT 之前的部分,拼接固定内容
- $processed = substr($sql, 0, $limitPos) . 'LIMIT 10';
- } else {
- // 无 LIMIT 时直接追加
- $processed = $sql . ' LIMIT 10';
- }
-
- return $processed;
- }
- /**
- * 替换 single reference
- */
- public static function replacements($data, $template,$new_sql) {
- // 动态构建替换数组(格式:[key] => value)
- $replacements = [];
- foreach ($data as $key => $value) {
- $replacements["{$key}"] = $value; // 将键名包裹在方括号中
- $replacements["{{$key}}"] = $value;
- $replacements["{{{$key}}}"] = $value;
- }
- if(empty($data)){
- $fileds = common::extractSelectFields($new_sql);
- foreach($fileds as $key){
- $replacements["{$key}"] = ""; // 将键名包裹在方括号中
- $replacements["{{$key}}"] = "";
- $replacements["{{{$key}}}"] = "";
- }
- }
- // 执行替换
- $result = strtr($template, $replacements);
- // 输出结果
- return $result;
- }
- /**
- * 替换复杂的reference
- */
- public static function replacementsMultiline($data, $template,$new_sql) {
- //| {{h_bol}} | {{m_bol}} | {{transport_mode}} | {{service}} | 格式
- $replaceTemplate = "";
- $explode_str = "|";
- foreach($data as $key => $val){
- if($key == 0){
- foreach($val as $field => $fieldVal){
- $explode_str.=" {{{$field}}} |";
- }
- }else{
- continue;
- }
- }
- if(empty($data)){
- $fileds = common::extractSelectFields($new_sql);
- foreach($fileds as $fieldVal){
- $explode_str.=" {{{$fieldVal}}} |";
- }
- }
- //检查模板 是否已经带有特定表格的序列
- if(strpos($template, $explode_str) !== false){
- $spacing = utils::getMarkDownTableSpacing($template,$explode_str);
- $parts = explode("$explode_str", $template,2);
- // 生成所有行
- $generatedRows = [];
- foreach ($data as $row) {
- $replacements = [];
- foreach ($row as $key => $value) {
- $replacements["{{{$key}}}"] = $value;
- }
- $generatedRows[] = strtr($explode_str, $replacements);
- }
- $replaceTemplate = $parts[0] . implode($spacing, $generatedRows) . $parts[1];
- }else{
- //全文替换 上面统一有excuteListSql 这里的结果要变一下
- $replaceTemplate = utils::replacements($data[0],$template,$new_sql);
- }
- return $replaceTemplate;
- }
- /**
- * 替换复杂的reference 固定问题 分开
- */
- public static function replacementsFixedMultilineForFixed($data, $template,$explode_str) {
- //| {{h_bol}} | {{m_bol}} | {{transport_mode}} | {{service}} | 格式
- $replaceTemplate = "";
- //检查模板 是否已经带有特定表格的序列
- if(strpos($template, $explode_str) !== false){
- $spacing = utils::getMarkDownTableSpacing($template,$explode_str);
- $parts = explode("$explode_str", $template,2);
- // 生成所有行
- $generatedRows = [];
- foreach ($data as $row) {
- $replacements = [];
- foreach ($row as $key => $value) {
- $replacements["{{{$key}}}"] = $value;
- }
- $generatedRows[] = strtr($explode_str, $replacements);
- }
- $replaceTemplate = $parts[0] . implode($spacing, $generatedRows) . $parts[1];
- }else{
- //有异常,模板原样返回
- $replaceTemplate = $template;
- }
- return $replaceTemplate;
- }
- /**
- * 替换 single reference Fixed
- */
- public static function replacementsFixed($data, $template,$fileds) {
- // 动态构建替换数组(格式:[key] => value)
- $replacements = [];
- foreach ($data as $key => $value) {
- $replacements["{$key}"] = $value; // 将键名包裹在方括号中
- $replacements["{{$key}}"] = $value;
- $replacements["{{{$key}}}"] = $value;
- }
- if(empty($data)){
- foreach($fileds as $key){
- $replacements["{$key}"] = ""; // 将键名包裹在方括号中
- $replacements["{{$key}}"] = "";
- $replacements["{{{$key}}}"] = "";
- }
- }
- // 执行替换
- $result = strtr($template, $replacements);
- // 输出结果
- return $result;
- }
- public static function getMarkDownTableSpacing($str,$search){
- //$str = "|--------------|\n sdsds| E1205546127 | ";
- //$search = "| E1205546127 |";
- // 查找搜索字符串的位置
- $pos = strpos($str, $search);
- if ($pos !== false) {
- // 从搜索字符串前面开始向前查找 "|" 的位置
- for ($i = $pos - 1; $i >= 0; $i--) {
- if ($str[$i] === '|') {
- // 提取两个位置之间的内容
- $result = substr($str, $i + 1, $pos - $i - 1);
- return $result;
- }
- }
- } else {
- return "\n";
- }
- }
- public static function uniqueGroupbyData($unique_filed,$groups_filed,$rows){
- $uniqueData = [];
- $hBolSeen = [];
- //需要去重
- if(!empty($unique_filed)){
- foreach ($rows as $row) {
- $hBol = $row[$unique_filed]."_".$row[$groups_filed];
- if (!isset($hBolSeen[$hBol])) {
- $uniqueData[] = $row;
- $hBolSeen[$hBol] = true;
- }
- }
- } else {
- //不需要去重
- $uniqueData = $rows;
- }
- //分组计数
- $dateGroups = [];
- if(!empty($groups_filed)){
- foreach ($uniqueData as $item) {
- $date = $item[$groups_filed];
-
- if (!isset($dateGroups[$date])) {
- $dateGroups[$date] = 0;
- }
- $dateGroups[$date]++;
- }
- }
- return $dateGroups;
- }
- }
- ?>
|