Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 require_once 'class_default_menu_sql.php';
00027 require_once 'class_itext.php';
00028
00029 class Default_Menu
00030 {
00031
00032
00033
00034
00035 private $a_menu_def;
00036
00037
00038
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 }