card.php 108 KB

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