pertype.php 49 KB

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