00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 require_once('class_database.php');
00032 require_once('ac_common.php');
00033
00034
00035
00036
00037 class Jrn_Def_sql
00038 {
00039
00040
00041 protected $variable = array(
00042 "jrn_def_id" => "jrn_def_id",
00043 "jrn_def_name" => "jrn_def_name"
00044 , "jrn_def_class_deb" => "jrn_def_class_deb"
00045 , "jrn_def_class_cred" => "jrn_def_class_cred"
00046 , "jrn_def_fiche_deb" => "jrn_def_fiche_deb"
00047 , "jrn_def_fiche_cred" => "jrn_def_fiche_cred"
00048 , "jrn_deb_max_line" => "jrn_deb_max_line"
00049 , "jrn_cred_max_line" => "jrn_cred_max_line"
00050 , "jrn_def_ech" => "jrn_def_ech"
00051 , "jrn_def_ech_lib" => "jrn_def_ech_lib"
00052 , "jrn_def_type" => "jrn_def_type"
00053 , "jrn_def_code" => "jrn_def_code"
00054 , "jrn_def_pj_pref" => "jrn_def_pj_pref"
00055 , "jrn_def_bank" => "jrn_def_bank"
00056 , "jrn_def_num_op" => "jrn_def_num_op"
00057 , "jrn_def_description" => "jrn_def_description"
00058 );
00059
00060 function __construct(& $p_cn, $p_id=-1)
00061 {
00062 $this->db = $p_cn;
00063 $this->jrn_def_id = $p_id;
00064
00065 if ($p_id == -1)
00066 {
00067
00068 foreach ($this->variable as $key => $value)
00069 $this->$value = null;
00070 $this->jrn_def_id = $p_id;
00071 }
00072 else
00073 {
00074
00075
00076 $this->load();
00077 }
00078 }
00079
00080 public function get_parameter($p_string)
00081 {
00082 if (array_key_exists($p_string, $this->variable))
00083 {
00084 $idx = $this->variable[$p_string];
00085 return $this->$idx;
00086 }
00087 else
00088 throw new Exception(__FILE__ . ":" . __LINE__ . $p_string . 'Erreur attribut inexistant');
00089 }
00090
00091 public function set_parameter($p_string, $p_value)
00092 {
00093 if (array_key_exists($p_string, $this->variable))
00094 {
00095 $idx = $this->variable[$p_string];
00096 $this->$idx = $p_value;
00097 }
00098 else
00099 throw new Exception(__FILE__ . ":" . __LINE__ . $p_string . 'Erreur attribut inexistant');
00100 }
00101
00102 public function get_info()
00103 {
00104 return var_export($this, true);
00105 }
00106
00107 public function verify_sql()
00108 {
00109
00110
00111 if (trim($this->jrn_def_name) == '')
00112 $this->jrn_def_name = null;
00113 if (trim($this->jrn_def_class_deb) == '')
00114 $this->jrn_def_class_deb = null;
00115 if (trim($this->jrn_def_class_cred) == '')
00116 $this->jrn_def_class_cred = null;
00117 if (trim($this->jrn_def_fiche_deb) == '')
00118 $this->jrn_def_fiche_deb = null;
00119 if (trim($this->jrn_def_fiche_cred) == '')
00120 $this->jrn_def_fiche_cred = null;
00121 if (trim($this->jrn_deb_max_line) == '')
00122 $this->jrn_deb_max_line = null;
00123 if ($this->jrn_deb_max_line !== null && settype($this->jrn_deb_max_line, 'float') == false)
00124 throw new Exception('DATATYPE jrn_deb_max_line $this->jrn_deb_max_line non numerique');
00125 if (trim($this->jrn_cred_max_line) == '')
00126 $this->jrn_cred_max_line = null;
00127 if ($this->jrn_cred_max_line !== null && settype($this->jrn_cred_max_line, 'float') == false)
00128 throw new Exception('DATATYPE jrn_cred_max_line $this->jrn_cred_max_line non numerique');
00129 if (trim($this->jrn_def_ech) == '')
00130 $this->jrn_def_ech = null;
00131 if (trim($this->jrn_def_ech_lib) == '')
00132 $this->jrn_def_ech_lib = null;
00133 if (trim($this->jrn_def_type) == '')
00134 $this->jrn_def_type = null;
00135 if (trim($this->jrn_def_code) == '')
00136 $this->jrn_def_code = null;
00137 if (trim($this->jrn_def_pj_pref) == '')
00138 $this->jrn_def_pj_pref = null;
00139 if (trim($this->jrn_def_bank) == '')
00140 $this->jrn_def_bank = null;
00141 if ($this->jrn_def_bank !== null && settype($this->jrn_def_bank, 'float') == false)
00142 throw new Exception('DATATYPE jrn_def_bank $this->jrn_def_bank non numerique');
00143 if (trim($this->jrn_def_num_op) == '')
00144 $this->jrn_def_num_op = null;
00145 if ($this->jrn_def_num_op !== null && settype($this->jrn_def_num_op, 'float') == false)
00146 throw new Exception('DATATYPE jrn_def_num_op $this->jrn_def_num_op non numerique');
00147 }
00148
00149 public function save($p_string='')
00150 {
00151
00152 if ($this->jrn_def_id == -1)
00153 $this->insert();
00154 else
00155 $this->update();
00156 }
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 public function seek($cond='', $p_array=null)
00167 {
00168 $sql = "select * from public.jrn_def $cond";
00169 $aobj = array();
00170 $ret = $this->db->exec_sql($sql, $p_array);
00171 return $ret;
00172 }
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 public function get_object($p_ret, $idx)
00183 {
00184
00185 $oobj = new Jrn_Def_sql($this->db);
00186 $array = Database::fetch_array($p_ret, $idx);
00187 foreach ($array as $idx => $value)
00188 {
00189 $oobj->$idx = $value;
00190 }
00191 return $oobj;
00192 }
00193
00194 public function insert($p_array=null)
00195 {
00196 if ($this->verify_sql() != 0)
00197 return;
00198 if ($this->jrn_def_id == -1)
00199 {
00200
00201 $sql = "insert into public.jrn_def(jrn_def_name
00202 ,jrn_def_class_deb
00203 ,jrn_def_class_cred
00204 ,jrn_def_fiche_deb
00205 ,jrn_def_fiche_cred
00206 ,jrn_deb_max_line
00207 ,jrn_cred_max_line
00208 ,jrn_def_ech
00209 ,jrn_def_ech_lib
00210 ,jrn_def_type
00211 ,jrn_def_code
00212 ,jrn_def_pj_pref
00213 ,jrn_def_bank
00214 ,jrn_def_num_op
00215 ,jrn_def_description
00216 ) values ($1
00217 ,$2
00218 ,$3
00219 ,$4
00220 ,$5
00221 ,$6
00222 ,$7
00223 ,$8
00224 ,$9
00225 ,$10
00226 ,$11
00227 ,$12
00228 ,$13
00229 ,$14
00230 ,$15
00231 ) returning jrn_def_id";
00232
00233 $this->jrn_def_id = $this->db->get_value(
00234 $sql, array($this->jrn_def_name
00235 , $this->jrn_def_class_deb
00236 , $this->jrn_def_class_cred
00237 , $this->jrn_def_fiche_deb
00238 , $this->jrn_def_fiche_cred
00239 , $this->jrn_deb_max_line
00240 , $this->jrn_cred_max_line
00241 , $this->jrn_def_ech
00242 , $this->jrn_def_ech_lib
00243 , $this->jrn_def_type
00244 , $this->jrn_def_code
00245 , $this->jrn_def_pj_pref
00246 , $this->jrn_def_bank
00247 , $this->jrn_def_num_op
00248 , strip_tags($this->jrn_def_description)
00249 )
00250 );
00251 }
00252 else
00253 {
00254 $sql = "insert into public.jrn_def(jrn_def_name
00255 ,jrn_def_class_deb
00256 ,jrn_def_class_cred
00257 ,jrn_def_fiche_deb
00258 ,jrn_def_fiche_cred
00259 ,jrn_deb_max_line
00260 ,jrn_cred_max_line
00261 ,jrn_def_ech
00262 ,jrn_def_ech_lib
00263 ,jrn_def_type
00264 ,jrn_def_code
00265 ,jrn_def_pj_pref
00266 ,jrn_def_bank
00267 ,jrn_def_num_op
00268 ,jrn_def_id
00269 ,jrn_def_description) values ($1
00270 ,$2
00271 ,$3
00272 ,$4
00273 ,$5
00274 ,$6
00275 ,$7
00276 ,$8
00277 ,$9
00278 ,$10
00279 ,$11
00280 ,$12
00281 ,$13
00282 ,$14
00283 ,$15
00284 ,$16
00285 ) returning jrn_def_id";
00286
00287 $this->jrn_def_id = $this->db->get_value(
00288 $sql, array($this->jrn_def_name
00289 , $this->jrn_def_class_deb
00290 , $this->jrn_def_class_cred
00291 , $this->jrn_def_fiche_deb
00292 , $this->jrn_def_fiche_cred
00293 , $this->jrn_deb_max_line
00294 , $this->jrn_cred_max_line
00295 , $this->jrn_def_ech
00296 , $this->jrn_def_ech_lib
00297 , $this->jrn_def_type
00298 , $this->jrn_def_code
00299 , $this->jrn_def_pj_pref
00300 , $this->jrn_def_bank
00301 , $this->jrn_def_num_op
00302 , $this->jrn_def_id
00303 , strip_tags($this->jrn_def_description))
00304 );
00305 }
00306 }
00307
00308 public function update($p_string='')
00309 {
00310 if ($this->verify_sql() != 0)
00311 return;
00312
00313 $sql = " update public.jrn_def set jrn_def_name = $1
00314 ,jrn_def_class_deb = $2
00315 ,jrn_def_class_cred = $3
00316 ,jrn_def_fiche_deb = $4
00317 ,jrn_def_fiche_cred = $5
00318 ,jrn_deb_max_line = $6
00319 ,jrn_cred_max_line = $7
00320 ,jrn_def_ech = $8
00321 ,jrn_def_ech_lib = $9
00322 ,jrn_def_type = $10
00323 ,jrn_def_code = $11
00324 ,jrn_def_pj_pref = $12
00325 ,jrn_def_bank = $13
00326 ,jrn_def_num_op = $14
00327 ,jrn_def_description = $15
00328 where jrn_def_id= $16";
00329 $res = $this->db->exec_sql(
00330 $sql, array($this->jrn_def_name
00331 , $this->jrn_def_class_deb
00332 , $this->jrn_def_class_cred
00333 , $this->jrn_def_fiche_deb
00334 , $this->jrn_def_fiche_cred
00335 , $this->jrn_deb_max_line
00336 , $this->jrn_cred_max_line
00337 , $this->jrn_def_ech
00338 , $this->jrn_def_ech_lib
00339 , $this->jrn_def_type
00340 , $this->jrn_def_code
00341 , $this->jrn_def_pj_pref
00342 , $this->jrn_def_bank
00343 , $this->jrn_def_num_op
00344 , strip_tags($this->jrn_def_description)
00345 , $this->jrn_def_id)
00346 );
00347 }
00348
00349
00350
00351
00352
00353 public function load()
00354 {
00355
00356 $sql = "select jrn_def_name
00357 ,jrn_def_class_deb
00358 ,jrn_def_class_cred
00359 ,jrn_def_fiche_deb
00360 ,jrn_def_fiche_cred
00361 ,jrn_deb_max_line
00362 ,jrn_cred_max_line
00363 ,jrn_def_ech
00364 ,jrn_def_ech_lib
00365 ,jrn_def_type
00366 ,jrn_def_code
00367 ,jrn_def_pj_pref
00368 ,jrn_def_bank
00369 ,jrn_def_num_op
00370 ,jrn_def_description
00371 from public.jrn_def where jrn_def_id=$1";
00372
00373 $res = $this->db->get_array(
00374 $sql, array($this->jrn_def_id)
00375 );
00376
00377 if (count($res) == 0)
00378 {
00379
00380 foreach ($this->variable as $key => $value)
00381 $this->$key = '';
00382
00383 return -1;
00384 }
00385 foreach ($res[0] as $idx => $value)
00386 {
00387 $this->$idx = $value;
00388 }
00389 return 0;
00390 }
00391
00392 public function delete()
00393 {
00394 $sql = "delete from public.jrn_def where jrn_def_id=$1";
00395 $res = $this->db->exec_sql($sql, array($this->jrn_def_id));
00396 }
00397
00398
00399
00400
00401 static function test_me()
00402 {
00403 }
00404
00405 }
00406
00407
00408 ?>