PatternDatabaseTable.inc
6.82 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
<?php
/**
*
* Class PatternDatabaseTable
*
* Builds a query using the table name and the array of specified columns
* and displays the results in an HTML table. The ID column of the table is
* included by default (basically renders a database table in html)
*
* The first column in the table can be rendered as a link
* to the document/folder using the $iLinkType variable to specify the link type,
* the $sLinkPageURL to specify the page URL to link to and $sLinkImageURL to specify
* the image to display in the case of either a $iLinkType of 2 (image only) or 3 (image + text)
*
* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa
* @date 7 January 2003
*
* @todo $iLinkImageURL is hard coded - change
* @todo $sLinkPageURL is hard coded - change
*
* @package lib.visualpatterns
*/
class PatternDatabaseTable {
/* Name of table to query */
var $sTableName;
/* Columns in table to query (ID is included by default) */
var $aColumns;
/* Column types. Possibles are 1 = text, 2 = boolean*/
var $aColumnTypes;
/* Where clause */
var $sWhereClause;
/* Order by clause */
var $sOrderByClause;
/* Link type. Possibles are: 0 = none; 1 = text; 2 = image, 3 = text/image */
var $iLinkType;
/* Image to display if $iLinkType = 1 */
var $sLinkImageURL;
/* URL of page to redirect to */
var $sLinkPageURL = "Navigate.inc";
/* Number of result to display in the table. The default value is 15 */
var $iResultsToDisplay;
/* Result number to start on (internal variable - not set by developer) */
var $iStartIndex;
function PatternTableSqlQuery($sTmpTableName, $aTmpColumns, $aTmpColumnTypes, $sTmpWhereClause = null, $iTmpLinkType = 0, $sTmpLinkImageURL = null, $iTmpResultsToDisplay = 15) {
$this->sTableName = & $sTmpTableName;
$this->aColumns = & $aTmpColumns;
$this->aColumnTypes = $aTmpColumnTypes;
$this->sWhereClause = & $sTmpWhereClause;
$this->iLinkType = & $iTmpLinkType;
$this->iResultsToDisplay = $iTmpResultsToDisplay;
$this->sLinkImageURL = "C:\temp\test\up.jpg";
}
/** Set the variable $this->sTableName */
function setTableName($sNewVal) {
$this->sTableName = & $sNew7Val;
}
/** Set the variable $this->aColumns */
function setColumns($aNewVal) {
$this->aColumns = & $aNewVal;
}
/** Set the variable $this->aColumnTypes */
function setColumnTypes($aNewVal) {
$this->aColumnTypes = $aTmpColumnTypes;
}
/** Set the variable $this->sWhereClause */
function setWhereClause($sNewVal) {
$this->sWhereClause = & $sNewVal;
}
/** Set the variable $this->iLinkType */
function setLinkType($iNewVal) {
$this->iLinkType = & $iNewVal;
}
/** Set the variable $this->sLinkImageURL */
function setLinkImageURL($sNewVal) {
$this->sLinkImageURL = & $sNewVal;
}
/** Set the variable $this->iStartIndex */
function setStartIndex($iNewVal) {
$this->iStartIndex = & $iNewVal;
}
/** Set the variable $this->iResultsToDisplay */
function setResultsToDisplay($iNewVal) {
$this->iResultsToDisplay = & $iNewVal;
}
/**
* 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;
$sToRender = "<table width=\"100%\" height=\"100%\">\n";
$sToRender .= "<tr>\n";
//$i starts at 1 because the $aColumns[0] is the ID column, which
//is used in links, but never actually displayed
for ($i = 0; $i < count($this->aColumns); $i++) {
$sToRender .= "<th align=\"left\">".$this->aColumns[$i]."</th>\n";
}
$sToRender .= "</tr>\n";
$sql = & $default->db;
$sql->createSQLQueryWithOffset($this->sTableName, $this->aColumns, $this->iStartIndex, $this->iResultsToDisplay);
$iDisplayed = 0;
//limit the result set displayed
while(($aRow = $sql->next_record()) && ($iDisplayed < $this->iResultsToDisplay)) {
$sToRender .= "<tr>";
//get the value for each column in the row
//and put it in a table column.
//$i starts at 1 because $aRow[0] is the ID column for the specified table, which
//is used in links, but never actually displayed
//$i < count(this->aColumns) + 1 because $this->aColumns should not contain the ID column
for ($i = 1; $i < count($this->aColumns) + 1; $i++) {
//if the first column is a link column
if (($this->iLinkType == 1 || $this->iLinkType == 2 || $this->iLinkType == 3) && ($i == 1)) {
switch ($this->iLinkType) {
case 1:
//display text only
$sToRender .= "<td><a href=\"" . $this->iLinkPageURL . "?fID=" . $aRow[0] . "&fTableName=" . $this->sTableName . "\">" . $aRow[$i] . "</td>\n";
$sToRender .= "</a></td>\n";
break;
case 2:
//display an image only
$sToRender .= "<td><a href=\"" . $this->iLinkPageURL . "?fID=" . $aRow[0] . "&fTableName=" . $this->sTableName . "\"><img src=\"" . $this->sLinkImageURL . "\"/></a></td>\n";
break;
case 3:
//display both an image and text
$sToRender .= "<td><a href=\"" . $this->iLinkPageURL . "?fID=" . $aRow[0] . "&fTableName=" . $this->sTableName . "\"><img src=\"" . $this->sLinkImageURL . "\"/>" . $aRow[0] . "</a></td>\n";
break;
default:
break;
}
} else {
$sToRender .= "<td>".$aRow[$i]."</td>\n";
}
}
$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";
/* Display only the next button */
if (($this->iStartIndex + $this->iResultsToDisplay) < $sql->getLastQueryResultCount() && $this->iStartIndex == 0) {
$sToRender .= "<td>";
$sToRender .= ("<a href=\"test.php?fStartIndex=" . ($this->iStartIndex + $this->iResultsToDisplay) . "\">Next</a>");
$sToRender .= "</td>\n";
}
/* Display both the next and the previous buttons */
else if (($this->iStartIndex + $this->iResultsToDisplay) < $sql->getLastQueryResultCount() && $this->iStartIndex > 0) {
$sToRender .= "<td>";
$sToRender .= ("<a href=\"test.php?fStartIndex=" . ($this->iStartIndex + $this->iResultsToDisplay) . "\">Next</a>");
$sToRender .= "</td>";
$sToRender .= "<td>";
$sToRender .= ("<a href=\"test.php?fStartIndex=" . ($this->iStartIndex - $this->iResultsToDisplay) . "\">Previous</a>");
$sToRender .= "</td>\n";
}
/* Display only the previous button */
else if ($this->iStartIndex > 0) {
$sToRender .= "<td>\n";
$sToRender .= (" ");
$sToRender .= "</td>";
$sToRender .= "<td>\n";
$sToRender .= ("<a href=\"test.php?fStartIndex=" . ($this->iStartIndex - $this->iResultsToDisplay) . "\">Previous</a>");
$sToRender .= "</td>";
}
//$sToRender .= "</td>\n";
$sToRender .= "</tr>\n";
$sToRender .= "</table>\n";
return $sToRender;
}
}
?>