peruser.php 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462
  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-2014 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) 2018-2019 Frédéric France <frederic.france@netlogic.fr>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/comm/action/peruser.php
  25. * \ingroup agenda
  26. * \brief Tab of calendar events per user
  27. */
  28. require '../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  37. if (!isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) {
  38. $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW = 3;
  39. }
  40. $action = GETPOST('action', 'aZ09');
  41. $filter = GETPOST("search_filter", 'alpha', 3) ? GETPOST("search_filter", 'alpha', 3) : GETPOST("filter", 'alpha', 3);
  42. $filtert = GETPOST("search_filtert", "int", 3) ? GETPOST("search_filtert", "int", 3) : GETPOST("filtert", "int", 3);
  43. $usergroup = GETPOST("search_usergroup", "int", 3) ? GETPOST("search_usergroup", "int", 3) : GETPOST("usergroup", "int", 3);
  44. //if (! ($usergroup > 0) && ! ($filtert > 0)) $filtert = $user->id;
  45. //$showbirthday = empty($conf->use_javascript_ajax)?GETPOST("showbirthday","int"):1;
  46. $showbirthday = 0;
  47. // If not choice done on calendar owner, we filter on user.
  48. /*if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS))
  49. {
  50. $filtert = $user->id;
  51. }*/
  52. $sortfield = GETPOST('sortfield', 'aZ09comma');
  53. $sortorder = GETPOST('sortorder', 'aZ09comma');
  54. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  55. if (empty($page) || $page == -1) {
  56. $page = 0;
  57. } // If $page is not defined, or '' or -1
  58. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  59. $offset = $limit * $page;
  60. if (!$sortorder) {
  61. $sortorder = "ASC";
  62. }
  63. if (!$sortfield) {
  64. $sortfield = "a.datec";
  65. }
  66. $socid = GETPOST("search_socid", "int") ?GETPOST("search_socid", "int") : GETPOST("socid", "int");
  67. if ($user->socid) {
  68. $socid = $user->socid;
  69. }
  70. if ($socid < 0) {
  71. $socid = '';
  72. }
  73. $canedit = 1;
  74. if (empty($user->rights->agenda->myactions->read)) {
  75. accessforbidden();
  76. }
  77. if (empty($user->rights->agenda->allactions->read)) {
  78. $canedit = 0;
  79. }
  80. if (empty($user->rights->agenda->allactions->read) || $filter == 'mine') { // If no permission to see all, we show only affected to me
  81. $filtert = $user->id;
  82. }
  83. $mode = 'show_peruser';
  84. $resourceid = GETPOST("search_resourceid", "int") ?GETPOST("search_resourceid", "int") : GETPOST("resourceid", "int");
  85. $year = GETPOST("year", "int") ?GETPOST("year", "int") : date("Y");
  86. $month = GETPOST("month", "int") ?GETPOST("month", "int") : date("m");
  87. $week = GETPOST("week", "int") ?GETPOST("week", "int") : date("W");
  88. $day = GETPOST("day", "int") ?GETPOST("day", "int") : date("d");
  89. $pid = GETPOSTISSET("search_projectid") ? GETPOST("search_projectid", "int", 3) : GETPOST("projectid", "int", 3);
  90. $status = GETPOSTISSET("search_status") ? GETPOST("search_status", 'alpha') : GETPOST("status", 'alpha');
  91. $type = GETPOSTISSET("search_type") ? GETPOST("search_type", 'alpha') : GETPOST("type", 'alpha');
  92. $maxprint = ((GETPOST("maxprint", 'int') != '') ?GETPOST("maxprint", 'int') : $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW);
  93. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  94. // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
  95. if (GETPOST('search_actioncode', 'array:aZ09')) {
  96. $actioncode = GETPOST('search_actioncode', 'array:aZ09', 3);
  97. if (!count($actioncode)) {
  98. $actioncode = '0';
  99. }
  100. } else {
  101. $actioncode = GETPOST("search_actioncode", "alpha", 3) ?GETPOST("search_actioncode", "alpha", 3) : (GETPOST("search_actioncode", "alpha") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE));
  102. }
  103. if ($actioncode == '' && empty($actioncodearray)) {
  104. $actioncode = (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE);
  105. }
  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. $tmp = empty($conf->global->MAIN_DEFAULT_WORKING_HOURS) ? '9-18' : $conf->global->MAIN_DEFAULT_WORKING_HOURS;
  113. $tmp = str_replace(' ', '', $tmp); // FIX 7533
  114. $tmparray = explode('-', $tmp);
  115. $begin_h = GETPOST('begin_h', 'int') != '' ? GETPOST('begin_h', 'int') : ($tmparray[0] != '' ? $tmparray[0] : 9);
  116. $end_h = GETPOST('end_h', 'int') ? GETPOST('end_h', 'int') : ($tmparray[1] != '' ? $tmparray[1] : 18);
  117. if ($begin_h < 0 || $begin_h > 23) {
  118. $begin_h = 9;
  119. }
  120. if ($end_h < 1 || $end_h > 24) {
  121. $end_h = 18;
  122. }
  123. if ($end_h <= $begin_h) {
  124. $end_h = $begin_h + 1;
  125. }
  126. $tmp = empty($conf->global->MAIN_DEFAULT_WORKING_DAYS) ? '1-5' : $conf->global->MAIN_DEFAULT_WORKING_DAYS;
  127. $tmp = str_replace(' ', '', $tmp); // FIX 7533
  128. $tmparray = explode('-', $tmp);
  129. $begin_d = GETPOST('begin_d', 'int') ?GETPOST('begin_d', 'int') : ($tmparray[0] != '' ? $tmparray[0] : 1);
  130. $end_d = GETPOST('end_d', 'int') ?GETPOST('end_d', 'int') : ($tmparray[1] != '' ? $tmparray[1] : 5);
  131. if ($begin_d < 1 || $begin_d > 7) {
  132. $begin_d = 1;
  133. }
  134. if ($end_d < 1 || $end_d > 7) {
  135. $end_d = 7;
  136. }
  137. if ($end_d < $begin_d) {
  138. $end_d = $begin_d + 1;
  139. }
  140. if ($status == '' && !GETPOSTISSET('search_status')) {
  141. $status = (empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS);
  142. }
  143. if (empty($mode) && !GETPOSTISSET('mode')) {
  144. $mode = (empty($conf->global->AGENDA_DEFAULT_VIEW) ? 'show_month' : $conf->global->AGENDA_DEFAULT_VIEW);
  145. }
  146. if (GETPOST('viewcal', 'alpha') && $mode != 'show_day' && $mode != 'show_week' && $mode != 'show_peruser') {
  147. $mode = 'show_month'; $day = '';
  148. } // View by month
  149. if (GETPOST('viewweek', 'alpha') || $mode == 'show_week') {
  150. $mode = 'show_week'; $week = ($week ? $week : date("W")); $day = ($day ? $day : date("d"));
  151. } // View by week
  152. if (GETPOST('viewday', 'alpha') || $mode == 'show_day') {
  153. $mode = 'show_day'; $day = ($day ? $day : date("d"));
  154. } // View by day
  155. $object = new ActionComm($db);
  156. // Load translation files required by the page
  157. $langs->loadLangs(array('users', 'agenda', 'other', 'commercial'));
  158. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  159. $hookmanager->initHooks(array('agenda'));
  160. $result = restrictedArea($user, 'agenda', 0, '', 'myactions');
  161. if ($user->socid && $socid) {
  162. $result = restrictedArea($user, 'societe', $socid);
  163. }
  164. $search_status = $status;
  165. /*
  166. * Actions
  167. */
  168. /*
  169. if ($action == 'delete_action' && $user->rights->agenda->delete) {
  170. $event = new ActionComm($db);
  171. $event->fetch($actionid);
  172. $event->fetch_optionals();
  173. $event->fetch_userassigned();
  174. $event->oldcopy = clone $event;
  175. $result = $event->delete();
  176. }
  177. */
  178. /*
  179. * View
  180. */
  181. $parameters = array(
  182. 'socid' => $socid,
  183. 'status' => $status,
  184. 'year' => $year,
  185. 'month' => $month,
  186. 'day' => $day,
  187. 'type' => $type,
  188. 'maxprint' => $maxprint,
  189. 'filter' => $filter,
  190. 'filtert' => $filtert,
  191. 'showbirthday' => $showbirthday,
  192. 'canedit' => $canedit,
  193. 'optioncss' => $optioncss,
  194. 'actioncode' => $actioncode,
  195. 'pid' => $pid,
  196. 'resourceid' => $resourceid,
  197. 'usergroup' => $usergroup,
  198. );
  199. $reshook = $hookmanager->executeHooks('beforeAgendaPerUser', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  200. if ($reshook < 0) {
  201. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  202. }
  203. $form = new Form($db);
  204. $companystatic = new Societe($db);
  205. $help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&oacute;dulo_Agenda';
  206. llxHeader('', $langs->trans("Agenda"), $help_url);
  207. $now = dol_now();
  208. $nowarray = dol_getdate($now);
  209. $nowyear = $nowarray['year'];
  210. $nowmonth = $nowarray['mon'];
  211. $nowday = $nowarray['mday'];
  212. // Define list of all external calendars (global setup)
  213. $listofextcals = array();
  214. $prev = dol_get_first_day_week($day, $month, $year);
  215. $first_day = $prev['first_day'];
  216. $first_month = $prev['first_month'];
  217. $first_year = $prev['first_year'];
  218. $week = $prev['week'];
  219. $day = (int) $day;
  220. $next = dol_get_next_week($day, $week, $month, $year);
  221. $next_year = $next['year'];
  222. $next_month = $next['month'];
  223. $next_day = $next['day'];
  224. $max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year));
  225. $tmpday = $first_day;
  226. //print 'xx'.$prev_year.'-'.$prev_month.'-'.$prev_day;
  227. //print 'xx'.$next_year.'-'.$next_month.'-'.$next_day;
  228. $title = $langs->trans("DoneAndToDoActions");
  229. if ($status == 'done') {
  230. $title = $langs->trans("DoneActions");
  231. }
  232. if ($status == 'todo') {
  233. $title = $langs->trans("ToDoActions");
  234. }
  235. $param = '';
  236. if ($actioncode || GETPOSTISSET('search_actioncode')) {
  237. if (is_array($actioncode)) {
  238. foreach ($actioncode as $str_action) {
  239. $param .= "&search_actioncode[]=".urlencode($str_action);
  240. }
  241. } else {
  242. $param .= "&search_actioncode=".urlencode($actioncode);
  243. }
  244. }
  245. if ($resourceid > 0) {
  246. $param .= "&search_resourceid=".urlencode($resourceid);
  247. }
  248. if ($status || GETPOSTISSET('status') || GETPOSTISSET('search_status')) {
  249. $param .= "&search_status=".urlencode($status);
  250. }
  251. if ($filter) {
  252. $param .= "&search_filter=".urlencode($filter);
  253. }
  254. if ($filtert) {
  255. $param .= "&search_filtert=".urlencode($filtert);
  256. }
  257. if ($usergroup > 0) {
  258. $param .= "&search_usergroup=".urlencode($usergroup);
  259. }
  260. if ($socid > 0) {
  261. $param .= "&search_socid=".urlencode($socid);
  262. }
  263. if ($showbirthday) {
  264. $param .= "&search_showbirthday=1";
  265. }
  266. if ($pid) {
  267. $param .= "&search_projectid=".urlencode($pid);
  268. }
  269. if ($type) {
  270. $param .= "&search_type=".urlencode($type);
  271. }
  272. if ($mode != 'show_peruser') {
  273. $param .= '&mode='.urlencode($mode);
  274. }
  275. if ($begin_h != '') {
  276. $param .= '&begin_h='.urlencode($begin_h);
  277. }
  278. if ($end_h != '') {
  279. $param .= '&end_h='.urlencode($end_h);
  280. }
  281. if ($begin_d != '') {
  282. $param .= '&begin_d='.urlencode($begin_d);
  283. }
  284. if ($end_d != '') {
  285. $param .= '&end_d='.urlencode($end_d);
  286. }
  287. $param .= "&maxprint=".urlencode($maxprint);
  288. $paramnoactionodate = $param;
  289. $prev = dol_get_first_day_week($day, $month, $year);
  290. //print "day=".$day." month=".$month." year=".$year;
  291. //var_dump($prev); exit;
  292. $prev_year = $prev['prev_year'];
  293. $prev_month = $prev['prev_month'];
  294. $prev_day = $prev['prev_day'];
  295. $first_day = $prev['first_day'];
  296. $first_month = $prev['first_month'];
  297. $first_year = $prev['first_year'];
  298. $week = $prev['week'];
  299. $day = (int) $day;
  300. $next = dol_get_next_week($first_day, $week, $first_month, $first_year);
  301. $next_year = $next['year'];
  302. $next_month = $next['month'];
  303. $next_day = $next['day'];
  304. // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
  305. $firstdaytoshow = dol_mktime(0, 0, 0, $first_month, $first_day, $first_year, 'gmt');
  306. $nb_weeks_to_show = (!empty($conf->global->AGENDA_NB_WEEKS_IN_VIEW_PER_USER)) ? ((int) $conf->global->AGENDA_NB_WEEKS_IN_VIEW_PER_USER * 7) : 7;
  307. $lastdaytoshow = dol_time_plus_duree($firstdaytoshow, $nb_weeks_to_show, 'd');
  308. //print $firstday.'-'.$first_month.'-'.$first_year;
  309. //print dol_print_date($firstdaytoshow,'dayhour');
  310. //print dol_print_date($lastdaytoshow,'dayhour');
  311. $max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year, 'gmt'));
  312. $tmpday = $first_day;
  313. $picto = 'calendarweek';
  314. $nav = "<a href=\"?year=".$prev_year."&amp;month=".$prev_month."&amp;day=".$prev_day.$param."\"><i class=\"fa fa-chevron-left\" title=\"".dol_escape_htmltag($langs->trans("Previous"))."\"></i></a> &nbsp; \n";
  315. $nav .= " <span id=\"month_name\">".dol_print_date(dol_mktime(0, 0, 0, $first_month, $first_day, $first_year), "%Y").", ".$langs->trans("Week")." ".$week;
  316. $nav .= " </span>\n";
  317. $nav .= " &nbsp; <a href=\"?year=".$next_year."&amp;month=".$next_month."&amp;day=".$next_day.$param."\"><i class=\"fa fa-chevron-right\" title=\"".dol_escape_htmltag($langs->trans("Next"))."\"></i></a>\n";
  318. if (empty($conf->dol_optimize_smallscreen)) {
  319. $nav .= " &nbsp; <a href=\"?year=".$nowyear."&amp;month=".$nowmonth."&amp;day=".$nowday.$param."\">".$langs->trans("Today")."</a> ";
  320. }
  321. $nav .= $form->selectDate($dateselect, 'dateselect', 0, 0, 1, '', 1, 0);
  322. $nav .= ' <button type="submit" class="liste_titre button_search" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
  323. // Must be after the nav definition
  324. $param .= '&year='.urlencode($year).'&month='.urlencode($month).($day ? '&day='.urlencode($day) : '');
  325. //print 'x'.$param;
  326. $paramnoaction = preg_replace('/action=[a-z_]+/', '', $param);
  327. $head = calendars_prepare_head($paramnoaction);
  328. print '<form method="POST" id="searchFormList" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  329. $showextcals = $listofextcals;
  330. // Legend
  331. if ($conf->use_javascript_ajax) {
  332. $s = '';
  333. $s .= '<script type="text/javascript">'."\n";
  334. $s .= 'jQuery(document).ready(function () {'."\n";
  335. $s .= 'jQuery("#check_mytasks").click(function() { jQuery(".family_mytasks").toggle(); jQuery(".family_other").toggle(); });'."\n";
  336. $s .= 'jQuery("#check_birthday").click(function() { jQuery(".family_birthday").toggle(); });'."\n";
  337. $s .= 'jQuery(".family_birthday").toggle();'."\n";
  338. if ($mode == "show_week" || $mode == "show_month" || empty($mode)) {
  339. $s .= 'jQuery( "td.sortable" ).sortable({connectWith: ".sortable",placeholder: "ui-state-highlight",items: "div:not(.unsortable)", receive: function( event, ui ) {';
  340. }
  341. $s .= '});'."\n";
  342. $s .= '</script>'."\n";
  343. if (!empty($conf->use_javascript_ajax)) {
  344. $s .= '<div class="nowrap clear float"><input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> '.$langs->trans("LocalAgenda").' &nbsp; </div>';
  345. if (is_array($showextcals) && count($showextcals) > 0) {
  346. foreach ($showextcals as $val) {
  347. $htmlname = md5($val['name']);
  348. $s .= '<script type="text/javascript">'."\n";
  349. $s .= 'jQuery(document).ready(function () {'."\n";
  350. $s .= ' jQuery("#check_ext'.$htmlname.'").click(function() {';
  351. $s .= ' /* alert("'.$htmlname.'"); */';
  352. $s .= ' jQuery(".family_ext'.$htmlname.'").toggle();';
  353. $s .= ' });'."\n";
  354. $s .= '});'."\n";
  355. $s .= '</script>'."\n";
  356. $s .= '<div class="nowrap float"><input type="checkbox" id="check_ext'.$htmlname.'" name="check_ext'.$htmlname.'" checked> '.$val ['name'].' &nbsp; </div>';
  357. }
  358. }
  359. //$s.='<div class="nowrap float"><input type="checkbox" id="check_birthday" name="check_birthday"> '.$langs->trans("AgendaShowBirthdayEvents").' &nbsp; </div>';
  360. // Calendars from hooks
  361. $parameters = array();
  362. $reshook = $hookmanager->executeHooks('addCalendarChoice', $parameters, $object, $action);
  363. if (empty($reshook)) {
  364. $s .= $hookmanager->resPrint;
  365. } elseif ($reshook > 1) {
  366. $s = $hookmanager->resPrint;
  367. }
  368. }
  369. }
  370. $massactionbutton = '';
  371. $viewmode = '';
  372. $viewmode .= '<a class="btnTitle reposition" href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&restore_lastsearch_values=1'.$paramnoactionodate.'">';
  373. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  374. $viewmode .= img_picto($langs->trans("List"), 'object_list', 'class="imgforviewmode pictoactionview block"');
  375. //$viewmode .= '</span>';
  376. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewList").'</span></a>';
  377. $viewmode .= '<a class="btnTitle reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_month&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').$paramnoactionodate.'">';
  378. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  379. $viewmode .= img_picto($langs->trans("ViewCal"), 'object_calendarmonth', 'class="pictoactionview block"');
  380. //$viewmode .= '</span>';
  381. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewCal").'</span></a>';
  382. $viewmode .= '<a class="btnTitle reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_week&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').$paramnoactionodate.'">';
  383. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  384. $viewmode .= img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="pictoactionview block"');
  385. //$viewmode .= '</span>';
  386. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewWeek").'</span></a>';
  387. $viewmode .= '<a class="btnTitle reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_day&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').$paramnoactionodate.'">';
  388. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  389. $viewmode .= img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="pictoactionview block"');
  390. //$viewmode .= '</span>';
  391. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewDay").'</span></a>';
  392. $viewmode .= '<a class="btnTitle btnTitleSelected reposition marginrightonly" href="'.DOL_URL_ROOT.'/comm/action/peruser.php?mode=show_peruser&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').$paramnoactionodate.'">';
  393. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  394. $viewmode .= img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="pictoactionview block"');
  395. //$viewmode .= '</span>';
  396. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewPerUser").'</span></a>';
  397. $viewmode .= '<span class="marginrightonly"></span>';
  398. // Add more views from hooks
  399. $parameters = array(); $object = null;
  400. $reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
  401. if (empty($reshook)) {
  402. $viewmode .= $hookmanager->resPrint;
  403. } elseif ($reshook > 1) {
  404. $viewmode = $hookmanager->resPrint;
  405. }
  406. $newparam = '';
  407. $newcardbutton = '';
  408. if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
  409. $tmpforcreatebutton = dol_getdate(dol_now(), true);
  410. $newparam .= '&month='.urlencode(str_pad($month, 2, "0", STR_PAD_LEFT)).'&year='.urlencode($tmpforcreatebutton['year']);
  411. if ($begin_h !== '') {
  412. $newparam .= '&begin_h='.urlencode($begin_h);
  413. }
  414. if ($end_h !== '') {
  415. $newparam .= '&end_h='.urlencode($end_h);
  416. }
  417. if ($begin_d !== '') {
  418. $newparam .= '&begin_d='.urlencode($begin_d);
  419. }
  420. if ($end_d !== '') {
  421. $newparam .= '&end_d='.urlencode($end_d);
  422. }
  423. //$param='month='.$monthshown.'&year='.$year;
  424. $hourminsec = '100000';
  425. $newcardbutton .= dolGetButtonTitle($langs->trans("AddAction"), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.sprintf("%04d%02d%02d", $tmpforcreatebutton['year'], $tmpforcreatebutton['mon'], $tmpforcreatebutton['mday']).$hourminsec.'&backtopage='.urlencode($_SERVER["PHP_SELF"].($newparam ? '?'.$newparam : '')));
  426. }
  427. $num = '';
  428. 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);
  429. $link = '';
  430. //print load_fiche_titre('', $link.' &nbsp; &nbsp; '.$nav.' '.$newcardbutton, '');
  431. // Local calendar
  432. $newtitle = '<div class="nowrap clear inline-block minheight30">';
  433. $newtitle .= '<input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> '.$langs->trans("LocalAgenda").' &nbsp; ';
  434. $newtitle .= '</div>';
  435. //$newtitle=$langs->trans($title);
  436. $s = $newtitle;
  437. print $s;
  438. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  439. print_actions_filter($form, $canedit, $search_status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
  440. print '</div>';
  441. // Get event in an array
  442. $eventarray = array();
  443. // DEFAULT CALENDAR + AUTOEVENT CALENDAR + CONFERENCEBOOTH CALENDAR
  444. $sql = 'SELECT';
  445. if ($usergroup > 0) {
  446. $sql .= " DISTINCT";
  447. }
  448. $sql .= ' a.id, a.label,';
  449. $sql .= ' a.datep,';
  450. $sql .= ' a.datep2,';
  451. $sql .= ' a.percent,';
  452. $sql .= ' a.fk_user_author,a.fk_user_action,';
  453. $sql .= ' a.transparency, a.priority, a.fulldayevent, a.location,';
  454. $sql .= ' a.fk_soc, a.fk_contact, a.fk_element, a.elementtype, a.fk_project,';
  455. $sql .= ' ca.code, ca.libelle as type_label, ca.color, ca.type as type_type, ca.picto as type_picto';
  456. $sql .= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm as ca, '.MAIN_DB_PREFIX."actioncomm as a";
  457. if (empty($user->rights->societe->client->voir) && !$socid) {
  458. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
  459. }
  460. // We must filter on resource table
  461. if ($resourceid > 0) {
  462. $sql .= ", ".MAIN_DB_PREFIX."element_resources as r";
  463. }
  464. // We must filter on assignement table
  465. if ($filtert > 0 || $usergroup > 0) {
  466. $sql .= ", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
  467. }
  468. if ($usergroup > 0) {
  469. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
  470. }
  471. $sql .= ' WHERE a.fk_action = ca.id';
  472. $sql .= ' AND a.entity IN ('.getEntity('agenda').')';
  473. // Condition on actioncode
  474. if (!empty($actioncode)) {
  475. if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
  476. if ($actioncode == 'AC_NON_AUTO') {
  477. $sql .= " AND ca.type != 'systemauto'";
  478. } elseif ($actioncode == 'AC_ALL_AUTO') {
  479. $sql .= " AND ca.type = 'systemauto'";
  480. } else {
  481. if ($actioncode == 'AC_OTH') {
  482. $sql .= " AND ca.type != 'systemauto'";
  483. }
  484. if ($actioncode == 'AC_OTH_AUTO') {
  485. $sql .= " AND ca.type = 'systemauto'";
  486. }
  487. }
  488. } else {
  489. if ($actioncode == 'AC_NON_AUTO') {
  490. $sql .= " AND ca.type != 'systemauto'";
  491. } elseif ($actioncode == 'AC_ALL_AUTO') {
  492. $sql .= " AND ca.type = 'systemauto'";
  493. } else {
  494. if (is_array($actioncode)) {
  495. $sql .= " AND ca.code IN (".$db->sanitize("'".implode("','", $actioncode)."'", 1).")";
  496. } else {
  497. $sql .= " AND ca.code IN (".$db->sanitize("'".implode("','", explode(',', $actioncode))."'", 1).")";
  498. }
  499. }
  500. }
  501. }
  502. if ($resourceid > 0) {
  503. $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".((int) $resourceid);
  504. }
  505. if ($pid) {
  506. $sql .= " AND a.fk_project = ".((int) $pid);
  507. }
  508. if (empty($user->rights->societe->client->voir) && !$socid) {
  509. $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).")";
  510. }
  511. if ($socid > 0) {
  512. $sql .= ' AND a.fk_soc = '.((int) $socid);
  513. }
  514. // We must filter on assignement table
  515. if ($filtert > 0 || $usergroup > 0) {
  516. $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
  517. }
  518. if ($mode == 'show_day') {
  519. $sql .= " AND (";
  520. $sql .= " (a.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
  521. $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
  522. $sql .= " OR ";
  523. $sql .= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
  524. $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
  525. $sql .= " OR ";
  526. $sql .= " (a.datep < '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
  527. $sql .= " AND a.datep2 > '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
  528. $sql .= ')';
  529. } else {
  530. // To limit array
  531. $sql .= " AND (";
  532. $sql .= " (a.datep BETWEEN '".$db->idate($firstdaytoshow - (60 * 60 * 24 * 2))."'"; // Start 2 day before $firstdaytoshow
  533. $sql .= " AND '".$db->idate($lastdaytoshow + (60 * 60 * 24 * 2))."')"; // End 2 day after $lastdaytoshow
  534. $sql .= " OR ";
  535. $sql .= " (a.datep2 BETWEEN '".$db->idate($firstdaytoshow - (60 * 60 * 24 * 2))."'";
  536. $sql .= " AND '".$db->idate($lastdaytoshow + (60 * 60 * 24 * 2))."')";
  537. $sql .= " OR ";
  538. $sql .= " (a.datep < '".$db->idate($firstdaytoshow - (60 * 60 * 24 * 2))."'";
  539. $sql .= " AND a.datep2 > '".$db->idate($lastdaytoshow + (60 * 60 * 24 * 2))."')";
  540. $sql .= ')';
  541. }
  542. if ($type) {
  543. $sql .= " AND ca.id = ".((int) $type);
  544. }
  545. if ($status == '0') {
  546. $sql .= " AND a.percent = 0";
  547. }
  548. if ($status == '-1') {
  549. $sql .= " AND a.percent = -1";
  550. } // Not applicable
  551. if ($status == '50') {
  552. $sql .= " AND (a.percent > 0 AND a.percent < 100)";
  553. } // Running already started
  554. if ($status == 'done' || $status == '100') {
  555. $sql .= " AND (a.percent = 100)";
  556. }
  557. if ($status == 'todo') {
  558. $sql .= " AND (a.percent >= 0 AND a.percent < 100)";
  559. }
  560. // We must filter on assignement table
  561. if ($filtert > 0 || $usergroup > 0) {
  562. $sql .= " AND (";
  563. if ($filtert > 0) {
  564. $sql .= "ar.fk_element = ".$filtert;
  565. }
  566. if ($usergroup > 0) {
  567. $sql .= ($filtert > 0 ? " OR " : "")." ugu.fk_usergroup = ".((int) $usergroup);
  568. }
  569. $sql .= ")";
  570. }
  571. // Sort on date
  572. $sql .= ' ORDER BY fk_user_action, datep'; //fk_user_action
  573. dol_syslog("comm/action/peruser.php", LOG_DEBUG);
  574. $resql = $db->query($sql);
  575. if ($resql) {
  576. $num = $db->num_rows($resql);
  577. $i = 0;
  578. while ($i < $num) {
  579. $obj = $db->fetch_object($resql);
  580. // Discard auto action if option is on
  581. if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->code == 'AC_OTH_AUTO') {
  582. $i++;
  583. continue;
  584. }
  585. $datep = $db->jdate($obj->datep);
  586. $datep2 = $db->jdate($obj->datep2);
  587. // Create a new object action
  588. $event = new ActionComm($db);
  589. $event->id = $obj->id;
  590. $event->datep = $datep; // datep and datef are GMT date
  591. $event->datef = $datep2;
  592. $event->type_code = $obj->code;
  593. $event->type_color = $obj->color;
  594. $event->label = $obj->label;
  595. $event->percentage = $obj->percent;
  596. $event->authorid = $obj->fk_user_author; // user id of creator
  597. $event->userownerid = $obj->fk_user_action; // user id of owner
  598. $event->priority = $obj->priority;
  599. $event->fulldayevent = $obj->fulldayevent;
  600. $event->location = $obj->location;
  601. $event->transparency = $obj->transparency;
  602. $event->fk_project = $obj->fk_project;
  603. $event->socid = $obj->fk_soc;
  604. $event->contact_id = $obj->fk_contact;
  605. $event->fk_element = $obj->fk_element;
  606. $event->elementtype = $obj->elementtype;
  607. // Defined date_start_in_calendar and date_end_in_calendar property
  608. // They are date start and end of action but modified to not be outside calendar view.
  609. if ($event->percentage <= 0) {
  610. $event->date_start_in_calendar = $datep;
  611. if ($datep2 != '' && $datep2 >= $datep) {
  612. $event->date_end_in_calendar = $datep2;
  613. } else {
  614. $event->date_end_in_calendar = $datep;
  615. }
  616. } else {
  617. $event->date_start_in_calendar = $datep;
  618. if ($datep2 != '' && $datep2 >= $datep) {
  619. $event->date_end_in_calendar = $datep2;
  620. } else {
  621. $event->date_end_in_calendar = $datep;
  622. }
  623. }
  624. // Check values
  625. if ($event->date_end_in_calendar < $firstdaytoshow ||
  626. $event->date_start_in_calendar >= $lastdaytoshow) {
  627. // This record is out of visible range
  628. unset($event);
  629. } else {
  630. //print $i.' - '.dol_print_date($this->date_start_in_calendar, 'dayhour').' - '.dol_print_date($this->date_end_in_calendar, 'dayhour').'<br>'."\n";
  631. $event->fetch_userassigned(); // This load $event->userassigned
  632. if ($event->date_start_in_calendar < $firstdaytoshow) {
  633. $event->date_start_in_calendar = $firstdaytoshow;
  634. }
  635. if ($event->date_end_in_calendar >= $lastdaytoshow) {
  636. $event->date_end_in_calendar = ($lastdaytoshow - 1);
  637. }
  638. // Add an entry in actionarray for each day
  639. $daycursor = $event->date_start_in_calendar;
  640. $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
  641. $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
  642. $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
  643. //print $daycursor.' '.dol_print_date($daycursor, 'dayhour', 'gmt').' '.$event->id.' -> '.$annee.'-'.$mois.'-'.$jour.'<br>';
  644. // Loop on each day covered by action to prepare an index to show on calendar
  645. $loop = true; $j = 0;
  646. $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
  647. do {
  648. //if ($event->id==408) print 'daykey='.$daykey.' '.$event->datep.' '.$event->datef.'<br>';
  649. $eventarray[$daykey][] = $event;
  650. $j++;
  651. $daykey += 60 * 60 * 24;
  652. if ($daykey > $event->date_end_in_calendar) {
  653. $loop = false;
  654. }
  655. } while ($loop);
  656. //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
  657. //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>';
  658. }
  659. $i++;
  660. }
  661. $db->free($resql);
  662. } else {
  663. dol_print_error($db);
  664. }
  665. $maxnbofchar = 18;
  666. $cachethirdparties = array();
  667. $cachecontacts = array();
  668. $cacheusers = array();
  669. // Define theme_datacolor array
  670. $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/theme_vars.inc.php";
  671. if (is_readable($color_file)) {
  672. include $color_file;
  673. }
  674. if (!is_array($theme_datacolor)) {
  675. $theme_datacolor = array(array(120, 130, 150), array(200, 160, 180), array(190, 190, 220));
  676. }
  677. $newparam = $param; // newparam is for birthday links
  678. $newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
  679. $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
  680. $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
  681. $newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
  682. $newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
  683. $newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
  684. $newparam = preg_replace('/viewweek=[0-9]+&?/i', '', $newparam);
  685. $newparam = preg_replace('/showbirthday_=/i', 'showbirthday=', $newparam); // Restore correct parameter
  686. $newparam .= '&viewweek=1';
  687. echo '<input type="hidden" name="actionmove" value="mupdate">';
  688. echo '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER['PHP_SELF']).'?'.dol_escape_htmltag($_SERVER['QUERY_STRING']).'">';
  689. echo '<input type="hidden" name="newdate" id="newdate">';
  690. // Line header with list of days
  691. //print "begin_d=".$begin_d." end_d=".$end_d;
  692. $currentdaytoshow = $firstdaytoshow;
  693. echo '<div class="div-table-responsive">';
  694. while ($currentdaytoshow < $lastdaytoshow) {
  695. echo '<table class="centpercent noborder nocellnopadd cal_month">';
  696. echo '<tr class="liste_titre">';
  697. echo '<td class="nopaddingtopimp nopaddingbottomimp nowraponsmartphone">';
  698. if ($canedit && $mode == 'show_peruser') {
  699. // Filter on hours
  700. print img_picto('', 'clock', 'class="fawidth30 inline-block paddingleft"');
  701. print '<span class="hideonsmartphone" title="'.$langs->trans("VisibleTimeRange").'">'.$langs->trans("Hours").'</span>';
  702. print "\n".'<div class="ui-grid-a inline-block"><div class="ui-block-a nowraponall">';
  703. print '<input type="number" class="short" name="begin_h" value="'.$begin_h.'" min="0" max="23">';
  704. if (empty($conf->dol_use_jmobile)) {
  705. print ' - ';
  706. } else {
  707. print '</div><div class="ui-block-b">';
  708. }
  709. print '<input type="number" class="short" name="end_h" value="'.$end_h.'" min="1" max="24">';
  710. if (empty($conf->dol_use_jmobile)) {
  711. print ' '.$langs->trans("H");
  712. }
  713. print '</div></div>';
  714. print '<br>';
  715. // Filter on days
  716. print img_picto('', 'clock', 'class="fawidth30 inline-block paddingleft"');
  717. print '<span class="hideonsmartphone" title="'.$langs->trans("VisibleDaysRange").'">'.$langs->trans("DaysOfWeek").'</span>';
  718. print "\n".'<div class="ui-grid-a inline-block"><div class="ui-block-a nowraponall">';
  719. print '<input type="number" class="short" name="begin_d" value="'.$begin_d.'" min="1" max="7">';
  720. if (empty($conf->dol_use_jmobile)) {
  721. print ' - ';
  722. } else {
  723. print '</div><div class="ui-block-b">';
  724. }
  725. print '<input type="number" class="short" name="end_d" value="'.$end_d.'" min="1" max="7">';
  726. print '</div></div>';
  727. }
  728. print '</td>';
  729. $i = 0; // 0 = sunday,
  730. while ($i < 7) {
  731. if (($i + 1) < $begin_d || ($i + 1) > $end_d) {
  732. $i++;
  733. continue;
  734. }
  735. echo '<td align="center" colspan="'.($end_h - $begin_h).'">';
  736. echo '<span class="bold spandayofweek">'.$langs->trans("Day".(($i + (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1)) % 7)).'</span>';
  737. print "<br>";
  738. if ($i) {
  739. print dol_print_date(dol_time_plus_duree($currentdaytoshow, $i, 'd'), 'day');
  740. } else {
  741. print dol_print_date($currentdaytoshow, 'day');
  742. }
  743. echo "</td>\n";
  744. $i++;
  745. }
  746. echo "</tr>\n";
  747. echo '<tr class="liste_titre">';
  748. echo '<td></td>';
  749. $i = 0;
  750. while ($i < 7) {
  751. if (($i + 1) < $begin_d || ($i + 1) > $end_d) {
  752. $i++;
  753. continue;
  754. }
  755. for ($h = $begin_h; $h < $end_h; $h++) {
  756. echo '<td class="center">';
  757. print '<small style="font-family: courier">'.sprintf("%02d", $h).'</small>';
  758. print "</td>";
  759. }
  760. echo "</td>\n";
  761. $i++;
  762. }
  763. echo "</tr>\n";
  764. // Define $usernames
  765. $usernames = array(); //init
  766. $usernamesid = array();
  767. /* Use this to have list of users only if users have events */
  768. if (!empty($conf->global->AGENDA_SHOWOWNERONLY_ONPERUSERVIEW)) {
  769. foreach ($eventarray as $daykey => $notused) {
  770. // Get all assigned users for each event
  771. foreach ($eventarray[$daykey] as $index => $event) {
  772. $event->fetch_userassigned();
  773. $listofuserid = $event->userassigned;
  774. foreach ($listofuserid as $userid => $tmp) {
  775. if (!in_array($userid, $usernamesid)) {
  776. $usernamesid[$userid] = $userid;
  777. }
  778. }
  779. }
  780. }
  781. } else {
  782. /* Use this list to have for all users */
  783. $sql = "SELECT DISTINCT u.rowid, u.lastname as lastname, u.firstname, u.statut, u.login, u.admin, u.entity";
  784. $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
  785. if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
  786. $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
  787. $sql .= " WHERE ug.entity IN (".getEntity('usergroup').")";
  788. $sql .= " AND ug.fk_user = u.rowid ";
  789. } else {
  790. if ($usergroup > 0) {
  791. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ug ON u.rowid = ug.fk_user";
  792. }
  793. $sql .= " WHERE u.entity IN (".getEntity('user').")";
  794. }
  795. $sql .= " AND u.statut = 1";
  796. if ($usergroup > 0) {
  797. $sql .= " AND ug.fk_usergroup = ".((int) $usergroup);
  798. }
  799. //print $sql;
  800. $resql = $db->query($sql);
  801. if ($resql) {
  802. $num = $db->num_rows($resql);
  803. $i = 0;
  804. if ($num) {
  805. while ($i < $num) {
  806. $obj = $db->fetch_object($resql);
  807. $usernamesid[$obj->rowid] = $obj->rowid;
  808. $i++;
  809. }
  810. }
  811. } else {
  812. dol_print_error($db);
  813. }
  814. }
  815. //var_dump($usernamesid);
  816. foreach ($usernamesid as $id) {
  817. $tmpuser = new User($db);
  818. $result = $tmpuser->fetch($id);
  819. $usernames[] = $tmpuser;
  820. }
  821. /*
  822. if ($filtert > 0)
  823. {
  824. $tmpuser = new User($db);
  825. $tmpuser->fetch($filtert);
  826. $usernames[] = $tmpuser;
  827. }
  828. else if ($usergroup)
  829. {
  830. $tmpgroup = new UserGroup($db);
  831. $tmpgroup->fetch($usergroup);
  832. $usernames = $tmpgroup->listUsersForGroup();
  833. }
  834. else
  835. {
  836. $tmpgroup = new UserGroup($db);
  837. //$tmpgroup->fetch($usergroup); No fetch, we want all users for all groups
  838. $usernames = $tmpgroup->listUsersForGroup();
  839. }*/
  840. // Load array of colors by type
  841. $colorsbytype = array();
  842. $labelbytype = array();
  843. $sql = "SELECT code, color, libelle as label FROM ".MAIN_DB_PREFIX."c_actioncomm ORDER BY position";
  844. $resql = $db->query($sql);
  845. while ($obj = $db->fetch_object($resql)) {
  846. $colorsbytype[$obj->code] = $obj->color;
  847. $labelbytype[$obj->code] = $obj->label;
  848. }
  849. // Loop on each user to show calendar
  850. $todayarray = dol_getdate($now, 'fast');
  851. $sav = $tmpday;
  852. $showheader = true;
  853. $var = false;
  854. foreach ($usernames as $username) {
  855. $var = !$var;
  856. echo "<tr>";
  857. echo '<td class="tdoverflowmax100 cal_current_month cal_peruserviewname'.($var ? ' cal_impair' : '').'">';
  858. print $username->getNomUrl(-1, '', 0, 0, 20, 1, '');
  859. print '</td>';
  860. $tmpday = $sav;
  861. // Lopp on each day of week
  862. $i = 0;
  863. for ($iter_day = 0; $iter_day < 8; $iter_day++) {
  864. if (($i + 1) < $begin_d || ($i + 1) > $end_d) {
  865. $i++;
  866. continue;
  867. }
  868. // Show days of the current week
  869. $curtime = dol_time_plus_duree($currentdaytoshow, $iter_day, 'd');
  870. $tmparray = dol_getdate($curtime, 'fast');
  871. $tmpday = $tmparray['mday'];
  872. $tmpmonth = $tmparray['mon'];
  873. $tmpyear = $tmparray['year'];
  874. //var_dump($curtime.' '.$tmpday.' '.$tmpmonth.' '.$tmpyear);
  875. $style = 'cal_current_month';
  876. if ($iter_day == 6) {
  877. $style .= ' cal_other_month';
  878. }
  879. $today = 0;
  880. if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $tmpmonth && $todayarray['year'] == $tmpyear) {
  881. $today = 1;
  882. }
  883. if ($today) {
  884. $style = 'cal_today_peruser';
  885. }
  886. show_day_events2($username, $tmpday, $tmpmonth, $tmpyear, 0, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, $showheader, $colorsbytype, $var);
  887. $i++;
  888. }
  889. echo "</tr>\n";
  890. $showheader = false;
  891. }
  892. echo "</table>\n";
  893. echo "<br>";
  894. $currentdaytoshow = dol_time_plus_duree($currentdaytoshow, 7, 'd');
  895. }
  896. echo '</div>';
  897. if (!empty($conf->global->AGENDA_USE_EVENT_TYPE) && !empty($conf->global->AGENDA_USE_COLOR_PER_EVENT_TYPE)) {
  898. $langs->load("commercial");
  899. print '<br>'.$langs->trans("Legend").': <br>';
  900. foreach ($colorsbytype as $code => $color) {
  901. if ($color) {
  902. print '<div style="float: left; padding: 2px; margin-right: 6px;"><div style="'.($color ? 'background: #'.$color.';' : '').'width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
  903. print $langs->trans("Action".$code) != "Action".$code ? $langs->trans("Action".$code) : $labelbytype[$code];
  904. //print $code;
  905. print '</div>';
  906. }
  907. }
  908. //$color=sprintf("%02x%02x%02x",$theme_datacolor[0][0],$theme_datacolor[0][1],$theme_datacolor[0][2]);
  909. print '<div style="float: left; padding: 2px; margin-right: 6px;"><div class="peruser_busy" style="width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
  910. print $langs->trans("Other");
  911. print '</div>';
  912. /* TODO Show this if at least one cumulated event
  913. print '<div style="float: left; padding: 2px; margin-right: 6px;"><div style="background: #222222; width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
  914. print $langs->trans("SeveralEvents");
  915. print '</div>';
  916. */
  917. }
  918. print "\n".'</form>';
  919. print "\n";
  920. // Add js code to manage click on a box
  921. print '<script type="text/javascript">
  922. jQuery(document).ready(function() {
  923. jQuery(".onclickopenref").click(function() {
  924. var ref=$(this).attr(\'ref\');
  925. var res = ref.split("_");
  926. var userid = res[1];
  927. var year = res[2];
  928. var month = res[3];
  929. var day = res[4];
  930. var hour = res[5];
  931. var min = res[6];
  932. var ids = res[7];
  933. if (ids == \'none\') /* No event */
  934. {
  935. /* alert(\'no event\'); */
  936. url = "'.DOL_URL_ROOT.'/comm/action/card.php?action=create&assignedtouser="+userid+"&datep="+year+month+day+hour+min+"00&backtopage='.urlencode($_SERVER["PHP_SELF"].'?year='.$year.'&month='.$month.'&day='.$day.($begin_h !== '' ? '&begin_h='.$begin_h : '').($end_h !== '' ? '&end_h='.$end_h : '').($begin_d !== '' ? '&begin_d='.$begin_d : '').($end_d !== '' ? '&end_d='.$end_d : '')).'"
  937. window.location.href = url;
  938. }
  939. else if (ids.indexOf(",") > -1) /* There is several events */
  940. {
  941. /* alert(\'several events\'); */
  942. url = "'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&filtert="+userid+"&dateselectyear="+year+"&dateselectmonth="+month+"&dateselectday="+day;
  943. window.location.href = url;
  944. }
  945. else /* One event */
  946. {
  947. /* alert(\'one event\'); */
  948. url = "'.DOL_URL_ROOT.'/comm/action/card.php?action=view&id="+ids
  949. window.location.href = url;
  950. }
  951. });
  952. });
  953. </script>';
  954. // End of page
  955. llxFooter();
  956. $db->close();
  957. /**
  958. * Show event line of a particular day for a user
  959. *
  960. * @param User $username Login
  961. * @param int $day Day
  962. * @param int $month Month
  963. * @param int $year Year
  964. * @param int $monthshown Current month shown in calendar view
  965. * @param string $style Style to use for this day
  966. * @param array $eventarray Array of events
  967. * @param int $maxprint Nb of actions to show each day on month view (0 means no limit)
  968. * @param int $maxnbofchar Nb of characters to show for event line
  969. * @param string $newparam Parameters on current URL
  970. * @param int $showinfo Add extended information (used by day view)
  971. * @param int $minheight Minimum height for each event. 60px by default.
  972. * @param boolean $showheader Show header
  973. * @param array $colorsbytype Array with colors by type
  974. * @param bool $var true or false for alternat style on tr/td
  975. * @return void
  976. */
  977. function show_day_events2($username, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint = 0, $maxnbofchar = 16, $newparam = '', $showinfo = 0, $minheight = 60, $showheader = false, $colorsbytype = array(), $var = false)
  978. {
  979. global $db;
  980. global $user, $conf, $langs, $hookmanager, $action;
  981. global $filter, $filtert, $status, $actioncode; // Filters used into search form
  982. global $theme_datacolor; // Array with a list of different we can use (come from theme)
  983. global $cachethirdparties, $cachecontacts, $cacheusers, $cacheprojects, $colorindexused;
  984. global $begin_h, $end_h;
  985. $cases1 = array(); // Color first half hour
  986. $cases2 = array(); // Color second half hour
  987. $i = 0; $numother = 0; $numbirthday = 0; $numical = 0; $numicals = array();
  988. //$ymd = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $day);
  989. $colorindexused[$user->id] = 0; // Color index for current user (user->id) is always 0
  990. $nextindextouse = count($colorindexused); // At first run this is 0, so first user has 0, next 1, ...
  991. //if ($username->id && $day==1) {
  992. //var_dump($eventarray);
  993. //}
  994. // We are in a particular day for $username, now we scan all events
  995. foreach ($eventarray as $daykey => $notused) {
  996. $annee = dol_print_date($daykey, '%Y');
  997. $mois = dol_print_date($daykey, '%m');
  998. $jour = dol_print_date($daykey, '%d');
  999. if ($day == $jour && $month == $mois && $year == $annee) { // Is it the day we are looking for when calling function ?
  1000. // Scan all event for this date
  1001. foreach ($eventarray[$daykey] as $index => $event) {
  1002. //print $daykey.' '.dol_print_date($daykey, 'dayhour', 'gmt').' '.$year.'-'.$month.'-'.$day.' -> '.$event->id.' '.$index.' '.$annee.'-'.$mois.'-'.$jour."<br>\n";
  1003. //var_dump($event);
  1004. $keysofuserassigned = array_keys($event->userassigned);
  1005. $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
  1006. if (!in_array($username->id, $keysofuserassigned)) {
  1007. continue; // We discard record if event is from another user than user we want to show
  1008. }
  1009. //if ($username->id != $event->userownerid) continue; // We discard record if event is from another user than user we want to show
  1010. $parameters = array();
  1011. $reshook = $hookmanager->executeHooks('formatEvent', $parameters, $event, $action); // Note that $action and $object may have been modified by some hooks
  1012. if ($reshook < 0) {
  1013. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  1014. }
  1015. // Define $color (Hex string like '0088FF') and $cssclass of event
  1016. $color = -1; $cssclass = ''; $colorindex = -1;
  1017. if (in_array($user->id, $keysofuserassigned)) {
  1018. $cssclass = 'family_mytasks';
  1019. if (empty($cacheusers[$event->userownerid])) {
  1020. $newuser = new User($db);
  1021. $newuser->fetch($event->userownerid);
  1022. $cacheusers[$event->userownerid] = $newuser;
  1023. }
  1024. //var_dump($cacheusers[$event->userownerid]->color);
  1025. // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
  1026. if (!empty($cacheusers[$event->userownerid]->color)) {
  1027. $color = $cacheusers[$event->userownerid]->color;
  1028. }
  1029. if (!empty($conf->global->AGENDA_USE_COLOR_PER_EVENT_TYPE)) {
  1030. $color = $event->type_color;
  1031. }
  1032. } elseif ($event->type_code == 'ICALEVENT') {
  1033. $numical++;
  1034. if (!empty($event->icalname)) {
  1035. if (!isset($numicals[dol_string_nospecial($event->icalname)])) {
  1036. $numicals[dol_string_nospecial($event->icalname)] = 0;
  1037. }
  1038. $numicals[dol_string_nospecial($event->icalname)]++;
  1039. }
  1040. $color = $event->icalcolor;
  1041. $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other unsortable');
  1042. } elseif ($event->type_code == 'BIRTHDAY') {
  1043. $numbirthday++; $colorindex = 2; $cssclass = 'family_birthday unsortable'; $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
  1044. } else {
  1045. $numother++;
  1046. $color = ($event->icalcolor ? $event->icalcolor : -1);
  1047. $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other');
  1048. if (empty($cacheusers[$event->userownerid])) {
  1049. $newuser = new User($db);
  1050. $newuser->fetch($event->userownerid);
  1051. $cacheusers[$event->userownerid] = $newuser;
  1052. }
  1053. //var_dump($cacheusers[$event->userownerid]->color);
  1054. // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
  1055. if (!empty($cacheusers[$event->userownerid]->color)) {
  1056. $color = $cacheusers[$event->userownerid]->color;
  1057. }
  1058. if (!empty($conf->global->AGENDA_USE_COLOR_PER_EVENT_TYPE)) {
  1059. $color = $event->type_color;
  1060. }
  1061. }
  1062. if ($color < 0) { // Color was not set on user card. Set color according to color index.
  1063. // Define color index if not yet defined
  1064. $idusertouse = ($event->userownerid ? $event->userownerid : 0);
  1065. if (isset($colorindexused[$idusertouse])) {
  1066. $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user
  1067. } else {
  1068. $colorindex = $nextindextouse;
  1069. $colorindexused[$idusertouse] = $colorindex;
  1070. if (!empty($theme_datacolor[$nextindextouse + 1])) {
  1071. $nextindextouse++; // Prepare to use next color
  1072. }
  1073. }
  1074. // Define color
  1075. $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
  1076. }
  1077. // Define all rects with event (cases1 is first half hour, cases2 is second half hour)
  1078. for ($h = $begin_h; $h < $end_h; $h++) {
  1079. //if ($username->id == 1 && $day==1) print 'h='.$h;
  1080. $newcolor = ''; //init
  1081. if (empty($event->fulldayevent)) {
  1082. $a = dol_mktime((int) $h, 0, 0, $month, $day, $year, 'tzuserrel', 0);
  1083. $b = dol_mktime((int) $h, 30, 0, $month, $day, $year, 'tzuserrel', 0);
  1084. $c = dol_mktime((int) $h + 1, 0, 0, $month, $day, $year, 'tzuserrel', 0);
  1085. $dateendtouse = $event->date_end_in_calendar;
  1086. if ($dateendtouse == $event->date_start_in_calendar) {
  1087. $dateendtouse++;
  1088. }
  1089. //print dol_print_date($event->date_start_in_calendar,'dayhour').'-'.dol_print_date($a,'dayhour').'-'.dol_print_date($b,'dayhour').'<br>';
  1090. if ($event->date_start_in_calendar < $b && $dateendtouse > $a) {
  1091. $busy = $event->transparency;
  1092. $cases1[$h][$event->id]['busy'] = $busy;
  1093. $cases1[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel');
  1094. if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
  1095. $tmpa = dol_getdate($event->date_start_in_calendar, true);
  1096. $tmpb = dol_getdate($event->date_end_in_calendar, true);
  1097. if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
  1098. $cases1[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
  1099. } else {
  1100. $cases1[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel');
  1101. }
  1102. }
  1103. if ($event->label) {
  1104. $cases1[$h][$event->id]['string'] .= ' - '.$event->label;
  1105. }
  1106. $cases1[$h][$event->id]['typecode'] = $event->type_code;
  1107. $cases1[$h][$event->id]['color'] = $color;
  1108. if ($event->fk_project > 0) {
  1109. if (empty($cacheprojects[$event->fk_project])) {
  1110. $tmpproj = new Project($db);
  1111. $tmpproj->fetch($event->fk_project);
  1112. $cacheprojects[$event->fk_project] = $tmpproj;
  1113. }
  1114. $cases1[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title;
  1115. }
  1116. if ($event->socid > 0) {
  1117. if (empty($cachethirdparties[$event->socid])) {
  1118. $tmpthirdparty = new Societe($db);
  1119. $tmpthirdparty->fetch($event->socid);
  1120. $cachethirdparties[$event->socid] = $tmpthirdparty;
  1121. }
  1122. $cases1[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name;
  1123. }
  1124. if ($event->contact_id > 0) {
  1125. if (empty($cachecontacts[$event->contact_id])) {
  1126. $tmpcontact = new Contact($db);
  1127. $tmpcontact->fetch($event->contact_id);
  1128. $cachecontacts[$event->contact_id] = $tmpcontact;
  1129. }
  1130. $cases1[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contact_id]->getFullName($langs);
  1131. }
  1132. }
  1133. if ($event->date_start_in_calendar < $c && $dateendtouse > $b) {
  1134. $busy = $event->transparency;
  1135. $cases2[$h][$event->id]['busy'] = $busy;
  1136. $cases2[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel');
  1137. if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
  1138. $tmpa = dol_getdate($event->date_start_in_calendar, true);
  1139. $tmpb = dol_getdate($event->date_end_in_calendar, true);
  1140. if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
  1141. $cases2[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
  1142. } else {
  1143. $cases2[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel');
  1144. }
  1145. }
  1146. if ($event->label) {
  1147. $cases2[$h][$event->id]['string'] .= ' - '.$event->label;
  1148. }
  1149. $cases2[$h][$event->id]['typecode'] = $event->type_code;
  1150. $cases2[$h][$event->id]['color'] = $color;
  1151. if ($event->fk_project > 0) {
  1152. if (empty($cacheprojects[$event->fk_project])) {
  1153. $tmpproj = new Project($db);
  1154. $tmpproj->fetch($event->fk_project);
  1155. $cacheprojects[$event->fk_project] = $tmpproj;
  1156. }
  1157. $cases2[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title;
  1158. }
  1159. if ($event->socid > 0) {
  1160. if (empty($cachethirdparties[$event->socid])) {
  1161. $tmpthirdparty = new Societe($db);
  1162. $tmpthirdparty->fetch($event->socid);
  1163. $cachethirdparties[$event->socid] = $tmpthirdparty;
  1164. }
  1165. $cases2[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name;
  1166. }
  1167. if ($event->contact_id > 0) {
  1168. if (empty($cachecontacts[$event->contact_id])) {
  1169. $tmpcontact = new Contact($db);
  1170. $tmpcontact->fetch($event->contact_id);
  1171. $cachecontacts[$event->contact_id] = $tmpcontact;
  1172. }
  1173. $cases2[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contact_id]->getFullName($langs);
  1174. }
  1175. }
  1176. } else {
  1177. $busy = $event->transparency;
  1178. $cases1[$h][$event->id]['busy'] = $busy;
  1179. $cases2[$h][$event->id]['busy'] = $busy;
  1180. $cases1[$h][$event->id]['string'] = $event->label;
  1181. $cases2[$h][$event->id]['string'] = $event->label;
  1182. $cases1[$h][$event->id]['typecode'] = $event->type_code;
  1183. $cases2[$h][$event->id]['typecode'] = $event->type_code;
  1184. $cases1[$h][$event->id]['color'] = $color;
  1185. $cases2[$h][$event->id]['color'] = $color;
  1186. }
  1187. }
  1188. $i++;
  1189. }
  1190. break; // We found the date we were looking for. No need to search anymore.
  1191. }
  1192. }
  1193. // Now output $casesX
  1194. for ($h = $begin_h; $h < $end_h; $h++) {
  1195. $color1 = ''; $color2 = '';
  1196. $style1 = ''; $style2 = '';
  1197. $string1 = '&nbsp;'; $string2 = '&nbsp;';
  1198. $title1 = ''; $title2 = '';
  1199. if (isset($cases1[$h]) && $cases1[$h] != '') {
  1200. //$title1.=count($cases1[$h]).' '.(count($cases1[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
  1201. if (count($cases1[$h]) > 1) {
  1202. $title1 .= count($cases1[$h]).' '.(count($cases1[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events"));
  1203. }
  1204. $string1 = '&nbsp;';
  1205. if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
  1206. $style1 = 'peruser_notbusy';
  1207. } else {
  1208. $style1 = 'peruser_busy';
  1209. }
  1210. foreach ($cases1[$h] as $id => $ev) {
  1211. if ($ev['busy']) {
  1212. $style1 = 'peruser_busy';
  1213. }
  1214. }
  1215. }
  1216. if (isset($cases2[$h]) && $cases2[$h] != '') {
  1217. //$title2.=count($cases2[$h]).' '.(count($cases2[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
  1218. if (count($cases2[$h]) > 1) {
  1219. $title2 .= count($cases2[$h]).' '.(count($cases2[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events"));
  1220. }
  1221. $string2 = '&nbsp;';
  1222. if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
  1223. $style2 = 'peruser_notbusy';
  1224. } else {
  1225. $style2 = 'peruser_busy';
  1226. }
  1227. foreach ($cases2[$h] as $id => $ev) {
  1228. if ($ev['busy']) {
  1229. $style2 = 'peruser_busy';
  1230. }
  1231. }
  1232. }
  1233. $ids1 = '';
  1234. $ids2 = '';
  1235. if (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) && array_keys($cases1[$h])) {
  1236. $ids1 = join(',', array_keys($cases1[$h]));
  1237. }
  1238. if (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) && array_keys($cases2[$h])) {
  1239. $ids2 = join(',', array_keys($cases2[$h]));
  1240. }
  1241. if ($h == $begin_h) {
  1242. echo '<td class="'.$style.'_peruserleft cal_peruser'.($var ? ' cal_impair '.$style.'_impair' : '').'">';
  1243. } else {
  1244. echo '<td class="'.$style.' cal_peruser'.($var ? ' cal_impair '.$style.'_impair' : '').'">';
  1245. }
  1246. if (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) == 1) { // only 1 event
  1247. $output = array_slice($cases1[$h], 0, 1);
  1248. $title1 = $langs->trans("Ref").' '.$ids1.($title1 ? ' - '.$title1 : '');
  1249. if ($output[0]['string']) {
  1250. $title1 .= ($title1 ? ' - ' : '').$output[0]['string'];
  1251. }
  1252. if ($output[0]['color']) {
  1253. $color1 = $output[0]['color'];
  1254. }
  1255. } elseif (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) > 1) {
  1256. $title1 = $langs->trans("Ref").' '.$ids1.($title1 ? ' - '.$title1 : '');
  1257. $color1 = '222222';
  1258. }
  1259. if (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) == 1) { // only 1 event
  1260. $output = array_slice($cases2[$h], 0, 1);
  1261. $title2 = $langs->trans("Ref").' '.$ids2.($title2 ? ' - '.$title2 : '');
  1262. if ($output[0]['string']) {
  1263. $title2 .= ($title2 ? ' - ' : '').$output[0]['string'];
  1264. }
  1265. if ($output[0]['color']) {
  1266. $color2 = $output[0]['color'];
  1267. }
  1268. } elseif (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) > 1) {
  1269. $title2 = $langs->trans("Ref").' '.$ids2.($title2 ? ' - '.$title2 : '');
  1270. $color2 = '222222';
  1271. }
  1272. print '<table class="nobordernopadding" width="100%">';
  1273. print '<tr><td ';
  1274. if ($style1 == 'peruser_notbusy') {
  1275. print 'style="border: 1px solid #'.($color1 ? $color1 : "888").' !important" ';
  1276. } elseif ($color1) {
  1277. print ($color1 ? 'style="background: #'.$color1.';"' : '');
  1278. }
  1279. print 'class="';
  1280. print ($style1 ? $style1.' ' : '');
  1281. print 'onclickopenref center'.($title2 ? ' classfortooltip' : '').($title1 ? ' cursorpointer' : '').'" ref="ref_'.$username->id.'_'.sprintf("%04d", $year).'_'.sprintf("%02d", $month).'_'.sprintf("%02d", $day).'_'.sprintf("%02d", $h).'_00_'.($ids1 ? $ids1 : 'none').'"'.($title1 ? ' title="'.$title1.'"' : '').'>';
  1282. print $string1;
  1283. print '</td><td ';
  1284. if ($style2 == 'peruser_notbusy') {
  1285. print 'style="border: 1px solid #'.($color2 ? $color2 : "888").' !important" ';
  1286. } elseif ($color2) {
  1287. print ($color2 ? 'style="background: #'.$color2.';"' : '');
  1288. }
  1289. print 'class="';
  1290. print ($style2 ? $style2.' ' : '');
  1291. print 'onclickopenref center'.($title2 ? ' classfortooltip' : '').($title1 ? ' cursorpointer' : '').'" ref="ref_'.$username->id.'_'.sprintf("%04d", $year).'_'.sprintf("%02d", $month).'_'.sprintf("%02d", $day).'_'.sprintf("%02d", $h).'_30_'.($ids2 ? $ids2 : 'none').'"'.($title2 ? ' title="'.$title2.'"' : '').'>';
  1292. print $string2;
  1293. print '</td></tr>';
  1294. print '</table>';
  1295. print '</td>';
  1296. }
  1297. }