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