From 988dc29f156b846658df3d15fae3f2ab37e992b8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 1 Feb 2012 20:44:06 +0100 Subject: [PATCH] New: Extra fields support int type. --- ChangeLog | 1 + htdocs/core/admin_extrafields.inc.php | 25 ++++++++++-- htdocs/core/class/CMailFile.class.php | 13 +++--- htdocs/core/class/commonobject.class.php | 33 ++++++++++++++- htdocs/core/class/extrafields.class.php | 43 ++++++++++++++------ htdocs/langs/en_US/admin.lang | 1 + htdocs/langs/en_US/errors.lang | 2 + htdocs/langs/fr_FR/admin.lang | 1 + htdocs/langs/fr_FR/errors.lang | 2 + htdocs/societe/admin/societe_extrafields.php | 4 +- 10 files changed, 99 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8c8b7693823..5ee900b9af7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -44,6 +44,7 @@ For users: - New: Value of data into charts are visible on mouse hover. - New: Import wizard can import contacts. - New: Install process is now two times faster. +- New: Extra fields support int type. - Fix: Can use POS module with several concurrent users. For developers: diff --git a/htdocs/core/admin_extrafields.inc.php b/htdocs/core/admin_extrafields.inc.php index 00d4e4cfa48..e723cc2ac5b 100644 --- a/htdocs/core/admin_extrafields.inc.php +++ b/htdocs/core/admin_extrafields.inc.php @@ -21,17 +21,27 @@ * \brief Code for actions on extrafields admin pages */ +$maxsizestring=255; +$maxsizeint=10; + // Add attribute if ($action == 'add') { if ($_POST["button"] != $langs->trans("Cancel")) { // Check values - if (GETPOST('type')=='varchar' && GETPOST('size') > 255) + if (GETPOST('type')=='varchar' && GETPOST('size') > $maxsizestring) { $error++; $langs->load("errors"); - $mesg=$langs->trans("ErrorSizeTooLongForVarcharType"); + $mesg=$langs->trans("ErrorSizeTooLongForVarcharType",$maxsizestring); + $action = 'create'; + } + if (GETPOST('type')=='int' && GETPOST('size') > $maxsizeint) + { + $error++; + $langs->load("errors"); + $mesg=$langs->trans("ErrorSizeTooLongForIntType",$maxsizeint); $action = 'create'; } @@ -69,11 +79,18 @@ if ($action == 'update') if ($_POST["button"] != $langs->trans("Cancel")) { // Check values - if (GETPOST('type')=='varchar' && GETPOST('size') > 255) + if (GETPOST('type')=='varchar' && GETPOST('size') > $maxsizestring) { $error++; $langs->load("errors"); - $mesg=$langs->trans("ErrorSizeTooLongForVarcharType"); + $mesg=$langs->trans("ErrorSizeTooLongForVarcharType",$maxsizestring); + $action = 'edit'; + } + if (GETPOST('type')=='int' && GETPOST('size') > $maxsizeint) + { + $error++; + $langs->load("errors"); + $mesg=$langs->trans("ErrorSizeTooLongForIntType",$maxsizeint); $action = 'edit'; } diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index 810e6d42fd0..c7cb21883a2 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -185,6 +185,8 @@ class CMailFile $this->addr_bcc = $addr_bcc; $this->deliveryreceipt = $deliveryreceipt; $smtp_headers = $this->write_smtpheaders(); + // TODO ? Add 'Date: ' . date("r") . "\r\n"; before X-Mailer + // TODO ? Add 'Message-ID: <' . time() . '.SMTPs@' . $host . ">\r\n"; before X-Mailer // Define mime_headers $mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list); @@ -219,16 +221,15 @@ class CMailFile $files_encoded = $this->write_files($filename_list,$mimetype_list,$mimefilename_list); } - // We now define $this->headers et $this->message + // We now define $this->headers and $this->message $this->headers = $smtp_headers . $mime_headers; - - $this->message = $text_body . $images_encoded . $files_encoded; - $this->message.= "--" . $this->mixed_boundary . "--" . $this->eol; - // On nettoie le header pour qu'il ne se termine pas par un retour chariot. // Ceci evite aussi les lignes vides en fin qui peuvent etre interpretees // comme des injections mail par les serveurs de messagerie. - //$this->headers = preg_replace("/([\r\n]+)$/i","",$this->headers); + $this->headers = preg_replace("/([\r\n]+)$/i","",$this->headers); + + $this->message = $text_body . $images_encoded . $files_encoded; + $this->message.= "--" . $this->mixed_boundary . "--" . $this->eol; } else if ($conf->global->MAIN_MAIL_SENDMODE == 'smtps') { diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index d5fbfed727c..4465d79aa06 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1778,14 +1778,45 @@ abstract class CommonObject /** - * Add/Update extra fields + * Add/Update all extra fields values for the current object. + * All data to describe values to insert are stored into $this->array_options=array('keyextrafield'=>'valueextrafieldtoadd') * * @return void */ function insertExtraFields() { + global $langs; + if (count($this->array_options) > 0) { + // Check parameters + $langs->load('admin'); + require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php"); + $extrafields = new ExtraFields($this->db); + $optionsArray = $extrafields->fetch_name_optionals_label($this->elementType); + + foreach($this->array_options as $key => $value) + { + $attributeKey = substr($key,8); // Remove 'options_' prefix + $attributeType = $extrafields->attribute_type[$attributeKey]; + $attributeSize = $extrafields->attribute_size[$attributeKey]; + $attributeLabel = $extrafields->attribute_label[$attributeKey]; + switch ($attributeType) + { + case 'int': + if (!is_numeric($value) && $value!='') + { + $error++; $this->errors[]=$langs->trans("ExtraFieldHasWrongValue",$attributeLabel); + return -1; + } + elseif ($value=='') + { + $this->array_options[$key] = null; + } + break; + } + } + $this->db->begin(); $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields WHERE fk_object = ".$this->id; diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 86ebf20bf6f..ce3860412fe 100755 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -27,8 +27,7 @@ */ /** - * \class ExtraFields - * \brief Class to manage standard extra fields + * Class to manage standard extra fields */ class ExtraFields { @@ -46,11 +45,11 @@ class ExtraFields /** * Constructor * - * @param DoliDB $DB Database handler + * @param DoliDB $db Database handler */ - function ExtraFields($DB) + function ExtraFields($db) { - $this->db = $DB ; + $this->db = $db; $this->error = array(); $this->attribute_type = array(); $this->attribute_label = array(); @@ -60,6 +59,7 @@ class ExtraFields /** * Add a new extra field parameter + * * @param attrname code of attribute * @param label label of attribute * @param type Type of attribute ('int', 'text', 'varchar', 'date', 'datehour') @@ -88,6 +88,7 @@ class ExtraFields /** * Add a new optionnal attribute + * * @param attrname code of attribute * @param type Type of attribute ('int', 'text', 'varchar', 'date', 'datehour') * @param length Size/length of attribute @@ -129,6 +130,7 @@ class ExtraFields /** * Add description of a new optionnal attribute + * * @param attrname code of attribute * @param label label of attribute * @param type Type of attribute ('int', 'text', 'varchar', 'date', 'datehour') @@ -172,6 +174,7 @@ class ExtraFields /** * Delete an optionnal attribute + * * @param attrname Code of attribute to delete * @param elementtype Element type ('member', 'product', 'company', ...) * @return int < 0 if KO, 0 if nothing is done, 1 if OK @@ -211,6 +214,7 @@ class ExtraFields /** * Delete description of an optionnal attribute + * * @param attrname Code of attribute to delete * @param elementtype Element type ('member', 'product', 'company', ...) * @return int < 0 if KO, 0 if nothing is done, 1 if OK @@ -246,6 +250,7 @@ class ExtraFields /** * Modify type of a personalized attribute + * * @param attrname name of attribute * @param type type of attribute * @param length length of attribute @@ -288,11 +293,12 @@ class ExtraFields /** * Modify description of personalized attribute - * @param attrname name of attribute - * @param label label of attribute - * @param type type of attribute - * @param length length of attribute - * @param elementtype Element type ('member', 'product', 'company', ...) + * + * @param string $attrname Name of attribute + * @param string $label Label of attribute + * @param string $type Type of attribute + * @param int $length Length of attribute + * @param string $elementtype Element type ('member', 'product', 'company', ...) */ function update_label($attrname,$label,$type,$size,$elementtype='member') { @@ -350,6 +356,8 @@ class ExtraFields /** * Load array of labels + * + * @return void */ function fetch_optionals() { @@ -359,6 +367,9 @@ class ExtraFields /** * Load array this->attribute_label + * + * @param string $elementtype Type of element + * @return array Array of attributes for all extra fields */ function fetch_name_optionals_label($elementtype='member') { @@ -429,7 +440,11 @@ class ExtraFields if ($showsize > 48) $showsize=48; } - if ($type == 'varchar') + if ($type == 'int') + { + $out=''; + } + else if ($type == 'varchar') { $out=''; } @@ -446,8 +461,10 @@ class ExtraFields /** * Return HTML string to put an output field into a page - * @param key Key of attribute - * @param value Value to show + * + * @param string $key Key of attribute + * @param string $value Value to show + * @return string Formated value */ function showOutputField($key,$value,$moreparam='') { diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 3b7cc939e25..7e9a02610b4 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -855,6 +855,7 @@ MAIN_PROXY_USER=Login to use the proxy server MAIN_PROXY_PASS=Password to use the proxy server DefineHereComplementaryAttributes=Define here all atributes, not already available by default, and that you want to be supported for %s. ExtraFields=Complementary attributes +ExtraFieldHasWrongValue=Attribut %s has a wrong value. SendingMailSetup=Setup of sendings by email SendmailOptionNotComplete=Warning, on some Linux systems, to send email from your email, sendmail execution setup must conatins option -ba (parameter mail.force_extra_parameters into your php.ini file). If some recipients never receive emails, try to edit this PHP parameter with mail.force_extra_parameters = -ba). PathToDocuments=Path to documents diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index b375711e4fc..0817785acce 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -51,6 +51,8 @@ ErrorPartialFile=File not received completely by server. ErrorNoTmpDir=Temporary directy %s does not exists. ErrorUploadBlockedByAddon=Upload blocked by a PHP/Apache plugin. ErrorFileSizeTooLarge=File size is too large. +ErrorSizeTooLongForIntType=Size too long for int type (%s digits maximum) +ErrorSizeTooLongForVarcharType=Size too long for string type (%s chars maximum) ErrorFieldCanNotContainSpecialCharacters=Field %s must not contains special characters. ErrorNoAccountancyModuleLoaded=No accountancy module activated ErrorExportDuplicateProfil=This profil name already exists for this export set. diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 0c775b5216d..9f88f1ef975 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -863,6 +863,7 @@ MAIN_PROXY_USER=Login pour passer le serveur proxy mandataire MAIN_PROXY_PASS=Mot de passe pour passer le serveur proxy mandataire DefineHereComplementaryAttributes=Definissez ici la liste des attributs supplémentaire, non disponible en standard, et que vous voulez voir gérez sur les %s. ExtraFields=Attributs suplémentaires +ExtraFieldHasWrongValue=L'attribut %s a une valeur incorrecte. SendingMailSetup=Configuration de l'envoi par mail SendmailOptionNotComplete=Attention, sur certains systèmes Linux, avec cette méthode d'envoi, pour pouvoir envoyer des mails en votre nom, la configuration d'exécution de sendmail doit contenir l'option -ba (paramètre mail.force_extra_parameters dans le fichier php.ini). Si certains de vos destinataires ne reçoivent pas de message, essayer de modifer ce paramètre PHP avec mail.force_extra_parameters = -ba. PathToDocuments= Chemin d'accès aux documents diff --git a/htdocs/langs/fr_FR/errors.lang b/htdocs/langs/fr_FR/errors.lang index 82a78406c04..b708c2aba1a 100644 --- a/htdocs/langs/fr_FR/errors.lang +++ b/htdocs/langs/fr_FR/errors.lang @@ -52,6 +52,8 @@ ErrorPartialFile=Fichier non reçu intégralement par le serveur. ErrorNoTmpDir=Répertoire temporaire de réception %s inexistant. ErrorUploadBlockedByAddon=Upload bloqué par un plugin PHP/Apache. ErrorFileSizeTooLarge=La taille du fichier est trop grande. +ErrorSizeTooLongForIntType=Longueur de champ trop longue pour le type int (%s chiffres maximum) +ErrorSizeTooLongForVarcharType=Longueur de champ trop longue pour le type chaine (%s caractères maximum) ErrorFieldCanNotContainSpecialCharacters=Le champ %s ne peut contenir de caractères spéciaux. ErrorNoAccountancyModuleLoaded=Aucun module de comptabilité activé ErrorExportDuplicateProfil=Ce nom de profil existe déjà pour ce lot d'export. diff --git a/htdocs/societe/admin/societe_extrafields.php b/htdocs/societe/admin/societe_extrafields.php index a1b73fdc711..307ee163c9e 100755 --- a/htdocs/societe/admin/societe_extrafields.php +++ b/htdocs/societe/admin/societe_extrafields.php @@ -208,7 +208,7 @@ if ($_GET["attrname"] && $action == 'edit') } -$db->close(); - llxFooter(); + +$db->close(); ?>