peruser.php 67 KB

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