booking_agenda.php 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740
  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. $idmenu = GETPOST('idmenu', 'int');
  107. $dateselect = dol_mktime(0, 0, 0, GETPOST('dateselectmonth', 'int'), GETPOST('dateselectday', 'int'), GETPOST('dateselectyear', 'int'));
  108. if ($dateselect > 0) {
  109. $day = GETPOST('dateselectday', 'int');
  110. $month = GETPOST('dateselectmonth', 'int');
  111. $year = GETPOST('dateselectyear', 'int');
  112. }
  113. // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
  114. if (GETPOST('search_actioncode', 'array:aZ09')) {
  115. $actioncode = GETPOST('search_actioncode', 'array:aZ09', 3);
  116. if (!count($actioncode)) {
  117. $actioncode = '0';
  118. }
  119. } else {
  120. $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));
  121. }
  122. if ($status == '' && !GETPOSTISSET('search_status')) {
  123. $status = ((empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS) || $disabledefaultvalues) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS);
  124. }
  125. $defaultview = (empty($conf->global->AGENDA_DEFAULT_VIEW) ? 'show_month' : $conf->global->AGENDA_DEFAULT_VIEW);
  126. $defaultview = (empty($user->conf->AGENDA_DEFAULT_VIEW) ? $defaultview : $user->conf->AGENDA_DEFAULT_VIEW);
  127. if (empty($mode) && !GETPOSTISSET('mode')) {
  128. //$mode = $defaultview;
  129. $mode = 'show_day';
  130. }
  131. if ($mode == 'default') { // When action is default, we want a calendar view and not the list
  132. $mode = (($defaultview != 'show_list') ? $defaultview : 'show_month');
  133. }
  134. if (GETPOST('viewday', 'int') || GETPOST('mode', 'alpha') == 'show_day') {
  135. $mode = 'show_day';
  136. $day = ($day ? $day : date("d"));
  137. } // View by day
  138. $object = new ActionComm($db);
  139. $bookingAgendaHelper = new BookingAgendaHelper($db);
  140. // Load translation files required by the page
  141. $langs->loadLangs(array('agenda', 'other', 'commercial'));
  142. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  143. $hookmanager->initHooks(array('agenda'));
  144. $result = restrictedArea($user, 'agenda', 0, 'actioncomm&societe', 'myactions|allactions', 'fk_soc', 'id');
  145. if ($user->socid && $socid) {
  146. $result = restrictedArea($user, 'societe', $socid);
  147. }
  148. /*
  149. * Actions
  150. */
  151. if (GETPOST("viewlist", 'alpha') || $mode == 'show_list') {
  152. $param = '';
  153. if (is_array($_POST)) {
  154. foreach ($_POST as $key => $val) {
  155. if ($key == 'token') {
  156. continue;
  157. }
  158. $param .= '&' . $key . '=' . urlencode($val);
  159. }
  160. }
  161. if (!preg_match('/action=/', $param)) {
  162. $param .= ($param ? '&' : '') . 'mode=show_list';
  163. }
  164. //print $param;
  165. header("Location: " . DOL_URL_ROOT . '/custom/booking/booking_list.php?' . $param);
  166. exit;
  167. }
  168. if (GETPOST("viewperuser", 'alpha') || $mode == 'show_peruser') {
  169. $param = '';
  170. if (is_array($_POST)) {
  171. foreach ($_POST as $key => $val) {
  172. if ($key == 'token') {
  173. continue;
  174. }
  175. $param .= '&' . $key . '=' . urlencode($val);
  176. }
  177. }
  178. //print $param;
  179. header("Location: " . DOL_URL_ROOT . '/comm/action/peruser.php?' . $param);
  180. exit;
  181. }
  182. /*
  183. if ($action == 'delete_action' && $user->rights->agenda->delete) {
  184. $event = new ActionComm($db);
  185. $event->fetch($actionid);
  186. $event->fetch_optionals();
  187. $event->fetch_userassigned();
  188. $event->oldcopy = dol_clone($event);
  189. $result = $event->delete();
  190. }
  191. */
  192. /*
  193. * View
  194. */
  195. $parameters = array(
  196. 'socid' => $socid,
  197. 'status' => $status,
  198. 'year' => $year,
  199. 'month' => $month,
  200. 'day' => $day,
  201. 'type' => $type,
  202. 'maxprint' => $maxprint,
  203. 'filter' => $filter,
  204. 'filtert' => $filtert,
  205. 'showbirthday' => $showbirthday,
  206. 'canedit' => $canedit,
  207. 'optioncss' => $optioncss,
  208. 'actioncode' => $actioncode,
  209. 'pid' => $pid,
  210. 'resourceid' => $resourceid,
  211. 'usergroup' => $usergroup,
  212. );
  213. $reshook = $hookmanager->executeHooks('beforeAgenda', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  214. if ($reshook < 0) {
  215. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  216. }
  217. $help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&oacute;dulo_Agenda';
  218. llxHeader('', $langs->trans("Agenda"), $help_url);
  219. $form = new Form($db);
  220. $companystatic = new Societe($db);
  221. $contactstatic = new Contact($db);
  222. $userstatic = new User($db);
  223. $now = dol_now();
  224. $nowarray = dol_getdate($now);
  225. $nowyear = $nowarray['year'];
  226. $nowmonth = $nowarray['mon'];
  227. $nowday = $nowarray['mday'];
  228. $listofextcals = array();
  229. // Define list of external calendars (global admin setup)
  230. if (empty($conf->global->AGENDA_DISABLE_EXT)) {
  231. $i = 0;
  232. while ($i < $MAXAGENDA) {
  233. $i++;
  234. $source = 'AGENDA_EXT_SRC' . $i;
  235. $name = 'AGENDA_EXT_NAME' . $i;
  236. $offsettz = 'AGENDA_EXT_OFFSETTZ' . $i;
  237. $color = 'AGENDA_EXT_COLOR' . $i;
  238. $default = 'AGENDA_EXT_ACTIVEBYDEFAULT' . $i;
  239. $buggedfile = 'AGENDA_EXT_BUGGEDFILE' . $i;
  240. if (getDolGlobalString($source) && getDolGlobalString($name)) {
  241. // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
  242. $listofextcals[] = array(
  243. 'src' => getDolGlobalString($source),
  244. 'name' => dol_string_nohtmltag(getDolGlobalString($name)),
  245. 'offsettz' => (int) getDolGlobalInt($offsettz, 0),
  246. 'color' => dol_string_nohtmltag(getDolGlobalString($color)),
  247. 'default' => dol_string_nohtmltag(getDolGlobalString($default)),
  248. 'buggedfile' => dol_string_nohtmltag(getDolGlobalString('buggedfile', ''))
  249. );
  250. }
  251. }
  252. }
  253. // Define list of external calendars (user setup)
  254. if (empty($user->conf->AGENDA_DISABLE_EXT)) {
  255. $i = 0;
  256. while ($i < $MAXAGENDA) {
  257. $i++;
  258. $source = 'AGENDA_EXT_SRC_' . $user->id . '_' . $i;
  259. $name = 'AGENDA_EXT_NAME_' . $user->id . '_' . $i;
  260. $offsettz = 'AGENDA_EXT_OFFSETTZ_' . $user->id . '_' . $i;
  261. $color = 'AGENDA_EXT_COLOR_' . $user->id . '_' . $i;
  262. $enabled = 'AGENDA_EXT_ENABLED_' . $user->id . '_' . $i;
  263. $default = 'AGENDA_EXT_ACTIVEBYDEFAULT_' . $user->id . '_' . $i;
  264. $buggedfile = 'AGENDA_EXT_BUGGEDFILE_' . $user->id . '_' . $i;
  265. if (getDolUserString($source) && getDolUserString($name)) {
  266. // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
  267. $listofextcals[] = array(
  268. 'src' => getDolUserString($source),
  269. 'name' => dol_string_nohtmltag(getDolUserString($name)),
  270. 'offsettz' => (int) (empty($user->conf->$offsettz) ? 0 : $user->conf->$offsettz),
  271. 'color' => dol_string_nohtmltag(getDolUserString($color)),
  272. 'default' => dol_string_nohtmltag(getDolUserString($default)),
  273. 'buggedfile' => dol_string_nohtmltag(isset($user->conf->buggedfile) ? $user->conf->buggedfile : '')
  274. );
  275. }
  276. }
  277. }
  278. if (empty($mode) || $mode == 'show_month') {
  279. $prev = dol_get_prev_month($month, $year);
  280. $prev_year = $prev['year'];
  281. $prev_month = $prev['month'];
  282. $next = dol_get_next_month($month, $year);
  283. $next_year = $next['year'];
  284. $next_month = $next['month'];
  285. $max_day_in_prev_month = date("t", dol_mktime(0, 0, 0, $prev_month, 1, $prev_year, 'gmt')); // Nb of days in previous month
  286. $max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year)); // Nb of days in next month
  287. // 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)
  288. $tmpday = -date("w", dol_mktime(12, 0, 0, $month, 1, $year, 'gmt')) + 2; // date('w') is 0 fo sunday
  289. $tmpday += ((isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1) - 1);
  290. if ($tmpday >= 1) {
  291. $tmpday -= 7; // If tmpday is 0 we start with sunday, if -6, we start with monday of previous week.
  292. }
  293. // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
  294. $firstdaytoshow = dol_mktime(0, 0, 0, $prev_month, $max_day_in_prev_month + $tmpday, $prev_year, 'tzuserrel');
  295. $next_day = 7 - ($max_day_in_month + 1 - $tmpday) % 7;
  296. if ($next_day < 6) {
  297. $next_day += 7;
  298. }
  299. $lastdaytoshow = dol_mktime(0, 0, 0, $next_month, $next_day, $next_year, 'tzuserrel');
  300. }
  301. if ($mode == 'show_week') {
  302. $prev = dol_get_first_day_week($day, $month, $year);
  303. $prev_year = $prev['prev_year'];
  304. $prev_month = $prev['prev_month'];
  305. $prev_day = $prev['prev_day'];
  306. $first_day = $prev['first_day'];
  307. $first_month = $prev['first_month'];
  308. $first_year = $prev['first_year'];
  309. $week = $prev['week'];
  310. $day = (int) $day;
  311. $next = dol_get_next_week($first_day, $week, $first_month, $first_year);
  312. $next_year = $next['year'];
  313. $next_month = $next['month'];
  314. $next_day = $next['day'];
  315. // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
  316. $firstdaytoshow = dol_mktime(0, 0, 0, $first_month, $first_day, $first_year, 'tzuserrel');
  317. $lastdaytoshow = dol_time_plus_duree($firstdaytoshow, 7, 'd');
  318. $max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year, 'gmt'));
  319. $tmpday = $first_day;
  320. }
  321. if ($mode == 'show_day') {
  322. $prev = dol_get_prev_day($day, $month, $year);
  323. $prev_year = $prev['year'];
  324. $prev_month = $prev['month'];
  325. $prev_day = $prev['day'];
  326. $next = dol_get_next_day($day, $month, $year);
  327. $next_year = $next['year'];
  328. $next_month = $next['month'];
  329. $next_day = $next['day'];
  330. // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
  331. $firstdaytoshow = dol_mktime(0, 0, 0, $prev_month, $prev_day, $prev_year, 'tzuserrel');
  332. $lastdaytoshow = dol_mktime(0, 0, 0, $next_month, $next_day, $next_year, 'tzuserrel');
  333. }
  334. //print 'xx'.$prev_year.'-'.$prev_month.'-'.$prev_day;
  335. //print 'xx'.$next_year.'-'.$next_month.'-'.$next_day;
  336. //print dol_print_date($firstdaytoshow,'dayhour').' '.dol_print_date($lastdaytoshow,'dayhour');
  337. /*$title = $langs->trans("DoneAndToDoActions");
  338. if ($status == 'done') $title = $langs->trans("DoneActions");
  339. if ($status == 'todo') $title = $langs->trans("ToDoActions");
  340. */
  341. $param = '';
  342. if ($actioncode || GETPOSTISSET('search_actioncode')) {
  343. if (is_array($actioncode)) {
  344. foreach ($actioncode as $str_action) {
  345. $param .= "&search_actioncode[]=" . urlencode($str_action);
  346. }
  347. } else {
  348. $param .= "&search_actioncode=" . urlencode($actioncode);
  349. }
  350. }
  351. if ($resourceid > 0) {
  352. $param .= "&search_resourceid=" . urlencode($resourceid);
  353. }
  354. if ($status || GETPOSTISSET('status') || GETPOSTISSET('search_status')) {
  355. $param .= "&search_status=" . urlencode($status);
  356. }
  357. if ($filter) {
  358. $param .= "&search_filter=" . urlencode($filter);
  359. }
  360. if ($filtert) {
  361. $param .= "&search_filtert=" . urlencode($filtert);
  362. }
  363. if ($usergroup > 0) {
  364. $param .= "&search_usergroup=" . urlencode($usergroup);
  365. }
  366. if ($socid > 0) {
  367. $param .= "&search_socid=" . urlencode($socid);
  368. }
  369. if ($showbirthday) {
  370. $param .= "&search_showbirthday=1";
  371. }
  372. if ($pid) {
  373. $param .= "&search_projectid=" . urlencode($pid);
  374. }
  375. if ($type) {
  376. $param .= "&search_type=" . urlencode($type);
  377. }
  378. $param .= "&maxprint=" . urlencode($maxprint);
  379. if ($mode == 'show_day' || $mode == 'show_week' || $mode == 'show_month') {
  380. $param .= '&mode=' . urlencode($mode);
  381. }
  382. // Show navigation bar
  383. if ($mode == 'show_day') {
  384. $nav = "<a href=\"?year=" . $prev_year . "&month=" . $prev_month . "&day=" . $prev_day . $param . "\"><i class=\"fa fa-chevron-left\"></i></a> &nbsp;\n";
  385. $nav .= " <span id=\"month_name\">" . dol_print_date(dol_mktime(0, 0, 0, $month, $day, $year), "daytextshort");
  386. $nav .= " </span>\n";
  387. $nav .= " &nbsp; <a href=\"?year=" . $next_year . "&month=" . $next_month . "&day=" . $next_day . $param . "&idmenu=" . $idmenu . "&mainmenu=booking&leftmenu=\"><i class=\"fa fa-chevron-right\"></i></a>\n";
  388. if (empty($conf->dol_optimize_smallscreen)) {
  389. $nav .= " &nbsp; <a href=\"?year=" . $nowyear . "&amp;month=" . $nowmonth . "&amp;day=" . $nowday . $param . "\">" . $langs->trans("Today") . "</a> ";
  390. }
  391. $picto = 'calendarday';
  392. }
  393. $nav .= $form->selectDate($dateselect, 'dateselect', 0, 0, 1, '', 1, 0);
  394. //$nav .= ' <input type="submit" class="button button-save" name="submitdateselect" value="'.$langs->trans("Refresh").'">';
  395. $nav .= '<button type="submit" class="liste_titre button_search valignmiddle" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
  396. // Must be after the nav definition
  397. $paramnodate = $param;
  398. $param .= '&year=' . $year . '&month=' . $month . ($day ? '&day=' . $day : '');
  399. //print 'x'.$param;
  400. /*$tabactive = '';
  401. if ($mode == 'show_month') $tabactive = 'cardmonth';
  402. if ($mode == 'show_week') $tabactive = 'cardweek';
  403. if ($mode == 'show_day') $tabactive = 'cardday';
  404. if ($mode == 'show_list') $tabactive = 'cardlist';
  405. if ($mode == 'show_pertuser') $tabactive = 'cardperuser';
  406. if ($mode == 'show_pertype') $tabactive = 'cardpertype';
  407. */
  408. $paramnoaction = preg_replace('/mode=[a-z_]+/', '', preg_replace('/action=[a-z_]+/', '', $param));
  409. $paramnoactionodate = preg_replace('/mode=[a-z_]+/', '', preg_replace('/action=[a-z_]+/', '', $paramnodate));
  410. $head = calendars_prepare_head($paramnoaction);
  411. print '<form method="POST" id="searchFormList" class="listactionsfilter" action="' . $_SERVER["PHP_SELF"] . '">' . "\n";
  412. if ($optioncss != '') {
  413. print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
  414. }
  415. print '<input type="hidden" name="token" value="' . newToken() . '">';
  416. print '<input type="hidden" name="mode" value="' . $mode . '">';
  417. //print dol_get_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action');
  418. //print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, $listofextcals, $actioncode, $usergroup, '', $resourceid);
  419. //print dol_get_fiche_end();
  420. $viewmode = '';
  421. /* $viewmode .= '<a class="btnTitle reposition" href="' . DOL_URL_ROOT . '/custom/booking/booking_list.php?mode=show_list&restore_lastsearch_values=1' . $paramnoactionodate . '">';
  422. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  423. $viewmode .= img_picto($langs->trans("List"), 'object_calendarlist', 'class="imgforviewmode pictoactionview block"');
  424. //$viewmode .= '</span>';
  425. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">' . $langs->trans("ViewList") . '</span></a>';
  426. */
  427. /* $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 . '">';
  428. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  429. $viewmode .= img_picto($langs->trans("ViewCal"), 'object_calendarmonth', 'class="pictoactionview block"');
  430. //$viewmode .= '</span>';
  431. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">' . $langs->trans("ViewCal") . '</span></a>';
  432. */
  433. /* $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 . '">';
  434. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  435. $viewmode .= img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="pictoactionview block"');
  436. //$viewmode .= '</span>';
  437. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">' . $langs->trans("ViewWeek") . '</span></a>';
  438. */
  439. /* $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 . '">';
  440. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  441. $viewmode .= img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="pictoactionview block"');
  442. //$viewmode .= '</span>';
  443. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">' . $langs->trans("ViewDay") . '</span></a>';
  444. */
  445. /* $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.'">';
  446. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  447. $viewmode .= img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="pictoactionview block"');
  448. //$viewmode .= '</span>';
  449. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewPerUser").'</span></a>';
  450. */
  451. // Add more views from hooks
  452. $parameters = array();
  453. $object = null;
  454. $reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
  455. if (empty($reshook)) {
  456. $viewmode .= $hookmanager->resPrint;
  457. } elseif ($reshook > 1) {
  458. $viewmode = $hookmanager->resPrint;
  459. }
  460. $viewmode .= '<span class="marginrightonly"></span>'; // To add a space before the navigation tools
  461. $newcardbutton = '';
  462. $newparam = '';
  463. if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
  464. $tmpforcreatebutton = dol_getdate(dol_now(), true);
  465. $newparam .= '&month=' . ((int) $month) . '&year=' . ((int) $tmpforcreatebutton['year']) . '&mode=' . urlencode($mode);
  466. //$param='month='.$monthshown.'&year='.$year;
  467. $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
  468. //$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 : '')));
  469. }
  470. // Define the legend/list of calendard to show
  471. $s = '';
  472. $link = '';
  473. $showextcals = $listofextcals;
  474. if (!empty($conf->use_javascript_ajax)) { // If javascript on
  475. $s .= "\n" . '<!-- Div to calendars selectors -->' . "\n";
  476. $s .= '<script type="text/javascript">' . "\n";
  477. $s .= 'jQuery(document).ready(function () {' . "\n";
  478. $s .= 'jQuery(".check_birthday").click(function() { console.log("Toggle birthdays"); jQuery(".family_birthday").toggle(); });' . "\n";
  479. $s .= 'jQuery(".check_holiday").click(function() { console.log("Toggle holidays"); jQuery(".family_holiday").toggle(); });' . "\n";
  480. if ($mode == "show_week" || $mode == "show_month" || empty($mode)) {
  481. // Code to enable drag and drop
  482. $s .= 'jQuery( "div.sortable" ).sortable({connectWith: ".sortable", placeholder: "ui-state-highlight", items: "div.movable", receive: function( event, ui ) {' . "\n";
  483. // Code to submit form
  484. $s .= 'console.log("submit form to record new event");' . "\n";
  485. //$s.='console.log(event.target);';
  486. $s .= 'var newval = jQuery(event.target).closest("div.dayevent").attr("id");' . "\n";
  487. $s .= 'console.log("found parent div.dayevent with id = "+newval);' . "\n";
  488. $s .= 'var frm=jQuery("#searchFormList");' . "\n";
  489. $s .= 'var newurl = ui.item.find("a.cal_event").attr("href");' . "\n";
  490. $s .= 'console.log("Found url on href of a.cal_event"+newurl+", we submit form with actionmove=mupdate");' . "\n";
  491. $s .= 'frm.attr("action", newurl).children("#newdate").val(newval);frm.submit();}' . "\n";
  492. $s .= '});' . "\n";
  493. }
  494. $s .= '});' . "\n";
  495. $s .= '</script>' . "\n";
  496. // Local calendar
  497. //$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>';
  498. // Holiday calendar
  499. //$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>';
  500. // External calendars
  501. if (is_array($showextcals) && count($showextcals) > 0) {
  502. $s .= '<script type="text/javascript">' . "\n";
  503. $s .= 'jQuery(document).ready(function () {
  504. jQuery("div input[name^=\"check_ext\"]").each(function(index, elem) {
  505. var name = jQuery(elem).attr("name");
  506. if (jQuery(elem).is(":checked")) {
  507. jQuery(".family_ext" + name.replace("check_ext", "")).show();
  508. } else {
  509. jQuery(".family_ext" + name.replace("check_ext", "")).hide();
  510. }
  511. });
  512. jQuery("div input[name^=\"check_ext\"]").click(function() {
  513. var name = $(this).attr("name");
  514. jQuery(".family_ext" + name.replace("check_ext", "")).toggle();
  515. });
  516. });' . "\n";
  517. $s .= '</script>' . "\n";
  518. foreach ($showextcals as $val) {
  519. $htmlname = md5($val['name']);
  520. if (!empty($val['default']) || GETPOST('check_ext' . $htmlname, 'int')) {
  521. $default = "checked";
  522. } else {
  523. $default = '';
  524. }
  525. $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>';
  526. }
  527. }
  528. // Birthdays
  529. //$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>';
  530. // Calendars from hooks
  531. $parameters = array();
  532. $reshook = $hookmanager->executeHooks('addCalendarChoice', $parameters, $object, $action);
  533. if (empty($reshook)) {
  534. $s .= $hookmanager->resPrint;
  535. } elseif ($reshook > 1) {
  536. $s = $hookmanager->resPrint;
  537. }
  538. $s .= "\n" . '<!-- End div to calendars selectors -->' . "\n";
  539. } else { // If javascript off
  540. $newparam = $param; // newparam is for birthday links
  541. $newparam = preg_replace('/showbirthday=[0-1]/i', 'showbirthday=' . (empty($showbirthday) ? 1 : 0), $newparam);
  542. if (!preg_match('/showbirthday=/i', $newparam)) {
  543. $newparam .= '&showbirthday=1';
  544. }
  545. $link = '<a href="' . $_SERVER['PHP_SELF'] . '?' . dol_escape_htmltag($newparam);
  546. $link .= '">';
  547. if (empty($showbirthday)) {
  548. $link .= $langs->trans("AgendaShowBirthdayEvents");
  549. } else {
  550. $link .= $langs->trans("AgendaHideBirthdayEvents");
  551. }
  552. $link .= '</a>';
  553. }
  554. // Load events from database into $eventarray
  555. $eventarray = array();
  556. // DEFAULT CALENDAR + AUTOEVENT CALENDAR + CONFERENCEBOOTH CALENDAR
  557. $sql = 'SELECT ';
  558. if ($usergroup > 0) {
  559. $sql .= " DISTINCT";
  560. }
  561. $sql .= ' a.id, a.label,';
  562. $sql .= ' a.datep,';
  563. $sql .= ' a.datep2,';
  564. $sql .= ' a.percent,';
  565. $sql .= ' a.fk_user_author,a.fk_user_action,';
  566. $sql .= ' a.transparency, a.priority, a.fulldayevent, a.location,';
  567. $sql .= ' a.fk_soc, a.fk_contact, a.fk_project,';
  568. $sql .= ' a.fk_element, a.elementtype,';
  569. $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';
  570. $sql .= ' FROM ' . MAIN_DB_PREFIX . 'c_actioncomm as ca, ' . MAIN_DB_PREFIX . "actioncomm as a";
  571. if (empty($user->rights->societe->client->voir) && !$socid) {
  572. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
  573. }
  574. // We must filter on resource table
  575. if ($resourceid > 0) {
  576. $sql .= ", " . MAIN_DB_PREFIX . "element_resources as r";
  577. }
  578. // We must filter on assignement table
  579. if ($filtert > 0 || $usergroup > 0) {
  580. $sql .= ", " . MAIN_DB_PREFIX . "actioncomm_resources as ar";
  581. }
  582. if ($usergroup > 0) {
  583. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
  584. }
  585. $sql .= ' WHERE a.fk_action = ca.id';
  586. $sql .= ' AND a.entity IN (' . getEntity('agenda') . ')';
  587. // Condition on actioncode
  588. if (!empty($actioncode)) {
  589. if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
  590. if ($actioncode == 'AC_NON_AUTO') {
  591. $sql .= " AND ca.type != 'systemauto'";
  592. } elseif ($actioncode == 'AC_ALL_AUTO') {
  593. $sql .= " AND ca.type = 'systemauto'";
  594. } else {
  595. if ($actioncode == 'AC_OTH') {
  596. $sql .= " AND ca.type != 'systemauto'";
  597. }
  598. if ($actioncode == 'AC_OTH_AUTO') {
  599. $sql .= " AND ca.type = 'systemauto'";
  600. }
  601. }
  602. } else {
  603. if ($actioncode == 'AC_NON_AUTO') {
  604. $sql .= " AND ca.type != 'systemauto'";
  605. } elseif ($actioncode == 'AC_ALL_AUTO') {
  606. $sql .= " AND ca.type = 'systemauto'";
  607. } else {
  608. if (is_array($actioncode)) {
  609. $sql .= " AND ca.code IN (" . $db->sanitize("'" . implode("','", $actioncode) . "'", 1) . ")";
  610. } else {
  611. $sql .= " AND ca.code IN (" . $db->sanitize("'" . implode("','", explode(',', $actioncode)) . "'", 1) . ")";
  612. }
  613. }
  614. }
  615. }
  616. if ($resourceid > 0) {
  617. $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = " . ((int) $resourceid);
  618. }
  619. if ($pid) {
  620. $sql .= " AND a.fk_project=" . ((int) $pid);
  621. }
  622. if (empty($user->rights->societe->client->voir) && !$socid) {
  623. $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = " . ((int) $user->id) . ")";
  624. }
  625. if ($socid > 0) {
  626. $sql .= " AND a.fk_soc = " . ((int) $socid);
  627. }
  628. // We must filter on assignement table
  629. if ($filtert > 0 || $usergroup > 0) {
  630. $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
  631. }
  632. //var_dump($day.' '.$month.' '.$year);
  633. if ($mode == 'show_day') {
  634. $sql .= " AND (";
  635. $sql .= " (a.datep BETWEEN '" . $db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel')) . "'";
  636. $sql .= " AND '" . $db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel')) . "')";
  637. $sql .= " OR ";
  638. $sql .= " (a.datep2 BETWEEN '" . $db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel')) . "'";
  639. $sql .= " AND '" . $db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel')) . "')";
  640. $sql .= " OR ";
  641. $sql .= " (a.datep < '" . $db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel')) . "'";
  642. $sql .= " AND a.datep2 > '" . $db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel')) . "')";
  643. $sql .= ')';
  644. } else {
  645. // To limit array
  646. $sql .= " AND (";
  647. $sql .= " (a.datep BETWEEN '" . $db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7)) . "'"; // Start 7 days before
  648. $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
  649. $sql .= " OR ";
  650. $sql .= " (a.datep2 BETWEEN '" . $db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7)) . "'";
  651. $sql .= " AND '" . $db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10)) . "')";
  652. $sql .= " OR ";
  653. $sql .= " (a.datep < '" . $db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7)) . "'";
  654. $sql .= " AND a.datep2 > '" . $db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10)) . "')";
  655. $sql .= ')';
  656. }
  657. if ($type) {
  658. $sql .= " AND ca.id = " . ((int) $type);
  659. }
  660. $sql .= " AND a.code = 'AC_EVENT'";
  661. if ($status == '0') {
  662. // To do (not started)
  663. $sql .= " AND a.percent = 0";
  664. }
  665. if ($status == 'na') {
  666. // Not applicable
  667. $sql .= " AND a.percent = -1";
  668. }
  669. if ($status == '50') {
  670. // Running already started
  671. $sql .= " AND (a.percent > 0 AND a.percent < 100)";
  672. }
  673. if ($status == 'done' || $status == '100') {
  674. $sql .= " AND (a.percent = 100)";
  675. }
  676. if ($status == 'todo') {
  677. $sql .= " AND (a.percent >= 0 AND a.percent < 100)";
  678. }
  679. // We must filter on assignement table
  680. if ($filtert > 0 || $usergroup > 0) {
  681. $sql .= " AND (";
  682. if ($filtert > 0) {
  683. $sql .= "ar.fk_element = " . ((int) $filtert);
  684. }
  685. if ($usergroup > 0) {
  686. $sql .= ($filtert > 0 ? " OR " : "") . " ugu.fk_usergroup = " . ((int) $usergroup);
  687. }
  688. $sql .= ")";
  689. }
  690. // Sort on date
  691. $sql .= ' ORDER BY datep';
  692. //print $sql;
  693. dol_syslog("custom/booking/booking_agenda.php", LOG_DEBUG);
  694. $resql = $db->query($sql);
  695. if ($resql) {
  696. $num = $db->num_rows($resql);
  697. $MAXONSAMEPAGE = 10000; // Useless to have more. Protection to avoid memory overload when high number of event (for example after a mass import)
  698. $i = 0;
  699. while ($i < $num && $i < $MAXONSAMEPAGE) {
  700. $obj = $db->fetch_object($resql);
  701. // Discard auto action if option is on
  702. if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->type_code == 'AC_OTH_AUTO') {
  703. $i++;
  704. continue;
  705. }
  706. // Create a new object action
  707. $event = new ActionComm($db);
  708. $event->id = $obj->id;
  709. $event->ref = $event->id;
  710. $event->fulldayevent = $obj->fulldayevent;
  711. // event->datep and event->datef must be GMT date.
  712. if ($event->fulldayevent) {
  713. $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
  714. $event->datep = $db->jdate($obj->datep, $tzforfullday ? 'tzuser' : 'tzserver'); // If saved in $tzforfullday = gmt, we must invert date to be in user tz
  715. $event->datef = $db->jdate($obj->datep2, $tzforfullday ? 'tzuser' : 'tzserver');
  716. } else {
  717. // Example: $obj->datep = '1970-01-01 01:00:00', jdate will return 0 if TZ of PHP server is Europe/Berlin (+1)
  718. $event->datep = $db->jdate($obj->datep, 'tzserver');
  719. $event->datef = $db->jdate($obj->datep2, 'tzserver');
  720. }
  721. //$event->datep_formated_gmt = dol_print_date($event->datep, 'dayhour', 'gmt');
  722. //var_dump($obj->id.' '.$obj->datep.' '.dol_print_date($obj->datep, 'dayhour', 'gmt'));
  723. //var_dump($obj->id.' '.$event->datep.' '.dol_print_date($event->datep, 'dayhour', 'gmt'));
  724. $event->type_code = $obj->type_code;
  725. $event->type_label = $obj->type_label;
  726. $event->type_color = $obj->type_color;
  727. $event->type = $obj->type_type;
  728. $event->type_picto = $obj->type_picto;
  729. $event->libelle = $obj->label; // deprecated
  730. $event->label = $obj->label;
  731. $event->percentage = $obj->percent;
  732. $event->authorid = $obj->fk_user_author; // user id of creator
  733. $event->userownerid = $obj->fk_user_action; // user id of owner
  734. $event->fetch_userassigned(); // This load $event->userassigned
  735. $event->priority = $obj->priority;
  736. $event->location = $obj->location;
  737. $event->transparency = $obj->transparency;
  738. $event->fk_element = $obj->fk_element;
  739. $event->elementtype = $obj->elementtype;
  740. $event->fk_project = $obj->fk_project;
  741. $event->socid = $obj->fk_soc;
  742. $event->contact_id = $obj->fk_contact;
  743. // Defined date_start_in_calendar and date_end_in_calendar property
  744. // They are date start and end of action but modified to not be outside calendar view.
  745. $event->date_start_in_calendar = $event->datep;
  746. if ($event->datef != '' && $event->datef >= $event->datep) {
  747. $event->date_end_in_calendar = $event->datef;
  748. } else {
  749. $event->date_end_in_calendar = $event->datep;
  750. }
  751. // Check values
  752. if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow) {
  753. // This record is out of visible range
  754. } else {
  755. if ($event->date_start_in_calendar < $firstdaytoshow) {
  756. $event->date_start_in_calendar = $firstdaytoshow;
  757. }
  758. if ($event->date_end_in_calendar >= $lastdaytoshow) {
  759. $event->date_end_in_calendar = ($lastdaytoshow - 1);
  760. }
  761. // Add an entry in actionarray for each day
  762. $daycursor = $event->date_start_in_calendar;
  763. $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
  764. $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
  765. $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
  766. $daycursorend = $event->date_end_in_calendar;
  767. $anneeend = dol_print_date($daycursorend, '%Y', 'tzuserrel');
  768. $moisend = dol_print_date($daycursorend, '%m', 'tzuserrel');
  769. $jourend = dol_print_date($daycursorend, '%d', 'tzuserrel');
  770. //var_dump(dol_print_date($event->date_start_in_calendar, 'dayhour', 'gmt')); // Hour at greenwich
  771. //var_dump($annee.'-'.$mois.'-'.$jour);
  772. //print 'annee='.$annee.' mois='.$mois.' jour='.$jour.'<br>';
  773. // Loop on each day covered by action to prepare an index to show on calendar
  774. $loop = true;
  775. $j = 0;
  776. $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt'); // $mois, $jour, $annee has been set for user tz
  777. $daykeyend = dol_mktime(0, 0, 0, $moisend, $jourend, $anneeend, 'gmt'); // $moisend, $jourend, $anneeend has been set for user tz
  778. /*
  779. print 'GMT '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'gmt').'<br>';
  780. print 'TZSERVER '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzserver').'<br>';
  781. print 'TZUSERREL '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel').'<br>';
  782. print 'GMT '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'gmt').'<br>';
  783. print 'TZSERVER '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzserver').'<br>';
  784. print 'TZUSER '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel').'<br>';
  785. */
  786. do {
  787. //if ($event->id==408)
  788. //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>';
  789. //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>';
  790. $eventarray[$daykey][] = $event;
  791. $j++;
  792. $daykey += 60 * 60 * 24;
  793. //if ($daykey > $event->date_end_in_calendar) {
  794. if ($daykey > $daykeyend) {
  795. $loop = false;
  796. }
  797. } while ($loop);
  798. //var_dump($eventarray);
  799. //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
  800. //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>';
  801. }
  802. $i++;
  803. }
  804. } else {
  805. dol_print_error($db);
  806. }
  807. // LEAVE CALENDAR
  808. $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";
  809. $sql .= " FROM " . MAIN_DB_PREFIX . "holiday as x, " . MAIN_DB_PREFIX . "user as u";
  810. $sql .= " WHERE u.rowid = x.fk_user";
  811. $sql .= " AND u.statut = '1'"; // Show only active users (0 = inactive user, 1 = active user)
  812. $sql .= " AND (x.statut = '2' OR x.statut = '3')"; // Show only public leaves (2 = leave wait for approval, 3 = leave approved)
  813. if ($mode == 'show_day') {
  814. // Request only leaves for the current selected day
  815. $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
  816. } elseif ($mode == 'show_week') {
  817. // TODO: Add filter to reduce database request
  818. } elseif ($mode == 'show_month') {
  819. // TODO: Add filter to reduce database request
  820. }
  821. $resql = $db->query($sql);
  822. if ($resql) {
  823. $num = $db->num_rows($resql);
  824. $i = 0;
  825. while ($i < $num) {
  826. $obj = $db->fetch_object($resql);
  827. $event = new ActionComm($db);
  828. // Need the id of the leave object for link to it
  829. $event->id = $obj->rowid;
  830. $event->ref = $event->id;
  831. $event->type_code = 'HOLIDAY';
  832. $event->type_label = '';
  833. $event->type_color = '';
  834. $event->type = 'holiday';
  835. $event->type_picto = 'holiday';
  836. $event->datep = $db->jdate($obj->date_start) + (empty($halfday) || $halfday == 1 ? 0 : 12 * 60 * 60 - 1);
  837. $event->datef = $db->jdate($obj->date_end) + (empty($halfday) || $halfday == -1 ? 24 : 12) * 60 * 60 - 1;
  838. $event->date_start_in_calendar = $event->datep;
  839. $event->date_end_in_calendar = $event->datef;
  840. if ($obj->status == 3) {
  841. // Show no symbol for leave with state "leave approved"
  842. $event->percentage = -1;
  843. } elseif ($obj->status == 2) {
  844. // Show TO-DO symbol for leave with state "leave wait for approval"
  845. $event->percentage = 0;
  846. }
  847. if ($obj->halfday == 1) {
  848. $event->label = $obj->lastname . ' (' . $langs->trans("Morning") . ')';
  849. } elseif ($obj->halfday == -1) {
  850. $event->label = $obj->lastname . ' (' . $langs->trans("Afternoon") . ')';
  851. } else {
  852. $event->label = $obj->lastname;
  853. }
  854. $daycursor = $event->date_start_in_calendar;
  855. $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
  856. $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
  857. $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
  858. $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
  859. do {
  860. $eventarray[$daykey][] = $event;
  861. $daykey += 60 * 60 * 24;
  862. } while ($daykey <= $event->date_end_in_calendar);
  863. $i++;
  864. }
  865. }
  866. // EXTERNAL CALENDAR
  867. // Complete $eventarray with external import Ical
  868. // Complete $eventarray with events coming from external module
  869. $parameters = array();
  870. $object = null;
  871. $reshook = $hookmanager->executeHooks('getCalendarEvents', $parameters, $object, $action);
  872. if (!empty($hookmanager->resArray['eventarray'])) {
  873. foreach ($hookmanager->resArray['eventarray'] as $keyDate => $events) {
  874. if (!isset($eventarray[$keyDate])) {
  875. $eventarray[$keyDate] = array();
  876. }
  877. $eventarray[$keyDate] = array_merge($eventarray[$keyDate], $events);
  878. }
  879. }
  880. // Sort events
  881. foreach ($eventarray as $keyDate => &$dateeventarray) {
  882. usort($dateeventarray, 'sort_events_by_date');
  883. }
  884. $maxnbofchar = 0;
  885. $cachethirdparties = array();
  886. $cachecontacts = array();
  887. $cacheusers = array();
  888. // Define theme_datacolor array
  889. $color_file = DOL_DOCUMENT_ROOT . "/theme/" . $conf->theme . "/theme_vars.inc.php";
  890. if (is_readable($color_file)) {
  891. include $color_file;
  892. }
  893. if (!is_array($theme_datacolor)) {
  894. $theme_datacolor = array(array(120, 130, 150), array(200, 160, 180), array(190, 190, 220));
  895. }
  896. $massactionbutton = '';
  897. 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);
  898. // Show div with list of calendars
  899. print $s;
  900. // View by day
  901. $newparam = $param; // newparam is for birthday links
  902. $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
  903. $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
  904. $newparam = preg_replace('/viewday=[0-9]+&?/i', '', $newparam);
  905. $newparam .= '&viewday=1';
  906. // Code to show just one day
  907. $style = 'cal_current_month cal_current_month_oneday';
  908. $today = 0;
  909. $todayarray = dol_getdate($now, 'fast');
  910. if ($todayarray['mday'] == $day && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
  911. $today = 1;
  912. }
  913. //if ($today) $style='cal_today';
  914. $timestamp = dol_mktime(12, 0, 0, $month, $day, $year);
  915. $arraytimestamp = dol_getdate($timestamp);
  916. /* print '<div class="liste_titre liste_titre_bydiv centpercent"><div class="divsearchfield">';
  917. print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
  918. print '</div></div>'; */
  919. print '<div class="div-table-responsive-no-min sectioncalendarbyday maxscreenheightless300">';
  920. echo '<table class="tagtable centpercent noborder nocellnopadd cal_pannel cal_month noborderbottom" style="margin-bottom: 5px !important;">';
  921. echo ' <tr class="tagtr liste_titre">';
  922. echo ' <td class="tagtd center bold uppercase">' . $langs->trans("Day" . $arraytimestamp['wday']) . "</td>\n";
  923. echo " </td>\n";
  924. echo '</table>';
  925. print '</div>';
  926. $eventdayDates = $bookingAgendaHelper->getEventDayDates($year, $month, $day);
  927. print '<div id="dateview">Updated content: ' . date("Y-m-d H:i:s") . '</div>';
  928. print $eventdayDates['eventdayprint'];
  929. print '<input type="hidden" id="jsyear" name="jsyear" value="' . $year . '">
  930. <input type="hidden" id="jsmonth" name="jsmonth" value="' . $month . '">
  931. <input type="hidden" id="jsday" name="jsday" value="' . $day . '">
  932. <input type="hidden" id="selectedEvent" name="selectedEvent" value="">';
  933. print '<div id="dayviewdiv" class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  934. $bookingAgendaHelper->showTable($eventdayDates, $selectedEvent);
  935. print '</div>';
  936. print '<div id="eventdetailviewdiv"></div>';
  937. print "\n" . '</form>';
  938. ?>
  939. <script>
  940. $(document).ready(function() {
  941. console.log("ready!");
  942. const selectedEvent = document.getElementById('selectedEvent');
  943. const value = selectedEvent.value;
  944. console.log(value);
  945. });
  946. function ShoMeTheEventDeatils(id) {
  947. const eventdetailviewdiv = document.getElementById('eventdetailviewdiv');
  948. $('#selectedEvent').attr('value', id);
  949. const xhr = new XMLHttpRequest();
  950. xhr.open('GET', 'booking_agenda_event_details_view.php?event=' + id, true);
  951. xhr.onload = function() {
  952. if (xhr.status === 200) {
  953. eventdetailviewdiv.innerHTML = xhr.responseText;
  954. } else {
  955. console.error('Error fetching content:', xhr.status, xhr.statusText);
  956. }
  957. };
  958. xhr.send();
  959. }
  960. function formatDate(date) {
  961. const year = date.getFullYear();
  962. const month = String(date.getMonth() + 1).padStart(2, '0'); // Hónap 0-alapú, ezért +1
  963. const day = String(date.getDate()).padStart(2, '0');
  964. const hours = String(date.getHours()).padStart(2, '0');
  965. const minutes = String(date.getMinutes()).padStart(2, '0');
  966. const seconds = String(date.getSeconds()).padStart(2, '0');
  967. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  968. }
  969. function updateDivContent() {
  970. const selectedEvent = document.getElementById('selectedEvent');
  971. const value = selectedEvent.value;
  972. const dateview = document.getElementById('dateview');
  973. const dayviewdiv = document.getElementById('dayviewdiv');
  974. var year = document.getElementById('jsyear');
  975. var month = document.getElementById('jsmonth');
  976. var day = document.getElementById('jsday');
  977. const now = new Date();
  978. document.getElementById('dateview').innerText = 'Updated content: ' + formatDate(now);
  979. const xhr = new XMLHttpRequest();
  980. xhr.open('GET', 'booking_agenda_table_view.php?year=' + year.value + '&month=' + month.value + '&day=' + day.value, true);
  981. xhr.onload = function() {
  982. if (xhr.status === 200) {
  983. dayviewdiv.innerHTML = xhr.responseText;
  984. } else {
  985. console.error('Error fetching content:', xhr.status, xhr.statusText);
  986. }
  987. };
  988. xhr.send();
  989. if (value != '') {
  990. console.log(value);
  991. ShoMeTheEventDeatils(value);
  992. }
  993. }
  994. setInterval(updateDivContent, 5000);
  995. </script>
  996. <style>
  997. .trheight {
  998. height: 50px;
  999. }
  1000. .elvalaszto {
  1001. background-color: grey;
  1002. }
  1003. .foglaltsag {
  1004. color: red;
  1005. }
  1006. .location {
  1007. color: black;
  1008. }
  1009. .firstcolumn {
  1010. background-color: lightgrey;
  1011. text-align: center;
  1012. font-weight: bold;
  1013. }
  1014. </style>
  1015. <?
  1016. // End of page
  1017. llxFooter();
  1018. $db->close();
  1019. /**
  1020. * Show event of a particular day
  1021. *
  1022. * @param DoliDB $db Database handler
  1023. * @param int $day Day
  1024. * @param int $month Month
  1025. * @param int $year Year
  1026. * @param int $monthshown Current month shown in calendar view
  1027. * @param string $style Style to use for this day
  1028. * @param array $eventarray Array of events
  1029. * @param int $maxprint Nb of actions to show each day on month view (0 means no limit)
  1030. * @param int $maxnbofchar Nb of characters to show for event line
  1031. * @param string $newparam Parameters on current URL
  1032. * @param int $showinfo Add extended information (used by day and week view)
  1033. * @param int $minheight Minimum height for each event. 60px by default.
  1034. * @param string $nonew 0=Add "new entry button", 1=No "new entry button", -1=Only "new entry button"
  1035. * @return void
  1036. */
  1037. function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint = 0, $maxnbofchar = 16, $newparam = '', $showinfo = 0, $minheight = 60, $nonew = 0)
  1038. {
  1039. global $user, $conf, $langs;
  1040. global $action, $mode, $filter, $filtert, $status, $actioncode, $usergroup; // Filters used into search form
  1041. global $theme_datacolor;
  1042. global $cachethirdparties, $cachecontacts, $cacheusers, $colorindexused;
  1043. if ($conf->use_javascript_ajax) { // Enable the "Show more button..."
  1044. $conf->global->MAIN_JS_SWITCH_AGENDA = 1;
  1045. }
  1046. $dateint = sprintf("%04d", $year) . sprintf("%02d", $month) . sprintf("%02d", $day);
  1047. //print 'show_day_events day='.$day.' month='.$month.' year='.$year.' dateint='.$dateint;
  1048. print "\n";
  1049. $curtime = dol_mktime(0, 0, 0, $month, $day, $year);
  1050. $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;
  1051. $urltocreate = '';
  1052. if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
  1053. $newparam .= '&month=' . str_pad($month, 2, "0", STR_PAD_LEFT) . '&year=' . $year;
  1054. $hourminsec = '100000';
  1055. $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 : ''));
  1056. }
  1057. // Line with title of day
  1058. print '<div id="dayevent_' . $dateint . '" class="dayevent tagtable centpercent nobordernopadding">' . "\n";
  1059. if ($nonew <= 0) {
  1060. print '<div class="tagtr cursorpointer" onclick="window.location=\'' . $urltocreate . '\';"><div class="nowrap tagtd"><div class="left inline-block">';
  1061. print '<a class="dayevent-aday" style="color: #666" href="' . $urltoshow . '">';
  1062. if ($showinfo) {
  1063. print dol_print_date($curtime, 'daytextshort');
  1064. } else {
  1065. print dol_print_date($curtime, '%d');
  1066. }
  1067. print '</a>';
  1068. print '</div><div class="nowrap floatright inline-block marginrightonly">';
  1069. if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
  1070. print '<a class="cursoradd" href="' . $urltocreate . '">'; // Explicit link, usefull for nojs interfaces
  1071. print img_picto($langs->trans("NewAction"), 'edit_add.png');
  1072. print '</a>';
  1073. }
  1074. print '</div></div></div>' . "\n";
  1075. }
  1076. if ($nonew < 0) {
  1077. print '</div>';
  1078. return;
  1079. }
  1080. // Line with td contains all div of each events
  1081. print '<div class="tagtr">';
  1082. print '<div class="tagtd centpercent agendacell sortable">';
  1083. //$curtime = dol_mktime (0, 0, 0, $month, $day, $year);
  1084. $i = 0;
  1085. $ireallyshown = 0;
  1086. $itoshow = 0;
  1087. $numother = 0;
  1088. $numbirthday = 0;
  1089. $numical = 0;
  1090. $numicals = array();
  1091. $ymd = sprintf("%04d", $year) . sprintf("%02d", $month) . sprintf("%02d", $day);
  1092. $colorindexused[$user->id] = 0; // Color index for current user (user->id) is always 0
  1093. $nextindextouse = is_array($colorindexused) ? count($colorindexused) : 0; // At first run this is 0, so fist user has 0, next 1, ...
  1094. //var_dump($colorindexused);
  1095. include_once DOL_DOCUMENT_ROOT . '/holiday/class/holiday.class.php';
  1096. $tmpholiday = new Holiday($db);
  1097. foreach ($eventarray as $daykey => $notused) { // daykey is the 'YYYYMMDD' to show according to user
  1098. $annee = dol_print_date($daykey, '%Y', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
  1099. $mois = dol_print_date($daykey, '%m', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
  1100. $jour = dol_print_date($daykey, '%d', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
  1101. //print 'event daykey='.$daykey.' dol_print_date(daykey)='.dol_print_date($daykey, 'dayhour', 'gmt').' jour='.$jour.' mois='.$mois.' annee='.$annee."<br>\n";
  1102. if ($day == $jour && $month == $mois && $year == $annee) {
  1103. foreach ($eventarray[$daykey] as $index => $event) {
  1104. if ($i < $maxprint || $maxprint == 0 || !empty($conf->global->MAIN_JS_SWITCH_AGENDA)) {
  1105. $keysofuserassigned = array_keys($event->userassigned);
  1106. $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
  1107. // Define $color (Hex string like '0088FF') and $cssclass of event
  1108. $color = -1;
  1109. $cssclass = '';
  1110. $colorindex = -1;
  1111. if (in_array($user->id, $keysofuserassigned)) {
  1112. $cssclass = 'family_mytasks';
  1113. if (empty($cacheusers[$event->userownerid])) {
  1114. $newuser = new User($db);
  1115. $newuser->fetch($event->userownerid);
  1116. $cacheusers[$event->userownerid] = $newuser;
  1117. }
  1118. //var_dump($cacheusers[$event->userownerid]->color);
  1119. // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
  1120. if (!empty($cacheusers[$event->userownerid]->color)) {
  1121. $color = $cacheusers[$event->userownerid]->color;
  1122. }
  1123. } elseif ($event->type_code == 'ICALEVENT') { // Event come from external ical file
  1124. $numical++;
  1125. if (!empty($event->icalname)) {
  1126. if (!isset($numicals[dol_string_nospecial($event->icalname)])) {
  1127. $numicals[dol_string_nospecial($event->icalname)] = 0;
  1128. }
  1129. $numicals[dol_string_nospecial($event->icalname)]++;
  1130. }
  1131. $color = ($event->icalcolor ? $event->icalcolor : -1);
  1132. $cssclass = (!empty($event->icalname) ? 'family_ext' . md5($event->icalname) : 'family_other');
  1133. } elseif ($event->type_code == 'BIRTHDAY') {
  1134. $numbirthday++;
  1135. $colorindex = 2;
  1136. $cssclass = 'family_birthday ';
  1137. $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
  1138. } else {
  1139. $numother++;
  1140. $color = ($event->icalcolor ? $event->icalcolor : -1);
  1141. $cssclass = (!empty($event->icalname) ? 'family_ext' . md5($event->icalname) : 'family_other');
  1142. if (empty($cacheusers[$event->userownerid])) {
  1143. $newuser = new User($db);
  1144. $newuser->fetch($event->userownerid);
  1145. $cacheusers[$event->userownerid] = $newuser;
  1146. }
  1147. //var_dump($cacheusers[$event->userownerid]->color);
  1148. // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
  1149. if (!empty($cacheusers[$event->userownerid]->color)) {
  1150. $color = $cacheusers[$event->userownerid]->color;
  1151. }
  1152. }
  1153. if ($color < 0) { // Color was not set on user card. Set color according to color index.
  1154. // Define color index if not yet defined
  1155. $idusertouse = ($event->userownerid ? $event->userownerid : 0);
  1156. if (isset($colorindexused[$idusertouse])) {
  1157. $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user
  1158. } else {
  1159. $colorindex = $nextindextouse;
  1160. $colorindexused[$idusertouse] = $colorindex;
  1161. if (!empty($theme_datacolor[$nextindextouse + 1])) {
  1162. $nextindextouse++; // Prepare to use next color
  1163. }
  1164. }
  1165. //print '|'.($color).'='.($idusertouse?$idusertouse:0).'='.$colorindex.'<br>';
  1166. // Define color
  1167. $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
  1168. }
  1169. $cssclass = $cssclass . ' eventday_' . $ymd;
  1170. // Defined style to disable drag and drop feature
  1171. if ($event->type_code == 'AC_OTH_AUTO') {
  1172. $cssclass .= " unmovable";
  1173. } elseif ($event->type_code == 'HOLIDAY') {
  1174. $cssclass .= " unmovable";
  1175. } elseif ($event->type_code == 'BIRTHDAY') {
  1176. $cssclass .= " unmovable";
  1177. } elseif ($event->type_code == 'ICALEVENT') {
  1178. $cssclass .= " unmovable";
  1179. } 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)) {
  1180. // If the event is on several days
  1181. $tmpyearend = dol_print_date($event->date_start_in_calendar, '%Y', 'tzuserrel');
  1182. $tmpmonthend = dol_print_date($event->date_start_in_calendar, '%m', 'tzuserrel');
  1183. $tmpdayend = dol_print_date($event->date_start_in_calendar, '%d', 'tzuserrel');
  1184. //var_dump($tmpyearend.' '.$tmpmonthend.' '.$tmpdayend);
  1185. if ($tmpyearend != $annee || $tmpmonthend != $mois || $tmpdayend != $jour) {
  1186. $cssclass .= " unmovable unmovable-mustusefirstdaytodrag";
  1187. } else {
  1188. $cssclass .= ' movable cursormove';
  1189. }
  1190. } else {
  1191. if (
  1192. $user->rights->agenda->allactions->create ||
  1193. (($event->authorid == $user->id || $event->userownerid == $user->id) && $user->rights->agenda->myactions->create)
  1194. ) {
  1195. $cssclass .= " movable cursormove";
  1196. } else {
  1197. $cssclass .= " unmovable";
  1198. }
  1199. }
  1200. $h = '';
  1201. $nowrapontd = 1;
  1202. if ($mode == 'show_day') {
  1203. $h = 'height: 100%; ';
  1204. $nowrapontd = 0;
  1205. }
  1206. if ($mode == 'show_week') {
  1207. $h = 'height: 100%; ';
  1208. $nowrapontd = 0;
  1209. }
  1210. // Show event box
  1211. print "\n";
  1212. print '<!-- start event ' . $i . ' -->' . "\n";
  1213. $morecss = '';
  1214. if ($maxprint && $ireallyshown >= $maxprint) {
  1215. $morecss = 'showifmore';
  1216. }
  1217. if ($event->type == 'birthdate' && !GETPOST('check_birthday')) {
  1218. $morecss = 'hidden';
  1219. }
  1220. if ($event->type == 'holiday' && !GETPOST('check_holiday')) {
  1221. $morecss = 'hidden';
  1222. }
  1223. if ($morecss != 'hidden') {
  1224. $itoshow++;
  1225. }
  1226. if ($morecss != 'showifmore' && $morecss != 'hidden') {
  1227. $ireallyshown++;
  1228. }
  1229. //var_dump($event->type.' - '.$morecss.' - '.$cssclass.' - '.$i.' - '.$ireallyshown.' - '.$itoshow);
  1230. print '<div id="event_' . $ymd . '_' . $i . '" class="event family_' . $event->type . ' ' . $cssclass . ($morecss ? ' ' . $morecss : '') . '"';
  1231. //print ' style="height: 100px;';
  1232. //print ' position: absolute; top: 40px; width: 50%;';
  1233. //print '"';
  1234. print '>';
  1235. //var_dump($event->userassigned);
  1236. //var_dump($event->transparency);
  1237. print '<table class="centpercent cal_event';
  1238. print(empty($event->transparency) ? ' cal_event_notbusy' : ' cal_event_busy');
  1239. //if (empty($event->transparency) && empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) print ' opacitymedium'; // Not busy
  1240. print '" style="' . $h;
  1241. $colortouse = $color;
  1242. // If colortouse is similar than background, we force to change it.
  1243. if (empty($event->transparency) && empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
  1244. print 'background: #f0f0f0;';
  1245. print 'border-left: 5px solid #' . $colortouse . ';';
  1246. } else {
  1247. print 'background: #f0f0f0;';
  1248. print 'border-left: 5px solid #' . dol_color_minus($colortouse, -3) . ';';
  1249. //print 'background: -webkit-gradient(linear, left top, left bottom, from(#'.dol_color_minus($colortouse, -3).'), to(#'.dol_color_minus($colortouse, -1).'));';
  1250. }
  1251. //print 'background: #'.$colortouse.';';
  1252. //print 'background: -webkit-gradient(linear, left top, left bottom, from(#'.dol_color_minus($color, -3).'), to(#'.dol_color_minus($color, -1).'));';
  1253. //if (!empty($event->transparency)) print 'background: #'.$color.'; background: -webkit-gradient(linear, left top, left bottom, from(#'.$color.'), to(#'.dol_color_minus($color,1).'));';
  1254. //else print 'background-color: transparent !important; background: none; border: 1px solid #bbb;';
  1255. //print ' -moz-border-radius:4px;"';
  1256. //print 'border: 1px solid #ccc" width="100%"';
  1257. print '">';
  1258. print '<tr>';
  1259. print '<td class="tdoverflow nobottom centpercent ' . ($nowrapontd ? 'nowrap ' : '') . 'cal_event' . ($event->type_code == 'BIRTHDAY' ? ' cal_event_birthday' : '') . '">';
  1260. $daterange = '';
  1261. if ($event->type_code == 'BIRTHDAY') { // It's birthday calendar
  1262. print $event->getNomUrl(1, $maxnbofchar, 'cal_event', 'birthday', 'contact');
  1263. } elseif ($event->type_code == 'HOLIDAY') { // It's holiday calendar
  1264. $tmpholiday->fetch($event->id);
  1265. print $tmpholiday->getNomUrl(1);
  1266. $tmpid = $tmpholiday->fk_user;
  1267. if (empty($cacheusers[$tmpid])) {
  1268. $newuser = new User($db);
  1269. $newuser->fetch($tmpid);
  1270. $cacheusers[$tmpid] = $newuser;
  1271. }
  1272. $listofusertoshow = '';
  1273. $listofusertoshow .= '<br>' . $cacheusers[$tmpid]->getNomUrl(-1, '', 0, 0, 0, 0, '', 'paddingright valigntextbottom');
  1274. print $listofusertoshow;
  1275. } else { // Other calendar
  1276. // Picto
  1277. if (empty($event->fulldayevent)) {
  1278. //print $event->getNomUrl(2).' ';
  1279. }
  1280. // Date
  1281. if (empty($event->fulldayevent)) {
  1282. // Show hours (start ... end)
  1283. $tmpyearstart = dol_print_date($event->date_start_in_calendar, '%Y', 'tzuserrel');
  1284. $tmpmonthstart = dol_print_date($event->date_start_in_calendar, '%m', 'tzuserrel');
  1285. $tmpdaystart = dol_print_date($event->date_start_in_calendar, '%d', 'tzuserrel');
  1286. $tmpyearend = dol_print_date($event->date_end_in_calendar, '%Y', 'tzuserrel');
  1287. $tmpmonthend = dol_print_date($event->date_end_in_calendar, '%m', 'tzuserrel');
  1288. $tmpdayend = dol_print_date($event->date_end_in_calendar, '%d', 'tzuserrel');
  1289. // Hour start
  1290. if ($tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour) {
  1291. $daterange .= dol_print_date($event->date_start_in_calendar, 'hour', 'tzuserrel');
  1292. if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
  1293. if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend) {
  1294. $daterange .= '-';
  1295. }
  1296. //else
  1297. //print '...';
  1298. }
  1299. }
  1300. if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
  1301. if ($tmpyearstart != $tmpyearend || $tmpmonthstart != $tmpmonthend || $tmpdaystart != $tmpdayend) {
  1302. $daterange .= '...';
  1303. }
  1304. }
  1305. // Hour end
  1306. if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
  1307. if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour) {
  1308. $daterange .= dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
  1309. }
  1310. }
  1311. } else {
  1312. if ($showinfo) {
  1313. print $langs->trans("EventOnFullDay") . "<br>\n";
  1314. }
  1315. }
  1316. // Show title
  1317. $titletoshow = $daterange;
  1318. //$titletoshow .= ($titletoshow ? ' ' : '').dol_escape_htmltag($event->label ? $event->label : $event->libelle);
  1319. if ($event->type_code != 'ICALEVENT') {
  1320. $savlabel = $event->label ? $event->label : $event->libelle;
  1321. $event->label = $titletoshow;
  1322. $event->libelle = $titletoshow; // deprecatd
  1323. // Note: List of users are inside $event->userassigned. Link may be clickable depending on permissions of user.
  1324. //$titletoshow = (($event->type_picto || $event->type_code) ? $event->getTypePicto() : '');
  1325. $titletoshow .= $event->getNomUrl(0, $maxnbofchar, 'cal_event cal_event_title', '', 0, 0);
  1326. $event->label = $savlabel;
  1327. $event->libelle = $savlabel;
  1328. }
  1329. // Loop on each assigned user
  1330. $listofusertoshow = '';
  1331. $posuserassigned = 0;
  1332. foreach ($event->userassigned as $tmpid => $tmpdata) {
  1333. if (!$posuserassigned && $titletoshow) {
  1334. $listofusertoshow .= '<br>';
  1335. }
  1336. $posuserassigned++;
  1337. if (empty($cacheusers[$tmpid])) {
  1338. $newuser = new User($db);
  1339. $newuser->fetch($tmpid);
  1340. $cacheusers[$tmpid] = $newuser;
  1341. }
  1342. $listofusertoshow .= $cacheusers[$tmpid]->getNomUrl(-3, '', 0, 0, 0, 0, '', 'paddingright valigntextbottom');
  1343. }
  1344. print $titletoshow;
  1345. print $listofusertoshow;
  1346. if ($event->type_code == 'ICALEVENT') {
  1347. print '<br>(' . dol_trunc($event->icalname, $maxnbofchar) . ')';
  1348. }
  1349. $thirdparty_id = ($event->socid > 0 ? $event->socid : ((is_object($event->societe) && $event->societe->id > 0) ? $event->societe->id : 0));
  1350. $contact_id = ($event->contact_id > 0 ? $event->contact_id : ((is_object($event->contact) && $event->contact->id > 0) ? $event->contact->id : 0));
  1351. // If action related to company / contact
  1352. $linerelatedto = '';
  1353. if ($thirdparty_id > 0) {
  1354. if (!isset($cachethirdparties[$thirdparty_id]) || !is_object($cachethirdparties[$thirdparty_id])) {
  1355. $thirdparty = new Societe($db);
  1356. $thirdparty->fetch($thirdparty_id);
  1357. $cachethirdparties[$thirdparty_id] = $thirdparty;
  1358. } else {
  1359. $thirdparty = $cachethirdparties[$thirdparty_id];
  1360. }
  1361. if (!empty($thirdparty->id)) {
  1362. $linerelatedto .= $thirdparty->getNomUrl(1, '', 0);
  1363. }
  1364. }
  1365. if (!empty($contact_id) && $contact_id > 0) {
  1366. if (!is_object($cachecontacts[$contact_id])) {
  1367. $contact = new Contact($db);
  1368. $contact->fetch($contact_id);
  1369. $cachecontacts[$contact_id] = $contact;
  1370. } else {
  1371. $contact = $cachecontacts[$contact_id];
  1372. }
  1373. if ($linerelatedto) {
  1374. $linerelatedto .= '&nbsp;';
  1375. }
  1376. if (!empty($contact->id)) {
  1377. $linerelatedto .= $contact->getNomUrl(1, '', 0);
  1378. }
  1379. }
  1380. if (!empty($event->fk_element) && $event->fk_element > 0 && !empty($event->elementtype) && !empty($conf->global->AGENDA_SHOW_LINKED_OBJECT)) {
  1381. include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
  1382. if ($linerelatedto) {
  1383. $linerelatedto .= '<br>';
  1384. }
  1385. $linerelatedto .= dolGetElementUrl($event->fk_element, $event->elementtype, 1);
  1386. }
  1387. if ($linerelatedto) {
  1388. print '<br>' . $linerelatedto;
  1389. }
  1390. }
  1391. // Show location
  1392. if ($showinfo) {
  1393. if ($event->location) {
  1394. print '<br>';
  1395. print $langs->trans("Location") . ': ' . $event->location;
  1396. }
  1397. }
  1398. print '</td>';
  1399. // Status - Percent
  1400. $withstatus = 0;
  1401. if ($event->type_code != 'BIRTHDAY' && $event->type_code != 'ICALEVENT') {
  1402. $withstatus = 1;
  1403. if ($event->percentage >= 0) {
  1404. $withstatus = 2;
  1405. }
  1406. }
  1407. print '<td class="nobottom right nowrap cal_event_right' . ($withstatus >= 2 ? ' cal_event_right_status' : '') . '">';
  1408. if ($withstatus) {
  1409. print $event->getLibStatut(3, 1);
  1410. } else {
  1411. print '&nbsp;';
  1412. }
  1413. print '</td></tr></table>';
  1414. print '</div><!-- end event ' . $i . ' -->' . "\n";
  1415. $i++;
  1416. } else {
  1417. print '<a href="' . DOL_URL_ROOT . '/custom/booking/booking_agenda.php?mode=' . $mode . '&maxprint=0&month=' . ((int) $monthshown) . '&year=' . ((int) $year);
  1418. print ($status ? '&status=' . $status : '') . ($filter ? '&filter=' . urlencode($filter) : '');
  1419. print($filtert ? '&search_filtert=' . urlencode($filtert) : '');
  1420. print($usergroup ? '&search_usergroup=' . urlencode($usergroup) : '');
  1421. print($actioncode != '' ? '&search_actioncode=' . urlencode($actioncode) : '');
  1422. print '">' . img_picto("all", "1downarrow_selected.png") . ' ...';
  1423. print ' +' . (count($eventarray[$daykey]) - $maxprint);
  1424. print '</a>';
  1425. break;
  1426. //$ok=false; // To avoid to show twice the link
  1427. }
  1428. }
  1429. break;
  1430. }
  1431. }
  1432. if (!$i) { // No events
  1433. print '&nbsp;';
  1434. }
  1435. if (!empty($conf->global->MAIN_JS_SWITCH_AGENDA) && $itoshow > $ireallyshown && $maxprint) {
  1436. print '<div class="center cursorpointer" id="more_' . $ymd . '">' . img_picto("All", "angle-double-down", 'class="warning"') . ' +' . ($itoshow - $ireallyshown) . '</div>';
  1437. //print ' +'.(count($eventarray[$daykey])-$maxprint);
  1438. print '<script type="text/javascript">' . "\n";
  1439. print 'jQuery(document).ready(function () {' . "\n";
  1440. print ' var open=0;' . "\n";
  1441. print ' jQuery("#more_' . $ymd . '").click(function() { console.log("Click on showmore for ' . $ymd . '"); reinit_day_' . $ymd . '(); event.stopImmediatePropagation(); });' . "\n";
  1442. print ' function reinit_day_' . $ymd . '() {' . "\n";
  1443. print ' jQuery(".eventday_' . $ymd . '.showifmore").toggle();' . "\n";
  1444. print ' open = open + 1; if (open > 1) { open = 0; }' . "\n";
  1445. print ' if (open) { ';
  1446. print ' jQuery("#more_' . $ymd . '").html(\'' . img_picto("All", "angle-double-up", 'class="warning"') . '\');' . "\n";
  1447. print ' } else { ';
  1448. print ' jQuery("#more_' . $ymd . '").html(\'' . img_picto("All", "angle-double-down", 'class="warning"') . ' +' . ($itoshow - $ireallyshown) . '\');' . "\n";
  1449. print ' }' . "\n";
  1450. print ' }' . "\n";
  1451. print '});' . "\n";
  1452. print '</script>' . "\n";
  1453. }
  1454. print '</div></div>'; // td tr
  1455. print '</div>'; // table
  1456. print "\n";
  1457. }
  1458. /**
  1459. * Change color with a delta
  1460. *
  1461. * @param string $color Color
  1462. * @param int $minus Delta (1 = 16 unit). Positive value = darker color, Negative value = brighter color.
  1463. * @param int $minusunit Minus unit
  1464. * @return string New color
  1465. */
  1466. function dol_color_minus($color, $minus, $minusunit = 16)
  1467. {
  1468. $newcolor = $color;
  1469. if ($minusunit == 16) {
  1470. $newcolor[0] = dechex(max(min(hexdec($newcolor[0]) - $minus, 15), 0));
  1471. $newcolor[2] = dechex(max(min(hexdec($newcolor[2]) - $minus, 15), 0));
  1472. $newcolor[4] = dechex(max(min(hexdec($newcolor[4]) - $minus, 15), 0));
  1473. } else {
  1474. // Not yet implemented
  1475. }
  1476. return $newcolor;
  1477. }
  1478. /**
  1479. * Sort events by date
  1480. *
  1481. * @param object $a Event A
  1482. * @param object $b Event B
  1483. * @return int < 0 if event A should be before event B, > 0 otherwise, 0 if they have the exact same time slot
  1484. */
  1485. function sort_events_by_date($a, $b)
  1486. {
  1487. // Sort holidays at first
  1488. if ($a->type_code === 'HOLIDAY') {
  1489. return -1;
  1490. }
  1491. if ($b->type_code === 'HOLIDAY') {
  1492. return 1;
  1493. }
  1494. // datep => Event start time
  1495. // datef => Event end time
  1496. // Events have different start time
  1497. if ($a->datep !== $b->datep) {
  1498. return $a->datep - $b->datep;
  1499. }
  1500. // Events have same start time and no end time
  1501. if ((!is_numeric($b->datef)) || (!is_numeric($a->datef))) {
  1502. return sort_events_by_percentage($a, $b);
  1503. }
  1504. // Events have the same start time and same end time
  1505. if ($b->datef === $a->datef) {
  1506. return sort_events_by_percentage($a, $b);
  1507. }
  1508. // Events have the same start time, but have different end time -> longest event first
  1509. return $b->datef - $a->datef;
  1510. }
  1511. /**
  1512. * Sort events by percentage
  1513. *
  1514. * @param object $a Event A
  1515. * @param object $b Event B
  1516. * @return int < 0 if event A should be before event B, > 0 otherwise, 0 if they have the exact same percentage
  1517. */
  1518. function sort_events_by_percentage($a, $b)
  1519. {
  1520. // Sort events with no percentage before each other
  1521. // (usefull to sort holidays, sick days or similar on the top)
  1522. if ($a->percentage < 0) {
  1523. return -1;
  1524. }
  1525. if ($b->percentage < 0) {
  1526. return 1;
  1527. }
  1528. return $b->percentage - $a->percentage;
  1529. }