peruser.php 50 KB

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