9 require_once NOALYSS_INCLUDE.
'/lib/class_database.php';
10 require_once NOALYSS_INCLUDE.
'/lib/ac_common.php';
16 protected $variable=array(
"id"=>
"ad_id",
"desc"=>
"ad_text",
"type"=>
"ad_type",
"size"=>
"ad_size",
"extra"=>
"ad_extra");
34 if ( array_key_exists($p_string,$this->variable) )
36 $idx=$this->variable[$p_string];
40 throw new Exception (__FILE__.
":".__LINE__.$p_string.
'Erreur attribut inexistant');
44 if ( array_key_exists($p_string,$this->variable) )
46 $idx=$this->variable[$p_string];
50 throw new Exception (__FILE__.
":".__LINE__.$p_string.
'Erreur attribut inexistant');
54 return var_export($this,
true);
60 if ( strlen(
trim($this->ad_text))==0)
61 throw new Exception(
'La description ne peut pas être vide',1);
62 if ( strlen(
trim($this->ad_type))==0)
63 throw new Exception(
'Le type ne peut pas être vide',1);
64 $this->ad_type=strtolower($this->ad_type);
65 if ( in_array($this->ad_type,array(
'date',
'text',
'numeric',
'zone',
'poste',
'card',
'select'))==
false)
66 throw new Exception(
'Le type doit être text, numeric,poste, card, select ou date',1);
67 if (
trim($this->ad_size)==
'' ||
isNumber($this->ad_size)==0||$this->ad_size>22)
69 switch ($this->ad_type)
88 if ( $this->ad_type ==
'numeric' ) {
89 $this->ad_extra=(
trim($this->ad_extra)==
'')?
'2':$this->ad_extra;
90 if (
isNumber($this->ad_extra) == 0)
throw new Exception (
"La précision doit être un chiffre");
93 if ( $this->ad_type ==
'select')
95 if (
trim($this->ad_extra)==
"")
throw new Exception (
"La requête SQL est vide ");
96 if ( preg_match(
'/^\h*select/i',$this->ad_extra) == 0)
throw new Exception (
"La requête SQL doit commencer par SELECT ");
99 $this->
cn->exec_sql($this->ad_extra);
100 }
catch (Exception
$e)
102 throw new Exception (
"La requête SQL ".
h($this->ad_extra).
" est invalide ");
110 if ( $this->ad_id == 0 )
125 $sql=
"select * from attr_def where $cond order by ad_text";
127 $sql=
"select * from attr_def order by ad_text";
133 if (
$size == 0 )
return $aobj;
134 for ($i=0;$i<
$size;$i++)
150 $sql=
"insert into attr_def(ad_text
151 ,ad_type,ad_size,ad_extra
156 $this->ad_id=$this->
cn->get_value(
158 array( $this->ad_text,$this->ad_type,$this->ad_size,$this->ad_extra
161 }
catch (Exception
$e)
173 if ( $this->ad_id < 9000)
return;
175 $sql=
" update attr_def set ad_text = $1
176 ,ad_type = $2,ad_size=$4,ad_extra=$5
182 ,$this->ad_id,$this->ad_size,$this->ad_extra)
184 }
catch (Exception
$e)
199 ,ad_type,ad_size,ad_extra
200 from attr_def where ad_id=$1";
202 $res=$this->
cn->get_array(
207 if ( count(
$res) == 0 )
221 public function delete()
223 if ($this->ad_id < 9000)
return;
224 $sql=$this->
cn->exec_sql(
"delete from fiche_detail where ad_id=$1 ",
225 array($this->ad_id));
227 $sql=
"delete from jnt_fic_attr where ad_id=$1";
228 $res=$this->
cn->exec_sql(
$sql,array($this->ad_id));
230 $sql=
"delete from attr_def where ad_id=$1";
231 $res=$this->
cn->exec_sql(
$sql,array($this->ad_id));
241 echo
h2info(
'Test object vide');
245 echo
h2info(
'Test object NON vide');
246 $obj->set_parameter(
'j_id',3);
251 $obj->set_parameter(
'j_qcode',
'NOUVEAU CODE');
257 $obj->set_parameter(
'j_id',0);
264 echo ((
$obj->load()==0)?
'Trouve':
'non trouve');
274 if ( $o1->ad_id > $o2->ad_id )
return 1;
275 if ( $o1->ad_id == $o2->ad_id )
return 0;
static test_me()
Unit test for the class.
set_parameter($p_string, $p_value)
__construct($p_cn, $p_id=0)
Manage the table attr_def.
seek($cond='', $p_array=null)
retrieve array of object thanks a condition
static sort_by_id($o1, $o2)
used with a usort function, to sort an array of Attribut on the attribut_id (ad_id) ...
function trim(s)
remove trailing and heading space
h($p_string)
to protect again bad characters which can lead to a cross scripting attack the string to be diplayed ...
This class allow you to connect to the postgresql database, execute sql, retrieve data...