Plugins  LAST
 All Data Structures Files Functions Variables Pages
class_copro_key.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of NOALYSS.
5  *
6  * NOALYSS is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * NOALYSS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with NOALYSS; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 /* $Revision$ */
21 
22 // Copyright (c) 2002 Author Dany De Bontridder dany@alchimerys.be
23 require_once 'class_copro_appel_fond_detail.php';
24 /**
25  * @file
26  * @brief Gère les clefs
27  *
28  */
29 class Copro_key
30 {
31  function verify ($p_array,$b_dupl=true)
32  {
33  global $cn;
34  extract ($p_array);
35  if (strlen(trim ($cr_name))==0)
36  throw new Exception("Le nom est vide");
37  if ($b_dupl )
38  {
39  $dupl=$cn->count_sql("select * from coprop.clef_repartition where cr_name=$1",array($cr_name));
40  if ( $dupl >0 )
41  throw new Exception("Une clef avec ce nom existe déja");
42  }
43 
44  }
45 
46  function insert($p_array)
47  {
48  global $cn;
49  extract($p_array);
50  try
51  {
52  $this->verify($p_array);
53  $cn->start();
54  $this->cr_id = $cn->get_value("insert into coprop.clef_repartition(cr_note,cr_name,cr_tantieme)
55  values($1,$2,$3) returning cr_id", array( strip_tags($cr_note), strip_tags($cr_name),$cr_tantieme));
56  for ($i = 0; $i < count($f_id); $i++)
57  {
58  if (${"part" . $f_id[$i]} == '')
59  ${"part" . $f_id[$i]} = 0;
60  $cn->exec_sql("insert into coprop.clef_repartition_detail(lot_fk,crd_amount,cr_id) values($1,$2,$3)", array($f_id[$i], ${"part" . $f_id[$i]}, $this->cr_id));
61  }
62  $cn->commit();
63  }
64  catch (Exception $exc)
65  {
66  $cn->rollback();
67  echo $exc->getTraceAsString();
68  }
69  }
70 
71  function update($p_array)
72  {
73  global $cn;
74  extract($p_array);
75  try
76  {
77  $this->verify($p_array,false);
78  $cn->start();
79  $cn->exec_sql("update coprop.clef_repartition set
80  cr_note=$1,cr_name=$2,cr_tantieme=$3
81  where cr_id=$4",
82  array( strip_tags($cr_note), strip_tags($cr_name),$cr_tantieme,$this->cr_id));
83  $cn->exec_sql("delete from coprop.clef_repartition_detail where cr_id=$1",array($this->cr_id));
84  for ($i = 0; $i < count($f_id); $i++)
85  {
86  if (${"part" . $f_id[$i]} == '')
87  ${"part" . $f_id[$i]} = 0;
88  $cn->exec_sql("insert into coprop.clef_repartition_detail(lot_fk,crd_amount,cr_id) values($1,$2,$3)", array($f_id[$i], ${"part" . $f_id[$i]}, $this->cr_id));
89  }
90  $cn->commit();
91  }
92  catch (Exception $exc)
93  {
94  $cn->rollback();
95  echo $exc->getTraceAsString();
96  }
97  }
98  function load()
99  {
100  global $cn;
101  $array=$cn->get_array("select * from coprop.clef_repartition where
102  cr_id=$1",array($this->cr_id));
103  if ( $cn->count() == 1 )
104  {
105  foreach ( array("cr_id","cr_name","cr_note","cr_tantieme") as $k=>$e) {
106  $this->$e=$array[0][$e];
107  }
108  }
109  }
110  function get_detail()
111  {
112  global $cn;
113  $array=$cn->get_array("select * from coprop.clef_repartition_detail
114  where cr_id=$1",array($this->cr_id));
115  return $array;
116  }
117 
118 }
119 
120 ?>
update($p_array)
verify($p_array, $b_dupl=true)
if(isset($_POST['remove'])) $array
insert($p_array)
global $cn