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