search.class.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. if (!defined('IN_ONLINE')) {
  3. exit('Access Denied');
  4. }
  5. class search {
  6. private static $_search;
  7. public static function getInstance() {
  8. if (!self::$_search) {
  9. $c = __CLASS__;
  10. self::$_search = new $c;
  11. }
  12. return self::$_search;
  13. }
  14. public function getDisplaySearch($model_name, $ids = "") {
  15. $rs = null;
  16. if (!empty($ids)) {
  17. $rs = $ids;
  18. } else {
  19. $sql = "select ids from public.ra_online_search_config where lower(login_name)='" . strtolower(_getLoginName()) . "' and lower(model_name) = '" . strtolower($model_name) . "'";
  20. $rs = common::excuteOneSql($sql);
  21. if (empty($rs)) {
  22. $sql = "select array_to_string(array(select id from public.ra_online_search where active = true and default_display = true and lower(model_name) = '" . strtolower($model_name) . "'";
  23. if (_isCustomerLogin())
  24. $sql .= " and customer_display = true";
  25. $sql .= " order by order_by asc, search_name asc), ',')";
  26. $rs = common::excuteOneSql($sql);
  27. }
  28. }
  29. $result = "";
  30. $sql = $this->_getSql($rs, "html_value, value_name, search_condition, value_name");
  31. $rss = common::excuteListSql($sql);
  32. foreach ($rss as $key => $value) {
  33. if ($value['search_condition'] == "year") {
  34. $result .= '<div class="modules3">Year : <input name="' . $value['value_name'] . '_start" id="' . $value['value_name'] . '_start" type="text" oninput = "value=value.replace(/[^\d]/g,\'\')" value=""><div class="line"> - </div>
  35. <input name="' . $value['value_name'] . '_end" id="' . $value['value_name'] . '_end" type="text" oninput = "value=value.replace(/[^\d]/g,\'\')" value=""></div>';
  36. } else {
  37. $result .= $value['html_value'];
  38. }
  39. }
  40. return $result;
  41. }
  42. public function _getSql($ids, $str) {
  43. $ids_arr = explode(',', $ids);
  44. $sql = "";
  45. foreach ($ids_arr as $value) {
  46. if (!empty($value)) {
  47. if (empty($sql)) {
  48. $sql .= "SELECT $str FROM public.ra_online_search_cso where id = " . $value;
  49. if (_isCustomerLogin())
  50. $sql .= ' and customer_display = true';
  51. } else {
  52. $sql .= " union all SELECT $str FROM public.ra_online_search_cso where id = " . $value;
  53. if (_isCustomerLogin())
  54. $sql .= ' and customer_display = true';
  55. }
  56. }
  57. }
  58. return $sql;
  59. }
  60. public function saveSettingDisplay($newid, $model_name) {
  61. $login_name = _getLoginName();
  62. if ($this->checkUserDisplaySetting($model_name) === TRUE) {
  63. $sql = "UPDATE public.ra_online_search_config SET ids = '" . common::check_input($newid) . "' WHERE lower(model_name) = '" . common::check_input(strtolower($model_name)) . "' AND lower(login_name) = '" . common::check_input(strtolower($login_name)) . "'";
  64. } else {
  65. $sql = "INSERT INTO public.ra_online_search_config (login_name, model_name, ids) VALUES ('" . common::check_input($login_name) . "', '" . common::check_input($model_name) . "', '" . common::check_input($newid) . "')";
  66. }
  67. common::excuteUpdateSql($sql);
  68. }
  69. /*
  70. * check user had setting display
  71. */
  72. public function checkUserDisplaySetting($model_name) {
  73. $login_name = _getLoginName();
  74. $sql = "select ids from public.ra_online_search_config where lower(login_name)='" . strtolower($login_name) . "' and lower(model_name) = '" . strtolower($model_name) . "'"; //check login_name is setting
  75. $rs = common::excuteObjectSql($sql);
  76. if (!empty($rs)) {
  77. return TRUE;
  78. }
  79. return FALSE;
  80. }
  81. public function getSearchSQL($model_name) {
  82. $sql = "select ids from public.ra_online_search_config_cso where lower(login_name)='" . strtolower(_getLoginName()) . "' and lower(model_name) = '" . strtolower($model_name) . "'";
  83. $rs = common::excuteOneSql($sql);
  84. if (empty($rs)) {
  85. $sql = "select array_to_string(array(select id from public.ra_online_search_cso where active = true and lower(model_name) = '" . strtolower($model_name) . "'";
  86. if (_isCustomerLogin())
  87. $sql .= " and customer_display = true";
  88. $sql .= " order by order_by), ',')";
  89. $rs = common::excuteOneSql($sql);
  90. }
  91. $result = " and 1=1";
  92. $sql = $this->_getSql($rs, "value_name, search_condition, is_int");
  93. $rss = common::excuteListSql($sql);
  94. foreach ($rss as $v) {
  95. if ((isset($_POST[$v['value_name']]) && !empty($_POST[$v['value_name']])) || (isset($_POST[$v['value_name'] . '_start']) && !empty($_POST[$v['value_name'] . '_start'])) || (isset($_POST[$v['value_name'] . '_end']) && !empty($_POST[$v['value_name'] . '_end']))) {
  96. if (strtolower($model_name) == "booking_search" && (strtolower($v['value_name']) == "transport_mode")) {
  97. //transport_mode todo
  98. } elseif (strtolower($model_name) == "ocean_search" && (strtolower($v['value_name']) == "transport_mode")){
  99. //transport_mode todo
  100. } else {
  101. if ($v['search_condition'] == '>=,<=') {
  102. $s = $v['value_name'] . '_start';
  103. $e = $v['value_name'] . '_end';
  104. if (isset($_POST[$s]) && !empty($_POST[$s])) {
  105. $result .= " and " . $v['value_name'] . " >= '" . common::check_input(common::usDate2sqlDate($_POST[$s]) . ' 00:00:00') . "'";
  106. }
  107. if (isset($_POST[$e]) && !empty($_POST[$e])) {
  108. $result .= " and " . $v['value_name'] . " <= '" . common::check_input(common::usDate2sqlDate($_POST[$e]) . ' 23:59:59') . "'";
  109. }
  110. } else {
  111. //处理多个输入查询情况包含一个 数组类型,也有可能单个字符串
  112. $value_arr = $_POST[$v['value_name']];
  113. if(!is_array($value_arr)){
  114. $value_arr = array($value_arr);
  115. }
  116. $more_sql = "1<>1";
  117. foreach($value_arr as $value){
  118. //处理合并查询 包含一个
  119. $value_name_arr = explode("/", $v['value_name']);
  120. foreach($value_name_arr as $value_name){
  121. if ($v['is_int'] == 't') {
  122. $more_sql .= " or " . " " . $value_name . " " . $v['search_condition'] . " " . trim($value);
  123. } elseif ($v['search_condition'] == 'ilike') {
  124. $more_sql .= " or " . $value_name . " " . $v['search_condition'] . " '" . common::check_input(trim($value)) . "%'";
  125. } elseif ($v['search_condition'] == 'like') {
  126. $more_sql .= " or " . $value_name . " " . $v['search_condition'] . " '%" . common::check_input(trim($value)) . "%'";
  127. } else {
  128. $more_sql .= " or " . $value_name . " " . $v['search_condition'] . " '" . common::check_input(trim($value)) . "'";
  129. }
  130. }
  131. }
  132. if ($more_sql <> "1<>1"){
  133. $result .= " and ($more_sql)";
  134. }
  135. }
  136. }
  137. }
  138. }
  139. return $result;
  140. }
  141. public function getDisplayColumn($model_name, $isin = true) {
  142. $rs = null;
  143. $sql = "select ids from public.ra_online_search_config where lower(login_name)='" . strtolower(_getLoginName()) . "' and lower(model_name) = '" . strtolower($model_name) . "'";
  144. $rs = common::excuteOneSql($sql);
  145. if (empty($rs)) {
  146. $sql = "select array_to_string(array(select id from public.ra_online_search where active = true and default_display = true and lower(model_name) = '" . strtolower($model_name) . "'";
  147. if (_isCustomerLogin())
  148. $sql .= " and customer_display = true";
  149. $sql .= " order by order_by asc, search_name asc), ',')";
  150. $rs = common::excuteOneSql($sql);
  151. }
  152. if ($isin) {
  153. $sql = $this->_getSql($rs, "id, search_name as name");
  154. $rss = common::excuteListSql($sql);
  155. } else {
  156. $sql = "SELECT id, search_name as name FROM public.ra_online_search WHERE active = true and lower(model_name) = '" . strtolower($model_name) . "' and id not in ($rs)";
  157. if (_isCustomerLogin())
  158. $sql .= ' and customer_display=true';
  159. $rss = common::excuteListSql($sql);
  160. }
  161. return $rss;
  162. }
  163. }
  164. ?>