Code simpler
This commit is contained in:
parent
c3deed6a57
commit
c2db14f348
@ -397,9 +397,8 @@ class Adherent extends CommonObject
|
|||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options (adhid";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options (adhid";
|
||||||
foreach($this->array_options as $key => $value)
|
foreach($this->array_options as $key => $value)
|
||||||
{
|
{
|
||||||
// Add field o fattribut
|
// Add field of attribut
|
||||||
$attr=substr($key,8);
|
$sql.=",".substr($key,8); // Remove 'options_' prefix
|
||||||
$sql.=",$attr";
|
|
||||||
}
|
}
|
||||||
$sql .= ") VALUES (".$this->id;
|
$sql .= ") VALUES (".$this->id;
|
||||||
foreach($this->array_options as $key => $value)
|
foreach($this->array_options as $key => $value)
|
||||||
@ -936,11 +935,11 @@ class Adherent extends CommonObject
|
|||||||
$sql.= " FROM ".MAIN_DB_PREFIX."adherent_options";
|
$sql.= " FROM ".MAIN_DB_PREFIX."adherent_options";
|
||||||
$sql.= " WHERE adhid=".$rowid;
|
$sql.= " WHERE adhid=".$rowid;
|
||||||
|
|
||||||
|
dolibarr_syslog("Adherent::fetch_optionals sql=".$sql, LOG_DEBUG);
|
||||||
$result=$this->db->query( $sql);
|
$result=$this->db->query( $sql);
|
||||||
|
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
if ($this->db->num_rows())
|
if ($this->db->num_rows($result))
|
||||||
{
|
{
|
||||||
$tab = $this->db->fetch_array($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
|
* \brief Fonction qui insere la cotisation dans la base de donnees
|
||||||
|
|||||||
@ -150,7 +150,7 @@ class AdherentOptions
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
dolibarr_syslog("AdherentOptions::create sql=".$sql);
|
dolibarr_syslog("AdherentOptions::create sql=".$sql, LOG_DEBUG);
|
||||||
if ($this->db->query($sql))
|
if ($this->db->query($sql))
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
@ -170,14 +170,14 @@ class AdherentOptions
|
|||||||
\param attrname nom de l'atribut
|
\param attrname nom de l'atribut
|
||||||
\param label nom du label
|
\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))
|
if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname))
|
||||||
{
|
{
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options_label SET ";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options_label SET ";
|
||||||
$escaped_label=mysql_escape_string($label);
|
$sql .= " name='$attrname', label='".addslashes($label)."',";
|
||||||
$sql .= " name='$attrname',label='".addslashes($escaped_label)."'";
|
$sql .= " type='".$type."', pos='".$pos."', size='".$size."'";
|
||||||
|
|
||||||
dolibarr_syslog("AdherentOptions::create_label sql=".$sql);
|
dolibarr_syslog("AdherentOptions::create_label sql=".$sql);
|
||||||
if ($this->db->query($sql))
|
if ($this->db->query($sql))
|
||||||
@ -321,60 +321,31 @@ class AdherentOptions
|
|||||||
*/
|
*/
|
||||||
function fetch_optionals()
|
function fetch_optionals()
|
||||||
{
|
{
|
||||||
$this->fetch_name_optionals();
|
|
||||||
$this->fetch_name_optionals_label();
|
$this->fetch_name_optionals_label();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
\brief fonction qui modifie un label
|
* \brief Load array this->attribute_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
|
|
||||||
*/
|
*/
|
||||||
function fetch_name_optionals_label()
|
function fetch_name_optionals_label()
|
||||||
{
|
{
|
||||||
$array_name_label=array();
|
$array_name_label=array();
|
||||||
$sql = "SELECT name,label FROM ".MAIN_DB_PREFIX."adherent_options_label";
|
$sql = "SELECT name,label,type FROM ".MAIN_DB_PREFIX."adherent_options_label";
|
||||||
|
$sql.= " ORDER BY pos";
|
||||||
|
|
||||||
if ( $this->db->query( $sql) )
|
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
|
// we can add this attribute to adherent object
|
||||||
$array_name_label[$tab->name]=stripslashes($tab->label);
|
$array_name_label[$tab->name]=$tab->label;
|
||||||
$this->attribute_label[$tab->name]=stripslashes($tab->label);
|
$this->attribute_name[$tab->name]=$tab->type;
|
||||||
|
$this->attribute_label[$tab->name]=$tab->label;
|
||||||
}
|
}
|
||||||
return $array_name_label;
|
return $array_name_label;
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
@ -521,7 +521,7 @@ if ($errmsg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fetch optionals attributes and labels
|
// fetch optionals attributes and labels
|
||||||
$adho->fetch_optionals();
|
$adho->fetch_name_optionals_label();
|
||||||
|
|
||||||
|
|
||||||
if ($action == 'edit')
|
if ($action == 'edit')
|
||||||
@ -539,7 +539,7 @@ if ($action == 'edit')
|
|||||||
// fetch optionals value
|
// fetch optionals value
|
||||||
$adh->fetch_optionals($rowid);
|
$adh->fetch_optionals($rowid);
|
||||||
// fetch optionals attributes and labels
|
// fetch optionals attributes and labels
|
||||||
$adho->fetch_optionals();
|
$adho->fetch_name_optionals_label();
|
||||||
|
|
||||||
$adht = new AdherentType($db);
|
$adht = new AdherentType($db);
|
||||||
$adht->fetch($adh->typeid);
|
$adht->fetch($adh->typeid);
|
||||||
@ -965,7 +965,7 @@ if ($rowid && $action != 'edit')
|
|||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
|
|
||||||
// Autres attributs
|
// Other attributs
|
||||||
foreach($adho->attribute_label as $key=>$value)
|
foreach($adho->attribute_label as $key=>$value)
|
||||||
{
|
{
|
||||||
print "<tr><td>$value</td><td>".$adh->array_options["options_$key"]." </td></tr>\n";
|
print "<tr><td>$value</td><td>".$adh->array_options["options_$key"]." </td></tr>\n";
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
\ingroup adherent
|
\ingroup adherent
|
||||||
\brief Page de configuratin des champs optionnels
|
\brief Page de configuratin des champs optionnels
|
||||||
\version $Id$
|
\version $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require("./pre.inc.php");
|
require("./pre.inc.php");
|
||||||
require(DOL_DOCUMENT_ROOT."/adherents/adherent_options.class.php");
|
require(DOL_DOCUMENT_ROOT."/adherents/adherent_options.class.php");
|
||||||
@ -32,6 +32,10 @@ $langs->load("members");
|
|||||||
$adho = new AdherentOptions($db);
|
$adho = new AdherentOptions($db);
|
||||||
$form = new Form($db);
|
$form = new Form($db);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Actions
|
||||||
|
*/
|
||||||
|
|
||||||
if ($_POST["action"] == 'add' && $user->rights->adherent->configurer)
|
if ($_POST["action"] == 'add' && $user->rights->adherent->configurer)
|
||||||
{
|
{
|
||||||
if ($_POST["button"] != $langs->trans("Cancel"))
|
if ($_POST["button"] != $langs->trans("Cancel"))
|
||||||
@ -42,7 +46,7 @@ if ($_POST["action"] == 'add' && $user->rights->adherent->configurer)
|
|||||||
$adho->create($_POST['attrname'],$_POST['type'],$_POST['size']);
|
$adho->create($_POST['attrname'],$_POST['type'],$_POST['size']);
|
||||||
if (isset($_POST['label']))
|
if (isset($_POST['label']))
|
||||||
{
|
{
|
||||||
$adho->create_label($_POST['attrname'],$_POST['label']);
|
$adho->create_label($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['pos'],$_POST['size']);
|
||||||
}
|
}
|
||||||
Header("Location: ".$_SERVER["PHP_SELF"]);
|
Header("Location: ".$_SERVER["PHP_SELF"]);
|
||||||
exit;
|
exit;
|
||||||
@ -109,8 +113,8 @@ print '<br>';
|
|||||||
|
|
||||||
if ($mesg) print '<div class="error">'.$mesg.'</div><br>';
|
if ($mesg) print '<div class="error">'.$mesg.'</div><br>';
|
||||||
|
|
||||||
$array_options=$adho->fetch_name_optionals();
|
// Load attribute_label
|
||||||
$array_label=$adho->fetch_name_optionals_label();
|
$adho->fetch_name_optionals_label();
|
||||||
|
|
||||||
print "<table class=\"noborder\" width=\"100%\">";
|
print "<table class=\"noborder\" width=\"100%\">";
|
||||||
|
|
||||||
@ -120,11 +124,9 @@ print '<td>'.$langs->trans("AttributeCode").'</td>';
|
|||||||
print '<td>'.$langs->trans("Type").'</td><td width="80"> </td>';
|
print '<td>'.$langs->trans("Type").'</td><td width="80"> </td>';
|
||||||
print "</tr>\n";
|
print "</tr>\n";
|
||||||
|
|
||||||
if (sizeof($array_options)>0)
|
$var=True;
|
||||||
|
foreach($adho->attribute_name as $key => $value)
|
||||||
{
|
{
|
||||||
$var=True;
|
|
||||||
foreach($adho->attribute_name as $key => $value)
|
|
||||||
{
|
|
||||||
$var=!$var;
|
$var=!$var;
|
||||||
print "<tr $bc[$var]>";
|
print "<tr $bc[$var]>";
|
||||||
print "<td>".$adho->attribute_label[$key]." </td>\n";
|
print "<td>".$adho->attribute_label[$key]." </td>\n";
|
||||||
@ -134,8 +136,6 @@ if (sizeof($array_options)>0)
|
|||||||
print " <a href=\"options.php?action=delete&attrname=$key\">".img_delete()."</a></td>\n";
|
print " <a href=\"options.php?action=delete&attrname=$key\">".img_delete()."</a></td>\n";
|
||||||
print "</tr>";
|
print "</tr>";
|
||||||
// $i++;
|
// $i++;
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print "</table>";
|
print "</table>";
|
||||||
@ -154,8 +154,8 @@ if ($_GET["action"] != 'create')
|
|||||||
|
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* Création d'un champ optionnel */
|
/* Creation d'un champ optionnel
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
if ($_GET["action"] == 'create')
|
if ($_GET["action"] == 'create')
|
||||||
|
|||||||
@ -179,7 +179,7 @@ print_titre($langs->trans("NewMember"));
|
|||||||
$adht = new AdherentType($db);
|
$adht = new AdherentType($db);
|
||||||
|
|
||||||
// fetch optionals attributes and labels
|
// fetch optionals attributes and labels
|
||||||
$adho->fetch_optionals();
|
$adho->fetch_name_optionals_label();
|
||||||
|
|
||||||
if (isset($_GET["action"]) && $_GET["action"] == 'added')
|
if (isset($_GET["action"]) && $_GET["action"] == 'added')
|
||||||
{
|
{
|
||||||
@ -242,7 +242,7 @@ print '<tr><td><FONT COLOR="red">*</FONT> '.$langs->trans("Login").'</td><td><in
|
|||||||
print '<tr><td><FONT COLOR="red">*</FONT> '.$langs->trans("Password").'</td><td><input type="password" name="pass1" size="40"><BR><input type="password" name="pass2" size="40"></td></tr>';
|
print '<tr><td><FONT COLOR="red">*</FONT> '.$langs->trans("Password").'</td><td><input type="password" name="pass1" size="40"><BR><input type="password" name="pass2" size="40"></td></tr>';
|
||||||
print '<tr><td>Date de naissance<BR>Format AAAA-MM-JJ</td><td><input type="text" name="naiss" size="40" value="'.$naiss.'"></td></tr>';
|
print '<tr><td>Date de naissance<BR>Format AAAA-MM-JJ</td><td><input type="text" name="naiss" size="40" value="'.$naiss.'"></td></tr>';
|
||||||
print '<tr><td><FONT COLOR="blue">*</FONT> URL Photo</td><td><input type="text" name="photo" size="40" value="'.$photo.'"></td></tr>';
|
print '<tr><td><FONT COLOR="blue">*</FONT> URL Photo</td><td><input type="text" name="photo" size="40" value="'.$photo.'"></td></tr>';
|
||||||
print '<tr><td>Profil public ?</td><td><input type="checkbox" name="public" checked></td></tr>';
|
print '<tr><td>'.$langs->trans("Public").' ?</td><td><input type="checkbox" name="public" checked></td></tr>';
|
||||||
foreach($adho->attribute_label as $key=>$value){
|
foreach($adho->attribute_label as $key=>$value){
|
||||||
print "<tr><td>$value</td><td><input type=\"text\" name=\"options_$key\" size=\"40\"></td></tr>\n";
|
print "<tr><td>$value</td><td><input type=\"text\" name=\"options_$key\" size=\"40\"></td></tr>\n";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -67,10 +67,9 @@ $adho = new AdherentOptions($db);
|
|||||||
llxHeaderVierge($langs->trans("MemberCard"));
|
llxHeaderVierge($langs->trans("MemberCard"));
|
||||||
|
|
||||||
// fetch optionals attributes and labels
|
// fetch optionals attributes and labels
|
||||||
$adho->fetch_optionals();
|
$adho->fetch_name_optionals_label();
|
||||||
if ($rowid > 0)
|
if ($rowid > 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
$adh = new Adherent($db);
|
$adh = new Adherent($db);
|
||||||
$adh->id = $rowid;
|
$adh->id = $rowid;
|
||||||
$adh->fetch($rowid);
|
$adh->fetch($rowid);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user