contact_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 contact_edit extends formWebObj
00029 {
00030   var $contact_record = array(
00031                               'name'  => '',
00032                               'email' => '',
00033                               'phone' => '',
00034                               'role'  => '',
00035                               'hours' => ''
00036                               );
00037   
00038   function init()
00039     {
00040       $this->addSVar('mode', 'hidden');  // add | edit | hidden
00041       $this->addSVar('contact_id', UNDEFINED);
00042     }
00043 
00044   function on_save($event_args)
00045     {
00046       //(double)check that only a site admin can save changes
00047       $site_id = WebApp::getSVar('site->id');
00048       if (!is_site_admin($site_id))
00049         {
00050           WebApp::message(T_("Only a site admin can do this!"));
00051           return;
00052         }
00053 
00054       $mode = $this->getSVar('mode');
00055       
00056       if ($mode=='add')
00057         {
00058           //add the new contact
00059           WebApp::execDBCmd('add_contact', $event_args);
00060 
00061           //set the new id
00062           $this->setSVar('contact_id', $event_args['contact_id']);
00063         }
00064       elseif ($mode=='edit')
00065         {
00066           WebApp::execDBCmd('update_contact', $event_args);
00067         }
00068 
00069       //switch the editing mode to hidden
00070       $this->setSVar('mode', 'hidden');
00071     }
00072 
00073   function onRender()
00074     {
00075       $mode = $this->getSVar('mode');
00076       if ($mode=='add')
00077         {
00078           WebApp::addVars($this->contact_record);
00079         }
00080       elseif ($mode=='edit')
00081         {
00082           $rs = WebApp::openRS('get_contact');
00083           WebApp::addVars($rs->Fields());
00084         }
00085     }
00086 }
00087 ?>

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