Source for file RSDEngineDBControllerFileUpdateRight.php

Documentation is available at RSDEngineDBControllerFileUpdateRight.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 RSDEngineDBControllerFileUpdateRight.
20 *
21 * @package RSDEngine
22 * @author Lukas Feiler <lukas.feiler@chello.at>
23 * @copyright Lukas Feiler 2003
24 * @filesource
25 */
26
27 /**RSDEngineDBControllerFileUpdateRight extends RSDEngineControllerFile.
28 */
29 require_once('RSDEngine/RSDEngineControllerFile.php');
30
31 /**Generates the controller file for updating a LiveUser right.
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 RSDEngineDBControllerFileUpdateRight extends RSDEngineControllerFile {
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()) . "Right" . ucfirst($this->config['column']->getColumnNameForVariableName()) . ".php";
51 }
52
53 /**Returns the filename of the corresponding template.
54 * @return String
55 */
56 function getTemplateFilename()
57 {
58 return "update" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . "Right" . ucfirst($this->config['column']->getColumnNameForVariableName()) . ".tpl";
59 }
60
61 /**Returns the filename of the get controller.
62 * @return String
63 */
64 function getControllerGetFilename()
65 {
66 return "get" . ucfirst($this->config['table']->getTableNameWithoutPrefix()) . ".php";
67 }
68
69 /**Returns the code for the controller file for updating a LiveUser right.
70 *
71 * @access private
72 * @return String The code for the file.
73 */
74 function getCode()
75 {
76 extract($this->config);
77 $table =& $this->config['table'];
78 $authors = RSArrayUtil::toString(split("\n",$authors),"\n",'* @author %val');
79 $records = ucfirst($this->config['table']->getTableNameWithoutPrefix());
80 $tableInstanceName = $table->getChildClassInstanceName();
81 $appInstanceName = $this->relatedClasses['dbApplicationClass']->getInstanceName();
82 if (($primaryKeyColumn = $table->getPrimaryKeyColumn()) === false){
83 return "No primary key was defined! Without a primary key the RSDEngine cannot generate code to view a single record!\n";
84 }
85 $primaryKeyColumnNameForVariableName = $primaryKeyColumn->getColumnNameForVariableName();
86 $primaryKeyColumnNameForPartialMethodName = $primaryKeyColumn->getColumnNameForPartialMethodName();
87 $rightColumnNameForVariableName = $column->getColumnNameForVariableName();
88 $rightColumnNameForPartialMethodName = $column->getColumnNameForPartialMethodName();
89 $grantRightToUserMethodName = $column->generateGrantRightToUserMethodName();
90 $revokeRightFromUserMethodName = $column->generateRevokeRightFromUserMethodName();
91 $grantRightToGroupMethodName = $column->generateGrantRightToGroupMethodName();
92 $revokeRightFromGroupMethodName = $column->generateRevokeRightFromGroupMethodName();
93 $getControllerFilename = $this->getControllerGetFilename();
94
95 $templateFilename = $this->getTemplateFilename();
96
97 $public = $table->getFileOptionProperty('updateController', 'public');
98 $write = $table->getFileOptionProperty('updateController', 'write');
99
100 $this->setWrite($write);
101
102 $data = '';
103 $data .="<?php\n" .
104 '/' . "**This file is the controller for updating the LiveUser right stored in the column $column->name in the table $table->name.\n" .
105 '*' . "\n" .
106 $authors . "\n" .
107 '* @copyright ' . $copyright . "\n" .
108 '* @package ' . $projectName . "\n" .
109 '* @filesource' . "\n" .
110 '*/' . "\n" .
111 "\n";
112 if ($this->config['auth'] || $this->config['liveUser']) {
113 if ($public) {
114 $data .='/' . '**This controller requires no authentication.' . "\n" .
115 "*/\n" .
116 "require_once('model/" . $this->relatedFiles['dbApplicationPublicInitFile']->getFilename() . "');\n";
117 } else {
118 $data .='/' . '**This controller requires authentication.' . "\n" .
119 "*/\n" .
120 "require_once('model/" . $this->relatedFiles['dbApplicationPrivateInitFile']->getFilename() . "');\n";
121 }
122 } else {
123 $data .='/' . '**Initializes the application.' . "\n" .
124 "*/\n" .
125 "require_once('model/" . $this->relatedFiles['dbApplicationInitFile']->getFilename() . "');\n";
126 }
127
128 $data .= <<<END
129 \$$primaryKeyColumnNameForVariableName = isset(\$_REQUEST['$primaryKeyColumnNameForVariableName']) ? \$_REQUEST['$primaryKeyColumnNameForVariableName'] : '';
130 \$action = isset(\$_REQUEST['action']) ? \$_REQUEST['action'] : '';
131 \$next = isset(\$_REQUEST['next']) ? \$_REQUEST['next'] : '';
132 \$grant${rightColumnNameForPartialMethodName}ToUsers = isset(\$_REQUEST['grant${rightColumnNameForPartialMethodName}ToUsers']) ? \$_REQUEST['grant${rightColumnNameForPartialMethodName}ToUsers'] : array();
133 \$revoke${rightColumnNameForPartialMethodName}FromUsers = isset(\$_REQUEST['revoke${rightColumnNameForPartialMethodName}FromUsers']) ? \$_REQUEST['revoke${rightColumnNameForPartialMethodName}FromUsers'] : array();
134 \$grant${rightColumnNameForPartialMethodName}ToGroups = isset(\$_REQUEST['grant${rightColumnNameForPartialMethodName}ToGroups']) ? \$_REQUEST['grant${rightColumnNameForPartialMethodName}ToGroups'] : array();
135 \$revoke${rightColumnNameForPartialMethodName}FromGroups = isset(\$_REQUEST['revoke${rightColumnNameForPartialMethodName}FromGroups']) ? \$_REQUEST['revoke${rightColumnNameForPartialMethodName}FromGroups'] : array();
136 \$error = false;
137 \$${tableInstanceName} =& \$${appInstanceName}->getTable('$table->name');
138
139 END;;; $data .="\$record = \$${tableInstanceName}->" . $table->getGetByPrimaryKeyMethodName() . "(\$" . $primaryKeyColumn->getColumnNameForVariableName() . ");\n";
140
141 $data .='if(PEAR::isError($record)){' . "\n" .
142 " \$${appInstanceName}->smarty->assign('error', true);\n" .
143 " \$${appInstanceName}->smarty->display('$templateFilename');\n" .
144 " exit;\n" .
145 "}\n";
146
147 $data .= <<<END
148
149 \$$rightColumnNameForVariableName = \$record['$column->name'];
150
151 if (!\$error && \$action) {
152 if (isset(\$grant${rightColumnNameForPartialMethodName}ToUsers)) {
153 while (list(\$key, \$authId) = each(\$grant${rightColumnNameForPartialMethodName}ToUsers)) {
154 \$pearError = \$${tableInstanceName}->$grantRightToUserMethodName(\$record, \$authId);
155 if (PEAR::isError(\$pearError)) {
156 \$error = true;
157 \$errorSource = 'grant${rightColumnNameForPartialMethodName}ToUsersError';
158 }
159 }
160 }
161 if (isset(\$grant${rightColumnNameForPartialMethodName}ToGroups)) {
162 while (list(\$key, \$groupId) = each(\$grant${rightColumnNameForPartialMethodName}ToGroups)) {
163 \$pearError = \$${tableInstanceName}->$grantRightToGroupMethodName(\$record, \$groupId);
164 if (PEAR::isError(\$pearError)) {
165 \$error = true;
166 \$errorSource = 'grant${rightColumnNameForPartialMethodName}ToGroupsError';
167 }
168 }
169 }
170 if (isset(\$revoke${rightColumnNameForPartialMethodName}FromUsers)) {
171 while (list(\$key, \$authId) = each(\$revoke${rightColumnNameForPartialMethodName}FromUsers)) {
172 \$pearError = \$${tableInstanceName}->$revokeRightFromUserMethodName(\$record, \$authId);
173 if (PEAR::isError(\$pearError)) {
174 \$error = true;
175 \$errorSource = 'revoke${rightColumnNameForPartialMethodName}FromUsersError';
176 }
177 }
178 }
179 if (isset(\$revoke${rightColumnNameForPartialMethodName}FromGroups)) {
180 while (list(\$key, \$groupId) = each(\$revoke${rightColumnNameForPartialMethodName}FromGroups)) {
181 \$pearError = \$${tableInstanceName}->$revokeRightFromGroupMethodName(\$record, \$groupId);
182 if (PEAR::isError(\$pearError)) {
183 \$error = true;
184 \$errorSource = 'revoke${rightColumnNameForPartialMethodName}FromGroupsError';
185 }
186 }
187 }
188
189 if (!\$error && \$next) {
190 header('Location: $getControllerFilename');
191 exit;
192 }
193 if (\$error) {
194 \$${appInstanceName}->smarty->assign('error', true);
195 if (isset(\$errorSource)) {
196 \$${appInstanceName}->smarty->assign(\$errorSource, true);
197 }
198 }
199 }
200
201
202 \$${appInstanceName}->smarty->assign('$primaryKeyColumnNameForVariableName', \$$primaryKeyColumnNameForVariableName);
203
204 \$grant${rightColumnNameForPartialMethodName}ToUsersOptions = \$${appInstanceName}->getLiveUserUsersByNegativeRightId(\$$rightColumnNameForVariableName);
205 \$revoke${rightColumnNameForPartialMethodName}FromUsersOptions = \$${appInstanceName}->getLiveUserUsersByRightId(\$$rightColumnNameForVariableName);
206
207 \$grant${rightColumnNameForPartialMethodName}ToGroupsOptions = \$${appInstanceName}->getLiveUserGroupsByNegativeRightId(\$$rightColumnNameForVariableName);
208 \$revoke${rightColumnNameForPartialMethodName}FromGroupsOptions = \$${appInstanceName}->getLiveUserGroupsByRightId(\$$rightColumnNameForVariableName);
209
210 if (!PEAR::isError(\$grant${rightColumnNameForPartialMethodName}ToUsersOptions)) {
211 \$grant${rightColumnNameForPartialMethodName}ToUsersOptions = \$${tableInstanceName}->recordArrayToSmartyHTMLOptionsArray('$liveUserAuthTableColumnUserid', \$grant${rightColumnNameForPartialMethodName}ToUsersOptions, '$liveUserAuthTableColumnHandle');
212 \$${appInstanceName}->smarty->assign('canGrant${rightColumnNameForPartialMethodName}ToUsers', \$${tableInstanceName}->canGrant${rightColumnNameForPartialMethodName}ToUser(\$record));
213 \$${appInstanceName}->smarty->assign('grant${rightColumnNameForPartialMethodName}ToUsersOptions', \$grant${rightColumnNameForPartialMethodName}ToUsersOptions);
214 } else {
215 \$${appInstanceName}->smarty->assign('error', true);
216 \$${appInstanceName}->smarty->assign('grant${rightColumnNameForPartialMethodName}ToUsersError', true);
217 }
218
219 if (!PEAR::isError(\$revoke${rightColumnNameForPartialMethodName}FromUsersOptions)) {
220 \$revoke${rightColumnNameForPartialMethodName}FromUsersOptions = \$${tableInstanceName}->recordArrayToSmartyHTMLOptionsArray('$liveUserAuthTableColumnUserid', \$revoke${rightColumnNameForPartialMethodName}FromUsersOptions, '$liveUserAuthTableColumnHandle');
221 \$${appInstanceName}->smarty->assign('canRevoke${rightColumnNameForPartialMethodName}FromUsers', \$${tableInstanceName}->canRevoke${rightColumnNameForPartialMethodName}FromUser(\$record));
222 \$${appInstanceName}->smarty->assign('revoke${rightColumnNameForPartialMethodName}FromUsersOptions', \$revoke${rightColumnNameForPartialMethodName}FromUsersOptions);
223 } else {
224 \$${appInstanceName}->smarty->assign('error', true);
225 \$${appInstanceName}->smarty->assign('revoke${rightColumnNameForPartialMethodName}FromUsersError', true);
226 }
227
228
229 if (!PEAR::isError(\$grant${rightColumnNameForPartialMethodName}ToGroupsOptions)) {
230 \$grant${rightColumnNameForPartialMethodName}ToGroupsOptions = \$${tableInstanceName}->recordArrayToSmartyHTMLOptionsArray('group_id', \$grant${rightColumnNameForPartialMethodName}ToGroupsOptions, 'group_define_name');
231 \$${appInstanceName}->smarty->assign('canGrant${rightColumnNameForPartialMethodName}ToGroups', \$${tableInstanceName}->canGrant${rightColumnNameForPartialMethodName}ToGroup(\$record));
232 \$${appInstanceName}->smarty->assign('grant${rightColumnNameForPartialMethodName}ToGroupsOptions', \$grant${rightColumnNameForPartialMethodName}ToGroupsOptions);
233 } else {
234 \$${appInstanceName}->smarty->assign('error', true);
235 \$${appInstanceName}->smarty->assign('grant${rightColumnNameForPartialMethodName}ToGroupsError', true);
236 }
237
238 if (!PEAR::isError(\$revoke${rightColumnNameForPartialMethodName}FromGroupsOptions)) {
239 \$revoke${rightColumnNameForPartialMethodName}FromGroupsOptions = \$${tableInstanceName}->recordArrayToSmartyHTMLOptionsArray('group_id', \$revoke${rightColumnNameForPartialMethodName}FromGroupsOptions, 'group_define_name');
240 \$${appInstanceName}->smarty->assign('canRevoke${rightColumnNameForPartialMethodName}FromGroups', \$${tableInstanceName}->canRevoke${rightColumnNameForPartialMethodName}FromGroup(\$record));
241 \$${appInstanceName}->smarty->assign('revoke${rightColumnNameForPartialMethodName}FromGroupsOptions', \$revoke${rightColumnNameForPartialMethodName}FromGroupsOptions);
242 } else {
243 \$${appInstanceName}->smarty->assign('error', true);
244 \$${appInstanceName}->smarty->assign('revoke${rightColumnNameForPartialMethodName}FromGroupsError', true);
245 }
246
247
248 \$${appInstanceName}->smarty->display('$templateFilename');
249
250 ?>
251 END;;;
252 return $data;
253 }
254 }
255 ?>

Documentation generated on Mon, 8 Dec 2003 13:11:20 +0100 by phpDocumentor 1.2.3