ajax.class.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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_new(){
  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") {
  66. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  67. $sqlWhere = " " . $sqlWhere;
  68. $search_field_mapping = array("Origin Agent"=>"origin",
  69. "Destination Agent"=>"agent",
  70. "Shipper Name"=>"shipper",
  71. "Consignee Name"=>"consignee",
  72. "Sales"=>"sales_rep",
  73. "Voyage"=>"voyage",
  74. "Vessel"=>"vessel");
  75. $str = $search_field_mapping['$search_field '];
  76. $table = $search_mode == "Tracking" ? "public.online_ocean" : "public.online_ocean";
  77. $sql = "select $str from $table where 1=1 $sqlWhere and f_etd >= current_date - INTERVAL '3 months'";
  78. $sql .= " order by contact_id limit 20";
  79. $rs = common::excuteListSql($sql);
  80. }
  81. //Shipper 和Consignee 的查询,但是表contact_v ,从ocean和air. 如果不做区分的话,可以上面的apex的Origin Agent/Destination Agent,合并
  82. if (strtolower($type) == "contanct") {
  83. $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) . "%')";
  84. $sql .= " order by contact_id limit 20";
  85. $rs = common::excuteListSql($sql);
  86. }
  87. $rs = common::excuteListSql($sql);
  88. $array = array();
  89. foreach($rs as $v){
  90. if(!empty($v['code'])){
  91. $array[] = $v['code'];
  92. }
  93. }
  94. common::echo_json_encode(200,$array);
  95. exit();
  96. }
  97. public function autoPort() {
  98. $cp = common::check_input($_POST ['cp']); //current_page
  99. $ps = common::check_input($_POST ['ps']); //ps
  100. if (empty($ps))
  101. $ps = 20;
  102. $term = $_POST['term'];
  103. $term = trim($term);
  104. $_curr_schemas = $_POST['model'];
  105. if (empty($_curr_schemas)) {
  106. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  107. if (empty($_curr_schemas)) {
  108. $_curr_schemas = "public";
  109. }
  110. }
  111. $rc = $_POST ['rc'];
  112. if ($rc == - 1) {
  113. $sql = "SELECT count(1) from $_curr_schemas.ports where (isoname ilike '" . common::check_input($term) . "%'
  114. or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%')";
  115. $rc = common::excuteOneSql($sql);
  116. }
  117. $tp = ceil($rc / $ps);
  118. if ($rc > 0) {
  119. $sql = "SELECT isoname as country, uncity as city,uncode from $_curr_schemas.ports where (isoname ilike '" . common::check_input($term) . "%'
  120. or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%')";
  121. $sql .= " order by code limit " . $ps . " offset " . ($cp - 1) * $ps;
  122. $rs = common::excuteListSql($sql);
  123. //前端要加上id 从1开始
  124. $retData = array();
  125. foreach($rs as $key => $val){
  126. if(!empty($val['country'])){
  127. $val["id"] = $key +1;
  128. $retData[] = $val;
  129. }
  130. }
  131. $arrTmp = array('searchData' => $retData,
  132. 'rc' => $rc,
  133. 'ps' => $ps,
  134. 'cp' => $cp,
  135. 'tp' => $tp);
  136. common::echo_json_encode(200,$arrTmp);
  137. exit();
  138. }else{
  139. $arrTmp = array('searchData' => array());
  140. common::echo_json_encode(200, $arrTmp);
  141. exit();
  142. }
  143. }
  144. public function autody() {
  145. $term = $_POST['term'];
  146. $type = $_POST['type'];
  147. $term = trim($term);
  148. if (strtolower($type) == "apex") {
  149. $_curr_schemas = $_POST['model'];
  150. if (empty($_curr_schemas)) {
  151. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  152. if (empty($_curr_schemas)) {
  153. $_curr_schemas = "public";
  154. }
  155. }
  156. if ($_curr_schemas == "public") {
  157. $sql = "select contact_id as code from ocean.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))"
  158. . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) "
  159. . "and active=true and coalesce(hblcode, '')<>'' and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
  160. } else {
  161. $sql = "select contact_id as code from $_curr_schemas.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))"
  162. . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) "
  163. . "and active=true and coalesce(hblcode, '')<>'' and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
  164. }
  165. $sql .= " order by contact_id limit 20";
  166. $rs = common::excuteListSql($sql);
  167. }
  168. //Shipper 和Consignee 的查询,但是表contact_v ,从ocean和air. 如果不做区分的话,可以上面的apex的Origin Agent/Destination Agent,合并
  169. if (strtolower($type) == "contanct") {
  170. $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) . "%')";
  171. $sql .= " order by contact_id limit 20";
  172. $rs = common::excuteListSql($sql);
  173. }
  174. if (strtolower($type) == "sales") {
  175. $_curr_schemas = $_POST['model'];
  176. if (empty($_curr_schemas)) {
  177. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  178. if (empty($_curr_schemas)) {
  179. $_curr_schemas = "public";
  180. }
  181. }
  182. $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) . "%')";
  183. $sql .= " order by salesopcode limit 20";
  184. }
  185. if (strtolower($type) == "vessel") {
  186. $vessel = $_POST['vessel'];
  187. $sql = "SELECT carrier, vessel as code, flag from vessel_infor where vessel ilike '" . common::check_input($vessel) . "%'";
  188. $sql .= " order by vessel limit 20";
  189. }
  190. $rs = common::excuteListSql($sql);
  191. $array = array();
  192. foreach($rs as $v){
  193. if(!empty($v['code'])){
  194. $array[] = $v['code'];
  195. }
  196. }
  197. common::echo_json_encode(200,$array);
  198. exit();
  199. }
  200. }
  201. ?>