common.class.php 62 KB

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