utils.class.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. <?php
  2. if (!defined('IN_ONLINE')) {
  3. exit('Access Denied');
  4. }
  5. /**
  6. * Description of utilsclass
  7. *
  8. * @author Administrator
  9. */
  10. class utils {
  11. public static function checkPassword($password,$rule="",$user_login="") {
  12. $str ="";
  13. if (!empty($rule)) {
  14. //是否校验大小写
  15. if (!empty($rule["hasOneUpperChar"])&&$rule["hasOneUpperChar"]) {
  16. if (!preg_match('/[A-Z]/',$password)) {
  17. $str ="Password must contain uppercase letters";
  18. }
  19. }
  20. //是否校验小写
  21. if (!empty($rule["hasOneLowerChar"])&&$rule["hasOneLowerChar"]) {
  22. if (!preg_match('/[a-z]/',$password)) {
  23. $str ="Password must contain lowercase letters";
  24. }
  25. }
  26. //是否存在数字
  27. if (!empty($rule["hasOneNumberChar"])&&$rule["hasOneNumberChar"]) {
  28. if (!preg_match('/[0-9]/',$password)) {
  29. $str ="Password must contain numbers";
  30. }
  31. }
  32. $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;";
  33. $user_type = common::excuteOneSql($sql);
  34. if (!empty($user_type)&&$user_type=="Super User") {
  35. if (strlen($password)<$rule["SuperMinLen"]||strlen($password)>$rule["SuperMaxLen"]) {
  36. $str ="Super user password length between ".$rule["SuperMinLen"]." and ".$rule["SuperMaxLen"];
  37. }
  38. }else{
  39. //校验密码长度
  40. if (strlen($password)<$rule["MinLen"]||strlen($password)>$rule["MaxLen"]) {
  41. $str ="Password length between ".$rule["MinLen"]." and ".$rule["MaxLen"];
  42. }
  43. }
  44. return $str;
  45. }else{
  46. if (preg_match('/^\d*$/', $password) || preg_match('/^[a-zA-Z]+$/', $password)) {
  47. $str ="Must include letters and numbers";
  48. }
  49. $len = strlen($password);
  50. $t = substr($password, 0, 1);
  51. for ($i = 1; $i < $len; $i++) {
  52. $t1 = substr($password, $i, 1);
  53. if ($t != $t1) {
  54. return "";
  55. }
  56. }
  57. return "error";
  58. }
  59. }
  60. //隐藏邮箱地址
  61. public static function maskEmail($email) {
  62. $idex = strlen($email) - strrpos($email, ".");
  63. $mask = substr($email, 0, 1) . str_repeat('*', 6) . "@" . str_repeat('*', 3) . substr($email, -$idex);
  64. return $mask;
  65. }
  66. public static function getInSql($str, $not = false, $sep = ";") {
  67. $str = trim($str);
  68. $str = trim($str, $sep);
  69. $str = trim($str);
  70. if (empty($str) && $str !== "0" && $str !== 0)
  71. return "1<>1";
  72. $str = strtolower($str);
  73. if (utils::checkExist($str, $sep)) {
  74. $aa = explode($sep, $str);
  75. $msg = "";
  76. foreach ($aa as $value) {
  77. $value = trim($value);
  78. if (empty($value))
  79. continue;
  80. if (empty($msg))
  81. $msg = "'" . common::check_input($value) . "'";
  82. else
  83. $msg .= ",'" . common::check_input($value) . "'";
  84. }
  85. if ($not !== FALSE)
  86. return " not in (" . $msg . ")";
  87. else
  88. return " in (" . $msg . ")";
  89. } else {
  90. if ($not !== FALSE)
  91. return " != '" . common::check_input(trim($str)) . "'";
  92. else
  93. return " = '" . common::check_input(trim($str)) . "'";
  94. }
  95. }
  96. public static function checkExist($string, $search, $u = TRUE) {
  97. if ($u === TRUE) {
  98. if (stripos($string, $search) !== false)
  99. return TRUE;
  100. }else {
  101. if (strpos($string, $search) !== false)
  102. return TRUE;
  103. }
  104. return FALSE;
  105. }
  106. public static function endWith($string, $end, $u = TRUE) {
  107. if ($u === TRUE) {
  108. $string = strtolower($string);
  109. $end = strtolower($end);
  110. return strrchr($string, $end) == $end;
  111. }
  112. return strrchr($string, $end) == $end;
  113. }
  114. public static function _get($str) {
  115. $rs = isset($_POST[$str]) ? $_POST[$str] : null;
  116. if (empty($rs))
  117. $rs = isset($_GET[$str]) ? $_GET[$str] : null;
  118. return $rs;
  119. }
  120. public static function startWith($string, $start, $u = TRUE) {
  121. if ($u === TRUE)
  122. return stripos($string, $start) === 0;
  123. return strpos($string, $start) === 0;
  124. }
  125. public static function outDisplay($content, $is_time = 'f', $is_first = 'f', $is_boolean = 'f', $excel_export = FALSE) {
  126. if (empty($content) && $content !== 0 && $content !== "0")
  127. return "";
  128. if (strtolower($is_time) == 't')
  129. return utils::dealTimeDisplay($content);
  130. if (strtolower($is_first) == 't') {
  131. if ($excel_export !== FALSE)
  132. return utils::getCompanyName($content);
  133. else
  134. return '<span title="' . $content . '">' . utils::getCompanyName($content) . '</span>';
  135. }
  136. if (strtolower($is_boolean) == 't')
  137. return utils::outTrue($content);
  138. return nl2br($content);
  139. }
  140. public static function _output($value) {
  141. if (empty($value))
  142. return "&nbsp;";
  143. else
  144. return $value;
  145. }
  146. public static function dealTimeDisplay($date) {
  147. if (empty($date))
  148. return "";
  149. if (strlen($date) > 10)
  150. return date("m/d/Y H:i:s", strtotime($date));
  151. return date("m/d/Y", strtotime($date));
  152. }
  153. public static function outDisplayForMerge($frist,$last,$split = "/") {
  154. if($frist == $last){
  155. return $frist;
  156. }
  157. if (!empty($frist)){
  158. if(!empty($last)){
  159. return $frist.$split.$last;
  160. }else{
  161. return $frist;
  162. }
  163. }else{
  164. return $last;
  165. }
  166. }
  167. public static function outTrue($r) {
  168. if (empty($r))
  169. return "No";
  170. $r = strtolower($r);
  171. if ($r == "t")
  172. return "Yes";
  173. elseif ($r == "f")
  174. return "No";
  175. else
  176. return $r;
  177. }
  178. public static function getCompanyName($detail) {
  179. $detail = nl2br($detail);
  180. if (strpos($detail, '<br />') === FALSE)
  181. return $detail;
  182. return substr($detail, 0, strpos($detail, '<br />'));
  183. }
  184. public static function getEmail($serial_no) {
  185. $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') "
  186. . "order by schem_not_display nulls last limit 1");
  187. $schema = $ocean["order_from"] . ".";
  188. $dest_op_from_agent = common::excuteOneSql("select dest_op_from_agent from " . $schema . "ocean where md5(serial_no)=md5('$serial_no')");
  189. if ($ocean["agent"] == "KYMTL" || $ocean["agent"] == "KYYYZ") {
  190. $email = array();
  191. $email["email"] = "";
  192. if (!empty($dest_op_from_agent)) {
  193. $so_email = common::excuteOneSql("select email from " . $schema . "employee where employee_id='" . $dest_op_from_agent . "' and active=true");
  194. }
  195. if (!empty($so_email)) {
  196. if (empty($email["email"])) {
  197. $email["email"] = $so_email;
  198. } else {
  199. $email["email"] .= ";" . $so_email;
  200. }
  201. }
  202. if (!empty($ocean["sales_rep"])) {
  203. $rep_email = common::excuteOneSql("select email from " . $schema . "employee where lower(salesopcode)='" . strtolower($ocean["sales_rep"]) . "' and active=true");
  204. if (!empty($rep_email)) {
  205. if (empty($email["email"])) {
  206. $email["email"] = $rep_email;
  207. } else {
  208. $email["email"] .= ";" . $rep_email;
  209. }
  210. }
  211. }
  212. } else {
  213. $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 "
  214. . "lower(u.user_login) in ('" . strtolower($ocean["created_by"]) . "', '" . strtolower($ocean["last_user"]) . "')");
  215. if (empty($dest_op_from_agent)) {
  216. if (!empty($ocean["dest_op"])) {
  217. $so_email = common::excuteOneSql("select email from " . $schema . "employee where employee_id='" . $ocean["dest_op"] . "' and active=true");
  218. }
  219. } else {
  220. $so_email = common::excuteOneSql("select email from " . $schema . "employee where employee_id='" . $dest_op_from_agent . "' and active=true");
  221. }
  222. if (empty($so_email)) {
  223. if ($ocean["agent"] == "APEXSFO") {
  224. $so_email = "oid2@apexshipping.com";
  225. }
  226. if ($ocean["agent"] == "APEXLAX") {
  227. $so_email = "laxoid@apexshipping.com";
  228. }
  229. if ($ocean["agent"] == "APEXNYC") {
  230. $so_email = "NYCOID@APEXSHIPPING.COM";
  231. }
  232. if ($ocean["agent"] == "APEXPNW") {
  233. $so_email = "pnwoid@apexshipping.com";
  234. }
  235. if ($ocean["agent"] == "STLUTA") {
  236. $so_email = "starlinkOID@apexshipping.com ";
  237. }
  238. if ($ocean["agent"] == "APEXORD") {
  239. $so_email = "ordoid@apexshipping.com";
  240. }
  241. }
  242. if (!empty($so_email)) {
  243. if (empty($email["email"])) {
  244. $email["email"] = $so_email;
  245. } else {
  246. $email["email"] .= ";" . $so_email;
  247. }
  248. }
  249. if (!empty($ocean["sales_rep"])) {
  250. $rep_email = common::excuteOneSql("select email from " . $schema . "employee where lower(salesopcode)='" . strtolower($ocean["sales_rep"]) . "' and active=true");
  251. if (!empty($rep_email)) {
  252. if (empty($email["email"])) {
  253. $email["email"] = $rep_email;
  254. } else {
  255. $email["email"] .= ";" . $rep_email;
  256. }
  257. }
  258. }
  259. }
  260. $email["h_bol"] = $ocean["h_bol"];
  261. $email["consignee"] = $ocean["consignee"];
  262. return $email;
  263. }
  264. /***
  265. * 过滤json中的某个数据
  266. * @param unknown $json
  267. * @param unknown $search
  268. * @param unknown $replace
  269. * @return mixed
  270. */
  271. public static function jsonFiltration($search,$replace,$json){
  272. //处理json中将斜杠转义问题
  273. $json = str_replace("\\/", "/", $json);
  274. return str_replace($search, $replace, $json);
  275. }
  276. /*
  277. * calculate eta destination by etd port
  278. */
  279. public static function calculate_ETA_Des($serial_no) {
  280. $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) . "'";
  281. $rs = common::excuteObjectSql($sql);
  282. $date = "";
  283. if (!empty($rs['eat'])) {
  284. $date = utils::calculate_ETA_Dest($rs['eat'], $rs['poul'], $rs['pod'], $rs['service']);
  285. }
  286. return $date;
  287. }
  288. public static function calculate_ETA_Dest($eta, $poul, $pod, $service) {
  289. if (empty($poul) || empty($pod))
  290. return $eta;
  291. $sql = "SELECT door_days, cy_days
  292. FROM eta_dest
  293. WHERE eta_dest.state::text = ((( SELECT unlocode.state
  294. FROM ports, unlocode
  295. WHERE ports.uncode::text = unlocode.uncode::text AND ports.code::text = '" . common::check_input($pod) . "'
  296. LIMIT 1))::text) AND (','::text || eta_dest.pod::text) ~~* (('%,'::text || '" . common::check_input($poul) . "') || '%'::text)
  297. LIMIT 1";
  298. //$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) . "%'";
  299. $rs = common::excuteObjectSql($sql);
  300. if (empty($rs))
  301. return $eta;
  302. if (utils::endWith($service, "cy"))
  303. return common::addDays($eta, $rs['cy_days']);
  304. else
  305. return common::addDays($eta, $rs['door_days']);
  306. }
  307. /*
  308. * password change, email alert
  309. */
  310. public static function sendEmailByPassword($username, $password, $email, $companyname='') {
  311. $sql = "select subject, ra_content as content from ra_online_email_tpl where lower(ra_type) = 'forgotpw'";
  312. $rs = common::excuteObjectSql($sql);
  313. if (!empty($rs)) {
  314. $subject = $rs['subject'];
  315. $content = $rs['content'];
  316. }
  317. if (!empty($subject) && !empty($content)) {
  318. $content = str_replace('<{username}>', $username, $content);
  319. $content = str_replace('<{password}>', $password, $content);
  320. $content = str_replace('<{companyname}>', $companyname, $content);
  321. global $db;
  322. common::excuteUpdateSql("INSERT INTO public.email_record_forgotpassword(type, title, from_email, to_email, content, insert_date,
  323. cc_email) VALUES ('forgot_password', '" . common::check_input($subject) . "', 'US.KApex.Online@kerryapex.com', '" .
  324. common::check_input($email) . "', '" . common::check_input($content) . "', now(), '');");
  325. return "success";
  326. //return Mail::sendMail($email, $subject, $content);
  327. } else
  328. return null;
  329. }
  330. public static function operation_log_records(){
  331. //排除opreation_log操作
  332. if( empty($_REQUEST["operate"])
  333. || ($_REQUEST["action"] == "login" && $_REQUEST["operate"] == "verifcation_code")
  334. || ($_REQUEST["action"] == "login" && $_REQUEST["operate"] == "check_uname")
  335. || ($_REQUEST["action"] == "ocean_order" && $_REQUEST["operate"] == "setting_ocean_order_display")
  336. || ($_REQUEST["action"] == "ocean_booking" && $_REQUEST["operate"] == "setting_display")){
  337. return;
  338. }
  339. if($_REQUEST["action"] == "login" && $_REQUEST["operate"] == "tracking_checked"){
  340. //public tracking_checked 的user name 记录对应IP 地址
  341. $user_type = "Customer";
  342. $user_name = common::ip();
  343. } elseif($_REQUEST["action"] == "login" && $_REQUEST["operate"] == "do_login"){
  344. //移除do_login 因为在登录的过程中,是没有用户信息的
  345. $user_name = $_REQUEST["uname"];
  346. } else{
  347. $user_name = _getLoginName();
  348. }
  349. $user_type = _isApexLogin() ? "Employee" : "Customer";
  350. //如果在没有登录前,没有登录信息,指定用户
  351. if(!isset($_SESSION['ONLINE_USER'])){
  352. $user_type = common::excuteOneSql("select user_type from public.ra_online_user u where lower(user_login) = '" . strtolower($user_name) . "'");
  353. }
  354. $operateInfo = utils::getPageByAction($_REQUEST["action"],$_REQUEST["operate"]);
  355. $page = $operateInfo["page"];
  356. $operation = $operateInfo["operate"];
  357. $operation_detail = utils::analyzeOperationDetail($_REQUEST["action"],$_REQUEST["operate"]);
  358. if(empty($operation_detail)){
  359. $operation_detail = common::check_input(utils::jsonFiltration("null", "\"\"", json_encode($_REQUEST)));
  360. }
  361. //过滤一分钟以内,相同用户的重复请求
  362. $exist_sql = "select count(1) from public.customer_service_operation_log
  363. where user_name = '$user_name'
  364. and page = '$page' and operation = '$operation' and operation_detail = '$operation_detail'
  365. and operation_time > NOW() - INTERVAL '1 minute' limit 1;";
  366. $exist_obj = common::excuteOneSql($exist_sql);
  367. if(empty($exist_obj)){
  368. $sql = "INSERT INTO public.customer_service_operation_log(user_type, user_name, page, operation, operation_detail,
  369. operation_time)
  370. VALUES ('$user_type', '$user_name', '$page', '$operation', '$operation_detail', now())";
  371. common::excuteUpdateSql($sql);
  372. }
  373. }
  374. public static function getPageByAction($action,$operate){
  375. //取消
  376. $operationConvertName = array(
  377. "login=do_login" => array("page" =>"Login","operate"=>"Login"),
  378. "login=forgot_password" => array("page" =>"Login","operate"=>"Forgot_PPassword"),
  379. "login=logout" => array("page" =>"logout","operate"=>"logout"),
  380. "login=update_pwd_expires" => array("page" =>"Login","operate"=>"Reset password"),
  381. "ocean_booking=search" => array("page" =>"Booking","operate"=>"Search"),
  382. "Booking_Search=save_setting_display" => array("page" =>"Booking","operate"=>"Customize Coulumns"),
  383. "booking=autody" => array("page" =>"Booking","operate"=>"More Filter"),
  384. "booking=autoport" => array("page" =>"Booking","operate"=>"More Filter"),
  385. "ocean_booking=detail" => array("page" =>"Booking","operate"=>"Open Detailed Page"),
  386. "ocean_booking=excel" => array("page" =>"Booking","operate"=>"Download"),
  387. "ocean_booking=save_communication" => array("page" =>"Booking","operate"=>"Send Email"),
  388. "opreation_log=search" => array("page" =>"Opreation_log","operate"=>"Search"),
  389. "login=tracking_checked" => array("page" =>"Tracking","operate"=>"Public tracking"),
  390. "ocean_order=search" => array("page" =>"Tracking","operate"=>"Search"),
  391. "Ocean_Search=save_setting_display" => array("page" =>"Tracking","operate"=>"Customize Coulumns"),
  392. "tracking=autody" => array("page" =>"Tracking","operate"=>"More Filter"),
  393. "tracking=autoport" => array("page" =>"Tracking","operate"=>"More Filter"),
  394. "ocean_order=detail" => array("page" =>"Tracking","operate"=>"Open Detailed Page"),
  395. "ocean_order=excel" => array("page" =>"Tracking","operate"=>"Download"),
  396. "ocean_order=download" => array("page" =>"Tracking","operate"=>"Download"),
  397. "ocean_order=save_communication" => array("page" =>"Booking","operate"=>"Send Email"),
  398. "ocean_order=ams_isf_log" => array("page" =>"Tracking","operate"=>"AMS/ISF"),
  399. "ocean_order=ocean_vgm" => array("page" =>"Tracking","operate"=>"Enter VGM"),
  400. "ocean_order=save_ocean_vgm" => array("page" =>"Tracking","operate"=>"Save VGM"),
  401. "ocean_order=share_shipment" => array("page" =>"Tracking","operate"=>"Share shipment"),
  402. "ocean_order=document_upload" => array("page" =>"Tracking","operate"=>"document_upload"),
  403. "ocean_order=document_upload_do" => array("page" =>"Tracking","operate"=>"document_upload_do"),
  404. "tools=mark_save" => array("page" =>"Tools","operate"=>"Mark_Save"),
  405. "password=" => array("page" =>"Profile","operate"=>"Change password"));
  406. if($action == "ajax" && $operate == "save_setting_display"){
  407. $model_name = $_REQUEST['model_name'];
  408. return $operationConvertName[$model_name."=".$operate];
  409. }
  410. if($action == "ajax" && ($operate == "autody" || $operate == "autoport")){
  411. $model_name = $_REQUEST['search_mode'];
  412. return $operationConvertName[$model_name."=".$operate];
  413. }
  414. return $operationConvertName[$action."=".$operate];
  415. }
  416. public static function analyzeOperationDetail($action,$operate){
  417. if($action == "login" && $operate == "do_login"){
  418. $detail = 'System Account';
  419. if($_REQUEST['token']){
  420. $detail = 'From Apex Online';
  421. }
  422. }
  423. if($action == "login" && $operate == "logout"){
  424. $detail = 'User Logout';
  425. }
  426. if($action == "login" && $operate == "tracking_checked"){
  427. $detail = 'Join public tracking action,Public tracking number:'.$_POST['reference_number'];
  428. }
  429. if($action == "password"){
  430. $detail = 'User Change password';
  431. }
  432. if(($action == "ocean_booking" || $action == "ocean_order") && $operate == "search"){
  433. $detail = "";
  434. //还有一个同以分钟内,不记录相同的查询 这个需要建表查询
  435. //{"action":"ocean_booking","operate":"search","_ntype":"ocean_booking","cp":"1","ps":"100","rc":"-1","other_filed":"","uname":"ra.admin","psw":"abc123456789"}
  436. $filter_common_field = array("action","operate","_ntype","cp","ps","rc","other_filed","uname","psw");
  437. foreach($_REQUEST as $selected_key => $selected){
  438. if(!utils::in_array($selected_key, $filter_common_field)){
  439. if(is_array($selected)){
  440. $selected = utils::implode(",",$selected);
  441. }
  442. $detail .="$selected_key:".$selected."; ";
  443. }
  444. }
  445. if(empty($detail)){
  446. $detail .="No search condition";
  447. }
  448. }
  449. if($action == "ajax" && $operate == "save_setting_display"){
  450. $detail = "";
  451. $type = $_REQUEST['model_name'] == "Booking_Search" ? "Booking_Search" : "Ocean_Search";
  452. //记录最终save 和 default 字段相比的结果
  453. $default_ids = common::excuteListSql("select id,display_name from public.ra_online_search_display_cso where model_name = '$type'
  454. and display_name in('Booking No.','MBL No.','HBL No.','Transportation Mode','Status',
  455. 'Shipper','Consignee','Origin Agent','Destination Agent','Creation Time','ETD','ETA',
  456. 'Voyage','Vessel','Week','Created by') order by default_order");
  457. $ids = utils::implode(";", $_POST['ids']);
  458. $save_ids = common::excuteListSql("select id,display_name from public.ra_online_search_display_cso where model_name = '$type'
  459. and id::text = any(regexp_split_to_array('$ids', ';')) order by default_order");
  460. $detele_detail = "";
  461. foreach($default_ids as $did){
  462. if(!utils::exist_array($did['id'],$save_ids)){
  463. $detele_detail .=$did['display_name']."/";
  464. }
  465. }
  466. $add_detail = "";
  467. foreach($save_ids as $sid){
  468. if(!utils::exist_array($sid['id'],$default_ids)){
  469. $add_detail .=$sid['display_name']."/";
  470. }
  471. }
  472. if(!empty($detele_detail)){
  473. $detail.="Detele fields: (".$detele_detail."). ";
  474. }
  475. if(!empty($add_detail)){
  476. $detail.="Add fields: (".$add_detail."). ";
  477. }
  478. if(empty($detail)){
  479. $detail = "The default field has not changed";
  480. }
  481. }
  482. if(($action == "ocean_booking" || $action == "ocean_order") && $operate == "detail"){
  483. $tabel = $action == "ocean_booking" ? "kln_booking" : "kln_ocean";
  484. $serial_no = common::deCode($_GET['a'], 'D');
  485. $sql = "SELECT booking_no,h_bol from public.$tabel where serial_no = '$serial_no' limit 1";
  486. $data = common::excuteObjectSql($sql);
  487. if(!empty($data['booking_no'])){
  488. $detail = 'Booking No.: '.$data['booking_no'];
  489. }else{
  490. $detail = 'HBOL: '.$data['h_bol'];
  491. }
  492. }
  493. if(($action == "ocean_booking" || $action == "ocean_order") && $operate == "save_communication"){
  494. $text = $_POST["text"];
  495. $detail = urldecode($text);
  496. }
  497. if(($action == "ocean_order") && $operate == "ams_isf_log"){
  498. $detail = "Enter AMS/ISF Page";
  499. }
  500. if(($action == "ocean_booking" || $action == "ocean_order") && $operate == "excel"){
  501. $detail = "Filter_condition:" . $_REQUEST['excel_filter_condition']." Selected Fields:". $_REQUEST['selected_fields'];
  502. }
  503. //Tracking詳情頁download的file(顯示file名稱)
  504. if(($action == "ocean_order") && $operate == "download"){
  505. $filename = common::deCode($_GET['url'], 'D');
  506. $filename = str_replace("/", DIRECTORY_SEPARATOR, $filename);
  507. $filename = str_replace("\\", DIRECTORY_SEPARATOR, $filename);
  508. $display_name = basename($filename);
  509. if (!file_exists($filename)){
  510. $detail = "Tracking Detail Attachment Download But File Not Exist : $display_name";
  511. }else{
  512. $detail = "Tracking Detail Attachment Download: $display_name";
  513. }
  514. }
  515. //Tracking詳情頁Upload Files(顯示file名稱)
  516. if(($action == "ocean_order") && $operate == "document_upload"){
  517. $detail = "Enter Upload Files page";
  518. }
  519. return $detail;
  520. }
  521. public static function calculateTicks($minValue, $maxValue, $targetTickCount = 10) {
  522. $tickSpacing = ($maxValue - $minValue);
  523. $tickSpacing = intval($tickSpacing);
  524. $interval = ceil($tickSpacing / $targetTickCount);
  525. $len = strlen($interval);
  526. if ($len >1){
  527. $interval = ceil($interval/pow(10,$len-1)) *pow(10,$len-1);
  528. }
  529. return $interval;
  530. }
  531. //只记录Public tracking
  532. public static function single_operation_log_save($user_type,$user_name,$page,$operation,$operation_detail){
  533. $sql = "INSERT INTO public.customer_service_operation_log(user_type, user_name, page, operation, operation_detail,
  534. operation_time)
  535. VALUES ('$user_type', '$user_name', '$page', '$operation', '$operation_detail', now())";
  536. common::excuteUpdateSql($sql);
  537. }
  538. public static function uuid() {
  539. return strtoupper(md5(uniqid("", TRUE) . mt_rand()));
  540. }
  541. public static function count($variable){
  542. if (is_array($variable)) {
  543. $count = count($variable);
  544. } else {
  545. $count = 0;
  546. }
  547. return $count;
  548. }
  549. public static function implode($sp,$variable){
  550. $variable = isset($variable) && is_array($variable) ? $variable : array();
  551. return implode($sp, $variable);
  552. }
  553. public static function in_array($str, $arr){
  554. if (is_array($arr)) {
  555. return in_array($str, $arr);
  556. } else {
  557. return false;
  558. }
  559. }
  560. public static function exist_array($key,$arr){
  561. $flag = false;
  562. foreach($arr as $v){
  563. if($v['id'] == $key ){
  564. $flag = true;
  565. }
  566. }
  567. return $flag;
  568. }
  569. public static function getConpanyForNotify($_schemas,$type){
  570. //如果有多個就留空
  571. $company = "";
  572. if($type == 'ocean'){
  573. $company = $_SESSION['ONLINE_USER']['company_name'];
  574. $company_arr = explode(";",$company);
  575. $temp = array();
  576. foreach($company_arr as $v){
  577. if(!empty($v)){
  578. $temp[] = $v;
  579. }
  580. }
  581. if(count($temp) <= 1){
  582. return $company;
  583. }
  584. }
  585. if($type == 'air'){
  586. $company_id = $_SESSION['ONLINE_USER']['air_customers'];
  587. $company_id_arr = explode(";",$company_id);
  588. $temp = array();
  589. foreach($company_id_arr as $v){
  590. if(!empty($v)){
  591. $temp[] = $v;
  592. }
  593. }
  594. if(count($temp) == 1){
  595. if ($_schemas == "public") {//apex ocean和air 分开
  596. $sql = "SELECT company from ocean.contacts where contact_id = '" . common::check_input($temp[0]) . "' ";
  597. } else {
  598. $sql = "SELECT company from $_schemas.contacts where contact_id = '" . common::check_input($temp[0]) . "' ";
  599. }
  600. $company = common::excuteOneSql($sql);
  601. }
  602. return $company;
  603. }
  604. }
  605. public static function getKlnDocNotifyContent($bol,$file_type,$upload_user_name,$upload_user_email,$company,$date_time){
  606. $report_setting = common::excuteObjectSql("select * from ra_online_auto_report_config where report_type = 'KLN_DOC_Notify' ");
  607. $report_content = $report_setting['report_content'];
  608. $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'");
  609. $missing_packing_th = "<tr>";
  610. foreach ($columns as $colk => $colvalue) {
  611. $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">
  612. <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>
  613. </td>';
  614. }
  615. $missing_packing_th .= "</tr>";
  616. $report_content = str_replace('<{missing_packing_th}>', $missing_packing_th, $report_content);
  617. $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)"));
  618. $missing_packing_tr = "";
  619. foreach ($data as $rk => $rv) {
  620. $missing_packing_tr .= "<tr>";
  621. foreach ($columns as $ck => $cv) {
  622. if(utils::endWith($cv['display_name'], "email")){
  623. $missing_packing_tr.='<td style="font-size:8.0pt;font-family:&quot;Arial&quot;,sans-serif;color:black;border-top:none;
  624. 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">
  625. <a href="mailto:'.$rv[$cv['database_column_name']].'">'.$rv[$cv['database_column_name']].'</a>
  626. </td>';
  627. }else{
  628. $missing_packing_tr.='<td style="font-size:8.0pt;font-family:&quot;Arial&quot;,sans-serif;color:black;'
  629. . '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>';
  630. }
  631. }
  632. $missing_packing_tr .= "</tr>";
  633. }
  634. $report_content = str_replace('<{missing_packing_tr}>', $missing_packing_tr, $report_content);
  635. return $report_content;
  636. }
  637. public static function _getSql($ids, $type,$shipment_mode,$sqlWhere) {
  638. $ids_arr = explode(',', $ids);
  639. $sql = "";
  640. if($type == "co2e_orgin"){
  641. $str = "SUM(COALESCE(carbon_emission,0)) as catnum ";
  642. $filed = "shippr_uncode";
  643. } else {
  644. $str = "SUM(COALESCE(carbon_emission,0)) as catnum ";
  645. $filed = "consignee_uncode";
  646. }
  647. $shipment_mode_where = " 1=1 ";
  648. //这里处理为空,目前没有数据
  649. $shipment_mode_where = " transport_mode = '$shipment_mode' ";
  650. $shipment_mode_where .= $sqlWhere;
  651. foreach ($ids_arr as $value) {
  652. if (!empty($value)) {
  653. if (empty($sql)) {
  654. $sql .= "SELECT $str FROM public.kln_ocean where $shipment_mode_where and $filed = '$value'";
  655. } else {
  656. $sql .= " union all SELECT $str from public.kln_ocean where $shipment_mode_where and $filed = '$value'";
  657. }
  658. }
  659. }
  660. return $sql;
  661. }
  662. public static function removeDuplicateArray($array){
  663. $result = array();
  664. foreach ($array as $value) {
  665. if (!in_array($value, $result)) {
  666. $result[] = $value;
  667. }
  668. }
  669. return $result;
  670. }
  671. /**
  672. * 读取文件内容后,重新生成无宏版本文件,支持docx,xlsx(这两个文件类型,被设计就是不能带宏的)
  673. * 估计废除了,除非转pdf去宏,没有其他办法。libreoffice可以通过软件里面的tools栏位按钮去点击去宏处理,但没有命令行。
  674. * 使用unoconv转换文档,但是最新的unoconv,不支持unoconv -f docx --no-macro 命令,网上查询的命令有误
  675. */
  676. // public static function removeFIlemacro($inputFileName,$outputFileName,$file_type) {
  677. // include_once ONLINE_ROOT . 'thirdparty_vendors' . DS . 'vendor' . DS . 'autoload.php';
  678. // if($file_type == "xlsx" || $file_type == "xls"){
  679. // // 读取文件
  680. // // $spreadsheet = PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);
  681. // // // 生成新文件
  682. // // $writerType = ucfirst($file_type);
  683. // // $writer = PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, $writerType); // 使用 Xlsx 格式保存
  684. // // $writer->save($outputFileName);
  685. // // // 删除来源文件
  686. // // unlink($inputFileName);
  687. // // LibreOffice 的命令行命令
  688. // // $command = "soffice --headless --convert-to pdf --outdir " . dirname($outputFileName) . " " . $inputFileName;
  689. // // // 执行命令
  690. // // exec($command, $output, $return_var);
  691. // // // 检查命令是否成功执行
  692. // // if ($return_var === 0) {
  693. // // echo "文档转换成功,已保存为无宏版本:$outputFile\n";
  694. // // } else {
  695. // // echo "文档转换失败,返回代码:$return_var\n";
  696. // // echo "输出:\n" . implode("\n", $output);
  697. // // }
  698. // }
  699. // if($file_type == "docx" || $file_type == "doc"){
  700. // //加载现有的 Word 文档
  701. // // $phpWord = PhpOffice\PhpWord\IOFactory::load($inputFileName);
  702. // // // 保存新的 Word 文档
  703. // // // $newPhpWord = new PhpOffice\PhpWord\PhpWord();
  704. // // // $newSection = $newPhpWord->addSection();
  705. // // // $newSection->addText('Hello World !');
  706. // // $writer = PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); // 使用 DOCX 格式保存
  707. // // $writer->save($outputFileName);
  708. // // //删除来源文件
  709. // // unlink($inputFileName);
  710. // // 使用unoconv转换文档
  711. // //$command = "unoconv -f docx --no-macro '$inputFileName' -o '$outputFileName'";
  712. // // $command = "libreoffice --headless --convert-to pdf $inputFileName --outdir D:\DOC\APEXTAO\20250127";
  713. // // $output = shell_exec($command);
  714. // // if ($output) {
  715. // // echo "文件转换成功!";
  716. // // } else {
  717. // // echo "文件转换失败。";
  718. // // }
  719. // //LibreOffice 的命令行命令
  720. // $command = "soffice --headless --convert-to pdf --outdir " . dirname($outputFileName) . " " . $inputFileName;
  721. // // 执行命令
  722. // exec($command." 2>&1", $output, $return_var);
  723. // // 检查命令是否成功执行
  724. // if ($return_var === 0) {
  725. // echo "文档转换成功,已保存为无宏版本:$outputFile\n";
  726. // } else {
  727. // echo "文档转换失败,返回代码:$return_var\n";
  728. // echo "输出:\n" . implode("\n", $output);
  729. // }
  730. // // 移除宏的命令
  731. // //$command = "soffice --convert-to docx:writer_pdf_Export --infilter=MS Word 97 --outdir /path/to/output $inputFileName";
  732. // //exec($command);
  733. // // 复制无宏的文档到新位置
  734. // //copy("/path/to/output/document.pdf", $outputFileName);
  735. // }
  736. // }
  737. // public static function hasMacros($filePath) {
  738. // $extension = pathinfo($filePath, PATHINFO_EXTENSION);
  739. // if ($extension === 'xlsx') {
  740. // // 检查 .xlsx 文件
  741. // $zip = new ZipArchive();
  742. // if ($zip->open($filePath) === TRUE) {
  743. // // 检查是否存在 vbaProject.bin 文件
  744. // $hasMacros = $zip->locateName('xl/vbaProject.bin') !== false;
  745. // $zip->close();
  746. // return $hasMacros;
  747. // } else {
  748. // return false; // 无法打开文件
  749. // }
  750. // } elseif ($extension === 'docx') {
  751. // // 检查 .docx 文件
  752. // $zip = new ZipArchive();
  753. // if ($zip->open($filePath) === TRUE) {
  754. // // 检查是否存在 vbaProject.bin 文件
  755. // $hasMacros = $zip->locateName('word/vbaProject.bin') !== false;
  756. // $zip->close();
  757. // return $hasMacros;
  758. // } else {
  759. // return false; // 无法打开文件
  760. // }
  761. // } else {
  762. // return false; // 不是支持的文件类型
  763. // }
  764. // }
  765. //$command = "soffice --headless --convert-to pdf --outdir " . dirname($outputFileName) . " " . $inputFileName;
  766. // public static function checkExcelMacros($filePath,$file_name) {
  767. // // Construct the command to execute LibreOffice in headless mode.
  768. // // Replace with the actual path to your LibreOffice executable if needed.
  769. // $libreofficePath = '"C:\Program Files\LibreOffice\program\soffice.exe"'; // Example path, adjust as needed.
  770. // //$command = "$libreofficePath --headless --convert-to txt:Text -o /tmp/output.txt \"$filePath\"";
  771. // $command = "$libreofficePath --headless --convert-to txt --outdir " . dirname($filePath) . " " . $filePath;
  772. // $convert_file = dirname($filePath)."\\".$file_name.".txt";
  773. // // Execute the command.
  774. // exec($command, $output, $returnCode);
  775. // // Check for errors.
  776. // if ($returnCode !== 0) {
  777. // return "Error converting file: " . implode("\n", $output); // Or handle the error as needed.
  778. // }
  779. // // 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.
  780. // $textFile = file_get_contents($convert_file);
  781. // // Clean up the temporary file (important!).
  782. // //unlink($convert_file);
  783. // // Search for indicators of macros. These are not foolproof, but they are a good start.
  784. // // More sophisticated methods might involve inspecting the file's internal structure.
  785. // // Look for VBA project stream.
  786. // 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
  787. // return true; // Macros found.
  788. // } else {
  789. // return false; // No clear macro indicators found.
  790. // }
  791. // }
  792. }
  793. ?>