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