ajax.class.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. <?php
  2. if (!defined('IN_ONLINE')) {
  3. exit('Access Denied');
  4. }
  5. /**
  6. * Description of auto
  7. *
  8. * @author Administrator
  9. */
  10. class ajax {
  11. private static $_ajax;
  12. public static function getInstance() {
  13. if (!self::$_ajax) {
  14. $c = __CLASS__;
  15. self::$_ajax = new $c;
  16. }
  17. return self::$_ajax;
  18. }
  19. public function run() {
  20. $time = time() - $_SESSION["LAST_OPERATE_TIME"];
  21. if ($time > $_SESSION['SESSION_TIMEOUT']) {
  22. exit(json_encode("session_time_out"));
  23. } else {
  24. $_SESSION["LAST_OPERATE_TIME"] = time();
  25. }
  26. $operate = utils::_get('operate');
  27. $operate = strtolower($operate);
  28. switch ($operate) {
  29. case 'save_setting_display':
  30. $this->save_setting_display();
  31. break;
  32. case 'autody':
  33. return json_encode($this->autody());
  34. break;
  35. case 'autoport':
  36. return json_encode($this->autoPort());
  37. break;
  38. default :
  39. break;
  40. }
  41. }
  42. public function save_setting_display() {
  43. $ids = $_POST['ids'];
  44. if(!empty($ids)){
  45. $ss = utils::implode(",", $_POST['ids']);
  46. column::getInstance()->saveSettingDisplay(utils::implode(",", $_POST['ids']),"", $_POST['model_name']);
  47. $data = array(
  48. 'msg' => 'success'
  49. );
  50. common::echo_json_encode(200,$data);
  51. }else{
  52. $data = array(
  53. 'msg' => 'data error'
  54. );
  55. common::echo_json_encode(500,$data);
  56. }
  57. }
  58. //不查询全局的信息,查询该用户,最近3个月内输入过的信息自动补全
  59. public function autody(){
  60. $term = $_POST['term'];
  61. $type = $_POST['type'];
  62. $search_field = $_POST['search_field'];
  63. $search_mode = $_POST['search_mode'];
  64. $term = trim($term);
  65. if (strtolower($type) == "apex" || strtolower($type) == "contanct" || strtolower($type) == "sales"
  66. || strtolower($type) == "vessel" || strtolower($type) == "voyage") {
  67. if($search_mode == "tracking"){
  68. $sqlWhere = $this->getTrackingSearchWhere();
  69. }elseif($search_mode == "booking"){
  70. $sqlWhere = $this->getBookingSearchWhere();
  71. }
  72. //Notify Party Bill to Destination Operator 是tracking里的,但booking没有,所以不影响
  73. $search_field_mapping = array("Origin Agent"=>"origin as code",
  74. "Destination Agent"=>"agent as code",
  75. "Shipper Name"=>"shipper as code",
  76. "Consignee Name"=>"consignee as code",
  77. "Notify Party" =>"notify_party as code",
  78. "Bill to" =>"billto as code",
  79. "Destination Operator"=>"dest_op as code",
  80. "Sales"=>"sales_rep as code",
  81. "Voyage/Flight_booking"=>"f_voyage as code,m_voyage as code_2",
  82. "Vessel_booking"=>"f_vessel as code,m_vessel as code_2",
  83. "Voyage/Flight_tracking"=>"voyage as code,f_voyage as code_2",
  84. "Vessel_tracking"=>"vessel as code,f_vessel as code_2");
  85. $sql_where_mapping = array("Origin Agent"=>" and (origin ilike '%" . common::check_input($term) . "%')",
  86. "Destination Agent"=>" and (agent ilike '%" . common::check_input($term) . "%')",
  87. "Shipper Name"=>" and (shipper ilike '%" . common::check_input($term) . "%')",
  88. "Consignee Name"=>" and (consignee ilike '%" . common::check_input($term) . "%')",
  89. "Notify Party"=>" and (notify_party ilike 'v" . common::check_input($term) . "%')",
  90. "Bill to"=>" and (billto ilike '%" . common::check_input($term) . "%')",
  91. "Destination Operator"=>" and (dest_op ilike '%" . common::check_input($term) . "%')",
  92. "Sales"=>" and (sales_rep ilike '%" . common::check_input($term) . "%')",
  93. "Voyage/Flight_booking"=>" and (f_voyage ilike '%" . common::check_input($term) . "%' or m_voyage ilike '%" . common::check_input($term) . "%')",
  94. "Vessel_booking"=>" and (f_vessel ilike '%" . common::check_input($term) . "%' or m_vessel ilike '%" . common::check_input($term) . "%')",
  95. "Voyage/Flight_tracking"=>" and (voyage ilike '%" . common::check_input($term) . "%' or f_voyage ilike '%" . common::check_input($term) . "%')",
  96. "Vessel_tracking"=>" and (vessel ilike '%" . common::check_input($term) . "%' or f_vessel ilike '%" . common::check_input($term) . "%')");
  97. //特殊处理一下合并Voyage和Vessel
  98. $_search_field = $search_field;
  99. if ($search_field == "Voyage/Flight" || $search_field == "Vessel"){
  100. $_str = $search_mode == "tracking" ? "tracking" : "booking";
  101. $_search_field = $search_field ."_".$_str;
  102. }
  103. $str = $search_field_mapping[$_search_field];
  104. $sql_where = $sql_where_mapping[$_search_field];
  105. $table = $search_mode == "tracking" ? "public.online_ocean " : "public.online_booking ";
  106. if($search_mode == "booking"){
  107. $order_by = " f_etd desc NULLS LAST";
  108. }else{
  109. $order_by = " etd desc NULLS LAST";
  110. if (_isCustomerLogin()) {
  111. $order_by = " eta desc NULLS LAST";
  112. }
  113. }
  114. $sql = "select DISTINCT * from (select $str from $table $sqlWhere $sql_where order by $order_by ) as temp";
  115. $sql .= " order by code limit 20";
  116. error_log($sql);
  117. $rs = common::excuteListSql($sql);
  118. }
  119. $rs = common::excuteListSql($sql);
  120. $array = array();
  121. foreach($rs as $v){
  122. if(!empty($v['code'])){
  123. $array[] = $v['code'];
  124. }
  125. if ($search_field == "Voyage/Flight" || $search_field == "Vessel"){
  126. $array[] = $v['code_2'];
  127. }
  128. }
  129. $array = utils::removeDuplicateArray($array);
  130. common::echo_json_encode(200,$array);
  131. exit();
  132. }
  133. public function autoPort() {
  134. $cp = common::check_input($_POST ['cp']); //current_page
  135. $ps = common::check_input($_POST ['ps']); //ps
  136. if (empty($ps))
  137. $ps = 20;
  138. $term = $_POST['term'];
  139. $term = trim($term);
  140. $search_field = $_POST['search_field'];
  141. $search_mode = $_POST['search_mode'];
  142. $_sql_arr = $this->getPortsUncity($search_field,$search_mode,$term);
  143. $rc = $_POST ['rc'];
  144. if ($rc == - 1) {
  145. $sql = $_sql_arr['count_sql'];
  146. $rc = common::excuteOneSql($sql);
  147. error_log($sql);
  148. }
  149. $tp = ceil($rc / $ps);
  150. if ($rc > 0) {
  151. $sql = $_sql_arr['sql'];
  152. $sql = "select DISTINCT ON (city) country, city,uncode from ($sql) as temp ";
  153. $sql .= " limit " . $ps . " offset " . ($cp - 1) * $ps;
  154. $rs = common::excuteListSql($sql);
  155. error_log($sql);
  156. //前端要加上id 从1开始
  157. $retData = array();
  158. $i = 0;
  159. foreach($rs as $key => $val){
  160. if($search_field == "Port of Loading"){
  161. if(!empty($val['uncode'])){
  162. $val["id"] = $i +1;
  163. $retData[] = $val;
  164. $i = $i +1;
  165. }
  166. }else{
  167. if(!empty($val['city'])){
  168. $val["id"] = $i +1;
  169. $retData[] = $val;
  170. $i = $i +1;
  171. }
  172. }
  173. }
  174. $arrTmp = array('searchData' => $retData,
  175. 'rc' => $rc,
  176. 'ps' => $ps,
  177. 'cp' => $cp,
  178. 'tp' => $tp);
  179. common::echo_json_encode(200,$arrTmp);
  180. exit();
  181. }else{
  182. $arrTmp = array('searchData' => array(), 'rc' => 0);
  183. common::echo_json_encode(200, $arrTmp);
  184. exit();
  185. }
  186. }
  187. public function autoPort_old() {
  188. $cp = common::check_input($_POST ['cp']); //current_page
  189. $ps = common::check_input($_POST ['ps']); //ps
  190. if (empty($ps))
  191. $ps = 20;
  192. $term = $_POST['term'];
  193. $term = trim($term);
  194. $_curr_schemas = $_POST['model'];
  195. if (empty($_curr_schemas)) {
  196. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  197. if (empty($_curr_schemas)) {
  198. $_curr_schemas = "public";
  199. }
  200. }
  201. $rc = $_POST ['rc'];
  202. if ($rc == - 1) {
  203. $sql = "SELECT count(1) from $_curr_schemas.ports where (isoname ilike '" . common::check_input($term) . "%'
  204. or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%')";
  205. $rc = common::excuteOneSql($sql);
  206. }
  207. $tp = ceil($rc / $ps);
  208. if ($rc > 0) {
  209. $sql = "SELECT isoname as country, uncity as city,uncode from $_curr_schemas.ports where (isoname ilike '" . common::check_input($term) . "%'
  210. or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%')";
  211. $sql .= " order by code limit " . $ps . " offset " . ($cp - 1) * $ps;
  212. $rs = common::excuteListSql($sql);
  213. //前端要加上id 从1开始
  214. $retData = array();
  215. foreach($rs as $key => $val){
  216. if(!empty($val['country'])){
  217. $val["id"] = $key +1;
  218. $retData[] = $val;
  219. }
  220. }
  221. $arrTmp = array('searchData' => $retData,
  222. 'rc' => $rc,
  223. 'ps' => $ps,
  224. 'cp' => $cp,
  225. 'tp' => $tp);
  226. common::echo_json_encode(200,$arrTmp);
  227. exit();
  228. }else{
  229. $arrTmp = array('searchData' => array());
  230. common::echo_json_encode(200, $arrTmp);
  231. exit();
  232. }
  233. }
  234. public function autody_old() {
  235. $term = $_POST['term'];
  236. $type = $_POST['type'];
  237. $term = trim($term);
  238. if (strtolower($type) == "apex") {
  239. $_curr_schemas = $_POST['model'];
  240. if (empty($_curr_schemas)) {
  241. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  242. if (empty($_curr_schemas)) {
  243. $_curr_schemas = "public";
  244. }
  245. }
  246. if ($_curr_schemas == "public") {
  247. $sql = "select contact_id as code from ocean.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))"
  248. . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) "
  249. . "and active=true and coalesce(hblcode, '')<>'' and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
  250. } else {
  251. $sql = "select contact_id as code from $_curr_schemas.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))"
  252. . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) "
  253. . "and active=true and coalesce(hblcode, '')<>'' and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
  254. }
  255. $sql .= " order by contact_id limit 20";
  256. $rs = common::excuteListSql($sql);
  257. }
  258. //Shipper 和Consignee 的查询,但是表contact_v ,从ocean和air. 如果不做区分的话,可以上面的apex的Origin Agent/Destination Agent,合并
  259. if (strtolower($type) == "contanct") {
  260. $sql = "SELECT company as code from contact_v where active = true and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
  261. $sql .= " order by contact_id limit 20";
  262. $rs = common::excuteListSql($sql);
  263. }
  264. if (strtolower($type) == "sales") {
  265. $_curr_schemas = $_POST['model'];
  266. if (empty($_curr_schemas)) {
  267. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  268. if (empty($_curr_schemas)) {
  269. $_curr_schemas = "public";
  270. }
  271. }
  272. $sql = "SELECT salesopcode as code from $_curr_schemas.employee where salesopcode is not null and salesopcode !='' and (salesopcode ilike '" . common::check_input($term) . "%' or employee_id ilike '" . common::check_input($term) . "%')";
  273. $sql .= " order by salesopcode limit 20";
  274. }
  275. if (strtolower($type) == "vessel") {
  276. $vessel = $_POST['vessel'];
  277. $sql = "SELECT carrier, vessel as code, flag from vessel_infor where vessel ilike '" . common::check_input($vessel) . "%'";
  278. $sql .= " order by vessel limit 20";
  279. }
  280. $rs = common::excuteListSql($sql);
  281. $array = array();
  282. foreach($rs as $v){
  283. if(!empty($v['code'])){
  284. $array[] = $v['code'];
  285. }
  286. }
  287. common::echo_json_encode(200,$array);
  288. exit();
  289. }
  290. public function getTrackingSearchWhere(){
  291. $sqlWhere = ' where ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  292. $sqlWhere .= search::getInstance()->getSearchSQL("Ocean_Search");
  293. if (!empty($_REQUEST["_reportRef"])) {
  294. $_reportType = $_REQUEST["_reportType"];
  295. $_reportRef = $_REQUEST["_reportRef"];
  296. if ($_reportType == "r3") {
  297. if ($_reportRef == "Previous 7 Days") {
  298. $sqlWhere .= " and eta>(current_date-interval '7 days') and eta<current_date";
  299. } else if ($_reportRef == "0 Day") {
  300. $sqlWhere .= " and eta=current_date";
  301. } else if ($_reportRef == "1-2 Days") {
  302. $sqlWhere .= " and eta>current_date and eta<=(current_date+interval '2 days')";
  303. } else if ($_reportRef == "3-6 Days") {
  304. $sqlWhere .= " and eta>(current_date+interval '2 days') and eta<=(current_date+interval '6 days')";
  305. } else if ($_reportRef == "7 Days") {
  306. $sqlWhere .= " and eta>(current_date+interval '6 days')";
  307. } else {
  308. $sqlWhere .= " and 1<>1";
  309. }
  310. } else if ($_reportType == "r4") {
  311. if ($_reportRef == "Previous 7 Days") {
  312. $sqlWhere .= " and etd>(current_date-interval '7 days') and etd<current_date";
  313. } else if ($_reportRef == "0 Day") {
  314. $sqlWhere .= " and etd=current_date";
  315. } else if ($_reportRef == "1-2 Days") {
  316. $sqlWhere .= " and etd>current_date and etd<=(current_date+interval '2 days')";
  317. } else if ($_reportRef == "3-6 Days") {
  318. $sqlWhere .= " and etd>(current_date+interval '2 days') and etd<=(current_date+interval '6 days')";
  319. } else if ($_reportRef == "7 Days") {
  320. $sqlWhere .= " and etd>(current_date+interval '6 days')";
  321. } else {
  322. $sqlWhere .= " and 1<>1";
  323. }
  324. } else if ($_reportType == "ata_r3") {
  325. if ($_reportRef == "0 Day") {
  326. $sqlWhere .= " and ata >= etd and (ata-etd) >= 0 and (ata-etd) < 1";
  327. } else if ($_reportRef == "1-2 Days") {
  328. $sqlWhere .= " and ata >= etd and (ata-etd) >= 1 and (ata-etd) < 2";
  329. } else if ($_reportRef == "3-6 Days") {
  330. $sqlWhere .= " and ata >= etd and (ata-etd) >= 2 and (ata-etd) < 6";
  331. } else if ($_reportRef == "7 Days") {
  332. $sqlWhere .= " and ata >= etd and (ata-etd) >= 6";
  333. } else {
  334. $sqlWhere .= " and 1<>1";
  335. }
  336. } else if ($_reportType == "atd_r4") {
  337. if ($_reportRef == "0 Day") {
  338. $sqlWhere .= " and atd >= etd and (atd-etd) >= 0 and (atd-etd) < 1";
  339. } else if ($_reportRef == "1-2 Days") {
  340. $sqlWhere .= " and atd >= etd and (atd-etd) >= 1 and (atd-etd) < 2";
  341. } else if ($_reportRef == "3-6 Days") {
  342. $sqlWhere .= " and atd >= etd and (atd-etd) >= 2 and (atd-etd) < 6";
  343. } else if ($_reportRef == "7 Days") {
  344. $sqlWhere .= " and atd >= etd and (atd-etd) >= 6 ";
  345. } else {
  346. $sqlWhere .= " and 1<>1";
  347. }
  348. } else if ($_reportType == "top") {
  349. if (!empty($_reportRef)) {
  350. $_reportStationType = $_REQUEST["_reportStationType"];
  351. if($_reportStationType == 'shippr_uncode'){
  352. $sqlWhere = " and shippr_uncode = '$_reportRef'";
  353. }
  354. if($_reportStationType == 'fport_of_loading_un'){
  355. $sqlWhere = " and fport_of_loading_un = '$_reportRef'";
  356. }
  357. if($_reportStationType == 'consignee_uncode'){
  358. $sqlWhere .= " and consignee_uncode = '$_reportRef'";
  359. }
  360. if($_reportStationType == 'mport_of_discharge_un'){
  361. $sqlWhere .= " and mport_of_discharge_un = '$_reportRef'";
  362. }
  363. } else {
  364. $sqlWhere .= " and 1<>1";
  365. }
  366. } else if ($_reportType == "co2e") {
  367. $_reportDataType = $_REQUEST["_reportDataType"];
  368. //查询sea 其他的为空
  369. if (!empty($_reportRef) && $_reportDataType == "sea") {
  370. $_reportStationType = $_REQUEST["_reportStationType"];
  371. if($_reportStationType == 'origin'){
  372. $sqlWhere .= " and shippr_uncode = '$_reportRef'";
  373. }else{
  374. $sqlWhere .= " and consignee_uncode = '$_reportRef'";
  375. }
  376. } else {
  377. $sqlWhere .= " and 1<>1";
  378. }
  379. } else {
  380. $_reportRef = explode("-", $_REQUEST["_reportRef"]);
  381. $_reportRefb_date = $_REQUEST["_reportRefb_date"];
  382. $bdate = common::excuteOneSql("select to_date('$_reportRefb_date','mm/YYYY')");
  383. $_reportRefe_date = $_REQUEST["_reportRefe_date"];
  384. $edate = common::excuteOneSql("select to_date('$_reportRefe_date','mm/YYYY') + interval '1 month' - interval '1 day'");
  385. //$sqlWhere .= " and eta>='$bdate' and eta<='$edate'";
  386. if ($_REQUEST["_reportRef"] == "Over 80 Days") {
  387. $sqlWhere .= " and (eta-etd)>80";
  388. } else {
  389. $sqlWhere .= " and (eta-etd)>" . $_reportRef[0] . " and (eta-etd)<=" . substr($_reportRef[1], 0, 2);
  390. }
  391. }
  392. }
  393. //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No.
  394. if (!empty($_POST["_textSearch"])) {
  395. $textSearch_arr = $_POST['_textSearch'];
  396. if(!is_array($textSearch_arr)){
  397. $textSearch_arr = array($textSearch_arr);
  398. }
  399. $more_sql = "1<>1";
  400. foreach($textSearch_arr as $tsv){
  401. $more_sql .= " or booking_no ilike '%" . common::check_input(trim($tsv)) . "%'";
  402. $more_sql .= " or h_bol ilike '%" . common::check_input(trim($tsv)) . "%'";
  403. $more_sql .= " or po_no ilike '%" . common::check_input(trim($tsv)) . "%'";
  404. $more_sql .= " or carrier_booking ilike '%" . common::check_input(trim($tsv)) . "%'";
  405. }
  406. if ($more_sql <> "1<>1"){
  407. $sqlWhere .= " and ($more_sql)";
  408. }
  409. }
  410. return $sqlWhere;
  411. }
  412. public function getBookingSearchWhere(){
  413. $sqlWhere = ' where ' . common::searchExtendHandNew("booking", $_SESSION["ONLINE_USER"]);
  414. $sqlWhere .= search::getInstance()->getSearchSQL("Booking_Search");
  415. //新版要排除type2情况,总数才会对的上
  416. $sqlWhere .= " and (not(bol_type != 'BOOKING' and booking_no is not null and booking_no <> ''))";
  417. //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No.
  418. if (!empty($_POST["_textSearch"])) {
  419. $textSearch_arr = $_POST['_textSearch'];
  420. if(!is_array($textSearch_arr)){
  421. $textSearch_arr = array($textSearch_arr);
  422. }
  423. $more_sql = "1<>1";
  424. foreach($textSearch_arr as $tsv){
  425. $more_sql .= " or booking_no ilike '%" . common::check_input(trim($tsv)) . "%'";
  426. $more_sql .= " or h_bol ilike '%" . common::check_input(trim($tsv)) . "%'";
  427. $more_sql .= " or po_no ilike '%" . common::check_input(trim($tsv)) . "%'";
  428. $more_sql .= " or carrier_booking ilike '%" . common::check_input(trim($tsv)) . "%'";
  429. }
  430. if ($more_sql <> "1<>1"){
  431. $sqlWhere .= " and ($more_sql)";
  432. }
  433. }
  434. return $sqlWhere;
  435. }
  436. PUBLIC function getPortsUncity($search_field,$search_mode,$term){
  437. //uncode 前两位便是 isoname,不用模糊查询这个了
  438. if($search_field == "Origin" && $search_mode == "booking"){
  439. $sqlWhere = $this->getBookingSearchWhere();
  440. $count_sql = "select COUNT(DISTINCT shipper_city)
  441. from public.online_booking $sqlWhere
  442. and COALESCE(shippr_uncode)<>''
  443. and (shipper_city ilike '%" . common::check_input($term) . "%'
  444. or shippr_uncode ilike '%" . common::check_input($term) . "%') ";
  445. $sql = "select left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode
  446. from public.online_booking $sqlWhere
  447. and COALESCE(shippr_uncode)<>''
  448. and (shipper_city ilike '%" . common::check_input($term) . "%'
  449. or shippr_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc NULLS LAST";
  450. return array("count_sql"=>$count_sql,"sql"=>$sql);
  451. }
  452. if($search_field == "Destination" && $search_mode == "booking"){
  453. $sqlWhere = $this->getBookingSearchWhere();
  454. $count_sql = "select count(DISTINCT consignee_city)
  455. from public.online_booking $sqlWhere
  456. and COALESCE(consignee_uncode)<>''
  457. and (consignee_city ilike '%" . common::check_input($term) . "%'
  458. or consignee_uncode ilike '%" . common::check_input($term) . "%') ";
  459. $sql = "select left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode
  460. from public.online_booking $sqlWhere
  461. and COALESCE(consignee_uncode)<>''
  462. and (consignee_city ilike '%" . common::check_input($term) . "%'
  463. or consignee_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc NULLS LAST";
  464. return array("count_sql"=>$count_sql,"sql"=>$sql);
  465. }
  466. if($search_field == "Place of Receipt" && $search_mode == "booking"){
  467. $sqlWhere = $this->getBookingSearchWhere();
  468. $count_sql = "select COUNT(DISTINCT place_of_receipt_exp)
  469. from public.online_booking $sqlWhere
  470. and COALESCE(place_of_receipt_uncode)<>''
  471. and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
  472. or place_of_receipt_uncode ilike '%" . common::check_input($term) . "%')";
  473. $sql = "select left(place_of_receipt_uncode, 2) as country,place_of_receipt_exp as city, place_of_receipt_uncode as uncode
  474. from public.online_booking $sqlWhere
  475. and COALESCE(place_of_receipt_uncode)<>''
  476. and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
  477. or place_of_receipt_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc NULLS LAST";
  478. return array("count_sql"=>$count_sql,"sql"=>$sql);
  479. }
  480. if($search_field == "Port of Loading" && $search_mode == "booking"){
  481. $sqlWhere = $this->getBookingSearchWhere();
  482. $count_sql = "select COUNT(DISTINCT fport_of_loading_exp)
  483. from public.online_booking $sqlWhere
  484. and COALESCE(fport_of_loading_uncode)<>''
  485. and (fport_of_loading_exp ilike '%" . common::check_input($term) . "%'
  486. or fport_of_loading_uncode ilike '%" . common::check_input($term) . "%')";
  487. $sql = "select left(fport_of_loading_uncode, 2) as country,fport_of_loading_exp as city, fport_of_loading_uncode as uncode
  488. from public.online_booking $sqlWhere
  489. and COALESCE(fport_of_loading_uncode)<>''
  490. and (fport_of_loading_exp ilike '%" . common::check_input($term) . "%'
  491. or fport_of_loading_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc NULLS LAST";
  492. return array("count_sql"=>$count_sql,"sql"=>$sql);
  493. }
  494. if($search_field == "Place of delivery" && $search_mode == "booking"){
  495. $sqlWhere = $this->getBookingSearchWhere();
  496. $count_sql = "select COUNT(DISTINCT place_of_delivery_exp)
  497. from public.online_booking $sqlWhere
  498. and COALESCE(place_of_delivery_uncode)<>''
  499. and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
  500. or place_of_delivery_uncode ilike '%" . common::check_input($term) . "%')";
  501. $sql = "select left(place_of_delivery_uncode, 2) as country,place_of_delivery_exp as city, place_of_delivery_uncode as uncode
  502. from public.online_booking $sqlWhere
  503. and COALESCE(place_of_delivery_uncode)<>''
  504. and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
  505. or place_of_delivery_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc NULLS LAST";
  506. return array("count_sql"=>$count_sql,"sql"=>$sql);
  507. }
  508. //tracking
  509. $order_by = " etd desc NULLS LAST";
  510. if (_isCustomerLogin()) {
  511. $order_by = " eta desc NULLS LAST";
  512. }
  513. if($search_field == "Origin" && $search_mode == "tracking"){
  514. $sqlWhere = $this->getTrackingSearchWhere();
  515. $count_sql = "select COUNT(DISTINCT city) from (select left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode
  516. from public.online_ocean $sqlWhere
  517. and COALESCE(shippr_uncode)<>''
  518. and (shipper_city ilike '%" . common::check_input($term) . "%'
  519. or shippr_uncode ilike '%" . common::check_input($term) . "%')
  520. union
  521. select left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode
  522. from public.online_ocean $sqlWhere
  523. and COALESCE(consignee_uncode)<>''
  524. and (consignee_city ilike '%" . common::check_input($term) . "%'
  525. or consignee_uncode ilike '%" . common::check_input($term) . "%')) as temp";
  526. $sql = "select country, city,uncode from(select left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode,etd,eta
  527. from public.online_ocean $sqlWhere
  528. and COALESCE(shippr_uncode)<>''
  529. and (shipper_city ilike '%" . common::check_input($term) . "%'
  530. or shippr_uncode ilike '%" . common::check_input($term) . "%')
  531. union
  532. select left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode,etd,eta
  533. from public.online_ocean $sqlWhere
  534. and COALESCE(consignee_uncode)<>''
  535. and (consignee_city ilike '%" . common::check_input($term) . "%'
  536. or consignee_uncode ilike '%" . common::check_input($term) . "%')) as temp order by $order_by";
  537. return array("count_sql"=>$count_sql,"sql"=>$sql);
  538. }
  539. if($search_field == "Destination" && $search_mode == "tracking"){
  540. $sqlWhere = $this->getTrackingSearchWhere();
  541. $count_sql = "select COUNT(DISTINCT final_desination_exp)
  542. from public.online_ocean $sqlWhere
  543. and COALESCE(final_desination_uncode)<>''
  544. and (final_desination_exp ilike '%" . common::check_input($term) . "%'
  545. or final_desination_uncode ilike '%" . common::check_input($term) . "%')";
  546. $sql = "select left(final_desination_uncode, 2) as country,final_desination_exp as city, final_desination_uncode as uncode
  547. from public.online_ocean $sqlWhere
  548. and COALESCE(final_desination_uncode)<>''
  549. and (final_desination_exp ilike '%" . common::check_input($term) . "%'
  550. or final_desination_uncode ilike '%" . common::check_input($term) . "%') order by $order_by";
  551. return array("count_sql"=>$count_sql,"sql"=>$sql);
  552. }
  553. if($search_field == "Place of Receipt" && $search_mode == "tracking"){
  554. $sqlWhere = $this->getTrackingSearchWhere();
  555. $count_sql = "select COUNT(DISTINCT place_of_receipt_exp)
  556. from public.online_ocean $sqlWhere
  557. and COALESCE(place_of_receipt_un)<>''
  558. and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
  559. or place_of_receipt_un ilike '%" . common::check_input($term) . "%')";
  560. $sql = "select left(place_of_receipt_un, 2) as country,place_of_receipt_exp as city, place_of_receipt_un as uncode
  561. from public.online_ocean $sqlWhere
  562. and COALESCE(place_of_receipt_un)<>''
  563. and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
  564. or place_of_receipt_un ilike '%" . common::check_input($term) . "%') order by $order_by";
  565. return array("count_sql"=>$count_sql,"sql"=>$sql);
  566. }
  567. if($search_field == "Port of Loading" && $search_mode == "tracking"){
  568. $sqlWhere = $this->getTrackingSearchWhere();
  569. $count_sql = "select COUNT(DISTINCT port_of_loading)
  570. from public.online_ocean $sqlWhere
  571. and COALESCE(fport_of_loading_un)<>''
  572. and (port_of_loading ilike '%" . common::check_input($term) . "%'
  573. or fport_of_loading_un ilike '%" . common::check_input($term) . "%')";
  574. $sql = "select left(fport_of_loading_un, 2) as country,port_of_loading as city, fport_of_loading_un as uncode
  575. from public.online_ocean $sqlWhere
  576. and COALESCE(fport_of_loading_un)<>''
  577. and (port_of_loading ilike '%" . common::check_input($term) . "%'
  578. or fport_of_loading_un ilike '%" . common::check_input($term) . "%') order by $order_by";
  579. return array("count_sql"=>$count_sql,"sql"=>$sql);
  580. }
  581. if($search_field == "Place of Discharge" && $search_mode == "tracking"){
  582. $sqlWhere = $this->getTrackingSearchWhere();
  583. $count_sql = "select COUNT(DISTINCT port_of_discharge)
  584. from public.online_ocean $sqlWhere
  585. and COALESCE(mport_of_discharge_un)<>''
  586. and (port_of_discharge ilike '%" . common::check_input($term) . "%'
  587. or mport_of_discharge_un ilike '%" . common::check_input($term) . "%')";
  588. $sql = "select left(mport_of_discharge_un, 2) as country,port_of_discharge as city, mport_of_discharge_un as uncode
  589. from public.online_ocean $sqlWhere
  590. and COALESCE(mport_of_discharge_un)<>''
  591. and (port_of_discharge ilike '%" . common::check_input($term) . "%'
  592. or mport_of_discharge_un ilike '%" . common::check_input($term) . "%') order by $order_by";
  593. return array("count_sql"=>$count_sql,"sql"=>$sql);
  594. }
  595. if($search_field == "Place of delivery" && $search_mode == "tracking"){
  596. $sqlWhere = $this->getTrackingSearchWhere();
  597. $count_sql = "select COUNT(DISTINCT place_of_delivery_exp)
  598. from public.online_ocean $sqlWhere
  599. and COALESCE(place_of_delivery_un)<>''
  600. and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
  601. or place_of_delivery_un ilike '%" . common::check_input($term) . "%')";
  602. $sql = "select left(place_of_delivery_un, 2) as country,place_of_delivery_exp as city, place_of_delivery_un as uncode
  603. from public.online_ocean $sqlWhere
  604. and COALESCE(place_of_delivery_un)<>''
  605. and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
  606. or place_of_delivery_un ilike '%" . common::check_input($term) . "%') order by $order_by";
  607. return array("count_sql"=>$count_sql,"sql"=>$sql);
  608. }
  609. }
  610. }
  611. ?>