common.class.php 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607
  1. <?php
  2. if (!defined('IN_ONLINE')) {
  3. exit('Access Denied');
  4. }
  5. /**
  6. * Description of common
  7. *
  8. * @author Administrator
  9. */
  10. class common {
  11. /*
  12. * mysql check input
  13. */
  14. public static function check_input($value, $boolean = FALSE, $toupper = FALSE) {
  15. if ($boolean !== FALSE) {
  16. if ($value == "t")
  17. return "'t'";
  18. else
  19. return "'f'";
  20. }
  21. $value = trim($value);
  22. if ($toupper !== FALSE)
  23. $value = mb_strtoupper($value);
  24. if (!is_numeric($value)) {
  25. $value = pg_escape_string($value);
  26. }
  27. return $value;
  28. }
  29. public static function excuteOneSql($sql, $exception = FALSE) {
  30. if ($exception) {
  31. global $db;
  32. $result = $db->GetOne($sql);
  33. return $result === FALSE ? null : $result;
  34. } else {
  35. if (empty($sql))
  36. exit(json_encode("Program encountered an error."));
  37. global $db;
  38. $result = $db->GetOne($sql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $sql), 0));
  39. return $result === FALSE ? null : $result;
  40. }
  41. }
  42. public static function excuteObjectSql($sql) {
  43. if (empty($sql))
  44. exit(json_encode("Program encountered an error."));
  45. global $db;
  46. $result = $db->GetRow($sql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $sql), 0));
  47. return $result === FALSE ? null : $result;
  48. }
  49. public static function excuteUpdateSql($sql, $req_id = FALSE) {
  50. if (empty($sql))
  51. exit(json_encode("Program encountered an error."));
  52. global $db;
  53. $rs = $db->Execute($sql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $sql), 0));
  54. if ($rs && $req_id !== FALSE)
  55. return $db->PO_Insert_ID();
  56. else
  57. return $rs;
  58. }
  59. public static function excuteListSql($sql, $exception = FALSE) {
  60. if ($exception) {
  61. global $db;
  62. $result = $db->GetAll($sql);
  63. return $result === FALSE ? null : $result;
  64. } else {
  65. if (empty($sql))
  66. exit(json_encode("Program encountered an error."));
  67. global $db;
  68. $result = $db->GetAll($sql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $sql), 0));
  69. return $result === FALSE ? null : $result;
  70. }
  71. }
  72. /*
  73. * Database log output
  74. */
  75. public static function dbLog($db, $sql) {
  76. $backMsg = $db->errorMsg() . ' sql=' . $sql;
  77. return $backMsg;
  78. }
  79. /*
  80. * get IP
  81. */
  82. public static function ip() {
  83. if (getenv("HTTP_X_FORWARDED_FOR"))
  84. return getenv("HTTP_X_FORWARDED_FOR");
  85. if (getenv("HTTP_CLIENT_IP"))
  86. return getenv("HTTP_CLIENT_IP");
  87. if (getenv("REMOTE_ADDR"))
  88. return getenv("REMOTE_ADDR");
  89. if ($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])
  90. return $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
  91. if ($HTTP_SERVER_VARS["HTTP_CLIENT_IP"])
  92. return $HTTP_SERVER_VARS["HTTP_CLIENT_IP"];
  93. if ($HTTP_SERVER_VARS["REMOTE_ADDR"])
  94. return $HTTP_SERVER_VARS["REMOTE_ADDR"];
  95. return "Unknown";
  96. }
  97. public static function getDBUuid() {
  98. global $db;
  99. $sql = "select uuid_generate_v1()";
  100. $uuid = $db->GetOne($sql);
  101. return $uuid;
  102. }
  103. public static function securityCheckHandNew($action) {
  104. if (strpos($action, "handset") === 0) {
  105. } elseif (strpos($action, "hand") === 0) {
  106. } else {
  107. common::sessionVerify();
  108. $httpAccept = $_SERVER['HTTP_ACCEPT']; // ajax request,is json or html
  109. $ajax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER
  110. ['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'; // is ajax request?
  111. //暂时这么写,放开action = main的查询是为了在没有登录时获取信息。
  112. //tools是为了避免查询的用户,没有配置tools权限,但是新版mark_save需要进入
  113. if($action == "main" || $action == "tools" || $action == "save_layout"){
  114. return;
  115. }
  116. if (!isset($_SESSION['ONLINE_USER'])) {
  117. self::timeoutPrintInfor($httpAccept, $ajax, 'no');
  118. } else {
  119. $time = time() - $_SESSION["LAST_OPERATE_TIME"];
  120. $set_session_timeout = $_SESSION['SESSION_TIMEOUT'];
  121. if (_getLoginName() == "ra.admin") {
  122. $set_session_timeout = 4 * 3600;
  123. }
  124. if ($time > $set_session_timeout) {
  125. self::timeoutPrintInfor($httpAccept, $ajax, 'yes');
  126. } else {
  127. $_SESSION["LAST_OPERATE_TIME"] = time();
  128. if (!_isAdmin() && $_GET["action"] != "linkcrm") {
  129. if (!utils::checkExist($_SESSION['ONLINE_USER']['permission'], $action)
  130. && !(stripos($action, "main") === 0)
  131. && !(stripos($action, "ajax") === 0)
  132. && !(stripos($action, "opreation_log") === 0)) {
  133. $data = array("msg"=>"Permission Denied");
  134. common::echo_json_encode(500, $data);
  135. exit();
  136. }
  137. }
  138. }
  139. }
  140. session_write_close();
  141. }
  142. }
  143. public static function getCompanySearch() {
  144. $sc_list = _get_schemas();
  145. if (count($sc_list) == 1) {
  146. return "";
  147. }
  148. if (_isCustomerLogin()) {
  149. $msg = '<input type="hidden" name="_apex_or_sfs" value=""/>';
  150. } else {
  151. $msg = '<div class="modules">Apex/SFS/Kerry :&nbsp;<select name="_apex_or_sfs" class="sl"><option value="">All</option>';
  152. if ($_SESSION['ONLINE_USER']['main_schemas'] == "public") {
  153. $msg .= '<option value="public">Apex</option>';
  154. } else {
  155. $msg .= '<option value="public">Apex</option>';
  156. }
  157. if ($_SESSION['ONLINE_USER']['main_schemas'] == "sfs") {
  158. $msg .= '<option value="sfs">SFS</option>';
  159. } else {
  160. $msg .= '<option value="sfs">SFS</option>';
  161. }
  162. if ($_SESSION['ONLINE_USER']['main_schemas'] == "kyiff") {
  163. $msg .= '<option value="kyiff">Kerry</option>';
  164. } else {
  165. $msg .= '<option value="kyiff">Kerry</option>';
  166. }
  167. $msg .= '</select></div>';
  168. }
  169. return $msg;
  170. }
  171. public static function sessionVerify() {
  172. if (!isset($_SESSION['user_agent'])) {
  173. $_SESSION['user_agent'] = MD5($_SERVER['REMOTE_ADDR']
  174. . $_SERVER['HTTP_USER_AGENT']);
  175. } elseif ($_SESSION['user_agent'] != MD5($_SERVER['REMOTE_ADDR']
  176. . $_SERVER['HTTP_USER_AGENT'])) {
  177. session_regenerate_id();
  178. }
  179. }
  180. public static function searchExtendHandNew($type, $user, $company_name = "station_name") {
  181. if (_isAdminHandNew($user)) {
  182. if(strtolower($type) == "air_booking" ) //|| strtolower($type) == "air"
  183. {
  184. return "1=1";
  185. }
  186. return " (schem_not_display is null or schem_not_display=false)";
  187. }
  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. //记录系统因session过期 退出登录
  519. utils::single_operation_log_save("logout","logout","System logout");
  520. $data = array("msg"=>"session_time_out");
  521. self::echo_json_encode(403,$data);
  522. exit();
  523. }
  524. private static function _oceanHandNew($user, $schemas = "public") {
  525. $o = $user['ocean_station'];
  526. $o_or = $user['ocean_station_or'];
  527. $d = $user['ocean_agent'];
  528. $d_or = $user['ocean_agent_or'];
  529. $sales = $user['ocean_sales'];
  530. $sales_or = $user['ocean_sales_or'];
  531. $op = $user['ocean_dest_op'];
  532. $op_or = $user['ocean_dest_op_or'];
  533. $follow = $user['ocean_following_sales'];
  534. $follow_or = $user['ocean_following_sales_or'];
  535. if (strtolower($o_or) == "all" || strtolower($d_or) == "all" || strtolower($sales_or) == "all" || strtolower($op_or) == "all") {
  536. return " and 1=1";
  537. }
  538. $sqlWhere = "";
  539. if (_isCustomerLoginHandNew($user)) {
  540. //error_log("_oceanHandNew".$schemas);
  541. $sqlWhere .= " and " . _customerFilerSearchHandNew($user, $schemas);
  542. } else {
  543. if (empty($o) && empty($d) && empty($sales) && empty($op) && empty($follow)) {
  544. return " and 1<>1";
  545. }
  546. if ((strtolower($o) == 'all' || empty($o)) && (strtolower($d) == "all" || empty($d))) {
  547. } else {
  548. $sql = "1=1";
  549. if (!empty($o) && strtolower($o) != 'all') {
  550. $sql .= " and lower(origin)";
  551. $sql .= utils::getInSql($o);
  552. }
  553. if (!empty($d) && strtolower($d) != 'all') {
  554. $sql .= " and lower(agent)";
  555. $sql .= utils::getInSql($d);
  556. }
  557. $sqlWhere .= " and (" . $sql . ")";
  558. }
  559. if (strtolower($sales) == 'all' || empty($sales)) {
  560. } else {
  561. if (utils::checkExist($sales, ";")) {
  562. $sql = "1!=1";
  563. $tt = explode(";", $sales);
  564. foreach ($tt as $t) {
  565. $t = trim($t);
  566. if (!empty($t))
  567. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  568. }
  569. $sqlWhere .= " and ($sql)";
  570. } else
  571. $sqlWhere .= " and lower(sales_rep)='" . strtolower($sales) . "'";
  572. }
  573. if (strtolower($op) == 'all' || empty($op)) {
  574. } else {
  575. $sqlWhere .= " and lower(dest_op) " . utils::getInSql($op);
  576. }
  577. if (strtolower($follow) == 'all' || empty($follow)) {
  578. } else {
  579. if (utils::checkExist($follow, ";")) {
  580. $sql = "1!=1";
  581. $tt = explode(";", $follow);
  582. foreach ($tt as $t) {
  583. $t = trim($t);
  584. if (!empty($t))
  585. $sql .= " or following_sales ilike '" . $t . "'";
  586. }
  587. $sqlWhere .= " and ($sql)";
  588. } else
  589. $sqlWhere .= " and following_sales ilike '" . $follow . "'";
  590. }
  591. $sqlWhere = " (1=1 $sqlWhere)";
  592. if (!empty($o_or)) {
  593. $sqlWhere .= " or lower(origin)";
  594. $sqlWhere .= utils::getInSql($o_or);
  595. }
  596. if (!empty($d_or)) {
  597. $sqlWhere .= " or lower(agent)";
  598. $sqlWhere .= utils::getInSql($d_or);
  599. }
  600. if (!empty($sales_or)) {
  601. if (utils::checkExist($sales_or, ";")) {
  602. $sql = "1!=1";
  603. $tt = explode(";", $sales_or);
  604. foreach ($tt as $t) {
  605. $t = trim($t);
  606. if (!empty($t))
  607. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  608. }
  609. $sqlWhere .= " or ($sql)";
  610. } else
  611. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales_or) . "'";
  612. }
  613. if (!empty($op_or)) {
  614. $sqlWhere .= " or lower(dest_op) " . utils::getInSql($op_or);
  615. }
  616. if (!empty($follow_or)) {
  617. if (utils::checkExist($follow_or, ";")) {
  618. $sql = "1!=1";
  619. $tt = explode(";", $follow_or);
  620. foreach ($tt as $t) {
  621. $t = trim($t);
  622. if (!empty($t))
  623. $sql .= " or following_sales ilike '" . $t . "'";
  624. }
  625. $sqlWhere .= " or ($sql)";
  626. }else {
  627. $sqlWhere .= " or following_sales ilike '" . $follow_or . "'";
  628. }
  629. }
  630. $sqlWhere = " and ($sqlWhere)";
  631. }
  632. return $sqlWhere;
  633. }
  634. private static function _bookingHandNew($user, $schames) {
  635. // if (_isDemo())
  636. // return " serial_no = 'D4DD1D79-83F4-4E65-9773-CF5277D72738'";
  637. $o = $user['ocean_station'];
  638. $o_or = $user['ocean_station_or'];
  639. $d = $user['ocean_agent'];
  640. $d_or = $user['ocean_agent_or'];
  641. $sales = $user['ocean_sales'];
  642. $sales_or = $user['ocean_sales_or'];
  643. $op = $user['ocean_dest_op'];
  644. $op_or = $user['ocean_dest_op_or'];
  645. $follow = $user['ocean_following_sales'];
  646. $follow_or = $user['ocean_following_sales_or'];
  647. if (strtolower($o_or) == "all" || strtolower($d_or) == "all" || strtolower($sales_or) == "all") {
  648. return " and 1=1";
  649. }
  650. // $sc_list = $user['schemas_list'];
  651. // if (empty($sc_list)) {
  652. // $sc_list = $_SESSION["schemas_list"];
  653. // }
  654. // if (empty($sc_list)) {
  655. // return " and 1<>1";
  656. // }
  657. // $sqlWhere = " and 1=1";
  658. // if ($user["is_kerry_shipment"] == "t") {
  659. // $sqlWhere = " and and is_kerry_shipment is not null and is_kerry_shipment=true";
  660. // } else if ($user["is_kerry_shipment"] == "f") {
  661. // $sqlWhere = " and (is_kerry_shipment is null or is_kerry_shipment=false)";
  662. // }
  663. // if (count($sc_list) == 1) {
  664. // $sch = $sc_list[0]['schemas_name'];
  665. // $sqlWhere .= " and order_from='$sch'";
  666. // } else {
  667. // $sqlWhere .= " and (schem_not_display is null or schem_not_display=false)";
  668. // }
  669. $sqlWhere = "";
  670. if (_isCustomerLoginHandNew($user)) {
  671. $sqlWhere .= " and " . _customerFilerSearchHandNew($user, $schames);
  672. } else {
  673. if (empty($o) && empty($d) && empty($sales) && empty($op) && empty($follow)) {
  674. return " and 1<>1";
  675. }
  676. if ((strtolower($o) == 'all' || empty($o)) && (strtolower($d) == "all" || empty($d))) {
  677. } else {
  678. $sql = "1=1";
  679. if (!empty($o) && strtolower($o) != 'all') {
  680. $sql .= " and lower(origin)";
  681. $sql .= utils::getInSql($o);
  682. }
  683. if (!empty($d) && strtolower($d) != 'all') {
  684. $sql .= " and lower(agent)";
  685. $sql .= utils::getInSql($d);
  686. }
  687. $sqlWhere .= " and (" . $sql . ")";
  688. }
  689. if (strtolower($sales) == 'all' || empty($sales)) {
  690. } else {
  691. if (utils::checkExist($sales, ";")) {
  692. $sql = "1!=1";
  693. $tt = explode(";", $sales);
  694. foreach ($tt as $t) {
  695. $t = trim($t);
  696. if (!empty($t))
  697. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  698. }
  699. $sqlWhere .= " and ($sql)";
  700. } else
  701. $sqlWhere .= " and lower(sales_rep)='" . strtolower($sales) . "'";
  702. }
  703. if (strtolower($follow) == 'all' || empty($follow)) {
  704. } else {
  705. if (utils::checkExist($follow, ";")) {
  706. $sql = "1!=1";
  707. $tt = explode(";", $follow);
  708. foreach ($tt as $t) {
  709. $t = trim($t);
  710. if (!empty($t))
  711. $sql .= " or following_sales ilike '" . $t . "%'";
  712. }
  713. $sqlWhere .= " and ($sql)";
  714. } else
  715. $sqlWhere .= " and following_sales ilike '" . $follow . "%'";
  716. }
  717. $sqlWhere = " (1=1 $sqlWhere)";
  718. if (!empty($o_or)) {
  719. $sqlWhere .= " or lower(origin)";
  720. $sqlWhere .= utils::getInSql($o_or);
  721. }
  722. if (!empty($d_or)) {
  723. $sqlWhere .= " or lower(agent)";
  724. $sqlWhere .= utils::getInSql($d_or);
  725. }
  726. if (!empty($sales_or)) {
  727. if (utils::checkExist($sales_or, ";")) {
  728. $sql = "1!=1";
  729. $tt = explode(";", $sales_or);
  730. foreach ($tt as $t) {
  731. $t = trim($t);
  732. if (!empty($t))
  733. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  734. }
  735. $sqlWhere .= " or ($sql)";
  736. } else
  737. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales_or) . "%'";
  738. }
  739. if (!empty($follow_or)) {
  740. if (utils::checkExist($follow_or, ";")) {
  741. $sql = "1!=1";
  742. $tt = explode(";", $follow_or);
  743. foreach ($tt as $t) {
  744. $t = trim($t);
  745. if (!empty($t))
  746. $sql .= " or following_sales ilike '" . $t . "%'";
  747. }
  748. $sqlWhere .= " or ($sql)";
  749. } else
  750. $sqlWhere .= " or following_sales ilike '" . $follow_or . "%'";
  751. }
  752. $sqlWhere = " and ($sqlWhere)";
  753. }
  754. return $sqlWhere;
  755. }
  756. private static function _airHandNew($user, $schemas = "public")
  757. {
  758. if($schemas=="public")
  759. {
  760. $station = $user['air_station'];
  761. $station_or = $user['air_station_or'];
  762. $sales = $user['air_sales'];
  763. $sales_or = $user['air_sales_or'];
  764. }
  765. else
  766. {
  767. $station = $user[$schemas."_ONLINE_USER"]['air_station'];
  768. $station_or = $user[$schemas."_ONLINE_USER"]['air_station_or'];
  769. $sales = $user[$schemas."_ONLINE_USER"]['air_sales'];
  770. $sales_or = $user[$schemas."_ONLINE_USER"]['air_sales_or'];
  771. }
  772. if (strtolower($station_or) == "all" || strtolower($sales_or) == "all" ) //|| strtolower($d_or) == "all"|| strtolower($op_or) == "all"|| strtolower($follow_or) == "all"
  773. {
  774. return " and 1=1";
  775. }
  776. $sqlWhere = "";
  777. if (_isCustomerLoginHandNew($user)) {
  778. //error_log("_oceanHandNew".$schemas);
  779. $sqlWhere .= " and " . _customerFilerSearchHandNew_Air($user, $schemas);
  780. }
  781. else
  782. {
  783. if (empty($station) && empty($sales) ) //&& empty($d)&& empty($op) && empty($follow)
  784. {
  785. return " and 1<>1";
  786. }
  787. if ((strtolower($station) == 'all' || empty($station)) ) //&& (strtolower($d) == "all" || empty($d))
  788. {
  789. }
  790. else
  791. {
  792. $sql = "1=1";
  793. if (!empty($station) && strtolower($station) != 'all') {
  794. $sql .= " and (lower(origin)";
  795. $sql .= utils::getInSql($station);
  796. $sql .= " or lower(destination_station)";
  797. $sql .= utils::getInSql($station);
  798. $sql .= ")";
  799. }
  800. $sqlWhere .= " and (" . $sql . ")";
  801. }
  802. if (strtolower($sales) == 'all' || empty($sales)) {
  803. } else
  804. {
  805. if (utils::checkExist($sales, ";")) {
  806. $sql = "1!=1";
  807. $tt = explode(";", $sales);
  808. foreach ($tt as $t) {
  809. $t = trim($t);
  810. if (!empty($t))
  811. {
  812. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  813. $sql .= " or lower(following_sales)='" . strtolower($t) . "'";
  814. }
  815. }
  816. $sqlWhere .= " and ($sql)";
  817. } else
  818. {
  819. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales) . "'";
  820. $sqlWhere .= " or lower(following_sales)='" . strtolower($sales) . "'";
  821. }
  822. }
  823. $sqlWhere = " (1=1 $sqlWhere)";
  824. if (!empty($station_or)) {
  825. $sqlWhere .= " or lower(origin)";
  826. $sqlWhere .= utils::getInSql($station_or);
  827. $sqlWhere .= " or lower(destination_station)";
  828. $sqlWhere .= utils::getInSql($station_or);
  829. }
  830. if (!empty($sales_or)) {
  831. if (utils::checkExist($sales_or, ";")) {
  832. $sql = "1!=1";
  833. $tt = explode(";", $sales_or);
  834. foreach ($tt as $t) {
  835. $t = trim($t);
  836. if (!empty($t))
  837. {
  838. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  839. $sql .= " or lower(following_sales)='" . strtolower($t) . "'";
  840. }
  841. }
  842. $sqlWhere .= " or ($sql)";
  843. } else
  844. {
  845. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales_or) . "'";
  846. $sqlWhere .= " or lower(following_sales)='" . strtolower($sales_or) . "'";
  847. }
  848. }
  849. $sqlWhere = " and ($sqlWhere)";
  850. }
  851. return $sqlWhere;
  852. }
  853. public static function isNewVersion() {
  854. if (utils::checkExist($_SERVER['PHP_SELF'], "main_new_version.php")) {
  855. return "_new";
  856. }
  857. return "";
  858. }
  859. public static function removeTopOceanOldVersionSpecialField($rss){
  860. $rss_bk = $rss;
  861. $new_arr = array();
  862. foreach ($rss_bk as $k => $v) {
  863. if (utils::startWith($v['database_column_name'], "__") || utils::startWith($v['database_column_name'], "___")){
  864. //unset($rss[$k]);
  865. }else{
  866. $new_arr[] = $v;
  867. }
  868. }
  869. return $new_arr;
  870. }
  871. public static function echo_json_encode($code,$data){
  872. $resData = array();
  873. $resData["code"] = $code;
  874. $resData["data"] =$data;
  875. echo utils::jsonFiltration("null", "\"\"", json_encode($resData));
  876. }
  877. /*
  878. * MM/DD/YYYY To YYYY-MM-DD
  879. */
  880. public static function usDate2sqlDate($timestr) {
  881. if (empty($timestr))
  882. return '';
  883. $datearray = explode("/", $timestr);
  884. $m = $datearray [0];
  885. $d = $datearray [1];
  886. $y = $datearray [2];
  887. return $y . "-" . $m . "-" . $d;
  888. }
  889. public static function uuid() {
  890. return md5(uniqid("", TRUE) . mt_rand());
  891. }
  892. /*
  893. * YYYYMMDD To MM/DD/YYYY
  894. */
  895. public static function date2usdate($datestr) {
  896. if (empty($datestr))
  897. return '';
  898. $y = substr($datestr, 0, 4);
  899. $m = substr($datestr, 4, 2);
  900. $d = substr($datestr, 6, 2);
  901. return $m . "/" . $d . "/" . $y;
  902. }
  903. /*
  904. * date add some days
  905. */
  906. public static function addDays($date, $days) {
  907. $time = strtotime($date) + $days * 24 * 3600;
  908. return date('m/d/Y', $time);
  909. }
  910. /*
  911. * download file from file system
  912. */
  913. public static function download_file($filename, $display_name = null, $delete = FALSE, $files = NULL) {
  914. $filename = str_replace("/", DIRECTORY_SEPARATOR, $filename);
  915. $filename = str_replace("\\", DIRECTORY_SEPARATOR, $filename);
  916. if (!file_exists($filename))
  917. exit('File Not Exist');
  918. if (empty($display_name))
  919. $display_name = basename($filename);
  920. //$file = fopen($filename, "r");
  921. header_remove("Content-type");
  922. header("Content-type:" . self::getContentType($filename));
  923. header("Expires: 0");
  924. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  925. header("Pragma: can-cache");
  926. header("Accept-ranges:bytes");
  927. header("Accept-length:" . filesize($filename));
  928. header("Content-Disposition:attachment;filename=\"" . $display_name . "\"");
  929. //echo fread($file, filesize($filename));
  930. //fclose($file);
  931. //针对大文件,规定每次读取文件的字节数为4096字节,直接输出数据
  932. $read_buffer = 4096;
  933. $handle = fopen($filename, 'rb');
  934. //总的缓冲的字节数
  935. $sum_buffer = 0;
  936. $filesize = filesize($filename);
  937. //只要没到文件尾,就一直读取
  938. while (!feof($handle) && $sum_buffer < $filesize) {
  939. echo fread($handle, $read_buffer);
  940. $sum_buffer += $read_buffer;
  941. }
  942. //关闭句柄
  943. fclose($handle);
  944. if ($delete !== FALSE) {
  945. unlink($filename);
  946. }
  947. if (!empty($files)) {
  948. foreach ($files as $f) {
  949. unlink($f);
  950. }
  951. }
  952. }
  953. public static function getContentType($filename) {
  954. $extend = self::getExtendFilename($filename);
  955. $filetype = array(
  956. 'xls' => 'application/vnd.ms-excel',
  957. 'doc' => 'application/msword',
  958. 'gif' => 'image/gif',
  959. 'jpg' => 'image/jpeg',
  960. 'jpeg' => 'image/jpeg',
  961. 'jpe' => 'image/jpeg',
  962. 'bmp' => 'image/bmp',
  963. 'png' => 'image/png',
  964. 'tif' => 'image/tiff',
  965. 'pdf' => 'application/pdf',
  966. 'zip' => 'application/zip'
  967. );
  968. return $filetype[$extend];
  969. }
  970. /*
  971. * Get the file extension
  972. */
  973. public static function getExtendFilename($file_name) {
  974. $extend = pathinfo($file_name);
  975. $extend = strtolower($extend["extension"]);
  976. return $extend;
  977. }
  978. public static function getManagement(){
  979. //Management 自己配置需要创建表保存
  980. $user_management_data = common::excuteObjectSql("select management,dashboard_filter from ra_online_user where user_login = '"._getLoginName()."'");
  981. //为空,配置使用默认值
  982. $user_management = $user_management_data['management'];
  983. if(empty($user_management)){
  984. $Management = common::getdefaultManagement();
  985. }else{
  986. $Management = json_decode($user_management,true);
  987. foreach($Management as $key =>$val){
  988. $Management[$key]['id'] = intval($val['id']);
  989. $Management[$key]['switchValue'] = $val['switchValue'] == "true" ? true : false;
  990. }
  991. }
  992. return array("Management" => $Management,"dashboard_filter" =>$user_management_data['dashboard_filter']);
  993. }
  994. public static function getItemStyle($type,$code){
  995. if($type == 'r1'){
  996. $data = array("0-20 Days" =>"#ffc594",
  997. "20-40 Days" =>"#ff9e4c",
  998. "40-60 Days" =>"#ff7500",
  999. "60-80 Days" =>"#ff3d00",
  1000. "Over 80 Days" =>"#d50000");
  1001. return $data[$code];
  1002. }
  1003. if($type == 'r4' || $type == 'r3' || $type == 'atd_r4' || $type == 'ata_r3'){
  1004. $data = array("0 Day" =>"#ffc594",
  1005. "Today" =>"#ffc594",
  1006. "1-2 Days" =>"#ff9e4c",
  1007. "3-6 Days" =>"#ff7500",
  1008. "7 Days" =>"#ff3d00");
  1009. return $data[$code];
  1010. }
  1011. if($type == 'r2' || utils::startWith($type,"co2e")){
  1012. $data = array("45" =>"#FFE3CC",
  1013. "40" =>"#FFAC66",
  1014. "20" =>"#FF7500",
  1015. "air" =>"#FFE3CC",
  1016. "sea" =>"#FFAC66",
  1017. "road" =>"#FF7500");
  1018. return $data[$code];
  1019. }
  1020. if($type == "top"){
  1021. $data = array("1" =>"#FF7500",
  1022. "2" =>"#ff9033",
  1023. "3" =>"#ff9e4d",
  1024. "4" =>"#ffac66",
  1025. "5" =>"#ffba80",
  1026. "6" =>"#ffc899",
  1027. "7" =>"#ffd6b3",
  1028. "8" =>"#ffe3cc",
  1029. "9" =>"#fff1e6",
  1030. "10" =>"#fff1e6");
  1031. return $data[$code];
  1032. }
  1033. }
  1034. //处理返回原表数据格式
  1035. public static function mian_repot_do($value,$type,$totalValue){
  1036. $data = array();
  1037. $value_arr = json_decode($value,true);
  1038. //r1 是 ETD to ETA (Days)圆形图表数据结构返回
  1039. if($type == 'r1'){
  1040. $ETDList = array();
  1041. foreach($value_arr as $arr){
  1042. $color = common::getItemStyle($type,$arr['name']);
  1043. $ETDList[] = array("value" =>intval($arr['value']),"name" =>$arr['name'],"itemStyle" =>array("color" =>$color));
  1044. }
  1045. $ETDList = array_reverse($ETDList);
  1046. $ETD_Title = "Total: $totalValue";
  1047. $data = array("ETDList" =>$ETDList,"ETD_Radius"=>array('50%','80%'),"ETD_Title" =>$ETD_Title);
  1048. }
  1049. if($type == 'r4' || $type == 'r3'){
  1050. //重新整理一下数据,给UI一致
  1051. $data_kd = array();
  1052. foreach($value_arr as $arr){
  1053. if(stripos("Today", $arr['name']) !== false){
  1054. $color = common::getItemStyle($type,"Today");
  1055. if(empty($data_kd["0"])){
  1056. $data_kd["0"] = array("value" =>intval($arr['value']),"name" =>"0 Day","itemStyle" =>array("color" =>$color));
  1057. }else{
  1058. $data_kd["0"]["value"] = $data_kd["0"]["value"] + intval($arr['value']);
  1059. }
  1060. }
  1061. if(stripos("+1 Days/+2 Days", $arr['name']) !== false){
  1062. $color = common::getItemStyle($type,"1-2 Days");
  1063. if(empty($data_kd["1"])){
  1064. $data_kd["1"] = array("value" =>intval($arr['value']),"name" =>"1-2 Days","itemStyle" =>array("color" =>$color));
  1065. }else{
  1066. $data_kd["1"]["value"] = $data_kd["1"]["value"] + intval($arr['value']);
  1067. }
  1068. }
  1069. if(stripos("+3 Days/+4 Days/+5 Days/+6 Days", $arr['name']) !== false){
  1070. $color = common::getItemStyle($type,"3-6 Days");
  1071. if(empty($data_kd["2"])){
  1072. $data_kd["2"] = array("value" =>intval($arr['value']),"name" =>"3-6 Days","itemStyle" =>array("color" =>$color));
  1073. }else{
  1074. $data_kd["2"]["value"] = $data_kd["2"]["value"] + intval($arr['value']);
  1075. }
  1076. }
  1077. if(stripos("+7 Days/Over 7 Days", $arr['name']) !== false){
  1078. $color = common::getItemStyle($type,"7 Days");
  1079. if(empty($data_kd["3"])){
  1080. $data_kd["3"] = array("value" =>intval($arr['value']),"name" =>"7 Days","itemStyle" =>array("color" =>$color));
  1081. }else{
  1082. $data_kd["3"]["value"] = $data_kd["3"]["value"] + intval($arr['value']);
  1083. }
  1084. }
  1085. }
  1086. if($type == 'r4'){
  1087. $data = array("ETDList" =>$data_kd,"ETD_Radius"=>array('30%','50%'),"title1" =>"Pending","title2" =>"(ATD-ETD)");
  1088. }
  1089. if($type == 'r3'){
  1090. $data = array("ETDList" =>$data_kd,"ETD_Radius"=>array('30%','50%'),"title1" =>"Pending","title2" =>"(ATD-ETD)");
  1091. }
  1092. }
  1093. return $data;
  1094. }
  1095. //单独处理co2e bar
  1096. public static function getCo2eBar(){
  1097. //新UI air sea road 目前只有sea
  1098. $type = $_REQUEST["r_type"];
  1099. $shipment_mode_arr = array("air","sea","road");
  1100. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  1101. $sqlWhere = " " . $sqlWhere;
  1102. $ContainerCount_Title = array();
  1103. //先查询总的排放量sea air road,确定排名后,在分别查询对应的sea air road
  1104. if ($type == "co2e_orgin"){
  1105. $co2e_shippr_sql = "select SUM(COALESCE(carbon_emission,0)::numeric(12,10)) as catnum ,
  1106. shippr_uncode as station from online_ocean where 1=1 $sqlWhere group by shippr_uncode order by catnum desc limit 10";
  1107. $co2e_aLL = common::excuteListSql($co2e_shippr_sql);
  1108. }
  1109. if ($type == "co2e_destination"){
  1110. $co2e_consignee_sql = "select SUM(COALESCE(carbon_emission,0)::numeric(12,10)) as catnum,
  1111. consignee_uncode as station from online_ocean where 1=1 $sqlWhere group by consignee_uncode order by catnum desc limit 10";
  1112. $co2e_aLL = common::excuteListSql($co2e_consignee_sql);
  1113. }
  1114. //最大Y值
  1115. $maxY = 0;
  1116. $stations = array();
  1117. foreach($co2e_aLL as $val){
  1118. $ContainerCount_Title[] = $val['station'];
  1119. $maxY = $maxY > $val['catnum'] ? $maxY : $val['catnum'];
  1120. $stations[] = $val['station'];
  1121. }
  1122. $station_str = utils::implode(',',$stations);
  1123. $ContainerCounSeries = array();
  1124. foreach($shipment_mode_arr as $_shipment_mode){
  1125. //类型有 sea air road,目前之类只查询sea的,其他为空
  1126. $shipment_mode = $_shipment_mode;
  1127. $co2e = array();
  1128. if ($type == "co2e_orgin"){
  1129. $co2e_shippr_sql_union = utils::_getSql($station_str,$type,$shipment_mode);
  1130. if(!empty($co2e_shippr_sql_union)){
  1131. $co2e = common::excuteListSql($co2e_shippr_sql_union);
  1132. }
  1133. }
  1134. if ($type == "co2e_destination"){
  1135. $co2e_consignee_union = utils::_getSql($station_str,$type,$shipment_mode);
  1136. if(!empty($co2e_consignee_union)){
  1137. $co2e = common::excuteListSql($co2e_consignee_union);
  1138. }
  1139. }
  1140. $total = 0;
  1141. $max = 0;
  1142. $data = array();
  1143. foreach($co2e as $val){
  1144. $data[] = $val['catnum'];
  1145. $total = $total + $val['catnum'];
  1146. $max = $max < $val['catnum'] ? $val['catnum'] : $max;
  1147. }
  1148. $ContainerCounSeries[$shipment_mode] = array("data"=>$data,"total"=>$total,"max"=>$max);
  1149. }
  1150. //处理返回时数据格式 其实不太需要计算最大值,在最开始总量查询的时候以及查询出来
  1151. $ContainerCounSeries_return = array();
  1152. foreach($ContainerCounSeries as $k =>$v){
  1153. $color = common::getItemStyle($type,$k);
  1154. $ContainerCounSeries_return[] = array("name"=>$k,"type"=>"bar","emphasis" => array("focus" =>"none"),
  1155. "stack" =>"总计","data" =>$v['data'],"itemStyle" =>array("color" =>$color));
  1156. }
  1157. //处理返回原表数据格式
  1158. //计算刻度值 最小值是0,最大值是3000,刻度是500 interval
  1159. $interval = utils::calculateTicks(0,$maxY,10);
  1160. if($interval == 0){
  1161. //处理返回默认值
  1162. $interval = 1;
  1163. }
  1164. $returnData = array("ContainerCount_Title"=>"","ContainerCountList" =>$ContainerCount_Title,"ContainerCounSeries" =>$ContainerCounSeries_return,
  1165. "min" => 0,"Max" =>$interval*10,"interval" =>$interval);
  1166. return $returnData;
  1167. }
  1168. public static function getTopBar(){
  1169. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  1170. $sqlWhere = " " . $sqlWhere;
  1171. $toporiginType = "shippr_uncode";
  1172. $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";
  1173. $shippr_uncode_10 = common::excuteListSql($shippr_uncode_10_sql);
  1174. //如果值没有:客户地址-->站点地址-->Port地址(POL/POD)
  1175. if(count($shippr_uncode_10) == 1 && empty($shippr_uncode_10[0]["shippr_uncode"])){
  1176. $toporiginType = "fport_of_loading_un";
  1177. $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";
  1178. $shippr_uncode_10 = common::excuteListSql($shippr_uncode_10_sql);
  1179. }
  1180. //$toporiginType = "fport_of_loading_un";
  1181. $topdestinationinType = "consignee_uncode";
  1182. $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";
  1183. $consignee_uncode_10 = common::excuteListSql($consignee_uncode_10_sql);
  1184. //如果值没有:客户地址-->站点地址-->Port地址(POL/POD)
  1185. if(count($consignee_uncode_10) == 1 && empty($consignee_uncode_10[0]["consignee_uncode"])){
  1186. $topdestinationinType = "mport_of_discharge_un";
  1187. $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";
  1188. $consignee_uncode_10 = common::excuteListSql($consignee_uncode_10_sql);
  1189. }
  1190. $toporigin = array();
  1191. $toporiginMap = array();
  1192. $i = 0;
  1193. $origiNunMax = 0;
  1194. foreach($shippr_uncode_10 as $orgin){
  1195. $i = $i + 1;
  1196. $map_sql = "select lon as lng, lat as lat,
  1197. '' as label, '' as infor, 3 as sort,
  1198. null::timestamp without time zone as stime,''::text as ptype
  1199. 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']."'";
  1200. $map = common::excuteObjectSql($map_sql);
  1201. //$json = '{"lng":121.8525,"lat":29.926545,"label":"'.$orgin['origin'].'","infor":"LAT KRABANG, THAILAND","sort":"0","stime":null,"ptype":"por"}';
  1202. //$map = json_decode($json,true);
  1203. if(!empty($map)){
  1204. $toporiginMap[] = array("qandl"=>array(floatval($map['lat']),floatval($map['lng'])),
  1205. "divIcon" => array("iconSize"=>0),
  1206. "name" =>$orgin['shippr_uncode'],
  1207. "color" =>common::getItemStyle("top",$i),
  1208. "value" =>$orgin['num'],
  1209. "textcolor" =>"#FFF");
  1210. }
  1211. //查询uncode,对应的city
  1212. $city = array();
  1213. $city['city'] = "";
  1214. if($toporiginType == "shippr_uncode"){
  1215. $public_ports_sql = "select shipper_city as city from online_ocean
  1216. where 1=1 $sqlWhere and shippr_uncode = '".$orgin['shippr_uncode']."'
  1217. order by id limit 1";
  1218. $city = common::excuteObjectSql($public_ports_sql);
  1219. }
  1220. //$city 做假数据
  1221. //$city['city'] = "CATARINA, TX".$i;
  1222. $toporigin[] = array("name"=>$orgin['shippr_uncode'],"city_name"=>$city['city'],"value"=>$orgin['num'],"color"=>common::getItemStyle("top",$i));
  1223. $origiNunMax = $origiNunMax < $orgin['num'] ? $orgin['num'] : $origiNunMax;
  1224. }
  1225. $topdestination = array();
  1226. $topdestinationinMap = array();
  1227. $i = 0;
  1228. $agentiNunMax = 0;
  1229. foreach($consignee_uncode_10 as $agent){
  1230. $i = $i + 1;
  1231. $map_sql = "select lon as lng, lat as lat,
  1232. '' as label, '' as infor, 3 as sort,
  1233. null::timestamp without time zone as stime,''::text as ptype
  1234. 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']."'";
  1235. $map = common::excuteObjectSql($map_sql);
  1236. // $json = '{"lng":"100.78594000","lat":"13.68521000","label":"'.$agent['agent'].'","infor":"LAT KRABANG, THAILAND","sort":"0","stime":null,"ptype":"por"}';
  1237. // $map = json_decode($json,true);
  1238. if(!empty($map)){
  1239. $topdestinationinMap[] = array("qandl"=>array(floatval($map['lat']),floatval($map['lng'])),
  1240. "divIcon" => array("iconSize"=>0),
  1241. "name" =>$agent['consignee_uncode'],
  1242. "color" =>common::getItemStyle("top",$i),
  1243. "value" =>$agent['num'],
  1244. "textcolor" =>"#FFF");
  1245. }
  1246. //查询uncode,对应的city
  1247. $city = array();
  1248. $city['city'] = "";
  1249. if($topdestinationinType == "consignee_uncode"){
  1250. $public_ports_sql = "select consignee_city as city from online_ocean
  1251. where 1=1 $sqlWhere and consignee_uncode = '".$agent['consignee_uncode']."'
  1252. order by id limit 1";
  1253. $city = common::excuteObjectSql($public_ports_sql);
  1254. }
  1255. //$city 做假数据
  1256. //$city['city'] = "CATARINA, TX".$i;
  1257. $topdestination[] = array("name"=>$agent['consignee_uncode'],"city_name"=>$city['city'],"value"=>$agent['num'],"color"=>common::getItemStyle("top",$i));
  1258. $agentiNunMax = $agentiNunMax < $agent['num'] ? $agent['num'] : $agentiNunMax;
  1259. }
  1260. //处理返回原表数据格式
  1261. $interval = utils::calculateTicks(0,$origiNunMax,10);
  1262. if($interval == 0){
  1263. //处理返回默认值
  1264. $interval = 1;
  1265. }
  1266. $dest_interval = utils::calculateTicks(0,$agentiNunMax,10);
  1267. if($dest_interval == 0){
  1268. //处理返回默认值
  1269. $dest_interval = 1;
  1270. }
  1271. $returnData = array("seller_data_list_origin"=>$toporigin,"toporiginMap"=>array_reverse($toporiginMap),"toporiginType"=>$toporiginType,
  1272. "seller_data_list_destination"=>$topdestination,"topdestinationinMap"=>array_reverse($topdestinationinMap),"topdestinationinType"=>$topdestinationinType,
  1273. "min" => 0,"Max" =>$interval*10,"interval" =>$interval,
  1274. "dest_min" => 0,"dest_Max" =>$dest_interval*10,"dest_interval" =>$dest_interval);
  1275. return $returnData;
  1276. }
  1277. public static function getdefaultManagement(){
  1278. $Management = array();
  1279. $Management[] = array("id"=>1 ,
  1280. "title"=>"KPI",
  1281. "switchValue"=>true,
  1282. "text"=>"Pie chart showing figures of shipments KPI of Departure and Arrival.");
  1283. $Management[] = array("id"=>2 ,
  1284. "title"=>"Pending Departure & Arrival",
  1285. "switchValue"=>true,
  1286. "text"=>"Pie chart showing figures of shipments which are soon to depart/arrive (Calculated from ETD/ETA).");
  1287. $Management[] = array("id"=>3 ,
  1288. "title"=>"Recent Status",
  1289. "switchValue"=>true,
  1290. "text"=>"A shipment list with latest status update on top.");
  1291. $Management[] = array("id"=>4 ,
  1292. "title"=>"ETD to ETA (Days)",
  1293. "switchValue"=>true,
  1294. "text"=>"Pie chart showing figures of shipments which are soon to depart/arrive (Calculated from ETD/ETA).");
  1295. $Management[] = array("id"=>5 ,
  1296. "title"=>"Container Count",
  1297. "switchValue"=>true,
  1298. "text"=>"Pie chart showing figures of shipments which are soon to depart/arrive (Calculated from ETD/ETA).");
  1299. $Management[] = array("id"=>6 ,
  1300. "title"=>"Top 10 Origin/Destination",
  1301. "switchValue"=>true,
  1302. "text"=>"Figure of the top 10 origin/destination.",
  1303. "title1"=>"Top 10 Origin",
  1304. "title2"=>"Top 10 Destination");
  1305. $Management[] = array("id"=>7 ,
  1306. "title"=>"CO2e Emission by Origin (Top 10)",
  1307. "switchValue"=>true,
  1308. "text"=>"Figure of the CO2e Emission by origin.");
  1309. $Management[] = array("id"=>8 ,
  1310. "title"=>"CO2e Emission by Destination (Top 10)",
  1311. "switchValue"=>true,
  1312. "text"=>"Figure of the CO2e Emission by destination.");
  1313. return $Management;
  1314. }
  1315. /**
  1316. * Destroy Session
  1317. */
  1318. public static function sessionDestroy() {
  1319. session_destroy();
  1320. setcookie(session_name(), '', time() - 3600);
  1321. $_SESSION = array();
  1322. }
  1323. public static function retStationInfo($address_1,$address_2,$address_3,$address_4,$city,$state,$country,$zipcode){
  1324. $stationInfo = "";
  1325. if(!empty($address_1)){
  1326. $stationInfo .= $address_1;
  1327. }
  1328. if(!empty($address_2)){
  1329. $stationInfo .= " ".$address_2;
  1330. }
  1331. if(!empty($address_3)){
  1332. $stationInfo .= " ".$address_3;
  1333. }
  1334. if(!empty($address_4)){
  1335. $stationInfo .= " ".$address_4;
  1336. }
  1337. $temp_str = "";
  1338. if(!empty($city)){
  1339. $temp_str .= $city." ";
  1340. }
  1341. if(!empty($state)){
  1342. $temp_str .= $state." ";
  1343. }
  1344. if(!empty($zipcode)){
  1345. $temp_str .= $zipcode." ";
  1346. }
  1347. if(!empty($country)){
  1348. $temp_str .= $country." ";
  1349. }
  1350. if(!empty($temp_str)){
  1351. return $stationInfo." ".trim($temp_str);
  1352. }
  1353. return $stationInfo;
  1354. }
  1355. public static function getInsertSqlNull($table_name, $values) {
  1356. $field = "";
  1357. $value = "";
  1358. foreach ($values as $k => $v) {
  1359. if ($k == 'tmp' || $k == 'action' || $k == 'operate' || $k == 'x' || $k == 'y') {
  1360. continue;
  1361. }
  1362. if (is_array($v)) {
  1363. $v = utils::implode(",", $v);
  1364. }
  1365. if (empty($field)) {
  1366. $field = $k;
  1367. if (utils::checkExist($v, 'now()')) {
  1368. $value = $v;
  1369. } elseif ($v == null) {
  1370. $value .= 'null';
  1371. } elseif ($v == 'TRUE' || $v == 'FALSE') {
  1372. $value .= $v;
  1373. } else {
  1374. $value = '\'' . common::check_input($v) . '\'';
  1375. }
  1376. } else {
  1377. $field .= ',' . $k;
  1378. if (utils::checkExist($v, 'now()'))
  1379. $value .= ', now()';
  1380. elseif ($v == null) {
  1381. $value .= ',null';
  1382. } else if ($v == 'TRUE' || $v == 'FALSE') {
  1383. $value .= ',' . $v;
  1384. } else {
  1385. $value .= ', \'' . common::check_input($v) . '\'';
  1386. }
  1387. }
  1388. }
  1389. return 'insert into ' . $table_name . '(' . $field . ') values (' . $value . ')';
  1390. }
  1391. //密码规则验证
  1392. public static function checkPasswordRule($login, $new_password){
  1393. $sql="select item_value from config where item='passwordCheckRules'";
  1394. $rs = common::excuteObjectSql($sql);
  1395. $str = "";
  1396. if (!empty($rs)) {
  1397. $passwordCheckRules = json_decode($rs["item_value"],true);
  1398. //校验使用次数
  1399. if (!empty($passwordCheckRules["pastPasswordCheckNum"])) {
  1400. $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"];
  1401. $passwords = common::excuteListSql($sql);
  1402. foreach ($passwords as $pwd) {
  1403. if ($pwd['password'] == $new_password) {
  1404. $str = "This password has been recently used";
  1405. }
  1406. }
  1407. }
  1408. if(empty($str)){
  1409. $str = utils::checkPassword($new_password,$passwordCheckRules,$login);
  1410. }
  1411. }else{
  1412. $str = utils::checkPassword($new_password);
  1413. }
  1414. return $str;
  1415. }
  1416. public static function getMilestonesInfo($ocean){
  1417. //Milestones info 列名固定
  1418. $Milestones_column = array();
  1419. $Milestones_column[] = array("title" =>"Milestones","field" =>"milestones","formatter" =>"normal","type" =>"normal");
  1420. $Milestones_column[] = array("title" =>"Date Time","field" =>"date_time","formatter" =>"dateTime","type" =>"normal");
  1421. $Milestones_column[] = array("title" =>"Locations","field" =>"locations","formatter" =>"normal","type" =>"normal");
  1422. $Milestones_column[] = array("title" =>"Remarks","field" =>"remarks","formatter" =>"normal","type" =>"normal");
  1423. //IFF Event and EDI 315 Mapping
  1424. $Mapping = array("IFFREC","IFFONB","IFFDEP","IFFARR","IFFUND","IFFAFD","IFFCTA","IFFICC","IFFPPD","IFFECP");
  1425. $Mapping_location = array();
  1426. foreach($Mapping as $code){
  1427. if($code == "IFFREC" || $code == "IFFONB" || $code == "IFFDEP" || $code == "IFFECP"){
  1428. //Place of Receipt,Port of Loading
  1429. $Mapping_location[$code] = empty($ocean['place_of_receipt_exp']) ? $ocean['fport_of_loading_exp'] : $ocean['place_of_receipt_exp'];
  1430. }
  1431. if($code == "IFFARR" || $code == "IFFICC" || $code == "IFFPPD"){
  1432. //Port of discharge
  1433. $Mapping_location[$code] = $ocean['mport_of_discharge_exp'];
  1434. }
  1435. if($code == "IFFUND"){
  1436. //Port of discharge,place of delivery / Final Destination
  1437. $Mapping_location[$code] = empty($ocean['mport_of_discharge_exp']) ? $ocean['place_of_delivery_exp']." ".$ocean['final_desination_exp'] : $ocean['mport_of_discharge_exp'];
  1438. }
  1439. if($code == "IFFAFD"){
  1440. //Place of Delivery
  1441. $Mapping_location[$code] = $ocean['place_of_delivery_exp'];
  1442. }
  1443. if($code == "IFFCTA"){
  1444. //Place of Delivery,port of discharge
  1445. $Mapping_location[$code] = empty($ocean['place_of_delivery_exp']) ? $ocean['mport_of_discharge_exp'] : $ocean['place_of_delivery_exp'];
  1446. }
  1447. }
  1448. //Milestones 数据信息待定
  1449. $Milestones_data = array();
  1450. $Milestones_data_arr = common::excuteListSql("select
  1451. case when code = 'IFFECP' then 'Empty Container Pickup' else dd.description end as description,
  1452. act_date||' '||act_time as date_time, remark,timezone,code,create_by,act_update_by
  1453. from ocean_milestone a
  1454. left join LATERAL (select sno,description from milestone where code=a.code and project_no = '*' limit 1) dd on true
  1455. where a.serial_no='".$ocean["serial_no"]."' and act_date is not null order by dd.sno asc, id asc");
  1456. foreach($Milestones_data_arr as $mda){
  1457. $locations = "";
  1458. if(!empty($Mapping_location[$mda['code']])){
  1459. $locations = $Mapping_location[$mda['code']];
  1460. }else{
  1461. //第二优先级:用Milestone更新的对应的站点的location
  1462. $user_login = empty($mda['act_update_by']) ? $mda['create_by'] : $mda['act_update_by'];
  1463. $city_by_user = common::excuteObjectSql("select e.city from ra_online_user r,employee e where r.employee_id=e.employee_id and lower(r.user_login)=lower('$user_login') limit 1");
  1464. $locations = $city_by_user['city'];
  1465. }
  1466. $Milestones_data[] = array("milestones"=>$mda['description'],"date_time"=>$mda['date_time'],"timezone" =>$mda['timezone'],
  1467. "locations" => $locations, "remarks" =>$mda['remark']);
  1468. }
  1469. $Milestones = array("Milestones_column"=>$Milestones_column,"Milestones_data" =>$Milestones_data);
  1470. return $Milestones;
  1471. }
  1472. /**
  1473. * 查询uncode 对应的时区
  1474. */
  1475. public static function getCityPortsInfo($uncodes){
  1476. $data =array();
  1477. $sql = "select timezonecode,ctrycitycode from public.city_ports where lower(ctrycitycode) ". common::getInNotInSql($uncodes);
  1478. $uncode_rs = common::excuteListSql($sql);
  1479. foreach($uncode_rs as $value){
  1480. $data[$value['ctrycitycode']] = $value['timezonecode'];
  1481. }
  1482. return $data;
  1483. }
  1484. }
  1485. ?>