pertype.php 49 KB

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