fix issue n°30845

This commit is contained in:
iouston
2024-11-15 16:23:08 +01:00
parent 0a17ea0cef
commit cf88b7b236

View File

@@ -7,7 +7,7 @@
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
* Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2018-2023 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2019 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*
@@ -50,14 +50,6 @@ require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
/**
* @var Conf $conf
* @var DoliDB $db
* @var HookManager $hookmanager
* @var Translate $langs
* @var User $user
*/
// Load translation files required by the page
$langs->loadLangs(array("companies", "other", "commercial", "bills", "orders", "agenda", "mails"));
@@ -88,23 +80,22 @@ if ($complete == 'na' || $complete == -2) {
$complete = -1;
}
$tzforfullday = null;
if ($fulldayevent) {
$tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
// For "full day" events, we must store date in GMT (It must be viewed as same moment everywhere)
$datep = dol_mktime(0, 0, 0, GETPOSTINT("apmonth"), GETPOSTINT("apday"), GETPOSTINT("apyear"), $tzforfullday ? $tzforfullday : 'tzuserrel');
$datef = dol_mktime(23, 59, 59, GETPOSTINT("p2month"), GETPOSTINT("p2day"), GETPOSTINT("p2year"), $tzforfullday ? $tzforfullday : 'tzuserrel');
$datep = dol_mktime('00', '00', 0, GETPOSTINT("apmonth"), GETPOSTINT("apday"), GETPOSTINT("apyear"), $tzforfullday ? $tzforfullday : 'tzuserrel');
$datef = dol_mktime('23', '59', '59', GETPOSTINT("p2month"), GETPOSTINT("p2day"), GETPOSTINT("p2year"), $tzforfullday ? $tzforfullday : 'tzuserrel');
//print $db->idate($datep); exit;
} else {
$datep = dol_mktime($aphour, $apmin, 0, GETPOSTINT("apmonth"), GETPOSTINT("apday"), GETPOSTINT("apyear"), 'tzuserrel');
$datef = dol_mktime($p2hour, $p2min, 59, GETPOSTINT("p2month"), GETPOSTINT("p2day"), GETPOSTINT("p2year"), 'tzuserrel');
$datef = dol_mktime($p2hour, $p2min, '59', GETPOSTINT("p2month"), GETPOSTINT("p2day"), GETPOSTINT("p2year"), 'tzuserrel');
}
$reg = array();
if (GETPOST('datep')) {
if (GETPOST('datep') == 'now') {
$datep = dol_now();
} elseif (preg_match('/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])$/', GETPOST("datep"), $reg)) { // Try to not use this. Use instead '&datep=now'
$datep = dol_mktime(0, 0, 0, (int) $reg[2], (int) $reg[3], (int) $reg[1], 'tzuserrel');
$datep = dol_mktime(0, 0, 0, $reg[2], $reg[3], $reg[1], 'tzuserrel');
}
}
@@ -132,7 +123,6 @@ $formactions = new FormActions($db);
// Load object
if ($id > 0 && $action != 'add') {
$ret = $object->fetch($id);
$ret1 = 0;
if ($ret > 0) {
$ret = $object->fetch_optionals();
$ret1 = $object->fetch_userassigned();
@@ -145,7 +135,7 @@ if ($id > 0 && $action != 'add') {
// fetch optionals attributes and labels
$extrafields->fetch_name_optionals_label($object->table_element);
// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('actioncard', 'globalcard'));
$parameters = array('socid' => $socid);
@@ -156,10 +146,10 @@ if ($reshook < 0) {
$TRemindTypes = array();
if (getDolGlobalString('AGENDA_REMINDER_BROWSER')) {
$TRemindTypes['browser'] = array('label' => $langs->trans('BrowserPush'), 'disabled' => (getDolGlobalString('AGENDA_REMINDER_BROWSER') ? 0 : 1));
$TRemindTypes['browser'] = array('label' => $langs->trans('BrowserPush'), 'disabled' => (!getDolGlobalString('AGENDA_REMINDER_BROWSER') ? 1 : 0));
}
if (getDolGlobalString('AGENDA_REMINDER_EMAIL')) {
$TRemindTypes['email'] = array('label' => $langs->trans('EMail'), 'disabled' => (getDolGlobalString('AGENDA_REMINDER_EMAIL') ? 0 : 1));
$TRemindTypes['email'] = array('label' => $langs->trans('EMail'), 'disabled' => (!getDolGlobalString('AGENDA_REMINDER_EMAIL') ? 1 : 0));
}
$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'));
@@ -333,14 +323,12 @@ if (empty($reshook) && $action == 'add' && $usercancreate) {
if ($fulldayevent) {
$tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
// For "full day" events, we must store date in GMT (It must be viewed as same moment everywhere)
$datep = dol_mktime(0, 0, 0, GETPOSTINT("apmonth"), GETPOSTINT("apday"), GETPOSTINT("apyear"), $tzforfullday ? $tzforfullday : 'tzuserrel');
$datef = dol_mktime(23, 59, 59, GETPOSTINT("p2month"), GETPOSTINT("p2day"), GETPOSTINT("p2year"), $tzforfullday ? $tzforfullday : 'tzuserrel');
$datep = dol_mktime('00', '00', '00', GETPOSTINT("apmonth"), GETPOSTINT("apday"), GETPOSTINT("apyear"), $tzforfullday ? $tzforfullday : 'tzuserrel');
$datef = dol_mktime('23', '59', '59', GETPOSTINT("p2month"), GETPOSTINT("p2day"), GETPOSTINT("p2year"), $tzforfullday ? $tzforfullday : 'tzuserrel');
} else {
$datep = dol_mktime(GETPOSTINT("aphour"), GETPOSTINT("apmin"), GETPOSTINT("apsec"), GETPOSTINT("apmonth"), GETPOSTINT("apday"), GETPOSTINT("apyear"), 'tzuserrel');
$datef = dol_mktime(GETPOSTINT("p2hour"), GETPOSTINT("p2min"), GETPOSTINT("apsec"), GETPOSTINT("p2month"), GETPOSTINT("p2day"), GETPOSTINT("p2year"), 'tzuserrel');
}
//set end date to now if percentage is set to 100 and end date not set
$datef = (!$datef && $percentage == 100) ? dol_now() : $datef;
// Check parameters
if (!$datef && $percentage == 100) {
@@ -368,7 +356,7 @@ if (empty($reshook) && $action == 'add' && $usercancreate) {
}
if (!$error) {
// Initialisation of object actioncomm
// Initialisation object actioncomm
$object->priority = GETPOSTISSET("priority") ? GETPOSTINT("priority") : 0;
$object->fulldayevent = ($fulldayevent ? 1 : 0);
$object->location = GETPOST("location", 'alphanohtml');
@@ -377,18 +365,13 @@ if (empty($reshook) && $action == 'add' && $usercancreate) {
if (GETPOST("elementtype", 'alpha')) {
$elProp = getElementProperties(GETPOST("elementtype", 'alpha'));
$modulecodetouseforpermissioncheck = $elProp['module'];
$submodulecodetouseforpermissioncheck = $elProp['subelement'];
$hasPermissionOnLinkedObject = 0;
if ($user->hasRight($modulecodetouseforpermissioncheck, 'read')) {
$hasPermissionOnLinkedObject = 1;
} elseif ($user->hasRight($modulecodetouseforpermissioncheck, $submodulecodetouseforpermissioncheck, 'read')) {
$hasPermissionOnLinkedObject = 1;
}
if ($hasPermissionOnLinkedObject) {
$object->fk_element = GETPOSTINT("fk_element");
$object->elementid = GETPOSTINT("fk_element");
$object->elementtype = GETPOST("elementtype", 'alpha');
}
}
@@ -415,7 +398,6 @@ if (empty($reshook) && $action == 'add' && $usercancreate) {
}
$object->fk_element = $taskid;
$object->elementid = $taskid;
$object->elementtype = 'task';
}
@@ -430,6 +412,15 @@ if (empty($reshook) && $action == 'add' && $usercancreate) {
if (!empty($_SESSION['assignedtouser'])) {
$listofuserid = json_decode($_SESSION['assignedtouser'], true);
}
$listofresourceid = array();
if (!empty($_SESSION['assignedtoresource'])) {
$listofresourceid = json_decode($_SESSION['assignedtoresource'], true);
}
echo '<pre>';
print_r($listofresourceid);
print '</pre>';
$i = 0;
foreach ($listofuserid as $key => $value) {
if ($i == 0) { // First entry
@@ -448,9 +439,7 @@ if (empty($reshook) && $action == 'add' && $usercancreate) {
$object->note_private = trim(GETPOST("note", "restricthtml"));
if (GETPOSTISSET("contactid")) {
$object->contact_id = GETPOSTINT("contactid");
$object->contact = $contact; // For backward compatibility
$object->contact = $contact;
}
if (GETPOSTINT('socid') > 0) {
@@ -537,16 +526,86 @@ if (empty($reshook) && $action == 'add' && $usercancreate) {
// Creation of action/event
$idaction = $object->create($user);
$moreparam = '';
if ($idaction > 0) {
if (!$object->error) {
if (count($listofresourceid)) {
foreach ($listofresourceid as $resource_id => $val) {
$resource_type = 'dolresource';
$busy = 1;//GETPOSTINT('busy');
// Resources association
if (getDolGlobalString('RESOURCE_USED_IN_EVENT_CHECK')) {
$eventDateStart = $object->datep;
$eventDateEnd = $object->datef;
$isFullDayEvent = $object->fulldayevent;
if (empty($eventDateEnd)) {
if ($isFullDayEvent) {
$eventDateStartArr = dol_getdate($eventDateStart);
$eventDateStart = dol_mktime(0, 0, 0, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']);
$eventDateEnd = dol_mktime(23, 59, 59, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']);
}
}
$sql = "SELECT er.rowid, r.ref as r_ref, ac.id as ac_id, ac.label as ac_label";
$sql .= " FROM " . MAIN_DB_PREFIX . "element_resources as er";
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "resource as r ON r.rowid = er.resource_id AND er.resource_type = '" . $db->escape($resource_type) . "'";
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "actioncomm as ac ON ac.id = er.element_id AND er.element_type = '" . $db->escape($object->element) . "'";
$sql .= " WHERE er.resource_id = " . ((int)$resource_id);
$sql .= " AND er.busy = 1";
$sql .= " AND (";
// event date start between ac.datep and ac.datep2 (if datep2 is null we consider there is no end)
$sql .= " (ac.datep <= '" . $db->idate($eventDateStart) . "' AND (ac.datep2 IS NULL OR ac.datep2 >= '" . $db->idate($eventDateStart) . "'))";
// event date end between ac.datep and ac.datep2
if (!empty($eventDateEnd)) {
$sql .= " OR (ac.datep <= '" . $db->idate($eventDateEnd) . "' AND (ac.datep2 >= '" . $db->idate($eventDateEnd) . "'))";
}
// event date start before ac.datep and event date end after ac.datep2
$sql .= " OR (";
$sql .= "ac.datep >= '" . $db->idate($eventDateStart) . "'";
if (!empty($eventDateEnd)) {
$sql .= " AND (ac.datep2 IS NOT NULL AND ac.datep2 <= '" . $db->idate($eventDateEnd) . "')";
}
$sql .= ")";
$sql .= ")";
$resql = $db->query($sql);
if (!$resql) {
$error++;
$object->error = $db->lasterror();
$object->errors[] = $object->error;
} else {
if ($db->num_rows($resql) > 0) {
// Resource already in use
$error++;
$object->error = $langs->trans('ErrorResourcesAlreadyInUse') . ' : ';
while ($obj = $db->fetch_object($resql)) {
$object->error .= '<br> - ' . $langs->trans('ErrorResourceUseInEvent', $obj->r_ref, $obj->ac_label . ' [' . $obj->ac_id . ']');
}
$object->errors[] = $object->error;
}
$db->free($resql);
}
}
if (!$error) {
$res = $object->add_element_resource($resource_id, $resource_type, $busy, $val['mandatory']);
}
}
}
unset($_SESSION['assignedtoresource']);
// Category association
$categories = GETPOST('categories', 'array');
$object->setCategories($categories);
unset($_SESSION['assignedtouser']);
$moreparam = '';
if ($user->id != $object->userownerid) {
$moreparam = "filtert=-1"; // We force to remove filter so created record is visible when going back to per user view.
}
@@ -624,19 +683,17 @@ if (empty($reshook) && $action == 'add' && $usercancreate) {
}
if ($eventisrecurring) {
$dayoffset = 0;
$monthoffset = 0;
// We set first date of recurrence and offsets
if ($selectedrecurrulefreq == 'WEEKLY' && !empty($selectedrecurrulebyday)) {
$firstdatearray = dol_get_first_day_week(GETPOSTINT("apday"), GETPOSTINT("apmonth"), GETPOSTINT("apyear"));
$datep = dol_mktime($fulldayevent ? 0 : GETPOSTINT("aphour"), $fulldayevent ? 0 : GETPOSTINT("apmin"), $fulldayevent ? 0 : GETPOSTINT("apsec"), $firstdatearray['month'], $firstdatearray['first_day'], $firstdatearray['year'], $tzforfullday ? $tzforfullday : 'tzuserrel');
$datep = dol_mktime($fulldayevent ? '00' : GETPOSTINT("aphour"), $fulldayevent ? '00' : GETPOSTINT("apmin"), $fulldayevent ? '00' : GETPOSTINT("apsec"), $firstdatearray['month'], $firstdatearray['first_day'], $firstdatearray['year'], $tzforfullday ? $tzforfullday : 'tzuserrel');
$datep = dol_time_plus_duree($datep, $selectedrecurrulebyday + 6, 'd');//We begin the week after
$dayoffset = 7;
$monthoffset = 0;
} elseif ($selectedrecurrulefreq == 'MONTHLY' && !empty($selectedrecurrulebymonthday)) {
$firstday = $selectedrecurrulebymonthday;
$firstmonth = GETPOST("apday") > $selectedrecurrulebymonthday ? GETPOSTINT("apmonth") + 1 : GETPOSTINT("apmonth");//We begin the week after
$datep = dol_mktime($fulldayevent ? 0 : GETPOSTINT("aphour"), $fulldayevent ? 0 : GETPOSTINT("apmin"), $fulldayevent ? 0 : GETPOSTINT("apsec"), $firstmonth, $firstday, GETPOSTINT("apyear"), $tzforfullday ? $tzforfullday : 'tzuserrel');
$datep = dol_mktime($fulldayevent ? '00' : GETPOSTINT("aphour"), $fulldayevent ? '00' : GETPOSTINT("apmin"), $fulldayevent ? '00' : GETPOSTINT("apsec"), $firstmonth, $firstday, GETPOSTINT("apyear"), $tzforfullday ? $tzforfullday : 'tzuserrel');
$dayoffset = 0;
$monthoffset = 1;
} else {
@@ -740,9 +797,9 @@ if (empty($reshook) && $action == 'add' && $usercancreate) {
// increment date for recurrent events
$datep = dol_time_plus_duree($datep, $dayoffset, 'd');
$datep = dol_time_plus_duree($datep, $monthoffset, 'm'); // @phan-suppress-current-line PhanPluginSuspiciousParamOrder
$datep = dol_time_plus_duree($datep, $monthoffset, 'm');
$datef = dol_time_plus_duree($datef, $dayoffset, 'd');
$datef = dol_time_plus_duree($datef, $monthoffset, 'm'); // @phan-suppress-current-line PhanPluginSuspiciousParamOrder
$datef = dol_time_plus_duree($datef, $monthoffset, 'm');
}
}
if (!empty($backtopage) && !$error) {
@@ -758,7 +815,7 @@ if (empty($reshook) && $action == 'add' && $usercancreate) {
}
// Action update event
if (empty($reshook) && $action == 'update' && $usercancreate) {
if (empty($reshook) && $action == 'update' && $usercancreate) {
if (empty($cancel)) {
$fulldayevent = GETPOST('fullday');
$aphour = GETPOSTINT('aphour');
@@ -790,14 +847,12 @@ if (empty($reshook) && $action == 'update' && $usercancreate) {
if ($fulldayevent) {
$tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
// For "full day" events, we must store date in GMT (It must be viewed as same moment everywhere)
$datep = dol_mktime(0, 0, 0, GETPOSTINT("apmonth"), GETPOSTINT("apday"), GETPOSTINT("apyear"), $tzforfullday ? $tzforfullday : 'tzuserrel');
$datef = dol_mktime(23, 59, 59, GETPOSTINT("p2month"), GETPOSTINT("p2day"), GETPOSTINT("p2year"), $tzforfullday ? $tzforfullday : 'tzuserrel');
$datep = dol_mktime('00', '00', '00', GETPOST("apmonth", 'int'), GETPOST("apday", 'int'), GETPOST("apyear", 'int'), $tzforfullday ? $tzforfullday : 'tzuserrel');
$datef = dol_mktime('23', '59', '59', GETPOST("p2month", 'int'), GETPOST("p2day", 'int'), GETPOST("p2year", 'int'), $tzforfullday ? $tzforfullday : 'tzuserrel');
} else {
$datep = dol_mktime(GETPOSTINT("aphour"), GETPOSTINT("apmin"), GETPOSTINT("apsec"), GETPOSTINT("apmonth"), GETPOSTINT("apday"), GETPOSTINT("apyear"), 'tzuserrel');
$datef = dol_mktime(GETPOSTINT("p2hour"), GETPOSTINT("p2min"), GETPOSTINT("apsec"), GETPOSTINT("p2month"), GETPOSTINT("p2day"), GETPOSTINT("p2year"), 'tzuserrel');
$datep = dol_mktime(GETPOST("aphour", 'int'), GETPOST("apmin", 'int'), GETPOST("apsec", 'int'), GETPOST("apmonth", 'int'), GETPOST("apday", 'int'), GETPOST("apyear", 'int'), 'tzuserrel');
$datef = dol_mktime(GETPOST("p2hour", 'int'), GETPOST("p2min", 'int'), GETPOST("apsec", 'int'), GETPOST("p2month", 'int'), GETPOST("p2day", 'int'), GETPOST("p2year", 'int'), 'tzuserrel');
}
//set end date to now if percentage is set to 100 and end date not set
$datef = (!$datef && $percentage == 100) ? dol_now() : $datef;
if ($object->elementtype == 'ticket') { // code should be TICKET_MSG, TICKET_MSG_PRIVATE, TICKET_MSG_SENTBYMAIL, TICKET_MSG_PRIVATE_SENTBYMAIL
if ($private) {
@@ -852,11 +907,16 @@ if (empty($reshook) && $action == 'update' && $usercancreate) {
}
if ($hasPermissionOnLinkedObject) {
$object->fk_element = GETPOSTINT("fk_element");
$object->elementid = GETPOSTINT("fk_element");
$object->elementtype = GETPOST("elementtype", 'alpha');
}
}
if (!$datef && $percentage == 100) {
$error++;
$donotclearsession = 1;
setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEnd")), $object->errors, 'errors');
$action = 'edit';
}
$transparency = (GETPOST("transparency") == 'on' ? 1 : 0);
@@ -1056,10 +1116,10 @@ if (empty($reshook) && $action == 'update' && $usercancreate) {
exit;
}
}
}
}
// Delete event
if (empty($reshook) && $action == 'confirm_delete' && GETPOST("confirm") == 'yes') {
if (empty($reshook) && $action == 'confirm_delete' && GETPOST("confirm") == 'yes') {
$object->fetch($id);
$object->fetch_optionals();
$object->fetch_userassigned();
@@ -1076,17 +1136,17 @@ if (empty($reshook) && $action == 'confirm_delete' && GETPOST("confirm") == 'yes
setEventMessages($object->error, $object->errors, 'errors');
}
}
}
}
/*
/*
* Action move update, used when user move an event in calendar by drag'n drop
* TODO Move this into page comm/action/index that trigger this call by the drag and drop of event.
*/
if (empty($reshook) && GETPOST('actionmove', 'alpha') == 'mupdate') {
if (empty($reshook) && GETPOST('actionmove', 'alpha') == 'mupdate') {
$error = 0;
$shour = (int) dol_print_date($object->datep, "%H", 'tzuserrel'); // We take the date visible by user $newdate is also date visible by user.
$smin = (int) dol_print_date($object->datep, "%M", 'tzuserrel');
$shour = dol_print_date($object->datep, "%H", 'tzuserrel'); // We take the date visible by user $newdate is also date visible by user.
$smin = dol_print_date($object->datep, "%M", 'tzuserrel');
$newdate = GETPOST('newdate', 'alpha');
if (empty($newdate) || strpos($newdate, 'dayevent_') != 0) {
@@ -1094,7 +1154,7 @@ if (empty($reshook) && GETPOST('actionmove', 'alpha') == 'mupdate') {
exit;
}
$datep = dol_mktime($shour, $smin, 0, (int) substr($newdate, 13, 2), (int) substr($newdate, 15, 2), (int) substr($newdate, 9, 4), 'tzuserrel');
$datep = dol_mktime($shour, $smin, 0, substr($newdate, 13, 2), substr($newdate, 15, 2), substr($newdate, 9, 4), 'tzuserrel');
//print dol_print_date($datep, 'dayhour');exit;
if ($datep != $object->datep) {
@@ -1180,35 +1240,35 @@ if (empty($reshook) && GETPOST('actionmove', 'alpha') == 'mupdate') {
} else {
$action = '';
}
}
}
// Actions to delete doc
$upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($object->ref);
$permissiontoadd = ($user->hasRight('agenda', 'allactions', 'create') || (($object->authorid == $user->id || $object->userownerid == $user->id) && $user->hasRight('agenda', 'myactions', 'read')));
if (empty($reshook)) {
$upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($object->ref);
$permissiontoadd = ($user->hasRight('agenda', 'allactions', 'create') || (($object->authorid == $user->id || $object->userownerid == $user->id) && $user->hasRight('agenda', 'myactions', 'read')));
if (empty($reshook)) {
include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
}
}
/*
/*
* View
*/
$form = new Form($db);
$formproject = new FormProjets($db);
$form = new Form($db);
$formproject = new FormProjets($db);
$arrayrecurrulefreq = array(
$arrayrecurrulefreq = array(
'no' => $langs->trans("OnceOnly"),
'MONTHLY' => $langs->trans("EveryMonth"),
'WEEKLY' => $langs->trans("EveryWeek")
// 'DAILY'=>$langs->trans("EveryDay")
);
);
$help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&omodulodulo_Agenda|DE:Modul_Terminplanung';
llxHeader('', $langs->trans("Agenda"), $help_url);
$help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&omodulodulo_Agenda|DE:Modul_Terminplanung';
llxHeader('', $langs->trans("Agenda"), $help_url);
if ($action == 'create') {
if ($action == 'create') {
$contact = new Contact($db);
$socpeopleassigned = GETPOST("socpeopleassigned", 'array');
@@ -1244,29 +1304,7 @@ if ($action == 'create') {
console.log("setdatefields");
setdatefields();
});
var old_startdate = null;
$("#ap").focus(function() {
old_startdate = new Date($("#apyear").val(), $("#apmonth").val() - 1, $("#apday").val());
});
$("#ap").next(".ui-datepicker-trigger").click(function() {
old_startdate = new Date($("#apyear").val(), $("#apmonth").val() - 1, $("#apday").val());
});
$("#ap").change(function() {
setTimeout(function() {
if ($("#p2").val() !== "") {
var new_startdate = new Date($("#apyear").val(), $("#apmonth").val() - 1, $("#apday").val());
var old_enddate = new Date($("#p2year").val(), $("#p2month").val() - 1, $("#p2day").val());
if (new_startdate > old_enddate) {
var timeDiff = old_enddate - old_startdate;
var new_enddate = new Date(new_startdate.getTime() + timeDiff);
$("#p2").val(formatDate(new_enddate, "' . $langs->trans('FormatDateShortJavaInput') . '"));
$("#p2day").val(new_enddate.getDate());
$("#p2month").val(new_enddate.getMonth() + 1);
$("#p2year").val(new_enddate.getFullYear());
}
}
}, 0);
});
$("#actioncode").change(function() {
if ($("#actioncode").val() == \'AC_RDV\') $("#dateend").addClass("fieldrequired");
else $("#dateend").removeClass("fieldrequired");
@@ -1309,7 +1347,7 @@ if ($action == 'create') {
print dol_get_fiche_head();
print '<table class="border centpercent nobottom">';
print '<table class="border centpercent">';
// Type of event
if (getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
@@ -1327,41 +1365,12 @@ if ($action == 'create') {
// Full day
print '<tr><td><span class="fieldrequired">'.$langs->trans("Date").'</span></td>';
print '<td class="valignmiddle height30"><input class="valignmiddle" type="checkbox" id="fullday" name="fullday" '.(GETPOST('fullday') ? ' checked' : '').'><label for="fullday" class="valignmiddle small">'.$langs->trans("EventOnFullDay").'</label>';
print '</td></tr>';
$datep = ($datep ? $datep : (is_null($object->datep) ? '' : $object->datep));
if (GETPOST('datep', 'alpha', 1)) {
$datep = dol_stringtotime(GETPOST('datep', 'alpha', 1), 'tzuserrel');
}
$datef = ($datef ? $datef : $object->datef);
if (GETPOST('datef', 'alpha', 1)) {
$datef = dol_stringtotime(GETPOST('datef', 'alpha', 1), 'tzuserrel');
}
if (empty($datef) && !empty($datep)) {
if (GETPOST("actioncode", 'aZ09') == 'AC_RDV' || (!getDolGlobalString('AGENDA_USE_EVENT_TYPE_DEFAULT') || getDolGlobalString('AGENDA_USE_EVENT_TYPE_DEFAULT') == '-1')) {
$datef = dol_time_plus_duree($datep, getDolGlobalInt('AGENDA_AUTOSET_END_DATE_WITH_DELTA_HOURS', 1), 'h');
}
}
// Date start
print '<tr><td class="nowrap">';
print '</td><td>';
if (GETPOST("afaire") == 1) {
print $form->selectDate($datep, 'ap', 1, 1, 0, "action", 1, 2, 0, 'fulldaystart', '', '', '', 1, '', '', 'tzuserrel'); // Empty value not allowed for start date and hours if "todo"
} else {
print $form->selectDate($datep, 'ap', 1, 1, 1, "action", 1, 2, 0, 'fulldaystart', '', '', '', 1, '', '', 'tzuserrel');
}
print ' <span class="hideonsmartphone">&nbsp; &nbsp; - &nbsp; &nbsp;</span><br class="showonsmartphone"> ';
print $form->selectDate($datef, 'p2', 1, 1, 1, "action", 1, 2, 0, 'fulldayend', '', '', '', 1, '', '', 'tzuserrel');
print '</td></tr>';
print '<tr><td></td><td>';
// Recurring event
$userepeatevent = (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 1 ? 1 : 0);
if ($userepeatevent) {
// Repeat
//print ' &nbsp; &nbsp; &nbsp; &nbsp; ';
print '<div class="opacitymedium inline-block small">';
print ' &nbsp; &nbsp; &nbsp; &nbsp; <div class="opacitymedium inline-block small">';
print img_picto($langs->trans("Recurrence"), 'recurring', 'style="margin-left: 6px" class="paddingright2"');
print '<input type="hidden" name="recurid" value="'.(empty($object->recurid) ? '' : $object->recurid).'">';
@@ -1441,6 +1450,33 @@ if ($action == 'create') {
print '</div>';
//print '</td></tr>';
}
print '</td></tr>';
$datep = ($datep ? $datep : (is_null($object->datep) ? '' : $object->datep));
if (GETPOSTINT('datep', 1)) {
$datep = dol_stringtotime(GETPOSTINT('datep', 1), 'tzuserrel');
}
$datef = ($datef ? $datef : $object->datef);
if (GETPOSTINT('datef', 1)) {
$datef = dol_stringtotime(GETPOSTINT('datef', 1), 'tzuserrel');
}
if (empty($datef) && !empty($datep)) {
if (GETPOST("actioncode", 'aZ09') == 'AC_RDV' || !getDolGlobalString('AGENDA_USE_EVENT_TYPE_DEFAULT')) {
$datef = dol_time_plus_duree($datep, getDolGlobalInt('AGENDA_AUTOSET_END_DATE_WITH_DELTA_HOURS', 1), 'h');
}
}
// Date start
print '<tr><td class="nowrap">';
print '</td><td>';
if (GETPOST("afaire") == 1) {
print $form->selectDate($datep, 'ap', 1, 1, 0, "action", 1, 2, 0, 'fulldaystart', '', '', '', 1, '', '', 'tzuserrel'); // Empty value not allowed for start date and hours if "todo"
} else {
print $form->selectDate($datep, 'ap', 1, 1, 1, "action", 1, 2, 0, 'fulldaystart', '', '', '', 1, '', '', 'tzuserrel');
}
print ' <span class="hideonsmartphone">&nbsp; &nbsp; - &nbsp; &nbsp;</span><br class="showonsmartphone"> ';
print $form->selectDate($datef, 'p2', 1, 1, 1, "action", 1, 2, 0, 'fulldayend', '', '', '', 1, '', '', 'tzuserrel');
print '</td></tr>';
print '<tr><td class="">&nbsp;</td><td></td></tr>';
@@ -1463,16 +1499,13 @@ if ($action == 'create') {
if (!empty($_SESSION['assignedtouser'])) {
$listofuserid = json_decode($_SESSION['assignedtouser'], true);
}
if (!is_array($listofuserid)) {
$listofuserid = array();
}
$firstelem = reset($listofuserid);
if (isset($listofuserid[$firstelem['id']])) {
$listofuserid[$firstelem['id']]['transparency'] = (GETPOSTISSET('transparency') ? GETPOST('transparency', 'alpha') : 0); // 0 by default when refreshing
}
}
print '<div class="assignedtouser">';
print $form->select_dolusers_forevent(($action == 'create' ? 'add' : 'update'), 'assignedtouser', 1, array(), 0, '', array(), 0, 0, 0, 'AND u.statut != 0', 1, $listofuserid, $listofcontactid, $listofotherid);
print $form->select_dolusers_forevent(($action == 'create' ? 'add' : 'update'), 'assignedtouser', 1, '', 0, '', '', 0, 0, 0, 'AND u.statut != 0', 1, $listofuserid, $listofcontactid, $listofotherid);
print '</div>';
print '</td></tr>';
@@ -1485,7 +1518,7 @@ if ($action == 'create') {
// Categories
print '<tr><td>'.$langs->trans("Categories").'</td><td>';
$cate_arbo = $form->select_all_categories(Categorie::TYPE_ACTIONCOMM, '', 'parent', 64, 0, 3);
print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, GETPOST('categories', 'array'), 0, 0, 'minwidth300 quatrevingtpercent widthcentpercentminusx', 0, 0);
print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, GETPOST('categories', 'array'), '', 0, 'minwidth300 quatrevingtpercent widthcentpercentminusx', 0, 0);
print "</td></tr>";
}
@@ -1504,16 +1537,13 @@ if ($action == 'create') {
if (!empty($_SESSION['assignedtoresource'])) {
$listofresourceid = json_decode($_SESSION['assignedtoresource'], true);
}
if (!is_array($listofresourceid)) {
$listofresourceid = array();
}
$firstelem = reset($listofresourceid);
if (isset($listofresourceid[$firstelem['id']])) {
$listofresourceid[$firstelem['id']]['transparency'] = (GETPOSTISSET('transparency') ? GETPOST('transparency', 'alpha') : 0); // 0 by default when refreshing
}
}
print '<div class="assignedtoresource">';
print $form->select_dolresources_forevent(($action == 'create' ? 'add' : 'update'), 'assignedtoresource', 1, array(), 0, '', array(), 0, 0, 0, 'AND u.statut != 0', 1, $listofresourceid);
print $form->select_dolresources_forevent(($action == 'create' ? 'add' : 'update'), 'assignedtoresource', 1, '', 0, '', '', 0, 0, 0, 'AND u.statut != 0', 1, $listofresourceid);
print '</div>';
print '</td></tr>';
}
@@ -1542,7 +1572,7 @@ if ($action == 'create') {
print '<br><hr><br>';
print '<table class="border centpercent nobottom">';
print '<table class="border centpercent">';
if (isModEnabled("societe")) {
// Related company
@@ -1559,7 +1589,7 @@ if ($action == 'create') {
if (!empty($user->socid)) {
print img_picto('', 'company', 'class="paddingrightonly"').$form->select_company($user->socid, 'socid', '', 1, 1, 0, $events, 0, 'minwidth300 widthcentpercentminusxx maxwidth500');
} else {
print img_picto('', 'company', 'class="paddingrightonly"').$form->select_company('', 'socid', '', $langs->trans('SelectThirdParty'), 1, 0, $events, 0, 'minwidth300 widthcentpercentminusxx maxwidth500');
print img_picto('', 'company', 'class="paddingrightonly"').$form->select_company('', 'socid', '', 'SelectThirdParty', 1, 0, $events, 0, 'minwidth300 widthcentpercentminusxx maxwidth500');
}
}
print '</td></tr>';
@@ -1590,10 +1620,10 @@ if ($action == 'create') {
*/
$sav = getDolGlobalString('CONTACT_USE_SEARCH_TO_SELECT');
$conf->global->CONTACT_USE_SEARCH_TO_SELECT = 0;
print $form->selectcontacts(GETPOSTISSET('socid') ? GETPOSTINT('socid') : $select_contact_default, $preselectedids, 'socpeopleassigned[]', 1, '', '', 0, 'minwidth300 widthcentpercentminusxx maxwidth500', 0, 0, 0, array(), 'multiple', 'contactid');
print $form->selectcontacts(GETPOSTISSET('socid') ? GETPOSTINT('socid') : $select_contact_default, $preselectedids, 'socpeopleassigned[]', 1, '', '', 0, 'minwidth300 widthcentpercentminusxx maxwidth500', 0, 0, array(), false, 'multiple', 'contactid');
$conf->global->CONTACT_USE_SEARCH_TO_SELECT = $sav;
} else {
print $form->selectcontacts(GETPOSTISSET('socid') ? GETPOSTINT('socid') : $select_contact_default, $preselectedids, 'socpeopleassigned[]', 1, '', '', 0, 'minwidth300 widthcentpercentminusxx maxwidth500', 0, 0, 0, array(), 'multiple', 'contactid');
print $form->selectcontacts(GETPOSTISSET('socid') ? GETPOSTINT('socid') : $select_contact_default, $preselectedids, 'socpeopleassigned[]', 1, '', '', 0, 'minwidth300 widthcentpercentminusxx maxwidth500', 0, 0, array(), false, 'multiple', 'contactid');
}
print '</td></tr>';
@@ -1729,41 +1759,6 @@ if ($action == 'create') {
print '</table>';
print '</div>';
$reminderDefaultEventTypes = getDolGlobalString('AGENDA_DEFAULT_REMINDER_EVENT_TYPES', '');
$reminderDefaultOffset = getDolGlobalInt('AGENDA_DEFAULT_REMINDER_OFFSET', 30);
$reminderDefaultUnit = getDolGlobalString('AGENDA_DEFAULT_REMINDER_OFFSET_UNIT');
$reminderDefaultEmailModel = getDolGlobalInt('AGENDA_DEFAULT_REMINDER_EMAIL_MODEL');
print "\n".'<script type="text/javascript">';
print '$(document).ready(function () {
const reminderDefaultEventTypes = '.$reminderDefaultEventTypes.';
$("#actioncode").change(function(){
var selected_event_type = $("#actioncode option:selected").val();
if (reminderDefaultEventTypes.includes(selected_event_type)) {
$(".reminderparameters").show();
$("#addreminder").prop("checked", true);
// Set period with default reminder period
$("[name=\"offsetvalue\"]").val("' . $reminderDefaultOffset . '");
$("#select_offsetunittype_duration").select2("destroy");
$("#select_offsetunittype_duration").val("'.$reminderDefaultUnit.'");
$("#select_offsetunittype_duration").select2();
$("#selectremindertype").select2("destroy");
$("#selectremindertype").val("email");
$("#selectremindertype").select2();
// Set default reminder mail model
$("#select_actioncommsendmodel_mail").closest("tr").show();
$("#select_actioncommsendmodel_mail").select2("destroy");
$("#select_actioncommsendmodel_mail").val("'.$reminderDefaultEmailModel.'");
$("#select_actioncommsendmodel_mail").select2();
}
});
})';
print '</script>'."\n";
print "\n".'<script type="text/javascript">';
print '$(document).ready(function () {
$("#addreminder").click(function(){
@@ -1803,7 +1798,7 @@ if ($action == 'create') {
print $form->buttonsSaveCancel("Add");
print "</form>";
}
}
// View or edit
if ($id > 0) {
@@ -1817,7 +1812,7 @@ if ($id > 0) {
}
$result2 = $object->fetch_thirdparty();
$result2 = $object->fetchProject();
$result2 = $object->fetch_projet();
$result3 = $object->fetch_contact();
$result4 = $object->fetch_userassigned();
$result5 = $object->fetch_optionals();
@@ -1825,8 +1820,8 @@ if ($id > 0) {
if ($listUserAssignedUpdated || $donotclearsession) {
$percentage = in_array(GETPOST('status'), array(-1, 100)) ? GETPOST('status') : (in_array($complete, array(-1, 100)) ? $complete : GETPOSTINT("percentage")); // If status is -1 or 100, percentage is not defined and we must use status
$datep = dol_mktime($fulldayevent ? 0 : $aphour, $fulldayevent ? 0 : $apmin, 0, GETPOSTINT("apmonth"), GETPOSTINT("apday"), GETPOSTINT("apyear"), 'tzuserrel');
$datef = dol_mktime($fulldayevent ? 23 : $p2hour, $fulldayevent ? 59 : $p2min, $fulldayevent ? 59 : 0, GETPOSTINT("p2month"), GETPOSTINT("p2day"), GETPOSTINT("p2year"), 'tzuserrel');
$datep = dol_mktime($fulldayevent ? '00' : $aphour, $fulldayevent ? '00' : $apmin, 0, GETPOSTINT("apmonth"), GETPOSTINT("apday"), GETPOSTINT("apyear"), 'tzuserrel');
$datef = dol_mktime($fulldayevent ? '23' : $p2hour, $fulldayevent ? '59' : $p2min, $fulldayevent ? '59' : '0', GETPOSTINT("p2month"), GETPOSTINT("p2day"), GETPOSTINT("p2year"), 'tzuserrel');
$object->type_id = dol_getIdFromCode($db, GETPOST("actioncode", 'aZ09'), 'c_actioncomm');
$object->label = GETPOST("label", "alphanohtml");
@@ -1901,29 +1896,6 @@ if ($id > 0) {
$("#fullday").change(function() {
setdatefields();
});
var old_startdate = null;
$("#ap").focus(function() {
old_startdate = new Date($("#apyear").val(), $("#apmonth").val() - 1, $("#apday").val());
});
$("#ap").next(".ui-datepicker-trigger").click(function() {
old_startdate = new Date($("#apyear").val(), $("#apmonth").val() - 1, $("#apday").val());
});
$("#ap").change(function() {
setTimeout(function() {
if ($("#p2").val() !== "") {
var new_startdate = new Date($("#apyear").val(), $("#apmonth").val() - 1, $("#apday").val());
var old_enddate = new Date($("#p2year").val(), $("#p2month").val() - 1, $("#p2day").val());
if (new_startdate > old_enddate) {
var timeDiff = old_enddate - old_startdate;
var new_enddate = new Date(new_startdate.getTime() + timeDiff);
$("#p2").val(formatDate(new_enddate, "' . $langs->trans('FormatDateShortJavaInput') . '"));
$("#p2day").val(new_enddate.getDate());
$("#p2month").val(new_enddate.getMonth() + 1);
$("#p2year").val(new_enddate.getFullYear());
}
}
}, 0);
});
$("#actioncode").change(function() {
if ($("#actioncode").val() == \'AC_RDV\') $("#dateend").addClass("fieldrequired");
else $("#dateend").removeClass("fieldrequired");
@@ -2089,7 +2061,7 @@ if ($id > 0) {
print '<tr><td class="tdtop nowrap fieldrequired">'.$langs->trans("ActionAssignedTo").'</td><td colspan="3">';
print '<div class="assignedtouser">';
print $form->select_dolusers_forevent(($action == 'create' ? 'add' : 'update'), 'assignedtouser', 1, array(), 0, '', array(), 0, 0, 0, 'AND u.statut != 0', 1, $listofuserid, $listofcontactid, $listofotherid);
print $form->select_dolusers_forevent(($action == 'create' ? 'add' : 'update'), 'assignedtouser', 1, '', 0, '', '', 0, 0, 0, 'AND u.statut != 0', 1, $listofuserid, $listofcontactid, $listofotherid);
print '</div>';
/*if (in_array($user->id,array_keys($listofuserid)))
{
@@ -2120,7 +2092,7 @@ if ($id > 0) {
foreach ($cats as $cat) {
$arrayselected[] = $cat->id;
}
print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, $arrayselected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
print "</td></tr>";
}
@@ -2270,11 +2242,9 @@ if ($id > 0) {
$actionCommReminder->typeremind = 'email';
}
$disabled = '';
/*
if ($object->datep < dol_now()) {
//$disabled = 'disabled title="'.dol_escape_htmltag($langs->trans("EventExpired")).'"';
}
*/
print '<label for="addreminder">'.img_picto('', 'bell', 'class="pictofixedwidth"').$langs->trans("AddReminder").'</label> <input type="checkbox" id="addreminder" name="addreminder"'.($checked ? ' '.$checked : '').($disabled ? ' '.$disabled : '').'><br>';
@@ -2303,7 +2273,7 @@ if ($id > 0) {
// Mail Model
if (getDolGlobalString('AGENDA_REMINDER_EMAIL')) {
print '<tr '.$hide.'><td class="titlefieldcreate nowrap">'.$langs->trans("EMailTemplates").'</td><td colspan="3">';
print $form->selectModelMail('actioncommsend', 'actioncomm_send', 1, 1, $actionCommReminder->fk_email_template);
print $form->selectModelMail('actioncommsend', 'actioncomm_send', 1, 1);
print '</td></tr>';
}
@@ -2331,40 +2301,6 @@ if ($id > 0) {
})';
print '</script>'."\n";
$reminderDefaultEventTypes = getDolGlobalString('AGENDA_DEFAULT_REMINDER_EVENT_TYPES', '');
$reminderDefaultOffset = getDolGlobalString('AGENDA_DEFAULT_REMINDER_OFFSET', 30);
$reminderDefaultUnit = getDolGlobalString('AGENDA_DEFAULT_REMINDER_OFFSET_UNIT');
$reminderDefaultEmailModel = getDolGlobalString('AGENDA_DEFAULT_REMINDER_EMAIL_MODEL');
print "\n".'<script type="text/javascript">';
print '$(document).ready(function () {
const reminderDefaultEventTypes = '.$reminderDefaultEventTypes.';
$("#actioncode").change(function(){
var selected_event_type = $("#actioncode option:selected").val();
if (reminderDefaultEventTypes.includes(selected_event_type)) {
$(".reminderparameters").show();
$("#addreminder").prop("checked", true);
// Set period with default reminder period
$("#offsetvalue").val('.$reminderDefaultOffset.');
$("#select_offsetunittype_duration").select2("destroy");
$("#select_offsetunittype_duration").val("'.$reminderDefaultUnit.'");
$("#select_offsetunittype_duration").select2();
$("#selectremindertype").select2("destroy");
$("#selectremindertype").val("email");
$("#selectremindertype").select2();
// Set default reminder mail model
$("#select_actioncommsendmodel_mail").closest("tr").show();
$("#select_actioncommsendmodel_mail").select2("destroy");
$("#select_actioncommsendmodel_mail").val("'.$reminderDefaultEmailModel.'");
$("#select_actioncommsendmodel_mail").select2();
}
});
})';
print '</script>'."\n";
print '</div>'; // End of div for reminderparameters
}
@@ -2477,13 +2413,12 @@ if ($id > 0) {
// Type
if (getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td>';
$labeltype = ($langs->transnoentities("Action".$object->type_code) != "Action".$object->type_code) ? $langs->transnoentities("Action".$object->type_code) : $object->type_label;
$labeltoshow = $labeltype;
$labeltoshow = $langs->trans("Action".$object->type_code);
if ($object->code) {
$labeltoshow .= ' ('.$object->code.')';
}
print $object->getTypePicto('pictofixedwidth paddingright', $labeltoshow);
print $labeltype;
print $langs->trans("Action".$object->type_code);
print '</td></tr>';
}
@@ -2567,7 +2502,7 @@ if ($id > 0) {
$listofcontactid = array(); // not used yet
$listofotherid = array(); // not used yet
print '<div class="assignedtouser">';
print $form->select_dolusers_forevent('view', 'assignedtouser', 1, array(), 0, '', array(), 0, 0, 0, '', ($object->datep != $object->datef) ? 1 : 0, $listofuserid, $listofcontactid, $listofotherid);
print $form->select_dolusers_forevent('view', 'assignedtouser', 1, '', 0, '', '', 0, 0, 0, '', ($object->datep != $object->datef) ? 1 : 0, $listofuserid, $listofcontactid, $listofotherid);
print '</div>';
/*
if ($object->datep != $object->datef && in_array($user->id,array_keys($listofuserid)))