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. /* $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.'">';
  445. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  446. $viewmode .= img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="pictoactionview block"');
  447. //$viewmode .= '</span>';
  448. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewPerUser").'</span></a>';
  449. */
  450. // Add more views from hooks
  451. $parameters = array();
  452. $object = null;
  453. $reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
  454. if (empty($reshook)) {
  455. $viewmode .= $hookmanager->resPrint;
  456. } elseif ($reshook > 1) {
  457. $viewmode = $hookmanager->resPrint;
  458. }
  459. $viewmode .= '<span class="marginrightonly"></span>'; // To add a space before the navigation tools
  460. $newcardbutton = '';
  461. $newparam = '';
  462. if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
  463. $tmpforcreatebutton = dol_getdate(dol_now(), true);
  464. $newparam .= '&month=' . ((int) $month) . '&year=' . ((int) $tmpforcreatebutton['year']) . '&mode=' . urlencode($mode);
  465. //$param='month='.$monthshown.'&year='.$year;
  466. $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
  467. $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 : '')));
  468. }
  469. // Define the legend/list of calendard to show
  470. $s = '';
  471. $link = '';
  472. $showextcals = $listofextcals;
  473. if (!empty($conf->use_javascript_ajax)) { // If javascript on
  474. $s .= "\n" . '<!-- Div to calendars selectors -->' . "\n";
  475. $s .= '<script type="text/javascript">' . "\n";
  476. $s .= 'jQuery(document).ready(function () {' . "\n";
  477. $s .= 'jQuery(".check_birthday").click(function() { console.log("Toggle birthdays"); jQuery(".family_birthday").toggle(); });' . "\n";
  478. $s .= 'jQuery(".check_holiday").click(function() { console.log("Toggle holidays"); jQuery(".family_holiday").toggle(); });' . "\n";
  479. if ($mode == "show_week" || $mode == "show_month" || empty($mode)) {
  480. // Code to enable drag and drop
  481. $s .= 'jQuery( "div.sortable" ).sortable({connectWith: ".sortable", placeholder: "ui-state-highlight", items: "div.movable", receive: function( event, ui ) {' . "\n";
  482. // Code to submit form
  483. $s .= 'console.log("submit form to record new event");' . "\n";
  484. //$s.='console.log(event.target);';
  485. $s .= 'var newval = jQuery(event.target).closest("div.dayevent").attr("id");' . "\n";
  486. $s .= 'console.log("found parent div.dayevent with id = "+newval);' . "\n";
  487. $s .= 'var frm=jQuery("#searchFormList");' . "\n";
  488. $s .= 'var newurl = ui.item.find("a.cal_event").attr("href");' . "\n";
  489. $s .= 'console.log("Found url on href of a.cal_event"+newurl+", we submit form with actionmove=mupdate");' . "\n";
  490. $s .= 'frm.attr("action", newurl).children("#newdate").val(newval);frm.submit();}' . "\n";
  491. $s .= '});' . "\n";
  492. }
  493. $s .= '});' . "\n";
  494. $s .= '</script>' . "\n";
  495. // Local calendar
  496. $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>';
  497. // Holiday calendar
  498. //$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>';
  499. // External calendars
  500. if (is_array($showextcals) && count($showextcals) > 0) {
  501. $s .= '<script type="text/javascript">' . "\n";
  502. $s .= 'jQuery(document).ready(function () {
  503. jQuery("div input[name^=\"check_ext\"]").each(function(index, elem) {
  504. var name = jQuery(elem).attr("name");
  505. if (jQuery(elem).is(":checked")) {
  506. jQuery(".family_ext" + name.replace("check_ext", "")).show();
  507. } else {
  508. jQuery(".family_ext" + name.replace("check_ext", "")).hide();
  509. }
  510. });
  511. jQuery("div input[name^=\"check_ext\"]").click(function() {
  512. var name = $(this).attr("name");
  513. jQuery(".family_ext" + name.replace("check_ext", "")).toggle();
  514. });
  515. });' . "\n";
  516. $s .= '</script>' . "\n";
  517. foreach ($showextcals as $val) {
  518. $htmlname = md5($val['name']);
  519. if (!empty($val['default']) || GETPOST('check_ext' . $htmlname, 'int')) {
  520. $default = "checked";
  521. } else {
  522. $default = '';
  523. }
  524. $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>';
  525. }
  526. }
  527. // Birthdays
  528. //$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>';
  529. // Calendars from hooks
  530. $parameters = array();
  531. $reshook = $hookmanager->executeHooks('addCalendarChoice', $parameters, $object, $action);
  532. if (empty($reshook)) {
  533. $s .= $hookmanager->resPrint;
  534. } elseif ($reshook > 1) {
  535. $s = $hookmanager->resPrint;
  536. }
  537. $s .= "\n" . '<!-- End div to calendars selectors -->' . "\n";
  538. } else { // If javascript off
  539. $newparam = $param; // newparam is for birthday links
  540. $newparam = preg_replace('/showbirthday=[0-1]/i', 'showbirthday=' . (empty($showbirthday) ? 1 : 0), $newparam);
  541. if (!preg_match('/showbirthday=/i', $newparam)) {
  542. $newparam .= '&showbirthday=1';
  543. }
  544. $link = '<a href="' . $_SERVER['PHP_SELF'] . '?' . dol_escape_htmltag($newparam);
  545. $link .= '">';
  546. if (empty($showbirthday)) {
  547. $link .= $langs->trans("AgendaShowBirthdayEvents");
  548. } else {
  549. $link .= $langs->trans("AgendaHideBirthdayEvents");
  550. }
  551. $link .= '</a>';
  552. }
  553. // Load events from database into $eventarray
  554. $eventarray = array();
  555. // DEFAULT CALENDAR + AUTOEVENT CALENDAR + CONFERENCEBOOTH CALENDAR
  556. $sql = 'SELECT ';
  557. if ($usergroup > 0) {
  558. $sql .= " DISTINCT";
  559. }
  560. $sql .= ' a.id, a.label,';
  561. $sql .= ' a.datep,';
  562. $sql .= ' a.datep2,';
  563. $sql .= ' a.percent,';
  564. $sql .= ' a.fk_user_author,a.fk_user_action,';
  565. $sql .= ' a.transparency, a.priority, a.fulldayevent, a.location,';
  566. $sql .= ' a.fk_soc, a.fk_contact, a.fk_project,';
  567. $sql .= ' a.fk_element, a.elementtype,';
  568. $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';
  569. $sql .= ' FROM ' . MAIN_DB_PREFIX . 'c_actioncomm as ca, ' . MAIN_DB_PREFIX . "actioncomm as a";
  570. if (empty($user->rights->societe->client->voir) && !$socid) {
  571. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
  572. }
  573. // We must filter on resource table
  574. if ($resourceid > 0) {
  575. $sql .= ", " . MAIN_DB_PREFIX . "element_resources as r";
  576. }
  577. // We must filter on assignement table
  578. if ($filtert > 0 || $usergroup > 0) {
  579. $sql .= ", " . MAIN_DB_PREFIX . "actioncomm_resources as ar";
  580. }
  581. if ($usergroup > 0) {
  582. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
  583. }
  584. $sql .= ' WHERE a.fk_action = ca.id';
  585. $sql .= ' AND a.entity IN (' . getEntity('agenda') . ')';
  586. // Condition on actioncode
  587. if (!empty($actioncode)) {
  588. if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
  589. if ($actioncode == 'AC_NON_AUTO') {
  590. $sql .= " AND ca.type != 'systemauto'";
  591. } elseif ($actioncode == 'AC_ALL_AUTO') {
  592. $sql .= " AND ca.type = 'systemauto'";
  593. } else {
  594. if ($actioncode == 'AC_OTH') {
  595. $sql .= " AND ca.type != 'systemauto'";
  596. }
  597. if ($actioncode == 'AC_OTH_AUTO') {
  598. $sql .= " AND ca.type = 'systemauto'";
  599. }
  600. }
  601. } else {
  602. if ($actioncode == 'AC_NON_AUTO') {
  603. $sql .= " AND ca.type != 'systemauto'";
  604. } elseif ($actioncode == 'AC_ALL_AUTO') {
  605. $sql .= " AND ca.type = 'systemauto'";
  606. } else {
  607. if (is_array($actioncode)) {
  608. $sql .= " AND ca.code IN (" . $db->sanitize("'" . implode("','", $actioncode) . "'", 1) . ")";
  609. } else {
  610. $sql .= " AND ca.code IN (" . $db->sanitize("'" . implode("','", explode(',', $actioncode)) . "'", 1) . ")";
  611. }
  612. }
  613. }
  614. }
  615. if ($resourceid > 0) {
  616. $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = " . ((int) $resourceid);
  617. }
  618. if ($pid) {
  619. $sql .= " AND a.fk_project=" . ((int) $pid);
  620. }
  621. if (empty($user->rights->societe->client->voir) && !$socid) {
  622. $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = " . ((int) $user->id) . ")";
  623. }
  624. if ($socid > 0) {
  625. $sql .= " AND a.fk_soc = " . ((int) $socid);
  626. }
  627. // We must filter on assignement table
  628. if ($filtert > 0 || $usergroup > 0) {
  629. $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
  630. }
  631. //var_dump($day.' '.$month.' '.$year);
  632. if ($mode == 'show_day') {
  633. $sql .= " AND (";
  634. $sql .= " (a.datep BETWEEN '" . $db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel')) . "'";
  635. $sql .= " AND '" . $db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel')) . "')";
  636. $sql .= " OR ";
  637. $sql .= " (a.datep2 BETWEEN '" . $db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel')) . "'";
  638. $sql .= " AND '" . $db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel')) . "')";
  639. $sql .= " OR ";
  640. $sql .= " (a.datep < '" . $db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel')) . "'";
  641. $sql .= " AND a.datep2 > '" . $db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel')) . "')";
  642. $sql .= ')';
  643. } else {
  644. // To limit array
  645. $sql .= " AND (";
  646. $sql .= " (a.datep BETWEEN '" . $db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7)) . "'"; // Start 7 days before
  647. $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
  648. $sql .= " OR ";
  649. $sql .= " (a.datep2 BETWEEN '" . $db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7)) . "'";
  650. $sql .= " AND '" . $db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10)) . "')";
  651. $sql .= " OR ";
  652. $sql .= " (a.datep < '" . $db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7)) . "'";
  653. $sql .= " AND a.datep2 > '" . $db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10)) . "')";
  654. $sql .= ')';
  655. }
  656. if ($type) {
  657. $sql .= " AND ca.id = " . ((int) $type);
  658. }
  659. $sql .= " AND a.code = 'AC_EVENT'";
  660. if ($status == '0') {
  661. // To do (not started)
  662. $sql .= " AND a.percent = 0";
  663. }
  664. if ($status == 'na') {
  665. // Not applicable
  666. $sql .= " AND a.percent = -1";
  667. }
  668. if ($status == '50') {
  669. // Running already started
  670. $sql .= " AND (a.percent > 0 AND a.percent < 100)";
  671. }
  672. if ($status == 'done' || $status == '100') {
  673. $sql .= " AND (a.percent = 100)";
  674. }
  675. if ($status == 'todo') {
  676. $sql .= " AND (a.percent >= 0 AND a.percent < 100)";
  677. }
  678. // We must filter on assignement table
  679. if ($filtert > 0 || $usergroup > 0) {
  680. $sql .= " AND (";
  681. if ($filtert > 0) {
  682. $sql .= "ar.fk_element = " . ((int) $filtert);
  683. }
  684. if ($usergroup > 0) {
  685. $sql .= ($filtert > 0 ? " OR " : "") . " ugu.fk_usergroup = " . ((int) $usergroup);
  686. }
  687. $sql .= ")";
  688. }
  689. // Sort on date
  690. $sql .= ' ORDER BY datep';
  691. //print $sql;
  692. dol_syslog("custom/booking/booking_agenda.php", LOG_DEBUG);
  693. $resql = $db->query($sql);
  694. if ($resql) {
  695. $num = $db->num_rows($resql);
  696. $MAXONSAMEPAGE = 10000; // Useless to have more. Protection to avoid memory overload when high number of event (for example after a mass import)
  697. $i = 0;
  698. while ($i < $num && $i < $MAXONSAMEPAGE) {
  699. $obj = $db->fetch_object($resql);
  700. // Discard auto action if option is on
  701. if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->type_code == 'AC_OTH_AUTO') {
  702. $i++;
  703. continue;
  704. }
  705. // Create a new object action
  706. $event = new ActionComm($db);
  707. $event->id = $obj->id;
  708. $event->ref = $event->id;
  709. $event->fulldayevent = $obj->fulldayevent;
  710. // event->datep and event->datef must be GMT date.
  711. if ($event->fulldayevent) {
  712. $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
  713. $event->datep = $db->jdate($obj->datep, $tzforfullday ? 'tzuser' : 'tzserver'); // If saved in $tzforfullday = gmt, we must invert date to be in user tz
  714. $event->datef = $db->jdate($obj->datep2, $tzforfullday ? 'tzuser' : 'tzserver');
  715. } else {
  716. // Example: $obj->datep = '1970-01-01 01:00:00', jdate will return 0 if TZ of PHP server is Europe/Berlin (+1)
  717. $event->datep = $db->jdate($obj->datep, 'tzserver');
  718. $event->datef = $db->jdate($obj->datep2, 'tzserver');
  719. }
  720. //$event->datep_formated_gmt = dol_print_date($event->datep, 'dayhour', 'gmt');
  721. //var_dump($obj->id.' '.$obj->datep.' '.dol_print_date($obj->datep, 'dayhour', 'gmt'));
  722. //var_dump($obj->id.' '.$event->datep.' '.dol_print_date($event->datep, 'dayhour', 'gmt'));
  723. $event->type_code = $obj->type_code;
  724. $event->type_label = $obj->type_label;
  725. $event->type_color = $obj->type_color;
  726. $event->type = $obj->type_type;
  727. $event->type_picto = $obj->type_picto;
  728. $event->libelle = $obj->label; // deprecated
  729. $event->label = $obj->label;
  730. $event->percentage = $obj->percent;
  731. $event->authorid = $obj->fk_user_author; // user id of creator
  732. $event->userownerid = $obj->fk_user_action; // user id of owner
  733. $event->fetch_userassigned(); // This load $event->userassigned
  734. $event->priority = $obj->priority;
  735. $event->location = $obj->location;
  736. $event->transparency = $obj->transparency;
  737. $event->fk_element = $obj->fk_element;
  738. $event->elementtype = $obj->elementtype;
  739. $event->fk_project = $obj->fk_project;
  740. $event->socid = $obj->fk_soc;
  741. $event->contact_id = $obj->fk_contact;
  742. // Defined date_start_in_calendar and date_end_in_calendar property
  743. // They are date start and end of action but modified to not be outside calendar view.
  744. $event->date_start_in_calendar = $event->datep;
  745. if ($event->datef != '' && $event->datef >= $event->datep) {
  746. $event->date_end_in_calendar = $event->datef;
  747. } else {
  748. $event->date_end_in_calendar = $event->datep;
  749. }
  750. // Check values
  751. if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow) {
  752. // This record is out of visible range
  753. } else {
  754. if ($event->date_start_in_calendar < $firstdaytoshow) {
  755. $event->date_start_in_calendar = $firstdaytoshow;
  756. }
  757. if ($event->date_end_in_calendar >= $lastdaytoshow) {
  758. $event->date_end_in_calendar = ($lastdaytoshow - 1);
  759. }
  760. // Add an entry in actionarray for each day
  761. $daycursor = $event->date_start_in_calendar;
  762. $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
  763. $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
  764. $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
  765. $daycursorend = $event->date_end_in_calendar;
  766. $anneeend = dol_print_date($daycursorend, '%Y', 'tzuserrel');
  767. $moisend = dol_print_date($daycursorend, '%m', 'tzuserrel');
  768. $jourend = dol_print_date($daycursorend, '%d', 'tzuserrel');
  769. //var_dump(dol_print_date($event->date_start_in_calendar, 'dayhour', 'gmt')); // Hour at greenwich
  770. //var_dump($annee.'-'.$mois.'-'.$jour);
  771. //print 'annee='.$annee.' mois='.$mois.' jour='.$jour.'<br>';
  772. // Loop on each day covered by action to prepare an index to show on calendar
  773. $loop = true;
  774. $j = 0;
  775. $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt'); // $mois, $jour, $annee has been set for user tz
  776. $daykeyend = dol_mktime(0, 0, 0, $moisend, $jourend, $anneeend, 'gmt'); // $moisend, $jourend, $anneeend has been set for user tz
  777. /*
  778. print 'GMT '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'gmt').'<br>';
  779. print 'TZSERVER '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzserver').'<br>';
  780. print 'TZUSERREL '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel').'<br>';
  781. print 'GMT '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'gmt').'<br>';
  782. print 'TZSERVER '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzserver').'<br>';
  783. print 'TZUSER '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel').'<br>';
  784. */
  785. do {
  786. //if ($event->id==408)
  787. //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>';
  788. //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>';
  789. $eventarray[$daykey][] = $event;
  790. $j++;
  791. $daykey += 60 * 60 * 24;
  792. //if ($daykey > $event->date_end_in_calendar) {
  793. if ($daykey > $daykeyend) {
  794. $loop = false;
  795. }
  796. } while ($loop);
  797. //var_dump($eventarray);
  798. //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
  799. //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>';
  800. }
  801. $i++;
  802. }
  803. } else {
  804. dol_print_error($db);
  805. }
  806. // LEAVE CALENDAR
  807. $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";
  808. $sql .= " FROM " . MAIN_DB_PREFIX . "holiday as x, " . MAIN_DB_PREFIX . "user as u";
  809. $sql .= " WHERE u.rowid = x.fk_user";
  810. $sql .= " AND u.statut = '1'"; // Show only active users (0 = inactive user, 1 = active user)
  811. $sql .= " AND (x.statut = '2' OR x.statut = '3')"; // Show only public leaves (2 = leave wait for approval, 3 = leave approved)
  812. if ($mode == 'show_day') {
  813. // Request only leaves for the current selected day
  814. $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
  815. } elseif ($mode == 'show_week') {
  816. // TODO: Add filter to reduce database request
  817. } elseif ($mode == 'show_month') {
  818. // TODO: Add filter to reduce database request
  819. }
  820. $resql = $db->query($sql);
  821. if ($resql) {
  822. $num = $db->num_rows($resql);
  823. $i = 0;
  824. while ($i < $num) {
  825. $obj = $db->fetch_object($resql);
  826. $event = new ActionComm($db);
  827. // Need the id of the leave object for link to it
  828. $event->id = $obj->rowid;
  829. $event->ref = $event->id;
  830. $event->type_code = 'HOLIDAY';
  831. $event->type_label = '';
  832. $event->type_color = '';
  833. $event->type = 'holiday';
  834. $event->type_picto = 'holiday';
  835. $event->datep = $db->jdate($obj->date_start) + (empty($halfday) || $halfday == 1 ? 0 : 12 * 60 * 60 - 1);
  836. $event->datef = $db->jdate($obj->date_end) + (empty($halfday) || $halfday == -1 ? 24 : 12) * 60 * 60 - 1;
  837. $event->date_start_in_calendar = $event->datep;
  838. $event->date_end_in_calendar = $event->datef;
  839. if ($obj->status == 3) {
  840. // Show no symbol for leave with state "leave approved"
  841. $event->percentage = -1;
  842. } elseif ($obj->status == 2) {
  843. // Show TO-DO symbol for leave with state "leave wait for approval"
  844. $event->percentage = 0;
  845. }
  846. if ($obj->halfday == 1) {
  847. $event->label = $obj->lastname . ' (' . $langs->trans("Morning") . ')';
  848. } elseif ($obj->halfday == -1) {
  849. $event->label = $obj->lastname . ' (' . $langs->trans("Afternoon") . ')';
  850. } else {
  851. $event->label = $obj->lastname;
  852. }
  853. $daycursor = $event->date_start_in_calendar;
  854. $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
  855. $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
  856. $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
  857. $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
  858. do {
  859. $eventarray[$daykey][] = $event;
  860. $daykey += 60 * 60 * 24;
  861. } while ($daykey <= $event->date_end_in_calendar);
  862. $i++;
  863. }
  864. }
  865. // EXTERNAL CALENDAR
  866. // Complete $eventarray with external import Ical
  867. // Complete $eventarray with events coming from external module
  868. $parameters = array();
  869. $object = null;
  870. $reshook = $hookmanager->executeHooks('getCalendarEvents', $parameters, $object, $action);
  871. if (!empty($hookmanager->resArray['eventarray'])) {
  872. foreach ($hookmanager->resArray['eventarray'] as $keyDate => $events) {
  873. if (!isset($eventarray[$keyDate])) {
  874. $eventarray[$keyDate] = array();
  875. }
  876. $eventarray[$keyDate] = array_merge($eventarray[$keyDate], $events);
  877. }
  878. }
  879. // Sort events
  880. foreach ($eventarray as $keyDate => &$dateeventarray) {
  881. usort($dateeventarray, 'sort_events_by_date');
  882. }
  883. $maxnbofchar = 0;
  884. $cachethirdparties = array();
  885. $cachecontacts = array();
  886. $cacheusers = array();
  887. // Define theme_datacolor array
  888. $color_file = DOL_DOCUMENT_ROOT . "/theme/" . $conf->theme . "/theme_vars.inc.php";
  889. if (is_readable($color_file)) {
  890. include $color_file;
  891. }
  892. if (!is_array($theme_datacolor)) {
  893. $theme_datacolor = array(array(120, 130, 150), array(200, 160, 180), array(190, 190, 220));
  894. }
  895. $massactionbutton = '';
  896. 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);
  897. // Show div with list of calendars
  898. print $s;
  899. // View by day
  900. $newparam = $param; // newparam is for birthday links
  901. $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
  902. $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
  903. $newparam = preg_replace('/viewday=[0-9]+&?/i', '', $newparam);
  904. $newparam .= '&viewday=1';
  905. // Code to show just one day
  906. $style = 'cal_current_month cal_current_month_oneday';
  907. $today = 0;
  908. $todayarray = dol_getdate($now, 'fast');
  909. if ($todayarray['mday'] == $day && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
  910. $today = 1;
  911. }
  912. //if ($today) $style='cal_today';
  913. $timestamp = dol_mktime(12, 0, 0, $month, $day, $year);
  914. $arraytimestamp = dol_getdate($timestamp);
  915. /* print '<div class="liste_titre liste_titre_bydiv centpercent"><div class="divsearchfield">';
  916. print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
  917. print '</div></div>'; */
  918. print '<div class="div-table-responsive-no-min sectioncalendarbyday maxscreenheightless300">';
  919. echo '<table class="tagtable centpercent noborder nocellnopadd cal_pannel cal_month noborderbottom" style="margin-bottom: 5px !important;">';
  920. echo ' <tr class="tagtr liste_titre">';
  921. echo ' <td class="tagtd center bold uppercase">' . $langs->trans("Day" . $arraytimestamp['wday']) . "</td>\n";
  922. echo " </td>\n";
  923. echo '</table>';
  924. print '</div>';
  925. $eventdayDates = $bookingAgendaHelper->getEventDayDates($year, $month, $day);
  926. print '<div id="dateview">Updated content: ' . date("Y-m-d H:i:s") . '</div>';
  927. print $eventdayDates['eventdayprint'];
  928. print '<input type="hidden" id="jsyear" name="jsyear" value="' . $year . '">
  929. <input type="hidden" id="jsmonth" name="jsmonth" value="' . $month . '">
  930. <input type="hidden" id="jsday" name="jsday" value="' . $day . '">
  931. <input type="hidden" id="selectedEvent" name="selectedEvent" value="">';
  932. 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
  933. $bookingAgendaHelper->showTable($eventdayDates, $selectedEvent);
  934. print '</div>';
  935. print '<div id="eventdetailviewdiv"></div>';
  936. print "\n" . '</form>';
  937. ?>
  938. <script>
  939. $(document).ready(function() {
  940. console.log("ready!");
  941. const selectedEvent = document.getElementById('selectedEvent');
  942. const value = selectedEvent.value;
  943. console.log(value);
  944. });
  945. function ShoMeTheEventDeatils(id) {
  946. const eventdetailviewdiv = document.getElementById('eventdetailviewdiv');
  947. $('#selectedEvent').attr('value', id);
  948. const xhr = new XMLHttpRequest();
  949. xhr.open('GET', 'booking_agenda_event_details_view.php?event=' + id, true);
  950. xhr.onload = function() {
  951. if (xhr.status === 200) {
  952. eventdetailviewdiv.innerHTML = xhr.responseText;
  953. } else {
  954. console.error('Error fetching content:', xhr.status, xhr.statusText);
  955. }
  956. };
  957. xhr.send();
  958. }
  959. function formatDate(date) {
  960. const year = date.getFullYear();
  961. const month = String(date.getMonth() + 1).padStart(2, '0'); // Hónap 0-alapú, ezért +1
  962. const day = String(date.getDate()).padStart(2, '0');
  963. const hours = String(date.getHours()).padStart(2, '0');
  964. const minutes = String(date.getMinutes()).padStart(2, '0');
  965. const seconds = String(date.getSeconds()).padStart(2, '0');
  966. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  967. }
  968. function updateDivContent() {
  969. const selectedEvent = document.getElementById('selectedEvent');
  970. const value = selectedEvent.value;
  971. const dateview = document.getElementById('dateview');
  972. const dayviewdiv = document.getElementById('dayviewdiv');
  973. var year = document.getElementById('jsyear');
  974. var month = document.getElementById('jsmonth');
  975. var day = document.getElementById('jsday');
  976. const now = new Date();
  977. document.getElementById('dateview').innerText = 'Updated content: ' + formatDate(now);
  978. const xhr = new XMLHttpRequest();
  979. xhr.open('GET', 'booking_agenda_table_view.php?year=' + year.value + '&month=' + month.value + '&day=' + day.value, true);
  980. xhr.onload = function() {
  981. if (xhr.status === 200) {
  982. dayviewdiv.innerHTML = xhr.responseText;
  983. } else {
  984. console.error('Error fetching content:', xhr.status, xhr.statusText);
  985. }
  986. };
  987. xhr.send();
  988. if (value != '') {
  989. console.log(value);
  990. ShoMeTheEventDeatils(value);
  991. }
  992. }
  993. setInterval(updateDivContent, 5000);
  994. </script>
  995. <style>
  996. .trheight {
  997. height: 50px;
  998. }
  999. .elvalaszto {
  1000. background-color: grey;
  1001. }
  1002. .foglaltsag {
  1003. color: red;
  1004. }
  1005. .location {
  1006. color: black;
  1007. }
  1008. .firstcolumn {
  1009. background-color: lightgrey;
  1010. text-align: center;
  1011. font-weight: bold;
  1012. }
  1013. </style>
  1014. <?
  1015. // End of page
  1016. llxFooter();
  1017. $db->close();
  1018. /**
  1019. * Show event of a particular day
  1020. *
  1021. * @param DoliDB $db Database handler
  1022. * @param int $day Day
  1023. * @param int $month Month
  1024. * @param int $year Year
  1025. * @param int $monthshown Current month shown in calendar view
  1026. * @param string $style Style to use for this day
  1027. * @param array $eventarray Array of events
  1028. * @param int $maxprint Nb of actions to show each day on month view (0 means no limit)
  1029. * @param int $maxnbofchar Nb of characters to show for event line
  1030. * @param string $newparam Parameters on current URL
  1031. * @param int $showinfo Add extended information (used by day and week view)
  1032. * @param int $minheight Minimum height for each event. 60px by default.
  1033. * @param string $nonew 0=Add "new entry button", 1=No "new entry button", -1=Only "new entry button"
  1034. * @return void
  1035. */
  1036. function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint = 0, $maxnbofchar = 16, $newparam = '', $showinfo = 0, $minheight = 60, $nonew = 0)
  1037. {
  1038. global $user, $conf, $langs;
  1039. global $action, $mode, $filter, $filtert, $status, $actioncode, $usergroup; // Filters used into search form
  1040. global $theme_datacolor;
  1041. global $cachethirdparties, $cachecontacts, $cacheusers, $colorindexused;
  1042. if ($conf->use_javascript_ajax) { // Enable the "Show more button..."
  1043. $conf->global->MAIN_JS_SWITCH_AGENDA = 1;
  1044. }
  1045. $dateint = sprintf("%04d", $year) . sprintf("%02d", $month) . sprintf("%02d", $day);
  1046. //print 'show_day_events day='.$day.' month='.$month.' year='.$year.' dateint='.$dateint;
  1047. print "\n";
  1048. $curtime = dol_mktime(0, 0, 0, $month, $day, $year);
  1049. $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;
  1050. $urltocreate = '';
  1051. if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
  1052. $newparam .= '&month=' . str_pad($month, 2, "0", STR_PAD_LEFT) . '&year=' . $year;
  1053. $hourminsec = '100000';
  1054. $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 : ''));
  1055. }
  1056. // Line with title of day
  1057. print '<div id="dayevent_' . $dateint . '" class="dayevent tagtable centpercent nobordernopadding">' . "\n";
  1058. if ($nonew <= 0) {
  1059. print '<div class="tagtr cursorpointer" onclick="window.location=\'' . $urltocreate . '\';"><div class="nowrap tagtd"><div class="left inline-block">';
  1060. print '<a class="dayevent-aday" style="color: #666" href="' . $urltoshow . '">';
  1061. if ($showinfo) {
  1062. print dol_print_date($curtime, 'daytextshort');
  1063. } else {
  1064. print dol_print_date($curtime, '%d');
  1065. }
  1066. print '</a>';
  1067. print '</div><div class="nowrap floatright inline-block marginrightonly">';
  1068. if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
  1069. print '<a class="cursoradd" href="' . $urltocreate . '">'; // Explicit link, usefull for nojs interfaces
  1070. print img_picto($langs->trans("NewAction"), 'edit_add.png');
  1071. print '</a>';
  1072. }
  1073. print '</div></div></div>' . "\n";
  1074. }
  1075. if ($nonew < 0) {
  1076. print '</div>';
  1077. return;
  1078. }
  1079. // Line with td contains all div of each events
  1080. print '<div class="tagtr">';
  1081. print '<div class="tagtd centpercent agendacell sortable">';
  1082. //$curtime = dol_mktime (0, 0, 0, $month, $day, $year);
  1083. $i = 0;
  1084. $ireallyshown = 0;
  1085. $itoshow = 0;
  1086. $numother = 0;
  1087. $numbirthday = 0;
  1088. $numical = 0;
  1089. $numicals = array();
  1090. $ymd = sprintf("%04d", $year) . sprintf("%02d", $month) . sprintf("%02d", $day);
  1091. $colorindexused[$user->id] = 0; // Color index for current user (user->id) is always 0
  1092. $nextindextouse = is_array($colorindexused) ? count($colorindexused) : 0; // At first run this is 0, so fist user has 0, next 1, ...
  1093. //var_dump($colorindexused);
  1094. include_once DOL_DOCUMENT_ROOT . '/holiday/class/holiday.class.php';
  1095. $tmpholiday = new Holiday($db);
  1096. foreach ($eventarray as $daykey => $notused) { // daykey is the 'YYYYMMDD' to show according to user
  1097. $annee = dol_print_date($daykey, '%Y', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
  1098. $mois = dol_print_date($daykey, '%m', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
  1099. $jour = dol_print_date($daykey, '%d', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
  1100. //print 'event daykey='.$daykey.' dol_print_date(daykey)='.dol_print_date($daykey, 'dayhour', 'gmt').' jour='.$jour.' mois='.$mois.' annee='.$annee."<br>\n";
  1101. if ($day == $jour && $month == $mois && $year == $annee) {
  1102. foreach ($eventarray[$daykey] as $index => $event) {
  1103. if ($i < $maxprint || $maxprint == 0 || !empty($conf->global->MAIN_JS_SWITCH_AGENDA)) {
  1104. $keysofuserassigned = array_keys($event->userassigned);
  1105. $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
  1106. // Define $color (Hex string like '0088FF') and $cssclass of event
  1107. $color = -1;
  1108. $cssclass = '';
  1109. $colorindex = -1;
  1110. if (in_array($user->id, $keysofuserassigned)) {
  1111. $cssclass = 'family_mytasks';
  1112. if (empty($cacheusers[$event->userownerid])) {
  1113. $newuser = new User($db);
  1114. $newuser->fetch($event->userownerid);
  1115. $cacheusers[$event->userownerid] = $newuser;
  1116. }
  1117. //var_dump($cacheusers[$event->userownerid]->color);
  1118. // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
  1119. if (!empty($cacheusers[$event->userownerid]->color)) {
  1120. $color = $cacheusers[$event->userownerid]->color;
  1121. }
  1122. } elseif ($event->type_code == 'ICALEVENT') { // Event come from external ical file
  1123. $numical++;
  1124. if (!empty($event->icalname)) {
  1125. if (!isset($numicals[dol_string_nospecial($event->icalname)])) {
  1126. $numicals[dol_string_nospecial($event->icalname)] = 0;
  1127. }
  1128. $numicals[dol_string_nospecial($event->icalname)]++;
  1129. }
  1130. $color = ($event->icalcolor ? $event->icalcolor : -1);
  1131. $cssclass = (!empty($event->icalname) ? 'family_ext' . md5($event->icalname) : 'family_other');
  1132. } elseif ($event->type_code == 'BIRTHDAY') {
  1133. $numbirthday++;
  1134. $colorindex = 2;
  1135. $cssclass = 'family_birthday ';
  1136. $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
  1137. } else {
  1138. $numother++;
  1139. $color = ($event->icalcolor ? $event->icalcolor : -1);
  1140. $cssclass = (!empty($event->icalname) ? 'family_ext' . md5($event->icalname) : 'family_other');
  1141. if (empty($cacheusers[$event->userownerid])) {
  1142. $newuser = new User($db);
  1143. $newuser->fetch($event->userownerid);
  1144. $cacheusers[$event->userownerid] = $newuser;
  1145. }
  1146. //var_dump($cacheusers[$event->userownerid]->color);
  1147. // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
  1148. if (!empty($cacheusers[$event->userownerid]->color)) {
  1149. $color = $cacheusers[$event->userownerid]->color;
  1150. }
  1151. }
  1152. if ($color < 0) { // Color was not set on user card. Set color according to color index.
  1153. // Define color index if not yet defined
  1154. $idusertouse = ($event->userownerid ? $event->userownerid : 0);
  1155. if (isset($colorindexused[$idusertouse])) {
  1156. $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user
  1157. } else {
  1158. $colorindex = $nextindextouse;
  1159. $colorindexused[$idusertouse] = $colorindex;
  1160. if (!empty($theme_datacolor[$nextindextouse + 1])) {
  1161. $nextindextouse++; // Prepare to use next color
  1162. }
  1163. }
  1164. //print '|'.($color).'='.($idusertouse?$idusertouse:0).'='.$colorindex.'<br>';
  1165. // Define color
  1166. $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
  1167. }
  1168. $cssclass = $cssclass . ' eventday_' . $ymd;
  1169. // Defined style to disable drag and drop feature
  1170. if ($event->type_code == 'AC_OTH_AUTO') {
  1171. $cssclass .= " unmovable";
  1172. } elseif ($event->type_code == 'HOLIDAY') {
  1173. $cssclass .= " unmovable";
  1174. } elseif ($event->type_code == 'BIRTHDAY') {
  1175. $cssclass .= " unmovable";
  1176. } elseif ($event->type_code == 'ICALEVENT') {
  1177. $cssclass .= " unmovable";
  1178. } 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)) {
  1179. // If the event is on several days
  1180. $tmpyearend = dol_print_date($event->date_start_in_calendar, '%Y', 'tzuserrel');
  1181. $tmpmonthend = dol_print_date($event->date_start_in_calendar, '%m', 'tzuserrel');
  1182. $tmpdayend = dol_print_date($event->date_start_in_calendar, '%d', 'tzuserrel');
  1183. //var_dump($tmpyearend.' '.$tmpmonthend.' '.$tmpdayend);
  1184. if ($tmpyearend != $annee || $tmpmonthend != $mois || $tmpdayend != $jour) {
  1185. $cssclass .= " unmovable unmovable-mustusefirstdaytodrag";
  1186. } else {
  1187. $cssclass .= ' movable cursormove';
  1188. }
  1189. } else {
  1190. if (
  1191. $user->rights->agenda->allactions->create ||
  1192. (($event->authorid == $user->id || $event->userownerid == $user->id) && $user->rights->agenda->myactions->create)
  1193. ) {
  1194. $cssclass .= " movable cursormove";
  1195. } else {
  1196. $cssclass .= " unmovable";
  1197. }
  1198. }
  1199. $h = '';
  1200. $nowrapontd = 1;
  1201. if ($mode == 'show_day') {
  1202. $h = 'height: 100%; ';
  1203. $nowrapontd = 0;
  1204. }
  1205. if ($mode == 'show_week') {
  1206. $h = 'height: 100%; ';
  1207. $nowrapontd = 0;
  1208. }
  1209. // Show event box
  1210. print "\n";
  1211. print '<!-- start event ' . $i . ' -->' . "\n";
  1212. $morecss = '';
  1213. if ($maxprint && $ireallyshown >= $maxprint) {
  1214. $morecss = 'showifmore';
  1215. }
  1216. if ($event->type == 'birthdate' && !GETPOST('check_birthday')) {
  1217. $morecss = 'hidden';
  1218. }
  1219. if ($event->type == 'holiday' && !GETPOST('check_holiday')) {
  1220. $morecss = 'hidden';
  1221. }
  1222. if ($morecss != 'hidden') {
  1223. $itoshow++;
  1224. }
  1225. if ($morecss != 'showifmore' && $morecss != 'hidden') {
  1226. $ireallyshown++;
  1227. }
  1228. //var_dump($event->type.' - '.$morecss.' - '.$cssclass.' - '.$i.' - '.$ireallyshown.' - '.$itoshow);
  1229. print '<div id="event_' . $ymd . '_' . $i . '" class="event family_' . $event->type . ' ' . $cssclass . ($morecss ? ' ' . $morecss : '') . '"';
  1230. //print ' style="height: 100px;';
  1231. //print ' position: absolute; top: 40px; width: 50%;';
  1232. //print '"';
  1233. print '>';
  1234. //var_dump($event->userassigned);
  1235. //var_dump($event->transparency);
  1236. print '<table class="centpercent cal_event';
  1237. print(empty($event->transparency) ? ' cal_event_notbusy' : ' cal_event_busy');
  1238. //if (empty($event->transparency) && empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) print ' opacitymedium'; // Not busy
  1239. print '" style="' . $h;
  1240. $colortouse = $color;
  1241. // If colortouse is similar than background, we force to change it.
  1242. if (empty($event->transparency) && empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
  1243. print 'background: #f0f0f0;';
  1244. print 'border-left: 5px solid #' . $colortouse . ';';
  1245. } else {
  1246. print 'background: #f0f0f0;';
  1247. print 'border-left: 5px solid #' . dol_color_minus($colortouse, -3) . ';';
  1248. //print 'background: -webkit-gradient(linear, left top, left bottom, from(#'.dol_color_minus($colortouse, -3).'), to(#'.dol_color_minus($colortouse, -1).'));';
  1249. }
  1250. //print 'background: #'.$colortouse.';';
  1251. //print 'background: -webkit-gradient(linear, left top, left bottom, from(#'.dol_color_minus($color, -3).'), to(#'.dol_color_minus($color, -1).'));';
  1252. //if (!empty($event->transparency)) print 'background: #'.$color.'; background: -webkit-gradient(linear, left top, left bottom, from(#'.$color.'), to(#'.dol_color_minus($color,1).'));';
  1253. //else print 'background-color: transparent !important; background: none; border: 1px solid #bbb;';
  1254. //print ' -moz-border-radius:4px;"';
  1255. //print 'border: 1px solid #ccc" width="100%"';
  1256. print '">';
  1257. print '<tr>';
  1258. print '<td class="tdoverflow nobottom centpercent ' . ($nowrapontd ? 'nowrap ' : '') . 'cal_event' . ($event->type_code == 'BIRTHDAY' ? ' cal_event_birthday' : '') . '">';
  1259. $daterange = '';
  1260. if ($event->type_code == 'BIRTHDAY') { // It's birthday calendar
  1261. print $event->getNomUrl(1, $maxnbofchar, 'cal_event', 'birthday', 'contact');
  1262. } elseif ($event->type_code == 'HOLIDAY') { // It's holiday calendar
  1263. $tmpholiday->fetch($event->id);
  1264. print $tmpholiday->getNomUrl(1);
  1265. $tmpid = $tmpholiday->fk_user;
  1266. if (empty($cacheusers[$tmpid])) {
  1267. $newuser = new User($db);
  1268. $newuser->fetch($tmpid);
  1269. $cacheusers[$tmpid] = $newuser;
  1270. }
  1271. $listofusertoshow = '';
  1272. $listofusertoshow .= '<br>' . $cacheusers[$tmpid]->getNomUrl(-1, '', 0, 0, 0, 0, '', 'paddingright valigntextbottom');
  1273. print $listofusertoshow;
  1274. } else { // Other calendar
  1275. // Picto
  1276. if (empty($event->fulldayevent)) {
  1277. //print $event->getNomUrl(2).' ';
  1278. }
  1279. // Date
  1280. if (empty($event->fulldayevent)) {
  1281. // Show hours (start ... end)
  1282. $tmpyearstart = dol_print_date($event->date_start_in_calendar, '%Y', 'tzuserrel');
  1283. $tmpmonthstart = dol_print_date($event->date_start_in_calendar, '%m', 'tzuserrel');
  1284. $tmpdaystart = dol_print_date($event->date_start_in_calendar, '%d', 'tzuserrel');
  1285. $tmpyearend = dol_print_date($event->date_end_in_calendar, '%Y', 'tzuserrel');
  1286. $tmpmonthend = dol_print_date($event->date_end_in_calendar, '%m', 'tzuserrel');
  1287. $tmpdayend = dol_print_date($event->date_end_in_calendar, '%d', 'tzuserrel');
  1288. // Hour start
  1289. if ($tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour) {
  1290. $daterange .= dol_print_date($event->date_start_in_calendar, 'hour', 'tzuserrel');
  1291. if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
  1292. if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend) {
  1293. $daterange .= '-';
  1294. }
  1295. //else
  1296. //print '...';
  1297. }
  1298. }
  1299. if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
  1300. if ($tmpyearstart != $tmpyearend || $tmpmonthstart != $tmpmonthend || $tmpdaystart != $tmpdayend) {
  1301. $daterange .= '...';
  1302. }
  1303. }
  1304. // Hour end
  1305. if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
  1306. if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour) {
  1307. $daterange .= dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
  1308. }
  1309. }
  1310. } else {
  1311. if ($showinfo) {
  1312. print $langs->trans("EventOnFullDay") . "<br>\n";
  1313. }
  1314. }
  1315. // Show title
  1316. $titletoshow = $daterange;
  1317. //$titletoshow .= ($titletoshow ? ' ' : '').dol_escape_htmltag($event->label ? $event->label : $event->libelle);
  1318. if ($event->type_code != 'ICALEVENT') {
  1319. $savlabel = $event->label ? $event->label : $event->libelle;
  1320. $event->label = $titletoshow;
  1321. $event->libelle = $titletoshow; // deprecatd
  1322. // Note: List of users are inside $event->userassigned. Link may be clickable depending on permissions of user.
  1323. //$titletoshow = (($event->type_picto || $event->type_code) ? $event->getTypePicto() : '');
  1324. $titletoshow .= $event->getNomUrl(0, $maxnbofchar, 'cal_event cal_event_title', '', 0, 0);
  1325. $event->label = $savlabel;
  1326. $event->libelle = $savlabel;
  1327. }
  1328. // Loop on each assigned user
  1329. $listofusertoshow = '';
  1330. $posuserassigned = 0;
  1331. foreach ($event->userassigned as $tmpid => $tmpdata) {
  1332. if (!$posuserassigned && $titletoshow) {
  1333. $listofusertoshow .= '<br>';
  1334. }
  1335. $posuserassigned++;
  1336. if (empty($cacheusers[$tmpid])) {
  1337. $newuser = new User($db);
  1338. $newuser->fetch($tmpid);
  1339. $cacheusers[$tmpid] = $newuser;
  1340. }
  1341. $listofusertoshow .= $cacheusers[$tmpid]->getNomUrl(-3, '', 0, 0, 0, 0, '', 'paddingright valigntextbottom');
  1342. }
  1343. print $titletoshow;
  1344. print $listofusertoshow;
  1345. if ($event->type_code == 'ICALEVENT') {
  1346. print '<br>(' . dol_trunc($event->icalname, $maxnbofchar) . ')';
  1347. }
  1348. $thirdparty_id = ($event->socid > 0 ? $event->socid : ((is_object($event->societe) && $event->societe->id > 0) ? $event->societe->id : 0));
  1349. $contact_id = ($event->contact_id > 0 ? $event->contact_id : ((is_object($event->contact) && $event->contact->id > 0) ? $event->contact->id : 0));
  1350. // If action related to company / contact
  1351. $linerelatedto = '';
  1352. if ($thirdparty_id > 0) {
  1353. if (!isset($cachethirdparties[$thirdparty_id]) || !is_object($cachethirdparties[$thirdparty_id])) {
  1354. $thirdparty = new Societe($db);
  1355. $thirdparty->fetch($thirdparty_id);
  1356. $cachethirdparties[$thirdparty_id] = $thirdparty;
  1357. } else {
  1358. $thirdparty = $cachethirdparties[$thirdparty_id];
  1359. }
  1360. if (!empty($thirdparty->id)) {
  1361. $linerelatedto .= $thirdparty->getNomUrl(1, '', 0);
  1362. }
  1363. }
  1364. if (!empty($contact_id) && $contact_id > 0) {
  1365. if (!is_object($cachecontacts[$contact_id])) {
  1366. $contact = new Contact($db);
  1367. $contact->fetch($contact_id);
  1368. $cachecontacts[$contact_id] = $contact;
  1369. } else {
  1370. $contact = $cachecontacts[$contact_id];
  1371. }
  1372. if ($linerelatedto) {
  1373. $linerelatedto .= '&nbsp;';
  1374. }
  1375. if (!empty($contact->id)) {
  1376. $linerelatedto .= $contact->getNomUrl(1, '', 0);
  1377. }
  1378. }
  1379. if (!empty($event->fk_element) && $event->fk_element > 0 && !empty($event->elementtype) && !empty($conf->global->AGENDA_SHOW_LINKED_OBJECT)) {
  1380. include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
  1381. if ($linerelatedto) {
  1382. $linerelatedto .= '<br>';
  1383. }
  1384. $linerelatedto .= dolGetElementUrl($event->fk_element, $event->elementtype, 1);
  1385. }
  1386. if ($linerelatedto) {
  1387. print '<br>' . $linerelatedto;
  1388. }
  1389. }
  1390. // Show location
  1391. if ($showinfo) {
  1392. if ($event->location) {
  1393. print '<br>';
  1394. print $langs->trans("Location") . ': ' . $event->location;
  1395. }
  1396. }
  1397. print '</td>';
  1398. // Status - Percent
  1399. $withstatus = 0;
  1400. if ($event->type_code != 'BIRTHDAY' && $event->type_code != 'ICALEVENT') {
  1401. $withstatus = 1;
  1402. if ($event->percentage >= 0) {
  1403. $withstatus = 2;
  1404. }
  1405. }
  1406. print '<td class="nobottom right nowrap cal_event_right' . ($withstatus >= 2 ? ' cal_event_right_status' : '') . '">';
  1407. if ($withstatus) {
  1408. print $event->getLibStatut(3, 1);
  1409. } else {
  1410. print '&nbsp;';
  1411. }
  1412. print '</td></tr></table>';
  1413. print '</div><!-- end event ' . $i . ' -->' . "\n";
  1414. $i++;
  1415. } else {
  1416. print '<a href="' . DOL_URL_ROOT . '/custom/booking/booking_agenda.php?mode=' . $mode . '&maxprint=0&month=' . ((int) $monthshown) . '&year=' . ((int) $year);
  1417. print ($status ? '&status=' . $status : '') . ($filter ? '&filter=' . urlencode($filter) : '');
  1418. print($filtert ? '&search_filtert=' . urlencode($filtert) : '');
  1419. print($usergroup ? '&search_usergroup=' . urlencode($usergroup) : '');
  1420. print($actioncode != '' ? '&search_actioncode=' . urlencode($actioncode) : '');
  1421. print '">' . img_picto("all", "1downarrow_selected.png") . ' ...';
  1422. print ' +' . (count($eventarray[$daykey]) - $maxprint);
  1423. print '</a>';
  1424. break;
  1425. //$ok=false; // To avoid to show twice the link
  1426. }
  1427. }
  1428. break;
  1429. }
  1430. }
  1431. if (!$i) { // No events
  1432. print '&nbsp;';
  1433. }
  1434. if (!empty($conf->global->MAIN_JS_SWITCH_AGENDA) && $itoshow > $ireallyshown && $maxprint) {
  1435. print '<div class="center cursorpointer" id="more_' . $ymd . '">' . img_picto("All", "angle-double-down", 'class="warning"') . ' +' . ($itoshow - $ireallyshown) . '</div>';
  1436. //print ' +'.(count($eventarray[$daykey])-$maxprint);
  1437. print '<script type="text/javascript">' . "\n";
  1438. print 'jQuery(document).ready(function () {' . "\n";
  1439. print ' var open=0;' . "\n";
  1440. print ' jQuery("#more_' . $ymd . '").click(function() { console.log("Click on showmore for ' . $ymd . '"); reinit_day_' . $ymd . '(); event.stopImmediatePropagation(); });' . "\n";
  1441. print ' function reinit_day_' . $ymd . '() {' . "\n";
  1442. print ' jQuery(".eventday_' . $ymd . '.showifmore").toggle();' . "\n";
  1443. print ' open = open + 1; if (open > 1) { open = 0; }' . "\n";
  1444. print ' if (open) { ';
  1445. print ' jQuery("#more_' . $ymd . '").html(\'' . img_picto("All", "angle-double-up", 'class="warning"') . '\');' . "\n";
  1446. print ' } else { ';
  1447. print ' jQuery("#more_' . $ymd . '").html(\'' . img_picto("All", "angle-double-down", 'class="warning"') . ' +' . ($itoshow - $ireallyshown) . '\');' . "\n";
  1448. print ' }' . "\n";
  1449. print ' }' . "\n";
  1450. print '});' . "\n";
  1451. print '</script>' . "\n";
  1452. }
  1453. print '</div></div>'; // td tr
  1454. print '</div>'; // table
  1455. print "\n";
  1456. }
  1457. /**
  1458. * Change color with a delta
  1459. *
  1460. * @param string $color Color
  1461. * @param int $minus Delta (1 = 16 unit). Positive value = darker color, Negative value = brighter color.
  1462. * @param int $minusunit Minus unit
  1463. * @return string New color
  1464. */
  1465. function dol_color_minus($color, $minus, $minusunit = 16)
  1466. {
  1467. $newcolor = $color;
  1468. if ($minusunit == 16) {
  1469. $newcolor[0] = dechex(max(min(hexdec($newcolor[0]) - $minus, 15), 0));
  1470. $newcolor[2] = dechex(max(min(hexdec($newcolor[2]) - $minus, 15), 0));
  1471. $newcolor[4] = dechex(max(min(hexdec($newcolor[4]) - $minus, 15), 0));
  1472. } else {
  1473. // Not yet implemented
  1474. }
  1475. return $newcolor;
  1476. }
  1477. /**
  1478. * Sort events by date
  1479. *
  1480. * @param object $a Event A
  1481. * @param object $b Event B
  1482. * @return int < 0 if event A should be before event B, > 0 otherwise, 0 if they have the exact same time slot
  1483. */
  1484. function sort_events_by_date($a, $b)
  1485. {
  1486. // Sort holidays at first
  1487. if ($a->type_code === 'HOLIDAY') {
  1488. return -1;
  1489. }
  1490. if ($b->type_code === 'HOLIDAY') {
  1491. return 1;
  1492. }
  1493. // datep => Event start time
  1494. // datef => Event end time
  1495. // Events have different start time
  1496. if ($a->datep !== $b->datep) {
  1497. return $a->datep - $b->datep;
  1498. }
  1499. // Events have same start time and no end time
  1500. if ((!is_numeric($b->datef)) || (!is_numeric($a->datef))) {
  1501. return sort_events_by_percentage($a, $b);
  1502. }
  1503. // Events have the same start time and same end time
  1504. if ($b->datef === $a->datef) {
  1505. return sort_events_by_percentage($a, $b);
  1506. }
  1507. // Events have the same start time, but have different end time -> longest event first
  1508. return $b->datef - $a->datef;
  1509. }
  1510. /**
  1511. * Sort events by percentage
  1512. *
  1513. * @param object $a Event A
  1514. * @param object $b Event B
  1515. * @return int < 0 if event A should be before event B, > 0 otherwise, 0 if they have the exact same percentage
  1516. */
  1517. function sort_events_by_percentage($a, $b)
  1518. {
  1519. // Sort events with no percentage before each other
  1520. // (usefull to sort holidays, sick days or similar on the top)
  1521. if ($a->percentage < 0) {
  1522. return -1;
  1523. }
  1524. if ($b->percentage < 0) {
  1525. return 1;
  1526. }
  1527. return $b->percentage - $a->percentage;
  1528. }