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