search.php
7.33 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
/*
* search.php
*
* Copyright (c) 1999-2002 The Owl Project Team
* Licensed under the GNU GPL. For full terms see the file COPYING.
*
* $Id$
*/
require("./config/owl.php");
require("./lib/owl.lib.php");
require("./config/html.php");
require("./lib/security.lib.php");
function find_path($parent) {
global $default;
$path = fid_to_name($parent);
$sql = new Owl_DB;
while($parent != 1) {
$sql->query("select parent from $default->owl_folders_table where id = '$parent'");
while($sql->next_record()) {
$path = fid_to_name($sql->f("parent"))."/".$path;
$parent = $sql->f("parent");
}
}
return $path;
}
// BEGIN patch Scott Tigr
// patch for layout
include("./lib/header.inc");
print("<TABLE WIDTH=$default->table_expand_width BGCOLOR=$default->main_header_bgcolor CELLSPACING=0 CELLPADDING=0 BORDER=$default->table_border HEIGHT=30>");
print("<TR><TD WIDTH=200 VALIGN=TOP>");
print("<TR>");
print("<TD ALIGN=LEFT WIDTH=33%>");
print uid_to_name($userid);
print(" : <A HREF='index.php?login=logout&sess=$sess'>$lang_logout</A></TD>");
print("<TD ALIGN=CENTER WIDTH=33%> </TD>");
print("<TD ALIGN=RIGHT WIDTH=33%> <A HREF='../browse.php?sess=$sess'><IMG SRC='$default->owl_root_url/locale/$language/graphics/btn_browse.gif' BORDER=0></A> </TD>");
print("</TR>");
print("</TABLE>");
print "<center>";
print "<br>";
if ($expand == 1) { // long view
print("\t\t<TABLE WIDTH=\"".$default->table_expand_width."\" border=\"0\">\n");
} else {
print("\t\t<TABLE WIDTH=$default->table_collapse_width>\n");
}
print("\t\t\t<tr><td align=\"left\"><b style=\"color:#0000aa;\">".$lang_search.":</b> ");
print(gen_navbar($parent) . "</td></tr></table>");
// END patch Scott Tigr
$groupid = owlusergroup($userid);
// first we have to find out what we can search
// we need a list of all folder that can be searched
// so we need to see which folders the user can read
$sql = new Owl_DB;
$sql->query("SELECT id,creatorid,groupid,security FROM $default->owl_folders_table");
//
// get all the folders that the user can read
while($sql->next_record()) {
$id = $sql->f("id");
if(check_auth($id, "folder_view", $userid) == 1) $folders[$id] = $id;
}
//
// get all the files in those folders that the user can read
foreach($folders as $item) {
$sql->query("SELECT * FROM $default->owl_files_table where parent = '$item'");
while($sql->next_record()) {
$id = $sql->f("id");
if(check_auth($id, "file_download", $userid) == 1) {
$files[$id][id] = $id;
$files[$id][n] = $sql->f("name");
$files[$id][m] = explode(" ", $sql->f("metadata"));
$files[$id][d] = explode(" ", $sql->f("description"));
$files[$id][f] = $sql->f("filename");
$files[$id][c] = $sql->f("checked_out");
$files[$id][u] = $sql->f("url");
$files[$id][p] = $sql->f("parent");
$files[$id][score] = 0;
}
}
}
//
// right now we have the array $files with all possible files that the user has read access to
// BEGIN bufix Scott Tigr
// error_handler if query empty
if (strlen(trim($query))>0) {
// END bugfix Scott Tigr
//
// break up our query string
$query = explode(" ", $query);
//
// the is the meat of the matching
if(sizeof($files) > 0) {
foreach($query as $keyword) {
foreach(array_keys($files) as $key) {
// BEGIN enhancement Sunil Savkar
// if the $parent string contains a keyword to be searched, then the score is
// adjusted. This takes into account the hierarchy.
if(eregi("$keyword", find_path($files[$key][p]))) $files[$key][score] = $files[$key][score] + 4;
if(eregi("$keyword", $files[$key][n])) $files[$key][score] = $files[$key][score] + 4;
if(eregi("$keyword", $files[$key][f])) $files[$key][score] = $files[$key][score] + 3;
foreach($files[$key][m] as $metaitem) {
// add 2 to the score if we find it in metadata (key search items)
if(eregi("$keyword", $metaitem)) $files[$key][score] = $files[$key][score] + 2;
}
foreach($files[$key][d] as $descitem) {
// only add 1 for regular description matches
if(eregi("$keyword", $descitem)) $files[$key][score] = $files[$key][score] + 1;
}
}
}
}
//
// gotta find order to the scores...any better ideas?
print "$lang_search_results_for \"".implode(" ", $query)."\"<BR><BR><HR WIDTH=200 ALIGN=CENTER><BR>";
$max = 30;
$hit = 1;
$CountLines = 0;
$iconfiles = array("html","htm","gif","jpg","bmp","zip","tar","doc","mdb","xls","ppt","pdf","gz","mp3","tgz");
if(sizeof($files) > 0) {
while($max > 0) {
foreach(array_keys($files) as $key) {
if($files[$key][score] == $max) {
$name = find_path($files[$key][p])."/".$files[$key][n];
$filename = $files[$key][f];
$choped = split("\.", $filename);
$pos = count($choped);
$ext = strtolower($choped[$pos-1]);
print("<TABLE WIDTH=$default->table_expand_width BORDER=$default->table_border CELLSPACING=1 CELLPADDING=1>");
$CountLines++;
$PrintLines = $CountLines % 2;
if ($PrintLines == 0)
print("<TR BGCOLOR='$default->table_cell_bg_alt'>");
else
print("<TR BGCOLOR='$default->table_cell_bg'>");
print "<TD ALIGN=CENTER width=5%>";
//for ($i=$max; $i>0; $i--) {
//}
$t_score = $max;
for ($c=$max; $c>=1; $c--) {
if ( $t_score >= 10) {
if ( 0 == ($c % 10)) {
print "<IMG SRC='$default->owl_root_url/graphics/star10.gif' BORDER=0>";
$t_score = $t_score - 10;
}
} else {
if ( (0 == ($t_score % 2)) && $t_score > 0 ) {
print "<IMG SRC='$default->owl_root_url/graphics/star.gif' BORDER=0>";
}
$t_score = $t_score - 1;
}
}
//print "<BR>($lang_score $max)";
print "</TD>";
print("<TD ALIGN=LEFT WIDTH=40%>");
print "$hit. <A HREF='download.php?sess=$sess&id=".$files[$key][id]."&parent=".$files[$key][p]."'>".$name."</A></TD>";
print("<TD ALIGN=LEFT WIDTH=15%>");
if ($files[$key][u] == "1")
print("<IMG SRC='$default->owl_root_url/locale/$default->owl_lang/graphics/icons/url.gif' BORDER=0> ");
else {
if (preg_grep("/$ext/",$iconfiles))
print("<IMG SRC='$default->owl_root_url/locale/$default->owl_lang/graphics/icons/$ext.jpg' BORDER=0> ");
else
print("<IMG SRC='$default->owl_root_url/locale/$default->owl_lang/graphics/icons/file.gif' BORDER=0> ");
}
print("  $filename</TD>");
print("<TD ALIGN=LEFT width=10%>");
printFileIcons($files[$key][id],$name,$files[$key][c],$files[$key][u],$default->owl_version_control,$ext);
print("</TD></TR></TABLE>");
//print "<TABLE><TR><TD WIDTH=10></TD><TD Align=left>".implode(" ", $files[$key][d])."</TD></TR></TABLE><BR>";
$hit++;
}
}
$max--;
}
}
print "<HR WIDTH=\"".$default->table_expand_width."\" ALIGN=\"center\"><BR>";
print "<A HREF='browse.php?sess=$sess&parent=$parent&expand=$expand'><IMG SRC='$default->owl_root_url/locale/$language/graphics/btn_browse.gif' BORDER=0></A><P></P>";
// BEGIN bugfix Scott Tigr
// error_handler if query empty
} // end of check strlen(query)
else { // if query was empty
print("<p>" . $lang_query_empty . "</p>");
}
include("./lib/footer.inc");
// END bugfix Scott Tigr
?>