ajax.class.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. column::getInstance()->saveSettingDisplay(implode(",", $_POST['ids']),"", $_POST['model_name']);
  46. $data = array(
  47. 'msg' => 'success'
  48. );
  49. common::echo_json_encode(200,$data);
  50. }else{
  51. $data = array(
  52. 'msg' => 'data error'
  53. );
  54. common::echo_json_encode(500,$data);
  55. }
  56. }
  57. public function autoPort() {
  58. $cp = common::check_input($_POST ['cp']); //current_page
  59. $ps = common::check_input($_POST ['ps']); //ps
  60. if (empty($ps))
  61. $ps = 20;
  62. $term = $_POST['term'];
  63. $term = trim($term);
  64. $_curr_schemas = $_POST['model'];
  65. if (empty($_curr_schemas)) {
  66. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  67. if (empty($_curr_schemas)) {
  68. $_curr_schemas = "public";
  69. }
  70. }
  71. $rc = $_POST ['rc'];
  72. if ($rc == - 1) {
  73. $sql = "SELECT count(1) from $_curr_schemas.ports where (isoname ilike '" . common::check_input($term) . "%'
  74. or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%')";
  75. $rc = common::excuteOneSql($sql);
  76. }
  77. $tp = ceil($rc / $ps);
  78. if ($rc > 0) {
  79. $sql = "SELECT isoname as country, uncity as city,uncode from $_curr_schemas.ports where (isoname ilike '" . common::check_input($term) . "%'
  80. or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%')";
  81. $sql .= " order by code limit " . $ps . " offset " . ($cp - 1) * $ps;
  82. $rs = common::excuteListSql($sql);
  83. //前端要加上id 从1开始
  84. foreach($rs as $key => $val){
  85. $rs[$key]["id"] = $key +1;
  86. }
  87. $arrTmp = array('searchData' => $rs,
  88. 'rc' => $rc,
  89. 'ps' => $ps,
  90. 'cp' => $cp,
  91. 'tp' => $tp);
  92. common::echo_json_encode(200,$arrTmp);
  93. exit();
  94. }else{
  95. $arrTmp = array('searchData' => "nodata");
  96. common::echo_json_encode(200, $arrTmp);
  97. exit();
  98. }
  99. }
  100. public function autody() {
  101. $term = $_POST['term'];
  102. $type = $_POST['type'];
  103. $term = trim($term);
  104. if (strtolower($type) == "apex") {
  105. $_curr_schemas = $_POST['model'];
  106. if (empty($_curr_schemas)) {
  107. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  108. if (empty($_curr_schemas)) {
  109. $_curr_schemas = "public";
  110. }
  111. }
  112. if ($_curr_schemas == "public") {
  113. $sql = "select contact_id as code from ocean.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))"
  114. . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) "
  115. . "and active=true and coalesce(hblcode, '')<>'' and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
  116. } else {
  117. $sql = "select contact_id as code from $_curr_schemas.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))"
  118. . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) "
  119. . "and active=true and coalesce(hblcode, '')<>'' and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
  120. }
  121. $sql .= " order by contact_id limit 20";
  122. $rs = common::excuteListSql($sql);
  123. }
  124. //Shipper 和Consignee 的查询 但是表contact_v ,从ocean和air. 如果不做区分的话,可以上面的apex的Origin Agent/Destination Agent,合并
  125. if (strtolower($type) == "contanct") {
  126. $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) . "%')";
  127. $sql .= " order by contact_id limit 20";
  128. $rs = common::excuteListSql($sql);
  129. }
  130. if (strtolower($type) == "sales") {
  131. $_curr_schemas = $_POST['model'];
  132. if (empty($_curr_schemas)) {
  133. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  134. if (empty($_curr_schemas)) {
  135. $_curr_schemas = "public";
  136. }
  137. }
  138. $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) . "%')";
  139. $sql .= " order by salesopcode limit 20";
  140. }
  141. if (strtolower($type) == "vessel") {
  142. $vessel = $_POST['vessel'];
  143. $sql = "SELECT carrier, vessel as code, flag from vessel_infor where vessel ilike '" . common::check_input($vessel) . "%'";
  144. $sql .= " order by vessel limit 20";
  145. }
  146. $rs = common::excuteListSql($sql);
  147. $array = array();
  148. foreach($rs as $v){
  149. $array[] = $v['code'];
  150. }
  151. common::echo_json_encode(200,$array);
  152. exit();
  153. }
  154. }
  155. ?>