common.class.php 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711
  1. <?php
  2. if (!defined('IN_ONLINE')) {
  3. exit('Access Denied');
  4. }
  5. /**
  6. * Description of common
  7. *
  8. * @author Administrator
  9. */
  10. class common {
  11. /*
  12. * mysql check input
  13. */
  14. public static function check_input($value, $boolean = FALSE, $toupper = FALSE) {
  15. if ($boolean !== FALSE) {
  16. if ($value == "t")
  17. return "'t'";
  18. else
  19. return "'f'";
  20. }
  21. $value = trim($value);
  22. if ($toupper !== FALSE)
  23. $value = mb_strtoupper($value);
  24. if (!is_numeric($value)) {
  25. $value = pg_escape_string($value);
  26. }
  27. return $value;
  28. }
  29. public static function excuteOneSql($sql, $exception = FALSE) {
  30. if ($exception) {
  31. global $db;
  32. $result = $db->GetOne($sql);
  33. return $result === FALSE ? null : $result;
  34. } else {
  35. if (empty($sql))
  36. exit(json_encode("Program encountered an error."));
  37. global $db;
  38. $result = $db->GetOne($sql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $sql), 0));
  39. return $result === FALSE ? null : $result;
  40. }
  41. }
  42. public static function excuteObjectSql($sql) {
  43. if (empty($sql))
  44. exit(json_encode("Program encountered an error."));
  45. global $db;
  46. $result = $db->GetRow($sql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $sql), 0));
  47. return $result === FALSE ? null : $result;
  48. }
  49. public static function excuteUpdateSql($sql, $req_id = FALSE) {
  50. if (empty($sql))
  51. exit(json_encode("Program encountered an error."));
  52. global $db;
  53. $rs = $db->Execute($sql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $sql), 0));
  54. if ($rs && $req_id !== FALSE)
  55. return $db->PO_Insert_ID();
  56. else
  57. return $rs;
  58. }
  59. public static function excuteListSql($sql, $exception = FALSE) {
  60. if ($exception) {
  61. global $db;
  62. $result = $db->GetAll($sql);
  63. return $result === FALSE ? null : $result;
  64. } else {
  65. if (empty($sql))
  66. exit(json_encode("Program encountered an error."));
  67. global $db;
  68. $result = $db->GetAll($sql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $sql), 0));
  69. return $result === FALSE ? null : $result;
  70. }
  71. }
  72. /*
  73. * Database log output
  74. */
  75. public static function dbLog($db, $sql) {
  76. $backMsg = $db->errorMsg() . ' sql=' . $sql;
  77. return $backMsg;
  78. }
  79. /*
  80. * get IP
  81. */
  82. public static function ip() {
  83. if (getenv("HTTP_X_FORWARDED_FOR"))
  84. return getenv("HTTP_X_FORWARDED_FOR");
  85. if (getenv("HTTP_CLIENT_IP"))
  86. return getenv("HTTP_CLIENT_IP");
  87. if (getenv("REMOTE_ADDR"))
  88. return getenv("REMOTE_ADDR");
  89. if ($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])
  90. return $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
  91. if ($HTTP_SERVER_VARS["HTTP_CLIENT_IP"])
  92. return $HTTP_SERVER_VARS["HTTP_CLIENT_IP"];
  93. if ($HTTP_SERVER_VARS["REMOTE_ADDR"])
  94. return $HTTP_SERVER_VARS["REMOTE_ADDR"];
  95. return "Unknown";
  96. }
  97. public static function getDBUuid() {
  98. global $db;
  99. $sql = "select uuid_generate_v1()";
  100. $uuid = $db->GetOne($sql);
  101. return $uuid;
  102. }
  103. public static function securityCheckHandNew($action) {
  104. if (strpos($action, "handset") === 0) {
  105. } elseif (strpos($action, "hand") === 0) {
  106. } else {
  107. common::sessionVerify();
  108. $httpAccept = $_SERVER['HTTP_ACCEPT']; // ajax request,is json or html
  109. $ajax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER
  110. ['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'; // is ajax request?
  111. //暂时这么写,放开action = main的查询是为了在没有登录时获取信息。
  112. //tools是为了避免查询的用户,没有配置tools权限,但是新版mark_save需要进入
  113. if($action == "main" || $action == "tools" || $action == "save_layout"){
  114. return;
  115. }
  116. if (!isset($_SESSION['ONLINE_USER'])) {
  117. self::timeoutPrintInfor($httpAccept, $ajax, 'no');
  118. } else {
  119. $time = time() - $_SESSION["LAST_OPERATE_TIME"];
  120. $set_session_timeout = $_SESSION['SESSION_TIMEOUT'];
  121. if (_getLoginName() == "ra.admin") {
  122. $set_session_timeout = 4 * 3600;
  123. }
  124. if ($time > $set_session_timeout) {
  125. self::timeoutPrintInfor($httpAccept, $ajax, 'yes');
  126. } else {
  127. $_SESSION["LAST_OPERATE_TIME"] = time();
  128. if (!_isAdmin() && $_GET["action"] != "linkcrm") {
  129. if (!utils::checkExist($_SESSION['ONLINE_USER']['permission'], $action)
  130. && !(stripos($action, "main") === 0)
  131. && !(stripos($action, "ajax") === 0)
  132. && !(stripos($action, "opreation_log") === 0)) {
  133. $data = array("msg"=>"Permission Denied");
  134. common::echo_json_encode(500, $data);
  135. exit();
  136. }
  137. }
  138. }
  139. }
  140. session_write_close();
  141. }
  142. }
  143. public static function getCompanySearch() {
  144. $sc_list = _get_schemas();
  145. if (count($sc_list) == 1) {
  146. return "";
  147. }
  148. if (_isCustomerLogin()) {
  149. $msg = '<input type="hidden" name="_apex_or_sfs" value=""/>';
  150. } else {
  151. $msg = '<div class="modules">Apex/SFS/Kerry :&nbsp;<select name="_apex_or_sfs" class="sl"><option value="">All</option>';
  152. if ($_SESSION['ONLINE_USER']['main_schemas'] == "public") {
  153. $msg .= '<option value="public">Apex</option>';
  154. } else {
  155. $msg .= '<option value="public">Apex</option>';
  156. }
  157. if ($_SESSION['ONLINE_USER']['main_schemas'] == "sfs") {
  158. $msg .= '<option value="sfs">SFS</option>';
  159. } else {
  160. $msg .= '<option value="sfs">SFS</option>';
  161. }
  162. if ($_SESSION['ONLINE_USER']['main_schemas'] == "kyiff") {
  163. $msg .= '<option value="kyiff">Kerry</option>';
  164. } else {
  165. $msg .= '<option value="kyiff">Kerry</option>';
  166. }
  167. $msg .= '</select></div>';
  168. }
  169. return $msg;
  170. }
  171. public static function sessionVerify() {
  172. if (!isset($_SESSION['user_agent'])) {
  173. $_SESSION['user_agent'] = MD5($_SERVER['REMOTE_ADDR']
  174. . $_SERVER['HTTP_USER_AGENT']);
  175. } elseif ($_SESSION['user_agent'] != MD5($_SERVER['REMOTE_ADDR']
  176. . $_SERVER['HTTP_USER_AGENT'])) {
  177. session_regenerate_id();
  178. }
  179. }
  180. public static function searchExtendHandNew($type, $user, $company_name = "station_name") {
  181. if (_isAdminHandNew($user)) {
  182. if(strtolower($type) == "air_booking" ) //|| strtolower($type) == "air"
  183. {
  184. return "1=1";
  185. }
  186. //return " (schem_not_display is null or schem_not_display=false)";
  187. return " (COALESCE(schem_not_display,false) = false)";
  188. }
  189. if (_isDocAdmin($user["user_login"])) {
  190. if(strtolower($type) == "air_booking" ) //|| strtolower($type) == "air"
  191. {
  192. return "1=1";
  193. }
  194. //return ' (schem_not_display is null or schem_not_display=false)';
  195. return ' (COALESCE(schem_not_display,false) = false)';
  196. }
  197. if (strtolower($type) != "ocean" && strtolower($type) != "booking" && strtolower($type) != "air_booking"&& strtolower($type) != "air") {
  198. return " 1<>1";
  199. }
  200. if (empty($user["schemas_list"])) {
  201. $user["schemas_list"] = $_SESSION["schemas_list"];
  202. }
  203. $schemas_list = $user["schemas_list"];
  204. if ($user["is_kerry_shipment"] == "t") {
  205. $sqlWhere = " is_kerry_shipment is not null and is_kerry_shipment=true";
  206. } else if ($user["is_kerry_shipment"] == "f") {
  207. //$sqlWhere = " (is_kerry_shipment is null or is_kerry_shipment=false)";
  208. $sqlWhere = " (COALESCE(is_kerry_shipment,false) = false)";
  209. } else {
  210. $sqlWhere = " 1=1";
  211. }
  212. if (!empty($_POST["_apex_or_sfs"])) {
  213. $sqlWhere .= " and order_from='" . $_POST["_apex_or_sfs"] . "'";
  214. }
  215. if (count($schemas_list) == 1) {
  216. $schames = $schemas_list[0]["schemas_name"];
  217. if(strtolower($type) == "air_booking" ||strtolower($type) == "air")
  218. {
  219. }
  220. else
  221. $sqlWhere .= " and order_from='$schames'";
  222. if ($schames == "sfs" && empty($user["sfs_ONLINE_USER"])) {
  223. $user = $_SESSION["sfs_ONLINE_USER"];
  224. }
  225. if (strtolower($type) == "ocean") {
  226. $sqlWhere .= self::_oceanHandNew($user, $schames);
  227. if ($company_name == "doc") {
  228. if (empty($user["view_file_format"])) {
  229. if (strtolower($user["user_type"]) == "customer") {
  230. $sqlWhere .= " and serial_no in (SELECT serial_no from $schames.ra_online_file_format where active = true and client_display = true)";
  231. } else {
  232. $sqlWhere .= " and serial_no in (SELECT serial_no from $schames.ra_online_file_format where active = true)";
  233. }
  234. } else {
  235. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  236. }
  237. }
  238. }
  239. if (strtolower($type) == "booking") {
  240. $sqlWhere .= self::_bookingHandNew($user, $schames);
  241. }
  242. if (strtolower($type) == "air_booking") {
  243. $sqlWhere .= self::_airHandNew($user, $schames);
  244. }
  245. if (strtolower($type) == "air") {
  246. $sqlWhere .= self::_airHandNew($user, $schames);
  247. if ($company_name == "doc") {
  248. if (empty($user["view_file_format"])) {
  249. if (strtolower($user["user_type"]) == "customer") {
  250. $sqlWhere .= " and serial_no in (SELECT serial_no from $schames.ra_online_file_format where active = true and client_display = true)";
  251. } else {
  252. $sqlWhere .= " and serial_no in (SELECT serial_no from $schames.ra_online_file_format where active = true)";
  253. }
  254. } else {
  255. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  256. }
  257. }
  258. }
  259. } elseif (count($schemas_list) == 2) {
  260. if(strtolower($type) == "air_booking" )//|| strtolower($type) == "air"
  261. {
  262. // $sqlWhere .= " and 1=1";
  263. }
  264. else{
  265. //$sqlWhere .= " and (schem_not_display is null or schem_not_display=false)";
  266. $sqlWhere .= " and (COALESCE(schem_not_display,false) = false)";
  267. }
  268. if (strtolower($type) == "ocean") {
  269. $sqlWhere .= " and ((order_from='public' ";
  270. $sqlWhere .= self::_oceanHandNew($user, "public");
  271. if ($company_name == "doc") {
  272. if (empty($user["view_file_format"])) {
  273. if (strtolower($user["user_type"]) == "customer") {
  274. $sqlWhere .= " and serial_no in (SELECT serial_no from public.ra_online_file_format where active = true and client_display = true)";
  275. } else {
  276. $sqlWhere .= " and serial_no in (SELECT serial_no from public.ra_online_file_format where active = true)";
  277. }
  278. } else {
  279. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  280. }
  281. }
  282. $sqlWhere .= ") or (order_from='sfs' ";
  283. if (empty($user["sfs_ONLINE_USER"])) {
  284. $user = $_SESSION["sfs_ONLINE_USER"];
  285. }
  286. $sqlWhere .= self::_oceanHandNew($user, "sfs");
  287. if ($company_name == "doc") {
  288. if (empty($user["view_file_format"])) {
  289. if (strtolower($user["user_type"]) == "customer") {
  290. $sqlWhere .= " and serial_no in (SELECT serial_no from sfs.ra_online_file_format where active = true and client_display = true)";
  291. } else {
  292. $sqlWhere .= " and serial_no in (SELECT serial_no from sfs.ra_online_file_format where active = true)";
  293. }
  294. } else {
  295. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  296. }
  297. }
  298. $sqlWhere .= ") )";
  299. }
  300. if (strtolower($type) == "booking") {
  301. $sqlWhere .= " and ((order_from='public' ";
  302. $sqlWhere .= self::_bookingHandNew($user, "public");
  303. $sqlWhere .= ") or (order_from='sfs' ";
  304. if (empty($user["sfs_ONLINE_USER"])) {
  305. $user = $_SESSION["sfs_ONLINE_USER"];
  306. }
  307. $sqlWhere .= self::_bookingHandNew($user, "sfs");
  308. $sqlWhere .= "))";
  309. }
  310. if (strtolower($type) == "air_booking") {
  311. $sqlWhere .= " and ((order_from='public' ";
  312. $sqlWhere .= self::_airHandNew($user, "public");
  313. $sqlWhere .= ") or (order_from='sfs' ";
  314. if (empty($user["sfs_ONLINE_USER"])) {
  315. $user = $_SESSION["sfs_ONLINE_USER"];
  316. }
  317. $sqlWhere .= self::_airHandNew($user, "sfs");
  318. $sqlWhere .= "))";
  319. // $sqlWhere .= self::_airHandNew($user, $schames);
  320. }
  321. if (strtolower($type) == "air") {
  322. $sqlWhere .= " and ((order_from='public' ";
  323. $sqlWhere .= self::_airHandNew($user, "public");
  324. if ($company_name == "doc") {
  325. if (empty($user["view_file_format"])) {
  326. if (strtolower($user["user_type"]) == "customer") {
  327. $sqlWhere .= " and serial_no in (SELECT serial_no from public.ra_online_file_format where active = true and client_display = true)";
  328. } else {
  329. $sqlWhere .= " and serial_no in (SELECT serial_no from public.ra_online_file_format where active = true)";
  330. }
  331. } else {
  332. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  333. }
  334. }
  335. $sqlWhere .= ") or (order_from='sfs' ";
  336. if (empty($user["sfs_ONLINE_USER"])) {
  337. $user = $_SESSION["sfs_ONLINE_USER"];
  338. }
  339. $sqlWhere .= self::_airHandNew($user, "sfs");
  340. if ($company_name == "doc") {
  341. if (empty($user["view_file_format"])) {
  342. if (strtolower($user["user_type"]) == "customer") {
  343. $sqlWhere .= " and serial_no in (SELECT serial_no from sfs.ra_online_file_format where active = true and client_display = true)";
  344. } else {
  345. $sqlWhere .= " and serial_no in (SELECT serial_no from sfs.ra_online_file_format where active = true)";
  346. }
  347. } else {
  348. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  349. }
  350. }
  351. $sqlWhere .= ") )";
  352. }
  353. } else {
  354. $sqlWhere = " 1<>1";
  355. }
  356. return $sqlWhere;
  357. }
  358. public static function getStatusStage($status) {
  359. if ($status == "EE" || $status == "I") {
  360. return 0;
  361. }
  362. if ($status == "AE" || $status == "VD" || $status == "VA_RELAY" || $status == "UV_RELAY" || $status == "AE_RELAY" || $status == "VD_RELAY") {
  363. return 1;
  364. }
  365. if ($status == "VA" || $status == "UV" || $status == "AL" || $status == "AR" || $status == "CU" || $status == "CT" || $status == "CR" || $status == "OA") {
  366. return 2;
  367. }
  368. if ($status == "AV" || $status == "D" || $status == "RD") {
  369. return 3;
  370. }
  371. return -1;
  372. }
  373. public static function getInNotInSql($contact_id, $type = 'in') {
  374. if (empty($contact_id))
  375. return " =''";
  376. $contact_id = trim($contact_id);
  377. $contact_id = trim($contact_id, ";");
  378. $contact_id = trim($contact_id);
  379. $contact_id = strtolower($contact_id);
  380. if ($type == 'in') {
  381. if (utils::checkExist($contact_id, ";")) {
  382. $ss = "";
  383. $aa = explode(";", $contact_id);
  384. foreach ($aa as $k => $v) {
  385. $v = trim($v);
  386. if (empty($ss))
  387. $ss = "'" . common::check_input($v) . "'";
  388. else
  389. $ss .= ",'" . common::check_input($v) . "'";
  390. }
  391. return " in (" . $ss . ")";
  392. } else {
  393. return " = '" . common::check_input($contact_id) . "'";
  394. }
  395. } else {
  396. if (utils::checkExist($contact_id, ";")) {
  397. $ss = "";
  398. $aa = explode(";", $contact_id);
  399. foreach ($aa as $k => $v) {
  400. $v = trim($v);
  401. if (empty($ss))
  402. $ss = "'" . common::check_input($v) . "'";
  403. else
  404. $ss .= ",'" . common::check_input($v) . "'";
  405. }
  406. return " in (" . $ss . ")";
  407. } else {
  408. return " != '" . common::check_input($contact_id) . "'";
  409. }
  410. }
  411. }
  412. public static function getInNotInSqlForSearch($contact_id, $type = 'in') {
  413. if (empty($contact_id))
  414. return " =''";
  415. $contact_id = trim($contact_id);
  416. $contact_id = trim($contact_id, ";");
  417. $contact_id = trim($contact_id);
  418. $contact_id = strtolower($contact_id);
  419. if ($type == 'in') {
  420. if (utils::checkExist($contact_id, ";")) {
  421. $ss = "";
  422. $aa = explode(";", $contact_id);
  423. foreach ($aa as $k => $v) {
  424. $v = trim($v);
  425. if (empty($ss))
  426. $ss = "'" . common::check_input($v) . "'";
  427. else
  428. $ss .= ",'" . common::check_input($v) . "'";
  429. }
  430. return $ss;
  431. } else {
  432. return "'" . common::check_input($contact_id) . "'";
  433. }
  434. }
  435. }
  436. /*
  437. * Encrypt a SQL query statement used to be passed as a parameter to get excel output
  438. encode :DeCode('str','E');
  439. decode :DeCode('enstr','D');
  440. */
  441. public static function deCode($string, $operation = "E") {
  442. $key = md5("uls_webwms");
  443. $key_length = strlen($key);
  444. if ($operation == "D")
  445. $string = rawurldecode($string);
  446. $string = $operation == 'D' ? base64_decode($string) : substr(md5($string . $key), 0, 8) . $string;
  447. $string_length = strlen($string);
  448. $rndkey = $box = array();
  449. $result = '';
  450. for ($i = 0; $i <= 255; $i++) {
  451. $rndkey [$i] = ord($key [$i % $key_length]);
  452. $box [$i] = $i;
  453. }
  454. for ($j = $i = 0; $i < 256; $i++) {
  455. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  456. $tmp = $box [$i];
  457. $box [$i] = $box [$j];
  458. $box [$j] = $tmp;
  459. }
  460. for ($a = $j = $i = 0; $i < $string_length; $i++) {
  461. $a = ($a + 1) % 256;
  462. $j = ($j + $box [$a]) % 256;
  463. $tmp = $box [$a];
  464. $box [$a] = $box [$j];
  465. $box [$j] = $tmp;
  466. $result .= chr(ord($string [$i]) ^ ($box [($box [$a] + $box [$j]) % 256]));
  467. }
  468. if ($operation == 'D') {
  469. if (substr($result, 0, 8) == substr(md5(substr($result, 8) . $key), 0, 8)) {
  470. return substr($result, 8);
  471. } else {
  472. return '';
  473. }
  474. } else {
  475. return rawurlencode(str_replace('=', '', base64_encode($result)));
  476. }
  477. }
  478. public static function getStatusDesc($code) {
  479. if (strtoupper($code) == "EE") {
  480. return "Empty Equipment Dispatched";
  481. }
  482. if (strtoupper($code) == "I") {
  483. return "Gate in full for a booking";
  484. }
  485. if (strtoupper($code) == "AE") {
  486. return "Container loaded on vessel";
  487. }
  488. if (strtoupper($code) == "VD") {
  489. return "Vessel Departure";
  490. }
  491. if (strtoupper($code) == "VA_RELAY") {
  492. return "Arrive Relay Port";
  493. }
  494. if (strtoupper($code) == "VD_RELAY") {
  495. return "Depart Relay Port";
  496. }
  497. if (strtoupper($code) == "AE_RELAY") {
  498. return "Loaded at Relay Port";
  499. }
  500. if (strtoupper($code) == "UV_RELAY") {
  501. return "Unloaded at Relay Port";
  502. }
  503. if (strtoupper($code) == "VA") {
  504. return "Vessel Arrival";
  505. }
  506. if (strtoupper($code) == "UV") {
  507. return "Unloaded From Vessel";
  508. }
  509. if (strtoupper($code) == "AL") {
  510. return "Container loaded on Rail";
  511. }
  512. if (strtoupper($code) == "AR") {
  513. return "Container unloaded from Rail";
  514. }
  515. if (strtoupper($code) == "CU") {
  516. return "Carrier and Customs Release";
  517. }
  518. if (strtoupper($code) == "CT") {
  519. return "Customs release";
  520. }
  521. if (strtoupper($code) == "CR") {
  522. return "Carrier release";
  523. }
  524. if (strtoupper($code) == "OA") {
  525. return "Gate out full from final discharge port";
  526. }
  527. if (strtoupper($code) == "AV") {
  528. return "Shipment available for pickup or delivery";
  529. }
  530. if (strtoupper($code) == "RD") {
  531. return "Container returned empty";
  532. }
  533. if (strtoupper($code) == "D") {
  534. return "Gate out for delivery to customer";
  535. }
  536. }
  537. public static function _toString($msg) {
  538. if ($msg == "" || $msg == NULL) {
  539. return "";
  540. }
  541. return $msg . "";
  542. }
  543. /*
  544. * timeout output
  545. */
  546. public static function timeoutPrintInfor($httpAccept, $ajax, $login) {
  547. //记录系统因session过期 退出登录
  548. utils::single_operation_log_save("logout","logout","System logout");
  549. $data = array("msg"=>"session_time_out");
  550. self::echo_json_encode(403,$data);
  551. exit();
  552. }
  553. private static function _oceanHandNew($user, $schemas = "public") {
  554. $o = $user['ocean_station'];
  555. $o_or = $user['ocean_station_or'];
  556. $d = $user['ocean_agent'];
  557. $d_or = $user['ocean_agent_or'];
  558. $sales = $user['ocean_sales'];
  559. $sales_or = $user['ocean_sales_or'];
  560. $op = $user['ocean_dest_op'];
  561. $op_or = $user['ocean_dest_op_or'];
  562. $follow = $user['ocean_following_sales'];
  563. $follow_or = $user['ocean_following_sales_or'];
  564. if (strtolower($o_or) == "all" || strtolower($d_or) == "all" || strtolower($sales_or) == "all" || strtolower($op_or) == "all") {
  565. return " and 1=1";
  566. }
  567. $sqlWhere = "";
  568. if (_isCustomerLoginHandNew($user)) {
  569. //error_log("_oceanHandNew".$schemas);
  570. $sqlWhere .= " and " . _customerFilerSearchHandNew($user, $schemas);
  571. } else {
  572. if (empty($o) && empty($d) && empty($sales) && empty($op) && empty($follow)) {
  573. return " and 1<>1";
  574. }
  575. if ((strtolower($o) == 'all' || empty($o)) && (strtolower($d) == "all" || empty($d))) {
  576. } else {
  577. $sql = "1=1";
  578. if (!empty($o) && strtolower($o) != 'all') {
  579. $sql .= " and lower(origin)";
  580. $sql .= utils::getInSql($o);
  581. }
  582. if (!empty($d) && strtolower($d) != 'all') {
  583. $sql .= " and lower(agent)";
  584. $sql .= utils::getInSql($d);
  585. }
  586. $sqlWhere .= " and (" . $sql . ")";
  587. }
  588. if (strtolower($sales) == 'all' || empty($sales)) {
  589. } else {
  590. if (utils::checkExist($sales, ";")) {
  591. $sql = "1!=1";
  592. $tt = explode(";", $sales);
  593. foreach ($tt as $t) {
  594. $t = trim($t);
  595. if (!empty($t))
  596. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  597. }
  598. $sqlWhere .= " and ($sql)";
  599. } else
  600. $sqlWhere .= " and lower(sales_rep)='" . strtolower($sales) . "'";
  601. }
  602. if (strtolower($op) == 'all' || empty($op)) {
  603. } else {
  604. $sqlWhere .= " and lower(dest_op) " . utils::getInSql($op);
  605. }
  606. if (strtolower($follow) == 'all' || empty($follow)) {
  607. } else {
  608. if (utils::checkExist($follow, ";")) {
  609. $sql = "1!=1";
  610. $tt = explode(";", $follow);
  611. foreach ($tt as $t) {
  612. $t = trim($t);
  613. if (!empty($t))
  614. $sql .= " or following_sales ilike '" . $t . "'";
  615. }
  616. $sqlWhere .= " and ($sql)";
  617. } else
  618. $sqlWhere .= " and following_sales ilike '" . $follow . "'";
  619. }
  620. $sqlWhere = " (1=1 $sqlWhere)";
  621. if (!empty($o_or)) {
  622. $sqlWhere .= " or lower(origin)";
  623. $sqlWhere .= utils::getInSql($o_or);
  624. }
  625. if (!empty($d_or)) {
  626. $sqlWhere .= " or lower(agent)";
  627. $sqlWhere .= utils::getInSql($d_or);
  628. }
  629. if (!empty($sales_or)) {
  630. if (utils::checkExist($sales_or, ";")) {
  631. $sql = "1!=1";
  632. $tt = explode(";", $sales_or);
  633. foreach ($tt as $t) {
  634. $t = trim($t);
  635. if (!empty($t))
  636. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  637. }
  638. $sqlWhere .= " or ($sql)";
  639. } else
  640. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales_or) . "'";
  641. }
  642. if (!empty($op_or)) {
  643. $sqlWhere .= " or lower(dest_op) " . utils::getInSql($op_or);
  644. }
  645. if (!empty($follow_or)) {
  646. if (utils::checkExist($follow_or, ";")) {
  647. $sql = "1!=1";
  648. $tt = explode(";", $follow_or);
  649. foreach ($tt as $t) {
  650. $t = trim($t);
  651. if (!empty($t))
  652. $sql .= " or following_sales ilike '" . $t . "'";
  653. }
  654. $sqlWhere .= " or ($sql)";
  655. }else {
  656. $sqlWhere .= " or following_sales ilike '" . $follow_or . "'";
  657. }
  658. }
  659. $sqlWhere = " and ($sqlWhere)";
  660. }
  661. return $sqlWhere;
  662. }
  663. private static function _bookingHandNew($user, $schames) {
  664. // if (_isDemo())
  665. // return " serial_no = 'D4DD1D79-83F4-4E65-9773-CF5277D72738'";
  666. $o = $user['ocean_station'];
  667. $o_or = $user['ocean_station_or'];
  668. $d = $user['ocean_agent'];
  669. $d_or = $user['ocean_agent_or'];
  670. $sales = $user['ocean_sales'];
  671. $sales_or = $user['ocean_sales_or'];
  672. $op = $user['ocean_dest_op'];
  673. $op_or = $user['ocean_dest_op_or'];
  674. $follow = $user['ocean_following_sales'];
  675. $follow_or = $user['ocean_following_sales_or'];
  676. if (strtolower($o_or) == "all" || strtolower($d_or) == "all" || strtolower($sales_or) == "all") {
  677. return " and 1=1";
  678. }
  679. // $sc_list = $user['schemas_list'];
  680. // if (empty($sc_list)) {
  681. // $sc_list = $_SESSION["schemas_list"];
  682. // }
  683. // if (empty($sc_list)) {
  684. // return " and 1<>1";
  685. // }
  686. // $sqlWhere = " and 1=1";
  687. // if ($user["is_kerry_shipment"] == "t") {
  688. // $sqlWhere = " and and is_kerry_shipment is not null and is_kerry_shipment=true";
  689. // } else if ($user["is_kerry_shipment"] == "f") {
  690. // $sqlWhere = " and (is_kerry_shipment is null or is_kerry_shipment=false)";
  691. // }
  692. // if (count($sc_list) == 1) {
  693. // $sch = $sc_list[0]['schemas_name'];
  694. // $sqlWhere .= " and order_from='$sch'";
  695. // } else {
  696. // $sqlWhere .= " and (schem_not_display is null or schem_not_display=false)";
  697. // }
  698. $sqlWhere = "";
  699. if (_isCustomerLoginHandNew($user)) {
  700. $sqlWhere .= " and " . _customerFilerSearchHandNew($user, $schames);
  701. } else {
  702. if (empty($o) && empty($d) && empty($sales) && empty($op) && empty($follow)) {
  703. return " and 1<>1";
  704. }
  705. if ((strtolower($o) == 'all' || empty($o)) && (strtolower($d) == "all" || empty($d))) {
  706. } else {
  707. $sql = "1=1";
  708. if (!empty($o) && strtolower($o) != 'all') {
  709. $sql .= " and lower(origin)";
  710. $sql .= utils::getInSql($o);
  711. }
  712. if (!empty($d) && strtolower($d) != 'all') {
  713. $sql .= " and lower(agent)";
  714. $sql .= utils::getInSql($d);
  715. }
  716. $sqlWhere .= " and (" . $sql . ")";
  717. }
  718. if (strtolower($sales) == 'all' || empty($sales)) {
  719. } else {
  720. if (utils::checkExist($sales, ";")) {
  721. $sql = "1!=1";
  722. $tt = explode(";", $sales);
  723. foreach ($tt as $t) {
  724. $t = trim($t);
  725. if (!empty($t))
  726. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  727. }
  728. $sqlWhere .= " and ($sql)";
  729. } else
  730. $sqlWhere .= " and lower(sales_rep)='" . strtolower($sales) . "'";
  731. }
  732. if (strtolower($follow) == 'all' || empty($follow)) {
  733. } else {
  734. if (utils::checkExist($follow, ";")) {
  735. $sql = "1!=1";
  736. $tt = explode(";", $follow);
  737. foreach ($tt as $t) {
  738. $t = trim($t);
  739. if (!empty($t))
  740. $sql .= " or following_sales ilike '" . $t . "%'";
  741. }
  742. $sqlWhere .= " and ($sql)";
  743. } else
  744. $sqlWhere .= " and following_sales ilike '" . $follow . "%'";
  745. }
  746. $sqlWhere = " (1=1 $sqlWhere)";
  747. if (!empty($o_or)) {
  748. $sqlWhere .= " or lower(origin)";
  749. $sqlWhere .= utils::getInSql($o_or);
  750. }
  751. if (!empty($d_or)) {
  752. $sqlWhere .= " or lower(agent)";
  753. $sqlWhere .= utils::getInSql($d_or);
  754. }
  755. if (!empty($sales_or)) {
  756. if (utils::checkExist($sales_or, ";")) {
  757. $sql = "1!=1";
  758. $tt = explode(";", $sales_or);
  759. foreach ($tt as $t) {
  760. $t = trim($t);
  761. if (!empty($t))
  762. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  763. }
  764. $sqlWhere .= " or ($sql)";
  765. } else
  766. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales_or) . "%'";
  767. }
  768. if (!empty($follow_or)) {
  769. if (utils::checkExist($follow_or, ";")) {
  770. $sql = "1!=1";
  771. $tt = explode(";", $follow_or);
  772. foreach ($tt as $t) {
  773. $t = trim($t);
  774. if (!empty($t))
  775. $sql .= " or following_sales ilike '" . $t . "%'";
  776. }
  777. $sqlWhere .= " or ($sql)";
  778. } else
  779. $sqlWhere .= " or following_sales ilike '" . $follow_or . "%'";
  780. }
  781. $sqlWhere = " and ($sqlWhere)";
  782. }
  783. return $sqlWhere;
  784. }
  785. private static function _airHandNew($user, $schemas = "public")
  786. {
  787. if($schemas=="public")
  788. {
  789. $station = $user['air_station'];
  790. $station_or = $user['air_station_or'];
  791. $sales = $user['air_sales'];
  792. $sales_or = $user['air_sales_or'];
  793. }
  794. else
  795. {
  796. $station = $user[$schemas."_ONLINE_USER"]['air_station'];
  797. $station_or = $user[$schemas."_ONLINE_USER"]['air_station_or'];
  798. $sales = $user[$schemas."_ONLINE_USER"]['air_sales'];
  799. $sales_or = $user[$schemas."_ONLINE_USER"]['air_sales_or'];
  800. }
  801. if (strtolower($station_or) == "all" || strtolower($sales_or) == "all" ) //|| strtolower($d_or) == "all"|| strtolower($op_or) == "all"|| strtolower($follow_or) == "all"
  802. {
  803. return " and 1=1";
  804. }
  805. $sqlWhere = "";
  806. if (_isCustomerLoginHandNew($user)) {
  807. //error_log("_oceanHandNew".$schemas);
  808. $sqlWhere .= " and " . _customerFilerSearchHandNew_Air($user, $schemas);
  809. }
  810. else
  811. {
  812. if (empty($station) && empty($sales) ) //&& empty($d)&& empty($op) && empty($follow)
  813. {
  814. return " and 1<>1";
  815. }
  816. if ((strtolower($station) == 'all' || empty($station)) ) //&& (strtolower($d) == "all" || empty($d))
  817. {
  818. }
  819. else
  820. {
  821. $sql = "1=1";
  822. if (!empty($station) && strtolower($station) != 'all') {
  823. $sql .= " and (lower(origin)";
  824. $sql .= utils::getInSql($station);
  825. $sql .= " or lower(destination_station)";
  826. $sql .= utils::getInSql($station);
  827. $sql .= ")";
  828. }
  829. $sqlWhere .= " and (" . $sql . ")";
  830. }
  831. if (strtolower($sales) == 'all' || empty($sales)) {
  832. } else
  833. {
  834. if (utils::checkExist($sales, ";")) {
  835. $sql = "1!=1";
  836. $tt = explode(";", $sales);
  837. foreach ($tt as $t) {
  838. $t = trim($t);
  839. if (!empty($t))
  840. {
  841. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  842. $sql .= " or lower(following_sales)='" . strtolower($t) . "'";
  843. }
  844. }
  845. $sqlWhere .= " and ($sql)";
  846. } else
  847. {
  848. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales) . "'";
  849. $sqlWhere .= " or lower(following_sales)='" . strtolower($sales) . "'";
  850. }
  851. }
  852. $sqlWhere = " (1=1 $sqlWhere)";
  853. if (!empty($station_or)) {
  854. $sqlWhere .= " or lower(origin)";
  855. $sqlWhere .= utils::getInSql($station_or);
  856. $sqlWhere .= " or lower(destination_station)";
  857. $sqlWhere .= utils::getInSql($station_or);
  858. }
  859. if (!empty($sales_or)) {
  860. if (utils::checkExist($sales_or, ";")) {
  861. $sql = "1!=1";
  862. $tt = explode(";", $sales_or);
  863. foreach ($tt as $t) {
  864. $t = trim($t);
  865. if (!empty($t))
  866. {
  867. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  868. $sql .= " or lower(following_sales)='" . strtolower($t) . "'";
  869. }
  870. }
  871. $sqlWhere .= " or ($sql)";
  872. } else
  873. {
  874. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales_or) . "'";
  875. $sqlWhere .= " or lower(following_sales)='" . strtolower($sales_or) . "'";
  876. }
  877. }
  878. $sqlWhere = " and ($sqlWhere)";
  879. }
  880. return $sqlWhere;
  881. }
  882. public static function isNewVersion() {
  883. if (utils::checkExist($_SERVER['PHP_SELF'], "main_new_version.php")) {
  884. return "_new";
  885. }
  886. return "";
  887. }
  888. public static function removeTopOceanOldVersionSpecialField($rss){
  889. $rss_bk = $rss;
  890. $new_arr = array();
  891. foreach ($rss_bk as $k => $v) {
  892. if (utils::startWith($v['database_column_name'], "__") || utils::startWith($v['database_column_name'], "___")){
  893. //unset($rss[$k]);
  894. }else{
  895. $new_arr[] = $v;
  896. }
  897. }
  898. return $new_arr;
  899. }
  900. public static function echo_json_encode($code,$data){
  901. $resData = array();
  902. $resData["code"] = $code;
  903. $resData["data"] =$data;
  904. //echo utils::jsonFiltration("null", "\"\"", json_encode($resData));
  905. echo json_encode($resData);
  906. }
  907. /*
  908. * MM/DD/YYYY To YYYY-MM-DD
  909. */
  910. public static function usDate2sqlDate($timestr) {
  911. if (empty($timestr))
  912. return '';
  913. $datearray = explode("/", $timestr);
  914. $m = $datearray [0];
  915. $d = $datearray [1];
  916. $y = $datearray [2];
  917. return $y . "-" . $m . "-" . $d;
  918. }
  919. public static function uuid() {
  920. return md5(uniqid("", TRUE) . mt_rand());
  921. }
  922. /*
  923. * YYYYMMDD To MM/DD/YYYY
  924. */
  925. public static function date2usdate($datestr) {
  926. if (empty($datestr))
  927. return '';
  928. $y = substr($datestr, 0, 4);
  929. $m = substr($datestr, 4, 2);
  930. $d = substr($datestr, 6, 2);
  931. return $m . "/" . $d . "/" . $y;
  932. }
  933. /*
  934. * date add some days
  935. */
  936. public static function addDays($date, $days) {
  937. $time = strtotime($date) + $days * 24 * 3600;
  938. return date('m/d/Y', $time);
  939. }
  940. /*
  941. * download file from file system
  942. */
  943. public static function download_file($filename, $display_name = null, $delete = FALSE, $files = NULL) {
  944. $filename = str_replace("/", DIRECTORY_SEPARATOR, $filename);
  945. $filename = str_replace("\\", DIRECTORY_SEPARATOR, $filename);
  946. if (!file_exists($filename))
  947. exit('File Not Exist');
  948. if (empty($display_name))
  949. $display_name = basename($filename);
  950. //$file = fopen($filename, "r");
  951. header_remove("Content-type");
  952. header("Content-type:" . self::getContentType($filename));
  953. header("Expires: 0");
  954. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  955. header("Pragma: can-cache");
  956. header("Accept-ranges:bytes");
  957. header("Accept-length:" . filesize($filename));
  958. header("Content-Disposition:attachment;filename=\"" . $display_name . "\"");
  959. //echo fread($file, filesize($filename));
  960. //fclose($file);
  961. //针对大文件,规定每次读取文件的字节数为4096字节,直接输出数据
  962. $read_buffer = 4096;
  963. $handle = fopen($filename, 'rb');
  964. //总的缓冲的字节数
  965. $sum_buffer = 0;
  966. $filesize = filesize($filename);
  967. //只要没到文件尾,就一直读取
  968. while (!feof($handle) && $sum_buffer < $filesize) {
  969. echo fread($handle, $read_buffer);
  970. $sum_buffer += $read_buffer;
  971. }
  972. //关闭句柄
  973. fclose($handle);
  974. if ($delete !== FALSE) {
  975. unlink($filename);
  976. }
  977. if (!empty($files)) {
  978. foreach ($files as $f) {
  979. unlink($f);
  980. }
  981. }
  982. }
  983. public static function getContentType($filename) {
  984. $extend = self::getExtendFilename($filename);
  985. $filetype = array(
  986. 'xls' => 'application/vnd.ms-excel',
  987. 'doc' => 'application/msword',
  988. 'gif' => 'image/gif',
  989. 'jpg' => 'image/jpeg',
  990. 'jpeg' => 'image/jpeg',
  991. 'jpe' => 'image/jpeg',
  992. 'bmp' => 'image/bmp',
  993. 'png' => 'image/png',
  994. 'tif' => 'image/tiff',
  995. 'pdf' => 'application/pdf',
  996. 'zip' => 'application/zip'
  997. );
  998. return $filetype[$extend];
  999. }
  1000. /*
  1001. * Get the file extension
  1002. */
  1003. public static function getExtendFilename($file_name) {
  1004. $extend = pathinfo($file_name);
  1005. $extend = strtolower($extend["extension"]);
  1006. return $extend;
  1007. }
  1008. public static function getManagement(){
  1009. //Management 自己配置需要创建表保存
  1010. $user_management_data = common::excuteObjectSql("select management,dashboard_filter from ra_online_user where user_login = '"._getLoginName()."'");
  1011. //为空,配置使用默认值
  1012. $user_management = $user_management_data['management'];
  1013. if(empty($user_management)){
  1014. $Management = common::getdefaultManagement();
  1015. }else{
  1016. $Management = json_decode($user_management,true);
  1017. foreach($Management as $key =>$val){
  1018. $Management[$key]['id'] = intval($val['id']);
  1019. $Management[$key]['switchValue'] = $val['switchValue'] == "true" ? true : false;
  1020. }
  1021. }
  1022. $user_dashboard_filter = $user_management_data['dashboard_filter'];
  1023. $dashboard_filter =array();
  1024. if(!empty($user_dashboard_filter)){
  1025. $dashboard_filter = json_decode($user_dashboard_filter,true);
  1026. if(!empty($dashboard_filter['date_end'])){
  1027. $dashboard_filter['date_end'] = common::usDate2sqlDate($dashboard_filter['date_end']);
  1028. }
  1029. if(!empty($dashboard_filter['date_start'])){
  1030. $dashboard_filter['date_start'] = common::usDate2sqlDate($dashboard_filter['date_start']);
  1031. }
  1032. }
  1033. return array("Management" => $Management,"dashboard_filter" =>$dashboard_filter);
  1034. }
  1035. public static function getItemStyle($type,$code){
  1036. if($type == 'r1'){
  1037. $data = array("0-20 Days" =>"#ffc594",
  1038. "20-40 Days" =>"#ff9e4c",
  1039. "40-60 Days" =>"#ff7500",
  1040. "60-80 Days" =>"#ff3d00",
  1041. "Over 80 Days" =>"#d50000");
  1042. return $data[$code];
  1043. }
  1044. if($type == 'r4' || $type == 'r3' || $type == 'atd_r4' || $type == 'ata_r3'){
  1045. $data = array("0 Day" =>"#ffc594",
  1046. "Today" =>"#ffc594",
  1047. "1-2 Days" =>"#ff9e4c",
  1048. "3-6 Days" =>"#ff7500",
  1049. "7 Days" =>"#ff3d00");
  1050. return $data[$code];
  1051. }
  1052. if($type == 'r2' || utils::startWith($type,"co2e")){
  1053. $data = array("45" =>"#FFE3CC",
  1054. "40" =>"#FFAC66",
  1055. "20" =>"#FF7500",
  1056. "air" =>"#FFE3CC",
  1057. "sea" =>"#FFAC66",
  1058. "road" =>"#FF7500");
  1059. return $data[$code];
  1060. }
  1061. if($type == "top"){
  1062. $data = array("1" =>"#FF7500",
  1063. "2" =>"#ff9033",
  1064. "3" =>"#ff9e4d",
  1065. "4" =>"#ffac66",
  1066. "5" =>"#ffba80",
  1067. "6" =>"#ffc899",
  1068. "7" =>"#ffd6b3",
  1069. "8" =>"#ffe3cc",
  1070. "9" =>"#fff1e6",
  1071. "10" =>"#fff1e6");
  1072. return $data[$code];
  1073. }
  1074. }
  1075. //处理返回原表数据格式
  1076. public static function mian_repot_do($value,$type,$totalValue){
  1077. $data = array();
  1078. $value_arr = json_decode($value,true);
  1079. //r1 是 ETD to ETA (Days)圆形图表数据结构返回
  1080. if($type == 'r1'){
  1081. $ETDList = array();
  1082. foreach($value_arr as $arr){
  1083. $color = common::getItemStyle($type,$arr['name']);
  1084. $ETDList[] = array("value" =>intval($arr['value']),"name" =>$arr['name'],"itemStyle" =>array("color" =>$color));
  1085. }
  1086. $ETDList = array_reverse($ETDList);
  1087. $ETD_Title = "Total: $totalValue";
  1088. $data = array("ETDList" =>$ETDList,"ETD_Radius"=>array('50%','80%'),"ETD_Title" =>$ETD_Title,"download_name" => "ETD to ETA (Days)");
  1089. }
  1090. if($type == 'r4' || $type == 'r3'){
  1091. //重新整理一下数据,给UI一致
  1092. $data_kd = array();
  1093. foreach($value_arr as $arr){
  1094. if(stripos("Today", $arr['name']) !== false){
  1095. $color = common::getItemStyle($type,"Today");
  1096. if(empty($data_kd["0"])){
  1097. $data_kd["0"] = array("value" =>intval($arr['value']),"name" =>"≤1 Day","itemStyle" =>array("color" =>$color));
  1098. }else{
  1099. $data_kd["0"]["value"] = $data_kd["0"]["value"] + intval($arr['value']);
  1100. }
  1101. }
  1102. if(stripos("+1 Days/+2 Days", $arr['name']) !== false){
  1103. $color = common::getItemStyle($type,"1-2 Days");
  1104. if(empty($data_kd["1"])){
  1105. $data_kd["1"] = array("value" =>intval($arr['value']),"name" =>"1-2 Days","itemStyle" =>array("color" =>$color));
  1106. }else{
  1107. $data_kd["1"]["value"] = $data_kd["1"]["value"] + intval($arr['value']);
  1108. }
  1109. }
  1110. if(stripos("+3 Days/+4 Days/+5 Days/+6 Days", $arr['name']) !== false){
  1111. $color = common::getItemStyle($type,"3-6 Days");
  1112. if(empty($data_kd["2"])){
  1113. $data_kd["2"] = array("value" =>intval($arr['value']),"name" =>"3-6 Days","itemStyle" =>array("color" =>$color));
  1114. }else{
  1115. $data_kd["2"]["value"] = $data_kd["2"]["value"] + intval($arr['value']);
  1116. }
  1117. }
  1118. if(stripos("+7 Days/Over 7 Days", $arr['name']) !== false){
  1119. $color = common::getItemStyle($type,"7 Days");
  1120. if(empty($data_kd["3"])){
  1121. $data_kd["3"] = array("value" =>intval($arr['value']),"name" =>"≥7 Days","itemStyle" =>array("color" =>$color));
  1122. }else{
  1123. $data_kd["3"]["value"] = $data_kd["3"]["value"] + intval($arr['value']);
  1124. }
  1125. }
  1126. }
  1127. if($type == 'r4'){
  1128. $data = array("ETDList" =>$data_kd,"ETD_Radius"=>array('30%','50%'),"title1" =>"Departure","title2" =>"","download_name" => "Pending Departure");
  1129. }
  1130. if($type == 'r3'){
  1131. $data = array("ETDList" =>$data_kd,"ETD_Radius"=>array('30%','50%'),"title1" =>"Arrival","title2" =>"","download_name" => "Pending Arrival");
  1132. }
  1133. }
  1134. return $data;
  1135. }
  1136. //单独处理co2e bar
  1137. public static function getCo2eBar(){
  1138. //新UI air sea road 目前只有sea
  1139. $type = $_REQUEST["r_type"];
  1140. $shipment_mode_arr = array("air","sea","road");
  1141. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  1142. $sqlWhere = " " . $sqlWhere;
  1143. $ContainerCount_Title = array();
  1144. //先查询总的排放量sea air road,确定排名后,在分别查询对应的sea air road
  1145. if ($type == "co2e_orgin"){
  1146. $co2e_shippr_sql = "select SUM(COALESCE(carbon_emission,0)::numeric(12,10)) as catnum ,
  1147. shippr_uncode as station from online_ocean where 1=1 and COALESCE(shippr_uncode,'')<>'' $sqlWhere group by shippr_uncode order by catnum desc limit 10";
  1148. $co2e_aLL = common::excuteListSql($co2e_shippr_sql);
  1149. }
  1150. if ($type == "co2e_destination"){
  1151. $co2e_consignee_sql = "select SUM(COALESCE(carbon_emission,0)::numeric(12,10)) as catnum,
  1152. consignee_uncode as station from online_ocean where 1=1 and COALESCE(consignee_uncode,'')<>'' $sqlWhere group by consignee_uncode order by catnum desc limit 10";
  1153. $co2e_aLL = common::excuteListSql($co2e_consignee_sql);
  1154. }
  1155. //最大Y值
  1156. $maxY = 0;
  1157. $stations = array();
  1158. foreach($co2e_aLL as $val){
  1159. $ContainerCount_Title[] = $val['station'];
  1160. $maxY = $maxY > $val['catnum'] ? $maxY : $val['catnum'];
  1161. $stations[] = $val['station'];
  1162. }
  1163. $station_str = utils::implode(',',$stations);
  1164. $ContainerCounSeries = array();
  1165. foreach($shipment_mode_arr as $_shipment_mode){
  1166. //类型有 sea air road,目前之类只查询sea的,其他为空
  1167. $shipment_mode = $_shipment_mode;
  1168. $co2e = array();
  1169. if ($type == "co2e_orgin"){
  1170. $co2e_shippr_sql_union = utils::_getSql($station_str,$type,$shipment_mode);
  1171. if(!empty($co2e_shippr_sql_union)){
  1172. $co2e = common::excuteListSql($co2e_shippr_sql_union);
  1173. }
  1174. $download_name = "CO2e Emission by Origin (Top 10)";
  1175. }
  1176. if ($type == "co2e_destination"){
  1177. $co2e_consignee_union = utils::_getSql($station_str,$type,$shipment_mode);
  1178. if(!empty($co2e_consignee_union)){
  1179. $co2e = common::excuteListSql($co2e_consignee_union);
  1180. }
  1181. $download_name = "CO2e Emission by Destination (Top 10)";
  1182. }
  1183. $total = 0;
  1184. $max = 0;
  1185. $data = array();
  1186. foreach($co2e as $val){
  1187. $data[] = $val['catnum'];
  1188. $total = $total + $val['catnum'];
  1189. $max = $max < $val['catnum'] ? $val['catnum'] : $max;
  1190. }
  1191. $ContainerCounSeries[$shipment_mode] = array("data"=>$data,"total"=>$total,"max"=>$max);
  1192. }
  1193. //处理返回时数据格式 其实不太需要计算最大值,在最开始总量查询的时候以及查询出来
  1194. $ContainerCounSeries_return = array();
  1195. foreach($ContainerCounSeries as $k =>$v){
  1196. $color = common::getItemStyle($type,$k);
  1197. $ContainerCounSeries_return[] = array("name"=>$k,"type"=>"bar","emphasis" => array("focus" =>"none"),
  1198. "stack" =>"总计","data" =>$v['data'],"itemStyle" =>array("color" =>$color));
  1199. }
  1200. //处理返回原表数据格式
  1201. //计算刻度值 最小值是0,最大值是3000,刻度是500 interval
  1202. $interval = utils::calculateTicks(0,$maxY,10);
  1203. if($interval == 0){
  1204. //处理返回默认值
  1205. $interval = 1;
  1206. }
  1207. $returnData = array("ContainerCount_Title"=>"","ContainerCountList" =>$ContainerCount_Title,"ContainerCounSeries" =>$ContainerCounSeries_return,
  1208. "min" => 0,"Max" =>$interval*10,"interval" =>$interval,"download_name" => $download_name);
  1209. return $returnData;
  1210. }
  1211. public static function getTopBar(){
  1212. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  1213. $sqlWhere = " " . $sqlWhere;
  1214. $toporiginType = "shippr_uncode";
  1215. $shippr_uncode_10_sql ="with aa as (select count(shippr_uncode) as num,shippr_uncode,
  1216. (array_agg(shipper_city))[1] AS shipper_city from online_ocean
  1217. where 1=1 and COALESCE(shippr_uncode,'')<>'' $sqlWhere group by shippr_uncode order by num desc limit 10)
  1218. select aa.*,dd.* from aa
  1219. left join LATERAL ( select lon as lng, lat as lat,
  1220. '' as label, '' as infor, 3 as sort,
  1221. null::timestamp without time zone as stime,''::text as ptype
  1222. from vessel.vt_unlocode where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=aa.shippr_uncode ) dd on true";
  1223. $shippr_uncode_10 = common::excuteListSql($shippr_uncode_10_sql);
  1224. //如果值没有:客户地址-->站点地址-->Port地址(POL/POD)
  1225. if(count($shippr_uncode_10) == 1 && empty($shippr_uncode_10[0]["shippr_uncode"])){
  1226. $toporiginType = "fport_of_loading_un";
  1227. $shippr_uncode_10_sql = "with aa as (select count(fport_of_loading_un) as num,fport_of_loading_un as shippr_uncode
  1228. from online_ocean where 1=1 and COALESCE(fport_of_loading_un,'')<>'' $sqlWhere group by fport_of_loading_un order by num desc limit 10)
  1229. select aa.*,dd.* from aa
  1230. left join LATERAL ( select lon as lng, lat as lat,
  1231. '' as label, '' as infor, 3 as sort,
  1232. null::timestamp without time zone as stime,''::text as ptype
  1233. from vessel.vt_unlocode where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=aa.fport_of_loading_un ) dd on true";
  1234. $shippr_uncode_10 = common::excuteListSql($shippr_uncode_10_sql);
  1235. }
  1236. //$toporiginType = "fport_of_loading_un";
  1237. $topdestinationinType = "consignee_uncode";
  1238. $consignee_uncode_10_sql = "with aa as (select count(consignee_uncode) as num,consignee_uncode,
  1239. (array_agg(consignee_city))[1] AS consignee_city
  1240. from online_ocean where 1=1 and COALESCE(consignee_uncode,'')<>'' $sqlWhere group by consignee_uncode order by num desc limit 10)
  1241. select aa.*,dd.* from aa
  1242. left join LATERAL ( select lon as lng, lat as lat,
  1243. '' as label, '' as infor, 3 as sort,
  1244. null::timestamp without time zone as stime,''::text as ptype
  1245. from vessel.vt_unlocode where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=aa.consignee_uncode ) dd on true";
  1246. $consignee_uncode_10 = common::excuteListSql($consignee_uncode_10_sql);
  1247. //如果值没有:客户地址-->站点地址-->Port地址(POL/POD)
  1248. if(count($consignee_uncode_10) == 1 && empty($consignee_uncode_10[0]["consignee_uncode"])){
  1249. $topdestinationinType = "mport_of_discharge_un";
  1250. $consignee_uncode_10_sql = "with aa as (select count(mport_of_discharge_un) as num,mport_of_discharge_un as consignee_uncode from online_ocean where 1=1 and COALESCE(mport_of_discharge_un,'')<>'' $sqlWhere group by mport_of_discharge_un order by num desc limit 10)
  1251. select aa.*,dd.* from aa
  1252. left join LATERAL ( select lon as lng, lat as lat,
  1253. '' as label, '' as infor, 3 as sort,
  1254. null::timestamp without time zone as stime,''::text as ptype
  1255. from vessel.vt_unlocode where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=aa.mport_of_discharge_un ) dd on true";
  1256. $consignee_uncode_10 = common::excuteListSql($consignee_uncode_10_sql);
  1257. }
  1258. $toporigin = array();
  1259. $toporiginMap = array();
  1260. $i = 0;
  1261. $origiNunMax = 0;
  1262. foreach($shippr_uncode_10 as $orgin){
  1263. $i = $i + 1;
  1264. $map = array();
  1265. if(!empty($orgin['lat'])&&!empty($orgin['lng'])){
  1266. $map = array("lat" =>$orgin['lat'],"lng" =>$orgin['lng']);
  1267. }
  1268. //$json = '{"lng":121.8525,"lat":29.926545,"label":"'.$orgin['origin'].'","infor":"LAT KRABANG, THAILAND","sort":"0","stime":null,"ptype":"por"}';
  1269. //$map = json_decode($json,true);
  1270. if(!empty($map)){
  1271. $toporiginMap[] = array("qandl"=>array(floatval($map['lat']),floatval($map['lng'])),
  1272. "divIcon" => array("iconSize"=>0),
  1273. "name" =>$orgin['shippr_uncode'],
  1274. "color" =>common::getItemStyle("top",$i),
  1275. "value" =>$orgin['num'],
  1276. "textcolor" =>"#FFF");
  1277. }
  1278. //查询uncode,对应的city
  1279. $city = "";
  1280. if($toporiginType == "shippr_uncode"){
  1281. $city = $orgin['shipper_city'];
  1282. }
  1283. //$city 做假数据
  1284. $toporigin[] = array("name"=>$orgin['shippr_uncode'],"city_name"=>$city,"value"=>$orgin['num'],"color"=>common::getItemStyle("top",$i));
  1285. $origiNunMax = $origiNunMax < $orgin['num'] ? $orgin['num'] : $origiNunMax;
  1286. }
  1287. $topdestination = array();
  1288. $topdestinationinMap = array();
  1289. $i = 0;
  1290. $agentiNunMax = 0;
  1291. foreach($consignee_uncode_10 as $agent){
  1292. $i = $i + 1;
  1293. $map = array();
  1294. if(!empty($agent['lat'])&&!empty($agent['lng'])){
  1295. $map = array("lat" =>$agent['lat'],"lng" =>$agent['lng']);
  1296. }
  1297. // $json = '{"lng":"100.78594000","lat":"13.68521000","label":"'.$agent['agent'].'","infor":"LAT KRABANG, THAILAND","sort":"0","stime":null,"ptype":"por"}';
  1298. // $map = json_decode($json,true);
  1299. if(!empty($map)){
  1300. $topdestinationinMap[] = array("qandl"=>array(floatval($map['lat']),floatval($map['lng'])),
  1301. "divIcon" => array("iconSize"=>0),
  1302. "name" =>$agent['consignee_uncode'],
  1303. "color" =>common::getItemStyle("top",$i),
  1304. "value" =>$agent['num'],
  1305. "textcolor" =>"#FFF");
  1306. }
  1307. //查询uncode,对应的city
  1308. $city = "";
  1309. if($topdestinationinType == "consignee_uncode"){
  1310. $city = $agent['consignee_city'];
  1311. }
  1312. //$city 做假数据
  1313. $topdestination[] = array("name"=>$agent['consignee_uncode'],"city_name"=>$city,"value"=>$agent['num'],"color"=>common::getItemStyle("top",$i));
  1314. $agentiNunMax = $agentiNunMax < $agent['num'] ? $agent['num'] : $agentiNunMax;
  1315. }
  1316. //处理返回原表数据格式
  1317. $interval = utils::calculateTicks(0,$origiNunMax,10);
  1318. if($interval == 0){
  1319. //处理返回默认值
  1320. $interval = 1;
  1321. }
  1322. $dest_interval = utils::calculateTicks(0,$agentiNunMax,10);
  1323. if($dest_interval == 0){
  1324. //处理返回默认值
  1325. $dest_interval = 1;
  1326. }
  1327. $returnData = array("seller_data_list_origin"=>$toporigin,"toporiginMap"=>array_reverse($toporiginMap),"toporiginType"=>$toporiginType,
  1328. "seller_data_list_destination"=>$topdestination,"topdestinationinMap"=>array_reverse($topdestinationinMap),"topdestinationinType"=>$topdestinationinType,
  1329. "min" => 0,"Max" =>$interval*10,"interval" =>$interval,
  1330. "dest_min" => 0,"dest_Max" =>$dest_interval*10,"dest_interval" =>$dest_interval);
  1331. return $returnData;
  1332. }
  1333. public static function getdefaultManagement(){
  1334. $Management = array();
  1335. $Management[] = array("id"=>1 ,
  1336. "title"=>"KPI",
  1337. "switchValue"=>true,
  1338. "text"=>"Pie chart showing figures of shipments KPI of Departure and Arrival.");
  1339. $Management[] = array("id"=>2 ,
  1340. "title"=>"Pending",
  1341. "switchValue"=>true,
  1342. "text"=>"Pie chart showing figures of shipments which are soon to depart/arrive (Calculated from ETD/ETA).");
  1343. $Management[] = array("id"=>3 ,
  1344. "title"=>"Recent Status",
  1345. "switchValue"=>true,
  1346. "text"=>"A shipment list with latest status update on top.");
  1347. $Management[] = array("id"=>4 ,
  1348. "title"=>"ETD to ETA (Days)",
  1349. "switchValue"=>true,
  1350. "text"=>"Pie chart showing figures of shipments which are soon to depart/arrive (Calculated from ETD/ETA).");
  1351. $Management[] = array("id"=>5 ,
  1352. "title"=>"Container Count",
  1353. "switchValue"=>true,
  1354. "text"=>"Pie chart showing figures of shipments which are soon to depart/arrive (Calculated from ETD/ETA).");
  1355. $Management[] = array("id"=>6 ,
  1356. "title"=>"Top 10 Origin/Destination",
  1357. "switchValue"=>true,
  1358. "text"=>"Figure of the top 10 origin/destination.",
  1359. "title1"=>"Top 10 Origin",
  1360. "title2"=>"Top 10 Destination");
  1361. $Management[] = array("id"=>7 ,
  1362. "title"=>"CO2e Emission by Origin (Top 10)",
  1363. "switchValue"=>true,
  1364. "text"=>"Figure of the CO2e Emission by origin.");
  1365. $Management[] = array("id"=>8 ,
  1366. "title"=>"CO2e Emission by Destination (Top 10)",
  1367. "switchValue"=>true,
  1368. "text"=>"Figure of the CO2e Emission by destination.");
  1369. return $Management;
  1370. }
  1371. /**
  1372. * Destroy Session
  1373. */
  1374. public static function sessionDestroy() {
  1375. session_destroy();
  1376. setcookie(session_name(), '', time() - 3600);
  1377. $_SESSION = array();
  1378. }
  1379. public static function retStationInfo($address_1,$address_2,$address_3,$address_4,$city,$state,$country,$zipcode){
  1380. $stationInfo = "";
  1381. if(!empty($address_1)){
  1382. $stationInfo .= $address_1;
  1383. }
  1384. if(!empty($address_2)){
  1385. $stationInfo .= " ".$address_2;
  1386. }
  1387. if(!empty($address_3)){
  1388. $stationInfo .= " ".$address_3;
  1389. }
  1390. if(!empty($address_4)){
  1391. $stationInfo .= " ".$address_4;
  1392. }
  1393. $temp_str = "";
  1394. if(!empty($city)){
  1395. $temp_str .= $city." ";
  1396. }
  1397. if(!empty($state)){
  1398. $temp_str .= $state." ";
  1399. }
  1400. if(!empty($zipcode)){
  1401. $temp_str .= $zipcode." ";
  1402. }
  1403. if(!empty($country)){
  1404. $temp_str .= $country." ";
  1405. }
  1406. if(!empty($temp_str)){
  1407. return $stationInfo." ".trim($temp_str);
  1408. }
  1409. return $stationInfo;
  1410. }
  1411. public static function getInsertSqlNull($table_name, $values) {
  1412. $field = "";
  1413. $value = "";
  1414. foreach ($values as $k => $v) {
  1415. if ($k == 'tmp' || $k == 'action' || $k == 'operate' || $k == 'x' || $k == 'y') {
  1416. continue;
  1417. }
  1418. if (is_array($v)) {
  1419. $v = utils::implode(",", $v);
  1420. }
  1421. if (empty($field)) {
  1422. $field = $k;
  1423. if (utils::checkExist($v, 'now()')) {
  1424. $value = $v;
  1425. } elseif ($v == null) {
  1426. $value .= 'null';
  1427. } elseif ($v == 'TRUE' || $v == 'FALSE') {
  1428. $value .= $v;
  1429. } else {
  1430. $value = '\'' . common::check_input($v) . '\'';
  1431. }
  1432. } else {
  1433. $field .= ',' . $k;
  1434. if (utils::checkExist($v, 'now()'))
  1435. $value .= ', now()';
  1436. elseif ($v == null) {
  1437. $value .= ',null';
  1438. } else if ($v == 'TRUE' || $v == 'FALSE') {
  1439. $value .= ',' . $v;
  1440. } else {
  1441. $value .= ', \'' . common::check_input($v) . '\'';
  1442. }
  1443. }
  1444. }
  1445. return 'insert into ' . $table_name . '(' . $field . ') values (' . $value . ')';
  1446. }
  1447. //密码规则验证
  1448. public static function checkPasswordRule($login, $new_password){
  1449. $sql="select item_value from config where item='passwordCheckRules'";
  1450. $rs = common::excuteObjectSql($sql);
  1451. $str = "";
  1452. if (!empty($rs)) {
  1453. $passwordCheckRules = json_decode($rs["item_value"],true);
  1454. //校验使用次数
  1455. if (!empty($passwordCheckRules["pastPasswordCheckNum"])) {
  1456. $sql = "select password from public.ra_online_user_password_history where lower(user_login)='".common::check_input(strtolower($login))."' order by id desc limit ".$passwordCheckRules["pastPasswordCheckNum"];
  1457. $passwords = common::excuteListSql($sql);
  1458. foreach ($passwords as $pwd) {
  1459. if ($pwd['password'] == $new_password) {
  1460. $str = "This password has been recently used";
  1461. }
  1462. }
  1463. }
  1464. if(empty($str)){
  1465. $str = utils::checkPassword($new_password,$passwordCheckRules,$login);
  1466. }
  1467. }else{
  1468. $str = utils::checkPassword($new_password);
  1469. }
  1470. return $str;
  1471. }
  1472. public static function getMilestonesInfo($ocean,$EDI315TimeAndLocation){
  1473. //Milestones info列名固定
  1474. $Milestones_column = array();
  1475. $Milestones_column[] = array("title" =>"Milestones","field" =>"milestones","formatter" =>"normal","type" =>"normal");
  1476. $Milestones_column[] = array("title" =>"Date Time","field" =>"date_time","formatter" =>"dateTime","type" =>"normal");
  1477. $Milestones_column[] = array("title" =>"Locations","field" =>"locations","formatter" =>"normal","type" =>"normal");
  1478. $Milestones_column[] = array("title" =>"Remarks","field" =>"remarks","formatter" =>"normal","type" =>"normal");
  1479. //EDI315 有关联查询,以那个为准。但是如果是手工录入或者不是EDI 进去的Milestone的情况,这以这个为准
  1480. $Milestones_NO_Mapping = common::getMilestones_NO_Mapping_Data($ocean);
  1481. //Milestones 数据信息待定
  1482. $Milestones_data = array();
  1483. $Milestones_data_arr = common::excuteListSql("select sn.description,act_date||' '||COALESCE(act_time,'') as date_time,
  1484. remark,timezone,a.code
  1485. from ocean_milestone a
  1486. inner join customer_service_milestone_sno sn on sn.code=a.code
  1487. where a.serial_no='".$ocean["serial_no"]."' and act_date is not null order by sn.sno asc");
  1488. foreach($Milestones_data_arr as $mda){
  1489. $locations = "";
  1490. $timezone = "";
  1491. if(!empty($EDI315TimeAndLocation[$mda['code']])){
  1492. $edi315Info = $EDI315TimeAndLocation[$mda['code']];
  1493. if(!empty($edi315Info)){
  1494. $locations = $edi315Info['location'];
  1495. $timezone = $edi315Info['timezone'];
  1496. }
  1497. }else{
  1498. $edi315Info = $Milestones_NO_Mapping[$mda['code']];
  1499. if(!empty($edi315Info)){
  1500. $locations = $edi315Info['location'];
  1501. $timezone = $edi315Info['timezone'];
  1502. }
  1503. }
  1504. $Milestones_data[] = array("milestones"=>$mda['description'],"date_time"=>$mda['date_time'],"timezone" =>$timezone,
  1505. "locations" => $locations, "remarks" =>$mda['remark']);
  1506. }
  1507. $Milestones = array("Milestones_column"=>$Milestones_column,"Milestones_data" =>$Milestones_data);
  1508. return $Milestones;
  1509. }
  1510. /**
  1511. * 查询uncode 对应的时区
  1512. */
  1513. public static function getCityPortsInfo($uncodes){
  1514. $data =array();
  1515. $sql = "select time_zone as timezonecode,uncode as ctrycitycode from public.city_timezone where lower(uncode) ". common::getInNotInSql($uncodes);
  1516. $uncode_rs = common::excuteListSql($sql);
  1517. foreach($uncode_rs as $value){
  1518. $data[$value['ctrycitycode']] = $value['timezonecode'];
  1519. }
  1520. return $data;
  1521. }
  1522. /**
  1523. * EDI315 有关联查询,以那个为准。但是如果是手工录入或者没有对应的情况,这以这个为准
  1524. */
  1525. public static function getMilestones_NO_Mapping_Data($ocean){
  1526. $Milestones_NO_Mapping = array();
  1527. //取origin
  1528. $Milestones_NO_Mapping['IFFBCF'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>$ocean['aa_city']);
  1529. $Milestones_NO_Mapping['IFFBCR'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>$ocean['aa_city']);
  1530. $Milestones_NO_Mapping['IFFSIL'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>$ocean['aa_city']);
  1531. $Milestones_NO_Mapping['IFFEDO'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>$ocean['aa_city']);
  1532. $Milestones_NO_Mapping['IFFECC'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>$ocean['aa_city']);
  1533. //取 1:Place of Receipt 2:Port of Loading
  1534. if(!empty($ocean['por_uncity'])){
  1535. $Milestones_NO_Mapping['IFFREC'] = array("code"=>"por/pol","timezone"=>$ocean['por_timezone'],"location"=>$ocean['por_uncity']);
  1536. $Milestones_NO_Mapping['IFFONB'] = array("code"=>"por/pol","timezone"=>$ocean['por_timezone'],"location"=>$ocean['por_uncity']);
  1537. $Milestones_NO_Mapping['IFFDEP'] = array("code"=>"por/pol","timezone"=>$ocean['por_timezone'],"location"=>$ocean['por_uncity']);
  1538. $Milestones_NO_Mapping['IFFECP'] = array("code"=>"por/pol","timezone"=>$ocean['por_timezone'],"location"=>$ocean['por_uncity']);
  1539. }else{
  1540. $Milestones_NO_Mapping['IFFREC'] = array("code"=>"por/pol","timezone"=>$ocean['pol_timezone'],"location"=>$ocean['pol_uncity']);
  1541. $Milestones_NO_Mapping['IFFONB'] = array("code"=>"por/pol","timezone"=>$ocean['pol_timezone'],"location"=>$ocean['pol_uncity']);
  1542. $Milestones_NO_Mapping['IFFDEP'] = array("code"=>"por/pol","timezone"=>$ocean['pol_timezone'],"location"=>$ocean['pol_uncity']);
  1543. $Milestones_NO_Mapping['IFFECP'] = array("code"=>"por/pol","timezone"=>$ocean['por_timezone'],"location"=>$ocean['por_uncity']);
  1544. }
  1545. //取destination
  1546. $Milestones_NO_Mapping['IFFCSN'] = array("code"=>"destination","timezone"=>$ocean['dd_timezone'],"location"=>$ocean['dd_city']);
  1547. $Milestones_NO_Mapping['IFFIDO'] = array("code"=>"destination","timezone"=>$ocean['dd_timezone'],"location"=>$ocean['dd_city']);
  1548. //取Port of discharge
  1549. $Milestones_NO_Mapping['IFFARR'] = array("code"=>"mpod","timezone"=>$ocean['mpod_timezone'],"location"=>$ocean['mpod_uncity']);
  1550. $Milestones_NO_Mapping['IFFICC'] = array("code"=>"mpod","timezone"=>$ocean['mpod_timezone'],"location"=>$ocean['mpod_uncity']);
  1551. $Milestones_NO_Mapping['IFFPPD'] = array("code"=>"mpod","timezone"=>$ocean['mpod_timezone'],"location"=>$ocean['mpod_uncity']);
  1552. //取1:Port of discharge 2:place of delivery / Final Destination
  1553. if(!empty($ocean['mpod_uncity'])){
  1554. $Milestones_NO_Mapping['IFFUND'] = array("code"=>"mpod/pod/fd","timezone"=>$ocean['mpod_timezone'],"location"=>$ocean['mpod_uncity']);
  1555. }else if(!empty($ocean['pod_uncity'])){
  1556. $Milestones_NO_Mapping['IFFUND'] = array("code"=>"mpod/pod/fd","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1557. }else{
  1558. $Milestones_NO_Mapping['IFFUND'] = array("code"=>"mpod/pod/fd","timezone"=>$ocean['fd_timezone'],"location"=>$ocean['fd_city']);
  1559. }
  1560. //Place of Delivery
  1561. $Milestones_NO_Mapping['IFFAFD'] = array("code"=>"pod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1562. $Milestones_NO_Mapping['IFFADW'] = array("code"=>"pod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1563. $Milestones_NO_Mapping['IFFDDW'] = array("code"=>"pod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1564. $Milestones_NO_Mapping['IFFDEL'] = array("code"=>"pod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1565. //1:Place of Delivery 2:port of discharge
  1566. if(!empty($ocean['pod_uncity'])){
  1567. $Milestones_NO_Mapping['IFFCTA'] = array("code"=>"pod/mpod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1568. }else{
  1569. $Milestones_NO_Mapping['IFFCTA'] = array("code"=>"pod/mpod","timezone"=>$ocean['mpod_timezone'],"location"=>$ocean['mpod_uncity']);
  1570. }
  1571. //final_destination
  1572. $Milestones_NO_Mapping['IFFECR'] = array("code"=>"fd","timezone"=>$ocean['fd_timezone'],"location"=>$ocean['fd_city']);
  1573. $Milestones_NO_Mapping['IFFHBL'] = array("code"=>"fd","timezone"=>$ocean['fd_timezone'],"location"=>$ocean['fd_city']);
  1574. return $Milestones_NO_Mapping;
  1575. }
  1576. }
  1577. ?>