card.php 105 KB

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