Fix: Accept _ in attribut type name. Better error management.

This commit is contained in:
Laurent Destailleur 2008-05-31 22:08:59 +00:00
parent 8246e1de5c
commit 2b084e56bd
4 changed files with 326 additions and 302 deletions

View File

@ -31,11 +31,11 @@
\author Sebastien Di Cintio \author Sebastien Di Cintio
\author Benoit Mortier \author Benoit Mortier
\version $Revision$ \version $Revision$
*/ */
/*! \class AdherentOptions /*! \class AdherentOptions
\brief Classe de gestion de la table des champs optionels adhérents \brief Classe de gestion de la table des champs optionels adhérents
*/ */
class AdherentOptions class AdherentOptions
{ {
@ -58,11 +58,11 @@ class AdherentOptions
* *
*/ */
/*! /*!
\brief AdherentOptions \brief AdherentOptions
\param DB base de données \param DB base de données
\param id id de l'adhérent \param id id de l'adhérent
*/ */
function AdherentOptions($DB, $id='') function AdherentOptions($DB, $id='')
{ {
@ -73,9 +73,9 @@ class AdherentOptions
$this->attribute_label = array(); $this->attribute_label = array();
} }
/*! /*!
\brief fonction qui imprime un liste d'erreurs \brief fonction qui imprime un liste d'erreurs
*/ */
function print_error_list() function print_error_list()
{ {
$num = sizeof($this->error); $num = sizeof($this->error);
@ -85,10 +85,10 @@ class AdherentOptions
} }
} }
/*! /*!
\brief fonction qui vérifie les données entrées \brief fonction qui vérifie les données entrées
\param minimum \param minimum
*/ */
function check($minimum=0) function check($minimum=0)
{ {
$err = 0; $err = 0;
@ -125,20 +125,18 @@ class AdherentOptions
} }
/*! /**
\brief fonction qui crée un attribut optionnel \brief fonction qui crée un attribut optionnel
\param attrname nom de l'atribut \param attrname nom de l'atribut
\param type type de l'attribut \param type type de l'attribut
\param length longuer de l'attribut \param length longuer de l'attribut
\remarks Ceci correspond a une modification de la table et pas a un rajout d'enregistrement \remarks Ceci correspond a une modification de la table et pas a un rajout d'enregistrement
*/
function create($attrname,$type='varchar',$length=255) {
/*
* Insertion dans la base
*/ */
if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-]*$/",$attrname)){ function create($attrname,$type='varchar',$length=255) {
if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname))
{
$sql = "ALTER TABLE ".MAIN_DB_PREFIX."adherent_options "; $sql = "ALTER TABLE ".MAIN_DB_PREFIX."adherent_options ";
switch ($type){ switch ($type){
case 'varchar' : case 'varchar' :
@ -155,6 +153,7 @@ class AdherentOptions
break; break;
} }
dolibarr_syslog("AdherentOptions::create sql=".$sql);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
return 1; return 1;
@ -169,21 +168,21 @@ class AdherentOptions
} }
} }
/*! /**
\brief fonction qui crée un label \brief fonction qui crée un label
\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='') {
/*
* Insertion dans la base
*/ */
if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-]*$/",$attrname)) { function create_label($attrname,$label='')
{
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); $escaped_label=mysql_escape_string($label);
$sql .= " name='$attrname',label='$escaped_label' "; $sql .= " name='$attrname',label='".addslashes($escaped_label)."'";
dolibarr_syslog("AdherentOptions::create_label sql=".$sql);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
return 1; return 1;
@ -196,14 +195,14 @@ class AdherentOptions
} }
} }
/*! /*!
\brief fonction qui supprime un attribut \brief fonction qui supprime un attribut
\param attrname nom de l'atribut \param attrname nom de l'atribut
*/ */
function delete($attrname) function delete($attrname)
{ {
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 = "ALTER TABLE ".MAIN_DB_PREFIX."adherent_options DROP COLUMN $attrname"; $sql = "ALTER TABLE ".MAIN_DB_PREFIX."adherent_options DROP COLUMN $attrname";
if ( $this->db->query( $sql) ) if ( $this->db->query( $sql) )
@ -221,14 +220,14 @@ class AdherentOptions
} }
/*! /*!
\brief fonction qui supprime un label \brief fonction qui supprime un label
\param attrname nom du label \param attrname nom du label
*/ */
function delete_label($attrname) function delete_label($attrname)
{ {
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 = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options_label WHERE name='$attrname'"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options_label WHERE name='$attrname'";
if ( $this->db->query( $sql) ) if ( $this->db->query( $sql) )
@ -246,16 +245,16 @@ class AdherentOptions
} }
/*! /*!
\brief fonction qui modifie un attribut optionnel \brief fonction qui modifie un attribut optionnel
\param attrname nom de l'atribut \param attrname nom de l'atribut
\param type type de l'attribut \param type type de l'attribut
\param length longuer de l'attribut \param length longuer de l'attribut
*/ */
function update($attrname,$type='varchar',$length=255) function update($attrname,$type='varchar',$length=255)
{ {
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 = "ALTER TABLE ".MAIN_DB_PREFIX."adherent_options "; $sql = "ALTER TABLE ".MAIN_DB_PREFIX."adherent_options ";
switch ($type){ switch ($type){
case 'varchar' : case 'varchar' :
@ -288,21 +287,20 @@ class AdherentOptions
} }
/*! /*!
\brief fonction qui modifie un label \brief fonction qui modifie un label
\param attrname nom de l'atribut \param attrname nom de l'atribut
\param label nom du label \param label nom du label
*/ */
function update_label($attrname,$label='') function update_label($attrname,$label='')
{ {
if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-]*$/",$attrname)){ if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)){
$escaped_label=mysql_escape_string($label);
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options_label WHERE name = $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options_label WHERE name =
'$attrname';"; '$attrname';";
$this->db->query($sql_del); $this->db->query($sql_del);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options_label (name,label) $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options_label (name,label)
VALUES ('$attrname','$escaped_label');"; VALUES ('$attrname','".addslashes($escaped_label)."')";
//$sql = "REPLACE INTO ".MAIN_DB_PREFIX."adherent_options_label SET name='$attrname',label='$escaped_label'"; //$sql = "REPLACE INTO ".MAIN_DB_PREFIX."adherent_options_label SET name='$attrname',label='$escaped_label'";
if ( $this->db->query( $sql) ) if ( $this->db->query( $sql) )
@ -321,9 +319,9 @@ class AdherentOptions
} }
/*! /*!
\brief fonction qui modifie un label \brief fonction qui modifie un label
*/ */
function fetch_optionals() function fetch_optionals()
{ {
$this->fetch_name_optionals(); $this->fetch_name_optionals();
@ -331,9 +329,9 @@ class AdherentOptions
} }
/*! /*!
\brief fonction qui modifie un label \brief fonction qui modifie un label
*/ */
function fetch_name_optionals() function fetch_name_optionals()
{ {
$array_name_options=array(); $array_name_options=array();
@ -363,9 +361,9 @@ class AdherentOptions
} }
/*! /*!
\brief fonction qui modifie un label \brief fonction qui modifie un label
*/ */
function fetch_name_optionals_label() function fetch_name_optionals_label()
{ {
$array_name_label=array(); $array_name_label=array();

View File

@ -16,15 +16,12 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*/ */
/** \file htdocs/adherents/options.php /** \file htdocs/adherents/options.php
\ingroup adherent \ingroup adherent
\brief Page de configuratin des champs optionnels \brief Page de configuratin des champs optionnels
\version $Revision$ \version $Id$
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
@ -35,43 +32,74 @@ $langs->load("members");
$adho = new AdherentOptions($db); $adho = new AdherentOptions($db);
$form = new Form($db); $form = new Form($db);
if ($_POST["action"] == 'add' && $user->admin) if ($_POST["action"] == 'add' && $user->rights->adherent->configurer)
{ {
if ($_POST["button"] != $langs->trans("Cancel")) { if ($_POST["button"] != $langs->trans("Cancel"))
{
// Type et taille non encore pris en compte => varchar(255) // Type et taille non encore pris en compte => varchar(255)
if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-]*$/",$_POST['attrname'])){ if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname']))
{
$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']);
} }
}
Header("Location: ".$_SERVER["PHP_SELF"]); 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->admin) if ($_POST["action"] == 'update' && $user->rights->adherent->configurer)
{ {
if ($_POST["button"] != $langs->trans("Cancel")) { if ($_POST["button"] != $langs->trans("Cancel"))
if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-]*$/",$_POST['attrname'])){ {
if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname']))
{
$adho->update($_POST['attrname'],$_POST['type'],$_POST['size']); $adho->update($_POST['attrname'],$_POST['type'],$_POST['size']);
} if (isset($_POST['label']))
if (isset($_POST['label'])){ {
$adho->update_label($_POST['attrname'],$_POST['label']); $adho->update_label($_POST['attrname'],$_POST['label']);
} }
}
Header("Location: ".$_SERVER["PHP_SELF"]); Header("Location: ".$_SERVER["PHP_SELF"]);
exit;
}
else
{
$langs->load("errors");
$mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode"));
}
}
} }
# Suppression attribut # Suppression attribut
if ($_GET["action"] == 'delete' && $user->admin) if ($_GET["action"] == 'delete' && $user->rights->adherent->configurer)
{ {
if(isset($_GET["attrname"]) && preg_match("/^\w[a-zA-Z0-9-]*$/",$_GET["attrname"])){ if(isset($_GET["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_GET["attrname"]))
{
$adho->delete($_GET["attrname"]); $adho->delete($_GET["attrname"]);
}
Header("Location: ".$_SERVER["PHP_SELF"]); Header("Location: ".$_SERVER["PHP_SELF"]);
exit;
}
else
{
$langs->load("errors");
$mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode"));
}
} }
/*
* View
*/
llxHeader(); llxHeader();
@ -79,11 +107,7 @@ llxHeader();
print_titre($langs->trans("OptionalFieldsSetup")); print_titre($langs->trans("OptionalFieldsSetup"));
print '<br>'; print '<br>';
/* ************************************************************************** */ if ($mesg) print '<div class="error">'.$mesg.'</div><br>';
/* */
/* */
/* */
/* ************************************************************************** */
$array_options=$adho->fetch_name_optionals(); $array_options=$adho->fetch_name_optionals();
$array_label=$adho->fetch_name_optionals_label(); $array_label=$adho->fetch_name_optionals_label();

View File

@ -28,3 +28,4 @@ ErrorGenbarCodeNotfound=File not found (Bad path, wrong permissions or access de
ErrorFunctionNotAvailableInPHP=Function <b>%s</b> is required for this feature but is not available in this version/setup of PHP. ErrorFunctionNotAvailableInPHP=Function <b>%s</b> is required for this feature but is not available in this version/setup of PHP.
ErrorDirAlreadyExists=A directory with this name already exists. ErrorDirAlreadyExists=A directory with this name already exists.
WarningAllowUrlFopenMustBeOn=Parameter <b>allow_url_fopen</b> must be set to <b>on</b> in filer <b>php.ini</b> for having this module working completely. You must modify this file manually. WarningAllowUrlFopenMustBeOn=Parameter <b>allow_url_fopen</b> must be set to <b>on</b> in filer <b>php.ini</b> for having this module working completely. You must modify this file manually.
ErrorFieldCanNotContainSpecialCharacters=Field <b>%s</b> must not contains special characters.

View File

@ -28,3 +28,4 @@ ErrorGenbarCodeNotfound=Fichier introuvable (Mauvais chemin, permissions incorre
ErrorFunctionNotAvailableInPHP=La fonction <b>%s</b> est requise pour cette fonctionnalité mais n'est pas disponible dans cette version/installation de PHP. ErrorFunctionNotAvailableInPHP=La fonction <b>%s</b> est requise pour cette fonctionnalité mais n'est pas disponible dans cette version/installation de PHP.
ErrorDirAlreadyExists=Un répertoire portant ce nom existe déjà. ErrorDirAlreadyExists=Un répertoire portant ce nom existe déjà.
WarningAllowUrlFopenMustBeOn=Attention, le paramètre <b>allow_url_fopen</b> doit etre positionné à <b>on</b> dans le fichier <b>php.ini</b> pour que ce module soit pleinement opérationnel. Vous devez modifier ce fichier manuellement. WarningAllowUrlFopenMustBeOn=Attention, le paramètre <b>allow_url_fopen</b> doit etre positionné à <b>on</b> dans le fichier <b>php.ini</b> pour que ce module soit pleinement opérationnel. Vous devez modifier ce fichier manuellement.
ErrorFieldCanNotContainSpecialCharacters=Le champ <b>%s</b> ne peut contenir de caractères spéciaux.