utils.class.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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.online_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. "tools=mark_save" => array("page" =>"Tools","operate"=>"Mark_Save"),
  403. "password=" => array("page" =>"Profile","operate"=>"Change password"));
  404. if($action == "ajax" && $operate == "save_setting_display"){
  405. $model_name = $_REQUEST['model_name'];
  406. return $operationConvertName[$model_name."=".$operate];
  407. }
  408. if($action == "ajax" && ($operate == "autody" || $operate == "autoport")){
  409. $model_name = $_REQUEST['search_mode'];
  410. return $operationConvertName[$model_name."=".$operate];
  411. }
  412. return $operationConvertName[$action."=".$operate];
  413. }
  414. public static function analyzeOperationDetail($action,$operate){
  415. if($action == "login" && $operate == "do_login"){
  416. $detail = 'System Account';
  417. if($_REQUEST['token']){
  418. $detail = 'From Apex Online';
  419. }
  420. }
  421. if($action == "login" && $operate == "logout"){
  422. $detail = 'User Logout';
  423. }
  424. if($action == "login" && $operate == "tracking_checked"){
  425. $detail = 'Join public tracking action,Public tracking number:'.$_POST['reference_number'];
  426. }
  427. if($action == "password"){
  428. $detail = 'User Change password';
  429. }
  430. if(($action == "ocean_booking" || $action == "ocean_order") && $operate == "search"){
  431. $detail = "";
  432. //还有一个同以分钟内,不记录相同的查询 这个需要建表查询
  433. //{"action":"ocean_booking","operate":"search","_ntype":"ocean_booking","cp":"1","ps":"100","rc":"-1","other_filed":"","uname":"ra.admin","psw":"abc123456789"}
  434. $filter_common_field = array("action","operate","_ntype","cp","ps","rc","other_filed","uname","psw");
  435. foreach($_REQUEST as $selected_key => $selected){
  436. if(!utils::in_array($selected_key, $filter_common_field)){
  437. if(is_array($selected)){
  438. $selected = utils::implode(",",$selected);
  439. }
  440. $detail .="$selected_key:".$selected."; ";
  441. }
  442. }
  443. if(empty($detail)){
  444. $detail .="No search condition";
  445. }
  446. }
  447. if($action == "ajax" && $operate == "save_setting_display"){
  448. $detail = "";
  449. $type = $_REQUEST['model_name'] == "Booking_Search" ? "Booking_Search" : "Ocean_Search";
  450. //记录最终save 和 default 字段相比的结果
  451. $default_ids = common::excuteListSql("select id,display_name from public.ra_online_search_display_cso where model_name = '$type'
  452. and display_name in('Booking No.','MBL No.','HBL No.','Transportation Mode','Status',
  453. 'Shipper','Consignee','Origin Agent','Destination Agent','Creation Time','ETD','ETA',
  454. 'Voyage','Vessel','Week','Created by') order by default_order");
  455. $ids = utils::implode(";", $_POST['ids']);
  456. $save_ids = common::excuteListSql("select id,display_name from public.ra_online_search_display_cso where model_name = '$type'
  457. and id::text = any(regexp_split_to_array('$ids', ';')) order by default_order");
  458. $detele_detail = "";
  459. foreach($default_ids as $did){
  460. if(!utils::exist_array($did['id'],$save_ids)){
  461. $detele_detail .=$did['display_name']."/";
  462. }
  463. }
  464. $add_detail = "";
  465. foreach($save_ids as $sid){
  466. if(!utils::exist_array($sid['id'],$default_ids)){
  467. $add_detail .=$sid['display_name']."/";
  468. }
  469. }
  470. if(!empty($detele_detail)){
  471. $detail.="Detele fields: (".$detele_detail."). ";
  472. }
  473. if(!empty($add_detail)){
  474. $detail.="Add fields: (".$add_detail."). ";
  475. }
  476. if(empty($detail)){
  477. $detail = "The default field has not changed";
  478. }
  479. }
  480. if(($action == "ocean_booking" || $action == "ocean_order") && $operate == "detail"){
  481. $tabel = $action == "ocean_booking" ? "online_booking" : "online_ocean";
  482. $serial_no = common::deCode($_GET['a'], 'D');
  483. $sql = "SELECT booking_no,h_bol from public.$tabel where serial_no = '$serial_no' limit 1";
  484. $data = common::excuteObjectSql($sql);
  485. if(!empty($data['booking_no'])){
  486. $detail = 'Booking No.: '.$data['booking_no'];
  487. }else{
  488. $detail = 'HBOL: '.$data['h_bol'];
  489. }
  490. }
  491. if(($action == "ocean_booking" || $action == "ocean_order") && $operate == "save_communication"){
  492. $text = $_POST["text"];
  493. $detail = urldecode($text);
  494. }
  495. if(($action == "ocean_order") && $operate == "ams_isf_log"){
  496. $detail = "Enter AMS/ISF Page";
  497. }
  498. if(($action == "ocean_booking" || $action == "ocean_order") && $operate == "excel"){
  499. $detail = "Filter_condition:" . $_REQUEST['excel_filter_condition']." Selected Fields:". $_REQUEST['selected_fields'];
  500. }
  501. //Tracking詳情頁download的file(顯示file名稱)
  502. if(($action == "ocean_order") && $operate == "download"){
  503. $filename = common::deCode($_GET['url'], 'D');
  504. $filename = str_replace("/", DIRECTORY_SEPARATOR, $filename);
  505. $filename = str_replace("\\", DIRECTORY_SEPARATOR, $filename);
  506. $display_name = basename($filename);
  507. if (!file_exists($filename)){
  508. $detail = "Tracking Detail Attachment Download But File Not Exist : $display_name";
  509. }else{
  510. $detail = "Tracking Detail Attachment Download: $display_name";
  511. }
  512. }
  513. return $detail;
  514. }
  515. public static function calculateTicks($minValue, $maxValue, $targetTickCount = 10) {
  516. $tickSpacing = ($maxValue - $minValue);
  517. $tickSpacing = intval($tickSpacing);
  518. $interval = ceil($tickSpacing / $targetTickCount);
  519. $len = strlen($interval);
  520. if ($len >1){
  521. $interval = ceil($interval/pow(10,$len-1)) *pow(10,$len-1);
  522. }
  523. return $interval;
  524. }
  525. //只记录Public tracking
  526. public static function single_operation_log_save($user_type,$user_name,$page,$operation,$operation_detail){
  527. $sql = "INSERT INTO public.customer_service_operation_log(user_type, user_name, page, operation, operation_detail,
  528. operation_time)
  529. VALUES ('$user_type', '$user_name', '$page', '$operation', '$operation_detail', now())";
  530. common::excuteUpdateSql($sql);
  531. }
  532. public static function uuid() {
  533. return strtoupper(md5(uniqid("", TRUE) . mt_rand()));
  534. }
  535. public static function count($variable){
  536. if (is_array($variable)) {
  537. $count = count($variable);
  538. } else {
  539. $count = 0;
  540. }
  541. return $count;
  542. }
  543. public static function implode($sp,$variable){
  544. $variable = isset($variable) && is_array($variable) ? $variable : array();
  545. return implode($sp, $variable);
  546. }
  547. public static function in_array($str, $arr){
  548. if (is_array($arr)) {
  549. return in_array($str, $arr);
  550. } else {
  551. return false;
  552. }
  553. }
  554. public static function exist_array($key,$arr){
  555. $flag = false;
  556. foreach($arr as $v){
  557. if($v['id'] == $key ){
  558. $flag = true;
  559. }
  560. }
  561. return $flag;
  562. }
  563. public static function _getSql($ids, $type,$shipment_mode,$sqlWhere) {
  564. $ids_arr = explode(',', $ids);
  565. $sql = "";
  566. if($type == "co2e_orgin"){
  567. $str = "SUM(COALESCE(carbon_emission,0)) as catnum ";
  568. $filed = "shippr_uncode";
  569. } else {
  570. $str = "SUM(COALESCE(carbon_emission,0)) as catnum ";
  571. $filed = "consignee_uncode";
  572. }
  573. $shipment_mode_where = " 1=1 ";
  574. //这里处理为空,目前没有数据
  575. $shipment_mode_where = " transport_mode = '$shipment_mode' ";
  576. $shipment_mode_where .= $sqlWhere;
  577. foreach ($ids_arr as $value) {
  578. if (!empty($value)) {
  579. if (empty($sql)) {
  580. $sql .= "SELECT $str FROM kln_ocean where $shipment_mode_where and $filed = '$value'";
  581. } else {
  582. $sql .= " union all SELECT $str from online_ocean where $shipment_mode_where and $filed = '$value'";
  583. }
  584. }
  585. }
  586. return $sql;
  587. }
  588. public static function removeDuplicateArray($array){
  589. $result = array();
  590. foreach ($array as $value) {
  591. if (!in_array($value, $result)) {
  592. $result[] = $value;
  593. }
  594. }
  595. return $result;
  596. }
  597. }
  598. ?>