-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkoraFileSearch.php
More file actions
executable file
·229 lines (188 loc) · 7.89 KB
/
koraFileSearch.php
File metadata and controls
executable file
·229 lines (188 loc) · 7.89 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
221
222
223
224
225
226
227
228
229
<?php
use KORA\Manager;
/**
Copyright (2008) Matrix: Michigan State University
This file is part of KORA.
KORA is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
KORA is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
// Initial Version: Brian Beck, 2008
// Refactor: Joe Deming, Anthony D'Onofrio 2013
require_once("includes/includes.php");
Manager::Init();
Manager::RequireLogin();
Manager::PrintHeader();
if (!@$solr_enabled) die("Solr is not enabled in includes/conf.php! KORA File Search cannot work.");
?>
<h2>Search Contents of Files in KORA</h2>
<form method="POST" action="koraFileSearch.php">
<table class="table">
<tr>
<td>
<b>Project</b>
</td>
<td>
<select id="pid" name="pid"></select>
</td>
</tr>
<tr>
<td>
<b>Scheme</b>
</td>
<td>
<select id="sid" name="sid"></select>
</td>
<tr>
<td>
<b>Keywords</b>
</td>
<td>
<input type="text" name="query" size="30" value="<?php if (Manager::CheckRequestsAreSet(["query"])) echo $_REQUEST["query"];?>">
</td>
</tr>
<tr><td colspan="2"><input type="submit" value="Search"></td></tr>
</table>
</form>
<script type="text/javascript">
$("#pid").load("listOptions.php"); // Populate the lists initially
$("#pid").change( function() { updateSIDs($("#pid").val()) } ); // When the PID selector gets changed, update the SID selector
function updateSIDs(pidtemp)
{
$("#sid").load("listOptions.php", {"pid": pidtemp}); // AJAX call this page, posting the PID that is selected
}
</script>
<?php
$query = null;
$pid = null;
$sid = null;
if ( Manager::CheckRequestsAreSet(["query"]) ) $query = $_REQUEST["query"];
if ( Manager::CheckRequestsAreSet(["pid"]) )
{
$pid = $_REQUEST["pid"];
if ($pid == "null") $pid = null; // The null option in the list was selected
else $pid = dechex($pid);
}
if ( Manager::CheckRequestsAreSet(["sid"]) )
{
$sid = $_REQUEST["sid"];
if ($sid == "null") $sid = null; // The null option in the list was selected
else $sid = dechex($sid);
}
if ( $query != null && @$solr_enabled )
{
$start_time = microtime(true); // Start a timer
// urlencode to ensure spaces and other special characters don't blow things up
$query = urlencode(addslashes($_REQUEST["query"]));
$req_url = solr_url."select/?q=".$query."&fl=id&rows=10000&indent=on";
$ch = curl_init($req_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Return the data instead of true/false
$xml_result = curl_exec($ch); // Execute the search in Solr
$search_time = microtime(true); // Start a timer for when the search was completed
// If for some reason Curl could not successfully connect, Solr probably isn't running, print an error
if (curl_errno($ch) != 0)
{
echo "ERROR: Could not connect to Solr. Please ensure that Solr is running on the server.";
Manager::PrintFooter();
return;
}
curl_close($ch); // Close the channel
echo "<strong>Ranked Results:</strong><br /><br />";
echo "<table style=\"border:0;\" cellspacing=5>";
echo "<tr><td><strong>Project Name</strong></td><td><strong>Record</strong></td><td><strong>File</strong></td></tr>";
$xml = new SimpleXMLElement($xml_result); // Parse $xml_result
$fullResults = (int)$xml->result->attributes()->numFound; // Determine number of results to iterate over
$trueResults = 0; // Actual number of results that will be printed to the screen
for($i = 0; $i < $fullResults; $i++)
{
$rid_cid = (string)$xml->result->doc[$i]->str; // Extract the RID-CID from each result
$rid_array = explode('-', $rid_cid); // Make an array
$rid = "$rid_array[0]-$rid_array[1]-$rid_array[2]"; // Put together the RID
$cid = $rid_array[3];
// Gets the URL for the file from clientUtilities.php
// Used to make a link to the file
$urlToFile = getURLFromRecordID($rid, $cid);
if ($pid != null) // Search one project only
{
if ($sid != null) // Search one scheme only
{
if ($pid == $rid_array[0] && $sid == $rid_array[1]) // Print only matching PIDs and SIDs
{
printLink($rid, $cid);
$trueResults++;
}
}
else // Searching one project but all schemes
{
if ($pid == $rid_array[0])
{
printLink($rid, $cid);
$trueResults++;
}
}
}
else // Searching all projects.
{
if( getUserPermissions(hexdec($rid_array[0])) != 0 || isProjectAdmin() || isSystemAdmin() ) // Check permissions
{
printLink($rid, $cid);
$trueResults++;
}
}
}
// Stop the timers and spit out some facts about the search
$end_time = microtime(true);
$total_time = $end_time - $start_time;
$total_time = 1000 * round($total_time, 4);
$search_time = 1000 * round($search_time - $start_time, 4);
$parse_time = round($total_time - $search_time, 4);
echo "</table>";
echo "<br />Generated $trueResults result(s) in $total_time milliseconds.<br />";
echo "Searching the index required $search_time milliseconds. Parsing results required $parse_time milliseconds.<br />";
}
// Prints the row in the table which is a link to the record and to the file itself
function printLink($rid, $cid)
{
$rid_array = explode("-", $rid);
$pid = hexdec($rid_array[0]);
$ridEscaped = escape($rid);
global $db;
$query = "SELECT name FROM project WHERE pid=$pid LIMIT 1";
$query = $db->query($query);
$query = $query->fetch_assoc();
// The project name for printing in the table
$projectName = $query["name"];
$query = "SELECT value FROM p{$pid}Data WHERE id=$ridEscaped AND cid=$cid";
$query = $db->query($query);
// make sure data was returned
if($query->num_rows == 1)
{
$fileInfo = $query->fetch_assoc();
$fileInfo = simplexml_load_string($fileInfo['value']);
// The original filename for printing the link below
$filename = $fileInfo->originalName;
$type = $fileInfo->type;
$type = explode(";", $type);
$type = $type[0];
}
// Get the URL to the record (trivial)
$urlToRecord = "viewObject.php?rid=$rid";
// Get the URL to the file
$urlToFile = getURLFromRecordID($rid, $cid);
// Print out the row in the table
echo "<tr><td>$projectName</td><td><a href=\"$urlToRecord\">$rid</a></td>";
echo "<td><img style=\"border:0\" height=18 width=18 src=\"images/";
// Prints out a pretty icon appropriate for the document type. Simple type checking.
if ($type == "application/msword" ) echo "doc";
else if ($type == "application/pdf" || $type == "application/x-pdf") echo "pdf";
else echo "txt";
echo "Icon.jpg\" alt=Document></img> <a href=\"$urlToFile\">$filename</a></td></tr>";
}
Manager::PrintFooter();
?>