card.php 109 KB

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