common.class.php 62 KB

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