diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index e35c8d2940d..7cf90691655 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -81,6 +81,9 @@ $result = restrictedArea($user, 'propal', $id);
$object = new Propal($db);
$extrafields = new ExtraFields($db);
+// fetch optionals attributes and labels
+$extralabels=$extrafields->fetch_name_optionals_label('propal');
+
// Load object
if ($id > 0 || ! empty($ref))
{
@@ -338,15 +341,9 @@ else if ($action == 'add' && $user->rights->propal->creer)
}
}
- // 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);
+
$id = $object->create($user);
}
@@ -1107,14 +1104,10 @@ else if ($action == 'down' && $user->rights->propal->creer)
}
else 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 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 !!
$hookmanager->initHooks(array('propaldao'));
@@ -1208,9 +1201,6 @@ $formfile = new FormFile($db);
$formpropal = new FormPropal($db);
$companystatic=new Societe($db);
-// fetch optionals attributes and labels
-$extralabels=$extrafields->fetch_name_optionals_label('propal');
-
$now=dol_now();
// Add new proposal
@@ -1872,6 +1862,13 @@ else
print '
| attribute_required[$key])) print ' class="fieldrequired"';
print '>'.$label.' | ';
+
+ // 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);
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 233ebaa4f32..935d475bb9e 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -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 '';
}
-
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 ' |
| attribute_required[$key])) print ' class="fieldrequired"';
print '>'.$label.' | ';
+ // 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);
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 79a471a0251..b128455b8ff 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -2132,15 +2132,19 @@ abstract class CommonObject
case 'price':
$this->array_options[$key] = price2num($this->array_options[$key]);
break;
+ case 'date':
+ $this->array_options[$key] = dol_print_date($this->array_options[$key],'dayrfc');
+ break;
+ case 'datetime':
+ $this->array_options[$key] = dol_print_date($this->array_options[$key],'dayhourrfc');
+ break;
}
- }
-
+ }
$this->db->begin();
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields WHERE fk_object = ".$this->id;
dol_syslog(get_class($this)."::insertExtraFields delete sql=".$sql_del);
$this->db->query($sql_del);
-
$sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."_extrafields (fk_object";
foreach($this->array_options as $key => $value)
{
diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php
index 5b12672f6ce..f9398c21cb8 100755
--- a/htdocs/core/class/extrafields.class.php
+++ b/htdocs/core/class/extrafields.class.php
@@ -582,7 +582,7 @@ class ExtraFields
* Return HTML string to put an input field into a page
*
* @param string $key Key of attribute
- * @param string $value Value to show
+ * @param string $value Value to show (for date type it must be in timestamp format)
* @param string $moreparam To add more parametes on html input tag
* @return void
*/
@@ -619,7 +619,13 @@ class ExtraFields
{
$tmp=explode(',',$size);
$newsize=$tmp[0];
- $out='';
+ if(!class_exists('Form'))
+ require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
+ $formstat = new Form($db);
+
+ $showtime = in_array($type,array('datetime')) ? 1 : 0;
+ $out = $formstat->select_date($value, 'options_'.$key, $showtime, $showtime, $required, '', 1, 1, 0, 0, 1);
+ //$out='';
}
elseif (in_array($type,array('int','double')))
{
@@ -670,9 +676,10 @@ class ExtraFields
}
$out.='';
}
- // Add comments
+ /* Add comments
if ($type == 'date') $out.=' (YYYY-MM-DD)';
elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)';
+ */
return $out;
}
@@ -698,10 +705,12 @@ class ExtraFields
if ($type == 'date')
{
$showsize=10;
+ $value=dol_print_date($value,'day');
}
elseif ($type == 'datetime')
{
$showsize=19;
+ $value=dol_print_date($value,'dayhour');
}
elseif ($type == 'int')
{
@@ -752,5 +761,42 @@ class ExtraFields
$out = ' |
| '.$this->attribute_label[$key].' |
';
return $out;
}
+
+ /**
+ * Fill array_options array for object by extrafields value (using for data send by forms)
+ *
+ * @param array $extralabels $array of extrafields
+ * @param object $object object
+ * @return int 1 if array_options set / 0 if no value
+ */
+ function setOptionalsFromPost($extralabels,&$object)
+ {
+ global $_POST;
+
+ if (is_array($extralabels))
+ {
+ // Get extra fields
+ foreach ($extralabels as $key => $value)
+ {
+ $key_type = $this->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;
+ }
+
+ return 1;
+ }
+ else {
+ return 0;
+ }
+ }
}
?>
diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php
index 80de6ec7146..0972d93f26a 100644
--- a/htdocs/societe/soc.php
+++ b/htdocs/societe/soc.php
@@ -55,6 +55,9 @@ if ($user->societe_id) $socid=$user->societe_id;
$object = new Societe($db);
$extrafields = new ExtraFields($db);
+// fetch optionals attributes and labels
+$extralabels=$extrafields->fetch_name_optionals_label('company');
+
// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
$object->getCanvas($socid);
$canvas = $object->canvas?$object->canvas:GETPOST("canvas");
@@ -166,15 +169,9 @@ if (empty($reshook))
$object->commercial_id = GETPOST('commercial_id');
$object->default_lang = GETPOST('default_lang');
- // 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 (GETPOST('deletephoto')) $object->logo = '';
else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
@@ -508,9 +505,6 @@ if (empty($reshook))
* View
*/
-// fetch optionals attributes and labels
-$extralabels=$extrafields->fetch_name_optionals_label('company');
-
$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
llxHeader('',$langs->trans("ThirdParty"),$help_url);
@@ -1000,6 +994,13 @@ else
if (! empty($extrafields->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 ' | ';