From ba36e30de92dfad8562f4af520618b325f24dbbd Mon Sep 17 00:00:00 2001
From: sparkyx
Posgresql est une base de données très rapide, cependant, il vous faudra configurer
+pour pouvoir en bénéficier
+
Vous pouvez ajouter la sécurité à votre server Postgresql en changeant dans pg_hba.conf. Mais avant de faire cela, ajoutez un mot de passe à diff --git a/html/fiche_csv.php b/html/fiche_csv.php index 55e55222a..9f36aa44d 100644 --- a/html/fiche_csv.php +++ b/html/fiche_csv.php @@ -42,25 +42,19 @@ if ( isset ($_POST['fd_id'])) { $fiche_def=new fiche_def($cn,$_POST['fd_id']); $fiche=new fiche($cn); $e=$fiche->GetByType($fiche_def->id); - // var_dump($e); - $old=-1; - foreach ($e as $detail) { - if ($old == -1 ) { - $old=$detail->id; - - $fiche_def->GetAttribut(); - foreach ($fiche_def->attribut as $attribut) - printf("%s\t",$attribut); - printf("\n"); - } - if ( $old != $detail->id) { - $old=$detail->id; - printf("\n"); - } - printf ("%s\t",$detail->attribut_value); - } - + // Heading + $fiche_def->GetAttribut(); + foreach ($fiche_def->attribut as $attribut) + printf("%s\t",$attribut->ad_text); printf("\n"); + + foreach ($e as $detail) { + foreach ( $detail->attribut as $dattribut ) + printf ("%s\t",$dattribut->av_text); + printf("\n"); + } + + } exit; ?> diff --git a/include/class_attribut.php b/include/class_attribut.php new file mode 100644 index 000000000..25dee9b4d --- /dev/null +++ b/include/class_attribut.php @@ -0,0 +1,55 @@ + +/* + * This file is part of PhpCompta. + * + * PhpCompta is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * PhpCompta is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with PhpCompta; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* $Revision$ */ +// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr +class Attribut { + var $ad_id; // pk for attribut + var $ad_text; // type of content + var $av_text; // Description (content) + var $cn; // database connection + function Attribut($p_ad_id) { + $this->ad_id=$p_ad_id; + $this->cn=-1; + } + +} + +/* function SortAttributeById + ************************************************** + * Purpose : Sort an array of object attribut thx the + * ad_id + * parm : + * - array of Attribut objects + * gen : + * - + * return: the ordered array + */ +function SortAttributeById($p_attribut) { + for ($i=0;$i< sizeof($p_attribut)-1;$i++) { + if ( $p_attribut[$i]->ad_id > $p_attribut[$i+1]->ad_id ) { + // then swap them + $t=$p_attribut[$i]; + $p_attribut[$i]=$p_attribut[$i+1]; + $p_attribut[$i+1] = $t; + $i=0; + } + } + + return $p_attribut; +} diff --git a/include/class_fiche.php b/include/class_fiche.php index 4e5cc8bc0..c262a2056 100644 --- a/include/class_fiche.php +++ b/include/class_fiche.php @@ -18,6 +18,8 @@ */ /* $Revision$ */ // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr +include_once("class_attribut.php"); + class fiche_def { var $cn; // database connection var $id; // id (fiche_def.fd_id @@ -54,7 +56,9 @@ class fiche_def { return ; for ($i=0;$i < $Max;$i++) { $row=pg_fetch_array($Ret,$i); - $this->attribut[$i]=$row['ad_text']; + $t = new Attribut($row['ad_id']); + $t->ad_text=$row['ad_text']; + $this->attribut[$i]=$t; } } @@ -119,9 +123,7 @@ class fiche { var $cn;// database connection var $id; // fiche.f_id var $fiche_def; // fd_id - var $attribut_id; // .ad_id - var $attribut_def; // ad_text - var $attribut_value; // av_text + var $attribut; // array of attribut object function fiche($p_cn,$p_id=0) { $this->cn=$p_cn; $this->id=$p_id; @@ -131,19 +133,12 @@ class fiche { if ( $this->id == 0){ return; } -// $sql="select * -// from jnt_fic_att_value -// natural join fiche -// natural join attr_value -// left join attr_def on (attr_def.ad_id=attr_value) where f_id=".$this->id; - - $sql="select * - from - ( select * from fiche_def natural join jnt_fic_attr natural join attr_def where fd_id = (select fd_id from fiche where f_id=$this->id)) - as w - full join ( select * from jnt_fic_att_value where f_id=$this->id ) as a on (w.ad_id=a.ad_id) -order by f_id,w.ad_id" -; + $sql="select * + from jnt_fic_att_value + natural join fiche + natural join attr_value + left join attr_def using (ad_id) where f_id=".$this->id. + " order by ad_id"; $Ret=ExecSql($this->cn,$sql); if ( ($Max=pg_NumRows($Ret)) == 0 ) @@ -151,10 +146,37 @@ order by f_id,w.ad_id" for ($i=0;$i<$Max;$i++) { $row=pg_fetch_array($Ret,$i); $this->fiche_def=$row['fd_id']; - $this->attribut_id=$row['ad_id']; - $this->attribut_value=$row['av_text']; - $this->attribut_def=$row['ad_text']; + $t=new Attribut ($row['ad_id']); + $t->ad_text=$row['ad_text']; + $t->av_text=$row['av_text']; + $this->attribut[$i]=$t; } + $e=new Fiche_def($this->cn,$this->fiche_def); + $e->GetAttribut(); + + if ( sizeof($this->attribut) != sizeof($e->attribut ) ) { + + // !!! Missing attribute + foreach ($e->attribut as $f ) { + $flag=0; + foreach ($this->attribut as $g ) { + if ( $g->ad_id == $f->ad_id ) + $flag=1; + } + if ( $flag == 0 ) { + // there's a missing one, we insert it + $t=new Attribut ($f->ad_id); + $t->av_text=""; + $t->ad_text=$f->ad_text; + $this->attribut[$Max]=$t; + $Max++; + } // if flag == 0 + + }// foreach + $this->attribut=SortAttributeById($this->attribut); + + + }//missing attribut } function size() { @@ -164,29 +186,11 @@ order by f_id,w.ad_id" return 0; } function GetByType($p_fd_id) { - // $sql="select * -// from jnt_fic_att_value -// natural join fiche -// natural join attr_value natural -// join attr_def where fd_id=".$p_fd_id. -// " order by f_id,ad_id"; - $sql="select * + $sql="select * from - ( select * from - fiche_def - natural join jnt_fic_attr - natural join attr_def - where fd_id = $p_fd_id - ) as w - right join - ( select * - from jnt_fic_att_value - inner join attr_def using (ad_id) - inner join attr_value using (jft_id) - join fiche using (f_id) where fd_id=$p_fd_id - ) as a on (w.ad_id=a.ad_id) - order by f_id,w.ad_id" -; + fiche + where fd_id=".$p_fd_id; + $Ret=ExecSql($this->cn,$sql); if ( ($Max=pg_NumRows($Ret)) == 0 ) @@ -195,11 +199,9 @@ order by f_id,w.ad_id" for ($i=0;$i<$Max;$i++) { $row=pg_fetch_array($Ret,$i); - $all[$i]=new fiche($this->cn,$row['f_id']); - $all[$i]->fiche_def=$row['fd_id']; - $all[$i]->attribut_id=$row['ad_id']; - $all[$i]->attribut_value=$row['av_text']; - $all[$i]->attribut_def=$row['ad_text']; + $t=new fiche($this->cn,$row['f_id']); + $t->getAttribut(); + $all[$i]=$t; } return $all; diff --git a/include/impress_fiche.php b/include/impress_fiche.php index 9c9c34568..44a305e90 100644 --- a/include/impress_fiche.php +++ b/include/impress_fiche.php @@ -28,7 +28,7 @@ $fiche_def=new fiche_def($cn); $fiche_def->GetAll(); -// var_dump($fiche); + $i=0; foreach ($fiche_def->all as $l_fiche) { $a[$i]=array("user_impress.php?type=fiche&fd_id=".$l_fiche->id,$l_fiche->label); @@ -55,24 +55,21 @@ if ( isset ($_GET['fd_id'])) { // var_dump($e); $old=-1; echo "
| ".$attribut->ad_text." | "; + echo "
|---|
| ".$attribut." | "; - echo "
| ".$detail->attribut_value." | "; + echo "
| ".$dattribut->av_text." | "; } + echo "