noalyss Version-9
default_menu.class.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 */
26require_once NOALYSS_INCLUDE.'/database/default_menu_sql.class.php';
27
29{
30
31 /**
32 * $a_menu_def is an array of Default_Menu_SQL
33 */
34 private $a_menu_def;
35
36 /**
37 * Possible value
38 */
39 private $code; // array with the valid code
40
41 function __construct()
42 {
43 global $cn;
45 $ret = $menu->seek();
46 for ($i = 0; $i < Database::num_row($ret); $i++)
47 {
48 $tmenu = $menu->next($ret, $i);
49 $idx = $tmenu->getp('md_code');
50 $this->a_menu_def[$idx] = $tmenu->getp('me_code');
51 }
52 $this->code = explode(',', 'code_follow,code_invoice,code_feenote',);
53 }
54
55 function input_value()
56 {
57 $code_invoice = new IText('code_invoice', $this->a_menu_def['code_invoice']);
58 $code_follow = new IText('code_follow', $this->a_menu_def['code_follow']);
59 $code_feenote = new IText('code_feenote', $this->a_menu_def['code_feenote']);
60 echo '<div class="form-group">';
61 echo '<div class="form-text">' .'<label for="code_invoice">'._('Code AD pour création facture depuis gestion').
62 "</label>"."</div>". '<div class="form-text">' .$code_invoice->input() . '</div>';
63
64 echo '<div class="form-text">' .'<label for="code_follow">'._('Code AD pour appel gestion').
65 "</label>"."</div>". '<div class="form-text">' .$code_follow->input() . '</div>';
66
67 echo '<div class="form-text">' .'<label for="code_feenote">'._('Code AD pour création note de frais ou facture achat').
68 "</label>"."</div>". '<div class="form-text">' .$code_feenote->input() . '</div>';
69 echo '</div>';
70 }
71
72 private function check_code($p_string)
73 {
74 global $cn;
75 $count = $cn->get_value('select count(*) from v_menu_description_favori where '
76 . 'code = $1', array($p_string));
77 if ($count == 0)
78 {
79 throw new Exception('code_inexistant');
80 }
81 }
82
83 function verify()
84 {
85 foreach ($this->code as $code)
86 {
87 $this->check_code($this->a_menu_def[$code]);
88 }
89 }
90
91 function set($p_string, $p_value)
92 {
93 if (in_array($p_string, $this->code) == false)
94 {
95 throw new Exception("code_invalid");
96 }
97 $this->a_menu_def[$p_string] = $p_value;
98 }
99 function get ($p_string)
100 {
101 return $this->a_menu_def[$p_string];
102 }
103
104 function save()
105 {
106 global $cn;
107 try
108 {
109 $this->verify();
110 foreach ($this->code as $key => $value)
111 {
112 $cn->exec_sql('update menu_default set me_code=$1 where
113 md_code =$2', array($value,$this->a_menu_def[$value]));
114 }
115 } catch (Exception $e)
116 {
117 record_log($e);
118 echo $e->getMessage();
119 throw $e;
120 }
121 }
122
123 static function test_me()
124 {
126
127 echo h2('Constructor', '');
128 $a = new Default_Menu();
129 echo $g_succeed . 'constructor';
130 if (count($a->a_menu_def) != 2)
131 echo $g_failed;
132 else
133 echo $g_succeed;
134 echo h2("input_value", "");
135 $a->input_value();
136 echo h2('verify');
137 $a->verify();
138 try {
139 echo h2('Verify must failed');
140 $a->set('code_follow', 'MEMNU/MEMEM/');
141 $a->verify();
142 } catch (Exception $e) {
143 echo $g_succeed. " OK ";
144 }
145 echo h2('Verify must succeed');
146 try {
147 $a->set('code_follow', 'GESTION/FOLLOW');
148 $a->verify();
149 echo $g_succeed. " OK ";
150 } catch (Exception $e)
151 {
152 echo $g_failed."NOK";
153 }
154 echo h2('Save');
155 $a->save();
156 echo h2('GET');
157 echo ( assert($a->get('code_follow')=='GESTION/FOLLOW') )?$g_succeed.$a->get('code_follow'):$g_failed.$a->get('code_follow');
158 echo ( assert($a->get('code_invoice')=='COMPTA/VENMENU/VEN') )?$g_succeed.$a->get('code_invoice'):$g_failed.$a->get('code_invoice');
159 echo $a->get('code_invoice');
160 }
161
162}
h2($p_string, $p_class="", $raw="")
Definition: ac_common.php:68
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342
global $g_user
if no group available , then stop
$idx
static num_row($ret)
wrapper for the function pg_num_rows
Description of class_default_menu_sql.
Description of class_default_menu.
$a_menu_def
$a_menu_def is an array of Default_Menu_SQL
$code
Possible value.
check_code($p_string)
Html Input.
Definition: itext.class.php:30
global $g_failed
global $g_succeed
$count