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