diff --git a/htdocs/adherents/adherent_options.class.php b/htdocs/adherents/adherent_options.class.php index 9c96d1f8639..2dd896b1d83 100644 --- a/htdocs/adherents/adherent_options.class.php +++ b/htdocs/adherents/adherent_options.class.php @@ -3,6 +3,7 @@ * Copyright (C) 2002-2003 Jean-Louis Bergamo * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Benoit Mortier + * Copyright (C) 2009 Laurent Destailleur * Copyright (C) 2009 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -36,9 +37,11 @@ class AdherentOptions var $id; var $db; // Tableau contenant le nom des champs en clef et la definition de ces champs - var $attribute_name; + var $attribute_type; // Tableau contenant le nom des champs en clef et le label de ces champs en value var $attribute_label; + // Tableau contenant le nom des champs en clef et la taille de ces champs en value + var $attribute_size; var $error; /* @@ -56,8 +59,9 @@ class AdherentOptions $this->db = $DB ; $this->id = $id; $this->error = array(); - $this->attribute_name = array(); + $this->attribute_type = array(); $this->attribute_label = array(); + $this->attribute_size = array(); } /** @@ -73,47 +77,11 @@ class AdherentOptions } /** - * \brief fonction qui verifie les donnees entrees - * \param minimum - */ - 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 prenom ou le nom de votre societe."; - $err++; - } - } - - if (strlen(trim($this->adresse)) == 0) - { - $error_string[$err] = "L'adresse saisie est invalide"; - $err++; - } - - // Return errors - if ($err) - { - $this->error = $error_string; - return 0; - } - else - { - return 1; - } - - } - - /** - * \brief fonction qui cree un attribut optionnel - * \param attrname nom de l'atribut - * \param type type 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 + * \brief Add a new attribute + * \param attrname nom de l'atribut + * \param type type de l'attribut + * \param length longuer de l'attribut + * \remarks Ceci correspond a un alter de la table et pas a un insert */ function create($attrname,$type='varchar',$length=255) { @@ -158,20 +126,20 @@ class AdherentOptions function create_label($attrname,$label='',$type='',$pos=0,$size=0) { global $conf; - + // Clean parameters if (empty($pos)) $pos=0; if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options_label SET "; - $sql.= " name = '".$attrname."'"; - $sql.= ", label = '".addslashes($label)."'"; - $sql.= ", type = '".$type."'"; - $sql.= ", pos = '".$pos."'"; - $sql.= ", size = '".$size."'"; - $sql.= ", entity = ".$conf->entity; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options_label SET"; + $sql.= " name = '".$attrname."',"; + $sql.= " label = '".addslashes($label)."',"; + $sql.= " type = '".$type."',"; + $sql.= " pos = '".$pos."',"; + $sql.= " size = '".$size."',"; + $sql.= " entity = ".$conf->entity; dol_syslog("AdherentOptions::create_label sql=".$sql); if ($this->db->query($sql)) @@ -220,13 +188,14 @@ class AdherentOptions function delete_label($attrname) { global $conf; - + if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options_label"; $sql.= " WHERE name = '$attrname'"; $sql.= " AND entity = ".$conf->entity; + dol_syslog("AdherentOptions::delete_label sql=".$sql); if ( $this->db->query( $sql) ) { return 1; @@ -245,17 +214,18 @@ class AdherentOptions } /** - * \brief fonction qui modifie un attribut optionnel - * \param attrname nom de l'atribut - * \param type type de l'attribut - * \param length longuer de l'attribut + * \brief Fonction qui modifie le type d'un attribut optionnel + * \param attrname nom de l'atribut + * \param type type de l'attribut + * \param length longuer de l'attribut + * \return int >0 if OK, <=0 if error * \TODO pouvoir gerer les entités */ function update($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){ case 'varchar' : case 'interger' : @@ -272,7 +242,8 @@ class AdherentOptions } //$sql .= "MODIFY COLUMN $attrname $type($length)"; - if ( $this->db->query( $sql) ) + dol_syslog("AdherentOptions::update sql=".$sql); + if ( $this->db->query($sql) ) { return 1; } @@ -281,7 +252,8 @@ class AdherentOptions print dol_print_error($this->db); return 0; } - }else + } + else { return 0; } @@ -289,39 +261,52 @@ class AdherentOptions } /** - * \brief fonction qui modifie un label + * \brief Modify an optionnal attribute * \param attrname nom de l'atribut * \param label nom du label + * \param type type + * \param size size */ - function update_label($attrname,$label='') + function update_label($attrname,$label,$type,$size) { global $conf; - + dol_syslog("AdherentOptions::update_label $attrname,$label,$type,$size"); + if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) { + $this->db->begin(); + $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options_label"; $sql_del.= " WHERE name = '".$attrname."'"; $sql_del.= " AND entity = ".$conf->entity; - - $this->db->query($sql_del); - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options_label ("; - $sql.= "name"; - $sql.= ", label"; - $sql.= ", entity"; + dol_syslog("AdherentOptions::update_label sql=".$sql_del); + $resql1=$this->db->query($sql_del); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options_label("; + $sql.= " name,"; + $sql.= " entity,"; + $sql.= " label,"; + $sql.= " type,"; + $sql.= " size"; $sql.= ") VALUES ("; - $sql.= "'".$attrname."'"; - $sql.= ", '".addslashes($escaped_label)."'"; - $sql.= ", ".$conf->entity; + $sql.= "'".$attrname."',"; + $sql.= " ".$conf->entity.","; + $sql.= " '".addslashes($label)."',"; + $sql.= " '".$type."',"; + $sql.= " '".$size."'"; $sql.= ")"; //$sql = "REPLACE INTO ".MAIN_DB_PREFIX."adherent_options_label SET name='$attrname',label='$escaped_label'"; + dol_syslog("AdherentOptions::update_label sql=".$sql); + $resql2=$this->db->query($sql); - if ( $this->db->query( $sql) ) + if ($resql1 && $resql2) { + $this->db->commit(); return 1; } else { + $this->db->rollback(); print dol_print_error($this->db); return 0; } @@ -349,15 +334,15 @@ class AdherentOptions function fetch_name_optionals_label() { global $conf; - + $array_name_label=array(); - - $sql = "SELECT name,label,type"; + + $sql = "SELECT name,label,type,size"; $sql.= " FROM ".MAIN_DB_PREFIX."adherent_options_label"; $sql.= " WHERE entity = ".$conf->entity; $sql.= " ORDER BY pos"; - dol_syslog("Adherent_options::fetch_name_optionals_label"); + dol_syslog("Adherent_options::fetch_name_optionals_label sql=".$sql); $resql=$this->db->query($sql); if ($resql) { @@ -367,8 +352,9 @@ class AdherentOptions { // we can add this attribute to adherent object $array_name_label[$tab->name]=$tab->label; - $this->attribute_name[$tab->name]=$tab->type; + $this->attribute_type[$tab->name]=$tab->type; $this->attribute_label[$tab->name]=$tab->label; + $this->attribute_size[$tab->name]=$tab->size; } } return $array_name_label; @@ -378,6 +364,6 @@ class AdherentOptions print dol_print_error($this->db); } } - + } ?> diff --git a/htdocs/adherents/options.php b/htdocs/adherents/options.php index 53481fb479a..c91a126ae00 100644 --- a/htdocs/adherents/options.php +++ b/htdocs/adherents/options.php @@ -61,6 +61,7 @@ if ($_POST["action"] == 'add' && $user->rights->adherent->configurer) } } +// Rename field if ($_POST["action"] == 'update' && $user->rights->adherent->configurer) { if ($_POST["button"] != $langs->trans("Cancel")) @@ -70,7 +71,7 @@ if ($_POST["action"] == 'update' && $user->rights->adherent->configurer) $adho->update($_POST['attrname'],$_POST['type'],$_POST['size']); if (isset($_POST['label'])) { - $adho->update_label($_POST['attrname'],$_POST['label']); + $adho->update_label($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['size']); } Header("Location: ".$_SERVER["PHP_SELF"]); exit; @@ -108,31 +109,33 @@ if ($_GET["action"] == 'delete' && $user->rights->adherent->configurer) llxHeader('',$langs->trans("OptionalFieldsSetup"),'EN:Module_Foundations|FR:Module_Adhérents|ES:Módulo_Miembros'); -print_titre($langs->trans("OptionalFieldsSetup")); -print '
'; +print_fiche_titre($langs->trans("OptionalFieldsSetup")); if ($mesg) print '
'.$mesg.'

