ajax.class.php 6.6 KB

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