noalyss  Version-6.9.1.8
 All Data Structures Namespaces Files Functions Variables Pages
class_default_menu.php
Go to the documentation of this file.
1 <?php
2 /*
3  * This file is part of NOALYSS.
4  *
5  * NOALYSS is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * NOALYSS is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with NOALYSS; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19 // Copyright Author Dany De Bontridder danydb@aevalys.eu
20 
21 /**
22  * Description of class_default_menu
23  *
24  * @author dany
25  */
26 require_once NOALYSS_INCLUDE.'/database/class_default_menu_sql.php';
27 require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
28 
30 {
31 
32  /**
33  * $a_menu_def is an array of Default_Menu_SQL
34  */
35  private $a_menu_def;
36 
37  /**
38  * Possible value
39  */
40  private $code; // array with the valid code
41 
42  function __construct()
43  {
44  global $cn;
45  $menu = new Default_Menu_SQL($cn);
46  $ret = $menu->seek();
47  for ($i = 0; $i < Database::num_row($ret); $i++)
48  {
49  $tmenu = $menu->next($ret, $i);
50  $idx = $tmenu->getp('md_code');
51  $this->a_menu_def[$idx] = $tmenu->getp('me_code');
52  }
53  $this->code = explode(',', 'code_follow,code_invoice');
54  }
55 
56  function input_value()
57  {
58  $code_invoice = new IText('code_invoice', $this->a_menu_def['code_invoice']);
59  $code_follow = new IText('code_follow', $this->a_menu_def['code_follow']);
60  echo '<p>' . _('Code pour création facture depuis gestion') . $code_invoice->input() . '</p>';
61  echo '<p>' . _('Code pour appel gestion') . $code_follow->input() . '</p>';
62  }
63 
64  private function check_code($p_string)
65  {
66  global $cn;
67  $count = $cn->get_value('select count(*) from v_menu_description_favori where '
68  . 'code = $1', array($p_string));
69  if ($count == 0)
70  {
71  throw new Exception('code_inexistant');
72  }
73  }
74 
75  function verify()
76  {
77  foreach ($this->code as $code)
78  {
79  $this->check_code($this->a_menu_def[$code]);
80  }
81  }
82 
83  function set($p_string, $p_value)
84  {
85  if (in_array($p_string, $this->code) == false)
86  {
87  throw new Exception("code_invalid");
88  }
89  $this->a_menu_def[$p_string] = $p_value;
90  }
91  function get ($p_string)
92  {
93  return $this->a_menu_def[$p_string];
94  }
95 
96  function save()
97  {
98  global $cn;
99  try
100  {
101  $this->verify();
102  foreach ($this->code as $key => $value)
103  {
104  $cn->exec_sql('update menu_default set me_code=$1 where
105  md_code =$2', array($value,$this->a_menu_def[$value]));
106  }
107  } catch (Exception $e)
108  {
109  error_log($e->getTraceAsString());
110  echo $e->getMessage();
111  throw $e;
112  }
113  }
114 
115  static function test_me()
116  {
117  global $cn, $g_user, $g_succeed, $g_failed;
118 
119  echo h2('Constructor', '');
120  $a = new Default_Menu();
121  echo $g_succeed . 'constructor';
122  if (count($a->a_menu_def) != 2)
123  echo $g_failed;
124  else
125  echo $g_succeed;
126  echo h2("input_value", "");
127  $a->input_value();
128  echo h2('verify');
129  $a->verify();
130  try {
131  echo h2('Verify must failed');
132  $a->set('code_follow', 'MEMNU/MEMEM/');
133  $a->verify();
134  } catch (Exception $e) {
135  echo $g_succeed. " OK ";
136  }
137  echo h2('Verify must succeed');
138  try {
139  $a->set('code_follow', 'GESTION/FOLLOW');
140  $a->verify();
141  echo $g_succeed. " OK ";
142  } catch (Exception $e)
143  {
144  echo $g_failed."NOK";
145  }
146  echo h2('Save');
147  $a->save();
148  echo h2('GET');
149  echo ( assert($a->get('code_follow')=='GESTION/FOLLOW') )?$g_succeed.$a->get('code_follow'):$g_failed.$a->get('code_follow');
150  echo ( assert($a->get('code_invoice')=='COMPTA/VENMENU/VEN') )?$g_succeed.$a->get('code_invoice'):$g_failed.$a->get('code_invoice');
151  echo $a->get('code_invoice');
152  }
153 
154 }
$code
Possible value.
static num_row($ret)
wrapper for the function pg_NumRows
$a_menu_def
$a_menu_def is an array of Default_Menu_SQL
h2($p_string, $p_class="", $raw="")
Definition: ac_common.php:68
Description of class_default_menu_sql.
$value
check_code($p_string)
$idx
Description of class_default_menu.
global $g_succeed
global $g_user
Find the default module or the first one.
Definition: action.inc.php:24
global $g_failed
$count
Definition: modele.inc.php:255
set($p_string, $p_value)