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