pertype.php 50 KB

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