[phpwebapp-commits] CVS: web_app class.WebApp.php,1.10,1.11
Brought to you by:
dashohoxha
From: Dashamir H. <das...@us...> - 2003-08-22 06:48:13
|
Update of /cvsroot/phpwebapp/web_app In directory sc8-pr-cvs1:/tmp/cvs-serv4508 Modified Files: class.WebApp.php Log Message: Index: class.WebApp.php =================================================================== RCS file: /cvsroot/phpwebapp/web_app/class.WebApp.php,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** class.WebApp.php 20 Aug 2003 07:07:56 -0000 1.10 --- class.WebApp.php 22 Aug 2003 06:48:09 -0000 1.11 *************** *** 1,3 **** --- 1,23 ---- <?php + /* + Copyright 2001,2002,2003 Dashamir Hoxha, das...@us... + + This file is part of phpWebApp. + + phpWebApp is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + phpWebApp is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with phpWebApp; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + /** * Contains some functions that are used frequently in the application. *************** *** 9,14 **** class WebApp { ! function callFreeEvent(&$event) { $file_name = "on.".$event->name.".php"; $fun_name = "on_".$event->name; --- 29,53 ---- class WebApp { ! /** ! * Returns true only the first time that the application ! * is opened, at the begining of the session. ! */ ! function first_time() ! { ! global $request; ! return $request->firstTime; ! } ! ! /** ! * A free event has target 'none', doesn't have a target webobject, ! * so no webobject can handle it. Instead, it is handled by the ! * function on_eventName($event), that is in the file 'on.eventName.php', ! * which is placed in the same folder as the target page or the source ! * page of the event. ! */ ! function callFreeEvent() { + global $event; + $file_name = "on.".$event->name.".php"; $fun_name = "on_".$event->name; *************** *** 19,23 **** if (file_exists($fname)) { ! include $fname; $fun_name($event); return; --- 58,62 ---- if (file_exists($fname)) { ! include_once $fname; $fun_name($event); return; *************** *** 29,42 **** if (file_exists($fname)) { ! include $fname; ! $fun_name($event); ! return; ! } ! ! //look for the event handler in the common path ! $fname = EVENTHANDLER_PATH.$file_name; ! if (file_exists($fname)) ! { ! include $fname; $fun_name($event); return; --- 68,72 ---- if (file_exists($fname)) { ! include_once $fname; $fun_name($event); return; *************** *** 47,52 **** } ! /*------ begin construct page functions ---------*/ ! /** constructs an HTML page which is sent directly to the browser */ function constructHtmlPage($tpl_file, $collect =false) { --- 77,87 ---- } ! /*----------- begin construct page functions --------------*/ ! ! /** ! * Constructs an HTML page which is sent directly to the browser. ! * If $collect is true, however, instead of sending the page to ! * the browser, it returns it as a big string. ! */ function constructHtmlPage($tpl_file, $collect =false) { *************** *** 93,113 **** /** ! * constructs an HTML page and returns it as a string, ! * then resumes constructing the previous page ! * (it is useful when you want to construct a page ! * for sending it by e-mail) */ function getHtmlPage($tpl_file) { ! global $webPage; //save the current webPage and whatever //is already constructed in it $old_webPage = $webPage; //create a new web page in the global variable $webPage $webPage = new WebPage; ! $collect = true; //construct it into the $html_page variable $html_page = WebApp::constructHtmlPage($tpl_file, $collect); --- 128,151 ---- /** ! * Constructs an HTML page and returns it as a string. ! * Then resumes constructing the previous page. ! * It is useful when you want to construct a page ! * for sending it by e-mail. */ function getHtmlPage($tpl_file) { ! global $webPage, $tplVars; //save the current webPage and whatever //is already constructed in it $old_webPage = $webPage; + $old_tplVars = $tplVars; //create a new web page in the global variable $webPage $webPage = new WebPage; ! $tplVars = new VarStack; ! //construct it into the $html_page variable + $collect = true; $html_page = WebApp::constructHtmlPage($tpl_file, $collect); *************** *** 115,118 **** --- 153,157 ---- //and continue with its construction $webPage = $old_webPage; + $tplVars = $old_tplVars; //return the constructed page *************** *** 121,129 **** /** ! * this function stops loading the current page ! * and starts loading and constructing the given page; ! * if no page is given, reloads the same page again */ ! function reloadPage($tpl_file=UNDEFINED) //doesn't work, see how to fix it { global $webPage; --- 160,170 ---- /** ! * This function stops loading the current page ! * and starts loading and constructing the given page. ! * If no page is given, reloads the same page again. ! * ! * @todo It doesn't work yet, see how to fix it. */ ! function reloadPage($tpl_file=UNDEFINED) { global $webPage; *************** *** 138,144 **** --- 179,191 ---- $webPage->load($tpl_file); } + /*------ end construct functions ----------------*/ /*------ begin variable functions ---------------*/ + + /** + * Add a template variable in the current scope + * (for the current webbox or template). + */ function addVar($var_name, $var_value) { *************** *** 147,150 **** --- 194,201 ---- } + /** + * Add a template variable in the global scope; + * it will be available in all the application templates. + */ function addGlobalVar($var_name, $var_value) { *************** *** 153,157 **** } ! /** declares a list of variables at once */ function addVars($arrVars) { --- 204,211 ---- } ! /** ! * Add a list (associative array) of template variables ! * at once. ! */ function addVars($arrVars) { *************** *** 160,164 **** } ! /** declares a list of variables at once */ function addGlobalVars($arrVars) { --- 214,218 ---- } ! /** Add a list of global template variables at once */ function addGlobalVars($arrVars) { *************** *** 167,171 **** } ! /** returns the value of the variable, or UNDEFINED if not found */ function getVar($var_name) { --- 221,228 ---- } ! /** ! * Returns the value of a template variable, ! * or UNDEFINED if such a variable does not exist. ! */ function getVar($var_name) { *************** *** 174,177 **** --- 231,235 ---- } + /** Add a session variable. */ function addSVar($var_name, $var_value, $db =false) { *************** *** 180,184 **** } ! /** set state variable */ function setSVar($var_name, $var_value) { --- 238,242 ---- } ! /** Set a new value to a session variable. */ function setSVar($var_name, $var_value) { *************** *** 201,205 **** } ! /** get state variable */ function getSVar($var_name) { --- 259,263 ---- } ! /** Get the value of a session variable. */ function getSVar($var_name) { *************** *** 210,215 **** /** ! * returns the web object with the given id ! * or UNDEFINED */ function getObject($obj_id) --- 268,273 ---- /** ! * Returns the web object with the given id, ! * or UNDEFINED. */ function getObject($obj_id) *************** *** 223,227 **** /*------ begin evaluate ------------------------*/ ! /** returns the value of the expression $expr */ function evaluate($expr) { --- 281,286 ---- /*------ begin evaluate ------------------------*/ ! ! /** Returns the value of the given expression. */ function evaluate($expr) { *************** *** 236,253 **** } /** ! * used by evaluate; returns an array with all the variable ! * names that are used in $expr (which will be declared as global) */ function get_var_names($expr) { - //this trick is done because ereg - //does not handle well the character '$' - $expr = str_replace("$", "###", $expr); - $var_names = array(); ! while ( ereg("###([[:alnum:]_]*)", $expr, $regs) ) { ! $var_names[] = "\$".$regs[1]; ! $expr = str_replace($regs[0], "", $expr); } return $var_names; --- 295,309 ---- } /** ! * Returns an array with all the variable names that are used ! * in the given $expr. Called by evaluate() (which will be declared ! * these variables as global). */ function get_var_names($expr) { $var_names = array(); ! while ( ereg('\$[[:alnum:]_]+', $expr, $regs) ) { ! $var_names[] = $regs[0]; ! $expr = str_replace($regs[0], '', $expr); } return $var_names; *************** *** 256,263 **** /** ! * Returns the value of a variable by looking first at ! * $tplVars, and then at $session vars, ! * then at PHP constants, and finally at PHP global variables; ! * if this variable is not found, returns the var_name itself */ function getVarValue($var_name) --- 312,319 ---- /** ! * Returns the value of a variable by looking first at $tplVars, ! * and then at $session vars, then at PHP constants, and finally ! * at PHP global variables. If this variable is not found, ! * returns the constant VAR_NOT_FOUND. */ function getVarValue($var_name) *************** *** 292,298 **** } ! //if still not found return the variable name itself $var_value = str_replace("var_name", $var_name, VAR_NOT_FOUND); - //$var_value = "{".$var_name."}"; return $var_value; } --- 348,353 ---- } ! //if still not found return the constant VAR_NOT_FOUND $var_value = str_replace("var_name", $var_name, VAR_NOT_FOUND); return $var_value; } *************** *** 327,332 **** } /** ! * gets the quote which surrounds the $var_name ! * single, double, or none */ function get_quote($var_name) --- 382,387 ---- } /** ! * Get the quote which surrounds the $var_name: ! * single, double, or none. */ function get_quote($var_name) *************** *** 348,352 **** return array($var_name, $quote); } ! /** escapes all the quotes in the $var_value */ function escape_quotes($var_value, $quote) { --- 403,407 ---- return array($var_name, $quote); } ! /** Escape all the quotes in the $var_value. */ function escape_quotes($var_value, $quote) { *************** *** 373,377 **** /*------ begin DB functions -------------------*/ ! /** executes the query and returns a Recordset */ function execQuery($query, $conn =UNDEFINED) { --- 428,436 ---- /*------ begin DB functions -------------------*/ ! ! /** ! * Execute the given query. ! * @return Recordset ! */ function execQuery($query, $conn =UNDEFINED) { *************** *** 382,387 **** /** ! * opens the given table and returns the records that ! * satisfy the given $condition; returns a TableRS */ function openTable($tbl_name, $condition ="(1=1)", $conn =UNDEFINED) --- 441,447 ---- /** ! * Open the given table and return the records that ! * satisfy the given $condition. ! * @return TableRS */ function openTable($tbl_name, $condition ="(1=1)", $conn =UNDEFINED) *************** *** 394,400 **** /** ! * executes the DB command with the given id ! * returns TRUE or FALSE indicating success or failure ! * $params is an array of {{vars}} that are used in the query */ function execDBCmd($cmd_id, $params =array()) --- 454,460 ---- /** ! * Execute the DB command with the given id. ! * $params is an array of {{vars}} that are used in the query. ! * Returns TRUE or FALSE indicating success or failure. */ function execDBCmd($cmd_id, $params =array()) *************** *** 417,422 **** /** ! * opens and returns the recordset with the given id ! * $params is an array of {{vars}} that are used in the query */ function openRS($rs_id, $params =array()) --- 477,483 ---- /** ! * Open and return the recordset with the given id. ! * $params is an array of {{vars}} that are used in the query. ! * @return Recordset */ function openRS($rs_id, $params =array()) *************** *** 443,447 **** /*------ mix functions ------------------------*/ ! /** takes a path and returns the corresponding url */ function to_url($path) { --- 504,508 ---- /*------ mix functions ------------------------*/ ! /** Convert the given path to url. */ function to_url($path) { *************** *** 451,454 **** --- 512,520 ---- } + /** + * Construct and return a link that can be used to access + * from outside a certain page of the application, in a certain + * state. + */ function get_external_link() { *************** *** 465,468 **** --- 531,535 ---- } + /** Display a pop-up message box to the user. */ function message($msg) { *************** *** 471,474 **** --- 538,542 ---- } + /** Output a debug message. */ function debug_msg($dbg_msg, $comment ="") { *************** *** 477,481 **** } ! /** formats and returns an error message */ function error_msg($err_msg) { --- 545,549 ---- } ! /** Format and return an error message. */ function error_msg($err_msg) { *************** *** 488,492 **** } ! /** formats and returns a warning message */ function warning_msg($warn_msg) { --- 556,560 ---- } ! /** Format and return a warning message. */ function warning_msg($warn_msg) { |