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