noalyss  Version-6.9.1.8
 All Data Structures Namespaces Files Functions Variables Pages
class_anc_plan.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 
20 // Copyright Author Dany De Bontridder danydb@aevalys.eu
21 
22 /*!\file
23  * \brief Concerns the Analytic plan (table plan_analytique)
24  */
25 
26 /*! \brief
27  * Concerns the Analytic plan (table plan_analytique)
28  */
29 require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
30 require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
31 require_once NOALYSS_INCLUDE.'/constant.php';
32 require_once NOALYSS_INCLUDE.'/lib/class_database.php';
33 require_once NOALYSS_INCLUDE.'/class/class_anc_account.php';
34 require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
35 
36 class Anc_Plan
37 {
38  var $db; /*!<database connection */
39  var $name; /*!< name plan_analytique.pa_name */
40  var $description; /*!< description of the PA plan_analytique.pa_description*/
41  var $id; /*!< id = plan_analytique.pa_id */
42 
43  function __construct($p_cn,$p_id=0)
44  {
45  $this->db=$p_cn;
46  $this->id=$p_id;
47  $this->name="";
48  $this->description="";
49  $this->get();
50  }
51  /*!\brief get the list of all existing PA
52  * \return an array of PA (not object)
53  *
54  */
55  function get_list($p_order=" order by pa_name")
56  {
57  $array=array();
58  $sql="select pa_id as id,pa_name as name,".
59  "pa_description as description from plan_analytique $p_order";
60  $ret=$this->db->exec_sql($sql);
62  return $array;
63  }
64 
65  function get()
66  {
67  if ( $this->id==0) return;
68 
69  $sql="select pa_name,pa_description from plan_analytique where pa_id=".$this->id;
70  $ret= $this->db->exec_sql($sql);
71  if ( Database::num_row($ret) == 0)
72  {
73  return;
74  }
76  $this->name=$a['pa_name'];
77  $this->description=$a['pa_description'];
78 
79  }
80 
81  function delete()
82  {
83  if ( $this->id == 0 ) return;
84  $this->db->exec_sql("delete from plan_analytique where pa_id=".$this->id);
85  }
86 
87  function update()
88  {
89  if ( $this->id==0) return;
90  $name=sql_string($this->name);
91  if ( strlen($name) == 0)
92  return;
93 
94  $description=sql_string($this->description);
95  $this->db->exec_sql("update plan_analytique set pa_name=$1,
96  pa_description=$2 where pa_id=$3",array($name,$description,$this->id));
97  }
98 
99  function add()
100  {
101  $name=sql_string($this->name);
102  if ( strlen($name) == 0)
103  return;
104  if ( $this->isAppend() == false) return;
105  $description=sql_string($this->description);
106  $this->db->exec_sql("insert into plan_analytique(pa_name,pa_description)".
107  " values (".
108  "'".$name."',".
109  "'".$description."')");
110  $this->id=$this->db->get_current_seq('plan_analytique_pa_id_seq');
111 
112  }
113  function form()
114  {
115 
116  $wName=new IText('pa_name',$this->name);
117 
118  $wName->table=1;
119  $wDescription=new IText('pa_description',$this->description);
120  $wDescription->table=1;
121  $wId=new IHidden("pa_id",$this->id);
122  $ret="<TABLE>";
123  $ret.='<tr>'.td(_('Nom')).$wName->input().'</tr>';
124  $ret.="<tr>".td(_('Description')).$wDescription->input()."</tr>";
125  $ret.="</table>";
126  $ret.=$wId->input();
127  return $ret;
128  }
129  function isAppend()
130  {
131  $count=$this->db->get_value("select count(pa_id) from plan_analytique");
132 
133  if ( $count > 10 )
134  return false;
135  else
136  return true;
137  }
138  /*!\brief get all the poste related to the current
139  * Analytic plan
140  * \return an array of Poste_analytic object
141  */
143  {
144  $sql="select po_id,po_name from poste_analytique where pa_id=".$this->id." $p_order";
145  $r=$this->db->exec_sql($sql);
146  $ret=array();
147  if ( Database::num_row($r) == 0 )
148  return $ret;
149 
151  foreach ($all as $line)
152  {
153  $obj=new Anc_Account($this->db,$line['po_id']);
154  $obj->get_by_id();
155  $ret[]=clone $obj;
156  }
157  return $ret;
158  }
159  /*!\brief show the header for a table for PA
160  * \return string like <th>name</th>...
161  */
162  function header()
163  {
164  $res="";
165  $a_plan=$this->get_list(" order by pa_id");
166  if ( empty($a_plan)) return "";
167  foreach ($a_plan as $r_plan)
168  {
169  $res.="<th>".h($r_plan['name'])."</th>";
170  }
171  return $res;
172  }
173  function count()
174  {
175  $a=$this->db->count_sql("select pa_id from plan_analytique");
176  return $a;
177  }
178  function exist()
179  {
180  $a=$this->db->count_sql("select pa_id from plan_analytique where pa_id=".
181  Database::escape_string($this->pa_id));
182 
183  return ($a==0)?false:true;
184 
185  }
186  /**
187  *@brief return an HTML string containing hidden input type to
188  * hold the differant PA_ID
189  *@param $p_array contains a array, it is the result of the fct
190  * Anc_Plan::get_list
191  *@return html string
192  *@see Anc_Plan::get_list
193  */
194  static function hidden($p_array)
195  {
196  $r='';
197  for ($i_anc=0;$i_anc <count($p_array);$i_anc++)
198  {
199  $r.=HtmlInput::hidden('pa_id[]',$p_array[$i_anc]['id']);
200  }
201  return $r;
202  }
203  static function test_me()
204  {
206  echo "<h1>Plan analytique : test</h1>";
207  echo "clean";
208  $cn->exec_sql("delete from plan_analytique");
209 
210  $p=new Anc_Plan($cn);
211  echo "<h2>Add</h2>";
212  $p->name="Nouveau 1";
213  $p->description="C'est un test";
214  echo "Add<hr>";
215  $p->add();
216  $p->name="Nouveau 2";
217  $p->add();
218  $pa_id=$p->id;
219  echo $p->id."/";
220  $p->name="Nouveau 3";
221  $p->add();
222  echo $p->id."/";
223 
224 
225  $p->name="Nouveau 4";
226  $p->add();
227  echo $p->id;
228 
229  echo "<h2>get</h2>";
230  $p->get();
231  var_dump($p);
232  echo "<h2>Update</h2> ";
233  $p->name="Update ";
234  $p->description="c'est change";
235  $p->update();
236  $p->get();
237  var_dump($p);
238  echo "<h2>get_list</h2>";
239  $a=$p->get_list();
240  var_dump($a);
241  echo "<h2>delete </h2>";
242  $p->delete();
243 
244 
245  }
246 }
247 
248 ?>
static fetch_all($ret)
wrapper for the function pg_fetch_all
sql_string($p_string)
Fix the problem with the quote char for the database.
Definition: ac_common.php:457
static num_row($ret)
wrapper for the function pg_NumRows
get_poste_analytique($p_order="")
get all the poste related to the current Analytic plan
get_list($p_order=" order by pa_name")
get the list of all existing PA
static hidden($p_array)
return an HTML string containing hidden input type to hold the differant PA_ID
header()
show the header for a table for PA
Concerns the Analytic plan (table plan_analytique)
static escape_string($p_string)
wrapper for the function pg_escape_string
static test_me()
static fetch_array($ret, $p_indice=0)
wrapper for the function pg_fetch_array
contains the object for the poste_analytique (table poste_analytique)
function clone(object)
$from_poste name
$all
__construct($p_cn, $p_id=0)
$count
Definition: modele.inc.php:255
static connect()
$SecUser db
static hidden($p_name, $p_value, $p_id="")
$p
Definition: array.php:34
$obj