card.php 94 KB

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