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