diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index 1f211c3cb79..6cd70b273be 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -2008,67 +2008,9 @@ if ($action == 'create')
print '';
}
- // 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))
- {
- foreach ($extrafields->attribute_label as $key => $label)
- {
- if ($action == 'edit_extras')
- {
- $value = (isset($_POST ["options_" . $key]) ? $_POST ["options_" . $key] : $object->array_options ["options_" . $key]);
- }
- else
- {
- $value = $object->array_options ["options_" . $key];
- }
- if ($extrafields->attribute_type [$key] == 'separate')
- {
- print $extrafields->showSeparator($key);
- }
- else
- {
- print '
';
- print 'attribute_required [$key])) print ' class="fieldrequired"';
- print '>' . $label . ' ';
- if (($object->statut == 0 || $extrafields->attribute_alwayseditable[$key]) && $user->rights->propal->creer && ($action != 'edit_extras' || GETPOST('attribute') != $key))
- print '' . img_edit().' ';
-
- print '
';
- print ' ';
-
- // 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"]) : $db->jdate($object->array_options ['options_' . $key]);
- }
-
- if ($action == 'edit_extras' && $user->rights->propal->creer && GETPOST('attribute') == $key)
- {
- print '';
- }
- else
- {
- print $extrafields->showOutputField($key, $value);
- }
- print ' ' . "\n";
- }
- }
- }
+ // Other attributes
+ $cols = 3;
+ include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
// Amount HT
print '' . $langs->trans('AmountHT') . ' ';
diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php
index f39d827b03e..60e5d81e37a 100644
--- a/htdocs/commande/card.php
+++ b/htdocs/commande/card.php
@@ -2130,67 +2130,9 @@ if ($action == 'create' && $user->rights->commande->creer) {
print ' ';
}
- // Other attributes (TODO Move this into an include)
- $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))
- {
- foreach ($extrafields->attribute_label as $key => $label)
- {
- if ($action == 'edit_extras')
- {
- $value = (isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
- }
- else
- {
- $value = $object->array_options["options_" . $key];
- }
-
- if ($extrafields->attribute_type[$key] == 'separate')
- {
- print $extrafields->showSeparator($key);
- }
- else
- {
- print '';
- print 'attribute_required [$key])) print ' class="fieldrequired"';
- print '>' . $label . ' ';
- if (($object->statut == 0 || $extrafields->attribute_alwayseditable[$key]) && $user->rights->propal->creer && ($action != 'edit_extras' || GETPOST('attribute') != $key))
- print '' . img_edit().' ';
-
- print '
';
- print ' ';
-
- // 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"]) : $db->jdate($object->array_options ['options_' . $key]);
- }
-
- if ($action == 'edit_extras' && $user->rights->commande->creer && GETPOST('attribute') == $key)
- {
- print '';
- }
- else
- {
- print $extrafields->showOutputField($key, $value);
- if ($object->statut == 0 && $user->rights->commande->creer)
- print '' . img_picto('', 'edit') . ' ' . $langs->trans('Modify') . ' ';
- }
- print ' ' . "\n";
- }
- }
- }
+ // Other attributes
+ $cols = 3;
+ include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
$rowspan = 4;
if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0)
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 22246fc8f03..eb4ca29f022 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -3324,58 +3324,9 @@ if ($action == 'create')
print '';
}
- // Other attributes (TODO Move this into an include)
- $res = $object->fetch_optionals($object->id, $extralabels);
- $parameters = array('colspan' => ' colspan="5"', "cols" => 5);
- $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)
- {
- if ($action == 'edit_extras') {
- $value = (isset($_POST["options_" . $key]) ? $_POST["options_" . $key] : $object->array_options ["options_" . $key]);
- } else {
- $value = $object->array_options ["options_" . $key];
- }
- if ($extrafields->attribute_type [$key] == 'separate') {
- print $extrafields->showSeparator($key);
- } else {
- print '';
- print 'attribute_required [$key])) print ' class="fieldrequired"';
- print '>' . $label . ' ';
- if (($object->statut == 0 || $extrafields->attribute_alwayseditable[$key]) && $user->rights->propal->creer && ($action != 'edit_extras' || GETPOST('attribute') != $key))
- print '' . img_edit().' ';
-
- print '
';
- print ' ';
-
- // 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"]) : $db->jdate($object->array_options ['options_' . $key]);
- }
-
- if ($action == 'edit_extras' && $user->rights->facture->creer && GETPOST('attribute') == $key) {
- print '';
- } else {
- print $extrafields->showOutputField($key, $value);
- if ($object->statut == 0 && $user->rights->facture->creer)
- print '' . img_picto('', 'edit') . ' ' . $langs->trans('Modify') . ' ';
- }
- print ' ' . "\n";
- }
- }
- }
+ // Other attributes
+ $cols = 5;
+ include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
print ' ';
diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php
index 1b47912fa41..af5f83cdbde 100644
--- a/htdocs/contrat/card.php
+++ b/htdocs/contrat/card.php
@@ -1189,52 +1189,8 @@ else
}
// Other attributes
- $parameters=array('colspan' => ' colspan="3"');
- $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
-
- $res = $object->fetch_optionals($object->id, $extralabels);
- if (empty($reshook) && ! empty($extrafields->attribute_label)) {
- foreach ($extrafields->attribute_label as $key => $label) {
- if ($action == 'edit_extras') {
- $value = (isset($_POST ["options_" . $key]) ? $_POST ["options_" . $key] : $object->array_options ["options_" . $key]);
- } else {
- $value = $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 . ' ';
- // 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"]) : $db->jdate($object->array_options ['options_' . $key]);
- }
-
- if ($action == 'edit_extras' && $user->rights->commande->creer && GETPOST('attribute') == $key) {
- print '';
- } else {
- print $extrafields->showOutputField($key, $value);
- if ($object->statut == 0 && $user->rights->commande->creer)
- print '' . img_picto('', 'edit') . ' ' . $langs->trans('Modify') . ' ';
- }
- print ' ' . "\n";
- }
- }
- }
-
-
-
+ $cols = 3;
+ include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
print "";
diff --git a/htdocs/core/tpl/extrafields_view.tpl.php b/htdocs/core/tpl/extrafields_view.tpl.php
new file mode 100644
index 00000000000..1591ce9fb6d
--- /dev/null
+++ b/htdocs/core/tpl/extrafields_view.tpl.php
@@ -0,0 +1,83 @@
+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ * Need to have following variables defined:
+ * $object (invoice, order, ...)
+ * $conf
+ * $langs
+ *
+ * $cols
+ */
+
+//$res = $object->fetch_optionals($object->id, $extralabels);
+$parameters = array('colspan' => ' colspan="'.$cols.'"', 'cols' => $cols, 'socid' => $object->fk_soc);
+$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action);
+
+if (empty($reshook) && ! empty($extrafields->attribute_label))
+{
+ foreach ($extrafields->attribute_label as $key => $label)
+ {
+ if ($action == 'edit_extras')
+ {
+ $value = (isset($_POST ["options_" . $key]) ? $_POST ["options_" . $key] : $object->array_options ["options_" . $key]);
+ }
+ else
+ {
+ $value = $object->array_options ["options_" . $key];
+ }
+ if ($extrafields->attribute_type [$key] == 'separate')
+ {
+ print $extrafields->showSeparator($key);
+ }
+ else
+ {
+ print '';
+ print 'attribute_required [$key])) print ' class="fieldrequired"';
+ print '>' . $label . ' ';
+ if (($object->statut == 0 || $extrafields->attribute_alwayseditable[$key]) && $user->rights->propal->creer && ($action != 'edit_extras' || GETPOST('attribute') != $key))
+ print '' . img_edit().' ';
+
+ print '
';
+ print ' ';
+
+ // 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"]) : $db->jdate($object->array_options ['options_' . $key]);
+ }
+
+ if ($action == 'edit_extras' && $user->rights->propal->creer && GETPOST('attribute') == $key)
+ {
+ print '';
+ }
+ else
+ {
+ print $extrafields->showOutputField($key, $value);
+ }
+ print ' ' . "\n";
+ }
+ }
+}
diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php
index 70d425d04a1..983293916b6 100644
--- a/htdocs/fichinter/card.php
+++ b/htdocs/fichinter/card.php
@@ -1330,49 +1330,9 @@ else if ($id > 0 || ! empty($ref))
// Statut
print ''.$langs->trans("Status").' '.$object->getLibStatut(4).' ';
- // Other attributes (TODO Move this into an include)
- $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))
- {
- foreach($extrafields->attribute_label as $key=>$label)
- {
- if ($action == 'edit_extras') {
- $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
- } else {
- $value=$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.' ';
- // 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"]):$db->jdate($object->array_options['options_'.$key]);
- }
- if ($action == 'edit_extras' && $user->rights->ficheinter->creer && GETPOST('attribute') == $key)
- {
- print ' ';
-
- print $extrafields->showInputField($key,$value);
-
- print ' ';
- }
- else
- {
- print $extrafields->showOutputField($key,$value);
- if (($object->statut == 0 || $object->statut == 1) && $user->rights->ficheinter->creer) print ' '.img_picto('','edit').' '.$langs->trans('Modify').' ';
- }
- print ' '."\n";
- }
- }
- }
+ // Other attributes
+ $cols = 3;
+ include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
print "";
diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php
index e5ba7b3b1dd..9c72319f74f 100644
--- a/htdocs/fourn/class/fournisseur.facture.class.php
+++ b/htdocs/fourn/class/fournisseur.facture.class.php
@@ -413,6 +413,15 @@ class FactureFournisseur extends CommonInvoice
$this->socid = $obj->socid;
$this->socnom = $obj->socnom;
+
+ // Retreive all extrafield
+ // fetch optionals attributes and labels
+ require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php');
+ $extrafields=new ExtraFields($this->db);
+ $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
+ $this->fetch_optionals($this->id,$extralabels);
+
+ if ($this->statut == 0) $this->brouillon = 1;
$result=$this->fetch_lines();
if ($result < 0)
diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php
index d6be5491f54..911a7a52159 100644
--- a/htdocs/fourn/commande/card.php
+++ b/htdocs/fourn/commande/card.php
@@ -1484,78 +1484,9 @@ elseif (! empty($object->id))
print '';
}
- // Other attributes (TODO Move this into an include)
- $parameters=array('socid'=>$socid, '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))
- {
- foreach($extrafields->attribute_label as $key=>$label)
- {
- if ($action == 'edit_extras')
- {
- $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
- }
- else
- {
- $value=$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.' ';
- // 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"]):$db->jdate($object->array_options['options_'.$key]);
- }
-
- if ($action == 'edit_extras' && $user->rights->commande->creer && GETPOST('attribute') == $key)
- {
- 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->fournisseur->commande->creer)
- {
- print '';
- print ' ';
- print '';
- print ' ';
- }
- else
- {
- if ($object->statut == 0 && $user->rights->fournisseur->commande->creer)
- {
- print ''.img_picto('','edit').' '.$langs->trans('Modify').' ';
- }
- }
- }
- }
+ // Other attributes
+ $cols = 3;
+ include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
// Ligne de 3 colonnes
print ''.$langs->trans("AmountHT").' ';
diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php
index b58c17dcf62..c8db601a8d9 100644
--- a/htdocs/fourn/facture/card.php
+++ b/htdocs/fourn/facture/card.php
@@ -72,6 +72,10 @@ $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
$hookmanager->initHooks(array('invoicesuppliercard','globalcard'));
$object=new FactureFournisseur($db);
+$extrafields = new ExtraFields($db);
+
+// fetch optionals attributes and labels
+$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
// Load object
if ($id > 0 || ! empty($ref))
@@ -1054,6 +1058,45 @@ elseif ($action == 'remove_file')
}
}
+elseif ($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++;
+
+ if (!$error)
+ {
+ // Actions on extra fields (by external module or standard code)
+ // FIXME le hook fait double emploi avec le trigger !!
+ $hookmanager->initHooks(array('supplierorderdao'));
+ $parameters=array('id'=>$object->id);
+
+ $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)
+ {
+ $error++;
+ }
+
+ }
+ }
+ else if ($reshook < 0) $error++;
+ }
+ else
+ {
+ $action = 'edit_extras';
+ }
+}
+
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fournisseur->facture->creer)
{
if ($action == 'addcontact')
@@ -1884,9 +1927,9 @@ else
print ' ';
}
- // Other options
- $parameters=array('colspan' => ' colspan="4"');
- $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
+ // Other attributes
+ $cols = 4;
+ include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
print '';