debut de prise en compte des champ optionnels

This commit is contained in:
jlb 2003-02-13 18:14:57 +00:00
parent 921cfdc66f
commit b218b7e62e
3 changed files with 209 additions and 2 deletions

View File

@ -0,0 +1,182 @@
<?PHP
/* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
*
* 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 "<li>" . $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 "<h2><br>$sql<br></h2>";
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 "<h2><br>$sql<br></h2>";
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() ;
}
}
}
?>

View File

@ -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 '<tr><td>Password</td><td class="valeur">'.$adh->pass.'&nbsp;</td></tr>';
print '<tr><td>Date de naissance<BR>Format AAAA-MM-JJ</td><td class="valeur">'.$adh->naiss.'&nbsp;</td></tr>';
print '<tr><td>URL Photo</td><td class="valeur">'.$adh->photo.'&nbsp;</td></tr>';
$myattr=$adh->fetch_name_optionals();
foreach($myattr as $key){
print "<tr><td>$key</td><td>".$adh->array_options["options_$key"]."&nbsp;</td></tr>\n";
}
print "</table>\n";
@ -170,6 +186,9 @@ if ($rowid)
print '<tr><td>Password</td><td><input type="text" name="pass" size="40" value="'.$adh->pass.'"></td></tr>';
print '<tr><td>Date de naissance<BR>Format AAAA-MM-JJ</td><td><input type="text" name="naiss" size="40" value="'.$adh->naiss.'"></td></tr>';
print '<tr><td>URL photo</td><td><input type="text" name="photo" size="40" value="'.$adh->photo.'"></td></tr>';
foreach($myattr as $key){
print "<tr><td>$key</td><td><input type=\"text\" name=\"options_$key\" size=\"40\" value=\"".$adh->array_options["options_$key"]."\"></td></tr>\n";
}
print '<tr><td colspan="2" align="center">';
print '<input type="submit" name="bouton" value="Enregistrer">&nbsp;';
print '<input type="submit" value="Annuler">';

View File

@ -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 "<form action=\"$PHP_SELF\" method=\"post\">\n";