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