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