noalyss  Version-6.9.1.8
 All Data Structures Namespaces Files Functions Variables Pages
class_acc_account.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 /*! \file
21  * \brief Manage the account
22  */
23 /*!
24  * \brief Manage the account from the table tmp_pcmn
25  */
26 require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
27 require_once NOALYSS_INCLUDE.'/lib/class_database.php';
28 require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
29 
31 {
32  var $db; /*!< $db database connection */
33  static private $variable = array("value"=>'pcm_val',
34  'type'=>'pcm_type',
35  'parent'=>'pcm_val_parent',
36  'libelle'=>'pcm_lib');
37  private $pcm_val;
38  private $pcm_type;
39  private $pcm_parent;
40  private $pcm_lib;
41  static public $type=array(
42  array('label'=>'Actif','value'=>'ACT'),
43  array('label'=>'Passif','value'=>'PAS'),
44  array('label'=>'Actif c. inverse','value'=>'ACTINV'),
45  array('label'=>'Passif c.inverse','value'=>'PASINV'),
46  array('label'=>'Produit','value'=>'PRO'),
47  array('label'=>'Produit Inverse','value'=>'PROINV'),
48  array('label'=>'Charge','value'=>'CHA'),
49  array('label'=>'Charge Inverse','value'=>'CHAINV'),
50  array('label'=>'Non defini','value'=>'CON')
51  );
52 
53  function __construct ($p_cn,$p_id=0)
54  {
55  $this->db=$p_cn;
56  $this->pcm_val=$p_id;
57  }
58  public function get_parameter($p_string)
59  {
60  if ( array_key_exists($p_string,self::$variable) )
61  {
62  $idx=self::$variable[$p_string];
63  return $this->$idx;
64  }
65  else
66  throw new Exception (__FILE__.":".__LINE__._('Erreur attribut inexistant'));
67  }
68 
69  function set_parameter($p_string,$p_value)
70  {
71  if ( array_key_exists($p_string,self::$variable) )
72  {
73  $idx=self::$variable[$p_string];
74  if ($this->check($idx,$p_value) == true ) $this->$idx=$p_value;
75  }
76  else
77  throw new Exception (__FILE__.":".__LINE__._('Erreur attribut inexistant'));
78 
79 
80  }
81  /*!\brief Return the name of a account
82  * it doesn't change any data member
83  * \return string with the pcm_lib
84  */
85  function get_lib()
86  {
87  $ret=$this->db->exec_sql(
88  "select pcm_lib from tmp_pcmn where
89  pcm_val=$1",array($this->pcm_val));
90  if ( Database::num_row($ret) != 0)
91  {
93  $this->pcm_lib=$r['pcm_lib'];
94  }
95  else
96  {
97  $this->pcm_lib=_("Poste inconnu");
98  }
99  return $this->pcm_lib;
100  }
101  /*!\brief Check that the value are valid
102  *\return true if all value are valid otherwise false
103  */
104  function check ($p_member='',$p_value='')
105  {
106  // if there is no argument we check all the member
107  if ($p_member == '' && $p_value== '' )
108  {
109  foreach (self::$variable as $l=>$k)
110  {
111  $this->check($k,$this->$k);
112  }
113  }
114  else
115  {
116  // otherwise we check only the value
117  if ( strcmp ($p_member,'pcm_val') == 0 )
118  {
119  return true;
120  }
121  else if ( strcmp ($p_member,'pcm_val_parent') == 0 )
122  {
123  return true;
124  }
125  else if ( strcmp ($p_member,'pcm_lib') == 0 )
126  {
127  return true;
128  }
129  else if ( strcmp ($p_member,'pcm_type') == 0 )
130  {
131  foreach (self::$type as $l=>$k)
132  {
133  if ( strcmp ($k['value'],$p_value) == 0 ) return true;
134 
135  }
136  throw new Exception(_('type de compte incorrect ').$p_value);
137  }
138  throw new Exception (_('Donnee member inconnue ').$p_member);
139  }
140 
141  }
142  /*!\brief Get all the value for this object from the database
143  * the data member are set
144  * \return false if this account doesn't exist otherwise true
145  */
146  function load()
147  {
148  $ret=$this->db->exec_sql("select pcm_lib,pcm_val_parent,pcm_type from
149  tmp_pcmn where pcm_val=$1",array($this->pcm_val));
151 
152  if ( ! $r ) return false;
153  $this->pcm_lib=$r[0]['pcm_lib'];
154  $this->pcm_val_parent=$r[0]['pcm_val_parent'];
155  $this->pcm_type=$r[0]['pcm_type'];
156  return true;
157 
158  }
159  function form($p_table=true)
160  {
161  $wType=new ISelect();
162  $wType->name='p_type';
163  $wType->value=self::$type;
164 
165  if ( ! $p_table )
166  {
167  $ret=' <TR>
168  <TD>
169  <INPUT TYPE="TEXT" NAME="p_val" SIZE=7>
170  </TD>
171  <TD>
172  <INPUT TYPE="TEXT" NAME="p_lib" size=50>
173  </TD>
174  <TD>
175  <INPUT TYPE="TEXT" NAME="p_parent" size=5>
176  </TD>
177  <TD>';
178 
179  $ret.=$wType->input().'</TD>';
180  return $ret;
181  }
182  else
183  {
184  $ret='<TABLE><TR>';
185  $ret.=sprintf ('<TD>'._('Numéro de classe').' </TD><TD><INPUT TYPE="TEXT" name="p_val" value="%s"></TD>',$this->pcm_val);
186  $ret.="</TR><TR>";
187  $ret.=sprintf('<TD>'._('Libellé').' </TD><TD><INPUT TYPE="TEXT" size="70" NAME="p_lib" value="%s"></TD>',h($this->pcm_lib));
188  $ret.= "</TR><TR>";
189  $ret.=sprintf ('<TD>'._('Classe Parent').'</TD><TD><INPUT TYPE="TEXT" name="p_parent" value="%s"></TD>',$this->pcm_val_parent);
190  $ret.='</tr><tr>';
191  $wType->selected=$this->pcm_type;
192  $ret.="<td> Type de poste </td>";
193  $ret.= '<td>'.$wType->input().'</td>';
194  $ret.="</TR> </TABLE>";
195  $ret.=dossier::hidden();
196 
197  return $ret;
198  }
199  }
200  function count($p_value)
201  {
202  $sql="select count(*) from tmp_pcmn where pcm_val=$1";
203  return $this->db->get_value($sql,array($p_value));
204  }
205  /*!\brief for developper only during test */
206  static function test_me()
207  {
208 
209  }
210  /**
211  *@brief update an accounting, but you can update pcm_val only if
212  * this accounting has never been used before */
213  function update($p_old)
214  {
215  if (strcmp(trim($p_old), trim($this->pcm_val)) !=0 )
216  {
217  $count=$this->db->get_value('select count(*) from jrnx where j_poste=$1',
218  array($p_old)
219  );
220  if ($count != 0)
221  throw new Exception(_('Impossible de changer la valeur: poste déjà utilisé'));
222  }
223  $this->pcm_lib=mb_substr($this->pcm_lib,0,150);
224  $this->check();
225  $sql="update tmp_pcmn set pcm_val=$1, pcm_lib=$2,pcm_val_parent=$3,pcm_type=$4 where pcm_val=$5";
226  $Ret=$this->db->exec_sql($sql,array($this->pcm_val,
227  $this->pcm_lib,
228  $this->pcm_val_parent,
229  $this->pcm_type,
230  $p_old));
231  }
232 }
__construct($p_cn, $p_id=0)
static fetch_all($ret)
wrapper for the function pg_fetch_all
load()
Get all the value for this object from the database the data member are set.
set_parameter($p_string, $p_value)
static num_row($ret)
wrapper for the function pg_NumRows
Manage the account from the table tmp_pcmn.
form($p_table=true)
$idx
get_lib()
Return the name of a account it doesn't change any data member.
static fetch_array($ret, $p_indice=0)
wrapper for the function pg_fetch_array
update($p_old)
update an accounting, but you can update pcm_val only if this accounting has never been used before ...
function trim(s)
remove trailing and heading space
Definition: scripts.js:95
h($p_string)
to protect again bad characters which can lead to a cross scripting attack the string to be diplayed ...
Definition: ac_common.php:38
$count
Definition: modele.inc.php:255
$SecUser db
get_parameter($p_string)
$type
static test_me()
for developper only during test
check($p_member='', $p_value='')
Check that the value are valid.