site_edit.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003 This file  is part  of HGSM.   HGSM is a  web application  for keeping
00004 information about a hierarchical structure (in this case a grid).
00005 
00006 Copyright 2005, 2006 Dashamir Hoxha, dashohoxha@users.sourceforge.net
00007 
00008 HGSM is free software; you  can redistribute it and/or modify it under
00009 the terms of  the GNU General Public License as  published by the Free
00010 Software  Foundation; either  version 2  of the  License, or  (at your
00011 option) any later version.
00012 
00013 HGSM is  distributed in the hope  that it will be  useful, but WITHOUT
00014 ANY WARRANTY; without even  the implied warranty of MERCHANTABILITY or
00015 FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License
00016 for more details.
00017 
00018 You  should have received  a copy  of the  GNU General  Public License
00019 along with HGSM; if not,  write to the Free Software Foundation, Inc.,
00020 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00021 */
00022 
00023 include_once FORM_PATH.'formWebObj.php';
00024 
00028 class site_edit extends formWebObj
00029 {
00030   var $site_record = array(
00031                            'site_id' => '',
00032                            'name'       => '',
00033                            'email'      => '',
00034                            'phone'      => '',
00035                            'admin'      => ''
00036                            );
00037   
00038   function init()
00039     {
00040       $this->addSVar('mode', 'hidden');  // add | edit | hidden
00041       $this->addSVar('site_id', UNDEFINED);
00042     }
00043 
00044   function on_save($event_args)
00045     {
00046       $mode = $this->getSVar('mode');
00047       if ($mode=='add')
00048         {
00049           //check that site_id does not exist in the table
00050           $rs = WebApp::openRS('get_site', $event_args);
00051           if (!$rs->EOF())
00052             {
00053               $this->site_record = $event_args;
00054               $site_id = $event_args['site_id'];
00055               $msg = "Site ID '$site_id' is used for another site.";
00056               WebApp::message($msg);
00057               return;
00058             }
00059 
00060           //add the new site
00061           $event_args['timestamp'] = time();
00062           WebApp::execDBCmd('add_site', $event_args);
00063 
00064           //set the new id
00065           $this->setSVar('site_id', $event_args['site_id']);
00066 
00067           //rebuild the menu items
00068           include_once MENU.'/rebuild_menu.php'; 
00069         }
00070       else if ($mode=='edit')
00071         {
00072           WebApp::execDBCmd('update_site', $event_args);
00073         }
00074 
00075       //switch the editing mode to hidden
00076       $this->setSVar('mode', 'hidden');
00077     }
00078 
00079   function onRender()
00080     {
00081       $mode = $this->getSVar('mode');
00082       if ($mode=='add')
00083         {
00084           WebApp::addVars($this->site_record);
00085         }
00086       else if ($mode=='edit')
00087         {
00088           $args = array('site_id' => $this->getSVar('site_id'));
00089           $rs = WebApp::openRS('get_site', $args);
00090           $vars = $rs->Fields();
00091           WebApp::addVars($vars);
00092         }
00093     }
00094 }
00095 ?>

Generated on Fri Jan 20 10:34:52 2006 for HGSM by  doxygen 1.4.5