peruser.php 57 KB

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