diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 15536909bf9..8c2871426a4 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -1159,14 +1159,11 @@ else if ($action == 'update_extras') { // Fill array 'array_options' with data from update form $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); - $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute')); + if($ret < 0) $error++; - if($ret < 0) { - $error++; - $action = 'edit_extras'; - } - - if(!$error) { + if (! $error) + { // Actions on extra fields (by external module or standard code) // FIXME le hook fait double emploi avec le trigger !! $hookmanager->initHooks(array('propaldao')); @@ -1174,17 +1171,16 @@ else if ($action == 'update_extras') $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks if (empty($reshook)) { - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + $result=$object->insertExtraFields(); + if ($result < 0) { - $result=$object->insertExtraFields(); - if ($result < 0) - { - $error++; - } + $error++; } } else if ($reshook < 0) $error++; } + + if ($error) $action = 'edit_extras'; } if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->propal->creer) @@ -1893,20 +1889,12 @@ else print ''; } - // Other attributes + // Other attributes (TODO Move this into an include) $res=$object->fetch_optionals($object->id,$extralabels); $parameters=array('colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook if (empty($reshook) && ! empty($extrafields->attribute_label)) { - if ($action == 'edit_extras') - { - print '
'; - print ''; - print ''; - print ''; - } - foreach($extrafields->attribute_label as $key=>$label) { if ($action == 'edit_extras') { @@ -1929,35 +1917,28 @@ else $value = isset($_POST["options_".$key])?dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]):$db->jdate($object->array_options['options_'.$key]); } - if ($action == 'edit_extras' && $user->rights->propal->creer) + if ($action == 'edit_extras' && $user->rights->propal->creer && GETPOST('attribute') == $key) { + print ''; + print ''; + print ''; + print ''; + print ''; + print $extrafields->showInputField($key,$value); + + print ''; + + print '
'; } else { print $extrafields->showOutputField($key,$value); + if ($object->statut == 0 && $user->rights->propal->creer) print ''.img_picto('','edit').' '.$langs->trans('Modify').''; } print ''."\n"; } } - - if(count($extrafields->attribute_label) > 0) { - - if ($action == 'edit_extras' && $user->rights->propal->creer) - { - print ''; - print ''; - print ''; - print ''; - - } - else { - if ($object->statut == 0 && $user->rights->propal->creer) - { - print ''.img_picto('','edit').' '.$langs->trans('Modify').''; - } - } - } } // Amount HT diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 737e31cca7f..697d47c78bf 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -1179,12 +1179,11 @@ else if ($action == 'update_extras') { // Fill array 'array_options' with data from update form $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); - $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute')); + if($ret < 0) $error++; - if($ret < 0) - $error++; - - if(!$error) { + if (! $error) + { // Actions on extra fields (by external module or standard code) // FIXME le hook fait double emploi avec le trigger !! $hookmanager->initHooks(array('orderdao')); @@ -1192,22 +1191,16 @@ else if ($action == 'update_extras') $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks if (empty($reshook)) { - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + $result=$object->insertExtraFields(); + if ($result < 0) { - $result=$object->insertExtraFields(); - if ($result < 0) - { - $error++; - } + $error++; } } else if ($reshook < 0) $error++; } - else - { - $action = 'edit_extras'; - } - + + if ($error) $action = 'edit_extras'; } /* @@ -2208,20 +2201,12 @@ else print ''; } - // Other attributes + // Other attributes (TODO Move this into an include) $res=$object->fetch_optionals($object->id,$extralabels); $parameters=array('colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook if (empty($reshook) && ! empty($extrafields->attribute_label)) { - if ($action == 'edit_extras') - { - print '
'; - print ''; - print ''; - print ''; - } - foreach($extrafields->attribute_label as $key=>$label) { if ($action == 'edit_extras') { @@ -2244,35 +2229,27 @@ else $value = isset($_POST["options_".$key])?dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]):$db->jdate($object->array_options['options_'.$key]); } - if ($action == 'edit_extras' && $user->rights->commande->creer) + if ($action == 'edit_extras' && $user->rights->commande->creer && GETPOST('attribute') == $key) { + print ''; + print ''; + print ''; + print ''; + print ''; + print $extrafields->showInputField($key,$value); + + print ''; + print '
'; } else { print $extrafields->showOutputField($key,$value); + if ($object->statut == 0 && $user->rights->commande->creer) print ''.img_picto('','edit').' '.$langs->trans('Modify').''; } print ''."\n"; } } - - if(count($extrafields->attribute_label) > 0) { - - if ($action == 'edit_extras' && $user->rights->commande->creer) - { - print ''; - print ''; - print ''; - print ''; - - } - else { - if ($object->statut == 0 && $user->rights->commande->creer) - { - print ''.img_picto('','edit').' '.$langs->trans('Modify').''; - } - } - } } $rowspan=4; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index a2c9dc80594..191d48c4fdf 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1926,11 +1926,11 @@ if ($action == 'update_extras') { // Fill array 'array_options' with data from add form $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); - $ret = $extrafields->setOptionalsFromPost($extralabels,$object); - if($ret < 0) - $error++; + $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute')); + if ($ret < 0) $error++; - if(!$error) { + if (! $error) + { // Actions on extra fields (by external module or standard code) // FIXME le hook fait double emploi avec le trigger !! $hookmanager->initHooks(array('invoicedao')); @@ -1938,22 +1938,16 @@ if ($action == 'update_extras') $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks if (empty($reshook)) { - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + $result=$object->insertExtraFields(); + if ($result < 0) { - $result=$object->insertExtraFields(); - if ($result < 0) - { - $error++; - } + $error++; } } else if ($reshook < 0) $error++; } - else - { - $action = 'edit_extras'; - } - + + if ($error) $action = 'edit_extras'; } @@ -3413,21 +3407,13 @@ else if ($id > 0 || ! empty($ref)) print ''; } - // Other attributes + // Other attributes (TODO Move this into an include) $res=$object->fetch_optionals($object->id,$extralabels); $parameters=array('colspan' => ' colspan="2"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook if (empty($reshook) && ! empty($extrafields->attribute_label)) { - if ($action == 'edit_extras') - { - print '
'; - print ''; - print ''; - print ''; - } - foreach($extrafields->attribute_label as $key=>$label) { if ($action == 'edit_extras') { @@ -3450,35 +3436,27 @@ else if ($id > 0 || ! empty($ref)) $value = isset($_POST["options_".$key])?dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]):$db->jdate($object->array_options['options_'.$key]); } - if ($action == 'edit_extras' && $user->rights->facture->creer) + if ($action == 'edit_extras' && $user->rights->facture->creer && GETPOST('attribute') == $key) { + print ''; + print ''; + print ''; + print ''; + print ''; + print $extrafields->showInputField($key,$value); + + print ''; + print '
'; } else { print $extrafields->showOutputField($key,$value); + if ($object->statut == 0 && $user->rights->facture->creer) print ''.img_picto('','edit').' '.$langs->trans('Modify').''; } print ''."\n"; } } - - if(count($extrafields->attribute_label) > 0) { - - if ($action == 'edit_extras' && $user->rights->facture->creer) - { - print ''; - print ''; - print ''; - print ''; - - } - else { - if ($object->statut == 0 && $user->rights->facture->creer) - { - print ''.img_picto('','edit').' '.$langs->trans('Modify').''; - } - } - } } print '
'; diff --git a/htdocs/compta/facture/admin/facture_cust_extrafields.php b/htdocs/compta/facture/admin/facture_cust_extrafields.php index a44d67d87a9..0efcb94d079 100644 --- a/htdocs/compta/facture/admin/facture_cust_extrafields.php +++ b/htdocs/compta/facture/admin/facture_cust_extrafields.php @@ -146,7 +146,9 @@ if ($action == 'create') /* ************************************************************************** */ if ($action == 'edit' && ! empty($attrname)) { - print "
"; + $langs->load("members"); + + print "
"; print_titre($langs->trans("FieldEdition", $attrname)); require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php'; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index b3e5f8f47d8..b17bc624a3c 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2142,10 +2142,12 @@ abstract class CommonObject */ function insertExtraFields() { - global $langs; + global $conf,$langs; $error=0; + if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used + if (! empty($this->array_options)) { // Check parameters @@ -2249,7 +2251,7 @@ abstract class CommonObject $out = ''; - if(count($extrafields->attribute_label) > 0) + if (count($extrafields->attribute_label) > 0) { $out .= "\n"; $out .= ' '; diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index c651603451d..e9d02fe4fd0 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -688,54 +688,52 @@ class ExtraFields { $param_list=array_keys($param['options']); $InfoFieldList = explode(":", $param_list[0]); + // 0 : tableName + // 1 : label field name + // 2 : key fields name (if differ of rowid) + // 3 : key field parent (for dependent lists) + // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value + $keyList=(empty($InfoFieldList[2])?'rowid':$InfoFieldList[2].' as rowid'); - // 0 1 : tableName - // 1 2 : label field name Nom du champ contenant le libelle - // 2 3 : key fields name (if differ of rowid) - // 3 4 : key field parent (for dependent lists) - // 4 5 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value - - - $keyList='rowid'; - - if (count($InfoFieldList)>=3) { + if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) + { list($parentName, $parentField) = explode('|', $InfoFieldList[3]); $keyList.= ', '.$parentField; } - if (count($InfoFieldList)>=4 && !empty($InfoFieldList[4])) { + if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) + { if (strpos($InfoFieldList[4], 'extra')!==false) { $keyList='main.'.$InfoFieldList[2].' as rowid'; - }else { + } else { $keyList=$InfoFieldList[2].' as rowid'; } } - $fields_label = explode('|',$InfoFieldList[1]); - if(is_array($fields_label)) { - $keyList .=', '; - $keyList .= implode(', ', $fields_label); - } - - $fields_label = explode('|',$InfoFieldList[1]); - if(is_array($fields_label)) { + if (is_array($fields_label)) + { $keyList .=', '; $keyList .= implode(', ', $fields_label); } + $sqlwhere=''; $sql = 'SELECT '.$keyList; $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; - if (!empty($InfoFieldList[4])) { - + if (!empty($InfoFieldList[4])) + { //We have to join on extrafield table - if (strpos($InfoFieldList[4], 'extra')!==false) { + if (strpos($InfoFieldList[4], 'extra')!==false) + { $sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra'; - $sql.= ' WHERE extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4]; - }else { - $sql.= ' WHERE '.$InfoFieldList[4]; + $sqlwhere.= ' AND extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4]; + } + else + { + $sqlwhere.= ' AND '.$InfoFieldList[4]; } } - //$sql.= ' WHERE entity = '.$conf->entity; + if (in_array($InfoFieldList[0],array('tablewithentity'))) $sqlwhere.= ' AND entity = '.$conf->entity; // Some tables may have field, some other not. For the moment we disable it. + $sql.=preg_replace('/^ AND /','',$sqlwhere); //print $sql; dol_syslog(get_class($this).'::showInputField type=sellist sql='.$sql); @@ -807,6 +805,9 @@ class ExtraFields } $this->db->free($resql); } + else { + print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.
'; + } } $out.=''; } @@ -1005,13 +1006,14 @@ class ExtraFields } /** - * Fill array_options array for object by extrafields value (using for data send by forms) + * Fill array_options property of object by extrafields value (using for data sent by forms) * * @param array $extralabels $array of extrafields - * @param object &$object object + * @param object &$object Object + * @param string $onlykey Only following key is filled * @return int 1 if array_options set / 0 if no value */ - function setOptionalsFromPost($extralabels,&$object) + function setOptionalsFromPost($extralabels,&$object,$onlykey='') { global $_POST, $langs; $nofillrequired='';// For error when required field left blank @@ -1022,6 +1024,8 @@ class ExtraFields // Get extra fields foreach ($extralabels as $key => $value) { + if (! empty($onlykey) && $key != $onlykey) continue; + $key_type = $this->attribute_type[$key]; if($this->attribute_required[$key] && !GETPOST("options_$key",2)) { diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index dc8ca8a30be..3ba7fee84c4 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -3664,7 +3664,7 @@ class Form * @param string $typehour if 'select' then input hour and input min is a combo, if 'text' input hour is in text and input min is a combo * @return void */ - function select_duration($prefix,$iSecond='',$disabled=0,$typehour='select') + function select_duration($prefix, $iSecond='', $disabled=0, $typehour='select') { global $langs; @@ -3680,7 +3680,7 @@ class Form if ($typehour=='select') { print ''; - print ''; - print ''; - } - foreach($extrafields->attribute_label as $key=>$label) { if ($action == 'edit_extras') { @@ -1319,35 +1278,27 @@ else if ($id > 0 || ! empty($ref)) { $value = isset($_POST["options_".$key])?dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]):$db->jdate($object->array_options['options_'.$key]); } - if ($action == 'edit_extras' && $user->rights->ficheinter->creer) + if ($action == 'edit_extras' && $user->rights->ficheinter->creer && GETPOST('attribute') == $key) { + print '
'; + print ''; + print ''; + print ''; + print ''; + print $extrafields->showInputField($key,$value); + + print ''; + print '
'; } else { print $extrafields->showOutputField($key,$value); + if ($object->statut == 0 && $user->rights->ficheinter->creer) print ''.img_picto('','edit').' '.$langs->trans('Modify').''; } print ''."\n"; } } - - if(count($extrafields->attribute_label) > 0) { - - if ($action == 'edit_extras' && $user->rights->ficheinter->creer) - { - print ''; - print ''; - print ''; - print ''; - - } - else { - if ($object->statut == 0 && $user->rights->ficheinter->creer) - { - print ''.img_picto('','edit').' '.$langs->trans('Modify').''; - } - } - } } print "
"; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 46e2fbd3f77..b9b5de0abb3 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1005,6 +1005,7 @@ BrowserIsKO=You are using the web browser %s. This browser is known to be a bad XDebugInstalled=XDebug est chargé. XCacheInstalled=XCache is loaded. AddRefInList=Display customer/supplier ref into list (select list or combobox) and most of hyperlink +FieldEdition=Edition of field %s ##### Module password generation PasswordGenerationStandard=Return a password generated according to internal Dolibarr algorithm: 8 characters containing shared numbers and characters in lowercase. PasswordGenerationNone=Do not suggest any generated password. Password must be type in manually. diff --git a/htdocs/langs/en_US/members.lang b/htdocs/langs/en_US/members.lang index ec925209b2c..e7c056ef5ee 100644 --- a/htdocs/langs/en_US/members.lang +++ b/htdocs/langs/en_US/members.lang @@ -118,7 +118,6 @@ LastMembers=Last %s members LastMembersModified=Last %s modified members LastSubscriptionsModified=Last %s modified subscriptions AttributeName=Attribute name -FieldEdition=Edition of field %s String=String Text=Text Int=Int diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index c841e290d46..dde859dcf2b 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -1017,6 +1017,7 @@ EncryptedPasswordInDatabase=Permettre le chiffrement des mots de passe dans la b DisableForgetPasswordLinkOnLogonPage=Ne pas afficher le lien "Mot de passe oublié" sur la page de connexion UsersSetup=Configuration du module utilisateurs UserMailRequired=Email requis pour créer un nouvel utilisateur +FieldEdition=Édition du champ %s ##### Company setup ##### CompanySetup=Configuration du module Tiers CompanyCodeChecker=Modèle de génération et contrôle des codes tiers (clients/fournisseurs) diff --git a/htdocs/langs/fr_FR/members.lang b/htdocs/langs/fr_FR/members.lang index 4b1c8b8d28b..9f508ff3fcd 100644 --- a/htdocs/langs/fr_FR/members.lang +++ b/htdocs/langs/fr_FR/members.lang @@ -118,7 +118,6 @@ LastMembers=Les %s derniers adhérents LastMembersModified=Les %s derniers adhérents modifiés LastSubscriptionsModified=Les %s dernières adhésions modifiées AttributeName=Nom de l'attribut -FieldEdition=Édition du champ %s String=Chaîne Text=Texte long Int=Numérique