noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_default_menu.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   NOALYSS is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00020 
00021 /**
00022  * Description of class_default_menu
00023  *
00024  * @author dany
00025  */
00026 require_once 'class_default_menu_sql.php';
00027 require_once 'class_itext.php';
00028 
00029 class Default_Menu
00030 {
00031 
00032     /**
00033      * $a_menu_def is an array of Default_Menu_SQL
00034      */
00035     private $a_menu_def;
00036 
00037     /**
00038      * Possible value
00039      */
00040     private $code;
00041 
00042     function __construct()
00043     {
00044         global $cn;
00045         $menu = new Default_Menu_SQL($cn);
00046         $ret = $menu->seek();
00047         for ($i = 0; $i < Database::num_row($ret); $i++)
00048         {
00049             $tmenu = $menu->next($ret, $i);
00050             $idx = $tmenu->getp('md_code');
00051             $this->a_menu_def[$idx] = $tmenu->getp('me_code');
00052         }
00053         $this->code = explode(',', 'code_follow,code_invoice');
00054     }
00055 
00056     function input_value()
00057     {
00058         $code_invoice = new IText('code_invoice', $this->a_menu_def['code_invoice']);
00059         $code_follow = new IText('code_follow', $this->a_menu_def['code_follow']);
00060         echo '<p>' . _('Code pour création facture depuis gestion') . $code_invoice->input() . '</p>';
00061         echo '<p>' . _('Code pour appel gestion') . $code_follow->input() . '</p>';
00062     }
00063 
00064     private function check_code($p_string)
00065     {
00066         global $cn;
00067         $count = $cn->get_value('select count(*) from v_menu_description_favori where '
00068                 . 'code = $1', array($p_string));
00069         if ($count == 0)
00070         {
00071             throw new Exception('code_inexistant');
00072         }
00073     }
00074 
00075     function verify()
00076     {
00077         foreach ($this->code as $code)
00078         {
00079             $this->check_code($this->a_menu_def[$code]);
00080         }
00081     }
00082 
00083     function set($p_string, $p_value)
00084     {
00085         if (in_array($p_string, $this->code) == false)
00086         {
00087             throw new Exception("code_invalid");
00088         }
00089         $this->a_menu_def[$p_string] = $p_value;
00090     }
00091     function get ($p_string)
00092     {
00093         return $this->a_menu_def[$p_string];
00094     }
00095 
00096     function save()
00097     {
00098         global $cn;
00099         try
00100         {
00101             $this->verify();
00102             foreach ($this->code as $key => $value)
00103             {
00104                 $cn->exec_sql('update menu_default set me_code=$1 where
00105                         md_code =$2', array($value,$this->a_menu_def[$value]));
00106             }
00107         } catch (Exception $e)
00108         {
00109             $e->getTraceAsString();
00110             throw $e;
00111         }
00112     }
00113 
00114     static function test_me()
00115     {
00116         global $cn, $g_user, $g_succeed, $g_failed;
00117 
00118         echo h2('Constructor', '');
00119         $a = new Default_Menu();
00120         echo $g_succeed . 'constructor';
00121         if (count($a->a_menu_def) != 2)
00122             echo $g_failed;
00123         else
00124             echo $g_succeed;
00125         echo h2("input_value", "");
00126         $a->input_value();
00127         echo h2('verify');
00128         $a->verify();
00129         try {
00130             echo h2('Verify must failed');
00131             $a->set('code_follow', 'MEMNU/MEMEM/');
00132             $a->verify();   
00133         } catch (Exception $e) {
00134             echo $g_succeed. " OK ";
00135         }
00136         echo h2('Verify must succeed');
00137         try {
00138             $a->set('code_follow', 'GESTION/FOLLOW');
00139             $a->verify();
00140             echo $g_succeed. " OK ";
00141         } catch (Exception $e)
00142         {
00143             echo $g_failed."NOK";
00144         }
00145         echo h2('Save');
00146         $a->save();
00147         echo h2('GET');
00148         echo ( assert($a->get('code_follow')=='GESTION/FOLLOW') )?$g_succeed.$a->get('code_follow'):$g_failed.$a->get('code_follow');
00149         echo ( assert($a->get('code_invoice')=='COMPTA/VENMENU/VEN') )?$g_succeed.$a->get('code_invoice'):$g_failed.$a->get('code_invoice');
00150         echo $a->get('code_invoice');
00151     }
00152 
00153 }
 All Data Structures Namespaces Files Functions Variables Enumerations