Documentation is available at RSDEngineDBApplicationBaseClass.php
1 <?php
2 // RSDEngine: The Rapid and Secure Development Engine
3 // Copyright (C) 2003 Lukas Feiler
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 /**Contains just the class RSDEngineDBApplicationBaseClass.
20 *
21 * @package RSDEngine
22 * @author Lukas Feiler <lukas.feiler@chello.at>
23 * @copyright Lukas Feiler 2003
24 * @filesource
25 */
26
27 /**RSDEngineDBApplicationBaseClass extends RSDEngineClass.
28 */
29 require_once('RSDEngine/RSDEngineClass.php');
30
31
32 /**Generates the application base class (the main class) for database backended applications.
33 *
34 * @author Lukas Feiler <lukas.feiler@chello.at>
35 * @version 0.1.9
36 * @copyright Lukas Feiler 2003
37 * @package RSDEngine
38 */
39 class RSDEngineDBApplicationBaseClass extends RSDEngineClass{
40
41 /**Returns the class name.
42 *
43 * In fact ucfirst($this->config['projectName']) . 'Base' is returned.
44 * @see config
45 *
46 * @return String The class name.
47 */
48 function getClassName()
49 {
50 return ucfirst($this->config['projectName']) . 'Base';
51 }
52
53 /**Returns the child class name.
54 *
55 * In fact ucfirst($this->config['projectName']) is returned.
56 * @see config
57 *
58 * @return String The child class name.
59 */
60 function getChildClassName()
61 {
62 return ucfirst($this->config['projectName']);
63 }
64
65 /**Returns the name for an instance created from this class.
66 *
67 * In fact strtolower($this->config['projectName']) is returned.
68 * @see config
69 *
70 * @return String The instance name.
71 */
72 function getInstanceName()
73 {
74 return strtolower($this->config['projectName']) . 'Base';
75 }
76
77 /**Returns the code for this class.
78 *
79 * The generated class will be extending RSDApplication.
80 * Note that this method requires $this->config to be correctly
81 * filled with all configuration options of the RSDEngine.
82 * @see config
83 * @see RSDApplication
84 *
85 * @return String The code of the appplication class.
86 */
87 function getCode()
88 {
89 extract($this->config);
90 $className = $this->getClassName();
91 $childClassName = $this->getChildClassName();
92 $instanceName = $this->getInstanceName();
93 $childClassInstanceName = strtolower($projectName);
94 $authors = RSArrayUtil::toString(split("\n",$authors),"\n",'* @author %val');
95 $projectNameUC = strtoupper($projectName);
96 $projectNameLC = strtolower($projectName);
97
98 $write = $this->config['writeApplicationBaseClass'];
99 $this->setWrite($write);
100
101 if ($webApplication) {
102 $smartyClassName = ucfirst($projectName) . 'Smarty';
103 $smartyFilename = "${smartyClassName}.php";
104 }
105
106 $parentClass = 'RSDApplication';
107 if ($liveUser) {
108 $parentClass = 'RSDLiveUserApplication';
109 }
110 $data = "";
111 $data.= '/' . "**Contains just the class $className.\n" .
112 "*\n" .
113 $authors . "\n" .
114 '* @copyright ' . $copyright . "\n" .
115 '* @package ' . $projectName . "\n" .
116 '* @filesource' . "\n" .
117 '*/' . "\n" .
118 "\n" .
119 '/' . '**' . $className . " extends $parentClass contained in $parentClass.php.\n" .
120 "*/\n" .
121 "require_once('RSDEngine/$parentClass.php');\n" .
122 "\n" .
123 '/' . "**PEAR::DB is needed for databases access and abstraction!\n" .
124 "*/\n" .
125 "require_once('DB.php');\n" .
126 "\n";
127 if ($auth) {
128 $data .='/' . "**PEAR::Auth is needed for authentication!\n" .
129 "*/\n" .
130 "require_once('Auth/Auth.php');\n" .
131 "\n";
132 }
133 if ($liveUser) {
134 $data .= <<<END
135 /**PEAR::LiveUser is needed for authentication & authorization!
136 */
137 require_once('LiveUser/LiveUser.php');
138 END;;; }
139
140 if ($webApplication) {
141 $data .="\n" .
142 "\n" .
143 '/' . "**Smarty is the template engine we use!\n" .
144 "*/\n" .
145 "require_once('$smartyFilename');\n" .
146 "\n";
147 }
148 $data .='/' . "**This global variable will hold a handle to the instance created of the class $className (which is the superclass of $childClassName).\n" .
149 "* The handle is assigned inside the constructor method to allow regular functions access the new instance.\n" .
150 "*/\n" .
151 "\$GLOBALS['${childClassInstanceName}Instance'] = null;\n" .
152 "\n" .
153 '/' . '**' . $className . ' is the main class of this application.' . "\n" .
154 '*' . "\n" .
155 '* It holds handles to all objects used in this application.' . "\n" .
156 '* It can be used as the only entry point to the whole application!' . "\n" .
157 $authors . "\n" .
158 '* @copyright ' . $copyright . "\n" .
159 '* @package ' . $projectName . "\n" .
160 '* @version 0.1' . "\n" .
161 '*/' . "\n" .
162 "class $className extends $parentClass {\n" .
163 "\n";
164 $data .=' /' . '**Initializes the application.' . "\n" .
165 ' * @param RSErrorManager $errorManager An instance of the class RSErrorManager.' . "\n" .
166 " */\n";
167
168 $data .=" function $className(&\$errorManager)\n" .
169 " {\n" .
170 " \n" .
171 " //to allow regular functions access the new instance\n" .
172 " \$GLOBALS['${childClassInstanceName}Instance'] =& \$this;\n" .
173 " \n" .
174 " //Set up the DSN\n" .
175 ' $this->dsn = $this->setUpDSN();' . "\n" .
176 " \n" .
177 " //Call parent constructor.\n" .
178 ' $this->RSDApplication($this->setUpDB(), $errorManager);' . "\n" .
179 "\n";
180 if ($webApplication) {
181 $data .=" //Set up Smarty.\n" .
182 " \$this->smarty =& \$this->setUpSmarty();\n" .
183 "\n";
184 }
185 if ($auth) {
186 $data .=" //Set up the Authentication System.\n" .
187 " \$this->auth =& \$this->setUpAuth();\n" .
188 " if (!defined('${projectNameUC}_LIVEUSER_FORCE_AUTHENTICATION') || ${projectNameUC}_LIVEUSER_FORCE_AUTHENTICATION == true) {\n" .
189 " \$this->auth->start();\n" .
190 " }\n" .
191 " \$this->user = \$_SESSION['${projectNameLC}CurrentUser'];\n" .
192 " \n" .
193 "\n";
194 }
195 if ($liveUser) {
196 $data .=" //Set up the Authentication and Authorization System.\n" .
197 " \$this->liveUser =& \$this->setUpLiveUser();\n" .
198 "\n";
199 }
200 $data .=' }' . "\n" .
201 "\n" .
202 " /" . "**Set up the DSN.\n" .
203 " * @return String The DSN\n" .
204 " */\n" .
205 " function setUpDSN()\n" .
206 " {\n" .
207 " //Construct the DSN.\n" .
208 " \$type = ${projectNameUC}_DB_TYPE;\n" .
209 " \$user = ${projectNameUC}_DB_USERNAME;\n" .
210 " \$pass = ${projectNameUC}_DB_PASSWORD;\n" .
211 " \$host = ${projectNameUC}_DB_HOST;\n" .
212 " \$dbName = ${projectNameUC}_DB_NAME;\n" .
213 ' $dsn = "$type://$user:$pass@$host/$dbName";' . "\n" .
214 " return \$dsn;\n" .
215 " }\n" .
216 "\n" .
217 " /" . "**Set up PEAR::DB.\n" .
218 " * @return mixed a newly created DB connection object, or a DB error object on error\n" .
219 " */\n" .
220 " function &setUpDB()\n" .
221 " {\n" .
222 " //Connect to datatabase\n" .
223 ' $db =& DB::connect($this->dsn, true);' . "\n" .
224 ' return $db;' . "\n" .
225 " }\n" .
226 "\n";
227
228 if ($webApplication) {
229 $data .=" /" . "**Set up Smarty.\n" .
230 " * @return $smartyClassName A new instance of $smartyClassName\n" .
231 " */\n" .
232 " function &setUpSmarty()\n" .
233 " {\n" .
234 " return new $smartyClassName();\n" .
235 " }\n" .
236 "\n";
237 }
238 if ($auth) {
239 $data .=" /" . "**Set up the PEAR::Auth.\n" .
240 " * @return Auth A new instanc of PEAR::Auth.\n" .
241 " */\n" .
242 " function &setUpAuth()\n" .
243 " {\n" .
244 ' $authParams = array(' . "\n" .
245 " 'dsn' => \$this->dsn,\n" .
246 " 'table' => ${projectNameUC}_AUTH_TABLE,\n" .
247 " 'usernamecol' => ${projectNameUC}_AUTH_USERNAME_COLUMN,\n" .
248 " 'passwordcol' => ${projectNameUC}_AUTH_PASSWORD_COLUMN,\n" .
249 " 'activatedcol' => ${projectNameUC}_AUTH_ACTIVATED_COLUMN,\n" .
250 " 'cryptType' => ${projectNameUC}_AUTH_CRYPTTYPE,\n" .
251 " 'persistent' => true\n" .
252 " );\n" .
253 " \$auth =& new Auth('RSDB', \$authParams, '${childClassInstanceName}LoginFunction');" . "\n" .
254 " \n" .
255 ' /' . '**You have to use setSessionname(), if you are running two or more different' . "\n" .
256 ' * applications with Auth on the same domain. If you don\'t use this function, a user' . "\n" .
257 ' * who has once logged in at one of the applications can also use the other' . "\n" .
258 ' * applications without logging in again!' . "\n" .
259 ' */' . "\n" .
260 " \$auth->setSessionname(${projectNameUC}_AUTH_SESSION_NAME);\n" .
261 " \n" .
262 ' /' . '**Sets the maximum time a session can be idle (in seconds). From a security and' . "\n" .
263 ' * performance standpoint of view it is highly recommended to use this method and set it' . "\n" .
264 ' * to < half an hour (1800).' . "\n" .
265 ' */' . "\n" .
266 " \$auth->setIdle(${projectNameUC}_AUTH_SESSION_TIMEOUT);\n" .
267 " \n" .
268 ' /' . '**Sets the login callback function.' . "\n" .
269 ' */' . "\n" .
270 " \$auth->setLoginCallback(array(&\$this, 'loginCallback'));\n" .
271 " \n" .
272 ' /' . '**Sets the logout callback function.' . "\n" .
273 ' */' . "\n" .
274 " \$auth->setLogoutCallback('${childClassInstanceName}LogoutFunction');\n" .
275 " \n" .
276 " return \$auth;\n" .
277 " }\n" .
278 "\n" .
279 ' /' . '**Outputs the login page.' . "\n" .
280 ' */' . "\n" .
281 ' function loginPage()' . "\n" .
282 " {\n" .
283 ' switch ($this->auth->getStatus()) {' . "\n" .
284 ' case AUTH_WRONG_LOGIN:' . "\n" .
285 ' $msg = "Wrong Login!";' . "\n" .
286 ' break;' . "\n" .
287 ' case AUTH_EXPIRED:' . "\n" .
288 ' $msg = "Your session expired.";' . "\n" .
289 ' break;' . "\n" .
290 ' case AUTH_IDLED:' . "\n" .
291 ' $msg = "Your session was too long idle.";' . "\n" .
292 ' break;' . "\n" .
293 ' default:' . "\n" .
294 ' $msg = "Please log in.";' . "\n" .
295 ' }' . "\n" .
296 ' ?>' . "\n" .
297 ' <form method="post">' . "\n" .
298 ' <input type="text" name="username">' . "\n" .
299 ' <input type="password" name="password">' . "\n" .
300 ' <input type="submit">' . "\n" .
301 ' </form>' . "\n" .
302 ' <br><?=$msg?>' . "\n" .
303 ' <?php' . "\n" .
304 " exit;\n" .
305 ' }' . "\n" .
306 "\n" .
307 ' /' . '**Performs a logout by calling $this->auth->logout().' . "\n" .
308 ' */' . "\n" .
309 ' function logout()' . "\n" .
310 " {\n" .
311 ' $this->auth->logout();' . "\n" .
312 ' }' . "\n" .
313 "\n" .
314 ' /' . '**Gets triggerd after logout.' . "\n" .
315 ' */' . "\n" .
316 ' function logoutCallback()' . "\n" .
317 " {\n" .
318 " header('Location: ' . ${projectNameUC}_AUTH_LOGOUT_URL);\n" .
319 ' }' . "\n" .
320 "\n" .
321 ' /' . '**Gets triggerd after login.' . "\n" .
322 ' */' . "\n" .
323 ' function loginCallback($username)' . "\n" .
324 " {\n" .
325 " \n";
326 $authRSDTable =& $rsdEngineDB->getTable($authTable);
327 $authUsernameRSDColumn = $authRSDTable->getColumn($authUsernameColumn);
328 $authTableInstanceName = $authRSDTable->getChildClassInstanceName();
329 $getByUsernameMethod = "getBy" . $authUsernameRSDColumn->getColumnNameForPartialMethodName();
330
331 $data .=" \$$authTableInstanceName =& \$this->getTable('$authTable');\n" .
332 " \$_SESSION['${projectNameLC}CurrentUser'] = \$${authTableInstanceName}->$getByUsernameMethod(\$username);\n" .
333 "\n" .
334 ' /**when reloading a page right after loging in,' . "\n" .
335 ' * the browerser wont ask any more for reposting any data.' . "\n" .
336 ' */' . "\n" .
337 " header('Location: ' . \$_SERVER['PHP_SELF']);\n" .
338 ' }' . "\n" .
339 "\n";
340 }
341
342 if ($liveUser) {
343 $data .= <<<END
344 /**Set up the PEAR::LiveUser.
345 * @return LiveUser A new instanc of PEAR::LiveUser.
346 */
347 function &setUpLiveUser()
348 {
349 \$options = array();
350 \$options['autoInit'] = true;
351 \$options['session'] = array(
352 'name' => ${projectNameUC}_LIVEUSER_SESSION_NAME,
353 'varname' => 'ludata'
354 );
355 \$options['login'] = array(
356 'method' => ${projectNameUC}_LIVEUSER_LOGIN_SUBMIT_METHOD,
357 'username' => 'username',
358 'password' => 'password',
359 'force' => !defined('${projectNameUC}_LIVEUSER_FORCE_AUTHENTICATION') || ${projectNameUC}_LIVEUSER_FORCE_AUTHENTICATION == true,
360 'function' => '${childClassInstanceName}LoginFunction',
361 'remember' => 'rememberMe'
362 );
363 \$options['logout'] = array(
364 'trigger' => 'logout',
365 'redirect' => ${projectNameUC}_LIVEUSER_LOGOUT_REDIRECT_URL,
366 'destroy' => ${projectNameUC}_LIVEUSER_DESTROY_SESSION_ON_LOGOUT,
367 'function' => '${childClassInstanceName}LogoutFunction'
368 );
369 \$options['authContainers'] = array(
370 array(
371 'type' => 'DB',
372 'connection' => \$this->db,
373 'loginTimeout' => ${projectNameUC}_LIVEUSER_AUTH_LOGIN_TIMEOUT,
374 'expireTime' => ${projectNameUC}_LIVEUSER_AUTH_EXPIRE_TIME,
375 'idleTime' => ${projectNameUC}_LIVEUSER_AUTH_IDLE_TIME,
376 'allowDuplicateHandles' => ${projectNameUC}_LIVEUSER_AUTH_ALLOW_DUPLICATE_HANDLES,
377 'passwordEncryptionMode' => ${projectNameUC}_LIVEUSER_AUTH_PASSWORD_ENCRYPTION_MODE,
378 'authTable' => ${projectNameUC}_LIVEUSER_AUTH_TABLE,
379 'authTableCols' => array(
380 'userId' => ${projectNameUC}_LIVEUSER_AUTH_TABLE_COLUMN_USERID,
381 'handle' => ${projectNameUC}_LIVEUSER_AUTH_TABLE_COLUMN_HANDLE,
382 'passwd' => ${projectNameUC}_LIVEUSER_AUTH_TABLE_COLUMN_PASSWORD,
383 'lastLogin' => ${projectNameUC}_LIVEUSER_AUTH_TABLE_COLUMN_LAST_LOGIN,
384 'isActive' => ${projectNameUC}_LIVEUSER_AUTH_TABLE_COLUMN_IS_ACTIVE
385 )
386 )
387 );
388 \$options['permContainer'] = array(
389 'type' => ${projectNameUC}_LIVEUSER_PERM_TYPE,
390 'connection' => \$this->db,
391 'prefix' => ${projectNameUC}_LIVEUSER_PERM_TABLE_PREFIX
392 );
393
394 if (${projectNameUC}_LIVEUSER_REMEMBER_ME) {
395 \$options['cookie'] = array(
396 'name' => ${projectNameUC}_LIVEUSER_REMEMBER_ME_COOKIE_NAME,
397 'lifetime' => ${projectNameUC}_LIVEUSER_REMEMBER_ME_COOKIE_LIFETIME,
398 'domain' => ${projectNameUC}_LIVEUSER_REMEMBER_ME_COOKIE_DOMAIN,
399 'path' => ${projectNameUC}_LIVEUSER_REMEMBER_ME_COOKIE_PATH,
400 'secret' => ${projectNameUC}_LIVEUSER_REMEMBER_ME_COOKIE_SECRET_KEY
401 );
402 }
403
404 //the LiveUser admin classes will need these options later
405 \$this->setLiveUserOptions(\$options);
406
407 \$liveUser =& LiveUser::factory(\$options);
408
409 if (${projectNameUC}_LIVEUSER_REFRESH_RIGHTS) {
410 \$liveUser->_perm->readRights();
411 }
412
413 return \$liveUser;
414 }
415
416 /**Set up the LiveUser permission admin class.
417 * @see ${projectNameUC}_LIVEUSER_PERM_ADMIN_CLASS
418 *
419 * @return mixed A newly created instance of the specified perm admin class
420 * with \$this->db and and the return value of \$this->getLiveUserOptions()
421 * passed as constructor argument.
422 */
423 function &setUpLiveUserPermAdmin()
424 {
425 \$classFile = ${projectNameUC}_LIVEUSER_PERM_ADMIN_FILE;
426 \$fp = @fopen(\$classFile, "r", true);
427 if (\$fp === false) {
428 return \$this->raiseError("The LiveUser perm admin class file \$classFile could not be found.", RSERROR_FATAL_ERROR);
429 }
430 fclose(\$fp);
431 require_once(${projectNameUC}_LIVEUSER_PERM_ADMIN_FILE);
432
433 \$className = ${projectNameUC}_LIVEUSER_PERM_ADMIN_CLASS;
434 if (!class_exists(\$className)) {
435 return \$this->raiseError("The LiveUser perm admin class \$className could not be found.", RSERROR_FATAL_ERROR);
436 }
437 \$connectionOptions = array();
438 \$connectionOptions['connection'] =& \$this->db;
439 \$liveUserPermAdmin =& new \$className(\$connectionOptions, \$this->getLiveUserOptions());
440 return \$liveUserPermAdmin;
441 }
442
443 /**Set up the LiveUser authentication admin class.
444 * @see ${projectNameUC}_LIVEUSER_AUTH_ADMIN_CLASS
445 *
446 * @return mixed A newly created instance of the specified auth admin class
447 * with \$this->db and and the return value of \$this->getLiveUserOptions()
448 * passed as constructor argument.
449 */
450 function &setUpLiveUserAuthAdmin()
451 {
452 require_once(${projectNameUC}_LIVEUSER_AUTH_ADMIN_FILE);
453 \$className = ${projectNameUC}_LIVEUSER_AUTH_ADMIN_CLASS;
454 if (!class_exists(\$className)) {
455 return \$this->raiseError("The LiveUser auth admin class \$className could not be found.", RSERROR_FATAL_ERROR);
456 }
457 \$options = \$this->getLiveUserOptions();
458 \$authContinerConfig =& \$options['authContainers'][0];
459 \$connectionOptions = array();
460 \$connectionOptions['connection'] =& \$this->db;
461 \$liveUserAuthAdmin =& new \$className(\$connectionOptions, \$authContinerConfig);
462 return \$liveUserAuthAdmin;
463 }
464
465
466 END;;; $data .=' function loginPage($liveUserObj = false)' . "\n" .
467 " {\n" .
468 ' $msg = "Please log in.";' . "\n" .
469 ' if (is_object($liveUserObj)) {' . "\n" .
470 ' if ($liveUserObj->status) {' . "\n" .
471 ' switch ($this->auth->getStatus()) {' . "\n" .
472 ' case LIVEUSER_AUTH_ISINACTIVE:' . "\n" .
473 ' $msg = "Your account has been deactivated!";' . "\n" .
474 ' break;' . "\n" .
475 ' case LIVEUSER_AUTH_IDLED:' . "\n" .
476 ' $msg = "Your session was too long idle.";' . "\n" .
477 ' break;' . "\n" .
478 ' case LIVEUSER_AUTH_EXPIRED:' . "\n" .
479 ' $msg = "Your session expired.";' . "\n" .
480 ' break;' . "\n" .
481 ' default:' . "\n" .
482 ' $msg = "Wrong username or password.";' . "\n" .
483 ' }' . "\n" .
484 ' }' . "\n" .
485 ' }' . "\n" .
486 ' ?>' . "\n" .
487 ' <form method="post">' . "\n" .
488 ' <input type="text" name="username">' . "\n" .
489 ' <input type="password" name="password">' . "\n" .
490 ' <input type="submit">' . "\n" .
491 ' </form>' . "\n" .
492 ' <br><?=$msg?>' . "\n" .
493 ' <?php' . "\n" .
494 " exit;\n" .
495 ' }' . "\n" .
496 "\n" .
497 ' /' . '**Performs a logout by forwarding to logout.php?logout=1.' . "\n" .
498 ' */' . "\n" .
499 ' function logout()' . "\n" .
500 " {\n" .
501 ' header("Location: logout.php?logout=1");' . "\n" .
502 ' exit;' . "\n" .
503 ' }' . "\n" .
504 "\n" .
505 ' /' . '**Gets triggerd after logout.' . "\n" .
506 ' */' . "\n" .
507 ' function logoutCallback()' . "\n" .
508 " {\n" .
509 " //does nothing for now\n" .
510 ' }' . "\n" .
511 "\n";
512 }
513 if ($mail) {
514 $data .=' /' . "**Sends an email.\n" .
515 " * @param mixed \$recipients An array or a string with comma separated recipients.\n" .
516 " * @param array \$headers An associative array of headers. The header name is used\n" .
517 " as key and the header value as value.\n" .
518 " * @param String \$body The body of the email.\n" .
519 " */\n" .
520 ' function sendMail($recipients, $headers, $body)' . "\n" .
521 " {\n" .
522 ' if (!is_object($this->_mail)) {' . "\n" .
523 " require_once('Mail.php');\n";
524 if ($mailType == 'sendmail') {
525 $data .=' $params = array(' . "\n" .
526 " 'sendmail_path' => ${projectNameUC}_MAIL_SENDMAIL_PATH,\n" .
527 " 'sendmail_args' => ${projectNameUC}_MAIL_SENDMAIL_ARGS\n" .
528 ' );' . "\n";
529 } elseif ($mailType == 'smtp') {
530 $data .=' $params = array(' . "\n" .
531 " 'host' => ${projectNameUC}_MAIL_SMTP_HOST,\n" .
532 " 'port' => ${projectNameUC}_MAIL_SMTP_PORT,\n" .
533 " 'auth' => ${projectNameUC}_MAIL_SMTP_AUTH,\n" .
534 " 'username' => ${projectNameUC}_MAIL_SMTP_USERNAME,\n" .
535 " 'password' => ${projectNameUC}_MAIL_SMTP_PASSWORD\n" .
536 ' );' . "\n";
537 } elseif ($mailType == 'mail') {
538 $data .=' $params = array();' . "\n";
539 }
540 $data .=" \$this->_mail =& Mail::factory(${projectNameUC}_MAIL_TYPE, \$params);\n" .
541 " }\n" .
542 " if (\$headers['From'] == '') {\n" .
543 " \$headers['From'] = ${projectNameUC}_MAIL_DEFAULT_SENDER;\n" .
544 " }\n" .
545 ' $this->_mail->send($recipients, $headers, $body);' . "\n" .
546 ' }' . "\n";
547
548 }
549 $data .="\n" .
550 ' /' . "**Returns the RSDTable object.\n" .
551 " * @param String \$tableName The name of the table.\n" .
552 " */\n" .
553 ' function &getTable($tableName)' . "\n" .
554 " {\n" .
555 ' if (!isset($this->_tables[$tableName])) {' . "\n" .
556 ' $tableNameWithoutPrefix = $tableName;' . "\n";
557 if ($tablePrefix) {
558 $data .= " \$tableNameWithoutPrefix = preg_replace('/^$tablePrefix/i','', \$tableNameWithoutPrefix);\n";
559 }
560 $data .=" \$className = '" . ucfirst($projectName) . "' . ucfirst(\$tableNameWithoutPrefix);\n" .
561 ' if (!class_exists($className)) {' . "\n" .
562 ' if (($fp = @fopen("$className.php", "r", true)) !== false) {' . "\n" .
563 ' fclose($fp);' . "\n" .
564 ' require_once("$className.php");' . "\n" .
565 ' }' . "\n" .
566 ' }' . "\n" .
567 ' if (class_exists($className)) {' . "\n" .
568 ' new $className($this->db, $this);' . "\n" .
569 ' } else {' . "\n" .
570 ' $this->raiseError("No class could be found for the table $tableName", RSERROR_FATAL_ERROR);' . "\n" .
571 ' }' . "\n" .
572 " }\n" .
573 ' return parent::getTable($tableName);' . "\n" .
574 " }\n";
575
576
577
578 $data .="}\n" .
579 "\n";
580
581 //procedural elements
582 if ($auth || $liveUser) {
583 $data .= <<<END
584
585 /**This function is set as callback function for generating a login form.
586 */
587 function ${childClassInstanceName}LoginFunction()
588 {
589 \$GLOBALS['${childClassInstanceName}Instance']->loginPage();
590 }
591
592 /**This function is set as callback function after a logout.
593 */
594 function ${childClassInstanceName}LogoutFunction()
595 {
596 \$GLOBALS['${childClassInstanceName}Instance']->logoutCallback();
597 }
598
599 END;;;
600
601 }
602 return $data;
603 }
604 }
605 ?>
Documentation generated on Mon, 8 Dec 2003 13:10:57 +0100 by phpDocumentor 1.2.3