From ba36e30de92dfad8562f4af520618b325f24dbbd Mon Sep 17 00:00:00 2001 From: sparkyx Date: Tue, 1 Feb 2005 20:56:14 +0000 Subject: [PATCH] Printing of card is now completely correct --- INSTALL-fr.txt | 53 ++++++++++++++------- doc/INSTALL-fr.sgml | 10 ++++ html/fiche_csv.php | 30 +++++------- include/class_attribut.php | 55 ++++++++++++++++++++++ include/class_fiche.php | 96 +++++++++++++++++++------------------- include/impress_fiche.php | 27 +++++------ include/postgres.php | 2 +- 7 files changed, 175 insertions(+), 98 deletions(-) create mode 100644 include/class_attribut.php diff --git a/INSTALL-fr.txt b/INSTALL-fr.txt index 0d021e8b6..68f902f64 100644 --- a/INSTALL-fr.txt +++ b/INSTALL-fr.txt @@ -15,7 +15,8 @@ 2. Postgresql (version 732 minimum) 2.1 Installation 2.2 Configuration et démarrage de PostgreSql - 2.3 Pour la sécurité + 2.3 Optimisation + 2.4 Pour la sécurité 3. Apache 3.1 Installation d'Apache @@ -63,12 +64,11 @@ Comme d'habitude pour postgres, il faut tout d'abord définir, créer l'utilisateur postgres puis initialiser l'endroit où seront stocké vos données (variable env. PGDATA), exemple - - root#mkdir /data/psql - root#chown postgres /data/psql - root#su - postgres - postgres#initdb -D /data/psql - postgres#pg_ctl -D /data/psql -o '-i' start + root#mkdir /data/psql + root#chown postgres /data/psql + root#su - postgres + postgres#initdb -D /data/psql + postgres#pg_ctl -D /data/psql -o '-i' start @@ -99,7 +99,21 @@ /opt/psql732/bin/createuser -a -d $USER - 2.3. Pour la sécurité + 2.3. Optimisation + + Posgresql est une base de données très rapide, cependant, il vous + faudra configurer pour pouvoir en bénéficier + + · Augmenter la zone mémoire pour les tri (dans postgres.conf) + sort_mem = 8192 + + · Faites tourner régulièrement vacumdb -a -z grâce au crontab + + · Dans php.ini, bien utiliser les permanent_connection + + · à compléter + + 2.4. Pour la sécurité 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 à @@ -115,7 +129,6 @@ 172.16.30.0 255.255.255.0 md5 local all phpcompta 172.16.30.0 255.255.255.0 md5 - Ensuite soit vous utilisez la variable d'environnement PGPASSWORD qui contient votre mot de passe soit avec le fichier .pgpass dont la syn- taxe est @@ -129,6 +142,7 @@ Ensuite soit vous utilisez la variable d'environnement PGPASSWORD qui contient votre mot de passe soit avec le fichier .pgpass dont la syntaxe est + host:port:database:username:password @@ -174,13 +188,14 @@ vous-même, les options suivantes fonctionnent - ./configure --prefix=/opt/php431 \ - --with-apxs2=/opt/http2/bin/apxs \ - --with-fastcgi \ - --with-zlib \ - --with-pgsql=/opt/psql732 \ - --with-mysql \ - --with-apache2=/software/httpd-2.0.44 + + ./configure --prefix=/opt/php431 \ + --with-apxs2=/opt/http2/bin/apxs \ + --with-fastcgi \ + --with-zlib \ + --with-pgsql=/opt/psql732 \ + --with-mysql \ + --with-apache2=/software/httpd-2.0.44 @@ -197,6 +212,11 @@ Sinon, adaptez votre fichier, il doit avoir au minimum les options suivantes + + magic_quotes_gpc = Off + magic_quotes_runtime = Off + magic_quotes_sybase = Off + register_globals = on [Session] @@ -234,7 +254,6 @@ · Là on vous comptez installer le soft, créer le répertoire, règler les permissions - · connecter vous en tant que l'utilisateur qu'il a le droit dans le répertoire décrit plus haut, puis taper ./install.sh diff --git a/doc/INSTALL-fr.sgml b/doc/INSTALL-fr.sgml index 6140b1b7e..e42a234bb 100644 --- a/doc/INSTALL-fr.sgml +++ b/doc/INSTALL-fr.sgml @@ -84,6 +84,16 @@ puisse cr

+Optimisation +

Posgresql est une base de données très rapide, cependant, il vous faudra configurer +pour pouvoir en bénéficier + + Augmenter la zone mémoire pour les tri (dans postgres.conf) sort_mem = 8192 + Faites tourner régulièrement vacumdb -a -z grâce au crontab + Dans php.ini, bien utiliser les permanent_connection + à compléter + + Pour la sécurité

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 @@ +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 ""; + echo ""; + $fiche_def->GetAttribut(); + foreach ($fiche_def->attribut as $attribut) + echo ""; + echo ""; foreach ($e as $detail) { - if ($old == -1 ) { - $old=$detail->id; - echo ""; - $fiche_def->GetAttribut(); - foreach ($fiche_def->attribut as $attribut) - echo ""; - echo ""; - } - if ( $old != $detail->id) { - $old=$detail->id; - echo ""; - } - echo ""; + echo ""; + foreach ( $detail->attribut as $dattribut ) { + echo ""; } + echo ""; + } - echo "
".$attribut->ad_text."
".$attribut."
".$detail->attribut_value."
".$dattribut->av_text."
"; + echo ""; echo ""; } ?> \ No newline at end of file diff --git a/include/postgres.php b/include/postgres.php index 7e724b5d9..1d2447ca8 100644 --- a/include/postgres.php +++ b/include/postgres.php @@ -80,7 +80,7 @@ function DbConnect($p_db=-1,$p_type='dossier') { $password=phpcompta_password; - $a=pg_connect("dbname=$l_dossier host=127.0.0.1 user='phpcompta' password='$password'"); + $a=pg_pconnect("dbname=$l_dossier host=127.0.0.1 user='phpcompta' password='$password'"); echo_debug ("connect to $p_db"); return $a; }