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