pertype.php 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Eric Seigne <erics@rycks.com>
  4. * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
  8. * Copyright (C) 2018-2019 Frédéric France <frederic.france@netlogic.fr>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/comm/action/pertype.php
  25. * \ingroup agenda
  26. * \brief Tab of calendar events per type
  27. */
  28. require '../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  37. if (!isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) {
  38. $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW = 3;
  39. }
  40. $action = GETPOST('action', 'aZ09');
  41. $filter = GETPOST("search_filter", 'alpha', 3) ? GETPOST("search_filter", 'alpha', 3) : GETPOST("filter", 'alpha', 3);
  42. $filtert = GETPOST("search_filtert", "int", 3) ? GETPOST("search_filtert", "int", 3) : GETPOST("filtert", "int", 3);
  43. $usergroup = GETPOST("search_usergroup", "int", 3) ? GETPOST("search_usergroup", "int", 3) : GETPOST("usergroup", "int", 3);
  44. //if (! ($usergroup > 0) && ! ($filtert > 0)) $filtert = $user->id;
  45. //$showbirthday = empty($conf->use_javascript_ajax)?GETPOST("showbirthday","int"):1;
  46. $showbirthday = 0;
  47. // If not choice done on calendar owner, we filter on user.
  48. if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS)) {
  49. $filtert = $user->id;
  50. }
  51. $sortfield = GETPOST('sortfield', 'aZ09comma');
  52. $sortorder = GETPOST('sortorder', 'aZ09comma');
  53. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  54. if (empty($page) || $page == -1) {
  55. $page = 0;
  56. } // If $page is not defined, or '' or -1
  57. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  58. $offset = $limit * $page;
  59. if (!$sortorder) {
  60. $sortorder = "ASC";
  61. }
  62. if (!$sortfield) {
  63. $sortfield = "a.datec";
  64. }
  65. // Security check
  66. $socid = GETPOST("search_socid", "int") ?GETPOST("search_socid", "int") : GETPOST("socid", "int");
  67. if ($user->socid) {
  68. $socid = $user->socid;
  69. }
  70. if ($socid < 0) {
  71. $socid = '';
  72. }
  73. $canedit = 1;
  74. if (empty($user->rights->agenda->myactions->read)) {
  75. accessforbidden();
  76. }
  77. if (empty($user->rights->agenda->allactions->read)) {
  78. $canedit = 0;
  79. }
  80. if (empty($user->rights->agenda->allactions->read) || $filter == 'mine') { // If no permission to see all, we show only affected to me
  81. $filtert = $user->id;
  82. }
  83. $mode = 'show_pertype';
  84. $resourceid = GETPOST("search_resourceid", "int") ?GETPOST("search_resourceid", "int") : GETPOST("resourceid", "int");
  85. $year = GETPOST("year", "int") ?GETPOST("year", "int") : date("Y");
  86. $month = GETPOST("month", "int") ?GETPOST("month", "int") : date("m");
  87. $week = GETPOST("week", "int") ?GETPOST("week", "int") : date("W");
  88. $day = GETPOST("day", "int") ?GETPOST("day", "int") : date("d");
  89. $pid = GETPOST("search_projectid", "int", 3) ?GETPOST("search_projectid", "int", 3) : GETPOST("projectid", "int", 3);
  90. $status = GETPOST("search_status", 'alpha') ?GETPOST("search_status", 'alpha') : GETPOST("status", 'alpha');
  91. $type = GETPOST("search_type", 'alpha') ?GETPOST("search_type", 'alpha') : GETPOST("type", 'alpha');
  92. $maxprint = ((GETPOST("maxprint", 'int') != '') ?GETPOST("maxprint", 'int') : $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW);
  93. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  94. // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
  95. if (GETPOST('search_actioncode', 'array')) {
  96. $actioncode = GETPOST('search_actioncode', 'array', 3);
  97. if (!count($actioncode)) {
  98. $actioncode = '0';
  99. }
  100. } else {
  101. $actioncode = GETPOST("search_actioncode", "alpha", 3) ?GETPOST("search_actioncode", "alpha", 3) : (GETPOST("search_actioncode", "alpha") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE));
  102. }
  103. if ($actioncode == '' && empty($actioncodearray)) {
  104. $actioncode = (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE);
  105. }
  106. $dateselect = dol_mktime(0, 0, 0, GETPOST('dateselectmonth', 'int'), GETPOST('dateselectday', 'int'), GETPOST('dateselectyear', 'int'));
  107. if ($dateselect > 0) {
  108. $day = GETPOST('dateselectday', 'int');
  109. $month = GETPOST('dateselectmonth', 'int');
  110. $year = GETPOST('dateselectyear', 'int');
  111. }
  112. $tmp = empty($conf->global->MAIN_DEFAULT_WORKING_HOURS) ? '9-18' : $conf->global->MAIN_DEFAULT_WORKING_HOURS;
  113. $tmp = str_replace(' ', '', $tmp); // FIX 7533
  114. $tmparray = explode('-', $tmp);
  115. $begin_h = GETPOST('begin_h', 'int') != '' ?GETPOST('begin_h', 'int') : ($tmparray[0] != '' ? $tmparray[0] : 9);
  116. $end_h = GETPOST('end_h', 'int') ?GETPOST('end_h', 'int') : ($tmparray[1] != '' ? $tmparray[1] : 18);
  117. if ($begin_h < 0 || $begin_h > 23) {
  118. $begin_h = 9;
  119. }
  120. if ($end_h < 1 || $end_h > 24) {
  121. $end_h = 18;
  122. }
  123. if ($end_h <= $begin_h) {
  124. $end_h = $begin_h + 1;
  125. }
  126. $tmp = empty($conf->global->MAIN_DEFAULT_WORKING_DAYS) ? '1-5' : $conf->global->MAIN_DEFAULT_WORKING_DAYS;
  127. $tmp = str_replace(' ', '', $tmp); // FIX 7533
  128. $tmparray = explode('-', $tmp);
  129. $begin_d = 1;
  130. $end_d = 53;
  131. if ($status == '' && !GETPOSTISSET('status')) {
  132. $status = (empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS);
  133. }
  134. if (empty($mode) && !GETPOSTISSET('mode')) {
  135. $mode = (empty($conf->global->AGENDA_DEFAULT_VIEW) ? 'show_month' : $conf->global->AGENDA_DEFAULT_VIEW);
  136. }
  137. if (GETPOST('viewcal', 'alpha') && $mode != 'show_day' && $mode != 'show_week' && $mode != 'show_peruser') {
  138. $mode = 'show_month'; $day = '';
  139. } // View by month
  140. if (GETPOST('viewweek', 'alpha') || $mode == 'show_week') {
  141. $mode = 'show_week'; $week = ($week ? $week : date("W")); $day = ($day ? $day : date("d"));
  142. } // View by week
  143. if (GETPOST('viewday', 'alpha') || $mode == 'show_day') {
  144. $mode = 'show_day'; $day = ($day ? $day : date("d"));
  145. } // View by day
  146. if (GETPOST('viewyear', 'alpha') || $mode == 'show_year') {
  147. $mode = 'show_year';
  148. } // View by year
  149. // Load translation files required by the page
  150. $langs->loadLangs(array('users', 'agenda', 'other', 'commercial'));
  151. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  152. $hookmanager->initHooks(array('agenda'));
  153. $result = restrictedArea($user, 'agenda', 0, '', 'myactions');
  154. if ($user->socid && $socid) {
  155. $result = restrictedArea($user, 'societe', $socid);
  156. }
  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')) {
  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(); $object = null;
  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_list', '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. // Define ponctual property
  600. if ($event->date_start_in_calendar == $event->date_end_in_calendar) {
  601. $event->ponctuel = 1;
  602. }
  603. // Check values
  604. if ($event->date_end_in_calendar < $firstdaytoshow ||
  605. $event->date_start_in_calendar >= $lastdaytoshow) {
  606. // This record is out of visible range
  607. unset($event);
  608. } else {
  609. //print $i.' - '.dol_print_date($this->date_start_in_calendar, 'dayhour').' - '.dol_print_date($this->date_end_in_calendar, 'dayhour').'<br>'."\n";
  610. $event->fetch_userassigned(); // This load $event->userassigned
  611. if ($event->date_start_in_calendar < $firstdaytoshow) {
  612. $event->date_start_in_calendar = $firstdaytoshow;
  613. }
  614. if ($event->date_end_in_calendar >= $lastdaytoshow) {
  615. $event->date_end_in_calendar = ($lastdaytoshow - 1);
  616. }
  617. // Add an entry in actionarray for each day
  618. $daycursor = $event->date_start_in_calendar;
  619. $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
  620. $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
  621. $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
  622. // Loop on each day covered by action to prepare an index to show on calendar
  623. $loop = true; $j = 0;
  624. $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
  625. do {
  626. //if ($event->id==408) print 'daykey='.$daykey.' '.$event->datep.' '.$event->datef.'<br>';
  627. $eventarray[$daykey][] = $event;
  628. $j++;
  629. $daykey += 60 * 60 * 24;
  630. if ($daykey > $event->date_end_in_calendar) {
  631. $loop = false;
  632. }
  633. } while ($loop);
  634. //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
  635. //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>';
  636. }
  637. $i++;
  638. }
  639. $db->free($resql);
  640. } else {
  641. dol_print_error($db);
  642. }
  643. $maxnbofchar = 18;
  644. $cachethirdparties = array();
  645. $cachecontacts = array();
  646. $cacheusers = array();
  647. // Define theme_datacolor array
  648. $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/theme_vars.inc.php";
  649. if (is_readable($color_file)) {
  650. include $color_file;
  651. }
  652. if (!is_array($theme_datacolor)) {
  653. $theme_datacolor = array(array(120, 130, 150), array(200, 160, 180), array(190, 190, 220));
  654. }
  655. $newparam = $param; // newparam is for birthday links
  656. $newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
  657. $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
  658. $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
  659. $newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
  660. $newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
  661. $newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
  662. $newparam = preg_replace('/viewweek=[0-9]+&?/i', '', $newparam);
  663. $newparam = preg_replace('/showbirthday_=/i', 'showbirthday=', $newparam); // Restore correct parameter
  664. $newparam .= '&viewweek=1';
  665. print '<input type="hidden" name="action" value="mupdate">';
  666. echo '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER['PHP_SELF']).'?'.dol_escape_htmltag($_SERVER['QUERY_STRING']).'">';
  667. echo '<input type="hidden" name="token" value="'.newToken().'">';
  668. echo '<input type="hidden" name="newdate" id="newdate">';
  669. // Line header with list of days
  670. //print "begin_d=".$begin_d." end_d=".$end_d;
  671. echo '<table width="100%" class="nocellnopadd cal_month">';
  672. echo '<tr class="liste_titre">';
  673. echo '<td></td>';
  674. $i = 0; // 0 = sunday,
  675. echo '<td align="center" colspan="'.($end_d - $begin_d).'">';
  676. echo $langs->trans("Year");
  677. print "<br>";
  678. print $year;
  679. echo "</td>\n";
  680. echo "</tr>\n";
  681. echo '<tr class="liste_titre">';
  682. echo '<td></td>';
  683. $i = 0;
  684. for ($h = $begin_d; $h < $end_d; $h++) {
  685. echo '<td class="center">';
  686. print '<small style="font-family: courier">'.sprintf("%02d", $h).'</small>';
  687. print "</td>";
  688. }
  689. echo "</td>\n";
  690. echo "</tr>\n";
  691. $typeofevents = array();
  692. // Load array of colors by type
  693. $colorsbytype = array();
  694. $labelbytype = array();
  695. $sql = "SELECT code, color, libelle as label FROM ".MAIN_DB_PREFIX."c_actioncomm ORDER BY position";
  696. $resql = $db->query($sql);
  697. while ($obj = $db->fetch_object($resql)) {
  698. $typeofevents[$obj->code] = $obj->code;
  699. $colorsbytype[$obj->code] = $obj->color;
  700. $labelbytype[$obj->code] = $obj->label;
  701. }
  702. // Loop on each user to show calendar
  703. $todayarray = dol_getdate($now, 'fast');
  704. $sav = $tmpday;
  705. $showheader = true;
  706. $var = false;
  707. foreach ($typeofevents as $typeofevent) {
  708. $var = !$var;
  709. echo "<tr>";
  710. echo '<td class="cal_current_month cal_peruserviewname'.($var ? ' cal_impair' : '').'">'.$typeofevent.'</td>';
  711. $tmpday = $sav;
  712. // Lopp on each day of week
  713. $i = 0;
  714. for ($iter_day = 0; $iter_day < 8; $iter_day++) {
  715. if (($i + 1) < $begin_d || ($i + 1) > $end_d) {
  716. $i++;
  717. continue;
  718. }
  719. // Show days of the current week
  720. $curtime = dol_time_plus_duree($firstdaytoshow, $iter_day, 'd');
  721. $tmparray = dol_getdate($curtime, 'fast');
  722. $tmpday = $tmparray['mday'];
  723. $tmpmonth = $tmparray['mon'];
  724. $tmpyear = $tmparray['year'];
  725. $style = 'cal_current_month';
  726. if ($iter_day == 6) {
  727. $style .= ' cal_other_month';
  728. }
  729. $today = 0;
  730. if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $tmpmonth && $todayarray['year'] == $tmpyear) {
  731. $today = 1;
  732. }
  733. if ($today) {
  734. $style = 'cal_today_peruser';
  735. }
  736. show_day_events_pertype($typeofevent, $tmpday, $tmpmonth, $tmpyear, 0, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, $showheader, $colorsbytype, $var);
  737. $i++;
  738. }
  739. echo "</tr>\n";
  740. $showheader = false;
  741. }
  742. echo "</table>\n";
  743. echo "<br>";
  744. if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
  745. $langs->load("commercial");
  746. print '<br>'.$langs->trans("Legend").': <br>';
  747. foreach ($colorsbytype as $code => $color) {
  748. if ($color) {
  749. print '<div style="float: left; padding: 2px; margin-right: 6px;"><div style="'.($color ? 'background: #'.$color.';' : '').'width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
  750. print $langs->trans("Action".$code) != "Action".$code ? $langs->trans("Action".$code) : $labelbytype[$code];
  751. //print $code;
  752. print '</div>';
  753. }
  754. }
  755. //$color=sprintf("%02x%02x%02x",$theme_datacolor[0][0],$theme_datacolor[0][1],$theme_datacolor[0][2]);
  756. print '<div style="float: left; padding: 2px; margin-right: 6px;"><div class="peruser_busy" style="width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
  757. print $langs->trans("Other");
  758. print '</div>';
  759. /* TODO Show this if at least one cumulated event
  760. print '<div style="float: left; padding: 2px; margin-right: 6px;"><div style="background: #222222; width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
  761. print $langs->trans("SeveralEvents");
  762. print '</div>';
  763. */
  764. }
  765. print "\n".'</form>';
  766. print "\n";
  767. // Add js code to manage click on a box
  768. print '<script type="text/javascript">
  769. jQuery(document).ready(function() {
  770. jQuery(".onclickopenref").click(function() {
  771. var ref=$(this).attr(\'ref\');
  772. var res = ref.split("_");
  773. var userid = res[1];
  774. var year = res[2];
  775. var month = res[3];
  776. var day = res[4];
  777. var hour = res[5];
  778. var min = res[6];
  779. var ids = res[7];
  780. if (ids == \'none\') /* No event */
  781. {
  782. /* alert(\'no event\'); */
  783. 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).'"
  784. window.location.href = url;
  785. }
  786. else if (ids.indexOf(",") > -1) /* There is several events */
  787. {
  788. /* alert(\'several events\'); */
  789. url = "'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&filtert="+userid+"&dateselectyear="+year+"&dateselectmonth="+month+"&dateselectday="+day;
  790. window.location.href = url;
  791. }
  792. else /* One event */
  793. {
  794. /* alert(\'one event\'); */
  795. url = "'.DOL_URL_ROOT.'/comm/action/card.php?action=view&id="+ids
  796. window.location.href = url;
  797. }
  798. });
  799. });
  800. </script>';
  801. // End of page
  802. llxFooter();
  803. $db->close();
  804. /**
  805. * Show event line of a particular day for a user
  806. *
  807. * @param User $username Login
  808. * @param int $day Day
  809. * @param int $month Month
  810. * @param int $year Year
  811. * @param int $monthshown Current month shown in calendar view
  812. * @param string $style Style to use for this day
  813. * @param array $eventarray Array of events
  814. * @param int $maxprint Nb of actions to show each day on month view (0 means no limit)
  815. * @param int $maxnbofchar Nb of characters to show for event line
  816. * @param string $newparam Parameters on current URL
  817. * @param int $showinfo Add extended information (used by day view)
  818. * @param int $minheight Minimum height for each event. 60px by default.
  819. * @param boolean $showheader Show header
  820. * @param array $colorsbytype Array with colors by type
  821. * @param bool $var true or false for alternat style on tr/td
  822. * @return void
  823. */
  824. 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)
  825. {
  826. global $db;
  827. global $user, $conf, $langs, $hookmanager, $action;
  828. global $filter, $filtert, $status, $actioncode; // Filters used into search form
  829. global $theme_datacolor; // Array with a list of different we can use (come from theme)
  830. global $cachethirdparties, $cachecontacts, $cacheusers, $cacheprojects, $colorindexused;
  831. global $begin_h, $end_h;
  832. $cases1 = array(); // Color first half hour
  833. $cases2 = array(); // Color second half hour
  834. $i = 0; $nummytasks = 0; $numother = 0; $numbirthday = 0; $numical = 0; $numicals = array();
  835. $ymd = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $day);
  836. $nextindextouse = count($colorindexused); // At first run, this is 0, so fist user has 0, next 1, ...
  837. //if ($username->id && $day==1) var_dump($eventarray);
  838. // We are in a particular day for $username, now we scan all events
  839. foreach ($eventarray as $daykey => $notused) {
  840. $annee = dol_print_date($daykey, '%Y');
  841. $mois = dol_print_date($daykey, '%m');
  842. $jour = dol_print_date($daykey, '%d');
  843. if ($day == $jour && $month == $mois && $year == $annee) { // Is it the day we are looking for when calling function ?
  844. // Scan all event for this date
  845. foreach ($eventarray[$daykey] as $index => $event) {
  846. //print $daykey.' '.$year.'-'.$month.'-'.$day.' -> '.$event->id.' '.$index.' '.$annee.'-'.$mois.'-'.$jour."<br>\n";
  847. //var_dump($event);
  848. $keysofuserassigned = array_keys($event->userassigned);
  849. if (!in_array($username->id, $keysofuserassigned)) {
  850. continue; // We discard record if event is from another user than user we want to show
  851. }
  852. //if ($username->id != $event->userownerid) continue; // We discard record if event is from another user than user we want to show
  853. $parameters = array();
  854. $reshook = $hookmanager->executeHooks('formatEvent', $parameters, $event, $action); // Note that $action and $object may have been modified by some hooks
  855. if ($reshook < 0) {
  856. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  857. }
  858. $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
  859. // Define $color (Hex string like '0088FF') and $cssclass of event
  860. $color = -1; $cssclass = ''; $colorindex = -1;
  861. if (in_array($user->id, $keysofuserassigned)) {
  862. $nummytasks++; $cssclass = 'family_mytasks';
  863. if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
  864. $color = $event->type_color;
  865. }
  866. } elseif ($event->type_code == 'ICALEVENT') {
  867. $numical++;
  868. if (!empty($event->icalname)) {
  869. if (!isset($numicals[dol_string_nospecial($event->icalname)])) {
  870. $numicals[dol_string_nospecial($event->icalname)] = 0;
  871. }
  872. $numicals[dol_string_nospecial($event->icalname)]++;
  873. }
  874. $color = $event->icalcolor;
  875. $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other unsortable');
  876. } elseif ($event->type_code == 'BIRTHDAY') {
  877. $numbirthday++; $colorindex = 2; $cssclass = 'family_birthday unsortable'; $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
  878. } else {
  879. $numother++; $cssclass = 'family_other';
  880. if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
  881. $color = $event->type_color;
  882. }
  883. }
  884. if ($color < 0) { // Color was not set on user card. Set color according to color index.
  885. // Define color index if not yet defined
  886. $idusertouse = ($event->userownerid ? $event->userownerid : 0);
  887. if (isset($colorindexused[$idusertouse])) {
  888. $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user
  889. } else {
  890. $colorindex = $nextindextouse;
  891. $colorindexused[$idusertouse] = $colorindex;
  892. if (!empty($theme_datacolor[$nextindextouse + 1])) {
  893. $nextindextouse++; // Prepare to use next color
  894. }
  895. }
  896. // Define color
  897. $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
  898. }
  899. //$cssclass=$cssclass.' '.$cssclass.'_day_'.$ymd;
  900. // Define all rects with event (cases1 is first half hour, cases2 is second half hour)
  901. for ($h = $begin_h; $h < $end_h; $h++) {
  902. //if ($username->id == 1 && $day==1) print 'h='.$h;
  903. $newcolor = ''; //init
  904. if (empty($event->fulldayevent)) {
  905. $a = dol_mktime((int) $h, 0, 0, $month, $day, $year, 'tzuserrel', 0);
  906. $b = dol_mktime((int) $h, 30, 0, $month, $day, $year, 'tzuserrel', 0);
  907. $c = dol_mktime((int) $h + 1, 0, 0, $month, $day, $year, 'tzuserrel', 0);
  908. $dateendtouse = $event->date_end_in_calendar;
  909. if ($dateendtouse == $event->date_start_in_calendar) {
  910. $dateendtouse++;
  911. }
  912. //print dol_print_date($event->date_start_in_calendar,'dayhour').'-'.dol_print_date($a,'dayhour').'-'.dol_print_date($b,'dayhour').'<br>';
  913. if ($event->date_start_in_calendar < $b && $dateendtouse > $a) {
  914. $busy = $event->transparency;
  915. $cases1[$h][$event->id]['busy'] = $busy;
  916. $cases1[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel');
  917. if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
  918. $tmpa = dol_getdate($event->date_start_in_calendar, true);
  919. $tmpb = dol_getdate($event->date_end_in_calendar, true);
  920. if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
  921. $cases1[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
  922. } else {
  923. $cases1[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel');
  924. }
  925. }
  926. if ($event->label) {
  927. $cases1[$h][$event->id]['string'] .= ' - '.$event->label;
  928. }
  929. $cases1[$h][$event->id]['typecode'] = $event->type_code;
  930. $cases1[$h][$event->id]['color'] = $color;
  931. if ($event->fk_project > 0) {
  932. if (empty($cacheprojects[$event->fk_project])) {
  933. $tmpproj = new Project($db);
  934. $tmpproj->fetch($event->fk_project);
  935. $cacheprojects[$event->fk_project] = $tmpproj;
  936. }
  937. $cases1[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title;
  938. }
  939. if ($event->socid > 0) {
  940. if (empty($cachethirdparties[$event->socid])) {
  941. $tmpthirdparty = new Societe($db);
  942. $tmpthirdparty->fetch($event->socid);
  943. $cachethirdparties[$event->socid] = $tmpthirdparty;
  944. }
  945. $cases1[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name;
  946. }
  947. if ($event->contact_id > 0) {
  948. if (empty($cachecontacts[$event->contact_id])) {
  949. $tmpcontact = new Contact($db);
  950. $tmpcontact->fetch($event->contact_id);
  951. $cachecontacts[$event->contact_id] = $tmpcontact;
  952. }
  953. $cases1[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contact_id]->getFullName($langs);
  954. }
  955. }
  956. if ($event->date_start_in_calendar < $c && $dateendtouse > $b) {
  957. $busy = $event->transparency;
  958. $cases2[$h][$event->id]['busy'] = $busy;
  959. $cases2[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel');
  960. if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
  961. $tmpa = dol_getdate($event->date_start_in_calendar, true);
  962. $tmpb = dol_getdate($event->date_end_in_calendar, true);
  963. if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
  964. $cases2[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
  965. } else {
  966. $cases2[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel');
  967. }
  968. }
  969. if ($event->label) {
  970. $cases2[$h][$event->id]['string'] .= ' - '.$event->label;
  971. }
  972. $cases2[$h][$event->id]['typecode'] = $event->type_code;
  973. $cases2[$h][$event->id]['color'] = $color;
  974. if ($event->fk_project > 0) {
  975. if (empty($cacheprojects[$event->fk_project])) {
  976. $tmpproj = new Project($db);
  977. $tmpproj->fetch($event->fk_project);
  978. $cacheprojects[$event->fk_project] = $tmpproj;
  979. }
  980. $cases2[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title;
  981. }
  982. if ($event->socid > 0) {
  983. if (empty($cachethirdparties[$event->socid])) {
  984. $tmpthirdparty = new Societe($db);
  985. $tmpthirdparty->fetch($event->socid);
  986. $cachethirdparties[$event->socid] = $tmpthirdparty;
  987. }
  988. $cases2[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name;
  989. }
  990. if ($event->contact_id > 0) {
  991. if (empty($cachecontacts[$event->contact_id])) {
  992. $tmpcontact = new Contact($db);
  993. $tmpcontact->fetch($event->contact_id);
  994. $cachecontacts[$event->contact_id] = $tmpcontact;
  995. }
  996. $cases2[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contact_id]->getFullName($langs);
  997. }
  998. }
  999. } else {
  1000. $busy = $event->transparency;
  1001. $cases1[$h][$event->id]['busy'] = $busy;
  1002. $cases2[$h][$event->id]['busy'] = $busy;
  1003. $cases1[$h][$event->id]['string'] = $event->label;
  1004. $cases2[$h][$event->id]['string'] = $event->label;
  1005. $cases1[$h][$event->id]['typecode'] = $event->type_code;
  1006. $cases2[$h][$event->id]['typecode'] = $event->type_code;
  1007. $cases1[$h][$event->id]['color'] = $color;
  1008. $cases2[$h][$event->id]['color'] = $color;
  1009. }
  1010. }
  1011. $i++;
  1012. }
  1013. break; // We found the date we were looking for. No need to search anymore.
  1014. }
  1015. }
  1016. // Now output $casesX
  1017. for ($h = $begin_h; $h < $end_h; $h++) {
  1018. $color1 = ''; $color2 = '';
  1019. $style1 = ''; $style2 = '';
  1020. $string1 = '&nbsp;'; $string2 = '&nbsp;';
  1021. $title1 = ''; $title2 = '';
  1022. if (isset($cases1[$h]) && $cases1[$h] != '') {
  1023. //$title1.=count($cases1[$h]).' '.(count($cases1[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
  1024. if (count($cases1[$h]) > 1) {
  1025. $title1 .= count($cases1[$h]).' '.(count($cases1[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events"));
  1026. }
  1027. $string1 = '&nbsp;';
  1028. if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
  1029. $style1 = 'peruser_notbusy';
  1030. } else {
  1031. $style1 = 'peruser_busy';
  1032. }
  1033. foreach ($cases1[$h] as $id => $ev) {
  1034. if ($ev['busy']) {
  1035. $style1 = 'peruser_busy';
  1036. }
  1037. }
  1038. }
  1039. if (isset($cases2[$h]) && $cases2[$h] != '') {
  1040. //$title2.=count($cases2[$h]).' '.(count($cases2[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
  1041. if (count($cases2[$h]) > 1) {
  1042. $title2 .= count($cases2[$h]).' '.(count($cases2[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events"));
  1043. }
  1044. $string2 = '&nbsp;';
  1045. if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
  1046. $style2 = 'peruser_notbusy';
  1047. } else {
  1048. $style2 = 'peruser_busy';
  1049. }
  1050. foreach ($cases2[$h] as $id => $ev) {
  1051. if ($ev['busy']) {
  1052. $style2 = 'peruser_busy';
  1053. }
  1054. }
  1055. }
  1056. $ids1 = ''; $ids2 = '';
  1057. if (count($cases1[$h]) && array_keys($cases1[$h])) {
  1058. $ids1 = join(',', array_keys($cases1[$h]));
  1059. }
  1060. if (count($cases2[$h]) && array_keys($cases2[$h])) {
  1061. $ids2 = join(',', array_keys($cases2[$h]));
  1062. }
  1063. if ($h == $begin_h) {
  1064. echo '<td class="'.$style.'_peruserleft cal_peruser'.($var ? ' cal_impair '.$style.'_impair' : '').'">';
  1065. } else {
  1066. echo '<td class="'.$style.' cal_peruser'.($var ? ' cal_impair '.$style.'_impair' : '').'">';
  1067. }
  1068. if (count($cases1[$h]) == 1) { // only 1 event
  1069. $output = array_slice($cases1[$h], 0, 1);
  1070. $title1 = $langs->trans("Ref").' '.$ids1.($title1 ? ' - '.$title1 : '');
  1071. if ($output[0]['string']) {
  1072. $title1 .= ($title1 ? ' - ' : '').$output[0]['string'];
  1073. }
  1074. if ($output[0]['color']) {
  1075. $color1 = $output[0]['color'];
  1076. }
  1077. } elseif (count($cases1[$h]) > 1) {
  1078. $title1 = $langs->trans("Ref").' '.$ids1.($title1 ? ' - '.$title1 : '');
  1079. $color1 = '222222';
  1080. }
  1081. if (count($cases2[$h]) == 1) { // only 1 event
  1082. $output = array_slice($cases2[$h], 0, 1);
  1083. $title2 = $langs->trans("Ref").' '.$ids2.($title2 ? ' - '.$title2 : '');
  1084. if ($output[0]['string']) {
  1085. $title2 .= ($title2 ? ' - ' : '').$output[0]['string'];
  1086. }
  1087. if ($output[0]['color']) {
  1088. $color2 = $output[0]['color'];
  1089. }
  1090. } elseif (count($cases2[$h]) > 1) {
  1091. $title2 = $langs->trans("Ref").' '.$ids2.($title2 ? ' - '.$title2 : '');
  1092. $color2 = '222222';
  1093. }
  1094. print '<table class="nobordernopadding" width="100%">';
  1095. print '<tr><td '.($color1 ? 'style="background: #'.$color1.';"' : '').'class="'.($style1 ? $style1.' ' : '').'onclickopenref'.($title1 ? ' cursorpointer' : '').'" ref="ref_'.$username->id.'_'.sprintf("%04d", $year).'_'.sprintf("%02d", $month).'_'.sprintf("%02d", $day).'_'.sprintf("%02d", $h).'_00_'.($ids1 ? $ids1 : 'none').'"'.($title1 ? ' title="'.$title1.'"' : '').'>';
  1096. print $string1;
  1097. print '</td><td '.($color2 ? 'style="background: #'.$color2.';"' : '').'class="'.($style2 ? $style2.' ' : '').'onclickopenref'.($title1 ? ' cursorpointer' : '').'" ref="ref_'.$username->id.'_'.sprintf("%04d", $year).'_'.sprintf("%02d", $month).'_'.sprintf("%02d", $day).'_'.sprintf("%02d", $h).'_30_'.($ids2 ? $ids2 : 'none').'"'.($title2 ? ' title="'.$title2.'"' : '').'>';
  1098. print $string2;
  1099. print '</td></tr>';
  1100. print '</table>';
  1101. print '</td>';
  1102. }
  1103. }