forked from cfinke/anyInventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
executable file
·116 lines (89 loc) · 3.67 KB
/
search.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
<?php
require_once("globals.php");
$title = SEARCH_RESULTS;
$breadcrumbs = SEARCH_RESULTS.": ".stripslashes($_GET["q"]);
$search_terms = explode(" ",$_GET["q"]);
$search_fields = array("name");
$output .= '<table>';
if (is_array($search_terms)){
if ((count($search_terms) == 1) && (is_numeric($search_terms[0]))){
$search_query = "SELECT " . $db->quoteIdentifier('id') . " FROM " . $db->quoteIdentifier('anyInventory_items') . " WHERE " . $db->quoteIdentifier('id') . "='".$search_terms[0]."'";
$search_result = $db->query($search_query);
if(DB::isError($search_result)) die($search_result->getMessage().'<br /><br />'.SUBMIT_REPORT . '<br /><br />'. $search_query);
if ($search_result->numRows() > 0){
$row = $search_result->fetchRow();
$item = new item($row["id"]);
if ($view_user->can_view($item->category->id)){
$output .= '
<tr class="tableHeader">
<td colspan="2">'.ID_MATCH.'</td>
</tr>';
$output .= '
<tr>
<td>'.$item->id.'</td>
<td>'.$item->export_teaser().'</td>
</tr>';
}
}
}
$search_query = "SELECT " . $db->quoteIdentifier('id') . " FROM " . $db->quoteIdentifier('anyInventory_items') . " WHERE 1 AND ";
foreach($search_terms as $search_term){
$search_query .= " " . $db->quoteIdentifier('name') . " LIKE '%".$search_term."%' AND ";
}
$search_query = substr($search_query,0,strlen($search_query) - 5);
$search_result = $db->query($search_query);
if(DB::isError($search_result)) die($search_result->getMessage().'<br /><br />'.SUBMIT_REPORT . '<br /><br />'. $search_query);
if ($search_result->numRows() > 0){
$output .= '
<tr class="tableHeader">
<td colspan="2">'.NAME_MATCH.'</td>
</tr>';
while ($row = $search_result->fetchRow()){
$item = new item($row["id"]);
if ($view_user->can_view($item->category->id)){
$output .= '
<tr>
<td>'.$item->id.'</td>
<td>'.$item->export_teaser().'</td>
</tr>';
}
}
}
$search_query = "SELECT " . $db->quoteIdentifier('item_id') . ", COUNT(" . $db->quoteIdentifier('item_id') . ") AS " . $db->quoteIdentifier('num_matches') . " FROM " . $db->quoteIdentifier('anyInventory_values') . " WHERE 1 AND ( ";
if (is_array($search_terms)){
foreach($search_terms as $search_term){
$search_query .= " " . $db->quoteIdentifier('value') . " LIKE '%".$search_term."%' OR ";
}
}
$search_query = substr($search_query,0,strlen($search_query) - 4).") GROUP BY " . $db->quoteIdentifier('item_id') . " ORDER BY " . $db->quoteIdentifier('num_matches') . " DESC";
$search_result = $db->query($search_query);
if(DB::isError($search_result)) die($search_result->getMessage().'<br /><br />'.SUBMIT_REPORT . '<br /><br />'. $search_query);
if ($search_result->numRows() > 0){
$output .= '
<tr class="tableHeader">
<td colspan="2">'.SEARCH_RESULTS.'</td>
</tr>';
while ($row = $search_result->fetchRow()){
$item = new item($row["item_id"]);
if ($view_user->can_view($item->category->id)){
$output .= '<tr>';
if ($item->category->auto_inc_field){
$output .= '<td>'.$item->id.'</td>';
}
else{
$output .= '<td> </td>';
}
$output .= '<td>'.$item->export_teaser().'</td></tr>';
}
}
}
else{
$output .= '<tr class="tableHeader"><td colspan="2">'.NO_RESULTS.'</td></tr><tr><td class="tableData" colspan="2">'.NO_MATCHING_ITEMS.'</td></tr>';
}
}
else{
$output .= '<tr class="tableHeader"><td colspan="2">'.NO_RESULTS.'</td></tr><tr><td class="tableData" colspan="2">'.NO_MATCHING_ITEMS.'</td></tr>';
}
$output .= '</table>';
display($output);
?>