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