/[health_html]/inc/search.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /inc/search.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (show annotations)
Mon Oct 29 14:43:21 2001 UTC (17 years, 9 months ago) by ravilov
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +15 -8 lines
Added a new page (Farmaceutski glasnik) to plivamed. Other improvements/fixes.

1 <?php
2 $basic_logic = "AND";
3 function Search($fields, $q1_fields, $q2_fields, $def_field = "") {
4 global $go;
5 $tp = new Smarty();
6 $qry_1 = "";
7 $qry_2 = "";
8 $form = "";
9 global $stype;
10 if ($stype) {
11 $search = array();
12 $i = 1;
13 while (true) {
14 global ${"search_".$i};
15 if (!${"search_".$i}) break;
16 global ${"delete_".$i}, ${"and_".$i}, ${"or_".$i},
17 ${"field_".$i}, ${"not_".$i},
18 ${"query_".$i}, ${"logic_".$i},
19 ${"concat_".$i}, ${"case_".$i};
20 if (${"delete_".$i}) { $go = false; $i++; continue; }
21 if (${"and_".$i}) { $go = false; ${"logic_".$i} = "AND"; }
22 if (${"or_".$i}) { $go = false; ${"logic_".$i} = "OR"; }
23 array_push($search, array(
24 "field" => ${"field_".$i},
25 "not" => ${"not_".$i},
26 "query" => MyEscape(${"query_".$i}, true),
27 "logic" => ${"logic_".$i},
28 "concat" => ${"concat_".$i},
29 "case" => ${"case_".$i}
30 ));
31 $i++;
32 }
33 global ${"and_".($i - 1)}, ${"or_".($i - 1)};
34 if (count($search) == 0 || ${"and_".($i - 1)} || ${"or_".($i - 1)}) {
35 $go = false;
36 $log = "";
37 if (${"and_".($i - 1)}) $log = "AND";
38 if (${"or_".($i - 1)}) $log = "OR";
39 if (count($search) > 0) $search[count($search) - 1]["logic"] = $log;
40 array_push($search, array(
41 "field" => $def_field ? $def_field : "",
42 "not" => "",
43 "query" => "",
44 "logic" => "",
45 "concat" => "OR",
46 "case" => ""
47 ));
48 }
49 $search[count($search) - 1]["logic"] = "";
50 $tp->assign("search", $search);
51 } else {
52 // Nothing.
53 }
54 if (!$stype) $stype = false;
55 $tp->assign("stype", $stype);
56 if (!$stype && !$go) {
57 reset($fields);
58 while (list($k, $v) = each($fields)) {
59 $var = "go_$k";
60 global $$var;
61 if ($$var) $go = true;
62 }
63 }
64 if ($go) {
65 if ($stype) {
66 $qry = "";
67 $logic = "";
68 $i = 1;
69 while (${"search_".$i}) {
70 $field = ${"field_".$i};
71 $not = ${"not_".$i} ? " NOT" : "";
72 $qry1 = preg_split('/\s+/', ${"query_".$i});
73 $qry2 = array();
74 $qry3 = array();
75 while (list($k, $v) = each($qry1)) {
76 if (!$qry1[$k]) continue;
77 if (${"case_".$i}) $qq = "(".$fields[$field]["dbname"]."$not LIKE '%".$qry1[$k]."%')";
78 else $qq = "(UPPER(".$fields[$field]["dbname"].")$not LIKE '%".MyUpper($qry1[$k])."%')";
79 $is_q1 = false;
80 for ($j = 0; $j < count($q1_fields); $j++)
81 if ($q1_fields[$j] == $field) $is_q1 = true;
82 $is_q2 = false;
83 for ($j = 0; $j < count($q2_fields); $j++)
84 if ($q2_fields[$j] == $field) $is_q2 = true;
85 if ($is_q1) $qry2[$k] = $qq;
86 if ($is_q2) $qry3[$k] = $qq;
87 }
88 $qry1 = implode(" ".${"concat_".$i}." ", $qry2);
89 if ($qry1) {
90 if ($logic) $qry_1 .= " $logic ";
91 $qry_1 .= "($qry1)";
92 $logic = ${"logic_".$i};
93 }
94 $qry1 = implode(" ".${"concat_".$i}." ", $qry3);
95 if ($qry1) {
96 if ($logic) $qry_2 .= " $logic ";
97 $qry_2 .= "($qry1)";
98 $logic = ${"logic_".$i};
99 }
100 $i++;
101 }
102 } else {
103 reset($fields);
104 while (list($k, $v) = each($fields)) {
105 $field = $k;
106 $var = "query_".$field; global $$var;
107 $query = $$var;
108 $tp->assign($var, $$var);
109 $go1 = "go_$field";
110 if (!$$var) continue;
111 $q = preg_split('/\s+/', $query);
112 $q2 = array();
113 $q3 = array();
114 while (list($k, $v) = each($q)) {
115 if (!$q[$k]) continue;
116 $qq = "(UPPER(".$fields[$field]["dbname"].") LIKE '%".MyUpper($q[$k])."%')";
117 $is_q1 = false;
118 for ($i = 0; $i < count($q1_fields); $i++)
119 if ($q1_fields[$i] == $field) $is_q1 = true;
120 $is_q2 = false;
121 for ($i = 0; $i < count($q2_fields); $i++)
122 if ($q2_fields[$i] == $field) $is_q2 = true;
123 if ($is_q1) $q2[$k] = $qq;
124 if ($is_q2) $q3[$k] = $qq;
125 }
126 global $basic_logic;
127 $qry_1 = implode(" ".$basic_logic." ", $q2);
128 $qry_2 = implode(" ".$basic_logic." ", $q3);
129 }
130 }
131 }
132 $flds = array();
133 reset($fields);
134 while (list($k, $v) = each($fields)) {
135 $var = "query_$k";
136 global $$var;
137 array_push($flds, array(
138 "name" => MyEscape($k, true),
139 "caption" => MyEscape($v["caption"]),
140 "query" => MyEscape($$var)
141 ));
142 }
143 $tp->assign("fields", $flds);
144 global $section, $section_menu;
145 $tp->assign("section", $section);
146 $tp->assign("section_menu", $section_menu);
147 $tp->assign("FORM_ACTION", HTMLSpecialChars("?section=$section&section_menu={$section_menu}&stype=$stype"));
148 $form = $tp->fetch("search.tpl");
149 return array($form, $qry_1, $qry_2);
150 }
151 ?>

  ViewVC Help
Powered by ViewVC 1.1.26