main_new_version.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. <?php
  2. $max_ec = ini_get('max_execution_time'); //set max_excution_time
  3. ini_set('max_execution_time', '600');
  4. $memory_limit = "";
  5. $action = "";
  6. if (isset($_GET['action']))
  7. $action = strtolower($_GET['action']);
  8. if (isset($_POST['action']))
  9. $action = strtolower($_POST['action']);
  10. include "include.ini.php";
  11. include 'service/ocean_booking.class.php';
  12. include 'service/ocean_order.class.php';
  13. include 'service/operation_log.class.php';
  14. include 'service/search.class.php';
  15. include 'service/column.class.php';
  16. include 'service/ajax.class.php';
  17. include 'service/login.class.php';
  18. include 'service/tools.class.php';
  19. include 'service/robot.class.php';
  20. include 'service/AIClientFactory.php';
  21. //为了调用,临时做一个登录动作 如果是正式版 要注释掉菜单System Settings
  22. //$_POST['uname'] = "ra.admin";
  23. //$_POST['psw'] = common::excuteOneSql("select ra_password from public.ra_online_user where user_login = 'ra.admin'");
  24. // $name =strpos(common::ip(), "192.168.0.158") !== false || strpos(common::ip(), "192.168.0.161") !== false ? "dddde" : 'ra.admin';
  25. // $_POST['uname'] = $name;
  26. // $_POST['psw'] = common::excuteOneSql("select ra_password from public.ra_online_user where user_login = '".$name."'");
  27. // login::getInstance()->do_login_auto();
  28. //验证路由权限
  29. common::securityCheckHandNew($action);
  30. if (_is_only_vgm()) {
  31. Header("Location:main.php?action=main");
  32. }
  33. error_log("--------------前端请求post参数---------------");
  34. error_log(utils::jsonFiltration("null", "\"\"", json_encode($_POST)));
  35. error_log("--------------前端请求get参数---------------");
  36. error_log(utils::jsonFiltration("null", "\"\"", json_encode($_GET)));
  37. //Operation log 日志记录
  38. utils::operation_log_records();
  39. switch ($action) {
  40. case 'ocean_booking':
  41. ocean_booking::getInstance()->ocean_booking();
  42. break;
  43. case 'ocean_order':
  44. ocean_order::getInstance()->ocean_order();
  45. break;
  46. case 'ajax':
  47. echo ajax::getInstance()->run();
  48. break;
  49. case 'opreation_log':
  50. echo operation_log::getInstance()->operation_log();
  51. break;
  52. case 'main':
  53. //如果在没有登录前,没有登录信息,指定用户
  54. if(!isset($_SESSION['ONLINE_USER'])){
  55. $menuList = array();
  56. $menuList[] = array("index"=>'1',"label"=>"Dashboard","icon"=>"icon_data_fill_b","path"=>"/dashboard");
  57. $menuList[] = array("index"=>'2',"label"=>"Booking","icon"=>"icon_booking__fill_b","path"=>"/booking");
  58. $menuList[] = array("index"=>'3',"label"=>"Tracking","icon"=>"icon_tracking__fill_b","path"=>"/tracking");
  59. } else {
  60. //d登录后,根据配置的权限,是否显示
  61. if (_isAdmin())
  62. $sql = "select f_column, min(menu_id) as menu_id, max(menu_icon_font) as menu_icon_font from public.ra_online_permission where has_new_version=true group by f_column order by min(order_by)";
  63. elseif (_isNewUser())
  64. $sql = "select f_column, min(menu_id) as menu_id, max(menu_icon_font) as menu_icon_font from public.ra_online_permission where has_new_version=true and customer_check = true group by f_column ORDER BY min(order_by)";
  65. else
  66. $sql = "select p.f_column, min(menu_id) as menu_id, max(menu_icon_font) as menu_icon_font from public.ra_online_user_permission up left join public.ra_online_permission p on up.p_id = p.id where has_new_version=true and lower(user_name) = '" . common::check_input(strtolower(_getLoginName())) . "' group by p.f_column ORDER BY min(p.order_by)";
  67. $rs = common::excuteListSql($sql);
  68. if (empty($rs) && _isApexLogin()) {
  69. $sql = "select f_column, min(menu_id) as menu_id, max(menu_icon_font) as menu_icon_font from public.ra_online_permission where has_new_version=true and default_check = true group by f_column ORDER BY min(order_by)";
  70. $rs = common::excuteListSql($sql);
  71. }
  72. $menuSetting = array("Ocean Booking" => array("label"=>"Booking","path"=>"/booking","icon"=>"icon_booking__fill_b"),
  73. "Ocean B/L Info." => array("label"=>"Tracking","path"=>"/tracking","icon"=>"icon_tracking__fill_b"));
  74. $menuList = array();
  75. $menuList[] = array("index"=>'1',"label"=>"Dashboard","icon"=>"icon_data_fill_b","path"=>"/dashboard");
  76. $index = 2;
  77. foreach ($rs as $value) {
  78. if ($value['f_column'] == "Shipment Info."){
  79. if (_isAdmin())
  80. $ll = common::excuteListSql("select s_column, url_action, sub_menu_id from public.ra_online_permission where has_new_version=true and f_column = '" . common::check_input($value['f_column']) . "' ORDER BY order_by");
  81. elseif (_isNewUser())
  82. $ll = common::excuteListSql("select s_column, url_action, sub_menu_id from public.ra_online_permission where has_new_version=true and customer_check = true and f_column = '" . common::check_input($value['f_column']) . "' ORDER BY order_by");
  83. else
  84. $ll = common::excuteListSql("select s_column, url_action, sub_menu_id from public.ra_online_permission p left join public.ra_online_user_permission gp on gp.p_id = p.id where has_new_version=true and f_column = '" . common::check_input($value['f_column']) . "' and lower(gp.user_name) = '" . common::check_input(strtolower(_getLoginName())) . "' ORDER BY p.order_by");
  85. if (empty($ll) && _isApexLogin()) {
  86. $ll = common::excuteListSql("select s_column, url_action, sub_menu_id from public.ra_online_permission where has_new_version=true and f_column = '" . common::check_input($value['f_column']) . "' and default_check = true ORDER BY order_by");
  87. }
  88. //单独拼接URL
  89. foreach ($ll as $v) {
  90. if($v['s_column'] =="Ocean Booking" || $v['s_column'] =="Ocean B/L Info."){
  91. $urlData = $menuSetting[$v['s_column']];
  92. $menuList[] = array("index"=>"$index","label"=>$urlData['label'],"icon"=>$urlData['icon'],"path"=>$urlData['path']);
  93. $index = $index + 1;
  94. }
  95. }
  96. }
  97. }
  98. // $menuList[] = array("index"=>$index,"label"=>"System Management","icon"=>"icon_system__management_fill_b","type"=>"list",
  99. // "children"=>array(array("index" =>$index.'-1',"label" =>"Operation Log","path"=>"/Operationlog")));
  100. $systemManagement = array("index"=>"$index","label"=>"System Management","icon"=>"icon_system__management_fill_b","type"=>"list");
  101. $children = array();
  102. //$children[] = array("index" =>$index.'-1',"label" =>"System Message","path"=>"/system-message");
  103. //$children[] = array("index" =>$index.'-2',"label" =>"System Settings","path"=>"/SystemSettings");
  104. //只有chud的账户可以看日志记录
  105. if(strtolower(_getLoginName()) == "chud"
  106. || strtolower(_getLoginName()) == strtolower("IT.Andywu")
  107. || strtolower(_getLoginName()) == "ra.admin"){
  108. $children[] = array("index" =>$index.'-3',"label" =>"Operation Log","path"=>"/Operationlog");
  109. //$children[] = array("index" =>$index.'-4',"label" =>"Prompt Configuration","path"=>"/PromptConfiguration");
  110. }
  111. $systemManagement["children"] = $children;
  112. if (!empty($children)){
  113. $menuList[] = $systemManagement;
  114. }
  115. }
  116. common::echo_json_encode(200, $menuList);
  117. exit();
  118. break;
  119. case 'main_filter':
  120. $data = common::getManagement();
  121. common::echo_json_encode(200, $data['dashboard_filter']);
  122. exit();
  123. break;
  124. case 'main_report':
  125. //分担查询
  126. include ONLINE_ROOT . 'libs' . DS . 'map_config.ini.php';
  127. //这里只剩下r3,r4的查询
  128. $type = $_REQUEST["r_type"];
  129. $sqlWhere = ' and ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  130. $sqlWhere = " " . $sqlWhere;
  131. $sqlWhere .= common::getDashboardTransportationSqlWhere();
  132. $sqlWhere = common::check_input($sqlWhere);
  133. // $list = common::excuteListSql("select * from public.online_order_status_date_kln_pending('$type'::text, '$sqlWhere'::text) "
  134. // . "r (c bigint, e integer, b integer, d text)");
  135. $sql = "select * from public.online_order_status_date_kln_pending('$type'::text, '$sqlWhere'::text) "
  136. . "r (c bigint, e integer, b integer, d text)";
  137. $list = $mapdb->GetAll($sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $sql), 0));
  138. $key = "[";
  139. $value = "[";
  140. $totalValue = 0;
  141. foreach ($list as $vv) {
  142. if ($key != "[") {
  143. $key .= ",";
  144. $value .= ",";
  145. }
  146. if ($type == "r2" || $type == "r3" || $type == "r4") {
  147. $key .= '"' . $vv["d"] . '"';
  148. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["d"] . '" }';
  149. $totalValue = $totalValue + $vv["c"];
  150. } else {
  151. if ($vv["e"] == -1) {
  152. $key .= '"Over 80 Days"';
  153. $value .= '{"value":"' . $vv["c"] . '","name":"Over 80 Days"}';
  154. } else {
  155. $key .= '"' . $vv["b"] . '-' . $vv["e"] . ' Days"';
  156. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["b"] . '-' . $vv["e"] . ' Days"}';
  157. }
  158. $totalValue = $totalValue + $vv["c"];
  159. }
  160. }
  161. $key .= "]";
  162. $value .= "]";
  163. //处理返回原表数据格式 r1 r3 r4的数据返回
  164. $data = common::mian_repot_do($value,$type,$totalValue);
  165. common::echo_json_encode(200, $data);
  166. exit();
  167. break;
  168. case 'main_report_etd':
  169. //分担查询
  170. include ONLINE_ROOT . 'libs' . DS . 'map_config.ini.php';
  171. //这里只有r1查询
  172. $type = "r1";
  173. $container_type = "";
  174. $date_type = strtolower($_REQUEST["date_type"]);
  175. if (empty($_REQUEST["date_start"])) {
  176. $bdate = "null";
  177. } else {
  178. $bdate = $_REQUEST["date_start"];
  179. $bdate = "'$bdate'";
  180. }
  181. if (empty($_REQUEST["date_end"])) {
  182. $edate = "null";
  183. } else {
  184. $edate = $_REQUEST["date_end"];
  185. $edate = "'$edate'";
  186. }
  187. $sqlWhere = ' and ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  188. $sqlWhere = " " . $sqlWhere;
  189. $sqlWhere = $sqlWhere . common::getDashboardTransportationSqlWhere();
  190. $sqlWhere = common::check_input($sqlWhere);
  191. // $list = common::excuteListSql("select * from public.online_order_status_date_kln_r1_r2('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text,'$date_type'::text) "
  192. // . "r (c bigint, e integer, b integer, d text)");
  193. $sql = "select * from public.online_order_status_date_kln_r1_r2('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text,'$date_type'::text) "
  194. . "r (c bigint, e integer, b integer, d text)";
  195. $list = $mapdb->GetAll($sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $sql), 0));
  196. $key = "[";
  197. $value = "[";
  198. $totalValue = 0;
  199. foreach ($list as $vv) {
  200. if ($key != "[") {
  201. $key .= ",";
  202. $value .= ",";
  203. }
  204. if ($type == "r2" || $type == "r3" || $type == "r4") {
  205. $key .= '"' . $vv["d"] . '"';
  206. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["d"] . '" }';
  207. $totalValue = $totalValue + $vv["c"];
  208. } else {
  209. if ($vv["e"] == -1) {
  210. $key .= '"Over 80 Days"';
  211. $value .= '{"value":"' . $vv["c"] . '","name":"Over 80 Days"}';
  212. } else {
  213. $key .= '"' . $vv["b"] . '-' . $vv["e"] . ' Days"';
  214. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["b"] . '-' . $vv["e"] . ' Days"}';
  215. }
  216. $totalValue = $totalValue + $vv["c"];
  217. }
  218. }
  219. $key .= "]";
  220. $value .= "]";
  221. //处理返回原表数据格式 r1 r3 r4的数据返回
  222. $data = common::mian_repot_do($value,$type,$totalValue);
  223. common::echo_json_encode(200, $data);
  224. exit();
  225. break;
  226. case 'main_report_kpi':
  227. //分担查询
  228. include ONLINE_ROOT . 'libs' . DS . 'map_config.ini.php';
  229. $type = $_REQUEST["r_type"];
  230. $sqlWhere = ' and ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  231. $sqlWhere = " " . $sqlWhere;
  232. $sqlWhere = $sqlWhere . common::getDashboardTransportationSqlWhere();
  233. $sqlWhere = common::check_input($sqlWhere);
  234. $date_type = strtolower($_REQUEST["date_type"]);
  235. if (isset($_REQUEST['date_start']) && !empty($_REQUEST['date_start']))
  236. $sqlWhere .= " and $date_type >= ''" . common::usDate2sqlDate($_REQUEST['date_start']) . " 00:00:00''";
  237. if (isset($_REQUEST['date_end']) && !empty($_REQUEST['date_end']))
  238. $sqlWhere .= " and $date_type <= ''" . common::usDate2sqlDate($_REQUEST['date_end']) . " 23:59:59''";
  239. // $list = common::excuteListSql("select * from public.online_order_status_date_kln_kpi('$type'::text,'$sqlWhere'::text) "
  240. // . "r (c bigint, d text)");
  241. $sql = "select * from public.online_order_status_date_kln_kpi('$type'::text,'$sqlWhere'::text) "
  242. . "r (c bigint, d text)";
  243. $list = $mapdb->GetAll($sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $sql), 0));
  244. $key = "[";
  245. $value = "[";
  246. $totalValue = 0;
  247. foreach ($list as $vv) {
  248. if ($key != "[") {
  249. $key .= ",";
  250. $value .= ",";
  251. }
  252. if ($type == "ata_r3" || $type == "atd_r4" ) {
  253. $key .= '"' . $vv["d"] .'"';
  254. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["d"] .'"}';
  255. $totalValue = $totalValue + $vv["c"];
  256. }
  257. }
  258. $key .= "]";
  259. $value .= "]";
  260. //处理返回原表数据格式
  261. $ETDList = array();
  262. $value_arr = json_decode($value,true);
  263. foreach($value_arr as $arr){
  264. $color = common::getItemStyle($type,$arr['name']);
  265. if($arr['name'] == "0 Day"){
  266. $arr['name'] = "≤1 Day";
  267. }
  268. if($arr['name'] == "7 Days"){
  269. $arr['name'] = "≥7 Days";
  270. }
  271. $ETDList[] = array("value" =>intval($arr['value']),"name" =>$arr['name'],"itemStyle" =>array("color" =>$color));
  272. }
  273. // 排序依据的键数组(这里我们用一个数字数组来表示)
  274. $order = ["≤1 Day", "1-2 Days", "3-6 Days","≥7 Days"];
  275. $ETDList = utils::arrayOrderBykeys($order,$ETDList,"name");
  276. if($type == 'atd_r4'){
  277. $data = array("ETDList" =>$ETDList,"ETD_Radius"=>array('30%','50%'),"title1" =>"Departure","title2" =>"(ATD-ETD)","download_name" => "KPI Departure");
  278. }
  279. if($type == 'ata_r3'){
  280. $data = array("ETDList" =>$ETDList,"ETD_Radius"=>array('30%','50%'),"title1" =>"Arrival","title2" =>"(ATA-ETA)","download_name" => "KPI Arrival");
  281. }
  282. common::echo_json_encode(200, $data);
  283. exit();
  284. break;
  285. case 'main_report_container_bar':
  286. //新UI 20 40 45 3份数据同时查询,且是柱状图,所以与r3 r4查询分开
  287. $container_type ='';
  288. $ContainerCounSeries = array();
  289. $date_type = strtolower($_REQUEST["date_type"]);
  290. $type = $_REQUEST["r_type"];
  291. if (empty($_REQUEST["date_start"])) {
  292. $bdate = "null";
  293. } else {
  294. $bdate = $_REQUEST["date_start"];
  295. $bdate = "'$bdate'";
  296. }
  297. if (empty($_REQUEST["date_end"])) {
  298. $edate = "null";
  299. } else {
  300. $edate = $_REQUEST["date_end"];
  301. $edate = "'$edate'";
  302. }
  303. $list= array();
  304. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  305. $sqlWhere = common::check_input($sqlWhere);
  306. $sqlWhere = " " . $sqlWhere;
  307. //这个20 40 45都查询出来。否则值查询都对应的size,其他的不查询
  308. $value_arr = common::excuteListSql("select * from public.online_order_status_date_kln_r1_r2('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text, '$date_type'::text) "
  309. . "r (month_group text, _20_rc numeric, _40_rc numeric, _45_rc numeric)");
  310. $key_arr = array();
  311. $container_type_arr = array("20","40","45");
  312. foreach($container_type_arr as $_container_type){
  313. $data = array();
  314. //每一个size 的所有月份总计
  315. $total = 0;
  316. //每一个size 对应的最大值
  317. $max = 0;
  318. foreach($value_arr as $arr){
  319. $data[] = intval($arr['_'.$_container_type.'_rc']);
  320. $total = $total + intval($arr['_'.$_container_type.'_rc']);
  321. $max = $max < intval($arr['_'.$_container_type.'_rc']) ? intval($arr['_'.$_container_type.'_rc']) : $max;
  322. if ($_container_type == '20'){
  323. $key_arr[] = $arr['month_group'];
  324. }
  325. }
  326. $ContainerCounSeries[$_container_type] = array("data"=>$data,"total"=>$total,"max"=>$max);
  327. }
  328. //处理返回时数据格式
  329. $ContainerCounSeries_return = array();
  330. //横坐标栏位
  331. $ContainerCount_Title = $key_arr;
  332. //所查的所有模式计算总和
  333. $total = 0;
  334. //所有size下的最大值,方便标注计算最长的Y坐标
  335. $max_all = 0;
  336. foreach($ContainerCounSeries as $k =>$v){
  337. //这个type 是页面传过来的。这个固定r2
  338. $color = common::getItemStyle($type,$k);
  339. $total = $total + $v['total'];
  340. $ContainerCounSeries_return[] = array("name"=>strval($k),"type"=>"bar","emphasis" => array("focus" =>"none"),
  341. "stack" =>"总计","data" =>$v['data'],"itemStyle" =>array("color" =>$color));
  342. $max_all = $max_all + $v['max'];
  343. }
  344. //计算Y坐标的间隔
  345. $interval = utils::calculateTicks(0,$max_all,5);
  346. if($interval == 0){
  347. //处理返回默认值
  348. $interval = 2;
  349. }
  350. $returnData = array("ContainerCount_Title"=>"Total: $total","ContainerCountList" =>$ContainerCount_Title,"ContainerCounSeries" =>$ContainerCounSeries_return,
  351. "min" => 0,"Max" =>$interval*5,"interval" =>$interval,"download_name" => "Container Count");
  352. //demo
  353. // $json = '{"code":200,"data":{"ContainerCount_Title":"Total: 463518","ContainerCountList":["OCT,23","NOV,23","DEC,23","JAN,24","FEB,24","MAR,24","APR,24","MAY,24","JUN,24","JUL,24","AUG,24","SEP,24","OCT,24"],"ContainerCounSeries":[{"name":"20","type":"bar","emphasis":{"focus":"none"},"stack":"\u603b\u8ba1","data":[4400,8600,8804,9271,8961,8793,8534,9476,9530,10277,10081,8997,5784],"itemStyle":{"color":"#FF7500"}},{"name":"40","type":"bar","emphasis":{"focus":"none"},"stack":"\u603b\u8ba1","data":[13652,28021,30422,30136,26320,27035,23979,26494,28406,33318,32318,30962,16369],"itemStyle":{"color":"#FFAC66"}},{"name":"45","type":"bar","emphasis":{"focus":"none"},"stack":"\u603b\u8ba1","data":[189,337,415,437,439,321,250,320,324,603,328,415,200],"itemStyle":{"color":"#FFE3CC"}}],"min":0,"Max":45000,"interval":9000}}';
  354. // $returnData = json_decode($json,true);
  355. // echo json_encode($returnData);
  356. // exit();
  357. common::echo_json_encode(200, $returnData);
  358. exit();
  359. break;
  360. case 'main_report_co2e_bar':
  361. $returnData = common::getCo2eBar();
  362. common::echo_json_encode(200, $returnData);
  363. exit();
  364. break;
  365. case 'main_report_top10_bar':
  366. $returnData = common::getTopBarNew();
  367. common::echo_json_encode(200, $returnData);
  368. exit();
  369. break;
  370. case 'main_report_revenue':
  371. $returnData = common::getRevenue();
  372. common::echo_json_encode(200, $returnData);
  373. exit();
  374. break;
  375. case 'main_map':
  376. $uncode = $_POST["uncode"];
  377. $serial_no = $_POST["serial_no"];
  378. $unall = explode("|", $uncode);
  379. $sql = "";
  380. if (!empty($unall[0]) && $unall[0] != "''") {
  381. $sql .= "select lon as lng, lat as lat, uncode, 'Place of receipt: '||name1 as location_namewo, 'por' as type from vessel.vt_unlocode where "
  382. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  383. . "($unall[0])";
  384. }
  385. if (!empty($unall[1]) && $unall[1] != "''") {
  386. if (!empty($sql)) {
  387. $sql .= " union ";
  388. }
  389. $sql .= "select lon as lng, lat as lat, uncode, 'POL: '||name1 as location_namewo, 'pol' as type from vessel.vt_unlocode where "
  390. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  391. . "($unall[1])";
  392. }
  393. if (!empty($unall[2]) && $unall[2] != "''") {
  394. if (!empty($sql)) {
  395. $sql .= " union ";
  396. }
  397. $sql .= "select lon as lng, lat as lat, uncode, 'POD: '||name1 as location_namewo, 'pod' as type from vessel.vt_unlocode where "
  398. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  399. . "($unall[2])";
  400. }
  401. if (!empty($unall[3]) && $unall[3] != "''") {
  402. if (!empty($sql)) {
  403. $sql .= " union ";
  404. }
  405. $sql .= "select lon as lng, lat as lat, uncode, 'Place of delivery: '||name1 as location_namewo, 'poe' as type from vessel.vt_unlocode where "
  406. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  407. . "($unall[3])";
  408. }
  409. $tkStatus = common::excuteListSql("select tl.by_pickup, g.consignee_exp, g.pickup_from_exp, c.ctnr, g.deliveryto_exp, g.serial_no, tl.location, tl.type, tl.id,
  410. to_char(tl.upload_time, 'MM/DD/YYYY HH24:MI:SS') as utime
  411. from public.tk_general g, public.tk_commodity c left join public.tk_location tl on c.serial_no=tl.serial_no
  412. where g.serial_no=c.serial_no and g.bol=(select m_bol from public.ocean where serial_no='$serial_no') order by tl.order_id");
  413. foreach ($tkStatus as $vv) {
  414. $ll = explode(",", $vv["location"]);
  415. if ($vv["by_pickup"] == "t") {
  416. $pf = explode("\r\n", $vv["pickup_from_exp"]);
  417. $pf = common::check_input($pf[0]) . "(" . $vv["ctnr"] . ")";
  418. $dt = explode("\r\n", $vv["consignee_exp"]);
  419. $dt = common::check_input($dt[0]) . "(" . $vv["ctnr"] . ")";
  420. } else {
  421. $pf = explode("\r\n", $vv["consignee_exp"]);
  422. $pf = common::check_input($pf[0]) . "(" . $vv["ctnr"] . ")";
  423. $dt = explode("\r\n", $vv["deliveryto_exp"]);
  424. $dt = common::check_input($dt[0]) . "(" . $vv["ctnr"] . ")";
  425. }
  426. if ($vv["type"] == "26" && !empty($ll[1])) {
  427. if (!empty($sql)) {
  428. $sql .= " union ";
  429. }
  430. $sql .= "select '" . $ll[1] . "' as lng, '" . $ll[0] . "' as lat, '" . $vv["ctnr"] . "' as uncode, 'Pick up: " . $vv["utime"] . "<br>'||'" . $pf . "' as location_namewo, 'pickup' as type";
  431. } elseif ($vv["type"] == "25" && !empty($ll[1])) {
  432. if (!empty($sql)) {
  433. $sql .= " union ";
  434. }
  435. $sql .= "select '" . $ll[1] . "' as lng, '" . $ll[0] . "' as lat, '" . $vv["ctnr"] . "' as uncode, 'Delivery: " . $vv["utime"] . "<br>'||'" . $dt . "' as location_namewo, 'delivery' as type";
  436. }
  437. }
  438. if (!empty($sql)) {
  439. $gps = common::excuteListSql($sql . "");
  440. }
  441. if (!empty($serial_no)) {
  442. $all = explode(",", $serial_no);
  443. foreach ($all as $a) {
  444. $rs = common::excuteOneSql("select public.get_vessel_position('$a'::text)");
  445. if (!empty($rs)) {
  446. $rss = explode("|", $rs);
  447. $lng_lat = explode(",", $rss[1]);
  448. $gps[] = array("lng" => $lng_lat[0], "lat" => $lng_lat[1], "uncode" => "", "location_namewo" => "", "type" => "vessel", "vessel_name" => $rss[2], "m_shipname" => "", "mmsi" => "", "imo" => "", "m_shipstate" => "", "m_shiptype" => "", "m_dest" => "", "m_newshiparrive" => "", "m_newlasttime" => "", "lasttime" => "", "sub" => "");
  449. }
  450. }
  451. }
  452. $data = array("gps" => $gps);
  453. common::echo_json_encode("200", $data);
  454. exit();
  455. break;
  456. case 'main_map_new':
  457. include ONLINE_ROOT . 'libs' . DS . 'map_config.ini.php';
  458. //修改添加port_of_transshipment 和port_of_transshipment_name的坐标获取(有为空的可能)
  459. $serial_no = $_REQUEST["serial_no"];
  460. $_schemas = $_REQUEST['_schemas'];
  461. if(empty($_schemas)){
  462. $_schemas ="public";
  463. }
  464. //$serial_no = "F41E6016-1A97-4C93-8198-53D8B3B26220";
  465. $transport_mode = common::excuteOneSql("SELECT transport_mode FROM public.kln_ocean ko
  466. WHERE ko.serial_no = '$serial_no' and order_from = '$_schemas'");
  467. if($transport_mode == "sea"){
  468. $sql = "with ss as (select '$serial_no' as sn)
  469. , aa as (
  470. select place_of_receipt_un, place_of_delivery_un, fport_of_loading_un, mport_of_discharge_un, port_of_loading, port_of_discharge, place_of_delivery_exp, place_of_receipt_exp,dd.*
  471. from public.kln_ocean oo
  472. left join LATERAL (
  473. select (select uncode from ports where code = o.port_of_transshipment) as port_of_transshipment_un,
  474. port_of_transshipment_name
  475. from $_schemas.ocean o where o.serial_no=oo.serial_no order by id desc limit 1
  476. ) dd on true
  477. where serial_no=(select sn from ss) limit 1
  478. )
  479. , rr as (
  480. select lon as lng, lat as lat, 'Origin' as label, port_of_loading as infor, 1 as sort, null::timestamp without time zone as stime, 'pol'::text as ptype
  481. from vessel.vt_unlocode, aa where (lat<=90 and lat>=-90) and (lon<=180 and lon>=-180) and lon is not null and lat is not null and uncode=fport_of_loading_un
  482. union all
  483. select lon as lng, lat as lat, 'Destination' as label, port_of_discharge as infor, 2 as sort, null::timestamp without time zone as stime, 'pod'::text as ptype
  484. from vessel.vt_unlocode, aa where (lat<=90 and lat>=-90) and (lon<=180 and lon>=-180) and lon is not null and lat is not null and uncode=mport_of_discharge_un
  485. union all
  486. select lon as lng, lat as lat, 'Transfer' as label, port_of_transshipment_name as infor, 3 as sort, null::timestamp without time zone as stime, 'poe'::text as ptype
  487. from vessel.vt_unlocode, aa where (lat<=90 and lat>=-90) and (lon<=180 and lon>=-180) and lon is not null and lat is not null and uncode=port_of_transshipment_un
  488. )
  489. select * from rr order by sort, stime";
  490. } elseif ($transport_mode == "air"){
  491. $sql = "with ss as (select '$serial_no' as sn)
  492. , aa as (
  493. select place_of_receipt_un, place_of_delivery_un, fport_of_loading_un, mport_of_discharge_un, port_of_loading, port_of_discharge, place_of_delivery_exp, place_of_receipt_exp
  494. from public.kln_ocean oo
  495. where serial_no=(select sn from ss) limit 1
  496. )
  497. , rr as (
  498. select lon as lng, lat as lat, 'Origin' as label, port_of_loading as infor, 1 as sort, null::timestamp without time zone as stime, 'pol'::text as ptype
  499. from vessel.vt_unlocode, aa where (lat<=90 and lat>=-90) and (lon<=180 and lon>=-180) and lon is not null and lat is not null and uncode=fport_of_loading_un
  500. union all
  501. select lon as lng, lat as lat, 'Destination' as label, port_of_discharge as infor, 2 as sort, null::timestamp without time zone as stime, 'pod'::text as ptype
  502. from vessel.vt_unlocode, aa where (lat<=90 and lat>=-90) and (lon<=180 and lon>=-180) and lon is not null and lat is not null and uncode=mport_of_discharge_un
  503. )
  504. select * from rr order by sort, stime";
  505. }
  506. $rss = common::excuteListSql($sql);
  507. //$rss = $mapdb->GetAll($sql);
  508. //先固定死
  509. // $json = '[{"lng":"100.78594000","lat":"13.68521000","label":"Origin","infor":"LAT KRABANG, THAILAND","sort":"0","stime":null,"ptype":"por"},
  510. // {"lng":"100.88333333","lat":"13.08333333","label":"Destination","infor":"LAEM CHABANG PORT,THAILAND","sort":"1","stime":null,"ptype":"pol"},
  511. // {"lng":"-122.28640000","lat":"37.79784000","label":"Transfer","infor":"OAKLAND, CA, USA","sort":"2","stime":null,"ptype":"pod"}]';
  512. //$rss = json_decode($json,true);
  513. ///global $mapdb;
  514. //查询线(包含所有的线) 空运不查询航线
  515. if ($transport_mode == "air"){
  516. $Line =array();
  517. }else{
  518. error_log("select * from get_track_data('$serial_no',true)");
  519. $map_sql = "select * from get_track_data('$serial_no',true)";
  520. $Line = $mapdb->GetAll($map_sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $map_sql), 0));
  521. }
  522. $solidLine = array();
  523. $dottedLine = array();
  524. $rangePoint = array();
  525. foreach($Line as $line){
  526. if($line['tp'] == "1"){
  527. $solidLine[] = $line;
  528. }elseif($line['tp'] == "0"){
  529. $dottedLine[] = $line;
  530. }else{
  531. $rangePoint[] = $line;
  532. }
  533. }
  534. //如果没有虚线,这这个范围点也是异常的,不需要显示
  535. if(empty($dottedLine)){
  536. $rangePoint = array();
  537. }
  538. $data = array("point"=>$rss,"solidLine"=>$solidLine,"dottedLine"=>$dottedLine,"rangePoint"=>$rangePoint);
  539. common::echo_json_encode(200, $data);
  540. //common::echo_json_encode(200, $rss);
  541. exit();
  542. break;
  543. case 'main_welcome':
  544. //分担查询
  545. include ONLINE_ROOT . 'libs' . DS . 'map_config.ini.php';
  546. $cp = common::check_input($_POST ['cp']); //current_page
  547. $ps = common::check_input($_POST ['ps']); //ps
  548. if (empty($ps))
  549. $ps = 10;
  550. $sqlWhere = ' where ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  551. $sqlWhere .= common::getDashboardTransportationSqlWhere();
  552. // test dome
  553. // $_POST['is_default'] = "no";
  554. // $_POST['date_start'] =null;
  555. // $_POST['date_end'] = null;
  556. //默认初始条件:ALL& ETD& Current Month 当前月的1号到最后一天 这个默认条件已经废除,前端不会这样传参数
  557. if (isset($_POST['is_default']) && strtolower($_POST['is_default']) == "yes" && false){
  558. $sqlWhere .= "and etd>='" . date("Y-m") . "-01' and etd<='" . date("Y-m") . "-01'::date + interval '1 month'";
  559. } else {
  560. $date_type = strtolower(common::check_input($_POST ['date_type']));
  561. if (isset($_POST['date_start']) && !empty($_POST['date_start']))
  562. $sqlWhere .= " and $date_type >= '" . common::usDate2sqlDate($_POST['date_start']) . " 00:00:00'";
  563. if (isset($_POST['date_end']) && !empty($_POST['date_end']))
  564. $sqlWhere .= " and $date_type <= '" . common::usDate2sqlDate($_POST['date_end']) . " 23:59:59'";
  565. }
  566. if (isset($_POST['customer']) && !empty($_POST['customer'])){
  567. $sqlWhere .= " and (shipper ilike '%".common::check_input($_POST['customer'])."%' or shipper_id ilike '%".common::check_input($_POST['customer'])."%'
  568. or consignee ilike '%".common::check_input($_POST['customer'])."%' or consignee_id ilike '%".common::check_input($_POST['customer'])."%')";
  569. }
  570. $rc = $_POST ['rc'];
  571. if ($rc == - 1) {
  572. $sql = "SELECT count(1) from public.kln_ocean" . $sqlWhere;
  573. //$rc = common::excuteOneSql($sql);
  574. $rc = $mapdb->GetOne($sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $sql), 0));
  575. }
  576. $tp = ceil($rc / $ps);
  577. if ($rc > 0) {
  578. $sql = "SELECT order_from as _schemas,serial_no, consignee, shipper, h_bol,final_desination_uncode, transport_mode,
  579. to_char(etd, 'MM/DD/YYYY'::text) as etd,
  580. to_char(eta, 'MM/DD/YYYY'::text) AS eta,
  581. fport_of_loading_un, mport_of_discharge_un, place_of_receipt_un, place_of_delivery_un, booking_no,
  582. f_vessel,f_voyage,origin,
  583. CASE
  584. WHEN ((m_iffbcf is not null or m_iffbcf is null) and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Created'::text
  585. WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Cargo Received'::text
  586. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
  587. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  588. WHEN (m_iffdel is not null) THEN 'Completed'::text
  589. ELSE 'Created'::text
  590. END AS new_status
  591. FROM public.kln_ocean $sqlWhere";
  592. //$sqlWhere and last_status_315_update_time is not null";
  593. $sql .= " ORDER BY eta desc,id DESC limit " . $ps . " offset " . ($cp - 1) * $ps;
  594. //$sql .= " ORDER BY last_status_315_update_time DESC limit " . $ps . " offset " . ($cp - 1) * $ps;
  595. //$rss = common::excuteListSql($sql);
  596. $rss = $mapdb->GetAll($sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $sql), 0));
  597. //RecentStatusList
  598. $RecentStatusList = array();
  599. foreach ($rss as $key => $value) {
  600. $serial_no = $value["serial_no"];
  601. $_schemas_bk = $value['_schemas'];
  602. $_schemas = $value['_schemas'];
  603. if($_schemas == "public"){
  604. $_schemas = "ocean";
  605. }
  606. //单独取查询milestone信息
  607. if ($value['transport_mode'] == "sea"){
  608. $milestone_sql = "select a.act_date,a.act_time,sn.description,a.timezone,
  609. a.code as dd_code
  610. from public.ocean_milestone a
  611. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'sea'
  612. where a.serial_no='$serial_no'
  613. and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFDEL', ','))
  614. and a.act_date is not null
  615. order by sn.sno desc limit 1";
  616. } elseif ($value['transport_mode'] == "air"){
  617. //air milestone 的Departed实际描述要替换: IFFDEP =》 IFFONB
  618. $milestone_sql = "select a.act_date,a.act_time,sn.description,a.timezone,
  619. a.code as dd_code
  620. from $_schemas_bk.air_milestone a
  621. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
  622. where a.serial_no='$serial_no'
  623. and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFONB,IFFARR,IFFDEL', ','))
  624. and a.act_date is not null
  625. order by sn.sno desc limit 1";
  626. }
  627. $milestone = common::excuteObjectSql($milestone_sql);
  628. $value["act_date"] = $milestone["act_date"];
  629. $value["act_time"] = $milestone["act_time"];
  630. $value["description"] = $milestone["description"];
  631. $value["timezone"] = $milestone["timezone"];
  632. $value["dd_code"] = $milestone["dd_code"];
  633. $timezone = "";
  634. //按照最新execl Timezone From 来自于origin
  635. if($value['dd_code'] == "IFFBCF" || $value['dd_code'] == "IFFCPU"){
  636. $sql = "SELECT (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'')) as timezone
  637. FROM $_schemas.contacts c WHERE c.contact_id = '".$value['origin']."'";
  638. $timezone = common::excuteOneSql($sql);
  639. }
  640. //按照最新execl Timezone From 来自于final_destination
  641. if($value['dd_code'] == "IFFDEL"){
  642. $sql = "select time_zone from public.city_timezone where uncode = '".$value['final_desination_uncode']."'";
  643. $timezone = common::excuteOneSql($sql);
  644. }
  645. if($value['dd_code'] == "IFFREC" || $value['dd_code'] == "IFFDEP" || $value['dd_code'] == "IFFARR"){
  646. $EDI315Time = array();
  647. if ($value['transport_mode'] == "sea"){
  648. //Timezone From 来自于EDI315
  649. $EDI315Time = common::getEDI315Time($serial_no,$value['_schemas']);
  650. }
  651. if($value['dd_code'] == "IFFREC" || $value['dd_code'] == "IFFDEP"){
  652. //先以EDI315 时区为准,如果没有这代表数据是手动输入,或者没有同步情况
  653. $timezone = $EDI315Time[$value['dd_code']]['timezone'];
  654. if(empty($timezone)){
  655. if($value['dd_code'] == "IFFREC"){
  656. $sql = "select time_zone from public.city_timezone where uncode = '".$value['place_of_receipt_un']."'";
  657. }else{
  658. $sql = "select time_zone from public.city_timezone where uncode = '".$value['fport_of_loading_un']."'";
  659. }
  660. $timezone = common::excuteOneSql($sql);
  661. }
  662. }
  663. if($value['dd_code'] == "IFFARR"){
  664. $timezone = $EDI315Time[$value['dd_code']]['timezone'];
  665. if(empty($timezone)){
  666. $sql = "select time_zone from public.city_timezone where uncode = '".$value['mport_of_discharge_un']."'";
  667. $timezone = common::excuteOneSql($sql);
  668. }
  669. }
  670. }
  671. $Arrived = $value['description'];
  672. $startStation=$value['fport_of_loading_un'];
  673. $endStation=$value['mport_of_discharge_un'];
  674. if ($value['transport_mode'] == "sea"){
  675. $startStation=$value['place_of_receipt_un'];
  676. $endStation=$value['place_of_delivery_un'];
  677. }
  678. if ($value['transport_mode'] == "air"){
  679. $startStation=!empty($ocean['place_of_receipt_un'])? $ocean['place_of_receipt_un'] : $ocean['fport_of_loading_un'];
  680. $endStation=!empty($ocean['place_of_delivery_un']) ? $ocean['place_of_delivery_un'] : $ocean['mport_of_discharge_un'];
  681. }
  682. $RecentStatusList[] = array("Title"=>$value['h_bol'],
  683. "name"=>utils::outDisplayForMerge($value['f_vessel'],$value['f_voyage']),
  684. "bookingNumber" =>$value['booking_no'],
  685. "IsSubscribe" =>false,
  686. "shipperName"=>$value['shipper'],
  687. "consigneeName" =>$value['consignee'],
  688. "startStation"=>$startStation,
  689. "endStation"=>$endStation,
  690. "ETD"=>$value['etd'],
  691. "ETA"=>$value['eta'],
  692. "type"=>$value['new_status'],
  693. "Arrived"=>$Arrived,
  694. "Time"=>$value["act_date"],
  695. "act_time" =>$value["act_time"],
  696. "timezone"=>$timezone,
  697. "_schemas"=>$value["_schemas"],
  698. "transport_mode"=>$value["transport_mode"],
  699. 'is_subscribe' =>common::checkedSubscribe($value['serial_no']),
  700. "a" =>common::deCode($value['serial_no'], 'E'));
  701. }
  702. $data = common::getManagement();
  703. $arrTmp = array('searchData' => $RecentStatusList,
  704. 'Management' => $data['Management'],
  705. 'dashboard_filter' => $data['dashboard_filter'],
  706. 'is_customer' =>_isCustomerLogin(),
  707. 'rc' => $rc,
  708. 'ps' => $ps,
  709. 'cp' => $cp,
  710. 'tp' => $tp);
  711. } else {
  712. $data = common::getManagement();
  713. $arrTmp = array('searchData' => array(),
  714. 'Management' => $data['Management'],
  715. 'dashboard_filter' => $data['dashboard_filter']);
  716. }
  717. common::echo_json_encode(200,$arrTmp);
  718. exit();
  719. break;
  720. case 'save_layout':
  721. $management = json_encode($_POST["management"]);
  722. $dashboard_filter = json_encode($_POST["dashboardObj"]);
  723. $_param = "";
  724. if(!empty($_POST["management"])){
  725. $_param .= " management = '$management' ";
  726. }
  727. if(isset($_POST["dashboardObj"]) && !empty($dashboard_filter)){
  728. $_param .= ",dashboard_filter = '$dashboard_filter' ";
  729. }
  730. if(!empty($_param)){
  731. common::excuteUpdateSql("update public.ra_online_user set $_param where lower(user_login) = '" . strtolower(_getLoginName()) . "'");
  732. }
  733. $returnData = array("msg" => "success");
  734. common::echo_json_encode(200, $returnData);
  735. exit();
  736. break;
  737. case 'password':
  738. tools::getInstance()->updatePassword();
  739. break;
  740. case 'tools':
  741. tools::getInstance()->markSystem();
  742. break;
  743. case 'robot':
  744. robot::getInstance()->robot_prompt_configuration();
  745. break;
  746. case 'robot_chat':
  747. robot::getInstance()->ai_chat();
  748. break;
  749. case 'system_setting':
  750. tools::getInstance()->user_system_setting();
  751. break;
  752. case 'monitoring_setting':
  753. tools::getInstance()->user_monitoring_setting();
  754. break;
  755. case 'notifications_rules':
  756. tools::getInstance()->notifications_rules();
  757. break;
  758. case 'user_guide':
  759. $rootPath = realpath(dirname(__FILE__)) . DS;
  760. //common::download_file($rootPath."images\ACE-M1_ISF_ACI_User_Guide\ACE-M1_ISF_ACI_User_Guide.pdf", "ACE-M1_ISF_ACI_User_Guide_V2.0.pdf");
  761. // PDF文件在服务器上的位置
  762. $filename = $rootPath."userFile". DS."KLN_Online_User_Guide_24.11.26.pdf";
  763. $display_name = "KLN_Online_User_Guide_24_11_26.pdf";
  764. // Header content type
  765. header("Content-type: application/pdf");
  766. header("Content-Length: " . filesize($filename));
  767. header("Content-Disposition:attachment;filename=\"" . $display_name . "\"");
  768. // 将文件发送到浏览器。
  769. readfile($filename);
  770. break;
  771. case 'feature_update':
  772. $id = $_REQUEST["id"];
  773. $rootPath = realpath(dirname(__FILE__)) . DS;
  774. //common::download_file($rootPath."images\ACE-M1_ISF_ACI_User_Guide\ACE-M1_ISF_ACI_User_Guide.pdf", "ACE-M1_ISF_ACI_User_Guide_V2.0.pdf");
  775. // PDF文件在服务器上的位置
  776. $filename = $rootPath."upload". DS."feature_update_".$id.".pdf";
  777. $display_name = "feature_update.pdf";
  778. // Header content type
  779. header("Content-type: application/pdf");
  780. header("Content-Length: " . filesize($filename));
  781. header("Content-Disposition:inline;filename=\"" . $display_name . "\"");
  782. // 将文件发送到浏览器。
  783. readfile($filename);
  784. break;
  785. default:
  786. $data = array(
  787. 'msg' => 'Page not found',
  788. );
  789. common::echo_json_encode(500, $data);
  790. }
  791. $db->Close();
  792. $db = null;
  793. if ($max_ec > 0)
  794. ini_set('max_execution_time', $max_ec); //recover old value
  795. if (!empty($memory_limit))
  796. ini_set('memory_limit', $memory_limit);
  797. ?>