peruser.php 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  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@capnetworks.com>
  6. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/comm/action/peruser.php
  24. * \ingroup agenda
  25. * \brief Tab of calendar events per user
  26. */
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
  33. if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  34. if (! isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW=3;
  35. $filter = GETPOST("filter",'',3);
  36. $filtert = GETPOST("filtert","int",3);
  37. $usergroup = GETPOST("usergroup","int",3);
  38. //if (! ($usergroup > 0) && ! ($filtert > 0)) $filtert = $user->id;
  39. //$showbirthday = empty($conf->use_javascript_ajax)?GETPOST("showbirthday","int"):1;
  40. $showbirthday = 0;
  41. // If not choice done on calendar owner, we filter on user.
  42. if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS))
  43. {
  44. $filtert=$user->id;
  45. }
  46. $sortfield = GETPOST("sortfield",'alpha');
  47. $sortorder = GETPOST("sortorder",'alpha');
  48. $page = GETPOST("page","int");
  49. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  50. $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
  51. $offset = $limit * $page;
  52. if (! $sortorder) $sortorder="ASC";
  53. if (! $sortfield) $sortfield="a.datec";
  54. // Security check
  55. $socid = GETPOST("socid","int");
  56. if ($user->societe_id) $socid=$user->societe_id;
  57. $result = restrictedArea($user, 'agenda', 0, '', 'myactions');
  58. if ($socid < 0) $socid='';
  59. $canedit=1;
  60. if (! $user->rights->agenda->myactions->read) accessforbidden();
  61. if (! $user->rights->agenda->allactions->read) $canedit=0;
  62. if (! $user->rights->agenda->allactions->read || $filter =='mine') // If no permission to see all, we show only affected to me
  63. {
  64. $filtert=$user->id;
  65. }
  66. //$action=GETPOST('action','alpha');
  67. $action='show_peruser'; //We use 'show_week' mode
  68. $resourceid=GETPOST("resourceid","int");
  69. $year=GETPOST("year","int")?GETPOST("year","int"):date("Y");
  70. $month=GETPOST("month","int")?GETPOST("month","int"):date("m");
  71. $week=GETPOST("week","int")?GETPOST("week","int"):date("W");
  72. $day=GETPOST("day","int")?GETPOST("day","int"):date("d");
  73. $pid=GETPOST("projectid","int",3);
  74. $status=GETPOST("status");
  75. $type=GETPOST("type");
  76. $maxprint=(isset($_GET["maxprint"])?GETPOST("maxprint"):$conf->global->AGENDA_MAX_EVENTS_DAY_VIEW);
  77. // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
  78. if (GETPOST('actioncode','array'))
  79. {
  80. $actioncode=GETPOST('actioncode','array',3);
  81. if (! count($actioncode)) $actioncode='0';
  82. }
  83. else
  84. {
  85. $actioncode=GETPOST("actioncode","alpha",3)?GETPOST("actioncode","alpha",3):(GETPOST("actioncode")=='0'?'0':(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE));
  86. }
  87. if ($actioncode == '' && empty($actioncodearray)) $actioncode=(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE);
  88. $dateselect=dol_mktime(0, 0, 0, GETPOST('dateselectmonth'), GETPOST('dateselectday'), GETPOST('dateselectyear'));
  89. if ($dateselect > 0)
  90. {
  91. $day=GETPOST('dateselectday');
  92. $month=GETPOST('dateselectmonth');
  93. $year=GETPOST('dateselectyear');
  94. }
  95. $tmp=empty($conf->global->MAIN_DEFAULT_WORKING_HOURS)?'9-18':$conf->global->MAIN_DEFAULT_WORKING_HOURS;
  96. $tmparray=explode('-',$tmp);
  97. $begin_h = GETPOST('begin_h')!=''?GETPOST('begin_h','int'):($tmparray[0] != '' ? $tmparray[0] : 9);
  98. $end_h = GETPOST('end_h')?GETPOST('end_h'):($tmparray[1] != '' ? $tmparray[1] : 18);
  99. if ($begin_h < 0 || $begin_h > 23) $begin_h = 9;
  100. if ($end_h < 1 || $end_h > 24) $end_h = 18;
  101. if ($end_h <= $begin_h) $end_h = $begin_h + 1;
  102. $tmp=empty($conf->global->MAIN_DEFAULT_WORKING_DAYS)?'1-5':$conf->global->MAIN_DEFAULT_WORKING_DAYS;
  103. $tmparray=explode('-',$tmp);
  104. $begin_d = GETPOST('begin_d')?GETPOST('begin_d','int'):($tmparray[0] != '' ? $tmparray[0] : 1);
  105. $end_d = GETPOST('end_d')?GETPOST('end_d'):($tmparray[1] != '' ? $tmparray[1] : 5);
  106. if ($begin_d < 1 || $begin_d > 7) $begin_d = 1;
  107. if ($end_d < 1 || $end_d > 7) $end_d = 7;
  108. if ($end_d < $begin_d) $end_d = $begin_d + 1;
  109. if ($status == '' && ! isset($_GET['status']) && ! isset($_POST['status'])) $status=(empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS)?'':$conf->global->AGENDA_DEFAULT_FILTER_STATUS);
  110. if (empty($action) && ! isset($_GET['action']) && ! isset($_POST['action'])) $action=(empty($conf->global->AGENDA_DEFAULT_VIEW)?'show_month':$conf->global->AGENDA_DEFAULT_VIEW);
  111. if (GETPOST('viewcal') && $action != 'show_day' && $action != 'show_week' && $action != 'show_peruser') {
  112. $action='show_month'; $day='';
  113. } // View by month
  114. if (GETPOST('viewweek') || $action == 'show_week') {
  115. $action='show_week'; $week=($week?$week:date("W")); $day=($day?$day:date("d"));
  116. } // View by week
  117. if (GETPOST('viewday') || $action == 'show_day') {
  118. $action='show_day'; $day=($day?$day:date("d"));
  119. } // View by day
  120. $langs->load("users");
  121. $langs->load("agenda");
  122. $langs->load("other");
  123. $langs->load("commercial");
  124. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  125. $hookmanager->initHooks(array('agenda'));
  126. /*
  127. * Actions
  128. */
  129. if ($action =='delete_action')
  130. {
  131. $event = new ActionComm($db);
  132. $event->fetch($actionid);
  133. $result=$event->delete();
  134. }
  135. /*
  136. * View
  137. */
  138. $help_url='EN:Module_Agenda_En|FR:Module_Agenda|ES:M&oacute;dulo_Agenda';
  139. llxHeader('',$langs->trans("Agenda"),$help_url);
  140. $form=new Form($db);
  141. $companystatic=new Societe($db);
  142. $now=dol_now();
  143. $nowarray=dol_getdate($now);
  144. $nowyear=$nowarray['year'];
  145. $nowmonth=$nowarray['mon'];
  146. $nowday=$nowarray['mday'];
  147. // Define list of all external calendars (global setup)
  148. $listofextcals=array();
  149. $prev = dol_get_first_day_week($day, $month, $year);
  150. $first_day = $prev['first_day'];
  151. $first_month = $prev['first_month'];
  152. $first_year = $prev['first_year'];
  153. $week = $prev['week'];
  154. $day = (int) $day;
  155. $next = dol_get_next_week($day, $week, $month, $year);
  156. $next_year = $next['year'];
  157. $next_month = $next['month'];
  158. $next_day = $next['day'];
  159. $max_day_in_month = date("t",dol_mktime(0,0,0,$month,1,$year));
  160. $tmpday = $first_day;
  161. //print 'xx'.$prev_year.'-'.$prev_month.'-'.$prev_day;
  162. //print 'xx'.$next_year.'-'.$next_month.'-'.$next_day;
  163. $title=$langs->trans("DoneAndToDoActions");
  164. if ($status == 'done') $title=$langs->trans("DoneActions");
  165. if ($status == 'todo') $title=$langs->trans("ToDoActions");
  166. $param='';
  167. if ($actioncode || isset($_GET['actioncode']) || isset($_POST['actioncode'])) $param.="&actioncode=".$actioncode;
  168. if ($resourceid > 0) $param.="&resourceid=".$resourceid;
  169. if ($status || isset($_GET['status']) || isset($_POST['status'])) $param.="&status=".$status;
  170. if ($filter) $param.="&filter=".$filter;
  171. if ($filtert) $param.="&filtert=".$filtert;
  172. if ($usergroup) $param.="&usergroup=".$usergroup;
  173. if ($socid) $param.="&socid=".$socid;
  174. if ($showbirthday) $param.="&showbirthday=1";
  175. if ($pid) $param.="&projectid=".$pid;
  176. if ($type) $param.="&type=".$type;
  177. if ($action == 'show_day' || $action == 'show_week' || $action == 'show_month' || $action != 'show_peruser') $param.='&action='.$action;
  178. $param.="&maxprint=".$maxprint;
  179. $prev = dol_get_first_day_week($day, $month, $year);
  180. //print "day=".$day." month=".$month." year=".$year;
  181. //var_dump($prev); exit;
  182. $prev_year = $prev['prev_year'];
  183. $prev_month = $prev['prev_month'];
  184. $prev_day = $prev['prev_day'];
  185. $first_day = $prev['first_day'];
  186. $first_month= $prev['first_month'];
  187. $first_year = $prev['first_year'];
  188. $week = $prev['week'];
  189. $day = (int) $day;
  190. $next = dol_get_next_week($first_day, $week, $first_month, $first_year);
  191. $next_year = $next['year'];
  192. $next_month = $next['month'];
  193. $next_day = $next['day'];
  194. // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
  195. $firstdaytoshow=dol_mktime(0,0,0,$first_month,$first_day,$first_year);
  196. $lastdaytoshow=dol_time_plus_duree($firstdaytoshow, 7, 'd');
  197. //print $firstday.'-'.$first_month.'-'.$first_year;
  198. //print dol_print_date($firstdaytoshow,'dayhour');
  199. //print dol_print_date($lastdaytoshow,'dayhour');
  200. $max_day_in_month = date("t",dol_mktime(0,0,0,$month,1,$year));
  201. $tmpday = $first_day;
  202. $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";
  203. $nav.=" <span id=\"month_name\">".dol_print_date(dol_mktime(0,0,0,$first_month,$first_day,$first_year),"%Y").", ".$langs->trans("Week")." ".$week;
  204. $nav.=" </span>\n";
  205. $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";
  206. $nav.=" &nbsp; (<a href=\"?year=".$nowyear."&amp;month=".$nowmonth."&amp;day=".$nowday.$param."\">".$langs->trans("Today")."</a>)";
  207. $picto='calendarweek';
  208. $nav.=' &nbsp; <form name="dateselect" action="'.$_SERVER["PHP_SELF"].'?action=show_peruser'.$param.'">';
  209. $nav.='<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
  210. $nav.='<input type="hidden" name="action" value="' . $action . '">';
  211. $nav.='<input type="hidden" name="filtert" value="' . $filtert . '">';
  212. $nav.='<input type="hidden" name="usergroup" value="' . $usergroup . '">';
  213. $nav.='<input type="hidden" name="actioncode" value="' . $actioncode . '">';
  214. $nav.='<input type="hidden" name="resourceid" value="' . $resourceid . '">';
  215. $nav.='<input type="hidden" name="status" value="' . $status . '">';
  216. $nav.='<input type="hidden" name="socid" value="' . $socid . '">';
  217. $nav.='<input type="hidden" name="projectid" value="' . $projectid . '">';
  218. $nav.='<input type="hidden" name="begin_h" value="' . $begin_h . '">';
  219. $nav.='<input type="hidden" name="end_h" value="' . $end_h . '">';
  220. $nav.='<input type="hidden" name="begin_d" value="' . $begin_d . '">';
  221. $nav.='<input type="hidden" name="end_d" value="' . $end_d . '">';
  222. $nav.='<input type="hidden" name="showbirthday" value="' . $showbirthday . '">';
  223. $nav.=$form->select_date($dateselect, 'dateselect', 0, 0, 1, '', 1, 0, 1);
  224. $nav.=' <input type="submit" name="submitdateselect" class="button" value="'.$langs->trans("Refresh").'">';
  225. $nav.='</form>';
  226. // Must be after the nav definition
  227. $param.='&year='.$year.'&month='.$month.($day?'&day='.$day:'');
  228. //print 'x'.$param;
  229. $tabactive='';
  230. if ($action == 'show_month') $tabactive='cardmonth';
  231. if ($action == 'show_week') $tabactive='cardweek';
  232. if ($action == 'show_day') $tabactive='cardday';
  233. if ($action == 'show_list') $tabactive='cardlist';
  234. if ($action == 'show_peruser') $tabactive='cardperuser';
  235. $paramnoaction=preg_replace('/action=[a-z_]+/','',$param);
  236. $head = calendars_prepare_head($paramnoaction);
  237. dol_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action');
  238. print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, $listofextcals, $actioncode, $usergroup, '', $resourceid);
  239. dol_fiche_end();
  240. $showextcals=$listofextcals;
  241. // Legend
  242. if ($conf->use_javascript_ajax)
  243. {
  244. $s='';
  245. $s.='<script type="text/javascript">' . "\n";
  246. $s.='jQuery(document).ready(function () {' . "\n";
  247. $s.='jQuery("#check_mytasks").click(function() { jQuery(".family_mytasks").toggle(); jQuery(".family_other").toggle(); });' . "\n";
  248. $s.='jQuery("#check_birthday").click(function() { jQuery(".family_birthday").toggle(); });' . "\n";
  249. $s.='jQuery(".family_birthday").toggle();' . "\n";
  250. if ($action=="show_week" || $action=="show_month" || empty($action))
  251. {
  252. $s.='jQuery( "td.sortable" ).sortable({connectWith: ".sortable",placeholder: "ui-state-highlight",items: "div:not(.unsortable)", receive: function( event, ui ) {';
  253. $s.='var frm=jQuery("#move_event");frm.attr("action",ui.item.find("a.cal_event").attr("href")).children("#newdate").val(jQuery(event.target).closest("div").attr("id"));frm.submit();}});'."\n";
  254. }
  255. $s.='});' . "\n";
  256. $s.='</script>' . "\n";
  257. if (! empty($conf->use_javascript_ajax))
  258. {
  259. $s.='<div class="nowrap clear float"><input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> ' . $langs->trans("LocalAgenda").' &nbsp; </div>';
  260. if (is_array($showextcals) && count($showextcals) > 0)
  261. {
  262. foreach ($showextcals as $val)
  263. {
  264. $htmlname = md5($val['name']);
  265. $s.='<script type="text/javascript">' . "\n";
  266. $s.='jQuery(document).ready(function () {' . "\n";
  267. $s.=' jQuery("#check_ext' . $htmlname . '").click(function() {';
  268. $s.=' /* alert("'.$htmlname.'"); */';
  269. $s.=' jQuery(".family_ext' . $htmlname . '").toggle();';
  270. $s.=' });' . "\n";
  271. $s.='});' . "\n";
  272. $s.='</script>' . "\n";
  273. $s.='<div class="nowrap float"><input type="checkbox" id="check_ext' . $htmlname . '" name="check_ext' . $htmlname . '" checked> ' . $val ['name'] . ' &nbsp; </div>';
  274. }
  275. }
  276. //$s.='<div class="nowrap float"><input type="checkbox" id="check_birthday" name="check_birthday"> '.$langs->trans("AgendaShowBirthdayEvents").' &nbsp; </div>';
  277. // Calendars from hooks
  278. $parameters=array(); $object=null;
  279. $reshook=$hookmanager->executeHooks('addCalendarChoice',$parameters,$object,$action);
  280. if (empty($reshook))
  281. {
  282. $s.= $hookmanager->resPrint;
  283. }
  284. elseif ($reshook > 1)
  285. {
  286. $s = $hookmanager->resPrint;
  287. }
  288. }
  289. }
  290. $link='';
  291. print load_fiche_titre($s, $link.' &nbsp; &nbsp; '.$nav, '');
  292. // Get event in an array
  293. $eventarray=array();
  294. $sql = 'SELECT';
  295. if ($usergroup > 0) $sql.=" DISTINCT";
  296. $sql.= ' a.id, a.label,';
  297. $sql.= ' a.datep,';
  298. $sql.= ' a.datep2,';
  299. $sql.= ' a.percent,';
  300. $sql.= ' a.fk_user_author,a.fk_user_action,';
  301. $sql.= ' a.transparency, a.priority, a.fulldayevent, a.location,';
  302. $sql.= ' a.fk_soc, a.fk_contact, a.fk_element, a.elementtype,';
  303. $sql.= ' ca.code, ca.color';
  304. $sql.= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm as ca, '.MAIN_DB_PREFIX."actioncomm as a";
  305. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
  306. // We must filter on resource table
  307. if ($resourceid > 0) $sql.=", ".MAIN_DB_PREFIX."element_resources as r";
  308. // We must filter on assignement table
  309. if ($filtert > 0 || $usergroup > 0) $sql.=", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
  310. if ($usergroup > 0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
  311. $sql.= ' WHERE a.fk_action = ca.id';
  312. $sql.= ' AND a.entity IN ('.getEntity('agenda').')';
  313. // Condition on actioncode
  314. if (! empty($actioncode))
  315. {
  316. if (empty($conf->global->AGENDA_USE_EVENT_TYPE))
  317. {
  318. if ($actioncode == 'AC_NON_AUTO') $sql.= " AND ca.type != 'systemauto'";
  319. elseif ($actioncode == 'AC_ALL_AUTO') $sql.= " AND ca.type = 'systemauto'";
  320. else
  321. {
  322. if ($actioncode == 'AC_OTH') $sql.= " AND ca.type != 'systemauto'";
  323. if ($actioncode == 'AC_OTH_AUTO') $sql.= " AND ca.type = 'systemauto'";
  324. }
  325. }
  326. else
  327. {
  328. if ($actioncode == 'AC_NON_AUTO') $sql.= " AND ca.type != 'systemauto'";
  329. elseif ($actioncode == 'AC_ALL_AUTO') $sql.= " AND ca.type = 'systemauto'";
  330. else
  331. {
  332. $sql.=" AND ca.code IN ('".implode("','", explode(',',$actioncode))."')";
  333. }
  334. }
  335. }
  336. if ($resourceid > 0) $sql.=" AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".$db->escape($resourceid);
  337. if ($pid) $sql.=" AND a.fk_project=".$db->escape($pid);
  338. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")";
  339. if ($socid > 0) $sql.= ' AND a.fk_soc = '.$socid;
  340. // We must filter on assignement table
  341. if ($filtert > 0 || $usergroup > 0) $sql.= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
  342. if ($action == 'show_day')
  343. {
  344. $sql.= " AND (";
  345. $sql.= " (a.datep BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,$day,$year))."'";
  346. $sql.= " AND '".$db->idate(dol_mktime(23,59,59,$month,$day,$year))."')";
  347. $sql.= " OR ";
  348. $sql.= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,$day,$year))."'";
  349. $sql.= " AND '".$db->idate(dol_mktime(23,59,59,$month,$day,$year))."')";
  350. $sql.= " OR ";
  351. $sql.= " (a.datep < '".$db->idate(dol_mktime(0,0,0,$month,$day,$year))."'";
  352. $sql.= " AND a.datep2 > '".$db->idate(dol_mktime(23,59,59,$month,$day,$year))."')";
  353. $sql.= ')';
  354. }
  355. else
  356. {
  357. // To limit array
  358. $sql.= " AND (";
  359. $sql.= " (a.datep BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,1,$year)-(60*60*24*7))."'"; // Start 7 days before
  360. $sql.= " AND '".$db->idate(dol_mktime(23,59,59,$month,28,$year)+(60*60*24*10))."')"; // End 7 days after + 3 to go from 28 to 31
  361. $sql.= " OR ";
  362. $sql.= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,1,$year)-(60*60*24*7))."'";
  363. $sql.= " AND '".$db->idate(dol_mktime(23,59,59,$month,28,$year)+(60*60*24*10))."')";
  364. $sql.= " OR ";
  365. $sql.= " (a.datep < '".$db->idate(dol_mktime(0,0,0,$month,1,$year)-(60*60*24*7))."'";
  366. $sql.= " AND a.datep2 > '".$db->idate(dol_mktime(23,59,59,$month,28,$year)+(60*60*24*10))."')";
  367. $sql.= ')';
  368. }
  369. if ($type) $sql.= " AND ca.id = ".$type;
  370. if ($status == '0') { $sql.= " AND a.percent = 0"; }
  371. if ($status == '-1') { $sql.= " AND a.percent = -1"; } // Not applicable
  372. if ($status == '50') { $sql.= " AND (a.percent > 0 AND a.percent < 100)"; } // Running already started
  373. if ($status == 'done' || $status == '100') { $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep2 <= '".$db->idate($now)."'))"; }
  374. if ($status == 'todo') { $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep2 > '".$db->idate($now)."'))"; }
  375. // We must filter on assignement table
  376. if ($filtert > 0 || $usergroup > 0)
  377. {
  378. $sql.= " AND (";
  379. if ($filtert > 0) $sql.= "ar.fk_element = ".$filtert;
  380. if ($usergroup > 0) $sql.= ($filtert>0?" OR ":"")." ugu.fk_usergroup = ".$usergroup;
  381. $sql.= ")";
  382. }
  383. // Sort on date
  384. $sql.= ' ORDER BY fk_user_action, datep'; //fk_user_action
  385. //print $sql;
  386. dol_syslog("comm/action/peruser.php", LOG_DEBUG);
  387. $resql=$db->query($sql);
  388. if ($resql)
  389. {
  390. $num = $db->num_rows($resql);
  391. $i=0;
  392. while ($i < $num)
  393. {
  394. $obj = $db->fetch_object($resql);
  395. // Discard auto action if option is on
  396. if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->code == 'AC_OTH_AUTO')
  397. {
  398. $i++;
  399. continue;
  400. }
  401. // Create a new object action
  402. $event=new ActionComm($db);
  403. $event->id=$obj->id;
  404. $event->datep=$db->jdate($obj->datep); // datep and datef are GMT date
  405. $event->datef=$db->jdate($obj->datep2);
  406. $event->type_code=$obj->code;
  407. $event->type_color=$obj->color;
  408. //$event->libelle=$obj->label; // deprecated
  409. $event->label=$obj->label;
  410. $event->percentage=$obj->percent;
  411. //$event->author->id=$obj->fk_user_author; // user id of creator
  412. $event->authorid=$obj->fk_user_author; // user id of creator
  413. $event->userownerid=$obj->fk_user_action; // user id of owner
  414. $event->fetch_userassigned(); // This load $event->userassigned
  415. $event->priority=$obj->priority;
  416. $event->fulldayevent=$obj->fulldayevent;
  417. $event->location=$obj->location;
  418. $event->transparency=$obj->transparency;
  419. $event->socid=$obj->fk_soc;
  420. $event->contactid=$obj->fk_contact;
  421. //$event->societe->id=$obj->fk_soc; // deprecated
  422. //$event->contact->id=$obj->fk_contact; // deprecated
  423. $event->fk_element=$obj->fk_element;
  424. $event->elementtype=$obj->elementtype;
  425. // Defined date_start_in_calendar and date_end_in_calendar property
  426. // They are date start and end of action but modified to not be outside calendar view.
  427. if ($event->percentage <= 0)
  428. {
  429. $event->date_start_in_calendar=$event->datep;
  430. if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar=$event->datef;
  431. else $event->date_end_in_calendar=$event->datep;
  432. }
  433. else
  434. {
  435. $event->date_start_in_calendar=$event->datep;
  436. if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar=$event->datef;
  437. else $event->date_end_in_calendar=$event->datep;
  438. }
  439. // Define ponctual property
  440. if ($event->date_start_in_calendar == $event->date_end_in_calendar)
  441. {
  442. $event->ponctuel=1;
  443. }
  444. // Check values
  445. if ($event->date_end_in_calendar < $firstdaytoshow ||
  446. $event->date_start_in_calendar >= $lastdaytoshow)
  447. {
  448. // This record is out of visible range
  449. }
  450. else
  451. {
  452. if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
  453. if ($event->date_end_in_calendar >= $lastdaytoshow) $event->date_end_in_calendar=($lastdaytoshow - 1);
  454. // Add an entry in actionarray for each day
  455. $daycursor=$event->date_start_in_calendar;
  456. $annee = date('Y',$daycursor);
  457. $mois = date('m',$daycursor);
  458. $jour = date('d',$daycursor);
  459. // Loop on each day covered by action to prepare an index to show on calendar
  460. $loop=true; $j=0;
  461. $daykey=dol_mktime(0,0,0,$mois,$jour,$annee);
  462. do
  463. {
  464. //if ($event->id==408) print 'daykey='.$daykey.' '.$event->datep.' '.$event->datef.'<br>';
  465. $eventarray[$daykey][]=$event;
  466. $j++;
  467. $daykey+=60*60*24;
  468. if ($daykey > $event->date_end_in_calendar) $loop=false;
  469. }
  470. while ($loop);
  471. //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
  472. //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>';
  473. }
  474. $i++;
  475. }
  476. }
  477. else
  478. {
  479. dol_print_error($db);
  480. }
  481. $maxnbofchar=18;
  482. $cachethirdparties=array();
  483. $cachecontacts=array();
  484. // Define theme_datacolor array
  485. $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/graph-color.php";
  486. if (is_readable($color_file))
  487. {
  488. include_once $color_file;
  489. }
  490. if (! is_array($theme_datacolor)) $theme_datacolor=array(array(120,130,150), array(200,160,180), array(190,190,220));
  491. $newparam=$param; // newparam is for birthday links
  492. $newparam=preg_replace('/showbirthday=/i','showbirthday_=',$newparam); // To avoid replacement when replace day= is done
  493. $newparam=preg_replace('/action=show_month&?/i','',$newparam);
  494. $newparam=preg_replace('/action=show_week&?/i','',$newparam);
  495. $newparam=preg_replace('/day=[0-9]+&?/i','',$newparam);
  496. $newparam=preg_replace('/month=[0-9]+&?/i','',$newparam);
  497. $newparam=preg_replace('/year=[0-9]+&?/i','',$newparam);
  498. $newparam=preg_replace('/viewweek=[0-9]+&?/i','',$newparam);
  499. $newparam=preg_replace('/showbirthday_=/i','showbirthday=',$newparam); // Restore correct parameter
  500. $newparam.='&viewweek=1';
  501. echo '<form id="move_event" action="" method="POST"><input type="hidden" name="action" value="mupdate">';
  502. echo '<input type="hidden" name="backtopage" value="'.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'">';
  503. echo '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  504. echo '<input type="hidden" name="newdate" id="newdate">' ;
  505. echo '</form>';
  506. // Line header with list of days
  507. //print "begin_d=".$begin_d." end_d=".$end_d;
  508. echo '<div class="div-table-responsive">';
  509. echo '<table width="100%" class="noborder nocellnopadd cal_month">';
  510. echo '<tr class="liste_titre">';
  511. echo '<td></td>';
  512. $i=0; // 0 = sunday,
  513. while ($i < 7)
  514. {
  515. if (($i + 1) < $begin_d || ($i + 1) > $end_d)
  516. {
  517. $i++;
  518. continue;
  519. }
  520. echo '<td align="center" colspan="'.($end_h - $begin_h).'">';
  521. echo $langs->trans("Day".(($i+(isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1)) % 7));
  522. print "<br>";
  523. if ($i) print dol_print_date(dol_time_plus_duree($firstdaytoshow, $i, 'd'),'day');
  524. else print dol_print_date($firstdaytoshow,'day');
  525. echo "</td>\n";
  526. $i++;
  527. }
  528. echo "</tr>\n";
  529. echo '<tr class="liste_titre">';
  530. echo '<td></td>';
  531. $i=0;
  532. while ($i < 7)
  533. {
  534. if (($i + 1) < $begin_d || ($i + 1) > $end_d)
  535. {
  536. $i++;
  537. continue;
  538. }
  539. for ($h = $begin_h; $h < $end_h; $h++)
  540. {
  541. echo '<td align="center">';
  542. print '<small style="font-family: courier">'.sprintf("%02d",$h).'</small>';
  543. print "</td>";
  544. }
  545. echo "</td>\n";
  546. $i++;
  547. }
  548. echo "</tr>\n";
  549. // Define $usernames
  550. $usernames = array(); //init
  551. $usernamesid = array();
  552. /* Use this to have list of users only if users have events */
  553. if (! empty($conf->global->AGENDA_SHOWOWNERONLY_ONPERUSERVIEW))
  554. {
  555. foreach ($eventarray as $daykey => $notused)
  556. {
  557. // Get all assigned users for each event
  558. foreach ($eventarray[$daykey] as $index => $event)
  559. {
  560. $event->fetch_userassigned();
  561. $listofuserid=$event->userassigned;
  562. foreach($listofuserid as $userid => $tmp)
  563. {
  564. if (! in_array($userid, $usernamesid)) $usernamesid[$userid] = $userid;
  565. }
  566. }
  567. }
  568. }
  569. /* Use this list to have for all users */
  570. else
  571. {
  572. $sql = "SELECT u.rowid, u.lastname as lastname, u.firstname, u.statut, u.login, u.admin, u.entity";
  573. $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
  574. if ($usergroup > 0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ug ON u.rowid = ug.fk_user";
  575. $sql.= " WHERE u.statut = 1 AND u.entity IN (".getEntity('user').")";
  576. if ($usergroup > 0) $sql.= " AND ug.fk_usergroup = ".$usergroup;
  577. //print $sql;
  578. $resql=$db->query($sql);
  579. if ($resql)
  580. {
  581. $num = $db->num_rows($resql);
  582. $i = 0;
  583. if ($num)
  584. {
  585. while ($i < $num)
  586. {
  587. $obj = $db->fetch_object($resql);
  588. $usernamesid[$obj->rowid]=$obj->rowid;
  589. $i++;
  590. }
  591. }
  592. }
  593. else dol_print_error($db);
  594. }
  595. //var_dump($usernamesid);
  596. foreach($usernamesid as $id)
  597. {
  598. $tmpuser=new User($db);
  599. $result=$tmpuser->fetch($id);
  600. $usernames[]=$tmpuser;
  601. }
  602. /*
  603. if ($filtert > 0)
  604. {
  605. $tmpuser = new User($db);
  606. $tmpuser->fetch($filtert);
  607. $usernames[] = $tmpuser;
  608. }
  609. else if ($usergroup)
  610. {
  611. $tmpgroup = new UserGroup($db);
  612. $tmpgroup->fetch($usergroup);
  613. $usernames = $tmpgroup->listUsersForGroup();
  614. }
  615. else
  616. {
  617. $tmpgroup = new UserGroup($db);
  618. //$tmpgroup->fetch($usergroup); No fetch, we want all users for all groups
  619. $usernames = $tmpgroup->listUsersForGroup();
  620. }*/
  621. // Load array of colors by type
  622. $colorsbytype=array();
  623. $labelbytype=array();
  624. $sql="SELECT code, color, libelle FROM ".MAIN_DB_PREFIX."c_actioncomm ORDER BY position";
  625. $resql=$db->query($sql);
  626. while ($obj = $db->fetch_object($resql))
  627. {
  628. $colorsbytype[$obj->code]=$obj->color;
  629. $labelbytype[$obj->code]=$obj->libelle;
  630. }
  631. // Loop on each user to show calendar
  632. $todayarray=dol_getdate($now,'fast');
  633. $sav = $tmpday;
  634. $showheader = true;
  635. $var = false;
  636. foreach ($usernames as $username)
  637. {
  638. $var = ! $var;
  639. echo "<tr>";
  640. echo '<td class="cal_current_month cal_peruserviewname'.($var?' cal_impair':'').'">';
  641. print $username->getNomUrl(-1,'',0,0,24,1,'');
  642. print '</td>';
  643. $tmpday = $sav;
  644. // Lopp on each day of week
  645. $i = 0;
  646. for ($iter_day = 0; $iter_day < 8; $iter_day++)
  647. {
  648. if (($i + 1) < $begin_d || ($i + 1) > $end_d)
  649. {
  650. $i++;
  651. continue;
  652. }
  653. // Show days of the current week
  654. $curtime = dol_time_plus_duree($firstdaytoshow, $iter_day, 'd');
  655. $tmparray = dol_getdate($curtime,'fast');
  656. $tmpday = $tmparray['mday'];
  657. $tmpmonth = $tmparray['mon'];
  658. $tmpyear = $tmparray['year'];
  659. $style='cal_current_month';
  660. if ($iter_day == 6) $style.=' cal_other_month';
  661. $today=0;
  662. if ($todayarray['mday']==$tmpday && $todayarray['mon']==$tmpmonth && $todayarray['year']==$tmpyear) $today=1;
  663. if ($today) $style='cal_today_peruser';
  664. show_day_events2($username, $tmpday, $tmpmonth, $tmpyear, $monthshown, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, $showheader, $colorsbytype, $var);
  665. $i++;
  666. }
  667. echo "</tr>\n";
  668. $showheader = false;
  669. }
  670. echo "</table>\n";
  671. echo '</div>';
  672. if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
  673. {
  674. $langs->load("commercial");
  675. print '<br>'.$langs->trans("Legend").': <br>';
  676. foreach($colorsbytype as $code => $color)
  677. {
  678. if ($color)
  679. {
  680. print '<div style="float: left; padding: 2px; margin-right: 6px;"><div style="'.($color?'background: #'.$color.';':'').'width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
  681. print $langs->trans("Action".$code)!="Action".$code?$langs->trans("Action".$code):$labelbytype[$code];
  682. //print $code;
  683. print '</div>';
  684. }
  685. }
  686. //$color=sprintf("%02x%02x%02x",$theme_datacolor[0][0],$theme_datacolor[0][1],$theme_datacolor[0][2]);
  687. print '<div style="float: left; padding: 2px; margin-right: 6px;"><div class="peruser_busy" style="width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
  688. print $langs->trans("Other");
  689. print '</div>';
  690. /* TODO Show this if at least one cumulated event
  691. print '<div style="float: left; padding: 2px; margin-right: 6px;"><div style="background: #222222; width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
  692. print $langs->trans("SeveralEvents");
  693. print '</div>';
  694. */
  695. }
  696. // Add js code to manage click on a box
  697. print '<script type="text/javascript" language="javascript">
  698. jQuery(document).ready(function() {
  699. jQuery(".onclickopenref").click(function() {
  700. var ref=$(this).attr(\'ref\');
  701. var res = ref.split("_");
  702. var userid = res[1];
  703. var year = res[2];
  704. var month = res[3];
  705. var day = res[4];
  706. var hour = res[5];
  707. var min = res[6];
  708. var ids = res[7];
  709. if (ids == \'none\') /* No event */
  710. {
  711. /* alert(\'no event\'); */
  712. 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).'"
  713. window.location.href = url;
  714. }
  715. else if (ids.indexOf(",") > -1) /* There is several events */
  716. {
  717. /* alert(\'several events\'); */
  718. url = "'.DOL_URL_ROOT.'/comm/action/listactions.php?filtert="+userid+"&dateselectyear="+year+"&dateselectmonth="+month+"&dateselectday="+day;
  719. window.location.href = url;
  720. }
  721. else /* One event */
  722. {
  723. /* alert(\'one event\'); */
  724. url = "'.DOL_URL_ROOT.'/comm/action/card.php?action=view&id="+ids
  725. window.location.href = url;
  726. }
  727. });
  728. });
  729. </script>';
  730. llxFooter();
  731. $db->close();
  732. /**
  733. * Show event line of a particular day for a user
  734. *
  735. * @param string $username Login
  736. * @param int $day Day
  737. * @param int $month Month
  738. * @param int $year Year
  739. * @param int $monthshown Current month shown in calendar view
  740. * @param string $style Style to use for this day
  741. * @param array $eventarray Array of events
  742. * @param int $maxprint Nb of actions to show each day on month view (0 means no limit)
  743. * @param int $maxnbofchar Nb of characters to show for event line
  744. * @param string $newparam Parameters on current URL
  745. * @param int $showinfo Add extended information (used by day view)
  746. * @param int $minheight Minimum height for each event. 60px by default.
  747. * @param boolean $showheader Show header
  748. * @param array $colorsbytype Array with colors by type
  749. * @param bool $var true or false for alternat style on tr/td
  750. * @return void
  751. */
  752. 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)
  753. {
  754. global $db;
  755. global $user, $conf, $langs, $hookmanager, $action;
  756. global $filter, $filtert, $status, $actioncode; // Filters used into search form
  757. global $theme_datacolor; // Array with a list of different we can use (come from theme)
  758. global $cachethirdparties, $cachecontacts, $colorindexused;
  759. global $begin_h, $end_h;
  760. $cases1 = array(); // Color first half hour
  761. $cases2 = array(); // Color second half hour
  762. $curtime = dol_mktime(0, 0, 0, $month, $day, $year);
  763. $i=0; $nummytasks=0; $numother=0; $numbirthday=0; $numical=0; $numicals=array();
  764. $ymd=sprintf("%04d",$year).sprintf("%02d",$month).sprintf("%02d",$day);
  765. $nextindextouse=count($colorindexused); // At first run, this is 0, so fist user has 0, next 1, ...
  766. //if ($username->id && $day==1) var_dump($eventarray);
  767. // We are in a particular day for $username, now we scan all events
  768. foreach ($eventarray as $daykey => $notused)
  769. {
  770. $annee = date('Y',$daykey);
  771. $mois = date('m',$daykey);
  772. $jour = date('d',$daykey);
  773. //print $annee.'-'.$mois.'-'.$jour.' '.$year.'-'.$month.'-'.$day."<br>\n";
  774. if ($day==$jour && $month==$mois && $year==$annee) // Is it the day we are looking for when calling function ?
  775. {
  776. // Scan all event for this date
  777. foreach ($eventarray[$daykey] as $index => $event)
  778. {
  779. //var_dump($event);
  780. $keysofuserassigned=array_keys($event->userassigned);
  781. if (! in_array($username->id,$keysofuserassigned)) continue; // We discard record if event is from another user than user we want to show
  782. //if ($username->id != $event->userownerid) continue; // We discard record if event is from another user than user we want to show
  783. $parameters=array();
  784. $reshook=$hookmanager->executeHooks('formatEvent',$parameters,$event,$action); // Note that $action and $object may have been modified by some hooks
  785. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  786. $ponct=($event->date_start_in_calendar == $event->date_end_in_calendar);
  787. // Define $color (Hex string like '0088FF') and $cssclass of event
  788. $color=-1; $cssclass=''; $colorindex=-1;
  789. if (in_array($user->id, $keysofuserassigned))
  790. {
  791. $nummytasks++; $cssclass='family_mytasks';
  792. if (! empty($conf->global->AGENDA_USE_EVENT_TYPE)) $color=$event->type_color;
  793. }
  794. else if ($event->type_code == 'ICALEVENT')
  795. {
  796. $numical++;
  797. if (! empty($event->icalname))
  798. {
  799. if (! isset($numicals[dol_string_nospecial($event->icalname)])) {
  800. $numicals[dol_string_nospecial($event->icalname)] = 0;
  801. }
  802. $numicals[dol_string_nospecial($event->icalname)]++;
  803. }
  804. $color=$event->icalcolor;
  805. $cssclass=(! empty($event->icalname)?'family_ext'.md5($event->icalname):'family_other unsortable');
  806. }
  807. else if ($event->type_code == 'BIRTHDAY')
  808. {
  809. $numbirthday++; $colorindex=2; $cssclass='family_birthday unsortable'; $color=sprintf("%02x%02x%02x",$theme_datacolor[$colorindex][0],$theme_datacolor[$colorindex][1],$theme_datacolor[$colorindex][2]);
  810. }
  811. else
  812. {
  813. $numother++; $cssclass='family_other';
  814. if (! empty($conf->global->AGENDA_USE_EVENT_TYPE)) $color=$event->type_color;
  815. }
  816. if ($color < 0) // Color was not forced. Set color according to color index.
  817. {
  818. // Define color index if not yet defined
  819. $idusertouse=($event->userownerid?$event->userownerid:0);
  820. if (isset($colorindexused[$idusertouse]))
  821. {
  822. $colorindex=$colorindexused[$idusertouse]; // Color already assigned to this user
  823. }
  824. else
  825. {
  826. $colorindex=$nextindextouse;
  827. $colorindexused[$idusertouse]=$colorindex;
  828. if (! empty($theme_datacolor[$nextindextouse+1])) $nextindextouse++; // Prepare to use next color
  829. }
  830. // Define color
  831. $color=sprintf("%02x%02x%02x",$theme_datacolor[$colorindex][0],$theme_datacolor[$colorindex][1],$theme_datacolor[$colorindex][2]);
  832. }
  833. //$cssclass=$cssclass.' '.$cssclass.'_day_'.$ymd;
  834. // Define all rects with event (cases1 is first half hour, cases2 is second half hour)
  835. for ($h = $begin_h; $h < $end_h; $h++)
  836. {
  837. //if ($username->id == 1 && $day==1) print 'h='.$h;
  838. $newcolor = ''; //init
  839. if (empty($event->fulldayevent))
  840. {
  841. $a = dol_mktime((int) $h,0,0,$month,$day,$year,false,0);
  842. $b = dol_mktime((int) $h,30,0,$month,$day,$year,false,0);
  843. $c = dol_mktime((int) $h+1,0,0,$month,$day,$year,false,0);
  844. $dateendtouse=$event->date_end_in_calendar;
  845. if ($dateendtouse==$event->date_start_in_calendar) $dateendtouse++;
  846. //print dol_print_date($event->date_start_in_calendar,'dayhour').'-'.dol_print_date($a,'dayhour').'-'.dol_print_date($b,'dayhour').'<br>';
  847. if ($event->date_start_in_calendar < $b && $dateendtouse > $a)
  848. {
  849. $busy=$event->transparency;
  850. $cases1[$h][$event->id]['busy']=$busy;
  851. $cases1[$h][$event->id]['string']=dol_print_date($event->date_start_in_calendar,'dayhour');
  852. if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar)
  853. {
  854. $tmpa=dol_getdate($event->date_start_in_calendar,true);
  855. $tmpb=dol_getdate($event->date_end_in_calendar,true);
  856. if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) $cases1[$h][$event->id]['string'].='-'.dol_print_date($event->date_end_in_calendar,'hour');
  857. else $cases1[$h][$event->id]['string'].='-'.dol_print_date($event->date_end_in_calendar,'dayhour');
  858. }
  859. $cases1[$h][$event->id]['string'].=' - '.$event->label;
  860. $cases1[$h][$event->id]['typecode']=$event->type_code;
  861. if ($event->socid)
  862. {
  863. //$cases1[$h][$event->id]['string'].='xxx';
  864. }
  865. $cases1[$h][$event->id]['color']=$color;
  866. }
  867. if ($event->date_start_in_calendar < $c && $dateendtouse > $b)
  868. {
  869. $busy=$event->transparency;
  870. $cases2[$h][$event->id]['busy']=$busy;
  871. $cases2[$h][$event->id]['string']=dol_print_date($event->date_start_in_calendar,'dayhour');
  872. if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar)
  873. {
  874. $tmpa=dol_getdate($event->date_start_in_calendar,true);
  875. $tmpb=dol_getdate($event->date_end_in_calendar,true);
  876. if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) $cases2[$h][$event->id]['string'].='-'.dol_print_date($event->date_end_in_calendar,'hour');
  877. else $cases2[$h][$event->id]['string'].='-'.dol_print_date($event->date_end_in_calendar,'dayhour');
  878. }
  879. $cases2[$h][$event->id]['string'].=' - '.$event->label;
  880. $cases2[$h][$event->id]['typecode']=$event->type_code;
  881. if ($event->socid)
  882. {
  883. //$cases2[$h][$event->id]['string'].='xxx';
  884. }
  885. $cases2[$h][$event->id]['color']=$color;
  886. }
  887. }
  888. else
  889. {
  890. $busy=$event->transparency;
  891. $cases1[$h][$event->id]['busy']=$busy;
  892. $cases2[$h][$event->id]['busy']=$busy;
  893. $cases1[$h][$event->id]['string']=$event->label;
  894. $cases2[$h][$event->id]['string']=$event->label;
  895. $cases1[$h][$event->id]['typecode']=$event->type_code;
  896. $cases2[$h][$event->id]['typecode']=$event->type_code;
  897. $cases1[$h][$event->id]['color']=$color;
  898. $cases2[$h][$event->id]['color']=$color;
  899. }
  900. }
  901. $i++;
  902. }
  903. break; // We found the date we were looking for. No need to search anymore.
  904. }
  905. }
  906. for ($h = $begin_h; $h < $end_h; $h++)
  907. {
  908. $color1='';$color2='';
  909. $style1='';$style2='';
  910. $string1='&nbsp;';$string2='&nbsp;';
  911. $title1='';$title2='';
  912. if (isset($cases1[$h]) && $cases1[$h] != '')
  913. {
  914. //$title1.=count($cases1[$h]).' '.(count($cases1[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
  915. if (count($cases1[$h]) > 1) $title1.=count($cases1[$h]).' '.(count($cases1[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
  916. $string1='&nbsp;';
  917. if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) $style1='peruser_notbusy';
  918. else $style1='peruser_busy';
  919. foreach($cases1[$h] as $id => $ev)
  920. {
  921. if ($ev['busy']) $style1='peruser_busy';
  922. }
  923. }
  924. if (isset($cases2[$h]) && $cases2[$h] != '')
  925. {
  926. //$title2.=count($cases2[$h]).' '.(count($cases2[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
  927. if (count($cases2[$h]) > 1) $title2.=count($cases2[$h]).' '.(count($cases2[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
  928. $string2='&nbsp;';
  929. if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) $style2='peruser_notbusy';
  930. else $style2='peruser_busy';
  931. foreach($cases2[$h] as $id => $ev)
  932. {
  933. if ($ev['busy']) $style2='peruser_busy';
  934. }
  935. }
  936. $ids1='';$ids2='';
  937. if (count($cases1[$h]) && array_keys($cases1[$h])) $ids1=join(',',array_keys($cases1[$h]));
  938. if (count($cases2[$h]) && array_keys($cases2[$h])) $ids2=join(',',array_keys($cases2[$h]));
  939. if ($h == $begin_h) echo '<td class="'.$style.'_peruserleft cal_peruser'.($var?' cal_impair '.$style.'_impair':'').'">';
  940. else echo '<td class="'.$style.' cal_peruser'.($var?' cal_impair '.$style.'_impair':'').'">';
  941. if (count($cases1[$h]) == 1) // only 1 event
  942. {
  943. $output = array_slice($cases1[$h], 0, 1);
  944. $title1=$langs->trans("Ref").' '.$ids1.($title1?' - '.$title1:'');
  945. if ($output[0]['string']) $title1.=($title1?' - ':'').$output[0]['string'];
  946. if ($output[0]['color']) $color1 = $output[0]['color'];
  947. }
  948. else if (count($cases1[$h]) > 1)
  949. {
  950. $title1=$langs->trans("Ref").' '.$ids1.($title1?' - '.$title1:'');
  951. $color1='222222';
  952. }
  953. if (count($cases2[$h]) == 1) // only 1 event
  954. {
  955. $output = array_slice($cases2[$h], 0, 1);
  956. $title2=$langs->trans("Ref").' '.$ids2.($title2?' - '.$title2:'');
  957. if ($output[0]['string']) $title2.=($title2?' - ':'').$output[0]['string'];
  958. if ($output[0]['color']) $color2 = $output[0]['color'];
  959. }
  960. else if (count($cases2[$h]) > 1)
  961. {
  962. $title2=$langs->trans("Ref").' '.$ids2.($title2?' - '.$title2:'');
  963. $color2='222222';
  964. }
  965. print '<table class="nobordernopadding" width="100%">';
  966. print '<tr><td '.($color1?'style="background: #'.$color1.';"':'').'class="'.($style1?$style1.' ':'').'onclickopenref'.($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.'"':'').'>';
  967. print $string1;
  968. print '</td><td '.($color2?'style="background: #'.$color2.';"':'').'class="'.($style2?$style2.' ':'').'onclickopenref'.($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.'"':'').'>';
  969. print $string2;
  970. print '</td></tr>';
  971. print '</table>';
  972. print '</td>';
  973. }
  974. }