card.php 104 KB

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