diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php index 787cad2664f..e76d41a6fd2 100644 --- a/htdocs/adherents/fiche.php +++ b/htdocs/adherents/fiche.php @@ -64,6 +64,9 @@ if (! empty($conf->mailmanspip->enabled)) $object = new Adherent($db); $extrafields = new ExtraFields($db); +// fetch optionals attributes and labels +$extralabels=$extrafields->fetch_name_optionals_label('member'); + // Get object canvas (By default, this is not defined, so standard usage of dolibarr) $object->getCanvas($socid); $canvas = $object->canvas?$object->canvas:GETPOST("canvas"); @@ -282,14 +285,8 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->adherent->creer) $object->statut = $_POST["statut"]; $object->public = $_POST["public"]; - // Get extra fields - foreach($_POST as $key => $value) - { - if (preg_match("/^options_/",$key)) - { - $object->array_options[$key]=$_POST[$key]; - } - } + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost($extralabels,$object); // Check if we need to also synchronize user information $nosyncuser=0; @@ -451,14 +448,8 @@ if ($action == 'add' && $user->rights->adherent->creer) $object->fk_soc = $socid; $object->public = $public; - // Get extra fields - foreach($_POST as $key => $value) - { - if (preg_match("/^options_/",$key)) - { - $object->array_options[$key]=$_POST[$key]; - } - } + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost($extralabels,$object); // Check parameters if (empty($morphy) || $morphy == "-1") { @@ -684,9 +675,6 @@ if ($user->rights->adherent->creer && $action == 'confirm_add_spip' && $confirm $form = new Form($db); $formcompany = new FormCompany($db); -// fetch optionals attributes and labels -$extralabels=$extrafields->fetch_name_optionals_label('member'); - $help_url='EN:Module_Foundations|FR:Module_Adhérents|ES:Módulo_Miembros'; llxHeader('',$langs->trans("Member"),$help_url); @@ -885,15 +873,7 @@ else $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)) { - foreach($extrafields->attribute_label as $key=>$label) - { - $value=(isset($_POST["options_".$key])?GETPOST('options_'.$key,'alpha'):(isset($object->array_options["options_".$key])?$object->array_options["options_".$key]:'')); - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print '>'.$label.''; - print $extrafields->showInputField($key,$value); - print ''."\n"; - } + print $object->showOptionals($extrafields,'edit'); } /* @@ -1128,15 +1108,7 @@ else $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)) { - foreach($extrafields->attribute_label as $key=>$label) - { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print '>'.$label.''; - print $extrafields->showInputField($key,$value); - print ''."\n"; - } + print $object->showOptionals($extrafields,'edit'); } // Third party Dolibarr @@ -1458,13 +1430,7 @@ else $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)) { - foreach($extrafields->attribute_label as $key=>$label) - { - $value=$object->array_options["options_$key"]; - print "".$label.""; - print $extrafields->showOutputField($key,$value); - print "\n"; - } + print $object->showOptionals($extrafields); } // Third party Dolibarr diff --git a/htdocs/adherents/type.php b/htdocs/adherents/type.php index f4a60f55cd9..72fc3cc2a37 100644 --- a/htdocs/adherents/type.php +++ b/htdocs/adherents/type.php @@ -56,6 +56,9 @@ $result=restrictedArea($user,'adherent',$rowid,'adherent_type'); $extrafields = new ExtraFields($db); +// fetch optionals attributes and labels +$extralabels=$extrafields->fetch_name_optionals_label('adherent_type'); + if (GETPOST('button_removefilter')) { $search_lastname=""; @@ -84,14 +87,8 @@ if ($action == 'add' && $user->rights->adherent->configurer) $adht->mail_valid = trim($_POST["mail_valid"]); $adht->vote = trim($_POST["vote"]); - // Get extra fields - foreach($_POST as $key => $value) - { - if (preg_match("/^options_/",$key)) - { - $adht->array_options[$key]=GETPOST($key); - } - } + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost($extralabels,$adht); if ($adht->libelle) { @@ -127,14 +124,8 @@ if ($action == 'update' && $user->rights->adherent->configurer) $adht->mail_valid = trim($_POST["mail_valid"]); $adht->vote = trim($_POST["vote"]); - // Get extra fields - foreach($_POST as $key => $value) - { - if (preg_match("/^options_/",$key)) - { - $adht->array_options[$key]=GETPOST($key); - } - } + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost($extralabels,$adht); $adht->update($user->id); @@ -167,8 +158,6 @@ llxHeader('',$langs->trans("MembersTypeSetup"),'EN:Module_Foundations|FR:Module_ $form=new Form($db); -// fetch optionals attributes and labels -$extralabels=$extrafields->fetch_name_optionals_label('adherent_type'); // Liste of members type @@ -245,6 +234,7 @@ if (! $rowid && $action != 'create' && $action != 'edit') if ($action == 'create') { $form = new Form($db); + $adht = new AdherentType($db); print_fiche_titre($langs->trans("NewMemberType")); @@ -278,23 +268,11 @@ if ($action == 'create') // Other attributes $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook - - print "\n"; - if (empty($reshook) && ! empty($extrafields->attribute_label)) { - print '

