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