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