standardSearchUI.inc
9.68 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
<?php
/**
* $Id$
*
* Presentation functionality used to searchDocumentBL.php.
*
* Copyright (c) 2003 Jam Warehouse http://www.jamwarehouse.com
*
* This program 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.
*
* This program 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @version $Revision$
* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa
* @package search
*/
function getHeading() {
return renderHeading(_("Standard Search"));
}
function getMessage() {
$sRefreshMessage = "<table><tr><td align=\"center\">" . _("If your browser displays a 'Warning: Page has Expired' message when you attempt to return to these search results, please click your browser's 'Refresh' button") . "</td></tr></table>";
}
function getSearchResultsByCategory($iFolderID, $sKeywords, $iStartIndex, $sCategory) {
global $default;
// XXX: Icky MySQL-specific stuff.
$sVersion = DBUtil::getOneResultKey("SHOW VARIABLES LIKE 'version'", "Value");
if ((int)substr($sVersion, 0, 1) >= 4) {
$boolean_mode = "IN BOOLEAN MODE";
} else {
$boolean_mode = "";
}
/*ok*/ $sQuery = "SELECT DISTINCT '" . "$default->graphicsUrl/widgets/dfolder.gif" . "' AS folder_image_url, " .
"F.id AS folder_id, D.id AS document_id, D.name AS document_name, " .
"ROUND(MATCH(DT.document_text) AGAINST (? $boolean_mode) OR 1, 3) AS score " .
"FROM $default->documents_table AS D INNER JOIN $default->document_text_table AS DT ON D.id = DT.document_id " .
"INNER JOIN $default->document_fields_link_table AS DFL ON DT.document_id=DFL.document_id " .
"INNER JOIN $default->document_fields_table AS DF ON DF.id = DFL.document_field_id " .
"INNER JOIN $default->status_table AS SL ON D.status_id = SL.id " .
"INNER JOIN $default->folders_table AS F on F.ID = D.folder_id " .
"INNER JOIN $default->search_permissions_table AS SDUL ON SDUL.document_id = D.id " .
"WHERE MATCH(DT.document_text) AGAINST (? $boolean_mode) " .
"AND (F.is_public OR SDUL.user_id = ?) " .
"AND SL.name='Live' ";
$aParams = array($sKeywords, $sKeywords, $_SESSION["userID"]);
//only check in the parent_folder_ids if we're not searching from the
//root folder down
if (isset($iFolderID) && ($iFolderID != 1)) {
$iFolderID = (int)$iFolderID;
$sQuery .= "AND (F.parent_folder_ids LIKE '%,$iFolderID,%' OR F.id = $iFolderID) ";
}
$sQuery .= "AND DF.name LIKE 'Category' ";
if (isset($sCategory)) {
$sQuery .= "AND DFL.value LIKE ? ";
$aParams[] = $sCategory;
}
$sQuery .= "ORDER BY score DESC";
$aColumns = array("folder_image_url", "document_name","score");
$aColumnTypes = array(4,3,1);
$aColumnHeaders = array("<font color=\"ffffff\">" . _("Folder") . "</font>","<font color=\"ffffff\">" . _("Document") . "</font>","<font color=\"ffffff\">" . _("Score") . "</font>");
$aLinkURLs = array("$default->rootUrl/control.php?action=browse","$default->rootUrl/control.php?action=viewDocument");
$aDBQueryStringColumns = array("document_id","folder_id");
$aQueryStringVariableNames = array("fDocumentID", "fFolderID");
$oPatternBrowse = & new PatternBrowseableSearchResults(array($sQuery, $aParams), 10, $aColumns, $aColumnTypes, $aColumnHeaders, $aLinkURLs, $aDBQueryStringColumns, $aQueryStringVariableNames);
$oPatternBrowse->setStartIndex($iStartIndex);
$oPatternBrowse->setSearchText($sKeywords);
return getHeading() . $oPatternBrowse->render() . getSearchVariablesHtml($sKeywords, "category", $iFolderID, "", $sCategory, "") . getMessage();
}
function getSearchResultsByDocumentType($iFolderID, $sKeywords, $iStartIndex, $iDocTypeID) {
global $default;
// XXX: Icky MySQL-specific stuff.
$sVersion = DBUtil::getOneResultKey("SHOW VARIABLES LIKE 'version'", "Value");
if ((int)substr($sVersion, 0, 1) >= 4) {
$boolean_mode = "IN BOOLEAN MODE";
} else {
$boolean_mode = "";
}
/*ok*/ $sQuery = "SELECT DISTINCT '" . "$default->graphicsUrl/widgets/dfolder.gif" . "' AS folder_image_url, " .
"F.id AS folder_id, D.id AS document_id, D.name AS document_name, " .
"ROUND(MATCH(DT.document_text) AGAINST (? $boolean_mode),3) AS score " .
"FROM $default->documents_table AS D INNER JOIN $default->document_text_table AS DT ON D.id = DT.document_id " .
"INNER JOIN $default->status_table AS SL ON D.status_id = SL.id " .
"INNER JOIN $default->folders_table AS F on F.ID = D.folder_id " .
"INNER JOIN $default->search_permissions_table AS SDUL ON SDUL.document_id = D.id " .
"WHERE MATCH(DT.document_text) AGAINST (? $boolean_mode) " .
"AND (F.is_public OR SDUL.user_id = ?) ";
$aParams = array($sKeywords, $sKeywords, $_SESSION["userID"]);
if (isset($iDocTypeID)) {
$sQuery .= "AND D.document_type_id = ? ";
$aParams[] = $iDocTypeID;
}
$sQuery .= "AND SL.name='Live' ";
//only check in the parent_folder_ids if we're not searching from the
//root folder down
if (isset($iFolderID) && ($iFolderID != 1)) {
$iFolderID = (int)$iFolderID;
$sQuery .= "AND (F.parent_folder_ids LIKE '%,$iFolderID,%' OR F.id = $iFolderID) ";
}
$sQuery .= "ORDER BY score DESC";
$aColumns = array("folder_image_url", "document_name","score");
$aColumnTypes = array(4,3,1);
$aColumnHeaders = array("<font color=\"ffffff\">" . _("Folder") . "</font>","<font color=\"ffffff\">" . _("Document") . "</font>","<font color=\"ffffff\">" . _("Score") . "</font>");
$aLinkURLs = array("$default->rootUrl/control.php?action=browse","$default->rootUrl/control.php?action=viewDocument");
$aDBQueryStringColumns = array("document_id","folder_id");
$aQueryStringVariableNames = array("fDocumentID", "fFolderID");
$oPatternBrowse = & new PatternBrowseableSearchResults(array($sQuery, $aParams), 10, $aColumns, $aColumnTypes, $aColumnHeaders, $aLinkURLs, $aDBQueryStringColumns, $aQueryStringVariableNames);
$oPatternBrowse->setStartIndex($iStartIndex);
$oPatternBrowse->setSearchText($sKeywords);
return getHeading() . $oPatternBrowse->render() . getSearchVariablesHtml($sKeywords, "documentType", $iFolderID, "", "", $iDocTypeID) . getMessage();
}
function getSeachResultsByFolder($iFolderID, $iStartIndex, $sKeywords) {
global $default;
// XXX: Icky MySQL-specific stuff.
$sVersion = DBUtil::getOneResultKey("SHOW VARIABLES LIKE 'version'", "Value");
if ((int)substr($sVersion, 0, 1) >= 4) {
$boolean_mode = "IN BOOLEAN MODE";
} else {
$boolean_mode = "";
}
/*ok*/ $sQuery = "SELECT DISTINCT '" . "$default->graphicsUrl/widgets/dfolder.gif" . "' AS folder_image_url, " .
"F.id AS folder_id, D.id AS document_id, D.name AS document_name, " .
"ROUND(MATCH(DT.document_text) AGAINST (? $boolean_mode),3) AS score " .
"FROM $default->documents_table AS D INNER JOIN $default->document_text_table AS DT ON D.id = DT.document_id " .
"INNER JOIN $default->status_table AS SL ON D.status_id = SL.id " .
"INNER JOIN $default->folders_table AS F on F.ID = D.folder_id " .
"INNER JOIN $default->search_permissions_table AS SDUL ON SDUL.document_id = D.id " .
"WHERE MATCH(DT.document_text) AGAINST (? $boolean_mode) " .
"AND (F.is_public OR SDUL.user_id = ?) " .
"AND SL.name='Live' ";
$aParams = array($sKeywords, $sKeywords, $_SESSION["userID"]);
//only check in the parent_folder_ids if we're not searching from the
//root folder down
if (isset($iFolderID) && ($iFolderID != 1)) {
$iFolderID = (int)$iFolderID;
$sQuery .= "AND (F.parent_folder_ids LIKE '%,$iFolderID,%' OR F.id = $iFolderID) ";
}
$sQuery .= "ORDER BY score DESC";
$aColumns = array("folder_image_url", "document_name","score");
$aColumnTypes = array(4,3,1);
$aColumnHeaders = array("<font color=\"ffffff\">" . _("Folder") . "</font>", "<font color=\"ffffff\">" . _("Document") . "</font>", "<font color=\"ffffff\">" . _("Score") . "</font>");
$aLinkURLs = array("$default->rootUrl/control.php?action=browse","$default->rootUrl/control.php?action=viewDocument");
$aDBQueryStringColumns = array("document_id","folder_id");
$aQueryStringVariableNames = array("fDocumentID", "fFolderID");
$oPatternBrowse = & new PatternBrowseableSearchResults(array($sQuery, $aParams), 10, $aColumns, $aColumnTypes, $aColumnHeaders, $aLinkURLs, $aDBQueryStringColumns, $aQueryStringVariableNames);
$oPatternBrowse->setStartIndex($iStartIndex);
$oPatternBrowse->setSearchText($sKeywords);
return getHeading() . $oPatternBrowse->render() . getSearchVariablesHtml($sKeywords, "", $iFolderID, "", "", "") . getMessage();
}
function getSearchVariablesHtml($sSearchText, $sBrowseType, $iFolderID, $iDocumentID, $sCategoryName, $iDocType) {
$sToRender = "<input type=\"hidden\" name=\"fSearchText\" value=\"$sSearchText\" />\n";
$sToRender .= "<input type=\"hidden\" name=\"fBrowseType\" value=\"$sBrowseType\" />\n";
$sToRender .= "<input type=\"hidden\" name=\"fFolderID\" value=\"$iFolderID\" />\n";
$sToRender .= "<input type=\"hidden\" name=\"fDocumentID\" value=\"$iDocumentID\" />\n";
$sToRender .= "<input type=\"hidden\" name=\"fCategoryName\" value=\"$sCategoryName\" />\n";
$sToRender .= "<input type=\"hidden\" name=\"fDocType\" value=\"$iDocType\" />\n";
return $sToRender;
}
?>