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