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