diff --git a/htdocs/adherents/adherent.class.php b/htdocs/adherents/adherent.class.php
index e79b0e790d4..9d7ed85d944 100644
--- a/htdocs/adherents/adherent.class.php
+++ b/htdocs/adherents/adherent.class.php
@@ -397,9 +397,8 @@ class Adherent extends CommonObject
$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options (adhid";
foreach($this->array_options as $key => $value)
{
- // Add field o fattribut
- $attr=substr($key,8);
- $sql.=",$attr";
+ // Add field of attribut
+ $sql.=",".substr($key,8); // Remove 'options_' prefix
}
$sql .= ") VALUES (".$this->id;
foreach($this->array_options as $key => $value)
@@ -936,11 +935,11 @@ class Adherent extends CommonObject
$sql.= " FROM ".MAIN_DB_PREFIX."adherent_options";
$sql.= " WHERE adhid=".$rowid;
+ dolibarr_syslog("Adherent::fetch_optionals sql=".$sql, LOG_DEBUG);
$result=$this->db->query( $sql);
-
if ($result)
{
- if ($this->db->num_rows())
+ if ($this->db->num_rows($result))
{
$tab = $this->db->fetch_array($result);
@@ -961,43 +960,6 @@ class Adherent extends CommonObject
}
- /**
- * \brief Fetch optional attribute name
- */
- function fetch_name_optionals()
- {
- $array_name_options=array();
- $sql = "SHOW COLUMNS FROM ".MAIN_DB_PREFIX."adherent_options";
-
- $result=$this->db->query( $sql);
-
- if ($result)
- {
- if ($this->db->num_rows())
- {
- //$array_name_options[]=$tab->Field;
- while ($tab = $this->db->fetch_object($result))
- {
- if ($tab->Field != 'optid' && $tab->Field != 'tms' && $tab->Field != 'adhid')
- {
- // we can add this attribute to adherent object
- $array_name_options[]=$tab->Field;
- }
- }
- return $array_name_options;
- }
- else
- {
- return array();
- }
- }
- else
- {
- dolibarr_print_error($this->db);
- return array() ;
- }
-
- }
/**
* \brief Fonction qui insere la cotisation dans la base de donnees
diff --git a/htdocs/adherents/adherent_options.class.php b/htdocs/adherents/adherent_options.class.php
index 3d316360fcf..2a06a6d69d5 100644
--- a/htdocs/adherents/adherent_options.class.php
+++ b/htdocs/adherents/adherent_options.class.php
@@ -150,7 +150,7 @@ class AdherentOptions
break;
}
- dolibarr_syslog("AdherentOptions::create sql=".$sql);
+ dolibarr_syslog("AdherentOptions::create sql=".$sql, LOG_DEBUG);
if ($this->db->query($sql))
{
return 1;
@@ -170,15 +170,15 @@ class AdherentOptions
\param attrname nom de l'atribut
\param label nom du label
*/
- function create_label($attrname,$label='')
+ function create_label($attrname,$label='',$type='',$pos=0,$size=0)
{
if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname))
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options_label SET ";
- $escaped_label=mysql_escape_string($label);
- $sql .= " name='$attrname',label='".addslashes($escaped_label)."'";
-
+ $sql .= " name='$attrname', label='".addslashes($label)."',";
+ $sql .= " type='".$type."', pos='".$pos."', size='".$size."'";
+
dolibarr_syslog("AdherentOptions::create_label sql=".$sql);
if ($this->db->query($sql))
{
@@ -321,60 +321,31 @@ class AdherentOptions
*/
function fetch_optionals()
{
- $this->fetch_name_optionals();
$this->fetch_name_optionals_label();
}
- /*!
- \brief fonction qui modifie un label
- */
- function fetch_name_optionals()
- {
- $array_name_options=array();
- $sql = "SHOW COLUMNS FROM ".MAIN_DB_PREFIX."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() ;
- }
-
- }
-
- /*!
- \brief fonction qui modifie un label
- */
+ /**
+ * \brief Load array this->attribute_label
+ */
function fetch_name_optionals_label()
{
$array_name_label=array();
- $sql = "SELECT name,label FROM ".MAIN_DB_PREFIX."adherent_options_label";
-
- if ( $this->db->query( $sql) )
+ $sql = "SELECT name,label,type FROM ".MAIN_DB_PREFIX."adherent_options_label";
+ $sql.= " ORDER BY pos";
+
+ dolibarr_syslog("Adherent_options::fetch_name_optionals_label");
+ $resql=$this->db->query($sql);
+ if ($resql)
{
- if ($this->db->num_rows())
+ if ($this->db->num_rows($resql))
{
- while ($tab = $this->db->fetch_object())
+ while ($tab = $this->db->fetch_object($resql))
{
- // we can add this attribute to adherent object
- $array_name_label[$tab->name]=stripslashes($tab->label);
- $this->attribute_label[$tab->name]=stripslashes($tab->label);
+ // we can add this attribute to adherent object
+ $array_name_label[$tab->name]=$tab->label;
+ $this->attribute_name[$tab->name]=$tab->type;
+ $this->attribute_label[$tab->name]=$tab->label;
}
return $array_name_label;
}else{
diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php
index d26125aaa08..9d98d7618f4 100644
--- a/htdocs/adherents/fiche.php
+++ b/htdocs/adherents/fiche.php
@@ -44,12 +44,12 @@ $canadduser=$user->rights->adherent->creer;
// Defini si peux lire/modifier info user ou mot de passe
if ($_GET["rowid"])
{
- $caneditfield=$user->rights->adherent->creer;
- $caneditpassword=$user->rights->adherent->creer;
+ $caneditfield=$user->rights->adherent->creer;
+ $caneditpassword=$user->rights->adherent->creer;
}
if (! $user->rights->adherent->lire)
{
- accessforbidden();
+ accessforbidden();
}
@@ -521,7 +521,7 @@ if ($errmsg)
}
// fetch optionals attributes and labels
-$adho->fetch_optionals();
+$adho->fetch_name_optionals_label();
if ($action == 'edit')
@@ -539,7 +539,7 @@ if ($action == 'edit')
// fetch optionals value
$adh->fetch_optionals($rowid);
// fetch optionals attributes and labels
- $adho->fetch_optionals();
+ $adho->fetch_name_optionals_label();
$adht = new AdherentType($db);
$adht->fetch($adh->typeid);
@@ -965,7 +965,7 @@ if ($rowid && $action != 'edit')
print '';
- // Autres attributs
+ // Other attributs
foreach($adho->attribute_label as $key=>$value)
{
print "
| $value | ".$adh->array_options["options_$key"]." |
\n";
diff --git a/htdocs/adherents/options.php b/htdocs/adherents/options.php
index b4d42c960d7..597b9a97317 100644
--- a/htdocs/adherents/options.php
+++ b/htdocs/adherents/options.php
@@ -19,10 +19,10 @@
*/
/** \file htdocs/adherents/options.php
- \ingroup adherent
- \brief Page de configuratin des champs optionnels
- \version $Id$
-*/
+ \ingroup adherent
+ \brief Page de configuratin des champs optionnels
+ \version $Id$
+ */
require("./pre.inc.php");
require(DOL_DOCUMENT_ROOT."/adherents/adherent_options.class.php");
@@ -32,66 +32,70 @@ $langs->load("members");
$adho = new AdherentOptions($db);
$form = new Form($db);
-if ($_POST["action"] == 'add' && $user->rights->adherent->configurer)
+/*
+ * Actions
+ */
+
+if ($_POST["action"] == 'add' && $user->rights->adherent->configurer)
{
- if ($_POST["button"] != $langs->trans("Cancel"))
- {
- // Type et taille non encore pris en compte => varchar(255)
- if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname']))
- {
- $adho->create($_POST['attrname'],$_POST['type'],$_POST['size']);
- if (isset($_POST['label']))
- {
- $adho->create_label($_POST['attrname'],$_POST['label']);
- }
- Header("Location: ".$_SERVER["PHP_SELF"]);
- exit;
- }
- else
- {
- $langs->load("errors");
- $mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode"));
- $_GET["action"] = 'create';
- }
- }
+ if ($_POST["button"] != $langs->trans("Cancel"))
+ {
+ // Type et taille non encore pris en compte => varchar(255)
+ if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname']))
+ {
+ $adho->create($_POST['attrname'],$_POST['type'],$_POST['size']);
+ if (isset($_POST['label']))
+ {
+ $adho->create_label($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['pos'],$_POST['size']);
+ }
+ Header("Location: ".$_SERVER["PHP_SELF"]);
+ exit;
+ }
+ else
+ {
+ $langs->load("errors");
+ $mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode"));
+ $_GET["action"] = 'create';
+ }
+ }
}
-if ($_POST["action"] == 'update' && $user->rights->adherent->configurer)
+if ($_POST["action"] == 'update' && $user->rights->adherent->configurer)
{
- if ($_POST["button"] != $langs->trans("Cancel"))
- {
- if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname']))
- {
- $adho->update($_POST['attrname'],$_POST['type'],$_POST['size']);
- if (isset($_POST['label']))
- {
- $adho->update_label($_POST['attrname'],$_POST['label']);
- }
- Header("Location: ".$_SERVER["PHP_SELF"]);
- exit;
- }
- else
- {
- $langs->load("errors");
- $mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode"));
- }
- }
+ if ($_POST["button"] != $langs->trans("Cancel"))
+ {
+ if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname']))
+ {
+ $adho->update($_POST['attrname'],$_POST['type'],$_POST['size']);
+ if (isset($_POST['label']))
+ {
+ $adho->update_label($_POST['attrname'],$_POST['label']);
+ }
+ Header("Location: ".$_SERVER["PHP_SELF"]);
+ exit;
+ }
+ else
+ {
+ $langs->load("errors");
+ $mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode"));
+ }
+ }
}
# Suppression attribut
if ($_GET["action"] == 'delete' && $user->rights->adherent->configurer)
{
- if(isset($_GET["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_GET["attrname"]))
- {
- $adho->delete($_GET["attrname"]);
- Header("Location: ".$_SERVER["PHP_SELF"]);
- exit;
- }
- else
- {
- $langs->load("errors");
- $mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode"));
- }
+ if(isset($_GET["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_GET["attrname"]))
+ {
+ $adho->delete($_GET["attrname"]);
+ Header("Location: ".$_SERVER["PHP_SELF"]);
+ exit;
+ }
+ else
+ {
+ $langs->load("errors");
+ $mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode"));
+ }
}
@@ -109,8 +113,8 @@ print '
';
if ($mesg) print ''.$mesg.'
';
-$array_options=$adho->fetch_name_optionals();
-$array_label=$adho->fetch_name_optionals_label();
+// Load attribute_label
+$adho->fetch_name_optionals_label();
print "";
@@ -119,23 +123,19 @@ print '| '.$langs->trans("Label").' | ';
print ''.$langs->trans("AttributeCode").' | ';
print ''.$langs->trans("Type").' | | ';
print "\n";
-
-if (sizeof($array_options)>0)
-{
- $var=True;
- foreach($adho->attribute_name as $key => $value)
- {
- $var=!$var;
- print "";
- print "| ".$adho->attribute_label[$key]." | \n";
- print "$key | \n";
- print "$value | \n";
- print "".img_edit()."";
- print " ".img_delete()." | \n";
- print "
";
- // $i++;
- }
+$var=True;
+foreach($adho->attribute_name as $key => $value)
+{
+ $var=!$var;
+ print "";
+ print "| ".$adho->attribute_label[$key]." | \n";
+ print "$key | \n";
+ print "$value | \n";
+ print "".img_edit()."";
+ print " ".img_delete()." | \n";
+ print "
";
+ // $i++;
}
print "
";
@@ -144,7 +144,7 @@ print "";
* Barre d'actions
*
*/
-if ($_GET["action"] != 'create')
+if ($_GET["action"] != 'create')
{
print '';
print "
".$langs->trans("NewAttribute")."";
@@ -154,14 +154,14 @@ if ($_GET["action"] != 'create')
/* ************************************************************************** */
/* */
-/* Création d'un champ optionnel */
-/* */
+/* Creation d'un champ optionnel
+ /* */
/* ************************************************************************** */
if ($_GET["action"] == 'create')
{
print "
";
-
+
print_titre($langs->trans('NewAttribute'));
print '
\n";
print "\n";
-}
+}
/* ************************************************************************** */
/* */
@@ -194,33 +194,33 @@ if ($_GET["action"] == 'create')
if ($_GET["attrname"] && $_GET["action"] == 'edit')
{
- print_titre($langs->trans("FieldEdition",$_GET["attrname"]));
-
- /*
- * formulaire d'edition
- */
- print '
";
-
}
$db->close();
diff --git a/htdocs/public/adherents/new.php b/htdocs/public/adherents/new.php
index 23119c01838..30b1ee12b36 100644
--- a/htdocs/public/adherents/new.php
+++ b/htdocs/public/adherents/new.php
@@ -179,7 +179,7 @@ print_titre($langs->trans("NewMember"));
$adht = new AdherentType($db);
// fetch optionals attributes and labels
-$adho->fetch_optionals();
+$adho->fetch_name_optionals_label();
if (isset($_GET["action"]) && $_GET["action"] == 'added')
{
@@ -242,7 +242,7 @@ print '
| * '.$langs->trans("Login").' | | * '.$langs->trans("Password").' |
| |
';
print '
Date de naissance Format AAAA-MM-JJ | |
';
print '
| * URL Photo | |
';
-print '
| Profil public ? | |
';
+print '
| '.$langs->trans("Public").' ? | |
';
foreach($adho->attribute_label as $key=>$value){
print "
| $value | |
\n";
}
diff --git a/htdocs/public/adherents/priv_fiche.php b/htdocs/public/adherents/priv_fiche.php
index f772da9c085..85ab240b503 100644
--- a/htdocs/public/adherents/priv_fiche.php
+++ b/htdocs/public/adherents/priv_fiche.php
@@ -67,10 +67,9 @@ $adho = new AdherentOptions($db);
llxHeaderVierge($langs->trans("MemberCard"));
// fetch optionals attributes and labels
-$adho->fetch_optionals();
+$adho->fetch_name_optionals_label();
if ($rowid > 0)
{
-
$adh = new Adherent($db);
$adh->id = $rowid;
$adh->fetch($rowid);