dolibarr 23.0.3
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
5 * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
8 * Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
9 * Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
10 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
11 * Copyright (C) 2019 Ferran Marcet <fmarcet@2byte.es>
12 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27
34// Load Dolibarr environment
35require '../../main.inc.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
44require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
45require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
46require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
47require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
48require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
49require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
50require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
51require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
52require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncommreminder.class.php';
53require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
54require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
55require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
56require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
57require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
58
59// Load translation files required by the page
60$langs->loadLangs(["companies", "other", "commercial", "bills", "orders", "agenda", "mails"]);
61
62// Get Parameters
63$action = GETPOST('action', 'aZ09');
64$cancel = GETPOST('cancel', 'alpha');
65$backtopage = GETPOST('backtopage', 'alpha');
66$socpeopleassigned = GETPOST('socpeopleassigned', 'array');
67$origin = GETPOST('origin', 'alpha');
68$originid = GETPOSTINT('originid');
69$confirm = GETPOST('confirm', 'alpha');
70
71$fulldayevent = GETPOST('fullday', 'alpha');
72
73$aphour = GETPOSTINT('aphour');
74$apmin = GETPOSTINT('apmin');
75$p2hour = GETPOSTINT('p2hour');
76$p2min = GETPOSTINT('p2min');
77
78$addreminder = GETPOST('addreminder', 'alpha');
79$offsetvalue = GETPOSTINT('offsetvalue');
80$offsetunit = GETPOST('offsetunittype_duration', 'aZ09');
81$remindertype = GETPOST('selectremindertype', 'aZ09');
82$modelmail = GETPOSTINT('actioncommsendmodel_mail');
83$complete = GETPOST('complete', 'alpha'); // 'na' must be allowed
84$private = GETPOST('private', 'alphanohtml');
85if ($complete == 'na' || $complete == -2) {
86 $complete = -1;
87}
88
89$tzforfullday = null;
90if ($fulldayevent) {
91 $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
92 // For "full day" events, we must store date in GMT (It must be viewed as same moment everywhere)
93 $datep = dol_mktime(0, 0, 0, GETPOSTINT("apmonth"), GETPOSTINT("apday"), GETPOSTINT("apyear"), $tzforfullday ? $tzforfullday : 'tzuserrel');
94 $datef = dol_mktime(23, 59, 59, GETPOSTINT("p2month"), GETPOSTINT("p2day"), GETPOSTINT("p2year"), $tzforfullday ? $tzforfullday : 'tzuserrel');
95 //print $db->idate($datep); exit;
96} else {
97 $datep = dol_mktime($aphour, $apmin, 0, GETPOSTINT("apmonth"), GETPOSTINT("apday"), GETPOSTINT("apyear"), 'tzuserrel');
98 $datef = dol_mktime($p2hour, $p2min, 59, GETPOSTINT("p2month"), GETPOSTINT("p2day"), GETPOSTINT("p2year"), 'tzuserrel');
99}
100$reg = [];
101if (GETPOST('datep')) {
102 if (GETPOST('datep') == 'now') {
103 $datep = dol_now();
104 } 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'
105 $datep = dol_mktime(0, 0, 0, (int) $reg[2], (int) $reg[3], (int) $reg[1], 'tzuserrel');
106 }
107}
108
109$currentyear = (int) dol_print_date(dol_now(), '%Y');
110
111if (GETPOSTISSET("limityear") && GETPOSTINT("limityear") < 2100) {
112 $repeateventlimitdate = dol_mktime(23, 59, 59, GETPOSTISSET("limitmonth") ? GETPOSTINT("limitmonth") : 1, GETPOSTISSET("limitday") ? GETPOSTINT("limitday") : 1, GETPOSTINT("limityear"), $tzforfullday ? $tzforfullday : 'tzuserrel');
113} else {
114 $repeateventlimitdate = dol_mktime(23, 59, 59, 12, 31, $currentyear, $tzforfullday ? $tzforfullday : 'tzuserrel');
115}
116
117// Security check
118$socid = GETPOSTINT('socid');
119if (empty($socid)) {
120 $socid = $user->socid; // External users: fall back to their own company (consistent with other card pages)
121}
122$id = GETPOSTINT('id');
123if ($user->socid && ($socid != $user->socid)) {
125}
126
127$error = GETPOST("error");
128$donotclearsession = GETPOST('donotclearsession') ? GETPOST('donotclearsession') : 0;
129
130// Initialize Objects
131$object = new ActionComm($db);
132$cactioncomm = new CActionComm($db);
133$contact = new Contact($db);
134$extrafields = new ExtraFields($db);
135$formfile = new FormFile($db);
136
137$form = new Form($db);
138$formfile = new FormFile($db);
139$formactions = new FormActions($db);
140
141// Load object
142if ($id > 0 && $action != 'add') {
143 $ret = $object->fetch($id);
144 $ret1 = 0;
145 if ($ret > 0) {
146 $ret = $object->fetch_optionals();
147 $ret1 = $object->fetch_userassigned();
148 }
149 if ($ret < 0 || $ret1 < 0) {
150 dol_print_error(null, $object->error);
151 }
152}
153
154// fetch optionals attributes and labels
155$extrafields->fetch_name_optionals_label($object->table_element);
156
157if (empty($action) && empty($object->id)) {
158 $action = 'create';
159}
160
161// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
162$hookmanager->initHooks(['actioncard', 'globalcard']);
163
164$TRemindTypes = [];
165if (getDolGlobalString('AGENDA_REMINDER_BROWSER')) {
166 $TRemindTypes['browser'] = [
167 'label' => $langs->trans('BrowserPush'),
168 'disabled' => (getDolGlobalString('AGENDA_REMINDER_BROWSER') ? 0 : 1),
169 'type' => ActionCommReminder::TYPE_USER,
170 'data-html' => img_picto('', 'globe', 'class="pictofixedwidth"') . $langs->trans('BrowserPush'),
171 ];
172}
173if (getDolGlobalString('AGENDA_REMINDER_EMAIL')) {
174 $TRemindTypes['email'] = [
175 'label' => $langs->trans('EMail'),
176 'disabled' => (getDolGlobalString('AGENDA_REMINDER_EMAIL') ? 0 : 1),
177 'type' => ActionCommReminder::TYPE_USER,
178 'data-html' => img_picto('', 'email', 'class="pictofixedwidth"') . $langs->trans('EMail'),
179 ];
180}
181if (getDolGlobalString('AGENDA_REMINDER_SMS')) {
182 $langs->load('sms');
183 $TRemindTypes['sms'] = [
184 'label' => $langs->trans('Sms'),
185 'disabled' => (getDolGlobalString('MAIN_SMS_SENDMODE') ? 0 : 1),
186 'type' => ActionCommReminder::TYPE_USER,
187 'data-html' => img_picto('', 'phoning_mobile', 'class="pictofixedwidth"') . $langs->trans('Sms'),
188 ];
189}
190$TDurationTypes = $form->getDurationTypes($langs);
191$TDurationTypesExcluded = ['y', 'm', 's'];
192$enablereminders = getDolGlobalString('AGENDA_REMINDER_EMAIL') || getDolGlobalString('AGENDA_REMINDER_BROWSER') || getDolGlobalString('AGENDA_REMINDER_SMS');
193$parameters = [
194 'socid' => $socid,
195 'TRemindTypes' => &$TRemindTypes,
196 'enablereminders' => &$enablereminders,
197 'TDurationTypes' => &$TDurationTypes,
198 'TDurationTypesExcluded' => &$TDurationTypesExcluded,
199];
200$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
201if ($reshook < 0) {
202 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
203}
204
205$result = restrictedArea($user, 'agenda', $object, 'actioncomm&societe', 'myactions|allactions', 'fk_soc', 'id');
206
207$usercancreate = $user->hasRight('agenda', 'allactions', 'create') || ((empty($object->id) || $object->authorid == $user->id || $object->userownerid == $user->id) && $user->hasRight('agenda', 'myactions', 'create'));
208$usercandelete = $user->hasRight('agenda', 'allactions', 'delete') || (($object->authorid === $user->id || $object->userownerid === $user->id) && $user->hasRight('agenda', 'myactions', 'delete'));
209
210
211/*
212 * Actions
213 */
214
215$listUserAssignedUpdated = false;
216$listResourceAssignedUpdated = false;
217$assignedtouser = [];
218
219// Remove user to assigned list
220if (empty($reshook) && (GETPOST('removedassigned') || GETPOST('removedassigned') == '0')) {
221 $idtoremove = GETPOST('removedassigned');
222
223 if (!empty($_SESSION['assignedtouser'])) {
224 $tmpassigneduserids = json_decode($_SESSION['assignedtouser'], true);
225 } else {
226 $tmpassigneduserids = [];
227 }
228
229 foreach ($tmpassigneduserids as $key => $val) {
230 if ($val['id'] == $idtoremove || $val['id'] == -1) {
231 unset($tmpassigneduserids[$key]);
232 }
233 }
234
235 $_SESSION['assignedtouser'] = json_encode($tmpassigneduserids);
236 $donotclearsession = 1;
237 if ($action == 'add') { // Test on permission not required here
238 $action = 'create';
239 }
240 if ($action == 'update') { // Test on permission not required here
241 $action = 'edit';
242 }
243
244 $listUserAssignedUpdated = true;
245}
246// Remove resource to assigned list
247if (empty($reshook) && (GETPOST('removedassignedresource') || GETPOST('removedassignedresource') == '0')) {
248 $idtoremove = GETPOST('removedassignedresource');
249
250 if (!empty($_SESSION['assignedtoresource'])) {
251 $tmpassignedresourceids = json_decode($_SESSION['assignedtoresource'], true);
252 } else {
253 $tmpassignedresourceids = [];
254 }
255
256 foreach ($tmpassignedresourceids as $key => $val) {
257 if ($val['id'] == $idtoremove || $val['id'] == -1) {
258 unset($tmpassignedresourceids[$key]);
259 }
260 }
261
262 $_SESSION['assignedtoresource'] = json_encode($tmpassignedresourceids);
263
264 if ($action == 'add' && $usercancreate) {
265 $action = 'create';
266 }
267 if ($action == 'update' && $usercancreate) {
268 $action = 'edit';
269 }
270
271 $listResourceAssignedUpdated = true;
272}
273
274// Add user to assigned list
275if (empty($reshook) && (GETPOST('addassignedtouser') || GETPOST('updateassignedtouser'))) {
276 // Add a new user
277 if (GETPOST('assignedtouser') > 0) {
278 $assignedtouser = [];
279 if (!empty($_SESSION['assignedtouser'])) {
280 $assignedtouser = json_decode($_SESSION['assignedtouser'], true);
281 }
282 $assignedtouser[GETPOST('assignedtouser')] = array('id' => GETPOSTINT('assignedtouser'), 'transparency' => GETPOST('transparency'), 'mandatory' => 1);
283 $_SESSION['assignedtouser'] = json_encode($assignedtouser);
284 }
285 $donotclearsession = 1;
286 if ($action == 'add' && $usercancreate) {
287 $action = 'create';
288 }
289 if ($action == 'update' && $usercancreate) {
290 $action = 'edit';
291 }
292
293 $listUserAssignedUpdated = true;
294}
295
296// Add resource to assigned list
297if (empty($reshook) && (GETPOST('addassignedtoresource') || GETPOST('updateassignedtoresource'))) {
298 // Add a new user
299 if (GETPOST('assignedtoresource') > 0) {
300 $assignedtoresource = [];
301 if (!empty($_SESSION['assignedtoresource'])) {
302 $assignedtoresource = json_decode($_SESSION['assignedtoresource'], true);
303 }
304 $assignedtoresource[GETPOST('assignedtoresource')] = array('id' => GETPOSTINT('assignedtoresource'), 'transparency' => GETPOST('transparency'), 'mandatory' => 1);
305 $_SESSION['assignedtoresource'] = json_encode($assignedtoresource);
306 }
307 $donotclearsession = 1;
308 if ($action == 'add' && $usercancreate) {
309 $action = 'create';
310 }
311 if ($action == 'update' && $usercancreate) {
312 $action = 'edit';
313 }
314
315 $listResourceAssignedUpdated = true;
316}
317
318// Link to a project
319if (empty($reshook) && $action == 'classin' && ($user->hasRight('agenda', 'allactions', 'create') ||
320 (($object->authorid == $user->id || $object->userownerid == $user->id) && $user->hasRight('agenda', 'myactions', 'create')))) {
321 //$object->fetch($id);
322 $object->setProject(GETPOSTINT('projectid'));
323}
324
325// Action clone object
326if (empty($reshook) && $action == 'confirm_clone' && $confirm == 'yes' && $usercancreate) {
327 // @phan-suppress-next-line PhanPluginBothLiteralsBinaryOp
328 if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) {
329 setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
330 } else {
331 if ($id > 0) {
332 //$object->fetch($id);
333 if (!empty($object->socpeopleassigned)) {
334 reset($object->socpeopleassigned);
335 $object->contact_id = key($object->socpeopleassigned);
336 }
337 $result = $object->createFromClone($user, GETPOSTINT('socid'));
338 if ($result > 0) {
339 header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
340 exit();
341 } else {
342 setEventMessages($object->error, $object->errors, 'errors');
343 $action = '';
344 }
345 }
346 }
347}
348
349// Add event
350if (empty($reshook) && $action == 'add' && $usercancreate) {
351 $error = 0;
352
353 if (empty($backtopage)) {
354 if ($socid > 0) {
355 $backtopage = DOL_URL_ROOT.'/societe/agenda.php?socid='.$socid;
356 } else {
357 $backtopage = DOL_URL_ROOT.'/comm/action/index.php';
358 }
359 }
360
361 if (!empty($socpeopleassigned[0])) {
362 $result = $contact->fetch($socpeopleassigned[0]);
363 }
364
365 if ($cancel) {
366 header("Location: ".$backtopage);
367 exit;
368 }
369
370 $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
371
372 // Clean parameters
373 if ($fulldayevent) {
374 $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
375 // For "full day" events, we must store date in GMT (It must be viewed as same moment everywhere)
376 $datep = dol_mktime(0, 0, 0, GETPOSTINT("apmonth"), GETPOSTINT("apday"), GETPOSTINT("apyear"), $tzforfullday ? $tzforfullday : 'tzuserrel');
377 $datef = dol_mktime(23, 59, 59, GETPOSTINT("p2month"), GETPOSTINT("p2day"), GETPOSTINT("p2year"), $tzforfullday ? $tzforfullday : 'tzuserrel');
378 } else {
379 $datep = dol_mktime(GETPOSTINT("aphour"), GETPOSTINT("apmin"), GETPOSTINT("apsec"), GETPOSTINT("apmonth"), GETPOSTINT("apday"), GETPOSTINT("apyear"), 'tzuserrel');
380 $datef = dol_mktime(GETPOSTINT("p2hour"), GETPOSTINT("p2min"), GETPOSTINT("apsec"), GETPOSTINT("p2month"), GETPOSTINT("p2day"), GETPOSTINT("p2year"), 'tzuserrel');
381 }
382 //set end date to now if percentage is set to 100 and end date not set
383 $datef = (!$datef && $percentage == 100) ? dol_now() : $datef;
384
385 // Check parameters
386 if (!$datef && $percentage == 100) {
387 $error++;
388 $donotclearsession = 1;
389 $action = 'create';
390 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEnd")), null, 'errors');
391 }
392
393 if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') && !GETPOST('label')) {
394 $error++;
395 $donotclearsession = 1;
396 $action = 'create';
397 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Title")), null, 'errors');
398 }
399
400 // Initialisation object cactioncomm
401 if (GETPOSTISSET('actioncode') && !GETPOST('actioncode', 'aZ09')) { // actioncode is '0'
402 $error++;
403 $donotclearsession = 1;
404 $action = 'create';
405 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
406 } else {
407 $object->type_code = GETPOST('actioncode', 'aZ09');
408 }
409
410 $listofresourceid = [];
411
412 if (!$error) {
413 // Initialisation of object actioncomm
414 $object->priority = GETPOSTISSET("priority") ? GETPOSTINT("priority") : 0;
415 $object->fulldayevent = ($fulldayevent ? 1 : 0);
416 $object->location = GETPOST("location", 'alphanohtml');
417 $object->label = GETPOST('label', 'alphanohtml');
418
419 if (GETPOST("elementtype", 'alpha')) {
420 $elProp = getElementProperties(GETPOST("elementtype", 'alpha'));
421 $modulecodetouseforpermissioncheck = $elProp['module'];
422 // Keep permission check aligned with rights class aliases (see restrictedArea()).
423 if ($modulecodetouseforpermissioncheck == 'productbatch') {
424 $modulecodetouseforpermissioncheck = 'produit';
425 }
426 $submodulecodetouseforpermissioncheck = $elProp['subelement'];
427
428 $hasPermissionOnLinkedObject = 0;
429 if ($user->hasRight($modulecodetouseforpermissioncheck, 'read')) {
430 $hasPermissionOnLinkedObject = 1;
431 } elseif ($user->hasRight($modulecodetouseforpermissioncheck, $submodulecodetouseforpermissioncheck, 'read')) {
432 $hasPermissionOnLinkedObject = 1;
433 }
434
435 if ($hasPermissionOnLinkedObject) {
436 $object->fk_element = GETPOSTINT("fk_element");
437 $object->elementid = GETPOSTINT("fk_element");
438 $object->elementtype = GETPOST("elementtype", 'alpha');
439 }
440 }
441
442 if (!GETPOST('label')) {
443 if (GETPOST('actioncode', 'aZ09') == 'AC_RDV' && $contact->getFullName($langs)) {
444 $object->label = $langs->transnoentitiesnoconv("TaskRDVWith", $contact->getFullName($langs));
445 } else {
446 if ($langs->trans("Action".$object->type_code) != "Action".$object->type_code) {
447 $object->label = $langs->transnoentitiesnoconv("Action".$object->type_code)."\n";
448 } else {
449 $cactioncomm->fetch($object->type_code);
450 $object->label = $cactioncomm->label;
451 }
452 }
453 }
454 $object->fk_project = GETPOSTISSET("projectid") ? GETPOSTINT("projectid") : 0;
455
456 $taskid = GETPOSTINT('taskid');
457 if (!empty($taskid)) {
458 $taskProject = new Task($db);
459 if ($taskProject->fetch($taskid) > 0) {
460 $object->fk_project = $taskProject->fk_project;
461 }
462
463 $object->fk_element = $taskid;
464 $object->elementid = $taskid;
465 $object->elementtype = 'project_task';
466 }
467
468 $object->datep = $datep;
469 $object->datef = $datef;
470 $object->percentage = $percentage;
471 $object->duree = (((int) GETPOST('dureehour') * 60) + (int) GETPOST('dureemin')) * 60;
472
473 $transparency = (GETPOST("transparency") == 'on' ? 1 : 0);
474
475 $listofuserid = [];
476 if (!empty($_SESSION['assignedtouser'])) {
477 $listofuserid = json_decode($_SESSION['assignedtouser'], true);
478 }
479
480 if (!empty($_SESSION['assignedtoresource'])) {
481 $listofresourceid = json_decode($_SESSION['assignedtoresource'], true);
482 }
483
484 $i = 0;
485 foreach ($listofuserid as $key => $value) {
486 if ($i == 0) { // First entry
487 if ($value['id'] > 0) {
488 $object->userownerid = $value['id'];
489 }
490 $object->transparency = $transparency;
491 }
492
493 $object->userassigned[$value['id']] = array('id' => $value['id'], 'transparency' => $transparency);
494
495 $i++;
496 }
497 }
498
499 $object->note_private = trim(GETPOST("note", "restricthtml"));
500
501 if (GETPOSTISSET("contactid")) {
502 $object->contact_id = GETPOSTINT("contactid");
503 $object->fetch_contact();
504 }
505
506 if (GETPOSTINT('socid') > 0) {
507 $object->socid = GETPOSTINT('socid');
508 $object->fetch_thirdparty();
509 }
510
511 // Check parameters
512 if (empty($object->userownerid) && empty($_SESSION['assignedtouser'])) {
513 $error++;
514 $donotclearsession = 1;
515 $action = 'create';
516 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ActionsOwnedBy")), null, 'errors');
517 }
518 if ($object->type_code == 'AC_RDV' && ($datep == '' || ($datef == '' && empty($fulldayevent)))) {
519 $error++;
520 $donotclearsession = 1;
521 $action = 'create';
522 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEnd")), null, 'errors');
523 }
524
525 if (!GETPOST('apyear') && !GETPOST('adyear')) {
526 $error++;
527 $donotclearsession = 1;
528 $action = 'create';
529 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
530 }
531
532 foreach ($socpeopleassigned as $cid) {
533 $object->socpeopleassigned[$cid] = array('id' => $cid);
534 }
535 if (!empty($object->socpeopleassigned)) {
536 reset($object->socpeopleassigned);
537 $object->contact_id = key($object->socpeopleassigned);
538 }
539
540 // Fill array 'array_options' with data from add form
541 $ret = $extrafields->setOptionalsFromPost(null, $object);
542 if ($ret < 0) {
543 $error++;
544 $donotclearsession = 1;
545 $action = 'create';
546 }
547
548
549 if (!$error) {
550 $db->begin();
551
552 $dayinyear = dol_print_date($object->datep, '%m%d');
553 $dayinmonth = dol_print_date($object->datep, '%d');
554 $dayinweek = dol_print_date($object->datep, '%w');
555
556 $selectedrecurrulefreq = 'no';
557 $selectedrecurrulebyyearmonthday = '';
558 $selectedrecurrulebymonthday = '';
559 $selectedrecurrulebyday = '';
560 $object->recurrule = GETPOSTISSET('recurrulefreq') ? "FREQ=".GETPOST('recurrulefreq', 'alpha') : "";
561 $object->recurrule .= (GETPOST('recurrulefreq', 'alpha') == 'YEARLY') ? "_BYYEARMONTHDAY".((int) $dayinyear) : "";
562 $object->recurrule .= (GETPOST('recurrulefreq', 'alpha') == 'MONTHLY') ? "_BYMONTHDAY".((int) $dayinmonth) : "";
563 $object->recurrule .= (GETPOST('recurrulefreq', 'alpha') == 'WEEKLY') ? "_BYDAY".((int) $dayinweek) : "";
564
565 $reg1 = [];
566 $reg2 = [];
567 $reg3 = [];
568 $reg4 = [];
569 if ($object->recurrule && preg_match('/FREQ=([A-Z]+)/i', $object->recurrule, $reg1)) {
570 $selectedrecurrulefreq = $reg1[1];
571 }
572 if ($object->recurrule && preg_match('/FREQ=YEARLY.*BYYEARMONTHDAY(\d+)/i', $object->recurrule, $reg4)) {
573 $selectedrecurrulebyyearmonthday = (int) $reg4[1];
574 }
575 if ($object->recurrule && preg_match('/FREQ=MONTHLY.*BYMONTHDAY(\d+)/i', $object->recurrule, $reg2)) {
576 $selectedrecurrulebymonthday = (int) $reg2[1];
577 }
578 if ($object->recurrule && preg_match('/FREQ=WEEKLY.*BYDAY(\d+)/i', $object->recurrule, $reg3)) {
579 $selectedrecurrulebyday = (int) $reg3[1];
580 }
581
582 // Is event recurrent ?
583 $eventisrecurring = 0;
584 $userepeatevent = (getDolGlobalInt('MAIN_DISABLE_RECURRING_EVENTS') ? 0 : 1);
585 if ($userepeatevent && !empty($selectedrecurrulefreq) && $selectedrecurrulefreq != 'no') {
586 $eventisrecurring = 1;
587 $object->recurid = dol_print_date(dol_now('gmt'), 'dayhourlog', 'gmt');
588 $object->recurdateend = dol_mktime(0, 0, 0, GETPOSTINT('limitmonth'), GETPOSTINT('limitday'), GETPOSTINT('limityear'));
589 } else {
590 unset($object->recurid);
591 unset($object->recurrule);
592 unset($object->recurdateend);
593 }
594
595 // Creation of action/event
596 $idaction = $object->create($user);
597 $moreparam = '';
598
599 if ($idaction > 0) {
600 if (!$object->error) {
601 if (is_array($listofresourceid) && count($listofresourceid)) {
602 foreach ($listofresourceid as $resource_id => $val) {
603 $resource_type = 'dolresource';
604 $busy = 1;//GETPOSTINT('busy');
605
606 // Resources association
607 if (getDolGlobalString('RESOURCE_USED_IN_EVENT_CHECK')) {
608 $eventDateStart = $object->datep;
609 $eventDateEnd = $object->datef;
610 $isFullDayEvent = $object->fulldayevent;
611 if (empty($eventDateEnd)) {
612 if ($isFullDayEvent) {
613 $eventDateStartArr = dol_getdate($eventDateStart);
614 $eventDateStart = dol_mktime(0, 0, 0, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']);
615 $eventDateEnd = dol_mktime(23, 59, 59, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']);
616 }
617 }
618
619 $sql = "SELECT er.rowid, r.ref as r_ref, ac.id as ac_id, ac.label as ac_label";
620 $sql .= " FROM " . MAIN_DB_PREFIX . "element_resources as er";
621 $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "resource as r ON r.rowid = er.resource_id AND er.resource_type = '" . $db->escape($resource_type) . "'";
622 $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "actioncomm as ac ON ac.id = er.element_id AND er.element_type = '" . $db->escape($object->element) . "'";
623 $sql .= " WHERE er.resource_id = " . ((int) $resource_id);
624 $sql .= " AND er.busy = 1";
625 $sql .= " AND (";
626
627 // event date start between ac.datep and ac.datep2 (if datep2 is null we consider there is no end)
628 $sql .= " (ac.datep <= '" . $db->idate($eventDateStart) . "' AND (ac.datep2 IS NULL OR ac.datep2 >= '" . $db->idate($eventDateStart) . "'))";
629 // event date end between ac.datep and ac.datep2
630 if (!empty($eventDateEnd)) {
631 $sql .= " OR (ac.datep <= '" . $db->idate($eventDateEnd) . "' AND (ac.datep2 >= '" . $db->idate($eventDateEnd) . "'))";
632 }
633 // event date start before ac.datep and event date end after ac.datep2
634 $sql .= " OR (";
635 $sql .= "ac.datep >= '" . $db->idate($eventDateStart) . "'";
636 if (!empty($eventDateEnd)) {
637 $sql .= " AND (ac.datep2 IS NOT NULL AND ac.datep2 <= '" . $db->idate($eventDateEnd) . "')";
638 }
639 $sql .= ")";
640
641 $sql .= ")";
642 $resql = $db->query($sql);
643 if (!$resql) {
644 $error++;
645 $object->error = $db->lasterror();
646 $object->errors[] = $object->error;
647 } else {
648 if ($db->num_rows($resql) > 0) {
649 // Resource already in use
650 $error++;
651 $object->error = $langs->trans('ErrorResourcesAlreadyInUse') . ' : ';
652 while ($obj = $db->fetch_object($resql)) {
653 $object->error .= '<br> - ' . $langs->trans('ErrorResourceUseInEvent', $obj->r_ref, $obj->ac_label . ' [' . $obj->ac_id . ']');
654 }
655 $object->errors[] = $object->error;
656
657 setEventMessages($object->error, null, 'errors');
658 }
659 $db->free($resql);
660 }
661 }
662
663 if (!$error) {
664 $res = $object->add_element_resource($resource_id, $resource_type, $busy, $val['mandatory']);
665 }
666 }
667 }
668
669 unset($_SESSION['assignedtoresource']);
670
671
672 // Category association
673 if (!$error) {
674 $categories = GETPOST('categories', 'array');
675 $object->setCategories($categories);
676 }
677
678 unset($_SESSION['assignedtouser']);
679
680 if ($user->id != $object->userownerid) {
681 $moreparam = "filtert=-1"; // We force to remove filter so created record is visible when going back to per user view.
682 }
683
684 // Create reminders
685 if (!$error && $addreminder == 'on') {
686 $actionCommReminder = new ActionCommReminder($db);
687
688 $dateremind = dol_time_plus_duree($datep, -1 * $offsetvalue, $offsetunit);
689
690 $actionCommReminder->dateremind = $dateremind;
691 $actionCommReminder->typeremind = $remindertype;
692 $actionCommReminder->offsetunit = $offsetunit;
693 $actionCommReminder->offsetvalue = $offsetvalue;
694 $actionCommReminder->status = $actionCommReminder::STATUS_TODO;
695 $actionCommReminder->fk_actioncomm = $object->id;
696 if ($remindertype == 'email') {
697 $actionCommReminder->fk_email_template = $modelmail;
698 }
699
700 // the notification must be created for every user assigned to the event
701 foreach ($object->userassigned as $userassigned) {
702 $actionCommReminder->fk_user = $userassigned['id'];
703 $res = $actionCommReminder->create($user);
704
705 if ($res <= 0) {
706 // If error
707 $langs->load("errors");
708 $error++;
709 setEventMessages($langs->trans('ErrorReminderActionCommCreation'), null, 'errors');
710 $action = 'create';
711 $donotclearsession = 1;
712 break;
713 }
714 }
715 }
716
717 // Modify $moreparam so we are sure to see the event we have just created, whatever are the default value of filter on next page.
718 /*$moreparam .= ($moreparam ? '&' : '').'search_actioncode=0';
719 $moreparam .= ($moreparam ? '&' : '').'search_status=-1';
720 $moreparam .= ($moreparam ? '&' : '').'search_filtert='.$object->userownerid;
721 */
722 $moreparam .= ($moreparam ? '&' : '').'disabledefaultvalues=1';
723
724 // if (!empty($backtopage)) {
725 // dol_syslog("Back to ".$backtopage.($moreparam ? (preg_match('/\?/', $backtopage) ? '&'.$moreparam : '?'.$moreparam) : ''));
726 // header("Location: ".$backtopage.($moreparam ? (preg_match('/\?/', $backtopage) ? '&'.$moreparam : '?'.$moreparam) : ''));
727 // } elseif ($idaction) {
728 // header("Location: ".DOL_URL_ROOT.'/comm/action/card.php?id='.$idaction.($moreparam ? '&'.$moreparam : ''));
729 // } else {
730 // header("Location: ".DOL_URL_ROOT.'/comm/action/index.php'.($moreparam ? '?'.$moreparam : ''));
731 // }
732 // exit;
733 } else {
734 // If error
735 $langs->load("errors");
736 $error++;
737 setEventMessages($langs->trans($object->error), null, 'errors');
738 $action = 'create';
739 $donotclearsession = 1;
740 }
741 } else {
742 $error++;
743 setEventMessages($object->error, $object->errors, 'errors');
744 $action = 'create';
745 $donotclearsession = 1;
746 }
747
748 // Manage other events in case of recurring event
749 if (!$error && $eventisrecurring) {
750 $dayoffset = 0;
751 $monthoffset = 0;
752 $yearoffset = 0;
753 // We set first date of recurrence and offsets
754 if ($selectedrecurrulefreq == 'WEEKLY' && !empty($selectedrecurrulebyday)) {
755 $firstdatearray = dol_get_first_day_week(GETPOSTINT("apday"), GETPOSTINT("apmonth"), GETPOSTINT("apyear"));
756 $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');
757 $datep = dol_time_plus_duree($datep, $selectedrecurrulebyday + 6, 'd');//We begin the week after
758 $dayoffset = 7;
759 $monthoffset = 0;
760 $yearoffset = 0;
761 } elseif ($selectedrecurrulefreq == 'MONTHLY' && !empty($selectedrecurrulebymonthday)) {
762 $firstday = $selectedrecurrulebymonthday;
763 $firstmonth = GETPOST("apday") > $selectedrecurrulebymonthday ? GETPOSTINT("apmonth") + 1 : GETPOSTINT("apmonth");//We begin the month after
764 $datep = dol_mktime($fulldayevent ? 0 : GETPOSTINT("aphour"), $fulldayevent ? 0 : GETPOSTINT("apmin"), $fulldayevent ? 0 : GETPOSTINT("apsec"), $firstmonth, $firstday, GETPOSTINT("apyear"), $tzforfullday ? $tzforfullday : 'tzuserrel');
765 $datep = dol_time_plus_duree($datep, 1, 'm');//We begin the month after
766 $dayoffset = 0;
767 $monthoffset = 1;
768 $yearoffset = 0;
769 } elseif ($selectedrecurrulefreq == 'YEARLY' && !empty($selectedrecurrulebyyearmonthday)) {
770 $datep = dol_mktime($fulldayevent ? 0 : GETPOSTINT("aphour"), $fulldayevent ? 0 : GETPOSTINT("apmin"), $fulldayevent ? 0 : GETPOSTINT("apsec"), GETPOSTINT("apmonth"), GETPOSTINT("apday"), GETPOSTINT("apyear"), $tzforfullday ? $tzforfullday : 'tzuserrel');
771 $datep = dol_time_plus_duree($datep, 1, 'y');//We begin the year after
772 $dayoffset = 0;
773 $monthoffset = 0;
774 $yearoffset = 1;
775 } else {
776 $error++;
777 }
778 // End date
779 // Set date of end of event
780 $deltatime = num_between_day($object->datep, $datep);
781 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
782 $datef = dol_time_plus_duree($datef, $deltatime, 'd');
783
784 while ($datep <= $repeateventlimitdate && !$error) {
785 $finalobject = clone $object;
786
787
788 $finalobject->datep = $datep;
789 $finalobject->datef = $datef;
790 // Creation of action/event
791 $idaction = $finalobject->create($user);
792
793 if ($idaction > 0) {
794 if (!$finalobject->error) {
795 // Category association
796 $categories = GETPOST('categories', 'array');
797 $finalobject->setCategories($categories);
798
799 unset($_SESSION['assignedtouser']);
800
801 $moreparam = '';
802 if ($user->id != $finalobject->userownerid) {
803 $moreparam = "filtert=-1"; // We force to remove filter so created record is visible when going back to per user view.
804 }
805
806 // Create reminders
807 if ($addreminder == 'on') {
808 $actionCommReminder = new ActionCommReminder($db);
809
810 $dateremind = dol_time_plus_duree($datep, -1 * $offsetvalue, $offsetunit);
811
812 $actionCommReminder->dateremind = $dateremind;
813 $actionCommReminder->typeremind = $remindertype;
814 $actionCommReminder->offsetunit = $offsetunit;
815 $actionCommReminder->offsetvalue = $offsetvalue;
816 $actionCommReminder->status = $actionCommReminder::STATUS_TODO;
817 $actionCommReminder->fk_actioncomm = $finalobject->id;
818 if ($remindertype == 'email') {
819 $actionCommReminder->fk_email_template = $modelmail;
820 }
821
822 // the notification must be created for every user assigned to the event
823 foreach ($finalobject->userassigned as $userassigned) {
824 $actionCommReminder->fk_user = $userassigned['id'];
825 $res = $actionCommReminder->create($user);
826
827 if ($res <= 0) {
828 // If error
829 $error++;
830 $langs->load("errors");
831 setEventMessages($langs->trans('ErrorReminderActionCommCreation'), null, 'errors');
832 $action = 'create';
833 $donotclearsession = 1;
834 break;
835 }
836 }
837 }
838
839 // Modify $moreparam so we are sure to see the event we have just created, whatever are the default value of filter on next page.
840 /*$moreparam .= ($moreparam ? '&' : '').'search_actioncode=0';
841 $moreparam .= ($moreparam ? '&' : '').'search_status=-1';
842 $moreparam .= ($moreparam ? '&' : '').'search_filtert='.$object->userownerid;
843 */
844 $moreparam .= ($moreparam ? '&' : '').'disabledefaultvalues=1';
845 } else {
846 // If error
847 $error++;
848 $langs->load("errors");
849 $error = $langs->trans($finalobject->error);
850 setEventMessages($error, null, 'errors');
851 $action = 'create';
852 $donotclearsession = 1;
853 }
854 } else {
855 $error++;
856 setEventMessages($finalobject->error, $finalobject->errors, 'errors');
857 $action = 'create';
858 $donotclearsession = 1;
859 }
860
861 // If event is not recurrent, we stop here
862 if (!($userepeatevent && GETPOSTISSET('recurrulefreq') && GETPOST('recurrulefreq') != 'no' && GETPOSTISSET("limityear") && GETPOSTISSET("limitmonth") && GETPOSTISSET("limitday"))) {
863 break;
864 }
865
866 // increment date for recurrent events
867 $datep = dol_time_plus_duree($datep, $dayoffset, 'd');
868 $datep = dol_time_plus_duree($datep, $monthoffset, 'm'); // @phan-suppress-current-line PhanPluginSuspiciousParamOrder
869 $datep = dol_time_plus_duree($datep, $yearoffset, 'y'); // @phan-suppress-current-line PhanPluginSuspiciousParamOrder
870 $datef = dol_time_plus_duree($datef, $dayoffset, 'd');
871 $datef = dol_time_plus_duree($datef, $monthoffset, 'm'); // @phan-suppress-current-line PhanPluginSuspiciousParamOrder
872 $datef = dol_time_plus_duree($datef, $yearoffset, 'y'); // @phan-suppress-current-line PhanPluginSuspiciousParamOrder
873 }
874 }
875
876 if ($error) {
877 $db->rollback();
878 } else {
879 $db->commit();
880 }
881
882 if (!empty($backtopage) && !$error) {
883 dol_syslog("Back to ".$backtopage.($moreparam ? (preg_match('/\?/', $backtopage) ? '&'.$moreparam : '?'.$moreparam) : ''));
884 header("Location: ".$backtopage.($moreparam ? (preg_match('/\?/', $backtopage) ? '&'.$moreparam : '?'.$moreparam) : ''));
885 } elseif ($idaction) {
886 header("Location: ".DOL_URL_ROOT.'/comm/action/card.php?id='.$idaction.($moreparam ? '&'.$moreparam : ''));
887 } else {
888 header("Location: ".DOL_URL_ROOT.'/comm/action/index.php'.($moreparam ? '?'.$moreparam : ''));
889 }
890 exit;
891 }
892}
893
894// Action update event
895if (empty($reshook) && $action == 'update' && $usercancreate) {
896 if (empty($cancel)) {
897 $fulldayevent = GETPOST('fullday');
898 $aphour = GETPOSTINT('aphour');
899 $apmin = GETPOSTINT('apmin');
900 $p2hour = GETPOSTINT('p2hour');
901 $p2min = GETPOSTINT('p2min');
902 $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
903
904 // Clean parameters
905 if ($aphour == -1) {
906 $aphour = '0';
907 }
908 if ($apmin == -1) {
909 $apmin = '0';
910 }
911 if ($p2hour == -1) {
912 $p2hour = '0';
913 }
914 if ($p2min == -1) {
915 $p2min = '0';
916 }
917
918 $object->fetch($id);
919 $object->fetch_optionals();
920 $object->fetch_userassigned();
921 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
922
923 // Clean parameters
924 if ($fulldayevent) {
925 $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
926 // For "full day" events, we must store date in GMT (It must be viewed as same moment everywhere)
927 $datep = dol_mktime(0, 0, 0, GETPOSTINT("apmonth"), GETPOSTINT("apday"), GETPOSTINT("apyear"), $tzforfullday ? $tzforfullday : 'tzuserrel');
928 $datef = dol_mktime(23, 59, 59, GETPOSTINT("p2month"), GETPOSTINT("p2day"), GETPOSTINT("p2year"), $tzforfullday ? $tzforfullday : 'tzuserrel');
929 } else {
930 if (!GETPOSTISSET('ap') && !GETPOSTISSET('aphour') && !GETPOSTISSET('apmin')) { // If date fields are disabled, we keep old value
931 $datep = $object->datep;
932 } else {
933 $datep = dol_mktime(GETPOSTINT("aphour"), GETPOSTINT("apmin"), GETPOSTINT("apsec"), GETPOSTINT("apmonth"), GETPOSTINT("apday"), GETPOSTINT("apyear"), 'tzuserrel');
934 }
935 if (!GETPOSTISSET('p2') && !GETPOSTISSET('p2hour') && !GETPOSTISSET('p2min')) { // If date fields are disabled, we keep old value
936 $datef = $object->datef;
937 } else {
938 $datef = dol_mktime(GETPOSTINT("p2hour"), GETPOSTINT("p2min"), GETPOSTINT("apsec"), GETPOSTINT("p2month"), GETPOSTINT("p2day"), GETPOSTINT("p2year"), 'tzuserrel');
939 }
940 }
941
942 //set end date to now if percentage is set to 100 and end date not set
943 $datef = (!$datef && $percentage == 100) ? dol_now() : $datef;
944
945 if ($object->elementtype == 'ticket') { // code should be TICKET_MSG, TICKET_MSG_PRIVATE, TICKET_MSG_SENTBYMAIL, TICKET_MSG_PRIVATE_SENTBYMAIL
946 if ($private) {
947 if ($object->code == 'TICKET_MSG') {
948 $object->code = 'TICKET_MSG_PRIVATE';
949 }
950 if ($object->code == 'TICKET_MSG_SENTBYMAIL') {
951 $object->code = 'TICKET_MSG_PRIVATE_SENTBYMAIL';
952 }
953 } else {
954 if ($object->code == 'TICKET_MSG_PRIVATE') {
955 $object->code = 'TICKET_MSG';
956 }
957 if ($object->code == 'TICKET_MSG_PRIVATE_SENTBYMAIL') {
958 $object->code = 'TICKET_MSG_SENTBYMAIL';
959 }
960 }
961 // type_id and type_code is not modified
962 } else {
963 $object->type_id = dol_getIdFromCode($db, GETPOST("actioncode", 'aZ09'), 'c_actioncomm');
964 $object->type_code = GETPOST("actioncode", 'aZ09');
965 }
966
967 $object->label = GETPOST("label", "alphanohtml");
968 $object->datep = $datep;
969 $object->datef = $datef;
970 $object->percentage = $percentage;
971 $object->priority = GETPOSTINT("priority");
972 $object->fulldayevent = GETPOST("fullday") ? 1 : 0;
973 $object->location = GETPOST('location', "alphanohtml");
974 $object->socid = GETPOSTINT("socid");
975 $socpeopleassigned = GETPOST("socpeopleassigned", 'array');
976 $object->socpeopleassigned = [];
977 foreach ($socpeopleassigned as $cid) {
978 $object->socpeopleassigned[$cid] = array('id' => $cid);
979 }
980 $object->contact_id = GETPOSTINT("contactid");
981 if (empty($object->contact_id) && !empty($object->socpeopleassigned)) {
982 reset($object->socpeopleassigned);
983 $object->contact_id = key($object->socpeopleassigned);
984 }
985 $object->fk_project = GETPOSTINT("projectid");
986 $taskid = GETPOSTINT('taskid');
987 if (!empty($taskid)) {
988 $taskProject = new Task($db);
989 if ($taskProject->fetch($taskid) > 0) {
990 $object->fk_project = $taskProject->fk_project;
991 }
992
993 $object->fk_element = $taskid;
994 $object->elementid = $taskid;
995 $object->elementtype = 'project_task';
996 }
997
998 $object->note_private = trim(GETPOST("note", "restricthtml"));
999
1000 if (GETPOST("elementtype", 'alpha')) {
1001 $elProp = getElementProperties(GETPOST("elementtype", 'alpha'));
1002 $modulecodetouseforpermissioncheck = $elProp['module'];
1003 // Keep permission check aligned with rights class aliases (see restrictedArea()).
1004 if ($modulecodetouseforpermissioncheck == 'productbatch') {
1005 $modulecodetouseforpermissioncheck = 'produit';
1006 }
1007
1008 $hasPermissionOnLinkedObject = 0;
1009 if ($user->hasRight($modulecodetouseforpermissioncheck, 'read')) {
1010 $hasPermissionOnLinkedObject = 1;
1011 }
1012 if ($hasPermissionOnLinkedObject) {
1013 $object->fk_element = GETPOSTINT("fk_element");
1014 $object->elementid = GETPOSTINT("fk_element");
1015 $object->elementtype = GETPOST("elementtype", 'alpha');
1016 }
1017 }
1018
1019
1020 $transparency = (GETPOST("transparency") == 'on' ? 1 : 0);
1021
1022 // Users
1023 $listofuserid = [];
1024 if (!empty($_SESSION['assignedtouser'])) { // Now concat assigned users
1025 // Restore array with key with same value than param 'id'
1026 $tmplist1 = json_decode($_SESSION['assignedtouser'], true);
1027 foreach ($tmplist1 as $key => $val) {
1028 if ($val['id'] > 0 && $val['id'] != $assignedtouser) {
1029 $listofuserid[$val['id']] = $val;
1030 }
1031 }
1032 } else {
1033 $assignedtouser = (!empty($object->userownerid) && $object->userownerid > 0 ? $object->userownerid : 0);
1034 if ($assignedtouser) {
1035 $listofuserid[$assignedtouser] = array('id' => $assignedtouser, 'mandatory' => 0, 'transparency' => ($user->id == $assignedtouser ? $transparency : '')); // Owner first
1036 }
1037 }
1038 $object->userassigned = [];
1039 $object->userownerid = 0; // Clear old content
1040 $i = 0;
1041 foreach ($listofuserid as $key => $val) {
1042 if ($i == 0) {
1043 $object->userownerid = $val['id'];
1044 }
1045 $object->userassigned[$val['id']] = array('id' => $val['id'], 'mandatory' => 0, 'transparency' => ($user->id == $val['id'] ? $transparency : ''));
1046 $i++;
1047 }
1048
1049 $object->transparency = $transparency; // We set transparency on event (even if we can also store it on each user, standard says this property is for event)
1050 // TODO store also transparency on owner user
1051
1052 // Check parameters
1053 if (GETPOSTISSET('actioncode') && !GETPOST('actioncode', 'aZ09')) { // actioncode is '0'
1054 $error++;
1055 $donotclearsession = 1;
1056 $action = 'edit';
1057 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
1058 } else {
1059 $result = $cactioncomm->fetch(GETPOST('actioncode', 'aZ09'));
1060 }
1061 if (empty($object->userownerid)) {
1062 $error++;
1063 $donotclearsession = 1;
1064 $action = 'edit';
1065 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ActionsOwnedBy")), null, 'errors');
1066 }
1067
1068 // Fill array 'array_options' with data from add form
1069 $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
1070 if ($ret < 0) {
1071 $error++;
1072 }
1073
1074 if (!$error) {
1075 // check if an event resource is already in use
1076 if (getDolGlobalString('RESOURCE_USED_IN_EVENT_CHECK') && $object->element == 'action') {
1077 $eventDateStart = $object->datep;
1078 $eventDateEnd = $object->datef;
1079
1080 $sql = "SELECT er.rowid, r.ref as r_ref, ac.id as ac_id, ac.label as ac_label";
1081 $sql .= " FROM ".MAIN_DB_PREFIX."element_resources as er";
1082 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."resource as r ON r.rowid = er.resource_id AND er.resource_type = 'dolresource'";
1083 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm as ac ON ac.id = er.element_id AND er.element_type = '".$db->escape($object->element)."'";
1084 $sql .= " WHERE ac.id <> ".((int) $object->id);
1085 $sql .= " AND er.resource_id IN (";
1086 $sql .= " SELECT resource_id FROM ".MAIN_DB_PREFIX."element_resources";
1087 $sql .= " WHERE element_id = ".((int) $object->id);
1088 $sql .= " AND element_type = '".$db->escape($object->element)."'";
1089 $sql .= " AND busy = 1";
1090 $sql .= ")";
1091 $sql .= " AND er.busy = 1";
1092 $sql .= " AND (";
1093
1094 // event date start between ac.datep and ac.datep2 (if datep2 is null we consider there is no end)
1095 $sql .= " (ac.datep <= '".$db->idate($eventDateStart)."' AND (ac.datep2 IS NULL OR ac.datep2 >= '".$db->idate($eventDateStart)."'))";
1096 // event date end between ac.datep and ac.datep2
1097 if (!empty($eventDateEnd)) {
1098 $sql .= " OR (ac.datep <= '".$db->idate($eventDateEnd)."' AND (ac.datep2 >= '".$db->idate($eventDateEnd)."'))";
1099 }
1100 // event date start before ac.datep and event date end after ac.datep2
1101 $sql .= " OR (";
1102 $sql .= "ac.datep >= '".$db->idate($eventDateStart)."'";
1103 if (!empty($eventDateEnd)) {
1104 $sql .= " AND (ac.datep2 IS NOT NULL AND ac.datep2 <= '".$db->idate($eventDateEnd)."')";
1105 }
1106 $sql .= ")";
1107
1108 $sql .= ")";
1109 $resql = $db->query($sql);
1110 if (!$resql) {
1111 $error++;
1112 $object->error = $db->lasterror();
1113 $object->errors[] = $object->error;
1114 } else {
1115 if ($db->num_rows($resql) > 0) {
1116 // Resource already in use
1117 $error++;
1118 $object->error = $langs->trans('ErrorResourcesAlreadyInUse').' : ';
1119 while ($obj = $db->fetch_object($resql)) {
1120 $object->error .= '<br> - '.$langs->trans('ErrorResourceUseInEvent', $obj->r_ref, $obj->ac_label.' ['.$obj->ac_id.']');
1121 }
1122 $object->errors[] = $object->error;
1123 }
1124 $db->free($resql);
1125 }
1126
1127 if ($error) {
1128 setEventMessages($object->error, $object->errors, 'errors');
1129 }
1130 }
1131 }
1132
1133 if (!$error) {
1134 $db->begin();
1135
1136 $result = $object->update($user);
1137
1138 if ($result > 0) {
1139 // Category association
1140 $categories = GETPOST('categories', 'array');
1141 $object->setCategories($categories);
1142
1143 $object->loadReminders($remindertype, 0, false);
1144
1145 // If there is reminders, we remove them
1146 if (!empty($object->reminders)) {
1147 foreach ($object->reminders as $reminder) {
1148 if ($reminder->status < 1) { // If already sent, we never remove it
1149 $reminder->delete($user);
1150 }
1151 }
1152 $object->reminders = [];
1153 }
1154
1155 // Create reminders for every assigned user if reminder is on
1156 if ($addreminder == 'on') {
1157 $actionCommReminder = new ActionCommReminder($db);
1158
1159 $dateremind = dol_time_plus_duree($datep, -1 * $offsetvalue, $offsetunit);
1160
1161 $actionCommReminder->dateremind = $dateremind;
1162 $actionCommReminder->typeremind = $remindertype;
1163 $actionCommReminder->offsetunit = $offsetunit;
1164 $actionCommReminder->offsetvalue = $offsetvalue;
1165 $actionCommReminder->status = $actionCommReminder::STATUS_TODO;
1166 $actionCommReminder->fk_actioncomm = $object->id;
1167 if ($remindertype == 'email') {
1168 $actionCommReminder->fk_email_template = $modelmail;
1169 }
1170
1171 // the notification must be created for every user assigned to the event
1172 foreach ($object->userassigned as $userassigned) {
1173 $actionCommReminder->fk_user = $userassigned['id'];
1174
1175 // We update the event, so we recreate the notification event.
1176 // First we delete all reminders for the user and the type of reminding (all offset dates).
1177 $sqldelete = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_reminder";
1178 $sqldelete .= " WHERE fk_user = ".((int) $actionCommReminder->fk_user)." AND fk_actioncomm = ".((int) $object->id)." AND typeremind = '".$db->escape($remindertype)."'";
1179 $resqldelete = $db->query($sqldelete);
1180
1181 $res = $actionCommReminder->create($user);
1182
1183 if ($res <= 0) {
1184 // If error
1185 $langs->load("errors");
1186 $error = $langs->trans('ErrorReminderActionCommCreation');
1187 setEventMessages($error, null, 'errors');
1188 $action = 'create';
1189 $donotclearsession = 1;
1190 break;
1191 }
1192 }
1193 }
1194
1195 if (!$error) {
1196 unset($_SESSION['assignedtouser']);
1197 unset($_SESSION['assignedtoresource']);
1198
1199 $db->commit();
1200 } else {
1201 $db->rollback();
1202 $action = 'edit';
1203 }
1204 } else {
1205 setEventMessages($object->error, $object->errors, 'errors');
1206 $db->rollback();
1207 }
1208 }
1209 }
1210
1211 if (!$error) {
1212 if (!empty($backtopage)) {
1213 unset($_SESSION['assignedtouser']);
1214 header("Location: ".$backtopage);
1215 exit;
1216 }
1217 }
1218}
1219
1220// Delete event
1221if (empty($reshook) && $action == 'confirm_delete' && GETPOST("confirm") == 'yes' && $usercandelete) {
1222 $object->fetch($id);
1223 $object->fetch_optionals();
1224 $object->fetch_userassigned();
1225 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
1226
1227 $result = $object->delete($user);
1228
1229 if ($result >= 0) {
1230 header("Location: index.php");
1231 exit;
1232 } else {
1233 setEventMessages($object->error, $object->errors, 'errors');
1234 }
1235}
1236
1237/*
1238 * Action move update, used when user move an event in calendar by drag'n drop
1239 * TODO Move this into page comm/action/index that trigger this call by the drag and drop of event.
1240 */
1241if (empty($reshook) && GETPOST('actionmove', 'alpha') == 'mupdate' && $usercancreate) {
1242 $error = 0;
1243
1244 $shour = (int) dol_print_date($object->datep, "%H", 'tzuserrel'); // We take the date visible by user $newdate is also date visible by user.
1245 $smin = (int) dol_print_date($object->datep, "%M", 'tzuserrel');
1246
1247 $newdate = GETPOST('newdate', 'alpha');
1248 if (empty($newdate) || strpos($newdate, 'dayevent_') != 0) {
1249 header("Location: ".$backtopage, true, 307);
1250 exit;
1251 }
1252
1253 $datep = dol_mktime($shour, $smin, 0, (int) substr($newdate, 13, 2), (int) substr($newdate, 15, 2), (int) substr($newdate, 9, 4), 'tzuserrel');
1254 //print dol_print_date($datep, 'dayhour');exit;
1255
1256 if ($datep != $object->datep) {
1257 if (!empty($object->datef)) {
1258 $object->datef += $datep - $object->datep;
1259 }
1260 $object->datep = $datep;
1261
1262 if (!$error) {
1263 // check if an event resource is already in use
1264 if (getDolGlobalString('RESOURCE_USED_IN_EVENT_CHECK') && $object->element == 'action') {
1265 $eventDateStart = $object->datep;
1266 $eventDateEnd = $object->datef;
1267
1268 $sql = "SELECT er.rowid, r.ref as r_ref, ac.id as ac_id, ac.label as ac_label";
1269 $sql .= " FROM ".MAIN_DB_PREFIX."element_resources as er";
1270 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."resource as r ON r.rowid = er.resource_id AND er.resource_type = 'dolresource'";
1271 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm as ac ON ac.id = er.element_id AND er.element_type = '".$db->escape($object->element)."'";
1272 $sql .= " WHERE ac.id <> ".((int) $object->id);
1273 $sql .= " AND er.resource_id IN (";
1274 $sql .= " SELECT resource_id FROM ".MAIN_DB_PREFIX."element_resources";
1275 $sql .= " WHERE element_id = ".((int) $object->id);
1276 $sql .= " AND element_type = '".$db->escape($object->element)."'";
1277 $sql .= " AND busy = 1";
1278 $sql .= ")";
1279 $sql .= " AND er.busy = 1";
1280 $sql .= " AND (";
1281
1282 // event date start between ac.datep and ac.datep2 (if datep2 is null we consider there is no end)
1283 $sql .= " (ac.datep <= '".$db->idate($eventDateStart)."' AND (ac.datep2 IS NULL OR ac.datep2 >= '".$db->idate($eventDateStart)."'))";
1284 // event date end between ac.datep and ac.datep2
1285 if (!empty($eventDateEnd)) {
1286 $sql .= " OR (ac.datep <= '".$db->idate($eventDateEnd)."' AND (ac.datep2 >= '".$db->idate($eventDateEnd)."'))";
1287 }
1288 // event date start before ac.datep and event date end after ac.datep2
1289 $sql .= " OR (";
1290 $sql .= "ac.datep >= '".$db->idate($eventDateStart)."'";
1291 if (!empty($eventDateEnd)) {
1292 $sql .= " AND (ac.datep2 IS NOT NULL AND ac.datep2 <= '".$db->idate($eventDateEnd)."')";
1293 }
1294 $sql .= ")";
1295
1296 $sql .= ")";
1297 $resql = $db->query($sql);
1298 if (!$resql) {
1299 $error++;
1300 $object->error = $db->lasterror();
1301 $object->errors[] = $object->error;
1302 } else {
1303 if ($db->num_rows($resql) > 0) {
1304 // Resource already in use
1305 $error++;
1306 $object->error = $langs->trans('ErrorResourcesAlreadyInUse').' : ';
1307 while ($obj = $db->fetch_object($resql)) {
1308 $object->error .= '<br> - '.$langs->trans('ErrorResourceUseInEvent', $obj->r_ref, $obj->ac_label.' ['.$obj->ac_id.']');
1309 }
1310 $object->errors[] = $object->error;
1311 }
1312 $db->free($resql);
1313 }
1314
1315 if ($error) {
1316 setEventMessages($object->error, $object->errors, 'errors');
1317 }
1318 }
1319 }
1320
1321 if (!$error) {
1322 $db->begin();
1323 $result = $object->update($user);
1324 if ($result < 0) {
1325 $error++;
1326 setEventMessages($object->error, $object->errors, 'errors');
1327 $db->rollback();
1328 } else {
1329 $db->commit();
1330 }
1331 }
1332 }
1333 if (!empty($backtopage)) {
1334 header("Location: ".$backtopage, true, 307);
1335 exit;
1336 } else {
1337 $action = '';
1338 }
1339}
1340
1341// Actions to delete doc
1342$upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($object->ref);
1343$permissiontoadd = ($user->hasRight('agenda', 'allactions', 'create') || (($object->authorid == $user->id || $object->userownerid == $user->id) && $user->hasRight('agenda', 'myactions', 'read')));
1344if (empty($reshook)) {
1345 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
1346}
1347
1348
1349/*
1350 * View
1351 */
1352
1353$form = new Form($db);
1354$formproject = new FormProjets($db);
1355
1356$arrayrecurrulefreq = array(
1357 'no' => $langs->trans("OnceOnly"),
1358 'YEARLY' => $langs->trans("EveryYear"),
1359 'MONTHLY' => $langs->trans("EveryMonth"),
1360 'WEEKLY' => $langs->trans("EveryWeek")
1361 // 'DAILY'=>$langs->trans("EveryDay")
1362);
1363
1364
1365$help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&omodulodulo_Agenda|DE:Modul_Terminplanung';
1366llxHeader('', $langs->trans("Agenda"), $help_url);
1367
1368if ($action == 'create') {
1369 $contact = new Contact($db);
1370
1371 $socpeopleassigned = GETPOST("socpeopleassigned", 'array');
1372 if (!empty($socpeopleassigned[0])) {
1373 $result = $contact->fetch($socpeopleassigned[0]);
1374 if ($result < 0) {
1375 dol_print_error($db, $contact->error);
1376 }
1377 }
1378
1379 dol_set_focus("#label");
1380
1381 if (!empty($conf->use_javascript_ajax)) {
1382 print "\n".'<script type="text/javascript">';
1383 print '$(document).ready(function () {
1384 function setdatefields()
1385 {
1386 if ($("#fullday:checked").val() == null) {
1387 $(".fulldaystarthour").removeAttr("disabled");
1388 $(".fulldaystartmin").removeAttr("disabled");
1389 $(".fulldayendhour").removeAttr("disabled");
1390 $(".fulldayendmin").removeAttr("disabled");
1391 $("#p2").removeAttr("disabled");
1392 } else {
1393 $(".fulldaystarthour").prop("disabled", true).val("00");
1394 $(".fulldaystartmin").prop("disabled", true).val("00");
1395 $(".fulldayendhour").prop("disabled", true).val("23");
1396 $(".fulldayendmin").prop("disabled", true).val("59");
1397 $("#p2").removeAttr("disabled");
1398 }
1399 }
1400 $("#fullday").change(function() {
1401 console.log("setdatefields");
1402 setdatefields();
1403 });
1404 var old_startdate = null;
1405 $("#ap").focus(function() {
1406 old_startdate = new Date($("#apyear").val(), $("#apmonth").val() - 1, $("#apday").val());
1407 });
1408 $("#ap").next(".ui-datepicker-trigger").click(function() {
1409 old_startdate = new Date($("#apyear").val(), $("#apmonth").val() - 1, $("#apday").val());
1410 });
1411 $("#ap").change(function() {
1412 setTimeout(function() {
1413 if ($("#p2").val() !== "") {
1414 var new_startdate = new Date($("#apyear").val(), $("#apmonth").val() - 1, $("#apday").val());
1415 var old_enddate = new Date($("#p2year").val(), $("#p2month").val() - 1, $("#p2day").val());
1416 if (new_startdate > old_enddate) {
1417 var timeDiff = old_enddate - old_startdate;
1418 var new_enddate = new Date(new_startdate.getTime() + timeDiff);
1419 $("#p2").val(formatDate(new_enddate, "' . $langs->trans('FormatDateShortJavaInput') . '"));
1420 $("#p2day").val(new_enddate.getDate());
1421 $("#p2month").val(new_enddate.getMonth() + 1);
1422 $("#p2year").val(new_enddate.getFullYear());
1423 }
1424 }
1425 }, 0);
1426 });
1427 $("#actioncode").change(function() {
1428 if ($("#actioncode").val() == \'AC_RDV\') $("#dateend").addClass("fieldrequired");
1429 else $("#dateend").removeClass("fieldrequired");
1430 });
1431 $("#aphour,#apmin").change(function() {
1432 if ($("#actioncode").val() == \'AC_RDV\') {
1433 var oldhour = parseInt($("#aphour").val());
1434 var oldmin = parseInt($("#apmin").val());
1435 var oldday = parseInt($("#apday").val());
1436 var oldmonth = $("#apmonth").val();
1437 var oldyear = $("#apyear").val();
1438
1439 var newhour = oldhour + 1;
1440 var newday = oldday;
1441 var newmonth = oldmonth;
1442 var newyear = oldyear;
1443 if (newhour >= 24) {
1444 newhour = 0;
1445 newday = oldday + 1;
1446 }
1447 console.log("Start date was changed, we modify end date "+oldhour+" "+oldmin+" -> "+newhour+" "+oldmin);
1448 $("#p2hour").val(("00" + newhour).substr(-2,2));
1449 $("#p2min").val(("00" + oldmin).substr(-2,2));
1450 $("#p2day").val(newday);
1451 $("#p2month").val(newmonth);
1452 $("#p2year").val(newyear);
1453 $("#p2").val($("#ap").val());
1454 }
1455 });
1456 if ($("#actioncode").val() == \'AC_RDV\') $("#dateend").addClass("fieldrequired");
1457 else $("#dateend").removeClass("fieldrequired");
1458 setdatefields();
1459 })';
1460 print '</script>'."\n";
1461 }
1462
1463 print '<form name="formaction" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
1464 print '<input type="hidden" name="token" value="'.newToken().'">';
1465 print '<input type="hidden" name="action" value="add">';
1466 print '<input type="hidden" name="donotclearsession" value="1">';
1467 print '<input type="hidden" name="page_y" value="">';
1468 if ($backtopage) {
1469 print '<input type="hidden" name="backtopage" value="'.($backtopage != '1' ? $backtopage : '').'">';
1470 }
1471 if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
1472 print '<input type="hidden" name="actioncode" value="'.dol_getIdFromCode($db, 'AC_OTH', 'c_actioncomm').'">';
1473 }
1474
1475 print load_fiche_titre($langs->trans("AddAnAction"), '', 'title_agenda');
1476
1477 print dol_get_fiche_head();
1478
1479 print '<div class="divcreate">';
1480 print '<table class="border centpercent nobottom">';
1481
1482 // Title
1483 print '<tr><td'.(getDolGlobalString('AGENDA_USE_EVENT_TYPE') ? ' class="fieldrequired"' : ' class="fieldrequired titlefieldcreate"').'>'.$langs->trans("Title").'</td><td><input type="text" id="label" name="label" class="soixantepercent" value="'.GETPOST('label').'"></td></tr>';
1484
1485 // Type of event
1486 if (getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
1487 print '<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans("Type").'</span></b></td><td>';
1488 $default = getDolGlobalString('AGENDA_USE_EVENT_TYPE_DEFAULT', 'AC_RDV');
1489 print img_picto($langs->trans("ActionType"), 'square', 'class="fawidth30 inline-block" style="color: #ddd;"');
1490 $selectedvalue = GETPOSTISSET("actioncode") ? GETPOST("actioncode", 'aZ09') : ($object->type_code ? $object->type_code : $default);
1491 print $formactions->select_type_actions($selectedvalue, "actioncode", "systemauto", 0, -1, 0, 1); // TODO Replace 0 with -2 in onlyautoornot
1492 print '</td></tr>';
1493 }
1494
1495 // Full day
1496 print '<tr><td><span class="fieldrequired">'.$langs->trans("Date").'</span></td>';
1497 print '<td class="valignmiddle height30">';
1498 print '<div>';
1499 print '<input class="valignmiddle" type="checkbox" id="fullday" name="fullday" '.(GETPOST('fullday') ? ' checked' : '').'><label for="fullday" class="valignmiddle small">'.$langs->trans("EventOnFullDay").'</label>';
1500 print '</div>';
1501 print '</td></tr>';
1502
1503 $datep = ($datep ? $datep : (is_null($object->datep) ? '' : $object->datep));
1504 if (GETPOST('datep', 'alpha', 1)) {
1505 $datep = dol_stringtotime(GETPOST('datep', 'alpha', 1), 'tzuserrel');
1506 }
1507 $datef = ($datef ? $datef : $object->datef);
1508 if (GETPOST('datef', 'alpha', 1)) {
1509 $datef = dol_stringtotime(GETPOST('datef', 'alpha', 1), 'tzuserrel');
1510 }
1511 if (empty($datef) && !empty($datep)) {
1512 if (GETPOST("actioncode", 'aZ09') == 'AC_RDV' || (!getDolGlobalString('AGENDA_USE_EVENT_TYPE_DEFAULT') || getDolGlobalString('AGENDA_USE_EVENT_TYPE_DEFAULT') == '-1')) {
1513 $datef = dol_time_plus_duree($datep, getDolGlobalInt('AGENDA_AUTOSET_END_DATE_WITH_DELTA_HOURS', 1), 'h');
1514 }
1515 }
1516
1517 // Date start
1518 print '<tr><td class="nowrap">';
1519 print '</td><td>';
1520 print '<div class="inline-block">';
1521 if (GETPOST("afaire") == 1) {
1522 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"
1523 } else {
1524 print $form->selectDate($datep, 'ap', 1, 1, 1, "action", 1, 2, 0, 'fulldaystart', '', '', '', 1, '', '', 'tzuserrel');
1525 }
1526 print ' <span class="hideonsmartphone">&nbsp; &nbsp; - &nbsp; &nbsp;</span><br class="showonsmartphone"> ';
1527 print $form->selectDate($datef, 'p2', 1, 1, 1, "action", 1, 0, 0, 'fulldayend', '', '', '', 1, '', '', 'tzuserrel');
1528 print '</div>';
1529
1530 //print '</td></tr>';
1531
1532 // Recurring event
1533 $userepeatevent = (getDolGlobalInt('MAIN_DISABLE_RECURRING_EVENTS') ? 0 : 1);
1534 if ($userepeatevent) {
1535 //print '<tr><td></td><td>';
1536 print '<div class="clearbothonsmartphone hideonsmartphone inline-block"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>';
1537
1538 // Repeat
1539 print '<div class="inline-block small" data-html="repeat">';
1540 print '<span class="opacitymedium">';
1541 print img_picto($langs->trans("Recurrence"), 'recurring', 'style="margin-left: 3px" class="paddingright"');
1542 print '<input type="hidden" name="recurid" value="'.(empty($object->recurid) ? '' : $object->recurid).'">';
1543
1544 $selectedrecurrulefreq = 'no';
1545 $selectedrecurrulebyyearmonthday = '';
1546 $selectedrecurrulebymonthday = '';
1547 $selectedrecurrulebyday = '';
1548 $object->recurrule = GETPOSTISSET('recurrulefreq') ? "FREQ=".GETPOST('recurrulefreq', 'alpha') : "";
1549 $object->recurrule .= GETPOSTISSET('BYYEARMONTHDAY') ? "_BYYEARMONTHDAY".GETPOST('BYYEARMONTHDAY', 'alpha') : "";
1550 $object->recurrule .= GETPOSTISSET('BYMONTHDAY') ? "_BYMONTHDAY".GETPOST('BYMONTHDAY', 'alpha') : "";
1551 $object->recurrule .= GETPOSTISSET('BYDAY') ? "_BYDAY".GETPOST('BYDAY', 'alpha') : "";
1552
1553
1554 $reg = [];
1555 if ($object->recurrule && preg_match('/FREQ=([A-Z]+)/i', $object->recurrule, $reg)) {
1556 $selectedrecurrulefreq = $reg[1];
1557 }
1558 if ($object->recurrule && preg_match('/FREQ=YEARLY.*BYYEARMONTHDAY(\d+)/i', $object->recurrule, $reg)) {
1559 $selectedrecurrulebyyearmonthday = (int) $reg[1];
1560 }
1561 if ($object->recurrule && preg_match('/FREQ=MONTHLY.*BYMONTHDAY(\d+)/i', $object->recurrule, $reg)) {
1562 $selectedrecurrulebymonthday = (int) $reg[1];
1563 }
1564 if ($object->recurrule && preg_match('/FREQ=WEEKLY.*BYDAY(\d+)/i', $object->recurrule, $reg)) {
1565 $selectedrecurrulebyday = (int) $reg[1];
1566 }
1567
1568 print $form->selectarray('recurrulefreq', $arrayrecurrulefreq, $selectedrecurrulefreq, 0, 0, 0, '', 0, 0, 0, '', 'marginrightonly minwidth125 maxwidth150');
1569 print '</span>';
1570 // print '<script>console.log("recurrule: " +'.$object->recurrule.')</script>';
1571 // For recursive event
1572
1573
1574 // If recurrulefreq is MONTHLY
1575 /*
1576 print '<div class="hidden marginrightonly inline-block repeateventBYMONTHDAY">';
1577 print $langs->trans("DayOfMonth").': <input type="input" size="2" name="BYMONTHDAY" value="'.$selectedrecurrulebymonthday.'">';
1578 print '</div>';
1579 // If recurrulefreq is WEEKLY
1580 print '<div class="hidden marginrightonly inline-block repeateventBYDAY">';
1581 print $langs->trans("DayOfWeek").': <input type="input" size="4" name="BYDAY" value="'.$selectedrecurrulebyday.'">';
1582 print '</div>';
1583 */
1584
1585 // limit date
1586 $repeateventlimitdate = empty($repeateventlimitdate) ? (dol_now() + ((24 * 3600 * 365) + 1)) : $repeateventlimitdate;
1587
1588 print '<div class="hidden marginrightonly inline-block repeateventlimitdate">';
1589 print $langs->trans("Until")." ";
1590 print $form->selectDate($repeateventlimitdate, 'limit', 0, 0, 0, "action", 1, 0, 0, '', '', '', '', 1, '', '', 'tzuserrel');
1591 print '</div>';
1592 ?>
1593 <script type="text/javascript">
1594 jQuery(document).ready(function() {
1595 function init_repeat() {
1596 console.log("recurrule: " + "<?php echo $object->recurrule; ?>");
1597 console.log("reg1: " + "<?php echo $selectedrecurrulefreq; ?>");
1598 console.log("reg2: " + "<?php echo $selectedrecurrulebymonthday; ?>");
1599 console.log("reg3: " + "<?php echo $selectedrecurrulebyday; ?>");
1600 console.log("reg4: " + "<?php echo $selectedrecurrulebyyearmonthday; ?>");
1601 console.log("selectedrulefreq: " + "<?php echo $selectedrecurrulefreq; ?>");
1602 if (jQuery("#recurrulefreq").val() == 'YEARLY') {
1603 /* jQuery(".repeateventBYYEARMONTHDAY").css("display", "inline-block"); */ /* use this instead of show because we want inline-block and not block */
1604 jQuery(".repeateventlimitdate").css("display", "inline-block");
1605 jQuery(".repeateventBYMONTHDAY").hide();
1606 jQuery(".repeateventBYDAY").hide();
1607 } else if (jQuery("#recurrulefreq").val() == 'MONTHLY') {
1608 /* jQuery(".repeateventBYMONTHDAY").css("display", "inline-block"); */ /* use this instead of show because we want inline-block and not block */
1609 jQuery(".repeateventlimitdate").css("display", "inline-block");
1610 jQuery(".repeateventBYYEARMONTHDAY").hide();
1611 jQuery(".repeateventBYDAY").hide();
1612 } else if (jQuery("#recurrulefreq").val() == 'WEEKLY') {
1613 jQuery(".repeateventBYYEARMONTHDAY").hide();
1614 jQuery(".repeateventBYMONTHDAY").hide();
1615 /* jQuery(".repeateventBYDAY").css("display", "inline-block"); */ /* use this instead of show because we want inline-block and not block */
1616 jQuery(".repeateventlimitdate").css("display", "inline-block");
1617 } else {
1618 jQuery(".repeateventBYYEARMONTHDAY").hide();
1619 jQuery(".repeateventBYMONTHDAY").hide();
1620 jQuery(".repeateventBYDAY").hide();
1621 jQuery(".repeateventlimitdate").hide();
1622 }
1623 }
1624 init_repeat();
1625 jQuery("#recurrulefreq").change(function() {
1626 init_repeat();
1627 });
1628 });
1629 </script>
1630 <?php
1631 print '</div>';
1632 // print '</td></tr>';
1633 }
1634
1635 print '</td></tr>';
1636
1637
1638 // Location
1639 if (!getDolGlobalString('AGENDA_DISABLE_LOCATION')) {
1640 print '<tr><td class="titlefieldcreate">'.$langs->trans("Location").'</td><td>';
1641 print img_picto('', 'map-marker-alt', 'class="pictofixedwidth"');
1642 print '<input type="text" name="location" class="minwidth300 maxwidth150onsmartphone" value="'.(GETPOST('location') ? GETPOST('location') : $object->location).'"></td></tr>';
1643 }
1644
1645 print '</table>';
1646 print '</div>';
1647
1648 print '<br>';
1649
1650 print '<div class="divcreate">';
1651 print '<table class="border centpercent nobottom">';
1652
1653 // Assigned to user
1654 print '<tr><td class="nowrap titlefieldcreate"><span>';
1655 print $langs->trans("AssignedTo");
1656 print '</span></td><td>';
1657 $listofuserid = [];
1658 $listofcontactid = [];
1659 $listofotherid = [];
1660
1661 if (empty($donotclearsession)) {
1662 $assignedtouser = GETPOST("assignedtouser") ? GETPOST("assignedtouser") : (!empty($object->userownerid) && $object->userownerid > 0 ? $object->userownerid : $user->id);
1663 if ($assignedtouser) {
1664 $listofuserid[$assignedtouser] = array('id' => $assignedtouser, 'mandatory' => 0); // Owner first
1665 }
1666 //$listofuserid[$user->id] = array('id'=>$user->id, 'mandatory'=>0, 'transparency'=>(GETPOSTISSET('transparency') ? GETPOST('transparency', 'alpha') : 1)); // 1 by default at first init
1667 $listofuserid[$assignedtouser]['transparency'] = (GETPOSTISSET('transparency') ? GETPOST('transparency', 'alpha') : 1); // 1 by default at first init
1668 $_SESSION['assignedtouser'] = json_encode($listofuserid);
1669 } else {
1670 if (!empty($_SESSION['assignedtouser'])) {
1671 $listofuserid = json_decode($_SESSION['assignedtouser'], true);
1672 }
1673 if (!is_array($listofuserid)) {
1674 $listofuserid = [];
1675 }
1676 $firstelem = reset($listofuserid);
1677 if (isset($listofuserid[$firstelem['id']])) {
1678 $listofuserid[$firstelem['id']]['transparency'] = (GETPOSTISSET('transparency') ? GETPOST('transparency', 'alpha') : 0); // 0 by default when refreshing
1679 }
1680 }
1681 print '<!-- list of user to assign -->'."\n";
1682 print '<div class="assignedtouser">';
1683 print $form->select_dolusers_forevent(($action == 'create' ? 'add' : 'update'), 'assignedtouser', 1, [], 0, '', [], '0', 0, 0, 'u.statut:<>:0', 1, $listofuserid, $listofcontactid, $listofotherid);
1684 print '</div>';
1685 print '</td></tr>';
1686
1687 if (isModEnabled('resource')) {
1688 // Resources
1689 print '<tr><td class="tdtop nowrap">'.$langs->trans("Resource").'</td><td>';
1690
1691 $listofresourceid = [];
1692 if (empty($donotclearsession)) {
1693 $assignedtoresource = GETPOST("assignedtoresource");
1694 if ($assignedtoresource) {
1695 $listofresourceid[$assignedtoresource] = array('id' => $assignedtoresource, 'mandatory' => 0); // Owner first
1696 }
1697 $_SESSION['assignedtoresource'] = json_encode($listofresourceid);
1698 } else {
1699 if (!empty($_SESSION['assignedtoresource'])) {
1700 $listofresourceid = json_decode($_SESSION['assignedtoresource'], true);
1701 }
1702 if (!is_array($listofresourceid)) {
1703 $listofresourceid = [];
1704 }
1705 $firstelem = reset($listofresourceid);
1706 if ($firstelem && isset($listofresourceid[$firstelem['id']])) {
1707 $listofresourceid[$firstelem['id']]['transparency'] = (GETPOSTISSET('transparency') ? GETPOST('transparency', 'alpha') : 0); // 0 by default when refreshing
1708 }
1709 }
1710 print '<div class="assignedtoresource">';
1711 print $form->select_dolresources_forevent(($action == 'create' ? 'add' : 'update'), 'assignedtoresource', 1, [], 0, '', [], '0', 0, 0, 'AND u.statut != 0', 1, $listofresourceid);
1712 print '</div>';
1713 print '</td></tr>';
1714 }
1715
1716 if (isModEnabled('category')) {
1717 // Categories
1718 print '<tr><td>'.$langs->trans("Categories").'</td><td>';
1719 print $form->selectCategories(Categorie::TYPE_ACTIONCOMM, 'categories', $object);
1720 print "</td></tr>";
1721 }
1722
1723 print '</table>';
1724 print '</div>';
1725
1726
1727 print '<br>';
1728
1729 print '<div class="divcreate">';
1730 print '<table class="border centpercent nobottom">';
1731
1732 // Status
1733 print '<tr><td>'.$langs->trans("Status").' / '.$langs->trans("Progression").'</td>';
1734 print '<td>';
1735 $percent = $complete !== '' ? $complete : -1;
1736 if (GETPOSTISSET('status')) {
1737 $percent = GETPOST('status');
1738 } elseif (GETPOSTISSET('percentage')) {
1739 $percent = GETPOSTINT('percentage');
1740 } else {
1741 if ($complete == '0' || GETPOST("afaire") == 1) {
1742 $percent = '0';
1743 } elseif ($complete == 100 || GETPOST("afaire") == 2) {
1744 $percent = 100;
1745 }
1746 }
1747 print $formactions->form_select_status_action('formaction', $percent, 1, 'complete', 0, 0, 'minwidth150 maxwidth300', 1);
1748 print '</td></tr>';
1749
1750 if (isModEnabled("societe")) {
1751 // Related company
1752 print '<tr><td class="titlefieldcreate nowrap">'.$langs->trans("ActionOnCompany").'</td><td>';
1753 if (GETPOSTINT('socid') > 0) {
1754 $societe = new Societe($db);
1755 $societe->fetch(GETPOSTINT('socid'));
1756 print $societe->getNomUrl(1);
1757 print '<input type="hidden" id="socid" name="socid" value="'.GETPOSTINT('socid').'">';
1758 } else {
1759 $events = [];
1760 $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1&token='.currentToken(), 1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
1761 //For external user force the company to user company
1762 if (!empty($user->socid)) {
1763 print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company($user->socid, 'socid', '', 1, 1, 0, $events, 0, 'minwidth300 widthcentpercentminusxx maxwidth500');
1764 } else {
1765 print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company('', 'socid', '', $langs->trans('SelectThirdParty'), 1, 0, $events, 0, 'minwidth300 widthcentpercentminusxx maxwidth500');
1766 }
1767 }
1768 print '</td></tr>';
1769
1770 // Related contact
1771 print '<tr><td class="nowrap">'.$langs->trans("ActionOnContact").'</td><td>';
1772 $preselectedids = GETPOST('socpeopleassigned', 'array:int');
1773 if (GETPOSTINT('contactid')) {
1774 $preselectedids[GETPOSTINT('contactid')] = GETPOSTINT('contactid');
1775 }
1776 if ($origin == 'contact') {
1777 $preselectedids[GETPOSTINT('originid')] = GETPOSTINT('originid');
1778 }
1779 // select "all" or "none" contact by default
1780 if (getDolGlobalInt('MAIN_ACTIONCOM_CAN_ADD_ANY_CONTACT')) {
1781 // Warning: MAIN_ACTIONCOM_CAN_ADD_ANY_CONTACT will hangs on large databases
1782 $select_contact_default = 0; // select "all" contacts by default : avoid to use it if there is a lot of contacts
1783 } else {
1784 $select_contact_default = -1; // select "none" by default
1785 }
1786 print img_picto('', 'contact', 'class="pictofixedwidth"');
1787
1788 if (getDolGlobalString('CONTACT_USE_SEARCH_TO_SELECT') && $conf->use_javascript_ajax) {
1789 // FIXME Use a select without the "multiple" (not supported when CONTACT_USE_SEARCH_TO_SELECT is on) or allow use only when $object->socid is set...
1790 /*
1791 $selected = array_keys($object->socpeopleassigned);
1792 print $form->select_contact(getDolGlobalString('MAIN_ACTIONCOM_CAN_ADD_ANY_CONTACT') ? 0 : $object->socid, $selected, 'socpeopleassigned', 1, '', '', 1, 'minwidth300 widthcentpercentminusx', false, 0, 0, []);
1793 */
1794 $sav = getDolGlobalString('CONTACT_USE_SEARCH_TO_SELECT');
1795 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = 0;
1796 print $form->selectcontacts(GETPOSTISSET('socid') ? GETPOSTINT('socid') : $select_contact_default, $preselectedids, 'socpeopleassigned[]', 1, '', '', 0, 'minwidth300 widthcentpercentminusxx maxwidth500', 0, 0, 0, [], 'multiple', 'contactid');
1797 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = $sav;
1798 } else {
1799 print $form->selectcontacts(GETPOSTISSET('socid') ? GETPOSTINT('socid') : $select_contact_default, $preselectedids, 'socpeopleassigned[]', 1, '', '', 0, 'minwidth300 widthcentpercentminusxx maxwidth500', 0, 0, 0, [], 'multiple', 'contactid');
1800 }
1801
1802 print '</td></tr>';
1803 }
1804
1805 // Project
1806 if (isModEnabled('project')) {
1807 $langs->load("projects");
1808
1809 $projectid = GETPOSTINT('projectid');
1810
1811 print '<tr><td class="titlefieldcreate">'.$langs->trans("Project").'</td><td id="project-input-container">';
1812 print img_picto('', 'project', 'class="pictofixedwidth"');
1813 print $formproject->select_projects(($object->socid > 0 ? $object->socid : -1), (string) $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx maxwidth500');
1814
1815 print '&nbsp;<a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.(empty($societe->id) ? '' : $societe->id).'&action=create&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create').'">';
1816 print '<span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddProject").'"></span></a>';
1817 $urloption = '?action=create&donotclearsession=1';
1818 $url = dol_buildpath('comm/action/card.php', 2).$urloption;
1819
1820 // update task list
1821 ?>
1822 <script type="text/javascript">
1823 $(document).ready(function () {
1824 $("#projectid").change(function () {
1825 var url = "<?php echo DOL_URL_ROOT; ?>/projet/ajax/projects.php?mode=gettasks&socid="+$("#search_socid").val()+"&projectid="+$("#projectid").val();
1826 console.log("Call url to get the new list of tasks: "+url);
1827 $.get(url, function(data) {
1828 console.log(data);
1829 if (data) $("#taskid").html(data).select2();
1830 })
1831 });
1832 });
1833 </script>
1834 <?php
1835
1836 print '</td></tr>';
1837
1838 // Task
1839 print '<tr><td class="titlefieldcreate">'.$langs->trans("Task").'</td><td id="project-task-input-container" >';
1840 print img_picto('', 'projecttask', 'class="pictofixedwidth"');
1841 $projectsListId = '';
1842 if (!empty($projectid)) {
1843 $projectsListId = $projectid;
1844 }
1845
1846 $tid = GETPOSTISSET("projecttaskid") ? GETPOSTINT("projecttaskid") : (GETPOSTISSET("taskid") ? GETPOSTINT("taskid") : '');
1847
1848 if (empty($projectsListId)) {
1849 print '<select class="valignmiddle flat maxwidth500 widthcentpercentminusxx minwidth150imp" id="taskid" name="taskid">';
1850 print '<option class="opacitymedium">&nbsp;</option>';
1851 print '<option class="opacitymedium" disabled data-html="'.dolPrintHTMLForAttribute($langs->trans("SelectAProjectFirst")).'">'.$langs->trans("SelectAProjectFirst").'</option>';
1852 print '</select>';
1853 print ajax_combobox('taskid');
1854 } else {
1855 print $formproject->selectTasks((!empty($societe->id) ? $societe->id : -1), $tid, 'taskid', 64, 0, '1', 1, 0, 0, 'maxwidth500 widthcentpercentminusxx', (string) $projectsListId, 'all', null, 1);
1856 }
1857 print '</td></tr>';
1858 }
1859
1860 // Object linked
1861 if (!empty($origin) && !empty($originid)) {
1862 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1863
1864 $hasPermissionOnLinkedObject = 0;
1865
1866 $elProp = getElementProperties($origin);
1867 $modulecodetouseforpermissioncheck = $elProp['module'];
1868 // Keep permission check aligned with rights class aliases (see restrictedArea()).
1869 if ($modulecodetouseforpermissioncheck == 'productbatch') {
1870 $modulecodetouseforpermissioncheck = 'produit';
1871 }
1872 if ($user->hasRight($modulecodetouseforpermissioncheck, 'read') || $user->hasRight($modulecodetouseforpermissioncheck, $elProp['element'], 'read')) {
1873 $hasPermissionOnLinkedObject = 1;
1874 }
1875 //var_dump('origin='.$origin.' originid='.$originid.' hasPermissionOnLinkedObject='.$hasPermissionOnLinkedObject);
1876
1877 if (! in_array($origin, array('societe', 'project', 'project_task', 'user'))) {
1878 // We do not use link for object that already contains a hard coded field to make links with agenda events
1879 print '<tr><td class="titlefieldcreate">'.$langs->trans("LinkedObject").'</td>';
1880 print '<td colspan="3">';
1881 if ($hasPermissionOnLinkedObject) {
1882 print dolGetElementUrl($originid, $origin, 1);
1883 print '<input type="hidden" name="fk_element" value="'.$originid.'">';
1884 print '<input type="hidden" name="elementtype" value="'.$origin.'">';
1885 print '<input type="hidden" name="originid" value="'.$originid.'">';
1886 print '<input type="hidden" name="origin" value="'.$origin.'">';
1887 } else {
1888 print '<!-- no permission on object to link '.$origin.' id '.$originid.' -->';
1889 }
1890 print '</td></tr>';
1891 }
1892 }
1893
1894 // Priority
1895 if (getDolGlobalString('AGENDA_SUPPORT_PRIORITY_IN_EVENTS')) {
1896 print '<tr><td class="titlefieldcreate nowrap">'.$langs->trans("Priority").'</td><td colspan="3">';
1897 print '<input type="text" name="priority" value="'.(GETPOSTISSET('priority') ? GETPOSTINT('priority') : ($object->priority ? $object->priority : '')).'" size="5">';
1898 print '</td></tr>';
1899 }
1900
1901 // Description
1902 print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
1903 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1904 $doleditor = new DolEditor('note', (GETPOSTISSET('note') ? GETPOST('note', 'restricthtml') : $object->note_private), '', 100, 'dolibarr_notes', 'In', true, true, isModEnabled('fckeditor'), ROWS_4, '90%');
1905 $doleditor->Create();
1906 print '</td></tr>';
1907
1908 // Other attributes
1909 $parameters = [];
1910 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1911 print $hookmanager->resPrint;
1912 if (empty($reshook)) {
1913 print $object->showOptionals($extrafields, 'create', $parameters);
1914 }
1915
1916 print '</table>';
1917 print '</div>';
1918
1919 if ($enablereminders) {
1920 //checkbox create reminder
1921 print '<hr>';
1922
1923 print '<label for="addreminder">'.img_picto('', 'bell', 'class="pictofixedwidth"').$langs->trans("AddReminder").'</label> <input type="checkbox" id="addreminder" name="addreminder"'.(empty(GETPOST('addreminder')) ? '' : 'checked').'><br>';
1924
1925 print '<div class="reminderparameters" '.(empty(GETPOST('addreminder')) ? 'style="display: none;' : '').' ">';
1926 print '<br>';
1927
1928 print '<table class="border centpercent">';
1929
1930 //Reminder
1931 print '<tr><td class="titlefieldcreate nowrap">'.$langs->trans("ReminderTime").'</td><td colspan="3">';
1932 print '<input class="width50" type="number" name="offsetvalue" value="'.(GETPOSTISSET('offsetvalue') ? GETPOSTINT('offsetvalue') : getDolGlobalInt('AGENDA_REMINDER_DEFAULT_OFFSET', 30)).'"> ';
1933
1934 print $form->selectTypeDuration('offsetunit', (empty($offsetunit) ? 'i' : $offsetunit), $TDurationTypesExcluded);
1935 print '</td></tr>';
1936
1937 //Reminder Type
1938 print '<tr><td class="titlefieldcreate nowrap">'.$langs->trans("ReminderType").'</td><td colspan="3">';
1939 print $form->selectarray('selectremindertype', $TRemindTypes, '', 0, 0, 0, '', 0, 0, 0, '', 'minwidth200 maxwidth500', 1);
1940 print '</td></tr>';
1941
1942 //Mail Model
1943 if (getDolGlobalString('AGENDA_REMINDER_EMAIL')) {
1944 print '<tr><td class="titlefieldcreate nowrap">'.$langs->trans("EMailTemplates").'</td><td colspan="3">';
1945 print $form->selectModelMail('actioncommsend', 'actioncomm_send', 1, 1, (empty($modelmail) ? 0 : $modelmail));
1946 print '</td></tr>';
1947 }
1948
1949 print '</table>';
1950 print '</div>';
1951
1952 $reminderDefaultEventTypes = getDolGlobalString('AGENDA_DEFAULT_REMINDER_EVENT_TYPES', '');
1953 $reminderDefaultOffset = getDolGlobalInt('AGENDA_DEFAULT_REMINDER_OFFSET', 30);
1954 $reminderDefaultUnit = getDolGlobalString('AGENDA_DEFAULT_REMINDER_OFFSET_UNIT');
1955 $reminderDefaultEmailModel = getDolGlobalInt('AGENDA_DEFAULT_REMINDER_EMAIL_MODEL');
1956
1957 print "\n".'<script type="text/javascript">';
1958 print '$(document).ready(function () {
1959 const reminderDefaultEventTypes = \''.dol_escape_js($reminderDefaultEventTypes).'\';
1960 $("#actioncode").change(function(){
1961 var selected_event_type = $("#actioncode option:selected").val();
1962
1963 if (reminderDefaultEventTypes.includes(selected_event_type)) {
1964 $(".reminderparameters").show();
1965 $("#addreminder").prop("checked", true);
1966
1967 // Set period with default reminder period
1968 $("[name=\"offsetvalue\"]").val(\'' . dol_escape_js((string) $reminderDefaultOffset) . '\');
1969 $("#select_offsetunittype_duration").select2("destroy");
1970 $("#select_offsetunittype_duration").val(\''.dol_escape_js($reminderDefaultUnit).'\');
1971 $("#select_offsetunittype_duration").select2();
1972
1973 $("#selectremindertype").select2("destroy");
1974 $("#selectremindertype").val("email");
1975 $("#selectremindertype").select2();
1976
1977 // Set default reminder mail model
1978 $("#select_actioncommsendmodel_mail").closest("tr").show();
1979 $("#select_actioncommsendmodel_mail").select2("destroy");
1980 $("#select_actioncommsendmodel_mail").val(\''.dol_escape_js((string) $reminderDefaultEmailModel).'\');
1981 $("#select_actioncommsendmodel_mail").select2();
1982 }
1983 });
1984 })';
1985 print '</script>'."\n";
1986
1987 print "\n".'<script type="text/javascript">';
1988 print '$(document).ready(function () {
1989 function toggle_reminder_part(evt) {
1990 console.log("Toggle reminder part");
1991 if ($("#addreminder").is(":checked")) {
1992 $(".reminderparameters").show();
1993 } else {
1994 $(".reminderparameters").hide();
1995 }
1996 $("#selectremindertype").select2("destroy");
1997 $("#selectremindertype").select2();
1998 $("#select_offsetunittype_duration").select2("destroy");
1999 $("#select_offsetunittype_duration").select2();
2000 selectremindertype();
2001 });
2002
2003 toggle_reminder_part();
2004 $("#addreminder").click(toggle_reminder_part);
2005
2006 $("#selectremindertype").change(function(){
2007 selectremindertype();
2008 });
2009
2010 function selectremindertype() {
2011 console.log("Call selectremindertype");
2012 var selected_option = $("#selectremindertype option:selected").val();
2013 if(selected_option == "email") {
2014 $("#select_actioncommsendmodel_mail").closest("tr").show();
2015 } else {
2016 $("#select_actioncommsendmodel_mail").closest("tr").hide();
2017 }
2018 }
2019
2020 })';
2021 print '</script>'."\n";
2022 }
2023
2024 print dol_get_fiche_end();
2025
2026 print $form->buttonsSaveCancel("Create");
2027
2028 print "</form>";
2029}
2030
2031// View or edit
2032if ($id > 0 && $action != 'create') {
2033 $result1 = $object->fetch($id);
2034 if ($result1 <= 0) {
2035 recordNotFound('', 0);
2036 }
2037
2038 $result2 = $object->fetch_thirdparty();
2039 $result2 = $object->fetchProject();
2040 $result3 = $object->fetch_contact();
2041 $result4 = $object->fetch_userassigned();
2042 $result5 = $object->fetch_optionals();
2043
2044 if ($listUserAssignedUpdated || $donotclearsession) {
2045 $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
2046
2047 $datep = dol_mktime($fulldayevent ? 0 : $aphour, $fulldayevent ? 0 : $apmin, 0, GETPOSTINT("apmonth"), GETPOSTINT("apday"), GETPOSTINT("apyear"), 'tzuserrel');
2048 $datef = dol_mktime($fulldayevent ? 23 : $p2hour, $fulldayevent ? 59 : $p2min, $fulldayevent ? 59 : 0, GETPOSTINT("p2month"), GETPOSTINT("p2day"), GETPOSTINT("p2year"), 'tzuserrel');
2049
2050 $object->type_id = dol_getIdFromCode($db, GETPOST("actioncode", 'aZ09'), 'c_actioncomm');
2051 $object->label = GETPOST("label", "alphanohtml");
2052 $object->datep = $datep;
2053 $object->datef = $datef;
2054 $object->percentage = $percentage;
2055 $object->priority = GETPOSTINT("priority");
2056 $object->fulldayevent = GETPOST("fullday") ? 1 : 0;
2057 $object->location = GETPOST('location', "alphanohtml");
2058 $object->socid = GETPOSTINT("socid");
2059 $socpeopleassigned = GETPOST("socpeopleassigned", 'array');
2060 foreach ($socpeopleassigned as $tmpid) {
2061 $object->socpeopleassigned[$id] = array('id' => $tmpid);
2062 }
2063 $object->contact_id = GETPOSTINT("contactid");
2064 $object->fk_project = GETPOSTINT("projectid");
2065
2066 $object->note_private = GETPOST("note", 'restricthtml');
2067 }
2068
2069 if ($result2 < 0 || $result3 < 0 || $result4 < 0 || $result5 < 0) {
2070 dol_print_error($db, $object->error);
2071 exit;
2072 }
2073
2074
2075 /*
2076 * Show tabs
2077 */
2078
2079 $head = actions_prepare_head($object);
2080
2081 $now = dol_now();
2082 $delay_warning = getDolGlobalInt('MAIN_DELAY_ACTIONS_TODO') * 24 * 60 * 60;
2083
2084
2085 // Confirmation suppression action
2086 if ($action == 'delete') {
2087 print $form->formconfirm("card.php?id=".urlencode((string) ($id)), $langs->trans("DeleteAction"), $langs->trans("ConfirmDeleteAction"), "confirm_delete", '', '', 1);
2088 }
2089
2090 if ($action == 'edit') {
2091 $caneditdateorowner = ($object->type != 'systemauto');
2092
2093 if (!empty($conf->use_javascript_ajax)) {
2094 print "\n".'<script type="text/javascript">';
2095 print '$(document).ready(function () {
2096 function setdatefields()
2097 {
2098 if ($("#fullday:checked").val() == null) {
2099 $(".fulldaystarthour").removeAttr("disabled");
2100 $(".fulldaystartmin").removeAttr("disabled");
2101 $(".fulldayendhour").removeAttr("disabled");
2102 $(".fulldayendmin").removeAttr("disabled");
2103 } else {
2104 $(".fulldaystarthour").prop("disabled", true).val("00");
2105 $(".fulldaystartmin").prop("disabled", true).val("00");
2106 $(".fulldayendhour").prop("disabled", true).val("23");
2107 $(".fulldayendmin").prop("disabled", true).val("59");
2108 }
2109 }
2110
2111 '.($caneditdateorowner ? ' setdatefields();' : '').'
2112
2113 $("#fullday").change(function() {
2114 setdatefields();
2115 });
2116 var old_startdate = null;
2117 $("#ap").focus(function() {
2118 old_startdate = new Date($("#apyear").val(), $("#apmonth").val() - 1, $("#apday").val());
2119 });
2120 $("#ap").next(".ui-datepicker-trigger").click(function() {
2121 old_startdate = new Date($("#apyear").val(), $("#apmonth").val() - 1, $("#apday").val());
2122 });
2123 $("#ap").change(function() {
2124 setTimeout(function() {
2125 if ($("#p2").val() !== "") {
2126 var new_startdate = new Date($("#apyear").val(), $("#apmonth").val() - 1, $("#apday").val());
2127 var old_enddate = new Date($("#p2year").val(), $("#p2month").val() - 1, $("#p2day").val());
2128 if (new_startdate > old_enddate) {
2129 var timeDiff = old_enddate - old_startdate;
2130 var new_enddate = new Date(new_startdate.getTime() + timeDiff);
2131 $("#p2").val(formatDate(new_enddate, "' . $langs->trans('FormatDateShortJavaInput') . '"));
2132 $("#p2day").val(new_enddate.getDate());
2133 $("#p2month").val(new_enddate.getMonth() + 1);
2134 $("#p2year").val(new_enddate.getFullYear());
2135 }
2136 }
2137 }, 0);
2138 });
2139 $("#actioncode").change(function() {
2140 if ($("#actioncode").val() == \'AC_RDV\') $("#dateend").addClass("fieldrequired");
2141 else $("#dateend").removeClass("fieldrequired");
2142 });
2143 })';
2144 print '</script>'."\n";
2145 }
2146
2147 print '<form name="formaction" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
2148 print '<input type="hidden" name="token" value="'.newToken().'">';
2149 print '<input type="hidden" name="action" value="update">';
2150 print '<input type="hidden" name="id" value="'.$id.'">';
2151 print '<input type="hidden" name="ref_ext" value="'.$object->ref_ext.'">';
2152 print '<input type="hidden" name="page_y" value="">';
2153 if ($backtopage) {
2154 print '<input type="hidden" name="backtopage" value="'.($backtopage != '1' ? $backtopage : '').'">';
2155 }
2156 if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') && ! preg_match('/^TICKET_MSG_PRIVATE/', $object->code)) {
2157 print '<input type="hidden" name="actioncode" value="'.$object->type_code.'">';
2158 }
2159
2160 print dol_get_fiche_head($head, 'card', $langs->trans("Action"), 0, 'action');
2161
2162 print '<table class="border tableforfield centpercent">';
2163
2164 // Ref
2165 print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td>'.$object->id.'</td></tr>';
2166
2167 // Title
2168 print '<tr><td class="fieldrequired'.(!getDolGlobalString('AGENDA_USE_EVENT_TYPE') ? ' titlefieldcreate' : '').'">'.$langs->trans("Title").'</td><td><input type="text" name="label" class="soixantepercent" value="'.$object->label.'"></td></tr>';
2169
2170 // Type of event
2171 if (getDolGlobalString('AGENDA_USE_EVENT_TYPE') && $object->elementtype != "ticket") {
2172 print '<tr><td class="fieldrequired">'.$langs->trans("Type").'</td><td>';
2173 if ($object->type_code != 'AC_OTH_AUTO') {
2174 print img_picto($langs->trans("ActionType"), 'square', 'class="fawidth30 inline-block" style="color: #ddd;"');
2175 print $formactions->select_type_actions(GETPOST("actioncode", 'aZ09') ? GETPOST("actioncode", 'aZ09') : $object->type_code, "actioncode", "systemauto", 0, 0, 0, 1);
2176 } else {
2177 print '<input type="hidden" name="actioncode" value="'.$object->type_code.'">';
2178 print $object->getTypePicto();
2179 print $langs->trans("Action".$object->type_code);
2180 }
2181 print '</td></tr>';
2182 }
2183
2184 // Private
2185 if ($object->elementtype == 'ticket') {
2186 print '<tr><td>'.$langs->trans("MarkMessageAsPrivate");
2187 print ' '.$form->textwithpicto('', $langs->trans("TicketMessagePrivateHelp"), 1, 'help');
2188 print '</td><td><input type="checkbox" id="private" name="private" '.(preg_match('/^TICKET_MSG_PRIVATE/', $object->code) ? ' checked' : '').'></td></tr>';
2189 }
2190
2191 // Full day event
2192 print '<tr><td><span class="fieldrequired">'.$langs->trans("Date").'</span></td><td class="valignmiddle height30 small">';
2193 print '<input '.($caneditdateorowner ? '' : ' disabled').' type="checkbox" id="fullday" name="fullday" '.($object->fulldayevent ? ' checked' : '').'>';
2194 print '<label for="fullday">'.$langs->trans("EventOnFullDay").'</label>';
2195
2196 // // Recurring event
2197 // $userepeatevent = (getDolGlobalInt('MAIN_DISABLE_RECURRING_EVENTS') ? 0 : 1);
2198 // if ($userepeatevent) {
2199 // // Repeat
2200 // //print '<tr><td></td><td colspan="3">';
2201 // print ' &nbsp; &nbsp; &nbsp; &nbsp; <div class="opacitymedium inline-block">';
2202 // print img_picto($langs->trans("Recurrence"), 'recurring', 'class="paddingright2"');
2203 // print '<input type="hidden" name="recurid" value="'.$object->recurid.'">';
2204 // $selectedrecurrulefreq = 'no';
2205 // $selectedrecurrulebymonthday = '';
2206 // $selectedrecurrulebyday = '';
2207 // if ($object->recurrule && preg_match('/FREQ=([A-Z]+)/i', $object->recurrule, $reg)) {
2208 // $selectedrecurrulefreq = $reg[1];
2209 // }
2210 // if ($object->recurrule && preg_match('/FREQ=MONTHLY.*BYMONTHDAY=(\d+)/i', $object->recurrule, $reg)) {
2211 // $selectedrecurrulebymonthday = $reg[1];
2212 // }
2213 // if ($object->recurrule && preg_match('/FREQ=WEEKLY.*BYDAY(\d+)/i', $object->recurrule, $reg)) {
2214 // $selectedrecurrulebyday = $reg[1];
2215 // }
2216 // print $form->selectarray('recurrulefreq', $arrayrecurrulefreq, $selectedrecurrulefreq, 0, 0, 0, '', 0, 0, 0, '', 'marginrightonly');
2217 // // If recurrulefreq is MONTHLY
2218 // print '<div class="hidden marginrightonly inline-block repeateventBYMONTHDAY">';
2219 // print $langs->trans("DayOfMonth").': <input type="input" size="2" name="BYMONTHDAY" value="'.$selectedrecurrulebymonthday.'">';
2220 // print '</div>';
2221 // // If recurrulefreq is WEEKLY
2222 // print '<div class="hidden marginrightonly inline-block repeateventBYDAY">';
2223 // print $langs->trans("DayOfWeek").': <input type="input" size="4" name="BYDAY" value="'.$selectedrecurrulebyday.'">';
2224 // print '</div>';
2225 // print '<script type="text/javascript">
2226 // jQuery(document).ready(function() {
2227 // function init_repeat()
2228 // {
2229 // if (jQuery("#recurrulefreq").val() == \'MONTHLY\')
2230 // {
2231 // jQuery(".repeateventBYMONTHDAY").css("display", "inline-block"); /* use this instead of show because we want inline-block and not block */
2232 // jQuery(".repeateventBYDAY").hide();
2233 // }
2234 // else if (jQuery("#recurrulefreq").val() == \'WEEKLY\')
2235 // {
2236 // jQuery(".repeateventBYMONTHDAY").hide();
2237 // jQuery(".repeateventBYDAY").css("display", "inline-block"); /* use this instead of show because we want inline-block and not block */
2238 // }
2239 // else
2240 // {
2241 // jQuery(".repeateventBYMONTHDAY").hide();
2242 // jQuery(".repeateventBYDAY").hide();
2243 // }
2244 // }
2245 // init_repeat();
2246 // jQuery("#recurrulefreq").change(function() {
2247 // init_repeat();
2248 // });
2249 // });
2250 // </script>';
2251 // print '</div>';
2252 // //print '</td></tr>';
2253 // }
2254 print '</td></tr>';
2255
2256 // Date start - end
2257 print '<tr><td class="nowrap">';
2258 print '</td><td>';
2259 $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
2260 print $form->selectDate($datep ? $datep : $object->datep, 'ap', 1, 1, 0, "action", 1, 2, ($caneditdateorowner ? 0 : 1), 'fulldaystart', '', '', '', 1, '', '', $object->fulldayevent ? ($tzforfullday ? $tzforfullday : 'tzuserrel') : 'tzuserrel');
2261 print ' <span class="hideonsmartphone">&nbsp; &nbsp; - &nbsp; &nbsp;</span> ';
2262 print $form->selectDate($datef ? $datef : $object->datef, 'p2', 1, 1, 1, "action", 1, 2, ($caneditdateorowner ? 0 : 1), 'fulldayend', '', '', '', 1, '', '', $object->fulldayevent ? ($tzforfullday ? $tzforfullday : 'tzuserrel') : 'tzuserrel');
2263 print '</td></tr>';
2264
2265 // Location
2266 if (!getDolGlobalString('AGENDA_DISABLE_LOCATION')) {
2267 print '<tr><td>'.$langs->trans("Location").'</td><td>';
2268 print img_picto('', 'map-marker-alt', 'class="pictofixedwidth"');
2269 print '<input type="text" name="location" class="minwidth300 maxwidth150onsmartphone" value="'.$object->location.'"></td></tr>';
2270 }
2271
2272 print '<tr class="tdsmallheight"><td class="tdsmallheight">&nbsp;</td><td class="tdsmallheight"></td></tr>';
2273
2274 // Assigned to
2275 $listofuserid = []; // User assigned
2276 if (empty($donotclearsession)) {
2277 if ($object->userownerid > 0) {
2278 $listofuserid[$object->userownerid] = array(
2279 'id' => $object->userownerid,
2280 'type' => 'user',
2281 //'transparency'=>$object->userassigned[$user->id]['transparency'],
2282 'transparency' => $object->transparency, // Force transparency on ownerfrom event
2283 'answer_status' => (isset($object->userassigned[$object->userownerid]['answer_status']) ? $object->userassigned[$object->userownerid]['answer_status'] : null),
2284 'mandatory' => (isset($object->userassigned[$object->userownerid]['mandatory']) ? $object->userassigned[$object->userownerid]['mandatory'] : null)
2285 );
2286 }
2287 if (!empty($object->userassigned)) { // Now concat assigned users
2288 // Restore array with key with same value than param 'id'
2289 $tmplist1 = $object->userassigned;
2290 foreach ($tmplist1 as $key => $val) {
2291 if ($val['id'] && $val['id'] != $object->userownerid) {
2292 $listofuserid[$val['id']] = $val;
2293 }
2294 }
2295 }
2296 $_SESSION['assignedtouser'] = json_encode($listofuserid);
2297 } else {
2298 if (!empty($_SESSION['assignedtouser'])) {
2299 $listofuserid = json_decode($_SESSION['assignedtouser'], true);
2300 }
2301 }
2302
2303 $listofcontactid = $object->socpeopleassigned; // Contact assigned
2304 $listofotherid = $object->otherassigned; // Other undefined email (not used yet)
2305
2306 print '<tr><td class="nowrap fieldrequired">'.$langs->trans("ActionAssignedTo").'</td><td>';
2307 print '<div class="assignedtouser">';
2308 print $form->select_dolusers_forevent(($action == 'create' ? 'add' : 'update'), 'assignedtouser', 1, [], 0, '', [], '0', 0, 0, 'u.statut:<>:0', 1, $listofuserid, $listofcontactid, $listofotherid, (int) $caneditdateorowner);
2309 print '</div>';
2310 /*if (in_array($user->id,array_keys($listofuserid)))
2311 {
2312 print '<div class="myavailability">';
2313 print $langs->trans("MyAvailability").': <input id="transparency" type="checkbox" name="transparency"'.($listofuserid[$user->id]['transparency']?' checked':'').'>'.$langs->trans("Busy");
2314 print '</div>';
2315 }*/
2316 print '</td></tr>';
2317
2318 // Tags-Categories
2319 if (isModEnabled('category')) {
2320 print '<tr><td>'.$langs->trans("Categories").'</td><td>';
2321 print $form->selectCategories(Categorie::TYPE_ACTIONCOMM, 'categories', $object);
2322 print "</td></tr>";
2323 }
2324
2325 print '</table>';
2326
2327
2328 print '<br>';
2329
2330
2331 print '<table class="border tableforfield centpercent">';
2332
2333 // Status
2334 print '<tr><td class="nowrap">'.$langs->trans("Status").' / '.$langs->trans("Progression").'</td><td colspan="3">';
2335 $percent = GETPOSTISSET("percentage") ? GETPOSTINT("percentage") : $object->percentage;
2336 $formactions->form_select_status_action('formaction', (string) $percent, 1, 'complete', 0, 0, 'minwidth150 maxwidth300');
2337 print '</td></tr>';
2338
2339 if (isModEnabled("societe")) {
2340 // Related company
2341 print '<tr><td class="titlefieldcreate">'.$langs->trans("ActionOnCompany").'</td>';
2342 print '<td>';
2343 print '<div>';
2344 $events = []; // 'method'=parameter action of url, 'url'=url to call that return new list of contacts
2345 $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1&token='.currentToken(), 1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
2346 // TODO Refresh also list of project if conf PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY not defined with list linked to socid ?
2347 // FIXME If we change company, we may get a project that does not match
2348 print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company($object->socid, 'socid', '', 'SelectThirdParty', 1, 0, $events, 0, 'minwidth300');
2349 print '</div>';
2350 print '</td></tr>';
2351
2352 // Related contact
2353 print '<tr><td>'.$langs->trans("ActionOnContact").'</td><td>';
2354 print '<div class="maxwidth200onsmartphone">';
2355
2356 print img_picto('', 'contact', 'class="paddingrightonly"');
2357 if (getDolGlobalString('CONTACT_USE_SEARCH_TO_SELECT') && $conf->use_javascript_ajax) {
2358 // FIXME Use the select_contact supporting the "multiple"
2359 /*
2360 $selected = array_keys($object->socpeopleassigned);
2361 print $form->select_contact(getDolGlobalString('MAIN_ACTIONCOM_CAN_ADD_ANY_CONTACT') ? 0 : $object->socid, $selected, 'socpeopleassigned', 1, '', '', 1, 'minwidth300 widthcentpercentminusx', false, 0, 0, []);
2362 */
2363 $sav = getDolGlobalString('CONTACT_USE_SEARCH_TO_SELECT');
2364 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = 0;
2365 print $form->selectcontacts(getDolGlobalString('MAIN_ACTIONCOM_CAN_ADD_ANY_CONTACT') ? 0 : ($object->socid > 0 ? $object->socid : -1), array_keys($object->socpeopleassigned), 'socpeopleassigned[]', 1, '', '', 1, 'minwidth300 widthcentpercentminusx', 0, 0, 0, [], 'multiple', 'contactid');
2366 $conf->global->CONTACT_USE_SEARCH_TO_SELECT = $sav;
2367 } else {
2368 // Warning: MAIN_ACTIONCOM_CAN_ADD_ANY_CONTACT will hangs on large databases
2369 print $form->selectcontacts(getDolGlobalString('MAIN_ACTIONCOM_CAN_ADD_ANY_CONTACT') ? 0 : $object->socid, array_keys($object->socpeopleassigned), 'socpeopleassigned[]', 1, '', '', 1, 'minwidth300 widthcentpercentminusx', 0, 0, 0, [], 'multiple', 'contactid');
2370 }
2371 print '</div>';
2372 print '</td>';
2373 print '</tr>';
2374 }
2375
2376 // Project
2377 if (isModEnabled('project')) {
2378 $langs->load("projects");
2379
2380 print '<tr><td class="titlefieldcreate">'.$langs->trans("Project").'</td><td>';
2381 print img_picto('', 'project', 'class="pictofixedwidth"');
2382 $numprojet = $formproject->select_projects(($object->socid > 0 ? $object->socid : -1), (string) $object->fk_project, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 0, 0, 'maxwidth500 widthcentpercentminusxx');
2383 if ($numprojet == 0) {
2384 print ' &nbsp; <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$object->socid.'&action=create&token='.newToken().'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit').'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddProject").'"></span></a>';
2385 }
2386 print '</td></tr>';
2387 }
2388
2389 // Priority
2390 if (getDolGlobalString('AGENDA_SUPPORT_PRIORITY_IN_EVENTS')) {
2391 print '<tr><td class="titlefieldcreate nowrap">'.$langs->trans("Priority").'</td><td>';
2392 print '<input type="text" name="priority" value="'.($object->priority ? $object->priority : '').'" size="5">';
2393 print '</td></tr>';
2394 }
2395
2396 // Object linked
2397 if ($object->fk_project || (!empty($object->elementid) && !empty($object->elementtype))) {
2398 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2399 print '<tr>';
2400 print '<td>'.$langs->trans("LinkedObject").'</td>';
2401
2402 if ($object->elementtype == 'project_task' && isModEnabled('project')) {
2403 print '<td id="project-task-input-container" >';
2404
2405 $urloption = '?action=create&donotclearsession=1'; // we use create not edit for more flexibility
2406 $url = DOL_URL_ROOT.'/comm/action/card.php'.$urloption;
2407
2408 // update task list
2409 ?>
2410 <script type="text/javascript" >
2411 $(document).ready(function () {
2412 $("#projectid").change(function () {
2413 var url = "<?php echo $url; ?>&projectid="+$("#projectid").val();
2414 $.get(url, function(data) {
2415 console.log($( data ).find("#fk_element").html());
2416 if (data) $("#fk_element").html( $( data ).find("#taskid").html() ).select2();
2417 })
2418 });
2419 });
2420 </script>
2421 <?php
2422
2423 print $formproject->selectTasks((!empty($societe->id) ? $societe->id : -1), $object->elementid, 'fk_element', 64, 0, '', 1, 0, 0, 'maxwidth500', (string) $object->fk_project, 'all', null, 1);
2424 print '<input type="hidden" name="elementtype" value="'.$object->elementtype.'">';
2425
2426 print '</td>';
2427 } else {
2428 if (empty($object->elementtype) && empty($object->elementid) && $object->fk_project) {
2429 $projectsListId = GETPOSTINT('projectid') ? GETPOSTINT('projectid') : $object->fk_project;
2430
2431 print '<td id="project-task-input-container" >';
2432
2433 // update task list
2434 ?>
2435 <script type="text/javascript">
2436 $(document).ready(function () {
2437 $("#projectid").change(function () {
2438 var url = "<?php echo DOL_URL_ROOT; ?>/projet/ajax/projects.php?mode=gettasks&socid="+$("#search_socid").val()+"&projectid="+$("#projectid").val();
2439 console.log("Call url to get new list of tasks: "+url);
2440 $.get(url, function(data) {
2441 console.log(data);
2442 if (data) $("#taskid").html(data).select2();
2443 })
2444 });
2445 });
2446 </script>
2447 <?php
2448
2449 $tid = '';
2450 if (GETPOSTISSET("projecttaskid") && GETPOSTINT("projecttaskid") > 0) {
2451 $tid = GETPOSTINT("projecttaskid");
2452 } elseif (GETPOSTISSET("taskid") && GETPOSTINT("taskid") > 0) {
2453 $tid = GETPOSTINT("taskid");
2454 }
2455
2456 print $formproject->selectTasks((!empty($societe->id) ? $societe->id : -1), $tid, 'taskid', 64, 0, '1', 1, 0, 0, 'maxwidth500 widthcentpercentminusxx', (string) $projectsListId, 'all', null, 1);
2457
2458 print '</td>';
2459 } else {
2460 print '<td>';
2461 print dolGetElementUrl($object->elementid, $object->elementtype, 1);
2462 print '<input type="hidden" name="fk_element" value="'.$object->elementid.'">';
2463 print '<input type="hidden" name="elementtype" value="'.$object->elementtype.'">';
2464 print '</td>';
2465 }
2466 }
2467
2468 print '</tr>';
2469 }
2470
2471 // Description
2472 print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
2473 // Wysiwyg editor
2474 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
2475 $doleditor = new DolEditor('note', $object->note_private, '', 120, 'dolibarr_notes', 'In', true, true, isModEnabled('fckeditor'), ROWS_4, '90%');
2476 $doleditor->Create();
2477 print '</td></tr>';
2478
2479 // Other attributes
2480 $parameters = [];
2481 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2482 print $hookmanager->resPrint;
2483 if (empty($reshook)) {
2484 print $object->showOptionals($extrafields, 'edit', $parameters);
2485 }
2486
2487 print '</table>';
2488
2489 // Reminders
2490 if ($enablereminders) {
2491 $filteruserid = $user->id;
2492 if ($user->hasRight('agenda', 'allactions', 'read')) {
2493 $filteruserid = 0;
2494 }
2495 $object->loadReminders('', $filteruserid, false);
2496
2497 print '<hr>';
2498
2499 if (count($object->reminders) > 0) {
2500 $checked = 'checked';
2501 $keys = array_keys($object->reminders);
2502 $firstreminderId = array_shift($keys);
2503
2504 $actionCommReminder = $object->reminders[$firstreminderId];
2505 } else {
2506 $checked = '';
2507 $actionCommReminder = new ActionCommReminder($db);
2508 $actionCommReminder->offsetvalue = getDolGlobalInt('AGENDA_REMINDER_DEFAULT_OFFSET', 30);
2509 $actionCommReminder->offsetunit = 'i';
2510 $actionCommReminder->typeremind = 'email';
2511 }
2512 $disabled = '';
2513 /*
2514 if ($object->datep < dol_now()) {
2515 //$disabled = 'disabled title="'.dol_escape_htmltag($langs->trans("EventExpired")).'"';
2516 }
2517 */
2518
2519 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>';
2520
2521 print '<div class="reminderparameters" '.(empty($checked) ? 'style="display: none;"' : '').'>';
2522
2523 print '<br>';
2524
2525 print '<table class="border centpercent">';
2526
2527 // Reminder
2528 print '<tr><td class="titlefieldcreate nowrap">'.$langs->trans("ReminderTime").'</td><td colspan="3">';
2529 print '<input type="number" name="offsetvalue" class="width50" value="'.$actionCommReminder->offsetvalue.'"> ';
2530 print $form->selectTypeDuration('offsetunit', $actionCommReminder->offsetunit, $TDurationTypesExcluded);
2531 print '</td></tr>';
2532
2533 // Reminder Type
2534 print '<tr><td class="titlefieldcreate nowrap">'.$langs->trans("ReminderType").'</td><td colspan="3">';
2535 print $form->selectarray('selectremindertype', $TRemindTypes, $actionCommReminder->typeremind, 0, 0, 0, '', 0, 0, 0, '', 'minwidth200', 1);
2536 print '</td></tr>';
2537
2538 $hide = '';
2539 if ($actionCommReminder->typeremind == 'browser') {
2540 $hide = 'style="display:none;"';
2541 }
2542
2543 // Mail Model
2544 if (getDolGlobalString('AGENDA_REMINDER_EMAIL')) {
2545 print '<tr '.$hide.'><td class="titlefieldcreate nowrap">'.$langs->trans("EMailTemplates").'</td><td colspan="3">';
2546 print $form->selectModelMail('actioncommsend', 'actioncomm_send', 1, 1, (string) $actionCommReminder->fk_email_template);
2547 print '</td></tr>';
2548 }
2549
2550 print '</table>';
2551 ?>
2552 <script type="text/javascript">
2553 $(document).ready(function () {
2554 $("#addreminder").click(function(){
2555 if (this.checked) {
2556 $(".reminderparameters").show();
2557 } else {
2558 $(".reminderparameters").hide();
2559 }
2560 });
2561 $("#selectremindertype").change(function(){
2562 var selected_option = $("#selectremindertype option:selected").val();
2563 if(selected_option == "email") {
2564 $("#select_actioncommsendmodel_mail").closest("tr").show();
2565 } else {
2566 $("#select_actioncommsendmodel_mail").closest("tr").hide();
2567 }
2568 });
2569 });
2570 </script>
2571 <?php
2572
2573 $reminderDefaultEventTypes = getDolGlobalString('AGENDA_DEFAULT_REMINDER_EVENT_TYPES', '');
2574 $reminderDefaultOffset = getDolGlobalString('AGENDA_DEFAULT_REMINDER_OFFSET', 30);
2575 $reminderDefaultUnit = getDolGlobalString('AGENDA_DEFAULT_REMINDER_OFFSET_UNIT');
2576 $reminderDefaultEmailModel = getDolGlobalString('AGENDA_DEFAULT_REMINDER_EMAIL_MODEL');
2577
2578 print "\n".'<script type="text/javascript">';
2579 print '$(document).ready(function () {
2580 const reminderDefaultEventTypes = \''.dol_escape_js($reminderDefaultEventTypes).'\';
2581 $("#actioncode").change(function(){
2582 var selected_event_type = $("#actioncode option:selected").val();
2583
2584 if (reminderDefaultEventTypes.includes(selected_event_type)) {
2585 $(".reminderparameters").show();
2586 $("#addreminder").prop("checked", true);
2587
2588 // Set period with default reminder period
2589 $("#offsetvalue").val(\''.dol_escape_js($reminderDefaultOffset).'\');
2590 $("#select_offsetunittype_duration").select2("destroy");
2591 $("#select_offsetunittype_duration").val(\''.dol_escape_js($reminderDefaultUnit).'\');
2592 $("#select_offsetunittype_duration").select2();
2593
2594 $("#selectremindertype").select2("destroy");
2595 $("#selectremindertype").val("email");
2596 $("#selectremindertype").select2();
2597
2598 // Set default reminder mail model
2599 $("#select_actioncommsendmodel_mail").closest("tr").show();
2600 $("#select_actioncommsendmodel_mail").select2("destroy");
2601 $("#select_actioncommsendmodel_mail").val(\''.dol_escape_js($reminderDefaultEmailModel).'\');
2602 $("#select_actioncommsendmodel_mail").select2();
2603 }
2604 });
2605 })';
2606 print '</script>'."\n";
2607 print '</div>'; // End of div for reminderparameters
2608 }
2609
2610 print dol_get_fiche_end();
2611
2612 print $form->buttonsSaveCancel();
2613
2614 print '</form>';
2615 } else {
2616 print dol_get_fiche_head($head, 'card', $langs->trans("Action"), -1, 'action');
2617
2618 $formconfirm = '';
2619
2620 // Clone event
2621 if ($action == 'clone') {
2622 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.GETPOST('id'), $langs->trans('ToClone'), $langs->trans('ConfirmCloneEvent', $object->label), 'confirm_clone', [], 'yes', 1);
2623 }
2624
2625 // Call Hook formConfirm
2626 $parameters = [];
2627 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2628 if (empty($reshook)) {
2629 $formconfirm .= $hookmanager->resPrint;
2630 } elseif ($reshook > 0) {
2631 $formconfirm = $hookmanager->resPrint;
2632 }
2633
2634 // Print form confirm
2635 print $formconfirm;
2636
2637 $linkback = '';
2638 // Link to other agenda views
2639 $linkback .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&restore_lastsearch_values=1">';
2640 $linkback .= img_picto($langs->trans("BackToList"), 'object_calendarlist', 'class="pictoactionview pictofixedwidth"');
2641 $linkback .= '<span class="hideonsmartphone">'.$langs->trans("BackToList").'</span>';
2642 $linkback .= '</a>';
2643 $linkback .= '</li>';
2644 $linkback .= '<li class="noborder litext">';
2645 $linkback .= '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_month&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').'">';
2646 $linkback .= img_picto($langs->trans("ViewCal"), 'object_calendar', 'class="pictoactionview pictofixedwidth"');
2647 $linkback .= '<span class="hideonsmartphone">'.$langs->trans("ViewCal").'</span>';
2648 $linkback .= '</a>';
2649 $linkback .= '</li>';
2650 $linkback .= '<li class="noborder litext">';
2651 $linkback .= '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_week&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').'">';
2652 $linkback .= img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="pictoactionview pictofixedwidth"');
2653 $linkback .= '<span class="hideonsmartphone">'.$langs->trans("ViewWeek").'</span>';
2654 $linkback .= '</a>';
2655 $linkback .= '</li>';
2656 $linkback .= '<li class="noborder litext">';
2657 $linkback .= '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_day&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').'">';
2658 $linkback .= img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="pictoactionview pictofixedwidth"');
2659 $linkback .= '<span class="hideonsmartphone">'.$langs->trans("ViewDay").'</span>';
2660 $linkback .= '</a>';
2661 $linkback .= '</li>';
2662 $linkback .= '<li class="noborder litext">';
2663 $linkback .= '<a href="'.DOL_URL_ROOT.'/comm/action/peruser.php?mode=show_peruser&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').'">';
2664 $linkback .= img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="pictoactionview pictofixedwidth"');
2665 $linkback .= '<span class="hideonsmartphone">'.$langs->trans("ViewPerUser").'</span>';
2666 $linkback .= '</a>';
2667
2668 // Add more views from hooks
2669 $parameters = [];
2670 $reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
2671 if (empty($reshook)) {
2672 $linkback .= $hookmanager->resPrint;
2673 } elseif ($reshook > 1) {
2674 $linkback = $hookmanager->resPrint;
2675 }
2676
2677 //$linkback.=$out;
2678
2679 $morehtmlref = '<div class="refidno">';
2680 // Thirdparty
2681 //$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
2682 // Project
2683 if (isModEnabled('project')) {
2684 $langs->load("projects");
2685 //$morehtmlref .= '<br>';
2686 if ($usercancreate) {
2687 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
2688 if ($action != 'classify') {
2689 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
2690 }
2691 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
2692 } else {
2693 if (!empty($object->fk_project)) {
2694 $proj = new Project($db);
2695 $proj->fetch($object->fk_project);
2696 $morehtmlref .= $proj->getNomUrl(1);
2697 if ($proj->title) {
2698 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
2699 }
2700 }
2701 }
2702 }
2703 $morehtmlref .= '</div>';
2704
2705
2706 dol_banner_tab($object, 'id', $linkback, ($user->socid ? 0 : 1), 'id', 'ref', $morehtmlref);
2707
2708 print '<div class="fichecenter">';
2709 print '<div class="fichehalfleft">';
2710
2711 print '<div class="underbanner clearboth"></div>';
2712
2713 // Show event in view mode
2714 print '<table class="border tableforfield centpercent">';
2715
2716 // Type
2717 if (getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
2718 print '<tr><td class="titlefieldmiddle">'.$langs->trans("Type").'</td><td>';
2719 $labeltype = ($langs->transnoentities("Action".$object->type_code) != "Action".$object->type_code) ? $langs->transnoentities("Action".$object->type_code) : $object->type_label;
2720 $labeltoshow = $labeltype;
2721 if ($object->code) {
2722 $labeltoshow .= ' ('.$object->code.')';
2723 }
2724 print $object->getTypePicto('pictofixedwidth paddingright', $labeltoshow);
2725 print $labeltype;
2726 print '</td></tr>';
2727 }
2728
2729 // Full day event
2730 print '<tr><td class="titlefieldmiddle">'.$langs->trans("EventOnFullDay").'</td><td>'.yn($object->fulldayevent ? 1 : 0, 3).'</td></tr>';
2731
2732 $rowspan = 4;
2733 if (!getDolGlobalString('AGENDA_DISABLE_LOCATION')) {
2734 $rowspan++;
2735 }
2736
2737 // Date start
2738 print '<tr><td>'.$langs->trans("DateActionStart").'</td><td title="'.dol_print_date($object->datep, 'dayhoursec', 'tzuserrel').'">';
2739 // Test a date before the 27 march and one after
2740 //print dol_print_date($object->datep, 'dayhour', 'gmt');
2741 //print dol_print_date($object->datep, 'dayhour', 'tzuser');
2742 //print dol_print_date($object->datep, 'dayhour', 'tzuserrel');
2743 if (empty($object->fulldayevent)) {
2744 print dol_print_date($object->datep, 'dayhour', 'tzuserrel');
2745 } else {
2746 $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
2747 print dol_print_date($object->datep, 'day', ($tzforfullday ? $tzforfullday : 'tzuserrel'));
2748 }
2749 if ($object->percentage == 0 && $object->datep && $object->datep < ($now - $delay_warning)) {
2750 print img_warning($langs->trans("Late"));
2751 }
2752 print '</td>';
2753 print '</tr>';
2754
2755 // Date end
2756 print '<tr><td>'.$langs->trans("DateActionEnd").'</td><td title="'.dol_print_date($object->datef, 'dayhoursec', 'tzuserrel').'">';
2757 if (empty($object->fulldayevent)) {
2758 print dol_print_date($object->datef, 'dayhour', 'tzuserrel');
2759 } else {
2760 $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
2761 print dol_print_date($object->datef, 'day', ($tzforfullday ? $tzforfullday : 'tzuserrel'));
2762 }
2763 if ($object->percentage > 0 && $object->percentage < 100 && $object->datef && $object->datef < ($now - $delay_warning)) {
2764 print img_warning($langs->trans("Late"));
2765 }
2766 print '</td></tr>';
2767
2768 // Recurring event (into a series)
2769 if ($object->recurid) {
2770 print '<tr><td class="titlefieldmiddle">'.$langs->trans("RecurringEvent").'</td><td>';
2771 print img_picto($langs->trans("EventPartOfARecurringSerie", $object->recurid), 'recurring', 'class="pictofixedwidth"');
2772 $reg = [];
2773 if (preg_match('/FREQ=MONTHLY_BYMONTHDAY(\d+)/', $object->recurrule, $reg)) {
2774 print $langs->trans("EveryMonth").' <span class="opacitymedium small">('.$langs->trans("DayOfMonth").' '.$reg[1].' - '.$langs->trans("Until").' '.dol_print_date($object->recurdateend, 'day').')</span>';
2775 }
2776 if (preg_match('/FREQ=YEARLY_BYYEARMONTHDAY(\d+)/', $object->recurrule, $reg)) {
2777 print $langs->trans("EveryYear").' <span class="opacitymedium small">('.$langs->trans("DayOfYear").' '.$reg[1].' - '.$langs->trans("Until").' '.dol_print_date($object->recurdateend, 'day').')</span>';
2778 }
2779 print '</td></tr>';
2780 }
2781
2782 // Location
2783 if (!getDolGlobalString('AGENDA_DISABLE_LOCATION')) {
2784 print '<tr><td>'.$langs->trans("Location").'</td><td>'.$object->location.'</td></tr>';
2785 }
2786
2787 // Assigned to user
2788 print '<tr><td class="nowrap">'.$langs->trans("ActionAssignedTo").'</td><td>';
2789 $listofuserid = [];
2790 if (empty($donotclearsession)) {
2791 if ($object->userownerid > 0) {
2792 $listofuserid[$object->userownerid] = array(
2793 'id' => $object->userownerid,
2794 'transparency' => $object->transparency, // Force transparency on owner from property of event
2795 'answer_status' => $object->userassigned[$object->userownerid]['answer_status'],
2796 'mandatory' => $object->userassigned[$object->userownerid]['mandatory']
2797 );
2798 }
2799 if (!empty($object->userassigned)) { // Now concat assigned users
2800 // Restore array with key with same value than param 'id'
2801 $tmplist1 = $object->userassigned;
2802 foreach ($tmplist1 as $key => $val) {
2803 if ($val['id'] && $val['id'] != $object->userownerid) {
2804 $listofuserid[$val['id']] = $val;
2805 }
2806 }
2807 }
2808 $_SESSION['assignedtouser'] = json_encode($listofuserid);
2809 } else {
2810 if (!empty($_SESSION['assignedtouser'])) {
2811 $listofuserid = json_decode($_SESSION['assignedtouser'], true);
2812 }
2813 }
2814
2815 $listofcontactid = []; // not used yet
2816 $listofotherid = []; // not used yet
2817 print '<div class="assignedtouser">';
2818 print $form->select_dolusers_forevent('view', 'assignedtouser', 1, [], 0, '', [], '0', 0, 0, '', ($object->datep != $object->datef) ? 1 : 0, $listofuserid, $listofcontactid, $listofotherid);
2819 print '</div>';
2820 /*
2821 if ($object->datep != $object->datef && in_array($user->id,array_keys($listofuserid)))
2822 {
2823 print '<div class="myavailability">';
2824 print $langs->trans("MyAvailability").': '.(($object->userassigned[$user->id]['transparency'] > 0)?$langs->trans("Busy"):$langs->trans("Available")); // We show nothing if event is assigned to nobody
2825 print '</div>';
2826 }
2827 */
2828 print ' </td></tr>';
2829
2830 // Categories
2831 if (isModEnabled('category')) {
2832 print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
2833 print $form->showCategories($object->id, Categorie::TYPE_ACTIONCOMM, 1);
2834 print "</td></tr>";
2835 }
2836
2837 print '</table>';
2838
2839 print '</div>';
2840
2841 print '<div class="fichehalfright">';
2842
2843 print '<div class="underbanner clearboth"></div>';
2844 print '<table class="border tableforfield centpercent">';
2845
2846 if (isModEnabled("societe")) {
2847 // Related company
2848 print '<tr><td class="titlefield">'.$langs->trans("ActionOnCompany").'</td>';
2849 print '<td>'.(is_object($object->thirdparty) && $object->thirdparty->id ? $object->thirdparty->getNomUrl(1) : ('<span class="opacitymedium">'.$langs->trans("None").'</span>'));
2850 if (is_object($object->thirdparty) && $object->thirdparty->id > 0 && $object->type_code == 'AC_TEL') {
2851 if ($object->thirdparty->fetch($object->thirdparty->id)) {
2852 print "<br>".dol_print_phone($object->thirdparty->phone);
2853 }
2854 }
2855 print '</td></tr>';
2856
2857 // Related contact
2858 print '<tr><td>'.$langs->trans("ActionOnContact").'</td>';
2859 print '<td>';
2860
2861 if (!empty($object->socpeopleassigned)) {
2862 foreach ($object->socpeopleassigned as $cid => $Tab) {
2863 $contact = new Contact($db);
2864 $result = $contact->fetch($cid);
2865
2866 if ($result < 0) {
2867 dol_print_error($db, $contact->error);
2868 }
2869
2870 if ($result > 0) {
2871 print $contact->getNomUrl(1);
2872 if ($object->type_code == 'AC_TEL') {
2873 if (!empty($contact->phone_pro)) {
2874 print '('.dol_print_phone($contact->phone_pro).')';
2875 }
2876 }
2877 print '<div class="paddingright"></div>';
2878 }
2879 }
2880 } else {
2881 print '<span class="opacitymedium">'.$langs->trans("None").'</span>';
2882 }
2883 print '</td></tr>';
2884 }
2885
2886 // Priority
2887 if (getDolGlobalString('AGENDA_SUPPORT_PRIORITY_IN_EVENTS')) {
2888 print '<tr><td class="nowrap" class="titlefield">' . $langs->trans("Priority") . '</td><td>';
2889 print($object->priority ? $object->priority : '');
2890 print '</td></tr>';
2891 }
2892
2893 // Object linked (if link is for thirdparty, contact, project it is a recording error. We should not have links in link table
2894 // for such objects because there is already a dedicated field into table llx_actioncomm.
2895 if (!empty($object->elementid) && !empty($object->elementtype) && !in_array($object->elementtype, array('societe', 'contact', 'project'))) {
2896 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2897 print '<tr><td>'.$langs->trans("LinkedObject").'</td>';
2898 $link = dolGetElementUrl($object->elementid, $object->elementtype, ($object->elementtype == 'user' ? -1 : 1));
2899 print '<td>';
2900 if (empty($link)) {
2901 print '<span class="opacitymedium">'.$langs->trans("ObjectDeleted").'</span>';
2902 } else {
2903 print $link;
2904 }
2905 print '</td></tr>';
2906 }
2907
2908 //mail information
2909 if (!empty($object->email_msgid)) {
2910 print '<tr><td>'.$langs->trans('MailTopic').'</td>';
2911 print '<td>'.dol_escape_htmltag($object->email_subject).'</td></tr>';
2912 print '<tr><td>'.$langs->trans('MailFrom').'</td>';
2913 print '<td>'.dol_escape_htmltag($object->email_from).'</td></tr>';
2914 print '<tr><td>'.$langs->trans('MailTo').'</td>';
2915 print '<td>'.dol_escape_htmltag($object->email_to).'</td></tr>';
2916 if (!empty($object->email_tocc)) {
2917 print '<tr><td>'.$langs->trans('MailCC').'</td>';
2918 print '<td>'.dol_escape_htmltag($object->email_tocc).'</td></tr>';
2919 }
2920 }
2921
2922 // Description
2923 print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td class="wordbreak sensiblehtmlcontent">';
2924 print dol_string_onlythesehtmltags(dol_htmlentitiesbr($object->note_private));
2925 print '</td></tr>';
2926
2927 // Other attributes
2928 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
2929
2930 // Reminders
2931 if ($enablereminders) {
2932 $filteruserid = $user->id;
2933 if ($user->hasRight('agenda', 'allactions', 'read')) {
2934 $filteruserid = 0;
2935 }
2936 $object->loadReminders('', $filteruserid, false);
2937
2938 print '<tr><td class="titlefieldcreate nowrap">'.$langs->trans("Reminders").'</td><td>';
2939
2940 if (count($object->reminders) > 0) {
2941 $tmpuserstatic = new User($db);
2942
2943 foreach ($object->reminders as $actioncommreminderid => $actioncommreminder) {
2944 print $TRemindTypes[$actioncommreminder->typeremind]['label'];
2945 if ($actioncommreminder->fk_user > 0) {
2946 $tmpuserstatic->fetch($actioncommreminder->fk_user);
2947 print ' ('.$tmpuserstatic->getNomUrl(0, '', 0, 0, 16).')';
2948 }
2949 print ' - '.$actioncommreminder->offsetvalue.' '.$TDurationTypes[$actioncommreminder->offsetunit];
2950
2951 if ($actioncommreminder->status == $actioncommreminder::STATUS_TODO) {
2952 print ' - <span class="opacitymedium">';
2953 print $langs->trans("NotSent");
2954 print ' </span>';
2955 } elseif ($actioncommreminder->status == $actioncommreminder::STATUS_DONE) {
2956 print ' - <span class="opacitymedium">';
2957 print $langs->trans("Done");
2958 print ' </span>';
2959 } elseif ($actioncommreminder->status == $actioncommreminder::STATUS_ERROR) {
2960 print ' - <span class="opacitymedium">';
2961 print $form->textwithpicto($langs->trans("Error"), $actioncommreminder->lasterror);
2962 print ' </span>';
2963 }
2964 print '<br>';
2965 }
2966 }
2967
2968 print '</td></tr>';
2969 }
2970
2971 print '</table>';
2972
2973 print '</div>';
2974 print '</div>';
2975 print '<div class="clearboth"></div>';
2976
2977 print dol_get_fiche_end();
2978 }
2979
2980
2981 /*
2982 * Action bar
2983 */
2984 print '<div class="tabsAction">';
2985
2986 $parameters = [];
2987 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2988 if (empty($reshook)) {
2989 if ($action != 'edit') {
2990 if ($user->hasRight('agenda', 'allactions', 'create') ||
2991 (($object->authorid == $user->id || $object->userownerid == $user->id) && $user->hasRight('agenda', 'myactions', 'create'))) {
2992 print '<div class="inline-block divButAction"><a class="butAction" href="card.php?action=edit&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Modify").'</a></div>';
2993 } else {
2994 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Modify").'</a></div>';
2995 }
2996
2997 if ($user->hasRight('agenda', 'allactions', 'create') ||
2998 (($object->authorid == $user->id || $object->userownerid == $user->id) && $user->hasRight('agenda', 'myactions', 'create'))) {
2999 print '<div class="inline-block divButAction"><a class="butAction" href="card.php?action=clone&object='.$object->element.'&id='.$object->id.'">'.$langs->trans("ToClone").'</a></div>';
3000 } else {
3001 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("ToClone").'</a></div>';
3002 }
3003
3004 if ($usercandelete) {
3005 print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?action=delete&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Delete").'</a></div>';
3006 } else {
3007 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Delete").'</a></div>';
3008 }
3009 }
3010 }
3011
3012 print '</div>';
3013
3014 if ($action != 'edit') {
3015 if (!getDolGlobalString('AGENDA_DISABLE_BUILDDOC')) {
3016 print '<div class="clearboth"></div><div class="fichecenter"><div class="fichehalfleft">';
3017 print '<a name="builddoc"></a>'; // ancre
3018
3019 // Generated documents
3020 $filedir = $conf->agenda->multidir_output[$conf->entity].'/'.$object->id;
3021 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
3022
3023 $genallowed = $user->hasRight('agenda', 'myactions', 'read');
3024 $delallowed = $user->hasRight('agenda', 'myactions', 'create');
3025
3026 print $formfile->showdocuments('actions', (string) $object->id, $filedir, $urlsource, $genallowed, $delallowed, '', 0, 0, 0, 0, 0, '', '', '', $langs->getDefaultLang());
3027
3028 if (getDolGlobalString('AGENDA_ENABLE_LINKED_ELEMENTS')) {
3029 // Show links to link elements
3030 $tmparray = $form->showLinkToObjectBlock($object, [], array('myobject'), 1);
3031 if (is_array($tmparray)) {
3032 $linktoelem = $tmparray['linktoelem'];
3033 $htmltoenteralink = $tmparray['htmltoenteralink'];
3034 print $htmltoenteralink;
3035 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
3036 } else {
3037 // backward compatibility
3038 $somethingshown = $form->showLinkedObjectBlock($object, $tmparray);
3039 }
3040 }
3041 print '</div><div class="fichehalfright">';
3042
3043 print '</div></div>';
3044 }
3045 }
3046}
3047
3048// End of page
3049llxFooter();
3050$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:475
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
$object ref
Definition info.php:90
Class to manage agenda events (actions)
Class for ActionCommReminder.
Class to manage different types of events.
Class to manage contact/addresses.
Class to manage a WYSIWYG editor.
Class to manage standard extra fields.
Class to manage building of HTML components.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage building of HTML components.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage tasks.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
dol_get_first_day_week($day, $month, $year, $gm=false)
Return first day of week for a date.
Definition date.lib.php:678
num_between_day($timestampStart, $timestampEnd, $lastday=0)
Function to return number of days between two dates (date must be UTC date !) Example: 2012-01-01 201...
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:125
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
Definition date.lib.php:434
dolGetElementUrl($objectid, $objecttype, $withpicto=0, $option='')
Return link url to an object.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
currentToken()
Return the value of token currently saved into session with name 'token'.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getElementProperties($elementType)
Get an array with properties of an element.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
treeview li table
No Email.
$conf db user
Active Directory does not allow anonymous connections.
Definition repair.php:129
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:125
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:128
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.