roc_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 roc_edit extends formWebObj
00029 {
00030   var $roc_record = array(
00031                           'ROC_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('ROC_id', UNDEFINED);
00042     }
00043 
00044   function on_save($event_args)
00045     {
00046       $mode = $this->getSVar('mode');
00047       if ($mode=='add')
00048         {
00049           //check that ROC_id does not exist in the table
00050           $rs = WebApp::openRS('get_roc', $event_args);
00051           if (!$rs->EOF())
00052             {
00053               $this->roc_record = $event_args;
00054               $ROC_id = $event_args['ROC_id'];
00055               $msg = T_("ROC ID 'v_ROC_id' is used for another ROC.");
00056               $msg = str_replace('v_ROC_id', $ROC_id, $msg);
00057               WebApp::message($msg);
00058               return;
00059             }
00060 
00061           //add the new roc
00062           $event_args['timestamp'] = time();
00063           WebApp::execDBCmd('add_roc', $event_args);
00064 
00065           //set the new id
00066           $this->setSVar('ROC_id', $event_args['ROC_id']);
00067 
00068           //rebuild the menu items
00069           include_once MENU.'/rebuild_menu.php'; 
00070         }
00071       else if ($mode=='edit')
00072         {
00073           WebApp::execDBCmd('update_roc', $event_args);
00074         }
00075 
00076       //switch the editing mode to hidden
00077       $this->setSVar('mode', 'hidden');
00078     }
00079 
00080   function onRender()
00081     {
00082       $mode = $this->getSVar('mode');
00083       if ($mode=='add')
00084         {
00085           WebApp::addVars($this->roc_record);
00086         }
00087       else if ($mode=='edit')
00088         {
00089           $args = array('ROC_id' => $this->getSVar('ROC_id'));
00090           $rs = WebApp::openRS('get_roc', $args);
00091           $vars = $rs->Fields();
00092           WebApp::addVars($vars);
00093         }
00094     }
00095 }
00096 ?>

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