Documentation is available at RSDEngineDBTemplateFileUpdate.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 RSDEngineDBTemplateFileUpdate.
20 *
21 * @package RSDEngine
22 * @author Lukas Feiler <lukas.feiler@chello.at>
23 * @copyright Lukas Feiler 2003
24 * @filesource
25 */
26
27 /**RSDEngineDBTemplateFileUpdate extends RSDEngineTemplateFile.
28 */
29 require_once('RSDEngine/RSDEngineTemplateFile.php');
30
31 /**Generates the smarty template file for updating records in a 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 RSDEngineDBTemplateFileUpdate 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 "update" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".tpl";
51 }
52
53 /**Returns the filename of the corresponding controller.
54 * @return String
55 */
56 function getControllerFilename()
57 {
58 return "update" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".php";
59 }
60
61 /**Returns the code for the template file for updating records in a table.
62 *
63 * @access private
64 * @return String The code for the file.
65 */
66 function getCode()
67 {
68 extract($this->config);
69 $table =& $this->config['table'];
70 $OPEN = $smartyLeftDelimiter;
71 $CLOSE = $smartyRightDelimiter;
72 $authors = RSArrayUtil::toString(split("\n",$authors),"\n",'* @author %val');
73 $records = ucfirst($this->config['table']->getTableNameWithoutPrefix());
74 $tableInstanceName = $table->getChildClassInstanceName();
75 $appInstanceName = $this->relatedClasses['dbApplicationClass']->getInstanceName();
76
77 $header = $table->getFileOptionProperty('updateTemplate', 'header');
78 $footer = $table->getFileOptionProperty('updateTemplate', 'footer');
79 $write = $table->getFileOptionProperty('updateTemplate', 'write');
80
81 $this->setWrite($write);
82
83 $data = '';
84 if (($primaryKeyColumn = $table->getPrimaryKeyColumn()) === false) {
85 $data .="No primary key was defined! Without a primary key the RSDEngine cannot generate code to update a single record!";
86 return "$data?>";
87 }
88 $data .="<html>\n" .
89 "<head>\n" .
90 " <title>update " . $table->getTableNameForVariableName() . "</title>\n" .
91 "</head>\n" .
92 "<body>\n";
93
94 if ($header) {
95 $data .="{{include file=\"header.tpl\"}}\n";
96 }
97
98 $data .=" ${OPEN}if \$error${CLOSE}\n" .
99 ' <font color="red">An error occured!</font>' . "\n" .
100 " ${OPEN}/if${CLOSE}\n" .
101 ' <form name="endlosForm" enctype="multipart/form-data" method="POST">' . "\n" .
102 " <table>\n";
103
104 //a tr for each column: <td>columnName</td><td><input ...></td>
105 reset($table->columns);
106 while (list($key,$column) = each($table->columns)) {
107 if ($column->defaultUpdateValue != "" || $column->isPrimaryKey || $column->doNotUpdate) {
108 continue;
109 }
110 $columnName = $table->columns[$key]->getColumnNameForVariableName();
111 $data .=" <tr>\n" .
112 " <td>$columnName:</td>\n" .
113 " <td>\n";
114 $data .= $column->getHTMLInputTag();
115 /*
116 if ($column->isForeignKey) {
117 $data .=' <select name="' . $columnName . '">' . "\n" .
118 " ${OPEN}html_options options=\$${columnName}Options selected=\$$columnName${CLOSE}\n" .
119 " </select>\n";
120 } elseif (is_array($isValidFileOptions = $column->getIsValidFileOptions())) {
121 $data .=' <input type="hidden" name="MAX_FILE_SIZE" value="' . $isValidFileOptions['maxSize'] . '">' . "\n" .
122 ' <input name="' . $columnName . '" type="file">' . "\n";
123
124 } else {
125 $data .=" <input type=\"text\" name=\"$columnName\" value=\"${OPEN}\$" . $columnName . "${CLOSE}\">\n";
126 }
127 */
128 $data .=" ${OPEN}if \$" . $column->name . "Error${CLOSE}\n" .
129 ' <font color="red"> invalid</font>' . "\n" .
130 " ${OPEN}/if${CLOSE}\n" .
131 " </td>\n" .
132 " <tr>\n";
133 }
134
135 //submit button for the create form
136 $data .=" <tr>\n" .
137 " <td></td>\n" .
138 " <td>\n" .
139 ' <input type="hidden" name="action" value="1">' . "\n" .
140 ' <input type="hidden" name="' . $primaryKeyColumn->getColumnNameForVariableName() . "\" value=\"${OPEN}\$" . $primaryKeyColumn->getColumnNameForVariableName() . "${CLOSE}\">\n" .
141 ' <input type="submit" value="Update">' . "\n" .
142 " </td>\n" .
143 " <tr>\n";
144
145 //end of section; end of table; end of body; end of html
146 $data .=" </table>\n" .
147 " </form>\n";
148 if ($footer) {
149 $data .="{{include file=\"footer.tpl\"}}\n";
150 }
151
152 $data .="</body>\n" .
153 "</html>";
154
155 return $data;
156 }
157 }
158 ?>
Documentation generated on Mon, 8 Dec 2003 13:12:34 +0100 by phpDocumentor 1.2.3