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