diff --git a/htdocs/admin/agenda_other.php b/htdocs/admin/agenda_other.php
index f48298f2d53..edcffb00e71 100644
--- a/htdocs/admin/agenda_other.php
+++ b/htdocs/admin/agenda_other.php
@@ -30,6 +30,7 @@ require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/defaultvalues.class.php';
if (!$user->admin)
accessforbidden();
@@ -84,7 +85,31 @@ if ($action == 'set')
dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_TYPE', $defaultfilter, 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_STATUS', GETPOST('AGENDA_DEFAULT_FILTER_STATUS'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, 'AGENDA_DEFAULT_VIEW', GETPOST('AGENDA_DEFAULT_VIEW'), 'chaine', 0, '', $conf->entity);
- dolibarr_set_const($db, 'AGENDA_EVENT_DEFAULT_STATUS', GETPOST('AGENDA_EVENT_DEFAULT_STATUS'), 'chaine', 0, '', $conf->entity);
+
+ $defaultValues = new DefaultValues($db);
+ $result = $defaultValues->fetchAll('','',0,0,array('t.page'=>'comm/action/card.php', 't.param'=>'complete','t.user_id'=>'0', 't.type'=>'createform', 'entity'=>$conf->entity));
+ if (!is_array($result) && $result<0) {
+ setEventMessages($defaultValues->error,$defaultValues->errors,'errors');
+ } elseif(count($result)>0) {
+ foreach($result as $defval) {
+ $defaultValues->id=$defval->id;
+ $resultDel = $defaultValues->delete($user);
+ if ($resultDel<0) {
+ setEventMessages($defaultValues->error,$defaultValues->errors,'errors');
+ }
+ }
+ }
+ $defaultValues->type='createform';
+ $defaultValues->entity=$conf->entity;
+ $defaultValues->user_id=0;
+ $defaultValues->page='comm/action/card.php';
+ $defaultValues->param='complete';
+ $defaultValues->value=GETPOST('AGENDA_EVENT_DEFAULT_STATUS');
+ $resultCreat=$defaultValues->create($user);
+ if ($resultCreat<0) {
+ setEventMessages($defaultValues->error,$defaultValues->errors,'errors');
+ }
+
} elseif ($action == 'specimen') // For orders
{
$modele = GETPOST('module', 'alpha');
@@ -353,12 +378,21 @@ if (!empty($conf->global->AGENDA_USE_EVENT_TYPE))
$formactions->select_type_actions($conf->global->AGENDA_USE_EVENT_TYPE_DEFAULT, "AGENDA_USE_EVENT_TYPE_DEFAULT", 'systemauto', 0, 1);
print ''."\n";
}
+
// AGENDA_EVENT_DEFAULT_STATUS
print '
'."\n";
print '| '.$langs->trans("AGENDA_EVENT_DEFAULT_STATUS").' | '."\n";
print ' | '."\n";
print ''."\n";
-$formactions->form_select_status_action('agenda', $conf->global->AGENDA_EVENT_DEFAULT_STATUS, 1, "AGENDA_EVENT_DEFAULT_STATUS", 0, 1, 'maxwidth200');
+$defval='na';
+$defaultValues = new DefaultValues($db);
+$result = $defaultValues->fetchAll('','',0,0,array('t.page'=>'comm/action/card.php', 't.param'=>'complete','t.user_id'=>'0', 't.type'=>'createform', 'entity'=>$conf->entity));
+if (!is_array($result) && $result<0) {
+ setEventMessages($defaultValues->error,$defaultValues->errors,'errors');
+} elseif(count($result)>0) {
+ $defval=reset($result)->value;
+}
+$formactions->form_select_status_action('agenda', $defval, 1, "AGENDA_EVENT_DEFAULT_STATUS", 0, 1, 'maxwidth200');
print ' |
'."\n";
// AGENDA_DEFAULT_FILTER_TYPE
diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php
index f3ad41eb7f2..a44747b0d7a 100644
--- a/htdocs/comm/action/card.php
+++ b/htdocs/comm/action/card.php
@@ -1050,13 +1050,11 @@ if ($action == 'create')
// Status
print '| '.$langs->trans("Status").' / '.$langs->trans("Percentage").' | ';
print '';
- $percent = -1;
if (GETPOSTISSET('status')) $percent = GETPOST('status');
elseif (GETPOSTISSET('percentage')) $percent = GETPOST('percentage');
else {
if (GETPOST('complete') == '0' || GETPOST("afaire") == 1) $percent = '0';
elseif (GETPOST('complete') == 100 || GETPOST("afaire") == 2) $percent = 100;
- elseif (isset($conf->global->AGENDA_EVENT_DEFAULT_STATUS) && $conf->global->AGENDA_EVENT_DEFAULT_STATUS!=='na') $percent = $conf->global->AGENDA_EVENT_DEFAULT_STATUS;
}
$formactions->form_select_status_action('formaction', $percent, 1, 'complete', 0, 0, 'maxwidth200');
print ' |
';
diff --git a/htdocs/core/class/defaultvalues.class.php b/htdocs/core/class/defaultvalues.class.php
index 0552a2ed90e..c43d3ae121c 100644
--- a/htdocs/core/class/defaultvalues.class.php
+++ b/htdocs/core/class/defaultvalues.class.php
@@ -235,12 +235,11 @@ class DefaultValues extends CommonObject
* Load object in memory from the database
*
* @param int $id Id object
- * @param string $ref Ref
* @return int <0 if KO, 0 if not found, >0 if OK
*/
- public function fetch($id, $ref = null)
+ public function fetch($id)
{
- $result = $this->fetchCommon($id, $ref);
+ $result = $this->fetchCommon($id, null);
return $result;
}
@@ -272,11 +271,13 @@ class DefaultValues extends CommonObject
$sqlwhere = array();
if (count($filter) > 0) {
foreach ($filter as $key => $value) {
- if ($key == 't.rowid') {
+ if ($key == 't.rowid' || ($key == 't.entity' && !is_array($value)) || $key == 't.user_id') {
$sqlwhere[] = $key.'='.$value;
} elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
$sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
- } elseif ($key == 'customsql') {
+ } elseif ($key == 't.page' || $key == 't.param' || $key == 't.type'){
+ $sqlwhere[] = $key.' = \''.$this->db->escape($value).'\'';
+ } elseif ($key == 'customsql') {
$sqlwhere[] = $value;
} elseif (is_array($value)) {
$sqlwhere[] = $key.' IN ('.implode(',',$value).')';