PatternBrowsableSearchResults.inc
10.2 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?php
/**
* $Id$
*
* Renders paginated query results in a table.
*
* 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 lib.visualpatterns
*/
class PatternBrowseableSearchResults {
/** query to be executed */
var $sQuery;
/** columns in query to be displayed */
var $aColumns;
/** column types */
var $aColumnTypes;
/** column headings to display */
var $aColumnHeadings;
/** link href for column type 3 */
var $aLinkURLs;
/** database column values to append to link url if a column type of 3 is specified */
var $aDBQueryStringColumns;
/** variables names to give $aDBQueryStringColumns on the query string */
var $aQueryStringVariableNames;
/** number of results to display per page */
var $iResultsToDisplay;
/* Result number to start on */
var $iStartIndex;
/** Column to order by */
var $sOrderByColumn;
/** direction of ordering, ascending or descending */
var $sOrderDirection = "ASC";
/** New QueryString when submitting to self */
var $sQueryString;
/** Search criteria **/
var $sSearchText;
/** Advanced Search Criteria to remember **/
var $aRememberValues;
function PatternBrowseableSearchResults($sTmpQuery, $iTmpResultsToDisplay, $aTmpColumns, $aTmpColumnTypes, $aTmpColumnHeaders, $aTmpLinkURLs = null, $aTmpDBQueryStringColumns = null, $aTmpQueryStringVariableNames = null) {
$this->sQuery = $sTmpQuery;
$this->iResultsToDisplay = $iTmpResultsToDisplay;
$this->aColumns = $aTmpColumns;
$this->aColumnHeadings = $aTmpColumnHeaders;
$this->aColumnTypes = $aTmpColumnTypes;
$this->aLinkURLs = $aTmpLinkURLs;
$this->aDBQueryStringColumns = $aTmpDBQueryStringColumns;
$this->aQueryStringVariableNames = $aTmpQueryStringVariableNames;
$this->sQueryString = "";
$this->aRememberValues = array();
}
function setQueryString($sNewQueryString) {
$this->sQueryString = $sNewQueryString;
}
function getQueryString() {
return $this->sOrderByColumn;
}
function setStartIndex($iNewValue) {
$this->iStartIndex = $iNewValue;
}
function setOrderByColumn($sNewValue) {
$this->sOrderByColumn = $sNewValue;
}
function setOrderDirection($sNewValue) {
$this->sOrderDirection = $sNewValue;
}
function setSearchText($sNewValue) {
$this->sSearchText = $sNewValue;
}
function setRememberValues($aRemember) {
$this->aRememberValues = $aRemember;
}
/**
* Build the HTML string used to render the object
*
* @return String of HTML used to render object
*
* @todo possibly add in image size restraints for link types 2 and 3
*/
function & render() {
global $default;
$sSectionName = $default->siteMap->getSectionName(substr($_SERVER["PHP_SELF"], strlen($default->rootUrl), strlen($_SERVER["PHP_SELF"])));
$sTHBGColour = $default->siteMap->getSectionColour($sSectionName, "th");
// run the query first and get the number of rows
$iTotalResults = $this->getResultCount();
// now add the limit and offset stuff for cutting down result set
// decrement startIndex because LIMIT starts at zero and startIndex starts at 1 (for display purposes)
if (is_array($this->sQuery)) {
$sQuery = $this->sQuery[0];
$aParams = $this->sQuery[1];
} else {
$sQuery = $this->sQuery;
$aParams = array();
}
$sQuery = $sQuery . " LIMIT ?, ?";
$aParams[] = $this->iStartIndex - 1;
$aParams[] = $this->iResultsToDisplay;
$sql = & $default->db;
$sql->query(array($sQuery, $aParams));
if ($sql->num_rows() == 0) {
//no results
$sToRender .= "<table width=\"100%\" height=\"80%\">\n";
$sToRender .= "<tr>\n";
$sToRender .= "<td><p class=\"errorText\">No results matched your criteria</p></td>\n";
$sToRender .= "</tr>\n";
$sToRender .= "</table>\n";
} else {
$sToRender .= "<table width=\"100%\" height=\"80%\">\n";
// display the number of results
$iEndIndex = $this->iStartIndex+$this->iResultsToDisplay-1 < $iTotalResults ? $this->iStartIndex+$this->iResultsToDisplay-1 : $iTotalResults;
$sToRender .= "<tr><td colspan=\"3\">Searched the KnowledgeTree for '$this->sSearchText'.</td></tr>";
$sToRender .= "<tr><td colspan=\"3\" align=\"right\">Displaying results $this->iStartIndex - $iEndIndex of $iTotalResults</td></tr>\n";
$sToRender .= "<tr>\n";
for ($i = 0; $i < count($this->aColumnHeadings); $i++) {
if (! (strcmp($this->sOrderByColumn, $this->aColumns[$i]) === false) && (strcmp($this->sOrderByColumn, $this->aColumns[$i]) == 0)) {
if (!(strcmp($this->sOrderDirection,"ASC") === false) && (strcmp($this->sOrderDirection,"ASC") == 0)) {
$sToRender .= "<th align=\"left\" bgcolor=\"" . $sTHBGColour . "\">" . $this->aColumnHeadings[$i]. "</th>\n";
} else {
$sToRender .= "<th align=\"left\" bgcolor=\"" . $sTHBGColour . "\">" . $this->aColumnHeadings[$i]. "</th>\n";
}
} else {
$sToRender .= "<th align=\"left\" bgcolor=\"" . $sTHBGColour . "\">" . $this->aColumnHeadings[$i]. "</th>\n";
}
}
$sToRender .= "</tr>\n";
$iColour = 0;
$iDisplayed = 0;
//limit the result set displayed
while($sql->next_record()) {
$sToRender .= "<tr bgcolor=\"" . getColour($iColour) . "\">";
$iColour++; $iDisplayed++;
for ($i = 0; $i < count($this->aColumns); $i++) {
switch ($this->aColumnTypes[$i]) {
case 1:
//display text
$sToRender .= "<td>" . $sql->f($this->aColumns[$i]) . "</td>\n";
break;
case 2:
//display a checkbox
$sToRender .= "<td>" . ($sql->f($this->aColumns[$i]) ? "Yes" : "No") . "</td>\n";
break;
case 3:
//display a url
$sToRender .= "<td><a href=\"" ;
$sURLplusQuery = $this->aLinkURLs[$i];
for ($j = 0; $j < count($this->aDBQueryStringColumns); $j++) {
if (strpos($sURLplusQuery, "?") === false) {
$sURLplusQuery .= "?" . $this->aQueryStringVariableNames[$j] . "=" . $sql->f($this->aDBQueryStringColumns[$j]);
} else {
$sURLplusQuery .= "&" . $this->aQueryStringVariableNames[$j] . "=" . $sql->f($this->aDBQueryStringColumns[$j]);
}
}
$sToRender .= $sURLplusQuery;
$sToRender .= "\">" . $sql->f($this->aColumns[$i]) . "</a></td>\n";
break;
case 4:
//diplay an image URL
$sToRender .= "<td><a href=\"" . $this->aLinkURLs[$i];
for ($j = 0; $j < count($this->aDBQueryStringColumns); $j++) {
if (strpos($sToRender, "?") === false) {
$sToRender .= "?" . $this->aQueryStringVariableNames[$j] . "=" . $sql->f($this->aDBQueryStringColumns[$j]);
} else {
$sToRender .= "&" . $this->aQueryStringVariableNames[$j] . "=" . $sql->f($this->aDBQueryStringColumns[$j]);
}
}
$sToRender .= "\"><img src=\"" . $sql->f($this->aColumns[$i]) . "\" border=\"0\" /></a></td>\n";
break;
default:
break;
}
}
$sToRender .= "</tr>\n";
}
//if we displayed less results than the number to display
//simply pad the table
while ($iDisplayed < $this->iResultsToDisplay) {
$sToRender .= "<tr><td> </td></tr>\n";
$iDisplayed++;
}
$sToRender .= "</table>";
$sToRender .= "<table>";
$sToRender .= "<tr>\n";
foreach ($this->aRememberValues as $k => $v) {
$v = htmlentities(urlencode($v));
$sToRender .= "<input type=\"hidden\" name=\"$k\" value=\"$v\" />\n";
}
// Display only the next button
if (($this->iStartIndex + $this->iResultsToDisplay - 1) < $iTotalResults && $this->iStartIndex == 1) {
$sToRender .= "<td> </td>";
$sToRender .= "<td align=\"left\">";
$sToRender .= "<input type=\"image\" src=\"" . KTHtml::getNextButton() . "\" onClick=\"setActionAndSubmit('" . $_SERVER["PHP_SELF"] . "?fStartIndex=" . ($this->iStartIndex + $this->iResultsToDisplay) . $this->sQueryString . "')\" />";
$sToRender .= "</td>\n";
}
// Display both the next and the previous buttons
else if (($this->iStartIndex + $this->iResultsToDisplay - 1) < $iTotalResults && $this->iStartIndex > 1) {
$sToRender .= "<td>";
$sToRender .= "<input type=\"image\" src=\"" . KTHtml::getPreviousButton() . "\" onClick=\"setActionAndSubmit('" . $_SERVER["PHP_SELF"] . "?fStartIndex=" . ($this->iStartIndex - $this->iResultsToDisplay) . $this->sQueryString . "')\" />";
$sToRender .= "</td>";
$sToRender .= "<td>";
$sToRender .= "<input type=\"image\" src=\"" . KTHtml::getNextButton() . "\" onClick=\"setActionAndSubmit('" . $_SERVER["PHP_SELF"] . "?fStartIndex=" . ($this->iStartIndex + $this->iResultsToDisplay) . $this->sQueryString . "')\" />";
$sToRender .= "</td>\n";
}
// Display only the previous button
else if ($this->iStartIndex > 1) {
$sToRender .= "<td align=\"left\">\n";
$sToRender .= "<input type=\"image\" src=\"" . KTHtml::getPreviousButton() . "\" onClick=\"setActionAndSubmit('" . $_SERVER["PHP_SELF"] . "?fStartIndex=" . ($this->iStartIndex - $this->iResultsToDisplay) . $this->sQueryString . "')\" />";
$sToRender .= "</td>";
}
$sToRender .= "</tr>\n";
$sToRender .= "</table>\n";
}
return $sToRender;
}
function getResultCount() {
global $default;
$sql = & $default->db;
if ($sql->query($this->sQuery)) {
return $sql->num_rows();
} else {
return 0;
}
}
}
?>