-
Notifications
You must be signed in to change notification settings - Fork 15
/
search_all.php
201 lines (126 loc) · 4.45 KB
/
search_all.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
require("./inc/conn.php");
require("./inc/layouts.php");
proteggi(1);
function search_all($s, $only_visible=true, $exact=false, $views=true, $max_res_x_tab=10){
global $vmsql, $db1;
if($s=='') return null;
$tab=RegTools::prendi_tabelle(User_Session::gid(),$only_visible,!$views);
$stat['n_tabelle']=count($tab);
$stat['n_campi']=0;
$cols=array();
foreach($tab as $t){
list($cols[$t['table_name']])=RegTools::prendi_colonne_frontend($t['table_name'],"column_name,table_type",$only_visible,User_Session::gid());
}
$sql_all=array();
// Ricerca
foreach($cols as $tabella=>$campo){
$sql=array();
$stat['n_campi']+=count($campo);
for($i=0;$i<count($campo);$i++){
if($exact){
$sql0=" SELECT '$tabella' tabella, '{$campo[$i]}' campo, count(*) n FROM $tabella WHERE _utf8 {$campo[$i]} COLLATE utf8_unicode_ci ='$s' \n";
$sql[]= ($db1['dbtype']=='mysql')
? $sql0 : str_replace(array("_utf8","COLLATE utf8_unicode_ci"),"",$sql0);
}
else{
$sql0=" SELECT '$tabella' tabella, '{$campo[$i]}' campo, count(*) n FROM $tabella WHERE {$campo[$i]} LIKE _utf8 '%$s%' COLLATE utf8_unicode_ci \n";
$sql[]= ($db1['dbtype']=='mysql')
? $sql0 : str_replace(array("_utf8","COLLATE utf8_unicode_ci"),"",$sql0);
}
}
$sql_all[]=implode(" UNION \n",$sql);
}
$sql_final= "SELECT * FROM (".implode(" UNION ",$sql_all).") tt WHERE n>0";
$t0=microtime(true);
$q=$vmsql->query($sql_final);
$t1=microtime(true);
$n=$vmsql->num_rows($q);
if($n>0){
$mat=$vmsql->fetch_assoc_all($q);
}
else{
$mat=null;
}
$stat['t']=($t1-$t0);
return array($mat,$stat);
}
$ss=(isset($_GET['s'])) ? trim($_GET['s']) : "";
$exact=(isset($_GET['e']) && $_GET['e']==1) ? 1:0;
$view_search=(isset($_GET['view_search']) && $_GET['view_search']==0) ? '':"checked=\"checked\"";
$exact_search=(!isset($_GET['e']) || $_GET['e']==0) ? '':"checked=\"checked\"";
$files=array("sty/tabelle.css","sty/admin.css","js/confirm_delete.js");
$title_pag = _("Global search");
echo openLayout1($title_pag,$files);
echo breadcrumbs(array("HOME",strtolower($title_pag)));
echo "<h1><img src=\"./img/search.png\" alt=\"search\" style=\"vertical-align:middle\" /> ".$title_pag."</h1>\n";
echo "<form action=\"" . Common::phpself() . "\" method=\"get\">
<p><label for=\"s\">"._('Search the entire database').":</label>
<input type=\"text\" size=\"80\" id=\"s\" name=\"s\" value=\"$ss\" tabindex=\"1\" />
<input type=\"submit\" value=\""._('Search')."\" tabindex=\"3\" />
<input type=\"hidden\" value=\"0\" name=\"view_search\" />
<br />
<input type=\"checkbox\" id=\"view_search\" value=\"1\" name=\"view_search\" $view_search tabindex=\"2\" />
<label for=\"view_search\">"._('Search also in Views')."</label>
<br />
<input type=\"checkbox\" id=\"e\" value=\"1\" name=\"e\" $exact_search tabindex=\"3\" />
<label for=\"e\">"._('Exact search')."</label>
</p>
</form>\n";
if(isset($_GET['s'])){
$s=trim($vmsql->escape($_GET['s']));
$only_visibile = (User_Session::level()<3) ? true:false;
// $only_visibile = true;
$also_view= (bool) $_GET['view_search'];
list($res,$stat) = search_all($s,$only_visibile,$exact,$also_view);
if($res!=null){
echo "<div id=\"risultati\">
<p>"
.sprintf(_('The word %s has been found in %s fields/tables:'),
"<strong>$ss</strong>","<strong>".count($res)."</strong>").
"</p>\n";
echo "<table class=\"tab-color\" summary=\"res\" border=\"1\">";
echo "<tr>
<th>"._('table')."</th>
<th>"._('field')."</th>
<th>"._('occurrences')."</th>
<th>"._('see')."</th>
</tr>\n";
foreach($res as $val){
echo "<tr>\n";
foreach($val as $v){
echo "<td>".$v."</td>\n";
}
$oid= RegTools::name2oid($val['tabella'],User_Session::gid());
if(RegTools::is_tabella_by_oid($oid,true)){
if(!$exact){
$sqs='*'.$s.'*';
}
else{
$sqs=$s;
}
echo "<td><a href=\"./scheda.php?oid=".$oid."&qs=".urlencode("dati[".$val['campo']."]")."=".$sqs."\">"._('show results')."</a></td>\n";
}
else{
echo "<td> - </td>\n";
}
echo "</tr>\n";
}
echo "</table></div>\n";
}
elseif ($s==''){
print "<p>"._('You have not searched anything!')."</p>\n";
}
else{
print "<p>".sprintf(_('No results for %s'),"<strong>".$ss."</strong>")."</p>\n";
}
}
else{
$s='';
}
if($s!=''){
echo "<p class=\"grigio piccolo\">"
.sprintf(_('Search on %d tables, %d fields in %01.4f seconds'),$stat['n_tabelle'],$stat['n_campi'],$stat['t'])
."</p>\n";
}
echo closeLayout1();