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