'; // Load attribute_label $adho->fetch_name_optionals_label(); -print ""; +print "
"; print ''; -print ''; print ''; -print ''; +print ''; +print ''; +print ''; +print ''; print "\n"; $var=True; -foreach($adho->attribute_name as $key => $value) +foreach($adho->attribute_type as $key => $value) { $var=!$var; print ""; - print "\n"; - print "\n"; - print "\n"; - print "\n"; + print "\n"; + print "\n"; + print '\n"; + print '\n"; print ""; // $i++; @@ -144,7 +147,7 @@ print "
'.$langs->trans("Label").''.$langs->trans("AttributeCode").''.$langs->trans("Type").' '.$langs->trans("Label").''.$langs->trans("Type").''.$langs->trans("Size").' 
".$adho->attribute_label[$key]." $key$value".img_edit().""; + print "".$key."".$adho->attribute_label[$key]."".$adho->attribute_type[$key]."'.$adho->attribute_size[$key]."'.img_edit().''; print "  ".img_delete()."
"; * Barre d'actions * */ -if ($_GET["action"] != 'create') +if ($_GET["action"] != 'create' && $_GET["action"] != 'edit') { print '
'; print "".$langs->trans("NewAttribute").""; @@ -161,12 +164,11 @@ if ($_GET["action"] != 'create') if ($_GET["action"] == 'create') { print "
"; - print_titre($langs->trans('NewAttribute')); print '
'; print ''; - print ''; + print '
'; print ''; @@ -194,7 +196,7 @@ if ($_GET["action"] == 'create') /* ************************************************************************** */ if ($_GET["attrname"] && $_GET["action"] == 'edit') { - + print "
"; print_titre($langs->trans("FieldEdition",$_GET["attrname"])); /* @@ -204,17 +206,29 @@ if ($_GET["attrname"] && $_GET["action"] == 'edit') print ''; print ''; print ''; - print '
'; + print '
'; - print ''; - print ''; - list($type,$size)=preg_split('/\(|\)/',$adho->attribute_name[$_GET["attrname"]]); - print ''; + print ''; + print ''; + print ''; + // Label + print ''; + print ''; + print ''; + $type=$adho->attribute_type[$_GET["attrname"]]; + $size=$adho->attribute_size[$_GET["attrname"]]; + print ''; + print ''; print '';
'.$langs->trans("Label").'
'.$langs->trans("AttributeName").''.$_GET["attrname"].' 
'.$langs->trans("Type").''; - $form->select_array('type',array('varchar'=>$langs->trans('String'), + // Code + print '
'.$langs->trans("AttributeCode").''.$_GET["attrname"].' 
'.$langs->trans("Label").'
'.$langs->trans("Type").''; + $type2label=array('varchar'=>$langs->trans('String'), 'text'=>$langs->trans('Text'), 'int'=>$langs->trans('Int'), 'date'=>$langs->trans('Date'), - 'datetime'=>$langs->trans('DateAndTime')),$type); + 'datetime'=>$langs->trans('DateAndTime')); + //$form->select_array('type',$type2label,$type); + print $type2label[$type]; + print ''; print '
'.$langs->trans("Size").'