Documentation is available at RSDEngineDBTemplateFileSearch.php
1 <?php
2 // RSDEngine: The Rapid and Secure Development Engine
3 // Copyright (C) 2003 Lukas Feiler
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 /**Contains just the class RSDEngineDBTemplateFileSearch.
20 *
21 * @package RSDEngine
22 * @author Lukas Feiler <lukas.feiler@chello.at>
23 * @copyright Lukas Feiler 2003
24 * @filesource
25 */
26
27 /**RSDEngineDBTemplateFileSearch extends RSDEngineTemplateFile.
28 */
29 require_once('RSDEngine/RSDEngineTemplateFile.php');
30
31 /**Generates the smarty template file for searching records from in table.
32 *
33 * @author Lukas Feiler <lukas.feiler@chello.at>
34 * @version 0.1.9
35 * @copyright Lukas Feiler 2003
36 * @package RSDEngine
37 */
38 class RSDEngineDBTemplateFileSearch extends RSDEngineTemplateFile {
39
40 /**Whether to overwrite an existing file.
41 * @var boolean
42 */
43 var $overwriteExisting = false;
44
45 /**Returns the filename.
46 * @return String
47 */
48 function getFilename()
49 {
50 return "search" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".tpl";
51 }
52
53 /**Returns the name of the file for displaying the records.
54 * @return String
55 */
56 function getRecordFilename()
57 {
58 return "search" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . "_record.tpl";
59 }
60
61 /**Returns the filename of the corresponding controller.
62 * @return String
63 */
64 function getControllerFilename()
65 {
66 return "search" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".php";
67 }
68
69 /**Returns the filename of the controller that displays just one record.
70 * @see RSDEngineDBControllerFileGetOne
71 * @return String
72 */
73 function getControllerGetOneFilename()
74 {
75 return "getOne" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".php";
76 }
77
78 /**Returns the filename of the controller that deletes a record.
79 * @see RSDEngineDBControllerFileDelete
80 * @return String
81 */
82 function getControllerDeleteFilename()
83 {
84 return "delete" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".php";
85 }
86
87 /**Returns the filename of the getStorage* controller for a specific record.
88 * @see RSDEngineDBControllerFileGetStored
89 * @return String
90 */
91 function getControllerGetStorageFilename(&$column)
92 {
93 return "getStored" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ucfirst($column->getColumnNameForVariableName()) . ".php";
94 }
95
96 /**Returns the filename of the controller that creates a record.
97 * @see RSDEngineDBControllerFileCreate
98 * @return String
99 */
100 function getControllerCreateFilename()
101 {
102 return "create" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".php";
103 }
104
105 /**Returns the filename of the controller that updates a record.
106 * @see RSDEngineDBControllerFileUpdate
107 * @return String
108 */
109 function getControllerUpdateFilename()
110 {
111 return "update" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".php";
112 }
113
114 /**Returns the filename of the controller that updates a LiveUser right.
115 * @see RSDEngineDBControllerFileUpdateRight
116 * @return String
117 */
118 function getControllerUpdateRightFilename(&$column)
119 {
120 return "update" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . "Right" . ucfirst($column->getColumnNameForVariableName()) . ".php";
121 }
122
123 /**Returns the filename of the controller that updates a LiveUser area.
124 * @see RSDEngineDBControllerFileUpdateArea
125 * @return String
126 */
127 function getControllerUpdateAreaFilename(&$column)
128 {
129 return "update" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . "Area" . ucfirst($column->getColumnNameForVariableName()) . ".php";
130 }
131
132 /**Returns the filename of the controller that updates a LiveUser group.
133 * @see RSDEngineDBControllerFileUpdateArea
134 * @return String
135 */
136 function getControllerUpdateGroupFilename(&$column)
137 {
138 return "update" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . "Group" . ucfirst($column->getColumnNameForVariableName()) . ".php";
139 }
140
141 /**Returns the code for the template file for searching records in a table.
142 *
143 * @access private
144 * @return String The code for the file.
145 */
146 function getCode()
147 {
148 extract($this->config);
149 $table =& $this->config['table'];
150 $OPEN = $smartyLeftDelimiter;
151 $CLOSE = $smartyRightDelimiter;
152 $authors = RSArrayUtil::toString(split("\n",$authors),"\n",'* @author %val');
153 $records = ucfirst($this->config['table']->getTableNameWithoutPrefix());
154 $tableInstanceName = $table->getChildClassInstanceName();
155 $appInstanceName = $this->relatedClasses['dbApplicationClass']->getInstanceName();
156
157
158 $allowUserOrderBy = $table->getFileOptionProperty('searchTemplate', 'allowUserOrderBy');
159 $orderBy = $table->getFileOptionProperty('searchTemplate', 'orderBy');
160 $selectMethodName = $table->getFileOptionProperty('searchTemplate', 'selectMethodName');
161 $paging = $table->getFileOptionProperty('searchTemplate', 'paging');
162 $recordsPerPage = $table->getFileOptionProperty('searchTemplate', 'recordsPerPage');
163 $header = $table->getFileOptionProperty('searchTemplate', 'header');
164 $footer = $table->getFileOptionProperty('searchTemplate', 'footer');
165 $showKeyColumns = $table->getFileOptionProperty('searchTemplate', 'showKeyColumns');
166 $separateRecordTemplate = $table->getFileOptionProperty('searchTemplate', 'separateRecordTemplate');
167 $write = $table->getFileOptionProperty('searchTemplate', 'write');
168
169 $this->setWrite($write);
170
171 $nonFilteredColumns = $table->getSelectMethodColumns($selectMethodName);
172
173 $columns = array();
174 reset($nonFilteredColumns);
175 while (list($key, $column) = each($nonFilteredColumns)) {
176 if (!$showKeyColumns) {
177 if ($column->isPrimaryKey || $column->isForeignKey) {
178 continue;
179 }
180 }
181 if ($column->doNotSelect) {
182 continue;
183 }
184 $columns[] = $nonFilteredColumns[$key];
185 }
186
187 $data = '';
188 $data .="<html>\n" .
189 "<head>\n" .
190 " <title>search " . $table->getTableNameForVariableName() . "</title>\n" .
191 "</head>\n" .
192 "<body>\n";
193 if ($header) {
194 $data .="{{include file=\"header.tpl\"}}\n";
195 }
196 $data .= " ${OPEN}\$errorMsg${CLOSE}\n";
197
198 //the search form
199 $data .=' <form name="endlosForm">' . "\n";
200 $orderByOptions = "";
201 reset($columns);
202 while (list($key, $val) = each($columns)) {
203 $columnName = $columns[$key]->getColumnNameForVariableName();
204 $data .= " $columnName: <input type=\"text\" name=\"$columnName\" value=\"${OPEN}\$" . $columnName . "${CLOSE}\"> | \n";
205 $orderByOptions .= " <option value=\"$columnName\"{{if \$orderBy == '$columnName'}} selected=\"selected\"{{/if}}>$columnName</option>\n";
206 }
207
208
209 //submit button for the search form and and list table start
210 $data .=' <select name="orderBy">' . "\n" .
211 $orderByOptions .
212 ' </select> | ' . "\n" .
213 ' <select name="orderDescending">' . "\n" .
214 ' {{html_options options=$orderDescendingOptions selected=$orderDescending}}' . "\n" .
215 ' </select> | ' . "\n" .
216 ' <input type="submit" value="Search">' . "\n" .
217 " </form>\n";
218
219
220 $data.= '' .
221 " <table border=1>\n" .
222 " <tr>\n";
223
224 //if we have a view, a update & a delete link (see below) we need one more column!
225 if (($primaryKeyColumn =& $table->getPrimaryKeyColumn()) !== false) {
226 $data .= " <td>view</td>\n";
227 $data .= " <td>update</td>\n";
228 $data .= " <td>delete</td>\n";
229 }
230
231 //column captions (first tr in the table)
232 reset($columns);
233 while (list($key, $val) = each($columns)) {
234 $columnCaption = $columns[$key]->getColumnNameForVariableName();
235 if ($allowUserOrderBy) {
236 $data .=" <td>\n" .
237 " {{if \$orderBy == '$columnCaption'}}\n" .
238 " {{if \$orderDescending}}\n" .
239 " <a href=\"{{\$URI}}&orderBy=$columnCaption&orderDescending=0\">$columnCaption /</a>\n" .
240 " {{else}}\n" .
241 " <a href=\"{{\$URI}}&orderBy=$columnCaption&orderDescending=1\">$columnCaption \</a>\n" .
242 " {{/if}}\n" .
243 " {{else}}\n" .
244 " <a href=\"{{\$URI}}&orderBy=$columnCaption&orderDescending=0\">$columnCaption</a>\n" .
245 " {{/if}}\n" .
246 " </td>\n";
247 } else {
248 $data .=" <td>\n" .
249 " $columnCaption\n" .
250 " </td>\n";
251 }
252 }
253
254
255 //end of first tr; begin of section
256 $data .= '' .
257 " </tr>\n" .
258 " ${OPEN}section name=list loop=\$" . $table->getTableNameForVariableName() . "${CLOSE}\n";
259
260
261 if (!$separateRecordTemplate) {
262 $data .= " <tr>\n";
263
264 //if this table has defined one column as primary key we have a 'view'-link in the first td & a 'delete'-link in the 2ed; if we do one more column is needed that would be added obove.
265 if (($primaryKeyColumn =& $table->getPrimaryKeyColumn()) !== false) {
266
267 //view
268 $data .= ' <td><a href="' .
269 $this->getControllerGetOneFilename() . '?' .
270 $primaryKeyColumn->getColumnNameForVariableName() . '=' .
271 $OPEN . '$' . $table->getTableNameForVariableName() . "[list]." . $primaryKeyColumn->name . "|escape${CLOSE}" .
272 "\">view</a></td>\n";
273
274 //update
275 if ($liveUser) {
276 $data .= ' {{if $' . $table->getTableNameForVariableName() . "[list].__canUpdate}}\n";
277 }
278 $data .= ' <td><a href="' .
279 $this->getControllerUpdateFilename() . '?' .
280 $primaryKeyColumn->getColumnNameForVariableName() . '=' .
281 $OPEN . '$' . $table->getTableNameForVariableName() . "[list]." . $primaryKeyColumn->name . "|escape${CLOSE}" .
282 "\">update</a></td>\n";
283 if ($liveUser) {
284 $data .=" {{else}}\n" .
285 " <td>update</td>\n" .
286 " {{/if}}\n";
287 }
288
289 //delete
290 if ($liveUser) {
291 $data .= ' {{if $' . $table->getTableNameForVariableName() . "[list].__canDelete}}\n";
292 }
293 $data .= ' <td><a href="' .
294 $this->getControllerDeleteFilename() . '?' .
295 $primaryKeyColumn->getColumnNameForVariableName() . '=' .
296 $OPEN . '$' . $table->getTableNameForVariableName() . "[list]." . $primaryKeyColumn->name . "|escape${CLOSE}" .
297 "\">delete</a></td>\n";
298 if ($liveUser) {
299 $data .=" {{else}}\n" .
300 " <td>delete</td>\n" .
301 " {{/if}}\n";
302 }
303 }
304
305 //td for each column (will be repeated becuase it's inside the section
306 reset($columns);
307 while (list($key, $val) = each($columns)) {
308 $columnCaption = $columns[$key]->getColumnNameForVariableName();
309 $columnNameForPartialMethodName = $columns[$key]->getColumnNameForPartialMethodName();
310 $isValidFileOptions = $columns[$key]->getIsValidFileOptions();
311 $editLiveUserRightOption = count($columns[$key]->editLiveUserRightOptions) > 0;
312 $editLiveUserAreaOption = count($columns[$key]->editLiveUserAreaOptions) > 0;
313 $editLiveUserGroupOption = count($columns[$key]->editLiveUserGroupOptions) > 0;
314
315 if ($editLiveUserRightOption) {
316 $data .=' {{if $' . $table->getTableNameForVariableName() . "[list].__canUpdate$columnNameForPartialMethodName}}\n" .
317 " <td>\n" .
318 " <a href=\"" . $this->getControllerUpdateRightFilename($columns[$key]) . '?' .
319 $primaryKeyColumn->getColumnNameForVariableName() . '=' .
320 $OPEN . '$' . $table->getTableNameForVariableName() . "[list]." . $primaryKeyColumn->name . "|escape${CLOSE}" .
321 "\">\n" .
322 " ${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}\n" .
323 " </a>\n" .
324 " </td>\n" .
325 " {{else}}\n" .
326 " <td>\n" .
327 " ${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}\n" .
328 " </td>\n" .
329 " {{/if}}\n";
330 } elseif ($editLiveUserAreaOption) {
331 $data .=' {{if $' . $table->getTableNameForVariableName() . "[list].__canUpdate$columnNameForPartialMethodName}}\n" .
332 " <td>\n" .
333 " <a href=\"" . $this->getControllerUpdateAreaFilename($columns[$key]) . '?' .
334 $primaryKeyColumn->getColumnNameForVariableName() . '=' .
335 $OPEN . '$' . $table->getTableNameForVariableName() . "[list]." . $primaryKeyColumn->name . "|escape${CLOSE}" .
336 "\">\n" .
337 " ${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}\n" .
338 " </a>\n" .
339 " </td>\n" .
340 " {{else}}\n" .
341 " <td>\n" .
342 " ${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}\n" .
343 " </td>\n" .
344 " {{/if}}\n";
345 } elseif ($editLiveUserGroupOption) {
346 $data .=' {{if $' . $table->getTableNameForVariableName() . "[list].__canUpdate$columnNameForPartialMethodName}}\n" .
347 " <td>\n" .
348 " <a href=\"" . $this->getControllerUpdateGroupFilename($columns[$key]) . '?' .
349 $primaryKeyColumn->getColumnNameForVariableName() . '=' .
350 $OPEN . '$' . $table->getTableNameForVariableName() . "[list]." . $primaryKeyColumn->name . "|escape${CLOSE}" .
351 "\">\n" .
352 " ${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}\n" .
353 " </a>\n" .
354 " </td>\n" .
355 " {{else}}\n" .
356 " <td>\n" .
357 " ${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}\n" .
358 " </td>\n" .
359 " {{/if}}\n";
360 } elseif ($isValidFileOptions == null || $primaryKeyColumn === false) {
361 $data .= " <td>${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}</td>\n";
362 } else {
363 $data .=" <td>\n" .
364 " <a href=\"" . $this->getControllerGetStorageFilename($columns[$key]) . '?' .
365 $primaryKeyColumn->getColumnNameForVariableName() . '=' .
366 $OPEN . '$' . $table->getTableNameForVariableName() . "[list]." . $primaryKeyColumn->name . "|escape${CLOSE}" .
367 "\">\n" .
368 " ${OPEN}\$" . $table->getTableNameForVariableName() . "[list]." . $columns[$key]->name . "|escape${CLOSE}\n" .
369 " </a>\n";
370 " </td>\n";
371 }
372 }
373 $data .= " </tr>\n";
374
375 } else {
376 $data .= " ${OPEN}include file=\"" . $this->getRecordFilename() . "\"${CLOSE}\n";
377 }
378
379 //end of section; end of table; end of body; end of html
380 $data .=" ${OPEN}/section${CLOSE}\n" .
381 " </table>\n";
382 if ($paging) {
383 $data .="<br>\n" .
384 "\n" .
385 "${OPEN}include file=\"paging.tpl\"${CLOSE}\n" .
386 "\n" .
387 "<br>\n";
388 }
389
390 $data .=" {{if \$canInsertInto" . ucfirst($table->getTableNameForVariableName()) . "}}\n" .
391 " <a href=\"" . $this->getControllerCreateFilename() . "\">create</a>\n" .
392 " {{/if}}\n";
393 if ($footer) {
394 $data .="{{include file=\"footer.tpl\"}}\n";
395 }
396 $data .="</body>\n" .
397 "</html>";
398
399 return $data;
400 }
401 }
402 ?>
Documentation generated on Mon, 8 Dec 2003 13:12:31 +0100 by phpDocumentor 1.2.3