'; - foreach($extrafields->attribute_label as $key=>$label) - { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$act->array_options["options_".$key]); - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print ' width="30%">'.$label.''."\n"; - } - print '
'; - print $extrafields->showInputField($key,$value); - print '


'; + print $adht->showOptionals($extrafields,'edit'); } + print "\n"; print '
'; print '
    '; @@ -356,23 +334,13 @@ if ($rowid > 0) // Other attributes $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook - - print ''; - - //Extra field if (empty($reshook) && ! empty($extrafields->attribute_label)) { - print '

'; - foreach($extrafields->attribute_label as $key=>$label) - { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:(isset($adht->array_options['options_'.$key])?$adht->array_options['options_'.$key]:'')); - print '\n"; - } - print '
'.$label.''; - print $extrafields->showOutputField($key,$value); - print "


'; + // View extrafields + print $adht->showOptionals($extrafields); } + print ''; print ''; /* diff --git a/htdocs/comm/action/fiche.php b/htdocs/comm/action/fiche.php index 07a6647f4bb..2851e55dfd9 100644 --- a/htdocs/comm/action/fiche.php +++ b/htdocs/comm/action/fiche.php @@ -63,6 +63,9 @@ $actioncomm = new ActionComm($db); $contact = new Contact($db); $extrafields = new ExtraFields($db); +// fetch optionals attributes and labels +$extralabels=$extrafields->fetch_name_optionals_label('actioncomm'); + //var_dump($_POST); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array @@ -203,14 +206,8 @@ if ($action == 'add_action') $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")).'
'; } - // Get extra fields - foreach($_POST as $key => $value) - { - if (preg_match("/^options_/",$key)) - { - $actioncomm->array_options[$key]=GETPOST($key); - } - } + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost($extralabels,$actioncomm); if (! $error) { @@ -343,14 +340,8 @@ if ($action == 'update') } $actioncomm->userdone = $userdone; - // Get extra fields - foreach($_POST as $key => $value) - { - if (preg_match("/^options_/",$key)) - { - $actioncomm->array_options[$key]=GETPOST($key); - } - } + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost($extralabels,$actioncomm); if (! $error) { @@ -395,9 +386,6 @@ llxHeader('',$langs->trans("Agenda"),$help_url); $form = new Form($db); $htmlactions = new FormActions($db); -// fetch optionals attributes and labels -$extralabels=$extrafields->fetch_name_optionals_label('actioncomm'); - if ($action == 'create') { $contact = new Contact($db); @@ -603,22 +591,13 @@ if ($action == 'create') $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$actioncomm,$action); // Note that $action and $object may have been modified by hook - print ''; if (empty($reshook) && ! empty($extrafields->attribute_label)) { - print '

'; - foreach($extrafields->attribute_label as $key=>$label) - { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:(isset($actioncomm->array_options["options_".$key])?$actioncomm->array_options["options_".$key]:'')); - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print ' width="30%">'.$label.''."\n"; - } - print '
'; - print $extrafields->showInputField($key,$value); - print '

'; + print $actioncomm->showOptionals($extrafields,'edit'); } + + print ''; print '

'; print ''; @@ -838,24 +817,13 @@ if ($id > 0) // Other attributes $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook - - print ''; - if (empty($reshook) && ! empty($extrafields->attribute_label)) { - print '

'; - foreach($extrafields->attribute_label as $key=>$label) - { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$act->array_options["options_".$key]); - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print ' width="30%">'.$label.''."\n"; - } - print '
'; - print $extrafields->showInputField($key,$value); - print '


'; + print $actioncomm->showOptionals($extrafields,'edit'); + } + print ''; print '

