card.php 107 KB

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