32 require
'../../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/agenda.lib.php';
36 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/user/class/usergroup.class.php';
43 if (!isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) {
44 $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW = 3;
47 $action =
GETPOST(
'action',
'aZ09');
49 $disabledefaultvalues =
GETPOST(
'disabledefaultvalues',
'int');
51 $filter =
GETPOST(
"search_filter",
'alpha', 3) ?
GETPOST(
"search_filter",
'alpha', 3) :
GETPOST(
"filter",
'alpha', 3);
52 $filtert =
GETPOST(
"search_filtert",
"int", 3) ?
GETPOST(
"search_filtert",
"int", 3) :
GETPOST(
"filtert",
"int", 3);
53 $usergroup =
GETPOST(
"search_usergroup",
"int", 3) ?
GETPOST(
"search_usergroup",
"int", 3) :
GETPOST(
"usergroup",
"int", 3);
60 if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS)) {
65 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
66 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
68 if (empty($page) || $page == -1) {
71 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
72 $offset = $limit * $page;
77 $sortfield =
"a.datec";
84 $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 $mode =
'show_pertype';
103 $resourceid =
GETPOST(
"search_resourceid",
"int") ?
GETPOST(
"search_resourceid",
"int") :
GETPOST(
"resourceid",
"int");
104 $year =
GETPOST(
"year",
"int") ?
GETPOST(
"year",
"int") : date(
"Y");
105 $month =
GETPOST(
"month",
"int") ?
GETPOST(
"month",
"int") : date(
"m");
106 $week =
GETPOST(
"week",
"int") ?
GETPOST(
"week",
"int") : date(
"W");
111 $maxprint = ((
GETPOST(
"maxprint",
'int') !=
'') ?
GETPOST(
"maxprint",
'int') : $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW);
112 $optioncss =
GETPOST(
'optioncss',
'aZ');
115 if (
GETPOST(
'search_actioncode',
'array:aZ09')) {
116 $actioncode =
GETPOST(
'search_actioncode',
'array:aZ09', 3);
117 if (!count($actioncode)) {
121 $actioncode =
GETPOST(
"search_actioncode",
"alpha", 3) ?
GETPOST(
"search_actioncode",
"alpha", 3) : (
GETPOST(
"search_actioncode",
"alpha") ==
'0' ?
'0' : ((empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) || $disabledefaultvalues) ?
'' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE));
125 if ($dateselect > 0) {
126 $day =
GETPOST(
'dateselectday',
'int');
127 $month =
GETPOST(
'dateselectmonth',
'int');
128 $year =
GETPOST(
'dateselectyear',
'int');
132 $tmp = empty($conf->global->MAIN_DEFAULT_WORKING_HOURS) ?
'9-18' : $conf->global->MAIN_DEFAULT_WORKING_HOURS;
133 $tmp = str_replace(
' ',
'', $tmp);
134 $tmparray = explode(
'-', $tmp);
135 $begin_h =
GETPOST(
'begin_h',
'int') !=
'' ?
GETPOST(
'begin_h',
'int') : ($tmparray[0] !=
'' ? $tmparray[0] : 9);
136 $end_h =
GETPOST(
'end_h',
'int') ?
GETPOST(
'end_h',
'int') : ($tmparray[1] !=
'' ? $tmparray[1] : 18);
137 if ($begin_h < 0 || $begin_h > 23) {
140 if ($end_h < 1 || $end_h > 24) {
143 if ($end_h <= $begin_h) {
144 $end_h = $begin_h + 1;
148 $tmp = empty($conf->global->MAIN_DEFAULT_WORKING_DAYS) ?
'1-5' : $conf->global->MAIN_DEFAULT_WORKING_DAYS;
149 $tmp = str_replace(
' ',
'', $tmp);
150 $tmparray = explode(
'-', $tmp);
155 $status = ((empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS) || $disabledefaultvalues) ?
'' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS);
158 $mode = (empty($conf->global->AGENDA_DEFAULT_VIEW) ?
'show_month' : $conf->global->AGENDA_DEFAULT_VIEW);
162 if (
GETPOST(
'viewcal',
'alpha') && $mode !=
'show_day' && $mode !=
'show_week' && $mode !=
'show_peruser') {
163 $mode =
'show_month'; $day =
'';
166 if (
GETPOST(
'viewweek',
'alpha') || $mode ==
'show_week') {
167 $mode =
'show_week'; $week = ($week ? $week : date(
"W")); $day = ($day ? $day : date(
"d"));
170 if (
GETPOST(
'viewday',
'alpha') || $mode ==
'show_day') {
171 $mode =
'show_day'; $day = ($day ? $day : date(
"d"));
174 if (
GETPOST(
'viewyear',
'alpha') || $mode ==
'show_year') {
182 $langs->loadLangs(array(
'users',
'agenda',
'other',
'commercial'));
185 $hookmanager->initHooks(array(
'agenda'));
188 if ($user->socid && $socid) {
192 $search_status = $status;
223 'maxprint' => $maxprint,
225 'filtert' => $filtert,
226 'showbirthday' => $showbirthday,
227 'canedit' => $canedit,
228 'optioncss' => $optioncss,
229 'actioncode' => $actioncode,
231 'resourceid' => $resourceid,
232 'usergroup' => $usergroup,
235 $reshook = $hookmanager->executeHooks(
'beforeAgendaPerType', $parameters, $object, $action);
241 $companystatic =
new Societe($db);
243 $help_url =
'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda|DE:Modul_Terminplanung';
248 $nowyear = $nowarray[
'year'];
249 $nowmonth = $nowarray[
'mon'];
250 $nowday = $nowarray[
'mday'];
254 $listofextcals = array();
261 $week = $prev[
'week'];
265 $next_year = $year + 1;
266 $next_month = $month;
269 $max_day_in_month = date(
"t",
dol_mktime(0, 0, 0, $month, 1, $year));
271 $tmpday = $first_day;
275 $title = $langs->trans(
"DoneAndToDoActions");
276 if ($status ==
'done') {
277 $title = $langs->trans(
"DoneActions");
279 if ($status ==
'todo') {
280 $title = $langs->trans(
"ToDoActions");
285 if (is_array($actioncode)) {
286 foreach ($actioncode as $str_action) {
287 $param .=
"&search_actioncode[]=".urlencode($str_action);
290 $param .=
"&search_actioncode=".urlencode($actioncode);
293 if ($resourceid > 0) {
294 $param .=
"&search_resourceid=".urlencode($resourceid);
297 $param .=
"&search_status=".urlencode($status);
300 $param .=
"&search_filter=".urlencode($filter);
303 $param .=
"&search_filtert=".urlencode($filtert);
305 if ($usergroup > 0) {
306 $param .=
"&search_usergroup=".urlencode($usergroup);
309 $param .=
"&search_socid=".urlencode($socid);
312 $param .=
"&search_showbirthday=1";
315 $param .=
"&search_projectid=".urlencode($pid);
318 $param .=
"&search_type=".urlencode($type);
320 if ($mode !=
'show_pertype') {
321 $param .=
'&mode='.urlencode($mode);
323 if ($begin_h !=
'') {
324 $param .=
'&begin_h='.urlencode($begin_h);
327 $param .=
'&end_h='.urlencode($end_h);
329 if ($begin_d !=
'') {
330 $param .=
'&begin_d='.urlencode($begin_d);
333 $param .=
'&end_d='.urlencode($end_d);
335 $param .=
"&maxprint=".urlencode($maxprint);
337 $paramnoactionodate = $param;
340 $prev_year = $year - 1;
341 $prev_month = $month;
347 $week = $prev[
'week'];
351 $next_year = $year + 1;
352 $next_month = $month;
357 $firstdaytoshow =
dol_mktime(0, 0, 0, $first_month, $first_day, $first_year,
'tzuserrel');
363 $max_day_in_month = date(
"t",
dol_mktime(0, 0, 0, $month, 1, $year,
'gmt'));
365 $tmpday = $first_day;
366 $picto =
'calendarweek';
368 $nav =
"<a href=\"?year=".$prev_year.
"&month=".$prev_month.
"&day=".$prev_day.$param.
"\">".
img_previous($langs->trans(
"Previous")).
"</a>\n";
369 $nav .=
" <span id=\"month_name\">".dol_print_date(
dol_mktime(0, 0, 0, $first_month, $first_day, $first_year),
"%Y").
"</span> \n";
370 $nav .=
"<a href=\"?year=".$next_year.
"&month=".$next_month.
"&day=".$next_day.$param.
"\">".
img_next($langs->trans(
"Next")).
"</a>\n";
371 if (empty($conf->dol_optimize_smallscreen)) {
372 $nav .=
" (<a href=\"?year=".$nowyear.
"&month=".$nowmonth.
"&day=".$nowday.$param.
"\">".$langs->trans(
"Today").
"</a>)";
375 $nav .=
$form->selectDate($dateselect,
'dateselect', 0, 0, 1,
'', 1, 0);
376 $nav .=
' <button type="submit" class="liste_titre button_search" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
379 $param .=
'&year='.urlencode($year).
'&month='.urlencode($month).($day ?
'&day='.urlencode($day) :
'');
383 $paramnoaction = preg_replace(
'/action=[a-z_]+/',
'', $param);
387 print
'<form method="POST" id="searchFormList" class="listactionsfilter" action="'.$_SERVER[
"PHP_SELF"].
'">'.
"\n";
389 $showextcals = $listofextcals;
391 if ($conf->use_javascript_ajax) {
393 $s .=
'<script type="text/javascript">'.
"\n";
394 $s .=
'jQuery(document).ready(function () {'.
"\n";
395 $s .=
'jQuery("#check_mytasks").click(function() { jQuery(".family_mytasks").toggle(); jQuery(".family_other").toggle(); });'.
"\n";
396 $s .=
'jQuery("#check_birthday").click(function() { jQuery(".family_birthday").toggle(); });'.
"\n";
397 $s .=
'jQuery(".family_birthday").toggle();'.
"\n";
398 if ($mode ==
"show_week" || $mode ==
"show_month" || empty($mode)) {
399 $s .=
'jQuery( "td.sortable" ).sortable({connectWith: ".sortable",placeholder: "ui-state-highlight",items: "div:not(.unsortable)", receive: function( event, ui ) {';
402 $s .=
'</script>'.
"\n";
403 if (!empty($conf->use_javascript_ajax)) {
404 $s .=
'<div class="nowrap clear float"><input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> '.$langs->trans(
"LocalAgenda").
' </div>';
405 if (is_array($showextcals) && count($showextcals) > 0) {
406 foreach ($showextcals as $val) {
407 $htmlname = md5($val[
'name']);
408 $s .=
'<script type="text/javascript">'.
"\n";
409 $s .=
'jQuery(document).ready(function () {'.
"\n";
410 $s .=
' jQuery("#check_ext'.$htmlname.
'").click(function() {';
411 $s .=
' /* alert("'.$htmlname.
'"); */';
412 $s .=
' jQuery(".family_ext'.$htmlname.
'").toggle();';
415 $s .=
'</script>'.
"\n";
416 $s .=
'<div class="nowrap float"><input type="checkbox" id="check_ext'.$htmlname.
'" name="check_ext'.$htmlname.
'" checked> '.$val [
'name'].
' </div>';
423 $parameters = array();
424 $reshook = $hookmanager->executeHooks(
'addCalendarChoice', $parameters, $object, $action);
425 if (empty($reshook)) {
426 $s .= $hookmanager->resPrint;
427 } elseif ($reshook > 1) {
428 $s = $hookmanager->resPrint;
433 $massactionbutton =
'';
436 $viewmode .=
'<a class="btnTitle reposition" href="'.DOL_URL_ROOT.
'/comm/action/list.php?mode=show_list&restore_lastsearch_values=1'.$paramnoactionodate.
'">';
438 $viewmode .=
img_picto($langs->trans(
"List"),
'object_calendarlist',
'class="imgforviewmode pictoactionview block"');
440 $viewmode .=
'<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans(
"ViewList").
'</span></a>';
442 $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.
'">';
444 $viewmode .=
img_picto($langs->trans(
"ViewCal"),
'object_calendarmonth',
'class="pictoactionview block"');
446 $viewmode .=
'<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans(
"ViewCal").
'</span></a>';
448 $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.
'">';
450 $viewmode .=
img_picto($langs->trans(
"ViewWeek"),
'object_calendarweek',
'class="pictoactionview block"');
452 $viewmode .=
'<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans(
"ViewWeek").
'</span></a>';
454 $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.
'">';
456 $viewmode .=
img_picto($langs->trans(
"ViewDay"),
'object_calendarday',
'class="pictoactionview block"');
458 $viewmode .=
'<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans(
"ViewDay").
'</span></a>';
460 $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.
'">';
462 $viewmode .=
img_picto($langs->trans(
"ViewPerUser"),
'object_calendarperuser',
'class="pictoactionview block"');
464 $viewmode .=
'<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans(
"ViewPerUser").
'</span></a>';
466 $viewmode .=
'<span class="marginrightonly"></span>';
469 $parameters = array(); $object =
null;
470 $reshook = $hookmanager->executeHooks(
'addCalendarView', $parameters, $object, $action);
471 if (empty($reshook)) {
472 $viewmode .= $hookmanager->resPrint;
473 } elseif ($reshook > 1) {
474 $viewmode = $hookmanager->resPrint;
479 if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
482 $newparam .=
'&month='.str_pad($month, 2,
"0", STR_PAD_LEFT).
'&year='.$tmpforcreatebutton[
'year'];
485 $hourminsec =
'100000';
486 $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 :
'')));
489 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);
496 $newtitle =
'<div class="nowrap clear inline-block minheight30">';
497 $newtitle .=
'<input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> '.$langs->trans(
"LocalAgenda").
' ';
498 $newtitle .=
'</div>';
505 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
506 print_actions_filter(
$form, $canedit, $search_status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup,
'', $resourceid);
511 $eventarray = array();
516 if ($usergroup > 0) {
519 $sql .=
' a.id, a.label,';
521 $sql .=
' a.datep2,';
522 $sql .=
' a.percent,';
523 $sql .=
' a.fk_user_author,a.fk_user_action,';
524 $sql .=
' a.transparency, a.priority, a.fulldayevent, a.location,';
525 $sql .=
' a.fk_soc, a.fk_contact, a.fk_element, a.elementtype, a.fk_project,';
526 $sql .=
' ca.code, ca.libelle as type_label, ca.color, ca.type as type_type, ca.picto as type_picto';
527 $sql .=
' FROM '.MAIN_DB_PREFIX.
'c_actioncomm as ca, '.MAIN_DB_PREFIX.
"actioncomm as a";
528 if (empty($user->rights->societe->client->voir) && !$socid) {
529 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
532 if ($resourceid > 0) {
533 $sql .=
", ".MAIN_DB_PREFIX.
"element_resources as r";
536 if ($filtert > 0 || $usergroup > 0) {
537 $sql .=
", ".MAIN_DB_PREFIX.
"actioncomm_resources as ar";
539 if ($usergroup > 0) {
540 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
542 $sql .=
' WHERE a.fk_action = ca.id';
543 $sql .=
' AND a.entity IN ('.getEntity(
'agenda').
')';
545 if (!empty($actioncode)) {
546 if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
547 if ($actioncode ==
'AC_NON_AUTO') {
548 $sql .=
" AND ca.type != 'systemauto'";
549 } elseif ($actioncode ==
'AC_ALL_AUTO') {
550 $sql .=
" AND ca.type = 'systemauto'";
552 if ($actioncode ==
'AC_OTH') {
553 $sql .=
" AND ca.type != 'systemauto'";
555 if ($actioncode ==
'AC_OTH_AUTO') {
556 $sql .=
" AND ca.type = 'systemauto'";
560 if ($actioncode ==
'AC_NON_AUTO') {
561 $sql .=
" AND ca.type != 'systemauto'";
562 } elseif ($actioncode ==
'AC_ALL_AUTO') {
563 $sql .=
" AND ca.type = 'systemauto'";
565 if (is_array($actioncode)) {
566 $sql .=
" AND ca.code IN (".$db->sanitize(
"'".implode(
"','", $actioncode).
"'", 1).
")";
568 $sql .=
" AND ca.code IN (".$db->sanitize(
"'".implode(
"','", explode(
',', $actioncode)).
"'", 1).
")";
573 if ($resourceid > 0) {
574 $sql .=
" AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".((int) $resourceid);
577 $sql .=
" AND a.fk_project=".((int) $pid);
579 if (empty($user->rights->societe->client->voir) && !$socid) {
580 $sql .=
" AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).
")";
583 $sql .=
' AND a.fk_soc = '.((int) $socid);
586 if ($filtert > 0 || $usergroup > 0) {
587 $sql .=
" AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
589 if ($mode ==
'show_day') {
591 $sql .=
" (a.datep BETWEEN '".$db->idate(
dol_mktime(0, 0, 0, $month, $day, $year,
'tzuserrel')).
"'";
592 $sql .=
" AND '".$db->idate(
dol_mktime(23, 59, 59, $month, $day, $year,
'tzuserrel')).
"')";
594 $sql .=
" (a.datep2 BETWEEN '".$db->idate(
dol_mktime(0, 0, 0, $month, $day, $year,
'tzuserrel')).
"'";
595 $sql .=
" AND '".$db->idate(
dol_mktime(23, 59, 59, $month, $day, $year,
'tzuserrel')).
"')";
597 $sql .=
" (a.datep < '".$db->idate(
dol_mktime(0, 0, 0, $month, $day, $year,
'tzuserrel')).
"'";
598 $sql .=
" AND a.datep2 > '".$db->idate(
dol_mktime(23, 59, 59, $month, $day, $year,
'tzuserrel')).
"')";
603 $sql .=
" (a.datep BETWEEN '".$db->idate(
dol_mktime(0, 0, 0, 1, 1, $year) - (60 * 60 * 24 * 7)).
"'";
604 $sql .=
" AND '".$db->idate(
dol_mktime(23, 59, 59, 12, 31, $year) + (60 * 60 * 24 * 7)).
"')";
606 $sql .=
" (a.datep2 BETWEEN '".$db->idate(
dol_mktime(0, 0, 0, 1, 1, $year) - (60 * 60 * 24 * 7)).
"'";
607 $sql .=
" AND '".$db->idate(
dol_mktime(23, 59, 59, 12, 31, $year) + (60 * 60 * 24 * 7)).
"')";
609 $sql .=
" (a.datep < '".$db->idate(
dol_mktime(0, 0, 0, 12, 1, $year) - (60 * 60 * 24 * 7)).
"'";
610 $sql .=
" AND a.datep2 > '".$db->idate(
dol_mktime(23, 59, 59, 12, 31, $year) + (60 * 60 * 24 * 7)).
"')";
614 $sql .=
" AND ca.id = ".((int) $type);
616 if ($status ==
'0') {
617 $sql .=
" AND a.percent = 0";
619 if ($status ===
'na') {
621 $sql .=
" AND a.percent = -1";
623 if ($status ==
'50') {
625 $sql .=
" AND (a.percent > 0 AND a.percent < 100)";
627 if ($status ==
'done' || $status ==
'100') {
628 $sql .=
" AND (a.percent = 100)";
630 if ($status ==
'todo') {
631 $sql .=
" AND (a.percent >= 0 AND a.percent < 100)";
634 if ($filtert > 0 || $usergroup > 0) {
637 $sql .=
"ar.fk_element = ".$filtert;
639 if ($usergroup > 0) {
640 $sql .= ($filtert > 0 ?
" OR " :
"").
" ugu.fk_usergroup = ".((
int) $usergroup);
645 $sql .=
' ORDER BY fk_user_action, datep';
648 dol_syslog(
"comm/action/pertype.php", LOG_DEBUG);
649 $resql = $db->query($sql);
651 $num = $db->num_rows(
$resql);
654 $obj = $db->fetch_object(
$resql);
657 if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->code ==
'AC_OTH_AUTO') {
662 $datep = $db->jdate($obj->datep);
663 $datep2 = $db->jdate($obj->datep2);
667 $event->id = $obj->id;
668 $event->datep = $datep;
669 $event->datef = $datep2;
670 $event->type_code = $obj->code;
671 $event->type_color = $obj->color;
672 $event->label = $obj->label;
673 $event->percentage = $obj->percent;
674 $event->authorid = $obj->fk_user_author;
675 $event->userownerid = $obj->fk_user_action;
676 $event->priority = $obj->priority;
677 $event->fulldayevent = $obj->fulldayevent;
678 $event->location = $obj->location;
679 $event->transparency = $obj->transparency;
681 $event->fk_project = $obj->fk_project;
683 $event->socid = $obj->fk_soc;
684 $event->contact_id = $obj->fk_contact;
686 $event->fk_element = $obj->fk_element;
687 $event->elementtype = $obj->elementtype;
691 if ($event->percentage <= 0) {
692 $event->date_start_in_calendar = $datep;
693 if ($datep2 !=
'' && $datep2 >= $datep) {
694 $event->date_end_in_calendar = $datep2;
696 $event->date_end_in_calendar = $datep;
699 $event->date_start_in_calendar = $datep;
700 if ($datep2 !=
'' && $datep2 >= $datep) {
701 $event->date_end_in_calendar = $datep2;
703 $event->date_end_in_calendar = $datep;
708 if ($event->date_end_in_calendar < $firstdaytoshow ||
709 $event->date_start_in_calendar >= $lastdaytoshow) {
714 $event->fetch_userassigned();
716 if ($event->date_start_in_calendar < $firstdaytoshow) {
717 $event->date_start_in_calendar = $firstdaytoshow;
719 if ($event->date_end_in_calendar >= $lastdaytoshow) {
720 $event->date_end_in_calendar = ($lastdaytoshow - 1);
724 $daycursor = $event->date_start_in_calendar;
730 $loop =
true; $j = 0;
731 $daykey =
dol_mktime(0, 0, 0, $mois, $jour, $annee,
'gmt');
735 $eventarray[$daykey][] = $event;
738 $daykey += 60 * 60 * 24;
739 if ($daykey > $event->date_end_in_calendar) {
755 $cachethirdparties = array();
756 $cachecontacts = array();
757 $cacheusers = array();
760 $color_file = DOL_DOCUMENT_ROOT.
"/theme/".$conf->theme.
"/theme_vars.inc.php";
761 if (is_readable($color_file)) {
764 if (!is_array($theme_datacolor)) {
765 $theme_datacolor = array(array(120, 130, 150), array(200, 160, 180), array(190, 190, 220));
770 $newparam = preg_replace(
'/showbirthday=/i',
'showbirthday_=', $newparam);
771 $newparam = preg_replace(
'/mode=show_month&?/i',
'', $newparam);
772 $newparam = preg_replace(
'/mode=show_week&?/i',
'', $newparam);
773 $newparam = preg_replace(
'/day=[0-9]+&?/i',
'', $newparam);
774 $newparam = preg_replace(
'/month=[0-9]+&?/i',
'', $newparam);
775 $newparam = preg_replace(
'/year=[0-9]+&?/i',
'', $newparam);
776 $newparam = preg_replace(
'/viewweek=[0-9]+&?/i',
'', $newparam);
777 $newparam = preg_replace(
'/showbirthday_=/i',
'showbirthday=', $newparam);
778 $newparam .=
'&viewweek=1';
780 print
'<input type="hidden" name="action" value="mupdate">';
781 echo
'<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER[
'PHP_SELF']).
'?'.
dol_escape_htmltag($_SERVER[
'QUERY_STRING']).
'">';
782 echo
'<input type="hidden" name="token" value="'.newToken().
'">';
783 echo
'<input type="hidden" name="newdate" id="newdate">';
790 echo
'<div class="div-table-responsive">';
792 echo
'<table class="centpercent nocellnopadd cal_month">';
794 echo
'<tr class="liste_titre">';
797 echo
'<td align="center" colspan="'.($end_d - $begin_d).
'">';
798 echo $langs->trans(
"Year");
804 echo
'<tr class="liste_titre">';
807 for ($h = $begin_d; $h < $end_d; $h++) {
808 echo
'<td class="center">';
809 print
'<small style="font-family: courier">'.sprintf(
"%02d", $h).
'</small>';
816 $typeofevents = array();
819 $colorsbytype = array();
820 $labelbytype = array();
821 $sql =
"SELECT code, color, libelle as label FROM ".MAIN_DB_PREFIX.
"c_actioncomm ORDER BY position";
822 $resql = $db->query($sql);
823 while ($obj = $db->fetch_object(
$resql)) {
824 $typeofevents[$obj->code] = $obj->code;
825 $colorsbytype[$obj->code] = $obj->color;
826 $labelbytype[$obj->code] = $obj->label;
834 foreach ($typeofevents as $typeofevent) {
837 echo
'<td class="cal_current_month cal_peruserviewname'.($var ?
' cal_impair' :
'').
'">'.$typeofevent.
'</td>';
842 for ($iter_day = 0; $iter_day < 8; $iter_day++) {
843 if (($i + 1) < $begin_d || ($i + 1) > $end_d) {
856 $style =
'cal_current_month';
857 if ($iter_day == 6) {
858 $style .=
' cal_other_month';
861 if ($todayarray[
'mday'] == $tmpday && $todayarray[
'mon'] == $tmpmonth && $todayarray[
'year'] == $tmpyear) {
865 $style =
'cal_today_peruser';
868 show_day_events_pertype($typeofevent, $tmpday, $tmpmonth, $tmpyear, 0, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, $showheader, $colorsbytype, $var);
881 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
882 $langs->load(
"commercial");
883 print
'<br>'.$langs->trans(
"Legend").
': <br>';
884 foreach ($colorsbytype as $code => $color) {
886 print
'<div style="float: left; padding: 2px; margin-right: 6px;"><div style="'.($color ?
'background: #'.$color.
';' :
'').
'width:16px; float: left; margin-right: 4px;"> </div>';
887 print $langs->trans(
"Action".$code) !=
"Action".$code ? $langs->trans(
"Action".$code) : $labelbytype[$code];
893 print
'<div style="float: left; padding: 2px; margin-right: 6px;"><div class="peruser_busy" style="width:16px; float: left; margin-right: 4px;"> </div>';
894 print $langs->trans(
"Other");
903 print
"\n".
'</form>';
907 print
'<script type="text/javascript">
908 jQuery(document).ready(function() {
909 jQuery(".onclickopenref").click(function() {
910 var ref=$(this).attr(\'ref\');
911 var res = ref.split("_");
919 if (ids == \'none\') /* No event */
921 /* alert(\'no event\'); */
922 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).
'"
923 window.location.href = url;
925 else if (ids.indexOf(",") > -1) /* There is several events */
927 /* alert(\'several events\'); */
928 url = "'.DOL_URL_ROOT.
'/comm/action/list.php?mode=show_list&filtert="+userid+"&dateselectyear="+year+"&dateselectmonth="+month+"&dateselectday="+day;
929 window.location.href = url;
933 /* alert(\'one event\'); */
934 url = "'.DOL_URL_ROOT.
'/comm/action/card.php?action=view&id="+ids
935 window.location.href = url;
968 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)
971 global $user, $conf, $langs, $hookmanager, $action;
972 global $filter, $filtert, $status, $actioncode;
973 global $theme_datacolor;
974 global $cachethirdparties, $cachecontacts, $cacheusers, $cacheprojects, $colorindexused;
975 global $begin_h, $end_h;
980 $i = 0; $nummytasks = 0; $numother = 0; $numbirthday = 0; $numical = 0; $numicals = array();
981 $ymd = sprintf(
"%04d", $year).sprintf(
"%02d", $month).sprintf(
"%02d", $day);
983 $nextindextouse = count($colorindexused);
989 foreach ($eventarray as $daykey => $notused) {
994 if ($day == $jour && (
int) $month == (
int) $mois && $year == $annee) {
996 foreach ($eventarray[$daykey] as $index => $event) {
1000 $keysofuserassigned = array_keys($event->userassigned);
1001 if (!in_array($username->id, $keysofuserassigned)) {
1006 $parameters = array();
1007 $reshook = $hookmanager->executeHooks(
'formatEvent', $parameters, $event, $action);
1012 $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
1015 $color = -1; $cssclass =
''; $colorindex = -1;
1016 if (in_array($user->id, $keysofuserassigned)) {
1017 $nummytasks++; $cssclass =
'family_mytasks';
1018 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1019 $color = $event->type_color;
1021 } elseif ($event->type_code ==
'ICALEVENT') {
1023 if (!empty($event->icalname)) {
1030 $color = $event->icalcolor;
1031 $cssclass = (!empty($event->icalname) ?
'family_ext'.md5($event->icalname) :
'family_other unsortable');
1032 } elseif ($event->type_code ==
'BIRTHDAY') {
1033 $numbirthday++; $colorindex = 2; $cssclass =
'family_birthday unsortable'; $color = sprintf(
"%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1035 $numother++; $cssclass =
'family_other';
1036 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1037 $color = $event->type_color;
1043 $idusertouse = ($event->userownerid ? $event->userownerid : 0);
1044 if (isset($colorindexused[$idusertouse])) {
1045 $colorindex = $colorindexused[$idusertouse];
1047 $colorindex = $nextindextouse;
1048 $colorindexused[$idusertouse] = $colorindex;
1049 if (!empty($theme_datacolor[$nextindextouse + 1])) {
1054 $color = sprintf(
"%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1059 for ($h = $begin_h; $h < $end_h; $h++) {
1062 if (empty($event->fulldayevent)) {
1063 $a =
dol_mktime((
int) $h, 0, 0, $month, $day, $year,
'tzuserrel', 0);
1064 $b =
dol_mktime((
int) $h, 30, 0, $month, $day, $year,
'tzuserrel', 0);
1065 $c =
dol_mktime((
int) $h + 1, 0, 0, $month, $day, $year,
'tzuserrel', 0);
1067 $dateendtouse = $event->date_end_in_calendar;
1068 if ($dateendtouse == $event->date_start_in_calendar) {
1074 if ($event->date_start_in_calendar < $b && $dateendtouse > $a) {
1075 $busy = $event->transparency;
1076 $cases1[$h][$event->id][
'busy'] = $busy;
1077 $cases1[$h][$event->id][
'string'] =
dol_print_date($event->date_start_in_calendar,
'dayhour',
'tzuserrel');
1078 if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
1079 $tmpa =
dol_getdate($event->date_start_in_calendar,
true);
1080 $tmpb =
dol_getdate($event->date_end_in_calendar,
true);
1081 if ($tmpa[
'mday'] == $tmpb[
'mday'] && $tmpa[
'mon'] == $tmpb[
'mon'] && $tmpa[
'year'] == $tmpb[
'year']) {
1082 $cases1[$h][$event->id][
'string'] .=
'-'.dol_print_date($event->date_end_in_calendar,
'hour',
'tzuserrel');
1084 $cases1[$h][$event->id][
'string'] .=
'-'.dol_print_date($event->date_end_in_calendar,
'dayhour',
'tzuserrel');
1087 if ($event->label) {
1088 $cases1[$h][$event->id][
'string'] .=
' - '.$event->label;
1090 $cases1[$h][$event->id][
'typecode'] = $event->type_code;
1091 $cases1[$h][$event->id][
'color'] = $color;
1092 if ($event->fk_project > 0) {
1093 if (empty($cacheprojects[$event->fk_project])) {
1095 $tmpproj->fetch($event->fk_project);
1096 $cacheprojects[$event->fk_project] = $tmpproj;
1098 $cases1[$h][$event->id][
'string'] .=
', '.$langs->trans(
"Project").
': '.$cacheprojects[$event->fk_project]->ref.
' - '.$cacheprojects[$event->fk_project]->title;
1100 if ($event->socid > 0) {
1101 if (empty($cachethirdparties[$event->socid])) {
1102 $tmpthirdparty =
new Societe($db);
1103 $tmpthirdparty->fetch($event->socid);
1104 $cachethirdparties[$event->socid] = $tmpthirdparty;
1106 $cases1[$h][$event->id][
'string'] .=
', '.$cachethirdparties[$event->socid]->name;
1108 if ($event->contact_id > 0) {
1109 if (empty($cachecontacts[$event->contact_id])) {
1110 $tmpcontact =
new Contact($db);
1111 $tmpcontact->fetch($event->contact_id);
1112 $cachecontacts[$event->contact_id] = $tmpcontact;
1114 $cases1[$h][$event->id][
'string'] .=
', '.$cachecontacts[$event->contact_id]->getFullName($langs);
1117 if ($event->date_start_in_calendar < $c && $dateendtouse > $b) {
1118 $busy = $event->transparency;
1119 $cases2[$h][$event->id][
'busy'] = $busy;
1120 $cases2[$h][$event->id][
'string'] =
dol_print_date($event->date_start_in_calendar,
'dayhour',
'tzuserrel');
1121 if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
1122 $tmpa =
dol_getdate($event->date_start_in_calendar,
true);
1123 $tmpb =
dol_getdate($event->date_end_in_calendar,
true);
1124 if ($tmpa[
'mday'] == $tmpb[
'mday'] && $tmpa[
'mon'] == $tmpb[
'mon'] && $tmpa[
'year'] == $tmpb[
'year']) {
1125 $cases2[$h][$event->id][
'string'] .=
'-'.dol_print_date($event->date_end_in_calendar,
'hour',
'tzuserrel');
1127 $cases2[$h][$event->id][
'string'] .=
'-'.dol_print_date($event->date_end_in_calendar,
'dayhour',
'tzuserrel');
1130 if ($event->label) {
1131 $cases2[$h][$event->id][
'string'] .=
' - '.$event->label;
1133 $cases2[$h][$event->id][
'typecode'] = $event->type_code;
1134 $cases2[$h][$event->id][
'color'] = $color;
1135 if ($event->fk_project > 0) {
1136 if (empty($cacheprojects[$event->fk_project])) {
1138 $tmpproj->fetch($event->fk_project);
1139 $cacheprojects[$event->fk_project] = $tmpproj;
1141 $cases2[$h][$event->id][
'string'] .=
', '.$langs->trans(
"Project").
': '.$cacheprojects[$event->fk_project]->ref.
' - '.$cacheprojects[$event->fk_project]->title;
1143 if ($event->socid > 0) {
1144 if (empty($cachethirdparties[$event->socid])) {
1145 $tmpthirdparty =
new Societe($db);
1146 $tmpthirdparty->fetch($event->socid);
1147 $cachethirdparties[$event->socid] = $tmpthirdparty;
1149 $cases2[$h][$event->id][
'string'] .=
', '.$cachethirdparties[$event->socid]->name;
1151 if ($event->contact_id > 0) {
1152 if (empty($cachecontacts[$event->contact_id])) {
1153 $tmpcontact =
new Contact($db);
1154 $tmpcontact->fetch($event->contact_id);
1155 $cachecontacts[$event->contact_id] = $tmpcontact;
1157 $cases2[$h][$event->id][
'string'] .=
', '.$cachecontacts[$event->contact_id]->getFullName($langs);
1161 $busy = $event->transparency;
1162 $cases1[$h][$event->id][
'busy'] = $busy;
1163 $cases2[$h][$event->id][
'busy'] = $busy;
1164 $cases1[$h][$event->id][
'string'] = $event->label;
1165 $cases2[$h][$event->id][
'string'] = $event->label;
1166 $cases1[$h][$event->id][
'typecode'] = $event->type_code;
1167 $cases2[$h][$event->id][
'typecode'] = $event->type_code;
1168 $cases1[$h][$event->id][
'color'] = $color;
1169 $cases2[$h][$event->id][
'color'] = $color;
1180 for ($h = $begin_h; $h < $end_h; $h++) {
1181 $color1 =
''; $color2 =
'';
1182 $style1 =
''; $style2 =
'';
1183 $string1 =
' '; $string2 =
' ';
1184 $title1 =
''; $title2 =
'';
1185 if (isset($cases1[$h]) && $cases1[$h] !=
'') {
1187 if (count($cases1[$h]) > 1) {
1188 $title1 .= count($cases1[$h]).
' '.(count($cases1[$h]) == 1 ? $langs->trans(
"Event") : $langs->trans(
"Events"));
1190 $string1 =
' ';
1191 if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
1192 $style1 =
'peruser_notbusy';
1194 $style1 =
'peruser_busy';
1196 foreach ($cases1[$h] as $id => $ev) {
1198 $style1 =
'peruser_busy';
1202 if (isset($cases2[$h]) && $cases2[$h] !=
'') {
1204 if (count($cases2[$h]) > 1) {
1205 $title2 .= count($cases2[$h]).
' '.(count($cases2[$h]) == 1 ? $langs->trans(
"Event") : $langs->trans(
"Events"));
1207 $string2 =
' ';
1208 if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
1209 $style2 =
'peruser_notbusy';
1211 $style2 =
'peruser_busy';
1213 foreach ($cases2[$h] as $id => $ev) {
1215 $style2 =
'peruser_busy';
1222 if (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) && array_keys($cases1[$h])) {
1223 $ids1 = join(
',', array_keys($cases1[$h]));
1225 if (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) && array_keys($cases2[$h])) {
1226 $ids2 = join(
',', array_keys($cases2[$h]));
1229 if ($h == $begin_h) {
1230 echo
'<td class="'.$style.
'_peruserleft cal_peruser'.($var ?
' cal_impair '.$style.
'_impair' :
'').
'">';
1232 echo
'<td class="'.$style.
' cal_peruser'.($var ?
' cal_impair '.$style.
'_impair' :
'').
'">';
1234 if (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) == 1) {
1235 $output = array_slice($cases1[$h], 0, 1);
1236 $title1 = $langs->trans(
"Ref").
' '.$ids1.($title1 ?
' - '.$title1 :
'');
1237 if ($output[0][
'string']) {
1238 $title1 .= ($title1 ?
' - ' :
'').$output[0][
'string'];
1240 if ($output[0][
'color']) {
1241 $color1 = $output[0][
'color'];
1243 } elseif (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) > 1) {
1244 $title1 = $langs->trans(
"Ref").
' '.$ids1.($title1 ?
' - '.$title1 :
'');
1248 if (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) == 1) {
1249 $output = array_slice($cases2[$h], 0, 1);
1250 $title2 = $langs->trans(
"Ref").
' '.$ids2.($title2 ?
' - '.$title2 :
'');
1251 if ($output[0][
'string']) {
1252 $title2 .= ($title2 ?
' - ' :
'').$output[0][
'string'];
1254 if ($output[0][
'color']) {
1255 $color2 = $output[0][
'color'];
1257 } elseif (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) > 1) {
1258 $title2 = $langs->trans(
"Ref").
' '.$ids2.($title2 ?
' - '.$title2 :
'');
1261 print
'<table class="nobordernopadding" width="100%">';
1262 print
'<tr><td '.($color1 ?
'style="background: #'.$color1.
';"' :
'').
'class="'.($style1 ? $style1.
' ' :
'').
'onclickopenref center'.($title1 ?
' cursorpointer' :
'').
'" ref="ref_'.$username->id.
'_'.sprintf(
"%04d", $year).
'_'.sprintf(
"%02d", $month).
'_'.sprintf(
"%02d", $day).
'_'.sprintf(
"%02d", $h).
'_00_'.($ids1 ? $ids1 :
'none').
'"'.($title1 ?
' title="'.$title1.
'"' :
'').
'>';
1264 print
'</td><td '.($color2 ?
'style="background: #'.$color2.
';"' :
'').
'class="'.($style2 ? $style2.
' ' :
'').
'onclickopenref center'.($title1 ?
' cursorpointer' :
'').
'" ref="ref_'.$username->id.
'_'.sprintf(
"%04d", $year).
'_'.sprintf(
"%02d", $month).
'_'.sprintf(
"%02d", $day).
'_'.sprintf(
"%02d", $h).
'_30_'.($ids2 ? $ids2 :
'none').
'"'.($title2 ?
' title="'.$title2.
'"' :
'').
'>';