'; print '     '; diff --git a/htdocs/comm/mailing/fiche.php b/htdocs/comm/mailing/fiche.php index d04b9c7aefe..195db2d53a8 100644 --- a/htdocs/comm/mailing/fiche.php +++ b/htdocs/comm/mailing/fiche.php @@ -48,6 +48,9 @@ $result=$object->fetch($id); $extrafields = new ExtraFields($db); +// fetch optionals attributes and labels +$extralabels=$extrafields->fetch_name_optionals_label('mailing'); + // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('mailingcard')); @@ -631,8 +634,6 @@ if (! empty($_POST["cancel"])) * View */ -// fetch optionals attributes and labels -$extralabels=$extrafields->fetch_name_optionals_label('mailing'); $help_url='EN:Module_EMailing|FR:Module_Mailing|ES:Módulo_Mailing'; llxHeader('',$langs->trans("Mailing"),$help_url); @@ -661,15 +662,7 @@ if ($action == 'create') $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)) { - foreach($extrafields->attribute_label as $key=>$label) - { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print '>'.$label.''; - print $extrafields->showInputField($key,$value); - print ''."\n"; - } + print $object->showOptionals($extrafields,'edit'); } print ''; @@ -823,15 +816,7 @@ else $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)) { - foreach($extrafields->attribute_label as $key=>$label) - { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print '>'.$label.''; - print $extrafields->showInputField($key,$value); - print "\n"; - } + print $object->showOptionals($extrafields); } print ''; @@ -1072,15 +1057,7 @@ else $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)) { - foreach($extrafields->attribute_label as $key=>$label) - { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print '>'.$label.''; - print $extrafields->showInputField($key,$value); - print "\n"; - } + print $object->showOptionals($extrafields,'edit'); } print ''; diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 7cf90691655..8c51c4ff941 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -1347,24 +1347,7 @@ if ($action == 'create') $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)) { - foreach($extrafields->attribute_label as $key=>$label) - { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - - // Show separator only - if ($extrafields->attribute_type[$key] == 'separate') - { - print $extrafields->showSeparator($key); - } - else - { - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print '>'.$label.''; - print $extrafields->showInputField($key,$value); - print ''."\n"; - } - } + print $object->showOptionals($extrafields,'edit'); } print ""; @@ -1849,7 +1832,7 @@ else print ''; } - + // TODO : use showOptionals($extrafields) function foreach($extrafields->attribute_label as $key=>$label) { $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index bdd61a6ace3..116fd5fe3cb 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -1564,15 +1564,7 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G $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)) { - foreach($extrafields->attribute_label as $key=>$label) - { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print '>'.$label.''; - print $extrafields->showInputField($key,$value); - print ''."\n"; - } + print $object->showOptionals($extrafields,'edit'); } // Template to use by default @@ -2091,15 +2083,7 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G $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)) { - foreach($extrafields->attribute_label as $key=>$label) - { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print '>'.$label.''; - print $extrafields->showInputField($key,$value); - print ''."\n"; - } + print $object->showOptionals($extrafields,'edit'); } // Total HT diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 935d475bb9e..c24f09f4baa 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -2097,23 +2097,7 @@ if ($action == 'create') $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)) { - foreach($extrafields->attribute_label as $key=>$label) - { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - // Show separator only - if ($extrafields->attribute_type[$key] == 'separate') - { - print $extrafields->showSeparator($key); - } - else - { - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print '>'.$label.''; - print $extrafields->showInputField($key,$value); - print ''."\n"; - } - } + print $object->showOptionals($extrafields,'edit'); } // Modele PDF diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index 885711bb526..db0fe091cd9 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -50,6 +50,9 @@ if ($user->societe_id) $socid=$user->societe_id; $object = new Contact($db); $extrafields = new ExtraFields($db); +// fetch optionals attributes and labels +$extralabels=$extrafields->fetch_name_optionals_label('contact'); + // Get object canvas (By default, this is not defined, so standard usage of dolibarr) $object->getCanvas($id); $objcanvas=null; @@ -155,14 +158,8 @@ if (empty($reshook)) $object->birthday = dol_mktime(0,0,0,$_POST["birthdaymonth"],$_POST["birthdayday"],$_POST["birthdayyear"]); $object->birthday_alert = $_POST["birthday_alert"]; - // Get extra fields - foreach($_POST as $key => $value) - { - if (preg_match("/^options_/",$key)) - { - $object->array_options[$key]=GETPOST($key); - } - } + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost($extralabels,$object); if (! $_POST["lastname"]) { @@ -252,14 +249,8 @@ if (empty($reshook)) $object->priv = $_POST["priv"]; $object->note = $_POST["note"]; - // Get extra fields - foreach($_POST as $key => $value) - { - if (preg_match("/^options_/",$key)) - { - $object->array_options[$key]=GETPOST($key); - } - } + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost($extralabels,$object); $result = $object->update($_POST["contactid"], $user); @@ -283,8 +274,6 @@ if (empty($reshook)) * View */ -// fetch optionals attributes and labels -$extralabels=$extrafields->fetch_name_optionals_label('contact'); $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; llxHeader('',$langs->trans("ContactsAddresses"),$help_url); @@ -518,22 +507,7 @@ else $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)) { - foreach($extrafields->attribute_label as $key=>$label) - { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:(isset($object->array_options["options_".$key])?$object->array_options["options_".$key]:'')); - if ($extrafields->attribute_type[$key] == 'separate') - { - print $extrafields->showSeparator($key); - } - else - { - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print '>'.$label.''; - print $extrafields->showInputField($key,$value); - print ''."\n"; - } - } + print $object->showOptionals($extrafields,'edit'); } print "
"; @@ -740,22 +714,7 @@ else $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)) { - foreach($extrafields->attribute_label as $key=>$label) - { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - if ($extrafields->attribute_type[$key] == 'separate') - { - print $extrafields->showSeparator($key); - } - else - { - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print '>'.$label.''; - print $extrafields->showInputField($key,$value); - print "\n"; - } - } + print $object->showOptionals($extrafields,'edit'); } $object->load_ref_elements(); @@ -959,20 +918,7 @@ else $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)) { - foreach($extrafields->attribute_label as $key=>$label) - { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:(isset($object->array_options['options_'.$key])?$object->array_options['options_'.$key]:'')); - if ($extrafields->attribute_type[$key] == 'separate') - { - print $extrafields->showSeparator($key); - } - else - { - print ''.$label.''; - print $extrafields->showOutputField($key,$value); - print "\n"; - } - } + print $object->showOptionals($extrafields); } $object->load_ref_elements(); diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 5b3106afa0d..17892d4631d 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -974,40 +974,7 @@ else $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)) { - $e=0; - foreach($extrafields->attribute_label as $key=>$label) - { - $colspan='3'; - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:(isset($object->array_options["options_".$key])?$object->array_options["options_".$key]:'')); - if ($extrafields->attribute_type[$key] == 'separate') - { - print $extrafields->showSeparator($key); - } - else - { - if (($e % 2) == 0) - { - print ''; - $colspan='0'; - } - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print '>'.$label.''; - print ''; - - // Convert date into timestamp format - if (in_array($extrafields->attribute_type[$key],array('date','datetime'))) - { - $value = dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]); - } - - print $extrafields->showInputField($key,$value); - print ''; - - if (($e % 2) == 1) print ''."\n"; - $e++; - } - } + print $object->showOptionals($extrafields,'edit'); } // Ajout du logo @@ -1416,37 +1383,7 @@ else $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)) { - $old_pos=0; - $e=0; - foreach($extrafields->attribute_label as $key=>$label) - { - $colspan = '3'; - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - if ($extrafields->attribute_type[$key] == 'separate') - { - print $extrafields->showSeparator($key); - } - else - { - if (($e % 2) == 0) - { - print ''."\n"; - $colspan = '0'; - } - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print '>'.$label.''."\n"; - print ''; - print $extrafields->showInputField($key,$value); - print ""."\n"; - - if (($e % 2) == 1 ) - { - print "\n"; - } - $e++; - } - } + print $object->showOptionals($extrafields,'edit'); } // Logo print ''; diff --git a/htdocs/user/fiche.php b/htdocs/user/fiche.php index 1ef52efc85b..be62afba37f 100644 --- a/htdocs/user/fiche.php +++ b/htdocs/user/fiche.php @@ -187,14 +187,8 @@ if ($action == 'add' && $canadduser) $object->note = GETPOST("note"); $object->ldap_sid = GETPOST("ldap_sid"); - // Get extra fields - foreach($_POST as $key => $value) - { - if (preg_match("/^options_/",$key)) - { - $object->array_options[$key]=GETPOST($key); - } - } + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost($extralabels,$object); // If multicompany is off, admin users must all be on entity 0. if (! empty($conf->multicompany->enabled)) @@ -329,14 +323,8 @@ if ($action == 'update' && ! $_POST["cancel"]) $object->openid = GETPOST("openid"); $object->fk_user = GETPOST("fk_user")>0?GETPOST("fk_user"):0; - // Get extra fields - foreach($_POST as $key => $value) - { - if (preg_match("/^options_/",$key)) - { - $object->array_options[$key]=GETPOST($key); - } - } + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost($extralabels,$object); if (! empty($conf->multicompany->enabled)) { @@ -927,15 +915,7 @@ if (($action == 'create') || ($action == 'adduserldap')) $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)) { - foreach($extrafields->attribute_label as $key=>$label) - { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print '>'.$label.''; - print $extrafields->showInputField($key,$value); - print ''."\n"; - } + print $object->showOptionals($extrafields,'edit'); } print "\n"; @@ -1304,15 +1284,7 @@ else $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)) { - foreach($extrafields->attribute_label as $key=>$label) - { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print '>'.$label.''; - print $extrafields->showOutputField($key,$value); - print ''."\n"; - } + print $object->showOptionals($extrafields); } print "\n"; @@ -1921,15 +1893,7 @@ else $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)) { - foreach($extrafields->attribute_label as $key=>$label) - { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print '>'.$label.''; - print $extrafields->showInputField($key,$value); - print ''."\n"; - } + print $object->showOptionals($extrafields,'edit'); } print '';