Fix use same duration code 'on 1 letter' than the production duration

record, also than tha sprintf.
This commit is contained in:
Laurent Destailleur 2020-09-04 14:18:48 +02:00
parent f2a16d860e
commit 7094cec42a
3 changed files with 31 additions and 38 deletions

View File

@ -58,23 +58,23 @@ $origin = GETPOST('origin', 'alpha');
$originid = GETPOST('originid', 'int'); $originid = GETPOST('originid', 'int');
$confirm = GETPOST('confirm', 'alpha'); $confirm = GETPOST('confirm', 'alpha');
$fulldayevent = GETPOST('fullday'); $fulldayevent = GETPOST('fullday', 'alpha');
$aphour = GETPOST('aphour'); $aphour = GETPOST('aphour', 'int');
$apmin = GETPOST('apmin'); $apmin = GETPOST('apmin', 'int');
$p2hour = GETPOST('p2hour'); $p2hour = GETPOST('p2hour', 'int');
$p2min = GETPOST('p2min'); $p2min = GETPOST('p2min', 'int');
$addreminder = GETPOST('addreminder'); $addreminder = GETPOST('addreminder', 'alpha');
$offsetvalue = GETPOST('offsetvalue'); $offsetvalue = GETPOST('offsetvalue', 'int');
$offsetunit = GETPOST('offsetunittype_duration'); $offsetunit = GETPOST('offsetunittype_duration', 'aZ09');
$remindertype = GETPOST('selectremindertype'); $remindertype = GETPOST('selectremindertype', 'aZ09');
$modelmail = GETPOST('actioncommsendmodel_mail'); $modelmail = GETPOST('actioncommsendmodel_mail', 'int');
//var_dump($_POST); exit; //var_dump($_POST); exit;
$datep = dol_mktime($fulldayevent ? '00' : $aphour, $fulldayevent ? '00' : $apmin, 0, GETPOST("apmonth"), GETPOST("apday"), GETPOST("apyear")); $datep = dol_mktime($fulldayevent ? '00' : $aphour, $fulldayevent ? '00' : $apmin, 0, GETPOST("apmonth", 'int'), GETPOST("apday", 'int'), GETPOST("apyear", 'int'));
$datef = dol_mktime($fulldayevent ? '23' : $p2hour, $fulldayevent ? '59' : $p2min, $fulldayevent ? '59' : '0', GETPOST("p2month"), GETPOST("p2day"), GETPOST("p2year")); $datef = dol_mktime($fulldayevent ? '23' : $p2hour, $fulldayevent ? '59' : $p2min, $fulldayevent ? '59' : '0', GETPOST("p2month", 'int'), GETPOST("p2day", 'int'), GETPOST("p2year", 'int'));
// Security check // Security check
$socid = GETPOST('socid', 'int'); $socid = GETPOST('socid', 'int');
@ -391,19 +391,7 @@ if (empty($reshook) && $action == 'add')
if ($addreminder == 'on'){ if ($addreminder == 'on'){
$actionCommReminder = new ActionCommReminder($db); $actionCommReminder = new ActionCommReminder($db);
if ($offsetunit == 'minute'){ $dateremind = dol_time_plus_duree($datep, -$offsetvalue, 'i');
$dateremind = dol_time_plus_duree($datep, -$offsetvalue, 'i');
} elseif ($offsetunit == 'hour'){
$dateremind = dol_time_plus_duree($datep, -$offsetvalue, 'h');
} elseif ($offsetunit == 'day') {
$dateremind = dol_time_plus_duree($datep, -$offsetvalue, 'd');
} elseif ($offsetunit == 'week') {
$dateremind = dol_time_plus_duree($datep, -$offsetvalue, 'w');
} elseif ($offsetunit == 'month') {
$dateremind = dol_time_plus_duree($datep, -$offsetvalue, 'm');
} elseif ($offsetunit == 'year') {
$dateremind = dol_time_plus_duree($datep, -$offsetvalue, 'y');
}
$actionCommReminder->dateremind = $dateremind; $actionCommReminder->dateremind = $dateremind;
$actionCommReminder->typeremind = $remindertype; $actionCommReminder->typeremind = $remindertype;
@ -418,15 +406,20 @@ if (empty($reshook) && $action == 'add')
if ($res <= 0){ if ($res <= 0){
// If error // If error
$db->rollback(); $error++;
$langs->load("errors"); $langs->load("errors");
$error = $langs->trans('ErrorReminderActionCommCreation'); $error = $langs->trans('ErrorReminderActionCommCreation').' '.$actionCommReminder->error;
setEventMessages($error, null, 'errors'); setEventMessages($error, $actionCommReminder->errors, 'errors');
$action = 'create'; $donotclearsession = 1; $action = 'create'; $donotclearsession = 1;
} }
} }
$db->commit(); if ($error) {
$db->rollback();
} else {
$db->commit();
}
if (!empty($backtopage)) if (!empty($backtopage))
{ {
dol_syslog("Back to ".$backtopage.($moreparam ? (preg_match('/\?/', $backtopage) ? '&'.$moreparam : '?'.$moreparam) : '')); dol_syslog("Back to ".$backtopage.($moreparam ? (preg_match('/\?/', $backtopage) ? '&'.$moreparam : '?'.$moreparam) : ''));
@ -929,9 +922,9 @@ if ($action == 'create')
print ' <span class="hideonsmartphone">&nbsp; &nbsp; - &nbsp; &nbsp;</span> '; print ' <span class="hideonsmartphone">&nbsp; &nbsp; - &nbsp; &nbsp;</span> ';
//print ' - '; //print ' - ';
if (GETPOST("afaire") == 1) { if (GETPOST("afaire") == 1) {
print $form->selectDate($datef, 'p2', 1, 1, 1, "action", 1, 2, 0, 'fulldayend'); print $form->selectDate($datef, 'p2', 1, 1, 1, "action", 1, 0, 0, 'fulldayend');
} else { } else {
print $form->selectDate($datef, 'p2', 1, 1, 1, "action", 1, 2, 0, 'fulldayend'); print $form->selectDate($datef, 'p2', 1, 1, 1, "action", 1, 0, 0, 'fulldayend');
} }
print '</td></tr>'; print '</td></tr>';
@ -1208,7 +1201,7 @@ if ($action == 'create')
//Time Type //Time Type
print '<tr><td class="titlefieldcreate nowrap">'.$langs->trans("TimeType").'</td><td colspan="3">'; print '<tr><td class="titlefieldcreate nowrap">'.$langs->trans("TimeType").'</td><td colspan="3">';
print $form->selectTypeDuration('offsetunit'); print $form->selectTypeDuration('offsetunit', 'i');
print '</td></tr>'; print '</td></tr>';
//Reminder Type //Reminder Type

View File

@ -50,6 +50,9 @@ class ActionCommReminder extends CommonObject
*/ */
public $picto = 'generic'; public $picto = 'generic';
const STATUS_TODO = 0;
const STATUS_DONE = 1;
/** /**
* 'type' if the field format. * 'type' if the field format.
@ -79,7 +82,7 @@ class ActionCommReminder extends CommonObject
'typeremind' => array('type'=>'varchar(32)', 'label'=>'TypeRemind', 'visible'=>-1, 'enabled'=>1, 'position'=>55, 'notnull'=>1, 'comment'=>"email, browser, sms",), 'typeremind' => array('type'=>'varchar(32)', 'label'=>'TypeRemind', 'visible'=>-1, 'enabled'=>1, 'position'=>55, 'notnull'=>1, 'comment'=>"email, browser, sms",),
'fk_user' => array('type'=>'integer', 'label'=>'User', 'visible'=>-1, 'enabled'=>1, 'position'=>65, 'notnull'=>1, 'index'=>1,), 'fk_user' => array('type'=>'integer', 'label'=>'User', 'visible'=>-1, 'enabled'=>1, 'position'=>65, 'notnull'=>1, 'index'=>1,),
'offsetvalue' => array('type'=>'integer', 'label'=>'OffsetValue', 'visible'=>1, 'enabled'=>1, 'position'=>56, 'notnull'=>1,), 'offsetvalue' => array('type'=>'integer', 'label'=>'OffsetValue', 'visible'=>1, 'enabled'=>1, 'position'=>56, 'notnull'=>1,),
'offsetunit' => array('type'=>'varchar(1)', 'label'=>'OffsetUnit', 'visible'=>1, 'enabled'=>1, 'position'=>57, 'notnull'=>1, 'comment'=>"m, h, d, w",), 'offsetunit' => array('type'=>'varchar(1)', 'label'=>'OffsetUnit', 'visible'=>1, 'enabled'=>1, 'position'=>57, 'notnull'=>1, 'comment'=>"y, m, d, w, h, i",),
'status' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>58, 'notnull'=>1, 'default'=>0, 'index'=>0, 'arrayofkeyval'=>array('0'=>'ToDo', '1'=>'Done')), 'status' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>58, 'notnull'=>1, 'default'=>0, 'index'=>0, 'arrayofkeyval'=>array('0'=>'ToDo', '1'=>'Done')),
'fk_actioncomm' => array('type'=>'integer', 'label'=>'Project', 'visible'=>1, 'enabled'=>1, 'position'=>59, 'notnull'=>1, 'index'=>1,), 'fk_actioncomm' => array('type'=>'integer', 'label'=>'Project', 'visible'=>1, 'enabled'=>1, 'position'=>59, 'notnull'=>1, 'index'=>1,),
'fk_email_template' => array('type'=>'integer', 'label'=>'EmailTemplate', 'visible'=>1, 'enabled'=>1, 'position'=>60, 'notnull'=>0), 'fk_email_template' => array('type'=>'integer', 'label'=>'EmailTemplate', 'visible'=>1, 'enabled'=>1, 'position'=>60, 'notnull'=>0),
@ -121,9 +124,6 @@ class ActionCommReminder extends CommonObject
*/ */
public $fk_email_template; public $fk_email_template;
const STATUS_TODO = 0;
const STATUS_DONE = 1;
// END MODULEBUILDER PROPERTIES // END MODULEBUILDER PROPERTIES

View File

@ -5680,11 +5680,11 @@ class Form
* @param string $selected Selected type * @param string $selected Selected type
* @return string HTML select string * @return string HTML select string
*/ */
public function selectTypeDuration($prefix, $selected = 'minute') public function selectTypeDuration($prefix, $selected = 'i')
{ {
global $langs; global $langs;
$TDurationTypes = array('year'=>$langs->trans('Years'), 'month'=>$langs->trans('Month'), 'week'=>$langs->trans('Weeks'), 'day'=>$langs->trans('Days'), 'hour'=>$langs->trans('Hours'), 'minute'=>$langs->trans('Minutes')); $TDurationTypes = array('y'=>$langs->trans('Years'), 'm'=>$langs->trans('Month'), 'w'=>$langs->trans('Weeks'), 'd'=>$langs->trans('Days'), 'h'=>$langs->trans('Hours'), 'i'=>$langs->trans('Minutes'));
$retstring = '<select class="flat" id="select_'.$prefix.'type_duration" name="'.$prefix.'type_duration">'; $retstring = '<select class="flat" id="select_'.$prefix.'type_duration" name="'.$prefix.'type_duration">';
foreach ($TDurationTypes as $key=>$typeduration) { foreach ($TDurationTypes as $key=>$typeduration) {