common.class.php 62 KB

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