From b218b7e62e4c39a3542610f03aab204354808cd2 Mon Sep 17 00:00:00 2001 From: jlb Date: Thu, 13 Feb 2003 18:14:57 +0000 Subject: [PATCH] debut de prise en compte des champ optionnels --- htdocs/adherents/adherent_options.class.php | 182 ++++++++++++++++++++ htdocs/adherents/edit.php | 19 ++ htdocs/adherents/fiche.php | 10 +- 3 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 htdocs/adherents/adherent_options.class.php diff --git a/htdocs/adherents/adherent_options.class.php b/htdocs/adherents/adherent_options.class.php new file mode 100644 index 00000000000..f8f6d514def --- /dev/null +++ b/htdocs/adherents/adherent_options.class.php @@ -0,0 +1,182 @@ + + * Copyright (C) 2002-2003 Jean-Louis Bergamo + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * $Source$ + * + */ + +/* + * Classe de gestion de la table des champs optionels + */ +class AdherentOptions +{ + var $id; + var $db; + /* + * Tableau contenant le nom des champs en clef et la definition de + * ces champs + */ + var $attribute_name; + + var $errorstr; + /* + * Constructor + * + */ + Function AdherentOptions($DB, $id='') + { + $this->db = $DB ; + $this->id = $id; + $this->errorstr = array(); + $this->attribute_name = array(); + } + /* + * Print error_list + * + * + */ + Function print_error_list() + { + $num = sizeof($this->errorstr); + for ($i = 0 ; $i < $num ; $i++) + { + print "
  • " . $this->errorstr[$i]; + } + } + /* + * Check argument + * + */ + Function check($minimum=0) + { + $err = 0; + + if (strlen(trim($this->societe)) == 0) + { + if ((strlen(trim($this->nom)) + strlen(trim($this->prenom))) == 0) + { + $error_string[$err] = "Vous devez saisir vos nom et prénom ou le nom de votre société."; + $err++; + } + } + + if (strlen(trim($this->adresse)) == 0) + { + $error_string[$err] = "L'adresse saisie est invalide"; + $err++; + } + + /* + * Return errors + * + */ + + if ($err) + { + $this->errorstr = $error_string; + return 0; + } + else + { + return 1; + } + + } + /* + * Création d'un attribut optionnel supplementaire + * Ceci correspond a une modification de la table + * et pas a un rajout d'enregistrement + * Prend en argument : le nom de l'attribut et eventuellemnt son + * type et sa longueur + * + */ + Function create($attrname,$type='varchar',$length=255) { + /* + * Insertion dans la base + */ + $sql = "ALTER TABLE llx_adherent_options "; + $sql .= " ADD $attrname $type($length)"; + + if ($this->db->query($sql)) + { + return 1; + } + else + { + print $this->db->error(); + print "


    $sql

    "; + return 0; + } + } + + /* + * Suppression d'un attribut + * + */ + Function delete($attrname) + + { + $sql = "ALTER TABLE llx_adherent_options DROP COLUMN $attrname"; + + if ( $this->db->query( $sql) ) + { + return 1; + } + else + { + print "Err : ".$this->db->error(); + print "


    $sql

    "; + return 0; + } + + } + + /* + * fetch optional attribute name + */ + Function fetch_name_optionals() + { + $array_name_options=array(); + $sql = "SHOW COLUMNS FROM llx_adherent_options"; + + if ( $this->db->query( $sql) ) + { + if ($this->db->num_rows()) + { + while ($tab = $this->db->fetch_object()) + { + if ($tab->Field != 'optid' && $tab->Field != 'tms' && $tab->Field != 'adhid') + { + // we can add this attribute to adherent object + $array_name_options[]=$tab->Field; + $this->attribute_name[$tab->Field]=$tab->Type; + } + } + return $array_name_options; + }else{ + return array(); + } + }else{ + print $this->db->error(); + return array() ; + } + + } +} +?> diff --git a/htdocs/adherents/edit.php b/htdocs/adherents/edit.php index c75b79a0b4b..3de1710d49b 100644 --- a/htdocs/adherents/edit.php +++ b/htdocs/adherents/edit.php @@ -22,6 +22,7 @@ require("./pre.inc.php"); require("../adherent.class.php"); require("../adherent_type.class.php"); +require($GLOBALS["DOCUMENT_ROOT"]."/adherents/adherent_options.class.php"); $db = new Db(); @@ -60,10 +61,20 @@ if ($action == 'update') $adh->statut = $HTTP_POST_VARS["statut"]; $adh->public = $HTTP_POST_VARS["public"]; + foreach($_POST as $key => $value){ + if (ereg("^options_",$key)){ + $adh->array_options[$key]=$_POST[$key]; + } + } if ($adh->update($user->id) ) { Header("Location: fiche.php?rowid=$adh->id&action=edit"); } + else + { + Header("Location: edit.php?rowid=$adh->id"); + } + } else { @@ -81,6 +92,7 @@ if ($rowid) $adh = new Adherent($db); $adh->id = $rowid; $adh->fetch($rowid); + $adh->fetch_optionals($rowid); $sql = "SELECT s.nom,s.idp, f.amount, f.total, f.facnumber"; $sql .= " FROM societe as s, llx_facture as f WHERE f.fk_soc = s.idp"; @@ -123,6 +135,10 @@ if ($rowid) print 'Password'.$adh->pass.' '; print 'Date de naissance
    Format AAAA-MM-JJ'.$adh->naiss.' '; print 'URL Photo'.$adh->photo.' '; + $myattr=$adh->fetch_name_optionals(); + foreach($myattr as $key){ + print "$key".$adh->array_options["options_$key"]." \n"; + } print "\n"; @@ -170,6 +186,9 @@ if ($rowid) print 'Password'; print 'Date de naissance
    Format AAAA-MM-JJ'; print 'URL photo'; + foreach($myattr as $key){ + print "$keyarray_options["options_$key"]."\">\n"; + } print ''; print ' '; print ''; diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php index df5c23c142a..451689f5fec 100644 --- a/htdocs/adherents/fiche.php +++ b/htdocs/adherents/fiche.php @@ -23,6 +23,7 @@ require("./pre.inc.php"); require("../adherent.class.php"); require("../adherent_type.class.php"); +require($GLOBALS["DOCUMENT_ROOT"]."/adherents/adherent_options.class.php"); require("../cotisation.class.php"); require("../paiement.class.php"); @@ -63,6 +64,11 @@ if ($HTTP_POST_VARS["action"] == 'add') $adh->commentaire = $HTTP_POST_VARS["comment"]; $adh->morphy = $HTTP_POST_VARS["morphy"]; + foreach($_POST as $key => $value){ + if (ereg("^options_",$key)){ + $adh->array_options[$key]=$_POST[$key]; + } + } if ($adh->create($user->id) ) { if ($cotisation > 0) @@ -123,8 +129,8 @@ if ($action == 'create') { $total = $obj->total; } } - $adh = new Adherent($db); - $myattr=$adh->fetch_name_optionals(); + $adho = new AdherentOptions($db); + $myattr=$adho->fetch_name_optionals(); print_titre("Nouvel adhérent"); print "
    \n";