common.class.php 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366
  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. if (!isset($_SESSION['ONLINE_USER'])) {
  112. self::timeoutPrintInfor($httpAccept, $ajax, 'no');
  113. } else {
  114. $time = time() - $_SESSION["LAST_OPERATE_TIME"];
  115. $set_session_timeout = $_SESSION['SESSION_TIMEOUT'];
  116. if (_getLoginName() == "ra.admin") {
  117. $set_session_timeout = 4 * 3600;
  118. }
  119. if ($time > $set_session_timeout) {
  120. self::timeoutPrintInfor($httpAccept, $ajax, 'yes');
  121. } else {
  122. $_SESSION["LAST_OPERATE_TIME"] = time();
  123. if (!_isAdmin() && $_GET["action"] != "linkcrm") {
  124. if (!utils::checkExist($_SESSION['ONLINE_USER']['permission'], $action) && !(stripos($action, "main") === 0) && !(stripos($action, "ajax") === 0)) {
  125. $data = array("msg"=>"Permission Denied");
  126. common::echo_json_encode(403, $data);
  127. exit();
  128. }
  129. }
  130. }
  131. }
  132. session_write_close();
  133. }
  134. }
  135. public static function getCompanySearch() {
  136. $sc_list = _get_schemas();
  137. if (count($sc_list) == 1) {
  138. return "";
  139. }
  140. if (_isCustomerLogin()) {
  141. $msg = '<input type="hidden" name="_apex_or_sfs" value=""/>';
  142. } else {
  143. $msg = '<div class="modules">Apex/SFS/Kerry :&nbsp;<select name="_apex_or_sfs" class="sl"><option value="">All</option>';
  144. if ($_SESSION['ONLINE_USER']['main_schemas'] == "public") {
  145. $msg .= '<option value="public">Apex</option>';
  146. } else {
  147. $msg .= '<option value="public">Apex</option>';
  148. }
  149. if ($_SESSION['ONLINE_USER']['main_schemas'] == "sfs") {
  150. $msg .= '<option value="sfs">SFS</option>';
  151. } else {
  152. $msg .= '<option value="sfs">SFS</option>';
  153. }
  154. if ($_SESSION['ONLINE_USER']['main_schemas'] == "kyiff") {
  155. $msg .= '<option value="kyiff">Kerry</option>';
  156. } else {
  157. $msg .= '<option value="kyiff">Kerry</option>';
  158. }
  159. $msg .= '</select></div>';
  160. }
  161. return $msg;
  162. }
  163. public static function sessionVerify() {
  164. if (!isset($_SESSION['user_agent'])) {
  165. $_SESSION['user_agent'] = MD5($_SERVER['REMOTE_ADDR']
  166. . $_SERVER['HTTP_USER_AGENT']);
  167. } elseif ($_SESSION['user_agent'] != MD5($_SERVER['REMOTE_ADDR']
  168. . $_SERVER['HTTP_USER_AGENT'])) {
  169. session_regenerate_id();
  170. }
  171. }
  172. public static function searchExtendHandNew($type, $user, $company_name = "station_name") {
  173. if (_isAdminHandNew($user)) {
  174. if(strtolower($type) == "air_booking" ) //|| strtolower($type) == "air"
  175. {
  176. return "1=1";
  177. }
  178. return " (schem_not_display is null or schem_not_display=false)";
  179. }
  180. if (_isDocAdmin($user["user_login"])) {
  181. if(strtolower($type) == "air_booking" ) //|| strtolower($type) == "air"
  182. {
  183. return "1=1";
  184. }
  185. return ' (schem_not_display is null or schem_not_display=false)';
  186. }
  187. if (strtolower($type) != "ocean" && strtolower($type) != "booking" && strtolower($type) != "air_booking"&& strtolower($type) != "air") {
  188. return " 1<>1";
  189. }
  190. if (empty($user["schemas_list"])) {
  191. $user["schemas_list"] = $_SESSION["schemas_list"];
  192. }
  193. $schemas_list = $user["schemas_list"];
  194. if ($user["is_kerry_shipment"] == "t") {
  195. $sqlWhere = " is_kerry_shipment is not null and is_kerry_shipment=true";
  196. } else if ($user["is_kerry_shipment"] == "f") {
  197. $sqlWhere = " (is_kerry_shipment is null or is_kerry_shipment=false)";
  198. } else {
  199. $sqlWhere = " 1=1";
  200. }
  201. if (!empty($_POST["_apex_or_sfs"])) {
  202. $sqlWhere .= " and order_from='" . $_POST["_apex_or_sfs"] . "'";
  203. }
  204. if (count($schemas_list) == 1) {
  205. $schames = $schemas_list[0]["schemas_name"];
  206. if(strtolower($type) == "air_booking" ||strtolower($type) == "air")
  207. {
  208. }
  209. else
  210. $sqlWhere .= " and order_from='$schames'";
  211. if ($schames == "sfs" && empty($user["sfs_ONLINE_USER"])) {
  212. $user = $_SESSION["sfs_ONLINE_USER"];
  213. }
  214. if (strtolower($type) == "ocean") {
  215. $sqlWhere .= self::_oceanHandNew($user, $schames);
  216. if ($company_name == "doc") {
  217. if (empty($user["view_file_format"])) {
  218. if (strtolower($user["user_type"]) == "customer") {
  219. $sqlWhere .= " and serial_no in (SELECT serial_no from $schames.ra_online_file_format where active = true and client_display = true)";
  220. } else {
  221. $sqlWhere .= " and serial_no in (SELECT serial_no from $schames.ra_online_file_format where active = true)";
  222. }
  223. } else {
  224. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  225. }
  226. }
  227. }
  228. if (strtolower($type) == "booking") {
  229. $sqlWhere .= self::_bookingHandNew($user, $schames);
  230. }
  231. if (strtolower($type) == "air_booking") {
  232. $sqlWhere .= self::_airHandNew($user, $schames);
  233. }
  234. if (strtolower($type) == "air") {
  235. $sqlWhere .= self::_airHandNew($user, $schames);
  236. if ($company_name == "doc") {
  237. if (empty($user["view_file_format"])) {
  238. if (strtolower($user["user_type"]) == "customer") {
  239. $sqlWhere .= " and serial_no in (SELECT serial_no from $schames.ra_online_file_format where active = true and client_display = true)";
  240. } else {
  241. $sqlWhere .= " and serial_no in (SELECT serial_no from $schames.ra_online_file_format where active = true)";
  242. }
  243. } else {
  244. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  245. }
  246. }
  247. }
  248. } elseif (count($schemas_list) == 2) {
  249. if(strtolower($type) == "air_booking" )//|| strtolower($type) == "air"
  250. {
  251. // $sqlWhere .= " and 1=1";
  252. }
  253. else
  254. $sqlWhere .= " and (schem_not_display is null or schem_not_display=false)";
  255. if (strtolower($type) == "ocean") {
  256. $sqlWhere .= " and ((order_from='public' ";
  257. $sqlWhere .= self::_oceanHandNew($user, "public");
  258. if ($company_name == "doc") {
  259. if (empty($user["view_file_format"])) {
  260. if (strtolower($user["user_type"]) == "customer") {
  261. $sqlWhere .= " and serial_no in (SELECT serial_no from public.ra_online_file_format where active = true and client_display = true)";
  262. } else {
  263. $sqlWhere .= " and serial_no in (SELECT serial_no from public.ra_online_file_format where active = true)";
  264. }
  265. } else {
  266. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  267. }
  268. }
  269. $sqlWhere .= ") or (order_from='sfs' ";
  270. if (empty($user["sfs_ONLINE_USER"])) {
  271. $user = $_SESSION["sfs_ONLINE_USER"];
  272. }
  273. $sqlWhere .= self::_oceanHandNew($user, "sfs");
  274. if ($company_name == "doc") {
  275. if (empty($user["view_file_format"])) {
  276. if (strtolower($user["user_type"]) == "customer") {
  277. $sqlWhere .= " and serial_no in (SELECT serial_no from sfs.ra_online_file_format where active = true and client_display = true)";
  278. } else {
  279. $sqlWhere .= " and serial_no in (SELECT serial_no from sfs.ra_online_file_format where active = true)";
  280. }
  281. } else {
  282. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  283. }
  284. }
  285. $sqlWhere .= ") )";
  286. }
  287. if (strtolower($type) == "booking") {
  288. $sqlWhere .= " and ((order_from='public' ";
  289. $sqlWhere .= self::_bookingHandNew($user, "public");
  290. $sqlWhere .= ") or (order_from='sfs' ";
  291. if (empty($user["sfs_ONLINE_USER"])) {
  292. $user = $_SESSION["sfs_ONLINE_USER"];
  293. }
  294. $sqlWhere .= self::_bookingHandNew($user, "sfs");
  295. $sqlWhere .= "))";
  296. }
  297. if (strtolower($type) == "air_booking") {
  298. $sqlWhere .= " and ((order_from='public' ";
  299. $sqlWhere .= self::_airHandNew($user, "public");
  300. $sqlWhere .= ") or (order_from='sfs' ";
  301. if (empty($user["sfs_ONLINE_USER"])) {
  302. $user = $_SESSION["sfs_ONLINE_USER"];
  303. }
  304. $sqlWhere .= self::_airHandNew($user, "sfs");
  305. $sqlWhere .= "))";
  306. // $sqlWhere .= self::_airHandNew($user, $schames);
  307. }
  308. if (strtolower($type) == "air") {
  309. $sqlWhere .= " and ((order_from='public' ";
  310. $sqlWhere .= self::_airHandNew($user, "public");
  311. if ($company_name == "doc") {
  312. if (empty($user["view_file_format"])) {
  313. if (strtolower($user["user_type"]) == "customer") {
  314. $sqlWhere .= " and serial_no in (SELECT serial_no from public.ra_online_file_format where active = true and client_display = true)";
  315. } else {
  316. $sqlWhere .= " and serial_no in (SELECT serial_no from public.ra_online_file_format where active = true)";
  317. }
  318. } else {
  319. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  320. }
  321. }
  322. $sqlWhere .= ") or (order_from='sfs' ";
  323. if (empty($user["sfs_ONLINE_USER"])) {
  324. $user = $_SESSION["sfs_ONLINE_USER"];
  325. }
  326. $sqlWhere .= self::_airHandNew($user, "sfs");
  327. if ($company_name == "doc") {
  328. if (empty($user["view_file_format"])) {
  329. if (strtolower($user["user_type"]) == "customer") {
  330. $sqlWhere .= " and serial_no in (SELECT serial_no from sfs.ra_online_file_format where active = true and client_display = true)";
  331. } else {
  332. $sqlWhere .= " and serial_no in (SELECT serial_no from sfs.ra_online_file_format where active = true)";
  333. }
  334. } else {
  335. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  336. }
  337. }
  338. $sqlWhere .= ") )";
  339. }
  340. } else {
  341. $sqlWhere = " 1<>1";
  342. }
  343. return $sqlWhere;
  344. }
  345. public static function getStatusStage($status) {
  346. if ($status == "EE" || $status == "I") {
  347. return 0;
  348. }
  349. if ($status == "AE" || $status == "VD" || $status == "VA_RELAY" || $status == "UV_RELAY" || $status == "AE_RELAY" || $status == "VD_RELAY") {
  350. return 1;
  351. }
  352. if ($status == "VA" || $status == "UV" || $status == "AL" || $status == "AR" || $status == "CU" || $status == "CT" || $status == "CR" || $status == "OA") {
  353. return 2;
  354. }
  355. if ($status == "AV" || $status == "D" || $status == "RD") {
  356. return 3;
  357. }
  358. return -1;
  359. }
  360. public static function getInNotInSql($contact_id, $type = 'in') {
  361. if (empty($contact_id))
  362. return " =''";
  363. $contact_id = trim($contact_id);
  364. $contact_id = trim($contact_id, ";");
  365. $contact_id = trim($contact_id);
  366. $contact_id = strtolower($contact_id);
  367. if ($type == 'in') {
  368. if (utils::checkExist($contact_id, ";")) {
  369. $ss = "";
  370. $aa = explode(";", $contact_id);
  371. foreach ($aa as $k => $v) {
  372. $v = trim($v);
  373. if (empty($ss))
  374. $ss = "'" . common::check_input($v) . "'";
  375. else
  376. $ss .= ",'" . common::check_input($v) . "'";
  377. }
  378. return " in (" . $ss . ")";
  379. } else {
  380. return " = '" . common::check_input($contact_id) . "'";
  381. }
  382. } else {
  383. if (utils::checkExist($contact_id, ";")) {
  384. $ss = "";
  385. $aa = explode(";", $contact_id);
  386. foreach ($aa as $k => $v) {
  387. $v = trim($v);
  388. if (empty($ss))
  389. $ss = "'" . common::check_input($v) . "'";
  390. else
  391. $ss .= ",'" . common::check_input($v) . "'";
  392. }
  393. return " in (" . $ss . ")";
  394. } else {
  395. return " != '" . common::check_input($contact_id) . "'";
  396. }
  397. }
  398. }
  399. /*
  400. * Encrypt a SQL query statement used to be passed as a parameter to get excel output
  401. encode :DeCode('str','E');
  402. decode :DeCode('enstr','D');
  403. */
  404. public static function deCode($string, $operation = "E") {
  405. $key = md5("uls_webwms");
  406. $key_length = strlen($key);
  407. if ($operation == "D")
  408. $string = rawurldecode($string);
  409. $string = $operation == 'D' ? base64_decode($string) : substr(md5($string . $key), 0, 8) . $string;
  410. $string_length = strlen($string);
  411. $rndkey = $box = array();
  412. $result = '';
  413. for ($i = 0; $i <= 255; $i++) {
  414. $rndkey [$i] = ord($key [$i % $key_length]);
  415. $box [$i] = $i;
  416. }
  417. for ($j = $i = 0; $i < 256; $i++) {
  418. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  419. $tmp = $box [$i];
  420. $box [$i] = $box [$j];
  421. $box [$j] = $tmp;
  422. }
  423. for ($a = $j = $i = 0; $i < $string_length; $i++) {
  424. $a = ($a + 1) % 256;
  425. $j = ($j + $box [$a]) % 256;
  426. $tmp = $box [$a];
  427. $box [$a] = $box [$j];
  428. $box [$j] = $tmp;
  429. $result .= chr(ord($string [$i]) ^ ($box [($box [$a] + $box [$j]) % 256]));
  430. }
  431. if ($operation == 'D') {
  432. if (substr($result, 0, 8) == substr(md5(substr($result, 8) . $key), 0, 8)) {
  433. return substr($result, 8);
  434. } else {
  435. return '';
  436. }
  437. } else {
  438. return rawurlencode(str_replace('=', '', base64_encode($result)));
  439. }
  440. }
  441. public static function getStatusDesc($code) {
  442. if (strtoupper($code) == "EE") {
  443. return "Empty Equipment Dispatched";
  444. }
  445. if (strtoupper($code) == "I") {
  446. return "Gate in full for a booking";
  447. }
  448. if (strtoupper($code) == "AE") {
  449. return "Container loaded on vessel";
  450. }
  451. if (strtoupper($code) == "VD") {
  452. return "Vessel Departure";
  453. }
  454. if (strtoupper($code) == "VA_RELAY") {
  455. return "Arrive Relay Port";
  456. }
  457. if (strtoupper($code) == "VD_RELAY") {
  458. return "Depart Relay Port";
  459. }
  460. if (strtoupper($code) == "AE_RELAY") {
  461. return "Loaded at Relay Port";
  462. }
  463. if (strtoupper($code) == "UV_RELAY") {
  464. return "Unloaded at Relay Port";
  465. }
  466. if (strtoupper($code) == "VA") {
  467. return "Vessel Arrival";
  468. }
  469. if (strtoupper($code) == "UV") {
  470. return "Unloaded From Vessel";
  471. }
  472. if (strtoupper($code) == "AL") {
  473. return "Container loaded on Rail";
  474. }
  475. if (strtoupper($code) == "AR") {
  476. return "Container unloaded from Rail";
  477. }
  478. if (strtoupper($code) == "CU") {
  479. return "Carrier and Customs Release";
  480. }
  481. if (strtoupper($code) == "CT") {
  482. return "Customs release";
  483. }
  484. if (strtoupper($code) == "CR") {
  485. return "Carrier release";
  486. }
  487. if (strtoupper($code) == "OA") {
  488. return "Gate out full from final discharge port";
  489. }
  490. if (strtoupper($code) == "AV") {
  491. return "Shipment available for pickup or delivery";
  492. }
  493. if (strtoupper($code) == "RD") {
  494. return "Container returned empty";
  495. }
  496. if (strtoupper($code) == "D") {
  497. return "Gate out for delivery to customer";
  498. }
  499. }
  500. public static function _toString($msg) {
  501. if ($msg == "" || $msg == NULL) {
  502. return "";
  503. }
  504. return $msg . "";
  505. }
  506. /*
  507. * timeout output
  508. */
  509. public static function timeoutPrintInfor($httpAccept, $ajax, $login) {
  510. $data = array("msg"=>"session_time_out");
  511. self::echo_json_encode(403,$data);
  512. exit();
  513. }
  514. private static function _oceanHandNew($user, $schemas = "public") {
  515. $o = $user['ocean_station'];
  516. $o_or = $user['ocean_station_or'];
  517. $d = $user['ocean_agent'];
  518. $d_or = $user['ocean_agent_or'];
  519. $sales = $user['ocean_sales'];
  520. $sales_or = $user['ocean_sales_or'];
  521. $op = $user['ocean_dest_op'];
  522. $op_or = $user['ocean_dest_op_or'];
  523. $follow = $user['ocean_following_sales'];
  524. $follow_or = $user['ocean_following_sales_or'];
  525. if (strtolower($o_or) == "all" || strtolower($d_or) == "all" || strtolower($sales_or) == "all" || strtolower($op_or) == "all") {
  526. return " and 1=1";
  527. }
  528. $sqlWhere = "";
  529. if (_isCustomerLoginHandNew($user)) {
  530. //error_log("_oceanHandNew".$schemas);
  531. $sqlWhere .= " and " . _customerFilerSearchHandNew($user, $schemas);
  532. } else {
  533. if (empty($o) && empty($d) && empty($sales) && empty($op) && empty($follow)) {
  534. return " and 1<>1";
  535. }
  536. if ((strtolower($o) == 'all' || empty($o)) && (strtolower($d) == "all" || empty($d))) {
  537. } else {
  538. $sql = "1=1";
  539. if (!empty($o) && strtolower($o) != 'all') {
  540. $sql .= " and lower(origin)";
  541. $sql .= utils::getInSql($o);
  542. }
  543. if (!empty($d) && strtolower($d) != 'all') {
  544. $sql .= " and lower(agent)";
  545. $sql .= utils::getInSql($d);
  546. }
  547. $sqlWhere .= " and (" . $sql . ")";
  548. }
  549. if (strtolower($sales) == 'all' || empty($sales)) {
  550. } else {
  551. if (utils::checkExist($sales, ";")) {
  552. $sql = "1!=1";
  553. $tt = explode(";", $sales);
  554. foreach ($tt as $t) {
  555. $t = trim($t);
  556. if (!empty($t))
  557. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  558. }
  559. $sqlWhere .= " and ($sql)";
  560. } else
  561. $sqlWhere .= " and lower(sales_rep)='" . strtolower($sales) . "'";
  562. }
  563. if (strtolower($op) == 'all' || empty($op)) {
  564. } else {
  565. $sqlWhere .= " and lower(dest_op) " . utils::getInSql($op);
  566. }
  567. if (strtolower($follow) == 'all' || empty($follow)) {
  568. } else {
  569. if (utils::checkExist($follow, ";")) {
  570. $sql = "1!=1";
  571. $tt = explode(";", $follow);
  572. foreach ($tt as $t) {
  573. $t = trim($t);
  574. if (!empty($t))
  575. $sql .= " or following_sales ilike '" . $t . "'";
  576. }
  577. $sqlWhere .= " and ($sql)";
  578. } else
  579. $sqlWhere .= " and following_sales ilike '" . $follow . "'";
  580. }
  581. $sqlWhere = " (1=1 $sqlWhere)";
  582. if (!empty($o_or)) {
  583. $sqlWhere .= " or lower(origin)";
  584. $sqlWhere .= utils::getInSql($o_or);
  585. }
  586. if (!empty($d_or)) {
  587. $sqlWhere .= " or lower(agent)";
  588. $sqlWhere .= utils::getInSql($d_or);
  589. }
  590. if (!empty($sales_or)) {
  591. if (utils::checkExist($sales_or, ";")) {
  592. $sql = "1!=1";
  593. $tt = explode(";", $sales_or);
  594. foreach ($tt as $t) {
  595. $t = trim($t);
  596. if (!empty($t))
  597. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  598. }
  599. $sqlWhere .= " or ($sql)";
  600. } else
  601. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales_or) . "'";
  602. }
  603. if (!empty($op_or)) {
  604. $sqlWhere .= " or lower(dest_op) " . utils::getInSql($op_or);
  605. }
  606. if (!empty($follow_or)) {
  607. if (utils::checkExist($follow_or, ";")) {
  608. $sql = "1!=1";
  609. $tt = explode(";", $follow_or);
  610. foreach ($tt as $t) {
  611. $t = trim($t);
  612. if (!empty($t))
  613. $sql .= " or following_sales ilike '" . $t . "'";
  614. }
  615. $sqlWhere .= " or ($sql)";
  616. }else {
  617. $sqlWhere .= " or following_sales ilike '" . $follow_or . "'";
  618. }
  619. }
  620. $sqlWhere = " and ($sqlWhere)";
  621. }
  622. return $sqlWhere;
  623. }
  624. private static function _bookingHandNew($user, $schames) {
  625. // if (_isDemo())
  626. // return " serial_no = 'D4DD1D79-83F4-4E65-9773-CF5277D72738'";
  627. $o = $user['ocean_station'];
  628. $o_or = $user['ocean_station_or'];
  629. $d = $user['ocean_agent'];
  630. $d_or = $user['ocean_agent_or'];
  631. $sales = $user['ocean_sales'];
  632. $sales_or = $user['ocean_sales_or'];
  633. $op = $user['ocean_dest_op'];
  634. $op_or = $user['ocean_dest_op_or'];
  635. $follow = $user['ocean_following_sales'];
  636. $follow_or = $user['ocean_following_sales_or'];
  637. if (strtolower($o_or) == "all" || strtolower($d_or) == "all" || strtolower($sales_or) == "all") {
  638. return " and 1=1";
  639. }
  640. // $sc_list = $user['schemas_list'];
  641. // if (empty($sc_list)) {
  642. // $sc_list = $_SESSION["schemas_list"];
  643. // }
  644. // if (empty($sc_list)) {
  645. // return " and 1<>1";
  646. // }
  647. // $sqlWhere = " and 1=1";
  648. // if ($user["is_kerry_shipment"] == "t") {
  649. // $sqlWhere = " and and is_kerry_shipment is not null and is_kerry_shipment=true";
  650. // } else if ($user["is_kerry_shipment"] == "f") {
  651. // $sqlWhere = " and (is_kerry_shipment is null or is_kerry_shipment=false)";
  652. // }
  653. // if (count($sc_list) == 1) {
  654. // $sch = $sc_list[0]['schemas_name'];
  655. // $sqlWhere .= " and order_from='$sch'";
  656. // } else {
  657. // $sqlWhere .= " and (schem_not_display is null or schem_not_display=false)";
  658. // }
  659. $sqlWhere = "";
  660. if (_isCustomerLoginHandNew($user)) {
  661. $sqlWhere .= " and " . _customerFilerSearchHandNew($user, $schames);
  662. } else {
  663. if (empty($o) && empty($d) && empty($sales) && empty($op) && empty($follow)) {
  664. return " and 1<>1";
  665. }
  666. if ((strtolower($o) == 'all' || empty($o)) && (strtolower($d) == "all" || empty($d))) {
  667. } else {
  668. $sql = "1=1";
  669. if (!empty($o) && strtolower($o) != 'all') {
  670. $sql .= " and lower(origin)";
  671. $sql .= utils::getInSql($o);
  672. }
  673. if (!empty($d) && strtolower($d) != 'all') {
  674. $sql .= " and lower(agent)";
  675. $sql .= utils::getInSql($d);
  676. }
  677. $sqlWhere .= " and (" . $sql . ")";
  678. }
  679. if (strtolower($sales) == 'all' || empty($sales)) {
  680. } else {
  681. if (utils::checkExist($sales, ";")) {
  682. $sql = "1!=1";
  683. $tt = explode(";", $sales);
  684. foreach ($tt as $t) {
  685. $t = trim($t);
  686. if (!empty($t))
  687. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  688. }
  689. $sqlWhere .= " and ($sql)";
  690. } else
  691. $sqlWhere .= " and lower(sales_rep)='" . strtolower($sales) . "'";
  692. }
  693. if (strtolower($follow) == 'all' || empty($follow)) {
  694. } else {
  695. if (utils::checkExist($follow, ";")) {
  696. $sql = "1!=1";
  697. $tt = explode(";", $follow);
  698. foreach ($tt as $t) {
  699. $t = trim($t);
  700. if (!empty($t))
  701. $sql .= " or following_sales ilike '" . $t . "%'";
  702. }
  703. $sqlWhere .= " and ($sql)";
  704. } else
  705. $sqlWhere .= " and following_sales ilike '" . $follow . "%'";
  706. }
  707. $sqlWhere = " (1=1 $sqlWhere)";
  708. if (!empty($o_or)) {
  709. $sqlWhere .= " or lower(origin)";
  710. $sqlWhere .= utils::getInSql($o_or);
  711. }
  712. if (!empty($d_or)) {
  713. $sqlWhere .= " or lower(agent)";
  714. $sqlWhere .= utils::getInSql($d_or);
  715. }
  716. if (!empty($sales_or)) {
  717. if (utils::checkExist($sales_or, ";")) {
  718. $sql = "1!=1";
  719. $tt = explode(";", $sales_or);
  720. foreach ($tt as $t) {
  721. $t = trim($t);
  722. if (!empty($t))
  723. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  724. }
  725. $sqlWhere .= " or ($sql)";
  726. } else
  727. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales_or) . "%'";
  728. }
  729. if (!empty($follow_or)) {
  730. if (utils::checkExist($follow_or, ";")) {
  731. $sql = "1!=1";
  732. $tt = explode(";", $follow_or);
  733. foreach ($tt as $t) {
  734. $t = trim($t);
  735. if (!empty($t))
  736. $sql .= " or following_sales ilike '" . $t . "%'";
  737. }
  738. $sqlWhere .= " or ($sql)";
  739. } else
  740. $sqlWhere .= " or following_sales ilike '" . $follow_or . "%'";
  741. }
  742. $sqlWhere = " and ($sqlWhere)";
  743. }
  744. return $sqlWhere;
  745. }
  746. private static function _airHandNew($user, $schemas = "public")
  747. {
  748. if($schemas=="public")
  749. {
  750. $station = $user['air_station'];
  751. $station_or = $user['air_station_or'];
  752. $sales = $user['air_sales'];
  753. $sales_or = $user['air_sales_or'];
  754. }
  755. else
  756. {
  757. $station = $user[$schemas."_ONLINE_USER"]['air_station'];
  758. $station_or = $user[$schemas."_ONLINE_USER"]['air_station_or'];
  759. $sales = $user[$schemas."_ONLINE_USER"]['air_sales'];
  760. $sales_or = $user[$schemas."_ONLINE_USER"]['air_sales_or'];
  761. }
  762. if (strtolower($station_or) == "all" || strtolower($sales_or) == "all" ) //|| strtolower($d_or) == "all"|| strtolower($op_or) == "all"|| strtolower($follow_or) == "all"
  763. {
  764. return " and 1=1";
  765. }
  766. $sqlWhere = "";
  767. if (_isCustomerLoginHandNew($user)) {
  768. //error_log("_oceanHandNew".$schemas);
  769. $sqlWhere .= " and " . _customerFilerSearchHandNew_Air($user, $schemas);
  770. }
  771. else
  772. {
  773. if (empty($station) && empty($sales) ) //&& empty($d)&& empty($op) && empty($follow)
  774. {
  775. return " and 1<>1";
  776. }
  777. if ((strtolower($station) == 'all' || empty($station)) ) //&& (strtolower($d) == "all" || empty($d))
  778. {
  779. }
  780. else
  781. {
  782. $sql = "1=1";
  783. if (!empty($station) && strtolower($station) != 'all') {
  784. $sql .= " and (lower(origin)";
  785. $sql .= utils::getInSql($station);
  786. $sql .= " or lower(destination_station)";
  787. $sql .= utils::getInSql($station);
  788. $sql .= ")";
  789. }
  790. $sqlWhere .= " and (" . $sql . ")";
  791. }
  792. if (strtolower($sales) == 'all' || empty($sales)) {
  793. } else
  794. {
  795. if (utils::checkExist($sales, ";")) {
  796. $sql = "1!=1";
  797. $tt = explode(";", $sales);
  798. foreach ($tt as $t) {
  799. $t = trim($t);
  800. if (!empty($t))
  801. {
  802. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  803. $sql .= " or lower(following_sales)='" . strtolower($t) . "'";
  804. }
  805. }
  806. $sqlWhere .= " and ($sql)";
  807. } else
  808. {
  809. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales) . "'";
  810. $sqlWhere .= " or lower(following_sales)='" . strtolower($sales) . "'";
  811. }
  812. }
  813. $sqlWhere = " (1=1 $sqlWhere)";
  814. if (!empty($station_or)) {
  815. $sqlWhere .= " or lower(origin)";
  816. $sqlWhere .= utils::getInSql($station_or);
  817. $sqlWhere .= " or lower(destination_station)";
  818. $sqlWhere .= utils::getInSql($station_or);
  819. }
  820. if (!empty($sales_or)) {
  821. if (utils::checkExist($sales_or, ";")) {
  822. $sql = "1!=1";
  823. $tt = explode(";", $sales_or);
  824. foreach ($tt as $t) {
  825. $t = trim($t);
  826. if (!empty($t))
  827. {
  828. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  829. $sql .= " or lower(following_sales)='" . strtolower($t) . "'";
  830. }
  831. }
  832. $sqlWhere .= " or ($sql)";
  833. } else
  834. {
  835. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales_or) . "'";
  836. $sqlWhere .= " or lower(following_sales)='" . strtolower($sales_or) . "'";
  837. }
  838. }
  839. $sqlWhere = " and ($sqlWhere)";
  840. }
  841. return $sqlWhere;
  842. }
  843. public static function isNewVersion() {
  844. if (utils::checkExist($_SERVER['PHP_SELF'], "main_new_version.php")) {
  845. return "_new";
  846. }
  847. return "";
  848. }
  849. public static function removeTopOceanOldVersionSpecialField($rss){
  850. $rss_bk = $rss;
  851. $new_arr = array();
  852. foreach ($rss_bk as $k => $v) {
  853. if (utils::startWith($v['database_column_name'], "__") || utils::startWith($v['database_column_name'], "___")){
  854. //unset($rss[$k]);
  855. }else{
  856. $new_arr[] = $v;
  857. }
  858. }
  859. return $new_arr;
  860. }
  861. public static function echo_json_encode($code,$data){
  862. $resData = array();
  863. $resData["code"] = $code;
  864. $resData["data"] =$data;
  865. echo utils::jsonFiltration("null", "\"\"", json_encode($resData));
  866. }
  867. /*
  868. * MM/DD/YYYY To YYYY-MM-DD
  869. */
  870. public static function usDate2sqlDate($timestr) {
  871. if (empty($timestr))
  872. return '';
  873. $datearray = explode("/", $timestr);
  874. $m = $datearray [0];
  875. $d = $datearray [1];
  876. $y = $datearray [2];
  877. return $y . "-" . $m . "-" . $d;
  878. }
  879. public static function uuid() {
  880. return md5(uniqid("", TRUE) . mt_rand());
  881. }
  882. /*
  883. * YYYYMMDD To MM/DD/YYYY
  884. */
  885. public static function date2usdate($datestr) {
  886. if (empty($datestr))
  887. return '';
  888. $y = substr($datestr, 0, 4);
  889. $m = substr($datestr, 4, 2);
  890. $d = substr($datestr, 6, 2);
  891. return $m . "/" . $d . "/" . $y;
  892. }
  893. /*
  894. * date add some days
  895. */
  896. public static function addDays($date, $days) {
  897. $time = strtotime($date) + $days * 24 * 3600;
  898. return date('m/d/Y', $time);
  899. }
  900. /*
  901. * download file from file system
  902. */
  903. public static function download_file($filename, $display_name = null, $delete = FALSE, $files = NULL) {
  904. $filename = str_replace("/", DIRECTORY_SEPARATOR, $filename);
  905. $filename = str_replace("\\", DIRECTORY_SEPARATOR, $filename);
  906. if (!file_exists($filename))
  907. exit('File Not Exist');
  908. if (empty($display_name))
  909. $display_name = basename($filename);
  910. //$file = fopen($filename, "r");
  911. header_remove("Content-type");
  912. header("Content-type:" . self::getContentType($filename));
  913. header("Expires: 0");
  914. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  915. header("Pragma: can-cache");
  916. header("Accept-ranges:bytes");
  917. header("Accept-length:" . filesize($filename));
  918. header("Content-Disposition:attachment;filename=\"" . $display_name . "\"");
  919. //echo fread($file, filesize($filename));
  920. //fclose($file);
  921. //针对大文件,规定每次读取文件的字节数为4096字节,直接输出数据
  922. $read_buffer = 4096;
  923. $handle = fopen($filename, 'rb');
  924. //总的缓冲的字节数
  925. $sum_buffer = 0;
  926. $filesize = filesize($filename);
  927. //只要没到文件尾,就一直读取
  928. while (!feof($handle) && $sum_buffer < $filesize) {
  929. echo fread($handle, $read_buffer);
  930. $sum_buffer += $read_buffer;
  931. }
  932. //关闭句柄
  933. fclose($handle);
  934. if ($delete !== FALSE) {
  935. unlink($filename);
  936. }
  937. if (!empty($files)) {
  938. foreach ($files as $f) {
  939. unlink($f);
  940. }
  941. }
  942. }
  943. public static function getContentType($filename) {
  944. $extend = self::getExtendFilename($filename);
  945. $filetype = array(
  946. 'xls' => 'application/vnd.ms-excel',
  947. 'doc' => 'application/msword',
  948. 'gif' => 'image/gif',
  949. 'jpg' => 'image/jpeg',
  950. 'jpeg' => 'image/jpeg',
  951. 'jpe' => 'image/jpeg',
  952. 'bmp' => 'image/bmp',
  953. 'png' => 'image/png',
  954. 'tif' => 'image/tiff',
  955. 'pdf' => 'application/pdf',
  956. 'zip' => 'application/zip'
  957. );
  958. return $filetype[$extend];
  959. }
  960. /*
  961. * Get the file extension
  962. */
  963. public static function getExtendFilename($file_name) {
  964. $extend = pathinfo($file_name);
  965. $extend = strtolower($extend["extension"]);
  966. return $extend;
  967. }
  968. public static function getManagement(){
  969. //Management 自己配置需要创建表保存
  970. $user_management = common::excuteOneSql("select management from ra_online_user where user_login = '"._getLoginName()."'");
  971. //为空,配置使用默认值
  972. if(empty($user_management)){
  973. $Management = common::getdefaultManagement();
  974. }else{
  975. $Management = json_decode($user_management,true);
  976. foreach($Management as $key =>$val){
  977. $Management[$key]['id'] = intval($val['id']);
  978. $Management[$key]['switchValue'] = $val['switchValue'] == "true" ? true : false;
  979. }
  980. }
  981. return $Management;
  982. }
  983. public static function getItemStyle($type,$code){
  984. if($type == 'r1'){
  985. $data = array("0-20 Days" =>"#ffc594",
  986. "20-40 Days" =>"#ff9e4c",
  987. "40-60 Days" =>"#ff7500",
  988. "60-80 Days" =>"#ff3d00",
  989. "Over 80 Days" =>"#d50000");
  990. return $data[$code];
  991. }
  992. if($type == 'r4' || $type == 'r3' || $type == 'atd_r4' || $type == 'ata_r3'){
  993. $data = array("0 Day" =>"#ffc594",
  994. "Today" =>"#ffc594",
  995. "1-2 Days" =>"#ff9e4c",
  996. "3-6 Days" =>"#ff7500",
  997. "7 Days" =>"#ff3d00");
  998. return $data[$code];
  999. }
  1000. if($type == 'r2' || utils::startWith($type,"co2e")){
  1001. $data = array("45" =>"#FFE3CC",
  1002. "40" =>"#FFAC66",
  1003. "20" =>"#FF7500",
  1004. "air" =>"#FFE3CC",
  1005. "sea" =>"#FFAC66",
  1006. "road" =>"#FF7500");
  1007. return $data[$code];
  1008. }
  1009. if($type == "top"){
  1010. $data = array("1" =>"#FF7500",
  1011. "2" =>"#ff9033",
  1012. "3" =>"#ff9e4d",
  1013. "4" =>"#ffac66",
  1014. "5" =>"#ffba80",
  1015. "6" =>"#ffc899",
  1016. "7" =>"#ffd6b3",
  1017. "8" =>"#ffe3cc",
  1018. "9" =>"#fff1e6",
  1019. "10" =>"#fff1e6");
  1020. return $data[$code];
  1021. }
  1022. }
  1023. //处理返回原表数据格式
  1024. public static function mian_repot_do($value,$type,$totalValue){
  1025. $data = array();
  1026. $value_arr = json_decode($value,true);
  1027. if($type == 'r1'){
  1028. $ETDList = array();
  1029. foreach($value_arr as $arr){
  1030. $color = common::getItemStyle($type,$arr['name']);
  1031. $ETDList[] = array("value" =>intval($arr['value']),"name" =>$arr['name'],"itemStyle" =>array("color" =>$color));
  1032. }
  1033. $ETD_Title = "Total: $totalValue";
  1034. $data = array("ETDList" =>$ETDList,"ETD_Radius"=>array('50%','80%'),"ETD_Title" =>$ETD_Title);
  1035. }
  1036. if($type == 'r4' || $type == 'r3'){
  1037. //重新整理一下数据,给UI一致
  1038. $data_kd = array();
  1039. foreach($value_arr as $arr){
  1040. if(stripos("Today", $arr['name']) !== false){
  1041. $color = common::getItemStyle($type,"Today");
  1042. if(empty($data_kd["0"])){
  1043. $data_kd["0"] = array("value" =>intval($arr['value']),"name" =>"0 Day","itemStyle" =>array("color" =>$color));
  1044. }else{
  1045. $data_kd["0"]["value"] = $data_kd["0"]["value"] + intval($arr['value']);
  1046. }
  1047. }
  1048. if(stripos("+1 Days/+2 Days", $arr['name']) !== false){
  1049. $color = common::getItemStyle($type,"1-2 Days");
  1050. if(empty($data_kd["1"])){
  1051. $data_kd["1"] = array("value" =>intval($arr['value']),"name" =>"1-2 Days","itemStyle" =>array("color" =>$color));
  1052. }else{
  1053. $data_kd["1"]["value"] = $data_kd["1"]["value"] + intval($arr['value']);
  1054. }
  1055. }
  1056. if(stripos("+3 Days/+4 Days/+5 Days/+6 Days", $arr['name']) !== false){
  1057. $color = common::getItemStyle($type,"3-6 Days");
  1058. if(empty($data_kd["2"])){
  1059. $data_kd["2"] = array("value" =>intval($arr['value']),"name" =>"3-6 Days","itemStyle" =>array("color" =>$color));
  1060. }else{
  1061. $data_kd["2"]["value"] = $data_kd["2"]["value"] + intval($arr['value']);
  1062. }
  1063. }
  1064. if(stripos("+7 Days/Over 7 Days", $arr['name']) !== false){
  1065. $color = common::getItemStyle($type,"7 Days");
  1066. if(empty($data_kd["3"])){
  1067. $data_kd["3"] = array("value" =>intval($arr['value']),"name" =>"7 Days","itemStyle" =>array("color" =>$color));
  1068. }else{
  1069. $data_kd["3"]["value"] = $data_kd["3"]["value"] + intval($arr['value']);
  1070. }
  1071. }
  1072. }
  1073. if($type == 'r4'){
  1074. $data = array("ETDList" =>$data_kd,"ETD_Radius"=>array('30%','50%'),"title1" =>"Pending","title2" =>"(ATD-ETD)");
  1075. }
  1076. if($type == 'r3'){
  1077. $data = array("ETDList" =>$data_kd,"ETD_Radius"=>array('30%','50%'),"title1" =>"Pending","title2" =>"(ATD-ETD)");
  1078. }
  1079. }
  1080. return $data;
  1081. }
  1082. //单独处理co2e bar
  1083. public static function getCo2eBar(){
  1084. //新UI air sea road 目前只有sea
  1085. $type = $_REQUEST["r_type"];
  1086. $container_type_arr = array("air","sea","road");
  1087. $container_type_param = 'sea';
  1088. $ContainerCounSeries = array();
  1089. $ContainerCount_Title = array("HKHKG","DKHKG","EKHKG","FKHKG","KKHKG","GKHKG","MKHKG","LKHKG","NKHKG","OKHKG");
  1090. foreach($container_type_arr as $_container_type){
  1091. //查询逻辑需要问,目前暂时写死ssh-keygen -t rsa -b 4096 -C "shuanghong.shuai@united-cn.net"
  1092. $container_type = $_container_type;
  1093. $data = array(1500, 1500, 2100, 1500, 2450, 1900, 1900, 900, 600, 500);
  1094. $total = 0;
  1095. $max = 0;
  1096. // foreach($value_arr as $arr){
  1097. // $data[] = intval($arr['value']);
  1098. // $total = $total + intval($arr['value']);
  1099. // }
  1100. foreach($data as $arr){
  1101. $total = $total + $arr;
  1102. $max = $max < $arr ? $arr : $max;
  1103. }
  1104. $ContainerCounSeries[$container_type] = array("data"=>$data,"total"=>$total,"max"=>$max);
  1105. }
  1106. //处理返回时数据格式
  1107. $max = 0;
  1108. $ContainerCounSeries_return = array();
  1109. foreach($ContainerCounSeries as $k =>$v){
  1110. $color = common::getItemStyle($type,$k);
  1111. $ContainerCounSeries_return[] = array("name"=>$k,"type"=>"bar","emphasis" => array("focus" =>"none"),
  1112. "stack" =>"总计","data" =>$v['data'],"itemStyle" =>array("color" =>$color));
  1113. $max = $max + $v['max'];
  1114. }
  1115. //处理返回原表数据格式
  1116. //计算刻度值 最小值是0,最大值是3000,刻度是500 interval
  1117. $interval = utils::calculateTicks(0,$max,10);
  1118. if($interval == 0){
  1119. //处理返回默认值
  1120. $interval = 1;
  1121. }
  1122. $returnData = array("ContainerCount_Title"=>"","ContainerCountList" =>$ContainerCount_Title,"ContainerCounSeries" =>$ContainerCounSeries_return,
  1123. "min" => 0,"Max" =>$interval*10,"interval" =>$interval);
  1124. return $returnData;
  1125. }
  1126. public static function getTopBar(){
  1127. $toporigin = array();
  1128. for($i = 0; $i<10; $i++){
  1129. $num = $i + 1;
  1130. $toporigin[] = array("name"=>"CNSGH$num","value"=>$num,"color"=>common::getItemStyle("top",$num));
  1131. }
  1132. $topdestination = array();
  1133. for($i = 0; $i<10; $i++){
  1134. $num = $i + 1;
  1135. $topdestination[] = array("name"=>"CNSGH$num","value"=>$num,"color"=>common::getItemStyle("top",$num));
  1136. }
  1137. //处理返回原表数据格式
  1138. $interval = utils::calculateTicks(0,10,10);
  1139. if($interval == 0){
  1140. //处理返回默认值
  1141. $interval = 1;
  1142. }
  1143. $returnData = array("seller_data_list_origin"=>$toporigin,"seller_data_list_destination"=>$topdestination,
  1144. "min" => 0,"Max" =>$interval*10,"interval" =>$interval);
  1145. return $returnData;
  1146. }
  1147. public static function getdefaultManagement(){
  1148. $Management = array();
  1149. $Management[] = array("id"=>1 ,
  1150. "title"=>"KPI",
  1151. "switchValue"=>true,
  1152. "text"=>"Pie chart showing figures of shipments KPI of Departure and Arrival.");
  1153. $Management[] = array("id"=>2 ,
  1154. "title"=>"Pending Departure & Arrival",
  1155. "switchValue"=>true,
  1156. "text"=>"Pie chart showing figures of shipments which are soon to depart/arrive (Calculated from ETD/ETA).");
  1157. $Management[] = array("id"=>3 ,
  1158. "title"=>"Recent Status",
  1159. "switchValue"=>true,
  1160. "text"=>"A shipment list with latest status update on top.");
  1161. $Management[] = array("id"=>4 ,
  1162. "title"=>"ETD to ETA (Days)",
  1163. "switchValue"=>true,
  1164. "text"=>"Pie chart showing figures of shipments which are soon to depart/arrive (Calculated from ETD/ETA).");
  1165. $Management[] = array("id"=>5 ,
  1166. "title"=>"Container Count",
  1167. "switchValue"=>true,
  1168. "text"=>"Pie chart showing figures of shipments which are soon to depart/arrive (Calculated from ETD/ETA).");
  1169. $Management[] = array("id"=>6 ,
  1170. "title"=>"Top 10 Origin/Destination",
  1171. "switchValue"=>true,
  1172. "text"=>"Figure of the top 10 origin/destination.",
  1173. "title1"=>"Top 10 Origin",
  1174. "title2"=>"Top 10 Destination");
  1175. $Management[] = array("id"=>7 ,
  1176. "title"=>"CO2e Emission by Origin (Top 10)",
  1177. "switchValue"=>true,
  1178. "text"=>"Figure of the CO2e Emission by origin.");
  1179. $Management[] = array("id"=>8 ,
  1180. "title"=>"CO2e Emission by Destination (Top 10)",
  1181. "switchValue"=>true,
  1182. "text"=>"Figure of the CO2e Emission by destination.");
  1183. return $Management;
  1184. }
  1185. /**
  1186. * Destroy Session
  1187. */
  1188. public static function sessionDestroy() {
  1189. session_destroy();
  1190. setcookie(session_name(), '', time() - 3600);
  1191. $_SESSION = array();
  1192. }
  1193. public static function retStationInfo($address_1,$address_2,$address_3,$address_4,$city,$state,$country,$zipcode){
  1194. $stationInfo = "";
  1195. if(!empty($address_1)){
  1196. $stationInfo .= $address_1;
  1197. }
  1198. if(!empty($address_2)){
  1199. $stationInfo .= " ".$address_2;
  1200. }
  1201. if(!empty($address_3)){
  1202. $stationInfo .= " ".$address_3;
  1203. }
  1204. if(!empty($address_4)){
  1205. $stationInfo .= " ".$address_4;
  1206. }
  1207. $temp_str = "";
  1208. if(!empty($city)){
  1209. $temp_str .= $city." ";
  1210. }
  1211. if(!empty($state)){
  1212. $temp_str .= $state." ";
  1213. }
  1214. if(!empty($zipcode)){
  1215. $temp_str .= $zipcode." ";
  1216. }
  1217. if(!empty($country)){
  1218. $temp_str .= $country." ";
  1219. }
  1220. if(!empty($temp_str)){
  1221. return $stationInfo." ".trim($temp_str);
  1222. }
  1223. return $stationInfo;
  1224. }
  1225. public static function getInsertSqlNull($table_name, $values) {
  1226. $field = "";
  1227. $value = "";
  1228. foreach ($values as $k => $v) {
  1229. if ($k == 'tmp' || $k == 'action' || $k == 'operate' || $k == 'x' || $k == 'y') {
  1230. continue;
  1231. }
  1232. if (is_array($v)) {
  1233. $v = implode(",", $v);
  1234. }
  1235. if (empty($field)) {
  1236. $field = $k;
  1237. if (utils::checkExist($v, 'now()')) {
  1238. $value = $v;
  1239. } elseif ($v == null) {
  1240. $value .= 'null';
  1241. } elseif ($v == 'TRUE' || $v == 'FALSE') {
  1242. $value .= $v;
  1243. } else {
  1244. $value = '\'' . common::check_input($v) . '\'';
  1245. }
  1246. } else {
  1247. $field .= ',' . $k;
  1248. if (utils::checkExist($v, 'now()'))
  1249. $value .= ', now()';
  1250. elseif ($v == null) {
  1251. $value .= ',null';
  1252. } else if ($v == 'TRUE' || $v == 'FALSE') {
  1253. $value .= ',' . $v;
  1254. } else {
  1255. $value .= ', \'' . common::check_input($v) . '\'';
  1256. }
  1257. }
  1258. }
  1259. return 'insert into ' . $table_name . '(' . $field . ') values (' . $value . ')';
  1260. }
  1261. }
  1262. ?>