booking_agenda.php 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Eric Seigne <erics@rycks.com>
  4. * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
  8. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  9. * Copyright (C) 2017 Open-DSI <support@open-dsi.fr>
  10. * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/custom/booking/booking_agenda.php
  27. * \ingroup agenda
  28. * \brief Home page of calendar events
  29. */
  30. // Load Dolibarr environment
  31. require '../../main.inc.php';
  32. require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
  33. require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
  34. require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
  35. require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
  36. require_once DOL_DOCUMENT_ROOT . '/core/lib/agenda.lib.php';
  37. require_once DOL_DOCUMENT_ROOT . '/custom/booking/class/booking_agenda_helper.class.php';
  38. if (isModEnabled('project')) {
  39. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
  40. }
  41. if (!isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) {
  42. $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW = 3;
  43. }
  44. if (empty($conf->global->AGENDA_EXT_NB)) {
  45. $conf->global->AGENDA_EXT_NB = 5;
  46. }
  47. $MAXAGENDA = $conf->global->AGENDA_EXT_NB;
  48. $disabledefaultvalues = GETPOST('disabledefaultvalues', 'int');
  49. $check_holiday = GETPOST('check_holiday', 'int');
  50. $filter = GETPOST("search_filter", 'alpha', 3) ? GETPOST("search_filter", 'alpha', 3) : GETPOST("filter", 'alpha', 3);
  51. $filtert = GETPOST("search_filtert", "int", 3) ? GETPOST("search_filtert", "int", 3) : GETPOST("filtert", "int", 3);
  52. $usergroup = GETPOST("search_usergroup", "int", 3) ? GETPOST("search_usergroup", "int", 3) : GETPOST("usergroup", "int", 3);
  53. $showbirthday = empty($conf->use_javascript_ajax) ? GETPOST("showbirthday", "int") : 1;
  54. // If not choice done on calendar owner (like on left menu link "Agenda"), we filter on user.
  55. if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS)) {
  56. $filtert = $user->id;
  57. }
  58. $newparam = '';
  59. $sortfield = GETPOST('sortfield', 'aZ09comma');
  60. $sortorder = GETPOST('sortorder', 'aZ09comma');
  61. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  62. if (empty($page) || $page == -1) {
  63. $page = 0;
  64. } // If $page is not defined, or '' or -1
  65. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  66. $offset = $limit * $page;
  67. if (!$sortorder) {
  68. $sortorder = "ASC";
  69. }
  70. if (!$sortfield) {
  71. $sortfield = "a.datec";
  72. }
  73. // Security check
  74. $socid = GETPOST("search_socid", "int") ? GETPOST("search_socid", "int") : GETPOST("socid", "int");
  75. if ($user->socid) {
  76. $socid = $user->socid;
  77. }
  78. if ($socid < 0) {
  79. $socid = '';
  80. }
  81. $canedit = 1;
  82. if (empty($user->rights->agenda->myactions->read)) {
  83. accessforbidden();
  84. }
  85. if (empty($user->rights->agenda->allactions->read)) {
  86. $canedit = 0;
  87. }
  88. if (empty($user->rights->agenda->allactions->read) || $filter == 'mine') { // If no permission to see all, we show only affected to me
  89. $filtert = $user->id;
  90. }
  91. $action = GETPOST('action', 'aZ09');
  92. $mode = GETPOST('mode', 'aZ09');
  93. if (empty($mode) && preg_match('/show_/', $action)) {
  94. $mode = $action; // For backward compatibility
  95. }
  96. $resourceid = GETPOST("search_resourceid", "int");
  97. $year = GETPOST("year", "int") ? GETPOST("year", "int") : date("Y");
  98. $month = GETPOST("month", "int") ? GETPOST("month", "int") : date("m");
  99. $week = GETPOST("week", "int") ? GETPOST("week", "int") : date("W");
  100. $day = GETPOST("day", "int") ? GETPOST("day", "int") : date("d");
  101. $pid = GETPOST("search_projectid", "int", 3) ? GETPOST("search_projectid", "int", 3) : GETPOST("projectid", "int", 3);
  102. $status = GETPOSTISSET("search_status") ? GETPOST("search_status", 'aZ09') : GETPOST("status", 'aZ09'); // status may be 0, 50, 100, 'todo', 'na' or -1
  103. $type = GETPOSTISSET("search_type") ? GETPOST("search_type", 'aZ09') : GETPOST("type", 'aZ09');
  104. $maxprint = GETPOSTISSET("maxprint") ? GETPOST("maxprint", 'int') : $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW;
  105. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  106. $dateselect = dol_mktime(0, 0, 0, GETPOST('dateselectmonth', 'int'), GETPOST('dateselectday', 'int'), GETPOST('dateselectyear', 'int'));
  107. if ($dateselect > 0) {
  108. $day = GETPOST('dateselectday', 'int');
  109. $month = GETPOST('dateselectmonth', 'int');
  110. $year = GETPOST('dateselectyear', 'int');
  111. }
  112. // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
  113. if (GETPOST('search_actioncode', 'array:aZ09')) {
  114. $actioncode = GETPOST('search_actioncode', 'array:aZ09', 3);
  115. if (!count($actioncode)) {
  116. $actioncode = '0';
  117. }
  118. } else {
  119. $actioncode = GETPOST("search_actioncode", "alpha", 3) ? GETPOST("search_actioncode", "alpha", 3) : (GETPOST("search_actioncode") == '0' ? '0' : ((empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) || $disabledefaultvalues) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE));
  120. }
  121. if ($status == '' && !GETPOSTISSET('search_status')) {
  122. $status = ((empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS) || $disabledefaultvalues) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS);
  123. }
  124. $defaultview = (empty($conf->global->AGENDA_DEFAULT_VIEW) ? 'show_month' : $conf->global->AGENDA_DEFAULT_VIEW);
  125. $defaultview = (empty($user->conf->AGENDA_DEFAULT_VIEW) ? $defaultview : $user->conf->AGENDA_DEFAULT_VIEW);
  126. if (empty($mode) && !GETPOSTISSET('mode')) {
  127. //$mode = $defaultview;
  128. $mode = 'show_day';
  129. }
  130. if ($mode == 'default') { // When action is default, we want a calendar view and not the list
  131. $mode = (($defaultview != 'show_list') ? $defaultview : 'show_month');
  132. }
  133. if (GETPOST('viewcal', 'int') && GETPOST('mode', 'alpha') != 'show_day' && GETPOST('mode', 'alpha') != 'show_week') {
  134. $mode = 'show_month';
  135. $day = '';
  136. } // View by month
  137. if (GETPOST('viewweek', 'int') || GETPOST('mode', 'alpha') == 'show_week') {
  138. $mode = 'show_week';
  139. $week = ($week ? $week : date("W"));
  140. $day = ($day ? $day : date("d"));
  141. } // View by week
  142. if (GETPOST('viewday', 'int') || GETPOST('mode', 'alpha') == 'show_day') {
  143. $mode = 'show_day';
  144. $day = ($day ? $day : date("d"));
  145. } // View by day
  146. $object = new ActionComm($db);
  147. $bookingAgendaHelper = new BookingAgendaHelper($db);
  148. // Load translation files required by the page
  149. $langs->loadLangs(array('agenda', 'other', 'commercial'));
  150. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  151. $hookmanager->initHooks(array('agenda'));
  152. $result = restrictedArea($user, 'agenda', 0, 'actioncomm&societe', 'myactions|allactions', 'fk_soc', 'id');
  153. if ($user->socid && $socid) {
  154. $result = restrictedArea($user, 'societe', $socid);
  155. }
  156. /*
  157. * Actions
  158. */
  159. if (GETPOST("viewlist", 'alpha') || $mode == 'show_list') {
  160. $param = '';
  161. if (is_array($_POST)) {
  162. foreach ($_POST as $key => $val) {
  163. if ($key == 'token') {
  164. continue;
  165. }
  166. $param .= '&' . $key . '=' . urlencode($val);
  167. }
  168. }
  169. if (!preg_match('/action=/', $param)) {
  170. $param .= ($param ? '&' : '') . 'mode=show_list';
  171. }
  172. //print $param;
  173. header("Location: " . DOL_URL_ROOT . '/custom/booking/booking_list.php?' . $param);
  174. exit;
  175. }
  176. if (GETPOST("viewperuser", 'alpha') || $mode == 'show_peruser') {
  177. $param = '';
  178. if (is_array($_POST)) {
  179. foreach ($_POST as $key => $val) {
  180. if ($key == 'token') {
  181. continue;
  182. }
  183. $param .= '&' . $key . '=' . urlencode($val);
  184. }
  185. }
  186. //print $param;
  187. header("Location: " . DOL_URL_ROOT . '/comm/action/peruser.php?' . $param);
  188. exit;
  189. }
  190. /*
  191. if ($action == 'delete_action' && $user->rights->agenda->delete) {
  192. $event = new ActionComm($db);
  193. $event->fetch($actionid);
  194. $event->fetch_optionals();
  195. $event->fetch_userassigned();
  196. $event->oldcopy = dol_clone($event);
  197. $result = $event->delete();
  198. }
  199. */
  200. /*
  201. * View
  202. */
  203. $parameters = array(
  204. 'socid' => $socid,
  205. 'status' => $status,
  206. 'year' => $year,
  207. 'month' => $month,
  208. 'day' => $day,
  209. 'type' => $type,
  210. 'maxprint' => $maxprint,
  211. 'filter' => $filter,
  212. 'filtert' => $filtert,
  213. 'showbirthday' => $showbirthday,
  214. 'canedit' => $canedit,
  215. 'optioncss' => $optioncss,
  216. 'actioncode' => $actioncode,
  217. 'pid' => $pid,
  218. 'resourceid' => $resourceid,
  219. 'usergroup' => $usergroup,
  220. );
  221. $reshook = $hookmanager->executeHooks('beforeAgenda', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  222. if ($reshook < 0) {
  223. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  224. }
  225. $help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&oacute;dulo_Agenda';
  226. llxHeader('', $langs->trans("Agenda"), $help_url);
  227. $form = new Form($db);
  228. $companystatic = new Societe($db);
  229. $contactstatic = new Contact($db);
  230. $userstatic = new User($db);
  231. $now = dol_now();
  232. $nowarray = dol_getdate($now);
  233. $nowyear = $nowarray['year'];
  234. $nowmonth = $nowarray['mon'];
  235. $nowday = $nowarray['mday'];
  236. $listofextcals = array();
  237. // Define list of external calendars (global admin setup)
  238. if (empty($conf->global->AGENDA_DISABLE_EXT)) {
  239. $i = 0;
  240. while ($i < $MAXAGENDA) {
  241. $i++;
  242. $source = 'AGENDA_EXT_SRC' . $i;
  243. $name = 'AGENDA_EXT_NAME' . $i;
  244. $offsettz = 'AGENDA_EXT_OFFSETTZ' . $i;
  245. $color = 'AGENDA_EXT_COLOR' . $i;
  246. $default = 'AGENDA_EXT_ACTIVEBYDEFAULT' . $i;
  247. $buggedfile = 'AGENDA_EXT_BUGGEDFILE' . $i;
  248. if (getDolGlobalString($source) && getDolGlobalString($name)) {
  249. // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
  250. $listofextcals[] = array(
  251. 'src' => getDolGlobalString($source),
  252. 'name' => dol_string_nohtmltag(getDolGlobalString($name)),
  253. 'offsettz' => (int) getDolGlobalInt($offsettz, 0),
  254. 'color' => dol_string_nohtmltag(getDolGlobalString($color)),
  255. 'default' => dol_string_nohtmltag(getDolGlobalString($default)),
  256. 'buggedfile' => dol_string_nohtmltag(getDolGlobalString('buggedfile', ''))
  257. );
  258. }
  259. }
  260. }
  261. // Define list of external calendars (user setup)
  262. if (empty($user->conf->AGENDA_DISABLE_EXT)) {
  263. $i = 0;
  264. while ($i < $MAXAGENDA) {
  265. $i++;
  266. $source = 'AGENDA_EXT_SRC_' . $user->id . '_' . $i;
  267. $name = 'AGENDA_EXT_NAME_' . $user->id . '_' . $i;
  268. $offsettz = 'AGENDA_EXT_OFFSETTZ_' . $user->id . '_' . $i;
  269. $color = 'AGENDA_EXT_COLOR_' . $user->id . '_' . $i;
  270. $enabled = 'AGENDA_EXT_ENABLED_' . $user->id . '_' . $i;
  271. $default = 'AGENDA_EXT_ACTIVEBYDEFAULT_' . $user->id . '_' . $i;
  272. $buggedfile = 'AGENDA_EXT_BUGGEDFILE_' . $user->id . '_' . $i;
  273. if (getDolUserString($source) && getDolUserString($name)) {
  274. // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
  275. $listofextcals[] = array(
  276. 'src' => getDolUserString($source),
  277. 'name' => dol_string_nohtmltag(getDolUserString($name)),
  278. 'offsettz' => (int) (empty($user->conf->$offsettz) ? 0 : $user->conf->$offsettz),
  279. 'color' => dol_string_nohtmltag(getDolUserString($color)),
  280. 'default' => dol_string_nohtmltag(getDolUserString($default)),
  281. 'buggedfile' => dol_string_nohtmltag(isset($user->conf->buggedfile) ? $user->conf->buggedfile : '')
  282. );
  283. }
  284. }
  285. }
  286. if (empty($mode) || $mode == 'show_month') {
  287. $prev = dol_get_prev_month($month, $year);
  288. $prev_year = $prev['year'];
  289. $prev_month = $prev['month'];
  290. $next = dol_get_next_month($month, $year);
  291. $next_year = $next['year'];
  292. $next_month = $next['month'];
  293. $max_day_in_prev_month = date("t", dol_mktime(0, 0, 0, $prev_month, 1, $prev_year, 'gmt')); // Nb of days in previous month
  294. $max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year)); // Nb of days in next month
  295. // tmpday is a negative or null cursor to know how many days before the 1st to show on month view (if tmpday=0, 1st is monday)
  296. $tmpday = -date("w", dol_mktime(12, 0, 0, $month, 1, $year, 'gmt')) + 2; // date('w') is 0 fo sunday
  297. $tmpday += ((isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1) - 1);
  298. if ($tmpday >= 1) {
  299. $tmpday -= 7; // If tmpday is 0 we start with sunday, if -6, we start with monday of previous week.
  300. }
  301. // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
  302. $firstdaytoshow = dol_mktime(0, 0, 0, $prev_month, $max_day_in_prev_month + $tmpday, $prev_year, 'tzuserrel');
  303. $next_day = 7 - ($max_day_in_month + 1 - $tmpday) % 7;
  304. if ($next_day < 6) {
  305. $next_day += 7;
  306. }
  307. $lastdaytoshow = dol_mktime(0, 0, 0, $next_month, $next_day, $next_year, 'tzuserrel');
  308. }
  309. if ($mode == 'show_week') {
  310. $prev = dol_get_first_day_week($day, $month, $year);
  311. $prev_year = $prev['prev_year'];
  312. $prev_month = $prev['prev_month'];
  313. $prev_day = $prev['prev_day'];
  314. $first_day = $prev['first_day'];
  315. $first_month = $prev['first_month'];
  316. $first_year = $prev['first_year'];
  317. $week = $prev['week'];
  318. $day = (int) $day;
  319. $next = dol_get_next_week($first_day, $week, $first_month, $first_year);
  320. $next_year = $next['year'];
  321. $next_month = $next['month'];
  322. $next_day = $next['day'];
  323. // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
  324. $firstdaytoshow = dol_mktime(0, 0, 0, $first_month, $first_day, $first_year, 'tzuserrel');
  325. $lastdaytoshow = dol_time_plus_duree($firstdaytoshow, 7, 'd');
  326. $max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year, 'gmt'));
  327. $tmpday = $first_day;
  328. }
  329. if ($mode == 'show_day') {
  330. $prev = dol_get_prev_day($day, $month, $year);
  331. $prev_year = $prev['year'];
  332. $prev_month = $prev['month'];
  333. $prev_day = $prev['day'];
  334. $next = dol_get_next_day($day, $month, $year);
  335. $next_year = $next['year'];
  336. $next_month = $next['month'];
  337. $next_day = $next['day'];
  338. // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
  339. $firstdaytoshow = dol_mktime(0, 0, 0, $prev_month, $prev_day, $prev_year, 'tzuserrel');
  340. $lastdaytoshow = dol_mktime(0, 0, 0, $next_month, $next_day, $next_year, 'tzuserrel');
  341. }
  342. //print 'xx'.$prev_year.'-'.$prev_month.'-'.$prev_day;
  343. //print 'xx'.$next_year.'-'.$next_month.'-'.$next_day;
  344. //print dol_print_date($firstdaytoshow,'dayhour').' '.dol_print_date($lastdaytoshow,'dayhour');
  345. /*$title = $langs->trans("DoneAndToDoActions");
  346. if ($status == 'done') $title = $langs->trans("DoneActions");
  347. if ($status == 'todo') $title = $langs->trans("ToDoActions");
  348. */
  349. $param = '';
  350. if ($actioncode || GETPOSTISSET('search_actioncode')) {
  351. if (is_array($actioncode)) {
  352. foreach ($actioncode as $str_action) {
  353. $param .= "&search_actioncode[]=" . urlencode($str_action);
  354. }
  355. } else {
  356. $param .= "&search_actioncode=" . urlencode($actioncode);
  357. }
  358. }
  359. if ($resourceid > 0) {
  360. $param .= "&search_resourceid=" . urlencode($resourceid);
  361. }
  362. if ($status || GETPOSTISSET('status') || GETPOSTISSET('search_status')) {
  363. $param .= "&search_status=" . urlencode($status);
  364. }
  365. if ($filter) {
  366. $param .= "&search_filter=" . urlencode($filter);
  367. }
  368. if ($filtert) {
  369. $param .= "&search_filtert=" . urlencode($filtert);
  370. }
  371. if ($usergroup > 0) {
  372. $param .= "&search_usergroup=" . urlencode($usergroup);
  373. }
  374. if ($socid > 0) {
  375. $param .= "&search_socid=" . urlencode($socid);
  376. }
  377. if ($showbirthday) {
  378. $param .= "&search_showbirthday=1";
  379. }
  380. if ($pid) {
  381. $param .= "&search_projectid=" . urlencode($pid);
  382. }
  383. if ($type) {
  384. $param .= "&search_type=" . urlencode($type);
  385. }
  386. $param .= "&maxprint=" . urlencode($maxprint);
  387. if ($mode == 'show_day' || $mode == 'show_week' || $mode == 'show_month') {
  388. $param .= '&mode=' . urlencode($mode);
  389. }
  390. // Show navigation bar
  391. if (empty($mode) || $mode == 'show_month') {
  392. $nav = "<a href=\"?year=" . $prev_year . "&month=" . $prev_month . $param . "\"><i class=\"fa fa-chevron-left\"></i></a> &nbsp;\n";
  393. $nav .= " <span id=\"month_name\">" . dol_print_date(dol_mktime(0, 0, 0, $month, 1, $year), "%b %Y");
  394. $nav .= " </span>\n";
  395. $nav .= " &nbsp; <a href=\"?year=" . $next_year . "&month=" . $next_month . $param . "\"><i class=\"fa fa-chevron-right\"></i></a>\n";
  396. if (empty($conf->dol_optimize_smallscreen)) {
  397. $nav .= " &nbsp; <a href=\"?year=" . $nowyear . "&month=" . $nowmonth . $param . "\">" . $langs->trans("Today") . "</a> ";
  398. }
  399. $picto = 'calendar';
  400. }
  401. if ($mode == 'show_week') {
  402. $nav = "<a href=\"?year=" . $prev_year . "&month=" . $prev_month . "&day=" . $prev_day . $param . "\"><i class=\"fa fa-chevron-left\" title=\"" . dol_escape_htmltag($langs->trans("Previous")) . "\"></i></a> &nbsp;\n";
  403. $nav .= " <span id=\"month_name\">" . dol_print_date(dol_mktime(0, 0, 0, $first_month, $first_day, $first_year), "%Y") . ", " . $langs->trans("Week") . " " . $week;
  404. $nav .= " </span>\n";
  405. $nav .= " &nbsp; <a href=\"?year=" . $next_year . "&month=" . $next_month . "&day=" . $next_day . $param . "\"><i class=\"fa fa-chevron-right\" title=\"" . dol_escape_htmltag($langs->trans("Next")) . "\"></i></a>\n";
  406. if (empty($conf->dol_optimize_smallscreen)) {
  407. $nav .= " &nbsp; <a href=\"?year=" . $nowyear . "&month=" . $nowmonth . "&day=" . $nowday . $param . "\">" . $langs->trans("Today") . "</a> ";
  408. }
  409. $picto = 'calendarweek';
  410. }
  411. if ($mode == 'show_day') {
  412. $nav = "<a href=\"?year=" . $prev_year . "&month=" . $prev_month . "&day=" . $prev_day . $param . "\"><i class=\"fa fa-chevron-left\"></i></a> &nbsp;\n";
  413. $nav .= " <span id=\"month_name\">" . dol_print_date(dol_mktime(0, 0, 0, $month, $day, $year), "daytextshort");
  414. $nav .= " </span>\n";
  415. $nav .= " &nbsp; <a href=\"?year=" . $next_year . "&month=" . $next_month . "&day=" . $next_day . $param . "\"><i class=\"fa fa-chevron-right\"></i></a>\n";
  416. if (empty($conf->dol_optimize_smallscreen)) {
  417. $nav .= " &nbsp; <a href=\"?year=" . $nowyear . "&amp;month=" . $nowmonth . "&amp;day=" . $nowday . $param . "\">" . $langs->trans("Today") . "</a> ";
  418. }
  419. $picto = 'calendarday';
  420. }
  421. $nav .= $form->selectDate($dateselect, 'dateselect', 0, 0, 1, '', 1, 0);
  422. //$nav .= ' <input type="submit" class="button button-save" name="submitdateselect" value="'.$langs->trans("Refresh").'">';
  423. $nav .= '<button type="submit" class="liste_titre button_search valignmiddle" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
  424. // Must be after the nav definition
  425. $paramnodate = $param;
  426. $param .= '&year=' . $year . '&month=' . $month . ($day ? '&day=' . $day : '');
  427. //print 'x'.$param;
  428. /*$tabactive = '';
  429. if ($mode == 'show_month') $tabactive = 'cardmonth';
  430. if ($mode == 'show_week') $tabactive = 'cardweek';
  431. if ($mode == 'show_day') $tabactive = 'cardday';
  432. if ($mode == 'show_list') $tabactive = 'cardlist';
  433. if ($mode == 'show_pertuser') $tabactive = 'cardperuser';
  434. if ($mode == 'show_pertype') $tabactive = 'cardpertype';
  435. */
  436. $paramnoaction = preg_replace('/mode=[a-z_]+/', '', preg_replace('/action=[a-z_]+/', '', $param));
  437. $paramnoactionodate = preg_replace('/mode=[a-z_]+/', '', preg_replace('/action=[a-z_]+/', '', $paramnodate));
  438. $head = calendars_prepare_head($paramnoaction);
  439. print '<form method="POST" id="searchFormList" class="listactionsfilter" action="' . $_SERVER["PHP_SELF"] . '">' . "\n";
  440. if ($optioncss != '') {
  441. print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
  442. }
  443. print '<input type="hidden" name="token" value="' . newToken() . '">';
  444. print '<input type="hidden" name="mode" value="' . $mode . '">';
  445. //print dol_get_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action');
  446. //print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, $listofextcals, $actioncode, $usergroup, '', $resourceid);
  447. //print dol_get_fiche_end();
  448. $viewmode = '';
  449. /* $viewmode .= '<a class="btnTitle reposition" href="' . DOL_URL_ROOT . '/custom/booking/booking_list.php?mode=show_list&restore_lastsearch_values=1' . $paramnoactionodate . '">';
  450. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  451. $viewmode .= img_picto($langs->trans("List"), 'object_calendarlist', 'class="imgforviewmode pictoactionview block"');
  452. //$viewmode .= '</span>';
  453. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">' . $langs->trans("ViewList") . '</span></a>';
  454. */
  455. /* $viewmode .= '<a class="btnTitle' . ($mode == 'show_month' ? ' btnTitleSelected' : '') . ' reposition" href="' . DOL_URL_ROOT . '/custom/booking/booking_agenda.php?mode=show_month&year=' . (isset($object->datep) ? dol_print_date($object->datep, '%Y') : $year) . '&month=' . (isset($object->datep) ? dol_print_date($object->datep, '%m') : $month) . '&day=' . (isset($object->datep) ? dol_print_date($object->datep, '%d') : $day) . $paramnoactionodate . '">';
  456. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  457. $viewmode .= img_picto($langs->trans("ViewCal"), 'object_calendarmonth', 'class="pictoactionview block"');
  458. //$viewmode .= '</span>';
  459. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">' . $langs->trans("ViewCal") . '</span></a>';
  460. */
  461. /* $viewmode .= '<a class="btnTitle' . ($mode == 'show_week' ? ' btnTitleSelected' : '') . ' reposition" href="' . DOL_URL_ROOT . '/custom/booking/booking_agenda.php?mode=show_week&year=' . (isset($object->datep) ? dol_print_date($object->datep, '%Y') : $year) . '&month=' . (isset($object->datep) ? dol_print_date($object->datep, '%m') : $month) . '&day=' . (isset($object->datep) ? dol_print_date($object->datep, '%d') : $day) . $paramnoactionodate . '">';
  462. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  463. $viewmode .= img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="pictoactionview block"');
  464. //$viewmode .= '</span>';
  465. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">' . $langs->trans("ViewWeek") . '</span></a>';
  466. */
  467. $viewmode .= '<a class="btnTitle' . ($mode == 'show_day' ? ' btnTitleSelected' : '') . ' reposition" href="' . DOL_URL_ROOT . '/custom/booking/booking_agenda.php?mode=show_day&year=' . (isset($object->datep) ? dol_print_date($object->datep, '%Y') : $year) . '&month=' . (isset($object->datep) ? dol_print_date($object->datep, '%m') : $month) . '&day=' . (isset($object->datep) ? dol_print_date($object->datep, '%d') : $day) . $paramnoactionodate . '">';
  468. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  469. $viewmode .= img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="pictoactionview block"');
  470. //$viewmode .= '</span>';
  471. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">' . $langs->trans("ViewDay") . '</span></a>';
  472. /* $viewmode .= '<a class="btnTitle reposition" href="'.DOL_URL_ROOT.'/comm/action/peruser.php?mode=show_peruser&year='.(isset($object->datep) ? dol_print_date($object->datep, '%Y') : $year).'&month='.(isset($object->datep) ? dol_print_date($object->datep, '%m') : $month).'&day='.(isset($object->datep) ? dol_print_date($object->datep, '%d') : $day).$paramnoactionodate.'">';
  473. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  474. $viewmode .= img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="pictoactionview block"');
  475. //$viewmode .= '</span>';
  476. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewPerUser").'</span></a>';
  477. */
  478. // Add more views from hooks
  479. $parameters = array();
  480. $object = null;
  481. $reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
  482. if (empty($reshook)) {
  483. $viewmode .= $hookmanager->resPrint;
  484. } elseif ($reshook > 1) {
  485. $viewmode = $hookmanager->resPrint;
  486. }
  487. $viewmode .= '<span class="marginrightonly"></span>'; // To add a space before the navigation tools
  488. $newcardbutton = '';
  489. $newparam = '';
  490. if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
  491. $tmpforcreatebutton = dol_getdate(dol_now(), true);
  492. $newparam .= '&month=' . ((int) $month) . '&year=' . ((int) $tmpforcreatebutton['year']) . '&mode=' . urlencode($mode);
  493. //$param='month='.$monthshown.'&year='.$year;
  494. $hourminsec = dol_print_date(dol_mktime(10, 0, 0, 1, 1, 1970, 'gmt'), '%H', 'gmt') . '0000'; // Set $hourminsec to '100000' to auto set hour to 10:00 at creation
  495. $newcardbutton .= dolGetButtonTitle($langs->trans("AddAction"), '', 'fa fa-plus-circle', DOL_URL_ROOT . '/custom/booking/booking_card.php?action=create&datep=' . sprintf("%04d%02d%02d", $tmpforcreatebutton['year'], $tmpforcreatebutton['mon'], $tmpforcreatebutton['mday']) . $hourminsec . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . ($newparam ? '?' . $newparam : '')));
  496. }
  497. // Define the legend/list of calendard to show
  498. $s = '';
  499. $link = '';
  500. $showextcals = $listofextcals;
  501. if (!empty($conf->use_javascript_ajax)) { // If javascript on
  502. $s .= "\n" . '<!-- Div to calendars selectors -->' . "\n";
  503. $s .= '<script type="text/javascript">' . "\n";
  504. $s .= 'jQuery(document).ready(function () {' . "\n";
  505. $s .= 'jQuery(".check_birthday").click(function() { console.log("Toggle birthdays"); jQuery(".family_birthday").toggle(); });' . "\n";
  506. $s .= 'jQuery(".check_holiday").click(function() { console.log("Toggle holidays"); jQuery(".family_holiday").toggle(); });' . "\n";
  507. if ($mode == "show_week" || $mode == "show_month" || empty($mode)) {
  508. // Code to enable drag and drop
  509. $s .= 'jQuery( "div.sortable" ).sortable({connectWith: ".sortable", placeholder: "ui-state-highlight", items: "div.movable", receive: function( event, ui ) {' . "\n";
  510. // Code to submit form
  511. $s .= 'console.log("submit form to record new event");' . "\n";
  512. //$s.='console.log(event.target);';
  513. $s .= 'var newval = jQuery(event.target).closest("div.dayevent").attr("id");' . "\n";
  514. $s .= 'console.log("found parent div.dayevent with id = "+newval);' . "\n";
  515. $s .= 'var frm=jQuery("#searchFormList");' . "\n";
  516. $s .= 'var newurl = ui.item.find("a.cal_event").attr("href");' . "\n";
  517. $s .= 'console.log("Found url on href of a.cal_event"+newurl+", we submit form with actionmove=mupdate");' . "\n";
  518. $s .= 'frm.attr("action", newurl).children("#newdate").val(newval);frm.submit();}' . "\n";
  519. $s .= '});' . "\n";
  520. }
  521. $s .= '});' . "\n";
  522. $s .= '</script>' . "\n";
  523. // Local calendar
  524. $s .= '<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_mytasks" name="check_mytasks" value="1" checked disabled> ' . $langs->trans("LocalAgenda") . ' &nbsp; </div>';
  525. // Holiday calendar
  526. //$s .= '<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_holiday" name="check_holiday" value="1" class="check_holiday"'.($check_holiday ? ' checked' : '').'><label for="check_holiday"> <span class="check_holiday_text">'.$langs->trans("Holidays").'</span></label> &nbsp; </div>';
  527. // External calendars
  528. if (is_array($showextcals) && count($showextcals) > 0) {
  529. $s .= '<script type="text/javascript">' . "\n";
  530. $s .= 'jQuery(document).ready(function () {
  531. jQuery("div input[name^=\"check_ext\"]").each(function(index, elem) {
  532. var name = jQuery(elem).attr("name");
  533. if (jQuery(elem).is(":checked")) {
  534. jQuery(".family_ext" + name.replace("check_ext", "")).show();
  535. } else {
  536. jQuery(".family_ext" + name.replace("check_ext", "")).hide();
  537. }
  538. });
  539. jQuery("div input[name^=\"check_ext\"]").click(function() {
  540. var name = $(this).attr("name");
  541. jQuery(".family_ext" + name.replace("check_ext", "")).toggle();
  542. });
  543. });' . "\n";
  544. $s .= '</script>' . "\n";
  545. foreach ($showextcals as $val) {
  546. $htmlname = md5($val['name']);
  547. if (!empty($val['default']) || GETPOST('check_ext' . $htmlname, 'int')) {
  548. $default = "checked";
  549. } else {
  550. $default = '';
  551. }
  552. $s .= '<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_ext' . $htmlname . '" name="check_ext' . $htmlname . '" value="1" ' . $default . '> <label for="check_ext' . $htmlname . '">' . dol_escape_htmltag($val['name']) . '</label> &nbsp; </div>';
  553. }
  554. }
  555. // Birthdays
  556. //$s .= '<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_birthday" name="check_birthday" class="check_birthday"><label for="check_birthday"> <span class="check_birthday_text">'.$langs->trans("AgendaShowBirthdayEvents").'</span></label> &nbsp; </div>';
  557. // Calendars from hooks
  558. $parameters = array();
  559. $reshook = $hookmanager->executeHooks('addCalendarChoice', $parameters, $object, $action);
  560. if (empty($reshook)) {
  561. $s .= $hookmanager->resPrint;
  562. } elseif ($reshook > 1) {
  563. $s = $hookmanager->resPrint;
  564. }
  565. $s .= "\n" . '<!-- End div to calendars selectors -->' . "\n";
  566. } else { // If javascript off
  567. $newparam = $param; // newparam is for birthday links
  568. $newparam = preg_replace('/showbirthday=[0-1]/i', 'showbirthday=' . (empty($showbirthday) ? 1 : 0), $newparam);
  569. if (!preg_match('/showbirthday=/i', $newparam)) {
  570. $newparam .= '&showbirthday=1';
  571. }
  572. $link = '<a href="' . $_SERVER['PHP_SELF'] . '?' . dol_escape_htmltag($newparam);
  573. $link .= '">';
  574. if (empty($showbirthday)) {
  575. $link .= $langs->trans("AgendaShowBirthdayEvents");
  576. } else {
  577. $link .= $langs->trans("AgendaHideBirthdayEvents");
  578. }
  579. $link .= '</a>';
  580. }
  581. // Load events from database into $eventarray
  582. $eventarray = array();
  583. // DEFAULT CALENDAR + AUTOEVENT CALENDAR + CONFERENCEBOOTH CALENDAR
  584. $sql = 'SELECT ';
  585. if ($usergroup > 0) {
  586. $sql .= " DISTINCT";
  587. }
  588. $sql .= ' a.id, a.label,';
  589. $sql .= ' a.datep,';
  590. $sql .= ' a.datep2,';
  591. $sql .= ' a.percent,';
  592. $sql .= ' a.fk_user_author,a.fk_user_action,';
  593. $sql .= ' a.transparency, a.priority, a.fulldayevent, a.location,';
  594. $sql .= ' a.fk_soc, a.fk_contact, a.fk_project,';
  595. $sql .= ' a.fk_element, a.elementtype,';
  596. $sql .= ' ca.code as type_code, ca.libelle as type_label, ca.color as type_color, ca.type as type_type, ca.picto as type_picto';
  597. $sql .= ' FROM ' . MAIN_DB_PREFIX . 'c_actioncomm as ca, ' . MAIN_DB_PREFIX . "actioncomm as a";
  598. if (empty($user->rights->societe->client->voir) && !$socid) {
  599. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
  600. }
  601. // We must filter on resource table
  602. if ($resourceid > 0) {
  603. $sql .= ", " . MAIN_DB_PREFIX . "element_resources as r";
  604. }
  605. // We must filter on assignement table
  606. if ($filtert > 0 || $usergroup > 0) {
  607. $sql .= ", " . MAIN_DB_PREFIX . "actioncomm_resources as ar";
  608. }
  609. if ($usergroup > 0) {
  610. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
  611. }
  612. $sql .= ' WHERE a.fk_action = ca.id';
  613. $sql .= ' AND a.entity IN (' . getEntity('agenda') . ')';
  614. // Condition on actioncode
  615. if (!empty($actioncode)) {
  616. if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
  617. if ($actioncode == 'AC_NON_AUTO') {
  618. $sql .= " AND ca.type != 'systemauto'";
  619. } elseif ($actioncode == 'AC_ALL_AUTO') {
  620. $sql .= " AND ca.type = 'systemauto'";
  621. } else {
  622. if ($actioncode == 'AC_OTH') {
  623. $sql .= " AND ca.type != 'systemauto'";
  624. }
  625. if ($actioncode == 'AC_OTH_AUTO') {
  626. $sql .= " AND ca.type = 'systemauto'";
  627. }
  628. }
  629. } else {
  630. if ($actioncode == 'AC_NON_AUTO') {
  631. $sql .= " AND ca.type != 'systemauto'";
  632. } elseif ($actioncode == 'AC_ALL_AUTO') {
  633. $sql .= " AND ca.type = 'systemauto'";
  634. } else {
  635. if (is_array($actioncode)) {
  636. $sql .= " AND ca.code IN (" . $db->sanitize("'" . implode("','", $actioncode) . "'", 1) . ")";
  637. } else {
  638. $sql .= " AND ca.code IN (" . $db->sanitize("'" . implode("','", explode(',', $actioncode)) . "'", 1) . ")";
  639. }
  640. }
  641. }
  642. }
  643. if ($resourceid > 0) {
  644. $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = " . ((int) $resourceid);
  645. }
  646. if ($pid) {
  647. $sql .= " AND a.fk_project=" . ((int) $pid);
  648. }
  649. if (empty($user->rights->societe->client->voir) && !$socid) {
  650. $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = " . ((int) $user->id) . ")";
  651. }
  652. if ($socid > 0) {
  653. $sql .= " AND a.fk_soc = " . ((int) $socid);
  654. }
  655. // We must filter on assignement table
  656. if ($filtert > 0 || $usergroup > 0) {
  657. $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
  658. }
  659. //var_dump($day.' '.$month.' '.$year);
  660. if ($mode == 'show_day') {
  661. $sql .= " AND (";
  662. $sql .= " (a.datep BETWEEN '" . $db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel')) . "'";
  663. $sql .= " AND '" . $db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel')) . "')";
  664. $sql .= " OR ";
  665. $sql .= " (a.datep2 BETWEEN '" . $db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel')) . "'";
  666. $sql .= " AND '" . $db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel')) . "')";
  667. $sql .= " OR ";
  668. $sql .= " (a.datep < '" . $db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel')) . "'";
  669. $sql .= " AND a.datep2 > '" . $db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel')) . "')";
  670. $sql .= ')';
  671. } else {
  672. // To limit array
  673. $sql .= " AND (";
  674. $sql .= " (a.datep BETWEEN '" . $db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7)) . "'"; // Start 7 days before
  675. $sql .= " AND '" . $db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10)) . "')"; // End 7 days after + 3 to go from 28 to 31
  676. $sql .= " OR ";
  677. $sql .= " (a.datep2 BETWEEN '" . $db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7)) . "'";
  678. $sql .= " AND '" . $db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10)) . "')";
  679. $sql .= " OR ";
  680. $sql .= " (a.datep < '" . $db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7)) . "'";
  681. $sql .= " AND a.datep2 > '" . $db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10)) . "')";
  682. $sql .= ')';
  683. }
  684. if ($type) {
  685. $sql .= " AND ca.id = " . ((int) $type);
  686. }
  687. $sql .= " AND a.code = 'AC_EVENT'";
  688. if ($status == '0') {
  689. // To do (not started)
  690. $sql .= " AND a.percent = 0";
  691. }
  692. if ($status == 'na') {
  693. // Not applicable
  694. $sql .= " AND a.percent = -1";
  695. }
  696. if ($status == '50') {
  697. // Running already started
  698. $sql .= " AND (a.percent > 0 AND a.percent < 100)";
  699. }
  700. if ($status == 'done' || $status == '100') {
  701. $sql .= " AND (a.percent = 100)";
  702. }
  703. if ($status == 'todo') {
  704. $sql .= " AND (a.percent >= 0 AND a.percent < 100)";
  705. }
  706. // We must filter on assignement table
  707. if ($filtert > 0 || $usergroup > 0) {
  708. $sql .= " AND (";
  709. if ($filtert > 0) {
  710. $sql .= "ar.fk_element = " . ((int) $filtert);
  711. }
  712. if ($usergroup > 0) {
  713. $sql .= ($filtert > 0 ? " OR " : "") . " ugu.fk_usergroup = " . ((int) $usergroup);
  714. }
  715. $sql .= ")";
  716. }
  717. // Sort on date
  718. $sql .= ' ORDER BY datep';
  719. //print $sql;
  720. dol_syslog("custom/booking/booking_agenda.php", LOG_DEBUG);
  721. $resql = $db->query($sql);
  722. if ($resql) {
  723. $num = $db->num_rows($resql);
  724. $MAXONSAMEPAGE = 10000; // Useless to have more. Protection to avoid memory overload when high number of event (for example after a mass import)
  725. $i = 0;
  726. while ($i < $num && $i < $MAXONSAMEPAGE) {
  727. $obj = $db->fetch_object($resql);
  728. // Discard auto action if option is on
  729. if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->type_code == 'AC_OTH_AUTO') {
  730. $i++;
  731. continue;
  732. }
  733. // Create a new object action
  734. $event = new ActionComm($db);
  735. $event->id = $obj->id;
  736. $event->ref = $event->id;
  737. $event->fulldayevent = $obj->fulldayevent;
  738. // event->datep and event->datef must be GMT date.
  739. if ($event->fulldayevent) {
  740. $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
  741. $event->datep = $db->jdate($obj->datep, $tzforfullday ? 'tzuser' : 'tzserver'); // If saved in $tzforfullday = gmt, we must invert date to be in user tz
  742. $event->datef = $db->jdate($obj->datep2, $tzforfullday ? 'tzuser' : 'tzserver');
  743. } else {
  744. // Example: $obj->datep = '1970-01-01 01:00:00', jdate will return 0 if TZ of PHP server is Europe/Berlin (+1)
  745. $event->datep = $db->jdate($obj->datep, 'tzserver');
  746. $event->datef = $db->jdate($obj->datep2, 'tzserver');
  747. }
  748. //$event->datep_formated_gmt = dol_print_date($event->datep, 'dayhour', 'gmt');
  749. //var_dump($obj->id.' '.$obj->datep.' '.dol_print_date($obj->datep, 'dayhour', 'gmt'));
  750. //var_dump($obj->id.' '.$event->datep.' '.dol_print_date($event->datep, 'dayhour', 'gmt'));
  751. $event->type_code = $obj->type_code;
  752. $event->type_label = $obj->type_label;
  753. $event->type_color = $obj->type_color;
  754. $event->type = $obj->type_type;
  755. $event->type_picto = $obj->type_picto;
  756. $event->libelle = $obj->label; // deprecated
  757. $event->label = $obj->label;
  758. $event->percentage = $obj->percent;
  759. $event->authorid = $obj->fk_user_author; // user id of creator
  760. $event->userownerid = $obj->fk_user_action; // user id of owner
  761. $event->fetch_userassigned(); // This load $event->userassigned
  762. $event->priority = $obj->priority;
  763. $event->location = $obj->location;
  764. $event->transparency = $obj->transparency;
  765. $event->fk_element = $obj->fk_element;
  766. $event->elementtype = $obj->elementtype;
  767. $event->fk_project = $obj->fk_project;
  768. $event->socid = $obj->fk_soc;
  769. $event->contact_id = $obj->fk_contact;
  770. // Defined date_start_in_calendar and date_end_in_calendar property
  771. // They are date start and end of action but modified to not be outside calendar view.
  772. $event->date_start_in_calendar = $event->datep;
  773. if ($event->datef != '' && $event->datef >= $event->datep) {
  774. $event->date_end_in_calendar = $event->datef;
  775. } else {
  776. $event->date_end_in_calendar = $event->datep;
  777. }
  778. // Check values
  779. if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow) {
  780. // This record is out of visible range
  781. } else {
  782. if ($event->date_start_in_calendar < $firstdaytoshow) {
  783. $event->date_start_in_calendar = $firstdaytoshow;
  784. }
  785. if ($event->date_end_in_calendar >= $lastdaytoshow) {
  786. $event->date_end_in_calendar = ($lastdaytoshow - 1);
  787. }
  788. // Add an entry in actionarray for each day
  789. $daycursor = $event->date_start_in_calendar;
  790. $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
  791. $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
  792. $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
  793. $daycursorend = $event->date_end_in_calendar;
  794. $anneeend = dol_print_date($daycursorend, '%Y', 'tzuserrel');
  795. $moisend = dol_print_date($daycursorend, '%m', 'tzuserrel');
  796. $jourend = dol_print_date($daycursorend, '%d', 'tzuserrel');
  797. //var_dump(dol_print_date($event->date_start_in_calendar, 'dayhour', 'gmt')); // Hour at greenwich
  798. //var_dump($annee.'-'.$mois.'-'.$jour);
  799. //print 'annee='.$annee.' mois='.$mois.' jour='.$jour.'<br>';
  800. // Loop on each day covered by action to prepare an index to show on calendar
  801. $loop = true;
  802. $j = 0;
  803. $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt'); // $mois, $jour, $annee has been set for user tz
  804. $daykeyend = dol_mktime(0, 0, 0, $moisend, $jourend, $anneeend, 'gmt'); // $moisend, $jourend, $anneeend has been set for user tz
  805. /*
  806. print 'GMT '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'gmt').'<br>';
  807. print 'TZSERVER '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzserver').'<br>';
  808. print 'TZUSERREL '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel').'<br>';
  809. print 'GMT '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'gmt').'<br>';
  810. print 'TZSERVER '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzserver').'<br>';
  811. print 'TZUSER '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel').'<br>';
  812. */
  813. do {
  814. //if ($event->id==408)
  815. //print 'daykey='.$daykey.' daykeyend='.$daykeyend.' '.dol_print_date($daykey, 'dayhour', 'gmt').' - '.dol_print_date($event->datep, 'dayhour', 'gmt').' '.dol_print_date($event->datef, 'dayhour', 'gmt').'<br>';
  816. //print 'daykey='.$daykey.' daykeyend='.$daykeyend.' '.dol_print_date($daykey, 'dayhour', 'tzuserrel').' - '.dol_print_date($event->datep, 'dayhour', 'tzuserrel').' '.dol_print_date($event->datef, 'dayhour', 'tzuserrel').'<br>';
  817. $eventarray[$daykey][] = $event;
  818. $j++;
  819. $daykey += 60 * 60 * 24;
  820. //if ($daykey > $event->date_end_in_calendar) {
  821. if ($daykey > $daykeyend) {
  822. $loop = false;
  823. }
  824. } while ($loop);
  825. //var_dump($eventarray);
  826. //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
  827. //print ' startincalendar='.dol_print_date($event->date_start_in_calendar).'-endincalendar='.dol_print_date($event->date_end_in_calendar).') was added in '.$j.' different index key of array<br>';
  828. }
  829. $i++;
  830. }
  831. } else {
  832. dol_print_error($db);
  833. }
  834. // LEAVE CALENDAR
  835. $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.statut, x.rowid, x.date_debut as date_start, x.date_fin as date_end, x.halfday, x.statut as status";
  836. $sql .= " FROM " . MAIN_DB_PREFIX . "holiday as x, " . MAIN_DB_PREFIX . "user as u";
  837. $sql .= " WHERE u.rowid = x.fk_user";
  838. $sql .= " AND u.statut = '1'"; // Show only active users (0 = inactive user, 1 = active user)
  839. $sql .= " AND (x.statut = '2' OR x.statut = '3')"; // Show only public leaves (2 = leave wait for approval, 3 = leave approved)
  840. if ($mode == 'show_day') {
  841. // Request only leaves for the current selected day
  842. $sql .= " AND '" . $db->escape($year) . "-" . $db->escape($month) . "-" . $db->escape($day) . "' BETWEEN x.date_debut AND x.date_fin"; // date_debut and date_fin are date without time
  843. } elseif ($mode == 'show_week') {
  844. // TODO: Add filter to reduce database request
  845. } elseif ($mode == 'show_month') {
  846. // TODO: Add filter to reduce database request
  847. }
  848. $resql = $db->query($sql);
  849. if ($resql) {
  850. $num = $db->num_rows($resql);
  851. $i = 0;
  852. while ($i < $num) {
  853. $obj = $db->fetch_object($resql);
  854. $event = new ActionComm($db);
  855. // Need the id of the leave object for link to it
  856. $event->id = $obj->rowid;
  857. $event->ref = $event->id;
  858. $event->type_code = 'HOLIDAY';
  859. $event->type_label = '';
  860. $event->type_color = '';
  861. $event->type = 'holiday';
  862. $event->type_picto = 'holiday';
  863. $event->datep = $db->jdate($obj->date_start) + (empty($halfday) || $halfday == 1 ? 0 : 12 * 60 * 60 - 1);
  864. $event->datef = $db->jdate($obj->date_end) + (empty($halfday) || $halfday == -1 ? 24 : 12) * 60 * 60 - 1;
  865. $event->date_start_in_calendar = $event->datep;
  866. $event->date_end_in_calendar = $event->datef;
  867. if ($obj->status == 3) {
  868. // Show no symbol for leave with state "leave approved"
  869. $event->percentage = -1;
  870. } elseif ($obj->status == 2) {
  871. // Show TO-DO symbol for leave with state "leave wait for approval"
  872. $event->percentage = 0;
  873. }
  874. if ($obj->halfday == 1) {
  875. $event->label = $obj->lastname . ' (' . $langs->trans("Morning") . ')';
  876. } elseif ($obj->halfday == -1) {
  877. $event->label = $obj->lastname . ' (' . $langs->trans("Afternoon") . ')';
  878. } else {
  879. $event->label = $obj->lastname;
  880. }
  881. $daycursor = $event->date_start_in_calendar;
  882. $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
  883. $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
  884. $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
  885. $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
  886. do {
  887. $eventarray[$daykey][] = $event;
  888. $daykey += 60 * 60 * 24;
  889. } while ($daykey <= $event->date_end_in_calendar);
  890. $i++;
  891. }
  892. }
  893. // EXTERNAL CALENDAR
  894. // Complete $eventarray with external import Ical
  895. if (count($listofextcals)) {
  896. require_once DOL_DOCUMENT_ROOT . '/comm/action/class/ical.class.php';
  897. foreach ($listofextcals as $extcal) {
  898. $url = $extcal['src']; // Example: https://www.google.com/calendar/ical/eldy10%40gmail.com/private-cde92aa7d7e0ef6110010a821a2aaeb/basic.ics
  899. $namecal = $extcal['name'];
  900. $offsettz = $extcal['offsettz'];
  901. $colorcal = $extcal['color'];
  902. $buggedfile = $extcal['buggedfile'];
  903. $ical = new ICal();
  904. $ical->parse($url);
  905. // After this $ical->cal['VEVENT'] contains array of events, $ical->cal['DAYLIGHT'] contains daylight info, $ical->cal['STANDARD'] contains non daylight info, ...
  906. //var_dump($ical->cal); exit;
  907. $icalevents = array();
  908. if (is_array($ical->get_event_list())) {
  909. $icalevents = array_merge($icalevents, $ical->get_event_list()); // Add $ical->cal['VEVENT']
  910. }
  911. if (is_array($ical->get_freebusy_list())) {
  912. $icalevents = array_merge($icalevents, $ical->get_freebusy_list()); // Add $ical->cal['VFREEBUSY']
  913. }
  914. if (count($icalevents) > 0) {
  915. // Duplicate all repeatable events into new entries
  916. $moreicalevents = array();
  917. foreach ($icalevents as $icalevent) {
  918. if (isset($icalevent['RRULE']) && is_array($icalevent['RRULE'])) { //repeatable event
  919. //if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
  920. //if ($event->date_end_in_calendar > $lastdaytoshow) $event->date_end_in_calendar=($lastdaytoshow-1);
  921. if ($icalevent['DTSTART;VALUE=DATE']) { //fullday event
  922. $datecurstart = dol_stringtotime($icalevent['DTSTART;VALUE=DATE'], 1);
  923. $datecurend = dol_stringtotime($icalevent['DTEND;VALUE=DATE'], 1) - 1; // We remove one second to get last second of day
  924. } elseif (is_array($icalevent['DTSTART']) && !empty($icalevent['DTSTART']['unixtime'])) {
  925. $datecurstart = $icalevent['DTSTART']['unixtime'];
  926. $datecurend = $icalevent['DTEND']['unixtime'];
  927. if (!empty($ical->cal['DAYLIGHT']['DTSTART']) && $datecurstart) {
  928. //var_dump($ical->cal);
  929. $tmpcurstart = $datecurstart;
  930. $tmpcurend = $datecurend;
  931. $tmpdaylightstart = dol_mktime(0, 0, 0, 1, 1, 1970, 1) + (int) $ical->cal['DAYLIGHT']['DTSTART'];
  932. $tmpdaylightend = dol_mktime(0, 0, 0, 1, 1, 1970, 1) + (int) $ical->cal['STANDARD']['DTSTART'];
  933. //var_dump($tmpcurstart);var_dump($tmpcurend); var_dump($ical->cal['DAYLIGHT']['DTSTART']);var_dump($ical->cal['STANDARD']['DTSTART']);
  934. // Edit datecurstart and datecurend
  935. if ($tmpcurstart >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) {
  936. $datecurstart -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
  937. } else {
  938. $datecurstart -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
  939. }
  940. if ($tmpcurend >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) {
  941. $datecurend -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
  942. } else {
  943. $datecurend -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
  944. }
  945. }
  946. // datecurstart and datecurend are now GMT date
  947. //var_dump($datecurstart); var_dump($datecurend); exit;
  948. } else {
  949. // Not a recongized record
  950. dol_syslog("Found a not recognized repeatable record with unknown date start", LOG_ERR);
  951. continue;
  952. }
  953. //print 'xx'.$datecurstart;exit;
  954. $interval = (empty($icalevent['RRULE']['INTERVAL']) ? 1 : $icalevent['RRULE']['INTERVAL']);
  955. $until = empty($icalevent['RRULE']['UNTIL']) ? 0 : dol_stringtotime($icalevent['RRULE']['UNTIL'], 1);
  956. $maxrepeat = empty($icalevent['RRULE']['COUNT']) ? 0 : $icalevent['RRULE']['COUNT'];
  957. if ($until && ($until + ($datecurend - $datecurstart)) < $firstdaytoshow) {
  958. continue; // We discard repeatable event that end before start date to show
  959. }
  960. if ($datecurstart >= $lastdaytoshow) {
  961. continue; // We discard repeatable event that start after end date to show
  962. }
  963. $numofevent = 0;
  964. while (($datecurstart < $lastdaytoshow) && (empty($maxrepeat) || ($numofevent < $maxrepeat))) {
  965. if ($datecurend >= $firstdaytoshow) { // We add event
  966. $newevent = $icalevent;
  967. unset($newevent['RRULE']);
  968. if ($icalevent['DTSTART;VALUE=DATE']) {
  969. $newevent['DTSTART;VALUE=DATE'] = dol_print_date($datecurstart, '%Y%m%d');
  970. $newevent['DTEND;VALUE=DATE'] = dol_print_date($datecurend + 1, '%Y%m%d');
  971. } else {
  972. $newevent['DTSTART'] = $datecurstart;
  973. $newevent['DTEND'] = $datecurend;
  974. }
  975. $moreicalevents[] = $newevent;
  976. }
  977. // Jump on next occurence
  978. $numofevent++;
  979. $savdatecurstart = $datecurstart;
  980. if ($icalevent['RRULE']['FREQ'] == 'DAILY') {
  981. $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'd');
  982. $datecurend = dol_time_plus_duree($datecurend, $interval, 'd');
  983. }
  984. if ($icalevent['RRULE']['FREQ'] == 'WEEKLY') {
  985. $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'w');
  986. $datecurend = dol_time_plus_duree($datecurend, $interval, 'w');
  987. } elseif ($icalevent['RRULE']['FREQ'] == 'MONTHLY') {
  988. $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'm');
  989. $datecurend = dol_time_plus_duree($datecurend, $interval, 'm');
  990. } elseif ($icalevent['RRULE']['FREQ'] == 'YEARLY') {
  991. $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'y');
  992. $datecurend = dol_time_plus_duree($datecurend, $interval, 'y');
  993. }
  994. // Test to avoid infinite loop ($datecurstart must increase)
  995. if ($savdatecurstart >= $datecurstart) {
  996. dol_syslog("Found a rule freq " . $icalevent['RRULE']['FREQ'] . " not managed by dolibarr code. Assume 1 week frequency.", LOG_ERR);
  997. $datecurstart += 3600 * 24 * 7;
  998. $datecurend += 3600 * 24 * 7;
  999. }
  1000. }
  1001. }
  1002. }
  1003. $icalevents = array_merge($icalevents, $moreicalevents);
  1004. // Loop on each entry into cal file to know if entry is qualified and add an ActionComm into $eventarray
  1005. foreach ($icalevents as $icalevent) {
  1006. //var_dump($icalevent);
  1007. //print $icalevent['SUMMARY'].'->';
  1008. //var_dump($icalevent);exit;
  1009. if (!empty($icalevent['RRULE'])) {
  1010. continue; // We found a repeatable event. It was already split into unitary events, so we discard general rule.
  1011. }
  1012. // Create a new object action
  1013. $event = new ActionComm($db);
  1014. $addevent = false;
  1015. if (isset($icalevent['DTSTART;VALUE=DATE'])) { // fullday event
  1016. // For full day events, date are also GMT but they wont but converted using tz during output
  1017. $datestart = dol_stringtotime($icalevent['DTSTART;VALUE=DATE'], 1);
  1018. if (empty($icalevent['DTEND;VALUE=DATE'])) {
  1019. $dateend = $datestart + 86400 - 1;
  1020. } else {
  1021. $dateend = dol_stringtotime($icalevent['DTEND;VALUE=DATE'], 1) - 1; // We remove one second to get last second of day
  1022. }
  1023. //print 'x'.$datestart.'-'.$dateend;exit;
  1024. //print dol_print_date($dateend,'dayhour','gmt');
  1025. $event->fulldayevent = 1;
  1026. $addevent = true;
  1027. } elseif (!is_array($icalevent['DTSTART'])) { // not fullday event (DTSTART is not array. It is a value like '19700101T000000Z' for 00:00 in greenwitch)
  1028. $datestart = $icalevent['DTSTART'];
  1029. $dateend = empty($icalevent['DTEND']) ? $datestart : $icalevent['DTEND'];
  1030. $datestart += +($offsettz * 3600);
  1031. $dateend += +($offsettz * 3600);
  1032. $addevent = true;
  1033. //var_dump($offsettz);
  1034. //var_dump(dol_print_date($datestart, 'dayhour', 'gmt'));
  1035. } elseif (isset($icalevent['DTSTART']['unixtime'])) { // File contains a local timezone + a TZ (for example when using bluemind)
  1036. $datestart = $icalevent['DTSTART']['unixtime'];
  1037. $dateend = $icalevent['DTEND']['unixtime'];
  1038. $datestart += +($offsettz * 3600);
  1039. $dateend += +($offsettz * 3600);
  1040. // $buggedfile is set to uselocalandtznodaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtznodaylight'
  1041. if ($buggedfile === 'uselocalandtznodaylight') { // unixtime is a local date that does not take daylight into account, TZID is +1 for example for 'Europe/Paris' in summer instead of 2
  1042. // TODO
  1043. }
  1044. // $buggedfile is set to uselocalandtzdaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtzdaylight' (for example with bluemind)
  1045. if ($buggedfile === 'uselocalandtzdaylight') { // unixtime is a local date that does take daylight into account, TZID is +2 for example for 'Europe/Paris' in summer
  1046. $localtzs = new DateTimeZone(preg_replace('/"/', '', $icalevent['DTSTART']['TZID']));
  1047. $localtze = new DateTimeZone(preg_replace('/"/', '', $icalevent['DTEND']['TZID']));
  1048. $localdts = new DateTime(dol_print_date($datestart, 'dayrfc', 'gmt'), $localtzs);
  1049. $localdte = new DateTime(dol_print_date($dateend, 'dayrfc', 'gmt'), $localtze);
  1050. $tmps = -1 * $localtzs->getOffset($localdts);
  1051. $tmpe = -1 * $localtze->getOffset($localdte);
  1052. $datestart += $tmps;
  1053. $dateend += $tmpe;
  1054. //var_dump($datestart);
  1055. }
  1056. $addevent = true;
  1057. }
  1058. if ($addevent) {
  1059. $event->id = $icalevent['UID'];
  1060. $event->ref = $event->id;
  1061. $userId = $userstatic->findUserIdByEmail($namecal);
  1062. if (!empty($userId) && $userId > 0) {
  1063. $event->userassigned[$userId] = $userId;
  1064. $event->percentage = -1;
  1065. }
  1066. $event->type_code = "ICALEVENT";
  1067. $event->type_label = $namecal;
  1068. $event->type_color = $colorcal;
  1069. $event->type = 'icalevent';
  1070. $event->type_picto = 'rss';
  1071. $event->icalname = $namecal;
  1072. $event->icalcolor = $colorcal;
  1073. $usertime = 0; // We dont modify date because we want to have date into memory datep and datef stored as GMT date. Compensation will be done during output.
  1074. $event->datep = $datestart + $usertime;
  1075. $event->datef = $dateend + $usertime;
  1076. if ($icalevent['SUMMARY']) {
  1077. $event->label = dol_string_nohtmltag($icalevent['SUMMARY']);
  1078. } elseif ($icalevent['DESCRIPTION']) {
  1079. $event->label = dol_nl2br(dol_string_nohtmltag($icalevent['DESCRIPTION']), 1);
  1080. } else {
  1081. $event->label = $langs->trans("ExtSiteNoLabel");
  1082. }
  1083. // Priority (see https://www.kanzaki.com/docs/ical/priority.html)
  1084. // LOW = 0 to 4
  1085. // MEDIUM = 5
  1086. // HIGH = 6 to 9
  1087. if (!empty($icalevent['PRIORITY'])) {
  1088. $event->priority = $icalevent['PRIORITY'];
  1089. }
  1090. // Transparency (see https://www.kanzaki.com/docs/ical/transp.html)
  1091. if (!empty($icalevent['TRANSP'])) {
  1092. if ($icalevent['TRANSP'] == "TRANSPARENT") {
  1093. $event->transparency = 0; // 0 = available / free
  1094. }
  1095. if ($icalevent['TRANSP'] == "OPAQUE") {
  1096. $event->transparency = 1; // 1 = busy
  1097. }
  1098. // TODO: MS outlook states
  1099. // X-MICROSOFT-CDO-BUSYSTATUS:FREE + TRANSP:TRANSPARENT => Available / Free
  1100. // X-MICROSOFT-CDO-BUSYSTATUS:FREE + TRANSP:OPAQUE => Work another place
  1101. // X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE + TRANSP:OPAQUE => With reservations
  1102. // X-MICROSOFT-CDO-BUSYSTATUS:BUSY + TRANSP:OPAQUE => Busy
  1103. // X-MICROSOFT-CDO-BUSYSTATUS:OOF + TRANSP:OPAQUE => Away from the office / off-site
  1104. }
  1105. if (!empty($icalevent['LOCATION'])) {
  1106. $event->location = $icalevent['LOCATION'];
  1107. }
  1108. $event->date_start_in_calendar = $event->datep;
  1109. if ($event->datef != '' && $event->datef >= $event->datep) {
  1110. $event->date_end_in_calendar = $event->datef;
  1111. } else {
  1112. $event->date_end_in_calendar = $event->datep;
  1113. }
  1114. // Add event into $eventarray if date range are ok.
  1115. if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow) {
  1116. //print 'x'.$datestart.'-'.$dateend;exit;
  1117. //print 'x'.$datestart.'-'.$dateend;exit;
  1118. //print 'x'.$datestart.'-'.$dateend;exit;
  1119. // This record is out of visible range
  1120. } else {
  1121. if ($event->date_start_in_calendar < $firstdaytoshow) {
  1122. $event->date_start_in_calendar = $firstdaytoshow;
  1123. }
  1124. if ($event->date_end_in_calendar >= $lastdaytoshow) {
  1125. $event->date_end_in_calendar = ($lastdaytoshow - 1);
  1126. }
  1127. // Add an entry in actionarray for each day
  1128. $daycursor = $event->date_start_in_calendar;
  1129. $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
  1130. $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
  1131. $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
  1132. // Loop on each day covered by action to prepare an index to show on calendar
  1133. $loop = true;
  1134. $j = 0;
  1135. // daykey must be date that represent day box in calendar so must be a user time
  1136. $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
  1137. $daykeygmt = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
  1138. do {
  1139. //if ($event->fulldayevent) print dol_print_date($daykeygmt,'dayhour','gmt').'-'.dol_print_date($daykey,'dayhour','gmt').'-'.dol_print_date($event->date_end_in_calendar,'dayhour','gmt').' ';
  1140. $eventarray[$daykey][] = $event;
  1141. $daykey += 60 * 60 * 24;
  1142. $daykeygmt += 60 * 60 * 24; // Add one day
  1143. if (($event->fulldayevent ? $daykeygmt : $daykey) > $event->date_end_in_calendar) {
  1144. $loop = false;
  1145. }
  1146. } while ($loop);
  1147. }
  1148. }
  1149. }
  1150. }
  1151. }
  1152. }
  1153. // Complete $eventarray with events coming from external module
  1154. $parameters = array();
  1155. $object = null;
  1156. $reshook = $hookmanager->executeHooks('getCalendarEvents', $parameters, $object, $action);
  1157. if (!empty($hookmanager->resArray['eventarray'])) {
  1158. foreach ($hookmanager->resArray['eventarray'] as $keyDate => $events) {
  1159. if (!isset($eventarray[$keyDate])) {
  1160. $eventarray[$keyDate] = array();
  1161. }
  1162. $eventarray[$keyDate] = array_merge($eventarray[$keyDate], $events);
  1163. }
  1164. }
  1165. // Sort events
  1166. foreach ($eventarray as $keyDate => &$dateeventarray) {
  1167. usort($dateeventarray, 'sort_events_by_date');
  1168. }
  1169. $maxnbofchar = 0;
  1170. $cachethirdparties = array();
  1171. $cachecontacts = array();
  1172. $cacheusers = array();
  1173. // Define theme_datacolor array
  1174. $color_file = DOL_DOCUMENT_ROOT . "/theme/" . $conf->theme . "/theme_vars.inc.php";
  1175. if (is_readable($color_file)) {
  1176. include $color_file;
  1177. }
  1178. if (!is_array($theme_datacolor)) {
  1179. $theme_datacolor = array(array(120, 130, 150), array(200, 160, 180), array(190, 190, 220));
  1180. }
  1181. $massactionbutton = '';
  1182. print_barre_liste($langs->trans("Agenda"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, -1, 'object_action', 0, $nav . '<span class="marginleftonly"></span>' . $newcardbutton, '', $limit, 1, 0, 1, $viewmode);
  1183. // Show div with list of calendars
  1184. print $s;
  1185. if (empty($mode) || $mode == 'show_month') { // View by month
  1186. $newparam = $param; // newparam is for birthday links
  1187. $newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
  1188. $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
  1189. $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
  1190. $newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
  1191. $newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
  1192. $newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
  1193. $newparam = preg_replace('/viewcal=[0-9]+&?/i', '', $newparam);
  1194. $newparam = preg_replace('/showbirthday_=/i', 'showbirthday=', $newparam); // Restore correct parameter
  1195. $newparam .= '&viewcal=1';
  1196. /* print '<div class="liste_titre liste_titre_bydiv centpercent">';
  1197. print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
  1198. print '</div>'; */
  1199. print '<div class="div-table-responsive-no-min sectioncalendarbymonth maxscreenheightless300">';
  1200. print '<table class="centpercent noborder nocellnopadd cal_pannel cal_month">';
  1201. print ' <tr class="liste_titre">';
  1202. // Column title of weeks numbers
  1203. echo ' <td class="center">#</td>';
  1204. $i = 0;
  1205. while ($i < 7) {
  1206. print ' <td class="center bold uppercase tdfordaytitle' . ($i == 0 ? ' borderleft' : '') . '">';
  1207. $numdayinweek = (($i + (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1)) % 7);
  1208. if (!empty($conf->dol_optimize_smallscreen)) {
  1209. $labelshort = array(0 => 'SundayMin', 1 => 'MondayMin', 2 => 'TuesdayMin', 3 => 'WednesdayMin', 4 => 'ThursdayMin', 5 => 'FridayMin', 6 => 'SaturdayMin');
  1210. print $langs->trans($labelshort[$numdayinweek]);
  1211. } else {
  1212. print $langs->trans("Day" . $numdayinweek);
  1213. }
  1214. print ' </td>' . "\n";
  1215. $i++;
  1216. }
  1217. echo ' </tr>' . "\n";
  1218. $todayarray = dol_getdate($now, 'fast');
  1219. $todaytms = dol_mktime(0, 0, 0, $todayarray['mon'], $todayarray['mday'], $todayarray['year']);
  1220. // In loops, tmpday contains day nb in current month (can be zero or negative for days of previous month)
  1221. //var_dump($eventarray);
  1222. for ($iter_week = 0; $iter_week < 6; $iter_week++) {
  1223. echo " <tr>\n";
  1224. // Get date of the current day, format 'yyyy-mm-dd'
  1225. if ($tmpday <= 0) { // If number of the current day is in previous month
  1226. $currdate0 = sprintf("%04d", $prev_year) . sprintf("%02d", $prev_month) . sprintf("%02d", $max_day_in_prev_month + $tmpday);
  1227. } elseif ($tmpday <= $max_day_in_month) { // If number of the current day is in current month
  1228. $currdate0 = sprintf("%04d", $year) . sprintf("%02d", $month) . sprintf("%02d", $tmpday);
  1229. } else // If number of the current day is in next month
  1230. {
  1231. $currdate0 = sprintf("%04d", $next_year) . sprintf("%02d", $next_month) . sprintf("%02d", $tmpday - $max_day_in_month);
  1232. }
  1233. // Get week number for the targeted date '$currdate0'
  1234. $numweek0 = date("W", strtotime(date($currdate0)));
  1235. // Show the week number, and define column width
  1236. echo ' <td class="center weeknumber opacitymedium" width="2%">' . $numweek0 . '</td>';
  1237. for ($iter_day = 0; $iter_day < 7; $iter_day++) {
  1238. if ($tmpday <= 0) {
  1239. /* Show days before the beginning of the current month (previous month) */
  1240. $style = 'cal_other_month cal_past';
  1241. if ($iter_day == 6) {
  1242. $style .= ' cal_other_month_right';
  1243. }
  1244. echo ' <td class="' . $style . ' nowrap tdtop" width="14%">';
  1245. show_day_events($db, $max_day_in_prev_month + $tmpday, $prev_month, $prev_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
  1246. echo " </td>\n";
  1247. } elseif ($tmpday <= $max_day_in_month) {
  1248. /* Show days of the current month */
  1249. $curtime = dol_mktime(0, 0, 0, $month, $tmpday, $year);
  1250. $style = 'cal_current_month';
  1251. if ($iter_day == 6) {
  1252. $style .= ' cal_current_month_right';
  1253. }
  1254. $today = 0;
  1255. if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
  1256. $today = 1;
  1257. }
  1258. if ($today) {
  1259. $style = 'cal_today';
  1260. }
  1261. if ($curtime < $todaytms) {
  1262. $style .= ' cal_past';
  1263. }
  1264. //var_dump($todayarray['mday']."==".$tmpday." && ".$todayarray['mon']."==".$month." && ".$todayarray['year']."==".$year.' -> '.$style);
  1265. echo ' <td class="' . $style . ' nowrap tdtop" width="14%">';
  1266. show_day_events($db, $tmpday, $month, $year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
  1267. echo "</td>\n";
  1268. } else {
  1269. /* Show days after the current month (next month) */
  1270. $style = 'cal_other_month';
  1271. if ($iter_day == 6) {
  1272. $style .= ' cal_other_month_right';
  1273. }
  1274. echo ' <td class="' . $style . ' nowrap tdtop" width="14%">';
  1275. show_day_events($db, $tmpday - $max_day_in_month, $next_month, $next_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
  1276. echo "</td>\n";
  1277. }
  1278. $tmpday++;
  1279. }
  1280. echo " </tr>\n";
  1281. }
  1282. print "</table>\n";
  1283. print '</div>';
  1284. print '<input type="hidden" name="actionmove" value="mupdate">';
  1285. print '<input type="hidden" name="backtopage" value="' . dol_escape_htmltag($_SERVER['PHP_SELF']) . '?mode=show_month&' . dol_escape_htmltag($_SERVER['QUERY_STRING']) . '">';
  1286. print '<input type="hidden" name="newdate" id="newdate">';
  1287. } elseif ($mode == 'show_week') {
  1288. // View by week
  1289. $newparam = $param; // newparam is for birthday links
  1290. $newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
  1291. $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
  1292. $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
  1293. $newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
  1294. $newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
  1295. $newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
  1296. $newparam = preg_replace('/viewweek=[0-9]+&?/i', '', $newparam);
  1297. $newparam = preg_replace('/showbirthday_=/i', 'showbirthday=', $newparam); // Restore correct parameter
  1298. $newparam .= '&viewweek=1';
  1299. /* print '<div class="liste_titre liste_titre_bydiv centpercent"><div class="divsearchfield">';
  1300. print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
  1301. print '</div></div>'; */
  1302. print '<div class="div-table-responsive-no-min sectioncalendarbyweek maxscreenheightless300">';
  1303. print '<table class="centpercent noborder nocellnopadd cal_pannel cal_month">';
  1304. print ' <tr class="liste_titre">';
  1305. $i = 0;
  1306. while ($i < 7) {
  1307. echo ' <td class="center bold uppercase tdfordaytitle">' . $langs->trans("Day" . (($i + (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1)) % 7)) . "</td>\n";
  1308. $i++;
  1309. }
  1310. echo " </tr>\n";
  1311. echo " <tr>\n";
  1312. for ($iter_day = 0; $iter_day < 7; $iter_day++) {
  1313. // Show days of the current week
  1314. $curtime = dol_time_plus_duree($firstdaytoshow, $iter_day, 'd'); // $firstdaytoshow is in timezone of server
  1315. $tmpday = dol_print_date($curtime, '%d', 'tzuserrel');
  1316. $tmpmonth = dol_print_date($curtime, '%m', 'tzuserrel');
  1317. $tmpyear = dol_print_date($curtime, '%Y', 'tzuserrel');
  1318. $style = 'cal_current_month';
  1319. if ($iter_day == 6) {
  1320. $style .= ' cal_other_month_right';
  1321. }
  1322. $today = 0;
  1323. $todayarray = dol_getdate($now, 'fast');
  1324. if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $tmpmonth && $todayarray['year'] == $tmpyear) {
  1325. $today = 1;
  1326. }
  1327. if ($today) {
  1328. $style = 'cal_today';
  1329. }
  1330. echo ' <td class="' . $style . '" width="14%" valign="top">';
  1331. show_day_events($db, $tmpday, $tmpmonth, $tmpyear, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300);
  1332. echo " </td>\n";
  1333. }
  1334. echo " </tr>\n";
  1335. print "</table>\n";
  1336. print '</div>';
  1337. echo '<input type="hidden" name="actionmove" value="mupdate">';
  1338. echo '<input type="hidden" name="backtopage" value="' . dol_escape_htmltag($_SERVER['PHP_SELF']) . '?mode=show_week&' . dol_escape_htmltag($_SERVER['QUERY_STRING']) . '">';
  1339. echo '<input type="hidden" name="newdate" id="newdate">';
  1340. } else { // View by day
  1341. $newparam = $param; // newparam is for birthday links
  1342. $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
  1343. $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
  1344. $newparam = preg_replace('/viewday=[0-9]+&?/i', '', $newparam);
  1345. $newparam .= '&viewday=1';
  1346. // Code to show just one day
  1347. $style = 'cal_current_month cal_current_month_oneday';
  1348. $today = 0;
  1349. $todayarray = dol_getdate($now, 'fast');
  1350. if ($todayarray['mday'] == $day && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
  1351. $today = 1;
  1352. }
  1353. //if ($today) $style='cal_today';
  1354. $timestamp = dol_mktime(12, 0, 0, $month, $day, $year);
  1355. $arraytimestamp = dol_getdate($timestamp);
  1356. /* print '<div class="liste_titre liste_titre_bydiv centpercent"><div class="divsearchfield">';
  1357. print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
  1358. print '</div></div>'; */
  1359. print '<div class="div-table-responsive-no-min sectioncalendarbyday maxscreenheightless300">';
  1360. echo '<table class="tagtable centpercent noborder nocellnopadd cal_pannel cal_month noborderbottom" style="margin-bottom: 5px !important;">';
  1361. echo ' <tr class="tagtr liste_titre">';
  1362. echo ' <td class="tagtd center bold uppercase">' . $langs->trans("Day" . $arraytimestamp['wday']) . "</td>\n";
  1363. echo " </td>\n";
  1364. /*
  1365. echo ' <div class="tagtr">';
  1366. echo ' <div class="tagtd width100"></div>';
  1367. echo ' <div class="tagtd center">';
  1368. echo show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, -1);
  1369. echo ' </div>'."\n";
  1370. echo " </div>\n";
  1371. */
  1372. echo '</table>';
  1373. print '</div>';
  1374. /* WIP View per hour */
  1375. $useviewhour = 0;
  1376. if ($useviewhour) {
  1377. print '<div class="div-table-responsive-no-min borderbottom">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  1378. $maxheightwin = (isset($_SESSION["dol_screenheight"]) && $_SESSION["dol_screenheight"] > 500) ? ($_SESSION["dol_screenheight"] - 200) : 660; // Also into index.php file
  1379. echo '<div style="max-height: ' . $maxheightwin . 'px;">';
  1380. echo '<div class="tagtable centpercent calendarviewcontainer">';
  1381. $maxnbofchar = 80;
  1382. $tmp = explode('-', $conf->global->MAIN_DEFAULT_WORKING_HOURS);
  1383. $minhour = round($tmp[0], 0);
  1384. $maxhour = round($tmp[1], 0);
  1385. if ($minhour > 23) {
  1386. $minhour = 23;
  1387. }
  1388. if ($maxhour < 1) {
  1389. $maxhour = 1;
  1390. }
  1391. if ($maxhour <= $minhour) {
  1392. $maxhour = $minhour + 1;
  1393. }
  1394. $i = 0;
  1395. $j = 0;
  1396. while ($i < 24) {
  1397. echo ' <div class="tagtr calendarviewcontainertr">' . "\n";
  1398. echo ' <div class="tagtd width100 tdtop">' . dol_print_date($i * 3600, 'hour', 'gmt') . '</div>';
  1399. echo ' <div class="tagtd ' . $style . ' tdtop"></div>' . "\n";
  1400. echo ' </div>' . "\n";
  1401. $i++;
  1402. $j++;
  1403. }
  1404. echo '</div></div>';
  1405. show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 1);
  1406. print '</div>';
  1407. } else {
  1408. $eventdayDates = $bookingAgendaHelper->getEventDayDates($year, $month, $day);
  1409. print $eventdayDates['eventdayprint'];
  1410. $k = 0;
  1411. $dailyStartTime = 9;
  1412. $dailyEndTime = 21;
  1413. $eventsArray = [];
  1414. $daysql = "SELECT
  1415. ed.rowid as eventdetail_id,
  1416. ed.label as eventdetail_label,
  1417. ac.id as actioncomm_id,
  1418. ac.datep,
  1419. ac.datep2,
  1420. ac.durationp,
  1421. ace.buffer,
  1422. ace.max_num,
  1423. ace.participants,
  1424. ed.fk_elventlocation_departure
  1425. FROM llx_eventwizard_eventdetails as ed
  1426. INNER JOIN llx_actioncomm as ac ON ac.fk_element = ed.rowid
  1427. INNER JOIN llx_actioncomm_extrafields as ace ON ace.fk_object = ac.id
  1428. WHERE ed.type IN (3,4)
  1429. AND ac.code = 'AC_EVENT'
  1430. AND ac.datep BETWEEN '{$eventdayDates['from']}' AND '{$eventdayDates['to']}'
  1431. AND ace.participants IS NOT NULL
  1432. ORDER BY ac.id DESC";
  1433. //print $daysql;
  1434. $eventsArray = $bookingAgendaHelper->getOneColumnFromTable($daysql, $eventsArray, 'actioncomm_id');
  1435. $locationArray = $bookingAgendaHelper->getlocations();
  1436. print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  1437. print '<table style="width:100%">';
  1438. print '<tr class="firstcolumn">
  1439. <td style="width:15%">' . $langs->trans('Location') . '</td>
  1440. <td style="width:7%">' . $langs->trans('Status') . '</td>';
  1441. for ($i = 9; $i < 21; $i++) {
  1442. $hourText = $i < 10 ? '0' . $i : $i;
  1443. //print '<td>' . $hourText . ':00 - ' . $hourText . ':59</td>';
  1444. print '<td>' . $hourText . '</td>';
  1445. $k++;
  1446. }
  1447. $k = $k + 2;
  1448. print '<tr class="elvalaszto"><td colspan="' . $k . '"></td></tr>';
  1449. print '</tr>';
  1450. /* print '<tr class="trheight">
  1451. <td class="firstcolumn"></td>
  1452. <td class="center">Max. létszám</td>';
  1453. $rowcolorCounter = 0;
  1454. for ($i = $dailyStartTime; $i < $dailyEndTime; $i++) {
  1455. $backgroundColor = $bookingAgendaHelper->getBGColor($rowcolorCounter);
  1456. $hourText = $bookingAgendaHelper->getHourText($i);
  1457. print '<td class="center" style="background-color: ' . $backgroundColor . ';">' . $bookingAgendaHelper->getMaxNumFromEVENT($eventsArray) . '</td>';
  1458. $rowcolorCounter++;
  1459. }
  1460. print '</tr>'; */
  1461. foreach ($eventsArray as $event) {
  1462. print '<tr class="trheight">
  1463. <td class="firstcolumn"></td>
  1464. <td class="center">Foglalás</td>';
  1465. $rowcolorCounter = 0;
  1466. for ($i = $dailyStartTime; $i < $dailyEndTime; $i++) {
  1467. $backgroundColor = $bookingAgendaHelper->getBGColor($rowcolorCounter);
  1468. $hourText = $bookingAgendaHelper->getHourText($i);
  1469. print '<td class="center" style="background-color: ' . $backgroundColor . ';">' . $bookingAgendaHelper->getsumReservation($event, $eventdayDates['eventday'], $hourText) . '</td>';
  1470. $rowcolorCounter++;
  1471. }
  1472. print '</tr>';
  1473. print '<tr class="trheight foglaltsag">
  1474. <td class="location firstcolumn">' . $locationArray[$bookingAgendaHelper->getLocationLabel($event)] . '</td>
  1475. <td class="center">Foglalt</td>';
  1476. $rowcolorCounter = 0;
  1477. for ($i = $dailyStartTime; $i < $dailyEndTime; $i++) {
  1478. $backgroundColor = $bookingAgendaHelper->getBGColor($rowcolorCounter);
  1479. $hourText = $bookingAgendaHelper->getHourText($i);
  1480. print '<td class="center" style="background-color: ' . $backgroundColor . ';">' . $bookingAgendaHelper->getsumOccupied($event, $eventdayDates['eventday'], $hourText) . '</td>';
  1481. $rowcolorCounter++;
  1482. }
  1483. print '</tr>';
  1484. print '<tr class="trheight">
  1485. <td class="firstcolumn"></td>
  1486. <td class="center">Szervíz</td>';
  1487. $rowcolorCounter = 0;
  1488. for ($i = $dailyStartTime; $i < $dailyEndTime; $i++) {
  1489. $backgroundColor = $bookingAgendaHelper->getBGColor($rowcolorCounter);
  1490. $hourText = $bookingAgendaHelper->getHourText($i);
  1491. print '<td class="center" style="background-color: ' . $backgroundColor . ';">' . $bookingAgendaHelper->getsumService($event, $eventdayDates['eventday'], $hourText) . '</td>';
  1492. $rowcolorCounter++;
  1493. }
  1494. print '</tr>';
  1495. print '<tr class="elvalaszto"><td colspan="' . $k . '"></td></tr>';
  1496. }
  1497. print '</div>';
  1498. }
  1499. }
  1500. print "\n" . '</form>';
  1501. ?>
  1502. <style>
  1503. .trheight {
  1504. height: 50px;
  1505. }
  1506. .elvalaszto {
  1507. background-color: grey;
  1508. }
  1509. .foglaltsag {
  1510. color: red;
  1511. }
  1512. .location {
  1513. color: black;
  1514. }
  1515. .firstcolumn {
  1516. background-color: lightgrey;
  1517. text-align: center;
  1518. font-weight: bold;
  1519. }
  1520. </style>
  1521. <?
  1522. // End of page
  1523. llxFooter();
  1524. $db->close();
  1525. /**
  1526. * Show event of a particular day
  1527. *
  1528. * @param DoliDB $db Database handler
  1529. * @param int $day Day
  1530. * @param int $month Month
  1531. * @param int $year Year
  1532. * @param int $monthshown Current month shown in calendar view
  1533. * @param string $style Style to use for this day
  1534. * @param array $eventarray Array of events
  1535. * @param int $maxprint Nb of actions to show each day on month view (0 means no limit)
  1536. * @param int $maxnbofchar Nb of characters to show for event line
  1537. * @param string $newparam Parameters on current URL
  1538. * @param int $showinfo Add extended information (used by day and week view)
  1539. * @param int $minheight Minimum height for each event. 60px by default.
  1540. * @param string $nonew 0=Add "new entry button", 1=No "new entry button", -1=Only "new entry button"
  1541. * @return void
  1542. */
  1543. function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint = 0, $maxnbofchar = 16, $newparam = '', $showinfo = 0, $minheight = 60, $nonew = 0)
  1544. {
  1545. global $user, $conf, $langs;
  1546. global $action, $mode, $filter, $filtert, $status, $actioncode, $usergroup; // Filters used into search form
  1547. global $theme_datacolor;
  1548. global $cachethirdparties, $cachecontacts, $cacheusers, $colorindexused;
  1549. if ($conf->use_javascript_ajax) { // Enable the "Show more button..."
  1550. $conf->global->MAIN_JS_SWITCH_AGENDA = 1;
  1551. }
  1552. $dateint = sprintf("%04d", $year) . sprintf("%02d", $month) . sprintf("%02d", $day);
  1553. //print 'show_day_events day='.$day.' month='.$month.' year='.$year.' dateint='.$dateint;
  1554. print "\n";
  1555. $curtime = dol_mktime(0, 0, 0, $month, $day, $year);
  1556. $urltoshow = DOL_URL_ROOT . '/custom/booking/booking_agenda.php?mode=show_day&day=' . str_pad($day, 2, "0", STR_PAD_LEFT) . '&month=' . str_pad($month, 2, "0", STR_PAD_LEFT) . '&year=' . $year . $newparam;
  1557. $urltocreate = '';
  1558. if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
  1559. $newparam .= '&month=' . str_pad($month, 2, "0", STR_PAD_LEFT) . '&year=' . $year;
  1560. $hourminsec = '100000';
  1561. $urltocreate = DOL_URL_ROOT . '/custom/booking/booking_card.php?action=create&datep=' . sprintf("%04d%02d%02d", $year, $month, $day) . $hourminsec . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . ($newparam ? '?' . $newparam : ''));
  1562. }
  1563. // Line with title of day
  1564. print '<div id="dayevent_' . $dateint . '" class="dayevent tagtable centpercent nobordernopadding">' . "\n";
  1565. if ($nonew <= 0) {
  1566. print '<div class="tagtr cursorpointer" onclick="window.location=\'' . $urltocreate . '\';"><div class="nowrap tagtd"><div class="left inline-block">';
  1567. print '<a class="dayevent-aday" style="color: #666" href="' . $urltoshow . '">';
  1568. if ($showinfo) {
  1569. print dol_print_date($curtime, 'daytextshort');
  1570. } else {
  1571. print dol_print_date($curtime, '%d');
  1572. }
  1573. print '</a>';
  1574. print '</div><div class="nowrap floatright inline-block marginrightonly">';
  1575. if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
  1576. print '<a class="cursoradd" href="' . $urltocreate . '">'; // Explicit link, usefull for nojs interfaces
  1577. print img_picto($langs->trans("NewAction"), 'edit_add.png');
  1578. print '</a>';
  1579. }
  1580. print '</div></div></div>' . "\n";
  1581. }
  1582. if ($nonew < 0) {
  1583. print '</div>';
  1584. return;
  1585. }
  1586. // Line with td contains all div of each events
  1587. print '<div class="tagtr">';
  1588. print '<div class="tagtd centpercent agendacell sortable">';
  1589. //$curtime = dol_mktime (0, 0, 0, $month, $day, $year);
  1590. $i = 0;
  1591. $ireallyshown = 0;
  1592. $itoshow = 0;
  1593. $numother = 0;
  1594. $numbirthday = 0;
  1595. $numical = 0;
  1596. $numicals = array();
  1597. $ymd = sprintf("%04d", $year) . sprintf("%02d", $month) . sprintf("%02d", $day);
  1598. $colorindexused[$user->id] = 0; // Color index for current user (user->id) is always 0
  1599. $nextindextouse = is_array($colorindexused) ? count($colorindexused) : 0; // At first run this is 0, so fist user has 0, next 1, ...
  1600. //var_dump($colorindexused);
  1601. include_once DOL_DOCUMENT_ROOT . '/holiday/class/holiday.class.php';
  1602. $tmpholiday = new Holiday($db);
  1603. foreach ($eventarray as $daykey => $notused) { // daykey is the 'YYYYMMDD' to show according to user
  1604. $annee = dol_print_date($daykey, '%Y', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
  1605. $mois = dol_print_date($daykey, '%m', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
  1606. $jour = dol_print_date($daykey, '%d', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
  1607. //print 'event daykey='.$daykey.' dol_print_date(daykey)='.dol_print_date($daykey, 'dayhour', 'gmt').' jour='.$jour.' mois='.$mois.' annee='.$annee."<br>\n";
  1608. if ($day == $jour && $month == $mois && $year == $annee) {
  1609. foreach ($eventarray[$daykey] as $index => $event) {
  1610. if ($i < $maxprint || $maxprint == 0 || !empty($conf->global->MAIN_JS_SWITCH_AGENDA)) {
  1611. $keysofuserassigned = array_keys($event->userassigned);
  1612. $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
  1613. // Define $color (Hex string like '0088FF') and $cssclass of event
  1614. $color = -1;
  1615. $cssclass = '';
  1616. $colorindex = -1;
  1617. if (in_array($user->id, $keysofuserassigned)) {
  1618. $cssclass = 'family_mytasks';
  1619. if (empty($cacheusers[$event->userownerid])) {
  1620. $newuser = new User($db);
  1621. $newuser->fetch($event->userownerid);
  1622. $cacheusers[$event->userownerid] = $newuser;
  1623. }
  1624. //var_dump($cacheusers[$event->userownerid]->color);
  1625. // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
  1626. if (!empty($cacheusers[$event->userownerid]->color)) {
  1627. $color = $cacheusers[$event->userownerid]->color;
  1628. }
  1629. } elseif ($event->type_code == 'ICALEVENT') { // Event come from external ical file
  1630. $numical++;
  1631. if (!empty($event->icalname)) {
  1632. if (!isset($numicals[dol_string_nospecial($event->icalname)])) {
  1633. $numicals[dol_string_nospecial($event->icalname)] = 0;
  1634. }
  1635. $numicals[dol_string_nospecial($event->icalname)]++;
  1636. }
  1637. $color = ($event->icalcolor ? $event->icalcolor : -1);
  1638. $cssclass = (!empty($event->icalname) ? 'family_ext' . md5($event->icalname) : 'family_other');
  1639. } elseif ($event->type_code == 'BIRTHDAY') {
  1640. $numbirthday++;
  1641. $colorindex = 2;
  1642. $cssclass = 'family_birthday ';
  1643. $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
  1644. } else {
  1645. $numother++;
  1646. $color = ($event->icalcolor ? $event->icalcolor : -1);
  1647. $cssclass = (!empty($event->icalname) ? 'family_ext' . md5($event->icalname) : 'family_other');
  1648. if (empty($cacheusers[$event->userownerid])) {
  1649. $newuser = new User($db);
  1650. $newuser->fetch($event->userownerid);
  1651. $cacheusers[$event->userownerid] = $newuser;
  1652. }
  1653. //var_dump($cacheusers[$event->userownerid]->color);
  1654. // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
  1655. if (!empty($cacheusers[$event->userownerid]->color)) {
  1656. $color = $cacheusers[$event->userownerid]->color;
  1657. }
  1658. }
  1659. if ($color < 0) { // Color was not set on user card. Set color according to color index.
  1660. // Define color index if not yet defined
  1661. $idusertouse = ($event->userownerid ? $event->userownerid : 0);
  1662. if (isset($colorindexused[$idusertouse])) {
  1663. $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user
  1664. } else {
  1665. $colorindex = $nextindextouse;
  1666. $colorindexused[$idusertouse] = $colorindex;
  1667. if (!empty($theme_datacolor[$nextindextouse + 1])) {
  1668. $nextindextouse++; // Prepare to use next color
  1669. }
  1670. }
  1671. //print '|'.($color).'='.($idusertouse?$idusertouse:0).'='.$colorindex.'<br>';
  1672. // Define color
  1673. $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
  1674. }
  1675. $cssclass = $cssclass . ' eventday_' . $ymd;
  1676. // Defined style to disable drag and drop feature
  1677. if ($event->type_code == 'AC_OTH_AUTO') {
  1678. $cssclass .= " unmovable";
  1679. } elseif ($event->type_code == 'HOLIDAY') {
  1680. $cssclass .= " unmovable";
  1681. } elseif ($event->type_code == 'BIRTHDAY') {
  1682. $cssclass .= " unmovable";
  1683. } elseif ($event->type_code == 'ICALEVENT') {
  1684. $cssclass .= " unmovable";
  1685. } elseif ($event->date_start_in_calendar && $event->date_end_in_calendar && date('Ymd', $event->date_start_in_calendar) != date('Ymd', $event->date_end_in_calendar)) {
  1686. // If the event is on several days
  1687. $tmpyearend = dol_print_date($event->date_start_in_calendar, '%Y', 'tzuserrel');
  1688. $tmpmonthend = dol_print_date($event->date_start_in_calendar, '%m', 'tzuserrel');
  1689. $tmpdayend = dol_print_date($event->date_start_in_calendar, '%d', 'tzuserrel');
  1690. //var_dump($tmpyearend.' '.$tmpmonthend.' '.$tmpdayend);
  1691. if ($tmpyearend != $annee || $tmpmonthend != $mois || $tmpdayend != $jour) {
  1692. $cssclass .= " unmovable unmovable-mustusefirstdaytodrag";
  1693. } else {
  1694. $cssclass .= ' movable cursormove';
  1695. }
  1696. } else {
  1697. if (
  1698. $user->rights->agenda->allactions->create ||
  1699. (($event->authorid == $user->id || $event->userownerid == $user->id) && $user->rights->agenda->myactions->create)
  1700. ) {
  1701. $cssclass .= " movable cursormove";
  1702. } else {
  1703. $cssclass .= " unmovable";
  1704. }
  1705. }
  1706. $h = '';
  1707. $nowrapontd = 1;
  1708. if ($mode == 'show_day') {
  1709. $h = 'height: 100%; ';
  1710. $nowrapontd = 0;
  1711. }
  1712. if ($mode == 'show_week') {
  1713. $h = 'height: 100%; ';
  1714. $nowrapontd = 0;
  1715. }
  1716. // Show event box
  1717. print "\n";
  1718. print '<!-- start event ' . $i . ' -->' . "\n";
  1719. $morecss = '';
  1720. if ($maxprint && $ireallyshown >= $maxprint) {
  1721. $morecss = 'showifmore';
  1722. }
  1723. if ($event->type == 'birthdate' && !GETPOST('check_birthday')) {
  1724. $morecss = 'hidden';
  1725. }
  1726. if ($event->type == 'holiday' && !GETPOST('check_holiday')) {
  1727. $morecss = 'hidden';
  1728. }
  1729. if ($morecss != 'hidden') {
  1730. $itoshow++;
  1731. }
  1732. if ($morecss != 'showifmore' && $morecss != 'hidden') {
  1733. $ireallyshown++;
  1734. }
  1735. //var_dump($event->type.' - '.$morecss.' - '.$cssclass.' - '.$i.' - '.$ireallyshown.' - '.$itoshow);
  1736. print '<div id="event_' . $ymd . '_' . $i . '" class="event family_' . $event->type . ' ' . $cssclass . ($morecss ? ' ' . $morecss : '') . '"';
  1737. //print ' style="height: 100px;';
  1738. //print ' position: absolute; top: 40px; width: 50%;';
  1739. //print '"';
  1740. print '>';
  1741. //var_dump($event->userassigned);
  1742. //var_dump($event->transparency);
  1743. print '<table class="centpercent cal_event';
  1744. print (empty($event->transparency) ? ' cal_event_notbusy' : ' cal_event_busy');
  1745. //if (empty($event->transparency) && empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) print ' opacitymedium'; // Not busy
  1746. print '" style="' . $h;
  1747. $colortouse = $color;
  1748. // If colortouse is similar than background, we force to change it.
  1749. if (empty($event->transparency) && empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
  1750. print 'background: #f0f0f0;';
  1751. print 'border-left: 5px solid #' . $colortouse . ';';
  1752. } else {
  1753. print 'background: #f0f0f0;';
  1754. print 'border-left: 5px solid #' . dol_color_minus($colortouse, -3) . ';';
  1755. //print 'background: -webkit-gradient(linear, left top, left bottom, from(#'.dol_color_minus($colortouse, -3).'), to(#'.dol_color_minus($colortouse, -1).'));';
  1756. }
  1757. //print 'background: #'.$colortouse.';';
  1758. //print 'background: -webkit-gradient(linear, left top, left bottom, from(#'.dol_color_minus($color, -3).'), to(#'.dol_color_minus($color, -1).'));';
  1759. //if (!empty($event->transparency)) print 'background: #'.$color.'; background: -webkit-gradient(linear, left top, left bottom, from(#'.$color.'), to(#'.dol_color_minus($color,1).'));';
  1760. //else print 'background-color: transparent !important; background: none; border: 1px solid #bbb;';
  1761. //print ' -moz-border-radius:4px;"';
  1762. //print 'border: 1px solid #ccc" width="100%"';
  1763. print '">';
  1764. print '<tr>';
  1765. print '<td class="tdoverflow nobottom centpercent ' . ($nowrapontd ? 'nowrap ' : '') . 'cal_event' . ($event->type_code == 'BIRTHDAY' ? ' cal_event_birthday' : '') . '">';
  1766. $daterange = '';
  1767. if ($event->type_code == 'BIRTHDAY') { // It's birthday calendar
  1768. print $event->getNomUrl(1, $maxnbofchar, 'cal_event', 'birthday', 'contact');
  1769. } elseif ($event->type_code == 'HOLIDAY') { // It's holiday calendar
  1770. $tmpholiday->fetch($event->id);
  1771. print $tmpholiday->getNomUrl(1);
  1772. $tmpid = $tmpholiday->fk_user;
  1773. if (empty($cacheusers[$tmpid])) {
  1774. $newuser = new User($db);
  1775. $newuser->fetch($tmpid);
  1776. $cacheusers[$tmpid] = $newuser;
  1777. }
  1778. $listofusertoshow = '';
  1779. $listofusertoshow .= '<br>' . $cacheusers[$tmpid]->getNomUrl(-1, '', 0, 0, 0, 0, '', 'paddingright valigntextbottom');
  1780. print $listofusertoshow;
  1781. } else { // Other calendar
  1782. // Picto
  1783. if (empty($event->fulldayevent)) {
  1784. //print $event->getNomUrl(2).' ';
  1785. }
  1786. // Date
  1787. if (empty($event->fulldayevent)) {
  1788. // Show hours (start ... end)
  1789. $tmpyearstart = dol_print_date($event->date_start_in_calendar, '%Y', 'tzuserrel');
  1790. $tmpmonthstart = dol_print_date($event->date_start_in_calendar, '%m', 'tzuserrel');
  1791. $tmpdaystart = dol_print_date($event->date_start_in_calendar, '%d', 'tzuserrel');
  1792. $tmpyearend = dol_print_date($event->date_end_in_calendar, '%Y', 'tzuserrel');
  1793. $tmpmonthend = dol_print_date($event->date_end_in_calendar, '%m', 'tzuserrel');
  1794. $tmpdayend = dol_print_date($event->date_end_in_calendar, '%d', 'tzuserrel');
  1795. // Hour start
  1796. if ($tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour) {
  1797. $daterange .= dol_print_date($event->date_start_in_calendar, 'hour', 'tzuserrel');
  1798. if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
  1799. if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend) {
  1800. $daterange .= '-';
  1801. }
  1802. //else
  1803. //print '...';
  1804. }
  1805. }
  1806. if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
  1807. if ($tmpyearstart != $tmpyearend || $tmpmonthstart != $tmpmonthend || $tmpdaystart != $tmpdayend) {
  1808. $daterange .= '...';
  1809. }
  1810. }
  1811. // Hour end
  1812. if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
  1813. if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour) {
  1814. $daterange .= dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
  1815. }
  1816. }
  1817. } else {
  1818. if ($showinfo) {
  1819. print $langs->trans("EventOnFullDay") . "<br>\n";
  1820. }
  1821. }
  1822. // Show title
  1823. $titletoshow = $daterange;
  1824. //$titletoshow .= ($titletoshow ? ' ' : '').dol_escape_htmltag($event->label ? $event->label : $event->libelle);
  1825. if ($event->type_code != 'ICALEVENT') {
  1826. $savlabel = $event->label ? $event->label : $event->libelle;
  1827. $event->label = $titletoshow;
  1828. $event->libelle = $titletoshow; // deprecatd
  1829. // Note: List of users are inside $event->userassigned. Link may be clickable depending on permissions of user.
  1830. //$titletoshow = (($event->type_picto || $event->type_code) ? $event->getTypePicto() : '');
  1831. $titletoshow .= $event->getNomUrl(0, $maxnbofchar, 'cal_event cal_event_title', '', 0, 0);
  1832. $event->label = $savlabel;
  1833. $event->libelle = $savlabel;
  1834. }
  1835. // Loop on each assigned user
  1836. $listofusertoshow = '';
  1837. $posuserassigned = 0;
  1838. foreach ($event->userassigned as $tmpid => $tmpdata) {
  1839. if (!$posuserassigned && $titletoshow) {
  1840. $listofusertoshow .= '<br>';
  1841. }
  1842. $posuserassigned++;
  1843. if (empty($cacheusers[$tmpid])) {
  1844. $newuser = new User($db);
  1845. $newuser->fetch($tmpid);
  1846. $cacheusers[$tmpid] = $newuser;
  1847. }
  1848. $listofusertoshow .= $cacheusers[$tmpid]->getNomUrl(-3, '', 0, 0, 0, 0, '', 'paddingright valigntextbottom');
  1849. }
  1850. print $titletoshow;
  1851. print $listofusertoshow;
  1852. if ($event->type_code == 'ICALEVENT') {
  1853. print '<br>(' . dol_trunc($event->icalname, $maxnbofchar) . ')';
  1854. }
  1855. $thirdparty_id = ($event->socid > 0 ? $event->socid : ((is_object($event->societe) && $event->societe->id > 0) ? $event->societe->id : 0));
  1856. $contact_id = ($event->contact_id > 0 ? $event->contact_id : ((is_object($event->contact) && $event->contact->id > 0) ? $event->contact->id : 0));
  1857. // If action related to company / contact
  1858. $linerelatedto = '';
  1859. if ($thirdparty_id > 0) {
  1860. if (!isset($cachethirdparties[$thirdparty_id]) || !is_object($cachethirdparties[$thirdparty_id])) {
  1861. $thirdparty = new Societe($db);
  1862. $thirdparty->fetch($thirdparty_id);
  1863. $cachethirdparties[$thirdparty_id] = $thirdparty;
  1864. } else {
  1865. $thirdparty = $cachethirdparties[$thirdparty_id];
  1866. }
  1867. if (!empty($thirdparty->id)) {
  1868. $linerelatedto .= $thirdparty->getNomUrl(1, '', 0);
  1869. }
  1870. }
  1871. if (!empty($contact_id) && $contact_id > 0) {
  1872. if (!is_object($cachecontacts[$contact_id])) {
  1873. $contact = new Contact($db);
  1874. $contact->fetch($contact_id);
  1875. $cachecontacts[$contact_id] = $contact;
  1876. } else {
  1877. $contact = $cachecontacts[$contact_id];
  1878. }
  1879. if ($linerelatedto) {
  1880. $linerelatedto .= '&nbsp;';
  1881. }
  1882. if (!empty($contact->id)) {
  1883. $linerelatedto .= $contact->getNomUrl(1, '', 0);
  1884. }
  1885. }
  1886. if (!empty($event->fk_element) && $event->fk_element > 0 && !empty($event->elementtype) && !empty($conf->global->AGENDA_SHOW_LINKED_OBJECT)) {
  1887. include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
  1888. if ($linerelatedto) {
  1889. $linerelatedto .= '<br>';
  1890. }
  1891. $linerelatedto .= dolGetElementUrl($event->fk_element, $event->elementtype, 1);
  1892. }
  1893. if ($linerelatedto) {
  1894. print '<br>' . $linerelatedto;
  1895. }
  1896. }
  1897. // Show location
  1898. if ($showinfo) {
  1899. if ($event->location) {
  1900. print '<br>';
  1901. print $langs->trans("Location") . ': ' . $event->location;
  1902. }
  1903. }
  1904. print '</td>';
  1905. // Status - Percent
  1906. $withstatus = 0;
  1907. if ($event->type_code != 'BIRTHDAY' && $event->type_code != 'ICALEVENT') {
  1908. $withstatus = 1;
  1909. if ($event->percentage >= 0) {
  1910. $withstatus = 2;
  1911. }
  1912. }
  1913. print '<td class="nobottom right nowrap cal_event_right' . ($withstatus >= 2 ? ' cal_event_right_status' : '') . '">';
  1914. if ($withstatus) {
  1915. print $event->getLibStatut(3, 1);
  1916. } else {
  1917. print '&nbsp;';
  1918. }
  1919. print '</td></tr></table>';
  1920. print '</div><!-- end event ' . $i . ' -->' . "\n";
  1921. $i++;
  1922. } else {
  1923. print '<a href="' . DOL_URL_ROOT . '/custom/booking/booking_agenda.php?mode=' . $mode . '&maxprint=0&month=' . ((int) $monthshown) . '&year=' . ((int) $year);
  1924. print ($status ? '&status=' . $status : '') . ($filter ? '&filter=' . urlencode($filter) : '');
  1925. print ($filtert ? '&search_filtert=' . urlencode($filtert) : '');
  1926. print ($usergroup ? '&search_usergroup=' . urlencode($usergroup) : '');
  1927. print ($actioncode != '' ? '&search_actioncode=' . urlencode($actioncode) : '');
  1928. print '">' . img_picto("all", "1downarrow_selected.png") . ' ...';
  1929. print ' +' . (count($eventarray[$daykey]) - $maxprint);
  1930. print '</a>';
  1931. break;
  1932. //$ok=false; // To avoid to show twice the link
  1933. }
  1934. }
  1935. break;
  1936. }
  1937. }
  1938. if (!$i) { // No events
  1939. print '&nbsp;';
  1940. }
  1941. if (!empty($conf->global->MAIN_JS_SWITCH_AGENDA) && $itoshow > $ireallyshown && $maxprint) {
  1942. print '<div class="center cursorpointer" id="more_' . $ymd . '">' . img_picto("All", "angle-double-down", 'class="warning"') . ' +' . ($itoshow - $ireallyshown) . '</div>';
  1943. //print ' +'.(count($eventarray[$daykey])-$maxprint);
  1944. print '<script type="text/javascript">' . "\n";
  1945. print 'jQuery(document).ready(function () {' . "\n";
  1946. print ' var open=0;' . "\n";
  1947. print ' jQuery("#more_' . $ymd . '").click(function() { console.log("Click on showmore for ' . $ymd . '"); reinit_day_' . $ymd . '(); event.stopImmediatePropagation(); });' . "\n";
  1948. print ' function reinit_day_' . $ymd . '() {' . "\n";
  1949. print ' jQuery(".eventday_' . $ymd . '.showifmore").toggle();' . "\n";
  1950. print ' open = open + 1; if (open > 1) { open = 0; }' . "\n";
  1951. print ' if (open) { ';
  1952. print ' jQuery("#more_' . $ymd . '").html(\'' . img_picto("All", "angle-double-up", 'class="warning"') . '\');' . "\n";
  1953. print ' } else { ';
  1954. print ' jQuery("#more_' . $ymd . '").html(\'' . img_picto("All", "angle-double-down", 'class="warning"') . ' +' . ($itoshow - $ireallyshown) . '\');' . "\n";
  1955. print ' }' . "\n";
  1956. print ' }' . "\n";
  1957. print '});' . "\n";
  1958. print '</script>' . "\n";
  1959. }
  1960. print '</div></div>'; // td tr
  1961. print '</div>'; // table
  1962. print "\n";
  1963. }
  1964. /**
  1965. * Change color with a delta
  1966. *
  1967. * @param string $color Color
  1968. * @param int $minus Delta (1 = 16 unit). Positive value = darker color, Negative value = brighter color.
  1969. * @param int $minusunit Minus unit
  1970. * @return string New color
  1971. */
  1972. function dol_color_minus($color, $minus, $minusunit = 16)
  1973. {
  1974. $newcolor = $color;
  1975. if ($minusunit == 16) {
  1976. $newcolor[0] = dechex(max(min(hexdec($newcolor[0]) - $minus, 15), 0));
  1977. $newcolor[2] = dechex(max(min(hexdec($newcolor[2]) - $minus, 15), 0));
  1978. $newcolor[4] = dechex(max(min(hexdec($newcolor[4]) - $minus, 15), 0));
  1979. } else {
  1980. // Not yet implemented
  1981. }
  1982. return $newcolor;
  1983. }
  1984. /**
  1985. * Sort events by date
  1986. *
  1987. * @param object $a Event A
  1988. * @param object $b Event B
  1989. * @return int < 0 if event A should be before event B, > 0 otherwise, 0 if they have the exact same time slot
  1990. */
  1991. function sort_events_by_date($a, $b)
  1992. {
  1993. // Sort holidays at first
  1994. if ($a->type_code === 'HOLIDAY') {
  1995. return -1;
  1996. }
  1997. if ($b->type_code === 'HOLIDAY') {
  1998. return 1;
  1999. }
  2000. // datep => Event start time
  2001. // datef => Event end time
  2002. // Events have different start time
  2003. if ($a->datep !== $b->datep) {
  2004. return $a->datep - $b->datep;
  2005. }
  2006. // Events have same start time and no end time
  2007. if ((!is_numeric($b->datef)) || (!is_numeric($a->datef))) {
  2008. return sort_events_by_percentage($a, $b);
  2009. }
  2010. // Events have the same start time and same end time
  2011. if ($b->datef === $a->datef) {
  2012. return sort_events_by_percentage($a, $b);
  2013. }
  2014. // Events have the same start time, but have different end time -> longest event first
  2015. return $b->datef - $a->datef;
  2016. }
  2017. /**
  2018. * Sort events by percentage
  2019. *
  2020. * @param object $a Event A
  2021. * @param object $b Event B
  2022. * @return int < 0 if event A should be before event B, > 0 otherwise, 0 if they have the exact same percentage
  2023. */
  2024. function sort_events_by_percentage($a, $b)
  2025. {
  2026. // Sort events with no percentage before each other
  2027. // (usefull to sort holidays, sick days or similar on the top)
  2028. if ($a->percentage < 0) {
  2029. return -1;
  2030. }
  2031. if ($b->percentage < 0) {
  2032. return 1;
  2033. }
  2034. return $b->percentage - $a->percentage;
  2035. }