common.class.php 72 KB

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