Source for file RSDEngineDBTable.php

Documentation is available at RSDEngineDBTable.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 the classes RSDEngineDBTable, RSDEngineRelation and RSDEngineMethod.
20 *
21 * @package RSDEngine
22 * @author Lukas Feiler <lukas.feiler@chello.at>
23 * @copyright Lukas Feiler 2003
24 * @filesource
25 */
26
27 /**Creates a class for accassing a database table.
28 *
29 * The access restriction for this class should be treated as 'friendly' - only accessable by classes in the same package.
30 *
31 * @author Lukas Feiler <lukas.feiler@chello.at>
32 * @version 0.1.9
33 * @copyright Lukas Feiler 2003
34 * @package RSDEngine
35 * @access public
36 */
37 class RSDEngineDBTable{
38 /**The SQL DDL for this table. Gets set inside the construtor method.
39 * @var String
40 */
41 var $contents = "";
42
43 /**The project name. Gets set inside the constructor method.
44 * @var String
45 */
46 var $projectName = "";
47
48 /**The authors, each stored as one array element. Gets set inside the constructor method.
49 * @var Array
50 */
51 var $authors = "";
52
53 /**The copyright information. This string must not contain newlines. Gets set inside the constructor method.
54 * @var String
55 */
56 var $copyright = "";
57
58 /**The prefix of this table. Often t_ or an shorthand for the project name of the form prj_. Providing a table prefix makes the generated code more readable because the prefix can be remove where appropriate. Set in the construtor method.
59 * @var String
60 * @see RSDEngineDBTable::RSDEngineDBTable
61 */
62 var $tablePrefix = "";
63
64 /**The prefix all columns of this table. Often f_. Providing a column prefix makes the generated code more readable because the prefix can be remove where appropriate. Set in the construtor method.
65 * @var String
66 * @see RSDEngineDBTable::RSDEngineDBTable
67 */
68 var $columnPrefix = "";
69
70 /**The name of the table.
71 * @var String
72 */
73 var $name = "";
74
75 /**An array of all RSDRelation objects having this table as starting point. New relations are added by calling the method _addRelation.
76 * @see _addRelation
77 * @var Array
78 */
79 var $relations = array();
80
81 /**An array of all unique constraints of this table. Each constraint is represented by an array holding all column names that build that constraint. New unique constraints are added by calling the method _addUniqueConstraint.
82 * @see _addUniqueConstraint
83 * @var Array
84 */
85 var $_uniqueConstraints = array();
86
87 /**An array that holds all RSDEngineColumn objects for this table. New columns are added by calling the method _addColumn.
88 * @see _addColumn
89 * @var Array
90 */
91 var $columns = array();
92
93 /**An array that holds the RSDEngineMethod objects for the class to generate. New methods are added by calling addMethod.
94 * @see addMethod
95 * @var Array
96 */
97 var $methods = array();
98
99 /**Holds a handle to the RSDEngineDB instance that created this instance.
100 * @var RSDEngineDB
101 */
102 var $rsdEngineDB = null;
103
104 /**An array holding all table options. These are defined between the table name and the opening brace.
105 * @var Array
106 */
107 var $tableOptions = array();
108
109 /**An array that holds each set of relations that was used to build a selectIncluding method.
110 * New elements are added by createSelectIncludingMethod. This property is required by the
111 * method _getSelectIncludingMethodName. Each element will be again an array. The name of
112 * the selectIncluding method will be used as key.
113 * @see createSelectIncludingMethod
114 * @see _getSelectIncludingMethodName
115 * @var Array
116 */
117 var $_selectIncludingMethodRelations = array();
118
119 /**Whether to ignore this table. Is set inside the method _parse.
120 *
121 * The RSDEngineDBTable::_parse will not add the table to its internal stack of tables if $ignore evaluates true.
122 * @see RSDEngineDBTable::_parse
123 * @see _parse
124 * @access public
125 * @var boolean
126 */
127 var $ignore = false;
128
129 /**An array containing all LiveUser table options of this table.
130 *
131 * This array gets filled by RSDEngineDBTable::_parseTableOptions.
132 *
133 * @see _parseTableOptions
134 * @see RSDEngineLiveUserRight
135 * @access private
136 * @var Array
137 */
138 var $_liveUserRights = array();
139
140 /**An array containing all file table options of this table.
141 *
142 * This array get filled by RSDEngineDBTable::_parseTableOptions.
143 *
144 * @access private
145 * @see _parseTableOptions
146 * @var Array
147 */
148 var $_fileOptions = array();
149
150 /**The label to be used for records of this table.
151 *
152 * This property gets set by RSDEngineDBTable::_parseLabelTableOption.
153 *
154 * @access private
155 * @see RSDEngineDBTable::_parseLabelTableOption
156 * @var String
157 */
158 var $_label = '';
159
160 /**PHP Code to be executed before an insert operation.
161 *
162 * @access private
163 * @see RSDEngineDBTable::_parseBeforeInsertTableOption
164 * @see _createInsertMethod
165 * @var String
166 */
167 var $_beforeInsert = '';
168
169 /**PHP Code to be executed after an insert operation.
170 *
171 * @access private
172 * @see RSDEngineDBTable::_parseAfterInsertTableOption
173 * @see _createInsertMethod
174 * @var String
175 */
176 var $_afterInsert = '';
177
178 /**PHP Code to be executed before an update operation.
179 *
180 * @access private
181 * @see RSDEngineDBTable::_parseBeforeUpdateTableOption
182 * @see _createUpdateMethod
183 * @var String
184 */
185 var $_beforeUpdate = '';
186
187 /**PHP Code to be executed after an update operation.
188 *
189 * @access private
190 * @see RSDEngineDBTable::_parseAfterUpdateTableOption
191 * @see _createUpdateMethod
192 * @var String
193 */
194 var $_afterUpdate = '';
195
196 /**PHP Code to be executed before a delete operation.
197 *
198 * @access private
199 * @see RSDEngineDBTable::_parseBeforeDeleteTableOption
200 * @see _createDeleteMethod
201 * @var String
202 */
203 var $_beforeDelete = '';
204
205 /**PHP Code to be executed after a delete operation.
206 *
207 * @access private
208 * @see RSDEngineDBTable::_parseAfterDeleteTableOption
209 * @see _createDeleteMethod
210 * @var String
211 */
212 var $_afterDelete = '';
213
214 /**An array of patterns used to include excluded selectIncluding* methods.
215 *
216 * @access private
217 * @see RSDEngineDBTable::_parseIncludeSelectMethodTableOptions
218 * @see createSelectIncludingMethod
219 * @var Array
220 */
221 var $_includeSelectMethodPatters = array();
222
223 /**An array of patterns used to exclude selectIncluding* methods.
224 *
225 * @access private
226 * @see RSDEngineDBTable::_parseExcludeSelectMethodTableOptions
227 * @see createSelectIncludingMethod
228 * @var Array
229 */
230 var $_excludeSelectMethodPatters = array();
231
232 /**Constructor that initializes this instance and calls parse.
233 *
234 * @see _parse
235 * @access public
236 * @param String $content The SQL DDL of the table for which to create this class.
237 * @param String $tablePrefix The prefix of this table. Often t_ or an shorthand for the project name of the form prj_. Providing a table prefix makes the generated code more readable because the prefix can be remove where appropriate.
238 * @param String $columnPrefix The prefix all columns of this table use. Often f_. Providing a column prefix makes the generated code more readable because the prefix can be remove where appropriate.
239 */
240 function RSDEngineDBTable($contents, $projectName, $authors, $copyright, $tablePrefix = "", $columnPrefix = "", &$rsdEngineDB)
241 {
242 $this->contents = $contents;
243 $this->projectName = $projectName;
244 if (is_array($authors)) {
245 $this->authors = $authors;
246 } else {
247 $this->authors = split("\n",$authors);
248 }
249 $this->copyright = $copyright;
250 $this->tablePrefix = $tablePrefix;
251 $this->columnPrefix = $columnPrefix;
252 $this->rsdEngineDB =& $rsdEngineDB;
253 $this->getSelectMethodName =& $this->rsdEngineDB->config['getSelectMethodName'];
254 $this->getOneSelectMethodName =& $this->rsdEngineDB->config['getOneSelectMethodName'];
255 $this->searchSelectMethodName =& $this->rsdEngineDB->config['searchSelectMethodName'];
256
257 $continue = $this->_parse();
258 if (!$continue) {
259 return;
260 }
261 $this->_createCheckUniqueConstraintsMethod();
262 $this->_createParseOptionsMethod();
263 $this->_createGetSmartyHTMLOptionsArrayMethod();
264 $this->_createGetIsValidMethodNameMethod();
265 }
266
267 /**Returns a literal representation of this RSDEngineDBTable instance.
268 *
269 * @return String
270 */
271 function toString()
272 {
273 return $this->name;
274 }
275
276 /**Creates all methods that depend an a column that is a primary or a foreign key.
277 *
278 * Calls _createDeleteByMethods, _createUpdateByMethods, _createGetByMethods,
279 * _createInsertMethod, _createIsValidMethods, _createGetNextMethods,
280 * _createStoreUploadedMethods, _createRemoveStoredMethods, _createGetStoredMethods,
281 * _createCanUpdate, _createCanDelete, _createCanSelect
282 *
283 * @access public
284 * @see _createDeleteByMethods
285 * @see _createUpdateByMethods
286 * @see _createGetByMethods
287 * @see _createInsertMethod
288 * @see _createIsValidMethods
289 * @see _createGetNextMethods
290 * @see _createStoreUploadedMethods
291 * @see _createRemoveStoredMethods
292 * @see _createGetStoredMethods
293 * @see _createCanUpdate
294 * @see _createCanDelete
295 * @see _createCanSelect
296 */
297 function createKeyMethods()
298 {
299 $this->_setLiveUserRightSelectIncludingMethodName();
300 $this->_createDeleteByMethods();
301 $this->_createUpdateByMethods();
302 $this->_createGetByMethods();
303 $this->_createInsertMethod();
304 $this->_createUpdateMethod();
305 $this->_createSelectMethod();
306 $this->_createDeleteMethod();
307 $this->_createIsValidMethods();
308 $this->_createGetNextMethods();
309 $this->_createStoreUploadedMethods();
310 $this->_createRemoveStoredMethods();
311 $this->_createGetStoredMethods();
312 $this->_createCanUpdate();
313 $this->_createCanDelete();
314 $this->_createCanSelect();
315 $this->_createCanUpdateLiveUserRightMethods();
316 }
317
318 /**Sets the property selectIncludingMethod for all LiveUserRight instances.
319 *
320 * This method is called in RSDEngineDBTable::createKeyMethods.
321 * The property selectIncludingMethod cannot be set earlier because the selectIncluding* methods must be generated first.
322 * @access private
323 */
324 function _setLiveUserRightSelectIncludingMethodName()
325 {
326 reset($this->_liveUserRights);
327 while (list($key, $liveUserRight) = each($this->_liveUserRights)) {
328 if ($liveUserRight->type != 'table.column') {
329 continue;
330 }
331
332 if ($this->_liveUserRights[$key]->operation == 'insert') {
333 //The current table itself cannot be included in the join because the record in question
334 //is not inserted yet. We need the a table directly related to the current table that is
335 //related as well to the 'target' table specified by 'table.column'. If there are multiple
336 //ways possible we need the shortest one.
337 $lastSize = -1;
338 $selectIncludingMethodName = '';
339 $relationToSelectIncludingTable = null;
340 $relations = $this->rsdEngineDB->_getRelationsByFromTable($this->name);
341 reset($relations);
342 while(list($key2, $relation) = each($relations)) {
343 if ($relation->toTable == $liveUserRight->tableName) {
344 //We do not need a selectIncluding method. The 'target' table is directly
345 //related to the current table.
346 $selectIncludingMethodName = 'select';
347 $relationToSelectIncludingTable = $relation;
348 break;
349 }
350 $table =& $this->rsdEngineDB->getTable($relation->toTable);
351 $methodName = $table->_getSelectIncludingMethodName($liveUserRight->tableName);
352 if ($methodName == '') {
353 //this directly related table has no relation to the 'target' table.
354 continue;
355 }
356 if ($lastSize == -1 || $lastSize > count($table->_selectIncludingMethodRelations[$methodName])) {
357 $lastSize = count($table->_selectIncludingMethodRelations[$methodName]);
358 $selectIncludingMethodName = $methodName;
359 $relationToSelectIncludingTable = $relation;
360 }
361 }
362 if ($selectIncludingMethodName == '' || $relationToSelectIncludingTable === null) {
363 return RSErrorManager::raiseRSError($this->name, '_liveUserRights', "RSDEngineDBTable::_setLiveUserRightSelectIncludingMethodName", "The table '$liveUserRight->tableName' used in the following table option seems to have no relation to '$this->name': '$liveUserRight->definition'.", RSERROR_FATAL_ERROR);
364 }
365 $this->_liveUserRights[$key]->selectIncludingMethodName = $selectIncludingMethodName;
366 $this->_liveUserRights[$key]->relationToSelectIncludingTable = $relationToSelectIncludingTable;
367 } else {
368 $selectIncludingMethodName = $this->_getSelectIncludingMethodName($liveUserRight->tableName);
369 if ($selectIncludingMethodName == '') {
370 return RSErrorManager::raiseRSError($this->name, '_liveUserRights', "RSDEngineDBTable::_setLiveUserRightSelectIncludingMethodName", "The table '$liveUserRight->tableName' used in the following table option seems to have no relation to '$this->name': '$liveUserRight->definition'.", RSERROR_FATAL_ERROR);
371 }
372 $this->_liveUserRights[$key]->selectIncludingMethodName = $selectIncludingMethodName;
373 }
374 }
375 }
376
377 /**Parses the SQL DDL stored in $this->contents.
378 *
379 * The method _parseBodyLine($bodyLine) gets called for each line.
380 * @see contents
381 * @see _parseBodyLine
382 * @return boolean True is returned on success. If false is returned the parsing of the whole table should be aborted.
383 * @access private
384 */
385 function _parse()
386 {
387 preg_match("/CREATE\sTABLE\s([\$]?[a-zA-Z0-9_]*)([\s\S]*)\([\n\r]([\s\S]*)[\n\r]{1}\);/i", $this->contents, $matches);
388
389 if (count($matches) != 4) {
390 RSErrorManager::raiseRSError('RSDEngineDBTable', "config['sql']", "RSDEngineDBTable::_parse", "The CREATE TABLE statement is in an incorrect format:\n" . $this->contents, RSERROR_FATAL_ERROR);
391 }
392 /*
393 * setting the table name
394 */
395 if (strpos($matches[1],'$') === 0) {
396 $matches[1] = str_replace('$','$this->',$matches[1]);
397 }
398 $this->name = $matches[1];
399
400 if ($this->name == $this->rsdEngineDB->config['liveUserAuthTable']) {
401 $liveUserAuthTableColumnUserid = $this->rsdEngineDB->config['liveUserAuthTableColumnUserid'];
402 $this->_afterInsert .= "if (PEAR::isError(\$error = \$this->app->callLiveUserPermAdminMethod('addUser', array(\$this->getColumnValue(\$inserts['$liveUserAuthTableColumnUserid']), 3, \$this->getColumnValue(\$inserts['$liveUserAuthTableColumnUserid']))))) {\n".
403 " \$this->delete(array('$liveUserAuthTableColumnUserid' => \$inserts['$liveUserAuthTableColumnUserid']));\n" .
404 " return \$error;\n" .
405 " }\n";
406
407 $this->_afterDelete .= " \$this->app->callLiveUserPermAdminMethod('removeUser', array(\$record['$liveUserAuthTableColumnUserid']));\n";
408 }
409
410 /*
411 * setting the table options
412 */
413 $tableOptionsStr = $matches[2];
414 if (strpos($tableOptionsStr, '/**ignore**/') !== false) {
415 $this->ignore = true;
416 $this->rsdEngineDB->config['rsdEngine']->logInfo("Ignoring table $this->name!");
417 return false;
418 }
419 $tableOptions = array();
420 $splitted = preg_split('/\/\*\*/', $tableOptionsStr);
421 while (list($key, $tableOption) = each($splitted)) {
422 $tableOption = preg_split('/\*\*\//', $tableOption);
423 if (count($tableOption) > 0 && trim($tableOption[0]) != '') {
424 $tableOptions[] = '/**' . $tableOption[0] . '**/';
425 }
426 }
427 $this->tableOptions = $tableOptions;
428 //preg_match_all('/\/\*\*[^*]*\*\*\//', $tableOptionsStr, $tableOptionMatches);
429 //$this->tableOptions = $tableOptionMatches[0];
430
431
432 /*
433 * setting the body and parsing it
434 */
435 $this->rsdEngineDB->config['rsdEngine']->logInfo("Parsing table $this->name...");
436
437 $body = $matches[3];
438 $bodyLines = preg_split('/,[\r\n]{1,}/', $body);
439 while (list($key, $bodyLine) = each($bodyLines)) {
440 $this->_parseBodyLine($bodyLine);
441 }
442
443
444 return true;
445 }
446
447 /**Parses the table options saved in $this->tableOptions.
448 * For now there are only LiveUser table options.
449 * Gets called by RSDEngineDBTable::_createKeyMethods.
450 * @see RSDEngineDBTable::_createKeyMethods
451 * @access public
452 */
453 function parseTableOptions()
454 {
455 $this->_parseLiveUserRightTableOptions();
456 $this->_parseFileTableOptions();
457 $this->_parseBeforeInsertTableOption();
458 $this->_parseAfterInsertTableOption();
459 $this->_parseBeforeUpdateTableOption();
460 $this->_parseAfterUpdateTableOption();
461 $this->_parseBeforeDeleteTableOption();
462 $this->_parseAfterDeleteTableOption();
463 $this->_parseLabelTableOption();
464 $this->_parseExcludeSelectMethodTableOptions();
465 $this->_parseIncludeSelectMethodTableOptions();
466
467 $this->_createGetLabelColumnMethod();
468 }
469
470 /**Parses the beforeInsert table option saved in $this->tableOptions.
471 * Gets called by RSDEngineDBTable::parseTableOptions.
472 * @access private
473 */
474 function _parseBeforeInsertTableOption()
475 {
476 $beforeInsert = '';
477 reset($this->tableOptions);
478 while (list($key, $tableOption) = each($this->tableOptions)) {
479 preg_match('/\/\*\*beforeInsert:([\s\S]*)\*\*\//i', $tableOption, $matches);
480 if (count($matches) !== 0) {
481 $this->_beforeInsert .= $matches[1] . "\n";
482 }
483 }
484 }
485
486 /**Parses the afterInsert table option saved in $this->tableOptions.
487 * Gets called by RSDEngineDBTable::parseTableOptions.
488 * @access private
489 */
490 function _parseAfterInsertTableOption()
491 {
492 $afterInsert = '';
493 reset($this->tableOptions);
494 while (list($key, $tableOption) = each($this->tableOptions)) {
495 preg_match('/\/\*\*afterInsert:([\s\S]*)\*\*\//i', $tableOption, $matches);
496 if (count($matches) !== 0) {
497 $this->_afterInsert .= $matches[1] . "\n";
498 }
499 }
500 }
501
502 /**Parses the beforeUpdate table option saved in $this->tableOptions.
503 * Gets called by RSDEngineDBTable::parseTableOptions.
504 * @access private
505 */
506 function _parseBeforeUpdateTableOption()
507 {
508 $beforeUpdate = '';
509 reset($this->tableOptions);
510 while (list($key, $tableOption) = each($this->tableOptions)) {
511 preg_match('/\/\*\*beforeUpdate:([\s\S]*)\*\*\//i', $tableOption, $matches);
512 if (count($matches) !== 0) {
513 $this->_beforeUpdate .= $matches[1] . "\n";
514 }
515 }
516 }
517
518 /**Parses the afterUpdate table option saved in $this->tableOptions.
519 * Gets called by RSDEngineDBTable::parseTableOptions.
520 * @access private
521 */
522 function _parseAfterUpdateTableOption()
523 {
524 $afterUpdate = '';
525 reset($this->tableOptions);
526 while (list($key, $tableOption) = each($this->tableOptions)) {
527 preg_match('/\/\*\*afterUpdate:([\s\S]*)\*\*\//i', $tableOption, $matches);
528 if (count($matches) !== 0) {
529 $this->_afterUpdate .= $matches[1] . "\n";
530 }
531 }
532 }
533
534 /**Parses the beforeDelete table option saved in $this->tableOptions.
535 * Gets called by RSDEngineDBTable::parseTableOptions.
536 * @access private
537 */
538 function _parseBeforeDeleteTableOption()
539 {
540 $beforeDelete = '';
541 reset($this->tableOptions);
542 while (list($key, $tableOption) = each($this->tableOptions)) {
543 preg_match('/\/\*\*beforeDelete:([\s\S]*)\*\*\//i', $tableOption, $matches);
544 if (count($matches) !== 0) {
545 $this->_beforeDelete .= $matches[1] . "\n";
546 }
547 }
548 }
549
550 /**Parses the afterDelete table option saved in $this->tableOptions.
551 * Gets called by RSDEngineDBTable::parseTableOptions.
552 * @access private
553 */
554 function _parseAfterDeleteTableOption()
555 {
556 $afterDelete = '';
557 reset($this->tableOptions);
558 while (list($key, $tableOption) = each($this->tableOptions)) {
559 preg_match('/\/\*\*afterDelete:([\s\S]*)\*\*\//i', $tableOption, $matches);
560 if (count($matches) !== 0) {
561 $this->_afterDelete .= $matches[1] . "\n";
562 }
563 }
564 }
565
566 /**Parses the file table options saved in $this->tableOptions.
567 * Gets called by RSDEngineDBTable::parseTableOptions.
568 * @access private
569 */
570 function _parseLabelTableOption()
571 {
572 $label = '';
573 reset($this->tableOptions);
574 while (list($key, $tableOption) = each($this->tableOptions)) {
575 preg_match('/\/\*\*label:([\s\S]*)\*\*\//', $tableOption, $matches);
576 if (count($matches) !== 0) {
577 $label = $matches[1];
578 }
579 }
580
581 if ($label == '') {
582 //just in case we find nothing
583 $label = '"label"';
584 reset($this->columns);
585 while (list($key, $column) = each($this->columns)) {
586 $label = $this->columns[$key]->name;
587 break;
588 }
589
590 reset($this->columns);
591 while (list($key, $column) = each($this->columns)) {
592 if (strpos(strtoupper($column->definition), "VARCHAR") !== false) {
593 $label = $column->name;
594 break;
595 }
596 }
597 }
598 $this->_label = $label;
599 }
600
601 /**Parses the file table options saved in $this->tableOptions.
602 * Gets called by RSDEngineDBTable::parseTableOptions.
603 * @access private
604 */
605 function _parseFileTableOptions()
606 {
607 $this->rsdEngineDB->config['rsdEngine']->logInfo("Parsing file options of $this->name:");
608
609 $fileOptions = array();
610 reset($this->tableOptions);
611 while (list($key, $tableOption) = each($this->tableOptions)) {
612 preg_match('/\/\*\*file(:[^*]*)\*\*\//', $tableOption, $matches);
613 if (count($matches) !== 0) {
614 $fileOption = $matches[1];
615
616 preg_match('/:type=(getController|getOneController|searchController|deleteController|updateController|createController|getTemplate|getTemplateRecord|getOneTemplate|searchTemplate|searchTemplateRecord|deleteTemplate|updateTemplate|createTemplate|childClass|baseClass|all|controllers|templates|classes|getOne|get|search|delete|update|create)/', $fileOption, $matches);
617 if (count($matches) === 0) {
618 $tmpType = 'all';
619 } else {
620 $tmpType = $matches[1];
621 }
622
623 if ($tmpType == 'controllers') {
624 $fileTypes = array('getController', 'getOneController', 'searchController', 'deleteController', 'updateController', 'createController');
625 } elseif ($tmpType == 'templates') {
626 $fileTypes = array('getTemplate', 'getTemplateRecord', 'getOneTemplate', 'searchTemplate', 'searchTemplateRecord', 'deleteTemplate', 'updateTemplate', 'createTemplate');
627 } elseif ($tmpType == 'classes') {
628 $fileTypes = array('childClass', 'baseClass');
629 } elseif ($tmpType == 'get') {
630 $fileTypes = array('getController', 'getTemplate', 'getTemplateRecord');
631 } elseif ($tmpType == 'getOne') {
632 $fileTypes = array('getOneController', 'getOneTemplate');
633 } elseif ($tmpType == 'search') {
634 $fileTypes = array('searchController', 'searchTemplate', 'searchTemplateRecord');
635 } elseif ($tmpType == 'delete') {
636 $fileTypes = array('deleteController', 'deleteTemplate');
637 } elseif ($tmpType == 'update') {
638 $fileTypes = array('updateController', 'updateTemplate');
639 } elseif ($tmpType == 'create') {
640 $fileTypes = array('createController', 'createTemplate');
641 } elseif ($tmpType == 'all') {
642 $fileTypes = array('getController', 'getOneController', 'searchController', 'deleteController', 'updateController', 'createController', 'getTemplate', 'getTemplateRecord', 'getOneTemplate', 'searchTemplate', 'searchTemplateRecord', 'deleteTemplate', 'updateTemplate', 'createTemplate', 'childClass', 'baseClass');
643 } else {
644 $fileTypes = array($tmpType);
645 }
646
647 preg_match('/:write=(true|false|overwrite)/', $fileOption, $matches);
648 if (count($matches) !== 0) {
649 $fileWrite = $matches[1];
650 } else {
651 $fileWrite = null;
652 }
653
654 preg_match('/:public=(true|false)/', $fileOption, $matches);
655 if (count($matches) !== 0) {
656 $filePublic = ($matches[1] === 'true');
657 } else {
658 $filePublic = null;
659 }
660
661 preg_match('/:header=(true|false)/', $fileOption, $matches);
662 if (count($matches) !== 0) {
663 $fileHeader = ($matches[1] === 'true');
664 } else {
665 $fileHeader = null;
666 }
667
668 preg_match('/:footer=(true|false)/', $fileOption, $matches);
669 if (count($matches) !== 0) {
670 $fileFooter = ($matches[1] === 'true');
671 } else {
672 $fileFooter = null;
673 }
674
675 preg_match('/:showKeyColumns=(true|false)/', $fileOption, $matches);
676 if (count($matches) !== 0) {
677 $showKeyColumns = ($matches[1] === 'true');
678 } else {
679 $showKeyColumns = null;
680 }
681
682 preg_match('/:orderBy=([^:*]*)/', $fileOption, $matches);
683 if (count($matches) !== 0) {
684 $fileOrderBy = $matches[1];
685 } else {
686 $fileOrderBy = null;
687 }
688
689 preg_match('/:allowUserOrderBy=(true|false)/', $fileOption, $matches);
690 if (count($matches) !== 0) {
691 $fileAllowUserOrderBy = ($matches[1] === 'true');
692 } else {
693 $fileAllowUserOrderBy = null;
694 }
695
696 preg_match('/:paging=(true|false)/', $fileOption, $matches);
697 if (count($matches) !== 0) {
698 $filePaging = ($matches[1] === 'true');
699 } else {
700 $filePaging = null;
701 }
702
703 preg_match('/:recordsPerPage=([0-9]*)/', $fileOption, $matches);
704 if (count($matches) !== 0) {
705 $fileRecordsPerPage = $matches[1];
706 } else {
707 $fileRecordsPerPage = null;
708 }
709
710 preg_match('/:selectMethodName=([a-zA-Z0-9_]*)/', $fileOption, $matches);
711 if (count($matches) !== 0) {
712 $fileSelectMethodName = $matches[1];
713 } else {
714 $fileSelectMethodName = null;
715 }
716
717 preg_match('/:separateRecordTemplate=(true|false)/', $fileOption, $matches);
718 if (count($matches) !== 0) {
719 $separateRecordTemplate = ($matches[1] === 'true');
720 } else {
721 $separateRecordTemplate = null;
722 }
723
724
725 reset($fileTypes);
726 while (list($key, $fileType) = each($fileTypes)) {
727 $properties = array(
728 'type' => $fileType,
729 'write' => $fileWrite,
730 'public' => $filePublic,
731 'header' => $fileHeader,
732 'footer' => $fileFooter,
733 'showKeyColumns' => $showKeyColumns,
734 'orderBy' => $fileOrderBy,
735 'allowUserOrderBy' => $fileAllowUserOrderBy,
736 'paging' => $filePaging,
737 'recordsPerPage' => $fileRecordsPerPage,
738 'selectMethodName' => $fileSelectMethodName,
739 'separateRecordTemplate' => $separateRecordTemplate
740 );
741
742 if (isset($fileOptions[$fileType])) {
743 $fileOptions[$fileType]->overwrite($properties);
744 } else {
745 $fileOptions[$fileType] =& new RSDEngineFileOption($properties);
746 }
747 }
748
749 /**file[:type=controllers|templates|classes|get|getOne|search|delete|update|create|getController|getOneController|searchController|deleteController|updateController|createController|getTemplate|getTemplateRecord|getOneTemplate|searchTemplate|searchTemplateRecord|deleteTemplate|updateTemplate|createTemplate|childClass|baseClass|all][:write=true|false|overwrite][:public=true|false][:header=true|false][:footer=true|false][:showKeyColumns=true|false][:orderBy=SQL_EXPRESSION][:allowUserOrderBy=true|false][:paging=true|false][:recordsPerPage=X[:selectMethodName=methodName]][separateRecordTemplate=true|false]**/
750 }
751 }
752 //logging
753 reset($fileOptions);
754 while (list($key, $val) = each($fileOptions)) {
755 $this->rsdEngineDB->config['rsdEngine']->logInfo(' - ' . $fileOptions[$key]->toString());
756 }
757 reset($fileOptions);
758
759 $this->_fileOptions =& $fileOptions;
760 }
761
762 /**Parses the LiveUserEdit table options saved in $this->tableOptions.
763 * Gets called by RSDEngineDBTable::parseTableOptions.
764 * @access private
765 */
766 function _parseLiveUserRightTableOptions()
767 {
768 if (!$this->rsdEngineDB->config['liveUser']) {
769 return;
770 }
771
772 $this->rsdEngineDB->config['rsdEngine']->logInfo("Parsing LiveUserRights of $this->name:");
773
774 reset($this->tableOptions);
775 while (list($key, $tableOption) = each($this->tableOptions)) {
776 $possibleOperations = array('all', 'insert', 'update', 'select', 'delete');
777 $allOperations = array('insert', 'update', 'select', 'delete');
778 $operation = '';
779 $leftOperand = '';
780 $rightOperand = '';
781 $type = '';
782 $tableName = '';
783 $columnName = '';
784 $query = '';
785 $selectIncludingMethodName = '';
786 $phpCode = '';
787 $condition = '';
788 $recordCondition = '';
789
790 preg_match('/\/\*\*LiveUserRight:(rightId|condition|recordCondition)=([\s\S]*)\*\*\//', $tableOption, $matches);
791 if (count($matches) !== 0) {
792 $operation = 'all';
793 $leftOperand = $matches[1];
794 $rightOperand = $matches[2];
795 } else {
796 preg_match('/\/\*\*LiveUserRight:([^:]*):(rightId|condition|recordCondition)=([\s\S]*)\*\*\//', $tableOption, $matches);
797 if (count($matches) !== 0) {
798 $operation = $matches[1];
799 $leftOperand = $matches[2];
800 $rightOperand = $matches[3];
801 } else {
802 //probably its an other table option
803 continue;
804 }
805 }
806
807 if (!in_array($operation, $possibleOperations)) {
808 continue;
809 }
810
811 if ($leftOperand == 'rightId') {
812
813 //type == 'column' ?
814 preg_match('/([a-z0-9_]*)/', $rightOperand, $matches);
815 if (isset($matches[1]) && $matches[1] == $rightOperand) {
816 $type = 'column';
817 $columnName = $rightOperand;
818
819 if (!$this->columnExists($columnName)) {
820 return RSErrorManager::raiseRSError($this->name, 'tableOptions', "RSDEngineDBTable::_parseTableOptions", "The column '$columnName' used in the following table option does not exist: '$tableOption'.", RSERROR_FATAL_ERROR);
821 }
822 }
823
824 //type == 'table.column' ?
825 preg_match('/([a-z0-9_]*)\.([a-z0-9_]*)/', $rightOperand, $matches);
826 if (isset($matches[1]) && isset($matches[2]) && ($matches[1] . '.' . $matches[2]) == $rightOperand) {
827 $type = 'table.column';
828 $tableName = $matches[1];
829 $columnName = $matches[2];
830
831 if (!$this->rsdEngineDB->tableExists($tableName)) {
832 return RSErrorManager::raiseRSError($this->name, 'tableOptions', "RSDEngineDBTable::_parseTableOptions", "The table '$tableName' used in the following table option does not exist: '$tableOption'.", RSERROR_FATAL_ERROR);
833 }
834 $table =& $this->rsdEngineDB->getTable($tableName);
835 if (!$table->columnExists($columnName)) {
836 return RSErrorManager::raiseRSError($this->name, 'tableOptions', "RSDEngineDBTable::_parseTableOptions", "The column '$columnName' used in the following table option does not exist: '$tableOption'.", RSERROR_FATAL_ERROR);
837 }
838 }
839
840 //type == 'SQL_QUERY' ?
841 preg_match('/(SELECT\ [^:]*\ FROM\ [^:]*)/i', $rightOperand, $matches);
842 if (isset($matches[1]) && $matches[1] == $rightOperand) {
843 $type = 'SQL_QUERY';
844 $query = $rightOperand;
845 }
846
847 //if it's none of the obove types it's PHP_CODE code:
848 if ($type == '') {
849 $type = 'PHP_CODE';
850 $phpCode = $rightOperand;
851 }
852
853 } elseif ($leftOperand == 'condition') {
854 $type = '';
855 $condition = $rightOperand;
856 } elseif ($leftOperand == 'recordCondition') {
857 $type = '';
858 $recordCondition = $rightOperand;
859 } else {
860 return RSErrorManager::raiseRSError($this->name, 'tableOptions', "RSDEngineDBTable::_parseTableOptions", "The left operand must be 'rightId', 'condition' or 'recordCondition' not '$leftOperand' in the table option '$tableOption'.", RSERROR_FATAL_ERROR);
861 }
862
863
864 if ($operation == 'all') {
865 $operations = $allOperations;
866 } else {
867 $operations = array($operation);
868 }
869
870 while (list($key, $operation) = each($operations)) {
871
872 //for the operation insert we only use $condition (it's only 1 record involved!)
873 if ($operation == 'insert' && $recordCondition != '') {
874 $conditionValue = $recordCondition;
875 } else {
876 $conditionValue = $condition;
877 }
878
879 //crate RSDEngineLiveUserRight instance
880 $liveUserRight =& new RSDEngineLiveUserRight(
881 array(
882 'operation' => $operation,
883 'type' => $type,
884 'tableName' => $tableName,
885 'columnName' => $columnName,
886 'query' => $query,
887 'selectIncludingMethodName' => $selectIncludingMethodName,
888 'phpCode' => $phpCode,
889 'condition' => $conditionValue,
890 'recordCondition' => $recordCondition,
891 'definition' => $tableOption
892 )
893 );
894 $this->_liveUserRights[] =& $liveUserRight;
895
896 //logging
897 $this->rsdEngineDB->config['rsdEngine']->logInfo(' - ' . $liveUserRight->toString());
898 }
899 }
900 }
901
902 /**Parses the includeSelectMethod table options saved in $this->tableOptions.
903 * Gets called by RSDEngineDBTable::parseTableOptions.
904 * @access private
905 */
906 function _parseIncludeSelectMethodTableOptions()
907 {
908 $this->rsdEngineDB->config['rsdEngine']->logInfo("Parsing includeSelectMethod options of $this->name:");
909
910 $patterns = array();
911 reset($this->tableOptions);
912 while (list($key, $tableOption) = each($this->tableOptions)) {
913 preg_match('/\/\*\*includeSelectMethod:([\s\S]*)\*\*\//', $tableOption, $matches);
914 if (count($matches) !== 0) {
915 $patterns = array_merge($patterns, split(',', $matches[1]));
916 }
917 }
918 $ret = array();
919 while (list($key, $pattern) = each($patterns)) {
920 if ($pattern != '') {
921 if (strtolower($pattern) == 'all') {
922 $pattern = '.*';
923 }
924 if ($pattern != '') {
925 $ret[] = "/^$pattern\$/";
926 }
927 }
928 }
929 $ret[] = "/^selectIncludingAll\$/";
930 $ret[] = "/^selectIncludingDirectlyRelated\$/";
931
932 $this->_includeSelectMethodPatters = $ret;
933 }
934
935 /**Parses the excludeSelectMethod table options saved in $this->tableOptions.
936 * Gets called by RSDEngineDBTable::parseTableOptions.
937 * @access private
938 */
939 function _parseExcludeSelectMethodTableOptions()
940 {
941 $this->rsdEngineDB->config['rsdEngine']->logInfo("Parsing excludeSelectMethod options of $this->name:");
942
943 $patterns = array();
944 reset($this->tableOptions);
945 while (list($key, $tableOption) = each($this->tableOptions)) {
946 preg_match('/\/\*\*excludeSelectMethod:([\s\S]*)\*\*\//', $tableOption, $matches);
947 if (count($matches) !== 0) {
948 $patterns = array_merge($patterns, split(',', $matches[1]));
949 }
950 }
951 $ret = array();
952 while (list($key, $pattern) = each($patterns)) {
953 if (strtolower($pattern) == 'all') {
954 $pattern = '.*';
955 }
956 if ($pattern != '') {
957 $ret[] = "/^$pattern\$/";
958 }
959 }
960 $this->_excludeSelectMethodPatters = $ret;
961 }
962
963 /**Parses on line of SQL-Code.
964 *
965 * If a column definition is found a new instance of RSDEngineColumn is created an stored in the associativ array columns.
966 * If a foreign key is found a new instance of RSDRelation is created an stored in the array relations.
967 * This method is called by the method _parse().
968 *
969 * @see relations
970 * @see columns
971 * @see _parse
972 * @access private
973 * @returns nothing
974 */
975 function _parseBodyLine($bodyLine)
976 {
977 $bodyLine = trim($bodyLine);
978
979 if ($bodyLine == "") {
980 return false;
981 }
982
983 preg_match("/[\s\S]*\/\*\*(ignore)\*\*\//i",$bodyLine,$matches);
984 if (isset($matches[1]) && $matches[1] != "") {
985 $this->rsdEngineDB->config['rsdEngine']->logInfo(" - IGNORE: ignoring the following line: $bodyLine");
986 return false;
987 }
988 if (strpos($bodyLine, '--') === 0 || strpos($bodyLine, '#') === 0) {
989 $this->rsdEngineDB->config['rsdEngine']->logInfo(" - IGNORE: ignoring the following line: $bodyLine");
990 return false;
991 }
992 preg_match("/([\$]?[a-z0-9_]*)[\s|\(]\s*([a-z0-9_]*)/i", $bodyLine, $matches);
993 if (isset($matches[1]) && strpos($matches[1],'$') === 0) {
994 $matches[1] = str_replace('$','$this->',$matches[1]);
995 }
996 $firstWord = $matches[1];
997 $secondWord = $matches[2];
998
999 if (strtoupper($firstWord) == "FOREIGN" && strtoupper($secondWord) == "KEY") {
1000 //foreign key (f_usertype_id) references sps_usertype(f_id),
1001 preg_match("/FOREIGN\s\s*KEY\s*\(([\s\S]*)\)\s\s*REFERENCES([\s\S]*)$/i", $bodyLine, $matches);
1002
1003 $fromTable = $this->name;
1004 $fromColumn = $matches[1];
1005 $to = $matches[2];
1006 preg_match("/([a-zA-Z0-9_]*)\s*\(([\s\S]*)\)/i", $to, $matches);
1007 $toTable = $matches[1];
1008 $toColumn = $matches[2];
1009 $this->_addRelation(new RSDEngineRelation($fromTable, $fromColumn, $toTable, $toColumn, $this));
1010
1011 preg_match("/[\s\S]*\/\*\*(deleteReferencedRecordOnDelete)\*\*\//i", $bodyLine, $matches);
1012 if (isset($matches[1]) && $matches[1] == "deleteReferencedRecordOnDelete") {
1013 $this->_afterDelete .= "\$table =& \$this->app->getTable('$toTable');\n" .
1014 "\$table->delete(array('$toColumn' => \$record['$fromColumn']));\n";
1015 }
1016 } elseif (strtoupper($firstWord) == "UNIQUE") {
1017 preg_match("/UNIQUE\s*INDEX?\s*[a-zA-Z0-9_]*\s*\(([\s\S]*)\)/i", $bodyLine, $matches);
1018 if (count($matches) < 2) {
1019 return RSErrorManager::raiseRSError($this->name, '', "RSDEngineDBTable::_parseBodyLine", "Invalid UNIQUE constaint definition in line '$bodyLine'.", RSERROR_FATAL_ERROR);
1020 }
1021 $columns = $matches[1];
1022 preg_match('/^[a-zA-Z0-9_]+$/', $columns, $matches);
1023 if (count($matches) == 1) {
1024 $uniqueColumnName = $matches[0];
1025 $uniqueColumn =& $this->getColumn($uniqueColumnName);
1026 if (PEAR::isError($uniqueColumn)) {
1027 return RSErrorManager::raiseRSError($this->name, $uniqueColumnName, "RSDEngineDBTable::_parseBodyLine", "The column $uniqueColumnName used in the line '$bodyLine' does not exist.", RSERROR_FATAL_ERROR);
1028 }
1029 $this->rsdEngineDB->config['rsdEngine']->logInfo(" - UNIQUE: $uniqueColumnName was defined as unique using a table constraint.");
1030 $uniqueColumn->unique = true;
1031 } else {
1032 $this->_addUniqueConstraint($columns);
1033 }
1034 } elseif (strtoupper($firstWord) == "PRIMARY" && strtoupper($secondWord) == "KEY") {
1035 preg_match("/PRIMARY\s*KEY\s*\(([\s\S]*)\)/i", $bodyLine, $matches);
1036 if (count($matches) < 2) {
1037 return RSErrorManager::raiseRSError($this->name, '', "RSDEngineDBTable::_parseBodyLine", "Invalid PRIMARY KEY definition in line '$bodyLine'.", RSERROR_FATAL_ERROR);
1038 }
1039 $primaryKeyColumnName = $matches[1];
1040 preg_match('/^[a-zA-Z0-9_]+$/', $primaryKeyColumnName, $matches);
1041 if (count($matches) == 1) {
1042 $primaryKeyColumn =& $this->getColumn($primaryKeyColumnName);
1043 if (PEAR::isError($primaryKeyColumn)) {
1044 return RSErrorManager::raiseRSError($this->name, $primaryKeyColumnName, "RSDEngineDBTable::_parseBodyLine", "The column $primaryKeyColumn used in the line '$bodyLine' does not exist.", RSERROR_FATAL_ERROR);
1045 }
1046 $this->rsdEngineDB->config['rsdEngine']->logInfo(" - PRIMARY KEY: $primaryKeyColumnName was defined as primary key using a table constraint.");
1047 $primaryKeyColumn->setKey("primary");
1048 } else {
1049 return RSErrorManager::raiseRSError($this->name, '', "RSDEngineDBTable::_parseBodyLine", "The line '$bodyLine' does not properly define a single column as primary key.", RSERROR_FATAL_ERROR);
1050 }
1051 } elseif (strtoupper($firstWord) == "INDEX") {
1052 $this->rsdEngineDB->config['rsdEngine']->logInfo(" - INGNORE: Ignoring INDEX definition in line '$bodyLine'.");
1053 return;
1054 } else {
1055 //f_binary_id NUMBER DEFAULT 0, /*isValid:date*/
1056
1057 //initialization
1058 $columnName = '';
1059 $isValid = '';
1060 $inputType = '';
1061 $inputTypeData = '';
1062 $sequenceName = '';
1063 $doNotInsert = '';
1064 $doNotUpdate = '';
1065 $doNotSelect = '';
1066 $editLiveUserRightOptions = array();
1067 $editLiveUserGroupOptions = array();
1068 $editLiveUserAreaOptions = array();
1069 $defaultInsertValue = '';
1070 $defaultUpdateValue = '';
1071 $key = '';
1072 $unique = '';
1073 $definition = '';
1074
1075
1076 $columnName = $firstWord;
1077 $key = "";
1078
1079 preg_match("/[\s\S]*\/\*\*isValid:([^*]*)\*\*\//i", $bodyLine, $matches);
1080 if (isset($matches[1])) {
1081 $isValid = $matches[1];
1082 } elseif ($this->rsdEngineDB->config['makeIsValidAssumption']) {
1083 preg_match("/\ CHAR\ VARYING|\ BINARY|\ VARBINARY|\ VARCHAR[2]?\s*\(\s*([0-9]*)\s*\)/i", $bodyLine, $matches);
1084 if (count($matches) == 2) {
1085 $maxLength = $matches[1];
1086 $isValid = "isString:1:$maxLength";
1087 } else {
1088 preg_match("/CHAR?\s*\(\s*([0-9]*)\s*\)/i", $bodyLine, $matches);
1089 if (count($matches) == 2) {
1090 $maxLength = $matches[1];
1091 $isValid = "isString:$maxLength:$maxLength";
1092 } else {
1093 preg_match("/\ TINYBLOB|\ TINYTEXT/i", $bodyLine, $matches);
1094 if (count($matches) == 1) {
1095 $isValid = "isString:0:" . (pow(2, 8)-1);
1096 } else {
1097 preg_match("/\ BLOB|\ TEXT/i", $bodyLine, $matches);
1098 if (count($matches) == 1) {
1099 $isValid = "isString:0:" . (pow(2, 16)-1);
1100 } else {
1101 preg_match("/\ MEDIUMBLOB|\ MEDIUMTEXT/i", $bodyLine, $matches);
1102 if (count($matches) == 1) {
1103 $isValid = "isString:0:" . (pow(2, 24)-1);
1104 } else {
1105 preg_match("/\ LONGBLOB|\ LONGTEXT/i", $bodyLine, $matches);
1106 if (count($matches) == 1) {
1107 $isValid = "isString:0:" . (pow(2, 32)-1);
1108 } else {
1109 preg_match("/\ TINYINT/i", $bodyLine, $matches);
1110 if (count($matches) == 1) {
1111 $isValid = "isInt:-128:127";
1112 } else {
1113 preg_match("/\ SMALLINT/i", $bodyLine, $matches);
1114 if (count($matches) == 1) {
1115 $isValid = "isInt:-32768:32767";
1116 } else {
1117 preg_match("/\ MEDIUMINT/i", $bodyLine, $matches);
1118 if (count($matches) == 1) {
1119 $isValid = "isInt:-8388608:8388607";
1120 } else {
1121 preg_match("/\ BIGINT/i", $bodyLine, $matches);
1122 if (count($matches) == 1) {
1123 $isValid = "isInt:-9223372036854775808:9223372036854775807";
1124 } else {
1125 preg_match("/\ INT/i", $bodyLine, $matches);
1126 if (count($matches) == 1) {
1127 $isValid = "isInt:-2147483648:2147483647";
1128 } else {
1129 preg_match("/\ DATETIME/i", $bodyLine, $matches);
1130 if (count($matches) == 1) {
1131 $isValid = "isDateTime";
1132 } else {
1133 preg_match("/\ DATE/i", $bodyLine, $matches);
1134 if (count($matches) == 1) {
1135 $isValid = "isDate";
1136 } else {
1137 preg_match("/\ TIME/i", $bodyLine, $matches);
1138 if (count($matches) == 1) {
1139 $isValid = "isTime";
1140 } else {
1141 preg_match("/\ TIMESTAMP/i", $bodyLine, $matches);
1142 if (count($matches) == 1) {
1143 $isValid = "isTimestamp";
1144 } else {
1145
1146 }
1147 }
1148 }
1149 }
1150 }
1151 }
1152 }
1153 }
1154 }
1155 }
1156 }
1157 }
1158 }
1159 }
1160 }
1161 }
1162
1163
1164 preg_match("/[\s\S]*\/\*\*inputType:([^*]*)\*\*\//i", $bodyLine, $matches);
1165 if (isset($matches[1])) {
1166 $inputTypeDefinition = $matches[1];
1167 $inputTypeDefinition = split(':', $inputTypeDefinition);
1168 $inputType = $inputTypeDefinition[0];
1169 if (count($inputTypeDefinition) > 1) {
1170 $inputTypeData = $inputTypeDefinition[1];
1171 }
1172 } elseif ($this->rsdEngineDB->config['makeInputTypeAssumption']) {
1173 preg_match("/\ CHAR\s*\(\s*([0-9]*)\s*\)/i", $bodyLine, $matches);
1174 if (count($matches) == 2) {
1175 $charLength = $matches[1];
1176 if ($charLength == '1' && ($isValid == 'isString:1:1' || $isValid == "in:'0':'1'" || $isValid == "in:'1':'0'" || $isValid == "in:'Y':'N'")) {
1177 $inputType = 'checkbox';
1178 $inputTypeData = '';
1179 }
1180 } else {
1181 preg_match("/\ DATETIME/i", $bodyLine, $matches);
1182 if (count($matches) == 1) {
1183 $inputType = 'datetime';
1184 $inputTypeData = '';
1185 } else {
1186 preg_match("/\ DATE/i", $bodyLine, $matches);
1187 if (count($matches) == 1) {
1188 $inputType = 'date';
1189 $inputTypeData = '';
1190 } else {
1191 preg_match("/\ TIME/i", $bodyLine, $matches);
1192 if (count($matches) == 1) {
1193 $inputType = 'time';
1194 $inputTypeData = '';
1195 } else {
1196 preg_match("/\ TEXT/i", $bodyLine, $matches);
1197 if (count($matches) == 1) {
1198 $inputType = 'textarea';
1199 $inputTypeData = '';
1200 }
1201 }
1202 }
1203 }
1204 }
1205 }
1206
1207
1208
1209 preg_match("/[\s\S]*\/\*\*defaultInsert:([^*]*)\*\*\//i", $bodyLine, $matches);
1210 if (isset($matches[1])) {
1211 $defaultInsertValue = $matches[1];
1212 }
1213
1214 preg_match("/[\s\S]*\/\*\*defaultUpdate:([^*]*)\*\*\//i", $bodyLine, $matches);
1215 if (isset($matches[1])) {
1216 $defaultUpdateValue = $matches[1];
1217 }
1218
1219 preg_match("/[\s\S]*\/\*\*sequence:([\$]?[a-zA-Z0-9_]*)\*\*\//i", $bodyLine, $matches);
1220 if (isset($matches[1])) {
1221 if (strpos($matches[1],'$') === 0) {
1222 $matches[1] = str_replace('$','$this->', $matches[1]);
1223 }
1224 $sequenceName = $matches[1];
1225 }
1226
1227 preg_match("/[\s\S]*\/\*\*(doNotInsert)\*\*\//i", $bodyLine, $matches);
1228 $doNotInsert = isset($matches[1]) && $matches[1] == "doNotInsert";
1229
1230 preg_match("/[\s\S]*\/\*\*(doNotUpdate)\*\*\//i", $bodyLine, $matches);
1231 $doNotUpdate = isset($matches[1]) && $matches[1] == "doNotUpdate";
1232
1233 preg_match("/[\s\S]*\/\*\*(doNotSelect)\*\*\//i", $bodyLine, $matches);
1234 $doNotSelect = isset($matches[1]) && $matches[1] == "doNotSelect";
1235
1236 preg_match("/[\s\S]*\/\*\*(deleteLiveUserRightOnDelete)\*\*\//i", $bodyLine, $matches);
1237 if (isset($matches[1]) && $matches[1] == "deleteLiveUserRightOnDelete") {
1238 $this->_afterDelete .= " \n" .
1239 " \$this->app->callLiveUserPermAdminMethod('removeRight', array(\$record['$columnName']));";
1240 }
1241
1242 preg_match("/[\s\S]*\/\*\*(deleteLiveUserAreaOnDelete)\*\*\//i", $bodyLine, $matches);
1243 if (isset($matches[1]) && $matches[1] == "deleteLiveUserAreaOnDelete") {
1244 $this->_afterDelete .= " \n" .
1245 " \$this->app->callLiveUserPermAdminMethod('removeArea', array(\$record['$columnName']));";
1246 }
1247
1248 preg_match("/[\s\S]*\/\*\*(deleteLiveUserGroupOnDelete)\*\*\//i", $bodyLine, $matches);
1249 if (isset($matches[1]) && $matches[1] == "deleteLiveUserGroupOnDelete") {
1250 $this->_afterDelete .= " \n" .
1251 " \$this->app->callLiveUserPermAdminMethod('removeGroup', array(\$record['$columnName']));";
1252 }
1253
1254 preg_match("/[\s\S]*\/\*\*(canBeNull)\*\*\//i", $bodyLine, $matches);
1255 if (isset($matches[1])) {
1256 $this->_beforeInsert .= "if (isset(\$inserts['$columnName']) && \$inserts['$columnName'] == \"userSubmittedNULL\") {\n" .
1257 " \$inserts['$columnName'] = new RSDColumnValue('NULL', '!');\n" .
1258 " }\n";
1259 $this->_beforeUpdate .= " if (isset(\$updates['$columnName']) && is_string(\$updates['$columnName']) && \$updates['$columnName'] == \"userSubmittedNULL\") {\n" .
1260 " \$updates['$columnName'] = new RSDColumnValue('NULL', '!');\n" .
1261 " }\n";
1262
1263 }
1264 preg_match_all("/\/\*\*editLiveUserRight[^*]*\*\*\//i", $bodyLine, $matches);
1265 $editLiveUserRightOptions = $matches[0];
1266
1267 preg_match_all("/\/\*\*editLiveUserGroup[^*]*\*\*\//i", $bodyLine, $matches);
1268 $editLiveUserGroupOptions = $matches[0];
1269
1270 preg_match_all("/\/\*\*editLiveUserArea[^*]*\*\*\//i", $bodyLine, $matches);
1271 $editLiveUserAreaOptions = $matches[0];
1272
1273
1274
1275 //preg_match("/[\s\S]*\/\*\*(FOREIGN KEY)\*\*\//i", $bodyLine, $matches);
1276 //if($matches[1] != "") $key = "foreign";
1277
1278 preg_match("/[\s\S]*\/\*\*(key)\*\*\//i", $bodyLine, $matches);
1279 if (isset($matches[1]) && $matches[1] != "") {
1280 $key = "undefined";
1281 }
1282
1283 preg_match("/[\s\S]*(UNIQUE)/i", $bodyLine, $matches);
1284 if (isset($matches[1]) && $matches[1] != "") {
1285 $unique = true;
1286 } else {
1287 $unique = false;
1288 }
1289
1290 preg_match("/[\s\S]*(PRIMARY KEY)/i", $bodyLine, $matches);
1291 if (isset($matches[1]) && $matches[1] != "") {
1292 $key = "primary";
1293 $unique = true;
1294 }
1295
1296 preg_match("/([a-zA-Z0-9_]*)\s\s*([\s\S]*)/i", $bodyLine, $matches);
1297 $definition = $matches[2];
1298
1299 if (
1300 $this->rsdEngineDB->config['auth'] &&
1301 $this->rsdEngineDB->config['authTable'] == $this->name &&
1302 $this->rsdEngineDB->config['authUsernameColumn'] == $columnName
1303 ) {
1304 $unique = true;
1305 $key = 'undefined';
1306 }
1307
1308 $this->_addColumn(
1309 new RSDEngineColumn(
1310 $columnName,
1311 $this->name,
1312 $isValid,
1313 $inputType,
1314 $inputTypeData,
1315 $sequenceName,
1316 $doNotInsert,
1317 $doNotUpdate,
1318 $doNotSelect,
1319 $editLiveUserRightOptions,
1320 $editLiveUserGroupOptions,
1321 $editLiveUserAreaOptions,
1322 $defaultInsertValue,
1323 $defaultUpdateValue,
1324 $key,
1325 $unique,
1326 $this->columnPrefix,
1327 $definition,
1328 $this
1329 )
1330 );
1331 }
1332 }
1333
1334 /**Adds an instance of RSDEngineColumn to the array $this->columns.
1335 *
1336 * @see column
1337 * @see RSDEngineColumn
1338 * @access private
1339 * @param RSDEngineColumn $column An instance of RSDEngineColumn.
1340 * @return mixed True on success and an instance of RSError or failure.
1341 */
1342 function _addColumn($column)
1343 {
1344 if ($this->columnExists($column->name)) {
1345 return RSErrorManager::raiseRSError($column->table, $column->name, "RSDEngineDBTable::_addColumn", "The column $column->name is defined two times in $column->table!", RSERROR_FATAL_ERROR);
1346 }
1347 if ($column->name == "") {
1348 if (get_class($column) == "rsdenginecolumn") {
1349 $message = "The property 'name' of the RSDEngineColumn instance passed to _addColumn was empty! The column was defined as: $column->definition";
1350 return RSErrorManager::raiseRSError($column->table, null, "RSDEngineDBTable::_addColumn", $message, RSERROR_FATAL_ERROR);
1351 } else {
1352 return RSErrorManager::raiseRSError(RSDEngineDB, null, "RSDEngineDBTable::_addColumn", "_addColumn was called with an argument that is not an instance of RSDEngineColumn. This probably means that the your SQL syntax was not correct.", RSERROR_FATAL_ERROR);
1353 }
1354 }
1355 $this->columns[$column->name] = $column;
1356 return true;
1357 }
1358
1359 /**Returns true if a column with such a name exists, otherwise false is returned.
1360 *
1361 * Gets called by RSDEngine::_checkRelations
1362 *
1363 * @see RSDEngine::_checkRelations
1364 * @access public
1365 * @param String $columnName The name of the column.
1366 */
1367 function columnExists($columnName)
1368 {
1369 return isset($this->columns[$columnName]);
1370 }
1371
1372 /**Returns the column named $columnName or an instance of RSError on failure.
1373 * @see columns
1374 *
1375 * @return mixed An instance of RSDEngineColumn or an instance of RSError.
1376 */
1377 function &getColumn($columnName)
1378 {
1379 if ($this->columnExists($columnName)) {
1380 return $this->columns[$columnName];
1381 } else {
1382 return RSErrorManager::raiseRSError($this->name, $columnName, "getColumn", "The column $columnName does not exists in the table $this->name.", RSERROR_FATAL_ERROR);
1383 }
1384 }
1385
1386 /**Returns the requested RSDEngineFileOption instance or the boolean value false if non-existing.
1387 * @see RSDEngineFileOption
1388 * @param String $type The type of the file option.
1389 * @return mixed An instance of RSDEngineFileOption or false.
1390 */
1391 function &_getFileOption($type)
1392 {
1393 if (isset($this->_fileOptions[$type])) {
1394 return $this->_fileOptions[$type];
1395 } else {
1396 return false;
1397 }
1398 }
1399
1400 function _getFileOptionDefaultProperty($fileType, $propertyName)
1401 {
1402 $properties = array();
1403
1404 //write
1405 $properties['write'] = 'true';
1406 if ($fileType == 'getController') {
1407 $properties['write'] = $this->rsdEngineDB->config['writeControllerGet'];
1408 } elseif ($fileType == 'getOneController') {
1409 $properties['write'] = $this->rsdEngineDB->config['writeControllerGetOne'];
1410 } elseif ($fileType == 'updateController') {
1411 $properties['write'] = $this->rsdEngineDB->config['writeControllerUpdate'];
1412 } elseif ($fileType == 'deleteController') {
1413 $properties['write'] = $this->rsdEngineDB->config['writeControllerDelete'];
1414 } elseif ($fileType == 'searchController') {
1415 $properties['write'] = $this->rsdEngineDB->config['writeControllerSearch'];
1416 } elseif ($fileType == 'createController') {
1417 $properties['write'] = $this->rsdEngineDB->config['writeControllerCreate'];
1418 } elseif ($fileType == 'getTemplate') {
1419 $properties['write'] = $this->rsdEngineDB->config['writeTemplateGet'];
1420 } elseif ($fileType == 'getOneTemplate') {
1421 $properties['write'] = $this->rsdEngineDB->config['writeTemplateGetOne'];
1422 } elseif ($fileType == 'getTemplateRecord') {
1423 $properties['write'] = $this->rsdEngineDB->config['writeTemplateGetRecord'];
1424 } elseif ($fileType == 'updateTemplate') {
1425 $properties['write'] = $this->rsdEngineDB->config['writeTemplateUpdate'];
1426 } elseif ($fileType == 'deleteTemplate') {
1427 $properties['write'] = $this->rsdEngineDB->config['writeTemplateDelete'];
1428 } elseif ($fileType == 'searchTemplate') {
1429 $properties['write'] = $this->rsdEngineDB->config['writeTemplateSearch'];
1430 } elseif ($fileType == 'searchTemplateRecord') {
1431 $properties['write'] = $this->rsdEngineDB->config['writeTemplateSearchRecord'];
1432 } elseif ($fileType == 'createTemplate') {
1433 $properties['write'] = $this->rsdEngineDB->config['writeTemplateCreate'];
1434 } elseif ($fileType == 'childClass') {
1435 $properties['write'] = $this->rsdEngineDB->config['writeTableChildClasses'];;
1436 } elseif ($fileType == 'baseClass') {
1437 $properties['write'] = $this->rsdEngineDB->config['writeTableBaseClasses'];;
1438 }
1439
1440 //public
1441 $properties['public'] = false;
1442 if ($fileType == 'getController') {
1443 $properties['public'] = $this->rsdEngineDB->config['getControllersArePublic'];
1444 } elseif ($fileType == 'getOneController') {
1445 $properties['public'] = $this->rsdEngineDB->config['getOneControllersArePublic'];
1446 } elseif ($fileType == 'getSearchController') {
1447 $properties['public'] = $this->rsdEngineDB->config['searchControllersArePublic'];
1448 } elseif ($fileType == 'updateController') {
1449 $properties['public'] = $this->rsdEngineDB->config['deleteControllersArePublic'];
1450 } elseif ($fileType == 'deleteController') {
1451 $properties['public'] = $this->rsdEngineDB->config['updateControllersArePublic'];
1452 } elseif ($fileType == 'createController') {
1453 $properties['public'] = $this->rsdEngineDB->config['createControllersArePublic'];
1454 }
1455
1456 //header
1457 $properties['header'] = $this->rsdEngineDB->config['useHeader'];
1458
1459 //footer
1460 $properties['footer'] = $this->rsdEngineDB->config['useFooter'];
1461
1462 //showKeyColumns
1463 $properties['showKeyColumns'] = $this->rsdEngineDB->config['showKeyColumns'];
1464
1465 //orderBy
1466 if (($primaryKey = $this->getPrimaryKeyColumn()) === false) {
1467 $properties['orderBy'] = '';
1468 } else {
1469 $properties['orderBy'] = $primaryKey->name;
1470 }
1471
1472 //allowUserOrderBy
1473 $properties['allowUserOrderBy'] = $this->rsdEngineDB->config['allowUserOrderBy'];
1474
1475 //paging
1476 $properties['paging'] = true;
1477 if ($fileType == 'getController') {
1478 $properties['paging'] = $this->rsdEngineDB->config['getPaging'];
1479 } elseif ($fileType == 'getTemplate') {
1480 $properties['paging'] = $this->rsdEngineDB->config['getPaging'];
1481 } elseif ($fileType == 'searchController') {
1482 $properties['paging'] = $this->rsdEngineDB->config['searchPaging'];
1483 } elseif ($fileType == 'searchTemplate') {
1484 $properties['paging'] = $this->rsdEngineDB->config['searchPaging'];
1485 }
1486
1487 //recordsPerPage
1488 $properties['recordsPerPage'] = $this->rsdEngineDB->config['recordsPerPage'];
1489
1490 //selectMethodName
1491 $properties['selectMethodName'] = 'select';
1492 if ($fileType == 'getController' || $fileType == 'getTemplate') {
1493 $properties['selectMethodName'] = $this->rsdEngineDB->config['getSelectMethodName'];
1494 } elseif ($fileType == 'getOneController' || $fileType == 'getOneTemplate') {
1495 $properties['selectMethodName'] = $this->rsdEngineDB->config['getOneSelectMethodName'];
1496 } elseif ($fileType == 'searchController' || $fileType == 'searchTemplate') {
1497 $properties['selectMethodName'] = $this->rsdEngineDB->config['searchSelectMethodName'];
1498 }
1499
1500 //separateRecordTemplate
1501 $properties['separateRecordTemplate'] = $this->rsdEngineDB->config['separateRecordTemplate'];
1502
1503 if (isset($properties[$propertyName])) {
1504 return $properties[$propertyName];
1505 } else {
1506 return null;
1507 }
1508 }
1509
1510 function getFileOptionProperty($fileType, $propertyName)
1511 {
1512 $option =& $this->_getFileOption($fileType);
1513 if ($option === false || !isset($option->$propertyName) || $option->$propertyName === null) {
1514 $defaultProperty = $this->_getFileOptionDefaultProperty($fileType, $propertyName);
1515 if ($defaultProperty === null) {
1516 return RSErrorManager::raiseRSError($this->name, '', "RSDEngineDBTable::getFileOptionProperty", "No such property: '$propertyName'.", RSERROR_FATAL_ERROR);
1517 } else {
1518 return $defaultProperty;
1519 }
1520 } else {
1521 return $option->$propertyName;
1522 }
1523 }
1524 /**Adds an instance of RSDRelation to the array $this->relations.
1525 *
1526 * @see relations
1527 * @see RSDRelation
1528 * @access private
1529 * @param RSDRelation $relation An instance of RSDRelation.
1530 */
1531 function _addRelation($relation)
1532 {
1533 $this->relations[] = $relation;
1534 }
1535
1536 /**Adds an array holding representing a unique constraint to the array $this->_uniqueConstraints.
1537 *
1538 * @see _uniqueConstraints
1539 * @access private
1540 * @param String $columns A comma seperated list of column names building the unique constraint.
1541 */
1542 function _addUniqueConstraint($columns)
1543 {
1544 $constraint = split(",",str_replace(" ", "", $columns));
1545 if (count($constraint) == 0) {
1546 return;
1547 }
1548 while (list($key, $val) = each($constraint)) {
1549 if (strpos($val,'$') === 0) {
1550 $constraint[$key] = str_replace('$', '$this->', $val);
1551 }
1552 }
1553
1554 $this->rsdEngineDB->config['rsdEngine']->logInfo(" - UNIQUE (" . RSArrayUtil::toString($constraint, ', ', '%val'). ")");
1555
1556 $this->_uniqueConstraints[] = $constraint;
1557 }
1558
1559
1560 /**Calls generateIsValidMethod on all RSDEngineColumn objects stored in $this->columns.
1561 *
1562 * @see columns
1563 * @see RSDEngineColumn
1564 * @see RSDEngineColumn::generateIsValidMethod
1565 * @see addMethod
1566 * @access private
1567 */
1568 function _createIsValidMethods()
1569 {
1570 reset($this->columns);
1571 while (list($key, $column) = each($this->columns)) {
1572 $this->addMethod($this->columns[$key]->generateIsValidMethod());
1573 }
1574 }
1575
1576 /**Calls generateUpdateLiveUserRightMethods and generateCanUpdateLiveUserRightMethods on all RSDEngineColumn objects stored in $this->columns.
1577 *
1578 * @see columns
1579 * @see RSDEngineColumn
1580 * @see RSDEngineColumn::generateUpdateLiveUserRightMethod
1581 * @see RSDEngineColumn::generateCanUpdateLiveUserRightMethod
1582 * @see addMethod
1583 * @access private
1584 */
1585 function _createCanUpdateLiveUserRightMethods()
1586 {
1587 reset($this->columns);
1588 while (list($key, $column) = each($this->columns)) {
1589 $this->columns[$key]->parseLiveUserOptions();
1590 if (count($this->columns[$key]->editLiveUserRightOptions) > 0){
1591 //editLiveUserRightOptions
1592 $methods = $this->columns[$key]->generateUpdateLiveUserRightMethods();
1593 while (list($methodKey, $method) = each($methods)) {
1594 $this->addMethod($methods[$methodKey]);
1595 }
1596 $methods = $this->columns[$key]->generateCanUpdateLiveUserRightMethods();
1597 while (list($methodKey, $method) = each($methods)) {
1598 $this->addMethod($methods[$methodKey]);
1599 }
1600 } elseif (count($this->columns[$key]->editLiveUserAreaOptions) > 0){
1601 //editLiveUserAreaOptions
1602 $this->addMethod($this->columns[$key]->generateAddAdminToAreaMethod());
1603 $this->addMethod($this->columns[$key]->generateRemoveAdminFromAreaMethod());
1604 $this->addMethod($this->columns[$key]->generateUpdateAreaNameAndCommentMethod());
1605 $methods = $this->columns[$key]->generateCanUpdateLiveUserAreaMethods();
1606 while (list($methodKey, $method) = each($methods)) {
1607 $this->addMethod($methods[$methodKey]);
1608 }
1609 } elseif (count($this->columns[$key]->editLiveUserGroupOptions) > 0){
1610 //editLiveUserGroupOptions
1611 $this->addMethod($this->columns[$key]->generateAddUserToGroupMethod());
1612 $this->addMethod($this->columns[$key]->generateRemoveUserFromGroupMethod());
1613 $this->addMethod($this->columns[$key]->generateUpdateGroupNameAndCommentMethod());
1614 $this->addMethod($this->columns[$key]->generateActivateGroupMethod());
1615 $this->addMethod($this->columns[$key]->generateDeactivateGroupMethod());
1616 $methods = $this->columns[$key]->generateCanUpdateLiveUserGroupMethods();
1617 while (list($methodKey, $method) = each($methods)) {
1618 $this->addMethod($methods[$methodKey]);
1619 }
1620 }
1621
1622 }
1623 }
1624
1625 /**Calls generateStoreUploadedMethod on all RSDEngineColumn objects stored in $this->columns.
1626 *
1627 * If generateStoreUploadedMethod returns a valid RSDEngineMethod object addMethod is called
1628 * with the RSDEngineMethod object as argument.
1629 *
1630 * @see columns
1631 * @see RSDEngineColumn
1632 * @see RSDEngineColumn::generateStoreUploadedMethod
1633 * @see addMethod
1634 * @access private
1635 */
1636 function _createStoreUploadedMethods()
1637 {
1638 reset($this->columns);
1639 while (list($key, $column) = each($this->columns)) {
1640 $method =& $this->columns[$key]->generateStoreUploadedMethod();
1641 if ($method !== false) {
1642 $this->addMethod($method);
1643 }
1644 }
1645 }
1646
1647 /**Calls generateRemoveStoredMethod on all RSDEngineColumn objects stored in $this->columns.
1648 *
1649 * If generateRemoveStoredMethod returns a valid RSDEngineMethod object addMethod is called
1650 * with the RSDEngineMethod object as argument.
1651 *
1652 * @see columns
1653 * @see RSDEngineColumn
1654 * @see RSDEngineColumn::generateRemoveStoredMethod
1655 * @see addMethod
1656 * @access private
1657 */
1658 function _createRemoveStoredMethods()
1659 {
1660 reset($this->columns);
1661 while (list($key, $column) = each($this->columns)) {
1662 $method =& $this->columns[$key]->generateRemoveStoredMethod();
1663 if ($method !== false) {
1664 $this->addMethod($method);
1665 }
1666 }
1667 }
1668
1669 /**Calls generateGetStoredMethod on all RSDEngineColumn objects stored in $this->columns.
1670 *
1671 * If generateGetStoredMethod returns a valid RSDEngineMethod object addMethod is called
1672 * with the RSDEngineMethod object as argument.
1673 *
1674 * @see columns
1675 * @see RSDEngineColumn
1676 * @see RSDEngineColumn::generateGetStoredMethod
1677 * @see addMethod
1678 * @access private
1679 */
1680 function _createGetStoredMethods()
1681 {
1682 reset($this->columns);
1683 while (list($key, $column) = each($this->columns)) {
1684 $method =& $this->columns[$key]->generateGetStoredMethod();
1685 if ($method !== false) {
1686 $this->addMethod($method);
1687 }
1688 }
1689 }
1690
1691 /**Calls generateGetNextMethod on all RSDEngineColumn objects stored in $this->columns.
1692 *
1693 * If generateGetNextMethod returns a valid RSDEngineMethod object addMethod is called with the RSDEngineMethod object as argument.
1694 *
1695 * @see columns
1696 * @see RSDEngineColumn
1697 * @see RSDEngineColumn::generateGetNextMethod
1698 * @see addMethod
1699 * @access private
1700 */
1701 function _createGetNextMethods()
1702 {
1703 reset($this->columns);
1704 while (list($key, $column) = each($this->columns)) {
1705 $method = $column->generateGetNextMethod();
1706 if ($method !== false) {
1707 $this->addMethod($method);
1708 }
1709 }
1710 }
1711
1712
1713 /**Creates the method 'checkUniqueConstrains'.
1714 *
1715 * @access private
1716 */
1717 function _createCheckUniqueConstraintsMethod()
1718 {
1719 $methodName = "checkUniqueConstraints";
1720 $paramString = '$assignments, $forceReferentialIntegrityCheck = false, $negativeConditions = false';
1721 $methodComments = "/" . "**" . "Returns true if no unique constraints would be violated by using the array of assignments passed as argument for a INSERT or a UPDATE operation. Otherwise an instance of PEAR_Error is returned.\n" .
1722 "*\n" .
1723 "* @param Array \$assignments An array of key-value pairs.\n" .
1724 "* @param boolean \$forceReferentialIntegrityCheck If to force an referential integrety check. This argument is optional. The default is false.\n" .
1725 "* @param String \$negativeConditions A string containing conditions that are used to solve the following problem:\n" .
1726 "* A record with the unique username 'tom' gets updated with a new password and the username is again set to 'tom'.\n" .
1727 "* When asking this method if the username 'tom' already exists the answer would be yes and our update operation would fail.\n" .
1728 "* The negative conditions allow us to exclude this very record and find out if there any other records with username='tom'.\n" .
1729 "* This argument is optional.\n" .
1730 "* @return mixed True on success an PEAR_Error on failure.\n" .
1731 "*/";
1732
1733 $body = " if (!" . strtoupper($this->projectName) . "_DB_ENSURE_REFERENTIAL_INTEGRITY && !\$forceReferentialIntegrityCheck){ \n" .
1734 " return true;\n" .
1735 " }\n" .
1736 ' if ($negativeConditions == "") {' . "\n" .
1737 ' $negativeConditions = "1 = 2";' . "\n" .
1738 ' }' . "\n";
1739 reset($this->_uniqueConstraints);
1740 while (list($key,$constraint) = each($this->_uniqueConstraints)) {
1741 //to be created:
1742 /*
1743 if(array_key_exists('f_field1',$assignments) && array_key_exists('f_field2',$assignments)){
1744 $count = $this->count(array('f_field1' => $assignments['f_field1'], 'f_field2' => $assignments['f_field2']));
1745 if(PEAR::isError($count) || $count > 0){
1746 return false;
1747 }
1748 }
1749 */
1750
1751 $def = "UNIQUE(" . RSArrayUtil::toString($constraint, ', ', '%val') . ")";
1752 $constraintKeys = array_values($constraint);
1753
1754 $condition = RSArrayUtil::toString($constraint, ' && ', 'array_key_exists("%val",$assignments)');
1755 $countConditions = RSArrayUtil::toString($constraint, ",\n ", '"%val" => $assignments["%val"]');
1756
1757 $countConditionsFormat = "";
1758 for ($i = 1; $i <= count($constraint); $i++) {
1759 $countConditionsFormat .= ($countConditionsFormat == "" ? "" : " AND ") . "%s$i";
1760 }
1761 $countConditionsFormat .= ' AND !($negativeConditions)';
1762
1763 $body .= " //$def\n" .
1764 " if ($condition) {\n" .
1765 " \$count = \$this->count(\n" .
1766 " array(\n" .
1767 " array(\n" .
1768 " $countConditions\n" .
1769 " ),\n" .
1770 " \"$countConditionsFormat\"\n" .
1771 " )\n" .
1772 " );\n" .
1773 ' if (PEAR::isError($count) || ($count !== 0 && $count !== "0")) {' . "\n" .
1774 ' return RSErrorManager::raiseRSError("' . $this->name . '", "' . $constraintKeys[0] . '", "validation", "The following constraint was violated:' . $def . '", DB_ERROR_ALREADY_EXISTS);' . "\n" .
1775 ' }' . "\n" .
1776 ' }' . "\n";
1777 }
1778 $body .= ' return true;';
1779 $this->addMethod(new RSDEngineMethod($methodName, $paramString, $methodComments, $body));
1780 }
1781
1782 /**Creates the method 'insert';
1783 *
1784 * @access private
1785 */
1786 function _createInsertMethod()
1787 {
1788
1789 $methodName = 'insert';
1790 $paramString = '$inserts, $hypothetical = false';
1791 if ($this->rsdEngineDB->config['liveUser']) {
1792 $paramString .= ', $checkRight = true';
1793 $checkRightParamComment ="\n" .
1794 "* @param boolean \$checkRight Whether to check if the current user has the right to perform this operation. The default is true.";
1795 } else {
1796 $checkRightParamComment = "";
1797 }
1798 $methodComments = "/" . "**" . "Inserts one record in this table. Returns a new DB_Result (from PEAR::DB) on success and an DB_Error (from PEAR::DB) which extends PEAR_Error.\n" .
1799 "*\n" .
1800 "* This method calles RSDTable::insert.\n" .
1801 "* @see RSDTable::insert\n" .
1802 "*\n" .
1803 "* @param Array \$inserts Contains the columns and the values as key-value pairs.$checkRightParamComment\n" .
1804 "* @param boolean \$hypothetical If set to true this method will return true if the user has the right to perform this operation.\n" .
1805 "* Otherwise an instance of RSError will be returned. This argument is optional. The default is false." .
1806 "* @return mixed True on success, an instance of PEAR_Error on failure.\n" .
1807 "*/";
1808
1809 $body = "";
1810
1811 reset($this->_liveUserRights);
1812 while (list($key, $liveUserRight) = each($this->_liveUserRights)) {
1813 if ($liveUserRight->operation != 'insert') {
1814 continue;
1815 }
1816
1817 if ($liveUserRight->condition != '') {
1818 $body .= <<<END
1819 if (\$checkRight && !($liveUserRight->condition)) {
1820 if (\$hypothetical) {
1821 return false;
1822 }
1823 return RSErrorManager::raiseRSError(\$this->name,'','insert',"You do not have the required permission to perform an insert operation in \$this->name.", RSERROR_PERMISSION_DENIED);
1824 }
1825
1826 END;;;
1827 } elseif ($liveUserRight->type == 'column') {
1828 $body .= <<<END
1829 if (\$checkRight && (!isset(\$inserts['$liveUserRight->columnName']) || !\$this->app->liveUser->checkRight(\$inserts['$liveUserRight->columnName']))) {
1830 if (\$hypothetical) {
1831 return false;
1832 }
1833 return RSErrorManager::raiseRSError(\$this->name,'','insert',"You do not have the required permission to perform an insert operation in \$this->name.", RSERROR_PERMISSION_DENIED);
1834 }
1835
1836 END;;; } elseif ($liveUserRight->type == 'table.column') {
1837 $to = $liveUserRight->relationToSelectIncludingTable->to;
1838 $toTable = $liveUserRight->relationToSelectIncludingTable->toTable;
1839 $fromColumn = $liveUserRight->relationToSelectIncludingTable->fromColumn;
1840 $toRSDTable =& $this->rsdEngineDB->getTable($toTable);
1841 $toTableNameForVariableName = $toRSDTable->getTableNameForVariableName();
1842
1843 $body .= <<<END
1844 if (\$checkRight) {
1845 if (\$hypothetical && !isset(\$inserts['$liveUserRight->columnName'])) {
1846 return true;
1847 }
1848 \$$toTableNameForVariableName =& \$this->app->getTable('$toTable');
1849 \$records = \$${toTableNameForVariableName}->get(array('$to' => \$inserts['$fromColumn']), '$liveUserRight->selectIncludingMethodName', '', '$liveUserRight->columnName', null, null, RSD_NO_LIVEUSER_RIGHT_CHECK);
1850
1851 if (!is_array(\$records)) {
1852 return RSErrorManager::raiseRSError(\$this->name,'','update','Could not check permissions.', RSERROR_UNKNOWN);
1853 }
1854
1855 while (list(\$key, \$record) = each(\$records)) {
1856 if (!\$this->app->liveUser->checkRight(\$record['$liveUserRight->columnName'])) {
1857 if (\$hypothetical) {
1858 return false;
1859 }
1860 return RSErrorManager::raiseRSError(\$this->name,'','update','You do not have the required permission for this update operation.', RSERROR_PERMISSION_DENIED);
1861 }
1862 }
1863 }
1864
1865 END;;;
1866
1867 //return RSErrorManager::raiseRSError($this->name, 'tableOptions', "RSDEngineDBTable::_createInsertMethod", "LiveUserRight type 'table.column' is not implemented for operation 'insert'.", RSERROR_FATAL_ERROR);
1868
1869
1870 } elseif ($liveUserRight->type == 'SQL_QUERY') {
1871 $body .= <<<END
1872 if (\$checkRight && (PEAR::isError(\$rightId = \$this->db->getOne("$liveUserRight->query")) || !\$this->app->liveUser->checkRight(\$rightId))) {
1873 if (\$hypothetical) {
1874 return false;
1875 }
1876 return RSErrorManager::raiseRSError(\$this->name,'','insert',"You do not have the required permission to perform an insert operation in \$this->name.", RSERROR_PERMISSION_DENIED);
1877 }
1878
1879 END;;; } elseif ($liveUserRight->type == 'PHP_CODE') {
1880 $body .= <<<END
1881 if (\$checkRight && (PEAR::isError(\$rightId = $liveUserRight->phpCode) || !\$this->app->liveUser->checkRight(\$rightId))) {
1882 if (\$hypothetical) {
1883 return false;
1884 }
1885 return RSErrorManager::raiseRSError(\$this->name,'','insert',"You do not have the required permission to perform an insert operation in \$this->name.", RSERROR_PERMISSION_DENIED);
1886 }
1887
1888 END;;; }
1889
1890
1891 //one is enough
1892 break;
1893 }
1894
1895 $body .=" if (\$hypothetical) {\n" .
1896 " return true;\n" .
1897 " }\n";
1898
1899 reset($this->columns);
1900 while (list($columnName, $column) = each($this->columns)) {
1901 if ($column->defaultInsertValue != "") {
1902 $body .= " if (!isset(\$inserts['$columnName'])) {\n" .
1903 " if (PEAR::isError(\$value = $column->defaultInsertValue)) {\n" .
1904 " return \$value;\n" .
1905 " } else {\n" .
1906 " \$inserts['$columnName'] = \$value;\n" .
1907 " }\n" .
1908 " }\n";
1909 }
1910 }
1911
1912 if ($this->_beforeInsert != '') {
1913 $body .= " $this->_beforeInsert\n";
1914 }
1915
1916 $body .=" if (PEAR::isError(\$error = parent::insert(\$inserts))) {\n" .
1917 " return \$error;\n" .
1918 " }\n";
1919
1920 if ($this->_afterInsert != '') {
1921 $body .= " $this->_afterInsert\n";
1922 }
1923 $body .=" return true;";
1924 $this->addMethod(new RSDEngineMethod($methodName, $paramString, $methodComments, $body));
1925 }
1926
1927
1928 /**Creates the method 'update';
1929 *
1930 * @access private
1931 */
1932 function _createUpdateMethod()
1933 {
1934
1935 $methodName = 'update';
1936 $paramString = '$updates, $whereConditions';
1937 if ($this->rsdEngineDB->config['liveUser']) {
1938 $paramString .= ', $checkRight = true';
1939 $checkRightParamComment = "\n* @param boolean \$checkRight Whether to check if the current user has the right to perform this operation. The default is true.";
1940 } else {
1941 $checkRightParamComment = "";
1942 }
1943 $methodComments = "/" . "**" . "Updates records in this table.\n" .
1944 "*\n" .
1945 "* This method calles RSDTable::update.\n" .
1946 "* @see RSDTable::update\n" .
1947 "*\n" .
1948 "* @param Array \$updates\n" .
1949 "* @param mixed \$whereConditions Any argument valid for generateWhereClause.$checkRightParamComment\n" .
1950 "* @return mixed True on success, an instance of PEAR_Error on failure.\n" .
1951 "*/";
1952
1953 $body = "";
1954
1955 reset($this->_liveUserRights);
1956 while (list($key, $liveUserRight) = each($this->_liveUserRights)) {
1957 if ($liveUserRight->operation != 'update') {
1958 continue;
1959 }
1960
1961 if ($liveUserRight->condition != '') {
1962 $body .= <<<END
1963 if (\$checkRight && !($liveUserRight->condition)) {
1964 return RSErrorManager::raiseRSError(\$this->name,'','insert',"You do not have the required permission to perform an insert operation in \$this->name.", RSERROR_PERMISSION_DENIED);
1965 }
1966
1967 END;;; } elseif ($liveUserRight->recordCondition != '') {
1968
1969
1970
1971 $body .= <<<END
1972 if (\$checkRight) {
1973 \$records = parent::select(\$whereConditions, '', '*', null, null, RSD_NO_LIVEUSER_RIGHT_CHECK);
1974
1975 if (!is_array(\$records)) {
1976 return RSErrorManager::raiseRSError(\$this->name,'','update','Could not check permissions.', RSERROR_UNKNOWN);
1977 }
1978
1979 while (list(\$key, \$record) = each(\$records)) {
1980 if (!($liveUserRight->recordCondition)) {
1981 return RSErrorManager::raiseRSError(\$this->name,'','update','You do not have the required permission for this update operation.', RSERROR_PERMISSION_DENIED);
1982 }
1983 }
1984 }
1985
1986 END;;;
1987 } elseif ($liveUserRight->type == 'column') {
1988
1989
1990
1991 $body .= <<<END
1992 if (\$checkRight) {
1993 \$records = parent::select(\$whereConditions, '', '$liveUserRight->columnName', null, null, RSD_NO_LIVEUSER_RIGHT_CHECK);
1994
1995 if (!is_array(\$records)) {
1996 return RSErrorManager::raiseRSError(\$this->name,'','update','Could not check permissions.', RSERROR_UNKNOWN);
1997 }
1998
1999 while (list(\$key, \$record) = each(\$records)) {
2000 if (!\$this->app->liveUser->checkRight(\$record['$liveUserRight->columnName'])) {
2001 return RSErrorManager::raiseRSError(\$this->name,'','update','You do not have the required permission for this update operation.', RSERROR_PERMISSION_DENIED);
2002 }
2003 }
2004 }
2005
2006 END;;;
2007
2008
2009 } elseif ($liveUserRight->type == 'table.column') {
2010
2011
2012
2013 $body .= <<<END
2014 if (\$checkRight) {
2015 \$records = \$this->$liveUserRight->selectIncludingMethodName(\$whereConditions, '', '$liveUserRight->columnName', null, null, RSD_NO_LIVEUSER_RIGHT_CHECK);
2016
2017 if (!is_array(\$records)) {
2018 return RSErrorManager::raiseRSError(\$this->name,'','update','Could not check permissions.', RSERROR_UNKNOWN);
2019 }
2020
2021 while (list(\$key, \$record) = each(\$records)) {
2022 if (!\$this->app->liveUser->checkRight(\$record['$liveUserRight->columnName'])) {
2023 return RSErrorManager::raiseRSError(\$this->name,'','update','You do not have the required permission for this update operation.', RSERROR_PERMISSION_DENIED);
2024 }
2025 }
2026 }
2027
2028 END;;;
2029
2030
2031 } elseif ($liveUserRight->type == 'SQL_QUERY') {
2032
2033
2034
2035 $body .= <<<END
2036 if (\$checkRight && (PEAR::isError(\$rightId = \$this->db->getOne("$liveUserRight->query")) || !\$this->app->liveUser->checkRight(\$rightId))) {
2037 return RSErrorManager::raiseRSError(\$this->name,'','update','You do not have the required permission for this update operation.', RSERROR_PERMISSION_DENIED);
2038 }
2039
2040 END;;;
2041
2042
2043 } elseif ($liveUserRight->type == 'PHP_CODE') {
2044
2045
2046
2047 $body .= <<<END
2048 if (\$checkRight && (PEAR::isError(\$rightId = $liveUserRight->phpCode) || !\$this->app->liveUser->checkRight(\$rightId))) {
2049 return RSErrorManager::raiseRSError(\$this->name,'','insert',"You do not have the required permission to perform an insert operation in \$this->name.", RSERROR_PERMISSION_DENIED);
2050 }
2051
2052 END;;;
2053
2054
2055 }
2056
2057 //one is enough
2058 break;
2059 }
2060 reset($this->columns);
2061 while (list($columnName, $column) = each($this->columns)) {
2062 if ($column->defaultUpdateValue != "") {
2063 $body .= " if (!isset(\$updates['$columnName'])) {\n" .
2064 " if (PEAR::isError(\$value = $column->defaultUpdateValue)) {\n" .
2065 " return \$value;\n" .
2066 " } else {\n" .
2067 " \$updates['$columnName'] = \$value;\n" .
2068 " }\n" .
2069 " }\n";
2070 }
2071 }
2072
2073 if ($this->_beforeUpdate != '') {
2074 $body .=" if (!isset(\$records) || !is_array(\$records)) {\n" .
2075 " \$records = parent::select(\$whereConditions, '', '*', null, null, RSD_NO_LIVEUSER_RIGHT_CHECK);\n" .
2076 " if (PEAR::isError(\$records)) {\n" .
2077 " return \$records;\n" .
2078 " }\n" .
2079 " }\n" .
2080 " reset(\$records);\n" .
2081 " while (list(\$key, \$record) = each(\$records)) {\n" .
2082 $this->_beforeUpdate . "\n" .
2083 " }\n" .
2084 "\n";
2085 }
2086
2087
2088 $body .=" if (PEAR::isError(\$error = parent::update(\$updates, \$whereConditions))) {\n" .
2089 " return \$error;\n" .
2090 " }\n";
2091
2092
2093 if ($this->_afterUpdate != '') {
2094 $body .="\n";
2095 " \$records = parent::select(\$whereConditions, '', '*', null, null, RSD_NO_LIVEUSER_RIGHT_CHECK);\n" .
2096 " if (PEAR::isError(\$records)) {\n" .
2097 " return \$records;\n" .
2098 " }\n" .
2099 " reset(\$records);\n" .
2100 " while (list(\$key, \$record) = each(\$records)) {\n" .
2101 $this->_afterUpdate . "\n" .
2102 " }\n";
2103 }
2104
2105 $body .= ' return true;';
2106
2107 $this->addMethod(new RSDEngineMethod($methodName, $paramString, $methodComments, $body));
2108 }
2109
2110 /**Creates the method 'delete';
2111 *
2112 * @access private
2113 */
2114 function _createDeleteMethod()
2115 {
2116
2117 $methodName = 'delete';
2118 $paramString = '$whereConditions';
2119 if ($this->rsdEngineDB->config['liveUser']) {
2120 $paramString .= ', $checkRight = true';
2121 $checkRightParamComment = "\n* @param boolean \$checkRight Whether to check if the current user has the right to perform this operation. The default is true.";
2122 } else {
2123 $checkRightParamComment = "";
2124 }
2125 $methodComments = "/" . "**" . "Deletes records from this table.\n" .
2126 "*\n" .
2127 "* This method calles RSDTable::delete.\n" .
2128 "* @see RSDTable::delete\n" .
2129 "*\n" .
2130 "* @param mixed \$whereConditions Any argument valid for generateWhereClause.$checkRightParamComment\n" .
2131 "* @return mixed True on success, an instance of PEAR_Error on failure.\n" .
2132 "*/";
2133
2134 $body = "";
2135
2136
2137 reset($this->_liveUserRights);
2138 while (list($key, $liveUserRight) = each($this->_liveUserRights)) {
2139 if ($liveUserRight->operation != 'delete') {
2140 continue;
2141 }
2142
2143 if ($liveUserRight->condition != '') {
2144 $body .= <<<END
2145 if (\$checkRight && !($liveUserRight->condition)) {
2146 return RSErrorManager::raiseRSError(\$this->name,'','delete',"You do not have the required permission to perform a delete operation in \$this->name.", RSERROR_PERMISSION_DENIED);
2147 }
2148
2149 END;;; } elseif ($liveUserRight->recordCondition != '') {
2150
2151
2152
2153 $body .= <<<END
2154 if (\$checkRight) {
2155 \$records = parent::select(\$whereConditions, '', '*', null, null, RSD_NO_LIVEUSER_RIGHT_CHECK);
2156
2157 if (!is_array(\$records)) {
2158 return RSErrorManager::raiseRSError(\$this->name,'','delete','Could not check permissions.', RSERROR_UNKNOWN);
2159 }
2160
2161 while (list(\$key, \$record) = each(\$records)) {
2162 if (!($liveUserRight->recordCondition)) {
2163 return RSErrorManager::raiseRSError(\$this->name,'','delete','You do not have the required permission for this delete operation.', RSERROR_PERMISSION_DENIED);
2164 }
2165 }
2166 }
2167
2168 END;;;
2169 } elseif ($liveUserRight->type == 'column') {
2170
2171
2172
2173 $body .= <<<END
2174 if (\$checkRight) {
2175 \$records = parent::select(\$whereConditions, '', '$liveUserRight->columnName', null, null, RSD_NO_LIVEUSER_RIGHT_CHECK);
2176
2177 if (!is_array(\$records)) {
2178 return RSErrorManager::raiseRSError(\$this->name,'','delete','Could not check permissions.', RSERROR_UNKNOWN);
2179 }
2180
2181 while (list(\$key, \$record) = each(\$records)) {
2182 if (!\$this->app->liveUser->checkRight(\$record['$liveUserRight->columnName'])) {
2183 return RSErrorManager::raiseRSError(\$this->name,'','delete','You do not have the required permission for this delete operation.', RSERROR_PERMISSION_DENIED);
2184 }
2185 }
2186 }
2187
2188 END;;;
2189
2190
2191 } elseif ($liveUserRight->type == 'table.column') {
2192
2193
2194
2195 $body .= <<<END
2196 if (\$checkRight) {
2197 \$records = \$this->$liveUserRight->selectIncludingMethodName(\$whereConditions, '', '$liveUserRight->columnName', null, null, RSD_NO_LIVEUSER_RIGHT_CHECK);
2198
2199 if (!is_array(\$records)) {
2200 return RSErrorManager::raiseRSError(\$this->name,'','delete','Could not check permissions.', RSERROR_UNKNOWN);
2201 }
2202
2203 while (list(\$key, \$record) = each(\$records)) {
2204 if (!\$this->app->liveUser->checkRight(\$record['$liveUserRight->columnName'])) {
2205 return RSErrorManager::raiseRSError(\$this->name,'','delete','You do not have the required permission for this delete operation.', RSERROR_PERMISSION_DENIED);
2206 }
2207 }
2208 }
2209
2210 END;;;
2211
2212
2213 } elseif ($liveUserRight->type == 'SQL_QUERY') {
2214
2215
2216
2217 $body .= <<<END
2218 if (\$checkRight && (PEAR::isError(\$rightId = \$this->db->getOne("$liveUserRight->query")) || !\$this->app->liveUser->checkRight(\$rightId))) {
2219 return RSErrorManager::raiseRSError(\$this->name,'','delete','You do not have the required permission for this delete operation.', RSERROR_PERMISSION_DENIED);
2220 }
2221
2222 END;;;
2223
2224
2225 } elseif ($liveUserRight->type == 'PHP_CODE') {
2226
2227
2228
2229 $body .= <<<END
2230 if (\$checkRight && (PEAR::isError(\$rightId = $liveUserRight->phpCode) || !\$this->app->liveUser->checkRight(\$rightId))) {
2231 return RSErrorManager::raiseRSError(\$this->name,'','delete',"You do not have the required permission to perform a delete operation in \$this->name.", RSERROR_PERMISSION_DENIED);
2232 }
2233
2234 END;;;
2235
2236
2237 }
2238
2239 //one is enough
2240 break;
2241 }
2242
2243
2244 if ($this->_beforeDelete != '' || $this->_afterDelete != '') {
2245 $body .=" if (!isset(\$records) || !is_array(\$records)) {\n" .
2246 " \$records = parent::select(\$whereConditions, '', '*', null, null, RSD_NO_LIVEUSER_RIGHT_CHECK);\n" .
2247 " if (PEAR::isError(\$records)) {\n" .
2248 " return \$records;\n" .
2249 " }\n" .
2250 " }\n";
2251 }
2252 if ($this->_beforeDelete != '') {
2253 $body .=" reset(\$records);\n" .
2254 " while (list(\$key, \$record) = each(\$records)) {\n" .
2255 $this->_beforeDelete . "\n" .
2256 " }\n" .
2257 "\n";
2258 }
2259
2260
2261 $body .=" if (PEAR::isError(\$error = parent::delete(\$whereConditions))) {\n" .
2262 " return \$error;\n" .
2263 " }\n";
2264
2265
2266 if ($this->_afterDelete != '') {
2267 $body .="\n" .
2268 " reset(\$records);\n" .
2269 " while (list(\$key, \$record) = each(\$records)) {\n" .
2270 $this->_afterDelete . "\n" .
2271 " }\n";
2272 }
2273
2274 $body .= ' return true;';
2275
2276
2277
2278
2279 $this->addMethod(new RSDEngineMethod($methodName, $paramString, $methodComments, $body));
2280 }
2281
2282 /**Creates the method 'select';
2283 *
2284 * @access private
2285 */
2286 function _createSelectMethod()
2287 {
2288
2289 $methodName = 'select';
2290 $paramString = '$whereClause = "", $orderByClause = "", $columns = "*", $from = null, $to = null';
2291 if ($this->rsdEngineDB->config['liveUser']) {
2292 $paramString .= ', $checkRight = true';
2293 $checkRightParamComment ="\n" .
2294 "* @param boolean \$checkRight Whether to check if the current user has the right to perform this operation. The default is true.";
2295 } else {
2296 $checkRightParamComment = "";
2297 }
2298 $methodComments = <<<END
2299 /**Returns a two-demensional Array of records. One record is hold by one array.
2300 *
2301 * All arguments are optional.
2302 * @see generateWhereClause
2303 *
2304 * @param String \$whereClause Any value valid for generateWhereClause.
2305 * @param String \$orderByClause A SQL-ORDER BY clause like 'ORDER BY table.column1 AND table.column2'
2306 * @param int \$from If \$from and \$to are specified only the records from \$from to \$to are fechted and returened.
2307 * @param int \$to See \$from.$checkRightParamComment
2308 * @return Array An array of records.
2309 */
2310 END;;;
2311 /*
2312 * needed to set __canUpdate and __canDelete
2313 */
2314 $updateDone = false;
2315 $deleteDone = false;
2316 $setCanBody = "";
2317 reset($this->_liveUserRights);
2318 while (list($key, $liveUserRight) = each($this->_liveUserRights)) {
2319 if ($liveUserRight->operation == 'update' && !$updateDone) {
2320 $updateDone = true;
2321
2322 if ($liveUserRight->condition != '') {
2323 $setCanBody .= <<<END
2324 if (\$checkRight) {
2325 if (!($liveUserRight->condition)) {
2326 \$__canUpdate = false;
2327 } else {
2328 \$__canUpdate = true;
2329 }
2330 }
2331
2332 END;;;
2333 } elseif ($liveUserRight->type == 'SQL_QUERY') {
2334 $setCanBody .= <<<END
2335 if (\$checkRight) {
2336 if (PEAR::isError(\$rightId = \$this->db->getOne("$liveUserRight->query")) || !\$this->app->liveUser->checkRight(\$rightId)) {
2337 \$__canUpdate = false;
2338 } else {
2339 \$__canUpdate = true;
2340 }
2341 }
2342
2343 END;;; } elseif ($liveUserRight->type == 'PHP_CODE') {
2344 $setCanBody .= <<<END
2345 if (\$checkRight) {
2346 if (PEAR::isError(\$rightId = $liveUserRight->phpCode) || !\$this->app->liveUser->checkRight(\$rightId)) {
2347 \$__canUpdate = false;
2348 } else {
2349 \$__canUpdate = true;
2350 }
2351 }
2352
2353 END;;; } else {
2354 $updateDone = false;
2355 }
2356 } elseif ($liveUserRight->operation == 'delete' && !$deleteDone) {
2357 $deleteDone = true;
2358
2359 if ($liveUserRight->condition != '') {
2360 $setCanBody .= <<<END
2361 if (\$checkRight) {
2362 if (!($liveUserRight->condition)) {
2363 \$__canDelete = false;
2364 } else {
2365 \$__canDelete = true;
2366 }
2367 }
2368
2369 END;;;
2370 } elseif ($liveUserRight->type == 'SQL_QUERY') {
2371 $setCanBody .= <<<END
2372 if (\$checkRight) {
2373 if (PEAR::isError(\$rightId = \$this->db->getOne("$liveUserRight->query")) || !\$this->app->liveUser->checkRight(\$rightId)) {
2374 \$__canDelete = false;
2375 } else {
2376 \$__canDelete = true;
2377 }
2378 }
2379
2380 END;;; } elseif ($liveUserRight->type == 'PHP_CODE') {
2381 $setCanBody .= <<<END
2382 if (\$checkRight) {
2383 if (PEAR::isError(\$rightId = $liveUserRight->phpCode) || !\$this->app->liveUser->checkRight(\$rightId)) {
2384 \$__canDelete = false;
2385 } else {
2386 \$__canDelete = true;
2387 }
2388 }
2389
2390 END;;; } else {
2391 $deleteDone = false;
2392 }
2393 }
2394 }
2395
2396 if ($updateDone) {
2397 $setCanUpdate = "if (isset(\$__canUpdate)) {\n" .
2398 " \$records[\$key]['__canUpdate'] = \$__canUpdate;\n" .
2399 "}";
2400 } else {
2401 $setCanUpdate = "";
2402 }
2403
2404 if ($deleteDone) {
2405 $setCanDelete = "if (isset(\$__canDelete)) {\n" .
2406 " \$records[\$key]['__canDelete'] = \$__canDelete;\n" .
2407 "}";
2408 } else {
2409 $setCanDelete = "";
2410 }
2411
2412
2413
2414
2415
2416 $body = "";
2417 reset($this->_liveUserRights);
2418 while (list($key, $liveUserRight) = each($this->_liveUserRights)) {
2419 if ($liveUserRight->operation != 'select') {
2420 continue;
2421 }
2422
2423 if ($liveUserRight->condition != '') {
2424 $body .= <<<END
2425 if (\$checkRight && !($liveUserRight->condition)) {
2426 return RSErrorManager::raiseRSError(\$this->name,'','select',"You do not have the required permission to perform a select operation in \$this->name.", RSERROR_PERMISSION_DENIED);
2427 }
2428
2429 \$records = parent::select(\$whereClause, \$orderByClause, \$columns, \$from, \$to, \$checkRight);
2430 if (\$checkRight) {
2431 $setCanBody
2432
2433 while (list(\$key, \$record) = each(\$records)) {
2434 $setCanUpdate
2435 $setCanDelete
2436 \$records[\$key]['__canSelect'] = true;
2437 }
2438 }
2439
2440 return \$records;
2441
2442 END;;;
2443 } elseif ($liveUserRight->recordCondition != '') {
2444
2445 $body .= <<<END
2446 \$records = parent::select(\$whereClause, \$orderByClause, \$columns, \$from, \$to, \$checkRight);
2447
2448 if (PEAR::isError(\$records)) {
2449 return \$records;
2450 }
2451
2452 if (!\$checkRight) {
2453 return \$records;
2454 }
2455 $setCanBody
2456
2457 \$ret = array();
2458 while (list(\$key, \$record) = each(\$records)) {
2459 if ($liveUserRight->recordCondition) {
2460 $setCanUpdate
2461 $setCanDelete
2462 \$records[\$key]['__canSelect'] = true;
2463 \$ret[] =& \$records[\$key];
2464 }
2465 }
2466 return \$ret;
2467
2468 END;;;
2469
2470 } elseif ($liveUserRight->type == 'column') {
2471
2472
2473
2474 $body .= <<<END
2475 \$records = parent::select(\$whereClause, \$orderByClause, \$columns, \$from, \$to, \$checkRight);
2476
2477 if (PEAR::isError(\$records)) {
2478 return \$records;
2479 }
2480
2481 if (!\$checkRight) {
2482 return \$records;
2483 }
2484 $setCanBody
2485
2486 \$ret = array();
2487 while (list(\$key, \$record) = each(\$records)) {
2488 if (\$this->app->liveUser->checkRight(\$record['$liveUserRight->columnName'])) {
2489 $setCanUpdate
2490 $setCanDelete
2491 \$records[\$key]['__canSelect'] = true;
2492 \$ret[] =& \$records[\$key];
2493 }
2494 }
2495 return \$ret;
2496
2497 END;;;
2498
2499
2500 } elseif ($liveUserRight->type == 'table.column') {
2501
2502
2503
2504 $body .= <<<END
2505 if (\$checkRight) {
2506 \$records = \$this->$liveUserRight->selectIncludingMethodName(\$whereClause, \$orderByClause, \$columns, \$from, \$to, \$checkRight);
2507
2508 if (PEAR::isError(\$records)) {
2509 return \$records;
2510 }
2511 $setCanBody
2512
2513 \$ret = array();
2514 while (list(\$key, \$record) = each(\$records)) {
2515 if (\$this->app->liveUser->checkRight(\$record['$liveUserRight->columnName'])) {
2516 $setCanUpdate
2517 $setCanDelete
2518 \$records[\$key]['__canSelect'] = true;
2519 \$ret[] =& \$records[\$key];
2520 }
2521 }
2522 return \$ret;
2523 } else {
2524 return parent::select(\$whereClause, \$orderByClause, \$columns, \$from, \$to, \$checkRight);
2525 }
2526
2527 END;;;
2528
2529
2530 } elseif ($liveUserRight->type == 'SQL_QUERY') {
2531
2532
2533
2534 $body .= <<<END
2535 if (\$checkRight && (PEAR::isError(\$rightId = \$this->db->getOne("$liveUserRight->query")) || !\$this->app->liveUser->checkRight(\$rightId))) {
2536 return RSErrorManager::raiseRSError(\$this->name,'','select','You do not have the required permission for this select operation.', RSERROR_PERMISSION_DENIED);
2537 }
2538
2539 \$records = parent::select(\$whereClause, \$orderByClause, \$columns, \$from, \$to, \$checkRight);
2540
2541 if (\$checkRight) {
2542 $setCanBody
2543
2544 while (list(\$key, \$record) = each(\$records)) {
2545 $setCanUpdate
2546 $setCanDelete
2547 \$records[\$key]['__canSelect'] = true;
2548 }
2549 }
2550
2551 return \$records;
2552
2553 END;;;
2554
2555
2556 } elseif ($liveUserRight->type == 'PHP_CODE') {
2557
2558
2559
2560 $body .= <<<END
2561 if (\$checkRight && (PEAR::isError(\$rightId = $liveUserRight->phpCode) || !\$this->app->liveUser->checkRight(\$rightId))) {
2562 return RSErrorManager::raiseRSError(\$this->name,'','select',"You do not have the required permission to perform a select operation in \$this->name.", RSERROR_PERMISSION_DENIED);
2563 }
2564
2565 \$records = parent::select(\$whereClause, \$orderByClause, \$columns, \$from, \$to, \$checkRight);
2566 if (\$checkRight) {
2567 $setCanBody
2568
2569 while (list(\$key, \$record) = each(\$records)) {
2570 $setCanUpdate
2571 $setCanDelete
2572 \$records[\$key]['__canSelect'] = true;
2573 }
2574 }
2575
2576 return \$records;
2577
2578 END;;;
2579
2580
2581 }
2582
2583 //one is enough
2584 break;
2585 }
2586
2587 if ($body == "") {
2588 if ($setCanBody != '') {
2589 $body .= <<<END
2590 \$records = parent::select(\$whereClause, \$orderByClause, \$columns, \$from, \$to);
2591 if (\$checkRight) {
2592 $setCanBody
2593
2594 while (list(\$key, \$record) = each(\$records)) {
2595 if (isset(\$__canUpdate)) {
2596 \$records[\$key]['__canUpdate'] = \$__canUpdate;
2597 }
2598 if (isset(\$__canDelete)) {
2599 \$records[\$key]['__canDelete'] = \$__canDelete;
2600 }
2601 \$records[\$key]['__canSelect'] = true;
2602 }
2603 }
2604
2605 return \$records;
2606
2607 END;;; } else {
2608 $body = <<<END
2609 \$records = parent::select(\$whereClause, \$orderByClause, \$columns, \$from, \$to);
2610 while (list(\$key, \$record) = each(\$records)) {
2611 \$records[\$key]['__canSelect'] = true;
2612 }
2613 return \$records;
2614 END;;; }
2615 }
2616 $this->addMethod(new RSDEngineMethod($methodName, $paramString, $methodComments, $body));
2617 }
2618
2619
2620
2621 /**Creates the method 'canUpdate';
2622 *
2623 * @access private
2624 */
2625 function _createCanUpdate()
2626 {
2627 if (!$this->rsdEngineDB->config['liveUser']) {
2628 return;
2629 }
2630
2631 $methodName = 'canUpdate';
2632 $paramString = '&$paramRecord';
2633 $methodComments = "/" . "**" . "Whether the user has the permission to update the record passed as argument.\n" .
2634 "*\n" .
2635 "* @param Array \$paramRecord.\n" .
2636 "* @return boolean Returns true if the user has the permission to update the record passed as argument.\n" .
2637 "*/";
2638
2639 $body = "";
2640
2641 $primaryKey = $this->getPrimaryKeyColumn();
2642 if ($primaryKey === false) {
2643 $primaryKeyName = '';
2644 $getByPrimaryKeyMethodName = 'toString';
2645 } else {
2646 $primaryKeyName = $primaryKey->name;
2647 $getByPrimaryKeyMethodName = $this->getGetByPrimaryKeyMethodName();
2648 }
2649
2650
2651 reset($this->_liveUserRights);
2652 while (list($key, $liveUserRight) = each($this->_liveUserRights)) {
2653 if ($liveUserRight->operation != 'update') {
2654 continue;
2655 }
2656
2657
2658 if ($liveUserRight->condition != '') {
2659 $body .= <<<END
2660 if (isset(\$paramRecord['__canUpdate'])) {
2661 return \$paramRecord['__canUpdate'];
2662 }
2663
2664 if (!($liveUserRight->condition)) {
2665 \$paramRecord['__canUpdate'] = false;
2666 return false;
2667 }
2668 \$paramRecord['__canUpdate'] = true;
2669 return true;
2670
2671 END;;;
2672 } elseif ($liveUserRight->recordCondition != '') {
2673
2674 $body .= <<<END
2675 if (isset(\$paramRecord['__canUpdate'])) {
2676 return \$paramRecord['__canUpdate'];
2677 }
2678
2679 if (!isset(\$paramRecord['$primaryKeyName']) || \$paramRecord['$primaryKeyName'] == '') {
2680 return false;
2681 }
2682 \$record = \$this->$getByPrimaryKeyMethodName(\$paramRecord['$primaryKeyName'], '', '', '*', null, null, RSD_NO_LIVEUSER_RIGHT_CHECK);
2683 if (!($liveUserRight->recordCondition)) {
2684 \$paramRecord['__canUpdate'] = false;
2685 return false;
2686 }
2687 \$paramRecord['__canUpdate'] = true;
2688 return true;
2689
2690 END;;;
2691 } elseif ($liveUserRight->type == 'column') {
2692
2693
2694
2695 $body .= <<<END
2696 if (isset(\$paramRecord['__canUpdate'])) {
2697 return \$paramRecord['__canUpdate'];
2698 }
2699
2700 if (!isset(\$paramRecord['$liveUserRight->columnName'])) {
2701 if (!isset(\$paramRecord['$primaryKeyName']) || \$paramRecord['$primaryKeyName'] == '') {
2702 return false;
2703 }
2704 \$record = \$this->$getByPrimaryKeyMethodName(\$paramRecord['$primaryKeyName'], '', '', '*', null, null, RSD_NO_LIVEUSER_RIGHT_CHECK);
2705 } else {
2706 \$record = \$paramRecord;
2707 }
2708 if (!\$this->app->liveUser->checkRight(\$record['$liveUserRight->columnName'])) {
2709 \$paramRecord['__canUpdate'] = false;
2710 return false;
2711 }
2712 \$paramRecord['__canUpdate'] = true;
2713 return true;
2714
2715 END;;;
2716
2717
2718 } elseif ($liveUserRight->type == 'table.column') {
2719
2720
2721
2722 $body .= <<<END
2723 if (isset(\$paramRecord['__canUpdate'])) {
2724 return \$paramRecord['__canUpdate'];
2725 }
2726
2727 if (!isset(\$paramRecord['$liveUserRight->columnName'])) {
2728 if (!isset(\$paramRecord['$primaryKeyName']) || \$paramRecord['$primaryKeyName'] == '') {
2729 return false;
2730 }
2731 \$record = \$this->getRow(
2732 array(
2733 '$primaryKeyName' => \$paramRecord['$primaryKeyName']
2734 ),
2735 '$liveUserRight->selectIncludingMethodName',
2736 '$liveUserRight->columnName',
2737 RSD_NO_LIVEUSER_RIGHT_CHECK
2738 );
2739 } else {
2740 \$record = \$paramRecord;
2741 }
2742 if (!\$this->app->liveUser->checkRight(\$record['$liveUserRight->columnName'])) {
2743 \$paramRecord['__canUpdate'] = false;
2744 return false;
2745 }
2746 \$paramRecord['__canUpdate'] = true;
2747 return true;
2748
2749 END;;;
2750
2751
2752 } elseif ($liveUserRight->type == 'SQL_QUERY') {
2753
2754
2755
2756 $body .= <<<END
2757 if (isset(\$paramRecord['__canUpdate'])) {
2758 return \$paramRecord['__canUpdate'];
2759 }
2760
2761 if (PEAR::isError(\$rightId = \$this->db->getOne("$liveUserRight->query")) || !\$this->app->liveUser->checkRight(\$rightId)) {
2762 \$paramRecord['__canUpdate'] = false;
2763 return false;
2764 }
2765 \$paramRecord['__canUpdate'] = true;
2766 return true;
2767
2768 END;;;
2769
2770
2771 } elseif ($liveUserRight->type == 'PHP_CODE') {
2772
2773
2774
2775 $body .= <<<END
2776 if (isset(\$paramRecord['__canUpdate'])) {
2777 return \$paramRecord['__canUpdate'];
2778 }
2779
2780 if (PEAR::isError(\$rightId = $liveUserRight->phpCode) || !\$this->app->liveUser->checkRight(\$rightId)) {
2781 \$paramRecord['__canUpdate'] = false;
2782 return false;
2783 }
2784 \$paramRecord['__canUpdate'] = true;
2785 return true;
2786
2787 END;;;
2788
2789
2790 }
2791
2792 //one is enough
2793 break;
2794 }
2795 if ($body == '') {
2796 $body = " \$paramRecord['__canUpdate'] = true;\n" .
2797 " return true;";
2798 }
2799 $this->addMethod(new RSDEngineMethod($methodName, $paramString, $methodComments, $body));
2800 }
2801
2802
2803
2804
2805
2806
2807 /**Creates the method 'canDelete';
2808 *
2809 * @access private
2810 */
2811 function _createCanDelete()
2812 {
2813 if (!$this->rsdEngineDB->config['liveUser']) {
2814 return;
2815 }
2816
2817 $methodName = 'canDelete';
2818 $paramString = '&$paramRecord';
2819 $methodComments = "/" . "**" . "Whether the user has the permission to delete the record passed as argument.\n" .
2820 "*\n" .
2821 "* @param Array \$record.\n" .
2822 "* @return boolean Returns true if the user has the permission to delete the record passed as argument.\n" .
2823 "*/";
2824
2825 $body = "";
2826
2827 $primaryKey = $this->getPrimaryKeyColumn();
2828 if ($primaryKey === false) {
2829 $primaryKeyName = '';
2830 $getByPrimaryKeyMethodName = 'toString';
2831 } else {
2832 $primaryKeyName = $primaryKey->name;
2833 $getByPrimaryKeyMethodName = $this->getGetByPrimaryKeyMethodName();
2834 }
2835
2836
2837 reset($this->_liveUserRights);
2838 while (list($key, $liveUserRight) = each($this->_liveUserRights)) {
2839 if ($liveUserRight->operation != 'delete') {
2840 continue;
2841 }
2842
2843
2844 if ($liveUserRight->condition != '') {
2845 $body .= <<<END
2846 if (isset(\$paramRecord['__canDelete'])) {
2847 return \$paramRecord['__canDelete'];
2848 }
2849
2850 if (!($liveUserRight->condition)) {
2851 \$paramRecord['__canDelete'] = false;
2852 return false;
2853 }
2854 \$paramRecord['__canDelete'] = true;
2855 return true;
2856
2857 END;;;
2858 } elseif ($liveUserRight->recordCondition != '') {
2859
2860 $body .= <<<END
2861 if (isset(\$paramRecord['__canDelete'])) {
2862 return \$paramRecord['__canDelete'];
2863 }
2864
2865 if (!isset(\$paramRecord['$primaryKeyName']) || \$paramRecord['$primaryKeyName'] == '') {
2866 return false;
2867 }
2868 \$record = \$this->$getByPrimaryKeyMethodName(\$paramRecord['$primaryKeyName'], '', '', '*', null, null, RSD_NO_LIVEUSER_RIGHT_CHECK);
2869 if (!($liveUserRight->recordCondition)) {
2870 \$paramRecord['__canDelete'] = false;
2871 return false;
2872 }
2873 \$paramRecord['__canDelete'] = true;
2874 return true;
2875
2876 END;;;
2877 } elseif ($liveUserRight->type == 'column') {
2878
2879
2880
2881 $body .= <<<END
2882 if (isset(\$paramRecord['__canDelete'])) {
2883 return \$paramRecord['__canDelete'];
2884 }
2885
2886 if (!isset(\$paramRecord['$liveUserRight->columnName'])) {
2887 if (!isset(\$paramRecord['$primaryKeyName']) || \$paramRecord['$primaryKeyName'] == '') {
2888 return false;
2889 }
2890 \$record = \$this->$getByPrimaryKeyMethodName(\$paramRecord['$primaryKeyName'], '', '', '*', null, null, RSD_NO_LIVEUSER_RIGHT_CHECK);
2891 } else {
2892 \$record = \$paramRecord;
2893 }
2894 if (!\$this->app->liveUser->checkRight(\$record['$liveUserRight->columnName'])) {
2895 \$paramRecord['__canDelete'] = false;
2896 return false;
2897 }
2898 \$paramRecord['__canDelete'] = true;
2899 return true;
2900
2901 END;;;
2902
2903
2904 } elseif ($liveUserRight->type == 'table.column') {
2905
2906
2907
2908 $body .= <<<END
2909 if (isset(\$paramRecord['__canDelete'])) {
2910 return \$paramRecord['__canDelete'];
2911 }
2912
2913 if (!isset(\$paramRecord['$liveUserRight->columnName'])) {
2914 if (!isset(\$paramRecord['$primaryKeyName']) || \$paramRecord['$primaryKeyName'] == '') {
2915 return false;
2916 }
2917 \$record = \$this->getRow(
2918 array(
2919 '$primaryKeyName' => \$paramRecord['$primaryKeyName']
2920 ),
2921 '$liveUserRight->selectIncludingMethodName',
2922 '$liveUserRight->columnName',
2923 RSD_NO_LIVEUSER_RIGHT_CHECK
2924 );
2925 } else {
2926 \$record = \$paramRecord;
2927 }
2928 if (!\$this->app->liveUser->checkRight(\$record['$liveUserRight->columnName'])) {
2929 \$paramRecord['__canDelete'] = false;
2930 return false;
2931 }
2932 \$paramRecord['__canDelete'] = true;
2933 return true;
2934
2935 END;;;
2936
2937
2938 } elseif ($liveUserRight->type == 'SQL_QUERY') {
2939
2940
2941
2942 $body .= <<<END
2943 if (isset(\$paramRecord['__canDelete'])) {
2944 return \$paramRecord['__canDelete'];
2945 }
2946
2947 if (PEAR::isError(\$rightId = \$this->db->getOne("$liveUserRight->query")) || !\$this->app->liveUser->checkRight(\$rightId)) {
2948 \$paramRecord['__canDelete'] = false;
2949 return false;
2950 }
2951 \$paramRecord['__canDelete'] = true;
2952 return true;
2953
2954 END;;;
2955
2956
2957 } elseif ($liveUserRight->type == 'PHP_CODE') {
2958
2959
2960
2961 $body .= <<<END
2962 if (isset(\$paramRecord['__canDelete'])) {
2963 return \$paramRecord['__canDelete'];
2964 }
2965
2966 if (PEAR::isError(\$rightId = $liveUserRight->phpCode) || !\$this->app->liveUser->checkRight(\$rightId)) {
2967 \$paramRecord['__canDelete'] = false;
2968 return false;
2969 }
2970 \$paramRecord['__canDelete'] = true;
2971 return true;
2972
2973 END;;;
2974
2975
2976 }
2977
2978 //one is enough
2979 break;
2980 }
2981 if ($body == '') {
2982 $body = " \$paramRecord['__canDelete'] = true;\n" .
2983 " return true;";
2984 }
2985 $this->addMethod(new RSDEngineMethod($methodName, $paramString, $methodComments, $body));
2986 }
2987
2988 /**Creates the method 'canDelete';
2989 *
2990 * @access private
2991 */
2992 function _createCanSelect()
2993 {
2994 if (!$this->rsdEngineDB->config['liveUser']) {
2995 return;
2996 }
2997
2998 $methodName = 'canSelect';
2999 $paramString = '&$paramRecord';
3000 $methodComments = "/" . "**" . "Whether the user has the permission to select the record passed as argument.\n" .
3001 "*\n" .
3002 "* @param Array \$record.\n" .
3003 "* @return boolean Returns true if the user has the permission to select the record passed as argument.\n" .
3004 "*/";
3005
3006 $body = "";
3007
3008 $primaryKey = $this->getPrimaryKeyColumn();
3009 if ($primaryKey === false) {
3010 $primaryKeyName = '';
3011 $getByPrimaryKeyMethodName = 'toString';
3012 } else {
3013 $primaryKeyName = $primaryKey->name;
3014 $getByPrimaryKeyMethodName = $this->getGetByPrimaryKeyMethodName();
3015 }
3016
3017
3018 reset($this->_liveUserRights);
3019 while (list($key, $liveUserRight) = each($this->_liveUserRights)) {
3020 if ($liveUserRight->operation != 'select') {
3021 continue;
3022 }
3023
3024
3025 if ($liveUserRight->condition != '') {
3026 $body .= <<<END
3027 if (isset(\$paramRecord['__canSelect'])) {
3028 return \$paramRecord['__canSelect'];
3029 }
3030
3031 if (!($liveUserRight->condition)) {
3032 \$paramRecord['__canSelect'] = false;
3033 return false;
3034 }
3035 \$paramRecord['__canSelect'] = true;
3036 return true;
3037
3038 END;;;
3039 } elseif ($liveUserRight->recordCondition != '') {
3040
3041 $body .= <<<END
3042 if (isset(\$paramRecord['__canSelect'])) {
3043 return \$paramRecord['__canSelect'];
3044 }
3045
3046 if (!isset(\$paramRecord['$primaryKeyName']) || \$paramRecord['$primaryKeyName'] == '') {
3047 return false;
3048 }
3049 \$record = \$this->$getByPrimaryKeyMethodName(\$paramRecord['$primaryKeyName'], '', '', '*', null, null, RSD_NO_LIVEUSER_RIGHT_CHECK);
3050 if (!($liveUserRight->recordCondition)) {
3051 \$paramRecord['__canSelect'] = false;
3052 return false;
3053 }
3054 \$paramRecord['__canSelect'] = true;
3055 return true;
3056
3057 END;;;
3058 } elseif ($liveUserRight->type == 'column') {
3059
3060
3061
3062 $body .= <<<END
3063 if (isset(\$paramRecord['__canSelect'])) {
3064 return \$paramRecord['__canSelect'];
3065 }
3066
3067 if (!isset(\$paramRecord['$liveUserRight->columnName'])) {
3068 if (!isset(\$paramRecord['$primaryKeyName']) || \$paramRecord['$primaryKeyName'] == '') {
3069 return false;
3070 }
3071 \$record = \$this->$getByPrimaryKeyMethodName(\$paramRecord['$primaryKeyName'], '', '', '*', null, null, RSD_NO_LIVEUSER_RIGHT_CHECK);
3072 } else {
3073 \$record = \$paramRecord;
3074 }
3075 if (!\$this->app->liveUser->checkRight(\$record['$liveUserRight->columnName'])) {
3076 \$paramRecord['__canSelect'] = false;
3077 return false;
3078 }
3079 \$paramRecord['__canSelect'] = true;
3080 return true;
3081
3082 END;;;
3083
3084
3085 } elseif ($liveUserRight->type == 'table.column') {
3086
3087
3088
3089 $body .= <<<END
3090 if (isset(\$paramRecord['__canSelect'])) {
3091 return \$paramRecord['__canSelect'];
3092 }
3093
3094 if (!isset(\$paramRecord['$liveUserRight->columnName'])) {
3095 if (!isset(\$paramRecord['$primaryKeyName']) || \$paramRecord['$primaryKeyName'] == '') {
3096 return false;
3097 }
3098 \$record = \$this->getRow(
3099 array(
3100 '$primaryKeyName' => \$paramRecord['$primaryKeyName']
3101 ),
3102 '$liveUserRight->selectIncludingMethodName',
3103 '$liveUserRight->columnName',
3104 RSD_NO_LIVEUSER_RIGHT_CHECK
3105 );
3106 } else {
3107 \$record = \$paramRecord;
3108 }
3109 if (!\$this->app->liveUser->checkRight(\$record['$liveUserRight->columnName'])) {
3110 \$paramRecord['__canSelect'] = false;
3111 return false;
3112 }
3113 \$paramRecord['__canSelect'] = true;
3114 return true;
3115
3116 END;;;
3117
3118
3119 } elseif ($liveUserRight->type == 'SQL_QUERY') {
3120
3121
3122
3123 $body .= <<<END
3124 if (isset(\$paramRecord['__canSelect'])) {
3125 return \$paramRecord['__canSelect'];
3126 }
3127
3128 if (PEAR::isError(\$rightId = \$this->db->getOne("$liveUserRight->query")) || !\$this->app->liveUser->checkRight(\$rightId)) {
3129 \$paramRecord['__canSelect'] = false;
3130 return false;
3131 }
3132 \$paramRecord['__canSelect'] = true;
3133 return true;
3134
3135 END;;;
3136
3137
3138 } elseif ($liveUserRight->type == 'PHP_CODE') {
3139
3140
3141
3142 $body .= <<<END
3143 if (isset(\$paramRecord['__canSelect'])) {
3144 return \$paramRecord['__canSelect'];
3145 }
3146
3147 if (PEAR::isError(\$rightId = $liveUserRight->phpCode) || !\$this->app->liveUser->checkRight(\$rightId)) {
3148 \$paramRecord['__canSelect'] = false;
3149 return false;
3150 }
3151 \$paramRecord['__canSelect'] = true;
3152 return true;
3153
3154 END;;;
3155
3156
3157 }
3158
3159 //one is enough
3160 break;
3161 }
3162 if ($body == '') {
3163 $body = " \$paramRecord['__canSelect'] = true;\n" .
3164 " return true;";
3165 }
3166 $this->addMethod(new RSDEngineMethod($methodName, $paramString, $methodComments, $body));
3167 }
3168
3169
3170 /**Returns a string with all column names seperated by ", ".
3171 *
3172 * @access private
3173 * @return String Comma-seperated list of all column names.
3174 */
3175 function _getCommaSeperatedListOfColumnNames()
3176 {
3177 reset($this->columns);
3178 $ret = "";
3179 while (list($columnName, $column) = each($this->columns)) {
3180 if($ret != "") $ret .= ", ";
3181 $ret .= $columnName;
3182 }
3183 return $ret;
3184 }
3185
3186 /**Returns a string with all column names formatted for use as identifyers and prefixd with '$', seperated by ', ' and optionally quoted.
3187 *
3188 * To put single quotes around the identifieyers pass the boolean value true as argument.
3189 * The method getColumnNameForVariableName is called on every column.
3190 *
3191 * @access private
3192 * @param boolean $quoted If true the column names get surrounded by single quotes. This argument is optional. The default is false.
3193 * @return String Comma-seperated list of all column names formatted for use as identifyers and prefixed with the dollar sign.
3194 */
3195 function _getCommaSeperatedListOfColumnNamesForVariableNames($quoted = false)
3196 {
3197 reset($this->columns);
3198 $ret = "";
3199 while (list($columnName, $column) = each($this->columns)) {
3200 if($ret != "") $ret .= ", ";
3201 $ret .= ($quoted ? "'" : "") . "\$" . $column->getColumnNameForVariableName() . ($quoted ? "'" : "");
3202 }
3203 return $ret;
3204 }
3205
3206 /**Creates a deleteByCOLUMNNAME method for each column that is a primary or a foreign key.
3207 *
3208 * @access private
3209 */
3210 function _createDeleteByMethods()
3211 {
3212 reset($this->columns);
3213 while (list($key, $column) = each($this->columns)) {
3214 if ($column->isAnyKey()) {
3215 $columnName = $column->name;
3216 $variableName = $column->getColumnNameForVariableName();
3217 $methodName = "deleteBy" . $column->getColumnNameForPartialMethodName();
3218 $body = "";
3219 $methodComments = "/" . "**" . "Deletes all records from this table where $columnName equals the value passed as argument.\n" .
3220 "*\n" .
3221 "* Returns the constant DB_OK (from PEAR::DB) which equals 1 on success and DB_Error (from PEAR::DB) which inherits from PEAR_Error on failure.\n" .
3222 "* The query executed will look like: DELETE FROM $this->name WHERE $columnName = '\$$variableName'.\n" .
3223 "*\n" .
3224 "* @param mixed \$$variableName The value that will be compared to $columnName\n" .
3225 "* @param boolean \$checkRight Whether to perform a permission check. This argument is optional. The default is true.\n" .
3226 "* @return boolean\n" .
3227 "*/";
3228
3229 /*
3230 //values in where-clauses are not checked!
3231 $body .= ' if (PEAR::isError($error = $this->' . $column->generateIsValidMethodName() . "(\$$variableName))) {\n";
3232 $body .= " return \$error;\n";
3233 $body .= " }\n";
3234 */
3235 $body .= ' return $this->delete($this->generateWhereClause(array("' . $columnName . '" => $' . $variableName . ')));';
3236 $this->addMethod(new RSDEngineMethod($methodName, "\$$variableName, \$checkRight = true", $methodComments, $body));
3237 }
3238 }
3239 }
3240
3241 /**Creates a updateByCOLUMNNAME method for each column that is a primary or a foreign key.
3242 *
3243 * @access private
3244 */
3245 function _createUpdateByMethods()
3246 {
3247 reset($this->columns);
3248 while (list($key, $column) = each($this->columns)) {
3249 if ($column->isAnyKey()) {
3250 $columnName = $column->name;
3251 $variableName = $column->getColumnNameForVariableName();
3252 $methodName = "updateBy" . $column->getColumnNameForPartialMethodName();
3253 $body = "";
3254 $methodComments = "/" . "**" . "Updates all records in this table where $columnName equals the value passed as first argument.\n" .
3255 "*\n" .
3256 "* Which columns should be updated must be specified by an associative array, passed as second argument, that contains column-value pairs.\n" .
3257 "* Returns the constant DB_OK (from PEAR::DB) which equals 1 on success and DB_Error (from PEAR::DB) which inherits from PEAR_Error on failure.\n" .
3258 "* The query executed will look like: UPDATE $this->name (...) VALUES(...) WHERE $columnName = '\$$variableName'.\n" .
3259 "* @param String \$$variableName\n" .
3260 "* @param Array \$updates An associative array. See RSDTalbe::update for details.\n" .
3261 "* @param boolean \$checkRight Whether to perform a permission check. This argument is optional. The default is true.\n" .
3262 "* @return mixed\n" .
3263 "*/";
3264 /*
3265 //values in where-clauses are not checked!
3266 $body .= ' if (PEAR::isError($error = $this->' . $column->generateIsValidMethodName() . "(\$$variableName))) {\n";
3267 $body .= " return \$error;\n";
3268 $body .= " }\n";
3269 */
3270 if ($column->unique) {
3271 $body .= ' return $this->updateRow($updates, $this->generateWhereClause(array("' . $columnName . '" => $' . $variableName . ')));';
3272 } else {
3273 $body .= ' return $this->update($updates, $this->generateWhereClause(array("' . $columnName . '" => $' . $variableName . ')));';
3274 }
3275 $this->addMethod(new RSDEngineMethod($methodName, "\$$variableName, \$updates, \$checkRight = true", $methodComments, $body));
3276 }
3277 }
3278 }
3279
3280 /**Creates a getByCOLUMNNAME method for each column that is a primary or a foreign key.
3281 *
3282 * @access private
3283 */
3284 function _createGetByMethods()
3285 {
3286 reset($this->columns);
3287 while (list($key,$column) = each($this->columns)) {
3288 if ($column->isAnyKey()) {
3289 $columnName = $column->name;
3290 $variableName = $column->getColumnNameForVariableName();
3291 $methodName = "getBy" . $column->getColumnNameForPartialMethodName();
3292 $paramString = '$' . $variableName . ', $selectMethod = \'\', $orderByClause = \'\', $columns = \'*\', $from = null, $to = null, $checkRight = true';
3293 $body = "";
3294 if ($column->unique) {
3295 $methodComments = "/" . "**" . "Returns just on record in an associative array ($column->name is defined as unique).\n" .
3296 "*\n" .
3297 "* Returns the record on success and DB_Error (from PEAR::DB) which inherits from PEAR_Error on failure.\n" .
3298 "* The query executed will look like: SELECT * FROM $this->name WHERE $columnName = '\$$variableName'.\n" .
3299 "*\n" .
3300 "* @return Array The record in an associative array.\n" .
3301 "*/";
3302 } else {
3303 $methodComments = "/" . "**" . "Returns an array containing all records from this table where $columnName equals the value passed as argument.\n" .
3304 "*\n" .
3305 "* Returns an associative array of records on success and DB_Error (from PEAR::DB) which inherits from PEAR_Error on failure.\n" .
3306 "* The query executed will look like: SELECT * FROM $this->name WHERE $columnName = '\$$variableName'.\n" .
3307 "*\n" .
3308 "* @return Array An associative array containing all records.\n" .
3309 "*/";
3310 }
3311 /*
3312 //values in where-clauses are not checked!
3313 $body .= ' if(PEAR::isError($error = $this->' . $column->generateIsValidMethodName() . "(\$$variableName))){\n";
3314 $body .= " return \$error;\n";
3315 $body .= " }\n";
3316 */
3317 if ($column->unique) {
3318 $body.= ' return $this->getRow(array("' . $columnName . '" => $' . $variableName . '), $selectMethod, $columns, $checkRight);';
3319 } else {
3320 $body.= ' return $this->get(array("' . $columnName . '" => $' . $variableName . '), $selectMethod, $orderByClause, $columns, $from, $to, $checkRight);';
3321 }
3322 $this->addMethod(new RSDEngineMethod($methodName, $paramString, $methodComments,$body));
3323 }
3324 }
3325 }
3326
3327 /**Creates just one method: getLabelColumn.
3328 *
3329 * @access private
3330 */
3331 function _createGetLabelColumnMethod()
3332 {
3333 $methodName = "getLabelColumn";
3334 $paramString = "";
3335 $methodComments = "/" . "**Returns an sql statement that can be used in a select query to retrieve a literal representation of this record.\n" .
3336 "*/";
3337
3338 $labelColumn = $this->_label;
3339
3340 $this->rsdEngineDB->config['rsdEngine']->logInfo(" - The method getLabelColumn will return '$labelColumn'");
3341 $body = " return '$labelColumn';";
3342 $this->addMethod(new RSDEngineMethod($methodName, $paramString, $methodComments, $body));
3343 }
3344
3345 /**Creates just one method: getSmartyHTMLOptionsArray.
3346 *
3347 * @access private
3348 */
3349 function _createGetSmartyHTMLOptionsArrayMethod()
3350 {
3351 $methodComments = "/" . "**Returns an array for use with a SMARTY {html_options} statement.\n" .
3352 "*\n" .
3353 "* This method calls RSDTable::getSmartyHTMLOptionsArray.\n" .
3354 "* @see RSDTable::getSmartyHTMLOptionsArray\n" .
3355 "*\n" .
3356 "* @param String \$labelColumn This string can be any valid sql like CONCAT(f_lastname, ', ', f_firstname).\n" .
3357 "* This argument is optional. The default is to use the return value of getLabelColumn.\n" .
3358 "*/";
3359 $methodName = 'getSmartyHTMLOptionsArray';
3360 $paramString = '$labelColumn = false';
3361 $primaryKeyColumn = $this->getPrimaryKeyColumn();
3362 $body = " return parent::getSmartyHTMLOptionsArray('$primaryKeyColumn->name',\$labelColumn);";
3363 $this->addMethod(new RSDEngineMethod($methodName, $paramString, $methodComments, $body));
3364 }
3365
3366 /**Creates just one method: getIsValidMethodName.
3367 *
3368 * @access private
3369 */
3370 function _createGetIsValidMethodNameMethod()
3371 {
3372 $methodComments = <<<END
3373 /**Returns the name of the method that checks if a value is valid for the column supplied as argument.
3374 * @param String \$columnName The column name.
3375 * @return String The name of the isValid-Method.
3376 */
3377 END;;; $methodName = 'getIsValidMethodName';
3378 $paramString = '$columnName';
3379 $body = " return parent::getIsValidMethodName(\$columnName, '$this->columnPrefix');";
3380 $this->addMethod(new RSDEngineMethod($methodName, $paramString, $methodComments, $body));
3381 }
3382
3383 /**Creates just one method: the constructor.
3384 *
3385 * @access private
3386 */
3387 function _getConstructorMethod()
3388 {
3389 $methodName = $this->getClassName();
3390 $methodComments = "/" . "**This constructor method puts 'this' into an associativ array. The key is the table name.\n*/";
3391 $paramString = '&$db, &$app, $options = false';
3392 $body = "";
3393 $body .= ' $this->_parseOptions($options);' . "\n";
3394 $body .= ' $this->name = "' . $this->name . "\";\n";
3395 $body .= "\t" . '$this->db = &$db;' . "\n";
3396 $body .= ' if (method_exists($app, "addTable")) {' . "\n";
3397 $body .= ' $this->app = &$app;' . "\n";
3398 $body .= ' $this->app->addTable($this);' . "\n";
3399 $body .= ' }';
3400 return new RSDEngineMethod($methodName,$paramString,$methodComments,$body);
3401 }
3402
3403 /**Creates the method '_parseOptions'.
3404 *
3405 * @access private
3406 */
3407 function _createParseOptionsMethod()
3408 {
3409 $methodName = '_parseOptions';
3410 $methodComments = "/" . "**Parses the options passed as an associativ array.\n" .
3411 "*\n" .
3412 "*@param Array \$options An associative array containing key value pairs.\n" .
3413 "*/";
3414 $paramString = '&$options';
3415 $body = "";
3416 if (strpos($this->name,'$') === 0) {
3417 $body .= " $this->name = \$options['table'] != '' ? \$options['table'] : '" . RSStringUtil::removeLeadingString($this->name,'$this->') . "';\n";
3418 }
3419 reset($this->columns);
3420 while (list($key,$column) = each($this->columns)) {
3421 if (strpos($column->name,'$') === 0) {
3422 $body .= " $column->name = \$options['" . $column->getColumnNameForVariableName() . "'] != '' ? \$options['" . $column->getColumnNameForVariableName() . "'] : '" . RSStringUtil::removeLeadingString($column->name,'$this->') . "';\n";
3423 }
3424 if (strpos($column->sequenceName,'$') === 0) {
3425 $body .= " $column->sequenceName = \$options['" . $column->getSequenceNameForVariableName() . "'] != '' ? \$options['" . $column->getSequenceNameForVariableName() . "'] : '" . RSStringUtil::removeLeadingString($column->sequenceName,'$this->') . "';\n";
3426 }
3427 }
3428 $this->addMethod(new RSDEngineMethod($methodName,$paramString,$methodComments,$body));
3429 }
3430
3431 /**Returns the name of the selectIncluding method that performs a join at least over all tables saved in $tableNames.
3432 *
3433 * This method tries to find the method performing the smalles join in which all elements of $tableNames are involved.
3434 * This method can be called with a string argument:
3435 * <code>
3436 * $this->_getSelectIncludingMethodName('prj_mytable');
3437 * </code>
3438 * Or if you need multiple tables to be involved in the join:
3439 * <code>
3440 * $this->_getSelectIncludingMethodName(array('prj_mytable', 'prj_mytable2'));
3441 * </code>
3442 *
3443 * @access private
3444 * @param mixed $tableNames The name of a table or multiple table names in an array.
3445 * @return mixed The method name or an empty string on failure.
3446 */
3447 function _getSelectIncludingMethodName($tableNames)
3448 {
3449 if (!is_array($tableNames)) {
3450 $tableNames = array($tableNames);
3451 }
3452
3453 //$this->name must not be one of the tables in $tableNames
3454 $tableNamesCleaned = array();
3455 reset($tableNames);
3456 while (list($key, $tableName) = each($tableNames)) {
3457 if ($tableName != $this->name) {
3458 $tableNamesCleaned[] = $tableName;
3459 }
3460 }
3461 $tableNames = $tableNamesCleaned;
3462
3463 $selectIncludingMethodName = "";
3464 $lastSize = -1;
3465 //we want to return the smallest set of relations that contains all elements of $tableNames
3466 reset($this->_selectIncludingMethodRelations);
3467 while (list($methodName, $relationSet) = each($this->_selectIncludingMethodRelations)) {
3468
3469 //now looping over all elements of $tableNames required
3470 $tablesFound = array();
3471 reset($tableNames);
3472 while (list($key, $tableName) = each($tableNames)) {
3473
3474 //now looping over all relations in this releation set
3475 reset($this->_selectIncludingMethodRelations[$methodName]);
3476 while (list($key, $relation) = each($this->_selectIncludingMethodRelations[$methodName])) {
3477 if ($relation->toTable === $tableName) {
3478 $tablesFound[$tableName] = true;
3479 }
3480 }
3481 }
3482 if (count($tablesFound) == count($tableNames)) {
3483 if ($lastSize == -1 || $lastSize > count($this->_selectIncludingMethodRelations[$methodName])) {
3484 $selectIncludingMethodName = $methodName;
3485 $lastSize = count($this->_selectIncludingMethodRelations[$methodName]);
3486 }
3487 }
3488 }
3489 if ($selectIncludingMethodName != '') {
3490 $this->_includeSelectMethodPatters[] = "/^$selectIncludingMethodName\$/";
3491 }
3492 return $selectIncludingMethodName;
3493 }
3494
3495 /**Returns all columns that are returned from the method selectIncludingAll.
3496 * @see RSDTalbe::selectIncludingAll
3497 */
3498 function getSelectMethodColumns($methodName)
3499 {
3500 if (!isset($this->_selectIncludingMethodRelations[$methodName])) {
3501 return $this->columns;
3502 }
3503
3504 $this->_includeSelectMethodPatters[] = "/^$methodName\$/";
3505
3506 $columns = array();
3507 while (list($key, $column) = each($this->columns)) {
3508 $columns[$column->name] = $column;
3509 }
3510
3511
3512 $relations = $this->_selectIncludingMethodRelations[$methodName];
3513 $tables = array($this->name => 1);
3514 reset($relations);
3515 while (list($key, $relation) = each($relations)) {
3516 if (!isset($tables[$relation->fromTable])) {
3517 $fromTable =& $this->rsdEngineDB->getTable($relation->fromTable);
3518 reset($fromTable->columns);
3519 while (list($key, $column) = each($fromTable->columns)) {
3520 if (!isset($columns[$column->name])) {
3521 $columns[$column->name] = $column;
3522 }
3523 }
3524 $tables[$relation->fromTable] = 1;
3525 }
3526 if (!isset($tables[$relation->toTable])) {
3527 $toTable =& $this->rsdEngineDB->getTable($relation->toTable);
3528 reset($toTable->columns);
3529 while (list($key, $column) = each($toTable->columns)) {
3530 if (!isset($columns[$column->name])) {
3531 $columns[$column->name] = $column;
3532 }
3533 }
3534 $tables[$relation->toTable] = 1;
3535 }
3536 }
3537 return $columns;
3538 }
3539
3540 /**Does some preparation for the method createSelectIncludingMethod.
3541 *
3542 * This method should be called for all methods before
3543 * createSelectIncludingMethod is called. This method will
3544 * fill $this->_selectIncludingMethodRelations.
3545 * @access public
3546 * @param String $methodName The name of the method to create.
3547 * @param Array $relations An array of relations between tables that should be joined.
3548 */
3549 function prepareSelectIncludingMethod($methodName, $relations)
3550 {
3551 if (!is_array($relations) || count($relations) == 0) {
3552 return false;
3553 }
3554 $this->_selectIncludingMethodRelations[$methodName] = $relations;
3555 return true;
3556 }
3557
3558 /**Creates a selectIncluding* method.
3559 *
3560 * Gets called by RSDEngine::_createJoinFunctionsForTable.
3561 * RSDEngineDBTable::prepareSelectIncludingMethod should be called before!
3562 *
3563 * @see RSDEngine::_createJoinFunctionsForTable
3564 * @see RSDEngineDBTable::prepareSelectIncludingMethod
3565 * @access public
3566 * @param String $methodName The name of the method to create.
3567 * @param Array $relations An array of relations between tables that should be joined.
3568 */
3569 function createSelectIncludingMethod($methodName, $relations)
3570 {
3571 if (!is_array($relations) || count($relations) == 0) {
3572 return false;
3573 }
3574
3575 $this->_selectIncludingMethodRelations[$methodName] = $relations;
3576
3577 $involvedTables[$this->name] = 1;
3578 $body = "";
3579 $paramString = '$whereClause="", $orderByClause="", $columns = "*", $from = null, $to = null, $checkRight = true';
3580 $methodComments = "/" . "**" . " Returns a two-demensional Array of records. One record is hold by one array.\n" .
3581 "* @return Array[]\n" .
3582 "* @param whereClause String A SQL-WHERE clause like 'WHERE table.filed=1'\n" .
3583 "* @param orderByClause String A SQL-ORDER BY clause like 'ORDER BY table.column1 AND table.column2'\n" .
3584 "*/";
3585
3586 $body.= " if (strpos(\$whereClause, 'WHERE') !== false) {\n" .
3587 " \$whereClause = preg_replace('/^WHERE/','AND (', \"\$whereClause)\");\n" .
3588 " }\n";
3589
3590 $body.= "\t\$query = \"SELECT\n" .
3591 "\t \$columns\n" .
3592 "\tFROM\n" .
3593 "\t " . $this->name;
3594 reset($relations);
3595 while (list($key, $relation) = each($relations)) {
3596 if (!isset($involvedTables[$relation->toTable])) {
3597 $involvedTables[$relation->toTable] = 1;
3598 $body .=",\n" .
3599 "\t\t" . $relation->toTable;
3600 }
3601 if (!isset($involvedTables[$relation->fromTable])) {
3602 $involvedTables[$relation->fromTable] = 1;
3603 $body .=",\n" .
3604 "\t\t" . $relation->fromTable;
3605 }
3606 }
3607 $body .="\n\tWHERE\n" .
3608 "\t\t(\n" .
3609 "\t\t\t1=1\n";
3610 reset($relations);
3611 $first = true;
3612 while (list($key,$relation) = each($relations)) {
3613 $body .= "\t\t\tAND\n";
3614 $body .= "\t\t\t" . $relation->from . " = " . $relation->to . "\n";
3615 $first = false;
3616 }
3617 $body .="\t\t)\n" .
3618 "\t\t\$whereClause\n" .
3619 "\t\$orderByClause\n" .
3620 "\t\";\n\n";
3621
3622 $checkRightBody = "";
3623
3624
3625
3626
3627 /*
3628 * needed to set __canUpdate and __canDelete
3629 */
3630 $updateDone = false;
3631 $deleteDone = false;
3632 $setCanBody = "";
3633 reset($this->_liveUserRights);
3634 while (list($key, $liveUserRight) = each($this->_liveUserRights)) {
3635 if ($liveUserRight->operation == 'update' && !$updateDone) {
3636 $updateDone = true;
3637
3638 if ($liveUserRight->condition != '') {
3639 $setCanBody .= <<<END
3640 if (\$checkRight) {
3641 if (!($liveUserRight->condition)) {
3642 \$__canUpdate = false;
3643 } else {
3644 \$__canUpdate = true;
3645 }
3646 }
3647
3648 END;;;
3649 } elseif ($liveUserRight->type == 'SQL_QUERY') {
3650 $setCanBody .= <<<END
3651 if (\$checkRight) {
3652 if (PEAR::isError(\$rightId = \$this->db->getOne("$liveUserRight->query")) || !\$this->app->liveUser->checkRight(\$rightId)) {
3653 \$__canUpdate = false;
3654 } else {
3655 \$__canUpdate = true;
3656 }
3657 }
3658
3659 END;;; } elseif ($liveUserRight->type == 'PHP_CODE') {
3660 $setCanBody .= <<<END
3661 if (\$checkRight) {
3662 if (PEAR::isError(\$rightId = $liveUserRight->phpCode) || !\$this->app->liveUser->checkRight(\$rightId)) {
3663 \$__canUpdate = false;
3664 } else {
3665 \$__canUpdate = true;
3666 }
3667 }
3668
3669 END;;; } else {
3670 $updateDone = false;
3671 }
3672 } elseif ($liveUserRight->operation == 'delete' && !$deleteDone) {
3673 $deleteDone = true;
3674
3675 if ($liveUserRight->condition != '') {
3676 $setCanBody .= <<<END
3677 if (\$checkRight) {
3678 if (!($liveUserRight->condition)) {
3679 \$__canDelete = false;
3680 } else {
3681 \$__canDelete = true;
3682 }
3683 }
3684
3685 END;;;
3686 } elseif ($liveUserRight->type == 'SQL_QUERY') {
3687 $setCanBody .= <<<END
3688 if (\$checkRight) {
3689 if (PEAR::isError(\$rightId = \$this->db->getOne("$liveUserRight->query")) || !\$this->app->liveUser->checkRight(\$rightId)) {
3690 \$__canDelete = false;
3691 } else {
3692 \$__canDelete = true;
3693 }
3694 }
3695
3696 END;;; } elseif ($liveUserRight->type == 'PHP_CODE') {
3697 $setCanBody .= <<<END
3698 if (\$checkRight) {
3699 if (PEAR::isError(\$rightId = $liveUserRight->phpCode) || !\$this->app->liveUser->checkRight(\$rightId)) {
3700 \$__canDelete = false;
3701 } else {
3702 \$__canDelete = true;
3703 }
3704 }
3705
3706 END;;; } else {
3707 $deleteDone = false;
3708 }
3709 }
3710 }
3711
3712 if ($updateDone) {
3713 $setCanUpdate = "if (isset(\$__canUpdate)) {\n" .
3714 " \$records[\$key]['__canUpdate'] = \$__canUpdate;\n" .
3715 "}";
3716 } else {
3717 $setCanUpdate = "";
3718 }
3719
3720 if ($deleteDone) {
3721 $setCanDelete = "if (isset(\$__canDelete)) {\n" .
3722 " \$records[\$key]['__canDelete'] = \$__canDelete;\n" .
3723 "}";
3724 } else {
3725 $setCanDelete = "";
3726 }
3727
3728
3729
3730
3731
3732 reset($this->_liveUserRights);
3733 while (list($key, $liveUserRight) = each($this->_liveUserRights)) {
3734 if ($liveUserRight->operation != 'select') {
3735 continue;
3736 }
3737
3738
3739 if ($liveUserRight->condition != '') {
3740 $checkRightBody .= <<<END
3741 if (\$checkRight && !($liveUserRight->condition)) {
3742 return RSErrorManager::raiseRSError(\$this->name,'','$methodName',"You do not have the required permission to perform a select operation in \$this->name.", RSERROR_PERMISSION_DENIED);
3743 }
3744
3745 \$records = \$this->getAll(\$query, null, DB_FETCHMODE_DEFAULT, \$from, \$to);
3746 if (\$checkRight) {
3747 $setCanBody
3748
3749 while (list(\$key, \$record) = each(\$records)) {
3750 $setCanUpdate
3751 $setCanDelete
3752 \$records[\$key]['__canSelect'] = true;
3753 }
3754 }
3755
3756 return \$records;
3757
3758 END;;;
3759 } elseif ($liveUserRight->recordCondition != '') {
3760 $checkRightBody .= <<<END
3761 \$records = \$this->getAll(\$query, null, DB_FETCHMODE_DEFAULT, \$from, \$to);
3762
3763 if (PEAR::isError(\$records)) {
3764 return \$records;
3765 }
3766
3767 if (!\$checkRight) {
3768 return \$records;
3769 }
3770 $setCanBody
3771
3772
3773 \$ret = array();
3774 while (list(\$key, \$record) = each(\$records)) {
3775 if ($liveUserRight->recordCondition) {
3776 $setCanUpdate
3777 $setCanDelete
3778 \$records[\$key]['__canSelect'] = true;
3779 \$ret[] =& \$records[\$key];
3780 }
3781 }
3782 return \$ret;
3783
3784 END;;;
3785 } elseif ($liveUserRight->type == 'column') {
3786
3787
3788
3789 $checkRightBody .= <<<END
3790 \$records = \$this->getAll(\$query, null, DB_FETCHMODE_DEFAULT, \$from, \$to);
3791
3792 if (PEAR::isError(\$records)) {
3793 return \$records;
3794 }
3795
3796 if (!\$checkRight) {
3797 return \$records;
3798 }
3799 $setCanBody
3800
3801
3802 \$ret = array();
3803 while (list(\$key, \$record) = each(\$records)) {
3804 if (\$this->app->liveUser->checkRight(\$record['$liveUserRight->columnName'])) {
3805 $setCanUpdate
3806 $setCanDelete
3807 \$records[\$key]['__canSelect'] = true;
3808 \$ret[] =& \$records[\$key];
3809 }
3810 }
3811 return \$ret;
3812
3813 END;;;
3814
3815
3816 } elseif ($liveUserRight->type == 'table.column') {
3817
3818 if (!in_array($liveUserRight->tableName, array_keys($involvedTables))) {
3819 //This selectIncluding method does not perform a join over the table required by 'table.column'.
3820 //So we have got to call a selectIncludingMethod that performs a join over the required table and
3821 //all tables of this selectIncludingMethod.
3822 $neededTables = array_keys($involvedTables);
3823 $neededTables[] = $liveUserRight->tableName;
3824 $extendedSelectIncludingMethodName = $this->_getSelectIncludingMethodName($neededTables);
3825 if ($extendedSelectIncludingMethodName == '') {
3826 return RSErrorManager::raiseRSError($this->name, '_liveUserRights', "RSDEngineDBTable::createSelectIncludingMethod", "The table '$liveUserRight->tableName' used in the following table option seems to have no relation to '$this->name': '$liveUserRight->definition'.", RSERROR_FATAL_ERROR);
3827 }
3828 $checkRightBody .= <<<END
3829 if (!\$checkRight) {
3830 \$records = \$this->getAll(\$query, null, DB_FETCHMODE_DEFAULT, \$from, \$to);
3831 } else {
3832 return \$this->$extendedSelectIncludingMethodName(\$whereClause, \$orderByClause, \$columns, \$from, \$to, \$checkRight);
3833 }
3834 END;;; } else {
3835 $checkRightBody .= <<<END
3836 \$records = \$this->getAll(\$query, null, DB_FETCHMODE_DEFAULT, \$from, \$to);
3837
3838 if (PEAR::isError(\$records)) {
3839 return \$records;
3840 }
3841
3842 if (!\$checkRight) {
3843 return \$records;
3844 }
3845 $setCanBody
3846
3847 \$ret = array();
3848 while (list(\$key, \$record) = each(\$records)) {
3849 if (\$this->app->liveUser->checkRight(\$record['$liveUserRight->columnName'])) {
3850 $setCanUpdate
3851 $setCanDelete
3852 \$records[\$key]['__canSelect'] = true;
3853 \$ret[] =& \$records[\$key];
3854 }
3855 }
3856 return \$ret;
3857
3858 END;;;
3859 }
3860
3861 } elseif ($liveUserRight->type == 'SQL_QUERY') {
3862
3863
3864
3865 $checkRightBody .= <<<END
3866 if (\$checkRight && (PEAR::isError(\$rightId = \$this->db->getOne("$liveUserRight->query")) || !\$this->app->liveUser->checkRight(\$rightId))) {
3867 return RSErrorManager::raiseRSError(\$this->name,'','$methodName','You do not have the required permission for this select operation.', RSERROR_PERMISSION_DENIED);
3868 }
3869
3870 \$records = parent::select(\$whereClause, \$orderByClause, \$columns, \$from, \$to, \$checkRight);
3871
3872 if (\$checkRight) {
3873 $setCanBody
3874
3875 while (list(\$key, \$record) = each(\$records)) {
3876 $setCanUpdate
3877 $setCanDelete
3878 \$records[\$key]['__canSelect'] = true;
3879 }
3880 }
3881
3882 return \$records;
3883
3884 END;;;
3885
3886
3887 } elseif ($liveUserRight->type == 'PHP_CODE') {
3888
3889
3890
3891 $checkRightBody .= <<<END
3892 if (\$checkRight && (PEAR::isError(\$rightId = $liveUserRight->phpCode) || !\$this->app->liveUser->checkRight(\$rightId))) {
3893 return RSErrorManager::raiseRSError(\$this->name,'','$methodName',"You do not have the required permission to perform a select operation in \$this->name.", RSERROR_PERMISSION_DENIED);
3894 }
3895
3896 \$records = \$this->getAll(\$query, null, DB_FETCHMODE_DEFAULT, \$from, \$to);
3897 if (\$checkRight) {
3898 $setCanBody
3899
3900 while (list(\$key, \$record) = each(\$records)) {
3901 $setCanUpdate
3902 $setCanDelete
3903 \$records[\$key]['__canSelect'] = true;
3904 }
3905 }
3906
3907 return \$records;
3908
3909 END;;;
3910
3911
3912 }
3913
3914
3915 //one is enough
3916 break;
3917 }
3918
3919 if ($checkRightBody == "") {
3920 $body .= ' return $this->getAll($query, null, DB_FETCHMODE_DEFAULT, $from, $to);';
3921 } else {
3922 $body .= $checkRightBody;
3923 }
3924 $this->addMethod(new RSDEngineMethod($methodName, $paramString, $methodComments,$body));
3925 }
3926
3927 /**Adds an instance of RSDEngineMethod to $this->methods.
3928 *
3929 * @see methods
3930 * @see RSDEngineMethods
3931 * @access public
3932 */
3933 function addMethod($method)
3934 {
3935 $this->methods[$method->name] = &$method;
3936 }
3937
3938 /**Returns the name of this table without the prefix.
3939 *
3940 * @see tablePrefix
3941 * @access public
3942 * @return String The table name without the prefix.
3943 */
3944 function getTableNameWithoutPrefix()
3945 {
3946 $name = $this->name;
3947 if(strpos($name,'$this->') === 0){
3948 $name = substr($name,strlen('$this->'));
3949 }
3950 if($this->tablePrefix != ""){
3951 $name = preg_replace('/^' . $this->tablePrefix . '/i','', $name);
3952 }
3953 return $name;
3954 }
3955
3956 /**Returns the name of this table for use as a variable name.
3957 * @return String The table name for use as variable name.
3958 */
3959 function getTableNameForVariableName()
3960 {
3961 return $this->getTableNameWithoutPrefix();
3962 }
3963
3964 /**Returns the name of generated class.
3965 *
3966 * The name is constructed like this:
3967 * {@source }
3968 *
3969 * @access public
3970 * @return String the name of the generated class.
3971 */
3972 function getClassName()
3973 {
3974 return ucfirst($this->projectName) . ucfirst($this->getTableNameWithoutPrefix()) . "Base";
3975 }
3976
3977 /**Returns the name of generated child class.
3978 *
3979 * The generated child class does nothing but inherit the generated base class. This is because it enables
3980 * the RSDEngine to update the base class without overwriting what the developer had to code by himself.
3981 * Man-generated code has to be implemented in the child class!
3982 * The name is constructed like this:
3983 * {@source }
3984 *
3985 * @access public
3986 * @return String the name of the generated class.
3987 */
3988 function getChildClassName()
3989 {
3990 return ucfirst($this->projectName) . ucfirst($this->getTableNameWithoutPrefix());
3991 }
3992
3993 /**Returns a reasonalbe name for an instance created from the child class.
3994 *
3995 * @access public
3996 * @return String The name of the instance.
3997 */
3998 function getChildClassInstanceName()
3999 {
4000 return strtolower($this->projectName) . ucfirst($this->getTableNameWithoutPrefix());
4001 }
4002
4003 /**Returns the name for identifyer that holds a newly created instance of the created class.
4004 *
4005 * @access public
4006 * @return String The instance name.
4007 */
4008 function getInstanceName()
4009 {
4010 return strtolower($this->getTableNameWithoutPrefix());
4011 }
4012
4013 /**Returns the code for the child class.
4014 *
4015 * @access public
4016 * @return String The code for the child class.
4017 */
4018 function getChildClassCode()
4019 {
4020 $ret = "";
4021 $ret .= "/" . "**Contains just on class: " . $this->getChildClassName() . "\n";
4022 $ret .= "*\n";
4023 while(list($key,$author) = each($this->authors)){
4024 $ret .= "* @author $author\n";
4025 }
4026 $ret .= "* @copyright " . $this->copyright . "\n";
4027 $ret .= "* @package " . $this->projectName . "\n";
4028 $ret .= "* @subpackage tables\n";
4029 $ret .= "* @filesource\n";
4030 $ret .= "* @version 0.1\n";
4031 $ret .= "*/\n\n";
4032 $ret .= "/" . "**" . $this->getChildClassName() . " extends " . $this->getClassName() . " contained in " . $this->getClassName() . ".php.\n";
4033 $ret .= "*/\n";
4034 $ret .= "require_once('" . $this->getClassName() . ".php');\n";
4035 $ret .= "\n";
4036 $ret .= "/" . "**This Class gives access to the table " . $this->name . "\n";
4037 $ret .= "* It extends " . $this->getClassName() . ". Feel free to overwrite any method in this class.\n";
4038 while (list($key, $author) = each($this->authors)) {
4039 $ret .= "* @author $author\n";
4040 }
4041 $ret .= "* @copyright " . $this->copyright . "\n";
4042 $ret .= "* @package " . $this->projectName . "\n";
4043 $ret .= "* @subpackage tables\n";
4044 $ret .= "* @version 0.1\n";
4045 $ret .= "*/\n";
4046 $ret .= "class " . $this->getChildClassName() . " extends " . $this->getClassName() . " {\n";
4047 $ret .= " function " . $this->getChildClassName() . '(&$db, &$app, $options = false)' . "\n";
4048 $ret .= " {\n";
4049 $ret .= ' $this->' . $this->getClassName() . '($db, $app, $options);' . "\n";
4050 $ret .= " }\n";
4051 $ret .= "}";
4052 return $ret;
4053 }
4054
4055 /**Returns the code for the base class.
4056 *
4057 * @access public
4058 * @return String The code for the base class.
4059 */
4060 function getCode()
4061 {
4062 $validationClassName = $this->rsdEngineDB->config['validationClassName'];
4063 $validationClassFile = $this->rsdEngineDB->config['validationClassFile'];
4064
4065 $ret = "";
4066 $ret .= "/" . "**Contains just on class: " . $this->getClassName() . "\n";
4067 $ret .= "*\n";
4068 while (list($key,$author) = each($this->authors)) {
4069 $ret .= "* @author $author\n";
4070 }
4071 $ret .= "* @copyright " . $this->copyright . "\n";
4072 $ret .= "* @package " . $this->projectName . "\n";
4073 $ret .= "* @version 0.1\n";
4074 $ret .= "*/\n\n";
4075 $ret .= "/" . "**" . $this->getClassName() . " extends RSDTable contained in RSDTable.php.\n";
4076 $ret .= "*/\n";
4077 $ret .= "require_once('RSDEngine/RSDTable.php');\n";
4078 $ret .= "\n";
4079 $ret .= "/" . "**" . $this->getClassName() . " requires $validationClassName in $validationClassFile.\n";
4080 $ret .= "*/\n";
4081 $ret .= "require_once('$validationClassFile');\n";
4082 $ret .= "\n";
4083 $ret .= "/" . "**Implements logic for accessing table $this->name. Do not change this class but " . $this->getChildClassName() . "\n";
4084 $ret .= "*\n";
4085 $ret .= "* It extends RSDTable.\n";
4086 while (list($key,$author) = each($this->authors)) {
4087 $ret .= "* @author $author\n";
4088 }
4089 $ret .= "* @copyright " . $this->copyright . "\n";
4090 $ret .= "* @package " . $this->projectName . "\n";
4091 $ret .= "* @subpackage tables\n";
4092 $ret .= "* @version 0.1\n";
4093 $ret .= "*/\n";
4094 $ret .= "class " . $this->getClassName() . " extends RSDTable {\n";
4095 $constructor = $this->_getConstructorMethod();
4096 $constructor->setIndent("\t");
4097
4098
4099 $ret .= $constructor->getCode();
4100
4101
4102 while (list($methodName, $method) = each($this->methods)) {
4103
4104 //some selectIncluding* methods are probably excluded
4105 if (strpos($methodName, 'selectIncluding') === 0) {
4106 //first we want to find out if the method is exluded
4107 $excluded = false;
4108 reset($this->_excludeSelectMethodPatters);
4109 while (list($key, $pattern) = each($this->_excludeSelectMethodPatters)) {
4110 if (preg_match($pattern, $methodName)) {
4111 $excluded = true;
4112 break;
4113 }
4114 }
4115
4116 //If the method was excluded we need to know if it wasn't included again
4117 //and is therefore an exception of the exclude
4118 if ($excluded) {
4119 $included = false;
4120 reset($this->_includeSelectMethodPatters);
4121 while (list($key, $pattern) = each($this->_includeSelectMethodPatters)) {
4122 if (preg_match($pattern, $methodName)) {
4123 $included = true;
4124 break;
4125 }
4126 }
4127
4128 if (!$included) {
4129 continue;
4130 }
4131 }
4132 }
4133
4134
4135 $method->setIndent("\t");
4136 $ret .= $method->getCode();
4137 }
4138
4139
4140 $ret .= "\n}";
4141 return $ret;
4142 }
4143
4144 /**Returns the first column defined as primary key
4145 *
4146 * @return mixed An instance of RSDEngineColumn or false if no primary key column is found.
4147 */
4148 function getPrimaryKeyColumn()
4149 {
4150 reset($this->columns);
4151 while (list($key, $val) = each($this->columns)) {
4152 if ($this->columns[$key]->isPrimaryKey) {
4153 return $this->columns[$key];
4154 }
4155 }
4156 //if no primary key has been found
4157 return false;
4158 }
4159
4160 /**Returns the name of the method that can be used to delete records by the primary key from this table.
4161 *
4162 * @return String the method name.
4163 */
4164 function getDeleteByPrimaryKeyMethodName()
4165 {
4166 if (($column = $this->getPrimaryKeyColumn()) !== false) {
4167 return "deleteBy" . $column->getColumnNameForPartialMethodName();
4168 } else {
4169 return false;
4170 }
4171 }
4172
4173 /**Returns the name of the method that can be used to update records by the primary key in this table.
4174 *
4175 * @return String the method name.
4176 */
4177 function getUpdateByPrimaryKeyMethodName()
4178 {
4179 if (($column = $this->getPrimaryKeyColumn()) !== false) {
4180 return "updateBy" . $column->getColumnNameForPartialMethodName();
4181 } else {
4182 return false;
4183 }
4184 }
4185
4186 /**Returns the name of the method that can be used to retrive records by the primary key from this table.
4187 *
4188 * @return String the method name.
4189 */
4190 function getGetByPrimaryKeyMethodName()
4191 {
4192 if (($column = $this->getPrimaryKeyColumn()) !== false) {
4193 return "getBy" . $column->getColumnNameForPartialMethodName();
4194 } else {
4195 return false;
4196 }
4197 }
4198 }
4199
4200 /**Holds all information for one column of an RSDEngineDBTable.
4201 *
4202 * The access restriction for this class should be treated as 'friendly' - only accessable by classes in the same package.
4203 *
4204 * @author Lukas Feiler <lukas.feiler@chello.at>
4205 * @version 0.1.9
4206 * @copyright Lukas Feiler 2003
4207 * @package RSDEngine
4208 * @access public
4209 */
4210 class RSDEngineColumn {
4211
4212 /**The name of this column. Is set in the construtor method.
4213 *
4214 * @var String
4215 * @see RSDEngineColumn::RSDEngineColumn
4216 */
4217 var $name = "";
4218
4219 /**The isValid defintion of this column. Is set in the construtor method.
4220 *
4221 * @var String
4222 * @see RSDEngineColumn::RSDEngineColumn
4223 */
4224 var $isValid = "";
4225
4226 /**The input type for this column. Is set in the construtor method.
4227 *
4228 * @var String
4229 * @see RSDEngineColumn::RSDEngineColumn
4230 */
4231 var $inputType = "";
4232
4233 /**The the input type data (e.g. the options for a select box) for this column. Is set in the construtor method.
4234 *
4235 * @var String
4236 * @see RSDEngineColumn::RSDEngineColumn
4237 */
4238 var $inputTypeData = "";
4239
4240 /**The name of the table that contains this column. Is set in the construtor method.
4241 *
4242 * @var String
4243 * @see RSDEngineColumn::RSDEngineColumn
4244 */
4245 var $table = "";
4246
4247 /**The name of the sequence from which to fetch the next id. Pass an empty string if no sequence should be used. Is set in the construtor method.
4248 *
4249 * @var String
4250 * @see RSDEngineColumn::RSDEngineColumn
4251 */
4252 var $sequenceName = "";
4253
4254 /**Whether no input filed should be generated for this column in the create template. Is set in the construtor method.
4255 *
4256 * @var boolean
4257 * @see RSDEngineColumn::RSDEngineColumn
4258 */
4259 var $doNotInsert = false;
4260
4261 /**Whether no input filed should be generated for this column in the update template. Is set in the construtor method.
4262 *
4263 * @var boolean
4264 * @see RSDEngineColumn::RSDEngineColumn
4265 */
4266 var $doNotUpdate = false;
4267
4268 /**Whether this columns should not be selected (displayed via a template). Is set in the construtor method.
4269 *
4270 * @var boolean
4271 * @see RSDEngineColumn::RSDEngineColumn
4272 */
4273 var $doNotSelect = false;
4274
4275 /**If this property contains any elements the LiveUser right stored in this column by ID is made editable through a generated template and controller.
4276 * This property gets set to an array of strings (option definitions) inside the constructor method and updated inside parseLiveUserOptions()
4277 * to an array of RSDEngineEditLiveUserRightOption.
4278 * @var Array
4279 * @see RSDEngineColumn::RSDEngineColumn
4280 * @see parseLiveUserOptions
4281 */
4282 var $editLiveUserRightOptions = array();
4283
4284 /**If this property contains any elements the LiveUser group stored in this column by ID is made editable through a generated template and controller.
4285 * This property gets set to an array of strings (option definitions) inside the constructor method and updated inside parseLiveUserOptions()
4286 * to an array of RSDEngineEditLiveUserGroupOption.
4287 * @var Array
4288 * @see RSDEngineColumn::RSDEngineColumn
4289 * @see parseLiveUserOptions
4290 */
4291 var $editLiveUserGroupOptions = array();
4292
4293 /**If this property contains any elements the LiveUser area stored in this column by ID is made editable through a generated template and controller.
4294 * This property gets set to an array of strings (option definitions) inside the constructor method and updated inside parseLiveUserOptions()
4295 * to an array of RSDEngineEditLiveUserAreaOption.
4296 * @var Array
4297 * @see RSDEngineColumn::RSDEngineColumn
4298 * @see parseLiveUserOptions
4299 */
4300 var $editLiveUserAreaOptions = array();
4301
4302 /**If non-empty this value is used in the generated insert method. Is set in the construtor method.
4303 *
4304 * @var String
4305 * @see RSDEngineColumn::RSDEngineColumn
4306 * @see RSDEngineDBTable::_createInsertMethod
4307 */
4308 var $defaultInsertValue = "";
4309
4310 /**If non-empty this value is used in the generated update method. Is set in the construtor method.
4311 *
4312 * @var String
4313 * @see RSDEngineColumn::RSDEngineColumn
4314 * @see RSDEngineDBTable::_createInsertMethod
4315 */
4316 var $defaultUpdateValue = "";
4317
4318 /**Indicates whether the values for this column must be unique. Is set in the construtor method.
4319 *
4320 * @var boolean
4321 * @see RSDEngineColumn::RSDEngineColumn
4322 */
4323 var $unique = false;
4324
4325 /**The prefix of this column name. Often f_. Providing a column prefix makes the generated code more readable because the prefix can be remove where appropriate.
4326 *
4327 * @var String
4328 */
4329 var $columnPrefix = "";
4330
4331 /**Where this column that is defined as a foreign key references to. If this column is not a foreign key this property is ignored.
4332 *
4333 * @var String
4334 */
4335 var $foreignKeyTarget = "";
4336
4337 /**If this column is a primary key.
4338 *
4339 * @var boolean
4340 */
4341 var $isPrimaryKey = false;
4342
4343 /**If this column is a foreign key.
4344 *
4345 * @var boolean
4346 */
4347 var $isForeignKey = false;
4348
4349 /**If this column is an undefined key.
4350 *
4351 * @var boolean
4352 */
4353 var $isUndefinedKey = false;
4354
4355 /**The sql definition of this column. Gets set inside the constructor.
4356 * @var String
4357 */
4358 var $definition = "";
4359
4360 /**The RSDEngineDBTable instance that created this instance.
4361 * @var RSDEngineDBTable
4362 */
4363 var $rsdEngineDBTable = null;
4364
4365 /**An associative array holding the validation options for this column.
4366 * Gets set by setIsValidFileOptions if this column is defined as isValid:file.
4367 * @see setIsValidFileOptions
4368 * @see getIsValidFileOptions
4369 * @var Array
4370 */
4371 var $_isValidFileOptions = null;
4372
4373 /**The constructor that initializes this instance.
4374 *
4375 * @param String $name The name of this column.
4376 * @param String $table The name of the table that contains this column.
4377 * @param String $isValid A string that defines the validation performed for this column. See the tutorial for details!
4378 * @param String $sequenceName The name of the sequence from which to fetch the next id. Pass an empty string if no sequence should be used.
4379 * @param boolean $doNotInsert Whether no input filed should be generated for this column in the create template.
4380 * @param boolean $doNotUpdate Whether no input filed should be generated for this column in the update template.
4381 * @param boolean $doNotSelect Whether this column should not be displayed via a template.
4382 * @param boolean $editLiveUserRight If this property is set to true, the LiveUser right stored in this column by ID is made editable through a generated template and controller.
4383 * @param boolean $editLiveUserGroup If this property is set to true, the LiveUser group stored in this column by ID is made editable through a generated template and controller.
4384 * @param boolean $editLiveUserArea If this property is set to true, the LiveUser area stored in this column by ID is made editable through a generated template and controller.
4385 * @param String $defaultInsertValue If non-empty this value is used in the generated insert method.
4386 * @param String $defaultUpdateValue If non-empty this value is used in the generated update method.
4387 * @param String $key If the string "primary", "foreign" or "undefined" is passed this column is treated as a key. This means that getBy, updateBy and deleteBy method are created for it.
4388 * @param boolean $unique Indicates whether the values for this column must be unique.
4389 * @param String $columnPrefix The prefix of this column name. Often f_. Providing a column prefix makes the generated code more readable because the prefix can be remove where appropriate.
4390 */
4391 function RSDEngineColumn($name, $table, $isValid, $inputType, $inputTypeData, $sequenceName, $doNotInsert, $doNotUpdate, $doNotSelect, $editLiveUserRightOptions, $editLiveUserGroupOptions, $editLiveUserAreaOptions, $defaultInsertValue, $defaultUpdateValue, $key, $unique, $columnPrefix, $definition, &$rsdEngineDBTable)
4392 {
4393 $this->name = $name;
4394 $this->table = $table;
4395 $this->fullName = "$table.$name";
4396 $this->definition = $definition;
4397 $this->isValid = $isValid;
4398 $this->inputType = $inputType;
4399 $this->inputTypeData = $inputTypeData;
4400 $this->sequenceName = $sequenceName;
4401 $this->setKey($key);
4402 $this->doNotInsert = $doNotInsert;
4403 $this->doNotUpdate = $doNotUpdate || $this->isPrimaryKey;
4404 $this->doNotSelect = $doNotSelect;
4405 $this->editLiveUserRightOptions = $editLiveUserRightOptions;
4406 $this->editLiveUserGroupOptions = $editLiveUserGroupOptions;
4407 $this->editLiveUserAreaOptions = $editLiveUserAreaOptions;
4408 $this->columnPrefix = $columnPrefix;
4409 $this->unique = $unique;
4410 $this->rsdEngineDBTable =& $rsdEngineDBTable;
4411 $this->setForeignKeyTarget(false);
4412
4413 if ($defaultInsertValue != '') {
4414 $this->defaultInsertValue = $defaultInsertValue;
4415 } elseif($this->sequenceName != '' && $this->isPrimaryKey && $this->rsdEngineDBTable->rsdEngineDB->config['makeSequenceAssumption']) {
4416 $this->defaultInsertValue = '$this->' . $this->generateGetNextMethodName() . "()";
4417 }
4418
4419 $this->defaultUpdateValue = $defaultUpdateValue;
4420
4421 $info = " - Parsing column $this->fullName: isValid=$this->isValid; sequenceName=$this->sequenceName; doNotInsert=$this->doNotInsert; doNotUpdate=$this->doNotUpdate; doNotSelect=$this->doNotSelect";
4422 $i = 0;
4423 reset($this->editLiveUserRightOptions);
4424 while (list($key, $value) = each($this->editLiveUserRightOptions)) {
4425 $info .= " editLiveUserRightOption$i=$value;";
4426 $i++;
4427 }
4428 $i = 0;
4429 reset($this->editLiveUserGroupOptions);
4430 while (list($key, $value) = each($this->editLiveUserGroupOptions)) {
4431 $info .= " editLiveUserGroupOption$i=$value;";
4432 $i++;
4433 }
4434 $i = 0;
4435 reset($this->editLiveUserAreaOptions);
4436 while (list($key, $value) = each($this->editLiveUserAreaOptions)) {
4437 $info .= " editLiveUserAreaOption$i=$value;";
4438 $i++;
4439 }
4440 $info .=" defaultInsertValue=$this->defaultInsertValue; defaultUpdateValue=$this->defaultUpdateValue; key=$key; unique=$this->unique";
4441 $this->rsdEngineDBTable->rsdEngineDB->config['rsdEngine']->logInfo($info);
4442 }
4443
4444 function getHTMLInputTag()
4445 {
4446 $columnName = $this->getColumnNameForVariableName();
4447 $data = "";
4448 $OPEN = $this->rsdEngineDBTable->rsdEngineDB->config['smartyLeftDelimiter'];
4449 $CLOSE = $this->rsdEngineDBTable->rsdEngineDB->config['smartyRightDelimiter'];
4450 if ($this->inputType == 'select' || ($this->inputType == '' && $this->isForeignKey)) {
4451 $data .=' <select name="' . $columnName . '">' . "\n" .
4452 " <option value=\"userSubmittedNULL\">Select</option>\n" .
4453 " ${OPEN}html_options options=\$${columnName}Options selected=\$$columnName${CLOSE}\n" .
4454 " </select>\n";
4455 } elseif ($this->inputType == 'radio') {
4456 $data .=" ${OPEN}html_radios name=\"${columnName}\" options=\$${columnName}Options checked=\$$columnName${CLOSE}\n";
4457 } elseif ($this->inputType == 'textarea') {
4458 $data .=" <textarea name=\"$columnName\" rows=\"5\" cols=\"40\">${OPEN}\$$columnName${CLOSE}</textarea>\n";
4459 } elseif ($this->inputType == 'checkbox') {
4460 $data .=" <input type=\"checkbox\" name=\"$columnName\" value=\"1\" ${OPEN}if \$$columnName${CLOSE}CHECKED${OPEN}/if${CLOSE}>\n";
4461 } elseif ($this->inputType == 'date') {
4462 $data .=" ${OPEN}html_select_date prefix=\"$columnName\" time=\$$columnName${CLOSE}\n";
4463 } elseif ($this->inputType == 'time') {
4464 $data .=" ${OPEN}html_select_time prefix=\"$columnName\" time=\$$columnName use_24_hours=\"true\"${CLOSE}\n";
4465 } elseif ($this->inputType == 'datetime') {
4466 $data .=" ${OPEN}html_select_date prefix=\"$columnName\" time=\$$columnName${CLOSE}\n";
4467 $data .=" ${OPEN}html_select_time prefix=\"$columnName\" time=\$$columnName use_24_hours=\"true\"${CLOSE}\n";
4468 } elseif ($this->inputType == 'password') {
4469 $data .=" <input type=\"password\" name=\"$columnName\" value=\"${OPEN}\$" . $columnName . "${CLOSE}\">\n";
4470 } elseif (is_array($isValidFileOptions = $this->getIsValidFileOptions())) {
4471 $data .=' <input type="hidden" name="MAX_FILE_SIZE" value="' . $isValidFileOptions['maxSize'] . '">' . "\n" .
4472 ' <input name="' . $columnName . '" type="file">' . "\n";
4473 } else {
4474 $data .=" <input type=\"text\" name=\"$columnName\" value=\"${OPEN}\$" . $columnName . "${CLOSE}\">\n";
4475 }
4476
4477 return $data;
4478 }
4479 /**Sets the properties isPrimaryKey, isForeignKey and isUndefinedKey based on the string passed as argument.
4480 *
4481 * Boolean values are assignd to these three properies:
4482 * {@source }
4483 * @param String $key Valid values are 'primary' for a primary key, 'foreign' for a foreign key, 'undefined' for an undefined key and an empty string for no key.
4484 */
4485 function setKey($key)
4486 {
4487 $this->isPrimaryKey = ($key == "primary");
4488 $this->isForeignKey = ($key == "foreign");
4489 $this->isUndefinedKey = ($key == "undefined");
4490 if ($this->isPrimaryKey) {
4491 $this->unique = true;
4492 $this->doNotUpdate = true;
4493 if ($this->sequenceName == '') { //&& $makeSequenceAssumption
4494 $this->sequenceName = 'seq_' .
4495 strtolower($this->rsdEngineDBTable->rsdEngineDB->config['projectName']) .
4496 '_' .
4497 $this->rsdEngineDBTable->getTableNameWithoutPrefix() .
4498 "_" .
4499 $this->getColumnNameWithoutPrefix();
4500 }
4501 if($this->sequenceName != '') {
4502 $this->defaultInsertValue = '$this->' . $this->generateGetNextMethodName() . "()";
4503 }
4504 }
4505 }
4506
4507 /**Returns true if this column is a primary, foreign or undefined key.
4508 *
4509 * @return boolen If this column is any key.
4510 */
4511 function isAnyKey()
4512 {
4513 return $this->isPrimaryKey == true || $this->isForeignKey == true || $this->isUndefinedKey == true;
4514 }
4515
4516 /**Sets the property foreignKeyTarget makes this column a foreign key.
4517 *
4518 * If the argument passed is not equal to (!==) the boolean value false setKey is called with the parameter 'foreign'.
4519 * @see foreignKeyTarget
4520 * @see setKey
4521 */
4522 function setForeignKeyTarget($foreignKeyTarget)
4523 {
4524 $this->foreignKeyTarget = $foreignKeyTarget;
4525 if ($foreignKeyTarget !== false) {
4526 $this->setKey("foreign");
4527 }
4528 }
4529
4530 /**Returns the value of the property foreignKeyTarget.
4531 *
4532 * @see foreignKeyTarget
4533 * @return String The value of the property foreignKeyTarget.
4534 */
4535 function getForeignKeyTarget()
4536 {
4537 return $this->foreignKeyTarget;
4538 }
4539
4540
4541 function generateStoreUploadedMethod()
4542 {
4543 if (!is_array($isValidFileOptions = $this->getIsValidFileOptions())) {
4544 return false;
4545 }
4546 $methodComments = "/" . "**Stores a file uploaded for this column in the defined storage directory.\n" .
4547 "*\n" .
4548 '* If you have an HTML form input (type="file") named userfile just pass $_FILES["userfile"] as first argument.' . "\n" .
4549 "* @param mixed \$fileArray An associative array with the elemts 'tmp_name', 'type' and optionally 'error'.\n" .
4550 "* @param String \$newFilename The new filename. This does not include the path!\n" .
4551 "* @return mixed True on success an instance of RSError otherwise.\n" .
4552 "*/";
4553
4554 $paramString = '$fileArray, $newFilename';
4555 $body = "";
4556 $body .=' if ($fileArray["error"] == UPLOAD_ERR_INI_SIZE || $fileArray["error"] == UPLOAD_ERR_FORM_SIZE) {' . "\n" .
4557 ' return RSErrorManager::raiseRSError("' . $this->table . '", "' . $this->name . '", "storeUploaded", "File too large!", RSERROR_INVALID);' . "\n" .
4558 ' }' . "\n" .
4559 ' if ($fileArray["error"] == UPLOAD_ERR_PARTIAL) {' . "\n" .
4560 ' return RSErrorManager::raiseRSError("' . $this->table . '", "' . $this->name . '", "storeUploaded", "The uploaded file was only partially uploaded.", RSERROR_INVALID);' . "\n" .
4561 ' }' . "\n" .
4562 ' if ($fileArray["error"] == UPLOAD_ERR_NO_FILE) {' . "\n" .
4563 ' return RSErrorManager::raiseRSError("' . $this->table . '", "' . $this->name . '", "storeUploaded", "No file was uploaded.", RSERROR_INVALID);' . "\n" .
4564 ' }' . "\n";
4565 if ($isValidFileOptions['contentType'] != "") {
4566 $body .=' if (strpos($fileArray["type"], "' . $isValidFileOptions['contentType'] . '") === false) {' . "\n" .
4567 ' return RSErrorManager::raiseRSError("' . $this->table . '", "' . $this->name . '", "storeUploaded", "Wrong content type.", RSERROR_INVALID);' . "\n" .
4568 ' }' . "\n";
4569 }
4570 $body .="\n" .
4571 ' $success = move_uploaded_file($fileArray["tmp_name"], ' . $isValidFileOptions['storageDirConstant'] . ' . "/" . $newFilename);' . "\n" .
4572 ' if (!$success) {' . "\n" .
4573 ' return RSErrorManager::raiseRSError("' . $this->table . '", "' . $this->name . '", "storeUploaded", "Could not store uploaded file!", RSERROR_INVALID);' . "\n" .
4574 ' }' . "\n" .
4575 ' return true;';
4576
4577 return new RSDEngineMethod($this->generateStoreUploadedMethodName(),$paramString,$methodComments,$body);
4578 }
4579
4580
4581 function generateRemoveStoredMethod()
4582 {
4583 if (!is_array($isValidFileOptions = $this->getIsValidFileOptions())) {
4584 return false;
4585 }
4586 $methodComments = "/" . "**Removes a file stored for this column.\n" .
4587 "*\n" .
4588 "* @param String \$filename The name of the file to delete. This does not include the path!\n" .
4589 "*/";
4590
4591 $paramString = '$filename';
4592 $body = " @unlink(" . $isValidFileOptions['storageDirConstant'] . " . '/' . \$filename);";
4593 return new RSDEngineMethod($this->generateRemoveStoredMethodName(), $paramString, $methodComments, $body);
4594 }
4595
4596 function generateGetStoredMethod()
4597 {
4598 if (!is_array($isValidFileOptions = $this->getIsValidFileOptions())) {
4599 return false;
4600 }
4601 $methodComments = "/" . "**Returns a stored file.\n" .
4602 "*\n" .
4603 "* @param String \$filename The name of the file to retieve. This does not include the path!\n" .
4604 "*/";
4605
4606 $paramString = '$filename';
4607 $body = " require_once('RSIO/RSIO.php');\n" .
4608 " return RSIO::getFileContents(" . $isValidFileOptions['storageDirConstant'] . " . '/' . \$filename);";
4609 return new RSDEngineMethod($this->generateGetStoredMethodName(), $paramString, $methodComments, $body);
4610 }
4611
4612 /**This method will parse all editLiveUserRight, editLiveUserGroup and editLiveUserGroupOptions.
4613 */
4614 function parseLiveUserOptions()
4615 {
4616 $editLiveUserRightOptions = array();
4617 reset($this->editLiveUserRightOptions);
4618 while (list($key, $editLiveUserRightOption) = each($this->editLiveUserRightOptions)) {
4619 $options =& RSDEngineEditLiveUserRightOption::factory($this->rsdEngineDBTable, $this, $editLiveUserRightOption);
4620 reset($options);
4621 while (list($key, $value) = each($options)) {
4622 $editLiveUserRightOptions[] =& $options[$key];
4623 }
4624 }
4625 $this->editLiveUserRightOptions =& $editLiveUserRightOptions;
4626
4627
4628 $editLiveUserAreaOptions = array();
4629 reset($this->editLiveUserAreaOptions);
4630 while (list($key, $editLiveUserAreaOption) = each($this->editLiveUserAreaOptions)) {
4631 $options =& RSDEngineEditLiveUserAreaOption::factory($this->rsdEngineDBTable, $this, $editLiveUserAreaOption);
4632 reset($options);
4633 while (list($key, $value) = each($options)) {
4634 $editLiveUserAreaOptions[] =& $options[$key];
4635 }
4636 }
4637 $this->editLiveUserAreaOptions =& $editLiveUserAreaOptions;
4638
4639
4640 $editLiveUserGroupOptions = array();
4641 reset($this->editLiveUserGroupOptions);
4642 while (list($key, $editLiveUserGroupOption) = each($this->editLiveUserGroupOptions)) {
4643 $options =& RSDEngineEditLiveUserGroupOption::factory($this->rsdEngineDBTable, $this, $editLiveUserGroupOption);
4644 reset($options);
4645 while (list($key, $value) = each($options)) {
4646 $editLiveUserGroupOptions[] =& $options[$key];
4647 }
4648 }
4649 $this->editLiveUserGroupOptions =& $editLiveUserGroupOptions;
4650 }
4651
4652 function generateCanGrantRightToUserMethodName()
4653 {
4654 return 'canGrant' . $this->getColumnNameForPartialMethodName() . 'ToUser';
4655 }
4656
4657 function generateCanRevokeRightFromUserMethodName()
4658 {
4659 return 'canRevoke' . $this->getColumnNameForPartialMethodName() . 'FromUser';
4660 }
4661
4662 function generateCanGrantRightToGroupMethodName()
4663 {
4664 return 'canGrant' . $this->getColumnNameForPartialMethodName() . 'ToGroup';
4665 }
4666
4667 function generateCanRevokeRightFromGroupMethodName()
4668 {
4669 return 'canRevoke' . $this->getColumnNameForPartialMethodName() . 'FromGroup';
4670 }
4671
4672
4673 function generateGrantRightToUserMethodName()
4674 {
4675 return 'grant' . $this->getColumnNameForPartialMethodName() . 'ToUser';
4676 }
4677
4678 function generateRevokeRightFromUserMethodName()
4679 {
4680 return 'revoke' . $this->getColumnNameForPartialMethodName() . 'FromUser';
4681 }
4682
4683 function generateGrantRightToGroupMethodName()
4684 {
4685 return 'grant' . $this->getColumnNameForPartialMethodName() . 'ToGroup';
4686 }
4687
4688 function generateRevokeRightFromGroupMethodName()
4689 {
4690 return 'revoke' . $this->getColumnNameForPartialMethodName() . 'FromGroup';
4691 }
4692
4693 /**Generates the methods for granting a right to/revoking it from a user/group.
4694 * These four methods should only be created if this column was defined with any editLiveUserRight option.
4695 * @return Array An array of RSDEngineMethod objects.
4696 */
4697 function generateUpdateLiveUserRightMethods()
4698 {
4699 $operations = array('grantUserRight', 'revokeUserRight', 'grantGroupRight', 'revokeGroupRight');
4700 while (list($key, $operation) = each($operations)) {
4701 if ($operation == 'grantUserRight') {
4702 $methodName = $this->generateGrantRightToUserMethodName();
4703 $canMethodName = $this->generateCanGrantRightToUserMethodName();
4704 $actionMethodName = 'grantLiveUserUserRight';
4705 $subjectArgument = 'userId';
4706 $methodComments = <<<END
4707 /**Grant the right stored in the column '$this->name' to a user.
4708 *
4709 * @param Array \$record An associative array that contains the column '$this->name'.
4710 * @param int \$userId The user that will be granted the right stored in '$this->name'.
4711 * @param boolean \$checkRight Whether to perform a right checking.
4712 * @return mixed True or an instance of PEAR_Error.
4713 */
4714 END;;; } elseif ($operation == 'revokeUserRight') {
4715 $methodName = $this->generateRevokeRightFromUserMethodName();
4716 $canMethodName = $this->generateCanRevokeRightFromUserMethodName();
4717 $actionMethodName = 'revokeLiveUserUserRight';
4718 $subjectArgument = 'userId';
4719 $methodComments = <<<END
4720 /**Revoke the right stored in the column '$this->name' from a user.
4721 *
4722 * @param Array \$record An associative array that contains the column '$this->name'.
4723 * @param int \$userId The user from which the right stored in '$this->name' will be revoked.
4724 * @param boolean \$checkRight Whether to perform a right checking.
4725 * @return mixed True or an instance of PEAR_Error.
4726 */
4727 END;;; } elseif ($operation == 'grantGroupRight') {
4728 $methodName = $this->generateGrantRightToGroupMethodName();
4729 $canMethodName = $this->generateCanGrantRightToGroupMethodName();
4730 $actionMethodName = 'grantLiveUserGroupRight';
4731 $subjectArgument = 'groupId';
4732 $methodComments = <<<END
4733 /**Grant the right stored in the column '$this->name' to a group.
4734 *
4735 * @param Array \$record An associative array that contains the column '$this->name'.
4736 * @param int \$groupId The group that will be granted the right stored in '$this->name'.
4737 * @param boolean \$checkRight Whether to perform a right checking.
4738 * @return mixed True or an instance of PEAR_Error.
4739 */
4740 END;;; } elseif ($operation == 'revokeGroupRight') {
4741 $methodName = $this->generateRevokeRightFromGroupMethodName();
4742 $canMethodName = $this->generateCanRevokeRightFromGroupMethodName();
4743 $actionMethodName = 'revokeLiveUserGroupRight';
4744 $subjectArgument = 'groupId';
4745 $methodComments = <<<END
4746 /**Revoke the right stored in the column '$this->name' from a group.
4747 *
4748 * @param Array \$record An associative array that contains the column '$this->name'.
4749 * @param int \$groupId The group from which the right stored in '$this->name' will be revoked.
4750 * @param boolean \$checkRight Whether to perform a right checking.
4751 * @return mixed True or an instance of PEAR_Error.
4752 */
4753 END;;; }
4754 $paramString = "&\$record, \$$subjectArgument, \$checkRight = true";
4755
4756 $body = <<<END
4757 if (!isset(\$record['$this->name'])) {
4758 return RSErrorManager::raiseRSError(\$this->name, '$this->name', '$methodName', "The record passed as argument did not contain the column $this->name that stores the right ID to deal with.", RSERROR_INVALID);
4759 }
4760 \$rightId = \$record['$this->name'];
4761 if (\$checkRight && !\$this->$canMethodName(\$record, \$$subjectArgument)) {
4762 return RSErrorManager::raiseRSError(\$this->name, '$this->name', '$methodName', "You do not have the required permission to perform this operation on right ID \$rightId and user ID \$$subjectArgument.", RSERROR_PERMISSION_DENIED);
4763 }
4764 return \$this->app->$actionMethodName(\$$subjectArgument, \$rightId);
4765 END;;;
4766
4767
4768 $methods[$operation] = new RSDEngineMethod($methodName, $paramString, $methodComments, $body);
4769 }
4770
4771 return $methods;
4772 }
4773
4774
4775
4776
4777 function generateCanUpdateLiveUserRightMethods()
4778 {
4779 $methodComments = <<<END
4780 /**Whether the user can permform the this modification of a LiveUser right.
4781 * If no argument is passed this method will return whether the user can update any property.
4782 * @param Array \$record An associative array.
4783 * @return boolean Whether the operation is permitted.
4784 */
4785 END;;;
4786 $body = ' return false;';
4787 $methods = array(
4788 'grantUserRight' => new RSDEngineMethod($this->generateCanGrantRightToUserMethodName(), '&$record, $userId = false', $methodComments, $body),
4789 'revokeUserRight' => new RSDEngineMethod($this->generateCanRevokeRightFromUserMethodName(), '&$record, $userId = false', $methodComments, $body),
4790 'grantGroupRight' => new RSDEngineMethod($this->generateCanGrantRightToGroupMethodName(), '&$record, $groupId = false', $methodComments, $body),
4791 'revokeGroupRight' => new RSDEngineMethod($this->generateCanRevokeRightFromGroupMethodName(), '&$record, $groupId = false', $methodComments, $body)
4792 );
4793
4794 $columnNameForPartialMethodName = $this->getColumnNameForPartialMethodName();
4795
4796 reset($this->editLiveUserRightOptions);
4797 while (list($key, $editLiveUserRightOption) = each($this->editLiveUserRightOptions)) {
4798 $canUpdatePseudoColumn = '';
4799 if ($editLiveUserRightOption->operation == 'grantUserRight') {
4800 $canUpdatePseudoColumn = '__canGrant' . $this->getColumnNameForPartialMethodName() . 'ToUser';
4801 $methodName = $this->generateCanGrantRightToUserMethodName();
4802 $paramString = '&$record, $userId = false';
4803 } elseif ($editLiveUserRightOption->operation == 'revokeUserRight') {
4804 $canUpdatePseudoColumn = '__canRevoke' . $this->getColumnNameForPartialMethodName() . 'FromUser';
4805 $methodName = $this->generateCanRevokeRightFromUserMethodName();
4806 $paramString = '&$record, $userId = false';
4807 } elseif ($editLiveUserRightOption->operation == 'grantGroupRight') {
4808 $canUpdatePseudoColumn = '__canGrant' . $this->getColumnNameForPartialMethodName() . 'ToGroup';
4809 $methodName = $this->generateCanGrantRightToGroupMethodName();
4810 $paramString = '&$record, $groupId = false';
4811 } elseif ($editLiveUserRightOption->operation == 'revokeGroupRight') {
4812 $canUpdatePseudoColumn = '__canRevoke' . $this->getColumnNameForPartialMethodName() . 'FromGroup';
4813 $methodName = $this->generateCanRevokeRightFromGroupMethodName();
4814 $paramString = '&$record, $groupId = false';
4815 }
4816
4817 $body = <<<END
4818 if (isset(\$record['$canUpdatePseudoColumn'])) {
4819 return \$record['$canUpdatePseudoColumn'];
4820 }
4821
4822 END;;;
4823 if ($editLiveUserRightOption->condition != '') {
4824 $body .= <<<END
4825 \$record['$canUpdatePseudoColumn'] = $editLiveUserRightOption->condition;
4826 if (\$record['$canUpdatePseudoColumn']) {
4827 \$record['__canUpdate$columnNameForPartialMethodName'] = true;
4828 }
4829 return \$record['$canUpdatePseudoColumn'];
4830 END;;;
4831 } elseif ($editLiveUserRightOption->type == 'column') {
4832 $body .= <<<END
4833 \$record['$canUpdatePseudoColumn'] = isset(\$record['$editLiveUserRightOption->columnName']) && \$this->app->liveUser->checkRight(\$record['$editLiveUserRightOption->columnName']);
4834 if (\$record['$canUpdatePseudoColumn']) {
4835 \$record['__canUpdate$columnNameForPartialMethodName'] = true;
4836 }
4837 return \$record['$canUpdatePseudoColumn'];
4838
4839 END;;; } elseif ($editLiveUserRightOption->type == 'table.column') {
4840 $body .= <<<END
4841 \$records = \$this->$editLiveUserRightOption->selectIncludingMethodName(\$whereConditions, '', '$editLiveUserRightOption->columnName', null, null, RSD_NO_LIVEUSER_RIGHT_CHECK);
4842
4843 if (!is_array(\$records)) {
4844 return RSErrorManager::raiseRSError(\$this->name,'','$methodName','Could not check permissions.', RSERROR_UNKNOWN);
4845 }
4846
4847 \$can = true;
4848 while (list(\$key, \$record) = each(\$records)) {
4849 if (!\$this->app->liveUser->checkRight(\$record['$editLiveUserRightOption->columnName'])) {
4850 \$can = false;
4851 }
4852 }
4853
4854 \$record['$canUpdatePseudoColumn'] = \$can && count($records) > 0;
4855 if (\$record['$canUpdatePseudoColumn']) {
4856 \$record['__canUpdate$columnNameForPartialMethodName'] = true;
4857 }
4858 return \$record['$canUpdatePseudoColumn'];
4859
4860 END;;; } elseif ($editLiveUserRightOption->type == 'SQL_QUERY') {
4861 $body .= <<<END
4862 \$record['$canUpdatePseudoColumn'] = !PEAR::isError(\$rightId = \$this->db->getOne("$editLiveUserRightOption->query")) && \$this->app->liveUser->checkRight(\$rightId);
4863 if (\$record['$canUpdatePseudoColumn']) {
4864 \$record['__canUpdate$columnNameForPartialMethodName'] = true;
4865 }
4866 return \$record['$canUpdatePseudoColumn'];
4867
4868 END;;; } elseif ($editLiveUserRightOption->type == 'PHP_CODE') {
4869 $body .= <<<END
4870 \$record['$canUpdatePseudoColumn'] = !PEAR::isError(\$rightId = $editLiveUserRightOption->phpCode) && \$this->app->liveUser->checkRight(\$rightId);
4871 if (\$record['$canUpdatePseudoColumn']) {
4872 \$record['__canUpdate$columnNameForPartialMethodName'] = true;
4873 }
4874 return \$record['$canUpdatePseudoColumn'];
4875
4876 END;;; }
4877 $methods[$editLiveUserRightOption->operation] = new RSDEngineMethod($methodName, $paramString, $methodComments, $body);
4878 }
4879 return $methods;
4880 }
4881
4882
4883
4884 function generateCanAddAdminToAreaMethodName()
4885 {
4886 return 'canAddAdminTo' . $this->getColumnNameForPartialMethodName();
4887 }
4888 function generateCanRemoveAdminFromAreaMethodName()
4889 {
4890 return 'canRemoveAdminFrom' . $this->getColumnNameForPartialMethodName();
4891 }
4892 function generateCanUpdateAreaNameAndCommentMethodName()
4893 {
4894 return 'canUpdate' . $this->getColumnNameForPartialMethodName() . 'NameAndComment';
4895 }
4896
4897 function generateAddAdminToAreaMethodName()
4898 {
4899 return 'addAdminTo' . $this->getColumnNameForPartialMethodName();
4900 }
4901 function generateRemoveAdminFromAreaMethodName()
4902 {
4903 return 'removeAdminFrom' . $this->getColumnNameForPartialMethodName();
4904 }
4905 function generateUpdateAreaNameAndCommentMethodName()
4906 {
4907 return 'update' . $this->getColumnNameForPartialMethodName() . 'NameAndComment';
4908 }
4909
4910 function generateAddAdminToAreaMethod()
4911 {
4912 $methodName = $this->generateAddAdminToAreaMethodName();
4913 $canMethodName = $this->generateCanAddAdminToAreaMethodName();
4914 $paramString = '&$record, $userId, $checkRight = true';
4915 $methodComments = <<<END
4916 /**Add a user as area admin to the area stored in the column '$this->name'.
4917 *
4918 * @param Array \$record An associative array that contains the column '$this->name'.
4919 * @param int \$userId The ID of the user that will be set as area admin.
4920 * @param boolean \$checkRight Whether to perform a right checking.
4921 * @return mixed True or an instance of PEAR_Error.
4922 */
4923 END;;; $body = <<<END
4924 if (!isset(\$record['$this->name'])) {
4925 return RSErrorManager::raiseRSError(\$this->name, '$this->name', '$methodName', "The record passed as argument did not contain the column $this->name that stores the area ID to deal with.", RSERROR_INVALID);
4926 }
4927 \$areaId = \$record['$this->name'];
4928 if (\$checkRight && !\$this->$canMethodName(\$record, \$userId)) {
4929 return RSErrorManager::raiseRSError(\$this->name, '$this->name', '$methodName', "You do not have the required permission to perform this operation on area ID \$areaId and user ID \$userId.", RSERROR_PERMISSION_DENIED);
4930 }
4931 return \$this->app->addLiveUserAreaAdmin(\$userId, \$areaId);
4932
4933 END;;; return new RSDEngineMethod($methodName, $paramString, $methodComments, $body);
4934 }
4935
4936 function generateRemoveAdminFromAreaMethod()
4937 {
4938 $methodName = $this->generateRemoveAdminFromAreaMethodName();
4939 $canMethodName = $this->generateCanRemoveAdminFromAreaMethodName();
4940 $paramString = '&$record, $userId, $checkRight = true';
4941 $methodComments = <<<END
4942 /**Remove a user from the list of area admins of the area stored in the column '$this->name'.
4943 *
4944 * @param Array \$record An associative array that contains the column '$this->name'.
4945 * @param int \$userId The ID of the user that will removed of the list of area admins.
4946 * @param boolean \$checkRight Whether to perform a right checking.
4947 * @return mixed True or an instance of PEAR_Error.
4948 */
4949 END;;; $body = <<<END
4950 if (!isset(\$record['$this->name'])) {
4951 return RSErrorManager::raiseRSError(\$this->name, '$this->name', '$methodName', "The record passed as argument did not contain the column $this->name that stores the area ID to deal with.", RSERROR_INVALID);
4952 }
4953 \$areaId = \$record['$this->name'];
4954 if (\$checkRight && !\$this->$canMethodName(\$record, \$userId)) {
4955 return RSErrorManager::raiseRSError(\$this->name, '$this->name', '$methodName', "You do not have the required permission to perform this operation on area ID \$areaId and user ID \$userId.", RSERROR_PERMISSION_DENIED);
4956 }
4957 return \$this->app->removeLiveUserAreaAdmin(\$userId, \$areaId);
4958
4959 END;;; return new RSDEngineMethod($methodName, $paramString, $methodComments, $body);
4960 }
4961
4962 function generateUpdateAreaNameAndCommentMethod()
4963 {
4964 $methodName = $this->generateUpdateAreaNameAndCommentMethodName();
4965 $canMethodName = $this->generateCanUpdateAreaNameAndCommentMethodName();
4966 $paramString = '&$record, $areaName, $areaComment, $checkRight = true';
4967 $methodComments = <<<END
4968 /**Update the name and comment of the area stored in the column '$this->name'.
4969 *
4970 * @param Array \$record An associative array that contains the column '$this->name'.
4971 * @param String \$areaName The name of the area.
4972 * @param String \$areaComment A comment for the area.
4973 * @param boolean \$checkRight Whether to perform a right checking.
4974 * @return mixed True or an instance of PEAR_Error.
4975 */
4976 END;;; $body = <<<END
4977 if (!isset(\$record['$this->name'])) {
4978 return RSErrorManager::raiseRSError(\$this->name, '$this->name', '$methodName', "The record passed as argument did not contain the column $this->name that stores the area ID to deal with.", RSERROR_INVALID);
4979 }
4980 \$areaId = \$record['$this->name'];
4981 if (\$checkRight && !\$this->$canMethodName(\$record, \$areaName, \$areaComment)) {
4982 return RSErrorManager::raiseRSError(\$this->name, '$this->name', '$methodName', "You do not have the required permission to update the name and comment of area ID \$areaId.", RSERROR_PERMISSION_DENIED);
4983 }
4984 \$areaDefineName = \$areaName;
4985 return \$this->app->callLiveUserPermAdminMethod('updateArea', array(\$areaId, \$areaDefineName, \$areaName, \$areaComment));
4986
4987 END;;; return new RSDEngineMethod($methodName, $paramString, $methodComments, $body);
4988 }
4989
4990 function generateCanUpdateLiveUserAreaMethods()
4991 {
4992 $body = ' return false;';
4993 $canAddAdminMethodComments = <<<END
4994 /**Whether the user can add an admin to the area saved in '$this->name' by ID.
4995 * @param Array \$record An associative array that contains the column '$this->name'.
4996 * @param int \$userId Ths ID of the user to add to the list of area admins.
4997 * @return boolean Whether the operation is permitted.
4998 */
4999 END;;;
5000 $canRemoveAdminMethodComments = <<<END
5001 /**Whether the user can remove an admin from the area saved in '$this->name' by ID.
5002 * @param Array \$record An associative array that contains the column '$this->name'.
5003 * @param int \$userId Ths ID of the user to remove from the list of area admins.
5004 * @return boolean Whether the operation is permitted.
5005 */
5006 END;;;
5007 $canUpdateAreaNameAndComment = <<<END
5008 /**Whether the user can update the name and comment of the area saved in '$this->name' by ID.
5009 * @param Array \$record An associative array that contains the column '$this->name'.
5010 * @param String \$areaName The area name.
5011 * @param String \$areaComment The area comment.
5012 * @return boolean Whether the operation is permitted.
5013 */
5014 END;;; $methods = array(
5015 'addAdmin' => new RSDEngineMethod($this->generateCanAddAdminToAreaMethodName(), '&$record, $userId = false', $canAddAdminMethodComments, $body),
5016 'removeAdmin' => new RSDEngineMethod($this->generateCanRemoveAdminFromAreaMethodName(), '&$record, $userId = false', $canRemoveAdminMethodComments, $body),
5017 'updateNameAndComment' => new RSDEngineMethod($this->generateCanUpdateAreaNameAndCommentMethodName(), '&$record, $areaName = false, $areaComment = false', $canUpdateAreaNameAndComment, $body)
5018 );
5019
5020 $columnNameForPartialMethodName = $this->getColumnNameForPartialMethodName();
5021
5022 reset($this->editLiveUserAreaOptions);
5023 while (list($key, $editLiveUserAreaOption) = each($this->editLiveUserAreaOptions)) {
5024 $canUpdatePseudoColumn = '';
5025 if ($editLiveUserAreaOption->operation == 'addAdmin') {
5026 $canUpdatePseudoColumn = '__canAddAdminTo' . $this->getColumnNameForPartialMethodName();
5027 $methodName = $this->generateCanAddAdminToAreaMethodName();
5028 $paramString = '&$record, $userId = false';
5029 $methodComments = $canAddAdminMethodComments;
5030
5031 } elseif ($editLiveUserAreaOption->operation == 'removeAdmin') {
5032 $canUpdatePseudoColumn = '__canRemoveAdminFrom' . $this->getColumnNameForPartialMethodName();
5033 $methodName = $this->generateCanRemoveAdminFromAreaMethodName();
5034 $paramString = '&$record, $userId = false';
5035 $methodComments = $canRemoveAdminMethodComments;
5036 } elseif ($editLiveUserAreaOption->operation == 'updateNameAndComment') {
5037 $canUpdatePseudoColumn = '__canUpdate' . $this->getColumnNameForPartialMethodName() . 'NameAndComment';
5038 $methodName = $this->generateCanUpdateAreaNameAndCommentMethodName();
5039 $paramString = '&$record, $areaName = false, $areaComment = false';
5040 $methodComments = $canUpdateAreaNameAndComment;
5041 }
5042
5043 $body = <<<END
5044 if (isset(\$record['$canUpdatePseudoColumn'])) {
5045 return \$record['$canUpdatePseudoColumn'];
5046 }
5047
5048 END;;;
5049 if ($editLiveUserAreaOption->condition != '') {
5050 $body .= <<<END
5051 \$record['$canUpdatePseudoColumn'] = $editLiveUserAreaOption->condition;
5052 if (\$record['$canUpdatePseudoColumn']) {
5053 \$record['__canUpdate$columnNameForPartialMethodName'] = true;
5054 }
5055 return \$record['$canUpdatePseudoColumn'];
5056 END;;;
5057 } elseif ($editLiveUserAreaOption->type == 'column') {
5058 $body .= <<<END
5059 \$record['$canUpdatePseudoColumn'] = isset(\$record['$editLiveUserAreaOption->columnName']) && \$this->app->liveUser->checkRight(\$record['$editLiveUserAreaOption->columnName']);
5060 if (\$record['$canUpdatePseudoColumn']) {
5061 \$record['__canUpdate$columnNameForPartialMethodName'] = true;
5062 }
5063 return \$record['$canUpdatePseudoColumn'];
5064
5065 END;;; } elseif ($editLiveUserAreaOption->type == 'table.column') {
5066 $body .= <<<END
5067 \$records = \$this->$editLiveUserAreaOption->selectIncludingMethodName(\$whereConditions, '', '$editLiveUserAreaOption->columnName', null, null, RSD_NO_LIVEUSER_RIGHT_CHECK);
5068
5069 if (!is_array(\$records)) {
5070 return RSErrorManager::raiseRSError(\$this->name,'','$methodName','Could not check permissions.', RSERROR_UNKNOWN);
5071 }
5072
5073 \$can = true;
5074 while (list(\$key, \$record) = each(\$records)) {
5075 if (!\$this->app->liveUser->checkRight(\$record['$editLiveUserAreaOption->columnName'])) {
5076 \$can = false;
5077 }
5078 }
5079
5080 \$record['$canUpdatePseudoColumn'] = \$can && count($records) > 0;
5081 if (\$record['$canUpdatePseudoColumn']) {
5082 \$record['__canUpdate$columnNameForPartialMethodName'] = true;
5083 }
5084 return \$record['$canUpdatePseudoColumn'];
5085
5086 END;;; } elseif ($editLiveUserAreaOption->type == 'SQL_QUERY') {
5087 $body .= <<<END
5088 \$record['$canUpdatePseudoColumn'] = !PEAR::isError(\$rightId = \$this->db->getOne("$editLiveUserAreaOption->query")) && \$this->app->liveUser->checkRight(\$rightId);
5089 if (\$record['$canUpdatePseudoColumn']) {
5090 \$record['__canUpdate$columnNameForPartialMethodName'] = true;
5091 }
5092 return \$record['$canUpdatePseudoColumn'];
5093
5094 END;;; } elseif ($editLiveUserAreaOption->type == 'PHP_CODE') {
5095 $body .= <<<END
5096 \$record['$canUpdatePseudoColumn'] = !PEAR::isError(\$rightId = $editLiveUserAreaOption->phpCode) && \$this->app->liveUser->checkRight(\$rightId);
5097 if (\$record['$canUpdatePseudoColumn']) {
5098 \$record['__canUpdate$columnNameForPartialMethodName'] = true;
5099 }
5100 return \$record['$canUpdatePseudoColumn'];
5101
5102 END;;; }
5103 $methods[$editLiveUserAreaOption->operation] = new RSDEngineMethod($methodName, $paramString, $methodComments, $body);
5104 }
5105 return $methods;
5106 }
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119 function generateCanAddUserToGroupMethodName()
5120 {
5121 return 'canAddUserTo' . $this->getColumnNameForPartialMethodName();
5122 }
5123 function generateCanRemoveUserFromGroupMethodName()
5124 {
5125 return 'canRemoveUserFrom' . $this->getColumnNameForPartialMethodName();
5126 }
5127 function generateCanUpdateGroupNameAndCommentMethodName()
5128 {
5129 return 'canUpdate' . $this->getColumnNameForPartialMethodName() . 'NameAndComment';
5130 }
5131 function generateCanActivateGroupMethodName()
5132 {
5133 return 'canActivate' . $this->getColumnNameForPartialMethodName();
5134 }
5135 function generateCanDeactivateGroupMethodName()
5136 {
5137 return 'canDeactivate' . $this->getColumnNameForPartialMethodName();
5138 }
5139
5140
5141 function generateAddUserToGroupMethodName()
5142 {
5143 return 'addUserTo' . $this->getColumnNameForPartialMethodName();
5144 }
5145 function generateRemoveUserFromGroupMethodName()
5146 {
5147 return 'removeUserFrom' . $this->getColumnNameForPartialMethodName();
5148 }
5149 function generateUpdateGroupNameAndCommentMethodName()
5150 {
5151 return 'update' . $this->getColumnNameForPartialMethodName() . 'NameAndComment';
5152 }
5153 function generateActivateGroupMethodName()
5154 {
5155 return 'activate' . $this->getColumnNameForPartialMethodName();
5156 }
5157 function generateDeactivateGroupMethodName()
5158 {
5159 return 'deactivate' . $this->getColumnNameForPartialMethodName();
5160 }
5161
5162
5163
5164 function generateAddUserToGroupMethod()
5165 {
5166 $methodName = $this->generateAddUserToGroupMethodName();
5167 $canMethodName = $this->generateCanAddUserToGroupMethodName();
5168 $paramString = '&$record, $userId, $checkRight = true';
5169 $methodComments = <<<END
5170 /**Add a user to the group stored in the column '$this->name'.
5171 *
5172 * @param Array \$record An associative array that contains the column '$this->name'.
5173 * @param int \$userId The ID of the user that will be added to the group.
5174 * @param boolean \$checkRight Whether to perform a right checking.
5175 * @return mixed True or an instance of PEAR_Error.
5176 */
5177 END;;; $body = <<<END
5178 if (!isset(\$record['$this->name'])) {
5179 return RSErrorManager::raiseRSError(\$this->name, '$this->name', '$methodName', "The record passed as argument did not contain the column $this->name that stores the group ID to deal with.", RSERROR_INVALID);
5180 }
5181 \$groupId = \$record['$this->name'];
5182 if (\$checkRight && !\$this->$canMethodName(\$record, \$userId)) {
5183 return RSErrorManager::raiseRSError(\$this->name, '$this->name', '$methodName', "You do not have the required permission to perform this operation on group ID \$groupId and user ID \$userId.", RSERROR_PERMISSION_DENIED);
5184 }
5185 return \$this->app->addLiveUserUserToGroup(\$userId, \$groupId);
5186
5187 END;;; return new RSDEngineMethod($methodName, $paramString, $methodComments, $body);
5188 }
5189
5190 function generateRemoveUserFromGroupMethod()
5191 {
5192 $methodName = $this->generateRemoveUserFromGroupMethodName();
5193 $canMethodName = $this->generateCanRemoveUserFromGroupMethodName();
5194 $paramString = '&$record, $userId, $checkRight = true';
5195 $methodComments = <<<END
5196 /**Remove a user from the group stored in the column '$this->name'.
5197 *
5198 * @param Array \$record An associative array that contains the column '$this->name'.
5199 * @param int \$userId The ID of the user that will be removed from the group.
5200 * @param boolean \$checkRight Whether to perform a right checking.
5201 * @return mixed True or an instance of PEAR_Error.
5202 */
5203 END;;; $body = <<<END
5204 if (!isset(\$record['$this->name'])) {
5205 return RSErrorManager::raiseRSError(\$this->name, '$this->name', '$methodName', "The record passed as argument did not contain the column $this->name that stores the group ID to deal with.", RSERROR_INVALID);
5206 }
5207 \$groupId = \$record['$this->name'];
5208 if (\$checkRight && !\$this->$canMethodName(\$record, \$userId)) {
5209 return RSErrorManager::raiseRSError(\$this->name, '$this->name', '$methodName', "You do not have the required permission to perform this operation on group ID \$groupId and user ID \$userId.", RSERROR_PERMISSION_DENIED);
5210 }
5211 return \$this->app->removeLiveUserUserFromGroup(\$userId, \$groupId);
5212
5213 END;;; return new RSDEngineMethod($methodName, $paramString, $methodComments, $body);
5214 }
5215
5216 function generateUpdateGroupNameAndCommentMethod()
5217 {
5218 $methodName = $this->generateUpdateGroupNameAndCommentMethodName();
5219 $canMethodName = $this->generateCanUpdateGroupNameAndCommentMethodName();
5220 $paramString = '&$record, $groupName, $groupComment, $checkRight = true';
5221 $methodComments = <<<END
5222 /**Update the name and comment of the group stored in the column '$this->name'.
5223 *
5224 * @param Array \$record An associative array that contains the column '$this->name'.
5225 * @param String \$groupName The name of the group.
5226 * @param String \$groupComment A comment for the group.
5227 * @param boolean \$checkRight Whether to perform a right checking.
5228 * @return mixed True or an instance of PEAR_Error.
5229 */
5230 END;;; $body = <<<END
5231 if (!isset(\$record['$this->name'])) {
5232 return RSErrorManager::raiseRSError(\$this->name, '$this->name', '$methodName', "The record passed as argument did not contain the column $this->name that stores the group ID to deal with.", RSERROR_INVALID);
5233 }
5234 \$groupId = \$record['$this->name'];
5235 if (\$checkRight && !\$this->$canMethodName(\$record, \$groupName, \$groupComment)) {
5236 return RSErrorManager::raiseRSError(\$this->name, '$this->name', '$methodName', "You do not have the required permission to update the name and comment of group ID \$groupId.", RSERROR_PERMISSION_DENIED);
5237 }
5238 return \$this->app->callLiveUserPermAdminMethod('updateGroup', array(\$groupId, \$groupName, \$groupComment));
5239
5240 END;;; return new RSDEngineMethod($methodName, $paramString, $methodComments, $body);
5241 }
5242
5243
5244 function generateActivateGroupMethod()
5245 {
5246 $methodName = $this->generateActivateGroupMethodName();
5247 $canMethodName = $this->generateCanActivateGroupMethodName();
5248 $paramString = '&$record, $checkRight = true';
5249 $methodComments = <<<END
5250 /**Activate the group stored in the column '$this->name'.
5251 *
5252 * @param Array \$record An associative array that contains the column '$this->name'.
5253 * @param boolean \$checkRight Whether to perform a right checking.
5254 * @return mixed True or an instance of PEAR_Error.
5255 */
5256 END;;; $body = <<<END
5257 if (!isset(\$record['$this->name'])) {
5258 return RSErrorManager::raiseRSError(\$this->name, '$this->name', '$methodName', "The record passed as argument did not contain the column $this->name that stores the group ID to deal with.", RSERROR_INVALID);
5259 }
5260 \$groupId = \$record['$this->name'];
5261 if (\$checkRight && !\$this->$canMethodName(\$record)) {
5262 return RSErrorManager::raiseRSError(\$this->name, '$this->name', '$methodName', "You do not have the required permission to activate the group ID \$groupId.", RSERROR_PERMISSION_DENIED);
5263 }
5264 return \$this->app->callLiveUserPermAdminMethod('activateGroup', array(\$groupId));
5265
5266 END;;; return new RSDEngineMethod($methodName, $paramString, $methodComments, $body);
5267 }
5268
5269
5270 function generateDeactivateGroupMethod()
5271 {
5272 $methodName = $this->generateDeactivateGroupMethodName();
5273 $canMethodName = $this->generateCanDeactivateGroupMethodName();
5274 $paramString = '&$record, $checkRight = true';
5275 $methodComments = <<<END
5276 /**Deactivate the group stored in the column '$this->name'.
5277 *
5278 * @param Array \$record An associative array that contains the column '$this->name'.
5279 * @param boolean \$checkRight Whether to perform a right checking.
5280 * @return mixed True or an instance of PEAR_Error.
5281 */
5282 END;;; $body = <<<END
5283 if (!isset(\$record['$this->name'])) {
5284 return RSErrorManager::raiseRSError(\$this->name, '$this->name', '$methodName', "The record passed as argument did not contain the column $this->name that stores the group ID to deal with.", RSERROR_INVALID);
5285 }
5286 \$groupId = \$record['$this->name'];
5287 if (\$checkRight && !\$this->$canMethodName(\$record)) {
5288 return RSErrorManager::raiseRSError(\$this->name, '$this->name', '$methodName', "You do not have the required permission to deactivate the group ID \$groupId.", RSERROR_PERMISSION_DENIED);
5289 }
5290 return \$this->app->callLiveUserPermAdminMethod('deactivateGroup', array(\$groupId));
5291
5292 END;;; return new RSDEngineMethod($methodName, $paramString, $methodComments, $body);
5293 }
5294
5295
5296
5297 function generateCanUpdateLiveUserGroupMethods()
5298 {
5299 $body = ' return false;';
5300 $canAddUserToGroupMethodComments = <<<END
5301 /**Whether the user can add a user to the group saved in '$this->name' by ID.
5302 * @param Array \$record An associative array that contains the column '$this->name'.
5303 * @param int \$userId Ths ID of the user to add to the group.
5304 * @return boolean Whether the operation is permitted.
5305 */
5306 END;;;
5307 $canRemoveUserFromGroupMethodComments = <<<END
5308 /**Whether the user can remove a user from the group saved in '$this->name' by ID.
5309 * @param Array \$record An associative array that contains the column '$this->name'.
5310 * @param int \$userId Ths ID of the user to add to the group.
5311 * @return boolean Whether the operation is permitted.
5312 */
5313 END;;;
5314 $canUpdateGroupNameAndCommentMethodComments = <<<END
5315 /**Whether the user can update the name and comment of the group saved in '$this->name' by ID.
5316 * @param Array \$record An associative array that contains the column '$this->name'.
5317 * @param String \$groupName The group name.
5318 * @param String \$groupComment The group comment.
5319 * @return boolean Whether the operation is permitted.
5320 */
5321 END;;;
5322 $canActivateGroupMethodComments = <<<END
5323 /**Whether the user can activate the group saved in '$this->name' by ID.
5324 * @param Array \$record An associative array that contains the column '$this->name'.
5325 * @return boolean Whether the operation is permitted.
5326 */
5327 END;;;
5328 $canDeactivateGroupMethodComments = <<<END
5329 /**Whether the user can deactivate the group saved in '$this->name' by ID.
5330 * @param Array \$record An associative array that contains the column '$this->name'.
5331 * @return boolean Whether the operation is permitted.
5332 */
5333 END;;; $methods = array(
5334 'addUser' => new RSDEngineMethod($this->generateCanAddUserToGroupMethodName(), '&$record, $userId = false', $canAddUserToGroupMethodComments, $body),
5335 'removeUser' => new RSDEngineMethod($this->generateCanRemoveUserFromGroupMethodName(), '&$record, $userId = false', $canRemoveUserFromGroupMethodComments, $body),
5336 'updateNameAndComment' => new RSDEngineMethod($this->generateCanUpdateGroupNameAndCommentMethodName(), '&$record, $areaName = false, $areaComment = false', $canUpdateGroupNameAndCommentMethodComments, $body),
5337 'activate' => new RSDEngineMethod($this->generateCanActivateGroupMethodName(), '&$record', $canActivateGroupMethodComments, $body),
5338 'deactivate' => new RSDEngineMethod($this->generateCanDeactivateGroupMethodName(), '&$record', $canDeactivateGroupMethodComments, $body)
5339 );
5340
5341 $columnNameForPartialMethodName = $this->getColumnNameForPartialMethodName();
5342
5343 reset($this->editLiveUserGroupOptions);
5344 while (list($key, $editLiveUserGroupOption) = each($this->editLiveUserGroupOptions)) {
5345 $canUpdatePseudoColumn = '';
5346 if ($editLiveUserGroupOption->operation == 'addUser') {
5347 $canUpdatePseudoColumn = '__canAddUserTo' . $this->getColumnNameForPartialMethodName();
5348 $methodName = $this->generateCanAddUserToGroupMethodName();
5349 $paramString = '&$record, $userId = false';
5350 $methodComments = $canAddUserToGroupMethodComments;
5351
5352 } elseif ($editLiveUserGroupOption->operation == 'removeUser') {
5353 $canUpdatePseudoColumn = '__canRemoveUserFrom' . $this->getColumnNameForPartialMethodName();
5354 $methodName = $this->generateCanRemoveUserFromGroupMethodName();
5355 $paramString = '&$record, $userId = false';
5356 $methodComments = $canRemoveUserFromGroupMethodComments;
5357 } elseif ($editLiveUserGroupOption->operation == 'updateNameAndComment') {
5358 $canUpdatePseudoColumn = '__canUpdate' . $this->getColumnNameForPartialMethodName() . 'NameAndComment';
5359 $methodName = $this->generateCanUpdateGroupNameAndCommentMethodName();
5360 $paramString = '&$record, $groupName = false, $groupComment = false';
5361 $methodComments = $canUpdateGroupNameAndCommentMethodComments;
5362 } elseif ($editLiveUserGroupOption->operation == 'activate') {
5363 $canUpdatePseudoColumn = '__canActivate' . $this->getColumnNameForPartialMethodName();
5364 $methodName = $this->generateCanActivateGroupMethodName();
5365 $paramString = '&$record';
5366 $methodComments = $canActivateGroupMethodComments;
5367 } elseif ($editLiveUserGroupOption->operation == 'deactivate') {
5368 $canUpdatePseudoColumn = '__canDeactivate' . $this->getColumnNameForPartialMethodName();
5369 $methodName = $this->generateCanDeactivateGroupMethodName();
5370 $paramString = '&$record';
5371 $methodComments = $canDeactivateGroupMethodComments;
5372 }
5373
5374 $body = <<<END
5375 if (isset(\$record['$canUpdatePseudoColumn'])) {
5376 return \$record['$canUpdatePseudoColumn'];
5377 }
5378
5379 END;;; if ($editLiveUserGroupOption->condition != '') {
5380 $body .= <<<END
5381 \$record['$canUpdatePseudoColumn'] = $editLiveUserGroupOption->condition;
5382 if (\$record['$canUpdatePseudoColumn']) {
5383 \$record['__canUpdate$columnNameForPartialMethodName'] = true;
5384 }
5385 return \$record['$canUpdatePseudoColumn'];
5386 END;;;
5387 } elseif ($editLiveUserGroupOption->type == 'column') {
5388 $body .= <<<END
5389 \$record['$canUpdatePseudoColumn'] = isset(\$record['$editLiveUserGroupOption->columnName']) && \$this->app->liveUser->checkRight(\$record['$editLiveUserGroupOption->columnName']);
5390 if (\$record['$canUpdatePseudoColumn']) {
5391 \$record['__canUpdate$columnNameForPartialMethodName'] = true;
5392 }
5393 return \$record['$canUpdatePseudoColumn'];
5394
5395 END;;; } elseif ($editLiveUserGroupOption->type == 'table.column') {
5396 $body .= <<<END
5397 \$records = \$this->$editLiveUserGroupOption->selectIncludingMethodName(\$whereConditions, '', '$editLiveUserGroupOption->columnName', null, null, RSD_NO_LIVEUSER_RIGHT_CHECK);
5398
5399 if (!is_array(\$records)) {
5400 return RSErrorManager::raiseRSError(\$this->name,'','$methodName','Could not check permissions.', RSERROR_UNKNOWN);
5401 }
5402
5403 \$can = true;
5404 while (list(\$key, \$record) = each(\$records)) {
5405 if (!\$this->app->liveUser->checkRight(\$record['$editLiveUserGroupOption->columnName'])) {
5406 \$can = false;
5407 }
5408 }
5409
5410 \$record['$canUpdatePseudoColumn'] = \$can && count($records) > 0;
5411 if (\$record['$canUpdatePseudoColumn']) {
5412 \$record['__canUpdate$columnNameForPartialMethodName'] = true;
5413 }
5414 return \$record['$canUpdatePseudoColumn'];
5415
5416 END;;; } elseif ($editLiveUserGroupOption->type == 'SQL_QUERY') {
5417 $body .= <<<END
5418 \$record['$canUpdatePseudoColumn'] = !PEAR::isError(\$rightId = \$this->db->getOne("$editLiveUserGroupOption->query")) && \$this->app->liveUser->checkRight(\$rightId);
5419 if (\$record['$canUpdatePseudoColumn']) {
5420 \$record['__canUpdate$columnNameForPartialMethodName'] = true;
5421 }
5422 return \$record['$canUpdatePseudoColumn'];
5423
5424 END;;; } elseif ($editLiveUserGroupOption->type == 'PHP_CODE') {
5425 $body .= <<<END
5426 \$record['$canUpdatePseudoColumn'] = !PEAR::isError(\$rightId = $editLiveUserGroupOption->phpCode) && \$this->app->liveUser->checkRight(\$rightId);
5427 if (\$record['$canUpdatePseudoColumn']) {
5428 \$record['__canUpdate$columnNameForPartialMethodName'] = true;
5429 }
5430 return \$record['$canUpdatePseudoColumn'];
5431
5432 END;;; }
5433 $methods[$editLiveUserGroupOption->operation] = new RSDEngineMethod($methodName, $paramString, $methodComments, $body);
5434 }
5435 return $methods;
5436 }
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448 /**Returns the validation options for this column if it was defined as isValid:file.
5449 * @return mixed An associtave array of options or null. The options are
5450 * 'maxSize', 'contentType', 'storageDir' and 'storageDirConstant'.
5451 */
5452 function getIsValidFileOptions()
5453 {
5454 return $this->_isValidFileOptions;
5455 }
5456
5457 /**Sets the validation options for this column that was defined as isValid:file.
5458 * @param Array $options An associtave array of options. Valid options are
5459 * 'maxSize', 'contentType', 'storageDir' and 'storageDirConstant'.
5460 */
5461 function setIsValidFileOptions($options)
5462 {
5463 $this->_isValidFileOptions = $options;
5464 }
5465
5466 /**Generates and Returns the isValid* method for this column.
5467 *
5468 * @return RSDEngineMethod The isValid method.
5469 */
5470 function generateIsValidMethod()
5471 {
5472 $methodComments = "/" . "**Returns true if the passed argument is valid for " . $this->name . ".\n" .
5473 "*\n" .
5474 "* @param mixed \$" . $this->getColumnNameForVariableName() . " The value to validate.\n" .
5475 "* @param boolean \$forceReferentialIntegrityCheck If to force an referential integrety check. This argument is optional. The default is false.\n" .
5476 "* @param String \$negativeConditions A string containing conditions that are used to solve the following problem:\n" .
5477 "* A record with the unique username 'tom' gets updated with a new password and the username is again set to 'tom'.\n" .
5478 "* When asking this method if the username 'tom' already exists the answer would be yes and our update operation would fail.\n" .
5479 "* The negative conditions allow us to exclude this very record and find out if there any other records with username='tom'.\n" .
5480 "* This argument is optional.\n" .
5481 "* @return boolean True if valid, otherwise false.\n" .
5482 "*/";
5483 $paramString = '$' . $this->getColumnNameForVariableName() . ', $forceReferentialIntegrityCheck = false, $negativeConditions = false';
5484 $body = "";
5485
5486 $isValidFields = split(":",$this->isValid);
5487 $isValidMethod = $isValidFields[0];
5488
5489 if (strtolower($isValidMethod) == "code") {
5490 $validationCode = substr($this->isValid, strpos($this->isValid,":") + 1);
5491 $validationCode = str_replace("%s",'$' . $this->getColumnNameForVariableName(), $validationCode);
5492 $body .= "\n";
5493 $body .= " /" . "/Validation-method was set to '$isValidMethod'\n";
5494 $body .= " if (!($validationCode)) {\n";
5495 $body .= ' return RSErrorManager::raiseRSError("' . $this->table . '", "' . $this->name . '", "validation", "The value is invalid.", RSERROR_INVALID);' . "\n";
5496 $body .= " }\n";
5497 } elseif (strtolower($isValidMethod) == "in") {
5498 //everything after the first colon
5499 $possibleValues = split(":",substr($this->isValid, strpos($this->isValid,":") + 1));
5500 $condition = RSArrayUtil::toString($possibleValues," || ", '$' . $this->getColumnNameForVariableName() . " === %val");
5501 $body .= "\n";
5502 $body .= " /" . "/Validation-method was set to '$isValidMethod'\n";
5503 $body .= " if (!($condition)) { \n";
5504 $body .= ' return RSErrorManager::raiseRSError("' . $this->table . '", "' . $this->name . '", "validation", "The value is invalid.", RSERROR_INVALID);' . "\n";
5505 $body .= " }\n";
5506 } elseif (strtolower($isValidMethod) == "file") {
5507
5508 if ($this->sequenceName == '') {
5509 return RSErrorManager::raiseRSError($this->table, $this->name, "RSDEngineColumn::generateIsValidMethod", "Columns defined as isValid:file require a sequence (/**sequence:seq_name**/).", RSERROR_FATAL_ERROR);
5510 }
5511
5512 $fields = $isValidFields;
5513 array_shift($fields);
5514 $maxSize = array_shift($fields);
5515 $contentType = array_shift($fields);
5516
5517 $conditions = array();
5518
5519
5520
5521
5522 //file_exists conditions
5523 $paths = RSArrayUtil::toString($fields, ':', '%val');
5524
5525 $defaultFile = "''";
5526 $storageDir = "''";
5527 if ($paths != "") {
5528 $paths = split(";", $paths);
5529
5530 if (isset($paths[0])) {
5531 if (RSValidation::startsWith($paths[0], './') || RSValidation::startsWith($paths[0], '../')) {
5532 $defaultFile = "dirname(__FILE__) . '/../" . $paths[0] . "'";
5533 } else {
5534 $defaultFile = "'" . $paths[0] . "'";
5535 }
5536 } else {
5537 $defaultFile = "''";
5538 }
5539
5540 if (isset($paths[1])) {
5541 if (RSValidation::startsWith($paths[1], './') || RSValidation::startsWith($paths[1], '../')) {
5542 $storageDir = "dirname(__FILE__) . '/../" . $paths[1] . "'";
5543 } else {
5544 $storageDir = "'" . $paths[1] . "'";
5545 }
5546 } else {
5547 $storageDir = "''";
5548 }
5549
5550 }
5551
5552 if ($storageDir == "''") {
5553 $storageDir = strtoupper($this->rsdEngineDBTable->projectName) . '_FILE_STORAGE_DIR';
5554 }
5555
5556 $pathExpr = "$storageDir . '/' . \$fileName";
5557
5558
5559 $body .= "\n";
5560 $body .= " /" . "/Validation-method was set to '$isValidMethod'\n";
5561 $body .= " \$fileName = \$" . $this->getColumnNameForVariableName() . ";\n";
5562 $body .= " \$filePath = $pathExpr;\n";
5563
5564 $conditions[] = 'strpos($fileName, "/") === false';
5565 $conditions[] = 'strpos($fileName, "\\\\") === false';
5566 $conditions[] = 'file_exists($filePath)';
5567
5568 //is_file condition
5569 $conditions[] = 'is_file($filePath)';
5570
5571 //is_readable condition
5572 $conditions[] = 'is_readable($filePath)';
5573
5574 //maxSize condition
5575 if ($maxSize != "") {
5576 $maxSize = strtoupper($maxSize);
5577 if (strpos($maxSize, 'MB')) {
5578 $maxSize = str_replace('MB', '', $maxSize) * 1024 * 1024;
5579 } else if (strpos($maxSize, 'KB')) {
5580 $maxSize = str_replace('KB', '', $maxSize) * 1024;
5581 }
5582 $conditions[] = 'filesize($filePath) < ' . $maxSize;
5583 }
5584
5585 //contentType conditions
5586 if ($contentType != null) {
5587 $conditions[] = "function_exists('mime_content_type') ? (strpos(mime_content_type(\$filePath), '$contentType') !== false) : true";
5588 }
5589
5590
5591 $conditions = RSArrayUtil::toString($conditions, "\n &&\n ", '%val');
5592 $body .=" if (\n" .
5593 " !(\n" .
5594 " $conditions\n" .
5595 " )\n" .
5596 " ) { \n" .
5597 ' return RSErrorManager::raiseRSError("' . $this->table . '", "' . $this->name . '", "validation", "Invalid file!", RSERROR_INVALID);' . "\n" .
5598 " }\n";
5599
5600
5601 $this->setIsValidFileOptions(
5602 array(
5603 'maxSize' => $maxSize,
5604 'contentType' => $contentType,
5605 'defaultFile' => $defaultFile,
5606 'defaultFileConstant' => strtoupper($this->rsdEngineDBTable->projectName) .
5607 '_' .
5608 strtoupper($this->rsdEngineDBTable->getTableNameWithoutPrefix()) .
5609 '_' .
5610 strtoupper($this->getColumnNameForVariableName()) .
5611 '_DEFAULT_FILE',
5612 'storageDir' => $storageDir,
5613 'storageDirConstant' => strtoupper($this->rsdEngineDBTable->projectName) .
5614 '_' .
5615 strtoupper($this->rsdEngineDBTable->getTableNameWithoutPrefix()) .
5616 '_' .
5617 strtoupper($this->getColumnNameForVariableName()) .
5618 '_STORAGE_DIR'
5619 )
5620 );
5621
5622 } elseif ($isValidMethod != "") {
5623 $validationClassName = $this->rsdEngineDBTable->rsdEngineDB->config['validationClassName'];
5624 $validationClassFile = $this->rsdEngineDBTable->rsdEngineDB->config['validationClassFile'];
5625 if (($fp = @fopen($validationClassFile, "r", true)) !== false) {
5626 fclose($fp);
5627 if (!class_exists($validationClassName)) {
5628 require_once($validationClassFile);
5629 }
5630 } else {
5631 return RSErrorManager::raiseRSError($this->table, $this->name, "RSDEngineColumn::generateIsValidMethod", "Unable to find the validation class file: $validationClassFile", RSERROR_FATAL_ERROR);
5632 }
5633 if (!class_exists($validationClassName)) {
5634 return RSErrorManager::raiseRSError($this->table, $this->name, "RSDEngineColumn::generateIsValidMethod", "$validationClassName is not a valid class. It is not defined in $validationClassFile.", RSERROR_FATAL_ERROR);
5635 }
5636 if (!method_exists(new $validationClassName(), $isValidMethod)) {
5637 return RSErrorManager::raiseRSError($this->table, $this->name, "RSDEngineColumn::generateIsValidMethod", "The class $validationClassName stored in $validationClassFile has no method named $isValidMethod.", RSERROR_FATAL_ERROR);
5638 }
5639
5640 $isValidArguments = array();
5641 $firstArg = $this->getColumnNameForVariableName();
5642 $isValidArguments[] = '$' . $firstArg;
5643 reset($isValidFields);
5644 for ($i = 1; $i < count($isValidFields); $i++) {
5645 $isValidArguments[] = $isValidFields[$i];
5646 }
5647
5648 $body .= " /" . "/Validation-method was set to '$isValidMethod'\n";
5649 $body .= " if (!$validationClassName::$isValidMethod(" . RSArrayUtil::toString($isValidArguments,", ","%val") . ")) {\n";
5650 $body .= ' return RSErrorManager::raiseRSError("' . $this->table . '", "' . $this->name . '", "validation", "The value for ' . $this->name .' is invalid.", RSERROR_INVALID);' . "\n";
5651 $body .= " }\n";
5652 }
5653 if ($this->unique) {
5654 $body .= "\n";
5655 $body .= ' if ($forceReferentialIntegrityCheck || ' . strtoupper($this->rsdEngineDBTable->projectName) . '_DB_ENSURE_REFERENTIAL_INTEGRITY) {' . "\n";
5656 $body .= ' if ($negativeConditions == "") {' . "\n";
5657 $body .= ' $negativeConditions = "1 = 2";' . "\n";
5658 $body .= ' }' . "\n";
5659 $body .= " /" . "/Validation: UNIQUE\n";
5660 $body .= " \$count = \$this->count(\n";
5661 $body .= " array(\n";
5662 $body .= " array(\n";
5663 $body .= " '$this->name' => \$" . $this->getColumnNameForVariableName() . "\n";
5664 $body .= " ),\n";
5665 $body .= " \"%s1 AND !(\$negativeConditions)\"\n";
5666 $body .= " )\n";
5667 $body .= " );\n";
5668 $body .= ' if (PEAR::isError($count)) {' . "\n";
5669 $body .= ' return $count;' . "\n";
5670 $body .= " }\n";
5671 $body .= ' if ($count !== 0 && $count !== "0") {' . "\n";
5672 $body .= ' return RSErrorManager::raiseRSError("' . $this->table . '", "' . $this->name . '", "validation", "The value is not unique.", DB_ERROR_ALREADY_EXISTS);' . "\n";
5673 $body .= " }\n";
5674 $body .= " }\n";
5675 }
5676 if ($this->getForeignKeyTarget()) {
5677 $body .= "\n";
5678 $body .= ' if ($forceReferentialIntegrityCheck || ' . strtoupper($this->rsdEngineDBTable->projectName) . '_DB_ENSURE_REFERENTIAL_INTEGRITY) {' . "\n";
5679 $body .= " /" . "/Validation: FOREIGN KEY\n";
5680 $body .= ' if (PEAR::isError($error = $this->isValidForeignKey($' . $this->getColumnNameForVariableName() . ', "' . $this->getForeignKeyTarget() . '"))) {' . "\n";
5681 $body .= ' return RSErrorManager::raiseRSError($this->name, \'' . $this->name . "', 'validation', 'invalid foreign key for referencing the primary key " . $this->getForeignKeyTarget() . '\', RSERROR_INVALID_FOREIGN_KEY);' . "\n";
5682 $body .= " }\n";
5683 $body .= " }\n";
5684 }
5685 $body .= "\n";
5686 $body .= " return true;";
5687 return new RSDEngineMethod($this->generateIsValidMethodName(),$paramString,$methodComments,$body);
5688 }
5689
5690 /**Returns the name of the isValid* method for this column.
5691 *
5692 * @return String The name of the isValid* method.
5693 */
5694 function generateIsValidMethodName()
5695 {
5696 return "isValid" . $this->getColumnNameForPartialMethodName();
5697 }
5698
5699 /**Returns the name of the storeUploaded* method for this column.
5700 *
5701 * @return String The name of the storeUploaded* method.
5702 */
5703 function generateStoreUploadedMethodName()
5704 {
5705 return "storeUploaded" . $this->getColumnNameForPartialMethodName();
5706 }
5707
5708 /**Returns the name of the removeStored* method for this column.
5709 *
5710 * @return String The name of the removeStored* method.
5711 */
5712 function generateRemoveStoredMethodName()
5713 {
5714 return "removeStored" . $this->getColumnNameForPartialMethodName();
5715 }
5716
5717 /**Returns the name of the getStored* method for this column.
5718 *
5719 * @return String The name of the getStored* method.
5720 */
5721 function generateGetStoredMethodName()
5722 {
5723 return "getStored" . $this->getColumnNameForPartialMethodName();
5724 }
5725
5726 /**Returns the name of the getNext* method for this column.
5727 *
5728 * @return String The name of the getNext* method.
5729 */
5730 function generateGetNextMethodName()
5731 {
5732 return "getNext" . $this->getColumnNameForPartialMethodName();
5733 }
5734
5735 /**Generates and Returns the getNext* method for this column.
5736 *
5737 * @see sequenceName
5738 * @return mixed If the property sequenceName is not an empty string a new instance of RSDEngineMethod is returned; otherwise false is returned.
5739 */
5740 function generateGetNextMethod()
5741 {
5742 if ($this->sequenceName == "") {
5743 return false;
5744 }
5745 $paramString = '';
5746 $methodComments = "/" . "**Returns a new id from the sequence $this->sequenceName for the column $this->name.\n" .
5747 "*\n" .
5748 "* @return int The new ID.\n" .
5749 "*/";
5750 $body = "";
5751 $body .= ' return $this->db->nextId("' . $this->sequenceName . '");';
5752
5753 return new RSDEngineMethod($this->generateGetNextMethodName(), $paramString, $methodComments, $body);
5754 }
5755
5756 /**Returns the column name without the prifix.
5757 *
5758 * @see columnPrefix
5759 * @return String The column name without prefix.
5760 */
5761 function getColumnNameWithoutPrefix()
5762 {
5763 $name = $this->name;
5764 if (strpos($name,'$this->') === 0) {
5765 $name = substr($name,strlen('$this->'));
5766 }
5767 if ($this->columnPrefix != "") {
5768 $name = preg_replace('/^' . $this->columnPrefix . '/i','', $name);
5769 }
5770 return $name;
5771 }
5772
5773 /**Returns the column name suitable for including it in a method name.
5774 *
5775 * This is done like this:
5776 * {@source }
5777 *
5778 * @see getColumnNameWithoutPrefix
5779 * @return String The column name suitable for a partial method name.
5780 */
5781 function getColumnNameForPartialMethodName()
5782 {
5783 $str = ucfirst(strtolower($this->getColumnNameWithoutPrefix()));
5784 //the e modifier makes the second argument to be parsed as PHP-Code!
5785 return preg_replace("/_([a-z0-9])/ie","strtoupper('\\1')",$str);
5786 }
5787
5788 /**Returns the column name suitable for use as an identifyer name.
5789 *
5790 * This is done like this:
5791 * {@source }
5792 *
5793 * @see getColumnNameWithoutPrefix
5794 * @return String The column name suitable for use as an identifyer name.
5795 */
5796 function getColumnNameForVariableName()
5797 {
5798 $str = strtolower($this->getColumnNameWithoutPrefix());
5799 //the e modifier makes the second argument to be parsed as PHP-Code!
5800 return preg_replace("/_([a-z0-9])/ie","strtoupper('\\1')", $str);
5801 }
5802
5803 /**Returns the sequence name suitable for use as an identifyer name.
5804 *
5805 * @return String The sequence name suitable for use as an identifyer name.
5806 */
5807 function getSequenceNameForVariableName()
5808 {
5809 $str = strtolower($this->sequenceName);
5810
5811 if (strpos($str,'$this->') === 0) {
5812 $str = substr($str,strlen('$this->'));
5813 }
5814
5815 //the e modifier makes the second argument to be parsed as PHP-Code!
5816 return preg_replace("/_([a-z0-9])/ie","strtoupper('\\1')", $str);
5817 }
5818
5819 /**Returns a literal representation of this column.
5820 * Format:
5821 * {@source }
5822 *
5823 * @return String A literal representation of this column
5824 */
5825 function toString()
5826 {
5827 return $this->fullName;
5828 }
5829 }
5830
5831
5832 /**Implements a relation between two database tables.
5833 *
5834 * The access restriction for this class should be treated as 'friendly' - only accessable by classes in the same package.
5835 *
5836 * @author Lukas Feiler <lukas.feiler@chello.at>
5837 * @version 0.1.9
5838 * @copyright Lukas Feiler 2003
5839 * @package RSDEngine
5840 * @access public
5841 */
5842 class RSDEngineRelation {
5843 /**
5844 * @var String The starting point table name. Is set in the construtor method.
5845 * @see RSDEngineRelation::RSDEngineRelation
5846 */
5847 var $fromTable = "";
5848
5849 /**
5850 * @var String The starting point column name. Is set in the construtor method.
5851 * @see RSDEngineRelation::RSDEngineRelation
5852 */
5853 var $fromColumn = "";
5854
5855 /**
5856 * @var String The target table name. Is set in the construtor method.
5857 * @see RSDEngineRelation::RSDEngineRelation
5858 */
5859 var $toTable = "";
5860
5861 /**
5862 * @var String The target column name. Is set in the construtor method.
5863 * @see RSDEngineRelation::RSDEngineRelation
5864 */
5865 var $toColumn = "";
5866
5867 /**
5868 * @var The starting point in TABLE.COLUMN notation. Is set in the construtor method.
5869 * @see RSDEngineRelation::RSDEngineRelation
5870 */
5871 var $from = "";
5872
5873 /**
5874 * @var The target in TABLE.COLUMN notation. Is set in the construtor method.
5875 * @see RSDEngineRelation::RSDEngineRelation
5876 */
5877 var $to = "";
5878
5879 /**The RSDEngineDBTable instance that created this instance.
5880 * @var RSDEngineDBTable
5881 */
5882 var $rsdEngineDBTable = null;
5883
5884 /**Constructor method that initializes this instance.
5885 *
5886 * @param String $fromTable The starting point table name.
5887 * @param String $fromColumn The starting point column name.
5888 * @param String $fromTable The target table name.
5889 * @param String $fromColumn The target column name.
5890 */
5891 function RSDEngineRelation($fromTable, $fromColumn, $toTable, $toColumn, &$rsdEngineDBTable)
5892 {
5893 $this->fromTable = $fromTable;
5894 $this->fromColumn = $fromColumn;
5895 $this->toTable = $toTable;
5896 $this->toColumn = $toColumn;
5897 $this->from = "$fromTable.$fromColumn";
5898 $this->to = "$toTable.$toColumn";
5899 $this->rsdEngineDBTable =& $rsdEngineDBTable;
5900
5901 $this->rsdEngineDBTable->rsdEngineDB->config['rsdEngine']->logInfo(" - Parsing relations " . $this->toString());
5902 }
5903
5904 /**Returns a literal representation of this relation.
5905 */
5906 function toString()
5907 {
5908 return $this->from . " = " . $this->to;
5909 }
5910 }
5911
5912
5913 /**A class for generating an entire PHP-Class.
5914 *
5915 * The access restriction for this class should be treated as 'friendly' - only accessable by classes in the same package.
5916 *
5917 * @author Lukas Feiler <lukas.feiler@chello.at>
5918 * @version 0.1.9
5919 * @copyright Lukas Feiler 2003
5920 * @package RSDEngine
5921 * @access public
5922 */
5923 class RSDEngineMethod {
5924 /**
5925 * @var String The method name. Is set in the construtor method.
5926 * @see RSDEngineMethod::RSDEngineMethod
5927 */
5928 var $name = "";
5929
5930 /**
5931 * @param String The parameter string as it is inserted between the opening and the closing brace in the method declaration. Is set in the construtor method.
5932 * @see RSDEngineMethod::RSDEngineMethod
5933 */
5934 var $parameters = "";
5935
5936 /**
5937 * @param String The comment block preceeding the method. Is set in the construtor method.
5938 * @see RSDEngineMethod::RSDEngineMethod
5939 */
5940 var $methodComments = "";
5941
5942 /**
5943 * @var String The method body.
5944 */
5945 var $body = "";
5946
5947 /**
5948 * @param String A String to be placed in front of every line. Is set in the construtor method and in the method setIndent.
5949 * @see RSDEngineMethod::RSDEngineMethod
5950 * @see setIndent
5951 */
5952 var $indent = "";
5953
5954 /**Constructor method that initializes this instance.
5955 *
5956 * @param String $name The method name.
5957 * @param String $parameters The parameter string as it is inserted between the opening and the closing brace in the method declaration.
5958 * @param String $methodComments The comment block preceeding the method.
5959 * @param String $body The method body.
5960 * @param String $indent A String to be placed in front of every line. This argument is optional. The default value is an empty string.
5961 */
5962 function RSDEngineMethod($name, $parameters, $methodComments, $body, $indent = "")
5963 {
5964 $this->name = $name;
5965 $this->parameters = $parameters;
5966 $this->body = $body;
5967 $this->indent = $indent;
5968 $this->methodComments = $methodComments;
5969 }
5970
5971 /**Sets the property indent.
5972 *
5973 * @see indent
5974 * @param String The value to assign to $this->indent.
5975 */
5976 function setIndent($indent)
5977 {
5978 $this->indent = $indent;
5979 }
5980
5981 /**Returns the method declaration.
5982 *
5983 * Looks like this:
5984 * {@source }
5985 *
5986 * @return String the method declaration.
5987 */
5988 function toString()
5989 {
5990 return $this->name . "(" . $this->parameters . ")";
5991 }
5992
5993 /**Returns the code of this method.
5994 *
5995 * @return String The code including the method comments, the method declaration and the founction body.
5996 */
5997 function getCode()
5998 {
5999 $name = $this->name;
6000 $parameters = $this->parameters;
6001 $body = $this->body;
6002
6003 $ret = "$this->
6004 methodCommentsfunction $name($parameters)
6005 {
6006 $body
6007 }
6008
6009 ";
6010 return preg_replace("/^([\s\S])/m", $this->indent . "$1", $ret);
6011 }
6012 }
6013
6014
6015 /**This class represents a LiveUser table option that is used to define the rights the current user must have to perform certain operations.
6016 *
6017 * @author Lukas Feiler <lukas.feiler@chello.at>
6018 * @version 0.1.9
6019 * @copyright Lukas Feiler 2003
6020 * @package RSDEngine
6021 * @access public
6022 */
6023 class RSDEngineLiveUserRight {
6024
6025 /**The name of the operation this right is required for. Possible values are 'select', 'insert', 'update', 'delete' and 'undefined'.
6026 * @access public
6027 * @var String
6028 */
6029 var $operation = '';
6030
6031 /**The type of LiveUserTableOption. Can be one of the following strings: 'column', 'table.column', 'SQL_QUERY' or 'PHP_CODE'.
6032 * @access public
6033 * @var String
6034 */
6035 var $type = '';
6036
6037 /**The name of the column that stores the rightId. This property is only used if $this->type is 'column' or 'table.column'.
6038 * @access public
6039 * @var String
6040 */
6041 var $columnName = '';
6042
6043 /**The name of the table that contains $columnName. This property is only used if $this->type is 'table.column'.
6044 * @access public
6045 * @var String
6046 */
6047 var $tableName = '';
6048
6049 /**The name of the selectIncluding* method used to perform the join over $tableName. This property is only used if $this->type is 'table.column'.
6050 * @access public
6051 * @var String
6052 */
6053 var $selectIncludingMethodName = '';
6054
6055 /**The SQL code to pass to the method $this->db->getOne to get the rightId. This property is only used if $this->type is 'SQL_QUERY'.
6056 * @access public
6057 * @var String
6058 */
6059 var $query = '';
6060
6061 /**The PHP code to execute to get the rightId. This property is only used if $this->type is 'PHP_CODE'.
6062 * @access public
6063 * @var String
6064 */
6065 var $phpCode = '';
6066
6067 /**The definition of this LiveUser right as table option.
6068 * @access public
6069 * @var String
6070 */
6071 var $definition = '';
6072
6073 /**The PHP code to execute to get a boolean value that indicates if the user is allowed to perform this operation or not.
6074 * If this property is set $this->type will be set to 'PHP_CODE'.
6075 * @access public
6076 * @var String
6077 */
6078 var $condition = '';
6079
6080 /**The PHP code to execute for every record to get a boolean value that indicates if the user is allowed to perform this operation on the specific record or not.
6081 * If this property is set $this->type will be set to 'PHP_CODE'.
6082 * @access public
6083 * @var String
6084 */
6085 var $recordCondition = '';
6086
6087 /**The relation to the table (class) that contains the selectIncludingMethod.
6088 *
6089 * This property is used for LiveUserRight:insert:rightId=table.column.
6090 *
6091 * @see selectIncludingMethodName
6092 * @var RSDEngineRelation
6093 */
6094 var $relationToSelectIncludingTable = null;
6095
6096 /**The constructor method.
6097 * @param Array $options An associative array. All values that have a key that is named like a property of this class are assigned to that property.
6098 */
6099 function RSDEngineLiveUserRight ($options)
6100 {
6101 reset($options);
6102 while (list($key, $value) = each($options)) {
6103 if (isset($this->$key)) {
6104 $this->$key = $value;
6105 }
6106 }
6107 }
6108
6109 /**Return a literal representation of this instance.
6110 * @return String
6111 */
6112 function toString()
6113 {
6114 $ret = "LiveUserRight:$this->operation: type=$this->type; ";
6115 $type = $this->type;
6116 switch ($type) {
6117 case 'column':
6118 $ret .= "columnName=$this->columnName";
6119 break;
6120 case 'table.column':
6121 $ret .= "tableName=$this->tableName; columnName=$this->columnName";
6122 break;
6123 case 'SQL_QUERY':
6124 $ret .= "query=$this->query";
6125 break;
6126 case 'PHP_CODE':
6127 if ($this->condition) {
6128 $ret .= "condition=$this->condition";
6129 } elseif ($this->recordCondition) {
6130 $ret .= "recordCondition=$this->recordCondition";
6131 } else {
6132 $ret .= "phpCode=$this->phpCode";
6133 }
6134 break;
6135 default:
6136 $ret .= 'UNKNOWN TYPE';
6137 break;
6138 }
6139 return $ret;
6140 }
6141 }
6142
6143
6144 /**This class represents a file table option that is used to define settings for individual files.
6145 *
6146 * @author Lukas Feiler <lukas.feiler@chello.at>
6147 * @version 0.1.9
6148 * @copyright Lukas Feiler 2003
6149 * @package RSDEngine
6150 * @access public
6151 */
6152 class RSDEngineFileOption {
6153
6154 /**The type of the file. Possible values are 'controller', 'view', 'childClass', 'baseClass', 'all'
6155 * @access public
6156 * @var String
6157 */
6158 var $type = null;
6159
6160 /**Whether to write (create) this file if non-existing, do not even try to create it or to overwrite it if existing. Valid values are 'true', 'false', 'overwrite'.
6161 * @access public
6162 * @var String
6163 */
6164 var $write = null;
6165
6166 /**Whether this file (controller) is public (or private).
6167 * @access public
6168 * @var boolean
6169 */
6170 var $public = null;
6171
6172 /**Whether to include a header file.
6173 * @access public
6174 * @var boolean
6175 */
6176 var $header = null;
6177
6178 /**Whether to include a footer file.
6179 * @access public
6180 * @var boolean
6181 */
6182 var $footer = null;
6183
6184 /**Whether to display the columns defined as primary or foreing key in the templates.
6185 * @access public
6186 * @var boolean
6187 */
6188 var $showKeyColumns = null;
6189
6190 /**The SQL expression by which the records should be ordered.
6191 * @access public
6192 * @var String
6193 */
6194 var $orderBy = null;
6195
6196 /**Whether to allow the user to specify by which column the records should be ordered.
6197 * @access public
6198 * @var boolean
6199 */
6200 var $allowUserOrderBy = null;
6201
6202 /**Whether to implement a paging feature
6203 * @access public
6204 * @var boolean
6205 */
6206 var $paging = null;
6207
6208 /**The number of records to display per page. This property is only relavant if $this->paging is set to true.
6209 * @access public
6210 * @var String
6211 */
6212 var $recordsPerPage = null;
6213
6214 /**The name of the selectIncluding* method used to get the records.
6215 * @access public
6216 * @var String
6217 */
6218 var $selectMethodName = null;
6219
6220 /**Whether to use a seperate template to display the records in the get/search template.
6221 * @access public
6222 * @var String
6223 */
6224 var $separateRecordTemplate = null;
6225
6226 /**The constructor method.
6227 * @param Array $options An associative array. All values that have a key that is named like a property of this class are assigned to that property.
6228 */
6229 function RSDEngineFileOption ($options)
6230 {
6231 reset($options);
6232 while (list($key, $value) = each($options)) {
6233 if (array_key_exists($key, get_object_vars($this))) {
6234 $this->$key = $value;
6235 }
6236 }
6237 }
6238
6239 /**Return a literal representation of this instance.
6240 * @return String
6241 */
6242 function toString()
6243 {
6244 return "RSDEngineFileOption: " .
6245 "type=" . $this->_propertyToString($this->type) . "; " .
6246 "write=" . $this->_propertyToString($this->write) . "; " .
6247 "public=" . $this->_propertyToString($this->public) . "; " .
6248 "header=" . $this->_propertyToString($this->header) . "; " .
6249 "footer=" . $this->_propertyToString($this->footer) . "; " .
6250 "showKeyColumns=" . $this->_propertyToString($this->showKeyColumns) . "; " .
6251 "orderBy=" . $this->_propertyToString($this->orderBy) . "; " .
6252 "allowUserOrderBy=" . $this->_propertyToString($this->allowUserOrderBy) . "; " .
6253 "paging=" . $this->_propertyToString($this->paging) . "; " .
6254 "recordsPerPage=" . $this->_propertyToString($this->recordsPerPage) . "; " .
6255 "selectMethodName=" . $this->_propertyToString($this->selectMethodName) . "; " .
6256 "separateRecordTemplate=" . $this->_propertyToString($this->separateRecordTemplate);
6257 }
6258
6259 function _propertyToString($value)
6260 {
6261 if ($value === null) {
6262 return 'null';
6263 } elseif ($value === false) {
6264 return '0';
6265 } elseif ($value === true) {
6266 return '1';
6267 } else {
6268 return $value;
6269 }
6270 }
6271
6272 /**Updates all properties in with the values of the associative array passed as argument if the values are not null.
6273 *
6274 * @param Array $properties
6275 */
6276 function overwrite($properties)
6277 {
6278 while (list($propertyName, $propertyValue) = each($properties)) {
6279 if ($propertyValue !== null && array_key_exists($propertyName, get_object_vars($this))) {
6280 $this->$propertyName = $propertyValue;
6281 }
6282 }
6283 }
6284 }
6285
6286 /**An instance of this class is created for every editLiveUserRight option.
6287 * The option is of the following format: editLiveUserRight[:$OPERATION][:[rightId=$RIGHT_ID]|[condition=PHP_CODE]]
6288 * Or to be mor specific: editLiveUserRight[:userRight|groupRight|grantRight|revokeRight|grantUserRight|revokeUserRight|grantGroupRight|revokeGroupRight|all][[:rightId=column|table.column|SQL_QUERY|PHP_CODE]|condition=PHP_CODE
6289 *
6290 * @author Lukas Feiler <lukas.feiler@chello.at>
6291 * @version 0.1.9
6292 * @copyright Lukas Feiler 2003
6293 * @package RSDEngine
6294 * @access public
6295 */
6296 class RSDEngineEditLiveUserRightOption {
6297
6298 /**The RSDEngineDBTable instance that created this instance.
6299 * @var RSDEngineDBTable
6300 */
6301 var $rsdEngineDBTable = null;
6302
6303 /**The column for which this option was set.
6304 * @var RSDEngineColumn
6305 */
6306 var $rsdEngineColumn = null;
6307
6308 /**The name of the operation.
6309 * Valid values are the following:
6310 * 'all', 'userRight', 'groupRight', 'grantRight', 'revokeRight', 'grantUserRight', 'revokeUserRight', 'grantGroupRight', 'revokeGroupRight'
6311 * @see $_possibleOperations
6312 * @var String
6313 */
6314 var $operation = '';
6315
6316 var $leftOperand = '';
6317
6318 var $rightOperand = '';
6319
6320 var $type = '';
6321
6322 var $tableName = '';
6323
6324 var $columnName = '';
6325
6326 var $query = '';
6327
6328 var $selectIncludingMethod = '';
6329
6330 var $phpCode = '';
6331
6332 var $condition = '';
6333
6334 function RSDEngineEditLiveUserRightOption($options)
6335 {
6336 reset($options);
6337 while (list($key, $value) = each($options)) {
6338 if (isset($this->$key)) {
6339 $this->$key =& $options[$key];
6340 }
6341 }
6342 }
6343
6344 function &factory(&$rsdEngineDBTable, &$rsdEngineColumn, $option)
6345 {
6346 $containers = array(
6347 'userRight' => array('grantUserRight', 'revokeUserRight'),
6348 'groupRight' => array('grantGroupRight', 'revokeGroupRight'),
6349 'grantRight' => array('grantUserRight', 'grantGroupRight'),
6350 'revokeRight' => array('revokeUserRight', 'revokeGroupRight'),
6351 'all' => array('grantUserRight', 'revokeUserRight', 'grantGroupRight', 'revokeGroupRight')
6352 );
6353 $possibleOperations = array('all', 'userRight', 'groupRight', 'grantRight', 'revokeRight', 'grantUserRight', 'revokeUserRight', 'grantGroupRight', 'revokeGroupRight');
6354
6355 $operation = '';
6356 $leftOperand = '';
6357 $rightOperand = '';
6358 $type = '';
6359 $tableName = '';
6360 $columnName = '';
6361 $query = '';
6362 $selectIncludingMethodName = '';
6363 $phpCode = '';
6364 $condition = '';
6365 $recordCondition = '';
6366
6367 //format: /**editLiveUserRight:rightId=$RIGHT_ID|condition=PHP_CODE**/
6368 //no operation specified: operation is set to 'all'
6369 preg_match("/\/\*\*editLiveUserRight:(rightId|condition)=([^*]*)\*\*\//", $option, $matches);
6370 if (count($matches) !== 0) {
6371 $operation = 'all';
6372 $leftOperand = $matches[1];
6373 $rightOperand = $matches[2];
6374 } else {
6375 //format: /**editLiveUserRight:$OPERATION:rightId=$RIGHT_ID|condition=PHP_CODE**/
6376 //everything is specified
6377 preg_match("/\/\*\*editLiveUserRight:([^:]*):(rightId|condition)=([^*]*)\*\*\//", $option, $matches);
6378 if (count($matches) !== 0) {
6379 $operation = $matches[1];
6380 $leftOperand = $matches[2];
6381 $rightOperand = $matches[3];
6382 } else {
6383 //format: /**editLiveUserRight:$OPERATION**/
6384 //no leftOperand and rightOperand specified: leftOperand is set to 'rightId', rightOperand to $rsdEngineColumn->name
6385 preg_match("/\/\*\*editLiveUserRight:(all|userRight|groupRight|grantRight|revokeRight|grantUserRight|revokeUserRight|grantGroupRight|revokeGroupRight)\*\*\//", $option, $matches);
6386 if (count($matches) !== 0) {
6387 $operation = $matches[1];
6388 $leftOperand = 'rightId';
6389 $rightOperand = $rsdEngineColumn->name;
6390 } else {
6391 //format: /**editLiveUserRight**/
6392 //no operation, no leftOperand and no rightOperand specified: operation is set to all, leftOperand is set to 'rightId', rightOperand to $rsdEngineColumn->name
6393 preg_match("/\/\*\*editLiveUserRight\*\*\//", $option, $matches);
6394 if (count($matches) !== 0) {
6395 $operation = 'all';
6396 $leftOperand = 'rightId';
6397 $rightOperand = $rsdEngineColumn->name;
6398 } else {
6399 return RSErrorManager::raiseRSError($rsdEngineDBTable->name, $rsdEngineColumn->name, "RSDEngineEditLiveUserRightOption::factory", "Wrong format of the option '$option'.", RSERROR_FATAL_ERROR);
6400 }
6401 }
6402 }
6403 }
6404
6405 if (!in_array($operation, $possibleOperations)) {
6406 return RSErrorManager::raiseRSError($rsdEngineDBTable->name, $rsdEngineColumn->name, "RSDEngineEditLiveUserRightOption::factory", "No such operation '$operation' in option '$option'.", RSERROR_FATAL_ERROR);
6407 }
6408
6409 if ($leftOperand == 'rightId') {
6410
6411 //type == 'column' ?
6412 preg_match('/([a-z0-9_]*)/', $rightOperand, $matches);
6413 if (isset($matches[1]) && $matches[1] == $rightOperand) {
6414 $type = 'column';
6415 $columnName = $rightOperand;
6416
6417 if (!$rsdEngineDBTable->columnExists($columnName)) {
6418 return RSErrorManager::raiseRSError($rsdEngineDBTable->name, $rsdEngineColumn->name, "RSDEngineEditLiveUserRightOption::factory", "The column '$columnName' used in the following option does not exist: '$option'.", RSERROR_FATAL_ERROR);
6419 }
6420 }
6421
6422 //type == 'table.column' ?
6423 preg_match('/([a-z0-9_]*)\.([a-z0-9_]*)/', $rightOperand, $matches);
6424 if (isset($matches[1]) && isset($matches[2]) && ($matches[1] . '.' . $matches[2]) == $rightOperand) {
6425 $type = 'table.column';
6426 $tableName = $matches[1];
6427 $columnName = $matches[2];
6428
6429 if (!$rsdEngineDBTable->rsdEngineDB->tableExists($tableName)) {
6430 return RSErrorManager::raiseRSError($rsdEngineDBTable->name, $rsdEngineColumn->name, "RSDEngineEditLiveUserRightOption::factory", "The table '$tableName' used in the following option does not exist: '$option'.", RSERROR_FATAL_ERROR);
6431 }
6432 $table =& $rsdEngineDBTable->rsdEngineDB->getTable($tableName);
6433 if (!$table->columnExists($columnName)) {
6434 return RSErrorManager::raiseRSError($rsdEngineDBTable->name, $rsdEngineColumn->name, "RSDEngineEditLiveUserRightOption::factory", "The column '$columnName' used in the following option does not exist: '$option'.", RSERROR_FATAL_ERROR);
6435 }
6436 }
6437
6438 //type == 'SQL_QUERY' ?
6439 preg_match('/(SELECT\ [^:]*\ FROM\ [^:]*)/i', $rightOperand, $matches);
6440 if (isset($matches[1]) && $matches[1] == $rightOperand) {
6441 $type = 'SQL_QUERY';
6442 $query = $rightOperand;
6443 }
6444
6445 //if it's none of the obove types it's PHP_CODE code:
6446 if ($type == '') {
6447 $type = 'PHP_CODE';
6448 $phpCode = $rightOperand;
6449 }
6450
6451 } elseif ($leftOperand == 'condition') {
6452 $type = '';
6453 $condition = $rightOperand;
6454 } else {
6455 return RSErrorManager::raiseRSError($rsdEngineDBTable->name, $rsdEngineColumn->name, "RSDEngineEditLiveUserRightOption::factory", "The left operand must be 'rightId' or 'condition' not '$leftOperand' in the option '$option'.", RSERROR_FATAL_ERROR);
6456 }
6457
6458
6459 if (isset($containers[$operation])) {
6460 $operations = $containers[$operation];
6461 } else {
6462 $operations = array($operation);
6463 }
6464
6465 $editLiveUserRightOptions = array();
6466 while (list($key, $operation) = each($operations)) {
6467
6468 //crate RSDEngineEditLiveUserRightOption instance
6469 $editLiveUserRightOption =& new RSDEngineEditLiveUserRightOption(
6470 array(
6471 'operation' => $operation,
6472 'leftOperand' => $leftOperand,
6473 'rightOperand' => $rightOperand,
6474 'type' => $type,
6475 'tableName' => $tableName,
6476 'columnName' => $columnName,
6477 'query' => $query,
6478 'selectIncludingMethodName' => $selectIncludingMethodName,
6479 'phpCode' => $phpCode,
6480 'condition' => $condition,
6481 'definition' => $option
6482 )
6483 );
6484
6485 //logging
6486 $rsdEngineDBTable->rsdEngineDB->config['rsdEngine']->logInfo(' - ' . $editLiveUserRightOption->toString());
6487 $editLiveUserRightOptions[] =& $editLiveUserRightOption;
6488 }
6489 return $editLiveUserRightOptions;
6490 }
6491
6492 /**Return a literal representation of this instance.
6493 * @return String
6494 */
6495 function toString()
6496 {
6497 $ret = "EditLiveUserRightOption:$this->operation: type=$this->type; ";
6498 $type = $this->type;
6499 switch ($type) {
6500 case 'column':
6501 $ret .= "columnName=$this->columnName";
6502 break;
6503 case 'table.column':
6504 $ret .= "tableName=$this->tableName; columnName=$this->columnName";
6505 break;
6506 case 'SQL_QUERY':
6507 $ret .= "query=$this->query";
6508 break;
6509 case 'PHP_CODE':
6510 if ($this->condition) {
6511 $ret .= "condition=$this->condition";
6512 } else {
6513 $ret .= "phpCode=$this->phpCode";
6514 }
6515 break;
6516 default:
6517 $ret .= 'UNKNOWN TYPE';
6518 break;
6519 }
6520 return $ret;
6521 }
6522 }
6523
6524
6525 /**An instance of this class is created for every editLiveUserArea option.
6526 * The option is of the following format: editLiveUserArea[:$OPERATION][:[rightId=$RIGHT_ID]|[condition=PHP_CODE]]
6527 * Or to be mor specific: editLiveUserArea[:addAdmin|removeAdmin|updateNameAndComment|all][[:rightId=column|table.column|SQL_QUERY|PHP_CODE]|condition=PHP_CODE
6528 *
6529 * @author Lukas Feiler <lukas.feiler@chello.at>
6530 * @version 0.1.9
6531 * @copyright Lukas Feiler 2003
6532 * @package RSDEngine
6533 * @access public
6534 */
6535 class RSDEngineEditLiveUserAreaOption {
6536
6537 /**The RSDEngineDBTable instance that created this instance.
6538 * @var RSDEngineDBTable
6539 */
6540 var $rsdEngineDBTable = null;
6541
6542 /**The column for which this option was set.
6543 * @var RSDEngineColumn
6544 */
6545 var $rsdEngineColumn = null;
6546
6547 /**The name of the operation.
6548 * Valid values are the following:
6549 * 'addAdmin', 'removeAdmin', 'updateNameAndComment', 'all'
6550 * @see $_possibleOperations
6551 * @var String
6552 */
6553 var $operation = '';
6554
6555 var $leftOperand = '';
6556
6557 var $rightOperand = '';
6558
6559 var $type = '';
6560
6561 var $tableName = '';
6562
6563 var $columnName = '';
6564
6565 var $query = '';
6566
6567 var $selectIncludingMethod = '';
6568
6569 var $phpCode = '';
6570
6571 var $condition = '';
6572
6573 function RSDEngineEditLiveUserAreaOption($options)
6574 {
6575 reset($options);
6576 while (list($key, $value) = each($options)) {
6577 if (isset($this->$key)) {
6578 $this->$key =& $options[$key];
6579 }
6580 }
6581 }
6582
6583 function &factory(&$rsdEngineDBTable, &$rsdEngineColumn, $option)
6584 {
6585 $containers = array(
6586 'all' => array('addAdmin', 'removeAdmin', 'updateNameAndComment')
6587 );
6588 $possibleOperations = array('addAdmin', 'removeAdmin', 'updateNameAndComment', 'all');
6589
6590 $operation = '';
6591 $leftOperand = '';
6592 $rightOperand = '';
6593 $type = '';
6594 $tableName = '';
6595 $columnName = '';
6596 $query = '';
6597 $selectIncludingMethodName = '';
6598 $phpCode = '';
6599 $condition = '';
6600 $recordCondition = '';
6601
6602 //format: /**editLiveUserArea:rightId=$RIGHT_ID|condition=PHP_CODE**/
6603 //no operation specified: operation is set to 'all'
6604 preg_match("/\/\*\*editLiveUserArea:(rightId|condition)=([^*]*)\*\*\//", $option, $matches);
6605 if (count($matches) !== 0) {
6606 $operation = 'all';
6607 $leftOperand = $matches[1];
6608 $rightOperand = $matches[2];
6609 } else {
6610 //format: /**editLiveUserArea:$OPERATION:rightId=$RIGHT_ID|condition=PHP_CODE**/
6611 //everything is specified
6612 preg_match("/\/\*\*editLiveUserArea:([^:]*):(rightId|condition)=([^*]*)\*\*\//", $option, $matches);
6613 if (count($matches) !== 0) {
6614 $operation = $matches[1];
6615 $leftOperand = $matches[2];
6616 $rightOperand = $matches[3];
6617 } else {
6618 //format: /**editLiveUserArea:$OPERATION**/
6619 //no leftOperand and rightOperand specified: leftOperand is set to 'rightId', rightOperand to $rsdEngineColumn->name
6620 preg_match("/\/\*\*editLiveUserArea:(addAdmin|removeAdmin|updateNameAndComment|all)\*\*\//", $option, $matches);
6621 if (count($matches) !== 0) {
6622 $operation = $matches[1];
6623 $leftOperand = 'condition';
6624 $rightOperand = "\$this->app->isLiveUserAreaAdmin(\$record['$rsdEngineColumn->name'])";
6625 } else {
6626 //format: /**editLiveUserArea**/
6627 //no operation, no leftOperand and no rightOperand specified: operation is set to all, leftOperand is set to 'rightId', rightOperand to $rsdEngineColumn->name
6628 preg_match("/\/\*\*editLiveUserArea\*\*\//", $option, $matches);
6629 if (count($matches) !== 0) {
6630 $operation = 'all';
6631 $leftOperand = 'condition';
6632 $rightOperand = "\$this->app->isLiveUserAreaAdmin(\$record['$rsdEngineColumn->name'])";
6633 } else {
6634 return RSErrorManager::raiseRSError($rsdEngineDBTable->name, $rsdEngineColumn->name, "RSDEngineEditLiveUserAreaOption::factory", "Wrong format of the option '$option'.", RSERROR_FATAL_ERROR);
6635 }
6636 }
6637 }
6638 }
6639
6640 if (!in_array($operation, $possibleOperations)) {
6641 return RSErrorManager::raiseRSError($rsdEngineDBTable->name, $rsdEngineColumn->name, "RSDEngineEditLiveUserAreaOption::factory", "No such operation '$operation' in option '$option'.", RSERROR_FATAL_ERROR);
6642 }
6643
6644 if ($leftOperand == 'rightId') {
6645
6646 //type == 'column' ?
6647 preg_match('/([a-z0-9_]*)/', $rightOperand, $matches);
6648 if (isset($matches[1]) && $matches[1] == $rightOperand) {
6649 $type = 'column';
6650 $columnName = $rightOperand;
6651
6652 if (!$rsdEngineDBTable->columnExists($columnName)) {
6653 return RSErrorManager::raiseRSError($rsdEngineDBTable->name, $rsdEngineColumn->name, "RSDEngineEditLiveUserAreaOption::factory", "The column '$columnName' used in the following option does not exist: '$option'.", RSERROR_FATAL_ERROR);
6654 }
6655 }
6656
6657 //type == 'table.column' ?
6658 preg_match('/([a-z0-9_]*)\.([a-z0-9_]*)/', $rightOperand, $matches);
6659 if (isset($matches[1]) && isset($matches[2]) && ($matches[1] . '.' . $matches[2]) == $rightOperand) {
6660 $type = 'table.column';
6661 $tableName = $matches[1];
6662 $columnName = $matches[2];
6663
6664 if (!$rsdEngineDBTable->rsdEngineDB->tableExists($tableName)) {
6665 return RSErrorManager::raiseRSError($rsdEngineDBTable->name, $rsdEngineColumn->name, "RSDEngineEditLiveUserAreaOption::factory", "The table '$tableName' used in the following option does not exist: '$option'.", RSERROR_FATAL_ERROR);
6666 }
6667 $table =& $rsdEngineDBTable->rsdEngineDB->getTable($tableName);
6668 if (!$table->columnExists($columnName)) {
6669 return RSErrorManager::raiseRSError($rsdEngineDBTable->name, $rsdEngineColumn->name, "RSDEngineEditLiveUserAreaOption::factory", "The column '$columnName' used in the following option does not exist: '$option'.", RSERROR_FATAL_ERROR);
6670 }
6671 }
6672
6673 //type == 'SQL_QUERY' ?
6674 preg_match('/(SELECT\ [^:]*\ FROM\ [^:]*)/i', $rightOperand, $matches);
6675 if (isset($matches[1]) && $matches[1] == $rightOperand) {
6676 $type = 'SQL_QUERY';
6677 $query = $rightOperand;
6678 }
6679
6680 //if it's none of the obove types it's PHP_CODE code:
6681 if ($type == '') {
6682 $type = 'PHP_CODE';
6683 $phpCode = $rightOperand;
6684 }
6685
6686 } elseif ($leftOperand == 'condition') {
6687 $type = '';
6688 $condition = $rightOperand;
6689 } else {
6690 return RSErrorManager::raiseRSError($rsdEngineDBTable->name, $rsdEngineColumn->name, "RSDEngineEditLiveUserAreaOption::factory", "The left operand must be 'rightId' or 'condition' not '$leftOperand' in the option '$option'.", RSERROR_FATAL_ERROR);
6691 }
6692
6693
6694 if (isset($containers[$operation])) {
6695 $operations = $containers[$operation];
6696 } else {
6697 $operations = array($operation);
6698 }
6699
6700 $editLiveUserAreaOptions = array();
6701 while (list($key, $operation) = each($operations)) {
6702
6703 //crate RSDEngineLiveUserArea instance
6704 $editLiveUserAreaOption =& new RSDEngineEditLiveUserAreaOption(
6705 array(
6706 'operation' => $operation,
6707 'leftOperand' => $leftOperand,
6708 'rightOperand' => $rightOperand,
6709 'type' => $type,
6710 'tableName' => $tableName,
6711 'columnName' => $columnName,
6712 'query' => $query,
6713 'selectIncludingMethodName' => $selectIncludingMethodName,
6714 'phpCode' => $phpCode,
6715 'condition' => $condition,
6716 'definition' => $option
6717 )
6718 );
6719
6720 //logging
6721 $rsdEngineDBTable->rsdEngineDB->config['rsdEngine']->logInfo(' - ' . $editLiveUserAreaOption->toString());
6722 $editLiveUserAreaOptions[] =& $editLiveUserAreaOption;
6723 }
6724 return $editLiveUserAreaOptions;
6725 }
6726
6727 /**Return a literal representation of this instance.
6728 * @return String
6729 */
6730 function toString()
6731 {
6732 $ret = "LiveUserAreaOption:$this->operation: type=$this->type; ";
6733 $type = $this->type;
6734 switch ($type) {
6735 case 'column':
6736 $ret .= "columnName=$this->columnName";
6737 break;
6738 case 'table.column':
6739 $ret .= "tableName=$this->tableName; columnName=$this->columnName";
6740 break;
6741 case 'SQL_QUERY':
6742 $ret .= "query=$this->query";
6743 break;
6744 case 'PHP_CODE':
6745 if ($this->condition) {
6746 $ret .= "condition=$this->condition";
6747 } else {
6748 $ret .= "phpCode=$this->phpCode";
6749 }
6750 break;
6751 default:
6752 $ret .= 'UNKNOWN TYPE';
6753 break;
6754 }
6755 return $ret;
6756 }
6757 }
6758
6759
6760 /**An instance of this class is created for every editLiveUserGroup option.
6761 * The option is of the following format: editLiveUserGroup[:$OPERATION][:[rightId=$RIGHT_ID]|[condition=PHP_CODE]]
6762 * Or to be mor specific: editLiveUserGroup[:addUser|removeUser|activate|deactivate|updateNameAndComment|all][[:rightId=column|table.column|SQL_QUERY|PHP_CODE]|condition=PHP_CODE
6763 *
6764 * @author Lukas Feiler <lukas.feiler@chello.at>
6765 * @version 0.1.9
6766 * @copyright Lukas Feiler 2003
6767 * @package RSDEngine
6768 * @access public
6769 */
6770 class RSDEngineEditLiveUserGroupOption {
6771
6772 /**The RSDEngineDBTable instance that created this instance.
6773 * @var RSDEngineDBTable
6774 */
6775 var $rsdEngineDBTable = null;
6776
6777 /**The column for which this option was set.
6778 * @var RSDEngineColumn
6779 */
6780 var $rsdEngineColumn = null;
6781
6782 /**The name of the operation.
6783 * Valid values are the following:
6784 * 'all', 'userRight', 'groupRight', 'grantRight', 'revokeRight', 'grantUserRight', 'revokeUserRight', 'grantGroupRight', 'revokeGroupRight'
6785 * @see $_possibleOperations
6786 * @var String
6787 */
6788 var $operation = '';
6789
6790 var $leftOperand = '';
6791
6792 var $rightOperand = '';
6793
6794 var $type = '';
6795
6796 var $tableName = '';
6797
6798 var $columnName = '';
6799
6800 var $query = '';
6801
6802 var $selectIncludingMethod = '';
6803
6804 var $phpCode = '';
6805
6806 var $condition = '';
6807
6808 function RSDEngineEditLiveUserGroupOption($options)
6809 {
6810 reset($options);
6811 while (list($key, $value) = each($options)) {
6812 if (isset($this->$key)) {
6813 $this->$key =& $options[$key];
6814 }
6815 }
6816 }
6817
6818 function &factory(&$rsdEngineDBTable, &$rsdEngineColumn, $option)
6819 {
6820 $containers = array(
6821 'all' => array('addUser', 'removeUser', 'activate', 'deactivate', 'updateNameAndComment')
6822 );
6823 $possibleOperations = array('addUser', 'removeUser', 'activate', 'deactivate', 'updateNameAndComment', 'all');
6824
6825 $operation = '';
6826 $leftOperand = '';
6827 $rightOperand = '';
6828 $type = '';
6829 $tableName = '';
6830 $columnName = '';
6831 $query = '';
6832 $selectIncludingMethodName = '';
6833 $phpCode = '';
6834 $condition = '';
6835 $recordCondition = '';
6836
6837 //format: /**editLiveUserGroup:rightId=$RIGHT_ID|condition=PHP_CODE**/
6838 //no operation specified: operation is set to 'all'
6839 preg_match("/\/\*\*editLiveUserGroup:(rightId|condition)=([^*]*)\*\*\//", $option, $matches);
6840 if (count($matches) !== 0) {
6841 $operation = 'all';
6842 $leftOperand = $matches[1];
6843 $rightOperand = $matches[2];
6844 } else {
6845 //format: /**editLiveUserGroup:$OPERATION:rightId=$RIGHT_ID|condition=PHP_CODE**/
6846 //everything is specified
6847 preg_match("/\/\*\*editLiveUserGroup:([^:]*):(rightId|condition)=([^*]*)\*\*\//", $option, $matches);
6848 if (count($matches) !== 0) {
6849 $operation = $matches[1];
6850 $leftOperand = $matches[2];
6851 $rightOperand = $matches[3];
6852 } else {
6853 //format: /**editLiveUserGroup:$OPERATION**/
6854 //no leftOperand and rightOperand specified: leftOperand is set to 'rightId', rightOperand to $rsdEngineColumn->name
6855 preg_match("/\/\*\*editLiveUserGroup:(addUser|removeUser|activate|deactivate|updateNameAndComment|all)\*\*\//", $option, $matches);
6856 if (count($matches) !== 0) {
6857 $operation = $matches[1];
6858 $leftOperand = 'condition';
6859 $rightOperand = "in_array(\$record['$rsdEngineColumn->name'], \$this->app->liveUser->_perm->getGroupIds())";
6860 } else {
6861 //format: /**editLiveUserGroup**/
6862 //no operation, no leftOperand and no rightOperand specified: operation is set to all, leftOperand is set to 'rightId', rightOperand to $rsdEngineColumn->name
6863 preg_match("/\/\*\*editLiveUserGroup\*\*\//", $option, $matches);
6864 if (count($matches) !== 0) {
6865 $operation = 'all';
6866 $leftOperand = 'condition';
6867 $rightOperand = "in_array(\$record['$rsdEngineColumn->name'], \$this->app->liveUser->_perm->getGroupIds())";
6868 } else {
6869 return RSErrorManager::raiseRSError($rsdEngineDBTable->name, $rsdEngineColumn->name, "RSDEngineEditLiveUserGroupOption::factory", "Wrong format of the option '$option'.", RSERROR_FATAL_ERROR);
6870 }
6871 }
6872 }
6873 }
6874
6875 if (!in_array($operation, $possibleOperations)) {
6876 return RSErrorManager::raiseRSError($rsdEngineDBTable->name, $rsdEngineColumn->name, "RSDEngineEditLiveUserGroupOption::factory", "No such operation '$operation' in option '$option'.", RSERROR_FATAL_ERROR);
6877 }
6878
6879 if ($leftOperand == 'rightId') {
6880
6881 //type == 'column' ?
6882 preg_match('/([a-z0-9_]*)/', $rightOperand, $matches);
6883 if (isset($matches[1]) && $matches[1] == $rightOperand) {
6884 $type = 'column';
6885 $columnName = $rightOperand;
6886
6887 if (!$rsdEngineDBTable->columnExists($columnName)) {
6888 return RSErrorManager::raiseRSError($rsdEngineDBTable->name, $rsdEngineColumn->name, "RSDEngineEditLiveUserGroupOption::factory", "The column '$columnName' used in the following option does not exist: '$option'.", RSERROR_FATAL_ERROR);
6889 }
6890 }
6891
6892 //type == 'table.column' ?
6893 preg_match('/([a-z0-9_]*)\.([a-z0-9_]*)/', $rightOperand, $matches);
6894 if (isset($matches[1]) && isset($matches[2]) && ($matches[1] . '.' . $matches[2]) == $rightOperand) {
6895 $type = 'table.column';
6896 $tableName = $matches[1];
6897 $columnName = $matches[2];
6898
6899 if (!$rsdEngineDBTable->rsdEngineDB->tableExists($tableName)) {
6900 return RSErrorManager::raiseRSError($rsdEngineDBTable->name, $rsdEngineColumn->name, "RSDEngineEditLiveUserGroupOption::factory", "The table '$tableName' used in the following option does not exist: '$option'.", RSERROR_FATAL_ERROR);
6901 }
6902 $table =& $rsdEngineDBTable->rsdEngineDB->getTable($tableName);
6903 if (!$table->columnExists($columnName)) {
6904 return RSErrorManager::raiseRSError($rsdEngineDBTable->name, $rsdEngineColumn->name, "RSDEngineEditLiveUserGroupOption::factory", "The column '$columnName' used in the following option does not exist: '$option'.", RSERROR_FATAL_ERROR);
6905 }
6906 }
6907
6908 //type == 'SQL_QUERY' ?
6909 preg_match('/(SELECT\ [^:]*\ FROM\ [^:]*)/i', $rightOperand, $matches);
6910 if (isset($matches[1]) && $matches[1] == $rightOperand) {
6911 $type = 'SQL_QUERY';
6912 $query = $rightOperand;
6913 }
6914
6915 //if it's none of the obove types it's PHP_CODE code:
6916 if ($type == '') {
6917 $type = 'PHP_CODE';
6918 $phpCode = $rightOperand;
6919 }
6920
6921 } elseif ($leftOperand == 'condition') {
6922 $type = '';
6923 $condition = $rightOperand;
6924 } else {
6925 return RSErrorManager::raiseRSError($rsdEngineDBTable->name, $rsdEngineColumn->name, "RSDEngineEditLiveUserGroupOption::factory", "The left operand must be 'rightId' or 'condition' not '$leftOperand' in the option '$option'.", RSERROR_FATAL_ERROR);
6926 }
6927
6928
6929 if (isset($containers[$operation])) {
6930 $operations = $containers[$operation];
6931 } else {
6932 $operations = array($operation);
6933 }
6934
6935 $editLiveUserGroupOptions = array();
6936 while (list($key, $operation) = each($operations)) {
6937
6938 //crate RSDEngineLiveUserGroup instance
6939 $editLiveUserGroupOption =& new RSDEngineEditLiveUserGroupOption(
6940 array(
6941 'operation' => $operation,
6942 'leftOperand' => $leftOperand,
6943 'rightOperand' => $rightOperand,
6944 'type' => $type,
6945 'tableName' => $tableName,
6946 'columnName' => $columnName,
6947 'query' => $query,
6948 'selectIncludingMethodName' => $selectIncludingMethodName,
6949 'phpCode' => $phpCode,
6950 'condition' => $condition,
6951 'definition' => $option
6952 )
6953 );
6954
6955 //logging
6956 $rsdEngineDBTable->rsdEngineDB->config['rsdEngine']->logInfo(' - ' . $editLiveUserGroupOption->toString());
6957 $editLiveUserGroupOptions[] =& $editLiveUserGroupOption;
6958 }
6959 return $editLiveUserGroupOptions;
6960 }
6961
6962 /**Return a literal representation of this instance.
6963 * @return String
6964 */
6965 function toString()
6966 {
6967 $ret = "LiveUserGroupOption:$this->operation: type=$this->type; ";
6968 $type = $this->type;
6969 switch ($type) {
6970 case 'column':
6971 $ret .= "columnName=$this->columnName";
6972 break;
6973 case 'table.column':
6974 $ret .= "tableName=$this->tableName; columnName=$this->columnName";
6975 break;
6976 case 'SQL_QUERY':
6977 $ret .= "query=$this->query";
6978 break;
6979 case 'PHP_CODE':
6980 if ($this->condition) {
6981 $ret .= "condition=$this->condition";
6982 } else {
6983 $ret .= "phpCode=$this->phpCode";
6984 }
6985 break;
6986 default:
6987 $ret .= 'UNKNOWN TYPE';
6988 break;
6989 }
6990 return $ret;
6991 }
6992 }
6993 ?>

Documentation generated on Mon, 8 Dec 2003 13:12:15 +0100 by phpDocumentor 1.2.3