PatternBrowsableSearchResults.inc
8.7 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
<?php
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;
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 = "";
}
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;
}
/**
* 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");
//add the limit and offset stuff for cutting down result set
$sLimitQuery = $this->sQuery . " LIMIT " . $this->iStartIndex . ", " . $this->iResultsToDisplay;
$sql = & $default->db;
$sql->query($sLimitQuery);
$sToRender;
if ($sql->num_rows() == 0) {
//no results
$sToRender = "<table width=\"100%\" height=\"100%\">\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=\"100%\">\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\"><a href=\"" . $_SERVER["PHP_SELF"] . "?fOrderBy=" . $this->aColumns[$i] . "&fOrderDirection=DESC&fStartIndex=" . $this->iStartIndex . "\">" . $this->aColumnHeadings[$i]."</a></th>\n";
$sToRender .= "<th align=\"left\" bgcolor=\"" . $sTHBGColour . "\">" . $this->aColumnHeadings[$i]. "</th>\n";
} else {
//$sToRender .= "<th align=\"left\"><a href=\"" . $_SERVER["PHP_SELF"] . "?fOrderBy=" . $this->aColumns[$i] . "&fOrderDirection=ASC&fStartIndex=" . $this->iStartIndex . "\">" . $this->aColumnHeadings[$i]."</a></th>\n";
$sToRender .= "<th align=\"left\" bgcolor=\"" . $sTHBGColour . "\">" . $this->aColumnHeadings[$i]. "</th>\n";
}
} else {
//$sToRender .= "<th align=\"left\"><a href=\"" . $_SERVER["PHP_SELF"] . "?fOrderBy=" . $this->aColumns[$i] . "&fOrderDirection=ASC&fStartIndex=" . $this->iStartIndex . "\">" . $this->aColumnHeadings[$i]."</a></th>\n";
$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() && ($iDisplayed < $this->iResultsToDisplay)) {
$sToRender .= "<tr bgcolor=\"" . getColour($iColour) . "\">";
$iColour++;
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:
//diplay 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";
$iDisplayed++;
}
//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 .= "<tr>\n";
$sToRender .= "<input type=\"hidden\" name=\"fStartIndex\" value=\"" . ($this->iStartIndex + $this->iResultsToDisplay) . "\" />\n";
/* Display only the next button */
if (($this->iStartIndex + $this->iResultsToDisplay) < $this->getResultCount($sql) && $this->iStartIndex == 0) {
$sToRender .= "<td>";
//$sToRender .= ("<a href=\"" . $_SERVER["PHP_SELF"] . "?fStartIndex=" . ($this->iStartIndex + $this->iResultsToDisplay) . "\">Next</a>");
$sToRender .= ("<input type=\"image\" src=\"$default->graphicsUrl/widgets/next.gif\" 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) < $this->getResultCount($sql) && $this->iStartIndex > 0) {
$sToRender .= "<td>";
$sToRender .= ("<input type=\"image\" src=\"$default->graphicsUrl/widgets/next.gif\" onClick=\"setActionAndSubmit('" . $_SERVER["PHP_SELF"] . "?fStartIndex=" . ($this->iStartIndex + $this->iResultsToDisplay) . $this->sQueryString . "')\" />");
$sToRender .= "</td>";
$sToRender .= "<td>";
$sToRender .= ("<input type=\"image\" src=\"$default->graphicsUrl/widgets/previous.gif\" onClick=\"setActionAndSubmit('" . $_SERVER["PHP_SELF"] . "?fStartIndex=" . ($this->iStartIndex - $this->iResultsToDisplay) . $this->sQueryString . "')\" />");
$sToRender .= "</td>\n";
}
/* Display only the previous button */
else if ($this->iStartIndex > 0) {
$sToRender .= "<td>\n";
$sToRender .= (" ");
$sToRender .= "</td>";
$sToRender .= "<td>\n";
$sToRender .= ("<input type=\"image\" src=\"$default->graphicsUrl/widgets/previous.gif\" onClick=\"setActionAndSubmit('" . $_SERVER["PHP_SELF"] . "?fStartIndex=" . ($this->iStartIndex - $this->iResultsToDisplay) . $this->sQueryString . "')\" />");
$sToRender .= "</td>";
}
$sToRender .= "</tr>\n";
$sToRender .= "</table>\n";
}
return $sToRender;
}
function getResultCount($sql) {
if ($sql->query($this->sQuery)) {
return $sql->num_rows();
}
return 0;
}
}
?>