noalyss Version-9
anc_plan.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
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 */
29require_once NOALYSS_INCLUDE.'/constant.php';
30require_once NOALYSS_INCLUDE.'/database/poste_analytique_sql.class.php';
31
33{
34 var $db; /*!<database connection */
35 var $name; /*!< name plan_analytique.pa_name */
36 var $description; /*!< description of the PA plan_analytique.pa_description*/
37 var $id; /*!< id = plan_analytique.pa_id */
38
39 function __construct($p_cn,$p_id=0)
40 {
41 $this->db=$p_cn;
42 $this->id=$p_id;
43 $this->name="";
44 $this->description="";
45 $this->get();
46 }
47 /*!\brief get the list of all existing PA
48 * \return an array of PA (not object)
49 *
50 */
51 function get_list($p_order=" order by pa_name")
52 {
53 $array=array();
54 $sql="select pa_id as id,pa_name as name,".
55 "pa_description as description from plan_analytique $p_order";
56 $ret=$this->db->exec_sql($sql);
58 if ($array == FALSE ) return array();
59 return $array;
60 }
61
62 function get()
63 {
64 if ( $this->id==0) return;
65
66 $sql="select pa_name,pa_description from plan_analytique where pa_id=$1";
67 $ret= $this->db->exec_sql($sql,array($this->id));
68 if ( Database::num_row($ret) == 0)
69 {
70 return;
71 }
73 $this->name=$a['pa_name'];
74 $this->description=$a['pa_description'];
75
76 }
77
78 function delete()
79 {
80 if ( $this->id == 0 ) return;
81 $this->db->exec_sql("delete from plan_analytique where pa_id=$1",array($this->id));
82 }
83
84 function update()
85 {
86 if ( $this->id==0) return;
87 $name=sql_string($this->name);
88 if ( strlen($name) == 0)
89 return;
90
91 $description=sql_string($this->description);
92 $this->db->exec_sql("update plan_analytique set pa_name=$1,
93 pa_description=$2 where pa_id=$3",array($name,$description,$this->id));
94 }
95
96 function add()
97 {
98 $name=sql_string($this->name);
99 if ( strlen($name) == 0)
100 return;
101 if ( $this->isAppend() == false) return;
102 $description=sql_string($this->description);
103 $this->db->exec_sql("insert into plan_analytique(pa_name,pa_description)".
104 " values ($1,$2 )"
105 ,array($name,$description));
106 $this->id=$this->db->get_current_seq('plan_analytique_pa_id_seq');
107
108 }
109 function form()
110 {
112 $wName=new IText('pa_name',$this->name,"pa_name");
113 $iName=new Inplace_Edit($wName);
114 $iName->set_callback("ajax_misc.php");
115 $iName->add_json_param("gDossier",$dossier_id);
116 $iName->add_json_param("action","anc_updatedescription");
117 $iName->add_json_param("op","anc_updatedescription");
118 $iName->add_json_param("id",$this->id);
119
120
121 $wDescription=new IText('pa_description',$this->description,"pa_description");
122 $wDescription->size=50;
123 if ( $this->description == "") $wDescription->value=_("Aucune description");
124 $iDescription=new Inplace_Edit($wDescription);
125 $iDescription->add_json_param("gDossier",$dossier_id);
126 $iDescription->add_json_param("op","anc_updatedescription");
127 $iDescription->add_json_param("action","anc_updatedescription");
128 $iDescription->set_callback("ajax_misc.php");
129 $iDescription->add_json_param("id",$this->id);
130
131
132 $wId=new IHidden("pa_id",$this->id);
133 $ret="<TABLE>";
134 $ret.='<tr>'.td(_('Nom')).'<td>'.$iName->input().'</td>'.'</tr>';
135 $ret.="<tr>".td(_('Description')).'<td>'.$iDescription->input().'</td>'."</tr>";
136 $ret.="</table>";
137 $ret.=$wId->input();
138 return $ret;
139 }
140 /**
141 * @brief add a new plan
142 */
143 function form_new()
144 {
145 $wName=new IText("pa_name");
146 $wDescription=new IText("pa_description");
147 $wDescription->size=80;
148
149 $ret="<TABLE>";
150 $ret.='<tr>'.td(_('Nom')).'<td>'.$wName->input().'</td>'.'</tr>';
151 $ret.="<tr>".td(_('Description')).'<td>'.$wDescription->input().'</td>'."</tr>";
152 $ret.="</table>";
153 return $ret;
154
155
156 }
157 function isAppend()
158 {
159 $count=$this->db->get_value("select count(pa_id) from plan_analytique");
160
161 if ( $count > 10 )
162 return false;
163 else
164 return true;
165 }
166 /*!\brief show the header for a table for PA
167 * \return string like <th>name</th>...
168 */
169 function header()
170 {
171 $res="";
172 $a_plan=$this->get_list(" order by pa_id");
173 if ( empty($a_plan)) return "";
174 foreach ($a_plan as $r_plan)
175 {
176 $res.="<th>".h($r_plan['name'])."</th>";
177 }
178 return $res;
179 }
180 function count()
181 {
182 $a=$this->db->count_sql("select pa_id from plan_analytique");
183 return $a;
184 }
185 function exist()
186 {
187 $a=$this->db->count_sql("select pa_id from plan_analytique where pa_id=$1",
188 array($this->pa_id));
189
190 return ($a==0)?false:true;
191
192 }
193 /**
194 *@brief return an HTML string containing hidden input type to
195 * hold the differant PA_ID
196 *@param $p_array contains a array, it is the result of the fct
197 * Anc_Plan::get_list
198 *@return html string
199 *@see Anc_Plan::get_list
200 */
201 static function hidden($p_array)
202 {
203 $r='';
204 for ($i_anc=0;$i_anc <count($p_array);$i_anc++)
205 {
206 $r.=HtmlInput::hidden('pa_id[]',$p_array[$i_anc]['id']);
207 }
208 return $r;
209 }
210 static function test_me()
211 {
213 echo "<h1>Plan analytique : test</h1>";
214 echo "clean";
215 $cn->exec_sql("delete from plan_analytique");
216
217 $p=new Anc_Plan($cn);
218 echo "<h2>Add</h2>";
219 $p->name="Nouveau 1";
220 $p->description="C'est un test";
221 echo "Add<hr>";
222 $p->add();
223 $p->name="Nouveau 2";
224 $p->add();
225 $pa_id=$p->id;
226 echo $p->id."/";
227 $p->name="Nouveau 3";
228 $p->add();
229 echo $p->id."/";
230
231
232 $p->name="Nouveau 4";
233 $p->add();
234 echo $p->id;
235
236 echo "<h2>get</h2>";
237 $p->get();
238 var_dump($p);
239 echo "<h2>Update</h2> ";
240 $p->name="Update ";
241 $p->description="c'est change";
242 $p->update();
243 $p->get();
244 var_dump($p);
245 echo "<h2>get_list</h2>";
246 $a=$p->get_list();
247 var_dump($a);
248 echo "<h2>delete </h2>";
249 $p->delete();
250
251
252 }
253}
254
255?>
sql_string($p_string)
Fix the problem with the quote char for the database.
Definition: ac_common.php:511
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$anc pa_id
$dossier_id
Definition: ajax_poste.php:43
$p
Definition: array.php:34
$from_poste name
Concerns the Analytic plan (table plan_analytique)
static hidden($p_array)
return an HTML string containing hidden input type to hold the differant PA_ID
get_list($p_order=" order by pa_name")
get the list of all existing PA
__construct($p_cn, $p_id=0)
header()
show the header for a table for PA
form_new()
add a new plan
static test_me()
static fetch_all($ret)
wrapper for the function pg_fetch_all
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static num_row($ret)
wrapper for the function pg_num_rows
static id()
return the 'gDossier' value after a check
static connect()
static hidden($p_name, $p_value, $p_id="")
Html Input.
Html Input.
Definition: itext.class.php:30
Inplace_edit class for ajax update of HtmlInput object.
$count
$SecUser db