noalyss  Version-9
fiche_attr.class.php
Go to the documentation of this file.
1 <?php
2 
3 //This file is part of NOALYSS and is under GPL
4 //see licence.txt
5 /**
6  * @brief Manage the table attr_def
7  *
8  *
9  */
10 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
11 require_once NOALYSS_INCLUDE."/database/attr_def_sql.class.php";
12 
13 class Fiche_Attr extends Attr_def_SQL
14 {
15  /* example private $variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0); */
16 
17  function __construct($p_cn, $p_id=0)
18  {
19  parent::__construct($p_cn, $p_id);
20  }
21 
22  public function get_parameter($p_string)
23  {
24  return $this->getp($p_string);
25  }
26 
27  public function set_parameter($p_string, $p_value)
28  {
29  $this->setp($p_string, $p_value);
30  }
31 
32  public function verify()
33  {
34  // Verify that the elt we want to add is correct
35  /* verify only the datatype */
36  if (strlen(trim($this->ad_text))==0)
37  throw new Exception('La description ne peut pas être vide', 1);
38  if (strlen(trim($this->ad_type))==0)
39  throw new Exception('Le type ne peut pas être vide', 1);
40  $this->ad_type=strtolower($this->ad_type);
41  if (in_array($this->ad_type, array('date', 'text', 'numeric', 'zone', 'poste', 'card', 'select','check'))==false)
42  throw new Exception('Le type doit être text, numeric,poste, card, select ou date', 1);
43  if (trim($this->ad_size)==''||isNumber($this->ad_size)==0||$this->ad_size>22)
44  {
45  switch ($this->ad_type)
46  {
47  case 'text':
48  $this->ad_size=22;
49  break;
50  case 'numeric':
51  $this->ad_size=9;
52  break;
53  case 'date':
54  $this->ad_size=8;
55  break;
56  case 'zone':
57  $this->ad_size=22;
58  break;
59 
60  default:
61  $this->ad_size=22;
62  }
63  }
64  if ($this->ad_type=='numeric')
65  {
66  $this->ad_extra=(trim($this->ad_extra)=='')?'2':$this->ad_extra;
67  if (isNumber($this->ad_extra)==0)
68  throw new Exception("La précision doit être un chiffre");
69  }
70  if ($this->ad_type=='select')
71  {
72  if (trim($this->ad_extra)=="")
73  throw new Exception("La requête SQL est vide ");
74  if (preg_match('/^\h*select/i', $this->ad_extra)==0)
75  throw new Exception("La requête SQL doit commencer par SELECT ");
76  try
77  {
78 
79  $this->cn->exec_sql($this->ad_extra);
80  }
81  catch (Exception $e)
82  {
83  record_log($e);
84  throw new Exception("La requête SQL ".h($this->ad_extra)." est invalide ");
85  }
86  }
87  }
88 
89 
90  public function update()
91  {
92  try
93  {
94  $this->verify();
95  if ($this->ad_id<9000)
96  return;
97  /* please adapt */
98  parent::update();
99  }
100  catch (Exception $e)
101  {
102  record_log($e);
103  throw $e;
104  }
105  }
106 
107  public function delete()
108  {
109  if ($this->ad_id<9000)
110  return;
111  $sql=$this->cn->exec_sql("delete from fiche_detail where ad_id=$1 ", array($this->ad_id));
112 
113  $sql="delete from jnt_fic_attr where ad_id=$1";
114  $res=$this->cn->exec_sql($sql, array($this->ad_id));
115 
116  $sql="delete from attr_def where ad_id=$1";
117  $res=$this->cn->exec_sql($sql, array($this->ad_id));
118  }
119 
120  /* !
121  * @brief used with a usort function, to sort an array of Attribut on the attribut_id (ad_id)
122  */
123 
124  static function sort_by_id($o1, $o2)
125  {
126  if ($o1->ad_id>$o2->ad_id)
127  return 1;
128  if ($o1->ad_id==$o2->ad_id)
129  return 0;
130  return -1;
131  }
132 
133  public function save()
134  {
135 
136  /* please adapt */
137  if ($this->ad_id < 1)
138  {
139  $this->ad_id=-1;
140  $this->insert();
141  }
142  else
143  $this->update();
144  }
145  public function to_array($prefix="")
146  {
147 
148  $array=array();
149  foreach ($this->name as $key=> $value)
150  {
151  $nkey=$prefix.$value;
152  $array[$nkey]=$this->$value;
153 // $nkey=$prefix.$key;
154 // $array[$nkey]=$this->$value;
155 //
156  }
157  tracedebug("card_attribute.log",$array);
158  return $array;
159  }
160 }
161 
162 //Fiche_Attr::test_me();
163 
164 
165 
$prefix
$prefix
Definition: ajax_search_display_tag.php:30
h
h( $row[ 'oa_description'])
Definition: ajax_anc_detail_operation.php:46
$e
$e
Definition: result_cat_card_summary.php:26
Fiche_Attr\sort_by_id
static sort_by_id($o1, $o2)
Definition: fiche_attr.class.php:124
cn
$input_from cn
Definition: balance.inc.php:66
Fiche_Attr
Manage the table attr_def.
Definition: fiche_attr.class.php:13
Fiche_Attr\__construct
__construct($p_cn, $p_id=0)
Definition: fiche_attr.class.php:17
Data_SQL\setp
setp($p_string, $p_value)
set the value thanks the alias name instead of the colum name
Definition: data_sql.class.php:159
Table_Data_SQL\insert
insert()
Definition: table_data_sql.class.php:100
$sql
$sql
Definition: ajax_add_concerned_card.php:100
$array
$array
Definition: ajax_add_concerned_card.php:115
Fiche_Attr\to_array
to_array($prefix="")
Turn an object (row) into an array, and the key could be prefixed with $prefix.
Definition: fiche_attr.class.php:145
name
$from_poste name
Definition: balance.inc.php:159
$value
$value
Definition: export_document.php:41
isNumber
isNumber($p_int)
Definition: ac_common.php:218
Attr_def_SQL
abstract of the table public.attr_def
Definition: attr_def_sql.class.php:32
Fiche_Attr\set_parameter
set_parameter($p_string, $p_value)
Definition: fiche_attr.class.php:27
Fiche_Attr\save
save()
Insert or update : if the row already exists, update otherwise insert.
Definition: fiche_attr.class.php:133
Fiche_Attr\get_parameter
get_parameter($p_string)
Definition: fiche_attr.class.php:22
Fiche_Attr\verify
verify()
Definition: fiche_attr.class.php:32
Fiche_Attr\update
update()
Definition: fiche_attr.class.php:90
$p_id
$p_id
Definition: ajax_accounting.php:33
$res
$res
Definition: ajax_preference.php:49
record_log
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1400
Data_SQL\getp
getp($p_string)
set the value thanks the alias name instead of the colum name
Definition: data_sql.class.php:145