card.php 103 KB

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