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