country.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 
00026 class country extends WebObject
00027 {
00028   function init()
00029     {
00030       $this->addSVar('id', 'AL');
00031       $this->addSVar('mode', 'view');  // view | edit
00032     }
00033 
00034   function on_set_mode($event_args)
00035     {
00036       $mode = $event_args['mode'];
00037 
00038       //(double)check that only a country admin can go to edit mode
00039       $country_id = $this->getSVar('id');
00040       if ($mode=='edit' and !is_country_admin($country_id))  return; 
00041 
00042       if ($mode=='view')
00043         {
00044           WebApp::setSVar('site_edit->mode', 'hidden');
00045         }
00046 
00047       $this->setSVar('mode', $mode);
00048     }
00049 
00050   function on_save($event_args)
00051     {
00052       //(double)check that only a country admin can save changes
00053       $country_id = $this->getSVar('id');
00054       if (!is_country_admin($country_id))  return; 
00055       
00056       $event_args['timestamp'] = time();
00057       WebApp::execDBCmd('save_country', $event_args);
00058     }
00059 
00060   function on_change_id($event_args)
00061     {
00062       //(double)check that only a ROC admin can do this
00063       $rs = WebApp::openRS('country');
00064       $roc_id = $rs->Field('ROC_id');
00065       if (!is_roc_admin($roc_id))  return;
00066 
00067       $new_id = $event_args['country_id'];
00068 
00069       //make sure that this id does not already exist
00070       $rs = WebApp::openRS('get_country_id', array('country_id'=>$new_id));
00071       if (!$rs->EOF())
00072         {
00073           WebApp::message(T_("Another country with this id already exists!"));
00074           return;
00075         }
00076 
00077       //change the country id in the DB
00078       $args = array('country_id'=>$new_id, 'timestamp'=>time());
00079       WebApp::execDBCmd('set_country_id', $args);
00080 
00081       //change the state variable id
00082       $old_id = $this->getSVar('id');
00083       $this->setSVar('id', $new_id);
00084 
00085       //change it also at the 'sites'
00086       $args = array('country_id'=>$new_id, 'old_country_id'=>$old_id);
00087       WebApp::execDBCmd('update_country_id', $args);
00088     }
00089 
00090   function on_set_admin($event_args)
00091     {
00092       //(double)check that only a ROC admin can do this
00093       $rs = WebApp::openRS('country');
00094       $roc_id = $rs->Field('ROC_id');
00095       if (!is_roc_admin($roc_id))
00096         {
00097           WebApp::message(T_("Only a ROC admin can do this!"));
00098           return;
00099         }
00100 
00101       $event_args['timestamp'] = time();
00102       WebApp::execDBCmd('set_admin', $event_args);
00103     }
00104 
00105   function onRender()
00106     {
00107       $rs = WebApp::openRS('country');
00108       $vars = $rs->Fields();
00109       $vars['timestamp'] = date('d/m/Y', $vars['timestamp']);
00110       WebApp::addVars($vars);
00111 
00112       $country_id = $vars['country_id'];
00113       $roc_id = $vars['roc_id'];
00114       WebApp::addVar('is_country_admin', is_country_admin($country_id));
00115       WebApp::addVar('is_roc_admin', is_roc_admin($roc_id));
00116     }
00117 }
00118 ?>

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