pertype.php 42 KB

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