33 require
'../../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/agenda.lib.php';
39 if (!empty($conf->project->enabled)) {
40 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
43 if (!isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) {
44 $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW = 3;
47 if (empty($conf->global->AGENDA_EXT_NB)) {
48 $conf->global->AGENDA_EXT_NB = 5;
50 $MAXAGENDA = $conf->global->AGENDA_EXT_NB;
52 $disabledefaultvalues =
GETPOST(
'disabledefaultvalues',
'int');
54 $check_holiday =
GETPOST(
'check_holiday',
'int');
55 $filter =
GETPOST(
"search_filter",
'alpha', 3) ?
GETPOST(
"search_filter",
'alpha', 3) :
GETPOST(
"filter",
'alpha', 3);
56 $filtert =
GETPOST(
"search_filtert",
"int", 3) ?
GETPOST(
"search_filtert",
"int", 3) :
GETPOST(
"filtert",
"int", 3);
57 $usergroup =
GETPOST(
"search_usergroup",
"int", 3) ?
GETPOST(
"search_usergroup",
"int", 3) :
GETPOST(
"usergroup",
"int", 3);
58 $showbirthday = empty($conf->use_javascript_ajax) ?
GETPOST(
"showbirthday",
"int") : 1;
61 if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS)) {
67 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
68 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
70 if (empty($page) || $page == -1) {
73 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
74 $offset = $limit * $page;
79 $sortfield =
"a.datec";
85 $socid = $user->socid;
92 if (empty($user->rights->agenda->myactions->read)) {
95 if (empty($user->rights->agenda->allactions->read)) {
98 if (empty($user->rights->agenda->allactions->read) || $filter ==
'mine') {
102 $action =
GETPOST(
'action',
'aZ09');
104 $mode =
GETPOST(
'mode',
'aZ09');
105 if (empty($mode) && preg_match(
'/show_/', $action)) {
108 $resourceid =
GETPOST(
"search_resourceid",
"int");
109 $year =
GETPOST(
"year",
"int") ?
GETPOST(
"year",
"int") : date(
"Y");
110 $month =
GETPOST(
"month",
"int") ?
GETPOST(
"month",
"int") : date(
"m");
111 $week =
GETPOST(
"week",
"int") ?
GETPOST(
"week",
"int") : date(
"W");
113 $pid =
GETPOST(
"search_projectid",
"int", 3) ?
GETPOST(
"search_projectid",
"int", 3) :
GETPOST(
"projectid",
"int", 3);
116 $maxprint =
GETPOSTISSET(
"maxprint") ?
GETPOST(
"maxprint",
'int') : $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW;
117 $optioncss =
GETPOST(
'optioncss',
'aZ');
120 if ($dateselect > 0) {
121 $day =
GETPOST(
'dateselectday',
'int');
122 $month =
GETPOST(
'dateselectmonth',
'int');
123 $year =
GETPOST(
'dateselectyear',
'int');
127 if (
GETPOST(
'search_actioncode',
'array:aZ09')) {
128 $actioncode =
GETPOST(
'search_actioncode',
'array:aZ09', 3);
129 if (!count($actioncode)) {
133 $actioncode =
GETPOST(
"search_actioncode",
"alpha", 3) ?
GETPOST(
"search_actioncode",
"alpha", 3) : (
GETPOST(
"search_actioncode") ==
'0' ?
'0' : ((empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) || $disabledefaultvalues) ?
'' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE));
137 $status = ((empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS) || $disabledefaultvalues) ?
'' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS);
140 $defaultview = (empty($conf->global->AGENDA_DEFAULT_VIEW) ?
'show_month' : $conf->global->AGENDA_DEFAULT_VIEW);
141 $defaultview = (empty($user->conf->AGENDA_DEFAULT_VIEW) ? $defaultview : $user->conf->AGENDA_DEFAULT_VIEW);
143 $mode = $defaultview;
145 if ($mode ==
'default') {
146 $mode = (($defaultview !=
'show_list') ? $defaultview :
'show_month');
148 if (
GETPOST(
'viewcal',
'int') &&
GETPOST(
'mode',
'alpha') !=
'show_day' &&
GETPOST(
'mode',
'alpha') !=
'show_week') {
149 $mode =
'show_month'; $day =
'';
151 if (
GETPOST(
'viewweek',
'int') ||
GETPOST(
'mode',
'alpha') ==
'show_week') {
152 $mode =
'show_week'; $week = ($week ? $week : date(
"W")); $day = ($day ? $day : date(
"d"));
154 if (
GETPOST(
'viewday',
'int') ||
GETPOST(
'mode',
'alpha') ==
'show_day') {
155 $mode =
'show_day'; $day = ($day ? $day : date(
"d"));
161 $langs->loadLangs(array(
'agenda',
'other',
'commercial'));
164 $hookmanager->initHooks(array(
'agenda'));
166 $result =
restrictedArea($user,
'agenda', 0,
'actioncomm&societe',
'myactions|allactions',
'fk_soc',
'id');
167 if ($user->socid && $socid) {
176 if (
GETPOST(
"viewlist",
'alpha') || $mode ==
'show_list') {
178 if (is_array($_POST)) {
179 foreach ($_POST as $key => $val) {
180 if ($key ==
'token') {
183 $param .=
'&'.$key.
'='.urlencode($val);
186 if (!preg_match(
'/action=/', $param)) {
187 $param .= ($param ?
'&' :
'').
'mode=show_list';
190 header(
"Location: ".DOL_URL_ROOT.
'/comm/action/list.php?'.$param);
194 if (
GETPOST(
"viewperuser",
'alpha') || $mode ==
'show_peruser') {
196 if (is_array($_POST)) {
197 foreach ($_POST as $key => $val) {
198 if ($key ==
'token') {
201 $param .=
'&'.$key.
'='.urlencode($val);
205 header(
"Location: ".DOL_URL_ROOT.
'/comm/action/peruser.php?'.$param);
233 'maxprint' => $maxprint,
235 'filtert' => $filtert,
236 'showbirthday' => $showbirthday,
237 'canedit' => $canedit,
238 'optioncss' => $optioncss,
239 'actioncode' => $actioncode,
241 'resourceid' => $resourceid,
242 'usergroup' => $usergroup,
244 $reshook = $hookmanager->executeHooks(
'beforeAgenda', $parameters, $object, $action);
249 $help_url =
'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda';
253 $companystatic =
new Societe($db);
254 $contactstatic =
new Contact($db);
255 $userstatic =
new User($db);
259 $nowyear = $nowarray[
'year'];
260 $nowmonth = $nowarray[
'mon'];
261 $nowday = $nowarray[
'mday'];
263 $listofextcals = array();
266 if (empty($conf->global->AGENDA_DISABLE_EXT)) {
268 while ($i < $MAXAGENDA) {
270 $source =
'AGENDA_EXT_SRC'.$i;
271 $name =
'AGENDA_EXT_NAME'.$i;
272 $offsettz =
'AGENDA_EXT_OFFSETTZ'.$i;
273 $color =
'AGENDA_EXT_COLOR'.$i;
274 $default =
'AGENDA_EXT_ACTIVEBYDEFAULT'.$i;
275 $buggedfile =
'AGENDA_EXT_BUGGEDFILE'.$i;
276 if (!empty($conf->global->$source) && !empty($conf->global->$name)) {
278 $listofextcals[] = array(
290 if (empty($user->conf->AGENDA_DISABLE_EXT)) {
292 while ($i < $MAXAGENDA) {
294 $source =
'AGENDA_EXT_SRC_'.$user->id.
'_'.$i;
295 $name =
'AGENDA_EXT_NAME_'.$user->id.
'_'.$i;
296 $offsettz =
'AGENDA_EXT_OFFSETTZ_'.$user->id.
'_'.$i;
297 $color =
'AGENDA_EXT_COLOR_'.$user->id.
'_'.$i;
298 $enabled =
'AGENDA_EXT_ENABLED_'.$user->id.
'_'.$i;
299 $default =
'AGENDA_EXT_ACTIVEBYDEFAULT_'.$user->id.
'_'.$i;
300 $buggedfile =
'AGENDA_EXT_BUGGEDFILE_'.$user->id.
'_'.$i;
301 if (!empty($user->conf->$source) && !empty($user->conf->$name)) {
303 $listofextcals[] = array(
304 'src' => $user->conf->$source,
306 'offsettz' => (
int) (empty($user->conf->$offsettz) ? 0 : $user->conf->$offsettz),
309 'buggedfile' =>
dol_string_nohtmltag(isset($user->conf->buggedfile) ? $user->conf->buggedfile :
'')
315 if (empty($mode) || $mode ==
'show_month') {
317 $prev_year = $prev[
'year'];
318 $prev_month = $prev[
'month'];
320 $next_year = $next[
'year'];
321 $next_month = $next[
'month'];
323 $max_day_in_prev_month = date(
"t",
dol_mktime(0, 0, 0, $prev_month, 1, $prev_year,
'gmt'));
324 $max_day_in_month = date(
"t",
dol_mktime(0, 0, 0, $month, 1, $year));
326 $tmpday = -date(
"w",
dol_mktime(12, 0, 0, $month, 1, $year,
'gmt')) + 2;
327 $tmpday += ((isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1) - 1);
332 $firstdaytoshow =
dol_mktime(0, 0, 0, $prev_month, $max_day_in_prev_month + $tmpday, $prev_year,
'tzuserrel');
333 $next_day = 7 - ($max_day_in_month + 1 - $tmpday) % 7;
337 $lastdaytoshow =
dol_mktime(0, 0, 0, $next_month, $next_day, $next_year,
'tzuserrel');
339 if ($mode ==
'show_week') {
341 $prev_year = $prev[
'prev_year'];
342 $prev_month = $prev[
'prev_month'];
343 $prev_day = $prev[
'prev_day'];
344 $first_day = $prev[
'first_day'];
345 $first_month = $prev[
'first_month'];
346 $first_year = $prev[
'first_year'];
348 $week = $prev[
'week'];
352 $next_year = $next[
'year'];
353 $next_month = $next[
'month'];
354 $next_day = $next[
'day'];
357 $firstdaytoshow =
dol_mktime(0, 0, 0, $first_month, $first_day, $first_year,
'tzuserrel');
360 $max_day_in_month = date(
"t",
dol_mktime(0, 0, 0, $month, 1, $year,
'gmt'));
362 $tmpday = $first_day;
364 if ($mode ==
'show_day') {
366 $prev_year = $prev[
'year'];
367 $prev_month = $prev[
'month'];
368 $prev_day = $prev[
'day'];
370 $next_year = $next[
'year'];
371 $next_month = $next[
'month'];
372 $next_day = $next[
'day'];
374 $firstdaytoshow =
dol_mktime(0, 0, 0, $prev_month, $prev_day, $prev_year,
'tzuserrel');
375 $lastdaytoshow =
dol_mktime(0, 0, 0, $next_month, $next_day, $next_year,
'tzuserrel');
388 if (is_array($actioncode)) {
389 foreach ($actioncode as $str_action) {
390 $param .=
"&search_actioncode[]=".urlencode($str_action);
393 $param .=
"&search_actioncode=".urlencode($actioncode);
396 if ($resourceid > 0) {
397 $param .=
"&search_resourceid=".urlencode($resourceid);
400 $param .=
"&search_status=".urlencode($status);
403 $param .=
"&search_filter=".urlencode($filter);
406 $param .=
"&search_filtert=".urlencode($filtert);
408 if ($usergroup > 0) {
409 $param .=
"&search_usergroup=".urlencode($usergroup);
412 $param .=
"&search_socid=".urlencode($socid);
415 $param .=
"&search_showbirthday=1";
418 $param .=
"&search_projectid=".urlencode($pid);
421 $param .=
"&search_type=".urlencode($type);
423 $param .=
"&maxprint=".urlencode($maxprint);
424 if ($mode ==
'show_day' || $mode ==
'show_week' || $mode ==
'show_month') {
425 $param .=
'&mode='.urlencode($mode);
429 if (empty($mode) || $mode ==
'show_month') {
430 $nav =
"<a href=\"?year=".$prev_year.
"&month=".$prev_month.$param.
"\"><i class=\"fa fa-chevron-left\"></i></a> \n";
431 $nav .=
" <span id=\"month_name\">".dol_print_date(
dol_mktime(0, 0, 0, $month, 1, $year),
"%b %Y");
432 $nav .=
" </span>\n";
433 $nav .=
" <a href=\"?year=".$next_year.
"&month=".$next_month.$param.
"\"><i class=\"fa fa-chevron-right\"></i></a>\n";
434 if (empty($conf->dol_optimize_smallscreen)) {
435 $nav .=
" <a href=\"?year=".$nowyear.
"&month=".$nowmonth.$param.
"\">".$langs->trans(
"Today").
"</a> ";
439 if ($mode ==
'show_week') {
440 $nav =
"<a href=\"?year=".$prev_year.
"&month=".$prev_month.
"&day=".$prev_day.$param.
"\"><i class=\"fa fa-chevron-left\" title=\"".
dol_escape_htmltag($langs->trans(
"Previous")).
"\"></i></a> \n";
441 $nav .=
" <span id=\"month_name\">".dol_print_date(
dol_mktime(0, 0, 0, $first_month, $first_day, $first_year),
"%Y").
", ".$langs->trans(
"Week").
" ".$week;
442 $nav .=
" </span>\n";
443 $nav .=
" <a href=\"?year=".$next_year.
"&month=".$next_month.
"&day=".$next_day.$param.
"\"><i class=\"fa fa-chevron-right\" title=\"".
dol_escape_htmltag($langs->trans(
"Next")).
"\"></i></a>\n";
444 if (empty($conf->dol_optimize_smallscreen)) {
445 $nav .=
" <a href=\"?year=".$nowyear.
"&month=".$nowmonth.
"&day=".$nowday.$param.
"\">".$langs->trans(
"Today").
"</a> ";
447 $picto =
'calendarweek';
449 if ($mode ==
'show_day') {
450 $nav =
"<a href=\"?year=".$prev_year.
"&month=".$prev_month.
"&day=".$prev_day.$param.
"\"><i class=\"fa fa-chevron-left\"></i></a> \n";
451 $nav .=
" <span id=\"month_name\">".dol_print_date(
dol_mktime(0, 0, 0, $month, $day, $year),
"daytextshort");
452 $nav .=
" </span>\n";
453 $nav .=
" <a href=\"?year=".$next_year.
"&month=".$next_month.
"&day=".$next_day.$param.
"\"><i class=\"fa fa-chevron-right\"></i></a>\n";
454 if (empty($conf->dol_optimize_smallscreen)) {
455 $nav .=
" <a href=\"?year=".$nowyear.
"&month=".$nowmonth.
"&day=".$nowday.$param.
"\">".$langs->trans(
"Today").
"</a> ";
457 $picto =
'calendarday';
460 $nav .=
$form->selectDate($dateselect,
'dateselect', 0, 0, 1,
'', 1, 0);
462 $nav .=
'<button type="submit" class="liste_titre button_search valignmiddle" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
465 $paramnodate = $param;
466 $param .=
'&year='.$year.
'&month='.$month.($day ?
'&day='.$day :
'');
481 $paramnoaction = preg_replace(
'/mode=[a-z_]+/',
'', preg_replace(
'/action=[a-z_]+/',
'', $param));
482 $paramnoactionodate = preg_replace(
'/mode=[a-z_]+/',
'', preg_replace(
'/action=[a-z_]+/',
'', $paramnodate));
486 print
'<form method="POST" id="searchFormList" class="listactionsfilter" action="'.$_SERVER[
"PHP_SELF"].
'">'.
"\n";
487 if ($optioncss !=
'') {
488 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
490 print
'<input type="hidden" name="token" value="'.newToken().
'">';
491 print
'<input type="hidden" name="mode" value="'.$mode.
'">';
498 $viewmode .=
'<a class="btnTitle reposition" href="'.DOL_URL_ROOT.
'/comm/action/list.php?mode=show_list&restore_lastsearch_values=1'.$paramnoactionodate.
'">';
500 $viewmode .=
img_picto($langs->trans(
"List"),
'object_calendarlist',
'class="imgforviewmode pictoactionview block"');
502 $viewmode .=
'<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans(
"ViewList").
'</span></a>';
504 $viewmode .=
'<a class="btnTitle'.($mode ==
'show_month' ?
' btnTitleSelected' :
'').
' reposition" href="'.DOL_URL_ROOT.
'/comm/action/index.php?mode=show_month&year='.(isset($object->datep) ?
dol_print_date($object->datep,
'%Y') : $year).
'&month='.(isset($object->datep) ?
dol_print_date($object->datep,
'%m') : $month).
'&day='.(isset($object->datep) ?
dol_print_date($object->datep,
'%d') : $day).$paramnoactionodate.
'">';
506 $viewmode .=
img_picto($langs->trans(
"ViewCal"),
'object_calendarmonth',
'class="pictoactionview block"');
508 $viewmode .=
'<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans(
"ViewCal").
'</span></a>';
510 $viewmode .=
'<a class="btnTitle'.($mode ==
'show_week' ?
' btnTitleSelected' :
'').
' reposition" href="'.DOL_URL_ROOT.
'/comm/action/index.php?mode=show_week&year='.(isset($object->datep) ?
dol_print_date($object->datep,
'%Y') : $year).
'&month='.(isset($object->datep) ?
dol_print_date($object->datep,
'%m') : $month).
'&day='.(isset($object->datep) ?
dol_print_date($object->datep,
'%d') : $day).$paramnoactionodate.
'">';
512 $viewmode .=
img_picto($langs->trans(
"ViewWeek"),
'object_calendarweek',
'class="pictoactionview block"');
514 $viewmode .=
'<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans(
"ViewWeek").
'</span></a>';
516 $viewmode .=
'<a class="btnTitle'.($mode ==
'show_day' ?
' btnTitleSelected' :
'').
' reposition" href="'.DOL_URL_ROOT.
'/comm/action/index.php?mode=show_day&year='.(isset($object->datep) ?
dol_print_date($object->datep,
'%Y') : $year).
'&month='.(isset($object->datep) ?
dol_print_date($object->datep,
'%m') : $month).
'&day='.(isset($object->datep) ?
dol_print_date($object->datep,
'%d') : $day).$paramnoactionodate.
'">';
518 $viewmode .=
img_picto($langs->trans(
"ViewDay"),
'object_calendarday',
'class="pictoactionview block"');
520 $viewmode .=
'<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans(
"ViewDay").
'</span></a>';
522 $viewmode .=
'<a class="btnTitle reposition" href="'.DOL_URL_ROOT.
'/comm/action/peruser.php?mode=show_peruser&year='.(isset($object->datep) ?
dol_print_date($object->datep,
'%Y') : $year).
'&month='.(isset($object->datep) ?
dol_print_date($object->datep,
'%m') : $month).
'&day='.(isset($object->datep) ?
dol_print_date($object->datep,
'%d') : $day).$paramnoactionodate.
'">';
524 $viewmode .=
img_picto($langs->trans(
"ViewPerUser"),
'object_calendarperuser',
'class="pictoactionview block"');
526 $viewmode .=
'<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans(
"ViewPerUser").
'</span></a>';
529 $parameters = array(); $object =
null;
530 $reshook = $hookmanager->executeHooks(
'addCalendarView', $parameters, $object, $action);
531 if (empty($reshook)) {
532 $viewmode .= $hookmanager->resPrint;
533 } elseif ($reshook > 1) {
534 $viewmode = $hookmanager->resPrint;
537 $viewmode .=
'<span class="marginrightonly"></span>';
542 if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
545 $newparam .=
'&month='.((int) $month).
'&year='.((int) $tmpforcreatebutton[
'year']).
'&mode='.urlencode($mode);
550 $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 :
'')));
556 $showextcals = $listofextcals;
558 if (!empty($conf->use_javascript_ajax)) {
559 $s .=
"\n".
'<!-- Div to calendars selectors -->'.
"\n";
560 $s .=
'<script type="text/javascript">'.
"\n";
561 $s .=
'jQuery(document).ready(function () {'.
"\n";
562 $s .=
'jQuery(".check_birthday").click(function() { console.log("Toggle birthdays"); jQuery(".family_birthday").toggle(); });'.
"\n";
563 $s .=
'jQuery(".check_holiday").click(function() { console.log("Toggle holidays"); jQuery(".family_holiday").toggle(); });'.
"\n";
564 if ($mode ==
"show_week" || $mode ==
"show_month" || empty($mode)) {
566 $s .=
'jQuery( "div.sortable" ).sortable({connectWith: ".sortable", placeholder: "ui-state-highlight", items: "div.movable", receive: function( event, ui ) {'.
"\n";
568 $s .=
'console.log("submit form to record new event");'.
"\n";
570 $s .=
'var newval = jQuery(event.target).closest("div.dayevent").attr("id");'.
"\n";
571 $s .=
'console.log("found parent div.dayevent with id = "+newval);'.
"\n";
572 $s .=
'var frm=jQuery("#searchFormList");'.
"\n";
573 $s .=
'var newurl = ui.item.find("a.cal_event").attr("href");'.
"\n";
574 $s .=
'console.log("Found url on href of a.cal_event"+newurl+", we submit form with actionmove=mupdate");'.
"\n";
575 $s .=
'frm.attr("action", newurl).children("#newdate").val(newval);frm.submit();}'.
"\n";
579 $s .=
'</script>'.
"\n";
582 $s .=
'<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_mytasks" name="check_mytasks" value="1" checked disabled> '.$langs->trans(
"LocalAgenda").
' </div>';
584 if ($user->rights->holiday->read) {
587 <div class="nowrap inline-block minheight30"><input type="checkbox" id="check_holiday" name="check_holiday" value="1" class="check_holiday"' . ($check_holiday
588 ?
' checked' :
'') .
'>
589 <label for="check_holiday">
590 <span class="check_holiday_text">' . $langs->trans(
"Holidays") .
'</span>
596 if (is_array($showextcals) && count($showextcals) > 0) {
597 $s .=
'<script type="text/javascript">'.
"\n";
598 $s .=
'jQuery(document).ready(function () {
599 jQuery("div input[name^=\"check_ext\"]").each(function(index, elem) {
600 var name = jQuery(elem).attr("name");
601 if (jQuery(elem).is(":checked")) {
602 jQuery(".family_ext" + name.replace("check_ext", "")).show();
604 jQuery(".family_ext" + name.replace("check_ext", "")).hide();
608 jQuery("div input[name^=\"check_ext\"]").click(function() {
609 var name = $(this).attr("name");
610 jQuery(".family_ext" + name.replace("check_ext", "")).toggle();
613 $s .=
'</script>'.
"\n";
615 foreach ($showextcals as $val) {
616 $htmlname = md5($val[
'name']);
618 if (!empty($val[
'default']) ||
GETPOST(
'check_ext'.$htmlname,
'int')) {
619 $default =
"checked";
624 $s .=
'<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_ext'.$htmlname.
'" name="check_ext'.$htmlname.
'" value="1" '.$default.
'> <label for="check_ext'.$htmlname.
'">'.
dol_escape_htmltag($val[
'name']).
'</label> </div>';
629 $s .=
'<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_birthday" name="check_birthday" class="check_birthday"><label for="check_birthday"> <span class="check_birthday_text">'.$langs->trans(
"AgendaShowBirthdayEvents").
'</span></label> </div>';
632 $parameters = array();
633 $reshook = $hookmanager->executeHooks(
'addCalendarChoice', $parameters, $object, $action);
634 if (empty($reshook)) {
635 $s .= $hookmanager->resPrint;
636 } elseif ($reshook > 1) {
637 $s = $hookmanager->resPrint;
640 $s .=
"\n".
'<!-- End div to calendars selectors -->'.
"\n";
643 $newparam = preg_replace(
'/showbirthday=[0-1]/i',
'showbirthday='.(empty($showbirthday) ? 1 : 0), $newparam);
644 if (!preg_match(
'/showbirthday=/i', $newparam)) {
645 $newparam .=
'&showbirthday=1';
649 if (empty($showbirthday)) {
650 $link .= $langs->trans(
"AgendaShowBirthdayEvents");
652 $link .= $langs->trans(
"AgendaHideBirthdayEvents");
659 $eventarray = array();
664 if ($usergroup > 0) {
667 $sql .=
' a.id, a.label,';
669 $sql .=
' a.datep2,';
670 $sql .=
' a.percent,';
671 $sql .=
' a.fk_user_author,a.fk_user_action,';
672 $sql .=
' a.transparency, a.priority, a.fulldayevent, a.location,';
673 $sql .=
' a.fk_soc, a.fk_contact, a.fk_project,';
674 $sql .=
' a.fk_element, a.elementtype,';
675 $sql .=
' ca.code as type_code, ca.libelle as type_label, ca.color as type_color, ca.type as type_type, ca.picto as type_picto';
676 $sql .=
' FROM '.MAIN_DB_PREFIX.
'c_actioncomm as ca, '.MAIN_DB_PREFIX.
"actioncomm as a";
677 if (empty($user->rights->societe->client->voir) && !$socid) {
678 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
681 if ($resourceid > 0) {
682 $sql .=
", ".MAIN_DB_PREFIX.
"element_resources as r";
685 if ($filtert > 0 || $usergroup > 0) {
686 $sql .=
", ".MAIN_DB_PREFIX.
"actioncomm_resources as ar";
688 if ($usergroup > 0) {
689 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
691 $sql .=
' WHERE a.fk_action = ca.id';
692 $sql .=
' AND a.entity IN ('.getEntity(
'agenda').
')';
694 if (!empty($actioncode)) {
695 if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
696 if ($actioncode ==
'AC_NON_AUTO') {
697 $sql .=
" AND ca.type != 'systemauto'";
698 } elseif ($actioncode ==
'AC_ALL_AUTO') {
699 $sql .=
" AND ca.type = 'systemauto'";
701 if ($actioncode ==
'AC_OTH') {
702 $sql .=
" AND ca.type != 'systemauto'";
704 if ($actioncode ==
'AC_OTH_AUTO') {
705 $sql .=
" AND ca.type = 'systemauto'";
709 if ($actioncode ==
'AC_NON_AUTO') {
710 $sql .=
" AND ca.type != 'systemauto'";
711 } elseif ($actioncode ==
'AC_ALL_AUTO') {
712 $sql .=
" AND ca.type = 'systemauto'";
714 if (is_array($actioncode)) {
715 $sql .=
" AND ca.code IN (".$db->sanitize(
"'".implode(
"','", $actioncode).
"'", 1).
")";
717 $sql .=
" AND ca.code IN (".$db->sanitize(
"'".implode(
"','", explode(
',', $actioncode)).
"'", 1).
")";
722 if ($resourceid > 0) {
723 $sql .=
" AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".((int) $resourceid);
726 $sql .=
" AND a.fk_project=".((int) $pid);
728 if (empty($user->rights->societe->client->voir) && !$socid) {
729 $sql .=
" AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).
")";
732 $sql .=
" AND a.fk_soc = ".((int) $socid);
735 if ($filtert > 0 || $usergroup > 0) {
736 $sql .=
" AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
739 if ($mode ==
'show_day') {
741 $sql .=
" (a.datep BETWEEN '".$db->idate(
dol_mktime(0, 0, 0, $month, $day, $year,
'tzuserrel')).
"'";
742 $sql .=
" AND '".$db->idate(
dol_mktime(23, 59, 59, $month, $day, $year,
'tzuserrel')).
"')";
744 $sql .=
" (a.datep2 BETWEEN '".$db->idate(
dol_mktime(0, 0, 0, $month, $day, $year,
'tzuserrel')).
"'";
745 $sql .=
" AND '".$db->idate(
dol_mktime(23, 59, 59, $month, $day, $year,
'tzuserrel')).
"')";
747 $sql .=
" (a.datep < '".$db->idate(
dol_mktime(0, 0, 0, $month, $day, $year,
'tzuserrel')).
"'";
748 $sql .=
" AND a.datep2 > '".$db->idate(
dol_mktime(23, 59, 59, $month, $day, $year,
'tzuserrel')).
"')";
753 $sql .=
" (a.datep BETWEEN '".$db->idate(
dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7)).
"'";
754 $sql .=
" AND '".$db->idate(
dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10)).
"')";
756 $sql .=
" (a.datep2 BETWEEN '".$db->idate(
dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7)).
"'";
757 $sql .=
" AND '".$db->idate(
dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10)).
"')";
759 $sql .=
" (a.datep < '".$db->idate(
dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7)).
"'";
760 $sql .=
" AND a.datep2 > '".$db->idate(
dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10)).
"')";
764 $sql .=
" AND ca.id = ".((int) $type);
766 if ($status ==
'0') {
767 $sql .=
" AND a.percent = 0";
769 if ($status ==
'-1' || $status ==
'na') {
771 $sql .=
" AND a.percent = -1";
773 if ($status ==
'50') {
775 $sql .=
" AND (a.percent > 0 AND a.percent < 100)";
777 if ($status ==
'done' || $status ==
'100') {
778 $sql .=
" AND (a.percent = 100)";
780 if ($status ==
'todo') {
781 $sql .=
" AND (a.percent >= 0 AND a.percent < 100)";
784 if ($filtert > 0 || $usergroup > 0) {
787 $sql .=
"ar.fk_element = ".((int) $filtert);
789 if ($usergroup > 0) {
790 $sql .= ($filtert > 0 ?
" OR " :
"").
" ugu.fk_usergroup = ".((
int) $usergroup);
795 $sql .=
' ORDER BY datep';
799 dol_syslog(
"comm/action/index.php", LOG_DEBUG);
800 $resql = $db->query($sql);
802 $num = $db->num_rows(
$resql);
804 $MAXONSAMEPAGE = 10000;
806 while ($i < $num && $i < $MAXONSAMEPAGE) {
807 $obj = $db->fetch_object(
$resql);
810 if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->type_code ==
'AC_OTH_AUTO') {
818 $event->id = $obj->id;
819 $event->ref = $event->id;
821 $event->fulldayevent = $obj->fulldayevent;
824 if ($event->fulldayevent) {
826 $event->datep = $db->jdate($obj->datep, $tzforfullday ?
'tzuser' :
'tzserver');
827 $event->datef = $db->jdate($obj->datep2, $tzforfullday ?
'tzuser' :
'tzserver');
830 $event->datep = $db->jdate($obj->datep,
'tzserver');
831 $event->datef = $db->jdate($obj->datep2,
'tzserver');
837 $event->type_code = $obj->type_code;
838 $event->type_label = $obj->type_label;
839 $event->type_color = $obj->type_color;
840 $event->type = $obj->type_type;
841 $event->type_picto = $obj->type_picto;
843 $event->libelle = $obj->label;
844 $event->label = $obj->label;
845 $event->percentage = $obj->percent;
847 $event->authorid = $obj->fk_user_author;
848 $event->userownerid = $obj->fk_user_action;
849 $event->fetch_userassigned();
851 $event->priority = $obj->priority;
852 $event->location = $obj->location;
853 $event->transparency = $obj->transparency;
854 $event->fk_element = $obj->fk_element;
855 $event->elementtype = $obj->elementtype;
857 $event->fk_project = $obj->fk_project;
859 $event->socid = $obj->fk_soc;
860 $event->contact_id = $obj->fk_contact;
864 $event->date_start_in_calendar = $event->datep;
865 if ($event->datef !=
'' && $event->datef >= $event->datep) {
866 $event->date_end_in_calendar = $event->datef;
868 $event->date_end_in_calendar = $event->datep;
872 if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow) {
875 if ($event->date_start_in_calendar < $firstdaytoshow) {
876 $event->date_start_in_calendar = $firstdaytoshow;
878 if ($event->date_end_in_calendar >= $lastdaytoshow) {
879 $event->date_end_in_calendar = ($lastdaytoshow - 1);
883 $daycursor = $event->date_start_in_calendar;
888 $daycursorend = $event->date_end_in_calendar;
898 $loop =
true; $j = 0;
899 $daykey =
dol_mktime(0, 0, 0, $mois, $jour, $annee,
'gmt');
900 $daykeyend =
dol_mktime(0, 0, 0, $moisend, $jourend, $anneeend,
'gmt');
914 $eventarray[$daykey][] = $event;
917 $daykey += 60 * 60 * 24;
919 if ($daykey > $daykeyend) {
938 $sql =
'SELECT sp.rowid, sp.lastname, sp.firstname, sp.birthday';
939 $sql .=
' FROM '.MAIN_DB_PREFIX.
'socpeople as sp';
940 $sql .=
' WHERE (priv=0 OR (priv=1 AND fk_user_creat='.((int) $user->id).
'))';
941 $sql .=
" AND sp.entity IN (".getEntity(
'contact').
")";
942 if ($mode ==
'show_day') {
943 $sql .=
' AND MONTH(birthday) = '.((int) $month);
944 $sql .=
' AND DAY(birthday) = '.((int) $day);
946 $sql .=
' AND MONTH(birthday) = '.((int) $month);
948 $sql .=
' ORDER BY birthday';
950 dol_syslog(
"comm/action/index.php", LOG_DEBUG);
951 $resql = $db->query($sql);
953 $num = $db->num_rows(
$resql);
956 $obj = $db->fetch_object(
$resql);
960 $event->id = $obj->rowid;
961 $event->ref = $event->id;
966 $event->datep =
dol_mktime(0, 0, 0, $datearray[
'mon'], $datearray[
'mday'], $year,
true);
967 $event->datef = $event->datep;
969 $event->type_code =
'BIRTHDAY';
970 $event->type_label =
'';
971 $event->type_color =
'';
972 $event->type =
'birthdate';
973 $event->type_picto =
'birthdate';
975 $event->label = $langs->trans(
"Birthday").
' '.
dolGetFirstLastname($obj->firstname, $obj->lastname);
976 $event->percentage = 100;
977 $event->fulldayevent = 1;
979 $event->date_start_in_calendar = $db->jdate($event->datep);
980 $event->date_end_in_calendar = $db->jdate($event->datef);
983 $daycursor = $event->datep;
988 $daykey =
dol_mktime(0, 0, 0, $mois, $jour, $annee,
'gmt');
990 $eventarray[$daykey][] = $event;
1007 if ($user->rights->holiday->read) {
1009 $sql =
"SELECT u.rowid as uid, u.lastname, u.firstname, u.statut, x.rowid, x.date_debut as date_start, x.date_fin as date_end, x.halfday, x.statut as status";
1010 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as x, ".MAIN_DB_PREFIX.
"user as u";
1011 $sql .=
" WHERE u.rowid = x.fk_user";
1012 $sql .=
" AND u.statut = '1'";
1013 $sql .=
" AND (x.statut = '2' OR x.statut = '3')";
1015 if ($mode ==
'show_day') {
1017 $sql .=
" AND '".$db->escape($year).
"-".$db->escape($month).
"-".$db->escape($day).
"' BETWEEN x.date_debut AND x.date_fin";
1018 } elseif ($mode ==
'show_week') {
1020 } elseif ($mode ==
'show_month') {
1024 $resql = $db->query($sql);
1026 $num = $db->num_rows(
$resql);
1030 $obj = $db->fetch_object(
$resql);
1035 $event->id = $obj->rowid;
1036 $event->ref = $event->id;
1038 $event->type_code =
'HOLIDAY';
1039 $event->type_label =
'';
1040 $event->type_color =
'';
1041 $event->type =
'holiday';
1042 $event->type_picto =
'holiday';
1044 $event->datep = $db->jdate($obj->date_start) + (empty($halfday) || $halfday == 1 ? 0 : 12 * 60 * 60 - 1);
1045 $event->datef = $db->jdate($obj->date_end) + (empty($halfday) || $halfday == -1 ? 24 : 12) * 60 * 60 - 1;
1046 $event->date_start_in_calendar = $event->datep;
1047 $event->date_end_in_calendar = $event->datef;
1049 if ($obj->status == 3) {
1051 $event->percentage = -1;
1052 } elseif ($obj->status == 2) {
1054 $event->percentage = 0;
1057 if ($obj->halfday == 1) {
1058 $event->label = $obj->lastname.
' ('.$langs->trans(
"Morning").
')';
1059 } elseif ($obj->halfday == -1) {
1060 $event->label = $obj->lastname.
' ('.$langs->trans(
"Afternoon").
')';
1062 $event->label = $obj->lastname;
1065 $daycursor = $event->date_start_in_calendar;
1070 $daykey =
dol_mktime(0, 0, 0, $mois, $jour, $annee,
'gmt');
1072 $eventarray[$daykey][] = $event;
1074 $daykey += 60 * 60 * 24;
1075 }
while ($daykey <= $event->date_end_in_calendar);
1084 if (count($listofextcals)) {
1085 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/ical.class.php';
1086 foreach ($listofextcals as $extcal) {
1087 $url = $extcal[
'src'];
1088 $namecal = $extcal[
'name'];
1089 $offsettz = $extcal[
'offsettz'];
1090 $colorcal = $extcal[
'color'];
1091 $buggedfile = $extcal[
'buggedfile'];
1098 $icalevents = array();
1099 if (is_array($ical->get_event_list())) {
1100 $icalevents = array_merge($icalevents, $ical->get_event_list());
1102 if (is_array($ical->get_freebusy_list())) {
1103 $icalevents = array_merge($icalevents, $ical->get_freebusy_list());
1106 if (count($icalevents) > 0) {
1108 $moreicalevents = array();
1109 foreach ($icalevents as $icalevent) {
1110 if (isset($icalevent[
'RRULE']) && is_array($icalevent[
'RRULE'])) {
1113 if ($icalevent[
'DTSTART;VALUE=DATE']) {
1116 } elseif (is_array($icalevent[
'DTSTART']) && !empty($icalevent[
'DTSTART'][
'unixtime'])) {
1117 $datecurstart = $icalevent[
'DTSTART'][
'unixtime'];
1118 $datecurend = $icalevent[
'DTEND'][
'unixtime'];
1119 if (!empty($ical->cal[
'DAYLIGHT'][
'DTSTART']) && $datecurstart) {
1121 $tmpcurstart = $datecurstart;
1122 $tmpcurend = $datecurend;
1123 $tmpdaylightstart =
dol_mktime(0, 0, 0, 1, 1, 1970, 1) + (int) $ical->cal[
'DAYLIGHT'][
'DTSTART'];
1124 $tmpdaylightend =
dol_mktime(0, 0, 0, 1, 1, 1970, 1) + (int) $ical->cal[
'STANDARD'][
'DTSTART'];
1127 if ($tmpcurstart >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) {
1128 $datecurstart -= ((int) $ical->cal[
'DAYLIGHT'][
'TZOFFSETTO']) * 36;
1130 $datecurstart -= ((int) $ical->cal[
'STANDARD'][
'TZOFFSETTO']) * 36;
1132 if ($tmpcurend >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) {
1133 $datecurend -= ((int) $ical->cal[
'DAYLIGHT'][
'TZOFFSETTO']) * 36;
1135 $datecurend -= ((int) $ical->cal[
'STANDARD'][
'TZOFFSETTO']) * 36;
1142 dol_syslog(
"Found a not recognized repeatable record with unknown date start", LOG_ERR);
1147 $interval = (empty($icalevent[
'RRULE'][
'INTERVAL']) ? 1 : $icalevent[
'RRULE'][
'INTERVAL']);
1148 $until = empty($icalevent[
'RRULE'][
'UNTIL']) ? 0 :
dol_stringtotime($icalevent[
'RRULE'][
'UNTIL'], 1);
1149 $maxrepeat = empty($icalevent[
'RRULE'][
'COUNT']) ? 0 : $icalevent[
'RRULE'][
'COUNT'];
1150 if ($until && ($until + ($datecurend - $datecurstart)) < $firstdaytoshow) {
1153 if ($datecurstart >= $lastdaytoshow) {
1158 while (($datecurstart < $lastdaytoshow) && (empty($maxrepeat) || ($numofevent < $maxrepeat))) {
1159 if ($datecurend >= $firstdaytoshow) {
1160 $newevent = $icalevent;
1161 unset($newevent[
'RRULE']);
1162 if ($icalevent[
'DTSTART;VALUE=DATE']) {
1163 $newevent[
'DTSTART;VALUE=DATE'] =
dol_print_date($datecurstart,
'%Y%m%d');
1164 $newevent[
'DTEND;VALUE=DATE'] =
dol_print_date($datecurend + 1,
'%Y%m%d');
1166 $newevent[
'DTSTART'] = $datecurstart;
1167 $newevent[
'DTEND'] = $datecurend;
1169 $moreicalevents[] = $newevent;
1173 $savdatecurstart = $datecurstart;
1174 if ($icalevent[
'RRULE'][
'FREQ'] ==
'DAILY') {
1178 if ($icalevent[
'RRULE'][
'FREQ'] ==
'WEEKLY') {
1181 } elseif ($icalevent[
'RRULE'][
'FREQ'] ==
'MONTHLY') {
1184 } elseif ($icalevent[
'RRULE'][
'FREQ'] ==
'YEARLY') {
1189 if ($savdatecurstart >= $datecurstart) {
1190 dol_syslog(
"Found a rule freq ".$icalevent[
'RRULE'][
'FREQ'].
" not managed by dolibarr code. Assume 1 week frequency.", LOG_ERR);
1191 $datecurstart += 3600 * 24 * 7;
1192 $datecurend += 3600 * 24 * 7;
1197 $icalevents = array_merge($icalevents, $moreicalevents);
1200 foreach ($icalevents as $icalevent) {
1205 if (!empty($icalevent[
'RRULE'])) {
1212 if (isset($icalevent[
'DTSTART;VALUE=DATE'])) {
1215 if (empty($icalevent[
'DTEND;VALUE=DATE'])) {
1216 $dateend = $datestart + 86400 - 1;
1222 $event->fulldayevent = 1;
1224 } elseif (!is_array($icalevent[
'DTSTART'])) {
1225 $datestart = $icalevent[
'DTSTART'];
1226 $dateend = empty($icalevent[
'DTEND']) ? $datestart : $icalevent[
'DTEND'];
1228 $datestart += +($offsettz * 3600);
1229 $dateend += +($offsettz * 3600);
1234 } elseif (isset($icalevent[
'DTSTART'][
'unixtime'])) {
1235 $datestart = $icalevent[
'DTSTART'][
'unixtime'];
1236 $dateend = $icalevent[
'DTEND'][
'unixtime'];
1238 $datestart += +($offsettz * 3600);
1239 $dateend += +($offsettz * 3600);
1242 if ($buggedfile ===
'uselocalandtznodaylight') {
1246 if ($buggedfile ===
'uselocalandtzdaylight') {
1247 $localtzs =
new DateTimeZone(preg_replace(
'/"/',
'', $icalevent[
'DTSTART'][
'TZID']));
1248 $localtze =
new DateTimeZone(preg_replace(
'/"/',
'', $icalevent[
'DTEND'][
'TZID']));
1249 $localdts =
new DateTime(
dol_print_date($datestart,
'dayrfc',
'gmt'), $localtzs);
1250 $localdte =
new DateTime(
dol_print_date($dateend,
'dayrfc',
'gmt'), $localtze);
1251 $tmps = -1 * $localtzs->getOffset($localdts);
1252 $tmpe = -1 * $localtze->getOffset($localdte);
1253 $datestart += $tmps;
1261 $event->id = $icalevent[
'UID'];
1262 $event->ref = $event->id;
1263 $userId = $userstatic->findUserIdByEmail($namecal);
1264 if (!empty($userId) && $userId > 0) {
1265 $event->userassigned[$userId] = $userId;
1266 $event->percentage = -1;
1269 $event->type_code =
"ICALEVENT";
1270 $event->type_label = $namecal;
1271 $event->type_color = $colorcal;
1272 $event->type =
'icalevent';
1273 $event->type_picto =
'rss';
1275 $event->icalname = $namecal;
1276 $event->icalcolor = $colorcal;
1278 $event->datep = $datestart + $usertime;
1279 $event->datef = $dateend + $usertime;
1281 if ($icalevent[
'SUMMARY']) {
1282 $event->label = $icalevent[
'SUMMARY'];
1283 } elseif ($icalevent[
'DESCRIPTION']) {
1284 $event->label =
dol_nl2br($icalevent[
'DESCRIPTION'], 1);
1286 $event->label = $langs->trans(
"ExtSiteNoLabel");
1293 if (!empty($icalevent[
'PRIORITY'])) {
1294 $event->priority = $icalevent[
'PRIORITY'];
1298 if ($icalevent[
'TRANSP']) {
1299 if ($icalevent[
'TRANSP'] ==
"TRANSPARENT") {
1300 $event->transparency = 0;
1302 if ($icalevent[
'TRANSP'] ==
"OPAQUE") {
1303 $event->transparency = 1;
1314 if (!empty($icalevent[
'LOCATION'])) {
1315 $event->location = $icalevent[
'LOCATION'];
1318 $event->date_start_in_calendar = $event->datep;
1320 if ($event->datef !=
'' && $event->datef >= $event->datep) {
1321 $event->date_end_in_calendar = $event->datef;
1323 $event->date_end_in_calendar = $event->datep;
1327 if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow) {
1333 if ($event->date_start_in_calendar < $firstdaytoshow) {
1334 $event->date_start_in_calendar = $firstdaytoshow;
1336 if ($event->date_end_in_calendar >= $lastdaytoshow) {
1337 $event->date_end_in_calendar = ($lastdaytoshow - 1);
1341 $daycursor = $event->date_start_in_calendar;
1347 $loop =
true; $j = 0;
1349 $daykey =
dol_mktime(0, 0, 0, $mois, $jour, $annee,
'gmt');
1350 $daykeygmt =
dol_mktime(0, 0, 0, $mois, $jour, $annee,
'gmt');
1353 $eventarray[$daykey][] = $event;
1354 $daykey += 60 * 60 * 24; $daykeygmt += 60 * 60 * 24;
1355 if (($event->fulldayevent ? $daykeygmt : $daykey) > $event->date_end_in_calendar) {
1369 $parameters = array(); $object =
null;
1370 $reshook = $hookmanager->executeHooks(
'getCalendarEvents', $parameters, $object, $action);
1371 if (!empty($hookmanager->resArray[
'eventarray'])) {
1372 foreach ($hookmanager->resArray[
'eventarray'] as $keyDate => $events) {
1373 if (!isset($eventarray[$keyDate])) {
1374 $eventarray[$keyDate] = array();
1376 $eventarray[$keyDate] = array_merge($eventarray[$keyDate], $events);
1381 foreach ($eventarray as $keyDate => &$dateeventarray) {
1382 usort($dateeventarray,
'sort_events_by_date');
1387 $cachethirdparties = array();
1388 $cachecontacts = array();
1389 $cacheusers = array();
1392 $color_file = DOL_DOCUMENT_ROOT.
"/theme/".$conf->theme.
"/theme_vars.inc.php";
1393 if (is_readable($color_file)) {
1394 include $color_file;
1396 if (!is_array($theme_datacolor)) {
1397 $theme_datacolor = array(array(120, 130, 150), array(200, 160, 180), array(190, 190, 220));
1400 $massactionbutton =
'';
1402 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);
1408 if (empty($mode) || $mode ==
'show_month') {
1410 $newparam = preg_replace(
'/showbirthday=/i',
'showbirthday_=', $newparam);
1411 $newparam = preg_replace(
'/mode=show_month&?/i',
'', $newparam);
1412 $newparam = preg_replace(
'/mode=show_week&?/i',
'', $newparam);
1413 $newparam = preg_replace(
'/day=[0-9]+&?/i',
'', $newparam);
1414 $newparam = preg_replace(
'/month=[0-9]+&?/i',
'', $newparam);
1415 $newparam = preg_replace(
'/year=[0-9]+&?/i',
'', $newparam);
1416 $newparam = preg_replace(
'/viewcal=[0-9]+&?/i',
'', $newparam);
1417 $newparam = preg_replace(
'/showbirthday_=/i',
'showbirthday=', $newparam);
1418 $newparam .=
'&viewcal=1';
1420 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
1421 print_actions_filter(
$form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup,
'', $resourceid);
1424 print
'<div class="div-table-responsive-no-min sectioncalendarbymonth maxscreenheightless300">';
1425 print
'<table class="centpercent noborder nocellnopadd cal_pannel cal_month">';
1426 print
' <tr class="liste_titre">';
1428 echo
' <td class="center">#</td>';
1431 print
' <td class="center bold uppercase tdfordaytitle'.($i == 0 ?
' borderleft' :
'').
'">';
1432 $numdayinweek = (($i + (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1)) % 7);
1433 if (!empty($conf->dol_optimize_smallscreen)) {
1434 $labelshort = array(0=>
'SundayMin', 1=>
'MondayMin', 2=>
'TuesdayMin', 3=>
'WednesdayMin', 4=>
'ThursdayMin', 5=>
'FridayMin', 6=>
'SaturdayMin');
1435 print $langs->trans($labelshort[$numdayinweek]);
1437 print $langs->trans(
"Day".$numdayinweek);
1439 print
' </td>'.
"\n";
1445 $todaytms =
dol_mktime(0, 0, 0, $todayarray[
'mon'], $todayarray[
'mday'], $todayarray[
'year']);
1449 for ($iter_week = 0; $iter_week < 6; $iter_week++) {
1453 $currdate0 = sprintf(
"%04d", $prev_year).sprintf(
"%02d", $prev_month).sprintf(
"%02d", $max_day_in_prev_month + $tmpday);
1454 } elseif ($tmpday <= $max_day_in_month) {
1455 $currdate0 = sprintf(
"%04d", $year).sprintf(
"%02d", $month).sprintf(
"%02d", $tmpday);
1458 $currdate0 = sprintf(
"%04d", $next_year).sprintf(
"%02d", $next_month).sprintf(
"%02d", $tmpday - $max_day_in_month);
1461 $numweek0 = date(
"W", strtotime(date($currdate0)));
1463 echo
' <td class="center weeknumber opacitymedium" width="2%">'.$numweek0.
'</td>';
1465 for ($iter_day = 0; $iter_day < 7; $iter_day++) {
1468 $style =
'cal_other_month cal_past';
1469 if ($iter_day == 6) {
1470 $style .=
' cal_other_month_right';
1472 echo
' <td class="'.$style.
' nowrap tdtop" width="14%">';
1473 show_day_events($db, $max_day_in_prev_month + $tmpday, $prev_month, $prev_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
1475 } elseif ($tmpday <= $max_day_in_month) {
1477 $curtime =
dol_mktime(0, 0, 0, $month, $tmpday, $year);
1478 $style =
'cal_current_month';
1479 if ($iter_day == 6) {
1480 $style .=
' cal_current_month_right';
1483 if ($todayarray[
'mday'] == $tmpday && $todayarray[
'mon'] == $month && $todayarray[
'year'] == $year) {
1487 $style =
'cal_today';
1489 if ($curtime < $todaytms) {
1490 $style .=
' cal_past';
1493 echo
' <td class="'.$style.
' nowrap tdtop" width="14%">';
1494 show_day_events($db, $tmpday, $month, $year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
1498 $style =
'cal_other_month';
1499 if ($iter_day == 6) {
1500 $style .=
' cal_other_month_right';
1502 echo
' <td class="'.$style.
' nowrap tdtop" width="14%">';
1503 show_day_events($db, $tmpday - $max_day_in_month, $next_month, $next_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
1513 print
'<input type="hidden" name="actionmove" value="mupdate">';
1514 print
'<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER[
'PHP_SELF']).
'?mode=show_month&'.
dol_escape_htmltag($_SERVER[
'QUERY_STRING']).
'">';
1515 print
'<input type="hidden" name="newdate" id="newdate">';
1516 } elseif ($mode ==
'show_week') {
1519 $newparam = preg_replace(
'/showbirthday=/i',
'showbirthday_=', $newparam);
1520 $newparam = preg_replace(
'/mode=show_month&?/i',
'', $newparam);
1521 $newparam = preg_replace(
'/mode=show_week&?/i',
'', $newparam);
1522 $newparam = preg_replace(
'/day=[0-9]+&?/i',
'', $newparam);
1523 $newparam = preg_replace(
'/month=[0-9]+&?/i',
'', $newparam);
1524 $newparam = preg_replace(
'/year=[0-9]+&?/i',
'', $newparam);
1525 $newparam = preg_replace(
'/viewweek=[0-9]+&?/i',
'', $newparam);
1526 $newparam = preg_replace(
'/showbirthday_=/i',
'showbirthday=', $newparam);
1527 $newparam .=
'&viewweek=1';
1529 print
'<div class="liste_titre liste_titre_bydiv centpercent"><div class="divsearchfield">';
1530 print_actions_filter(
$form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup,
'', $resourceid);
1531 print
'</div></div>';
1533 print
'<div class="div-table-responsive-no-min sectioncalendarbyweek maxscreenheightless300">';
1534 print
'<table class="centpercent noborder nocellnopadd cal_pannel cal_month">';
1535 print
' <tr class="liste_titre">';
1538 echo
' <td class="center bold uppercase tdfordaytitle">'.$langs->trans(
"Day".(($i + (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1)) % 7)).
"</td>\n";
1545 for ($iter_day = 0; $iter_day < 7; $iter_day++) {
1552 $style =
'cal_current_month';
1553 if ($iter_day == 6) {
1554 $style .=
' cal_other_month_right';
1559 if ($todayarray[
'mday'] == $tmpday && $todayarray[
'mon'] == $tmpmonth && $todayarray[
'year'] == $tmpyear) {
1563 $style =
'cal_today';
1566 echo
' <td class="'.$style.
'" width="14%" valign="top">';
1567 show_day_events($db, $tmpday, $tmpmonth, $tmpyear, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300);
1575 echo
'<input type="hidden" name="actionmove" value="mupdate">';
1576 echo
'<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER[
'PHP_SELF']).
'?mode=show_week&'.
dol_escape_htmltag($_SERVER[
'QUERY_STRING']).
'">';
1577 echo
'<input type="hidden" name="newdate" id="newdate">';
1580 $newparam = preg_replace(
'/mode=show_month&?/i',
'', $newparam);
1581 $newparam = preg_replace(
'/mode=show_week&?/i',
'', $newparam);
1582 $newparam = preg_replace(
'/viewday=[0-9]+&?/i',
'', $newparam);
1583 $newparam .=
'&viewday=1';
1585 $style =
'cal_current_month cal_current_month_oneday';
1588 if ($todayarray[
'mday'] == $day && $todayarray[
'mon'] == $month && $todayarray[
'year'] == $year) {
1593 $timestamp =
dol_mktime(12, 0, 0, $month, $day, $year);
1596 print
'<div class="liste_titre liste_titre_bydiv centpercent"><div class="divsearchfield">';
1597 print_actions_filter(
$form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup,
'', $resourceid);
1598 print
'</div></div>';
1600 print
'<div class="div-table-responsive-no-min sectioncalendarbyday maxscreenheightless300">';
1601 echo
'<table class="tagtable centpercent noborder nocellnopadd cal_pannel cal_month noborderbottom" style="margin-bottom: 5px !important;">';
1603 echo
' <tr class="tagtr liste_titre">';
1604 echo
' <td class="tagtd center bold uppercase">'.$langs->trans(
"Day".$arraytimestamp[
'wday']).
"</td>\n";
1622 print
'<div class="div-table-responsive-no-min borderbottom">';
1624 $maxheightwin = (isset($_SESSION[
"dol_screenheight"]) && $_SESSION[
"dol_screenheight"] > 500) ? ($_SESSION[
"dol_screenheight"] - 200) : 660;
1626 echo
'<div style="max-height: '.$maxheightwin.
'px;">';
1627 echo
'<div class="tagtable centpercent calendarviewcontainer">';
1631 $tmp = explode(
'-', $conf->global->MAIN_DEFAULT_WORKING_HOURS);
1632 $minhour = round($tmp[0], 0);
1633 $maxhour = round($tmp[1], 0);
1634 if ($minhour > 23) {
1640 if ($maxhour <= $minhour) {
1641 $maxhour = $minhour + 1;
1647 echo
' <div class="tagtr calendarviewcontainertr">'.
"\n";
1648 echo
' <div class="tagtd width100 tdtop">'.dol_print_date($i * 3600,
'hour',
'gmt').
'</div>';
1649 echo
' <div class="tagtd '.$style.
' tdtop"></div>'.
"\n";
1650 echo
' </div>'.
"\n";
1655 echo
'</div></div>';
1657 show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 1);
1661 print
'<div class="div-table-responsive-no-min">';
1663 show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 0);
1669 print
"\n".
'</form>';
1694 function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint = 0, $maxnbofchar = 16, $newparam =
'', $showinfo = 0, $minheight = 60, $nonew = 0)
1696 global $user, $conf, $langs;
1697 global $action, $mode, $filter, $filtert, $status, $actioncode, $usergroup;
1698 global $theme_datacolor;
1699 global $cachethirdparties, $cachecontacts, $cacheusers, $colorindexused;
1701 if ($conf->use_javascript_ajax) {
1702 $conf->global->MAIN_JS_SWITCH_AGENDA = 1;
1705 $dateint = sprintf(
"%04d", $year).sprintf(
"%02d", $month).sprintf(
"%02d", $day);
1711 $curtime =
dol_mktime(0, 0, 0, $month, $day, $year);
1712 $urltoshow = DOL_URL_ROOT.
'/comm/action/index.php?mode=show_day&day='.str_pad($day, 2,
"0", STR_PAD_LEFT).
'&month='.str_pad($month, 2,
"0", STR_PAD_LEFT).
'&year='.$year.$newparam;
1714 if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
1715 $newparam .=
'&month='.str_pad($month, 2,
"0", STR_PAD_LEFT).
'&year='.$year;
1716 $hourminsec =
'100000';
1717 $urltocreate = DOL_URL_ROOT.
'/comm/action/card.php?action=create&datep='.sprintf(
"%04d%02d%02d", $year, $month, $day).$hourminsec.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"].($newparam ?
'?'.$newparam :
''));
1721 print
'<div id="dayevent_'.$dateint.
'" class="dayevent tagtable centpercent nobordernopadding">'.
"\n";
1724 print
'<div class="tagtr cursorpointer" onclick="window.location=\''.$urltocreate.
'\';
"><div class="nowrap tagtd
"><div class="left
inline-block
">';
1725 print '<a class="dayevent-aday
" style="color: #666
" href="'.$urltoshow.'">';
1727 print dol_print_date($curtime, 'daytextshort');
1729 print dol_print_date($curtime, '%d');
1732 print '</div><div class="nowrap floatright
inline-block marginrightonly
">';
1733 if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
1734 print '<a class="cursoradd
" href="'.$urltocreate.'">'; // Explicit link, usefull for nojs interfaces
1735 print img_picto($langs->trans("NewAction
"), 'edit_add.png');
1738 print '</div></div></div>'."\n
";
1746 // Line with td contains all div of each events
1747 print '<div class="tagtr
">';
1748 print '<div class="tagtd centpercent agendacell sortable
">';
1750 //$curtime = dol_mktime (0, 0, 0, $month, $day, $year);
1751 $i = 0; $ireallyshown = 0; $itoshow = 0; $numother = 0; $numbirthday = 0; $numical = 0; $numicals = array();
1752 $ymd = sprintf("%04d
", $year).sprintf("%02d
", $month).sprintf("%02d
", $day);
1754 $colorindexused[$user->id] = 0; // Color index for current user (user->id) is always 0
1755 $nextindextouse = is_array($colorindexused) ?count($colorindexused) : 0; // At first run this is 0, so fist user has 0, next 1, ...
1756 //var_dump($colorindexused);
1758 include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
1759 $tmpholiday = new Holiday($db);
1761 foreach ($eventarray as $daykey => $notused) { // daykey is the 'YYYYMMDD' to show according to user
1762 $annee = dol_print_date($daykey, '%Y', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
1763 $mois = dol_print_date($daykey, '%m', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
1764 $jour = dol_print_date($daykey, '%d', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
1766 //print 'event daykey='.$daykey.' dol_print_date(daykey)='.dol_print_date($daykey, 'dayhour', 'gmt').' jour='.$jour.' mois='.$mois.' annee='.$annee."<br>\n
";
1768 if ($day == $jour && $month == $mois && $year == $annee) {
1769 foreach ($eventarray[$daykey] as $index => $event) {
1770 if ($i < $maxprint || $maxprint == 0 || !empty($conf->global->MAIN_JS_SWITCH_AGENDA)) {
1771 $keysofuserassigned = array_keys($event->userassigned);
1772 $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
1774 // Define $color (Hex string like '0088FF') and $cssclass of event
1775 $color = -1; $cssclass = ''; $colorindex = -1;
1776 if (in_array($user->id, $keysofuserassigned)) {
1777 $cssclass = 'family_mytasks';
1779 if (empty($cacheusers[$event->userownerid])) {
1780 $newuser = new User($db);
1781 $newuser->fetch($event->userownerid);
1782 $cacheusers[$event->userownerid] = $newuser;
1784 //var_dump($cacheusers[$event->userownerid]->color);
1786 // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
1787 if (!empty($cacheusers[$event->userownerid]->color)) {
1788 $color = $cacheusers[$event->userownerid]->color;
1790 } elseif ($event->type_code == 'ICALEVENT') { // Event come from external ical file
1792 if (!empty($event->icalname)) {
1793 if (!isset($numicals[dol_string_nospecial($event->icalname)])) {
1794 $numicals[dol_string_nospecial($event->icalname)] = 0;
1796 $numicals[dol_string_nospecial($event->icalname)]++;
1799 $color = ($event->icalcolor ? $event->icalcolor : -1);
1800 $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other');
1801 } elseif ($event->type_code == 'BIRTHDAY') {
1802 $numbirthday++; $colorindex = 2; $cssclass = 'family_birthday '; $color = sprintf("%02x%02x%02x
", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1805 $color = ($event->icalcolor ? $event->icalcolor : -1);
1806 $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other');
1808 if (empty($cacheusers[$event->userownerid])) {
1809 $newuser = new User($db);
1810 $newuser->fetch($event->userownerid);
1811 $cacheusers[$event->userownerid] = $newuser;
1813 //var_dump($cacheusers[$event->userownerid]->color);
1815 // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
1816 if (!empty($cacheusers[$event->userownerid]->color)) {
1817 $color = $cacheusers[$event->userownerid]->color;
1821 if ($color < 0) { // Color was not set on user card. Set color according to color index.
1822 // Define color index if not yet defined
1823 $idusertouse = ($event->userownerid ? $event->userownerid : 0);
1824 if (isset($colorindexused[$idusertouse])) {
1825 $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user
1827 $colorindex = $nextindextouse;
1828 $colorindexused[$idusertouse] = $colorindex;
1829 if (!empty($theme_datacolor[$nextindextouse + 1])) {
1830 $nextindextouse++; // Prepare to use next color
1833 //print '|'.($color).'='.($idusertouse?$idusertouse:0).'='.$colorindex.'<br>';
1835 $color = sprintf("%02x%02x%02x
", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1837 $cssclass = $cssclass.' eventday_'.$ymd;
1839 // Defined style to disable drag and drop feature
1840 if ($event->type_code == 'AC_OTH_AUTO') {
1841 $cssclass .= " unmovable
";
1842 } elseif ($event->type_code == 'HOLIDAY') {
1843 $cssclass .= " unmovable
";
1844 } elseif ($event->type_code == 'BIRTHDAY') {
1845 $cssclass .= " unmovable
";
1846 } elseif ($event->type_code == 'ICALEVENT') {
1847 $cssclass .= " unmovable
";
1848 } elseif ($event->date_start_in_calendar && $event->date_end_in_calendar && date('Ymd', $event->date_start_in_calendar) != date('Ymd', $event->date_end_in_calendar)) {
1849 // If the event is on several days
1850 $tmpyearend = dol_print_date($event->date_start_in_calendar, '%Y', 'tzuserrel');
1851 $tmpmonthend = dol_print_date($event->date_start_in_calendar, '%m', 'tzuserrel');
1852 $tmpdayend = dol_print_date($event->date_start_in_calendar, '%d', 'tzuserrel');
1853 //var_dump($tmpyearend.' '.$tmpmonthend.' '.$tmpdayend);
1854 if ($tmpyearend != $annee || $tmpmonthend != $mois || $tmpdayend != $jour) {
1855 $cssclass .= " unmovable unmovable-mustusefirstdaytodrag
";
1857 $cssclass .= ' movable cursormove';
1860 if ($user->rights->agenda->allactions->create ||
1861 (($event->authorid == $user->id || $event->userownerid == $user->id) && $user->rights->agenda->myactions->create)) {
1862 $cssclass .= " movable cursormove
";
1864 $cssclass .= " unmovable
";
1868 $h = ''; $nowrapontd = 1;
1869 if ($mode == 'show_day') {
1870 $h = 'height: 100%; '; $nowrapontd = 0;
1872 if ($mode == 'show_week') {
1873 $h = 'height: 100%; '; $nowrapontd = 0;
1878 print '<!-- start event '.$i.' -->'."\n
";
1881 if ($maxprint && $ireallyshown >= $maxprint) {
1882 $morecss = 'showifmore';
1884 if ($event->type == 'birthdate' && !GETPOST('check_birthday')) {
1885 $morecss = 'hidden';
1887 if ($event->type == 'holiday' && !GETPOST('check_holiday')) {
1888 $morecss = 'hidden';
1890 if ($morecss != 'hidden') {
1893 if ($morecss != 'showifmore' && $morecss != 'hidden') {
1896 //var_dump($event->type.' - '.$morecss.' - '.$cssclass.' - '.$i.' - '.$ireallyshown.' - '.$itoshow);
1898 print '<div id="event_
'.$ymd.'_
'.$i.'" class="event family_
'.$event->type.' '.$cssclass.($morecss ? ' '.$morecss : '').'"';
1899 //print ' style="height: 100px;
';
1900 //print ' position: absolute; top: 40px; width: 50%;
';
1904 //var_dump($event->userassigned);
1905 //var_dump($event->transparency);
1906 print '<table class="centpercent cal_event
';
1907 print (empty($event->transparency) ? ' cal_event_notbusy
' : ' cal_event_busy
');
1908 //if (empty($event->transparency) && empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) print ' opacitymedium
'; // Not busy
1909 print '" style="'.$h;
1910 $colortouse = $color;
1911 // If colortouse is similar than background, we force to change it.
1912 if (empty($event->transparency) && empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
1913 print 'background: #f0f0f0;
';
1914 print 'border-left: 5px solid #
'.$colortouse.';
';
1916 print 'background: #f0f0f0;
';
1917 print 'border-left: 5px solid #
'.dol_color_minus($colortouse, -3).';
';
1918 //print 'background: -webkit-gradient(linear, left top, left bottom, from(#
'.dol_color_minus($colortouse, -3).'), to(#
'.dol_color_minus($colortouse, -1).'));
';
1920 //print 'background: #
'.$colortouse.';
';
1921 //print 'background: -webkit-gradient(linear, left top, left bottom, from(#
'.dol_color_minus($color, -3).'), to(#
'.dol_color_minus($color, -1).'));
';
1922 //if (! empty($event->transparency)) print 'background: #
'.$color.'; background: -webkit-gradient(linear, left top, left bottom, from(#
'.$color.'), to(#
'.dol_color_minus($color,1).'));
';
1923 //else print 'background-color: transparent !important; background: none; border: 1px solid #bbb;
';
1924 //print ' -moz-border-radius:4px;
"';
1925 //print 'border: 1px solid #ccc" width=
"100%"';
1928 print '<td class="tdoverflow nobottom centpercent
'.($nowrapontd ? 'nowrap
' : '').'cal_event
'.($event->type_code == 'BIRTHDAY
' ? ' cal_event_birthday
' : '').'">';
1932 if ($event->type_code == 'BIRTHDAY') { // It's birthday calendar
1933 print $event->getNomUrl(1, $maxnbofchar, 'cal_event', 'birthday', 'contact');
1934 } elseif ($event->type_code == 'HOLIDAY') { // It's holiday calendar
1935 $tmpholiday->fetch($event->id);
1937 print $tmpholiday->getNomUrl(1);
1939 $tmpid = $tmpholiday->fk_user;
1940 if (empty($cacheusers[$tmpid])) {
1941 $newuser = new User($db);
1942 $newuser->fetch($tmpid);
1943 $cacheusers[$tmpid] = $newuser;
1946 $listofusertoshow = '';
1947 $listofusertoshow .= '<br>'.$cacheusers[$tmpid]->getNomUrl(-1, '', 0, 0, 0, 0, '', 'paddingright valigntextbottom');
1948 print $listofusertoshow;
1949 } else { // Other calendar
1951 if (empty($event->fulldayevent)) {
1952 //print $event->getNomUrl(2).' ';
1956 if (empty($event->fulldayevent)) {
1957 // Show hours (start ... end)
1958 $tmpyearstart = dol_print_date($event->date_start_in_calendar, '%Y', 'tzuserrel');
1959 $tmpmonthstart = dol_print_date($event->date_start_in_calendar, '%m', 'tzuserrel');
1960 $tmpdaystart = dol_print_date($event->date_start_in_calendar, '%d', 'tzuserrel');
1961 $tmpyearend = dol_print_date($event->date_end_in_calendar, '%Y', 'tzuserrel');
1962 $tmpmonthend = dol_print_date($event->date_end_in_calendar, '%m', 'tzuserrel');
1963 $tmpdayend = dol_print_date($event->date_end_in_calendar, '%d', 'tzuserrel');
1966 if ($tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour) {
1967 $daterange .= dol_print_date($event->date_start_in_calendar, 'hour', 'tzuserrel');
1968 if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
1969 if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend) {
1976 if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
1977 if ($tmpyearstart != $tmpyearend || $tmpmonthstart != $tmpmonthend || $tmpdaystart != $tmpdayend) {
1978 $daterange .= '...';
1982 if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
1983 if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour) {
1984 $daterange .= dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
1989 print $langs->trans("EventOnFullDay
")."<br>\n
";
1994 $titletoshow = $daterange;
1995 $titletoshow .= ($titletoshow ? ' ' : '').($event->label ? $event->label : $event->libelle);
1997 if ($event->type_code != 'ICALEVENT') {
1998 $savlabel = $event->label ? $event->label : $event->libelle;
1999 $event->label = $titletoshow;
2000 $event->libelle = $titletoshow; // deprecatd
2001 // Note: List of users are inside $event->userassigned. Link may be clickable depending on permissions of user.
2002 $titletoshow = (($event->type_picto || $event->type_code) ? $event->getTypePicto() : '');
2003 $titletoshow .= $event->getNomUrl(0, $maxnbofchar, 'cal_event cal_event_title', '', 0, 0);
2004 $event->label = $savlabel;
2005 $event->libelle = $savlabel;
2008 // Loop on each assigned user
2009 $listofusertoshow = '';
2010 $posuserassigned = 0;
2011 foreach ($event->userassigned as $tmpid => $tmpdata) {
2012 if (!$posuserassigned && $titletoshow) {
2013 $listofusertoshow .= '<br>';
2016 if (empty($cacheusers[$tmpid])) {
2017 $newuser = new User($db);
2018 $newuser->fetch($tmpid);
2019 $cacheusers[$tmpid] = $newuser;
2022 $listofusertoshow .= $cacheusers[$tmpid]->getNomUrl(-3, '', 0, 0, 0, 0, '', 'paddingright valigntextbottom');
2026 print $listofusertoshow;
2028 if ($event->type_code == 'ICALEVENT') {
2029 print '<br>('.dol_trunc($event->icalname, $maxnbofchar).')';
2032 $thirdparty_id = ($event->socid > 0 ? $event->socid : ((is_object($event->societe) && $event->societe->id > 0) ? $event->societe->id : 0));
2033 $contact_id = ($event->contact_id > 0 ? $event->contact_id : ((is_object($event->contact) && $event->contact->id > 0) ? $event->contact->id : 0));
2035 // If action related to company / contact
2036 $linerelatedto = '';
2037 if ($thirdparty_id > 0) {
2038 if (!isset($cachethirdparties[$thirdparty_id]) || !is_object($cachethirdparties[$thirdparty_id])) {
2039 $thirdparty = new Societe($db);
2040 $thirdparty->fetch($thirdparty_id);
2041 $cachethirdparties[$thirdparty_id] = $thirdparty;
2043 $thirdparty = $cachethirdparties[$thirdparty_id];
2045 if (!empty($thirdparty->id)) {
2046 $linerelatedto .= $thirdparty->getNomUrl(1, '', 0);
2049 if (!empty($contact_id) && $contact_id > 0) {
2050 if (!is_object($cachecontacts[$contact_id])) {
2051 $contact = new Contact($db);
2052 $contact->fetch($contact_id);
2053 $cachecontacts[$contact_id] = $contact;
2055 $contact = $cachecontacts[$contact_id];
2057 if ($linerelatedto) {
2058 $linerelatedto .= ' ';
2060 if (!empty($contact->id)) {
2061 $linerelatedto .= $contact->getNomUrl(1, '', 0);
2064 if (!empty($event->fk_element) && $event->fk_element > 0 && !empty($event->elementtype) && !empty($conf->global->AGENDA_SHOW_LINKED_OBJECT)) {
2065 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2066 if ($linerelatedto) {
2067 $linerelatedto .= '<br>';
2069 $linerelatedto .= dolGetElementUrl($event->fk_element, $event->elementtype, 1);
2071 if ($linerelatedto) {
2072 print '<br>'.$linerelatedto;
2078 if ($event->location) {
2080 print $langs->trans("Location
").': '.$event->location;
2087 if ($event->type_code != 'BIRTHDAY' && $event->type_code != 'ICALEVENT') {
2089 if ($event->percentage >= 0) {
2093 print '<td class="nobottom right nowrap cal_event_right
'.($withstatus >= 2 ? ' cal_event_right_status
' : '').'">';
2095 print $event->getLibStatut(3, 1);
2099 print '</td></tr></table>';
2100 print '</div><!-- end event '.$i.' -->'."\n
";
2104 print '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=
'.$mode.'&maxprint=0&month=
'.((int) $monthshown).'&year=
'.((int) $year);
2105 print ($status ? '&status=
'.$status : '').($filter ? '&filter=
'.urlencode($filter) : '');
2106 print ($filtert ? '&search_filtert=
'.urlencode($filtert) : '');
2107 print ($usergroup ? '&search_usergroup=
'.urlencode($usergroup) : '');
2108 print ($actioncode != '' ? '&search_actioncode=
'.urlencode($actioncode) : '');
2109 print '">'.img_picto("all
", "1downarrow_selected.png
").' ...';
2110 print ' +'.(count($eventarray[$daykey]) - $maxprint);
2113 //$ok=false; // To avoid to show twice the link
2120 if (!$i) { // No events
2124 if (!empty($conf->global->MAIN_JS_SWITCH_AGENDA) && $itoshow > $ireallyshown && $maxprint) {
2125 print '<div class="center cursorpointer
" id="more_
'.$ymd.'">'.img_picto("All
", "angle-
double-down
", 'class="warning
"').' +'.($itoshow - $ireallyshown).'</div>';
2126 //print ' +'.(count($eventarray[$daykey])-$maxprint);
2128 print '<script type="text/javascript
">'."\n
";
2129 print 'jQuery(document).ready(function () {'."\n
";
2130 print ' var open=0;'."\n
";
2131 print ' jQuery("#more_
'.$ymd.'").click(function() { console.log("Click on showmore
for '.$ymd.'"); reinit_day_'.$ymd.'(); event.stopImmediatePropagation(); });'."\n
";
2132 print ' function reinit_day_'.$ymd.'() {'."\n
";
2133 print ' jQuery(".eventday_
'.$ymd.'.showifmore
").toggle();'."\n
";
2134 print ' open = open + 1; if (open > 1) { open = 0; }'."\n
";
2135 print ' if (open) { ';
2136 print ' jQuery("#more_
'.$ymd.'").html(\''.img_picto("All
", "angle-
double-up
", 'class="warning
"').'\');'."\n
";
2138 print ' jQuery("#more_
'.$ymd.'").html(\''.img_picto("All
", "angle-
double-down
", 'class="warning
"').' +'.($itoshow - $ireallyshown).'\');'."\n
";
2142 print '</script>'."\n
";
2145 print '</div></div>'; // td tr
2147 print '</div>'; // table
2160 function dol_color_minus($color, $minus, $minusunit = 16)
2163 if ($minusunit == 16) {
2164 $newcolor[0] = dechex(max(min(hexdec($newcolor[0]) - $minus, 15), 0));
2165 $newcolor[2] = dechex(max(min(hexdec($newcolor[2]) - $minus, 15), 0));
2166 $newcolor[4] = dechex(max(min(hexdec($newcolor[4]) - $minus, 15), 0));
2168 // Not yet implemented
2180 function sort_events_by_date($a, $b)
2182 // Sort holidays at first
2183 if ($a->type_code === 'HOLIDAY') {
2186 if ($b->type_code === 'HOLIDAY') {
2190 // datep => Event start time
2191 // datef => Event end time
2193 // Events have different start time
2194 if ($a->datep !== $b->datep) {
2195 return $a->datep - $b->datep;
2198 // Events have same start time and no end time
2199 if ((!is_numeric($b->datef)) || (!is_numeric($a->datef))) {
2200 return sort_events_by_percentage($a, $b);
2203 // Events have the same start time and same end time
2204 if ($b->datef === $a->datef) {
2205 return sort_events_by_percentage($a, $b);
2208 // Events have the same start time, but have different end time -> longest event first
2209 return $b->datef - $a->datef;
2219 function sort_events_by_percentage($a, $b)
2221 // Sort events with no percentage before each other
2222 // (usefull to sort holidays, sick days or similar on the top)
2224 if ($a->percentage < 0) {
2228 if ($b->percentage < 0) {
2232 return $b->percentage - $a->percentage;