31 require
'../../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/user/class/usergroup.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/agenda.lib.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
42 if (!isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) {
43 $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW = 3;
46 $action =
GETPOST(
'action',
'aZ09');
48 $disabledefaultvalues =
GETPOST(
'disabledefaultvalues',
'int');
50 $filter =
GETPOST(
"search_filter",
'alpha', 3) ?
GETPOST(
"search_filter",
'alpha', 3) :
GETPOST(
"filter",
'alpha', 3);
51 $filtert =
GETPOST(
"search_filtert",
"int", 3) ?
GETPOST(
"search_filtert",
"int", 3) :
GETPOST(
"filtert",
"int", 3);
52 $usergroup =
GETPOST(
"search_usergroup",
"int", 3) ?
GETPOST(
"search_usergroup",
"int", 3) :
GETPOST(
"usergroup",
"int", 3);
58 if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS)) {
62 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
63 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
65 if (empty($page) || $page == -1) {
68 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
69 $offset = $limit * $page;
74 $sortfield =
"a.datec";
80 $socid = $user->socid;
87 if (empty($user->rights->agenda->myactions->read)) {
90 if (empty($user->rights->agenda->allactions->read)) {
93 if (empty($user->rights->agenda->allactions->read) || $filter ==
'mine') {
97 $mode =
'show_pertype';
98 $resourceid =
GETPOST(
"search_resourceid",
"int") ?
GETPOST(
"search_resourceid",
"int") :
GETPOST(
"resourceid",
"int");
99 $year =
GETPOST(
"year",
"int") ?
GETPOST(
"year",
"int") : date(
"Y");
100 $month =
GETPOST(
"month",
"int") ?
GETPOST(
"month",
"int") : date(
"m");
101 $week =
GETPOST(
"week",
"int") ?
GETPOST(
"week",
"int") : date(
"W");
106 $maxprint = ((
GETPOST(
"maxprint",
'int') !=
'') ?
GETPOST(
"maxprint",
'int') : $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW);
107 $optioncss =
GETPOST(
'optioncss',
'aZ');
109 if (
GETPOST(
'search_actioncode',
'array')) {
110 $actioncode =
GETPOST(
'search_actioncode',
'array', 3);
111 if (!count($actioncode)) {
115 $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));
119 if ($dateselect > 0) {
120 $day =
GETPOST(
'dateselectday',
'int');
121 $month =
GETPOST(
'dateselectmonth',
'int');
122 $year =
GETPOST(
'dateselectyear',
'int');
125 $tmp = empty($conf->global->MAIN_DEFAULT_WORKING_HOURS) ?
'9-18' : $conf->global->MAIN_DEFAULT_WORKING_HOURS;
126 $tmp = str_replace(
' ',
'', $tmp);
127 $tmparray = explode(
'-', $tmp);
128 $begin_h =
GETPOST(
'begin_h',
'int') !=
'' ?
GETPOST(
'begin_h',
'int') : ($tmparray[0] !=
'' ? $tmparray[0] : 9);
129 $end_h =
GETPOST(
'end_h',
'int') ?
GETPOST(
'end_h',
'int') : ($tmparray[1] !=
'' ? $tmparray[1] : 18);
130 if ($begin_h < 0 || $begin_h > 23) {
133 if ($end_h < 1 || $end_h > 24) {
136 if ($end_h <= $begin_h) {
137 $end_h = $begin_h + 1;
140 $tmp = empty($conf->global->MAIN_DEFAULT_WORKING_DAYS) ?
'1-5' : $conf->global->MAIN_DEFAULT_WORKING_DAYS;
141 $tmp = str_replace(
' ',
'', $tmp);
142 $tmparray = explode(
'-', $tmp);
147 $status = ((empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS) || $disabledefaultvalues) ?
'' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS);
150 $mode = (empty($conf->global->AGENDA_DEFAULT_VIEW) ?
'show_month' : $conf->global->AGENDA_DEFAULT_VIEW);
153 if (
GETPOST(
'viewcal',
'alpha') && $mode !=
'show_day' && $mode !=
'show_week' && $mode !=
'show_peruser') {
154 $mode =
'show_month'; $day =
'';
156 if (
GETPOST(
'viewweek',
'alpha') || $mode ==
'show_week') {
157 $mode =
'show_week'; $week = ($week ? $week : date(
"W")); $day = ($day ? $day : date(
"d"));
159 if (
GETPOST(
'viewday',
'alpha') || $mode ==
'show_day') {
160 $mode =
'show_day'; $day = ($day ? $day : date(
"d"));
162 if (
GETPOST(
'viewyear',
'alpha') || $mode ==
'show_year') {
169 $langs->loadLangs(array(
'users',
'agenda',
'other',
'commercial'));
172 $hookmanager->initHooks(array(
'agenda'));
175 if ($user->socid && $socid) {
179 $search_status = $status;
210 'maxprint' => $maxprint,
212 'filtert' => $filtert,
213 'showbirthday' => $showbirthday,
214 'canedit' => $canedit,
215 'optioncss' => $optioncss,
216 'actioncode' => $actioncode,
218 'resourceid' => $resourceid,
219 'usergroup' => $usergroup,
221 $reshook = $hookmanager->executeHooks(
'beforeAgendaPerType', $parameters, $object, $action);
227 $companystatic =
new Societe($db);
229 $help_url =
'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda';
234 $nowyear = $nowarray[
'year'];
235 $nowmonth = $nowarray[
'mon'];
236 $nowday = $nowarray[
'mday'];
240 $listofextcals = array();
247 $week = $prev[
'week'];
251 $next_year = $year + 1;
252 $next_month = $month;
255 $max_day_in_month = date(
"t",
dol_mktime(0, 0, 0, $month, 1, $year));
257 $tmpday = $first_day;
261 $title = $langs->trans(
"DoneAndToDoActions");
262 if ($status ==
'done') {
263 $title = $langs->trans(
"DoneActions");
265 if ($status ==
'todo') {
266 $title = $langs->trans(
"ToDoActions");
271 if (is_array($actioncode)) {
272 foreach ($actioncode as $str_action) {
273 $param .=
"&search_actioncode[]=".urlencode($str_action);
276 $param .=
"&search_actioncode=".urlencode($actioncode);
279 if ($resourceid > 0) {
280 $param .=
"&search_resourceid=".urlencode($resourceid);
283 $param .=
"&search_status=".urlencode($status);
286 $param .=
"&search_filter=".urlencode($filter);
289 $param .=
"&search_filtert=".urlencode($filtert);
291 if ($usergroup > 0) {
292 $param .=
"&search_usergroup=".urlencode($usergroup);
295 $param .=
"&search_socid=".urlencode($socid);
298 $param .=
"&search_showbirthday=1";
301 $param .=
"&search_projectid=".urlencode($pid);
304 $param .=
"&search_type=".urlencode($type);
306 if ($mode ==
'show_day' || $mode ==
'show_week' || $mode ==
'show_month' || $mode !=
'show_peruser') {
307 $param .=
'&mode='.urlencode($mode);
309 if ($begin_h !=
'') {
310 $param .=
'&begin_h='.urlencode($begin_h);
313 $param .=
'&end_h='.urlencode($end_h);
315 if ($begin_d !=
'') {
316 $param .=
'&begin_d='.urlencode($begin_d);
319 $param .=
'&end_d='.urlencode($end_d);
321 $param .=
"&maxprint=".urlencode($maxprint);
323 $paramnoactionodate = $param;
326 $prev_year = $year - 1;
327 $prev_month = $month;
333 $week = $prev[
'week'];
337 $next_year = $year + 1;
338 $next_month = $month;
342 $firstdaytoshow =
dol_mktime(0, 0, 0, $first_month, $first_day, $first_year,
'tzuserrel');
348 $max_day_in_month = date(
"t",
dol_mktime(0, 0, 0, $month, 1, $year,
'gmt'));
350 $tmpday = $first_day;
351 $picto =
'calendarweek';
353 $nav =
"<a href=\"?year=".$prev_year.
"&month=".$prev_month.
"&day=".$prev_day.$param.
"\">".
img_previous($langs->trans(
"Previous")).
"</a>\n";
354 $nav .=
" <span id=\"month_name\">".dol_print_date(
dol_mktime(0, 0, 0, $first_month, $first_day, $first_year),
"%Y").
"</span> \n";
355 $nav .=
"<a href=\"?year=".$next_year.
"&month=".$next_month.
"&day=".$next_day.$param.
"\">".
img_next($langs->trans(
"Next")).
"</a>\n";
356 if (empty($conf->dol_optimize_smallscreen)) {
357 $nav .=
" (<a href=\"?year=".$nowyear.
"&month=".$nowmonth.
"&day=".$nowday.$param.
"\">".$langs->trans(
"Today").
"</a>)";
360 $nav .=
$form->selectDate($dateselect,
'dateselect', 0, 0, 1,
'', 1, 0);
361 $nav .=
' <button type="submit" class="liste_titre button_search" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
364 $param .=
'&year='.urlencode($year).
'&month='.urlencode($month).($day ?
'&day='.urlencode($day) :
'');
368 $paramnoaction = preg_replace(
'/action=[a-z_]+/',
'', $param);
372 print
'<form method="POST" id="searchFormList" class="listactionsfilter" action="'.$_SERVER[
"PHP_SELF"].
'">'.
"\n";
374 $showextcals = $listofextcals;
376 if ($conf->use_javascript_ajax) {
378 $s .=
'<script type="text/javascript">'.
"\n";
379 $s .=
'jQuery(document).ready(function () {'.
"\n";
380 $s .=
'jQuery("#check_mytasks").click(function() { jQuery(".family_mytasks").toggle(); jQuery(".family_other").toggle(); });'.
"\n";
381 $s .=
'jQuery("#check_birthday").click(function() { jQuery(".family_birthday").toggle(); });'.
"\n";
382 $s .=
'jQuery(".family_birthday").toggle();'.
"\n";
383 if ($mode ==
"show_week" || $mode ==
"show_month" || empty($mode)) {
384 $s .=
'jQuery( "td.sortable" ).sortable({connectWith: ".sortable",placeholder: "ui-state-highlight",items: "div:not(.unsortable)", receive: function( event, ui ) {';
387 $s .=
'</script>'.
"\n";
388 if (!empty($conf->use_javascript_ajax)) {
389 $s .=
'<div class="nowrap clear float"><input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> '.$langs->trans(
"LocalAgenda").
' </div>';
390 if (is_array($showextcals) && count($showextcals) > 0) {
391 foreach ($showextcals as $val) {
392 $htmlname = md5($val[
'name']);
393 $s .=
'<script type="text/javascript">'.
"\n";
394 $s .=
'jQuery(document).ready(function () {'.
"\n";
395 $s .=
' jQuery("#check_ext'.$htmlname.
'").click(function() {';
396 $s .=
' /* alert("'.$htmlname.
'"); */';
397 $s .=
' jQuery(".family_ext'.$htmlname.
'").toggle();';
400 $s .=
'</script>'.
"\n";
401 $s .=
'<div class="nowrap float"><input type="checkbox" id="check_ext'.$htmlname.
'" name="check_ext'.$htmlname.
'" checked> '.$val [
'name'].
' </div>';
408 $parameters = array();
409 $reshook = $hookmanager->executeHooks(
'addCalendarChoice', $parameters, $object, $action);
410 if (empty($reshook)) {
411 $s .= $hookmanager->resPrint;
412 } elseif ($reshook > 1) {
413 $s = $hookmanager->resPrint;
418 $massactionbutton =
'';
421 $viewmode .=
'<a class="btnTitle reposition" href="'.DOL_URL_ROOT.
'/comm/action/list.php?mode=show_list&restore_lastsearch_values=1'.$paramnoactionodate.
'">';
423 $viewmode .=
img_picto($langs->trans(
"List"),
'object_calendarlist',
'class="imgforviewmode pictoactionview block"');
425 $viewmode .=
'<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans(
"ViewList").
'</span></a>';
427 $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.
'">';
429 $viewmode .=
img_picto($langs->trans(
"ViewCal"),
'object_calendarmonth',
'class="pictoactionview block"');
431 $viewmode .=
'<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans(
"ViewCal").
'</span></a>';
433 $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.
'">';
435 $viewmode .=
img_picto($langs->trans(
"ViewWeek"),
'object_calendarweek',
'class="pictoactionview block"');
437 $viewmode .=
'<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans(
"ViewWeek").
'</span></a>';
439 $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.
'">';
441 $viewmode .=
img_picto($langs->trans(
"ViewDay"),
'object_calendarday',
'class="pictoactionview block"');
443 $viewmode .=
'<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans(
"ViewDay").
'</span></a>';
445 $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.
'">';
447 $viewmode .=
img_picto($langs->trans(
"ViewPerUser"),
'object_calendarperuser',
'class="pictoactionview block"');
449 $viewmode .=
'<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans(
"ViewPerUser").
'</span></a>';
451 $viewmode .=
'<span class="marginrightonly"></span>';
454 $parameters = array(); $object =
null;
455 $reshook = $hookmanager->executeHooks(
'addCalendarView', $parameters, $object, $action);
456 if (empty($reshook)) {
457 $viewmode .= $hookmanager->resPrint;
458 } elseif ($reshook > 1) {
459 $viewmode = $hookmanager->resPrint;
464 if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
467 $newparam .=
'&month='.str_pad($month, 2,
"0", STR_PAD_LEFT).
'&year='.$tmpforcreatebutton[
'year'];
470 $hourminsec =
'100000';
471 $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 :
'')));
474 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);
481 $newtitle =
'<div class="nowrap clear inline-block minheight30">';
482 $newtitle .=
'<input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> '.$langs->trans(
"LocalAgenda").
' ';
483 $newtitle .=
'</div>';
490 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
491 print_actions_filter(
$form, $canedit, $search_status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup,
'', $resourceid);
496 $eventarray = array();
501 if ($usergroup > 0) {
504 $sql .=
' a.id, a.label,';
506 $sql .=
' a.datep2,';
507 $sql .=
' a.percent,';
508 $sql .=
' a.fk_user_author,a.fk_user_action,';
509 $sql .=
' a.transparency, a.priority, a.fulldayevent, a.location,';
510 $sql .=
' a.fk_soc, a.fk_contact, a.fk_element, a.elementtype, a.fk_project,';
511 $sql .=
' ca.code, ca.libelle as type_label, ca.color, ca.type as type_type, ca.picto as type_picto';
512 $sql .=
' FROM '.MAIN_DB_PREFIX.
'c_actioncomm as ca, '.MAIN_DB_PREFIX.
"actioncomm as a";
513 if (empty($user->rights->societe->client->voir) && !$socid) {
514 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
517 if ($resourceid > 0) {
518 $sql .=
", ".MAIN_DB_PREFIX.
"element_resources as r";
521 if ($filtert > 0 || $usergroup > 0) {
522 $sql .=
", ".MAIN_DB_PREFIX.
"actioncomm_resources as ar";
524 if ($usergroup > 0) {
525 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
527 $sql .=
' WHERE a.fk_action = ca.id';
528 $sql .=
' AND a.entity IN ('.getEntity(
'agenda').
')';
530 if (!empty($actioncode)) {
531 if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
532 if ($actioncode ==
'AC_NON_AUTO') {
533 $sql .=
" AND ca.type != 'systemauto'";
534 } elseif ($actioncode ==
'AC_ALL_AUTO') {
535 $sql .=
" AND ca.type = 'systemauto'";
537 if ($actioncode ==
'AC_OTH') {
538 $sql .=
" AND ca.type != 'systemauto'";
540 if ($actioncode ==
'AC_OTH_AUTO') {
541 $sql .=
" AND ca.type = 'systemauto'";
545 if ($actioncode ==
'AC_NON_AUTO') {
546 $sql .=
" AND ca.type != 'systemauto'";
547 } elseif ($actioncode ==
'AC_ALL_AUTO') {
548 $sql .=
" AND ca.type = 'systemauto'";
550 if (is_array($actioncode)) {
551 $sql .=
" AND ca.code IN (".$db->sanitize(
"'".implode(
"','", $actioncode).
"'", 1).
")";
553 $sql .=
" AND ca.code IN (".$db->sanitize(
"'".implode(
"','", explode(
',', $actioncode)).
"'", 1).
")";
558 if ($resourceid > 0) {
559 $sql .=
" AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".((int) $resourceid);
562 $sql .=
" AND a.fk_project=".((int) $pid);
564 if (empty($user->rights->societe->client->voir) && !$socid) {
565 $sql .=
" AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).
")";
568 $sql .=
' AND a.fk_soc = '.((int) $socid);
571 if ($filtert > 0 || $usergroup > 0) {
572 $sql .=
" AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
574 if ($mode ==
'show_day') {
576 $sql .=
" (a.datep BETWEEN '".$db->idate(
dol_mktime(0, 0, 0, $month, $day, $year,
'tzuserrel')).
"'";
577 $sql .=
" AND '".$db->idate(
dol_mktime(23, 59, 59, $month, $day, $year)).
"')";
579 $sql .=
" (a.datep2 BETWEEN '".$db->idate(
dol_mktime(0, 0, 0, $month, $day, $year,
'tzuserrel')).
"'";
580 $sql .=
" AND '".$db->idate(
dol_mktime(23, 59, 59, $month, $day, $year)).
"')";
582 $sql .=
" (a.datep < '".$db->idate(
dol_mktime(0, 0, 0, $month, $day, $year)).
"'";
583 $sql .=
" AND a.datep2 > '".$db->idate(
dol_mktime(23, 59, 59, $month, $day, $year,
'tzuserrel')).
"')";
588 $sql .=
" (a.datep BETWEEN '".$db->idate(
dol_mktime(0, 0, 0, 1, 1, $year) - (60 * 60 * 24 * 7)).
"'";
589 $sql .=
" AND '".$db->idate(
dol_mktime(23, 59, 59, 12, 31, $year) + (60 * 60 * 24 * 7)).
"')";
591 $sql .=
" (a.datep2 BETWEEN '".$db->idate(
dol_mktime(0, 0, 0, 1, 1, $year) - (60 * 60 * 24 * 7)).
"'";
592 $sql .=
" AND '".$db->idate(
dol_mktime(23, 59, 59, 12, 31, $year) + (60 * 60 * 24 * 7)).
"')";
594 $sql .=
" (a.datep < '".$db->idate(
dol_mktime(0, 0, 0, 12, 1, $year) - (60 * 60 * 24 * 7)).
"'";
595 $sql .=
" AND a.datep2 > '".$db->idate(
dol_mktime(23, 59, 59, 12, 31, $year) + (60 * 60 * 24 * 7)).
"')";
599 $sql .=
" AND ca.id = ".((int) $type);
601 if ($status ==
'0') {
602 $sql .=
" AND a.percent = 0";
604 if ($status ==
'-1') {
605 $sql .=
" AND a.percent = -1";
607 if ($status ==
'50') {
608 $sql .=
" AND (a.percent > 0 AND a.percent < 100)";
610 if ($status ==
'done' || $status ==
'100') {
611 $sql .=
" AND (a.percent = 100)";
613 if ($status ==
'todo') {
614 $sql .=
" AND (a.percent >= 0 AND a.percent < 100)";
617 if ($filtert > 0 || $usergroup > 0) {
620 $sql .=
"ar.fk_element = ".$filtert;
622 if ($usergroup > 0) {
623 $sql .= ($filtert > 0 ?
" OR " :
"").
" ugu.fk_usergroup = ".((
int) $usergroup);
628 $sql .=
' ORDER BY fk_user_action, datep';
631 dol_syslog(
"comm/action/pertype.php", LOG_DEBUG);
632 $resql = $db->query($sql);
634 $num = $db->num_rows(
$resql);
637 $obj = $db->fetch_object(
$resql);
640 if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->code ==
'AC_OTH_AUTO') {
645 $datep = $db->jdate($obj->datep);
646 $datep2 = $db->jdate($obj->datep2);
650 $event->id = $obj->id;
651 $event->datep = $datep;
652 $event->datef = $datep2;
653 $event->type_code = $obj->code;
654 $event->type_color = $obj->color;
655 $event->label = $obj->label;
656 $event->percentage = $obj->percent;
657 $event->authorid = $obj->fk_user_author;
658 $event->userownerid = $obj->fk_user_action;
659 $event->priority = $obj->priority;
660 $event->fulldayevent = $obj->fulldayevent;
661 $event->location = $obj->location;
662 $event->transparency = $obj->transparency;
664 $event->fk_project = $obj->fk_project;
666 $event->socid = $obj->fk_soc;
667 $event->contact_id = $obj->fk_contact;
669 $event->fk_element = $obj->fk_element;
670 $event->elementtype = $obj->elementtype;
674 if ($event->percentage <= 0) {
675 $event->date_start_in_calendar = $datep;
676 if ($datep2 !=
'' && $datep2 >= $datep) {
677 $event->date_end_in_calendar = $datep2;
679 $event->date_end_in_calendar = $datep;
682 $event->date_start_in_calendar = $datep;
683 if ($datep2 !=
'' && $datep2 >= $datep) {
684 $event->date_end_in_calendar = $datep2;
686 $event->date_end_in_calendar = $datep;
691 if ($event->date_end_in_calendar < $firstdaytoshow ||
692 $event->date_start_in_calendar >= $lastdaytoshow) {
697 $event->fetch_userassigned();
699 if ($event->date_start_in_calendar < $firstdaytoshow) {
700 $event->date_start_in_calendar = $firstdaytoshow;
702 if ($event->date_end_in_calendar >= $lastdaytoshow) {
703 $event->date_end_in_calendar = ($lastdaytoshow - 1);
707 $daycursor = $event->date_start_in_calendar;
713 $loop =
true; $j = 0;
714 $daykey =
dol_mktime(0, 0, 0, $mois, $jour, $annee,
'gmt');
718 $eventarray[$daykey][] = $event;
721 $daykey += 60 * 60 * 24;
722 if ($daykey > $event->date_end_in_calendar) {
738 $cachethirdparties = array();
739 $cachecontacts = array();
740 $cacheusers = array();
743 $color_file = DOL_DOCUMENT_ROOT.
"/theme/".$conf->theme.
"/theme_vars.inc.php";
744 if (is_readable($color_file)) {
747 if (!is_array($theme_datacolor)) {
748 $theme_datacolor = array(array(120, 130, 150), array(200, 160, 180), array(190, 190, 220));
753 $newparam = preg_replace(
'/showbirthday=/i',
'showbirthday_=', $newparam);
754 $newparam = preg_replace(
'/mode=show_month&?/i',
'', $newparam);
755 $newparam = preg_replace(
'/mode=show_week&?/i',
'', $newparam);
756 $newparam = preg_replace(
'/day=[0-9]+&?/i',
'', $newparam);
757 $newparam = preg_replace(
'/month=[0-9]+&?/i',
'', $newparam);
758 $newparam = preg_replace(
'/year=[0-9]+&?/i',
'', $newparam);
759 $newparam = preg_replace(
'/viewweek=[0-9]+&?/i',
'', $newparam);
760 $newparam = preg_replace(
'/showbirthday_=/i',
'showbirthday=', $newparam);
761 $newparam .=
'&viewweek=1';
763 print
'<input type="hidden" name="action" value="mupdate">';
764 echo
'<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER[
'PHP_SELF']).
'?'.
dol_escape_htmltag($_SERVER[
'QUERY_STRING']).
'">';
765 echo
'<input type="hidden" name="token" value="'.newToken().
'">';
766 echo
'<input type="hidden" name="newdate" id="newdate">';
774 echo
'<table width="100%" class="nocellnopadd cal_month">';
776 echo
'<tr class="liste_titre">';
779 echo
'<td align="center" colspan="'.($end_d - $begin_d).
'">';
780 echo $langs->trans(
"Year");
786 echo
'<tr class="liste_titre">';
789 for ($h = $begin_d; $h < $end_d; $h++) {
790 echo
'<td class="center">';
791 print
'<small style="font-family: courier">'.sprintf(
"%02d", $h).
'</small>';
798 $typeofevents = array();
801 $colorsbytype = array();
802 $labelbytype = array();
803 $sql =
"SELECT code, color, libelle as label FROM ".MAIN_DB_PREFIX.
"c_actioncomm ORDER BY position";
804 $resql = $db->query($sql);
805 while ($obj = $db->fetch_object(
$resql)) {
806 $typeofevents[$obj->code] = $obj->code;
807 $colorsbytype[$obj->code] = $obj->color;
808 $labelbytype[$obj->code] = $obj->label;
816 foreach ($typeofevents as $typeofevent) {
819 echo
'<td class="cal_current_month cal_peruserviewname'.($var ?
' cal_impair' :
'').
'">'.$typeofevent.
'</td>';
824 for ($iter_day = 0; $iter_day < 8; $iter_day++) {
825 if (($i + 1) < $begin_d || ($i + 1) > $end_d) {
833 $tmpday = $tmparray[
'mday'];
834 $tmpmonth = $tmparray[
'mon'];
835 $tmpyear = $tmparray[
'year'];
837 $style =
'cal_current_month';
838 if ($iter_day == 6) {
839 $style .=
' cal_other_month';
842 if ($todayarray[
'mday'] == $tmpday && $todayarray[
'mon'] == $tmpmonth && $todayarray[
'year'] == $tmpyear) {
846 $style =
'cal_today_peruser';
849 show_day_events_pertype($typeofevent, $tmpday, $tmpmonth, $tmpyear, 0, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, $showheader, $colorsbytype, $var);
860 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
861 $langs->load(
"commercial");
862 print
'<br>'.$langs->trans(
"Legend").
': <br>';
863 foreach ($colorsbytype as $code => $color) {
865 print
'<div style="float: left; padding: 2px; margin-right: 6px;"><div style="'.($color ?
'background: #'.$color.
';' :
'').
'width:16px; float: left; margin-right: 4px;"> </div>';
866 print $langs->trans(
"Action".$code) !=
"Action".$code ? $langs->trans(
"Action".$code) : $labelbytype[$code];
872 print
'<div style="float: left; padding: 2px; margin-right: 6px;"><div class="peruser_busy" style="width:16px; float: left; margin-right: 4px;"> </div>';
873 print $langs->trans(
"Other");
882 print
"\n".
'</form>';
886 print
'<script type="text/javascript">
887 jQuery(document).ready(function() {
888 jQuery(".onclickopenref").click(function() {
889 var ref=$(this).attr(\'ref\');
890 var res = ref.split("_");
898 if (ids == \'none\') /* No event */
900 /* alert(\'no event\'); */
901 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).
'"
902 window.location.href = url;
904 else if (ids.indexOf(",") > -1) /* There is several events */
906 /* alert(\'several events\'); */
907 url = "'.DOL_URL_ROOT.
'/comm/action/list.php?mode=show_list&filtert="+userid+"&dateselectyear="+year+"&dateselectmonth="+month+"&dateselectday="+day;
908 window.location.href = url;
912 /* alert(\'one event\'); */
913 url = "'.DOL_URL_ROOT.
'/comm/action/card.php?action=view&id="+ids
914 window.location.href = url;
947 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)
950 global $user, $conf, $langs, $hookmanager, $action;
951 global $filter, $filtert, $status, $actioncode;
952 global $theme_datacolor;
953 global $cachethirdparties, $cachecontacts, $cacheusers, $cacheprojects, $colorindexused;
954 global $begin_h, $end_h;
959 $i = 0; $nummytasks = 0; $numother = 0; $numbirthday = 0; $numical = 0; $numicals = array();
960 $ymd = sprintf(
"%04d", $year).sprintf(
"%02d", $month).sprintf(
"%02d", $day);
962 $nextindextouse = count($colorindexused);
968 foreach ($eventarray as $daykey => $notused) {
973 if ($day == $jour && $month == $mois && $year == $annee) {
975 foreach ($eventarray[$daykey] as $index => $event) {
979 $keysofuserassigned = array_keys($event->userassigned);
980 if (!in_array($username->id, $keysofuserassigned)) {
985 $parameters = array();
986 $reshook = $hookmanager->executeHooks(
'formatEvent', $parameters, $event, $action);
991 $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
994 $color = -1; $cssclass =
''; $colorindex = -1;
995 if (in_array($user->id, $keysofuserassigned)) {
996 $nummytasks++; $cssclass =
'family_mytasks';
997 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
998 $color = $event->type_color;
1000 } elseif ($event->type_code ==
'ICALEVENT') {
1002 if (!empty($event->icalname)) {
1009 $color = $event->icalcolor;
1010 $cssclass = (!empty($event->icalname) ?
'family_ext'.md5($event->icalname) :
'family_other unsortable');
1011 } elseif ($event->type_code ==
'BIRTHDAY') {
1012 $numbirthday++; $colorindex = 2; $cssclass =
'family_birthday unsortable'; $color = sprintf(
"%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1014 $numother++; $cssclass =
'family_other';
1015 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1016 $color = $event->type_color;
1022 $idusertouse = ($event->userownerid ? $event->userownerid : 0);
1023 if (isset($colorindexused[$idusertouse])) {
1024 $colorindex = $colorindexused[$idusertouse];
1026 $colorindex = $nextindextouse;
1027 $colorindexused[$idusertouse] = $colorindex;
1028 if (!empty($theme_datacolor[$nextindextouse + 1])) {
1033 $color = sprintf(
"%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1038 for ($h = $begin_h; $h < $end_h; $h++) {
1041 if (empty($event->fulldayevent)) {
1042 $a =
dol_mktime((
int) $h, 0, 0, $month, $day, $year,
'tzuserrel', 0);
1043 $b =
dol_mktime((
int) $h, 30, 0, $month, $day, $year,
'tzuserrel', 0);
1044 $c =
dol_mktime((
int) $h + 1, 0, 0, $month, $day, $year,
'tzuserrel', 0);
1046 $dateendtouse = $event->date_end_in_calendar;
1047 if ($dateendtouse == $event->date_start_in_calendar) {
1053 if ($event->date_start_in_calendar < $b && $dateendtouse > $a) {
1054 $busy = $event->transparency;
1055 $cases1[$h][$event->id][
'busy'] = $busy;
1056 $cases1[$h][$event->id][
'string'] =
dol_print_date($event->date_start_in_calendar,
'dayhour',
'tzuserrel');
1057 if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
1058 $tmpa =
dol_getdate($event->date_start_in_calendar,
true);
1059 $tmpb =
dol_getdate($event->date_end_in_calendar,
true);
1060 if ($tmpa[
'mday'] == $tmpb[
'mday'] && $tmpa[
'mon'] == $tmpb[
'mon'] && $tmpa[
'year'] == $tmpb[
'year']) {
1061 $cases1[$h][$event->id][
'string'] .=
'-'.dol_print_date($event->date_end_in_calendar,
'hour',
'tzuserrel');
1063 $cases1[$h][$event->id][
'string'] .=
'-'.dol_print_date($event->date_end_in_calendar,
'dayhour',
'tzuserrel');
1066 if ($event->label) {
1067 $cases1[$h][$event->id][
'string'] .=
' - '.$event->label;
1069 $cases1[$h][$event->id][
'typecode'] = $event->type_code;
1070 $cases1[$h][$event->id][
'color'] = $color;
1071 if ($event->fk_project > 0) {
1072 if (empty($cacheprojects[$event->fk_project])) {
1074 $tmpproj->fetch($event->fk_project);
1075 $cacheprojects[$event->fk_project] = $tmpproj;
1077 $cases1[$h][$event->id][
'string'] .=
', '.$langs->trans(
"Project").
': '.$cacheprojects[$event->fk_project]->ref.
' - '.$cacheprojects[$event->fk_project]->title;
1079 if ($event->socid > 0) {
1080 if (empty($cachethirdparties[$event->socid])) {
1081 $tmpthirdparty =
new Societe($db);
1082 $tmpthirdparty->fetch($event->socid);
1083 $cachethirdparties[$event->socid] = $tmpthirdparty;
1085 $cases1[$h][$event->id][
'string'] .=
', '.$cachethirdparties[$event->socid]->name;
1087 if ($event->contact_id > 0) {
1088 if (empty($cachecontacts[$event->contact_id])) {
1089 $tmpcontact =
new Contact($db);
1090 $tmpcontact->fetch($event->contact_id);
1091 $cachecontacts[$event->contact_id] = $tmpcontact;
1093 $cases1[$h][$event->id][
'string'] .=
', '.$cachecontacts[$event->contact_id]->getFullName($langs);
1096 if ($event->date_start_in_calendar < $c && $dateendtouse > $b) {
1097 $busy = $event->transparency;
1098 $cases2[$h][$event->id][
'busy'] = $busy;
1099 $cases2[$h][$event->id][
'string'] =
dol_print_date($event->date_start_in_calendar,
'dayhour',
'tzuserrel');
1100 if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
1101 $tmpa =
dol_getdate($event->date_start_in_calendar,
true);
1102 $tmpb =
dol_getdate($event->date_end_in_calendar,
true);
1103 if ($tmpa[
'mday'] == $tmpb[
'mday'] && $tmpa[
'mon'] == $tmpb[
'mon'] && $tmpa[
'year'] == $tmpb[
'year']) {
1104 $cases2[$h][$event->id][
'string'] .=
'-'.dol_print_date($event->date_end_in_calendar,
'hour',
'tzuserrel');
1106 $cases2[$h][$event->id][
'string'] .=
'-'.dol_print_date($event->date_end_in_calendar,
'dayhour',
'tzuserrel');
1109 if ($event->label) {
1110 $cases2[$h][$event->id][
'string'] .=
' - '.$event->label;
1112 $cases2[$h][$event->id][
'typecode'] = $event->type_code;
1113 $cases2[$h][$event->id][
'color'] = $color;
1114 if ($event->fk_project > 0) {
1115 if (empty($cacheprojects[$event->fk_project])) {
1117 $tmpproj->fetch($event->fk_project);
1118 $cacheprojects[$event->fk_project] = $tmpproj;
1120 $cases2[$h][$event->id][
'string'] .=
', '.$langs->trans(
"Project").
': '.$cacheprojects[$event->fk_project]->ref.
' - '.$cacheprojects[$event->fk_project]->title;
1122 if ($event->socid > 0) {
1123 if (empty($cachethirdparties[$event->socid])) {
1124 $tmpthirdparty =
new Societe($db);
1125 $tmpthirdparty->fetch($event->socid);
1126 $cachethirdparties[$event->socid] = $tmpthirdparty;
1128 $cases2[$h][$event->id][
'string'] .=
', '.$cachethirdparties[$event->socid]->name;
1130 if ($event->contact_id > 0) {
1131 if (empty($cachecontacts[$event->contact_id])) {
1132 $tmpcontact =
new Contact($db);
1133 $tmpcontact->fetch($event->contact_id);
1134 $cachecontacts[$event->contact_id] = $tmpcontact;
1136 $cases2[$h][$event->id][
'string'] .=
', '.$cachecontacts[$event->contact_id]->getFullName($langs);
1140 $busy = $event->transparency;
1141 $cases1[$h][$event->id][
'busy'] = $busy;
1142 $cases2[$h][$event->id][
'busy'] = $busy;
1143 $cases1[$h][$event->id][
'string'] = $event->label;
1144 $cases2[$h][$event->id][
'string'] = $event->label;
1145 $cases1[$h][$event->id][
'typecode'] = $event->type_code;
1146 $cases2[$h][$event->id][
'typecode'] = $event->type_code;
1147 $cases1[$h][$event->id][
'color'] = $color;
1148 $cases2[$h][$event->id][
'color'] = $color;
1159 for ($h = $begin_h; $h < $end_h; $h++) {
1160 $color1 =
''; $color2 =
'';
1161 $style1 =
''; $style2 =
'';
1162 $string1 =
' '; $string2 =
' ';
1163 $title1 =
''; $title2 =
'';
1164 if (isset($cases1[$h]) && $cases1[$h] !=
'') {
1166 if (count($cases1[$h]) > 1) {
1167 $title1 .= count($cases1[$h]).
' '.(count($cases1[$h]) == 1 ? $langs->trans(
"Event") : $langs->trans(
"Events"));
1169 $string1 =
' ';
1170 if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
1171 $style1 =
'peruser_notbusy';
1173 $style1 =
'peruser_busy';
1175 foreach ($cases1[$h] as $id => $ev) {
1177 $style1 =
'peruser_busy';
1181 if (isset($cases2[$h]) && $cases2[$h] !=
'') {
1183 if (count($cases2[$h]) > 1) {
1184 $title2 .= count($cases2[$h]).
' '.(count($cases2[$h]) == 1 ? $langs->trans(
"Event") : $langs->trans(
"Events"));
1186 $string2 =
' ';
1187 if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
1188 $style2 =
'peruser_notbusy';
1190 $style2 =
'peruser_busy';
1192 foreach ($cases2[$h] as $id => $ev) {
1194 $style2 =
'peruser_busy';
1199 $ids1 =
''; $ids2 =
'';
1200 if (count($cases1[$h]) && array_keys($cases1[$h])) {
1201 $ids1 = join(
',', array_keys($cases1[$h]));
1203 if (count($cases2[$h]) && array_keys($cases2[$h])) {
1204 $ids2 = join(
',', array_keys($cases2[$h]));
1207 if ($h == $begin_h) {
1208 echo
'<td class="'.$style.
'_peruserleft cal_peruser'.($var ?
' cal_impair '.$style.
'_impair' :
'').
'">';
1210 echo
'<td class="'.$style.
' cal_peruser'.($var ?
' cal_impair '.$style.
'_impair' :
'').
'">';
1212 if (count($cases1[$h]) == 1) {
1213 $output = array_slice($cases1[$h], 0, 1);
1214 $title1 = $langs->trans(
"Ref").
' '.$ids1.($title1 ?
' - '.$title1 :
'');
1215 if ($output[0][
'string']) {
1216 $title1 .= ($title1 ?
' - ' :
'').$output[0][
'string'];
1218 if ($output[0][
'color']) {
1219 $color1 = $output[0][
'color'];
1221 } elseif (count($cases1[$h]) > 1) {
1222 $title1 = $langs->trans(
"Ref").
' '.$ids1.($title1 ?
' - '.$title1 :
'');
1226 if (count($cases2[$h]) == 1) {
1227 $output = array_slice($cases2[$h], 0, 1);
1228 $title2 = $langs->trans(
"Ref").
' '.$ids2.($title2 ?
' - '.$title2 :
'');
1229 if ($output[0][
'string']) {
1230 $title2 .= ($title2 ?
' - ' :
'').$output[0][
'string'];
1232 if ($output[0][
'color']) {
1233 $color2 = $output[0][
'color'];
1235 } elseif (count($cases2[$h]) > 1) {
1236 $title2 = $langs->trans(
"Ref").
' '.$ids2.($title2 ?
' - '.$title2 :
'');
1239 print
'<table class="nobordernopadding" width="100%">';
1240 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.
'"' :
'').
'>';
1242 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.
'"' :
'').
'>';