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