Use of new function to set optionals from add / update form

Format date display for data from JS calendar (date type extrafield)
This commit is contained in:
jfefe 2013-03-30 10:46:23 +01:00
parent f3a7d497c6
commit e99ba51f1d
3 changed files with 23 additions and 41 deletions

View File

@ -1104,22 +1104,9 @@ else if ($action == 'down' && $user->rights->propal->creer)
}
else if ($action == 'update_extras')
{
// Get extra fields
foreach ($extralabels as $key => $value)
{
$key_type = $extrafields->attribute_type[$key];
if (in_array($key_type,array('date','datetime')))
{
// Clean parameters
$value_key=dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]);
}
else
{
$value_key=GETPOST("options_".$key);
}
$object->array_options["options_".$key]=$value_key;
}
// Fill array 'array_options' with data from update form
$extralabels=$extrafields->fetch_name_optionals_label('propal');
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
// Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !!
@ -1875,6 +1862,13 @@ else
print '<tr><td';
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
print '>'.$label.'</td><td colspan="3">';
// Convert date into timestamp format
if (in_array($extrafields->attribute_type[$key],array('date','datetime')))
{
$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"]):$object->array_options['options_'.$key];
}
if ($action == 'edit_extras' && $user->rights->propal->creer)
{
print $extrafields->showInputField($key,$value);

View File

@ -1738,14 +1738,10 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->facture-
if ($action == 'update_extras')
{
// 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
$extralabels=$extrafields->fetch_name_optionals_label('facture');
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
// Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !!
$hookmanager->initHooks(array('invoicedao'));
@ -3125,7 +3121,6 @@ else if ($id > 0 || ! empty($ref))
print '<input type="hidden" name="id" value="'.$object->id.'">';
}
foreach($extrafields->attribute_label as $key=>$label)
{
$value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
@ -3138,6 +3133,12 @@ else if ($id > 0 || ! empty($ref))
print '<tr><td';
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
print '>'.$label.'</td><td colspan="5">';
// Convert date into timestamp format
if (in_array($extrafields->attribute_type[$key],array('date','datetime')))
{
$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"]):$object->array_options['options_'.$key];
}
if ($action == 'edit_extras' && $user->rights->facture->creer)
{
print $extrafields->showInputField($key,$value);

View File

@ -169,22 +169,9 @@ if (empty($reshook))
$object->commercial_id = GETPOST('commercial_id');
$object->default_lang = GETPOST('default_lang');
// Get extra fields
foreach ($extralabels as $key => $value)
{
$key_type = $extrafields->attribute_type[$key];
if (in_array($key_type,array('date','datetime')))
{
// Clean parameters
$value_key=dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]);
}
else
{
$value_key=GETPOST("options_".$key);
}
$object->array_options["options_".$key]=$value_key;
}
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if (GETPOST('deletephoto')) $object->logo = '';
else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);