search.class.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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"
  99. && (strtolower($v['value_name']) == "transport_mode"
  100. || strtolower($v['value_name']) == "incoterms"
  101. || strtolower($v['value_name']) == "service")){
  102. //transport_mode todo
  103. //incoterms 和 service特殊处理
  104. if(!empty($_POST[$v['value_name']])){
  105. //前台这个字段,All是字符串,其他值的提交过来的是数组
  106. $value_arr = $_POST[$v['value_name']];
  107. if(!is_array($value_arr)){
  108. $value_arr = array($value_arr);
  109. }
  110. $value_sql = "1<>1";
  111. foreach($value_arr as $val){
  112. if(strtolower($val) == "all"){
  113. continue;
  114. }else{
  115. $value_sql .= " or lower(".$v['value_name'].") = '".strtolower($val)."'";
  116. }
  117. }
  118. if ($value_sql <> "1<>1"){
  119. $result .= " and ($value_sql)";
  120. }
  121. }
  122. } else {
  123. if ($v['search_condition'] == '>=,<=') {
  124. $s = $v['value_name'] . '_start';
  125. $e = $v['value_name'] . '_end';
  126. if (isset($_POST[$s]) && !empty($_POST[$s])) {
  127. $result .= " and " . $v['value_name'] . " >= '" . common::check_input(common::usDate2sqlDate($_POST[$s]) . ' 00:00:00') . "'";
  128. }
  129. if (isset($_POST[$e]) && !empty($_POST[$e])) {
  130. $result .= " and " . $v['value_name'] . " <= '" . common::check_input(common::usDate2sqlDate($_POST[$e]) . ' 23:59:59') . "'";
  131. }
  132. } else {
  133. //处理多个输入查询情况包含一个 数组类型,也有可能单个字符串
  134. $value_arr = $_POST[$v['value_name']];
  135. if(!is_array($value_arr)){
  136. $value_arr = array($value_arr);
  137. }
  138. $more_sql = "1<>1";
  139. foreach($value_arr as $value){
  140. //处理合并查询 包含一个
  141. $value_name_arr = explode("/", $v['value_name']);
  142. foreach($value_name_arr as $value_name){
  143. if ($v['is_int'] == 't') {
  144. $more_sql .= " or " . " " . $value_name . " " . $v['search_condition'] . " " . trim($value);
  145. } elseif ($v['search_condition'] == 'ilike') {
  146. $more_sql .= " or " . $value_name . " " . $v['search_condition'] . " '" . common::check_input(trim($value)) . "%'";
  147. } elseif ($v['search_condition'] == 'like') {
  148. $more_sql .= " or " . $value_name . " " . $v['search_condition'] . " '%" . common::check_input(trim($value)) . "%'";
  149. } else {
  150. $more_sql .= " or " . $value_name . " " . $v['search_condition'] . " '" . common::check_input(trim($value)) . "'";
  151. }
  152. }
  153. }
  154. if ($more_sql <> "1<>1"){
  155. $result .= " and ($more_sql)";
  156. }
  157. }
  158. }
  159. }
  160. }
  161. return $result;
  162. }
  163. public function getDisplayColumn($model_name, $isin = true) {
  164. $rs = null;
  165. $sql = "select ids from public.ra_online_search_config where lower(login_name)='" . strtolower(_getLoginName()) . "' and lower(model_name) = '" . strtolower($model_name) . "'";
  166. $rs = common::excuteOneSql($sql);
  167. if (empty($rs)) {
  168. $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) . "'";
  169. if (_isCustomerLogin())
  170. $sql .= " and customer_display = true";
  171. $sql .= " order by order_by asc, search_name asc), ',')";
  172. $rs = common::excuteOneSql($sql);
  173. }
  174. if ($isin) {
  175. $sql = $this->_getSql($rs, "id, search_name as name");
  176. $rss = common::excuteListSql($sql);
  177. } else {
  178. $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)";
  179. if (_isCustomerLogin())
  180. $sql .= ' and customer_display=true';
  181. $rss = common::excuteListSql($sql);
  182. }
  183. return $rss;
  184. }
  185. }
  186. ?>