card.php 88 KB

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