pertype.php 50 KB

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