* @license Zope Public License (ZPL) Version 2.1 {@link http://zoopframework.com/ss.4/7/license.html} */ class zone_default extends zone { /** * wildcards * * @var mixed * @access public */ var $wildcards = false; /** * urlvars * * @var mixed * @access public */ var $urlvars = false; /** * urlzones * * @var mixed * @access public */ var $urlzones = false; /** * allowed_children * * @var array * @access public */ var $allowed_children = array(); /** * zone_default * * @access public * @return void */ function zone_default() { // default zone. } /** * makePath * * @access public * @return void */ function makePath() { return ""; } /** * initZone * * @param mixed $inPath * @access public * @return void */ function initZone($inPath) { global $sGlobals; global $gui; if (isset($sGlobals->company)) { $gui->assign("UserCompany_id", $sGlobals->company["company_id"]); } //do things here that you want to happen on every request, because zone_default is //part of every request, therefore initzone is part of every request. //for example, assign the user's name into the gui. } /** * initPages * * @param mixed $inPath * @access public * @return void */ function initPages($inPath) { global $gui; global $sGlobals; //do things here that you want to happen for every page in zone_default //if the user has to be logged in for every page in zone_default(unlikely) //do something to require it like //RequireCondition(isset($sGlobals->userId)); //RequireCondition sends to login page when fails. //define login page in config.php } /** * pageDefault * * @param mixed $inPath * @access public * @return void */ function pageDefault($inPath) { // You may usually want the following line, but for our demo we don't // $this->zoneRedirect("login"); global $sGlobals; global $gui; // //this is for gets. It displays the page $gui->display("default.tpl"); } /** * postDefault * * @param mixed $inPath * @access public * @return void */ function postDefault($inPath) { global $sGlobals; //this is for posts, it handles when forms get submitted. } /** * pageKeepOpen * * @param mixed $inPath * @access public * @return void */ function pageKeepOpen($inPath) { //you can write some javascript in your //templates that requests this page every so often //to keep your sessions alive. } /** * pageLogin * * @param mixed $inPath * @access public * @return void */ function pageLogin($inPath) { //we wrote a custom require that basically does //RequireCondition(app_status != 'live'); //we called it: //requireNotLive(); //generally you will want do do things like //this for security checks. Use RequireCondition //to implement the functions, and everything will //do what you want. Generally application specific //functions like this will go in misc.php global $sGlobals; global $gui; if(isset($sGlobals->loginError)) { $error = "invalid login"; unset($sGlobals->loginError); } else { $error = ""; } $gui->assign("error", $error); $gui->showLogout = 0; $gui->showNext = 0; $gui->display("login.tpl"); } /** * postLogin * * @param mixed $inPath * @access public * @return void */ function postLogin($inPath) { //requireNotLive(); global $sGlobals; //always submit forms with an actionField //depend on the actionField to redirect. //Sequencing depends on a form field called //actionField $action = getPostText("actionField"); $username = getPostText("username"); $password = getPostText("password"); // For the database functions to work you need to setup the database in app_dir/config/db.php $personId = sql_fetch_one_cell("SELECT user_id FROM users WHERE username = '$username' AND password = '$password'"); //sql_fetch_one_cell is one of many usefull sql functions //almost all are of the form sql_fetch_*($sql), //with optional params following the sql statement //it might be useful to take a look through pgsql.php, and database.php //to see which functions exist to format the data how you want. //almost any format you'll need is there. // we only need to do this if they are trying to go forward if( $action == "next" ) { if($personId === false) { $sGlobals->loginError = "bad username or password"; redirect(app_login_page); } $sGlobals->user_id = $personId; $company_id = sql_fetch_one_cell("SELECT company_id FROM users WHERE user_id = '$personId'"); $sGlobals->company = sql_fetch_one("SELECT * from companies WHERE company_id = '$company_id'"); $this->zoneRedirect($this->processLogin()); } } /** * isAdmin * * @access public * @return void */ function isAdmin() { global $sGlobals; if ($sGlobals->company['company_id'] == 1) { return true; } else { return false; } } /** * processLogin * * @access public * @return void */ function processLogin() { global $sGlobals; RequireCondition(isset($sGlobals->user_id)); BaseRedirect(zone_admin::makePath() . "/default"); BaseRedirect("/admin"); } /** * pageLogout * * @param mixed $inPath * @access public * @return void */ function pageLogout($inPath) { global $sGlobals; unset($sGlobals->user_id); BaseRedirect("/"); } /** * pageGuiControlExample * * @param mixed $inPath * @access public * @return void */ function pageGuiControlExample($inPath) { global $gui; // needed to send the variables to the template engine (smarty). $text = &getGuiControl('text', 'text_guicontrol'); $text->setParam('value', "i am the value"); $text->setParam('validate', array('type' => 'int', 'required' => true)); $select = &getGuiControl('select', 'select'); $select->setParam('index', array('option1' => 'option1', 'option2' => 'option2')); $select_update = &getGuiControl('select_update', 'select_update'); $select_update->setParam('index', array('optionA' => 'optionA', 'optionB' => 'optionB')); $select_update->setParam('url', SCRIPT_URL . "/SelectUpdateList"); $select_update->setParam('method', "POST"); $gui->assign("select_update", $select_update); $gui->assign("select", $select); $gui->assign("text", $text); $gui->assign("css", "styles.css"); $gui->assign("title", "Zoop PHP Framework GuiControl Demo"); $gui->display("examples/guiControls.tpl"); } /** * postGuiControlExample * * @param mixed $inPath * @access public * @return void */ function postGuiControlExample($inPath) { echo("the form has been posted to the postGuiControlExample function successfully.
Here is the output of getRawPost()."); $POST = getRawPost(); echo_r($POST); } function postSelectUpdateList($inPath) // This function is called using ajax to populate a div in the pageGuiControlExample. { $newselectupdate = &getGuiControl('select', 'dynamically created select control'); $newselectupdate->setParam('index', array('optionC' => 'optionC', 'optionD' => 'optionD')); $newselectupdate->display(); } }