common.class.php 88 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983
  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, "user_guide") === 0)
  132. && !(stripos($action, "ajax") === 0)
  133. && !(stripos($action, "opreation_log") === 0)) {
  134. $data = array("msg"=>"Permission Denied");
  135. common::echo_json_encode(500, $data);
  136. exit();
  137. }
  138. }
  139. }
  140. }
  141. session_write_close();
  142. }
  143. }
  144. public static function getCompanySearch() {
  145. $sc_list = _get_schemas();
  146. if (utils::count($sc_list) == 1) {
  147. return "";
  148. }
  149. if (_isCustomerLogin()) {
  150. $msg = '<input type="hidden" name="_apex_or_sfs" value=""/>';
  151. } else {
  152. $msg = '<div class="modules">Apex/SFS/Kerry :&nbsp;<select name="_apex_or_sfs" class="sl"><option value="">All</option>';
  153. if ($_SESSION['ONLINE_USER']['main_schemas'] == "public") {
  154. $msg .= '<option value="public">Apex</option>';
  155. } else {
  156. $msg .= '<option value="public">Apex</option>';
  157. }
  158. if ($_SESSION['ONLINE_USER']['main_schemas'] == "sfs") {
  159. $msg .= '<option value="sfs">SFS</option>';
  160. } else {
  161. $msg .= '<option value="sfs">SFS</option>';
  162. }
  163. if ($_SESSION['ONLINE_USER']['main_schemas'] == "kyiff") {
  164. $msg .= '<option value="kyiff">Kerry</option>';
  165. } else {
  166. $msg .= '<option value="kyiff">Kerry</option>';
  167. }
  168. $msg .= '</select></div>';
  169. }
  170. return $msg;
  171. }
  172. public static function sessionVerify() {
  173. if (!isset($_SESSION['user_agent'])) {
  174. $_SESSION['user_agent'] = MD5($_SERVER['REMOTE_ADDR']
  175. . $_SERVER['HTTP_USER_AGENT']);
  176. } elseif ($_SESSION['user_agent'] != MD5($_SERVER['REMOTE_ADDR']
  177. . $_SERVER['HTTP_USER_AGENT'])) {
  178. session_regenerate_id();
  179. }
  180. }
  181. public static function searchExtendHand_KLN($type, $user, $company_name = "station_name") {
  182. $sqlWhere = " 1=1";
  183. if($type == "booking"){
  184. $ocean_booking_sqlWhere = self::searchExtendHandNew("booking",$user, $company_name);
  185. $air_booking_sqlWhere = self::searchExtendHandNew("air_booking",$user, $company_name);
  186. $sqlWhere = "((transport_mode ='sea' and ".$ocean_booking_sqlWhere.") or (transport_mode ='air' and ".$air_booking_sqlWhere."))";
  187. }
  188. if($type == "ocean"){
  189. $ocean_booking_sqlWhere = self::searchExtendHandNew("ocean",$user, $company_name);
  190. $air_booking_sqlWhere = self::searchExtendHandNew("air",$user, $company_name);
  191. $sqlWhere = "((transport_mode ='sea' and ".$ocean_booking_sqlWhere.") or (transport_mode ='air' and ".$air_booking_sqlWhere."))";
  192. }
  193. return $sqlWhere;
  194. }
  195. public static function searchExtendHandNew($type, $user, $company_name = "station_name") {
  196. if (_isAdminHandNew($user)) {
  197. if(strtolower($type) == "air_booking" )
  198. {
  199. return "1=1";
  200. }
  201. return " (COALESCE(schem_not_display,false) = false)";
  202. }
  203. if (_isDocAdmin($user["user_login"])) {
  204. if(strtolower($type) == "air_booking" )
  205. {
  206. return "1=1";
  207. }
  208. return ' (COALESCE(schem_not_display,false) = false)';
  209. }
  210. if (strtolower($type) != "ocean" && strtolower($type) != "booking" && strtolower($type) != "air_booking"&& strtolower($type) != "air") {
  211. return " 1<>1";
  212. }
  213. if (empty($user["schemas_list"])) {
  214. $user["schemas_list"] = $_SESSION["schemas_list"];
  215. }
  216. $schemas_list = $user["schemas_list"];
  217. if ($user["is_kerry_shipment"] == "t") {
  218. $sqlWhere = " is_kerry_shipment is not null and is_kerry_shipment=true";
  219. } else if ($user["is_kerry_shipment"] == "f") {
  220. $sqlWhere = " (COALESCE(is_kerry_shipment,false) = false)";
  221. } else {
  222. $sqlWhere = " 1=1 ";
  223. }
  224. if (!empty($_POST["_apex_or_sfs"])) {
  225. $sqlWhere .= " and order_from='" . $_POST["_apex_or_sfs"] . "'";
  226. }
  227. if (utils::count($schemas_list) == 1) {
  228. $schames = $schemas_list[0]["schemas_name"];
  229. if(strtolower($type) == "air_booking" ||strtolower($type) == "air")
  230. {
  231. }
  232. else
  233. $sqlWhere .= " and order_from='$schames'";
  234. if ($schames == "sfs" && empty($user["sfs_ONLINE_USER"])) {
  235. $user = $_SESSION["sfs_ONLINE_USER"];
  236. }
  237. if (strtolower($type) == "ocean") {
  238. $sqlWhere .= self::_oceanHandNew($user, $schames);
  239. if ($company_name == "doc") {
  240. if (empty($user["view_file_format"])) {
  241. if (strtolower($user["user_type"]) == "customer") {
  242. $sqlWhere .= " and serial_no in (SELECT serial_no from $schames.ra_online_file_format where active = true and client_display = true)";
  243. } else {
  244. $sqlWhere .= " and serial_no in (SELECT serial_no from $schames.ra_online_file_format where active = true)";
  245. }
  246. } else {
  247. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  248. }
  249. }
  250. }
  251. if (strtolower($type) == "booking") {
  252. $sqlWhere .= self::_bookingHandNew($user, $schames);
  253. }
  254. if (strtolower($type) == "air_booking") {
  255. $sqlWhere .= self::_air($schames);
  256. }
  257. if (strtolower($type) == "air") {
  258. $sqlWhere .= self::_air($schames);
  259. }
  260. } elseif (utils::count($schemas_list) == 2) {
  261. if(strtolower($type) == "air_booking" ){
  262. }else{
  263. $sqlWhere .= " and (COALESCE(schem_not_display,false) = false)";
  264. }
  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::_air("public");
  310. $sqlWhere .= ") or (order_from='sfs' ";
  311. if (empty($user["sfs_ONLINE_USER"])) {
  312. $user = $_SESSION["sfs_ONLINE_USER"];
  313. }
  314. $sqlWhere .= self::_air("sfs");
  315. $sqlWhere .= "))";
  316. }
  317. if (strtolower($type) == "air") {
  318. $sqlWhere .= " and ((order_from='public' ";
  319. $sqlWhere .= self::_air($user, "public");
  320. $sqlWhere .= ") or (order_from='sfs' ";
  321. if (empty($user["sfs_ONLINE_USER"])) {
  322. $user = $_SESSION["sfs_ONLINE_USER"];
  323. }
  324. $sqlWhere .= self::_air($user, "sfs");
  325. $sqlWhere .= ") )";
  326. }
  327. } else {
  328. $sqlWhere = " 1<>1";
  329. }
  330. return $sqlWhere;
  331. }
  332. public static function getStatusStage($status) {
  333. if ($status == "EE" || $status == "I") {
  334. return 0;
  335. }
  336. if ($status == "AE" || $status == "VD" || $status == "VA_RELAY" || $status == "UV_RELAY" || $status == "AE_RELAY" || $status == "VD_RELAY") {
  337. return 1;
  338. }
  339. if ($status == "VA" || $status == "UV" || $status == "AL" || $status == "AR" || $status == "CU" || $status == "CT" || $status == "CR" || $status == "OA") {
  340. return 2;
  341. }
  342. if ($status == "AV" || $status == "D" || $status == "RD") {
  343. return 3;
  344. }
  345. return -1;
  346. }
  347. public static function getInNotInSql($contact_id, $type = 'in') {
  348. if (empty($contact_id))
  349. return " =''";
  350. $contact_id = trim($contact_id);
  351. $contact_id = trim($contact_id, ";");
  352. $contact_id = trim($contact_id);
  353. $contact_id = strtolower($contact_id);
  354. if ($type == 'in') {
  355. if (utils::checkExist($contact_id, ";")) {
  356. $ss = "";
  357. $aa = explode(";", $contact_id);
  358. foreach ($aa as $k => $v) {
  359. $v = trim($v);
  360. if (empty($ss))
  361. $ss = "'" . common::check_input($v) . "'";
  362. else
  363. $ss .= ",'" . common::check_input($v) . "'";
  364. }
  365. return " in (" . $ss . ")";
  366. } else {
  367. return " = '" . common::check_input($contact_id) . "'";
  368. }
  369. } else {
  370. if (utils::checkExist($contact_id, ";")) {
  371. $ss = "";
  372. $aa = explode(";", $contact_id);
  373. foreach ($aa as $k => $v) {
  374. $v = trim($v);
  375. if (empty($ss))
  376. $ss = "'" . common::check_input($v) . "'";
  377. else
  378. $ss .= ",'" . common::check_input($v) . "'";
  379. }
  380. return " in (" . $ss . ")";
  381. } else {
  382. return " != '" . common::check_input($contact_id) . "'";
  383. }
  384. }
  385. }
  386. public static function getInNotInSqlForSearch($contact_id, $type = 'in') {
  387. if (empty($contact_id))
  388. return " =''";
  389. $contact_id = trim($contact_id);
  390. $contact_id = trim($contact_id, ";");
  391. $contact_id = trim($contact_id);
  392. $contact_id = strtolower($contact_id);
  393. if ($type == 'in') {
  394. if (utils::checkExist($contact_id, ";")) {
  395. $ss = "";
  396. $aa = explode(";", $contact_id);
  397. foreach ($aa as $k => $v) {
  398. $v = trim($v);
  399. if (empty($ss))
  400. $ss = "'" . common::check_input($v) . "'";
  401. else
  402. $ss .= ",'" . common::check_input($v) . "'";
  403. }
  404. return $ss;
  405. } else {
  406. return "'" . common::check_input($contact_id) . "'";
  407. }
  408. }
  409. }
  410. /*
  411. * Encrypt a SQL query statement used to be passed as a parameter to get excel output
  412. encode :DeCode('str','E');
  413. decode :DeCode('enstr','D');
  414. */
  415. public static function deCode($string, $operation = "E") {
  416. $key = md5("uls_webwms");
  417. $key_length = strlen($key);
  418. if ($operation == "D")
  419. $string = rawurldecode($string);
  420. $string = $operation == 'D' ? base64_decode($string) : substr(md5($string . $key), 0, 8) . $string;
  421. $string_length = strlen($string);
  422. $rndkey = $box = array();
  423. $result = '';
  424. for ($i = 0; $i <= 255; $i++) {
  425. $rndkey [$i] = ord($key [$i % $key_length]);
  426. $box [$i] = $i;
  427. }
  428. for ($j = $i = 0; $i < 256; $i++) {
  429. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  430. $tmp = $box [$i];
  431. $box [$i] = $box [$j];
  432. $box [$j] = $tmp;
  433. }
  434. for ($a = $j = $i = 0; $i < $string_length; $i++) {
  435. $a = ($a + 1) % 256;
  436. $j = ($j + $box [$a]) % 256;
  437. $tmp = $box [$a];
  438. $box [$a] = $box [$j];
  439. $box [$j] = $tmp;
  440. $result .= chr(ord($string [$i]) ^ ($box [($box [$a] + $box [$j]) % 256]));
  441. }
  442. if ($operation == 'D') {
  443. if (substr($result, 0, 8) == substr(md5(substr($result, 8) . $key), 0, 8)) {
  444. return substr($result, 8);
  445. } else {
  446. return '';
  447. }
  448. } else {
  449. return rawurlencode(str_replace('=', '', base64_encode($result)));
  450. }
  451. }
  452. public static function getStatusDesc($code) {
  453. if (strtoupper($code) == "EE") {
  454. return "Empty Equipment Dispatched";
  455. }
  456. if (strtoupper($code) == "I") {
  457. return "Gate in full for a booking";
  458. }
  459. if (strtoupper($code) == "AE") {
  460. return "Container loaded on vessel";
  461. }
  462. if (strtoupper($code) == "VD") {
  463. return "Vessel Departure";
  464. }
  465. if (strtoupper($code) == "VA_RELAY") {
  466. return "Arrive Relay Port";
  467. }
  468. if (strtoupper($code) == "VD_RELAY") {
  469. return "Depart Relay Port";
  470. }
  471. if (strtoupper($code) == "AE_RELAY") {
  472. return "Loaded at Relay Port";
  473. }
  474. if (strtoupper($code) == "UV_RELAY") {
  475. return "Unloaded at Relay Port";
  476. }
  477. if (strtoupper($code) == "VA") {
  478. return "Vessel Arrival";
  479. }
  480. if (strtoupper($code) == "UV") {
  481. return "Unloaded From Vessel";
  482. }
  483. if (strtoupper($code) == "AL") {
  484. return "Container loaded on Rail";
  485. }
  486. if (strtoupper($code) == "AR") {
  487. return "Container unloaded from Rail";
  488. }
  489. if (strtoupper($code) == "CU") {
  490. return "Carrier and Customs Release";
  491. }
  492. if (strtoupper($code) == "CT") {
  493. return "Customs release";
  494. }
  495. if (strtoupper($code) == "CR") {
  496. return "Carrier release";
  497. }
  498. if (strtoupper($code) == "OA") {
  499. return "Gate out full from final discharge port";
  500. }
  501. if (strtoupper($code) == "AV") {
  502. return "Shipment available for pickup or delivery";
  503. }
  504. if (strtoupper($code) == "RD") {
  505. return "Container returned empty";
  506. }
  507. if (strtoupper($code) == "D") {
  508. return "Gate out for delivery to customer";
  509. }
  510. }
  511. public static function _toString($msg) {
  512. if ($msg == "" || $msg == NULL) {
  513. return "";
  514. }
  515. return $msg . "";
  516. }
  517. /*
  518. * timeout output
  519. */
  520. public static function timeoutPrintInfor($httpAccept, $ajax, $login) {
  521. //记录系统因session过期 退出登录
  522. $data = array("msg"=>"session_time_out");
  523. self::echo_json_encode(403,$data);
  524. exit();
  525. }
  526. /**
  527. * _bookingHandNew 和 _oceanHandNew逻辑完全一样,只是ocean 多一个dest_op字段,在booking里没有的
  528. */
  529. private static function _oceanHandNew($user, $schemas = "public") {
  530. $o = $user['ocean_station'];
  531. $o_or = $user['ocean_station_or'];
  532. $d = $user['ocean_agent'];
  533. $d_or = $user['ocean_agent_or'];
  534. $sales = $user['ocean_sales'];
  535. $sales_or = $user['ocean_sales_or'];
  536. $op = $user['ocean_dest_op'];
  537. $op_or = $user['ocean_dest_op_or'];
  538. $follow = $user['ocean_following_sales'];
  539. $follow_or = $user['ocean_following_sales_or'];
  540. if (strtolower($o_or) == "all" || strtolower($d_or) == "all" || strtolower($sales_or) == "all" || strtolower($op_or) == "all") {
  541. return " and 1=1";
  542. }
  543. $sqlWhere = "";
  544. if (_isCustomerLoginHandNew($user)) {
  545. $sqlWhere .= " and " . _customerFilerSearchHandNew($user, $schemas);
  546. } else {
  547. if (empty($o) && empty($d) && empty($sales) && empty($op) && empty($follow)) {
  548. return " and 1<>1";
  549. }
  550. if ((strtolower($o) == 'all' || empty($o)) && (strtolower($d) == "all" || empty($d))) {
  551. } else {
  552. $sql = "1=1";
  553. if (!empty($o) && strtolower($o) != 'all') {
  554. $sql .= " and lower(origin)";
  555. $sql .= utils::getInSql($o);
  556. }
  557. if (!empty($d) && strtolower($d) != 'all') {
  558. $sql .= " and lower(agent)";
  559. $sql .= utils::getInSql($d);
  560. }
  561. $sqlWhere .= " and (" . $sql . ")";
  562. }
  563. if (strtolower($sales) == 'all' || empty($sales)) {
  564. } else {
  565. if (utils::checkExist($sales, ";")) {
  566. $sql = "1!=1";
  567. $tt = explode(";", $sales);
  568. foreach ($tt as $t) {
  569. $t = trim($t);
  570. if (!empty($t))
  571. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  572. }
  573. $sqlWhere .= " and ($sql)";
  574. } else
  575. $sqlWhere .= " and lower(sales_rep)='" . strtolower($sales) . "'";
  576. }
  577. if (strtolower($op) == 'all' || empty($op)) {
  578. } else {
  579. $sqlWhere .= " and lower(dest_op) " . utils::getInSql($op);
  580. }
  581. if (strtolower($follow) == 'all' || empty($follow)) {
  582. } else {
  583. if (utils::checkExist($follow, ";")) {
  584. $sql = "1!=1";
  585. $tt = explode(";", $follow);
  586. foreach ($tt as $t) {
  587. $t = trim($t);
  588. if (!empty($t))
  589. $sql .= " or following_sales ilike '" . $t . "'";
  590. }
  591. $sqlWhere .= " and ($sql)";
  592. } else
  593. $sqlWhere .= " and following_sales ilike '" . $follow . "'";
  594. }
  595. $sqlWhere = " (1=1 $sqlWhere)";
  596. if (!empty($o_or)) {
  597. $sqlWhere .= " or lower(origin)";
  598. $sqlWhere .= utils::getInSql($o_or);
  599. }
  600. if (!empty($d_or)) {
  601. $sqlWhere .= " or lower(agent)";
  602. $sqlWhere .= utils::getInSql($d_or);
  603. }
  604. if (!empty($sales_or)) {
  605. if (utils::checkExist($sales_or, ";")) {
  606. $sql = "1!=1";
  607. $tt = explode(";", $sales_or);
  608. foreach ($tt as $t) {
  609. $t = trim($t);
  610. if (!empty($t))
  611. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  612. }
  613. $sqlWhere .= " or ($sql)";
  614. } else
  615. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales_or) . "'";
  616. }
  617. if (!empty($op_or)) {
  618. $sqlWhere .= " or lower(dest_op) " . utils::getInSql($op_or);
  619. }
  620. if (!empty($follow_or)) {
  621. if (utils::checkExist($follow_or, ";")) {
  622. $sql = "1!=1";
  623. $tt = explode(";", $follow_or);
  624. foreach ($tt as $t) {
  625. $t = trim($t);
  626. if (!empty($t))
  627. $sql .= " or following_sales ilike '" . $t . "'";
  628. }
  629. $sqlWhere .= " or ($sql)";
  630. }else {
  631. $sqlWhere .= " or following_sales ilike '" . $follow_or . "'";
  632. }
  633. }
  634. $sqlWhere = " and ($sqlWhere)";
  635. }
  636. return $sqlWhere;
  637. }
  638. /**
  639. * _bookingHandNew 和 _oceanHandNew逻辑完全一样,只是ocean 多一个dest_op字段,在booking里没有的
  640. */
  641. private static function _bookingHandNew($user, $schames) {
  642. $o = $user['ocean_station'];
  643. $o_or = $user['ocean_station_or'];
  644. $d = $user['ocean_agent'];
  645. $d_or = $user['ocean_agent_or'];
  646. $sales = $user['ocean_sales'];
  647. $sales_or = $user['ocean_sales_or'];
  648. $op = $user['ocean_dest_op'];
  649. $op_or = $user['ocean_dest_op_or'];
  650. $follow = $user['ocean_following_sales'];
  651. $follow_or = $user['ocean_following_sales_or'];
  652. if (strtolower($o_or) == "all" || strtolower($d_or) == "all" || strtolower($sales_or) == "all") {
  653. return " and 1=1";
  654. }
  655. $sqlWhere = "";
  656. if (_isCustomerLoginHandNew($user)) {
  657. $sqlWhere .= " and " . _customerFilerSearchHandNew($user, $schames);
  658. } else {
  659. if (empty($o) && empty($d) && empty($sales) && empty($op) && empty($follow)) {
  660. return " and 1<>1";
  661. }
  662. if ((strtolower($o) == 'all' || empty($o)) && (strtolower($d) == "all" || empty($d))) {
  663. } else {
  664. $sql = "1=1";
  665. if (!empty($o) && strtolower($o) != 'all') {
  666. $sql .= " and lower(origin)";
  667. $sql .= utils::getInSql($o);
  668. }
  669. if (!empty($d) && strtolower($d) != 'all') {
  670. $sql .= " and lower(agent)";
  671. $sql .= utils::getInSql($d);
  672. }
  673. $sqlWhere .= " and (" . $sql . ")";
  674. }
  675. if (strtolower($sales) == 'all' || empty($sales)) {
  676. } else {
  677. if (utils::checkExist($sales, ";")) {
  678. $sql = "1!=1";
  679. $tt = explode(";", $sales);
  680. foreach ($tt as $t) {
  681. $t = trim($t);
  682. if (!empty($t))
  683. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  684. }
  685. $sqlWhere .= " and ($sql)";
  686. } else
  687. $sqlWhere .= " and lower(sales_rep)='" . strtolower($sales) . "'";
  688. }
  689. if (strtolower($follow) == 'all' || empty($follow)) {
  690. } else {
  691. if (utils::checkExist($follow, ";")) {
  692. $sql = "1!=1";
  693. $tt = explode(";", $follow);
  694. foreach ($tt as $t) {
  695. $t = trim($t);
  696. if (!empty($t))
  697. $sql .= " or following_sales ilike '" . $t . "%'";
  698. }
  699. $sqlWhere .= " and ($sql)";
  700. } else
  701. $sqlWhere .= " and following_sales ilike '" . $follow . "%'";
  702. }
  703. $sqlWhere = " (1=1 $sqlWhere)";
  704. if (!empty($o_or)) {
  705. $sqlWhere .= " or lower(origin)";
  706. $sqlWhere .= utils::getInSql($o_or);
  707. }
  708. if (!empty($d_or)) {
  709. $sqlWhere .= " or lower(agent)";
  710. $sqlWhere .= utils::getInSql($d_or);
  711. }
  712. if (!empty($sales_or)) {
  713. if (utils::checkExist($sales_or, ";")) {
  714. $sql = "1!=1";
  715. $tt = explode(";", $sales_or);
  716. foreach ($tt as $t) {
  717. $t = trim($t);
  718. if (!empty($t))
  719. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  720. }
  721. $sqlWhere .= " or ($sql)";
  722. } else
  723. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales_or) . "%'";
  724. }
  725. if (!empty($follow_or)) {
  726. if (utils::checkExist($follow_or, ";")) {
  727. $sql = "1!=1";
  728. $tt = explode(";", $follow_or);
  729. foreach ($tt as $t) {
  730. $t = trim($t);
  731. if (!empty($t))
  732. $sql .= " or following_sales ilike '" . $t . "%'";
  733. }
  734. $sqlWhere .= " or ($sql)";
  735. } else
  736. $sqlWhere .= " or following_sales ilike '" . $follow_or . "%'";
  737. }
  738. $sqlWhere = " and ($sqlWhere)";
  739. }
  740. return $sqlWhere;
  741. }
  742. /**
  743. * online air
  744. */
  745. private static function _air($schemas = "public") {
  746. $station = _getAirStation($schemas);
  747. $station_or = _getAirStationOr($schemas);
  748. $sales = _getAirSales($schemas);
  749. $sales_or = _getAirSalesOr($schemas);
  750. $sqlWhere = " 1=1 ";
  751. if (_isCustomerLogin()) {
  752. $sqlWhere .= " and " . _customerAirFilerSearch($schemas);
  753. } else {
  754. if (empty($station) && empty($sales)) {
  755. return " 1<>1";
  756. }
  757. if (strtolower($station_or) == "all" || strtolower($sales_or) == "all")
  758. return $sqlWhere;
  759. if (strtolower($station) == 'all' || empty($station)) {
  760. } else {
  761. $sqlWhere .= " and (lower(origin)";
  762. $sqlWhere .= utils::getInSql($station);
  763. $sqlWhere .= " or lower(agent)";
  764. $sqlWhere .= utils::getInSql($station);
  765. $sqlWhere .= ")";
  766. }
  767. if (strtolower($sales) == 'all' || empty($sales)) {
  768. } else {
  769. $sqlWhere .= " and (lower(sales_rep) " . utils::getInSql($sales) . " or lower(following_sales) " . utils::getInSql($sales) . ")";
  770. }
  771. $sqlWhere = " ($sqlWhere)";
  772. if (!empty($station_or))
  773. $sqlWhere = "$sqlWhere or lower(origin)" . utils::getInSql($station_or) . " or lower(agent)" . utils::getInSql($station_or);
  774. if (!empty($sales_or))
  775. $sqlWhere = "$sqlWhere or lower(sales_rep)" . utils::getInSql($sales_or) . " or lower(following_sales)" . utils::getInSql($sales_or);
  776. }
  777. return " and ($sqlWhere)";
  778. }
  779. public static function isNewVersion() {
  780. if (utils::checkExist($_SERVER['PHP_SELF'], "main_new_version.php")) {
  781. return "_new";
  782. }
  783. return "";
  784. }
  785. public static function removeTopOceanOldVersionSpecialField($rss){
  786. $rss_bk = $rss;
  787. $new_arr = array();
  788. foreach ($rss_bk as $k => $v) {
  789. if (utils::startWith($v['database_column_name'], "__") || utils::startWith($v['database_column_name'], "___")){
  790. //unset($rss[$k]);
  791. }else{
  792. $new_arr[] = $v;
  793. }
  794. }
  795. return $new_arr;
  796. }
  797. public static function echo_json_encode($code,$data){
  798. $resData = array();
  799. $resData["code"] = $code;
  800. $resData["data"] =$data;
  801. //echo utils::jsonFiltration("null", "\"\"", json_encode($resData));
  802. echo json_encode($resData);
  803. }
  804. /*
  805. * MM/DD/YYYY To YYYY-MM-DD
  806. */
  807. public static function usDate2sqlDate($timestr) {
  808. if (empty($timestr))
  809. return '';
  810. $datearray = explode("/", $timestr);
  811. $m = $datearray [0];
  812. $d = $datearray [1];
  813. $y = $datearray [2];
  814. return $y . "-" . $m . "-" . $d;
  815. }
  816. public static function uuid() {
  817. return md5(uniqid("", TRUE) . mt_rand());
  818. }
  819. /*
  820. * YYYYMMDD To MM/DD/YYYY
  821. */
  822. public static function date2usdate($datestr) {
  823. if (empty($datestr))
  824. return '';
  825. $y = substr($datestr, 0, 4);
  826. $m = substr($datestr, 4, 2);
  827. $d = substr($datestr, 6, 2);
  828. return $m . "/" . $d . "/" . $y;
  829. }
  830. /*
  831. * date add some days
  832. */
  833. public static function addDays($date, $days) {
  834. $time = strtotime($date) + $days * 24 * 3600;
  835. return date('m/d/Y', $time);
  836. }
  837. /*
  838. * download file from file system
  839. */
  840. public static function download_file($filename, $display_name = null, $delete = FALSE, $files = NULL) {
  841. $filename = str_replace("/", DIRECTORY_SEPARATOR, $filename);
  842. $filename = str_replace("\\", DIRECTORY_SEPARATOR, $filename);
  843. if (!file_exists($filename))
  844. exit('File Not Exist');
  845. if (empty($display_name))
  846. $display_name = basename($filename);
  847. //$file = fopen($filename, "r");
  848. header_remove("Content-type");
  849. header("Content-type:" . self::getContentType($filename));
  850. header("Expires: 0");
  851. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  852. header("Pragma: can-cache");
  853. header("Accept-ranges:bytes");
  854. header("Accept-length:" . filesize($filename));
  855. header("Content-Disposition:attachment;filename=\"" . $display_name . "\"");
  856. //echo fread($file, filesize($filename));
  857. //fclose($file);
  858. //针对大文件,规定每次读取文件的字节数为4096字节,直接输出数据
  859. $read_buffer = 4096;
  860. $handle = fopen($filename, 'rb');
  861. //总的缓冲的字节数
  862. $sum_buffer = 0;
  863. $filesize = filesize($filename);
  864. //只要没到文件尾,就一直读取
  865. while (!feof($handle) && $sum_buffer < $filesize) {
  866. echo fread($handle, $read_buffer);
  867. $sum_buffer += $read_buffer;
  868. }
  869. //关闭句柄
  870. fclose($handle);
  871. if ($delete !== FALSE) {
  872. unlink($filename);
  873. }
  874. if (!empty($files)) {
  875. foreach ($files as $f) {
  876. unlink($f);
  877. }
  878. }
  879. }
  880. public static function getContentType($filename) {
  881. $extend = self::getExtendFilename($filename);
  882. $filetype = array(
  883. 'xls' => 'application/vnd.ms-excel',
  884. 'doc' => 'application/msword',
  885. 'gif' => 'image/gif',
  886. 'jpg' => 'image/jpeg',
  887. 'jpeg' => 'image/jpeg',
  888. 'jpe' => 'image/jpeg',
  889. 'bmp' => 'image/bmp',
  890. 'png' => 'image/png',
  891. 'tif' => 'image/tiff',
  892. 'pdf' => 'application/pdf',
  893. 'zip' => 'application/zip'
  894. );
  895. return $filetype[$extend];
  896. }
  897. /*
  898. * Get the file extension
  899. */
  900. public static function getExtendFilename($file_name) {
  901. $extend = pathinfo($file_name);
  902. $extend = strtolower($extend["extension"]);
  903. return $extend;
  904. }
  905. public static function getManagement(){
  906. //Management 自己配置需要创建表保存
  907. $user_management_data = common::excuteObjectSql("select management,dashboard_filter from ra_online_user where user_login = '"._getLoginName()."'");
  908. //为空,配置使用默认值
  909. $user_management = $user_management_data['management'];
  910. if(empty($user_management)){
  911. $Management = common::getdefaultManagement();
  912. }else{
  913. $Management = json_decode($user_management,true);
  914. foreach($Management as $key =>$val){
  915. $Management[$key]['id'] = intval($val['id']);
  916. $Management[$key]['switchValue'] = $val['switchValue'] == "true" ? true : false;
  917. }
  918. }
  919. $user_dashboard_filter = $user_management_data['dashboard_filter'];
  920. $dashboard_filter =array();
  921. if(!empty($user_dashboard_filter)){
  922. $dashboard_filter = json_decode($user_dashboard_filter,true);
  923. }else{
  924. $threeMonthsAgoTimestamp = strtotime('-3 months');
  925. $date_start = date('Y-m-d', $threeMonthsAgoTimestamp);
  926. $date_end = date('Y-m-d');
  927. $date_start_two = date('m/d/Y', $threeMonthsAgoTimestamp);
  928. $date_end_two = date('m/d/Y');
  929. //ETD
  930. $_12MonthsAgoTimestamp = strtotime('-11 months');
  931. $etd_date_start = date('Y-m', $_12MonthsAgoTimestamp);
  932. $etd_date_end = date('Y-m');
  933. $etd_date_start_two = date('m/Y', $_12MonthsAgoTimestamp);
  934. $etd_date_end_two = date('m/Y');
  935. //柜子
  936. $ctnr_date_start = date('Y-m', $_12MonthsAgoTimestamp);
  937. $ctnr_date_end = date('Y-m');
  938. $ctnr_date_start_two = date('m/Y', $_12MonthsAgoTimestamp);
  939. $ctnr_date_end_two = date('m/Y');
  940. //Top
  941. $top_date_start = date('Y-m-d', $_12MonthsAgoTimestamp);
  942. $top_date_end = date('Y-m-d');
  943. $top_date_start_two = date('m/d/Y', $_12MonthsAgoTimestamp);
  944. $top_date_end_two = date('m/d/Y');
  945. //KPIDefaulteData
  946. $dashboard_filter['KPIDefaulteData'] = array("transportation" =>array('All'),"date_type"=>"ETD","date_start"=>$date_start_two,"date_start_two"=>$date_start,
  947. "date_end"=>$date_end_two,"date_end_two"=>$date_end);
  948. //PendingDefaultData
  949. $dashboard_filter['PendingDefaultData'] = array("transportation" =>array('All'),"date_type"=>"ETD","date_start"=>"","date_start_two"=>"",
  950. "date_end"=>"","date_end_two"=>"");
  951. //RecentDefaultData
  952. $dashboard_filter['RecentDefaultData'] = array("transportation" =>array('All'),"date_type"=>"ETD","date_start"=>$date_start_two,"date_start_two"=>$date_start,
  953. "date_end"=>$date_end_two,"date_end_two"=>$date_end);
  954. //ETDDefaultData
  955. $dashboard_filter['ETDDefaultData'] = array("transportation" =>array('All'),"date_type"=>"ETA","date_start"=>$etd_date_start_two,"date_start_two"=>$etd_date_start,
  956. "date_end"=>$etd_date_end_two,"date_end_two"=>$etd_date_end);
  957. //ContainerefaultData
  958. $dashboard_filter['ContainerefaultData'] = array("transportation" =>array('Sea'),"date_type"=>"ETA","date_start"=>$ctnr_date_start_two,"date_start_two"=>$ctnr_date_start,
  959. "date_end"=>$ctnr_date_end_two,"date_end_two"=>$ctnr_date_end);
  960. //RevenueDefaultData
  961. if(_isRevenueDisplay()){
  962. $dashboard_filter['RevenueDefaultData'] = array("transportation" =>array('All'),"date_type"=>"Invoice Issue Date","date_start"=>$ctnr_date_start_two,"date_start_two"=>$ctnr_date_start,
  963. "date_end"=>$ctnr_date_end_two,"date_end_two"=>$ctnr_date_end);
  964. }
  965. //Top10faultData
  966. $dashboard_filter['Top10faultData'] = array("transportation" =>array('All'),"date_type"=>"ETA","date_start"=>$top_date_start_two,"date_start_two"=>$top_date_start,
  967. "date_end"=>$top_date_end_two,"date_end_two"=>$top_date_end);
  968. //OriginCo2Top10faultData
  969. $dashboard_filter['OriginCo2Top10faultData'] = array("transportation" =>array('All'),"date_type"=>"ETA","date_start"=>$top_date_start_two,"date_start_two"=>$top_date_start,
  970. "date_end"=>$top_date_end_two,"date_end_two"=>$top_date_end);
  971. //DestinationCo2Top10faultData
  972. $dashboard_filter['DestinationCo2Top10faultData'] = array("transportation" =>array('All'),"date_type"=>"ETA","date_start"=>$top_date_start_two,"date_start_two"=>$top_date_start,
  973. "date_end"=>$top_date_end_two,"date_end_two"=>$top_date_end);
  974. }
  975. return array("Management" => $Management,"dashboard_filter" =>$dashboard_filter);
  976. }
  977. public static function getItemStyle($type,$code){
  978. if($type == 'r1'){
  979. $data = array("0-20 Days" =>"#ffc594",
  980. "20-40 Days" =>"#ff9e4c",
  981. "40-60 Days" =>"#ff7500",
  982. "60-80 Days" =>"#ff3d00",
  983. "Over 80 Days" =>"#d50000");
  984. return $data[$code];
  985. }
  986. if($type == 'r4' || $type == 'r3' || $type == 'atd_r4' || $type == 'ata_r3'){
  987. $data = array("0 Day" =>"#ffc594",
  988. "Today" =>"#ffc594",
  989. "1-2 Days" =>"#ff9e4c",
  990. "3-6 Days" =>"#ff7500",
  991. "7 Days" =>"#ff3d00");
  992. return $data[$code];
  993. }
  994. if($type == 'r2' || utils::startWith($type,"co2e")){
  995. $data = array("45" =>"#FFE3CC",
  996. "40" =>"#FFAC66",
  997. "20" =>"#FF7500",
  998. "air" =>"#FFE3CC",
  999. "sea" =>"#FFAC66",
  1000. "road" =>"#FF7500");
  1001. return $data[$code];
  1002. }
  1003. if($type == "top"){
  1004. $data = array("1" =>"#FF7500",
  1005. "2" =>"#ff9033",
  1006. "3" =>"#ff9e4d",
  1007. "4" =>"#ffac66",
  1008. "5" =>"#ffba80",
  1009. "6" =>"#ffc899",
  1010. "7" =>"#ffd6b3",
  1011. "8" =>"#ffe3cc",
  1012. "9" =>"#fff1e6",
  1013. "10" =>"#fff1e6");
  1014. return $data[$code];
  1015. }
  1016. }
  1017. //处理返回原表数据格式
  1018. public static function mian_repot_do($value,$type,$totalValue){
  1019. $data = array();
  1020. $value_arr = json_decode($value,true);
  1021. //r1 是 ETD to ETA (Days)圆形图表数据结构返回
  1022. if($type == 'r1'){
  1023. $ETDList = array();
  1024. foreach($value_arr as $arr){
  1025. $color = common::getItemStyle($type,$arr['name']);
  1026. $ETDList[] = array("value" =>intval($arr['value']),"name" =>$arr['name'],"itemStyle" =>array("color" =>$color));
  1027. }
  1028. $ETDList = array_reverse($ETDList);
  1029. $ETD_Title = "Total: $totalValue";
  1030. $data = array("ETDList" =>$ETDList,"ETD_Radius"=>array('50%','80%'),"ETD_Title" =>$ETD_Title,"download_name" => "ETD to ETA (Days)");
  1031. }
  1032. if($type == 'r4' || $type == 'r3'){
  1033. //重新整理一下数据,给UI一致
  1034. $data_kd = array();
  1035. foreach($value_arr as $arr){
  1036. if(stripos("Today", $arr['name']) !== false){
  1037. $color = common::getItemStyle($type,"Today");
  1038. if(empty($data_kd["0"])){
  1039. $data_kd["0"] = array("value" =>intval($arr['value']),"name" =>"≤1 Day","itemStyle" =>array("color" =>$color));
  1040. }else{
  1041. $data_kd["0"]["value"] = $data_kd["0"]["value"] + intval($arr['value']);
  1042. }
  1043. }
  1044. if(stripos("+1 Days/+2 Days", $arr['name']) !== false){
  1045. $color = common::getItemStyle($type,"1-2 Days");
  1046. if(empty($data_kd["1"])){
  1047. $data_kd["1"] = array("value" =>intval($arr['value']),"name" =>"1-2 Days","itemStyle" =>array("color" =>$color));
  1048. }else{
  1049. $data_kd["1"]["value"] = $data_kd["1"]["value"] + intval($arr['value']);
  1050. }
  1051. }
  1052. if(stripos("+3 Days/+4 Days/+5 Days/+6 Days", $arr['name']) !== false){
  1053. $color = common::getItemStyle($type,"3-6 Days");
  1054. if(empty($data_kd["2"])){
  1055. $data_kd["2"] = array("value" =>intval($arr['value']),"name" =>"3-6 Days","itemStyle" =>array("color" =>$color));
  1056. }else{
  1057. $data_kd["2"]["value"] = $data_kd["2"]["value"] + intval($arr['value']);
  1058. }
  1059. }
  1060. if(stripos("+7 Days/Over 7 Days", $arr['name']) !== false){
  1061. $color = common::getItemStyle($type,"7 Days");
  1062. if(empty($data_kd["3"])){
  1063. $data_kd["3"] = array("value" =>intval($arr['value']),"name" =>"≥7 Days","itemStyle" =>array("color" =>$color));
  1064. }else{
  1065. $data_kd["3"]["value"] = $data_kd["3"]["value"] + intval($arr['value']);
  1066. }
  1067. }
  1068. }
  1069. if($type == 'r4'){
  1070. $data = array("ETDList" =>$data_kd,"ETD_Radius"=>array('30%','50%'),"title1" =>"Departure","title2" =>"","download_name" => "Pending Departure");
  1071. }
  1072. if($type == 'r3'){
  1073. $data = array("ETDList" =>$data_kd,"ETD_Radius"=>array('30%','50%'),"title1" =>"Arrival","title2" =>"","download_name" => "Pending Arrival");
  1074. }
  1075. }
  1076. return $data;
  1077. }
  1078. //单独处理co2e bar
  1079. public static function getCo2eBar(){
  1080. //新UI air sea road 目前只有sea
  1081. $type = $_REQUEST["r_type"];
  1082. $sqlWhere = ' and ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  1083. $sqlWhere = " " . $sqlWhere;
  1084. $date_type = strtolower($_REQUEST["date_type"]);
  1085. if (isset($_REQUEST['date_start']) && !empty($_REQUEST['date_start']))
  1086. $sqlWhere .= " and $date_type >= '" . common::usDate2sqlDate($_REQUEST['date_start']) . " 00:00:00'";
  1087. if (isset($_REQUEST['date_end']) && !empty($_REQUEST['date_end']))
  1088. $sqlWhere .= " and $date_type <= '" . common::usDate2sqlDate($_REQUEST['date_end']) . " 23:59:59'";
  1089. $transportation = $_REQUEST["transportation"];
  1090. if(!is_array($transportation)){
  1091. $transportation = array($transportation);
  1092. }
  1093. $mode_param = "";
  1094. if(utils::count($transportation) == 1 && strtolower($transportation[0]) == 'all' ){
  1095. $mode_param = "'sea','air','road'";
  1096. }else{
  1097. $transport_mode = utils::implode(';', $transportation);
  1098. $mode_param = common::getInNotInSqlForSearch($transport_mode);
  1099. }
  1100. $sqlWhere .= " and transport_mode in ($mode_param)";
  1101. $ContainerCount_Title = array();
  1102. //先查询总的排放量sea air road,确定排名后,在分别查询对应的sea air road
  1103. //这里的问题跟 top 一样 。总的排放量查询有问题。目前是总的排放量 暂时等于 sea的排放量
  1104. if ($type == "co2e_orgin"){
  1105. $co2e_shippr_sql = "select SUM(COALESCE(carbon_emission,0)) as catnum ,
  1106. shippr_uncode as station from public.kln_ocean where 1=1 and COALESCE(shippr_uncode,'')<>'' and carbon_emission is not null $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)) as catnum ,
  1111. consignee_uncode as station from public.kln_ocean where 1=1 and COALESCE(consignee_uncode,'')<>'' and carbon_emission is not null $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. if(!empty($val['station'])){
  1121. $stations[] = $val['station'];
  1122. }
  1123. }
  1124. $station_str = utils::implode(',',$stations);
  1125. $ContainerCounSeries = array();
  1126. $shipment_mode_arr = array("air","sea","road");
  1127. foreach($shipment_mode_arr as $_shipment_mode){
  1128. //类型有 sea air road,目前之类只查询sea的,其他为空
  1129. $shipment_mode = $_shipment_mode;
  1130. $co2e = array();
  1131. if ($type == "co2e_orgin"){
  1132. $co2e_shippr_sql_union = utils::_getSql($station_str,$type,$shipment_mode,$sqlWhere);
  1133. if(!empty($co2e_shippr_sql_union)){
  1134. $co2e = common::excuteListSql($co2e_shippr_sql_union);
  1135. }
  1136. $download_name = "CO2e Emission by Origin (Top 10)";
  1137. }
  1138. if ($type == "co2e_destination"){
  1139. $co2e_consignee_union = utils::_getSql($station_str,$type,$shipment_mode,$sqlWhere);
  1140. if(!empty($co2e_consignee_union)){
  1141. $co2e = common::excuteListSql($co2e_consignee_union);
  1142. }
  1143. $download_name = "CO2e Emission by Destination (Top 10)";
  1144. }
  1145. $total = 0;
  1146. $max = 0;
  1147. $data = array();
  1148. foreach($co2e as $val){
  1149. $data[] = empty($val['catnum'])? 0 : round($val['catnum'], 4);
  1150. $total = $total + $val['catnum'];
  1151. $max = $max < $val['catnum'] ? $val['catnum'] : $max;
  1152. }
  1153. $ContainerCounSeries[$shipment_mode] = array("data"=>$data,"total"=>$total,"max"=>$max);
  1154. }
  1155. //处理返回时数据格式 其实不太需要计算最大值,在最开始总量查询的时候以及查询出来
  1156. $ContainerCounSeries_return = array();
  1157. foreach($ContainerCounSeries as $k =>$v){
  1158. $color = common::getItemStyle($type,$k);
  1159. $ContainerCounSeries_return[] = array("name"=>$k,"type"=>"bar","emphasis" => array("focus" =>"none"),
  1160. "stack" =>"总计","data" =>$v['data'],"itemStyle" =>array("color" =>$color),'barWidth'=>'40');
  1161. }
  1162. //处理返回原表数据格式
  1163. //计算刻度值 最小值是0,最大值是3000,刻度是500 interval
  1164. $interval = utils::calculateTicks(0,$maxY,10);
  1165. if($interval == 0){
  1166. //处理返回默认值
  1167. $interval = 1;
  1168. }
  1169. $returnData = array("ContainerCount_Title"=>"","ContainerCountList" =>$ContainerCount_Title,"ContainerCounSeries" =>$ContainerCounSeries_return,
  1170. "min" => 0,"Max" =>$interval*10,"interval" =>$interval,"download_name" => $download_name);
  1171. return $returnData;
  1172. }
  1173. public static function getTopBar(){
  1174. $sqlWhere = ' and ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  1175. $sqlWhere = " " . $sqlWhere;
  1176. $date_type = strtolower($_REQUEST["date_type"]);
  1177. if (isset($_REQUEST['date_start']) && !empty($_REQUEST['date_start']))
  1178. $sqlWhere .= " and $date_type >= '" . common::usDate2sqlDate($_REQUEST['date_start']) . " 00:00:00'";
  1179. if (isset($_REQUEST['date_end']) && !empty($_REQUEST['date_end']))
  1180. $sqlWhere .= " and $date_type <= '" . common::usDate2sqlDate($_REQUEST['date_end']) . " 23:59:59'";
  1181. $transportation = $_REQUEST["transportation"];
  1182. if(!is_array($transportation)){
  1183. $transportation = array($transportation);
  1184. }
  1185. $mode_param = "";
  1186. if(utils::count($transportation) == 1 && strtolower($transportation[0]) == 'all' ){
  1187. $mode_param = "'sea','air','road'";
  1188. }else{
  1189. $transport_mode = utils::implode(';', $transportation);
  1190. $mode_param = common::getInNotInSqlForSearch($transport_mode);
  1191. }
  1192. $sqlWhere .= " and transport_mode in ($mode_param)";
  1193. $toporiginType = "shippr_uncode";
  1194. $shippr_uncode_10_sql ="with aa as (select count(shippr_uncode) as num,shippr_uncode,
  1195. (array_agg(shipper_city))[1] AS shipper_city from public.kln_ocean
  1196. where 1=1 and COALESCE(shippr_uncode,'')<>'' $sqlWhere group by shippr_uncode order by num desc limit 10)
  1197. select aa.*,dd.* from aa
  1198. left join LATERAL ( select lon as lng, lat as lat,
  1199. '' as label, '' as infor, 3 as sort,
  1200. null::timestamp without time zone as stime,''::text as ptype
  1201. from vessel.vt_unlocode where (lat<=90 and lat>=-90) and (lon<=180 and lon>=-180) and lon is not null and lat is not null and uncode=aa.shippr_uncode ) dd on true";
  1202. //todo 这里预写个大概
  1203. //common::getTopBarSQL($toporiginType,$_REQUEST["transportation"]);
  1204. $shippr_uncode_10 = common::excuteListSql($shippr_uncode_10_sql);
  1205. //如果值没有:客户地址-->站点地址-->Port地址(POL/POD)
  1206. if(utils::count($shippr_uncode_10) == 1 && empty($shippr_uncode_10[0]["shippr_uncode"])){
  1207. $toporiginType = "fport_of_loading_un";
  1208. $shippr_uncode_10_sql = "with aa as (select count(fport_of_loading_un) as num,fport_of_loading_un as shippr_uncode
  1209. from public.kln_ocean where 1=1 and COALESCE(fport_of_loading_un,'')<>'' $sqlWhere group by fport_of_loading_un order by num desc limit 10)
  1210. select aa.*,dd.* from aa
  1211. left join LATERAL ( select lon as lng, lat as lat,
  1212. '' as label, '' as infor, 3 as sort,
  1213. null::timestamp without time zone as stime,''::text as ptype
  1214. from vessel.vt_unlocode where (lat<=90 and lat>=-90) and (lon<=180 and lon>=-180) and lon is not null and lat is not null and uncode=aa.fport_of_loading_un ) dd on true";
  1215. $shippr_uncode_10 = common::excuteListSql($shippr_uncode_10_sql);
  1216. }
  1217. //$toporiginType = "fport_of_loading_un";
  1218. $topdestinationinType = "consignee_uncode";
  1219. $consignee_uncode_10_sql = "with aa as (select count(consignee_uncode) as num,consignee_uncode,
  1220. (array_agg(consignee_city))[1] AS consignee_city
  1221. from public.kln_ocean where 1=1 and COALESCE(consignee_uncode,'')<>'' $sqlWhere group by consignee_uncode order by num desc limit 10)
  1222. select aa.*,dd.* from aa
  1223. left join LATERAL ( select lon as lng, lat as lat,
  1224. '' as label, '' as infor, 3 as sort,
  1225. null::timestamp without time zone as stime,''::text as ptype
  1226. from vessel.vt_unlocode where (lat<=90 and lat>=-90) and (lon<=180 and lon>=-180) and lon is not null and lat is not null and uncode=aa.consignee_uncode ) dd on true";
  1227. $consignee_uncode_10 = common::excuteListSql($consignee_uncode_10_sql);
  1228. //如果值没有:客户地址-->站点地址-->Port地址(POL/POD)
  1229. if(utils::count($consignee_uncode_10) == 1 && empty($consignee_uncode_10[0]["consignee_uncode"])){
  1230. $topdestinationinType = "mport_of_discharge_un";
  1231. $consignee_uncode_10_sql = "with aa as (select count(mport_of_discharge_un) as num,mport_of_discharge_un as consignee_uncode from public.kln_ocean where 1=1 and COALESCE(mport_of_discharge_un,'')<>'' $sqlWhere group by mport_of_discharge_un order by num desc limit 10)
  1232. select aa.*,dd.* from aa
  1233. left join LATERAL ( select lon as lng, lat as lat,
  1234. '' as label, '' as infor, 3 as sort,
  1235. null::timestamp without time zone as stime,''::text as ptype
  1236. from vessel.vt_unlocode where (lat<=90 and lat>=-90) and (lon<=180 and lon>=-180) and lon is not null and lat is not null and uncode=aa.mport_of_discharge_un ) dd on true";
  1237. $consignee_uncode_10 = common::excuteListSql($consignee_uncode_10_sql);
  1238. }
  1239. $toporigin = array();
  1240. $toporiginMap = array();
  1241. $i = 0;
  1242. $origiNunMax = 0;
  1243. foreach($shippr_uncode_10 as $orgin){
  1244. $i = $i + 1;
  1245. $map = array();
  1246. if(!empty($orgin['lat'])&&!empty($orgin['lng'])){
  1247. $map = array("lat" =>$orgin['lat'],"lng" =>$orgin['lng']);
  1248. }
  1249. //$json = '{"lng":121.8525,"lat":29.926545,"label":"'.$orgin['origin'].'","infor":"LAT KRABANG, THAILAND","sort":"0","stime":null,"ptype":"por"}';
  1250. //$map = json_decode($json,true);
  1251. if(!empty($map)){
  1252. $toporiginMap[] = array("qandl"=>array(floatval($map['lat']),floatval($map['lng'])),
  1253. "divIcon" => array("iconSize"=>0),
  1254. "name" =>$orgin['shippr_uncode'],
  1255. "color" =>common::getItemStyle("top",$i),
  1256. "value" =>$orgin['num'],
  1257. "textcolor" =>"#FFF");
  1258. }
  1259. //查询uncode,对应的city
  1260. $city = "";
  1261. if($toporiginType == "shippr_uncode"){
  1262. $city = $orgin['shipper_city'];
  1263. }
  1264. //$city 做假数据
  1265. $toporigin[] = array("name"=>$orgin['shippr_uncode'],"city_name"=>$city,"value"=>$orgin['num'],"color"=>common::getItemStyle("top",$i));
  1266. $origiNunMax = $origiNunMax < $orgin['num'] ? $orgin['num'] : $origiNunMax;
  1267. }
  1268. $topdestination = array();
  1269. $topdestinationinMap = array();
  1270. $i = 0;
  1271. $agentiNunMax = 0;
  1272. foreach($consignee_uncode_10 as $agent){
  1273. $i = $i + 1;
  1274. $map = array();
  1275. if(!empty($agent['lat'])&&!empty($agent['lng'])){
  1276. $map = array("lat" =>$agent['lat'],"lng" =>$agent['lng']);
  1277. }
  1278. // $json = '{"lng":"100.78594000","lat":"13.68521000","label":"'.$agent['agent'].'","infor":"LAT KRABANG, THAILAND","sort":"0","stime":null,"ptype":"por"}';
  1279. // $map = json_decode($json,true);
  1280. if(!empty($map)){
  1281. $topdestinationinMap[] = array("qandl"=>array(floatval($map['lat']),floatval($map['lng'])),
  1282. "divIcon" => array("iconSize"=>0),
  1283. "name" =>$agent['consignee_uncode'],
  1284. "color" =>common::getItemStyle("top",$i),
  1285. "value" =>$agent['num'],
  1286. "textcolor" =>"#FFF");
  1287. }
  1288. //查询uncode,对应的city
  1289. $city = "";
  1290. if($topdestinationinType == "consignee_uncode"){
  1291. $city = $agent['consignee_city'];
  1292. }
  1293. //$city 做假数据
  1294. $topdestination[] = array("name"=>$agent['consignee_uncode'],"city_name"=>$city,"value"=>$agent['num'],"color"=>common::getItemStyle("top",$i));
  1295. $agentiNunMax = $agentiNunMax < $agent['num'] ? $agent['num'] : $agentiNunMax;
  1296. }
  1297. //处理返回原表数据格式
  1298. $interval = utils::calculateTicks(0,$origiNunMax,10);
  1299. if($interval == 0){
  1300. //处理返回默认值
  1301. $interval = 1;
  1302. }
  1303. $dest_interval = utils::calculateTicks(0,$agentiNunMax,10);
  1304. if($dest_interval == 0){
  1305. //处理返回默认值
  1306. $dest_interval = 1;
  1307. }
  1308. $returnData = array("seller_data_list_origin"=>$toporigin,"toporiginMap"=>array_reverse($toporiginMap),"toporiginType"=>$toporiginType,
  1309. "seller_data_list_destination"=>$topdestination,"topdestinationinMap"=>array_reverse($topdestinationinMap),"topdestinationinType"=>$topdestinationinType,
  1310. "min" => 0,"Max" =>$interval*10,"interval" =>$interval,
  1311. "dest_min" => 0,"dest_Max" =>$dest_interval*10,"dest_interval" =>$dest_interval);
  1312. return $returnData;
  1313. }
  1314. public static function getRevenue(){
  1315. //$data = '{"bar_title":"Total: 0","barList":["DEC,23","JAN,24","FEB,24","MAR,24","APR,24","MAY,24","JUN,24","JUL,24","AUG,24","SEP,24","OCT,24","NOV,24"],"barSeries":[{"name":"USD","type":"bar","data":[1,1,1,1,1,1,1,1,1,1,1,1],"emphasis":{"disabled":true,"focus":"none"},"itemStyle":{"color":"#FF7500","borderRadius":6},"label":{"show":false,"color":"#646A73","position":"top","fontFamily":"Lato-Light","hideWhenMouseLeave":false}},{"name":"THB","type":"bar","data":[2,2,2,2,2,2,2,2,2,2,2,2],"emphasis":{"disabled":true,"focus":"none"},"itemStyle":{"color":"#FFAC66","borderRadius":6},"label":{"show":false,"color":"#646A73","position":"top","fontFamily":"Lato-Light","hideWhenMouseLeave":false}},{"name":"SGD","type":"bar","data":[3,3,3,3,3,3,3,3,3,3,3,3],"emphasis":{"disabled":true,"focus":"none"},"itemStyle":{"color":"#FFE3CC","borderRadius":6},"label":{"show":false,"color":"#646A73","position":"top","fontFamily":"Lato-Light","hideWhenMouseLeave":false}}],"Max":5,"interval":1,"download_name":"Rvenue","isShowTooltips":true}';
  1316. //return json_decode($data,true);
  1317. $date_from = null;
  1318. $date_to = null;
  1319. if (isset($_REQUEST['date_start']) && !empty($_REQUEST['date_start'])){
  1320. $date_start = common::dateFormatToYM($_REQUEST['date_start']);
  1321. $date_from = $date_start."-01";
  1322. }
  1323. if (isset($_REQUEST['date_end']) && !empty($_REQUEST['date_end'])){
  1324. $date_end = common::dateFormatToYM($_REQUEST['date_end']);
  1325. $date_to = date('Y-m-t', strtotime($date_end."-01"));
  1326. }
  1327. $param = '{"user_login":"'._getLoginName().'","report_type":"ALL","date_from":"'.$date_from.'","date_to":"'.$date_to.'"}';
  1328. $sql = "SELECT * FROM get_customer_revenue_report('$param');FETCH ALL FROM r2;";
  1329. error_log("Revenue_sql:".$sql);
  1330. $r2_data = common::excuteListSql($sql);
  1331. //$r2_data = common::excuteListSql("select * from _test_data_table");
  1332. $barList = array();
  1333. $groupedItems = array();
  1334. foreach ($r2_data as $item) {
  1335. if(!utils::in_array($item['month'],$barList)){
  1336. $barList[] = $item['month'];
  1337. }
  1338. $groupedItems[$item['currency']][] = $item;
  1339. }
  1340. //补齐所有货币的月份
  1341. foreach($groupedItems as $ckey =>$cvalueArr){
  1342. $currency = array();
  1343. foreach($barList as $month){
  1344. $currency[] = common::findCurrencyByMonth($month,$ckey,$cvalueArr);
  1345. }
  1346. $groupedItems[$ckey] = $currency;
  1347. }
  1348. //处理barSeries
  1349. $barSeries = array();
  1350. //先准备4种颜色
  1351. $color = array("#FF7500","#FFAC66","#FFE3CC");
  1352. $index = 0;
  1353. $max = 0;
  1354. foreach($groupedItems as $currency => $series){
  1355. $series_max = 0;
  1356. $num = $index % 3;
  1357. $index = $index +1;
  1358. $tem_series = array();
  1359. $tem_series["name"] = $currency;
  1360. $tem_series["type"] = "bar";
  1361. $tem_series["emphasis"] = array("disabled"=>true,"focus"=>"none");
  1362. $tem_series["itemStyle"] = array("color"=>$color[$num],"borderRadius"=>6);
  1363. $tem_series["label"] = array("show"=>false,"color"=>"#646A73","position"=>"top","fontFamily"=>"Lato-Light","hideWhenMouseLeave"=>false);
  1364. //准备series data
  1365. $data = array();
  1366. $total = 0;
  1367. foreach($series as $_series){
  1368. $invoice_amount = empty($_series['invoice_amount'])? 0 : round($_series['invoice_amount'], 4);
  1369. $data[]=$invoice_amount;
  1370. $total = $total + $invoice_amount;
  1371. $max = $max<$_series['invoice_amount'] ? $_series['invoice_amount'] : $max;
  1372. $series_max = $series_max<$_series['invoice_amount'] ? $_series['invoice_amount'] : $series_max;
  1373. }
  1374. //计算Y坐标的间隔 每种货币的
  1375. $interval = utils::calculateTicks(0,$series_max,5);
  1376. if($interval == 0){
  1377. //处理返回默认值
  1378. $interval = 2;
  1379. }
  1380. $tem_series["Max"] = $interval*5;
  1381. $tem_series["interval"] = $interval;
  1382. $tem_series["data"] = $data;
  1383. $tem_series["total"] = floatval(number_format($total, 4, '.', ''));
  1384. $barSeries[] = $tem_series;
  1385. }
  1386. //计算Y坐标的间隔
  1387. $interval = utils::calculateTicks(0,$max,5);
  1388. if($interval == 0){
  1389. //处理返回默认值
  1390. $interval = 2;
  1391. }
  1392. $revenueBarData = array("bar_title" =>"Total:","barList" => $barList,
  1393. "barSeries" =>$barSeries,"download_name"=>"Rvenue","isShowTooltips"=>true,"Max" =>$interval*5,"interval" =>$interval);
  1394. return $revenueBarData;
  1395. }
  1396. public static function findCurrencyByMonth($month,$ckey,$cvalueArr){
  1397. $data = array("month" =>$month,"currency"=>$ckey,"invoice_amount"=>0,"sort_month"=>"");
  1398. foreach($cvalueArr as $realmonth){
  1399. if($realmonth['month'] == $month){
  1400. $data = $realmonth;
  1401. }
  1402. }
  1403. return $data;
  1404. }
  1405. public static function getdefaultManagement(){
  1406. $Management = array();
  1407. $Management[] = array("id"=>1 ,
  1408. "title"=>"KPI",
  1409. "switchValue"=>true,
  1410. "text"=>"Pie chart showing figures of shipments KPI of Departure and Arrival.");
  1411. $Management[] = array("id"=>2 ,
  1412. "title"=>"Pending",
  1413. "switchValue"=>true,
  1414. "text"=>"Pie chart showing figures of shipments which are soon to depart/arrive (Calculated from ETD/ETA).");
  1415. $Management[] = array("id"=>3 ,
  1416. "title"=>"ETD to ETA (Days)",
  1417. "switchValue"=>true,
  1418. "text"=>"Pie chart showing figures of shipments which are soon to depart/arrive (Calculated from ETD/ETA).");
  1419. $Management[] = array("id"=>4 ,
  1420. "title"=>"Container Count",
  1421. "switchValue"=>true,
  1422. "text"=>"Pie chart showing figures of shipments which are soon to depart/arrive (Calculated from ETD/ETA).");
  1423. if(_isRevenueDisplay()){
  1424. $Management[] = array("id"=>5 ,
  1425. "title"=>"Revenue Spent",
  1426. "switchValue"=>true,
  1427. "text"=>"Revenue data for the past 12 months.");
  1428. }
  1429. $Management[] = array("id"=>6 ,
  1430. "title"=>"Top 10 Origin/Destination",
  1431. "switchValue"=>true,
  1432. "text"=>"Figure of the top 10 origin/destination.",
  1433. "title1"=>"Top 10 Origin",
  1434. "title2"=>"Top 10 Destination");
  1435. $Management[] = array("id"=>7 ,
  1436. "title"=>"CO2e Emission by Origin (Top 10)",
  1437. "switchValue"=>true,
  1438. "text"=>"Figure of the CO2e Emission by origin.");
  1439. $Management[] = array("id"=>8 ,
  1440. "title"=>"CO2e Emission by Destination (Top 10)",
  1441. "switchValue"=>true,
  1442. "text"=>"Figure of the CO2e Emission by destination.");
  1443. $Management[] = array("id"=>9 ,
  1444. "title"=>"Recent Status",
  1445. "switchValue"=>true,
  1446. "text"=>"A shipment list with latest status update on top.");
  1447. return $Management;
  1448. }
  1449. /**
  1450. * Destroy Session
  1451. */
  1452. public static function sessionDestroy() {
  1453. session_destroy();
  1454. setcookie(session_name(), '', time() - 3600);
  1455. $_SESSION = array();
  1456. }
  1457. public static function dateFormatToYM($dateString){
  1458. $date = DateTime::createFromFormat('m/Y', $dateString);
  1459. $formattedDate = $date->format('Y-m'); // YYYY-MM
  1460. return $formattedDate;
  1461. }
  1462. public static function retStationInfo($address_1,$address_2,$address_3,$address_4,$city,$state,$country,$zipcode){
  1463. $stationInfo = "";
  1464. if(!empty($address_1)){
  1465. $stationInfo .= $address_1;
  1466. }
  1467. if(!empty($address_2)){
  1468. $stationInfo .= " ".$address_2;
  1469. }
  1470. if(!empty($address_3)){
  1471. $stationInfo .= " ".$address_3;
  1472. }
  1473. if(!empty($address_4)){
  1474. $stationInfo .= " ".$address_4;
  1475. }
  1476. $temp_str = "";
  1477. if(!empty($city)){
  1478. $temp_str .= $city." ";
  1479. }
  1480. if(!empty($state)){
  1481. $temp_str .= $state." ";
  1482. }
  1483. if(!empty($zipcode)){
  1484. $temp_str .= $zipcode." ";
  1485. }
  1486. if(!empty($country)){
  1487. $temp_str .= $country." ";
  1488. }
  1489. if(!empty($temp_str)){
  1490. return $stationInfo." ".trim($temp_str);
  1491. }
  1492. return $stationInfo;
  1493. }
  1494. public static function getInsertSqlNull($table_name, $values) {
  1495. $field = "";
  1496. $value = "";
  1497. foreach ($values as $k => $v) {
  1498. if ($k == 'tmp' || $k == 'action' || $k == 'operate' || $k == 'x' || $k == 'y') {
  1499. continue;
  1500. }
  1501. if (is_array($v)) {
  1502. $v = utils::implode(",", $v);
  1503. }
  1504. if (empty($field)) {
  1505. $field = $k;
  1506. if (utils::checkExist($v, 'now()')) {
  1507. $value = $v;
  1508. } elseif ($v == null) {
  1509. $value .= 'null';
  1510. } elseif ($v == 'TRUE' || $v == 'FALSE') {
  1511. $value .= $v;
  1512. } else {
  1513. $value = '\'' . common::check_input($v) . '\'';
  1514. }
  1515. } else {
  1516. $field .= ',' . $k;
  1517. if (utils::checkExist($v, 'now()'))
  1518. $value .= ', now()';
  1519. elseif ($v == null) {
  1520. $value .= ',null';
  1521. } else if ($v == 'TRUE' || $v == 'FALSE') {
  1522. $value .= ',' . $v;
  1523. } else {
  1524. $value .= ', \'' . common::check_input($v) . '\'';
  1525. }
  1526. }
  1527. }
  1528. return 'insert into ' . $table_name . '(' . $field . ') values (' . $value . ')';
  1529. }
  1530. //密码规则验证
  1531. public static function checkPasswordRule($login, $new_password){
  1532. $sql="select item_value from config where item='passwordCheckRules'";
  1533. $rs = common::excuteObjectSql($sql);
  1534. $str = "";
  1535. if (!empty($rs)) {
  1536. $passwordCheckRules = json_decode($rs["item_value"],true);
  1537. //校验使用次数
  1538. if (!empty($passwordCheckRules["pastPasswordCheckNum"])) {
  1539. $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"];
  1540. $passwords = common::excuteListSql($sql);
  1541. foreach ($passwords as $pwd) {
  1542. if ($pwd['password'] == $new_password) {
  1543. $str = "This password has been recently used";
  1544. }
  1545. }
  1546. }
  1547. if(empty($str)){
  1548. $str = utils::checkPassword($new_password,$passwordCheckRules,$login);
  1549. }
  1550. }else{
  1551. $str = utils::checkPassword($new_password);
  1552. }
  1553. return $str;
  1554. }
  1555. public static function getMilestonesInfo($ocean,$transport_mode,$_schemas,$EDI315TimeAndLocation=array()){
  1556. //Milestones info列名固定
  1557. $Milestones_column = array();
  1558. $Milestones_column[] = array("title" =>"Milestones","field" =>"milestones","formatter" =>"normal","type" =>"normal");
  1559. $Milestones_column[] = array("title" =>"Date Time","field" =>"date_time","formatter" =>"dateTime","type" =>"normal");
  1560. $Milestones_column[] = array("title" =>"Locations","field" =>"locations","formatter" =>"normal","type" =>"normal");
  1561. $Milestones_column[] = array("title" =>"Remarks","field" =>"remarks","formatter" =>"normal","type" =>"normal");
  1562. //EDI315 有关联查询,以那个为准。但是如果是手工录入或者不是EDI 进去的Milestone的情况,这以这个为准
  1563. $Milestones_NO_Mapping = common::getMilestones_NO_Mapping_Data($ocean);
  1564. //Milestones 数据信息待定
  1565. $Milestones_data = array();
  1566. if($transport_mode == 'sea'){
  1567. $Milestones_data_arr = common::excuteListSql("select sn.description,act_date||' '||COALESCE(act_time,'') as date_time,
  1568. remark,timezone,a.code
  1569. from public.ocean_milestone a
  1570. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'sea'
  1571. where a.serial_no='".$ocean["serial_no"]."' and act_date is not null order by sn.sno asc");
  1572. }else{
  1573. $Milestones_data_arr = common::excuteListSql("select sn.description,act_date||' '||COALESCE(act_time,'') as date_time,
  1574. remark,timezone,a.code
  1575. from $_schemas.air_milestone a
  1576. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
  1577. where a.serial_no='".$ocean["serial_no"]."' and act_date is not null order by sn.sno asc");
  1578. }
  1579. foreach($Milestones_data_arr as $mda){
  1580. $timezone = "";
  1581. $IFFICC_locations ="";
  1582. if(!empty($EDI315TimeAndLocation[$mda['code']])){
  1583. $edi315Info = $EDI315TimeAndLocation[$mda['code']];
  1584. if(!empty($edi315Info)){
  1585. $timezone = $edi315Info['timezone'];
  1586. }
  1587. //IFFICC 比较特殊用EDI的locations
  1588. if($mda['code'] == "IFFICC"){
  1589. $IFFICC_locations = $edi315Info['location'];
  1590. }
  1591. }else{
  1592. $edi315Info = $Milestones_NO_Mapping[$mda['code']];
  1593. if(!empty($edi315Info)){
  1594. $timezone = $edi315Info['timezone'];
  1595. }
  1596. }
  1597. //locations 以配置的信息为准
  1598. $locations = "";
  1599. $edi315Info = $Milestones_NO_Mapping[$mda['code']];
  1600. if(!empty($edi315Info)){
  1601. $locations = $edi315Info['location'];
  1602. if($mda['code'] == "IFFICC" && !empty($IFFICC_locations)){
  1603. $locations = $IFFICC_locations;
  1604. }
  1605. }
  1606. $Milestones_data[] = array("milestones"=>$mda['description'],"date_time"=>$mda['date_time'],"timezone" =>$timezone,
  1607. "locations" => $locations, "remarks" =>$mda['remark']);
  1608. }
  1609. $Milestones = array("Milestones_column"=>$Milestones_column,"Milestones_data" =>$Milestones_data);
  1610. return $Milestones;
  1611. }
  1612. /**
  1613. * 查询uncode 对应的时区
  1614. */
  1615. public static function getCityPortsInfo($uncodes){
  1616. $data =array();
  1617. $sql = "select time_zone as timezonecode,uncode as ctrycitycode from public.city_timezone where lower(uncode) ". common::getInNotInSql($uncodes);
  1618. $uncode_rs = common::excuteListSql($sql);
  1619. foreach($uncode_rs as $value){
  1620. $data[$value['ctrycitycode']] = $value['timezonecode'];
  1621. }
  1622. return $data;
  1623. }
  1624. /**
  1625. * EDI315 有关联查询,以那个为准。但是如果是手工录入或者没有对应的情况,这以这个为准
  1626. */
  1627. public static function getMilestones_NO_Mapping_Data($ocean){
  1628. $Milestones_NO_Mapping = array();
  1629. //取origin $ocean['aa_city'] 不是必需,对应文件里未提location来源
  1630. $Milestones_NO_Mapping['IFFBCF'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
  1631. $Milestones_NO_Mapping['IFFBCR'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
  1632. $Milestones_NO_Mapping['IFFCPU'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
  1633. $Milestones_NO_Mapping['IFFSIL'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
  1634. $Milestones_NO_Mapping['IFFEDO'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
  1635. $Milestones_NO_Mapping['IFFECC'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
  1636. //Place of Receipt
  1637. $Milestones_NO_Mapping['IFFREC'] = array("code"=>"por/pol","timezone"=>$ocean['por_timezone'],"location"=>$ocean['por_uncity']);
  1638. $Milestones_NO_Mapping['IFFECP'] = array("code"=>"por/pol","timezone"=>$ocean['por_timezone'],"location"=>$ocean['por_uncity']);
  1639. //Port of loading
  1640. $Milestones_NO_Mapping['IFFONB'] = array("code"=>"por/pol","timezone"=>$ocean['pol_timezone'],"location"=>$ocean['pol_uncity']);
  1641. $Milestones_NO_Mapping['IFFDEP'] = array("code"=>"por/pol","timezone"=>$ocean['pol_timezone'],"location"=>$ocean['pol_uncity']);
  1642. //取destination $ocean['dd_city']不是必需
  1643. $Milestones_NO_Mapping['IFFCSN'] = array("code"=>"destination","timezone"=>$ocean['dd_timezone'],"location"=>"");
  1644. $Milestones_NO_Mapping['IFFIDO'] = array("code"=>"destination","timezone"=>$ocean['dd_timezone'],"location"=>"");
  1645. //取Port of discharge
  1646. $Milestones_NO_Mapping['IFFARR'] = array("code"=>"mpod","timezone"=>$ocean['mpod_timezone'],"location"=>$ocean['mpod_uncity']);
  1647. $Milestones_NO_Mapping['IFFUND'] = array("code"=>"mpod/pod/fd","timezone"=>$ocean['mpod_timezone'],"location"=>$ocean['mpod_uncity']);
  1648. $Milestones_NO_Mapping['IFFICC'] = array("code"=>"mpod","timezone"=>$ocean['mpod_timezone'],"location"=>$ocean['mpod_uncity']);
  1649. //Place of Delivery
  1650. $Milestones_NO_Mapping['IFFAFD'] = array("code"=>"pod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1651. $Milestones_NO_Mapping['IFFCTA'] = array("code"=>"pod/mpod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1652. $Milestones_NO_Mapping['IFFADW'] = array("code"=>"pod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1653. $Milestones_NO_Mapping['IFFDDW'] = array("code"=>"pod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1654. $Milestones_NO_Mapping['IFFPPD'] = array("code"=>"mpod/pod/fd","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1655. $Milestones_NO_Mapping['IFFECR'] = array("code"=>"mpod/pod/fd","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1656. //final_destination $ocean['fd_city']不是必需
  1657. $Milestones_NO_Mapping['IFFDEL'] = array("code"=>"fd","timezone"=>$ocean['_fd_timezone'],"location"=>"");
  1658. $Milestones_NO_Mapping['IFFHBL'] = array("code"=>"fd","timezone"=>$ocean['_fd_timezone'],"location"=>"");
  1659. return $Milestones_NO_Mapping;
  1660. }
  1661. /**
  1662. * 这个详细查询已经带模式了
  1663. */
  1664. public static function getEDI315StatusForDetail($serial_no){
  1665. $data = array();
  1666. $ctnr_sql = "SELECT oc.ctnr, oc.serial_no,oc.size FROM oc_container oc LEFT JOIN ocean o ON oc.serial_no = o.serial_no
  1667. WHERE o.serial_no='$serial_no'";
  1668. $ctnr_data = common::excuteListSql($ctnr_sql);
  1669. $containerStatusData = array();
  1670. $VD = "";
  1671. $VA = "";
  1672. foreach ($ctnr_data as $cd){
  1673. //存在柜号为空的数据情况
  1674. if(empty($cd['ctnr'])){
  1675. continue;
  1676. }
  1677. //(select uncity from public.ports where uncode = s.event_code) as uncity, 按新版的逻辑这个先取消掉
  1678. $ctnr_status_sql = "select s.source_id, s.event_base as event,
  1679. to_char(to_timestamp(s.event_date, 'YYYYMMDD'), 'YYYY-MM-DD') as eventdate,
  1680. to_char(to_timestamp(s.event_time, 'HH24MI'), 'HH24:MI') as eventtime,
  1681. e.description,s.event_type as eventtype,
  1682. s.event_code as eventcode, s.event_city as eventcity,
  1683. (select time_zone from public.city_timezone where uncode = s.event_code) as timezone,
  1684. '' as uncity,
  1685. case when event ='I' or event ='TR' then 'IFFREC'::text
  1686. when event ='AE' then 'IFFONB'::text
  1687. when event ='VD' then 'IFFDEP'::text
  1688. when event ='EB' or event ='VA' then 'IFFARR'::text
  1689. when event ='UV' then 'IFFUND'::text
  1690. when event ='VA' then 'IFFAFD'::text
  1691. when event ='AV' then 'IFFCTA'::text
  1692. when event ='CT' then 'IFFICC'::text
  1693. when event ='OA' or event ='D' then 'IFFPPD'::text
  1694. when event ='RD' then 'IFFECR'::text
  1695. when event ='EE' then 'IFFECP'::text
  1696. else '' ::text
  1697. end as milestone_code
  1698. from public.ra_online_container_status_v s
  1699. left join public.ra_online_edi_event e on s.event_base = e.ra_name
  1700. where s.serial_no = '" . pg_escape_string($cd['serial_no']) . "'
  1701. and s.container_no = '" . pg_escape_string($cd['ctnr']) . "' and is_display = true
  1702. order by to_timestamp(s.event_date, 'YYYYMMDD') desc,
  1703. to_timestamp(s.event_time, 'HH24MI') desc,e.ra_order desc";
  1704. $ctnr_status = common::excuteListSql($ctnr_status_sql);
  1705. //Container_Status 新版只显示几个状态, CTNR# EE I AE VD VA
  1706. $container_status_column = array("EE","I","AE","VD","VA");
  1707. $containerStatusDataTemp = array();
  1708. $content = array();
  1709. //按顺序处理 新版只显示几个状态
  1710. //foreach($container_status_column as $status){
  1711. foreach($ctnr_status as $event){
  1712. //if(strtolower($event['event']) == strtolower($status)){
  1713. $eventdate = $event["eventdate"];
  1714. if (empty($event["source_id"]) || $event["source_id"]==0) {
  1715. $eventdate.= " " . $event["eventtime"];
  1716. }
  1717. $location_code = $event["eventcode"];
  1718. $content[] = array("code" =>$event['event'],"title" =>$event['description'],"date"=>$eventdate,"country"=>$location_code,"timezone"=>$event['timezone']);
  1719. if(strtolower($event['event']) == "vd" && !empty($eventdate)){
  1720. $VD = $eventdate;
  1721. }
  1722. if(strtolower($event['event']) == "va" && !empty($eventdate)){
  1723. $VA = $eventdate;
  1724. }
  1725. //}
  1726. }
  1727. //}
  1728. //记录所有的信息
  1729. $EDI315TimeAndLocation = array();
  1730. foreach($ctnr_status as $event){
  1731. if(!empty($EDI315TimeAndLocation['IFFARR']) && $EDI315TimeAndLocation['IFFARR']['code'] == "EB"){
  1732. //如果存在EB 的EB 的优先级最高
  1733. continue;
  1734. }
  1735. if(!empty($EDI315TimeAndLocation['IFFPPD']) && $EDI315TimeAndLocation['IFFARR']['code'] == "OA"){
  1736. //如果存在OA 的OA 的优先级最高
  1737. continue;
  1738. }
  1739. $EDI315TimeAndLocation[$event['milestone_code']] = array("code"=>$event['event'],"timezone"=>$event['timezone'],"location"=>$event['uncity']);
  1740. }
  1741. $containerStatusDataTemp['label'] = $cd['ctnr']." / ".$cd['size'];
  1742. $containerStatusDataTemp['content'] = $content;
  1743. $containerStatusData[] = $containerStatusDataTemp;
  1744. }
  1745. $data['containerStatusData'] = $containerStatusData;
  1746. $data['EDI315TimeAndLocation'] = $EDI315TimeAndLocation;
  1747. $data['VD'] = $VD;
  1748. $data['VA'] = $VA;
  1749. return $data;
  1750. }
  1751. public static function getEDI315Time($serial_no,$_schemas){
  1752. //Timezone From 来自于EDI315
  1753. $ctnr_sql = "SELECT oc.ctnr, oc.serial_no,oc.size FROM $_schemas.oc_container oc LEFT JOIN $_schemas.ocean o ON oc.serial_no = o.serial_no
  1754. WHERE o.serial_no='$serial_no'";
  1755. $ctnr_data = common::excuteListSql($ctnr_sql);
  1756. $EDI315TimeAndLocation = array();
  1757. foreach ($ctnr_data as $cd){
  1758. //存在柜号为空的数据情况
  1759. if(empty($cd['ctnr'])){
  1760. continue;
  1761. }
  1762. $ctnr_status_sql = "select
  1763. (select time_zone from public.city_timezone where uncode = s.event_code) as timezone,
  1764. case when event ='I' or event ='TR' then 'IFFREC'::text
  1765. when event ='AE' then 'IFFONB'::text
  1766. when event ='VD' then 'IFFDEP'::text
  1767. when event ='EB' or event ='VA' then 'IFFARR'::text
  1768. when event ='UV' then 'IFFUND'::text
  1769. when event ='VA' then 'IFFAFD'::text
  1770. when event ='AV' then 'IFFCTA'::text
  1771. when event ='CT' then 'IFFICC'::text
  1772. when event ='OA' or event ='D' then 'IFFPPD'::text
  1773. when event ='RD' then 'IFFECR'::text
  1774. when event ='EE' then 'IFFECP'::text
  1775. else '' ::text
  1776. end as milestone_code
  1777. from public.ra_online_container_status_v s
  1778. left join public.ra_online_edi_event e on s.event_base = e.ra_name
  1779. where s.serial_no = '" . pg_escape_string($cd['serial_no']) . "'
  1780. and s.container_no = '" . pg_escape_string($cd['ctnr']) . "' and is_display = true
  1781. order by to_timestamp(s.event_date, 'YYYYMMDD') asc,
  1782. to_timestamp(s.event_time, 'HH24MI') asc,e.ra_order asc";
  1783. $ctnr_status = common::excuteListSql($ctnr_status_sql);
  1784. //记录所有的信息、替换最后一个柜子
  1785. $EDI315TimeAndLocation = array();
  1786. foreach($ctnr_status as $event){
  1787. if(!empty($EDI315TimeAndLocation['IFFARR']) && $EDI315TimeAndLocation['IFFARR']['code'] == "EB"){
  1788. //如果存在EB 的EB 的优先级最高
  1789. continue;
  1790. }
  1791. if(!empty($EDI315TimeAndLocation['IFFPPD']) && $EDI315TimeAndLocation['IFFARR']['code'] == "OA"){
  1792. //如果存在OA 的OA 的优先级最高
  1793. continue;
  1794. }
  1795. $EDI315TimeAndLocation[$event['milestone_code']] = array("code"=>$event['event'],"timezone"=>$event['timezone']);
  1796. }
  1797. }
  1798. return $EDI315TimeAndLocation;
  1799. }
  1800. public static function getDashboardTransportationSqlWhere(){
  1801. $transportation = $_REQUEST["transportation"];
  1802. if(!is_array($transportation)){
  1803. $transportation = array($transportation);
  1804. }
  1805. $mode_param = "";
  1806. if(utils::count($transportation) == 1 && strtolower($transportation[0]) == 'all' ){
  1807. $mode_param = "'sea','air','road'";
  1808. }else{
  1809. $transport_mode = utils::implode(';', $transportation);
  1810. $mode_param = common::getInNotInSqlForSearch($transport_mode);
  1811. }
  1812. return " and transport_mode in ($mode_param)";
  1813. }
  1814. /*
  1815. * Create Directory
  1816. */
  1817. public static function mkdirs($path, $mode = 0777) { //creates directory tree recursively
  1818. if (!file_exists($path)) {
  1819. if (!mkdir($path, $mode, TRUE))
  1820. return FALSE;
  1821. }
  1822. return TRUE;
  1823. }
  1824. }
  1825. ?>