diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index 3549b122baa..204ef0ec6f2 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -1414,11 +1414,7 @@ if ($action == 'create')
print '
';
print '| ' . $langs->trans('NotePublic') . ' | ';
print '';
- $note_public = '';
- if (is_object($objectsrc)) // Take value from source object
- {
- $note_public = $objectsrc->note_public;
- }
+ $note_public = $object->getDefaultCreateValueFor('note_public', (is_object($objectsrc)?$objectsrc->note_public:null));
$doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
print $doleditor->Create(1);
@@ -1428,11 +1424,7 @@ if ($action == 'create')
print ' |
';
print '| ' . $langs->trans('NotePrivate') . ' | ';
print '';
- $note_private = '';
- if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) // Take value from source object
- {
- $note_private = $objectsrc->note_private;
- }
+ $note_private = $object->getDefaultCreateValueFor('note_private', ((! empty($origin) && ! empty($originid) && is_object($objectsrc))?$objectsrc->note_private:null));
$doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
print $doleditor->Create(1);
// print '
diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php
index 1d418ac295c..83b86ee5525 100644
--- a/htdocs/commande/card.php
+++ b/htdocs/commande/card.php
@@ -1292,8 +1292,8 @@ if ($action == 'create' && $user->rights->commande->creer)
$datedelivery = (! empty($objectsrc->date_livraison) ? $objectsrc->date_livraison : '');
- $note_private = (! empty($objectsrc->note_private) ? $objectsrc->note_private : (! empty($objectsrc->note_private) ? $objectsrc->note_private : ''));
- $note_public = (! empty($objectsrc->note_public) ? $objectsrc->note_public : '');
+ $note_private = $object->getDefaultCreateValueFor('note_private', (! empty($objectsrc->note_private) ? $objectsrc->note_private : null));
+ $note_public = $object->getDefaultCreateValueFor('note_public', (! empty($objectsrc->note_public) ? $objectsrc->note_public : null));
// Object source contacts list
$srccontactslist = $objectsrc->liste_contact(- 1, 'external', 1);
@@ -1311,6 +1311,9 @@ if ($action == 'create' && $user->rights->commande->creer)
$remise_absolue = 0;
$dateorder = empty($conf->global->MAIN_AUTOFILL_DATE_ORDER)?-1:'';
$projectid = 0;
+
+ $note_private = $object->getDefaultCreateValueFor('note_private');
+ $note_public = $object->getDefaultCreateValueFor('note_public');
}
$absolute_discount=$soc->getAvailableDiscounts();
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 5f324712ab7..6b0af5f7043 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -2285,11 +2285,7 @@ if ($action == 'create')
print ' |
';
print '| ' . $langs->trans('NotePublic') . ' | ';
print '';
- $note_public = '';
- if (is_object($objectsrc)) // Take value from source object
- {
- $note_public = $objectsrc->note_public;
- }
+ $note_public = $object->getDefaultCreateValueFor('note_public', (is_object($objectsrc)?$objectsrc->note_public:null));
$doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
print $doleditor->Create(1);
@@ -2299,11 +2295,7 @@ if ($action == 'create')
print ' |
';
print '| ' . $langs->trans('NotePrivate') . ' | ';
print '';
- $note_private = '';
- if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) // Take value from source object
- {
- $note_private = $objectsrc->note_private;
- }
+ $note_private = $object->getDefaultCreateValueFor('note_private', ((! empty($origin) && ! empty($originid) && is_object($objectsrc))?$objectsrc->note_private:null));
$doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
print $doleditor->Create(1);
// print '
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 383723eefd3..2a7834473dc 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -3549,7 +3549,47 @@ abstract class CommonObject
/* Functions common to commonobject and commonobjectline */
+ /* For default values */
+ /**
+ * Return the default value to use for a field when showing the create form of object.
+ * Return values in this order:
+ * 1) If parameter is available into POST, we return it first.
+ * 2) If not but an alternate value was provided as parameter of function, we return it.
+ * 3) If not but a constant $conf->global->OBJECTELEMENT_FIELDNAME is set, we return it (It is better to use the dedicated table).
+ * 4) Return value found into database (TODO No yet implemented)
+ *
+ * @param string $fieldname Name of field
+ * @param string $alternatevalue Alternate value to use
+ * @return string Default value
+ **/
+ function getDefaultCreateValueFor($fieldname, $alternatevalue=null)
+ {
+ global $conf, $_POST;
+
+ // If param is has been posted with use this value first.
+ if (isset($_POST[$fieldname])) return GETPOST($fieldname, 2);
+
+ if (isset($alternatevalue)) return $alternatevalue;
+
+ $newelement=$this->element;
+ if ($newelement == 'facture') $newelement='invoice';
+ if ($newelement == 'commande') $newelement='order';
+ if (empty($newelement))
+ {
+ dol_syslog("Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING);
+ return '';
+ }
+
+ $keyforfieldname=strtoupper($newelement.'_DEFAULT_'.$fieldname);
+ //var_dump($keyforfieldname);
+ if (isset($conf->global->$keyforfieldname)) return $conf->global->$keyforfieldname;
+
+ // TODO Ad here a scan into table llx_overwrite_default with a filter on $this->element and $fieldname
+
+ }
+
+
/* For triggers */
diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php
index 9b0001e79d6..bb01b5b8f6a 100644
--- a/htdocs/fourn/commande/card.php
+++ b/htdocs/fourn/commande/card.php
@@ -1460,8 +1460,8 @@ if ($action=='create')
$datedelivery = (! empty($objectsrc->date_livraison) ? $objectsrc->date_livraison : '');
- $note_private = (! empty($objectsrc->note_private) ? $objectsrc->note_private : (! empty($objectsrc->note_private) ? $objectsrc->note_private : ''));
- $note_public = (! empty($objectsrc->note_public) ? $objectsrc->note_public : '');
+ $note_private = $object->getDefaultCreateValueFor('note_private', (! empty($objectsrc->note_private) ? $objectsrc->note_private : null));
+ $note_public = $object->getDefaultCreateValueFor('note_public', (! empty($objectsrc->note_public) ? $objectsrc->note_public : null));
// Object source contacts list
$srccontactslist = $objectsrc->liste_contact(- 1, 'external', 1);
@@ -1471,6 +1471,9 @@ if ($action=='create')
{
$cond_reglement_id = $societe->cond_reglement_supplier_id;
$mode_reglement_id = $societe->mode_reglement_supplier_id;
+
+ $note_private = $object->getDefaultCreateValueFor('note_private');
+ $note_public = $object->getDefaultCreateValueFor('note_public');
}
print ' |