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 (!$user->hasRight(
'agenda',
'myactions',
'read')) {
95 if (!$user->hasRight(
'agenda',
'allactions',
'read')) {
98 if (!$user->hasRight(
'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';
369 $nav =
'<div class="navselectiondate inline-block nowraponall">';
370 $nav .=
"<a href=\"?year=".$prev_year.
"&month=".$prev_month.
"&day=".$prev_day.$param.
"\">".
img_previous($langs->trans(
"Previous")).
"</a>\n";
371 $nav .=
" <span id=\"month_name\">".dol_print_date(
dol_mktime(0, 0, 0, $first_month, $first_day, $first_year),
"%Y").
"</span> \n";
372 $nav .=
"<a href=\"?year=".$next_year.
"&month=".$next_month.
"&day=".$next_day.$param.
"\">".
img_next($langs->trans(
"Next")).
"</a>\n";
373 if (empty($conf->dol_optimize_smallscreen)) {
374 $nav .=
" (<a href=\"?year=".$nowyear.
"&month=".$nowmonth.
"&day=".$nowday.$param.
'" class="datenowlink">'.$langs->trans(
"Today").
"</a>)";
378 $nav .=
$form->selectDate($dateselect,
'dateselect', 0, 0, 1,
'', 1, 0);
379 $nav .=
' <button type="submit" class="liste_titre button_search" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
382 $param .=
'&year='.urlencode($year).
'&month='.urlencode($month).($day ?
'&day='.urlencode($day) :
'');
386 $paramnoaction = preg_replace(
'/action=[a-z_]+/',
'', $param);
390 print
'<form method="POST" id="searchFormList" class="listactionsfilter" action="'.$_SERVER[
"PHP_SELF"].
'">'.
"\n";
392 $showextcals = $listofextcals;
394 if ($conf->use_javascript_ajax) {
396 $s .=
'<script type="text/javascript">'.
"\n";
397 $s .=
'jQuery(document).ready(function () {'.
"\n";
398 $s .=
'jQuery("#check_mytasks").click(function() { jQuery(".family_mytasks").toggle(); jQuery(".family_other").toggle(); });'.
"\n";
399 $s .=
'jQuery("#check_birthday").click(function() { jQuery(".family_birthday").toggle(); });'.
"\n";
400 $s .=
'jQuery(".family_birthday").toggle();'.
"\n";
401 if ($mode ==
"show_week" || $mode ==
"show_month" || empty($mode)) {
402 $s .=
'jQuery( "td.sortable" ).sortable({connectWith: ".sortable",placeholder: "ui-state-highlight",items: "div:not(.unsortable)", receive: function( event, ui ) {';
405 $s .=
'</script>'.
"\n";
406 if (!empty($conf->use_javascript_ajax)) {
407 $s .=
'<div class="nowrap clear float"><input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> '.$langs->trans(
"LocalAgenda").
' </div>';
408 if (is_array($showextcals) && count($showextcals) > 0) {
409 foreach ($showextcals as $val) {
410 $htmlname = md5($val[
'name']);
411 $s .=
'<script type="text/javascript">'.
"\n";
412 $s .=
'jQuery(document).ready(function () {'.
"\n";
413 $s .=
' jQuery("#check_ext'.$htmlname.
'").click(function() {';
414 $s .=
' /* alert("'.$htmlname.
'"); */';
415 $s .=
' jQuery(".family_ext'.$htmlname.
'").toggle();';
418 $s .=
'</script>'.
"\n";
419 $s .=
'<div class="nowrap float"><input type="checkbox" id="check_ext'.$htmlname.
'" name="check_ext'.$htmlname.
'" checked> '.$val [
'name'].
' </div>';
426 $parameters = array();
427 $reshook = $hookmanager->executeHooks(
'addCalendarChoice', $parameters, $object, $action);
428 if (empty($reshook)) {
429 $s .= $hookmanager->resPrint;
430 } elseif ($reshook > 1) {
431 $s = $hookmanager->resPrint;
436 $massactionbutton =
'';
439 $viewmode .=
'<a class="btnTitle reposition" href="'.DOL_URL_ROOT.
'/comm/action/list.php?mode=show_list&restore_lastsearch_values=1'.$paramnoactionodate.
'">';
441 $viewmode .=
img_picto($langs->trans(
"List"),
'object_calendarlist',
'class="imgforviewmode pictoactionview block"');
443 $viewmode .=
'<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans(
"ViewList").
'</span></a>';
445 $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.
'">';
447 $viewmode .=
img_picto($langs->trans(
"ViewCal"),
'object_calendarmonth',
'class="pictoactionview block"');
449 $viewmode .=
'<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans(
"ViewCal").
'</span></a>';
451 $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.
'">';
453 $viewmode .=
img_picto($langs->trans(
"ViewWeek"),
'object_calendarweek',
'class="pictoactionview block"');
455 $viewmode .=
'<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans(
"ViewWeek").
'</span></a>';
457 $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.
'">';
459 $viewmode .=
img_picto($langs->trans(
"ViewDay"),
'object_calendarday',
'class="pictoactionview block"');
461 $viewmode .=
'<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans(
"ViewDay").
'</span></a>';
463 $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.
'">';
465 $viewmode .=
img_picto($langs->trans(
"ViewPerUser"),
'object_calendarperuser',
'class="pictoactionview block"');
467 $viewmode .=
'<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans(
"ViewPerUser").
'</span></a>';
469 $viewmode .=
'<span class="marginrightonly"></span>';
472 $parameters = array(); $object =
null;
473 $reshook = $hookmanager->executeHooks(
'addCalendarView', $parameters, $object, $action);
474 if (empty($reshook)) {
475 $viewmode .= $hookmanager->resPrint;
476 } elseif ($reshook > 1) {
477 $viewmode = $hookmanager->resPrint;
482 if ($user->rights->agenda->myactions->create || $user->hasRight(
'agenda',
'allactions',
'create')) {
485 $newparam .=
'&month='.str_pad($month, 2,
"0", STR_PAD_LEFT).
'&year='.$tmpforcreatebutton[
'year'];
488 $hourminsec =
'100000';
489 $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 :
'')));
492 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);
499 $newtitle =
'<div class="nowrap clear inline-block minheight30">';
500 $newtitle .=
'<input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> '.$langs->trans(
"LocalAgenda").
' ';
501 $newtitle .=
'</div>';
508 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
509 print_actions_filter(
$form, $canedit, $search_status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup,
'', $resourceid);
514 $eventarray = array();
519 if ($usergroup > 0) {
522 $sql .=
' a.id, a.label,';
524 $sql .=
' a.datep2,';
525 $sql .=
' a.percent,';
526 $sql .=
' a.fk_user_author,a.fk_user_action,';
527 $sql .=
' a.transparency, a.priority, a.fulldayevent, a.location,';
528 $sql .=
' a.fk_soc, a.fk_contact, a.fk_element, a.elementtype, a.fk_project,';
529 $sql .=
' ca.code, ca.libelle as type_label, ca.color, ca.type as type_type, ca.picto as type_picto';
530 $sql .=
' FROM '.MAIN_DB_PREFIX.
'c_actioncomm as ca, '.MAIN_DB_PREFIX.
"actioncomm as a";
531 if (empty($user->rights->societe->client->voir) && !$socid) {
532 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
535 if ($resourceid > 0) {
536 $sql .=
", ".MAIN_DB_PREFIX.
"element_resources as r";
539 if ($filtert > 0 || $usergroup > 0) {
540 $sql .=
", ".MAIN_DB_PREFIX.
"actioncomm_resources as ar";
542 if ($usergroup > 0) {
543 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
545 $sql .=
' WHERE a.fk_action = ca.id';
546 $sql .=
' AND a.entity IN ('.getEntity(
'agenda').
')';
548 if (!empty($actioncode)) {
549 if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
550 if ($actioncode ==
'AC_NON_AUTO') {
551 $sql .=
" AND ca.type != 'systemauto'";
552 } elseif ($actioncode ==
'AC_ALL_AUTO') {
553 $sql .=
" AND ca.type = 'systemauto'";
555 if ($actioncode ==
'AC_OTH') {
556 $sql .=
" AND ca.type != 'systemauto'";
558 if ($actioncode ==
'AC_OTH_AUTO') {
559 $sql .=
" AND ca.type = 'systemauto'";
563 if ($actioncode ==
'AC_NON_AUTO') {
564 $sql .=
" AND ca.type != 'systemauto'";
565 } elseif ($actioncode ==
'AC_ALL_AUTO') {
566 $sql .=
" AND ca.type = 'systemauto'";
568 if (is_array($actioncode)) {
569 $sql .=
" AND ca.code IN (".$db->sanitize(
"'".implode(
"','", $actioncode).
"'", 1).
")";
571 $sql .=
" AND ca.code IN (".$db->sanitize(
"'".implode(
"','", explode(
',', $actioncode)).
"'", 1).
")";
576 if ($resourceid > 0) {
577 $sql .=
" AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".((int) $resourceid);
580 $sql .=
" AND a.fk_project=".((int) $pid);
582 if (empty($user->rights->societe->client->voir) && !$socid) {
583 $sql .=
" AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).
")";
586 $sql .=
' AND a.fk_soc = '.((int) $socid);
589 if ($filtert > 0 || $usergroup > 0) {
590 $sql .=
" AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
592 if ($mode ==
'show_day') {
594 $sql .=
" (a.datep 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.datep2 BETWEEN '".$db->idate(
dol_mktime(0, 0, 0, $month, $day, $year,
'tzuserrel')).
"'";
598 $sql .=
" AND '".$db->idate(
dol_mktime(23, 59, 59, $month, $day, $year,
'tzuserrel')).
"')";
600 $sql .=
" (a.datep < '".$db->idate(
dol_mktime(0, 0, 0, $month, $day, $year,
'tzuserrel')).
"'";
601 $sql .=
" AND a.datep2 > '".$db->idate(
dol_mktime(23, 59, 59, $month, $day, $year,
'tzuserrel')).
"')";
606 $sql .=
" (a.datep 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.datep2 BETWEEN '".$db->idate(
dol_mktime(0, 0, 0, 1, 1, $year) - (60 * 60 * 24 * 7)).
"'";
610 $sql .=
" AND '".$db->idate(
dol_mktime(23, 59, 59, 12, 31, $year) + (60 * 60 * 24 * 7)).
"')";
612 $sql .=
" (a.datep < '".$db->idate(
dol_mktime(0, 0, 0, 12, 1, $year) - (60 * 60 * 24 * 7)).
"'";
613 $sql .=
" AND a.datep2 > '".$db->idate(
dol_mktime(23, 59, 59, 12, 31, $year) + (60 * 60 * 24 * 7)).
"')";
617 $sql .=
" AND ca.id = ".((int) $type);
619 if ($status ==
'0') {
620 $sql .=
" AND a.percent = 0";
622 if ($status ===
'na') {
624 $sql .=
" AND a.percent = -1";
626 if ($status ==
'50') {
628 $sql .=
" AND (a.percent > 0 AND a.percent < 100)";
630 if ($status ==
'done' || $status ==
'100') {
631 $sql .=
" AND (a.percent = 100)";
633 if ($status ==
'todo') {
634 $sql .=
" AND (a.percent >= 0 AND a.percent < 100)";
637 if ($filtert > 0 || $usergroup > 0) {
640 $sql .=
"ar.fk_element = ".$filtert;
642 if ($usergroup > 0) {
643 $sql .= ($filtert > 0 ?
" OR " :
"").
" ugu.fk_usergroup = ".((
int) $usergroup);
648 $sql .=
' ORDER BY fk_user_action, datep';
651 dol_syslog(
"comm/action/pertype.php", LOG_DEBUG);
652 $resql = $db->query(
$sql);
654 $num = $db->num_rows($resql);
657 $obj = $db->fetch_object($resql);
660 if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->code ==
'AC_OTH_AUTO') {
665 $datep = $db->jdate($obj->datep);
666 $datep2 = $db->jdate($obj->datep2);
670 $event->id = $obj->id;
671 $event->datep = $datep;
672 $event->datef = $datep2;
673 $event->type_code = $obj->code;
674 $event->type_color = $obj->color;
675 $event->label = $obj->label;
676 $event->percentage = $obj->percent;
677 $event->authorid = $obj->fk_user_author;
678 $event->userownerid = $obj->fk_user_action;
679 $event->priority = $obj->priority;
680 $event->fulldayevent = $obj->fulldayevent;
681 $event->location = $obj->location;
682 $event->transparency = $obj->transparency;
684 $event->fk_project = $obj->fk_project;
686 $event->socid = $obj->fk_soc;
687 $event->contact_id = $obj->fk_contact;
689 $event->fk_element = $obj->fk_element;
690 $event->elementtype = $obj->elementtype;
694 if ($event->percentage <= 0) {
695 $event->date_start_in_calendar = $datep;
696 if ($datep2 !=
'' && $datep2 >= $datep) {
697 $event->date_end_in_calendar = $datep2;
699 $event->date_end_in_calendar = $datep;
702 $event->date_start_in_calendar = $datep;
703 if ($datep2 !=
'' && $datep2 >= $datep) {
704 $event->date_end_in_calendar = $datep2;
706 $event->date_end_in_calendar = $datep;
711 if ($event->date_end_in_calendar < $firstdaytoshow ||
712 $event->date_start_in_calendar >= $lastdaytoshow) {
717 $event->fetch_userassigned();
719 if ($event->date_start_in_calendar < $firstdaytoshow) {
720 $event->date_start_in_calendar = $firstdaytoshow;
722 if ($event->date_end_in_calendar >= $lastdaytoshow) {
723 $event->date_end_in_calendar = ($lastdaytoshow - 1);
727 $daycursor = $event->date_start_in_calendar;
733 $loop =
true; $j = 0;
734 $daykey =
dol_mktime(0, 0, 0, $mois, $jour, $annee,
'gmt');
738 $eventarray[$daykey][] = $event;
741 $daykey += 60 * 60 * 24;
742 if ($daykey > $event->date_end_in_calendar) {
758 $cachethirdparties = array();
759 $cachecontacts = array();
760 $cacheusers = array();
763 $color_file = DOL_DOCUMENT_ROOT.
"/theme/".$conf->theme.
"/theme_vars.inc.php";
764 if (is_readable($color_file)) {
767 if (!is_array($theme_datacolor)) {
768 $theme_datacolor = array(array(120, 130, 150), array(200, 160, 180), array(190, 190, 220));
773 $newparam = preg_replace(
'/showbirthday=/i',
'showbirthday_=', $newparam);
774 $newparam = preg_replace(
'/mode=show_month&?/i',
'', $newparam);
775 $newparam = preg_replace(
'/mode=show_week&?/i',
'', $newparam);
776 $newparam = preg_replace(
'/day=[0-9]+&?/i',
'', $newparam);
777 $newparam = preg_replace(
'/month=[0-9]+&?/i',
'', $newparam);
778 $newparam = preg_replace(
'/year=[0-9]+&?/i',
'', $newparam);
779 $newparam = preg_replace(
'/viewweek=[0-9]+&?/i',
'', $newparam);
780 $newparam = preg_replace(
'/showbirthday_=/i',
'showbirthday=', $newparam);
781 $newparam .=
'&viewweek=1';
783 print
'<input type="hidden" name="action" value="mupdate">';
784 echo
'<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER[
'PHP_SELF']).
'?'.
dol_escape_htmltag($_SERVER[
'QUERY_STRING']).
'">';
785 echo
'<input type="hidden" name="token" value="'.newToken().
'">';
786 echo
'<input type="hidden" name="newdate" id="newdate">';
793 echo
'<div class="div-table-responsive">';
795 echo
'<table class="centpercent nocellnopadd cal_month">';
797 echo
'<tr class="liste_titre">';
800 echo
'<td align="center" colspan="'.($end_d - $begin_d).
'">';
801 echo $langs->trans(
"Year");
807 echo
'<tr class="liste_titre">';
810 for ($h = $begin_d; $h < $end_d; $h++) {
811 echo
'<td class="center">';
812 print
'<small style="font-family: courier">'.sprintf(
"%02d", $h).
'</small>';
819 $typeofevents = array();
822 $colorsbytype = array();
823 $labelbytype = array();
824 $sql =
"SELECT code, color, libelle as label FROM ".MAIN_DB_PREFIX.
"c_actioncomm ORDER BY position";
825 $resql = $db->query(
$sql);
826 while ($obj = $db->fetch_object($resql)) {
827 $typeofevents[$obj->code] = $obj->code;
828 $colorsbytype[$obj->code] = $obj->color;
829 $labelbytype[$obj->code] = $obj->label;
837 foreach ($typeofevents as $typeofevent) {
840 echo
'<td class="cal_current_month cal_peruserviewname'.($var ?
' cal_impair' :
'').
'">'.$typeofevent.
'</td>';
845 for ($iter_day = 0; $iter_day < 8; $iter_day++) {
846 if (($i + 1) < $begin_d || ($i + 1) > $end_d) {
859 $style =
'cal_current_month';
860 if ($iter_day == 6) {
861 $style .=
' cal_other_month';
864 if ($todayarray[
'mday'] == $tmpday && $todayarray[
'mon'] == $tmpmonth && $todayarray[
'year'] == $tmpyear) {
868 $style =
'cal_today_peruser';
871 show_day_events_pertype($typeofevent, $tmpday, $tmpmonth, $tmpyear, 0, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, $showheader, $colorsbytype, $var);
884 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
885 $langs->load(
"commercial");
886 print
'<br>'.$langs->trans(
"Legend").
': <br>';
887 foreach ($colorsbytype as $code => $color) {
889 print
'<div style="float: left; padding: 2px; margin-right: 6px;"><div style="'.($color ?
'background: #'.$color.
';' :
'').
'width:16px; float: left; margin-right: 4px;"> </div>';
890 print $langs->trans(
"Action".$code) !=
"Action".$code ? $langs->trans(
"Action".$code) : $labelbytype[$code];
896 print
'<div style="float: left; padding: 2px; margin-right: 6px;"><div class="peruser_busy" style="width:16px; float: left; margin-right: 4px;"> </div>';
897 print $langs->trans(
"Other");
906 print
"\n".
'</form>';
910 print
'<script type="text/javascript">
911 jQuery(document).ready(function() {
912 jQuery(".onclickopenref").click(function() {
913 var ref=$(this).attr(\'ref\');
914 var res = ref.split("_");
922 if (ids == \'none\') /* No event */
924 /* alert(\'no event\'); */
925 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).
'"
926 window.location.href = url;
928 else if (ids.indexOf(",") > -1) /* There is several events */
930 /* alert(\'several events\'); */
931 url = "'.DOL_URL_ROOT.
'/comm/action/list.php?mode=show_list&filtert="+userid+"&dateselectyear="+year+"&dateselectmonth="+month+"&dateselectday="+day;
932 window.location.href = url;
936 /* alert(\'one event\'); */
937 url = "'.DOL_URL_ROOT.
'/comm/action/card.php?action=view&id="+ids
938 window.location.href = url;
971 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)
974 global $user, $conf, $langs, $hookmanager, $action;
975 global $filter, $filtert, $status, $actioncode;
976 global $theme_datacolor;
977 global $cachethirdparties, $cachecontacts, $cacheusers, $cacheprojects, $colorindexused;
978 global $begin_h, $end_h;
983 $i = 0; $nummytasks = 0; $numother = 0; $numbirthday = 0; $numical = 0; $numicals = array();
984 $ymd = sprintf(
"%04d", $year).sprintf(
"%02d", $month).sprintf(
"%02d", $day);
986 $nextindextouse = count($colorindexused);
992 foreach ($eventarray as $daykey => $notused) {
997 if ($day == $jour && (
int) $month == (
int) $mois && $year == $annee) {
999 foreach ($eventarray[$daykey] as $index => $event) {
1003 $keysofuserassigned = array_keys($event->userassigned);
1004 if (!in_array($username->id, $keysofuserassigned)) {
1009 $parameters = array();
1010 $reshook = $hookmanager->executeHooks(
'formatEvent', $parameters, $event, $action);
1015 $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
1018 $color = -1; $cssclass =
''; $colorindex = -1;
1019 if (in_array($user->id, $keysofuserassigned)) {
1020 $nummytasks++; $cssclass =
'family_mytasks';
1021 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1022 $color = $event->type_color;
1024 } elseif ($event->type_code ==
'ICALEVENT') {
1026 if (!empty($event->icalname)) {
1033 $color = $event->icalcolor;
1034 $cssclass = (!empty($event->icalname) ?
'family_ext'.md5($event->icalname) :
'family_other unsortable');
1035 } elseif ($event->type_code ==
'BIRTHDAY') {
1036 $numbirthday++; $colorindex = 2; $cssclass =
'family_birthday unsortable'; $color = sprintf(
"%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1038 $numother++; $cssclass =
'family_other';
1039 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1040 $color = $event->type_color;
1046 $idusertouse = ($event->userownerid ? $event->userownerid : 0);
1047 if (isset($colorindexused[$idusertouse])) {
1048 $colorindex = $colorindexused[$idusertouse];
1050 $colorindex = $nextindextouse;
1051 $colorindexused[$idusertouse] = $colorindex;
1052 if (!empty($theme_datacolor[$nextindextouse + 1])) {
1057 $color = sprintf(
"%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1062 for ($h = $begin_h; $h < $end_h; $h++) {
1065 if (empty($event->fulldayevent)) {
1066 $a =
dol_mktime((
int) $h, 0, 0, $month, $day, $year,
'tzuserrel', 0);
1067 $b =
dol_mktime((
int) $h, 30, 0, $month, $day, $year,
'tzuserrel', 0);
1068 $c =
dol_mktime((
int) $h + 1, 0, 0, $month, $day, $year,
'tzuserrel', 0);
1070 $dateendtouse = $event->date_end_in_calendar;
1071 if ($dateendtouse == $event->date_start_in_calendar) {
1077 if ($event->date_start_in_calendar < $b && $dateendtouse > $a) {
1078 $busy = $event->transparency;
1079 $cases1[$h][$event->id][
'busy'] = $busy;
1080 $cases1[$h][$event->id][
'string'] =
dol_print_date($event->date_start_in_calendar,
'dayhour',
'tzuserrel');
1081 if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
1082 $tmpa =
dol_getdate($event->date_start_in_calendar,
true);
1083 $tmpb =
dol_getdate($event->date_end_in_calendar,
true);
1084 if ($tmpa[
'mday'] == $tmpb[
'mday'] && $tmpa[
'mon'] == $tmpb[
'mon'] && $tmpa[
'year'] == $tmpb[
'year']) {
1085 $cases1[$h][$event->id][
'string'] .=
'-'.dol_print_date($event->date_end_in_calendar,
'hour',
'tzuserrel');
1087 $cases1[$h][$event->id][
'string'] .=
'-'.dol_print_date($event->date_end_in_calendar,
'dayhour',
'tzuserrel');
1090 if ($event->label) {
1091 $cases1[$h][$event->id][
'string'] .=
' - '.$event->label;
1093 $cases1[$h][$event->id][
'typecode'] = $event->type_code;
1094 $cases1[$h][$event->id][
'color'] = $color;
1095 if ($event->fk_project > 0) {
1096 if (empty($cacheprojects[$event->fk_project])) {
1098 $tmpproj->fetch($event->fk_project);
1099 $cacheprojects[$event->fk_project] = $tmpproj;
1101 $cases1[$h][$event->id][
'string'] .=
', '.$langs->trans(
"Project").
': '.$cacheprojects[$event->fk_project]->ref.
' - '.$cacheprojects[$event->fk_project]->title;
1103 if ($event->socid > 0) {
1104 if (empty($cachethirdparties[$event->socid])) {
1105 $tmpthirdparty =
new Societe($db);
1106 $tmpthirdparty->fetch($event->socid);
1107 $cachethirdparties[$event->socid] = $tmpthirdparty;
1109 $cases1[$h][$event->id][
'string'] .=
', '.$cachethirdparties[$event->socid]->name;
1111 if ($event->contact_id > 0) {
1112 if (empty($cachecontacts[$event->contact_id])) {
1113 $tmpcontact =
new Contact($db);
1114 $tmpcontact->fetch($event->contact_id);
1115 $cachecontacts[$event->contact_id] = $tmpcontact;
1117 $cases1[$h][$event->id][
'string'] .=
', '.$cachecontacts[$event->contact_id]->getFullName($langs);
1120 if ($event->date_start_in_calendar < $c && $dateendtouse > $b) {
1121 $busy = $event->transparency;
1122 $cases2[$h][$event->id][
'busy'] = $busy;
1123 $cases2[$h][$event->id][
'string'] =
dol_print_date($event->date_start_in_calendar,
'dayhour',
'tzuserrel');
1124 if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
1125 $tmpa =
dol_getdate($event->date_start_in_calendar,
true);
1126 $tmpb =
dol_getdate($event->date_end_in_calendar,
true);
1127 if ($tmpa[
'mday'] == $tmpb[
'mday'] && $tmpa[
'mon'] == $tmpb[
'mon'] && $tmpa[
'year'] == $tmpb[
'year']) {
1128 $cases2[$h][$event->id][
'string'] .=
'-'.dol_print_date($event->date_end_in_calendar,
'hour',
'tzuserrel');
1130 $cases2[$h][$event->id][
'string'] .=
'-'.dol_print_date($event->date_end_in_calendar,
'dayhour',
'tzuserrel');
1133 if ($event->label) {
1134 $cases2[$h][$event->id][
'string'] .=
' - '.$event->label;
1136 $cases2[$h][$event->id][
'typecode'] = $event->type_code;
1137 $cases2[$h][$event->id][
'color'] = $color;
1138 if ($event->fk_project > 0) {
1139 if (empty($cacheprojects[$event->fk_project])) {
1141 $tmpproj->fetch($event->fk_project);
1142 $cacheprojects[$event->fk_project] = $tmpproj;
1144 $cases2[$h][$event->id][
'string'] .=
', '.$langs->trans(
"Project").
': '.$cacheprojects[$event->fk_project]->ref.
' - '.$cacheprojects[$event->fk_project]->title;
1146 if ($event->socid > 0) {
1147 if (empty($cachethirdparties[$event->socid])) {
1148 $tmpthirdparty =
new Societe($db);
1149 $tmpthirdparty->fetch($event->socid);
1150 $cachethirdparties[$event->socid] = $tmpthirdparty;
1152 $cases2[$h][$event->id][
'string'] .=
', '.$cachethirdparties[$event->socid]->name;
1154 if ($event->contact_id > 0) {
1155 if (empty($cachecontacts[$event->contact_id])) {
1156 $tmpcontact =
new Contact($db);
1157 $tmpcontact->fetch($event->contact_id);
1158 $cachecontacts[$event->contact_id] = $tmpcontact;
1160 $cases2[$h][$event->id][
'string'] .=
', '.$cachecontacts[$event->contact_id]->getFullName($langs);
1164 $busy = $event->transparency;
1165 $cases1[$h][$event->id][
'busy'] = $busy;
1166 $cases2[$h][$event->id][
'busy'] = $busy;
1167 $cases1[$h][$event->id][
'string'] = $event->label;
1168 $cases2[$h][$event->id][
'string'] = $event->label;
1169 $cases1[$h][$event->id][
'typecode'] = $event->type_code;
1170 $cases2[$h][$event->id][
'typecode'] = $event->type_code;
1171 $cases1[$h][$event->id][
'color'] = $color;
1172 $cases2[$h][$event->id][
'color'] = $color;
1183 for ($h = $begin_h; $h < $end_h; $h++) {
1184 $color1 =
''; $color2 =
'';
1185 $style1 =
''; $style2 =
'';
1186 $string1 =
' '; $string2 =
' ';
1187 $title1 =
''; $title2 =
'';
1188 if (isset($cases1[$h]) && $cases1[$h] !=
'') {
1190 if (count($cases1[$h]) > 1) {
1191 $title1 .= count($cases1[$h]).
' '.(count($cases1[$h]) == 1 ? $langs->trans(
"Event") : $langs->trans(
"Events"));
1193 $string1 =
' ';
1194 if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
1195 $style1 =
'peruser_notbusy';
1197 $style1 =
'peruser_busy';
1199 foreach ($cases1[$h] as $id => $ev) {
1201 $style1 =
'peruser_busy';
1205 if (isset($cases2[$h]) && $cases2[$h] !=
'') {
1207 if (count($cases2[$h]) > 1) {
1208 $title2 .= count($cases2[$h]).
' '.(count($cases2[$h]) == 1 ? $langs->trans(
"Event") : $langs->trans(
"Events"));
1210 $string2 =
' ';
1211 if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
1212 $style2 =
'peruser_notbusy';
1214 $style2 =
'peruser_busy';
1216 foreach ($cases2[$h] as $id => $ev) {
1218 $style2 =
'peruser_busy';
1225 if (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) && array_keys($cases1[$h])) {
1226 $ids1 = join(
',', array_keys($cases1[$h]));
1228 if (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) && array_keys($cases2[$h])) {
1229 $ids2 = join(
',', array_keys($cases2[$h]));
1232 if ($h == $begin_h) {
1233 echo
'<td class="'.$style.
'_peruserleft cal_peruser'.($var ?
' cal_impair '.$style.
'_impair' :
'').
'">';
1235 echo
'<td class="'.$style.
' cal_peruser'.($var ?
' cal_impair '.$style.
'_impair' :
'').
'">';
1237 if (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) == 1) {
1238 $output = array_slice($cases1[$h], 0, 1);
1239 $title1 = $langs->trans(
"Ref").
' '.$ids1.($title1 ?
' - '.$title1 :
'');
1240 if ($output[0][
'string']) {
1241 $title1 .= ($title1 ?
' - ' :
'').$output[0][
'string'];
1243 if ($output[0][
'color']) {
1244 $color1 = $output[0][
'color'];
1246 } elseif (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) > 1) {
1247 $title1 = $langs->trans(
"Ref").
' '.$ids1.($title1 ?
' - '.$title1 :
'');
1251 if (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) == 1) {
1252 $output = array_slice($cases2[$h], 0, 1);
1253 $title2 = $langs->trans(
"Ref").
' '.$ids2.($title2 ?
' - '.$title2 :
'');
1254 if ($output[0][
'string']) {
1255 $title2 .= ($title2 ?
' - ' :
'').$output[0][
'string'];
1257 if ($output[0][
'color']) {
1258 $color2 = $output[0][
'color'];
1260 } elseif (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) > 1) {
1261 $title2 = $langs->trans(
"Ref").
' '.$ids2.($title2 ?
' - '.$title2 :
'');
1264 print
'<table class="nobordernopadding" width="100%">';
1265 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.
'"' :
'').
'>';
1267 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.
'"' :
'').
'>';