From a46594562ac36e0f5ebac524e037124ed27fa1ea Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Fri, 6 Jan 2012 11:03:56 +0000 Subject: [PATCH] ajout de select dans les fiches --- include/card_attr.inc.php | 11 +++++++++-- include/class_fiche.php | 23 +++++++++++++++++++---- include/class_fiche_attr.php | 18 +++++++++--------- include/class_fiche_def.php | 17 +++++++++-------- sql/upgrade.sql | 3 +-- 5 files changed, 47 insertions(+), 25 deletions(-) diff --git a/include/card_attr.inc.php b/include/card_attr.inc.php index dad4b46b0..2a7190664 100644 --- a/include/card_attr.inc.php +++ b/include/card_attr.inc.php @@ -38,6 +38,7 @@ if ( isset($_POST['save'])) $ad_text=$_POST['desc']; $ad_type=$_POST['type']; $ad_size=$_POST['size']; + $ad_extra=$_POST['extra']; try { $cn->start(); @@ -47,6 +48,7 @@ if ( isset($_POST['save'])) $fa->set_parameter('desc',$ad_text[$e]); $fa->set_parameter('type',$ad_type[$e]); $fa->set_parameter('size',$ad_size[$e]); + $fa->set_parameter('extra',$ad_extra[$e]); if ( trim($ad_text[$e])!='' && trim($ad_type[$e])!='') $fa->save(); } @@ -69,6 +71,7 @@ $desc=new IText('desc[]'); $desc->size=50; $size=new INum('size[]'); $size->size=5; +$extra=new IText('extra[]'); $select_type->value=array( array('value'=>'text','label'=>'Texte'), @@ -77,8 +80,7 @@ $select_type->value=array( array('value'=>'zone','label'=>'Zone de texte'), array('value'=>'poste','label'=>'Poste Comptable'), array('value'=>'card','label'=>'Fiche'), - - + array('value'=>'select','label'=>'Selection') ); $remove=new IButton('rmfa'); $remove->label='Effacer'; @@ -108,6 +110,7 @@ for ($e=0;$einput()); $r.=td($select_type->input()); $r.=td($size->input()); + $r.=td($extra->input()); $remove->javascript=sprintf('if ( confirm(\'Vous confirmez ?\')) { removeCardAttribut(%d,%d,\'tb_rmfa\',this);}', $row->get_parameter('id'),$gDossier); @@ -119,10 +122,12 @@ for ($e=0;$ereadOnly=true; $desc->readOnly=true; $size->readOnly=true; + $extra->readOnly=true; $r.=td($desc->input().HtmlInput::hidden('type[]','')); $r.=td($select_type->input()); $r.=td($size->input()); + $r.=td($extra->input()); $r.=td(""); } @@ -135,12 +140,14 @@ for ($e=0;$ereadOnly=false; $select_type->readOnly=false; $size->readOnly=false; +$extra->readOnly=false; $desc->value=''; $select_type->selected=-1; $r=td(HtmlInput::hidden('ad_id[]','0')); $r.=td($desc->input()); $r.=td($select_type->input()); $r.=td($size->input()); +$r.=td($extra->input()); echo tr($r); echo ''; diff --git a/include/class_fiche.php b/include/class_fiche.php index be3715657..356e10e2e 100644 --- a/include/class_fiche.php +++ b/include/class_fiche.php @@ -197,6 +197,7 @@ class Fiche $t->ad_type=$f->ad_type; $t->ad_size=$f->ad_size; $t->ad_id=$f->ad_id; + $t->ad_extra=$f->ad_extra; $this->attribut[$Max]=$t; $Max++; } // if flag == 0 @@ -344,8 +345,8 @@ class Fiche if ($this->id==0) return NOTFOUND; // object is not in memory we need to look into the database $sql="select ad_value from fiche_detail - where f_id=".sql_string($this->id)." and ad_id=".$p_ad_id; - $Res=$this->cn->exec_sql($sql); + where f_id= $1 and ad_id= $2 "; + $Res=$this->cn->exec_sql($sql,array($this->id,$p_ad_id)); $row=Database::fetch_all($Res); // if not found return error if ( $row == false ) @@ -505,6 +506,10 @@ class Fiche $w->table=1; $bulle=HtmlInput::infobulle(14); break; + case 'select': + $w=new ISelect("av_text".$attr->ad_id); + $w->value=$this->cn->make_array($attr->ad_extra); + break; case 'card': $w=new ICard("av_text".$attr->ad_id); // filter on frd_id @@ -626,18 +631,22 @@ class Fiche case 'text': $w=new IText('av_text'.$r->ad_id); $w->size=$r->ad_size; + $w->value=$r->av_text; break; case 'numeric': $w=new INum('av_text'.$r->ad_id); $w->size=$r->ad_size; + $w->value=$r->av_text; break; case 'date': $w=new IDate('av_text'.$r->ad_id); + $w->value=$r->av_text; break; case 'zone': $w=new ITextArea('av_text'.$r->ad_id); $w->width=$r->ad_size; $w->heigh=2; + $w->value=$r->av_text; break; case 'poste': $w=new IPoste("av_text".$r->ad_id); @@ -646,6 +655,7 @@ class Fiche $w->width=$r->ad_size; $w->table=0; $bulle=HtmlInput::infobulle(14); + $w->value=$r->av_text; break; case 'card': $w=new ICard("av_text".$r->ad_id); @@ -663,8 +673,13 @@ class Fiche $w->set_attribute('label',"av_text".$r->ad_id."_label"); $msg=$w->search(); $msg.=$label->input(); + $w->value=$r->av_text; break; - + case 'select': + $w=new ISelect(); + $w->value=$this->cn->make_array($attr->ad_extra); + $w->selected=$r->av_text; + break; default: var_dump($r); throw new Exception("Type invalide"); @@ -672,7 +687,7 @@ class Fiche $w->table=0; } } - $w->value=$r->av_text; + $w->name="av_text".$r->ad_id; $w->readonly=$p_readonly; diff --git a/include/class_fiche_attr.php b/include/class_fiche_attr.php index eb7bae4ad..02e3e419d 100644 --- a/include/class_fiche_attr.php +++ b/include/class_fiche_attr.php @@ -15,7 +15,7 @@ class Fiche_Attr { /* example private $variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0); */ - protected $variable=array("id"=>"ad_id","desc"=>"ad_text","type"=>"ad_type","size"=>"ad_size"); + protected $variable=array("id"=>"ad_id","desc"=>"ad_text","type"=>"ad_type","size"=>"ad_size","extra"=>"ad_extra"); function __construct ($p_cn,$p_id=0) { $this->cn=$p_cn; @@ -64,8 +64,8 @@ class Fiche_Attr if ( strlen(trim($this->ad_type))==0) throw new Exception('Le type ne peut pas être vide',1); $this->ad_type=strtolower($this->ad_type); - if ( in_array($this->ad_type,array('date','text','numeric','zone','poste','card'))==false) - throw new Exception('Le type doit être text, numeric,poste, card ou date',1); + if ( in_array($this->ad_type,array('date','text','numeric','zone','poste','card','select'))==false) + throw new Exception('Le type doit être text, numeric,poste, card, select ou date',1); if ( trim($this->ad_size)=='' || isNumber($this->ad_size)==0||$this->ad_size>22) { switch ($this->ad_type) @@ -130,14 +130,14 @@ class Fiche_Attr $this->verify(); /* please adapt */ $sql="insert into attr_def(ad_text - ,ad_type,ad_size + ,ad_type,ad_size,ad_extra ) values ($1 - ,$2,$3 + ,$2,$3,$4 ) returning ad_id"; $this->ad_id=$this->cn->get_value( $sql, - array( $this->ad_text,$this->ad_type,$this->ad_size + array( $this->ad_text,$this->ad_type,$this->ad_size,$this->ad_extra ) ); @@ -149,13 +149,13 @@ class Fiche_Attr if ( $this->ad_id < 9000) return; /* please adapt */ $sql=" update attr_def set ad_text = $1 - ,ad_type = $2,ad_size=$4 + ,ad_type = $2,ad_size=$4,ad_extra=$5 where ad_id= $3"; $res=$this->cn->exec_sql( $sql, array($this->ad_text ,$this->ad_type - ,$this->ad_id,$this->ad_size) + ,$this->ad_id,$this->ad_size,$this->ad_extra) ); } @@ -167,7 +167,7 @@ class Fiche_Attr { $sql="select ad_text - ,ad_type + ,ad_type,ad_size,ad_extra from attr_def where ad_id=$1"; /* please adapt */ $res=$this->cn->get_array( diff --git a/include/class_fiche_def.php b/include/class_fiche_def.php index e327c8b7d..f2231823e 100644 --- a/include/class_fiche_def.php +++ b/include/class_fiche_def.php @@ -88,6 +88,7 @@ class Fiche_Def $t->jnt_order=$row['jnt_order']; $t->ad_size=$row['ad_size']; $t->ad_type=$row['ad_type']; + $t->ad_extra=$row['ad_extra']; $this->attribut[$i]=clone $t; } return $this->attribut; @@ -296,7 +297,7 @@ class Fiche_Def $sql="select f_id,ad_value from fiche join fiche_detail using(f_id) - where ad_id=1 and fd_id=".$this->id." order by 2"; + where ad_id=1 and fd_id=$1 order by 2"; // we use jrn_navigation_bar if ($step == 1 && $_SESSION['g_pagesize'] != -1 ) @@ -306,7 +307,7 @@ class Fiche_Def $sql.=" offset $offset limit $step"; } - $Ret=$this->cn->get_array($sql); + $Ret=$this->cn->get_array($sql,array($this->id)); return $Ret; } @@ -601,17 +602,17 @@ class Fiche_Def foreach ($array as $ch) { $this->cn->start(); - $sql="delete from jnt_fic_attr where fd_id=".$this->id. - " and ad_id=".$ch; - $this->cn->exec_sql($sql); + $sql="delete from jnt_fic_attr where fd_id=$1 ". + " and ad_id=$2"; + $this->cn->exec_sql($sql,array($this->id,$ch)); $sql="delete from fiche_detail where jft_id in ( select ". " jft_id from fiche_Detail ". " join fiche using(f_id) ". " where ". - "fd_id = ".$this->id." and ". - "ad_id=".$ch.")"; - $this->cn->exec_sql($sql); + "fd_id = $1 and ". + "ad_id=$2)"; + $this->cn->exec_sql($sql,array($this->id,$ch)); $this->cn->commit(); } diff --git a/sql/upgrade.sql b/sql/upgrade.sql index e9b4349fb..98aedbc45 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -1,2 +1 @@ -update jrnx set j_text = null from jrn where jr_grpt_id=j_grpt and j_text=jr_comment; -insert into parameter (pr_id,pr_value) values ('MY_UPDLAB','N'); +alter table attr_def add ad_extra text ; \ No newline at end of file