peruser.php 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466
  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. $disabledefaultvalues = GETPOST('disabledefaultvalues', 'int');
  42. $filter = GETPOST("search_filter", 'alpha', 3) ? GETPOST("search_filter", 'alpha', 3) : GETPOST("filter", 'alpha', 3);
  43. $filtert = GETPOST("search_filtert", "int", 3) ? GETPOST("search_filtert", "int", 3) : GETPOST("filtert", "int", 3);
  44. $usergroup = GETPOST("search_usergroup", "int", 3) ? GETPOST("search_usergroup", "int", 3) : GETPOST("usergroup", "int", 3);
  45. //if (! ($usergroup > 0) && ! ($filtert > 0)) $filtert = $user->id;
  46. //$showbirthday = empty($conf->use_javascript_ajax)?GETPOST("showbirthday","int"):1;
  47. $showbirthday = 0;
  48. // If not choice done on calendar owner, we filter on user.
  49. /*if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS))
  50. {
  51. $filtert = $user->id;
  52. }*/
  53. $sortfield = GETPOST('sortfield', 'aZ09comma');
  54. $sortorder = GETPOST('sortorder', 'aZ09comma');
  55. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  56. if (empty($page) || $page == -1) {
  57. $page = 0;
  58. } // If $page is not defined, or '' or -1
  59. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  60. $offset = $limit * $page;
  61. if (!$sortorder) {
  62. $sortorder = "ASC";
  63. }
  64. if (!$sortfield) {
  65. $sortfield = "a.datec";
  66. }
  67. $socid = GETPOST("search_socid", "int") ?GETPOST("search_socid", "int") : GETPOST("socid", "int");
  68. if ($user->socid) {
  69. $socid = $user->socid;
  70. }
  71. if ($socid < 0) {
  72. $socid = '';
  73. }
  74. $canedit = 1;
  75. if (empty($user->rights->agenda->myactions->read)) {
  76. accessforbidden();
  77. }
  78. if (empty($user->rights->agenda->allactions->read)) {
  79. $canedit = 0;
  80. }
  81. if (empty($user->rights->agenda->allactions->read) || $filter == 'mine') { // If no permission to see all, we show only affected to me
  82. $filtert = $user->id;
  83. }
  84. $mode = 'show_peruser';
  85. $resourceid = GETPOST("search_resourceid", "int") ?GETPOST("search_resourceid", "int") : GETPOST("resourceid", "int");
  86. $year = GETPOST("year", "int") ?GETPOST("year", "int") : date("Y");
  87. $month = GETPOST("month", "int") ?GETPOST("month", "int") : date("m");
  88. $week = GETPOST("week", "int") ?GETPOST("week", "int") : date("W");
  89. $day = GETPOST("day", "int") ?GETPOST("day", "int") : date("d");
  90. $pid = GETPOSTISSET("search_projectid") ? GETPOST("search_projectid", "int", 3) : GETPOST("projectid", "int", 3);
  91. $status = GETPOSTISSET("search_status") ? GETPOST("search_status", 'aZ09') : GETPOST("status", 'aZ09'); // status may be 0, 50, 100, 'todo', 'na' or -1
  92. $type = GETPOSTISSET("search_type") ? GETPOST("search_type", 'alpha') : GETPOST("type", 'alpha');
  93. $maxprint = ((GETPOST("maxprint", 'int') != '') ?GETPOST("maxprint", 'int') : $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW);
  94. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  95. // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
  96. if (GETPOST('search_actioncode', 'array:aZ09')) {
  97. $actioncode = GETPOST('search_actioncode', 'array:aZ09', 3);
  98. if (!count($actioncode)) {
  99. $actioncode = '0';
  100. }
  101. } else {
  102. $actioncode = GETPOST("search_actioncode", "alpha", 3) ?GETPOST("search_actioncode", "alpha", 3) : (GETPOST("search_actioncode", "alpha") == '0' ? '0' : ((empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) || $disabledefaultvalues) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE));
  103. }
  104. $dateselect = dol_mktime(0, 0, 0, GETPOST('dateselectmonth', 'int'), GETPOST('dateselectday', 'int'), GETPOST('dateselectyear', 'int'));
  105. if ($dateselect > 0) {
  106. $day = GETPOST('dateselectday', 'int');
  107. $month = GETPOST('dateselectmonth', 'int');
  108. $year = GETPOST('dateselectyear', 'int');
  109. }
  110. $tmp = empty($conf->global->MAIN_DEFAULT_WORKING_HOURS) ? '9-18' : $conf->global->MAIN_DEFAULT_WORKING_HOURS;
  111. $tmp = str_replace(' ', '', $tmp); // FIX 7533
  112. $tmparray = explode('-', $tmp);
  113. $begin_h = GETPOST('begin_h', 'int') != '' ? GETPOST('begin_h', 'int') : ($tmparray[0] != '' ? $tmparray[0] : 9);
  114. $end_h = GETPOST('end_h', 'int') ? GETPOST('end_h', 'int') : ($tmparray[1] != '' ? $tmparray[1] : 18);
  115. if ($begin_h < 0 || $begin_h > 23) {
  116. $begin_h = 9;
  117. }
  118. if ($end_h < 1 || $end_h > 24) {
  119. $end_h = 18;
  120. }
  121. if ($end_h <= $begin_h) {
  122. $end_h = $begin_h + 1;
  123. }
  124. $tmp = empty($conf->global->MAIN_DEFAULT_WORKING_DAYS) ? '1-5' : $conf->global->MAIN_DEFAULT_WORKING_DAYS;
  125. $tmp = str_replace(' ', '', $tmp); // FIX 7533
  126. $tmparray = explode('-', $tmp);
  127. $begin_d = GETPOST('begin_d', 'int') ?GETPOST('begin_d', 'int') : ($tmparray[0] != '' ? $tmparray[0] : 1);
  128. $end_d = GETPOST('end_d', 'int') ?GETPOST('end_d', 'int') : ($tmparray[1] != '' ? $tmparray[1] : 5);
  129. if ($begin_d < 1 || $begin_d > 7) {
  130. $begin_d = 1;
  131. }
  132. if ($end_d < 1 || $end_d > 7) {
  133. $end_d = 7;
  134. }
  135. if ($end_d < $begin_d) {
  136. $end_d = $begin_d + 1;
  137. }
  138. if ($status == '' && !GETPOSTISSET('search_status')) {
  139. $status = ((empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS) || $disabledefaultvalues) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS);
  140. }
  141. if (empty($mode) && !GETPOSTISSET('mode')) {
  142. $mode = (empty($conf->global->AGENDA_DEFAULT_VIEW) ? 'show_month' : $conf->global->AGENDA_DEFAULT_VIEW);
  143. }
  144. if (GETPOST('viewcal', 'alpha') && $mode != 'show_day' && $mode != 'show_week' && $mode != 'show_peruser') {
  145. $mode = 'show_month'; $day = '';
  146. } // View by month
  147. if (GETPOST('viewweek', 'alpha') || $mode == 'show_week') {
  148. $mode = 'show_week'; $week = ($week ? $week : date("W")); $day = ($day ? $day : date("d"));
  149. } // View by week
  150. if (GETPOST('viewday', 'alpha') || $mode == 'show_day') {
  151. $mode = 'show_day'; $day = ($day ? $day : date("d"));
  152. } // View by day
  153. $object = new ActionComm($db);
  154. // Load translation files required by the page
  155. $langs->loadLangs(array('users', 'agenda', 'other', 'commercial'));
  156. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  157. $hookmanager->initHooks(array('agenda'));
  158. $result = restrictedArea($user, 'agenda', 0, '', 'myactions');
  159. if ($user->socid && $socid) {
  160. $result = restrictedArea($user, 'societe', $socid);
  161. }
  162. $search_status = $status;
  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') || GETPOSTISSET('search_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();
  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_calendarlist', '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. print_actions_filter($form, $canedit, $search_status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
  438. print '</div>';
  439. // Get event in an array
  440. $eventarray = array();
  441. // DEFAULT CALENDAR + AUTOEVENT CALENDAR + CONFERENCEBOOTH CALENDAR
  442. $sql = 'SELECT';
  443. if ($usergroup > 0) {
  444. $sql .= " DISTINCT";
  445. }
  446. $sql .= ' a.id, a.label,';
  447. $sql .= ' a.datep,';
  448. $sql .= ' a.datep2,';
  449. $sql .= ' a.percent,';
  450. $sql .= ' a.fk_user_author,a.fk_user_action,';
  451. $sql .= ' a.transparency, a.priority, a.fulldayevent, a.location,';
  452. $sql .= ' a.fk_soc, a.fk_contact, a.fk_element, a.elementtype, a.fk_project,';
  453. $sql .= ' ca.code, ca.libelle as type_label, ca.color, ca.type as type_type, ca.picto as type_picto';
  454. $sql .= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm as ca, '.MAIN_DB_PREFIX."actioncomm as a";
  455. if (empty($user->rights->societe->client->voir) && !$socid) {
  456. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
  457. }
  458. // We must filter on resource table
  459. if ($resourceid > 0) {
  460. $sql .= ", ".MAIN_DB_PREFIX."element_resources as r";
  461. }
  462. // We must filter on assignement table
  463. if ($filtert > 0 || $usergroup > 0) {
  464. $sql .= ", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
  465. }
  466. if ($usergroup > 0) {
  467. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
  468. }
  469. $sql .= ' WHERE a.fk_action = ca.id';
  470. $sql .= ' AND a.entity IN ('.getEntity('agenda').')';
  471. // Condition on actioncode
  472. if (!empty($actioncode)) {
  473. if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
  474. if ($actioncode == 'AC_NON_AUTO') {
  475. $sql .= " AND ca.type != 'systemauto'";
  476. } elseif ($actioncode == 'AC_ALL_AUTO') {
  477. $sql .= " AND ca.type = 'systemauto'";
  478. } else {
  479. if ($actioncode == 'AC_OTH') {
  480. $sql .= " AND ca.type != 'systemauto'";
  481. }
  482. if ($actioncode == 'AC_OTH_AUTO') {
  483. $sql .= " AND ca.type = 'systemauto'";
  484. }
  485. }
  486. } else {
  487. if ($actioncode == 'AC_NON_AUTO') {
  488. $sql .= " AND ca.type != 'systemauto'";
  489. } elseif ($actioncode == 'AC_ALL_AUTO') {
  490. $sql .= " AND ca.type = 'systemauto'";
  491. } else {
  492. if (is_array($actioncode)) {
  493. $sql .= " AND ca.code IN (".$db->sanitize("'".implode("','", $actioncode)."'", 1).")";
  494. } else {
  495. $sql .= " AND ca.code IN (".$db->sanitize("'".implode("','", explode(',', $actioncode))."'", 1).")";
  496. }
  497. }
  498. }
  499. }
  500. if ($resourceid > 0) {
  501. $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".((int) $resourceid);
  502. }
  503. if ($pid) {
  504. $sql .= " AND a.fk_project = ".((int) $pid);
  505. }
  506. if (empty($user->rights->societe->client->voir) && !$socid) {
  507. $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).")";
  508. }
  509. if ($socid > 0) {
  510. $sql .= ' AND a.fk_soc = '.((int) $socid);
  511. }
  512. // We must filter on assignement table
  513. if ($filtert > 0 || $usergroup > 0) {
  514. $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
  515. }
  516. if ($mode == 'show_day') {
  517. $sql .= " AND (";
  518. $sql .= " (a.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
  519. $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
  520. $sql .= " OR ";
  521. $sql .= " (a.datep2 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.datep < '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
  525. $sql .= " AND a.datep2 > '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
  526. $sql .= ')';
  527. } else {
  528. // To limit array
  529. $sql .= " AND (";
  530. $sql .= " (a.datep BETWEEN '".$db->idate($firstdaytoshow - (60 * 60 * 24 * 2))."'"; // Start 2 day before $firstdaytoshow
  531. $sql .= " AND '".$db->idate($lastdaytoshow + (60 * 60 * 24 * 2))."')"; // End 2 day after $lastdaytoshow
  532. $sql .= " OR ";
  533. $sql .= " (a.datep2 BETWEEN '".$db->idate($firstdaytoshow - (60 * 60 * 24 * 2))."'";
  534. $sql .= " AND '".$db->idate($lastdaytoshow + (60 * 60 * 24 * 2))."')";
  535. $sql .= " OR ";
  536. $sql .= " (a.datep < '".$db->idate($firstdaytoshow - (60 * 60 * 24 * 2))."'";
  537. $sql .= " AND a.datep2 > '".$db->idate($lastdaytoshow + (60 * 60 * 24 * 2))."')";
  538. $sql .= ')';
  539. }
  540. if ($type) {
  541. $sql .= " AND ca.id = ".((int) $type);
  542. }
  543. if ($status == '0') {
  544. $sql .= " AND a.percent = 0";
  545. }
  546. if ($status == '-1' || $status == 'na') {
  547. // Not applicable
  548. $sql .= " AND a.percent = -1";
  549. }
  550. if ($status == '50') {
  551. // Running already started
  552. $sql .= " AND (a.percent > 0 AND a.percent < 100)";
  553. }
  554. if ($status == 'done' || $status == '100') {
  555. $sql .= " AND (a.percent = 100)";
  556. }
  557. if ($status == 'todo') {
  558. $sql .= " AND (a.percent >= 0 AND a.percent < 100)";
  559. }
  560. // We must filter on assignement table
  561. if ($filtert > 0 || $usergroup > 0) {
  562. $sql .= " AND (";
  563. if ($filtert > 0) {
  564. $sql .= "ar.fk_element = ".$filtert;
  565. }
  566. if ($usergroup > 0) {
  567. $sql .= ($filtert > 0 ? " OR " : "")." ugu.fk_usergroup = ".((int) $usergroup);
  568. }
  569. $sql .= ")";
  570. }
  571. // Sort on date
  572. $sql .= ' ORDER BY fk_user_action, datep'; //fk_user_action
  573. dol_syslog("comm/action/peruser.php", LOG_DEBUG);
  574. $resql = $db->query($sql);
  575. if ($resql) {
  576. $num = $db->num_rows($resql);
  577. $i = 0;
  578. while ($i < $num) {
  579. $obj = $db->fetch_object($resql);
  580. // Discard auto action if option is on
  581. if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->code == 'AC_OTH_AUTO') {
  582. $i++;
  583. continue;
  584. }
  585. $datep = $db->jdate($obj->datep);
  586. $datep2 = $db->jdate($obj->datep2);
  587. // Create a new object action
  588. $event = new ActionComm($db);
  589. $event->id = $obj->id;
  590. $event->datep = $datep; // datep and datef are GMT date
  591. $event->datef = $datep2;
  592. $event->type_code = $obj->code;
  593. $event->type_color = $obj->color;
  594. $event->label = $obj->label;
  595. $event->percentage = $obj->percent;
  596. $event->authorid = $obj->fk_user_author; // user id of creator
  597. $event->userownerid = $obj->fk_user_action; // user id of owner
  598. $event->priority = $obj->priority;
  599. $event->fulldayevent = $obj->fulldayevent;
  600. $event->location = $obj->location;
  601. $event->transparency = $obj->transparency;
  602. $event->fk_project = $obj->fk_project;
  603. $event->socid = $obj->fk_soc;
  604. $event->contact_id = $obj->fk_contact;
  605. $event->fk_element = $obj->fk_element;
  606. $event->elementtype = $obj->elementtype;
  607. // Defined date_start_in_calendar and date_end_in_calendar property
  608. // They are date start and end of action but modified to not be outside calendar view.
  609. if ($event->percentage <= 0) {
  610. $event->date_start_in_calendar = $datep;
  611. if ($datep2 != '' && $datep2 >= $datep) {
  612. $event->date_end_in_calendar = $datep2;
  613. } else {
  614. $event->date_end_in_calendar = $datep;
  615. }
  616. } else {
  617. $event->date_start_in_calendar = $datep;
  618. if ($datep2 != '' && $datep2 >= $datep) {
  619. $event->date_end_in_calendar = $datep2;
  620. } else {
  621. $event->date_end_in_calendar = $datep;
  622. }
  623. }
  624. // Check values
  625. if ($event->date_end_in_calendar < $firstdaytoshow ||
  626. $event->date_start_in_calendar >= $lastdaytoshow) {
  627. // This record is out of visible range
  628. unset($event);
  629. } else {
  630. //print $i.' - '.dol_print_date($this->date_start_in_calendar, 'dayhour').' - '.dol_print_date($this->date_end_in_calendar, 'dayhour').'<br>'."\n";
  631. $event->fetch_userassigned(); // This load $event->userassigned
  632. if ($event->date_start_in_calendar < $firstdaytoshow) {
  633. $event->date_start_in_calendar = $firstdaytoshow;
  634. }
  635. if ($event->date_end_in_calendar >= $lastdaytoshow) {
  636. $event->date_end_in_calendar = ($lastdaytoshow - 1);
  637. }
  638. // Add an entry in actionarray for each day
  639. $daycursor = $event->date_start_in_calendar;
  640. $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
  641. $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
  642. $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
  643. //print $daycursor.' '.dol_print_date($daycursor, 'dayhour', 'gmt').' '.$event->id.' -> '.$annee.'-'.$mois.'-'.$jour.'<br>';
  644. // Loop on each day covered by action to prepare an index to show on calendar
  645. $loop = true; $j = 0;
  646. $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
  647. do {
  648. //if ($event->id==408) print 'daykey='.$daykey.' '.$event->datep.' '.$event->datef.'<br>';
  649. $eventarray[$daykey][] = $event;
  650. $j++;
  651. $daykey += 60 * 60 * 24;
  652. if ($daykey > $event->date_end_in_calendar) {
  653. $loop = false;
  654. }
  655. } while ($loop);
  656. //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
  657. //print ' startincalendar='.dol_print_date($event->date_start_in_calendar).'-endincalendar='.dol_print_date($event->date_end_in_calendar).') was added in '.$j.' different index key of array<br>';
  658. }
  659. $i++;
  660. }
  661. $db->free($resql);
  662. } else {
  663. dol_print_error($db);
  664. }
  665. $maxnbofchar = 18;
  666. $cachethirdparties = array();
  667. $cachecontacts = array();
  668. $cacheusers = array();
  669. // Define theme_datacolor array
  670. $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/theme_vars.inc.php";
  671. if (is_readable($color_file)) {
  672. include $color_file;
  673. }
  674. if (!is_array($theme_datacolor)) {
  675. $theme_datacolor = array(array(120, 130, 150), array(200, 160, 180), array(190, 190, 220));
  676. }
  677. $newparam = $param; // newparam is for birthday links
  678. $newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
  679. $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
  680. $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
  681. $newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
  682. $newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
  683. $newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
  684. $newparam = preg_replace('/viewweek=[0-9]+&?/i', '', $newparam);
  685. $newparam = preg_replace('/showbirthday_=/i', 'showbirthday=', $newparam); // Restore correct parameter
  686. $newparam .= '&viewweek=1';
  687. echo '<input type="hidden" name="actionmove" value="mupdate">';
  688. echo '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER['PHP_SELF']).'?'.dol_escape_htmltag($_SERVER['QUERY_STRING']).'">';
  689. echo '<input type="hidden" name="newdate" id="newdate">';
  690. // Line header with list of days
  691. //print "begin_d=".$begin_d." end_d=".$end_d;
  692. $currentdaytoshow = $firstdaytoshow;
  693. echo '<div class="div-table-responsive">';
  694. while ($currentdaytoshow < $lastdaytoshow) {
  695. echo '<table class="centpercent noborder nocellnopadd cal_month">';
  696. echo '<tr class="liste_titre">';
  697. echo '<td class="nopaddingtopimp nopaddingbottomimp nowraponsmartphone">';
  698. if ($canedit && $mode == 'show_peruser') {
  699. // Filter on hours
  700. print img_picto('', 'clock', 'class="fawidth30 inline-block paddingleft"');
  701. print '<span class="hideonsmartphone" title="'.$langs->trans("VisibleTimeRange").'">'.$langs->trans("Hours").'</span>';
  702. print "\n".'<div class="ui-grid-a inline-block"><div class="ui-block-a nowraponall">';
  703. print '<input type="number" class="short" name="begin_h" value="'.$begin_h.'" min="0" max="23">';
  704. if (empty($conf->dol_use_jmobile)) {
  705. print ' - ';
  706. } else {
  707. print '</div><div class="ui-block-b">';
  708. }
  709. print '<input type="number" class="short" name="end_h" value="'.$end_h.'" min="1" max="24">';
  710. if (empty($conf->dol_use_jmobile)) {
  711. print ' '.$langs->trans("H");
  712. }
  713. print '</div></div>';
  714. print '<br>';
  715. // Filter on days
  716. print img_picto('', 'clock', 'class="fawidth30 inline-block paddingleft"');
  717. print '<span class="hideonsmartphone" title="'.$langs->trans("VisibleDaysRange").'">'.$langs->trans("DaysOfWeek").'</span>';
  718. print "\n".'<div class="ui-grid-a inline-block"><div class="ui-block-a nowraponall">';
  719. print '<input type="number" class="short" name="begin_d" value="'.$begin_d.'" min="1" max="7">';
  720. if (empty($conf->dol_use_jmobile)) {
  721. print ' - ';
  722. } else {
  723. print '</div><div class="ui-block-b">';
  724. }
  725. print '<input type="number" class="short" name="end_d" value="'.$end_d.'" min="1" max="7">';
  726. print '</div></div>';
  727. }
  728. print '</td>';
  729. $i = 0; // 0 = sunday,
  730. while ($i < 7) {
  731. if (($i + 1) < $begin_d || ($i + 1) > $end_d) {
  732. $i++;
  733. continue;
  734. }
  735. echo '<td align="center" colspan="'.($end_h - $begin_h).'">';
  736. echo '<span class="bold spandayofweek">'.$langs->trans("Day".(($i + (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1)) % 7)).'</span>';
  737. print "<br>";
  738. if ($i) {
  739. print dol_print_date(dol_time_plus_duree($currentdaytoshow, $i, 'd'), 'day');
  740. } else {
  741. print dol_print_date($currentdaytoshow, 'day');
  742. }
  743. echo "</td>\n";
  744. $i++;
  745. }
  746. echo "</tr>\n";
  747. echo '<tr class="liste_titre">';
  748. echo '<td></td>';
  749. $i = 0;
  750. while ($i < 7) {
  751. if (($i + 1) < $begin_d || ($i + 1) > $end_d) {
  752. $i++;
  753. continue;
  754. }
  755. for ($h = $begin_h; $h < $end_h; $h++) {
  756. echo '<td class="center">';
  757. print '<small style="font-family: courier">'.sprintf("%02d", $h).'</small>';
  758. print "</td>";
  759. }
  760. echo "</td>\n";
  761. $i++;
  762. }
  763. echo "</tr>\n";
  764. // Define $usernames
  765. $usernames = array(); //init
  766. $usernamesid = array();
  767. /* Use this to have list of users only if users have events */
  768. if (!empty($conf->global->AGENDA_SHOWOWNERONLY_ONPERUSERVIEW)) {
  769. foreach ($eventarray as $daykey => $notused) {
  770. // Get all assigned users for each event
  771. foreach ($eventarray[$daykey] as $index => $event) {
  772. $event->fetch_userassigned();
  773. $listofuserid = $event->userassigned;
  774. foreach ($listofuserid as $userid => $tmp) {
  775. if (!in_array($userid, $usernamesid)) {
  776. $usernamesid[$userid] = $userid;
  777. }
  778. }
  779. }
  780. }
  781. } else {
  782. /* Use this list to have for all users */
  783. $sql = "SELECT DISTINCT u.rowid, u.lastname as lastname, u.firstname, u.statut, u.login, u.admin, u.entity";
  784. $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
  785. if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
  786. $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
  787. $sql .= " WHERE ug.entity IN (".getEntity('usergroup').")";
  788. $sql .= " AND ug.fk_user = u.rowid ";
  789. } else {
  790. if ($usergroup > 0) {
  791. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ug ON u.rowid = ug.fk_user";
  792. }
  793. $sql .= " WHERE u.entity IN (".getEntity('user').")";
  794. }
  795. $sql .= " AND u.statut = 1";
  796. if ($usergroup > 0) {
  797. $sql .= " AND ug.fk_usergroup = ".((int) $usergroup);
  798. }
  799. if ($user->socid > 0) {
  800. // External users should see only contacts of their company
  801. $sql .= " AND u.fk_soc = ".((int) $user->socid);
  802. }
  803. //print $sql;
  804. $resql = $db->query($sql);
  805. if ($resql) {
  806. $num = $db->num_rows($resql);
  807. $i = 0;
  808. if ($num) {
  809. while ($i < $num) {
  810. $obj = $db->fetch_object($resql);
  811. $usernamesid[$obj->rowid] = $obj->rowid;
  812. $i++;
  813. }
  814. }
  815. } else {
  816. dol_print_error($db);
  817. }
  818. }
  819. //var_dump($usernamesid);
  820. foreach ($usernamesid as $id) {
  821. $tmpuser = new User($db);
  822. $result = $tmpuser->fetch($id);
  823. $usernames[] = $tmpuser;
  824. }
  825. /*
  826. if ($filtert > 0)
  827. {
  828. $tmpuser = new User($db);
  829. $tmpuser->fetch($filtert);
  830. $usernames[] = $tmpuser;
  831. }
  832. else if ($usergroup)
  833. {
  834. $tmpgroup = new UserGroup($db);
  835. $tmpgroup->fetch($usergroup);
  836. $usernames = $tmpgroup->listUsersForGroup();
  837. }
  838. else
  839. {
  840. $tmpgroup = new UserGroup($db);
  841. //$tmpgroup->fetch($usergroup); No fetch, we want all users for all groups
  842. $usernames = $tmpgroup->listUsersForGroup();
  843. }*/
  844. // Load array of colors by type
  845. $colorsbytype = array();
  846. $labelbytype = array();
  847. $sql = "SELECT code, color, libelle as label FROM ".MAIN_DB_PREFIX."c_actioncomm ORDER BY position";
  848. $resql = $db->query($sql);
  849. while ($obj = $db->fetch_object($resql)) {
  850. $colorsbytype[$obj->code] = $obj->color;
  851. $labelbytype[$obj->code] = $obj->label;
  852. }
  853. // Loop on each user to show calendar
  854. $todayarray = dol_getdate($now, 'fast');
  855. $sav = $tmpday;
  856. $showheader = true;
  857. $var = false;
  858. foreach ($usernames as $username) {
  859. $var = !$var;
  860. echo "<tr>";
  861. echo '<td class="tdoverflowmax100 cal_current_month cal_peruserviewname'.($var ? ' cal_impair' : '').'">';
  862. print $username->getNomUrl(-1, '', 0, 0, 20, 1, '');
  863. print '</td>';
  864. $tmpday = $sav;
  865. // Lopp on each day of week
  866. $i = 0;
  867. for ($iter_day = 0; $iter_day < 8; $iter_day++) {
  868. if (($i + 1) < $begin_d || ($i + 1) > $end_d) {
  869. $i++;
  870. continue;
  871. }
  872. // Show days of the current week
  873. $curtime = dol_time_plus_duree($currentdaytoshow, $iter_day, 'd');
  874. $tmparray = dol_getdate($curtime, 'fast');
  875. $tmpday = $tmparray['mday'];
  876. $tmpmonth = $tmparray['mon'];
  877. $tmpyear = $tmparray['year'];
  878. //var_dump($curtime.' '.$tmpday.' '.$tmpmonth.' '.$tmpyear);
  879. $style = 'cal_current_month';
  880. if ($iter_day == 6) {
  881. $style .= ' cal_other_month';
  882. }
  883. $today = 0;
  884. if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $tmpmonth && $todayarray['year'] == $tmpyear) {
  885. $today = 1;
  886. }
  887. if ($today) {
  888. $style = 'cal_today_peruser';
  889. }
  890. show_day_events2($username, $tmpday, $tmpmonth, $tmpyear, 0, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, $showheader, $colorsbytype, $var);
  891. $i++;
  892. }
  893. echo "</tr>\n";
  894. $showheader = false;
  895. }
  896. echo "</table>\n";
  897. echo "<br>";
  898. $currentdaytoshow = dol_time_plus_duree($currentdaytoshow, 7, 'd');
  899. }
  900. echo '</div>';
  901. if (!empty($conf->global->AGENDA_USE_EVENT_TYPE) && !empty($conf->global->AGENDA_USE_COLOR_PER_EVENT_TYPE)) {
  902. $langs->load("commercial");
  903. print '<br>'.$langs->trans("Legend").': <br>';
  904. foreach ($colorsbytype as $code => $color) {
  905. if ($color) {
  906. print '<div style="float: left; padding: 2px; margin-right: 6px;"><div style="'.($color ? 'background: #'.$color.';' : '').'width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
  907. print $langs->trans("Action".$code) != "Action".$code ? $langs->trans("Action".$code) : $labelbytype[$code];
  908. //print $code;
  909. print '</div>';
  910. }
  911. }
  912. //$color=sprintf("%02x%02x%02x",$theme_datacolor[0][0],$theme_datacolor[0][1],$theme_datacolor[0][2]);
  913. print '<div style="float: left; padding: 2px; margin-right: 6px;"><div class="peruser_busy" style="width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
  914. print $langs->trans("Other");
  915. print '</div>';
  916. /* TODO Show this if at least one cumulated event
  917. print '<div style="float: left; padding: 2px; margin-right: 6px;"><div style="background: #222222; width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
  918. print $langs->trans("SeveralEvents");
  919. print '</div>';
  920. */
  921. }
  922. print "\n".'</form>';
  923. print "\n";
  924. // Add js code to manage click on a box
  925. print '<script type="text/javascript">
  926. jQuery(document).ready(function() {
  927. jQuery(".onclickopenref").click(function() {
  928. var ref=$(this).attr(\'ref\');
  929. var res = ref.split("_");
  930. var userid = res[1];
  931. var year = res[2];
  932. var month = res[3];
  933. var day = res[4];
  934. var hour = res[5];
  935. var min = res[6];
  936. var ids = res[7];
  937. if (ids == \'none\') /* No event */
  938. {
  939. /* alert(\'no event\'); */
  940. 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 : '')).'"
  941. window.location.href = url;
  942. }
  943. else if (ids.indexOf(",") > -1) /* There is several events */
  944. {
  945. /* alert(\'several events\'); */
  946. url = "'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&filtert="+userid+"&dateselectyear="+year+"&dateselectmonth="+month+"&dateselectday="+day;
  947. window.location.href = url;
  948. }
  949. else /* One event */
  950. {
  951. /* alert(\'one event\'); */
  952. url = "'.DOL_URL_ROOT.'/comm/action/card.php?action=view&id="+ids
  953. window.location.href = url;
  954. }
  955. });
  956. });
  957. </script>';
  958. // End of page
  959. llxFooter();
  960. $db->close();
  961. /**
  962. * Show event line of a particular day for a user
  963. *
  964. * @param User $username Login
  965. * @param int $day Day
  966. * @param int $month Month
  967. * @param int $year Year
  968. * @param int $monthshown Current month shown in calendar view
  969. * @param string $style Style to use for this day
  970. * @param array $eventarray Array of events
  971. * @param int $maxprint Nb of actions to show each day on month view (0 means no limit)
  972. * @param int $maxnbofchar Nb of characters to show for event line
  973. * @param string $newparam Parameters on current URL
  974. * @param int $showinfo Add extended information (used by day view)
  975. * @param int $minheight Minimum height for each event. 60px by default.
  976. * @param boolean $showheader Show header
  977. * @param array $colorsbytype Array with colors by type
  978. * @param bool $var true or false for alternat style on tr/td
  979. * @return void
  980. */
  981. 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)
  982. {
  983. global $db;
  984. global $user, $conf, $langs, $hookmanager, $action;
  985. global $filter, $filtert, $status, $actioncode; // Filters used into search form
  986. global $theme_datacolor; // Array with a list of different we can use (come from theme)
  987. global $cachethirdparties, $cachecontacts, $cacheusers, $cacheprojects, $colorindexused;
  988. global $begin_h, $end_h;
  989. $cases1 = array(); // Color first half hour
  990. $cases2 = array(); // Color second half hour
  991. $i = 0; $numother = 0; $numbirthday = 0; $numical = 0; $numicals = array();
  992. //$ymd = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $day);
  993. $colorindexused[$user->id] = 0; // Color index for current user (user->id) is always 0
  994. $nextindextouse = count($colorindexused); // At first run this is 0, so first user has 0, next 1, ...
  995. //if ($username->id && $day==1) {
  996. //var_dump($eventarray);
  997. //}
  998. // We are in a particular day for $username, now we scan all events
  999. foreach ($eventarray as $daykey => $notused) {
  1000. $annee = dol_print_date($daykey, '%Y');
  1001. $mois = dol_print_date($daykey, '%m');
  1002. $jour = dol_print_date($daykey, '%d');
  1003. if ($day == $jour && $month == $mois && $year == $annee) { // Is it the day we are looking for when calling function ?
  1004. // Scan all event for this date
  1005. foreach ($eventarray[$daykey] as $index => $event) {
  1006. //print $daykey.' '.dol_print_date($daykey, 'dayhour', 'gmt').' '.$year.'-'.$month.'-'.$day.' -> '.$event->id.' '.$index.' '.$annee.'-'.$mois.'-'.$jour."<br>\n";
  1007. //var_dump($event);
  1008. $keysofuserassigned = array_keys($event->userassigned);
  1009. $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
  1010. if (!in_array($username->id, $keysofuserassigned)) {
  1011. continue; // We discard record if event is from another user than user we want to show
  1012. }
  1013. //if ($username->id != $event->userownerid) continue; // We discard record if event is from another user than user we want to show
  1014. $parameters = array();
  1015. $reshook = $hookmanager->executeHooks('formatEvent', $parameters, $event, $action); // Note that $action and $object may have been modified by some hooks
  1016. if ($reshook < 0) {
  1017. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  1018. }
  1019. // Define $color (Hex string like '0088FF') and $cssclass of event
  1020. $color = -1; $cssclass = ''; $colorindex = -1;
  1021. if (in_array($user->id, $keysofuserassigned)) {
  1022. $cssclass = 'family_mytasks';
  1023. if (empty($cacheusers[$event->userownerid])) {
  1024. $newuser = new User($db);
  1025. $newuser->fetch($event->userownerid);
  1026. $cacheusers[$event->userownerid] = $newuser;
  1027. }
  1028. //var_dump($cacheusers[$event->userownerid]->color);
  1029. // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
  1030. if (!empty($cacheusers[$event->userownerid]->color)) {
  1031. $color = $cacheusers[$event->userownerid]->color;
  1032. }
  1033. if (!empty($conf->global->AGENDA_USE_COLOR_PER_EVENT_TYPE)) {
  1034. $color = $event->type_color;
  1035. }
  1036. } elseif ($event->type_code == 'ICALEVENT') {
  1037. $numical++;
  1038. if (!empty($event->icalname)) {
  1039. if (!isset($numicals[dol_string_nospecial($event->icalname)])) {
  1040. $numicals[dol_string_nospecial($event->icalname)] = 0;
  1041. }
  1042. $numicals[dol_string_nospecial($event->icalname)]++;
  1043. }
  1044. $color = $event->icalcolor;
  1045. $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other unsortable');
  1046. } elseif ($event->type_code == 'BIRTHDAY') {
  1047. $numbirthday++; $colorindex = 2; $cssclass = 'family_birthday unsortable'; $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
  1048. } else {
  1049. $numother++;
  1050. $color = ($event->icalcolor ? $event->icalcolor : -1);
  1051. $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other');
  1052. if (empty($cacheusers[$event->userownerid])) {
  1053. $newuser = new User($db);
  1054. $newuser->fetch($event->userownerid);
  1055. $cacheusers[$event->userownerid] = $newuser;
  1056. }
  1057. //var_dump($cacheusers[$event->userownerid]->color);
  1058. // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
  1059. if (!empty($cacheusers[$event->userownerid]->color)) {
  1060. $color = $cacheusers[$event->userownerid]->color;
  1061. }
  1062. if (!empty($conf->global->AGENDA_USE_COLOR_PER_EVENT_TYPE)) {
  1063. $color = $event->type_color;
  1064. }
  1065. }
  1066. if ($color < 0) { // Color was not set on user card. Set color according to color index.
  1067. // Define color index if not yet defined
  1068. $idusertouse = ($event->userownerid ? $event->userownerid : 0);
  1069. if (isset($colorindexused[$idusertouse])) {
  1070. $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user
  1071. } else {
  1072. $colorindex = $nextindextouse;
  1073. $colorindexused[$idusertouse] = $colorindex;
  1074. if (!empty($theme_datacolor[$nextindextouse + 1])) {
  1075. $nextindextouse++; // Prepare to use next color
  1076. }
  1077. }
  1078. // Define color
  1079. $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
  1080. }
  1081. // Define all rects with event (cases1 is first half hour, cases2 is second half hour)
  1082. for ($h = $begin_h; $h < $end_h; $h++) {
  1083. //if ($username->id == 1 && $day==1) print 'h='.$h;
  1084. $newcolor = ''; //init
  1085. if (empty($event->fulldayevent)) {
  1086. $a = dol_mktime((int) $h, 0, 0, $month, $day, $year, 'tzuserrel', 0);
  1087. $b = dol_mktime((int) $h, 30, 0, $month, $day, $year, 'tzuserrel', 0);
  1088. $c = dol_mktime((int) $h + 1, 0, 0, $month, $day, $year, 'tzuserrel', 0);
  1089. $dateendtouse = $event->date_end_in_calendar;
  1090. if ($dateendtouse == $event->date_start_in_calendar) {
  1091. $dateendtouse++;
  1092. }
  1093. //print dol_print_date($event->date_start_in_calendar,'dayhour').'-'.dol_print_date($a,'dayhour').'-'.dol_print_date($b,'dayhour').'<br>';
  1094. if ($event->date_start_in_calendar < $b && $dateendtouse > $a) {
  1095. $busy = $event->transparency;
  1096. $cases1[$h][$event->id]['busy'] = $busy;
  1097. $cases1[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel');
  1098. if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
  1099. $tmpa = dol_getdate($event->date_start_in_calendar, true);
  1100. $tmpb = dol_getdate($event->date_end_in_calendar, true);
  1101. if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
  1102. $cases1[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
  1103. } else {
  1104. $cases1[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel');
  1105. }
  1106. }
  1107. if ($event->label) {
  1108. $cases1[$h][$event->id]['string'] .= ' - '.$event->label;
  1109. }
  1110. $cases1[$h][$event->id]['typecode'] = $event->type_code;
  1111. $cases1[$h][$event->id]['color'] = $color;
  1112. if ($event->fk_project > 0) {
  1113. if (empty($cacheprojects[$event->fk_project])) {
  1114. $tmpproj = new Project($db);
  1115. $tmpproj->fetch($event->fk_project);
  1116. $cacheprojects[$event->fk_project] = $tmpproj;
  1117. }
  1118. $cases1[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title;
  1119. }
  1120. if ($event->socid > 0) {
  1121. if (empty($cachethirdparties[$event->socid])) {
  1122. $tmpthirdparty = new Societe($db);
  1123. $tmpthirdparty->fetch($event->socid);
  1124. $cachethirdparties[$event->socid] = $tmpthirdparty;
  1125. }
  1126. $cases1[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name;
  1127. }
  1128. if ($event->contact_id > 0) {
  1129. if (empty($cachecontacts[$event->contact_id])) {
  1130. $tmpcontact = new Contact($db);
  1131. $tmpcontact->fetch($event->contact_id);
  1132. $cachecontacts[$event->contact_id] = $tmpcontact;
  1133. }
  1134. $cases1[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contact_id]->getFullName($langs);
  1135. }
  1136. }
  1137. if ($event->date_start_in_calendar < $c && $dateendtouse > $b) {
  1138. $busy = $event->transparency;
  1139. $cases2[$h][$event->id]['busy'] = $busy;
  1140. $cases2[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel');
  1141. if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
  1142. $tmpa = dol_getdate($event->date_start_in_calendar, true);
  1143. $tmpb = dol_getdate($event->date_end_in_calendar, true);
  1144. if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
  1145. $cases2[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
  1146. } else {
  1147. $cases2[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel');
  1148. }
  1149. }
  1150. if ($event->label) {
  1151. $cases2[$h][$event->id]['string'] .= ' - '.$event->label;
  1152. }
  1153. $cases2[$h][$event->id]['typecode'] = $event->type_code;
  1154. $cases2[$h][$event->id]['color'] = $color;
  1155. if ($event->fk_project > 0) {
  1156. if (empty($cacheprojects[$event->fk_project])) {
  1157. $tmpproj = new Project($db);
  1158. $tmpproj->fetch($event->fk_project);
  1159. $cacheprojects[$event->fk_project] = $tmpproj;
  1160. }
  1161. $cases2[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title;
  1162. }
  1163. if ($event->socid > 0) {
  1164. if (empty($cachethirdparties[$event->socid])) {
  1165. $tmpthirdparty = new Societe($db);
  1166. $tmpthirdparty->fetch($event->socid);
  1167. $cachethirdparties[$event->socid] = $tmpthirdparty;
  1168. }
  1169. $cases2[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name;
  1170. }
  1171. if ($event->contact_id > 0) {
  1172. if (empty($cachecontacts[$event->contact_id])) {
  1173. $tmpcontact = new Contact($db);
  1174. $tmpcontact->fetch($event->contact_id);
  1175. $cachecontacts[$event->contact_id] = $tmpcontact;
  1176. }
  1177. $cases2[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contact_id]->getFullName($langs);
  1178. }
  1179. }
  1180. } else {
  1181. $busy = $event->transparency;
  1182. $cases1[$h][$event->id]['busy'] = $busy;
  1183. $cases2[$h][$event->id]['busy'] = $busy;
  1184. $cases1[$h][$event->id]['string'] = $event->label;
  1185. $cases2[$h][$event->id]['string'] = $event->label;
  1186. $cases1[$h][$event->id]['typecode'] = $event->type_code;
  1187. $cases2[$h][$event->id]['typecode'] = $event->type_code;
  1188. $cases1[$h][$event->id]['color'] = $color;
  1189. $cases2[$h][$event->id]['color'] = $color;
  1190. }
  1191. }
  1192. $i++;
  1193. }
  1194. break; // We found the date we were looking for. No need to search anymore.
  1195. }
  1196. }
  1197. // Now output $casesX
  1198. for ($h = $begin_h; $h < $end_h; $h++) {
  1199. $color1 = ''; $color2 = '';
  1200. $style1 = ''; $style2 = '';
  1201. $string1 = '&nbsp;'; $string2 = '&nbsp;';
  1202. $title1 = ''; $title2 = '';
  1203. if (isset($cases1[$h]) && $cases1[$h] != '') {
  1204. //$title1.=count($cases1[$h]).' '.(count($cases1[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
  1205. if (count($cases1[$h]) > 1) {
  1206. $title1 .= count($cases1[$h]).' '.(count($cases1[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events"));
  1207. }
  1208. $string1 = '&nbsp;';
  1209. if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
  1210. $style1 = 'peruser_notbusy';
  1211. } else {
  1212. $style1 = 'peruser_busy';
  1213. }
  1214. foreach ($cases1[$h] as $id => $ev) {
  1215. if ($ev['busy']) {
  1216. $style1 = 'peruser_busy';
  1217. }
  1218. }
  1219. }
  1220. if (isset($cases2[$h]) && $cases2[$h] != '') {
  1221. //$title2.=count($cases2[$h]).' '.(count($cases2[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
  1222. if (count($cases2[$h]) > 1) {
  1223. $title2 .= count($cases2[$h]).' '.(count($cases2[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events"));
  1224. }
  1225. $string2 = '&nbsp;';
  1226. if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
  1227. $style2 = 'peruser_notbusy';
  1228. } else {
  1229. $style2 = 'peruser_busy';
  1230. }
  1231. foreach ($cases2[$h] as $id => $ev) {
  1232. if ($ev['busy']) {
  1233. $style2 = 'peruser_busy';
  1234. }
  1235. }
  1236. }
  1237. $ids1 = '';
  1238. $ids2 = '';
  1239. if (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) && array_keys($cases1[$h])) {
  1240. $ids1 = join(',', array_keys($cases1[$h]));
  1241. }
  1242. if (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) && array_keys($cases2[$h])) {
  1243. $ids2 = join(',', array_keys($cases2[$h]));
  1244. }
  1245. if ($h == $begin_h) {
  1246. echo '<td class="'.$style.'_peruserleft cal_peruser'.($var ? ' cal_impair '.$style.'_impair' : '').'">';
  1247. } else {
  1248. echo '<td class="'.$style.' cal_peruser'.($var ? ' cal_impair '.$style.'_impair' : '').'">';
  1249. }
  1250. if (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) == 1) { // only 1 event
  1251. $output = array_slice($cases1[$h], 0, 1);
  1252. $title1 = $langs->trans("Ref").' '.$ids1.($title1 ? ' - '.$title1 : '');
  1253. if ($output[0]['string']) {
  1254. $title1 .= ($title1 ? ' - ' : '').$output[0]['string'];
  1255. }
  1256. if ($output[0]['color']) {
  1257. $color1 = $output[0]['color'];
  1258. }
  1259. } elseif (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) > 1) {
  1260. $title1 = $langs->trans("Ref").' '.$ids1.($title1 ? ' - '.$title1 : '');
  1261. $color1 = '222222';
  1262. }
  1263. if (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) == 1) { // only 1 event
  1264. $output = array_slice($cases2[$h], 0, 1);
  1265. $title2 = $langs->trans("Ref").' '.$ids2.($title2 ? ' - '.$title2 : '');
  1266. if ($output[0]['string']) {
  1267. $title2 .= ($title2 ? ' - ' : '').$output[0]['string'];
  1268. }
  1269. if ($output[0]['color']) {
  1270. $color2 = $output[0]['color'];
  1271. }
  1272. } elseif (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) > 1) {
  1273. $title2 = $langs->trans("Ref").' '.$ids2.($title2 ? ' - '.$title2 : '');
  1274. $color2 = '222222';
  1275. }
  1276. print '<table class="nobordernopadding" width="100%">';
  1277. print '<tr><td ';
  1278. if ($style1 == 'peruser_notbusy') {
  1279. print 'style="border: 1px solid #'.($color1 ? $color1 : "888").' !important" ';
  1280. } elseif ($color1) {
  1281. print ($color1 ? 'style="background: #'.$color1.';"' : '');
  1282. }
  1283. print 'class="';
  1284. print ($style1 ? $style1.' ' : '');
  1285. 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.'"' : '').'>';
  1286. print $string1;
  1287. print '</td><td ';
  1288. if ($style2 == 'peruser_notbusy') {
  1289. print 'style="border: 1px solid #'.($color2 ? $color2 : "888").' !important" ';
  1290. } elseif ($color2) {
  1291. print ($color2 ? 'style="background: #'.$color2.';"' : '');
  1292. }
  1293. print 'class="';
  1294. print ($style2 ? $style2.' ' : '');
  1295. print 'onclickopenref center'.($title2 ? ' classfortooltip' : '').($title1 ? ' cursorpointer' : '').'" ref="ref_'.$username->id.'_'.sprintf("%04d", $year).'_'.sprintf("%02d", $month).'_'.sprintf("%02d", $day).'_'.sprintf("%02d", $h).'_30_'.($ids2 ? $ids2 : 'none').'"'.($title2 ? ' title="'.$title2.'"' : '').'>';
  1296. print $string2;
  1297. print '</td></tr>';
  1298. print '</table>';
  1299. print '</td>';
  1300. }
  1301. }