ajax.class.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  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 * from ($sql) as temp ";
  153. $sql .= " order by city limit " . $ps . " offset " . ($cp - 1) * $ps;
  154. $rs = common::excuteListSql($sql);
  155. //前端要加上id 从1开始
  156. $retData = array();
  157. $i = 0;
  158. foreach($rs as $key => $val){
  159. if($search_field == "Port of Loading"){
  160. if(!empty($val['uncode'])){
  161. $val["id"] = $i +1;
  162. $retData[] = $val;
  163. $i = $i +1;
  164. }
  165. }else{
  166. if(!empty($val['city'])){
  167. $val["id"] = $i +1;
  168. $retData[] = $val;
  169. $i = $i +1;
  170. }
  171. }
  172. }
  173. $arrTmp = array('searchData' => $retData,
  174. 'rc' => $rc,
  175. 'ps' => $ps,
  176. 'cp' => $cp,
  177. 'tp' => $tp);
  178. common::echo_json_encode(200,$arrTmp);
  179. exit();
  180. }else{
  181. $arrTmp = array('searchData' => array(), 'rc' => 0);
  182. common::echo_json_encode(200, $arrTmp);
  183. exit();
  184. }
  185. }
  186. public function autoPort_old() {
  187. $cp = common::check_input($_POST ['cp']); //current_page
  188. $ps = common::check_input($_POST ['ps']); //ps
  189. if (empty($ps))
  190. $ps = 20;
  191. $term = $_POST['term'];
  192. $term = trim($term);
  193. $_curr_schemas = $_POST['model'];
  194. if (empty($_curr_schemas)) {
  195. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  196. if (empty($_curr_schemas)) {
  197. $_curr_schemas = "public";
  198. }
  199. }
  200. $rc = $_POST ['rc'];
  201. if ($rc == - 1) {
  202. $sql = "SELECT count(1) from $_curr_schemas.ports where (isoname ilike '" . common::check_input($term) . "%'
  203. or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%')";
  204. $rc = common::excuteOneSql($sql);
  205. }
  206. $tp = ceil($rc / $ps);
  207. if ($rc > 0) {
  208. $sql = "SELECT isoname as country, uncity as city,uncode from $_curr_schemas.ports where (isoname ilike '" . common::check_input($term) . "%'
  209. or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%')";
  210. $sql .= " order by code limit " . $ps . " offset " . ($cp - 1) * $ps;
  211. $rs = common::excuteListSql($sql);
  212. //前端要加上id 从1开始
  213. $retData = array();
  214. foreach($rs as $key => $val){
  215. if(!empty($val['country'])){
  216. $val["id"] = $key +1;
  217. $retData[] = $val;
  218. }
  219. }
  220. $arrTmp = array('searchData' => $retData,
  221. 'rc' => $rc,
  222. 'ps' => $ps,
  223. 'cp' => $cp,
  224. 'tp' => $tp);
  225. common::echo_json_encode(200,$arrTmp);
  226. exit();
  227. }else{
  228. $arrTmp = array('searchData' => array());
  229. common::echo_json_encode(200, $arrTmp);
  230. exit();
  231. }
  232. }
  233. public function autody_old() {
  234. $term = $_POST['term'];
  235. $type = $_POST['type'];
  236. $term = trim($term);
  237. if (strtolower($type) == "apex") {
  238. $_curr_schemas = $_POST['model'];
  239. if (empty($_curr_schemas)) {
  240. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  241. if (empty($_curr_schemas)) {
  242. $_curr_schemas = "public";
  243. }
  244. }
  245. if ($_curr_schemas == "public") {
  246. $sql = "select contact_id as code from ocean.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))"
  247. . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) "
  248. . "and active=true and coalesce(hblcode, '')<>'' and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
  249. } else {
  250. $sql = "select contact_id as code from $_curr_schemas.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))"
  251. . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) "
  252. . "and active=true and coalesce(hblcode, '')<>'' and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
  253. }
  254. $sql .= " order by contact_id limit 20";
  255. $rs = common::excuteListSql($sql);
  256. }
  257. //Shipper 和Consignee 的查询,但是表contact_v ,从ocean和air. 如果不做区分的话,可以上面的apex的Origin Agent/Destination Agent,合并
  258. if (strtolower($type) == "contanct") {
  259. $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) . "%')";
  260. $sql .= " order by contact_id limit 20";
  261. $rs = common::excuteListSql($sql);
  262. }
  263. if (strtolower($type) == "sales") {
  264. $_curr_schemas = $_POST['model'];
  265. if (empty($_curr_schemas)) {
  266. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  267. if (empty($_curr_schemas)) {
  268. $_curr_schemas = "public";
  269. }
  270. }
  271. $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) . "%')";
  272. $sql .= " order by salesopcode limit 20";
  273. }
  274. if (strtolower($type) == "vessel") {
  275. $vessel = $_POST['vessel'];
  276. $sql = "SELECT carrier, vessel as code, flag from vessel_infor where vessel ilike '" . common::check_input($vessel) . "%'";
  277. $sql .= " order by vessel limit 20";
  278. }
  279. $rs = common::excuteListSql($sql);
  280. $array = array();
  281. foreach($rs as $v){
  282. if(!empty($v['code'])){
  283. $array[] = $v['code'];
  284. }
  285. }
  286. common::echo_json_encode(200,$array);
  287. exit();
  288. }
  289. public function getTrackingSearchWhere(){
  290. $sqlWhere = ' where ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  291. $sqlWhere .= search::getInstance()->getSearchSQL("Ocean_Search");
  292. if (!empty($_REQUEST["_reportRef"])) {
  293. $_reportType = $_REQUEST["_reportType"];
  294. $_reportRef = $_REQUEST["_reportRef"];
  295. if ($_reportType == "r3") {
  296. if ($_reportRef == "Previous 7 Days") {
  297. $sqlWhere .= " and eta>(current_date-interval '7 days') and eta<current_date";
  298. } else if ($_reportRef == "0 Day") {
  299. $sqlWhere .= " and eta=current_date";
  300. } else if ($_reportRef == "1-2 Days") {
  301. $sqlWhere .= " and eta>current_date and eta<=(current_date+interval '2 days')";
  302. } else if ($_reportRef == "3-6 Days") {
  303. $sqlWhere .= " and eta>(current_date+interval '2 days') and eta<=(current_date+interval '6 days')";
  304. } else if ($_reportRef == "7 Days") {
  305. $sqlWhere .= " and eta>(current_date+interval '6 days')";
  306. } else {
  307. $sqlWhere .= " and 1<>1";
  308. }
  309. } else if ($_reportType == "r4") {
  310. if ($_reportRef == "Previous 7 Days") {
  311. $sqlWhere .= " and etd>(current_date-interval '7 days') and etd<current_date";
  312. } else if ($_reportRef == "0 Day") {
  313. $sqlWhere .= " and etd=current_date";
  314. } else if ($_reportRef == "1-2 Days") {
  315. $sqlWhere .= " and etd>current_date and etd<=(current_date+interval '2 days')";
  316. } else if ($_reportRef == "3-6 Days") {
  317. $sqlWhere .= " and etd>(current_date+interval '2 days') and etd<=(current_date+interval '6 days')";
  318. } else if ($_reportRef == "7 Days") {
  319. $sqlWhere .= " and etd>(current_date+interval '6 days')";
  320. } else {
  321. $sqlWhere .= " and 1<>1";
  322. }
  323. } else if ($_reportType == "ata_r3") {
  324. if ($_reportRef == "0 Day") {
  325. $sqlWhere .= " and ata >= etd and (ata-etd) >= 0 and (ata-etd) < 1";
  326. } else if ($_reportRef == "1-2 Days") {
  327. $sqlWhere .= " and ata >= etd and (ata-etd) >= 1 and (ata-etd) < 2";
  328. } else if ($_reportRef == "3-6 Days") {
  329. $sqlWhere .= " and ata >= etd and (ata-etd) >= 2 and (ata-etd) < 6";
  330. } else if ($_reportRef == "7 Days") {
  331. $sqlWhere .= " and ata >= etd and (ata-etd) >= 6";
  332. } else {
  333. $sqlWhere .= " and 1<>1";
  334. }
  335. } else if ($_reportType == "atd_r4") {
  336. if ($_reportRef == "0 Day") {
  337. $sqlWhere .= " and atd >= etd and (atd-etd) >= 0 and (atd-etd) < 1";
  338. } else if ($_reportRef == "1-2 Days") {
  339. $sqlWhere .= " and atd >= etd and (atd-etd) >= 1 and (atd-etd) < 2";
  340. } else if ($_reportRef == "3-6 Days") {
  341. $sqlWhere .= " and atd >= etd and (atd-etd) >= 2 and (atd-etd) < 6";
  342. } else if ($_reportRef == "7 Days") {
  343. $sqlWhere .= " and atd >= etd and (atd-etd) >= 6 ";
  344. } else {
  345. $sqlWhere .= " and 1<>1";
  346. }
  347. } else if ($_reportType == "top") {
  348. if (!empty($_reportRef)) {
  349. $_reportStationType = $_REQUEST["_reportStationType"];
  350. if($_reportStationType == 'shippr_uncode'){
  351. $sqlWhere = " and shippr_uncode = '$_reportRef'";
  352. }
  353. if($_reportStationType == 'fport_of_loading_un'){
  354. $sqlWhere = " and fport_of_loading_un = '$_reportRef'";
  355. }
  356. if($_reportStationType == 'consignee_uncode'){
  357. $sqlWhere .= " and consignee_uncode = '$_reportRef'";
  358. }
  359. if($_reportStationType == 'mport_of_discharge_un'){
  360. $sqlWhere .= " and mport_of_discharge_un = '$_reportRef'";
  361. }
  362. } else {
  363. $sqlWhere .= " and 1<>1";
  364. }
  365. } else if ($_reportType == "co2e") {
  366. $_reportDataType = $_REQUEST["_reportDataType"];
  367. //查询sea 其他的为空
  368. if (!empty($_reportRef) && $_reportDataType == "sea") {
  369. $_reportStationType = $_REQUEST["_reportStationType"];
  370. if($_reportStationType == 'origin'){
  371. $sqlWhere .= " and shippr_uncode = '$_reportRef'";
  372. }else{
  373. $sqlWhere .= " and consignee_uncode = '$_reportRef'";
  374. }
  375. } else {
  376. $sqlWhere .= " and 1<>1";
  377. }
  378. } else {
  379. $_reportRef = explode("-", $_REQUEST["_reportRef"]);
  380. $_reportRefb_date = $_REQUEST["_reportRefb_date"];
  381. $bdate = common::excuteOneSql("select to_date('$_reportRefb_date','mm/YYYY')");
  382. $_reportRefe_date = $_REQUEST["_reportRefe_date"];
  383. $edate = common::excuteOneSql("select to_date('$_reportRefe_date','mm/YYYY') + interval '1 month' - interval '1 day'");
  384. //$sqlWhere .= " and eta>='$bdate' and eta<='$edate'";
  385. if ($_REQUEST["_reportRef"] == "Over 80 Days") {
  386. $sqlWhere .= " and (eta-etd)>80";
  387. } else {
  388. $sqlWhere .= " and (eta-etd)>" . $_reportRef[0] . " and (eta-etd)<=" . substr($_reportRef[1], 0, 2);
  389. }
  390. }
  391. }
  392. //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No.
  393. if (!empty($_POST["_textSearch"])) {
  394. $textSearch_arr = $_POST['_textSearch'];
  395. if(!is_array($textSearch_arr)){
  396. $textSearch_arr = array($textSearch_arr);
  397. }
  398. $more_sql = "1<>1";
  399. foreach($textSearch_arr as $tsv){
  400. $more_sql .= " or booking_no ilike '%" . common::check_input(trim($tsv)) . "%'";
  401. $more_sql .= " or h_bol ilike '%" . common::check_input(trim($tsv)) . "%'";
  402. $more_sql .= " or po_no ilike '%" . common::check_input(trim($tsv)) . "%'";
  403. $more_sql .= " or carrier_booking ilike '%" . common::check_input(trim($tsv)) . "%'";
  404. }
  405. if ($more_sql <> "1<>1"){
  406. $sqlWhere .= " and ($more_sql)";
  407. }
  408. }
  409. return $sqlWhere;
  410. }
  411. public function getBookingSearchWhere(){
  412. $sqlWhere = ' where ' . common::searchExtendHandNew("booking", $_SESSION["ONLINE_USER"]);
  413. $sqlWhere .= search::getInstance()->getSearchSQL("Booking_Search");
  414. //新版要排除type2情况,总数才会对的上
  415. $sqlWhere .= " and (not(bol_type != 'BOOKING' and booking_no is not null and booking_no <> ''))";
  416. //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No.
  417. if (!empty($_POST["_textSearch"])) {
  418. $textSearch_arr = $_POST['_textSearch'];
  419. if(!is_array($textSearch_arr)){
  420. $textSearch_arr = array($textSearch_arr);
  421. }
  422. $more_sql = "1<>1";
  423. foreach($textSearch_arr as $tsv){
  424. $more_sql .= " or booking_no ilike '%" . common::check_input(trim($tsv)) . "%'";
  425. $more_sql .= " or h_bol ilike '%" . common::check_input(trim($tsv)) . "%'";
  426. $more_sql .= " or po_no ilike '%" . common::check_input(trim($tsv)) . "%'";
  427. $more_sql .= " or carrier_booking ilike '%" . common::check_input(trim($tsv)) . "%'";
  428. }
  429. if ($more_sql <> "1<>1"){
  430. $sqlWhere .= " and ($more_sql)";
  431. }
  432. }
  433. return $sqlWhere;
  434. }
  435. PUBLIC function getPortsUncity($search_field,$search_mode,$term){
  436. //uncode 前两位便是 isoname,不用模糊查询这个了
  437. if($search_field == "Origin" && $search_mode == "booking"){
  438. $sqlWhere = $this->getBookingSearchWhere();
  439. $count_sql = "select COUNT(DISTINCT shipper_city)
  440. from public.online_booking $sqlWhere
  441. and COALESCE(shippr_uncode)<>''
  442. and (shipper_city ilike '%" . common::check_input($term) . "%'
  443. or shippr_uncode ilike '%" . common::check_input($term) . "%') ";
  444. $sql = "select DISTINCT ON (shipper_city) left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode
  445. from public.online_booking $sqlWhere
  446. and COALESCE(shippr_uncode)<>''
  447. and (shipper_city ilike '%" . common::check_input($term) . "%'
  448. or shippr_uncode ilike '%" . common::check_input($term) . "%') ";
  449. return array("count_sql"=>$count_sql,"sql"=>$sql);
  450. }
  451. if($search_field == "Destination" && $search_mode == "booking"){
  452. $sqlWhere = $this->getBookingSearchWhere();
  453. $count_sql = "select count(DISTINCT consignee_city)
  454. from public.online_booking $sqlWhere
  455. and COALESCE(consignee_uncode)<>''
  456. and (consignee_city ilike '%" . common::check_input($term) . "%'
  457. or consignee_uncode ilike '%" . common::check_input($term) . "%') ";
  458. $sql = "select DISTINCT ON (consignee_city) left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode
  459. from public.online_booking $sqlWhere
  460. and COALESCE(consignee_uncode)<>''
  461. and (consignee_city ilike '%" . common::check_input($term) . "%'
  462. or consignee_uncode ilike '%" . common::check_input($term) . "%')";
  463. return array("count_sql"=>$count_sql,"sql"=>$sql);
  464. }
  465. if($search_field == "Place of Receipt" && $search_mode == "booking"){
  466. $sqlWhere = $this->getBookingSearchWhere();
  467. $count_sql = "select COUNT(DISTINCT place_of_receipt_exp)
  468. from public.online_booking $sqlWhere
  469. and COALESCE(place_of_receipt_uncode)<>''
  470. and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
  471. or place_of_receipt_uncode ilike '%" . common::check_input($term) . "%')";
  472. $sql = "select DISTINCT ON (place_of_receipt_exp) left(place_of_receipt_uncode, 2) as country,place_of_receipt_exp as city, place_of_receipt_uncode as uncode
  473. from public.online_booking $sqlWhere
  474. and COALESCE(place_of_receipt_uncode)<>''
  475. and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
  476. or place_of_receipt_uncode ilike '%" . common::check_input($term) . "%')";
  477. return array("count_sql"=>$count_sql,"sql"=>$sql);
  478. }
  479. if($search_field == "Port of Loading" && $search_mode == "booking"){
  480. $sqlWhere = $this->getBookingSearchWhere();
  481. $count_sql = "select COUNT(DISTINCT fport_of_loading_exp)
  482. from public.online_booking $sqlWhere
  483. and COALESCE(fport_of_loading_uncode)<>''
  484. and (fport_of_loading_exp ilike '%" . common::check_input($term) . "%'
  485. or fport_of_loading_uncode ilike '%" . common::check_input($term) . "%')";
  486. $sql = "select DISTINCT ON (fport_of_loading_exp) left(fport_of_loading_uncode, 2) as country,fport_of_loading_exp as city, fport_of_loading_uncode as uncode
  487. from public.online_booking $sqlWhere
  488. and COALESCE(fport_of_loading_uncode)<>''
  489. and (fport_of_loading_exp ilike '%" . common::check_input($term) . "%'
  490. or fport_of_loading_uncode ilike '%" . common::check_input($term) . "%')";
  491. return array("count_sql"=>$count_sql,"sql"=>$sql);
  492. }
  493. if($search_field == "Place of delivery" && $search_mode == "booking"){
  494. $sqlWhere = $this->getBookingSearchWhere();
  495. $count_sql = "select COUNT(DISTINCT place_of_delivery_exp)
  496. from public.online_booking $sqlWhere
  497. and COALESCE(place_of_delivery_uncode)<>''
  498. and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
  499. or place_of_delivery_uncode ilike '%" . common::check_input($term) . "%')";
  500. $sql = "select DISTINCT ON (place_of_delivery_exp) left(place_of_delivery_uncode, 2) as country,place_of_delivery_exp as city, place_of_delivery_uncode as uncode
  501. from public.online_booking $sqlWhere
  502. and COALESCE(place_of_delivery_uncode)<>''
  503. and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
  504. or place_of_delivery_uncode ilike '%" . common::check_input($term) . "%')";
  505. return array("count_sql"=>$count_sql,"sql"=>$sql);
  506. }
  507. //tracking
  508. if($search_field == "Origin" && $search_mode == "tracking"){
  509. $sqlWhere = $this->getTrackingSearchWhere();
  510. $count_sql = "select COUNT(DISTINCT city) from (select left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode
  511. from public.online_ocean $sqlWhere
  512. and COALESCE(shippr_uncode)<>''
  513. and (shipper_city ilike '%" . common::check_input($term) . "%'
  514. or shippr_uncode ilike '%" . common::check_input($term) . "%')
  515. union
  516. select left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode
  517. from public.online_ocean $sqlWhere
  518. and COALESCE(consignee_uncode)<>''
  519. and (consignee_city ilike '%" . common::check_input($term) . "%'
  520. or consignee_uncode ilike '%" . common::check_input($term) . "%')) as temp";
  521. $sql = "select * from(select DISTINCT ON (shipper_city) left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode
  522. from public.online_ocean $sqlWhere
  523. and COALESCE(shippr_uncode)<>''
  524. and (shipper_city ilike '%" . common::check_input($term) . "%'
  525. or shippr_uncode ilike '%" . common::check_input($term) . "%')
  526. union
  527. select DISTINCT ON (consignee_city) left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode
  528. from public.online_ocean $sqlWhere
  529. and COALESCE(consignee_uncode)<>''
  530. and (consignee_city ilike '%" . common::check_input($term) . "%'
  531. or consignee_uncode ilike '%" . common::check_input($term) . "%')) as temp";
  532. return array("count_sql"=>$count_sql,"sql"=>$sql);
  533. }
  534. if($search_field == "Destination" && $search_mode == "tracking"){
  535. $sqlWhere = $this->getTrackingSearchWhere();
  536. $count_sql = "select COUNT(DISTINCT final_desination_exp)
  537. from public.online_ocean $sqlWhere
  538. and COALESCE(final_desination_uncode)<>''
  539. and (final_desination_exp ilike '%" . common::check_input($term) . "%'
  540. or final_desination_uncode ilike '%" . common::check_input($term) . "%')";
  541. $sql = "select DISTINCT ON (final_desination_exp) left(final_desination_uncode, 2) as country,final_desination_exp as city, final_desination_uncode as uncode
  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. return array("count_sql"=>$count_sql,"sql"=>$sql);
  547. }
  548. if($search_field == "Place of Receipt" && $search_mode == "tracking"){
  549. $sqlWhere = $this->getTrackingSearchWhere();
  550. $count_sql = "select COUNT(DISTINCT place_of_receipt_exp)
  551. from public.online_ocean $sqlWhere
  552. and COALESCE(place_of_receipt_un)<>''
  553. and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
  554. or place_of_receipt_un ilike '%" . common::check_input($term) . "%')";
  555. $sql = "select DISTINCT ON (place_of_receipt_exp) left(place_of_receipt_un, 2) as country,place_of_receipt_exp as city, place_of_receipt_un as uncode
  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. return array("count_sql"=>$count_sql,"sql"=>$sql);
  561. }
  562. if($search_field == "Port of Loading" && $search_mode == "tracking"){
  563. $sqlWhere = $this->getTrackingSearchWhere();
  564. $count_sql = "select COUNT(DISTINCT port_of_loading)
  565. from public.online_ocean $sqlWhere
  566. and COALESCE(fport_of_loading_un)<>''
  567. and (port_of_loading ilike '%" . common::check_input($term) . "%'
  568. or fport_of_loading_un ilike '%" . common::check_input($term) . "%')";
  569. $sql = "select DISTINCT ON (port_of_loading) left(fport_of_loading_un, 2) as country,port_of_loading as city, fport_of_loading_un as uncode
  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. return array("count_sql"=>$count_sql,"sql"=>$sql);
  575. }
  576. if($search_field == "Place of Discharge" && $search_mode == "tracking"){
  577. $sqlWhere = $this->getTrackingSearchWhere();
  578. $count_sql = "select COUNT(DISTINCT port_of_discharge)
  579. from public.online_ocean $sqlWhere
  580. and COALESCE(mport_of_discharge_un)<>''
  581. and (port_of_discharge ilike '%" . common::check_input($term) . "%'
  582. or mport_of_discharge_un ilike '%" . common::check_input($term) . "%')";
  583. $sql = "select DISTINCT ON (port_of_discharge) left(mport_of_discharge_un, 2) as country,port_of_discharge as city, mport_of_discharge_un as uncode
  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. return array("count_sql"=>$count_sql,"sql"=>$sql);
  589. }
  590. if($search_field == "Place of delivery" && $search_mode == "tracking"){
  591. $sqlWhere = $this->getTrackingSearchWhere();
  592. $count_sql = "select COUNT(DISTINCT place_of_delivery_exp)
  593. from public.online_ocean $sqlWhere
  594. and COALESCE(place_of_delivery_un)<>''
  595. and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
  596. or place_of_delivery_un ilike '%" . common::check_input($term) . "%')";
  597. $sql = "select DISTINCT ON (place_of_delivery_exp) left(place_of_delivery_un, 2) as country,place_of_delivery_exp as city, place_of_delivery_un as uncode
  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. return array("count_sql"=>$count_sql,"sql"=>$sql);
  603. }
  604. }
  605. }
  606. ?>