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