card.php 82 KB

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