card.php 92 KB

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