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