card.php 66 KB

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