pertype.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  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/pertype.php
  24. * \ingroup agenda
  25. * \brief Tab of calendar events per type
  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_pertype';
  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 = 1;
  105. $end_d = 53;
  106. if ($status == '' && ! isset($_GET['status']) && ! isset($_POST['status'])) $status=(empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS)?'':$conf->global->AGENDA_DEFAULT_FILTER_STATUS);
  107. if (empty($action) && ! isset($_GET['action']) && ! isset($_POST['action'])) $action=(empty($conf->global->AGENDA_DEFAULT_VIEW)?'show_month':$conf->global->AGENDA_DEFAULT_VIEW);
  108. if (GETPOST('viewcal') && $action != 'show_day' && $action != 'show_week' && $action != 'show_peruser') {
  109. $action='show_month'; $day='';
  110. } // View by month
  111. if (GETPOST('viewweek') || $action == 'show_week') {
  112. $action='show_week'; $week=($week?$week:date("W")); $day=($day?$day:date("d"));
  113. } // View by week
  114. if (GETPOST('viewday') || $action == 'show_day') {
  115. $action='show_day'; $day=($day?$day:date("d"));
  116. } // View by day
  117. if (GETPOST('viewyear') || $action == 'show_year') {
  118. $action='show_year';
  119. } // View by year
  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($year, $month);
  150. $first_day = 1;
  151. $first_month = 1;
  152. $first_year = $year;
  153. $week = $prev['week'];
  154. $day = (int) $day;
  155. $next = dol_get_next_day($day, $month, $year);
  156. $next_year = $year + 1;
  157. $next_month = $month;
  158. $next_day = $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' || $action != 'show_pertype') $param.='&action='.$action;
  178. $param.="&maxprint=".$maxprint;
  179. $prev = dol_get_first_day($year, 1);
  180. $prev_year = $year - 1;
  181. $prev_month = $month;
  182. $prev_day = $day;
  183. $first_day = 1;
  184. $first_month= 1;
  185. $first_year = $year;
  186. $week = $prev['week'];
  187. $day = (int) $day;
  188. $next = dol_get_next_day(31, 12, $year);
  189. $next_year = $year + 1;
  190. $next_month = $month;
  191. $next_day = $day;
  192. // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
  193. $firstdaytoshow=dol_mktime(0,0,0,$first_month,$first_day,$first_year);
  194. $lastdaytoshow=dol_time_plus_duree($firstdaytoshow, 7, 'd');
  195. //print $firstday.'-'.$first_month.'-'.$first_year;
  196. //print dol_print_date($firstdaytoshow,'dayhour');
  197. //print dol_print_date($lastdaytoshow,'dayhour');
  198. $max_day_in_month = date("t",dol_mktime(0,0,0,$month,1,$year));
  199. $tmpday = $first_day;
  200. $nav ="<a href=\"?year=".$prev_year."&amp;month=".$prev_month."&amp;day=".$prev_day.$param."\">".img_previous($langs->trans("Previous"))."</a>\n";
  201. $nav.=" <span id=\"month_name\">".dol_print_date(dol_mktime(0,0,0,$first_month,$first_day,$first_year),"%Y")."</span> \n";
  202. $nav.="<a href=\"?year=".$next_year."&amp;month=".$next_month."&amp;day=".$next_day.$param."\">".img_next($langs->trans("Next"))."</a>\n";
  203. $nav.=" &nbsp; (<a href=\"?year=".$nowyear."&amp;month=".$nowmonth."&amp;day=".$nowday.$param."\">".$langs->trans("Today")."</a>)";
  204. $picto='calendarweek';
  205. $nav.=' &nbsp; <form name="dateselect" action="'.$_SERVER["PHP_SELF"].'?action=show_peruser'.$param.'">';
  206. $nav.='<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
  207. $nav.='<input type="hidden" name="action" value="' . $action . '">';
  208. $nav.='<input type="hidden" name="filtert" value="' . $filtert . '">';
  209. $nav.='<input type="hidden" name="usergroup" value="' . $usergroup . '">';
  210. $nav.='<input type="hidden" name="actioncode" value="' . $actioncode . '">';
  211. $nav.='<input type="hidden" name="resourceid" value="' . $resourceid . '">';
  212. $nav.='<input type="hidden" name="status" value="' . $status . '">';
  213. $nav.='<input type="hidden" name="socid" value="' . $socid . '">';
  214. $nav.='<input type="hidden" name="projectid" value="' . $projectid . '">';
  215. $nav.='<input type="hidden" name="begin_h" value="' . $begin_h . '">';
  216. $nav.='<input type="hidden" name="end_h" value="' . $end_h . '">';
  217. $nav.='<input type="hidden" name="begin_d" value="' . $begin_d . '">';
  218. $nav.='<input type="hidden" name="end_d" value="' . $end_d . '">';
  219. $nav.='<input type="hidden" name="showbirthday" value="' . $showbirthday . '">';
  220. $nav.=$form->select_date($dateselect, 'dateselect', 0, 0, 1, '', 1, 0, 1);
  221. $nav.=' <input type="submit" name="submitdateselect" class="button" value="'.$langs->trans("Refresh").'">';
  222. $nav.='</form>';
  223. // Must be after the nav definition
  224. $param.='&year='.$year.'&month='.$month.($day?'&day='.$day:'');
  225. //print 'x'.$param;
  226. $tabactive='cardpertype';
  227. $paramnoaction=preg_replace('/action=[a-z_]+/','',$param);
  228. $head = calendars_prepare_head($paramnoaction);
  229. dol_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action');
  230. print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, $listofextcals, $actioncode, $usergroup, '', $resourceid);
  231. dol_fiche_end();
  232. $showextcals=$listofextcals;
  233. // Legend
  234. if ($conf->use_javascript_ajax)
  235. {
  236. $s='';
  237. $s.='<script type="text/javascript">' . "\n";
  238. $s.='jQuery(document).ready(function () {' . "\n";
  239. $s.='jQuery("#check_mytasks").click(function() { jQuery(".family_mytasks").toggle(); jQuery(".family_other").toggle(); });' . "\n";
  240. $s.='jQuery("#check_birthday").click(function() { jQuery(".family_birthday").toggle(); });' . "\n";
  241. $s.='jQuery(".family_birthday").toggle();' . "\n";
  242. if ($action=="show_week" || $action=="show_month" || empty($action))
  243. {
  244. $s.='jQuery( "td.sortable" ).sortable({connectWith: ".sortable",placeholder: "ui-state-highlight",items: "div:not(.unsortable)", receive: function( event, ui ) {';
  245. $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";
  246. }
  247. $s.='});' . "\n";
  248. $s.='</script>' . "\n";
  249. if (! empty($conf->use_javascript_ajax))
  250. {
  251. $s.='<div class="nowrap clear float"><input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> ' . $langs->trans("LocalAgenda").' &nbsp; </div>';
  252. if (is_array($showextcals) && count($showextcals) > 0)
  253. {
  254. foreach ($showextcals as $val)
  255. {
  256. $htmlname = md5($val['name']);
  257. $s.='<script type="text/javascript">' . "\n";
  258. $s.='jQuery(document).ready(function () {' . "\n";
  259. $s.=' jQuery("#check_ext' . $htmlname . '").click(function() {';
  260. $s.=' /* alert("'.$htmlname.'"); */';
  261. $s.=' jQuery(".family_ext' . $htmlname . '").toggle();';
  262. $s.=' });' . "\n";
  263. $s.='});' . "\n";
  264. $s.='</script>' . "\n";
  265. $s.='<div class="nowrap float"><input type="checkbox" id="check_ext' . $htmlname . '" name="check_ext' . $htmlname . '" checked> ' . $val ['name'] . ' &nbsp; </div>';
  266. }
  267. }
  268. //$s.='<div class="nowrap float"><input type="checkbox" id="check_birthday" name="check_birthday"> '.$langs->trans("AgendaShowBirthdayEvents").' &nbsp; </div>';
  269. // Calendars from hooks
  270. $parameters=array(); $object=null;
  271. $reshook=$hookmanager->executeHooks('addCalendarChoice',$parameters,$object,$action);
  272. if (empty($reshook))
  273. {
  274. $s.= $hookmanager->resPrint;
  275. }
  276. elseif ($reshook > 1)
  277. {
  278. $s = $hookmanager->resPrint;
  279. }
  280. }
  281. }
  282. $link='';
  283. print load_fiche_titre($s, $link.' &nbsp; &nbsp; '.$nav, '');
  284. // Get event in an array
  285. $eventarray=array();
  286. $sql = 'SELECT';
  287. if ($usergroup > 0) $sql.=" DISTINCT";
  288. $sql.= ' a.id, a.label,';
  289. $sql.= ' a.datep,';
  290. $sql.= ' a.datep2,';
  291. $sql.= ' a.percent,';
  292. $sql.= ' a.fk_user_author,a.fk_user_action,';
  293. $sql.= ' a.transparency, a.priority, a.fulldayevent, a.location,';
  294. $sql.= ' a.fk_soc, a.fk_contact, a.fk_element, a.elementtype,';
  295. $sql.= ' ca.code, ca.color';
  296. $sql.= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm as ca, '.MAIN_DB_PREFIX."actioncomm as a";
  297. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
  298. // We must filter on resource table
  299. if ($resourceid > 0) $sql.=", ".MAIN_DB_PREFIX."element_resources as r";
  300. // We must filter on assignement table
  301. if ($filtert > 0 || $usergroup > 0) $sql.=", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
  302. if ($usergroup > 0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
  303. $sql.= ' WHERE a.fk_action = ca.id';
  304. $sql.= ' AND a.entity IN ('.getEntity('agenda').')';
  305. // Condition on actioncode
  306. if (! empty($actioncode))
  307. {
  308. if (empty($conf->global->AGENDA_USE_EVENT_TYPE))
  309. {
  310. if ($actioncode == 'AC_NON_AUTO') $sql.= " AND ca.type != 'systemauto'";
  311. elseif ($actioncode == 'AC_ALL_AUTO') $sql.= " AND ca.type = 'systemauto'";
  312. else
  313. {
  314. if ($actioncode == 'AC_OTH') $sql.= " AND ca.type != 'systemauto'";
  315. if ($actioncode == 'AC_OTH_AUTO') $sql.= " AND ca.type = 'systemauto'";
  316. }
  317. }
  318. else
  319. {
  320. if ($actioncode == 'AC_NON_AUTO') $sql.= " AND ca.type != 'systemauto'";
  321. elseif ($actioncode == 'AC_ALL_AUTO') $sql.= " AND ca.type = 'systemauto'";
  322. else
  323. {
  324. $sql.=" AND ca.code IN ('".implode("','", explode(',',$actioncode))."')";
  325. }
  326. }
  327. }
  328. if ($resourceid > 0) $sql.=" AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".$db->escape($resourceid);
  329. if ($pid) $sql.=" AND a.fk_project=".$db->escape($pid);
  330. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")";
  331. if ($socid > 0) $sql.= ' AND a.fk_soc = '.$socid;
  332. // We must filter on assignement table
  333. if ($filtert > 0 || $usergroup > 0) $sql.= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
  334. if ($action == 'show_day')
  335. {
  336. $sql.= " AND (";
  337. $sql.= " (a.datep BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,$day,$year))."'";
  338. $sql.= " AND '".$db->idate(dol_mktime(23,59,59,$month,$day,$year))."')";
  339. $sql.= " OR ";
  340. $sql.= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,$day,$year))."'";
  341. $sql.= " AND '".$db->idate(dol_mktime(23,59,59,$month,$day,$year))."')";
  342. $sql.= " OR ";
  343. $sql.= " (a.datep < '".$db->idate(dol_mktime(0,0,0,$month,$day,$year))."'";
  344. $sql.= " AND a.datep2 > '".$db->idate(dol_mktime(23,59,59,$month,$day,$year))."')";
  345. $sql.= ')';
  346. }
  347. else
  348. {
  349. // To limit array
  350. $sql.= " AND (";
  351. $sql.= " (a.datep BETWEEN '".$db->idate(dol_mktime(0,0,0,1,1,$year)-(60*60*24*7))."'"; // Start 7 days before
  352. $sql.= " AND '".$db->idate(dol_mktime(23,59,59,12,31,$year)+(60*60*24*7))."')"; // End 7 days after
  353. $sql.= " OR ";
  354. $sql.= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0,0,0,1,1,$year)-(60*60*24*7))."'";
  355. $sql.= " AND '".$db->idate(dol_mktime(23,59,59,12,31,$year)+(60*60*24*7))."')";
  356. $sql.= " OR ";
  357. $sql.= " (a.datep < '".$db->idate(dol_mktime(0,0,0,12,1,$year)-(60*60*24*7))."'";
  358. $sql.= " AND a.datep2 > '".$db->idate(dol_mktime(23,59,59,12,31,$year)+(60*60*24*7))."')";
  359. $sql.= ')';
  360. }
  361. if ($type) $sql.= " AND ca.id = ".$type;
  362. if ($status == '0') { $sql.= " AND a.percent = 0"; }
  363. if ($status == '-1') { $sql.= " AND a.percent = -1"; } // Not applicable
  364. if ($status == '50') { $sql.= " AND (a.percent > 0 AND a.percent < 100)"; } // Running already started
  365. if ($status == 'done' || $status == '100') { $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep2 <= '".$db->idate($now)."'))"; }
  366. if ($status == 'todo') { $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep2 > '".$db->idate($now)."'))"; }
  367. // We must filter on assignement table
  368. if ($filtert > 0 || $usergroup > 0)
  369. {
  370. $sql.= " AND (";
  371. if ($filtert > 0) $sql.= "ar.fk_element = ".$filtert;
  372. if ($usergroup > 0) $sql.= ($filtert>0?" OR ":"")." ugu.fk_usergroup = ".$usergroup;
  373. $sql.= ")";
  374. }
  375. // Sort on date
  376. $sql.= ' ORDER BY fk_user_action, datep'; //fk_user_action
  377. //print $sql;
  378. dol_syslog("comm/action/index.php", LOG_DEBUG);
  379. $resql=$db->query($sql);
  380. if ($resql)
  381. {
  382. $num = $db->num_rows($resql);
  383. $i=0;
  384. while ($i < $num)
  385. {
  386. $obj = $db->fetch_object($resql);
  387. // Discard auto action if option is on
  388. if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->code == 'AC_OTH_AUTO')
  389. {
  390. $i++;
  391. continue;
  392. }
  393. // Create a new object action
  394. $event=new ActionComm($db);
  395. $event->id=$obj->id;
  396. $event->datep=$db->jdate($obj->datep); // datep and datef are GMT date
  397. $event->datef=$db->jdate($obj->datep2);
  398. $event->type_code=$obj->code;
  399. $event->type_color=$obj->color;
  400. //$event->libelle=$obj->label; // deprecated
  401. $event->label=$obj->label;
  402. $event->percentage=$obj->percent;
  403. //$event->author->id=$obj->fk_user_author; // user id of creator
  404. $event->authorid=$obj->fk_user_author; // user id of creator
  405. $event->userownerid=$obj->fk_user_action; // user id of owner
  406. $event->fetch_userassigned(); // This load $event->userassigned
  407. $event->priority=$obj->priority;
  408. $event->fulldayevent=$obj->fulldayevent;
  409. $event->location=$obj->location;
  410. $event->transparency=$obj->transparency;
  411. $event->socid=$obj->fk_soc;
  412. $event->contactid=$obj->fk_contact;
  413. //$event->societe->id=$obj->fk_soc; // deprecated
  414. //$event->contact->id=$obj->fk_contact; // deprecated
  415. $event->fk_element=$obj->fk_element;
  416. $event->elementtype=$obj->elementtype;
  417. // Defined date_start_in_calendar and date_end_in_calendar property
  418. // They are date start and end of action but modified to not be outside calendar view.
  419. if ($event->percentage <= 0)
  420. {
  421. $event->date_start_in_calendar=$event->datep;
  422. if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar=$event->datef;
  423. else $event->date_end_in_calendar=$event->datep;
  424. }
  425. else
  426. {
  427. $event->date_start_in_calendar=$event->datep;
  428. if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar=$event->datef;
  429. else $event->date_end_in_calendar=$event->datep;
  430. }
  431. // Define ponctual property
  432. if ($event->date_start_in_calendar == $event->date_end_in_calendar)
  433. {
  434. $event->ponctuel=1;
  435. }
  436. // Check values
  437. if ($event->date_end_in_calendar < $firstdaytoshow ||
  438. $event->date_start_in_calendar >= $lastdaytoshow)
  439. {
  440. // This record is out of visible range
  441. }
  442. else
  443. {
  444. if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
  445. if ($event->date_end_in_calendar >= $lastdaytoshow) $event->date_end_in_calendar=($lastdaytoshow - 1);
  446. // Add an entry in actionarray for each day
  447. $daycursor=$event->date_start_in_calendar;
  448. $annee = date('Y',$daycursor);
  449. $mois = date('m',$daycursor);
  450. $jour = date('d',$daycursor);
  451. // Loop on each day covered by action to prepare an index to show on calendar
  452. $loop=true; $j=0;
  453. $daykey=dol_mktime(0,0,0,$mois,$jour,$annee);
  454. do
  455. {
  456. //if ($event->id==408) print 'daykey='.$daykey.' '.$event->datep.' '.$event->datef.'<br>';
  457. $eventarray[$daykey][]=$event;
  458. $j++;
  459. $daykey+=60*60*24;
  460. if ($daykey > $event->date_end_in_calendar) $loop=false;
  461. }
  462. while ($loop);
  463. //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
  464. //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>';
  465. }
  466. $i++;
  467. }
  468. }
  469. else
  470. {
  471. dol_print_error($db);
  472. }
  473. $maxnbofchar=18;
  474. $cachethirdparties=array();
  475. $cachecontacts=array();
  476. // Define theme_datacolor array
  477. $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/graph-color.php";
  478. if (is_readable($color_file))
  479. {
  480. include_once $color_file;
  481. }
  482. if (! is_array($theme_datacolor)) $theme_datacolor=array(array(120,130,150), array(200,160,180), array(190,190,220));
  483. $newparam=$param; // newparam is for birthday links
  484. $newparam=preg_replace('/showbirthday=/i','showbirthday_=',$newparam); // To avoid replacement when replace day= is done
  485. $newparam=preg_replace('/action=show_month&?/i','',$newparam);
  486. $newparam=preg_replace('/action=show_week&?/i','',$newparam);
  487. $newparam=preg_replace('/day=[0-9]+&?/i','',$newparam);
  488. $newparam=preg_replace('/month=[0-9]+&?/i','',$newparam);
  489. $newparam=preg_replace('/year=[0-9]+&?/i','',$newparam);
  490. $newparam=preg_replace('/viewweek=[0-9]+&?/i','',$newparam);
  491. $newparam=preg_replace('/showbirthday_=/i','showbirthday=',$newparam); // Restore correct parameter
  492. $newparam.='&viewweek=1';
  493. echo '<form id="move_event" action="" method="POST"><input type="hidden" name="action" value="mupdate">';
  494. echo '<input type="hidden" name="backtopage" value="'.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'">';
  495. echo '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  496. echo '<input type="hidden" name="newdate" id="newdate">' ;
  497. echo '</form>';
  498. // Line header with list of days
  499. //print "begin_d=".$begin_d." end_d=".$end_d;
  500. echo '<table width="100%" class="nocellnopadd cal_month">';
  501. echo '<tr class="liste_titre">';
  502. echo '<td></td>';
  503. $i=0; // 0 = sunday,
  504. echo '<td align="center" colspan="'.($end_d - $begin_d).'">';
  505. echo $langs->trans("Year");
  506. print "<br>";
  507. print $year;
  508. echo "</td>\n";
  509. echo "</tr>\n";
  510. echo '<tr class="liste_titre">';
  511. echo '<td></td>';
  512. $i=0;
  513. for ($h = $begin_d; $h < $end_d; $h++)
  514. {
  515. echo '<td align="center">';
  516. print '<small style="font-family: courier">'.sprintf("%02d",$h).'</small>';
  517. print "</td>";
  518. }
  519. echo "</td>\n";
  520. echo "</tr>\n";
  521. $typeofevents=array();
  522. // Load array of colors by type
  523. $colorsbytype=array();
  524. $labelbytype=array();
  525. $sql="SELECT code, color, libelle FROM ".MAIN_DB_PREFIX."c_actioncomm";
  526. $resql=$db->query($sql);
  527. while ($obj = $db->fetch_object($resql))
  528. {
  529. $colorsbytype[$obj->code]=$obj->color;
  530. $labelbytype[$obj->code]=$obj->libelle;
  531. }
  532. // Loop on each user to show calendar
  533. $todayarray=dol_getdate($now,'fast');
  534. $sav = $tmpday;
  535. $showheader = true;
  536. $var = false;
  537. foreach ($typeofevents as $typeofevent)
  538. {
  539. $var = ! $var;
  540. echo "<tr>";
  541. echo '<td class="cal_current_month cal_peruserviewname'.($var?' cal_impair':'').'">' . $username->getNomUrl(1). '</td>';
  542. $tmpday = $sav;
  543. // Lopp on each day of week
  544. $i = 0;
  545. for ($iter_day = 0; $iter_day < 8; $iter_day++)
  546. {
  547. if (($i + 1) < $begin_d || ($i + 1) > $end_d)
  548. {
  549. $i++;
  550. continue;
  551. }
  552. // Show days of the current week
  553. $curtime = dol_time_plus_duree($firstdaytoshow, $iter_day, 'd');
  554. $tmparray = dol_getdate($curtime,'fast');
  555. $tmpday = $tmparray['mday'];
  556. $tmpmonth = $tmparray['mon'];
  557. $tmpyear = $tmparray['year'];
  558. $style='cal_current_month';
  559. if ($iter_day == 6) $style.=' cal_other_month';
  560. $today=0;
  561. if ($todayarray['mday']==$tmpday && $todayarray['mon']==$tmpmonth && $todayarray['year']==$tmpyear) $today=1;
  562. if ($today) $style='cal_today_peruser';
  563. show_day_events_pertype($username, $tmpday, $tmpmonth, $tmpyear, $monthshown, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, $showheader, $colorsbytype, $var);
  564. $i++;
  565. }
  566. echo "</tr>\n";
  567. $showheader = false;
  568. }
  569. echo "</table>\n";
  570. if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
  571. {
  572. $langs->load("commercial");
  573. print '<br>'.$langs->trans("Legend").': <br>';
  574. foreach($colorsbytype as $code => $color)
  575. {
  576. if ($color)
  577. {
  578. print '<div style="float: left; padding: 2px; margin-right: 6px;"><div style="'.($color?'background: #'.$color.';':'').'width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
  579. print $langs->trans("Action".$code)!="Action".$code?$langs->trans("Action".$code):$labelbytype[$code];
  580. //print $code;
  581. print '</div>';
  582. }
  583. }
  584. //$color=sprintf("%02x%02x%02x",$theme_datacolor[0][0],$theme_datacolor[0][1],$theme_datacolor[0][2]);
  585. print '<div style="float: left; padding: 2px; margin-right: 6px;"><div class="peruser_busy" style="width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
  586. print $langs->trans("Other");
  587. print '</div>';
  588. /* TODO Show this if at least one cumulated event
  589. print '<div style="float: left; padding: 2px; margin-right: 6px;"><div style="background: #222222; width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
  590. print $langs->trans("SeveralEvents");
  591. print '</div>';
  592. */
  593. }
  594. // Add js code to manage click on a box
  595. print '<script type="text/javascript" language="javascript">
  596. jQuery(document).ready(function() {
  597. jQuery(".onclickopenref").click(function() {
  598. var ref=$(this).attr(\'ref\');
  599. var res = ref.split("_");
  600. var userid = res[1];
  601. var year = res[2];
  602. var month = res[3];
  603. var day = res[4];
  604. var hour = res[5];
  605. var min = res[6];
  606. var ids = res[7];
  607. if (ids == \'none\') /* No event */
  608. {
  609. /* alert(\'no event\'); */
  610. 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).'"
  611. window.location.href = url;
  612. }
  613. else if (ids.indexOf(",") > -1) /* There is several events */
  614. {
  615. /* alert(\'several events\'); */
  616. url = "'.DOL_URL_ROOT.'/comm/action/listactions.php?filtert="+userid+"&dateselectyear="+year+"&dateselectmonth="+month+"&dateselectday="+day;
  617. window.location.href = url;
  618. }
  619. else /* One event */
  620. {
  621. /* alert(\'one event\'); */
  622. url = "'.DOL_URL_ROOT.'/comm/action/card.php?action=view&id="+ids
  623. window.location.href = url;
  624. }
  625. });
  626. });
  627. </script>';
  628. llxFooter();
  629. $db->close();
  630. /**
  631. * Show event line of a particular day for a user
  632. *
  633. * @param string $username Login
  634. * @param int $day Day
  635. * @param int $month Month
  636. * @param int $year Year
  637. * @param int $monthshown Current month shown in calendar view
  638. * @param string $style Style to use for this day
  639. * @param array $eventarray Array of events
  640. * @param int $maxprint Nb of actions to show each day on month view (0 means no limit)
  641. * @param int $maxnbofchar Nb of characters to show for event line
  642. * @param string $newparam Parameters on current URL
  643. * @param int $showinfo Add extended information (used by day view)
  644. * @param int $minheight Minimum height for each event. 60px by default.
  645. * @param boolean $showheader Show header
  646. * @param array $colorsbytype Array with colors by type
  647. * @param bool $var true or false for alternat style on tr/td
  648. * @return void
  649. */
  650. function show_day_events_pertype($username, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint=0, $maxnbofchar=16, $newparam='', $showinfo=0, $minheight=60, $showheader=false, $colorsbytype=array(), $var=false)
  651. {
  652. global $db;
  653. global $user, $conf, $langs, $hookmanager, $action;
  654. global $filter, $filtert, $status, $actioncode; // Filters used into search form
  655. global $theme_datacolor; // Array with a list of different we can use (come from theme)
  656. global $cachethirdparties, $cachecontacts, $colorindexused;
  657. global $begin_h, $end_h;
  658. $cases1 = array(); // Color first half hour
  659. $cases2 = array(); // Color second half hour
  660. $curtime = dol_mktime(0, 0, 0, $month, $day, $year);
  661. $i=0; $nummytasks=0; $numother=0; $numbirthday=0; $numical=0; $numicals=array();
  662. $ymd=sprintf("%04d",$year).sprintf("%02d",$month).sprintf("%02d",$day);
  663. $nextindextouse=count($colorindexused); // At first run, this is 0, so fist user has 0, next 1, ...
  664. //if ($username->id && $day==1) var_dump($eventarray);
  665. // We are in a particular day for $username, now we scan all events
  666. foreach ($eventarray as $daykey => $notused)
  667. {
  668. $annee = date('Y',$daykey);
  669. $mois = date('m',$daykey);
  670. $jour = date('d',$daykey);
  671. //print $annee.'-'.$mois.'-'.$jour.' '.$year.'-'.$month.'-'.$day."<br>\n";
  672. if ($day==$jour && $month==$mois && $year==$annee) // Is it the day we are looking for when calling function ?
  673. {
  674. // Scan all event for this date
  675. foreach ($eventarray[$daykey] as $index => $event)
  676. {
  677. //var_dump($event);
  678. $keysofuserassigned=array_keys($event->userassigned);
  679. if (! in_array($username->id,$keysofuserassigned)) continue; // We discard record if event is from another user than user we want to show
  680. //if ($username->id != $event->userownerid) continue; // We discard record if event is from another user than user we want to show
  681. $parameters=array();
  682. $reshook=$hookmanager->executeHooks('formatEvent',$parameters,$event,$action); // Note that $action and $object may have been modified by some hooks
  683. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  684. $ponct=($event->date_start_in_calendar == $event->date_end_in_calendar);
  685. // Define $color (Hex string like '0088FF') and $cssclass of event
  686. $color=-1; $cssclass=''; $colorindex=-1;
  687. if (in_array($user->id, $keysofuserassigned))
  688. {
  689. $nummytasks++; $cssclass='family_mytasks';
  690. if (! empty($conf->global->AGENDA_USE_EVENT_TYPE)) $color=$event->type_color;
  691. }
  692. else if ($event->type_code == 'ICALEVENT')
  693. {
  694. $numical++;
  695. if (! empty($event->icalname))
  696. {
  697. if (! isset($numicals[dol_string_nospecial($event->icalname)])) {
  698. $numicals[dol_string_nospecial($event->icalname)] = 0;
  699. }
  700. $numicals[dol_string_nospecial($event->icalname)]++;
  701. }
  702. $color=$event->icalcolor;
  703. $cssclass=(! empty($event->icalname)?'family_ext'.md5($event->icalname):'family_other unsortable');
  704. }
  705. else if ($event->type_code == 'BIRTHDAY')
  706. {
  707. $numbirthday++; $colorindex=2; $cssclass='family_birthday unsortable'; $color=sprintf("%02x%02x%02x",$theme_datacolor[$colorindex][0],$theme_datacolor[$colorindex][1],$theme_datacolor[$colorindex][2]);
  708. }
  709. else
  710. {
  711. $numother++; $cssclass='family_other';
  712. if (! empty($conf->global->AGENDA_USE_EVENT_TYPE)) $color=$event->type_color;
  713. }
  714. if ($color < 0) // Color was not forced. Set color according to color index.
  715. {
  716. // Define color index if not yet defined
  717. $idusertouse=($event->userownerid?$event->userownerid:0);
  718. if (isset($colorindexused[$idusertouse]))
  719. {
  720. $colorindex=$colorindexused[$idusertouse]; // Color already assigned to this user
  721. }
  722. else
  723. {
  724. $colorindex=$nextindextouse;
  725. $colorindexused[$idusertouse]=$colorindex;
  726. if (! empty($theme_datacolor[$nextindextouse+1])) $nextindextouse++; // Prepare to use next color
  727. }
  728. // Define color
  729. $color=sprintf("%02x%02x%02x",$theme_datacolor[$colorindex][0],$theme_datacolor[$colorindex][1],$theme_datacolor[$colorindex][2]);
  730. }
  731. //$cssclass=$cssclass.' '.$cssclass.'_day_'.$ymd;
  732. // Define all rects with event (cases1 is first half hour, cases2 is second half hour)
  733. for ($h = $begin_h; $h < $end_h; $h++)
  734. {
  735. //if ($username->id == 1 && $day==1) print 'h='.$h;
  736. $newcolor = ''; //init
  737. if (empty($event->fulldayevent))
  738. {
  739. $a = dol_mktime((int) $h,0,0,$month,$day,$year,false,0);
  740. $b = dol_mktime((int) $h,30,0,$month,$day,$year,false,0);
  741. $c = dol_mktime((int) $h+1,0,0,$month,$day,$year,false,0);
  742. $dateendtouse=$event->date_end_in_calendar;
  743. if ($dateendtouse==$event->date_start_in_calendar) $dateendtouse++;
  744. //print dol_print_date($event->date_start_in_calendar,'dayhour').'-'.dol_print_date($a,'dayhour').'-'.dol_print_date($b,'dayhour').'<br>';
  745. if ($event->date_start_in_calendar < $b && $dateendtouse > $a)
  746. {
  747. $busy=$event->transparency;
  748. $cases1[$h][$event->id]['busy']=$busy;
  749. $cases1[$h][$event->id]['string']=dol_print_date($event->date_start_in_calendar,'dayhour');
  750. if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar)
  751. {
  752. $tmpa=dol_getdate($event->date_start_in_calendar,true);
  753. $tmpb=dol_getdate($event->date_end_in_calendar,true);
  754. 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');
  755. else $cases1[$h][$event->id]['string'].='-'.dol_print_date($event->date_end_in_calendar,'dayhour');
  756. }
  757. $cases1[$h][$event->id]['string'].=' - '.$event->label;
  758. $cases1[$h][$event->id]['typecode']=$event->type_code;
  759. if ($event->socid)
  760. {
  761. //$cases1[$h][$event->id]['string'].='xxx';
  762. }
  763. $cases1[$h][$event->id]['color']=$color;
  764. }
  765. if ($event->date_start_in_calendar < $c && $dateendtouse > $b)
  766. {
  767. $busy=$event->transparency;
  768. $cases2[$h][$event->id]['busy']=$busy;
  769. $cases2[$h][$event->id]['string']=dol_print_date($event->date_start_in_calendar,'dayhour');
  770. if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar)
  771. {
  772. $tmpa=dol_getdate($event->date_start_in_calendar,true);
  773. $tmpb=dol_getdate($event->date_end_in_calendar,true);
  774. 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');
  775. else $cases2[$h][$event->id]['string'].='-'.dol_print_date($event->date_end_in_calendar,'dayhour');
  776. }
  777. $cases2[$h][$event->id]['string'].=' - '.$event->label;
  778. $cases2[$h][$event->id]['typecode']=$event->type_code;
  779. if ($event->socid)
  780. {
  781. //$cases2[$h][$event->id]['string'].='xxx';
  782. }
  783. $cases2[$h][$event->id]['color']=$color;
  784. }
  785. }
  786. else
  787. {
  788. $busy=$event->transparency;
  789. $cases1[$h][$event->id]['busy']=$busy;
  790. $cases2[$h][$event->id]['busy']=$busy;
  791. $cases1[$h][$event->id]['string']=$event->label;
  792. $cases2[$h][$event->id]['string']=$event->label;
  793. $cases1[$h][$event->id]['typecode']=$event->type_code;
  794. $cases2[$h][$event->id]['typecode']=$event->type_code;
  795. $cases1[$h][$event->id]['color']=$color;
  796. $cases2[$h][$event->id]['color']=$color;
  797. }
  798. }
  799. $i++;
  800. }
  801. break; // We found the date we were looking for. No need to search anymore.
  802. }
  803. }
  804. for ($h = $begin_h; $h < $end_h; $h++)
  805. {
  806. $color1='';$color2='';
  807. $style1='';$style2='';
  808. $string1='&nbsp;';$string2='&nbsp;';
  809. $title1='';$title2='';
  810. if (isset($cases1[$h]) && $cases1[$h] != '')
  811. {
  812. //$title1.=count($cases1[$h]).' '.(count($cases1[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
  813. if (count($cases1[$h]) > 1) $title1.=count($cases1[$h]).' '.(count($cases1[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
  814. $string1='&nbsp;';
  815. if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) $style1='peruser_notbusy';
  816. else $style1='peruser_busy';
  817. foreach($cases1[$h] as $id => $ev)
  818. {
  819. if ($ev['busy']) $style1='peruser_busy';
  820. }
  821. }
  822. if (isset($cases2[$h]) && $cases2[$h] != '')
  823. {
  824. //$title2.=count($cases2[$h]).' '.(count($cases2[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
  825. if (count($cases2[$h]) > 1) $title2.=count($cases2[$h]).' '.(count($cases2[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
  826. $string2='&nbsp;';
  827. if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) $style2='peruser_notbusy';
  828. else $style2='peruser_busy';
  829. foreach($cases2[$h] as $id => $ev)
  830. {
  831. if ($ev['busy']) $style2='peruser_busy';
  832. }
  833. }
  834. $ids1='';$ids2='';
  835. if (count($cases1[$h]) && array_keys($cases1[$h])) $ids1=join(',',array_keys($cases1[$h]));
  836. if (count($cases2[$h]) && array_keys($cases2[$h])) $ids2=join(',',array_keys($cases2[$h]));
  837. if ($h == $begin_h) echo '<td class="'.$style.'_peruserleft cal_peruser'.($var?' cal_impair '.$style.'_impair':'').'">';
  838. else echo '<td class="'.$style.' cal_peruser'.($var?' cal_impair '.$style.'_impair':'').'">';
  839. if (count($cases1[$h]) == 1) // only 1 event
  840. {
  841. $output = array_slice($cases1[$h], 0, 1);
  842. $title1=$langs->trans("Ref").' '.$ids1.($title1?' - '.$title1:'');
  843. if ($output[0]['string']) $title1.=($title1?' - ':'').$output[0]['string'];
  844. if ($output[0]['color']) $color1 = $output[0]['color'];
  845. }
  846. else if (count($cases1[$h]) > 1)
  847. {
  848. $title1=$langs->trans("Ref").' '.$ids1.($title1?' - '.$title1:'');
  849. $color1='222222';
  850. }
  851. if (count($cases2[$h]) == 1) // only 1 event
  852. {
  853. $output = array_slice($cases2[$h], 0, 1);
  854. $title2=$langs->trans("Ref").' '.$ids2.($title2?' - '.$title2:'');
  855. if ($output[0]['string']) $title2.=($title2?' - ':'').$output[0]['string'];
  856. if ($output[0]['color']) $color2 = $output[0]['color'];
  857. }
  858. else if (count($cases2[$h]) > 1)
  859. {
  860. $title2=$langs->trans("Ref").' '.$ids2.($title2?' - '.$title2:'');
  861. $color2='222222';
  862. }
  863. print '<table class="nobordernopadding" width="100%">';
  864. 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.'"':'').'>';
  865. print $string1;
  866. 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.'"':'').'>';
  867. print $string2;
  868. print '</td></tr>';
  869. print '</table>';
  870. print '</td>';
  871. }
  872. }