dolibarr  9.0.0
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.dolibarr@gmail.com>
10  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
32 require '../../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
44 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
45 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
46 
47 // Load translation files required by the page
48 $langs->loadLangs(array("companies", "other", "commercial", "bills", "orders", "agenda"));
49 
50 $action=GETPOST('action','alpha');
51 $cancel=GETPOST('cancel','alpha');
52 $backtopage=GETPOST('backtopage','alpha');
53 $socpeopleassigned=GETPOST('socpeopleassigned','array');
54 $origin=GETPOST('origin','alpha');
55 $originid=GETPOST('originid','int');
56 $confirm = GETPOST('confirm', 'alpha');
57 
58 $fulldayevent=GETPOST('fullday');
59 
60 $aphour = GETPOST('aphour');
61 $apmin = GETPOST('apmin');
62 $p2hour = GETPOST('p2hour');
63 $p2min = GETPOST('p2min');
64 
65 $datep=dol_mktime($fulldayevent?'00':$aphour, $fulldayevent?'00':$apmin, 0, GETPOST("apmonth"), GETPOST("apday"), GETPOST("apyear"));
66 $datef=dol_mktime($fulldayevent?'23':$p2hour, $fulldayevent?'59':$p2min, $fulldayevent?'59':'0', GETPOST("p2month"), GETPOST("p2day"), GETPOST("p2year"));
67 
68 // Security check
69 $socid = GETPOST('socid','int');
70 $id = GETPOST('id','int');
71 if ($user->societe_id) $socid=$user->societe_id;
72 $result = restrictedArea($user, 'agenda', $id, 'actioncomm&societe', 'myactions|allactions', 'fk_soc', 'id');
73 if ($user->societe_id && $socid) $result = restrictedArea($user,'societe',$socid);
74 
75 $error=GETPOST("error");
76 $donotclearsession=GETPOST('donotclearsession')?GETPOST('donotclearsession'):0;
77 
78 $cactioncomm = new CActionComm($db);
79 $object = new ActionComm($db);
80 $contact = new Contact($db);
81 $extrafields = new ExtraFields($db);
82 $formfile = new FormFile($db);
83 
84 $form = new Form($db);
85 $formfile = new FormFile($db);
86 $formactions = new FormActions($db);
87 
88 // fetch optionals attributes and labels
89 $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
90 
91 //var_dump($_POST);
92 
93 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
94 $hookmanager->initHooks(array('actioncard','globalcard'));
95 
96 
97 /*
98  * Actions
99  */
100 
101 $listUserAssignedUpdated = false;
102 // Remove user to assigned list
103 if (GETPOST('removedassigned') || GETPOST('removedassigned') == '0')
104 {
105  $idtoremove=GETPOST('removedassigned');
106 
107  if (! empty($_SESSION['assignedtouser'])) $tmpassigneduserids=json_decode($_SESSION['assignedtouser'],1);
108  else $tmpassigneduserids=array();
109 
110  foreach ($tmpassigneduserids as $key => $val)
111  {
112  if ($val['id'] == $idtoremove || $val['id'] == -1) unset($tmpassigneduserids[$key]);
113  }
114  //var_dump($_POST['removedassigned']);exit;
115  $_SESSION['assignedtouser']=json_encode($tmpassigneduserids);
116  $donotclearsession=1;
117  if ($action == 'add') $action = 'create';
118  if ($action == 'update') $action = 'edit';
119 
120  $listUserAssignedUpdated = true;
121 }
122 
123 // Add user to assigned list
124 if (GETPOST('addassignedtouser') || GETPOST('updateassignedtouser'))
125 {
126  // Add a new user
127  if (GETPOST('assignedtouser') > 0)
128  {
129  $assignedtouser=array();
130  if (! empty($_SESSION['assignedtouser']))
131  {
132  $assignedtouser=json_decode($_SESSION['assignedtouser'], true);
133  }
134  $assignedtouser[GETPOST('assignedtouser')]=array('id'=>GETPOST('assignedtouser'), 'transparency'=>GETPOST('transparency'), 'mandatory'=>1);
135  $_SESSION['assignedtouser']=json_encode($assignedtouser);
136  }
137  $donotclearsession=1;
138  if ($action == 'add') $action = 'create';
139  if ($action == 'update') $action = 'edit';
140 
141  $listUserAssignedUpdated = true;
142 }
143 
144 // Link to a project
145 if ($action == 'classin' && ($user->rights->agenda->allactions->create ||
146  (($object->authorid == $user->id || $object->userownerid == $user->id) && $user->rights->agenda->myactions->create)))
147 {
148  $object->fetch($id);
149  $object->setProject(GETPOST('projectid'));
150 }
151 
152 // Action clone object
153 if ($action == 'confirm_clone' && $confirm == 'yes')
154 {
155  if (1 == 0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers'))
156  {
157  setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
158  }
159  else
160  {
161  if ($id > 0) {
162  $object->fetch($id);
163  $result = $object->createFromClone(GETPOST('fk_userowner'), GETPOST('socid'));
164  if ($result > 0) {
165  header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $result);
166  exit();
167  } else {
168  setEventMessages($object->error, $object->errors, 'errors');
169  $action = '';
170  }
171  }
172  }
173 }
174 
175 // Add event
176 if ($action == 'add')
177 {
178  $error=0;
179 
180  if (empty($backtopage))
181  {
182  if ($socid > 0) $backtopage = DOL_URL_ROOT.'/societe/agenda.php?socid='.$socid;
183  else $backtopage=DOL_URL_ROOT.'/comm/action/index.php';
184  }
185 
186  if (!empty($socpeopleassigned[0]))
187  {
188  $result=$contact->fetch($socpeopleassigned[0]);
189  }
190 
191  if ($cancel)
192  {
193  header("Location: ".$backtopage);
194  exit;
195  }
196 
197  $percentage=in_array(GETPOST('status'),array(-1,100))?GETPOST('status'):(in_array(GETPOST('complete'),array(-1,100))?GETPOST('complete'):GETPOST("percentage")); // If status is -1 or 100, percentage is not defined and we must use status
198 
199  // Clean parameters
200  $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'));
201  $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'));
202 
203  // Check parameters
204  if (! $datef && $percentage == 100)
205  {
206  $error++; $donotclearsession=1;
207  $action = 'create';
208  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEnd")), null, 'errors');
209  }
210 
211  if (empty($conf->global->AGENDA_USE_EVENT_TYPE) && ! GETPOST('label'))
212  {
213  $error++; $donotclearsession=1;
214  $action = 'create';
215  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Title")), null, 'errors');
216  }
217 
218  // Initialisation objet cactioncomm
219  if (! GETPOST('actioncode') > 0) // actioncode is id
220  {
221  $error++; $donotclearsession=1;
222  $action = 'create';
223  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
224  }
225  else
226  {
227  $object->type_code = GETPOST('actioncode');
228  }
229 
230  if (! $error)
231  {
232  // Initialisation objet actioncomm
233  $object->priority = GETPOST("priority")?GETPOST("priority"):0;
234  $object->fulldayevent = (! empty($fulldayevent)?1:0);
235  $object->location = GETPOST("location");
236  $object->label = trim(GETPOST('label'));
237  $object->fk_element = GETPOST("fk_element");
238  $object->elementtype = GETPOST("elementtype");
239  if (! GETPOST('label'))
240  {
241  if (GETPOST('actioncode') == 'AC_RDV' && $contact->getFullName($langs))
242  {
243  $object->label = $langs->transnoentitiesnoconv("TaskRDVWith",$contact->getFullName($langs));
244  }
245  else
246  {
247  if ($langs->trans("Action".$object->type_code) != "Action".$object->type_code)
248  {
249  $object->label = $langs->transnoentitiesnoconv("Action".$object->type_code)."\n";
250  }
251  else $object->label = $cactioncomm->libelle;
252  }
253  }
254  $object->fk_project = isset($_POST["projectid"])?$_POST["projectid"]:0;
255 
256  $taskid = GETPOST('taskid','int');
257  if(!empty($taskid)){
258 
259  $taskProject = new Task($db);
260  if($taskProject->fetch($taskid)>0){
261  $object->fk_project = $taskProject->fk_project;
262  }
263 
264  $object->fk_element = $taskid;
265  $object->elementtype = 'task';
266  }
267 
268  $object->datep = $datep;
269  $object->datef = $datef;
270  $object->percentage = $percentage;
271  $object->duree=((float) (GETPOST('dureehour') * 60) + (float) GETPOST('dureemin')) * 60;
272 
273  $transparency=(GETPOST("transparency")=='on'?1:0);
274 
275  $listofuserid=array();
276  if (! empty($_SESSION['assignedtouser'])) $listofuserid=json_decode($_SESSION['assignedtouser'], true);
277  $i=0;
278  foreach($listofuserid as $key => $value)
279  {
280  if ($i == 0) // First entry
281  {
282  if ($value['id'] > 0) $object->userownerid=$value['id'];
283  $object->transparency = $transparency;
284  }
285 
286  $object->userassigned[$value['id']]=array('id'=>$value['id'], 'transparency'=>$transparency);
287 
288  $i++;
289  }
290  }
291 
292  if (! $error && ! empty($conf->global->AGENDA_ENABLE_DONEBY))
293  {
294  if (GETPOST("doneby") > 0) $object->userdoneid = GETPOST("doneby","int");
295  }
296 
297  $object->note = trim(GETPOST("note"));
298 
299  if (isset($_POST["contactid"])) $object->contact = $contact;
300 
301  if (GETPOST('socid','int') > 0)
302  {
303  $object->socid=GETPOST('socid','int');
304  $object->fetch_thirdparty();
305 
306  $object->societe = $object->thirdparty; // For backward compatibility
307  }
308 
309  // Check parameters
310  if (empty($object->userownerid) && empty($_SESSION['assignedtouser']))
311  {
312  $error++; $donotclearsession=1;
313  $action = 'create';
314  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ActionsOwnedBy")), null, 'errors');
315  }
316  if ($object->type_code == 'AC_RDV' && ($datep == '' || ($datef == '' && empty($fulldayevent))))
317  {
318  $error++; $donotclearsession=1;
319  $action = 'create';
320  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEnd")), null, 'errors');
321  }
322 
323  if (! GETPOST('apyear') && ! GETPOST('adyear'))
324  {
325  $error++; $donotclearsession=1;
326  $action = 'create';
327  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
328  }
329 
330  foreach ($socpeopleassigned as $cid)
331  {
332  $object->socpeopleassigned[$cid] = array('id' => $cid);
333  }
334  if (!empty($object->socpeopleassigned))
335  {
336  reset($object->socpeopleassigned);
337  $object->contactid = key($object->socpeopleassigned);
338  }
339 
340  // Fill array 'array_options' with data from add form
341  $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
342  if ($ret < 0) $error++;
343 
344  if (! $error)
345  {
346  $db->begin();
347 
348  // On cree l'action
349  $idaction=$object->create($user);
350 
351  if ($idaction > 0)
352  {
353  if (! $object->error)
354  {
355  unset($_SESSION['assignedtouser']);
356 
357  $moreparam='';
358  if ($user->id != $object->userownerid) $moreparam="filtert=-1"; // We force to remove filter so created record is visible when going back to per user view.
359 
360  $db->commit();
361  if (! empty($backtopage))
362  {
363  dol_syslog("Back to ".$backtopage.($moreparam?(preg_match('/\?/',$backtopage)?'&'.$moreparam:'?'.$moreparam):''));
364  header("Location: ".$backtopage.($moreparam?(preg_match('/\?/',$backtopage)?'&'.$moreparam:'?'.$moreparam):''));
365  }
366  elseif($idaction)
367  {
368  header("Location: ".DOL_URL_ROOT.'/comm/action/card.php?id='.$idaction.($moreparam?'&'.$moreparam:''));
369  }
370  else
371  {
372  header("Location: ".DOL_URL_ROOT.'/comm/action/index.php'.($moreparam?'?'.$moreparam:''));
373  }
374  exit;
375  }
376  else
377  {
378  // If error
379  $db->rollback();
380  $langs->load("errors");
381  $error=$langs->trans($object->error);
382  setEventMessages($error, null, 'errors');
383  $action = 'create'; $donotclearsession=1;
384  }
385  }
386  else
387  {
388  $db->rollback();
389  setEventMessages($object->error, $object->errors, 'errors');
390  $action = 'create'; $donotclearsession=1;
391  }
392  }
393 }
394 
395 /*
396  * Action update event
397  */
398 if ($action == 'update')
399 {
400  if (empty($cancel))
401  {
402  $fulldayevent=GETPOST('fullday');
403  $aphour=GETPOST('aphour');
404  $apmin=GETPOST('apmin');
405  $p2hour=GETPOST('p2hour');
406  $p2min=GETPOST('p2min');
407  $percentage=in_array(GETPOST('status'),array(-1,100))?GETPOST('status'):(in_array(GETPOST('complete'),array(-1,100))?GETPOST('complete'):GETPOST("percentage")); // If status is -1 or 100, percentage is not defined and we must use status
408 
409  // Clean parameters
410  if ($aphour == -1) $aphour='0';
411  if ($apmin == -1) $apmin='0';
412  if ($p2hour == -1) $p2hour='0';
413  if ($p2min == -1) $p2min='0';
414 
415  $object->fetch($id);
416  $object->fetch_userassigned();
417 
418  $datep=dol_mktime($fulldayevent?'00':$aphour, $fulldayevent?'00':$apmin, 0, $_POST["apmonth"], $_POST["apday"], $_POST["apyear"]);
419  $datef=dol_mktime($fulldayevent?'23':$p2hour, $fulldayevent?'59':$p2min, $fulldayevent?'59':'0', $_POST["p2month"], $_POST["p2day"], $_POST["p2year"]);
420 
421  $object->type_id = dol_getIdFromCode($db, GETPOST("actioncode"), 'c_actioncomm');
422  $object->label = GETPOST("label");
423  $object->datep = $datep;
424  $object->datef = $datef;
425  $object->percentage = $percentage;
426  $object->priority = GETPOST("priority");
427  $object->fulldayevent= GETPOST("fullday")?1:0;
428  $object->location = GETPOST('location');
429  $object->socid = GETPOST("socid");
430  $socpeopleassigned = GETPOST("socpeopleassigned",'array');
431  $object->socpeopleassigned = array();
432  foreach ($socpeopleassigned as $cid) $object->socpeopleassigned[$cid] = array('id' => $cid);
433  $object->contactid = GETPOST("contactid",'int');
434  $object->fk_project = GETPOST("projectid",'int');
435  $object->note = GETPOST("note","none"); // deprecated
436  $object->note_private= GETPOST("note","none");
437  $object->fk_element = GETPOST("fk_element");
438  $object->elementtype = GETPOST("elementtype");
439 
440  if (! $datef && $percentage == 100)
441  {
442  $error++; $donotclearsession=1;
443  setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("DateEnd")),$object->errors,'errors');
444  $action = 'edit';
445  }
446 
447  $transparency=(GETPOST("transparency")=='on'?1:0);
448 
449  // Users
450  $listofuserid=array();
451  if (! empty($_SESSION['assignedtouser'])) // Now concat assigned users
452  {
453  // Restore array with key with same value than param 'id'
454  $tmplist1=json_decode($_SESSION['assignedtouser'], true);
455  foreach($tmplist1 as $key => $val)
456  {
457  if ($val['id'] > 0 && $val['id'] != $assignedtouser) $listofuserid[$val['id']]=$val;
458  }
459  }
460  else {
461  $assignedtouser=(! empty($object->userownerid) && $object->userownerid > 0 ? $object->userownerid : 0);
462  if ($assignedtouser) $listofuserid[$assignedtouser]=array('id'=>$assignedtouser, 'mandatory'=>0, 'transparency'=>($user->id == $assignedtouser ? $transparency : '')); // Owner first
463  }
464  $object->userassigned=array(); $object->userownerid=0; // Clear old content
465  $i=0;
466  foreach($listofuserid as $key => $val)
467  {
468  if ($i == 0) $object->userownerid = $val['id'];
469  $object->userassigned[$val['id']]=array('id'=>$val['id'], 'mandatory'=>0, 'transparency'=>($user->id == $val['id'] ? $transparency : ''));
470  $i++;
471  }
472 
473  $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)
474  // TODO store also transparency on owner user
475 
476  if (! empty($conf->global->AGENDA_ENABLE_DONEBY))
477  {
478  if (GETPOST("doneby")) $object->userdoneid=GETPOST("doneby","int");
479  }
480 
481  // Check parameters
482  if (! GETPOST('actioncode') > 0)
483  {
484  $error++; $donotclearsession=1;
485  $action = 'edit';
486  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
487  }
488  else
489  {
490  $result=$cactioncomm->fetch(GETPOST('actioncode'));
491  }
492  if (empty($object->userownerid))
493  {
494  $error++; $donotclearsession=1;
495  $action = 'edit';
496  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ActionsOwnedBy")), null, 'errors');
497  }
498 
499  // Fill array 'array_options' with data from add form
500  $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
501  if ($ret < 0) $error++;
502 
503  if (! $error)
504  {
505  $db->begin();
506 
507  $result=$object->update($user);
508 
509  if ($result > 0)
510  {
511  unset($_SESSION['assignedtouser']);
512 
513  $db->commit();
514  }
515  else
516  {
517  setEventMessages($object->error,$object->errors,'errors');
518  $db->rollback();
519  }
520  }
521  }
522 
523  if (! $error)
524  {
525  if (! empty($backtopage))
526  {
527  unset($_SESSION['assignedtouser']);
528  header("Location: ".$backtopage);
529  exit;
530  }
531  }
532 }
533 
534 /*
535  * delete event
536  */
537 if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes')
538 {
539  $object->fetch($id);
540 
541  if ($user->rights->agenda->myactions->delete
542  || $user->rights->agenda->allactions->delete)
543  {
544  $result=$object->delete();
545 
546  if ($result >= 0)
547  {
548  header("Location: index.php");
549  exit;
550  }
551  else
552  {
553  setEventMessages($object->error,$object->errors,'errors');
554  }
555  }
556 }
557 
558 /*
559  * Action move update, used when user move an event in calendar by drag'n drop
560  * TODO Move this into page comm/action/index that trigger this call by the drag and drop of event.
561  */
562 if (GETPOST('actionmove','alpha') == 'mupdate')
563 {
564  $object->fetch($id);
565  $object->fetch_userassigned();
566 
567  $shour = dol_print_date($object->datep,"%H");
568  $smin = dol_print_date($object->datep, "%M");
569 
570  $newdate=GETPOST('newdate','alpha');
571  if (empty($newdate) || strpos($newdate,'dayevent_') != 0 )
572  {
573  header("Location: ".$backtopage);
574  exit;
575  }
576 
577  $datep=dol_mktime($shour, $smin, 0, substr($newdate,13,2), substr($newdate,15,2), substr($newdate,9,4));
578  if ($datep!=$object->datep)
579  {
580  if (!empty($object->datef))
581  {
582  $object->datef+=$datep-$object->datep;
583  }
584  $object->datep=$datep;
585  $result=$object->update($user);
586  if ($result < 0)
587  {
588  setEventMessages($object->error, $object->errors, 'errors');
589  }
590  }
591  if (! empty($backtopage))
592  {
593  header("Location: ".$backtopage);
594  exit;
595  }
596  else
597  {
598  $action='';
599  }
600 }
601 
602 // Actions to delete doc
603 $upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($object->ref);
604 $permissioncreate = ($user->rights->agenda->allactions->create || (($object->authorid == $user->id || $object->userownerid == $user->id) && $user->rights->agenda->myactions->read));
605 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
606 
607 
608 /*
609  * View
610  */
611 
612 $form=new Form($db);
613 $formproject=new FormProjets($db);
614 
615 $help_url='EN:Module_Agenda_En|FR:Module_Agenda|ES:M&omodulodulo_Agenda';
616 llxHeader('',$langs->trans("Agenda"),$help_url);
617 
618 if ($action == 'create')
619 {
620  $contact = new Contact($db);
621 
622  $socpeopleassigned = GETPOST("socpeopleassigned", 'array');
623  if (!empty($socpeopleassigned[0]))
624  {
625  $result=$contact->fetch($socpeopleassigned[0]);
626  if ($result < 0) dol_print_error($db,$contact->error);
627  }
628 
629  dol_set_focus("#label");
630 
631  if (! empty($conf->use_javascript_ajax))
632  {
633  print "\n".'<script type="text/javascript">';
634  print '$(document).ready(function () {
635  function setdatefields()
636  {
637  if ($("#fullday:checked").val() == null) {
638  $(".fulldaystarthour").removeAttr("disabled");
639  $(".fulldaystartmin").removeAttr("disabled");
640  $(".fulldayendhour").removeAttr("disabled");
641  $(".fulldayendmin").removeAttr("disabled");
642  $("#p2").removeAttr("disabled");
643  } else {
644  $(".fulldaystarthour").prop("disabled", true).val("00");
645  $(".fulldaystartmin").prop("disabled", true).val("00");
646  $(".fulldayendhour").prop("disabled", true).val("23");
647  $(".fulldayendmin").prop("disabled", true).val("59");
648  $("#p2").removeAttr("disabled");
649  }
650  }
651  setdatefields();
652  $("#fullday").change(function() {
653  setdatefields();
654  });
655  $("#selectcomplete").change(function() {
656  if ($("#selectcomplete").val() == 100)
657  {
658  if ($("#doneby").val() <= 0) $("#doneby").val(\''.$user->id.'\');
659  }
660  if ($("#selectcomplete").val() == 0)
661  {
662  $("#doneby").val(-1);
663  }
664  });
665  $("#actioncode").change(function() {
666  if ($("#actioncode").val() == \'AC_RDV\') $("#dateend").addClass("fieldrequired");
667  else $("#dateend").removeClass("fieldrequired");
668  });
669  })';
670  print '</script>'."\n";
671  }
672 
673  print '<form name="formaction" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
674  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
675  print '<input type="hidden" name="action" value="add">';
676  print '<input type="hidden" name="donotclearsession" value="1">';
677  if ($backtopage) print '<input type="hidden" name="backtopage" value="'.($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]).'">';
678  if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) print '<input type="hidden" name="actioncode" value="'.dol_getIdFromCode($db, 'AC_OTH', 'c_actioncomm').'">';
679 
680  if (GETPOST("actioncode") == 'AC_RDV') print load_fiche_titre($langs->trans("AddActionRendezVous"), '', 'title_agenda');
681  else print load_fiche_titre($langs->trans("AddAnAction"), '', 'title_agenda');
682 
683  dol_fiche_head();
684 
685  print '<table class="border" width="100%">';
686 
687  // Type of event
688  if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
689  {
690  print '<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans("Type").'</span></b></td><td>';
691  $default=(empty($conf->global->AGENDA_USE_EVENT_TYPE_DEFAULT)?'':$conf->global->AGENDA_USE_EVENT_TYPE_DEFAULT);
692  $formactions->select_type_actions(GETPOST("actioncode")?GETPOST("actioncode"):($object->type_code?$object->type_code:$default), "actioncode", "systemauto", 0, -1);
693  print '</td></tr>';
694  }
695 
696  // Title
697  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>';
698 
699  // Full day
700  print '<tr><td>'.$langs->trans("EventOnFullDay").'</td><td><input type="checkbox" id="fullday" name="fullday" '.(GETPOST('fullday')?' checked':'').'></td></tr>';
701 
702  // Date start
703  $datep=($datep?$datep:$object->datep);
704  if (GETPOST('datep','int',1)) $datep=dol_stringtotime(GETPOST('datep','int',1),0);
705  print '<tr><td class="nowrap"><span class="fieldrequired">'.$langs->trans("DateActionStart").'</span></td><td>';
706  if (GETPOST("afaire") == 1) {
707  print $form->selectDate($datep, 'ap', 1, 1, 0, "action", 1, 1, 0, 'fulldayend');
708  } elseif (GETPOST("afaire") == 2) {
709  print $form->selectDate($datep, 'ap', 1, 1, 1, "action", 1, 1, 0, 'fulldayend');
710  } else {
711  print $form->selectDate($datep, 'ap', 1, 1, 1, "action", 1, 1, 0, 'fulldaystart');
712  }
713  print '</td></tr>';
714 
715  // Date end
716  $datef=($datef?$datef:$object->datef);
717  if (GETPOST('datef','int',1)) $datef=dol_stringtotime(GETPOST('datef','int',1),0);
718  if (empty($datef) && ! empty($datep) && ! empty($conf->global->AGENDA_AUTOSET_END_DATE_WITH_DELTA_HOURS))
719  {
720  $datef=dol_time_plus_duree($datep, $conf->global->AGENDA_AUTOSET_END_DATE_WITH_DELTA_HOURS, 'h');
721  }
722  print '<tr><td><span id="dateend"'.(GETPOST("actioncode") == 'AC_RDV'?' class="fieldrequired"':'').'>'.$langs->trans("DateActionEnd").'</span></td><td>';
723  if (GETPOST("afaire") == 1) {
724  print $form->selectDate($datef, 'p2', 1, 1, 1, "action", 1, 1, 0, 'fulldayend');
725  } elseif (GETPOST("afaire") == 2) {
726  print $form->selectDate($datef, 'p2', 1, 1, 1, "action", 1, 1, 0, 'fulldayend');
727  } else {
728  print $form->selectDate($datef, 'p2', 1, 1, 1, "action", 1, 1, 0, 'fulldayend');
729  }
730  print '</td></tr>';
731 
732  // Dev in progress
733  $userepeatevent=($conf->global->MAIN_FEATURES_LEVEL == 2 ? 1 : 0);
734  if ($userepeatevent)
735  {
736  // Repeat
737  print '<tr><td>'.$langs->trans("RepeatEvent").'</td><td colspan="3">';
738  print '<input type="hidden" name="recurid" value="'.$object->recurid.'">';
739  $arrayrecurrulefreq=array(
740  'no'=>$langs->trans("No"),
741  'MONTHLY'=>$langs->trans("EveryMonth"),
742  'WEEKLY'=>$langs->trans("EveryWeek"),
743  //'DAYLY'=>$langs->trans("EveryDay")
744  );
745  $selectedrecurrulefreq='no';
746  $selectedrecurrulebymonthday='';
747  $selectedrecurrulebyday='';
748  if ($object->recurrule && preg_match('/FREQ=([A-Z]+)/i',$object->recurrule,$reg)) $selectedrecurrulefreq=$reg[1];
749  if ($object->recurrule && preg_match('/FREQ=MONTHLY.*BYMONTHDAY=(\d+)/i',$object->recurrule,$reg)) $selectedrecurrulebymonthday=$reg[1];
750  if ($object->recurrule && preg_match('/FREQ=WEEKLY.*BYDAY(\d+)/i',$object->recurrule,$reg)) $selectedrecurrulebyday=$reg[1];
751  print $form->selectarray('recurrulefreq', $arrayrecurrulefreq, $selectedrecurrulefreq, 0, 0, 0, '', 0, 0, 0, '', 'marginrightonly');
752  // If recurrulefreq is MONTHLY
753  print '<div class="hidden marginrightonly inline-block repeateventBYMONTHDAY">';
754  print $langs->trans("DayOfMonth").': <input type="input" size="2" name="BYMONTHDAY" value="'.$selectedrecurrulebymonthday.'">';
755  print '</div>';
756  // If recurrulefreq is WEEKLY
757  print '<div class="hidden marginrightonly inline-block repeateventBYDAY">';
758  print $langs->trans("DayOfWeek").': <input type="input" size="4" name="BYDAY" value="'.$selectedrecurrulebyday.'">';
759  print '</div>';
760  print '<script type="text/javascript" language="javascript">
761  jQuery(document).ready(function() {
762  function init_repeat()
763  {
764  if (jQuery("#recurrulefreq").val() == \'MONTHLY\')
765  {
766  jQuery(".repeateventBYMONTHDAY").css("display", "inline-block"); /* use this instead of show because we want inline-block and not block */
767  jQuery(".repeateventBYDAY").hide();
768  }
769  else if (jQuery("#recurrulefreq").val() == \'WEEKLY\')
770  {
771  jQuery(".repeateventBYMONTHDAY").hide();
772  jQuery(".repeateventBYDAY").css("display", "inline-block"); /* use this instead of show because we want inline-block and not block */
773  }
774  else
775  {
776  jQuery(".repeateventBYMONTHDAY").hide();
777  jQuery(".repeateventBYDAY").hide();
778  }
779  }
780  init_repeat();
781  jQuery("#recurrulefreq").change(function() {
782  init_repeat();
783  });
784  });
785  </script>';
786  print '</td></tr>';
787  }
788 
789  // Status
790  print '<tr><td>'.$langs->trans("Status").' / '.$langs->trans("Percentage").'</td>';
791  print '<td>';
792  $percent=-1;
793  if (isset($_GET['status']) || isset($_POST['status'])) $percent=GETPOST('status');
794  else if (isset($_GET['percentage']) || isset($_POST['percentage'])) $percent=GETPOST('percentage');
795  else
796  {
797  if (GETPOST('complete') == '0' || GETPOST("afaire") == 1) $percent='0';
798  else if (GETPOST('complete') == 100 || GETPOST("afaire") == 2) $percent=100;
799  }
800  $formactions->form_select_status_action('formaction', $percent, 1, 'complete', 0, 0, 'maxwidth200');
801  print '</td></tr>';
802 
803  // Location
804  if (empty($conf->global->AGENDA_DISABLE_LOCATION))
805  {
806  print '<tr><td>'.$langs->trans("Location").'</td><td colspan="3"><input type="text" name="location" class="soixantepercent" value="'.(GETPOST('location')?GETPOST('location'):$object->location).'"></td></tr>';
807  }
808 
809  // Assigned to
810  print '<tr><td class="tdtop nowrap">'.$langs->trans("ActionAffectedTo").'</td><td>';
811  $listofuserid=array();
812  if (empty($donotclearsession))
813  {
814  $assignedtouser=GETPOST("assignedtouser")?GETPOST("assignedtouser"):(! empty($object->userownerid) && $object->userownerid > 0 ? $object->userownerid : $user->id);
815  if ($assignedtouser) $listofuserid[$assignedtouser]=array('id'=>$assignedtouser,'mandatory'=>0,'transparency'=>$object->transparency); // Owner first
816  $listofuserid[$user->id]['transparency']=GETPOSTISSET('transparency')?GETPOST('transparency','alpha'):1; // 1 by default at first init
817  $_SESSION['assignedtouser']=json_encode($listofuserid);
818  }
819  else
820  {
821  if (!empty($_SESSION['assignedtouser']))
822  {
823  $listofuserid=json_decode($_SESSION['assignedtouser'], true);
824  }
825  $listofuserid[$user->id]['transparency']=GETPOSTISSET('transparency')?GETPOST('transparency','alpha'):0; // 0 by default when refreshing
826  }
827  print '<div class="assignedtouser">';
828  print $form->select_dolusers_forevent(($action=='create'?'add':'update'), 'assignedtouser', 1, '', 0, '', '', 0, 0, 0, 'AND u.statut != 0', 1, $listofuserid, $listofcontactid, $listofotherid);
829  print '</div>';
830  /*if (in_array($user->id,array_keys($listofuserid)))
831  {
832  print '<div class="myavailability">';
833  print $langs->trans("MyAvailability").': <input id="transparency" type="checkbox" name="transparency"'.(((! isset($_GET['transparency']) && ! isset($_POST['transparency'])) || GETPOST('transparency'))?' checked':'').'> '.$langs->trans("Busy");
834  print '</div>';
835  }*/
836  print '</td></tr>';
837 
838  // Realised by
839  if (! empty($conf->global->AGENDA_ENABLE_DONEBY))
840  {
841  print '<tr><td class="nowrap">'.$langs->trans("ActionDoneBy").'</td><td>';
842  print $form->select_dolusers(GETPOST("doneby")?GETPOST("doneby"):(! empty($object->userdoneid) && $percent==100?$object->userdoneid:0),'doneby',1);
843  print '</td></tr>';
844  }
845 
846  print '</table>';
847 
848 
849  print '<br><hr><br>';
850 
851 
852  print '<table class="border" width="100%">';
853 
854  if ($conf->societe->enabled)
855  {
856  // Related company
857  print '<tr><td class="titlefieldcreate nowrap">'.$langs->trans("ActionOnCompany").'</td><td>';
858  if (GETPOST('socid','int') > 0)
859  {
860  $societe = new Societe($db);
861  $societe->fetch(GETPOST('socid','int'));
862  print $societe->getNomUrl(1);
863  print '<input type="hidden" id="socid" name="socid" value="'.GETPOST('socid','int').'">';
864  }
865  else
866  {
867  $events=array();
868  $events[]=array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1',1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
869  //For external user force the company to user company
870  if (!empty($user->societe_id)) {
871  print $form->select_company($user->societe_id, 'socid', '', 1, 1, 0, $events, 0, 'minwidth300');
872  } else {
873  print $form->select_company('', 'socid', '', 'SelectThirdParty', 1, 0, $events, 0, 'minwidth300');
874  }
875  }
876  print '</td></tr>';
877 
878  // Related contact
879  print '<tr><td class="nowrap">'.$langs->trans("ActionOnContact").'</td><td>';
880  $preselectedids=GETPOST('socpeopleassigned', 'array');
881  if (GETPOST('contactid','int')) $preselectedids[GETPOST('contactid','int')]=GETPOST('contactid','int');
882  print $form->selectcontacts(GETPOST('socid','int'), $preselectedids, 'socpeopleassigned[]', 1, '', '', 0, 'quatrevingtpercent', false, 0, array(), false, 'multiple', 'contactid');
883  print '</td></tr>';
884  }
885 
886  // Project
887  if (! empty($conf->projet->enabled))
888  {
889  // Projet associe
890  $langs->load("projects");
891 
892  $projectid = GETPOST('projectid', 'int');
893 
894  print '<tr><td class="titlefieldcreate">'.$langs->trans("Project").'</td><td id="project-input-container" >';
895 
896  $numproject=$formproject->select_projects((! empty($societe->id)?$societe->id:-1), $projectid, 'projectid', 0, 0, 1, 1);
897 
898  print ' &nbsp; <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$societe->id.'&action=create">'.$langs->trans("AddProject").'</a>';
899  $urloption='?action=create';
900  $url = dol_buildpath('comm/action/card.php',2).$urloption;
901 
902  // update task list
903  print "\n".'<script type="text/javascript">';
904  print '$(document).ready(function () {
905  $("#projectid").change(function () {
906  var url = "'.$url.'&projectid="+$("#projectid").val();
907  $.get(url, function(data) {
908  console.log($( data ).find("#taskid").html());
909  if (data) $("#taskid").html( $( data ).find("#taskid").html() ).select2();
910  })
911  });
912  })';
913  print '</script>'."\n";
914 
915  print '</td></tr>';
916 
917  print '<tr><td class="titlefieldcreate">'.$langs->trans("Task").'</td><td id="project-task-input-container" >';
918 
919  $projectsListId=false;
920  if(!empty($projectid)){ $projectsListId=$projectid; }
921  $tid=GETPOST("projecttaskid")?GETPOST("projecttaskid"):'';
922  $formproject->selectTasks((! empty($societe->id)?$societe->id:-1), $tid, 'taskid', 24, 0, '1', 1, 0, 0, 'maxwidth500',$projectsListId);
923  print '</td></tr>';
924  }
925  if (!empty($origin) && !empty($originid))
926  {
927  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
928  print '<tr><td class="titlefieldcreate">'.$langs->trans("LinkedObject").'</td>';
929  print '<td colspan="3">'.dolGetElementUrl($originid,$origin,1).'</td></tr>';
930  print '<input type="hidden" name="fk_element" size="10" value="'.GETPOST('originid').'">';
931  print '<input type="hidden" name="elementtype" size="10" value="'.GETPOST('origin').'">';
932  print '<input type="hidden" name="originid" size="10" value="'.GETPOST('originid').'">';
933  print '<input type="hidden" name="origin" size="10" value="'.GETPOST('origin').'">';
934  }
935 
936  if (GETPOST("datep") && preg_match('/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])$/',GETPOST("datep"),$reg))
937  {
938  $object->datep=dol_mktime(0,0,0,$reg[2],$reg[3],$reg[1]);
939  }
940 
941  // Priority
942  print '<tr><td class="titlefieldcreate nowrap">'.$langs->trans("Priority").'</td><td colspan="3">';
943  print '<input type="text" name="priority" value="'.(GETPOST('priority')?GETPOST('priority'):($object->priority?$object->priority:'')).'" size="5">';
944  print '</td></tr>';
945 
946  // Description
947  print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
948  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
949  $doleditor=new DolEditor('note',(GETPOST('note','none')?GETPOST('note','none'):$object->note),'',180,'dolibarr_notes','In',true,true,$conf->fckeditor->enabled,ROWS_4,'90%');
950  $doleditor->Create();
951  print '</td></tr>';
952 
953  // Other attributes
954  $parameters=array();
955  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
956  print $hookmanager->resPrint;
957  if (empty($reshook))
958  {
959  print $object->showOptionals($extrafields,'edit');
960  }
961 
962  print '</table>';
963 
964  dol_fiche_end();
965 
966  print '<div class="center">';
967  print '<input type="submit" class="button" value="'.$langs->trans("Add").'">';
968  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
969  print '<input type="button" class="button" name="cancel" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
970  print '</div>';
971 
972  print "</form>";
973 }
974 
975 // View or edit
976 if ($id > 0)
977 {
978  $result1=$object->fetch($id);
979  if ($result1 <= 0)
980  {
981  $langs->load("errors");
982  print $langs->trans("ErrorRecordNotFound");
983 
984  llxFooter();
985  exit;
986  }
987 
988  $result2=$object->fetch_thirdparty();
989  $result2=$object->fetch_projet();
990  $result3=$object->fetch_contact();
991  $result4=$object->fetch_userassigned();
992  $result5=$object->fetch_optionals();
993 
994  if ($listUserAssignedUpdated || $donotclearsession)
995  {
996  $percentage=in_array(GETPOST('status'),array(-1,100))?GETPOST('status'):(in_array(GETPOST('complete'),array(-1,100))?GETPOST('complete'):GETPOST("percentage")); // If status is -1 or 100, percentage is not defined and we must use status
997 
998  $datep=dol_mktime($fulldayevent?'00':$aphour, $fulldayevent?'00':$apmin, 0, $_POST["apmonth"], $_POST["apday"], $_POST["apyear"]);
999  $datef=dol_mktime($fulldayevent?'23':$p2hour, $fulldayevent?'59':$p2min, $fulldayevent?'59':'0', $_POST["p2month"], $_POST["p2day"], $_POST["p2year"]);
1000 
1001  $object->type_id = dol_getIdFromCode($db, GETPOST("actioncode"), 'c_actioncomm');
1002  $object->label = GETPOST("label");
1003  $object->datep = $datep;
1004  $object->datef = $datef;
1005  $object->percentage = $percentage;
1006  $object->priority = GETPOST("priority");
1007  $object->fulldayevent= GETPOST("fullday")?1:0;
1008  $object->location = GETPOST('location');
1009  $object->socid = GETPOST("socid");
1010  $socpeopleassigned = GETPOST("socpeopleassigned",'array');
1011  foreach ($socpeopleassigned as $tmpid) $object->socpeopleassigned[$id] = array('id' => $tmpid);
1012  $object->contactid = GETPOST("contactid",'int');
1013  $object->fk_project = GETPOST("projectid",'int');
1014 
1015  $object->note = GETPOST("note",'none');
1016  }
1017 
1018  if ($result2 < 0 || $result3 < 0 || $result4 < 0 || $result5 < 0)
1019  {
1020  dol_print_error($db,$object->error);
1021  exit;
1022  }
1023 
1024  if ($object->authorid > 0) { $tmpuser=new User($db); $res=$tmpuser->fetch($object->authorid); $object->author=$tmpuser; }
1025  if ($object->usermodid > 0) { $tmpuser=new User($db); $res=$tmpuser->fetch($object->usermodid); $object->usermod=$tmpuser; }
1026 
1027 
1028  /*
1029  * Show tabs
1030  */
1031 
1032  $head=actions_prepare_head($object);
1033 
1034  $now=dol_now();
1035  $delay_warning=$conf->global->MAIN_DELAY_ACTIONS_TODO*24*60*60;
1036 
1037  // Confirmation suppression action
1038  if ($action == 'delete')
1039  {
1040  print $form->formconfirm("card.php?id=".$id,$langs->trans("DeleteAction"),$langs->trans("ConfirmDeleteAction"),"confirm_delete",'','',1);
1041  }
1042 
1043  if ($action == 'edit')
1044  {
1045  if (! empty($conf->use_javascript_ajax))
1046  {
1047  print "\n".'<script type="text/javascript">';
1048  print '$(document).ready(function () {
1049  function setdatefields()
1050  {
1051  if ($("#fullday:checked").val() == null) {
1052  $(".fulldaystarthour").removeAttr("disabled");
1053  $(".fulldaystartmin").removeAttr("disabled");
1054  $(".fulldayendhour").removeAttr("disabled");
1055  $(".fulldayendmin").removeAttr("disabled");
1056  } else {
1057  $(".fulldaystarthour").prop("disabled", true).val("00");
1058  $(".fulldaystartmin").prop("disabled", true).val("00");
1059  $(".fulldayendhour").prop("disabled", true).val("23");
1060  $(".fulldayendmin").prop("disabled", true).val("59");
1061  }
1062  }
1063  setdatefields();
1064  $("#fullday").change(function() {
1065  setdatefields();
1066  });
1067  })';
1068  print '</script>'."\n";
1069  }
1070 
1071  print '<form name="formaction" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
1072  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1073  print '<input type="hidden" name="action" value="update">';
1074  print '<input type="hidden" name="id" value="'.$id.'">';
1075  print '<input type="hidden" name="ref_ext" value="'.$object->ref_ext.'">';
1076  if ($backtopage) print '<input type="hidden" name="backtopage" value="'.($backtopage != '1'? $backtopage : $_SERVER["HTTP_REFERER"]).'">';
1077  if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) print '<input type="hidden" name="actioncode" value="'.$object->type_code.'">';
1078 
1079  dol_fiche_head($head, 'card', $langs->trans("Action"),0,'action');
1080 
1081  print '<table class="border" width="100%">';
1082 
1083  // Ref
1084  print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td colspan="3">'.$object->id.'</td></tr>';
1085 
1086  // Type of event
1087  if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
1088  {
1089  print '<tr><td class="fieldrequired">'.$langs->trans("Type").'</td><td colspan="3">';
1090  if ($object->type_code != 'AC_OTH_AUTO')
1091  {
1092  $formactions->select_type_actions(GETPOST("actioncode")?GETPOST("actioncode"):$object->type_code, "actioncode","systemauto");
1093  }
1094  else
1095  {
1096  print '<input type="hidden" name="actioncode" value="'.$object->type_code.'">'.$langs->trans("Action".$object->type_code);
1097  }
1098  print '</td></tr>';
1099  }
1100 
1101  // Title
1102  print '<tr><td class="fieldrequired">'.$langs->trans("Title").'</td><td colspan="3"><input type="text" name="label" class="soixantepercent" value="'.$object->label.'"></td></tr>';
1103 
1104  // Full day event
1105  print '<tr><td>'.$langs->trans("EventOnFullDay").'</td><td colspan="3"><input type="checkbox" id="fullday" name="fullday" '.($object->fulldayevent?' checked':'').'></td></tr>';
1106 
1107  // Date start
1108  print '<tr><td class="nowrap"><span class="fieldrequired">'.$langs->trans("DateActionStart").'</span></td><td colspan="3">';
1109  if (GETPOST("afaire") == 1) {
1110  print $form->selectDate($datep?$datep:$object->datep, 'ap', 1, 1, 0, "action", 1, 1, 0, 'fulldaystart');
1111  } elseif (GETPOST("afaire") == 2) {
1112  print $form->selectDate($datep?$datep:$object->datep, 'ap', 1, 1, 1, "action", 1, 1, 0, 'fulldaystart');
1113  } else {
1114  print $form->selectDate($datep?$datep:$object->datep, 'ap', 1, 1, 1, "action", 1, 1, 0, 'fulldaystart');
1115  }
1116  print '</td></tr>';
1117  // Date end
1118  print '<tr><td>'.$langs->trans("DateActionEnd").'</td><td colspan="3">';
1119  if (GETPOST("afaire") == 1) {
1120  print $form->selectDate($datef?$datef:$object->datef, 'p2', 1, 1, 1, "action", 1, 1, 0, 'fulldayend');
1121  } elseif (GETPOST("afaire") == 2) {
1122  print $form->selectDate($datef?$datef:$object->datef,'p2', 1, 1, 1, "action", 1, 1, 0, 'fulldayend');
1123  } else {
1124  print $form->selectDate($datef?$datef:$object->datef,'p2', 1, 1, 1, "action", 1, 1, 0, 'fulldayend');
1125  }
1126  print '</td></tr>';
1127 
1128  // Dev in progress
1129  $userepeatevent=($conf->global->MAIN_FEATURES_LEVEL == 2 ? 1 : 0);
1130  if ($userepeatevent)
1131  {
1132  // Repeat
1133  print '<tr><td>'.$langs->trans("RepeatEvent").'</td><td colspan="3">';
1134  print '<input type="hidden" name="recurid" value="'.$object->recurid.'">';
1135  $arrayrecurrulefreq = array(
1136  'no'=>$langs->trans("No"),
1137  'MONTHLY'=>$langs->trans("EveryMonth"),
1138  'WEEKLY'=>$langs->trans("EveryWeek"),
1139  //'DAYLY'=>$langs->trans("EveryDay"),
1140  );
1141  $selectedrecurrulefreq='no';
1142  $selectedrecurrulebymonthday='';
1143  $selectedrecurrulebyday='';
1144  if ($object->recurrule && preg_match('/FREQ=([A-Z]+)/i',$object->recurrule,$reg)) $selectedrecurrulefreq=$reg[1];
1145  if ($object->recurrule && preg_match('/FREQ=MONTHLY.*BYMONTHDAY=(\d+)/i',$object->recurrule,$reg)) $selectedrecurrulebymonthday=$reg[1];
1146  if ($object->recurrule && preg_match('/FREQ=WEEKLY.*BYDAY(\d+)/i',$object->recurrule,$reg)) $selectedrecurrulebyday=$reg[1];
1147  print $form->selectarray('recurrulefreq', $arrayrecurrulefreq, $selectedrecurrulefreq, 0, 0, 0, '', 0, 0, 0, '', 'marginrightonly');
1148  // If recurrulefreq is MONTHLY
1149  print '<div class="hidden marginrightonly inline-block repeateventBYMONTHDAY">';
1150  print $langs->trans("DayOfMonth").': <input type="input" size="2" name="BYMONTHDAY" value="'.$selectedrecurrulebymonthday.'">';
1151  print '</div>';
1152  // If recurrulefreq is WEEKLY
1153  print '<div class="hidden marginrightonly inline-block repeateventBYDAY">';
1154  print $langs->trans("DayOfWeek").': <input type="input" size="4" name="BYDAY" value="'.$selectedrecurrulebyday.'">';
1155  print '</div>';
1156  print '<script type="text/javascript" language="javascript">
1157  jQuery(document).ready(function() {
1158  function init_repeat()
1159  {
1160  if (jQuery("#recurrulefreq").val() == \'MONTHLY\')
1161  {
1162  jQuery(".repeateventBYMONTHDAY").css("display", "inline-block"); /* use this instead of show because we want inline-block and not block */
1163  jQuery(".repeateventBYDAY").hide();
1164  }
1165  else if (jQuery("#recurrulefreq").val() == \'WEEKLY\')
1166  {
1167  jQuery(".repeateventBYMONTHDAY").hide();
1168  jQuery(".repeateventBYDAY").css("display", "inline-block"); /* use this instead of show because we want inline-block and not block */
1169  }
1170  else
1171  {
1172  jQuery(".repeateventBYMONTHDAY").hide();
1173  jQuery(".repeateventBYDAY").hide();
1174  }
1175  }
1176  init_repeat();
1177  jQuery("#recurrulefreq").change(function() {
1178  init_repeat();
1179  });
1180  });
1181  </script>';
1182  print '</td></tr>';
1183  }
1184 
1185  // Status
1186  print '<tr><td class="nowrap">'.$langs->trans("Status").' / '.$langs->trans("Percentage").'</td><td colspan="3">';
1187  $percent = GETPOST("percentage") ? GETPOST("percentage"): $object->percentage;
1188  $formactions->form_select_status_action('formaction',$percent,1);
1189  print '</td></tr>';
1190 
1191  // Location
1192  if (empty($conf->global->AGENDA_DISABLE_LOCATION))
1193  {
1194  print '<tr><td>'.$langs->trans("Location").'</td><td colspan="3"><input type="text" name="location" class="soixantepercent" value="'.$object->location.'"></td></tr>';
1195  }
1196 
1197  // Assigned to
1198  $listofuserid=array(); // User assigned
1199  if (empty($donotclearsession))
1200  {
1201  if ($object->userownerid > 0)
1202  {
1203  $listofuserid[$object->userownerid]=array(
1204  'id'=>$object->userownerid,
1205  'type'=>'user',
1206  //'transparency'=>$object->userassigned[$user->id]['transparency'],
1207  'transparency'=>$object->transparency, // Force transparency on ownerfrom event
1208  'answer_status'=>$object->userassigned[$object->userownerid]['answer_status'],
1209  'mandatory'=>$object->userassigned[$object->userownerid]['mandatory']
1210  );
1211  }
1212  if (! empty($object->userassigned)) // Now concat assigned users
1213  {
1214  // Restore array with key with same value than param 'id'
1215  $tmplist1=$object->userassigned;
1216  foreach($tmplist1 as $key => $val)
1217  {
1218  if ($val['id'] && $val['id'] != $object->userownerid)
1219  {
1220  $listofuserid[$val['id']]=$val;
1221  }
1222  }
1223  }
1224  $_SESSION['assignedtouser']=json_encode($listofuserid);
1225  }
1226  else
1227  {
1228  if (!empty($_SESSION['assignedtouser']))
1229  {
1230  $listofuserid=json_decode($_SESSION['assignedtouser'], true);
1231  }
1232  }
1233  $listofcontactid=$object->socpeopleassigned; // Contact assigned
1234  $listofotherid=$object->otherassigned; // Other undefined email (not used yet)
1235 
1236  print '<tr><td class="tdtop nowrap fieldrequired">'.$langs->trans("ActionAssignedTo").'</td><td colspan="3">';
1237  print '<div class="assignedtouser">';
1238  print $form->select_dolusers_forevent(($action=='create'?'add':'update'), 'assignedtouser', 1, '', 0, '', '', 0, 0, 0, 'AND u.statut != 0', 1, $listofuserid, $listofcontactid, $listofotherid);
1239  print '</div>';
1240  /*if (in_array($user->id,array_keys($listofuserid)))
1241  {
1242  print '<div class="myavailability">';
1243  print $langs->trans("MyAvailability").': <input id="transparency" type="checkbox" name="transparency"'.($listofuserid[$user->id]['transparency']?' checked':'').'>'.$langs->trans("Busy");
1244  print '</div>';
1245  }*/
1246  print '</td></tr>';
1247 
1248  // Realised by
1249  if (! empty($conf->global->AGENDA_ENABLE_DONEBY))
1250  {
1251  print '<tr><td class="nowrap">'.$langs->trans("ActionDoneBy").'</td><td colspan="3">';
1252  print $form->select_dolusers($object->userdoneid> 0?$object->userdoneid:-1,'doneby',1);
1253  print '</td></tr>';
1254  }
1255 
1256  print '</table>';
1257 
1258 
1259  print '<br><hr><br>';
1260 
1261 
1262  print '<table class="border" width="100%">';
1263 
1264  if ($conf->societe->enabled)
1265  {
1266  // Related company
1267  print '<tr><td class="titlefieldcreate">'.$langs->trans("ActionOnCompany").'</td>';
1268  print '<td>';
1269  print '<div class="maxwidth200onsmartphone">';
1270  $events=array(); // 'method'=parameter action of url, 'url'=url to call that return new list of contacts
1271  $events[]=array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1',1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
1272  // TODO Refresh also list of project if $conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY not defined with list linked to socid ?
1273  // FIXME If we change company, we may get a project that does not match
1274  print $form->select_company($object->socid, 'socid', '', 'SelectThirdParty', 1, 0, $events, 0, 'minwidth200');
1275  print '</div>';
1276  print '</td></tr>';
1277 
1278  // related contact
1279  print '<tr><td>'.$langs->trans("ActionOnContact").'</td><td>';
1280  print '<div class="maxwidth200onsmartphone">';
1281  print $form->selectcontacts($object->socid, array_keys($object->socpeopleassigned), 'socpeopleassigned[]', 1, '', '', 0, 'quatrevingtpercent', false, 0, 0, array(), 'multiple', 'contactid');
1282  print '</div>';
1283  print '</td>';
1284  print '</tr>';
1285  }
1286 
1287  // Project
1288  if (! empty($conf->projet->enabled))
1289  {
1290  $langs->load("projects");
1291 
1292  print '<tr><td class="titlefieldcreate">'.$langs->trans("Project").'</td><td>';
1293  $numprojet=$formproject->select_projects(($object->socid > 0 ? $object->socid : -1), $object->fk_project, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 0);
1294  if ($numprojet==0)
1295  {
1296  print ' &nbsp; <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$object->socid.'&action=create&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit').'">'.$langs->trans("AddProject").'</a>';
1297  }
1298  print '</td></tr>';
1299  }
1300 
1301  // Priority
1302  print '<tr><td class="titlefieldcreate nowrap">'.$langs->trans("Priority").'</td><td>';
1303  print '<input type="text" name="priority" value="'.($object->priority?$object->priority:'').'" size="5">';
1304  print '</td></tr>';
1305  // Object linked
1306  if (! empty($object->fk_element) && ! empty($object->elementtype))
1307  {
1308  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1309  print '<tr>';
1310  print '<td>'.$langs->trans("LinkedObject").'</td>';
1311 
1312  if ($object->elementtype == 'task' && ! empty($conf->projet->enabled))
1313  {
1314  print '<td id="project-task-input-container" >';
1315 
1316  $urloption='?action=create'; // we use create not edit for more flexibility
1317  $url = DOL_URL_ROOT.'/comm/action/card.php'.$urloption;
1318 
1319  // update task list
1320  print "\n".'<script type="text/javascript" >';
1321  print '$(document).ready(function () {
1322  $("#projectid").change(function () {
1323  var url = "'.$url.'&projectid="+$("#projectid").val();
1324  $.get(url, function(data) {
1325  console.log($( data ).find("#fk_element").html());
1326  if (data) $("#fk_element").html( $( data ).find("#taskid").html() ).select2();
1327  })
1328  });
1329  })';
1330  print '</script>'."\n";
1331 
1332  $formproject->selectTasks((! empty($societe->id)?$societe->id:-1), $object->fk_element, 'fk_element', 24, 0, 0, 1, 0, 0, 'maxwidth500',$object->fk_project);
1333  print '<input type="hidden" name="elementtype" value="'.$object->elementtype.'">';
1334 
1335  print '</td>';
1336  }
1337  else
1338  {
1339  print '<td>';
1340  print dolGetElementUrl($object->fk_element,$object->elementtype,1);
1341  print '<input type="hidden" name="fk_element" value="'.$object->fk_element.'">';
1342  print '<input type="hidden" name="elementtype" value="'.$object->elementtype.'">';
1343  print '</td>';
1344  }
1345 
1346  print '</tr>';
1347  }
1348 
1349  // Description
1350  print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
1351  // Editeur wysiwyg
1352  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1353  $doleditor=new DolEditor('note',$object->note,'',200,'dolibarr_notes','In',true,true,$conf->fckeditor->enabled,ROWS_5,'90%');
1354  $doleditor->Create();
1355  print '</td></tr>';
1356 
1357  // Other attributes
1358  $parameters=array();
1359  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
1360  print $hookmanager->resPrint;
1361  if (empty($reshook))
1362  {
1363  print $object->showOptionals($extrafields,'edit');
1364  }
1365 
1366  print '</table>';
1367 
1368  dol_fiche_end();
1369 
1370  print '<div class="center">';
1371  print '<input type="submit" class="button" name="edit" value="'.$langs->trans("Save").'">';
1372  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1373  print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
1374  print '</div>';
1375 
1376  print '</form>';
1377  }
1378  else
1379  {
1380  dol_fiche_head($head, 'card', $langs->trans("Action"), -1, 'action');
1381 
1382 
1383  // Clone event
1384  if($action == 'clone')
1385  {
1386  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . GETPOST('id'), $langs->trans('CloneAction'), $langs->trans('ConfirmCloneEvent', $object->label), 'confirm_clone', $formquestion, 'yes', 1);
1387 
1388  print $formconfirm;
1389  }
1390 
1391  $linkback =img_picto($langs->trans("BackToList"),'object_list','class="hideonsmartphone pictoactionview"');
1392  $linkback.= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1393 
1394  // Link to other agenda views
1395  $out='';
1396  $out.='</li>';
1397  $out.='<li class="noborder litext">'.img_picto($langs->trans("ViewCal"),'object_calendar','class="hideonsmartphone pictoactionview"');
1398  $out.='<a href="'.DOL_URL_ROOT.'/comm/action/index.php?action=show_month&year='.dol_print_date($object->datep,'%Y').'&month='.dol_print_date($object->datep,'%m').'&day='.dol_print_date($object->datep,'%d').'">'.$langs->trans("ViewCal").'</a>';
1399  $out.='</li>';
1400  $out.='<li class="noborder litext">'.img_picto($langs->trans("ViewWeek"),'object_calendarweek','class="hideonsmartphone pictoactionview"');
1401  $out.='<a href="'.DOL_URL_ROOT.'/comm/action/index.php?action=show_week&year='.dol_print_date($object->datep,'%Y').'&month='.dol_print_date($object->datep,'%m').'&day='.dol_print_date($object->datep,'%d').'">'.$langs->trans("ViewWeek").'</a>';
1402  $out.='</li>';
1403  $out.='<li class="noborder litext">'.img_picto($langs->trans("ViewDay"),'object_calendarday','class="hideonsmartphone pictoactionview"');
1404  $out.='<a href="'.DOL_URL_ROOT.'/comm/action/index.php?action=show_day&year='.dol_print_date($object->datep,'%Y').'&month='.dol_print_date($object->datep,'%m').'&day='.dol_print_date($object->datep,'%d').'">'.$langs->trans("ViewDay").'</a>';
1405  $out.='</li>';
1406  $out.='<li class="noborder litext">'.img_picto($langs->trans("ViewPerUser"),'object_calendarperuser','class="hideonsmartphone pictoactionview"');
1407  $out.='<a href="'.DOL_URL_ROOT.'/comm/action/peruser.php?action=show_peruser&year='.dol_print_date($object->datep,'%Y').'&month='.dol_print_date($object->datep,'%m').'&day='.dol_print_date($object->datep,'%d').'">'.$langs->trans("ViewPerUser").'</a>';
1408  $linkback.=$out;
1409 
1410  $morehtmlref='<div class="refidno">';
1411  // Thirdparty
1412  //$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
1413  // Project
1414  if (! empty($conf->projet->enabled))
1415  {
1416  $langs->load("projects");
1417  //$morehtmlref.='<br>'.$langs->trans('Project') . ' ';
1418  $morehtmlref.=$langs->trans('Project') . ' ';
1419  if ($user->rights->agenda->allactions->create ||
1420  (($object->authorid == $user->id || $object->userownerid == $user->id) && $user->rights->agenda->myactions->create))
1421  {
1422  if ($action != 'classify')
1423  $morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
1424  if ($action == 'classify') {
1425  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
1426  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
1427  $morehtmlref.='<input type="hidden" name="action" value="classin">';
1428  $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1429  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
1430  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
1431  $morehtmlref.='</form>';
1432  } else {
1433  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
1434  }
1435  } else {
1436  if (! empty($object->fk_project)) {
1437  $proj = new Project($db);
1438  $proj->fetch($object->fk_project);
1439  $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
1440  $morehtmlref.=$proj->ref;
1441  $morehtmlref.='</a>';
1442  if ($proj->title) $morehtmlref.=' - '.$proj->title;
1443  } else {
1444  $morehtmlref.='';
1445  }
1446  }
1447  }
1448  $morehtmlref.='</div>';
1449 
1450 
1451  dol_banner_tab($object, 'id', $linkback, ($user->societe_id?0:1), 'id', 'ref', $morehtmlref);
1452 
1453  print '<div class="fichecenter">';
1454 
1455  print '<div class="underbanner clearboth"></div>';
1456 
1457  // Affichage fiche action en mode visu
1458  print '<table class="border" width="100%">';
1459 
1460  // Type
1461  if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
1462  {
1463  print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td colspan="3">'.$object->type.'</td></tr>';
1464  }
1465 
1466  // Full day event
1467  print '<tr><td class="titlefield">'.$langs->trans("EventOnFullDay").'</td><td colspan="3">'.yn($object->fulldayevent, 3).'</td></tr>';
1468 
1469  $rowspan=4;
1470  if (empty($conf->global->AGENDA_DISABLE_LOCATION)) $rowspan++;
1471 
1472  // Date start
1473  print '<tr><td>'.$langs->trans("DateActionStart").'</td><td colspan="3">';
1474  if (! $object->fulldayevent) print dol_print_date($object->datep,'dayhour');
1475  else print dol_print_date($object->datep,'day');
1476  if ($object->percentage == 0 && $object->datep && $object->datep < ($now - $delay_warning)) print img_warning($langs->trans("Late"));
1477  print '</td>';
1478  print '</tr>';
1479 
1480  // Date end
1481  print '<tr><td>'.$langs->trans("DateActionEnd").'</td><td colspan="3">';
1482  if (! $object->fulldayevent) print dol_print_date($object->datef,'dayhour');
1483  else print dol_print_date($object->datef,'day');
1484  if ($object->percentage > 0 && $object->percentage < 100 && $object->datef && $object->datef < ($now- $delay_warning)) print img_warning($langs->trans("Late"));
1485  print '</td></tr>';
1486 
1487  // Location
1488  if (empty($conf->global->AGENDA_DISABLE_LOCATION))
1489  {
1490  print '<tr><td>'.$langs->trans("Location").'</td><td colspan="3">'.$object->location.'</td></tr>';
1491  }
1492 
1493  // Assigned to
1494  print '<tr><td class="nowrap">'.$langs->trans("ActionAssignedTo").'</td><td colspan="3">';
1495  $listofuserid=array();
1496  if (empty($donotclearsession))
1497  {
1498  if ($object->userownerid > 0)
1499  {
1500  $listofuserid[$object->userownerid]=array(
1501  'id'=>$object->userownerid,
1502  'transparency'=>$object->transparency, // Force transparency on onwer from preoperty of event
1503  'answer_status'=>$object->userassigned[$object->userownerid]['answer_status'],
1504  'mandatory'=>$object->userassigned[$object->userownerid]['mandatory']
1505  );
1506  }
1507  if (! empty($object->userassigned)) // Now concat assigned users
1508  {
1509  // Restore array with key with same value than param 'id'
1510  $tmplist1=$object->userassigned;
1511  foreach($tmplist1 as $key => $val)
1512  {
1513  if ($val['id'] && $val['id'] != $object->userownerid) $listofuserid[$val['id']]=$val;
1514  }
1515  }
1516  $_SESSION['assignedtouser']=json_encode($listofuserid);
1517  }
1518  else
1519  {
1520  if (!empty($_SESSION['assignedtouser']))
1521  {
1522  $listofuserid=json_decode($_SESSION['assignedtouser'], true);
1523  }
1524  }
1525 
1526  $listofcontactid=array(); // not used yet
1527  $listofotherid=array(); // not used yet
1528  print '<div class="assignedtouser">';
1529  print $form->select_dolusers_forevent('view', 'assignedtouser', 1, '', 0, '', '', 0, 0, 0, '', ($object->datep != $object->datef)?1:0, $listofuserid, $listofcontactid, $listofotherid);
1530  print '</div>';
1531  /*
1532  if ($object->datep != $object->datef && in_array($user->id,array_keys($listofuserid)))
1533  {
1534  //var_dump($object->userassigned);
1535  //var_dump($listofuserid);
1536  print '<div class="myavailability">';
1537  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
1538  print '</div>';
1539  }
1540  */
1541  print ' </td></tr>';
1542 
1543  // Done by
1544  if ($conf->global->AGENDA_ENABLE_DONEBY)
1545  {
1546  print '<tr><td class="nowrap">'.$langs->trans("ActionDoneBy").'</td><td colspan="3">';
1547  if ($object->userdoneid > 0)
1548  {
1549  $tmpuser=new User($db);
1550  $tmpuser->fetch($object->userdoneid);
1551  print $tmpuser->getNomUrl(1);
1552  }
1553  print '</td></tr>';
1554  }
1555 
1556  print '</table>';
1557 
1558  print '<br>';
1559 
1560  print '<div class="underbanner clearboth"></div>';
1561  print '<table class="border" width="100%">';
1562 
1563  if ($conf->societe->enabled)
1564  {
1565  // Related company
1566  print '<tr><td class="titlefield">'.$langs->trans("ActionOnCompany").'</td><td colspan="3">'.($object->thirdparty->id?$object->thirdparty->getNomUrl(1):('<span class="opacitymedium">'.$langs->trans("None").'</span>'));
1567  if (is_object($object->thirdparty) && $object->thirdparty->id > 0 && $object->type_code == 'AC_TEL')
1568  {
1569  if ($object->thirdparty->fetch($object->thirdparty->id))
1570  {
1571  print "<br>".dol_print_phone($object->thirdparty->phone);
1572  }
1573  }
1574  print '</td></tr>';
1575 
1576  // Related contact
1577  print '<tr><td>'.$langs->trans("ActionOnContact").'</td>';
1578  print '<td colspan="3">';
1579 
1580  if (!empty($object->socpeopleassigned))
1581  {
1582  foreach ($object->socpeopleassigned as $cid => $Tab)
1583  {
1584  $contact = new Contact($db);
1585  $result = $contact->fetch($cid);
1586 
1587  if ($result < 0) dol_print_error($db,$contact->error);
1588 
1589  if ($result > 0)
1590  {
1591  print $contact->getNomUrl(1);
1592  if ($object->type_code == 'AC_TEL')
1593  {
1594  if (!empty($contact->phone_pro)) print '('.dol_print_phone($contact->phone_pro).')';
1595  }
1596  print '<div class="paddingright"></div>';
1597  }
1598  }
1599  }
1600  else
1601  {
1602  print '<span class="opacitymedium">'.$langs->trans("None").'</span>';
1603  }
1604  print '</td></tr>';
1605  }
1606 
1607  // Priority
1608  print '<tr><td class="nowrap" class="titlefield">'.$langs->trans("Priority").'</td><td colspan="3">';
1609  print ($object->priority?$object->priority:'');
1610  print '</td></tr>';
1611 
1612  // Object linked (if link is for thirdparty, contact, project it is a recording error. We should not have links in link table
1613  // for such objects because there is already a dedicated field into table llx_actioncomm.
1614  if (! empty($object->fk_element) && ! empty($object->elementtype) && ! in_array($object->elementtype, array('societe','contact','project')))
1615  {
1616  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1617  print '<tr><td>'.$langs->trans("LinkedObject").'</td>';
1618  $link=dolGetElementUrl($object->fk_element,$object->elementtype,1);
1619  print '<td colspan="3">';
1620  if (empty($link)) print '<span class="opacitymedium">'.$langs->trans("ObjectDeleted").'</span>';
1621  else print $link;
1622  print '</td></tr>';
1623  }
1624 
1625  // Description
1626  print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td colspan="3">';
1627  print dol_htmlentitiesbr($object->note);
1628  print '</td></tr>';
1629 
1630  // Other attributes
1631  $cols=3;
1632  include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
1633 
1634  print '</table>';
1635 
1636  print '</div>';
1637 
1638  dol_fiche_end();
1639  }
1640 
1641 
1642  /*
1643  * Barre d'actions
1644  */
1645 
1646  print '<div class="tabsAction">';
1647 
1648  $parameters=array();
1649  $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
1650  if (empty($reshook))
1651  {
1652  if ($action != 'edit')
1653  {
1654  if ($user->rights->agenda->allactions->create ||
1655  (($object->authorid == $user->id || $object->userownerid == $user->id) && $user->rights->agenda->myactions->create))
1656  {
1657  print '<div class="inline-block divButAction"><a class="butAction" href="card.php?action=edit&id='.$object->id.'">'.$langs->trans("Modify").'</a></div>';
1658  }
1659  else
1660  {
1661  print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Modify").'</a></div>';
1662  }
1663 
1664  if ($user->rights->agenda->allactions->create ||
1665  (($object->authorid == $user->id || $object->userownerid == $user->id) && $user->rights->agenda->myactions->create))
1666  {
1667  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>';
1668  }
1669  else
1670  {
1671  print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("ToClone").'</a></div>';
1672  }
1673 
1674  if ($user->rights->agenda->allactions->delete ||
1675  (($object->authorid == $user->id || $object->userownerid == $user->id) && $user->rights->agenda->myactions->delete))
1676  {
1677  print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?action=delete&id='.$object->id.'">'.$langs->trans("Delete").'</a></div>';
1678  }
1679  else
1680  {
1681  print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Delete").'</a></div>';
1682  }
1683  }
1684  }
1685 
1686  print '</div>';
1687 
1688  if ($action != 'edit')
1689  {
1690  if (empty($conf->global->AGENDA_DISABLE_BUILDDOC))
1691  {
1692  print '<div style="clear:both;"></div><div class="fichecenter"><div class="fichehalfleft">';
1693  print '<a name="builddoc"></a>'; // ancre
1694 
1695  /*
1696  * Documents generes
1697  */
1698 
1699  $filedir=$conf->agenda->multidir_output[$conf->entity].'/'.$object->id;
1700  $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id;
1701 
1702  $genallowed=$user->rights->agenda->myactions->read;
1703  $delallowed=$user->rights->agenda->myactions->create;
1704 
1705 
1706  print $formfile->showdocuments('actions',$object->id,$filedir,$urlsource,$genallowed,$delallowed,'',0,0,0,0,0,'','','',$object->default_lang);
1707 
1708  print '</div><div class="fichehalfright"><div class="ficheaddleft">';
1709 
1710 
1711  print '</div></div></div>';
1712  }
1713  }
1714 }
1715 
1716 // End of page
1717 llxFooter();
1718 $db->close();
Class to manage different types of events.
img_warning($titlealt='default', $moreatt='')
Show warning logo.
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
Class to manage building of HTML components.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') else if($action=='specimen') else if($action=='setmodel') else if($action=='del') else if($action=='setdoc') $formactions
View.
Class to manage agenda events (actions)
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Class to manage contact/addresses.
img_edit($titlealt='default', $float=0, $other='class="pictoedit"')
Show logo editer/modifier fiche.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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.
Class to manage Dolibarr users.
Definition: user.class.php:41
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0)
Return an id or code from a code or id.
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:295
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
actions_prepare_head($object)
Prepare array with list of tabs.
Definition: agenda.lib.php:452
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting a parameter.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage projects.
Class to manage building of HTML components.
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44
dol_now($mode='gmt')
Return date for now.
if($_POST["cancel"]==$langs->trans("Cancel") &&! $id) if($action=='add' && $_POST["cancel"]<> $langs->trans("Cancel")) if($action=='delete') if($id) $form
Actions.
Definition: card.php:153
Class to offer components to list and upload files.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolGetElementUrl($objectid, $objecttype, $withpicto=0, $option='')
Return link url to an object.
Class to manage tasks.
Definition: task.class.php:33
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_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...
Class to manage a WYSIWYG editor.
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
Definition: date.lib.php:116
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
div float
Buy price without taxes.
Definition: style.css.php:564
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of &#39;autofocus&#39; HTML5 tag)
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
$parameters
Actions.
Definition: card.php:114