2004-10-19 22:19:58 +02:00
< ? php
2004-02-09 09:57:34 +01:00
/* Copyright ( C ) 2001 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2008-07-17 18:48:24 +02:00
* Copyright ( C ) 2003 Eric Seigne < erics @ rycks . com >
2018-04-22 17:57:20 +02:00
* Copyright ( C ) 2004 - 2018 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 15:11:07 +01:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2011-03-08 20:39:21 +01:00
* Copyright ( C ) 2011 Juanjo Menent < jmenent @ 2 byte . es >
2014-08-08 14:25:14 +02:00
* Copyright ( C ) 2014 Cedric GROSS < c . gross @ kreiz - it . fr >
2015-03-05 10:20:32 +01:00
* Copyright ( C ) 2015 Marcos García < marcosgdf @ gmail . com >
2017-05-17 17:00:45 +02:00
* Copyright ( C ) 2017 Open - DSI < support @ open - dsi . fr >
2003-08-03 14:13:38 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2003-08-03 14:13:38 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2011-08-01 00:21:57 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2003-08-03 14:13:38 +02:00
*/
2004-10-30 03:54:14 +02:00
2013-06-14 22:33:01 +02:00
2005-04-14 01:28:41 +02:00
/**
2011-06-11 00:05:07 +02:00
* \file htdocs / comm / action / index . php
* \ingroup agenda
* \brief Home page of calendar events
2008-08-30 00:40:36 +02:00
*/
2008-02-26 19:34:53 +01:00
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/agenda.lib.php' ;
2013-06-14 22:33:01 +02:00
if ( ! empty ( $conf -> projet -> enabled )) {
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php' ;
}
2003-08-03 14:13:38 +02:00
2012-01-22 20:16:11 +01:00
if ( ! isset ( $conf -> global -> AGENDA_MAX_EVENTS_DAY_VIEW )) $conf -> global -> AGENDA_MAX_EVENTS_DAY_VIEW = 3 ;
2015-03-02 17:34:50 +01:00
if ( empty ( $conf -> global -> AGENDA_EXT_NB )) $conf -> global -> AGENDA_EXT_NB = 5 ;
$MAXAGENDA = $conf -> global -> AGENDA_EXT_NB ;
2018-04-21 12:16:12 +02:00
$filter = GETPOST ( " filter " , 'alpha' , 3 );
2017-05-05 18:42:11 +02:00
$filtert = GETPOST ( " filtert " , " int " , 3 );
2014-06-28 20:49:10 +02:00
$usergroup = GETPOST ( " usergroup " , " int " , 3 );
2012-01-22 20:16:11 +01:00
$showbirthday = empty ( $conf -> use_javascript_ajax ) ? GETPOST ( " showbirthday " , " int " ) : 1 ;
2016-05-30 18:12:27 +02:00
// If not choice done on calendar owner (like on left menu link "Agenda"), we filter on user.
2014-10-09 17:27:14 +02:00
if ( empty ( $filtert ) && empty ( $conf -> global -> AGENDA_ALL_CALENDARS ))
2014-10-09 17:05:57 +02:00
{
$filtert = $user -> id ;
}
2008-03-20 20:07:21 +01:00
2012-10-13 14:47:46 +02:00
$sortfield = GETPOST ( " sortfield " , 'alpha' );
$sortorder = GETPOST ( " sortorder " , 'alpha' );
2010-11-10 22:41:34 +01:00
$page = GETPOST ( " page " , " int " );
2017-06-06 10:53:53 +02:00
if ( empty ( $page ) || $page == - 1 ) { $page = 0 ; } // If $page is not defined, or '' or -1
2018-04-21 12:16:12 +02:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2012-01-22 02:12:11 +01:00
$offset = $limit * $page ;
2008-04-08 00:11:22 +02:00
if ( ! $sortorder ) $sortorder = " ASC " ;
if ( ! $sortfield ) $sortfield = " a.datec " ;
2008-03-20 20:07:21 +01:00
// Security check
2014-06-29 02:45:55 +02:00
$socid = GETPOST ( " socid " , " int " );
2008-03-20 20:07:21 +01:00
if ( $user -> societe_id ) $socid = $user -> societe_id ;
2010-06-09 20:25:20 +02:00
$result = restrictedArea ( $user , 'agenda' , 0 , '' , 'myactions' );
2014-06-29 02:45:55 +02:00
if ( $socid < 0 ) $socid = '' ;
2008-03-20 20:07:21 +01:00
$canedit = 1 ;
2008-03-31 06:55:56 +02:00
if ( ! $user -> rights -> agenda -> myactions -> read ) accessforbidden ();
2008-03-20 20:07:21 +01:00
if ( ! $user -> rights -> agenda -> allactions -> read ) $canedit = 0 ;
2011-06-11 00:05:07 +02:00
if ( ! $user -> rights -> agenda -> allactions -> read || $filter == 'mine' ) // If no permission to see all, we show only affected to me
2008-02-26 19:34:53 +01:00
{
2011-06-11 00:05:07 +02:00
$filtert = $user -> id ;
2008-02-26 19:34:53 +01:00
}
2004-10-31 18:13:24 +01:00
2010-11-20 14:08:44 +01:00
$action = GETPOST ( 'action' , 'alpha' );
2016-06-06 13:05:36 +02:00
$resourceid = GETPOST ( " resourceid " , " int " );
2010-11-10 21:16:31 +01:00
$year = GETPOST ( " year " , " int " ) ? GETPOST ( " year " , " int " ) : date ( " Y " );
$month = GETPOST ( " month " , " int " ) ? GETPOST ( " month " , " int " ) : date ( " m " );
2011-03-09 02:35:25 +01:00
$week = GETPOST ( " week " , " int " ) ? GETPOST ( " week " , " int " ) : date ( " W " );
2010-11-10 21:16:31 +01:00
$day = GETPOST ( " day " , " int " ) ? GETPOST ( " day " , " int " ) : 0 ;
2012-02-13 09:51:09 +01:00
$pid = GETPOST ( " projectid " , " int " , 3 );
2018-04-22 17:57:20 +02:00
$status = GETPOST ( " status " , 'aZ09' ); // status may be 0, 50, 100, 'todo'
$type = GETPOST ( " type " , 'az09' );
2012-01-22 20:16:11 +01:00
$maxprint = ( isset ( $_GET [ " maxprint " ]) ? GETPOST ( " maxprint " ) : $conf -> global -> AGENDA_MAX_EVENTS_DAY_VIEW );
2016-01-14 14:15:14 +01:00
// Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
if ( GETPOST ( 'actioncode' , 'array' ))
{
$actioncode = GETPOST ( 'actioncode' , 'array' , 3 );
if ( ! count ( $actioncode )) $actioncode = '0' ;
}
else
{
$actioncode = GETPOST ( " actioncode " , " alpha " , 3 ) ? GETPOST ( " actioncode " , " alpha " , 3 ) : ( GETPOST ( " actioncode " ) == '0' ? '0' : ( empty ( $conf -> global -> AGENDA_DEFAULT_FILTER_TYPE ) ? '' : $conf -> global -> AGENDA_DEFAULT_FILTER_TYPE ));
}
if ( $actioncode == '' && empty ( $actioncodearray )) $actioncode = ( empty ( $conf -> global -> AGENDA_DEFAULT_FILTER_TYPE ) ? '' : $conf -> global -> AGENDA_DEFAULT_FILTER_TYPE );
2014-06-29 23:35:00 +02:00
2014-07-19 22:37:18 +02:00
if ( $status == '' && ! isset ( $_GET [ 'status' ]) && ! isset ( $_POST [ 'status' ])) $status = ( empty ( $conf -> global -> AGENDA_DEFAULT_FILTER_STATUS ) ? '' : $conf -> global -> AGENDA_DEFAULT_FILTER_STATUS );
if ( empty ( $action ) && ! isset ( $_GET [ 'action' ]) && ! isset ( $_POST [ 'action' ])) $action = ( empty ( $conf -> global -> AGENDA_DEFAULT_VIEW ) ? 'show_month' : $conf -> global -> AGENDA_DEFAULT_VIEW );
2018-04-22 17:57:20 +02:00
if ( $action == 'default' )
{
$action = (( ! empty ( $conf -> global -> AGENDA_DEFAULT_VIEW ) && $conf -> global -> AGENDA_DEFAULT_VIEW != 'show_list' ) ? $conf -> global -> AGENDA_DEFAULT_VIEW : 'show_month' );
}
2013-09-25 21:26:06 +02:00
if ( GETPOST ( 'viewcal' ) && $action != 'show_day' && $action != 'show_week' ) {
2012-01-22 02:12:11 +01:00
$action = 'show_month' ; $day = '' ;
} // View by month
2014-06-27 20:50:46 +02:00
if ( GETPOST ( 'viewweek' ) || $action == 'show_week' ) {
2012-01-22 02:12:11 +01:00
$action = 'show_week' ; $week = ( $week ? $week : date ( " W " )); $day = ( $day ? $day : date ( " d " ));
} // View by week
2014-06-27 20:50:46 +02:00
if ( GETPOST ( 'viewday' ) || $action == 'show_day' ) {
2012-01-22 02:12:11 +01:00
$action = 'show_day' ; $day = ( $day ? $day : date ( " d " ));
} // View by day
2011-02-02 16:51:18 +01:00
2018-05-26 19:03:41 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'agenda' , 'other' , 'commercial' ));
2008-09-28 05:39:39 +02:00
2017-06-10 12:56:28 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2014-06-29 02:45:55 +02:00
$hookmanager -> initHooks ( array ( 'agenda' ));
2008-11-11 20:32:48 +01:00
2004-10-31 18:13:24 +01:00
/*
2008-02-26 19:34:53 +01:00
* Actions
2004-10-31 18:13:24 +01:00
*/
2014-06-29 23:35:00 +02:00
2018-04-20 13:23:34 +02:00
if ( GETPOST ( " viewlist " , 'alpha' ) || $action == 'show_list' )
2008-03-20 21:39:50 +01:00
{
2011-06-11 00:05:07 +02:00
$param = '' ;
2017-07-09 20:31:27 +02:00
if ( is_array ( $_POST ))
2011-06-11 00:05:07 +02:00
{
2017-07-09 20:31:27 +02:00
foreach ( $_POST as $key => $val )
{
if ( $key == 'token' ) continue ;
$param .= '&' . $key . '=' . urlencode ( $val );
}
2011-06-11 00:05:07 +02:00
}
//print $param;
2017-11-16 12:18:25 +01:00
header ( " Location: " . DOL_URL_ROOT . '/comm/action/list.php?' . $param );
2011-06-11 00:05:07 +02:00
exit ;
2008-03-20 21:39:50 +01:00
}
2005-04-14 01:28:41 +02:00
2018-04-20 13:23:34 +02:00
if ( GETPOST ( " viewperuser " , 'alpha' ) || $action == 'show_peruser' )
2014-06-29 23:35:00 +02:00
{
$param = '' ;
2017-07-09 20:31:27 +02:00
if ( is_array ( $_POST ))
2014-06-29 23:35:00 +02:00
{
2017-07-09 20:31:27 +02:00
foreach ( $_POST as $key => $val )
{
if ( $key == 'token' ) continue ;
$param .= '&' . $key . '=' . urlencode ( $val );
}
2014-06-29 23:35:00 +02:00
}
//print $param;
header ( " Location: " . DOL_URL_ROOT . '/comm/action/peruser.php?' . $param );
exit ;
}
2014-07-19 22:37:18 +02:00
if ( $action == 'delete_action' )
2005-04-14 01:28:41 +02:00
{
2011-06-11 00:05:07 +02:00
$event = new ActionComm ( $db );
$event -> fetch ( $actionid );
$result = $event -> delete ();
2005-04-14 01:28:41 +02:00
}
2003-08-29 21:16:15 +02:00
2003-08-03 14:13:38 +02:00
2008-02-26 19:34:53 +01:00
/*
2008-10-06 23:36:45 +02:00
* View
2008-02-26 19:34:53 +01:00
*/
2012-06-15 15:54:56 +02:00
$help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda' ;
2009-08-24 19:11:30 +02:00
llxHeader ( '' , $langs -> trans ( " Agenda " ), $help_url );
2008-02-26 19:34:53 +01:00
2008-03-20 20:07:21 +01:00
$form = new Form ( $db );
2010-11-19 23:36:49 +01:00
$companystatic = new Societe ( $db );
$contactstatic = new Contact ( $db );
2008-03-20 20:07:21 +01:00
2012-02-06 05:31:19 +01:00
$now = dol_now ();
2014-06-27 20:50:46 +02:00
$nowarray = dol_getdate ( $now );
$nowyear = $nowarray [ 'year' ];
$nowmonth = $nowarray [ 'mon' ];
$nowday = $nowarray [ 'mday' ];
2008-03-02 19:47:42 +01:00
2012-01-22 20:16:11 +01:00
$listofextcals = array ();
2014-08-15 17:08:05 +02:00
// Define list of external calendars (global admin setup)
2014-09-05 13:48:55 +02:00
if ( empty ( $conf -> global -> AGENDA_DISABLE_EXT ))
2012-01-22 20:16:11 +01:00
{
$i = 0 ;
2015-03-02 17:34:50 +01:00
while ( $i < $MAXAGENDA )
2012-01-22 20:16:11 +01:00
{
$i ++ ;
2012-07-13 11:40:06 +02:00
$source = 'AGENDA_EXT_SRC' . $i ;
$name = 'AGENDA_EXT_NAME' . $i ;
2015-07-28 18:12:45 +02:00
$offsettz = 'AGENDA_EXT_OFFSETTZ' . $i ;
2012-07-13 11:40:06 +02:00
$color = 'AGENDA_EXT_COLOR' . $i ;
2014-05-23 04:28:57 +02:00
$buggedfile = 'AGENDA_EXT_BUGGEDFILE' . $i ;
2012-07-13 11:40:06 +02:00
if ( ! empty ( $conf -> global -> $source ) && ! empty ( $conf -> global -> $name ))
{
2014-05-23 04:28:57 +02:00
// Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
2015-07-28 18:12:45 +02:00
$listofextcals [] = array ( 'src' => $conf -> global -> $source , 'name' => $conf -> global -> $name , 'offsettz' => $conf -> global -> $offsettz , 'color' => $conf -> global -> $color , 'buggedfile' => ( isset ( $conf -> global -> buggedfile ) ? $conf -> global -> buggedfile : 0 ));
2012-07-13 11:40:06 +02:00
}
2012-01-22 20:16:11 +01:00
}
}
2014-08-15 17:08:05 +02:00
// Define list of external calendars (user setup)
2014-09-05 13:48:55 +02:00
if ( empty ( $user -> conf -> AGENDA_DISABLE_EXT ))
2014-08-15 17:08:05 +02:00
{
2014-09-05 13:48:55 +02:00
$i = 0 ;
2015-03-02 17:34:50 +01:00
while ( $i < $MAXAGENDA )
2014-08-15 17:08:05 +02:00
{
2014-09-05 13:48:55 +02:00
$i ++ ;
$source = 'AGENDA_EXT_SRC_' . $user -> id . '_' . $i ;
$name = 'AGENDA_EXT_NAME_' . $user -> id . '_' . $i ;
2015-07-28 18:12:45 +02:00
$offsettz = 'AGENDA_EXT_OFFSETTZ_' . $user -> id . '_' . $i ;
2014-09-05 13:48:55 +02:00
$color = 'AGENDA_EXT_COLOR_' . $user -> id . '_' . $i ;
$enabled = 'AGENDA_EXT_ENABLED_' . $user -> id . '_' . $i ;
$buggedfile = 'AGENDA_EXT_BUGGEDFILE_' . $user -> id . '_' . $i ;
if ( ! empty ( $user -> conf -> $source ) && ! empty ( $user -> conf -> $name ))
{
// Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
2015-07-28 18:12:45 +02:00
$listofextcals [] = array ( 'src' => $user -> conf -> $source , 'name' => $user -> conf -> $name , 'offsettz' => $user -> conf -> $offsettz , 'color' => $user -> conf -> $color , 'buggedfile' => ( isset ( $user -> conf -> buggedfile ) ? $user -> conf -> buggedfile : 0 ));
2014-09-05 13:48:55 +02:00
}
2014-08-15 17:08:05 +02:00
}
}
2012-01-22 20:16:11 +01:00
2011-02-02 16:51:18 +01:00
if ( empty ( $action ) || $action == 'show_month' )
{
$prev = dol_get_prev_month ( $month , $year );
$prev_year = $prev [ 'year' ];
$prev_month = $prev [ 'month' ];
$next = dol_get_next_month ( $month , $year );
$next_year = $next [ 'year' ];
$next_month = $next [ 'month' ];
$max_day_in_prev_month = date ( " t " , dol_mktime ( 0 , 0 , 0 , $prev_month , 1 , $prev_year )); // Nb of days in previous month
$max_day_in_month = date ( " t " , dol_mktime ( 0 , 0 , 0 , $month , 1 , $year )); // Nb of days in next month
2014-10-14 00:27:23 +02:00
// tmpday is a negative or null cursor to know how many days before the 1st to show on month view (if tmpday=0, 1st is monday)
$tmpday = - date ( " w " , dol_mktime ( 12 , 0 , 0 , $month , 1 , $year , true )) + 2 ; // date('w') is 0 fo sunday
2011-02-02 16:51:18 +01:00
$tmpday += (( isset ( $conf -> global -> MAIN_START_WEEK ) ? $conf -> global -> MAIN_START_WEEK : 1 ) - 1 );
2014-10-14 00:27:23 +02:00
if ( $tmpday >= 1 ) $tmpday -= 7 ; // If tmpday is 0 we start with sunday, if -6, we start with monday of previous week.
2014-09-28 15:33:13 +02:00
// Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
2011-02-02 16:51:18 +01:00
$firstdaytoshow = dol_mktime ( 0 , 0 , 0 , $prev_month , $max_day_in_prev_month + $tmpday , $prev_year );
2014-09-28 15:33:13 +02:00
$next_day = 7 - ( $max_day_in_month + 1 - $tmpday ) % 7 ;
2011-02-02 16:51:18 +01:00
if ( $next_day < 6 ) $next_day += 7 ;
$lastdaytoshow = dol_mktime ( 0 , 0 , 0 , $next_month , $next_day , $next_year );
2011-03-08 20:39:21 +01:00
}
if ( $action == 'show_week' )
{
2011-06-11 00:05:07 +02:00
$prev = dol_get_first_day_week ( $day , $month , $year );
$prev_year = $prev [ 'prev_year' ];
2011-03-09 17:53:30 +01:00
$prev_month = $prev [ 'prev_month' ];
$prev_day = $prev [ 'prev_day' ];
2011-06-11 00:05:07 +02:00
$first_day = $prev [ 'first_day' ];
2014-09-05 15:10:31 +02:00
$first_month = $prev [ 'first_month' ];
$first_year = $prev [ 'first_year' ];
2011-03-09 17:53:30 +01:00
2011-03-20 15:38:54 +01:00
$week = $prev [ 'week' ];
2011-09-20 14:29:00 +02:00
$day = ( int ) $day ;
2014-09-05 15:10:31 +02:00
$next = dol_get_next_week ( $first_day , $week , $first_month , $first_year );
2011-03-09 17:53:30 +01:00
$next_year = $next [ 'year' ];
$next_month = $next [ 'month' ];
$next_day = $next [ 'day' ];
2011-03-20 15:38:54 +01:00
2014-09-28 15:33:13 +02:00
// Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
2014-09-05 15:10:31 +02:00
$firstdaytoshow = dol_mktime ( 0 , 0 , 0 , $first_month , $first_day , $first_year );
2014-09-28 15:33:13 +02:00
$lastdaytoshow = dol_time_plus_duree ( $firstdaytoshow , 7 , 'd' );
2011-03-20 15:38:54 +01:00
$max_day_in_month = date ( " t " , dol_mktime ( 0 , 0 , 0 , $month , 1 , $year ));
$tmpday = $first_day ;
2011-02-02 16:51:18 +01:00
}
2011-09-20 14:29:00 +02:00
if ( $action == 'show_day' )
2011-02-02 16:51:18 +01:00
{
$prev = dol_get_prev_day ( $day , $month , $year );
$prev_year = $prev [ 'year' ];
$prev_month = $prev [ 'month' ];
$prev_day = $prev [ 'day' ];
$next = dol_get_next_day ( $day , $month , $year );
$next_year = $next [ 'year' ];
$next_month = $next [ 'month' ];
$next_day = $next [ 'day' ];
2014-09-28 15:33:13 +02:00
// Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
2011-02-02 16:51:18 +01:00
$firstdaytoshow = dol_mktime ( 0 , 0 , 0 , $prev_month , $prev_day , $prev_year );
$lastdaytoshow = dol_mktime ( 0 , 0 , 0 , $next_month , $next_day , $next_year );
}
//print 'xx'.$prev_year.'-'.$prev_month.'-'.$prev_day;
//print 'xx'.$next_year.'-'.$next_month.'-'.$next_day;
2009-02-20 23:53:15 +01:00
//print dol_print_date($firstdaytoshow,'day');
//print dol_print_date($lastdaytoshow,'day');
2008-03-02 19:47:42 +01:00
2010-12-02 01:06:39 +01:00
$title = $langs -> trans ( " DoneAndToDoActions " );
2008-03-20 23:46:52 +01:00
if ( $status == 'done' ) $title = $langs -> trans ( " DoneActions " );
if ( $status == 'todo' ) $title = $langs -> trans ( " ToDoActions " );
$param = '' ;
2017-11-02 14:58:33 +01:00
if ( $actioncode || isset ( $_GET [ 'actioncode' ]) || isset ( $_POST [ 'actioncode' ])) {
if ( is_array ( $actioncode )) {
foreach ( $actioncode as $str_action ) $param .= " &actioncode[]= " . $str_action ;
} else $param .= " &actioncode= " . $actioncode ;
}
2016-06-06 13:05:36 +02:00
if ( $resourceid > 0 ) $param .= " &resourceid= " . $resourceid ;
2014-07-19 22:37:18 +02:00
if ( $status || isset ( $_GET [ 'status' ]) || isset ( $_POST [ 'status' ])) $param .= " &status= " . $status ;
2008-09-29 02:17:40 +02:00
if ( $filter ) $param .= " &filter= " . $filter ;
2018-11-30 23:25:44 +01:00
if ( $usergroup ) $param .= " &usergroup= " . $usergroup ;
2008-03-20 23:46:52 +01:00
if ( $filtert ) $param .= " &filtert= " . $filtert ;
2010-01-19 10:44:52 +01:00
if ( $socid ) $param .= " &socid= " . $socid ;
2008-09-28 05:39:39 +02:00
if ( $showbirthday ) $param .= " &showbirthday=1 " ;
2010-01-19 10:44:52 +01:00
if ( $pid ) $param .= " &projectid= " . $pid ;
2012-07-13 11:40:06 +02:00
if ( $type ) $param .= " &type= " . $type ;
2014-07-19 22:37:18 +02:00
if ( $action == 'show_day' || $action == 'show_week' || $action == 'show_month' ) $param .= '&action=' . $action ;
2012-01-22 20:16:11 +01:00
$param .= " &maxprint= " . $maxprint ;
2008-03-20 23:46:52 +01:00
2008-03-02 19:47:42 +01:00
// Show navigation bar
2011-02-02 16:51:18 +01:00
if ( empty ( $action ) || $action == 'show_month' )
{
2017-03-28 18:42:23 +02:00
$nav = " <a href= \" ?year= " . $prev_year . " &month= " . $prev_month . $param . " \" ><i class= \" fa fa-chevron-left \" ></i></a> \n " ;
2011-02-02 16:51:18 +01:00
$nav .= " <span id= \" month_name \" > " . dol_print_date ( dol_mktime ( 0 , 0 , 0 , $month , 1 , $year ), " %b %Y " );
$nav .= " </span> \n " ;
2017-03-28 18:42:23 +02:00
$nav .= " <a href= \" ?year= " . $next_year . " &month= " . $next_month . $param . " \" ><i class= \" fa fa-chevron-right \" ></i></a> \n " ;
2014-06-27 20:50:46 +02:00
$nav .= " (<a href= \" ?year= " . $nowyear . " &month= " . $nowmonth . $param . " \" > " . $langs -> trans ( " Today " ) . " </a>) " ;
2011-05-17 12:16:24 +02:00
$picto = 'calendar' ;
2011-03-08 20:39:21 +01:00
}
if ( $action == 'show_week' )
{
2017-03-28 18:42:23 +02:00
$nav = " <a href= \" ?year= " . $prev_year . " &month= " . $prev_month . " &day= " . $prev_day . $param . " \" ><i class= \" fa fa-chevron-left \" title= \" " . dol_escape_htmltag ( $langs -> trans ( " Previous " )) . " \" ></i></a> \n " ;
2014-09-05 15:10:31 +02:00
$nav .= " <span id= \" month_name \" > " . dol_print_date ( dol_mktime ( 0 , 0 , 0 , $first_month , $first_day , $first_year ), " %Y " ) . " , " . $langs -> trans ( " Week " ) . " " . $week ;
2011-06-11 00:05:07 +02:00
$nav .= " </span> \n " ;
2017-03-28 18:42:23 +02:00
$nav .= " <a href= \" ?year= " . $next_year . " &month= " . $next_month . " &day= " . $next_day . $param . " \" ><i class= \" fa fa-chevron-right \" title= \" " . dol_escape_htmltag ( $langs -> trans ( " Next " )) . " \" ></i></a> \n " ;
2014-06-27 20:50:46 +02:00
$nav .= " (<a href= \" ?year= " . $nowyear . " &month= " . $nowmonth . " &day= " . $nowday . $param . " \" > " . $langs -> trans ( " Today " ) . " </a>) " ;
2011-06-11 00:05:07 +02:00
$picto = 'calendarweek' ;
2011-02-02 16:51:18 +01:00
}
if ( $action == 'show_day' )
{
2017-03-28 18:42:23 +02:00
$nav = " <a href= \" ?year= " . $prev_year . " &month= " . $prev_month . " &day= " . $prev_day . $param . " \" ><i class= \" fa fa-chevron-left \" ></i></a> \n " ;
2011-02-02 16:51:18 +01:00
$nav .= " <span id= \" month_name \" > " . dol_print_date ( dol_mktime ( 0 , 0 , 0 , $month , $day , $year ), " daytextshort " );
$nav .= " </span> \n " ;
2017-03-28 18:42:23 +02:00
$nav .= " <a href= \" ?year= " . $next_year . " &month= " . $next_month . " &day= " . $next_day . $param . " \" ><i class= \" fa fa-chevron-right \" ></i></a> \n " ;
2014-06-27 20:50:46 +02:00
$nav .= " (<a href= \" ?year= " . $nowyear . " &month= " . $nowmonth . " &day= " . $nowday . $param . " \" > " . $langs -> trans ( " Today " ) . " </a>) " ;
2011-05-17 12:16:24 +02:00
$picto = 'calendarday' ;
2011-02-02 16:51:18 +01:00
}
2008-03-20 21:39:50 +01:00
2008-09-28 05:39:39 +02:00
// Must be after the nav definition
2008-09-29 02:17:40 +02:00
$param .= '&year=' . $year . '&month=' . $month . ( $day ? '&day=' . $day : '' );
2011-02-02 16:51:18 +01:00
//print 'x'.$param;
2008-09-28 05:39:39 +02:00
2008-03-02 19:47:42 +01:00
2011-05-16 19:27:20 +02:00
2014-06-27 20:50:46 +02:00
$tabactive = '' ;
if ( $action == 'show_month' ) $tabactive = 'cardmonth' ;
if ( $action == 'show_week' ) $tabactive = 'cardweek' ;
if ( $action == 'show_day' ) $tabactive = 'cardday' ;
if ( $action == 'show_list' ) $tabactive = 'cardlist' ;
2011-05-16 19:27:20 +02:00
2014-06-27 20:50:46 +02:00
$paramnoaction = preg_replace ( '/action=[a-z_]+/' , '' , $param );
$head = calendars_prepare_head ( $paramnoaction );
2011-05-16 19:27:20 +02:00
2017-11-25 00:12:45 +01:00
print '<form method="POST" id="searchFormList" class="listactionsfilter" action="' . $_SERVER [ " PHP_SELF " ] . '">' . " \n " ;
2017-12-01 12:01:17 +01:00
if ( $optioncss != '' ) print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2017-11-25 00:12:45 +01:00
2014-06-27 20:50:46 +02:00
dol_fiche_head ( $head , $tabactive , $langs -> trans ( 'Agenda' ), 0 , 'action' );
2016-06-06 13:05:36 +02:00
print_actions_filter ( $form , $canedit , $status , $year , $month , $day , $showbirthday , 0 , $filtert , 0 , $pid , $socid , $action , $listofextcals , $actioncode , $usergroup , '' , $resourceid );
2011-05-16 19:27:20 +02:00
dol_fiche_end ();
2015-06-30 17:09:52 +02:00
// Define the legend/list of calendard to show
$s = '' ; $link = '' ;
2014-06-28 20:49:10 +02:00
$showextcals = $listofextcals ;
2015-06-30 17:09:52 +02:00
if ( ! empty ( $conf -> use_javascript_ajax )) // If javascript on
2014-06-28 20:49:10 +02:00
{
2017-11-25 00:12:45 +01:00
$s .= " \n " . '<!-- Div to calendars selectors -->' . " \n " ;
2014-06-28 20:49:10 +02:00
$s .= '<script type="text/javascript">' . " \n " ;
$s .= 'jQuery(document).ready(function () {' . " \n " ;
2017-04-01 00:35:05 +02:00
$s .= 'jQuery("#check_birthday").click(function() { console.log("Toggle birthday"); jQuery(".family_birthday").toggle(); });' . " \n " ;
2014-06-28 20:49:10 +02:00
$s .= 'jQuery(".family_birthday").toggle();' . " \n " ;
2014-08-14 00:57:59 +02:00
if ( $action == " show_week " || $action == " show_month " || empty ( $action ))
2014-08-08 14:25:14 +02:00
{
2017-11-25 00:12:45 +01:00
// Code to enable drag and drop
$s .= 'jQuery( "div.sortable" ).sortable({connectWith: ".sortable", placeholder: "ui-state-highlight", items: "div.movable", receive: function( event, ui ) {' . " \n " ;
// Code to submit form
$s .= 'console.log("submit form to record new event");' . " \n " ;
//$s.='console.log(event.target);';
$s .= 'var newval = jQuery(event.target).closest("div.dayevent").attr("id");' . " \n " ;
$s .= 'console.log("found parent div.dayevent with id = "+newval);' . " \n " ;
$s .= 'var frm=jQuery("#searchFormList");' . " \n " ;
$s .= 'var newurl = ui.item.find("a.cal_event").attr("href");' . " \n " ;
$s .= 'console.log(newurl);' . " \n " ;
$s .= 'frm.attr("action", newurl).children("#newdate").val(newval);frm.submit();}' . " \n " ;
$s .= '});' . " \n " ;
}
$s .= '});' . " \n " ;
$s .= '</script>' . " \n " ;
2015-01-25 17:49:11 +01:00
2015-06-30 17:09:52 +02:00
// Local calendar
2017-11-14 12:18:02 +01:00
$s .= '<div class="nowrap clear inline-block minheight20"><input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> ' . $langs -> trans ( " LocalAgenda " ) . ' </div>' ;
2015-06-30 17:09:52 +02:00
// External calendars
2015-01-25 17:49:11 +01:00
if ( is_array ( $showextcals ) && count ( $showextcals ) > 0 )
2014-06-28 20:49:10 +02:00
{
2015-03-05 10:20:32 +01:00
$s .= '<script type="text/javascript">' . " \n " ;
$s .= ' jQuery ( document ) . ready ( function () {
2015-03-11 02:26:01 +01:00
jQuery ( " table input[name^= \" check_ext \" ] " ) . click ( function () {
2015-03-05 10:20:32 +01:00
var name = $ ( this ) . attr ( " name " );
2015-03-11 02:26:01 +01:00
jQuery ( " .family_ext " + name . replace ( " check_ext " , " " )) . toggle ();
2015-03-05 10:22:22 +01:00
});
2015-03-05 10:20:32 +01:00
}); ' . " \n " ;
$s .= '</script>' . " \n " ;
2015-01-25 17:49:11 +01:00
foreach ( $showextcals as $val )
2014-06-28 20:49:10 +02:00
{
2015-03-05 11:46:03 +01:00
$htmlname = md5 ( $val [ 'name' ]);
2017-11-14 12:18:02 +01:00
$s .= '<div class="nowrap inline-block"><input type="checkbox" id="check_ext' . $htmlname . '" name="check_ext' . $htmlname . '" checked> ' . $val [ 'name' ] . ' </div>' ;
2014-06-28 20:49:10 +02:00
}
}
2015-06-30 17:09:52 +02:00
// Birthdays
2017-11-14 12:18:02 +01:00
$s .= '<div class="nowrap inline-block"><input type="checkbox" id="check_birthday" name="check_birthday"> ' . $langs -> trans ( " AgendaShowBirthdayEvents " ) . ' </div>' ;
2014-06-28 20:49:10 +02:00
2015-06-30 17:09:52 +02:00
// Calendars from hooks
$parameters = array (); $object = null ;
$reshook = $hookmanager -> executeHooks ( 'addCalendarChoice' , $parameters , $object , $action );
if ( empty ( $reshook ))
{
$s .= $hookmanager -> resPrint ;
}
elseif ( $reshook > 1 )
{
$s = $hookmanager -> resPrint ;
}
}
else // If javascript off
2012-01-22 20:16:11 +01:00
{
$newparam = $param ; // newparam is for birthday links
$newparam = preg_replace ( '/showbirthday=[0-1]/i' , 'showbirthday=' . ( empty ( $showbirthday ) ? 1 : 0 ), $newparam );
if ( ! preg_match ( '/showbirthday=/i' , $newparam )) $newparam .= '&showbirthday=1' ;
2017-06-18 21:13:48 +02:00
$link = '<a href="' . dol_escape_htmltag ( $_SERVER [ 'PHP_SELF' ]);
$link .= '?' . dol_escape_htmltag ( $newparam );
2012-01-22 20:16:11 +01:00
$link .= '">' ;
if ( empty ( $showbirthday )) $link .= $langs -> trans ( " AgendaShowBirthdayEvents " );
else $link .= $langs -> trans ( " AgendaHideBirthdayEvents " );
$link .= '</a>' ;
}
2011-05-16 19:27:20 +02:00
2016-06-06 22:07:35 +02:00
print load_fiche_titre ( $s , $link . ' ' . $nav , '' , 0 , 0 , 'tablelistofcalendars' );
2008-03-20 20:07:21 +01:00
2015-06-30 17:09:52 +02:00
// Load events from database into $eventarray
2011-02-02 16:51:18 +01:00
$eventarray = array ();
2008-09-28 05:39:39 +02:00
2015-01-15 02:06:04 +01:00
$sql = 'SELECT ' ;
if ( $usergroup > 0 ) $sql .= " DISTINCT " ;
$sql .= ' a.id, a.label,' ;
2010-11-19 23:36:49 +01:00
$sql .= ' a.datep,' ;
$sql .= ' a.datep2,' ;
2008-04-16 03:04:12 +02:00
$sql .= ' a.percent,' ;
2015-01-15 02:06:04 +01:00
$sql .= ' a.fk_user_author,a.fk_user_action,' ;
2014-06-28 18:04:32 +02:00
$sql .= ' a.transparency, a.priority, a.fulldayevent, a.location,' ;
2010-11-19 23:36:49 +01:00
$sql .= ' a.fk_soc, a.fk_contact,' ;
2017-05-17 17:00:45 +02:00
$sql .= ' a.fk_element, a.elementtype,' ;
2016-08-25 12:24:38 +02:00
$sql .= ' ca.code as type_code, ca.libelle as type_label, ca.color as type_color' ;
2014-06-28 20:49:10 +02:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'c_actioncomm as ca, ' . MAIN_DB_PREFIX . " actioncomm as a " ;
2013-01-10 08:27:12 +01:00
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe_commerciaux as sc ON a.fk_soc = sc.fk_soc " ;
2016-06-06 13:05:36 +02:00
// We must filter on resource table
if ( $resourceid > 0 ) $sql .= " , " . MAIN_DB_PREFIX . " element_resources as r " ;
2015-01-15 02:06:04 +01:00
// We must filter on assignement table
if ( $filtert > 0 || $usergroup > 0 ) $sql .= " , " . MAIN_DB_PREFIX . " actioncomm_resources as ar " ;
if ( $usergroup > 0 ) $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " usergroup_user as ugu ON ugu.fk_user = ar.fk_element " ;
2013-01-10 08:27:12 +01:00
$sql .= ' WHERE a.fk_action = ca.id' ;
2017-05-30 18:50:54 +02:00
$sql .= ' AND a.entity IN (' . getEntity ( 'agenda' ) . ')' ;
2016-11-08 12:58:07 +01:00
// Condition on actioncode
if ( ! empty ( $actioncode ))
{
if ( empty ( $conf -> global -> AGENDA_USE_EVENT_TYPE ))
{
if ( $actioncode == 'AC_NON_AUTO' ) $sql .= " AND ca.type != 'systemauto' " ;
elseif ( $actioncode == 'AC_ALL_AUTO' ) $sql .= " AND ca.type = 'systemauto' " ;
else
{
if ( $actioncode == 'AC_OTH' ) $sql .= " AND ca.type != 'systemauto' " ;
if ( $actioncode == 'AC_OTH_AUTO' ) $sql .= " AND ca.type = 'systemauto' " ;
}
}
else
{
if ( $actioncode == 'AC_NON_AUTO' ) $sql .= " AND ca.type != 'systemauto' " ;
elseif ( $actioncode == 'AC_ALL_AUTO' ) $sql .= " AND ca.type = 'systemauto' " ;
else
{
2017-11-02 15:48:24 +01:00
if ( is_array ( $actioncode ))
{
2017-11-02 15:48:56 +01:00
$sql .= " AND ca.code IN (' " . implode ( " ',' " , $actioncode ) . " ') " ;
2017-11-02 15:48:24 +01:00
}
else
{
$sql .= " AND ca.code IN (' " . implode ( " ',' " , explode ( ',' , $actioncode )) . " ') " ;
}
2016-11-08 12:58:07 +01:00
}
}
}
2016-06-06 13:05:36 +02:00
if ( $resourceid > 0 ) $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = " . $db -> escape ( $resourceid );
2013-01-10 08:27:12 +01:00
if ( $pid ) $sql .= " AND a.fk_project= " . $db -> escape ( $pid );
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = " . $user -> id . " ) " ;
2014-06-29 04:34:12 +02:00
if ( $socid > 0 ) $sql .= ' AND a.fk_soc = ' . $socid ;
2015-01-15 02:06:04 +01:00
// We must filter on assignement table
if ( $filtert > 0 || $usergroup > 0 ) $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user' " ;
2011-02-02 16:51:18 +01:00
if ( $action == 'show_day' )
2008-08-30 00:40:36 +02:00
{
2011-06-11 00:05:07 +02:00
$sql .= " AND ( " ;
2014-01-08 20:40:30 +01:00
$sql .= " (a.datep BETWEEN ' " . $db -> idate ( dol_mktime ( 0 , 0 , 0 , $month , $day , $year )) . " ' " ;
2011-06-11 00:05:07 +02:00
$sql .= " AND ' " . $db -> idate ( dol_mktime ( 23 , 59 , 59 , $month , $day , $year )) . " ') " ;
$sql .= " OR " ;
2014-01-08 20:40:30 +01:00
$sql .= " (a.datep2 BETWEEN ' " . $db -> idate ( dol_mktime ( 0 , 0 , 0 , $month , $day , $year )) . " ' " ;
2011-06-11 00:05:07 +02:00
$sql .= " AND ' " . $db -> idate ( dol_mktime ( 23 , 59 , 59 , $month , $day , $year )) . " ') " ;
$sql .= " OR " ;
2014-01-08 20:40:30 +01:00
$sql .= " (a.datep < ' " . $db -> idate ( dol_mktime ( 0 , 0 , 0 , $month , $day , $year )) . " ' " ;
$sql .= " AND a.datep2 > ' " . $db -> idate ( dol_mktime ( 23 , 59 , 59 , $month , $day , $year )) . " ') " ;
2011-06-11 00:05:07 +02:00
$sql .= ')' ;
2008-08-30 00:40:36 +02:00
}
2008-09-29 02:17:40 +02:00
else
{
2011-06-11 00:05:07 +02:00
// To limit array
$sql .= " AND ( " ;
2014-01-08 20:40:30 +01:00
$sql .= " (a.datep BETWEEN ' " . $db -> idate ( dol_mktime ( 0 , 0 , 0 , $month , 1 , $year ) - ( 60 * 60 * 24 * 7 )) . " ' " ; // Start 7 days before
2011-06-11 00:05:07 +02:00
$sql .= " AND ' " . $db -> idate ( dol_mktime ( 23 , 59 , 59 , $month , 28 , $year ) + ( 60 * 60 * 24 * 10 )) . " ') " ; // End 7 days after + 3 to go from 28 to 31
$sql .= " OR " ;
2014-01-08 20:40:30 +01:00
$sql .= " (a.datep2 BETWEEN ' " . $db -> idate ( dol_mktime ( 0 , 0 , 0 , $month , 1 , $year ) - ( 60 * 60 * 24 * 7 )) . " ' " ;
2011-06-11 00:05:07 +02:00
$sql .= " AND ' " . $db -> idate ( dol_mktime ( 23 , 59 , 59 , $month , 28 , $year ) + ( 60 * 60 * 24 * 10 )) . " ') " ;
$sql .= " OR " ;
2014-01-08 20:40:30 +01:00
$sql .= " (a.datep < ' " . $db -> idate ( dol_mktime ( 0 , 0 , 0 , $month , 1 , $year ) - ( 60 * 60 * 24 * 7 )) . " ' " ;
$sql .= " AND a.datep2 > ' " . $db -> idate ( dol_mktime ( 23 , 59 , 59 , $month , 28 , $year ) + ( 60 * 60 * 24 * 10 )) . " ') " ;
2011-06-11 00:05:07 +02:00
$sql .= ')' ;
2008-09-29 02:17:40 +02:00
}
2012-07-13 11:40:06 +02:00
if ( $type ) $sql .= " AND ca.id = " . $type ;
2014-06-26 20:24:00 +02:00
if ( $status == '0' ) { $sql .= " AND a.percent = 0 " ; }
if ( $status == '-1' ) { $sql .= " AND a.percent = -1 " ; } // Not applicable
2014-07-19 22:37:18 +02:00
if ( $status == '50' ) { $sql .= " AND (a.percent > 0 AND a.percent < 100) " ; } // Running already started
2018-05-30 13:37:17 +02:00
if ( $status == 'done' || $status == '100' ) { $sql .= " AND (a.percent = 100) " ; }
if ( $status == 'todo' ) { $sql .= " AND (a.percent >= 0 AND a.percent < 100) " ; }
2015-01-15 02:06:04 +01:00
// We must filter on assignement table
if ( $filtert > 0 || $usergroup > 0 )
2008-03-20 20:07:21 +01:00
{
2011-06-11 00:05:07 +02:00
$sql .= " AND ( " ;
2015-01-15 02:06:04 +01:00
if ( $filtert > 0 ) $sql .= " ar.fk_element = " . $filtert ;
if ( $usergroup > 0 ) $sql .= ( $filtert > 0 ? " OR " : " " ) . " ugu.fk_usergroup = " . $usergroup ;
2011-06-11 00:05:07 +02:00
$sql .= " ) " ;
2008-03-20 20:07:21 +01:00
}
2008-09-29 02:17:40 +02:00
// Sort on date
$sql .= ' ORDER BY datep' ;
2009-07-08 15:35:00 +02:00
//print $sql;
2010-01-19 10:44:52 +01:00
2015-06-30 17:09:52 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( " comm/action/index.php " , LOG_DEBUG );
2008-08-30 00:40:36 +02:00
$resql = $db -> query ( $sql );
2008-03-20 20:07:21 +01:00
if ( $resql )
{
2011-06-11 00:05:07 +02:00
$num = $db -> num_rows ( $resql );
2017-07-12 23:05:26 +02:00
$MAXONSAMEPAGE = 10000 ; // Useless to have more. Protection to avoid memory overload when high number of event (for example after a mass import)
2011-06-11 00:05:07 +02:00
$i = 0 ;
2017-07-12 23:05:26 +02:00
while ( $i < $num && $i < $MAXONSAMEPAGE )
2011-06-11 00:05:07 +02:00
{
$obj = $db -> fetch_object ( $resql );
2014-10-20 12:29:35 +02:00
// Discard auto action if option is on
2014-10-20 13:20:19 +02:00
if ( ! empty ( $conf -> global -> AGENDA_ALWAYS_HIDE_AUTO ) && $obj -> type_code == 'AC_OTH_AUTO' )
2014-10-20 12:29:35 +02:00
{
$i ++ ;
continue ;
}
2011-06-11 00:05:07 +02:00
// Create a new object action
$event = new ActionComm ( $db );
$event -> id = $obj -> id ;
2015-07-28 18:12:45 +02:00
$event -> datep = $db -> jdate ( $obj -> datep ); // datep and datef are GMT date. Example: 1970-01-01 01:00:00, jdate will return 0 if TZ of PHP server is Europe/Berlin
2011-06-11 00:05:07 +02:00
$event -> datef = $db -> jdate ( $obj -> datep2 );
2015-07-28 18:12:45 +02:00
//var_dump($obj->datep);
//var_dump($event->datep);
2014-10-20 13:20:19 +02:00
$event -> type_code = $obj -> type_code ;
2014-10-20 13:14:33 +02:00
$event -> type_label = $obj -> type_label ;
2016-08-25 12:24:38 +02:00
$event -> type_color = $obj -> type_color ;
2011-06-11 00:05:07 +02:00
$event -> libelle = $obj -> label ;
2018-03-07 11:53:30 +01:00
$event -> label = $obj -> label ;
2011-06-11 00:05:07 +02:00
$event -> percentage = $obj -> percent ;
2014-10-11 15:04:42 +02:00
$event -> authorid = $obj -> fk_user_author ; // user id of creator
2014-09-26 12:27:18 +02:00
$event -> userownerid = $obj -> fk_user_action ; // user id of owner
$event -> fetch_userassigned (); // This load $event->userassigned
2011-02-02 16:51:18 +01:00
$event -> priority = $obj -> priority ;
$event -> fulldayevent = $obj -> fulldayevent ;
$event -> location = $obj -> location ;
2014-06-28 18:04:32 +02:00
$event -> transparency = $obj -> transparency ;
2017-05-17 17:00:45 +02:00
$event -> fk_element = $obj -> fk_element ;
$event -> elementtype = $obj -> elementtype ;
2011-02-02 16:51:18 +01:00
$event -> societe -> id = $obj -> fk_soc ;
2018-03-07 11:53:30 +01:00
$event -> thirdparty_id = $obj -> fk_soc ;
2011-02-02 16:51:18 +01:00
$event -> contact -> id = $obj -> fk_contact ;
2018-03-07 11:53:30 +01:00
$event -> contact_id = $obj -> fk_contact ;
2010-11-19 23:36:49 +01:00
2011-06-11 00:05:07 +02:00
// Defined date_start_in_calendar and date_end_in_calendar property
// They are date start and end of action but modified to not be outside calendar view.
if ( $event -> percentage <= 0 )
{
$event -> date_start_in_calendar = $event -> datep ;
if ( $event -> datef != '' && $event -> datef >= $event -> datep ) $event -> date_end_in_calendar = $event -> datef ;
else $event -> date_end_in_calendar = $event -> datep ;
}
else
{
$event -> date_start_in_calendar = $event -> datep ;
if ( $event -> datef != '' && $event -> datef >= $event -> datep ) $event -> date_end_in_calendar = $event -> datef ;
else $event -> date_end_in_calendar = $event -> datep ;
}
// Define ponctual property
if ( $event -> date_start_in_calendar == $event -> date_end_in_calendar )
{
$event -> ponctuel = 1 ;
}
// Check values
if ( $event -> date_end_in_calendar < $firstdaytoshow ||
2014-09-28 15:33:13 +02:00
$event -> date_start_in_calendar >= $lastdaytoshow )
2011-06-11 00:05:07 +02:00
{
// This record is out of visible range
}
else
{
if ( $event -> date_start_in_calendar < $firstdaytoshow ) $event -> date_start_in_calendar = $firstdaytoshow ;
2014-09-28 15:33:13 +02:00
if ( $event -> date_end_in_calendar >= $lastdaytoshow ) $event -> date_end_in_calendar = ( $lastdaytoshow - 1 );
2011-06-11 00:05:07 +02:00
// Add an entry in actionarray for each day
$daycursor = $event -> date_start_in_calendar ;
$annee = date ( 'Y' , $daycursor );
$mois = date ( 'm' , $daycursor );
$jour = date ( 'd' , $daycursor );
// Loop on each day covered by action to prepare an index to show on calendar
$loop = true ; $j = 0 ;
$daykey = dol_mktime ( 0 , 0 , 0 , $mois , $jour , $annee );
do
{
//if ($event->id==408) print 'daykey='.$daykey.' '.$event->datep.' '.$event->datef.'<br>';
$eventarray [ $daykey ][] = $event ;
$j ++ ;
$daykey += 60 * 60 * 24 ;
if ( $daykey > $event -> date_end_in_calendar ) $loop = false ;
}
while ( $loop );
//print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
//print ' startincalendar='.dol_print_date($event->date_start_in_calendar).'-endincalendar='.dol_print_date($event->date_end_in_calendar).') was added in '.$j.' different index key of array<br>';
}
$i ++ ;
}
2008-03-20 20:07:21 +01:00
}
else
{
2011-06-11 00:05:07 +02:00
dol_print_error ( $db );
2008-03-20 20:07:21 +01:00
}
2015-06-30 17:09:52 +02:00
// Complete $eventarray with birthdates
2008-09-28 05:39:39 +02:00
if ( $showbirthday )
{
2011-06-11 00:05:07 +02:00
// Add events in array
2013-02-23 17:01:10 +01:00
$sql = 'SELECT sp.rowid, sp.lastname, sp.firstname, sp.birthday' ;
2011-06-11 00:05:07 +02:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'socpeople as sp' ;
$sql .= ' WHERE (priv=0 OR (priv=1 AND fk_user_creat=' . $user -> id . '))' ;
2018-04-27 10:42:10 +02:00
$sql .= " AND sp.entity IN ( " . getEntity ( 'socpeople' ) . " ) " ;
2011-06-11 00:05:07 +02:00
if ( $action == 'show_day' )
{
$sql .= ' AND MONTH(birthday) = ' . $month ;
$sql .= ' AND DAY(birthday) = ' . $day ;
}
else
{
$sql .= ' AND MONTH(birthday) = ' . $month ;
}
$sql .= ' ORDER BY birthday' ;
2014-06-12 11:31:53 +02:00
dol_syslog ( " comm/action/index.php " , LOG_DEBUG );
2011-06-11 00:05:07 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
$event = new ActionComm ( $db );
$event -> id = $obj -> rowid ; // We put contact id in action id for birthdays events
$datebirth = dol_stringtotime ( $obj -> birthday , 1 );
//print 'ee'.$obj->birthday.'-'.$datebirth;
$datearray = dol_getdate ( $datebirth , true );
$event -> datep = dol_mktime ( 0 , 0 , 0 , $datearray [ 'mon' ], $datearray [ 'mday' ], $year , true ); // For full day events, date are also GMT but they wont but converted during output
$event -> datef = $event -> datep ;
$event -> type_code = 'BIRTHDAY' ;
2013-03-11 15:54:01 +01:00
$event -> libelle = $langs -> trans ( " Birthday " ) . ' ' . dolGetFirstLastname ( $obj -> firstname , $obj -> lastname );
2011-06-11 00:05:07 +02:00
$event -> percentage = 100 ;
2017-11-25 12:11:02 +01:00
$event -> fulldayevent = 1 ;
2011-06-11 00:05:07 +02:00
$event -> date_start_in_calendar = $event -> datep ;
$event -> date_end_in_calendar = $event -> datef ;
$event -> ponctuel = 0 ;
// Add an entry in actionarray for each day
$daycursor = $event -> date_start_in_calendar ;
$annee = date ( 'Y' , $daycursor );
$mois = date ( 'm' , $daycursor );
$jour = date ( 'd' , $daycursor );
$loop = true ;
$daykey = dol_mktime ( 0 , 0 , 0 , $mois , $jour , $annee );
do
{
$eventarray [ $daykey ][] = $event ;
$daykey += 60 * 60 * 24 ;
if ( $daykey > $event -> date_end_in_calendar ) $loop = false ;
}
while ( $loop );
$i ++ ;
}
}
else
{
dol_print_error ( $db );
}
2008-09-28 05:39:39 +02:00
}
2015-06-30 17:09:52 +02:00
// Complete $eventarray with external import Ical
2011-09-17 21:49:50 +02:00
if ( count ( $listofextcals ))
2011-06-11 00:05:07 +02:00
{
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/comm/action/class/ical.class.php' ;
2011-06-11 00:05:07 +02:00
foreach ( $listofextcals as $extcal )
{
2012-01-21 14:10:22 +01:00
$url = $extcal [ 'src' ]; // Example: https://www.google.com/calendar/ical/eldy10%40gmail.com/private-cde92aa7d7e0ef6110010a821a2aaeb/basic.ics
2011-06-11 00:05:07 +02:00
$namecal = $extcal [ 'name' ];
2015-07-28 18:12:45 +02:00
$offsettz = $extcal [ 'offsettz' ];
2011-06-11 00:05:07 +02:00
$colorcal = $extcal [ 'color' ];
2014-05-23 04:28:57 +02:00
$buggedfile = $extcal [ 'buggedfile' ];
//print "url=".$url." namecal=".$namecal." colorcal=".$colorcal." buggedfile=".$buggedfile;
2012-08-05 15:00:24 +02:00
$ical = new ICal ();
2011-06-11 00:05:07 +02:00
$ical -> parse ( $url );
2014-05-23 04:28:57 +02:00
2012-01-22 02:12:11 +01:00
// After this $ical->cal['VEVENT'] contains array of events, $ical->cal['DAYLIGHT'] contains daylight info, $ical->cal['STANDARD'] contains non daylight info, ...
//var_dump($ical->cal); exit;
2011-06-11 00:05:07 +02:00
$icalevents = array ();
2012-01-22 02:12:11 +01:00
if ( is_array ( $ical -> get_event_list ())) $icalevents = array_merge ( $icalevents , $ical -> get_event_list ()); // Add $ical->cal['VEVENT']
if ( is_array ( $ical -> get_freebusy_list ())) $icalevents = array_merge ( $icalevents , $ical -> get_freebusy_list ()); // Add $ical->cal['VFREEBUSY']
2011-06-11 00:05:07 +02:00
2012-01-21 14:10:22 +01:00
if ( count ( $icalevents ) > 0 )
2011-06-11 00:05:07 +02:00
{
2012-01-21 14:10:22 +01:00
// Duplicate all repeatable events into new entries
2012-01-22 02:12:11 +01:00
$moreicalevents = array ();
2011-06-11 00:05:07 +02:00
foreach ( $icalevents as $icalevent )
{
2012-07-13 11:40:06 +02:00
if ( isset ( $icalevent [ 'RRULE' ]) && is_array ( $icalevent [ 'RRULE' ])) //repeatable event
2012-01-21 14:10:22 +01:00
{
//if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
2014-09-28 15:33:13 +02:00
//if ($event->date_end_in_calendar > $lastdaytoshow) $event->date_end_in_calendar=($lastdaytoshow-1);
2012-01-22 02:12:11 +01:00
if ( $icalevent [ 'DTSTART;VALUE=DATE' ]) //fullday event
2012-01-21 14:10:22 +01:00
{
2012-01-22 02:12:11 +01:00
$datecurstart = dol_stringtotime ( $icalevent [ 'DTSTART;VALUE=DATE' ], 1 );
$datecurend = dol_stringtotime ( $icalevent [ 'DTEND;VALUE=DATE' ], 1 ) - 1 ; // We remove one second to get last second of day
2012-01-21 14:10:22 +01:00
}
2012-01-22 02:12:11 +01:00
else if ( is_array ( $icalevent [ 'DTSTART' ]) && ! empty ( $icalevent [ 'DTSTART' ][ 'unixtime' ]))
{
$datecurstart = $icalevent [ 'DTSTART' ][ 'unixtime' ];
$datecurend = $icalevent [ 'DTEND' ][ 'unixtime' ];
if ( ! empty ( $ical -> cal [ 'DAYLIGHT' ][ 'DTSTART' ]) && $datecurstart )
{
//var_dump($ical->cal);
$tmpcurstart = $datecurstart ;
$tmpcurend = $datecurend ;
$tmpdaylightstart = dol_mktime ( 0 , 0 , 0 , 1 , 1 , 1970 , 1 ) + ( int ) $ical -> cal [ 'DAYLIGHT' ][ 'DTSTART' ];
$tmpdaylightend = dol_mktime ( 0 , 0 , 0 , 1 , 1 , 1970 , 1 ) + ( int ) $ical -> cal [ 'STANDARD' ][ 'DTSTART' ];
//var_dump($tmpcurstart);var_dump($tmpcurend); var_dump($ical->cal['DAYLIGHT']['DTSTART']);var_dump($ical->cal['STANDARD']['DTSTART']);
// Edit datecurstart and datecurend
if ( $tmpcurstart >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend ) $datecurstart -= (( int ) $ical -> cal [ 'DAYLIGHT' ][ 'TZOFFSETTO' ]) * 36 ;
else $datecurstart -= (( int ) $ical -> cal [ 'STANDARD' ][ 'TZOFFSETTO' ]) * 36 ;
if ( $tmpcurend >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend ) $datecurend -= (( int ) $ical -> cal [ 'DAYLIGHT' ][ 'TZOFFSETTO' ]) * 36 ;
else $datecurend -= (( int ) $ical -> cal [ 'STANDARD' ][ 'TZOFFSETTO' ]) * 36 ;
}
// datecurstart and datecurend are now GMT date
//var_dump($datecurstart); var_dump($datecurend); exit;
}
else
{
// Not a recongized record
dol_syslog ( " Found a not recognized repeatable record with unknown date start " , LOG_ERR );
continue ;
}
//print 'xx'.$datecurstart;exit;
$interval = ( empty ( $icalevent [ 'RRULE' ][ 'INTERVAL' ]) ? 1 : $icalevent [ 'RRULE' ][ 'INTERVAL' ]);
$until = empty ( $icalevent [ 'RRULE' ][ 'UNTIL' ]) ? 0 : dol_stringtotime ( $icalevent [ 'RRULE' ][ 'UNTIL' ], 1 );
$maxrepeat = empty ( $icalevent [ 'RRULE' ][ 'COUNT' ]) ? 0 : $icalevent [ 'RRULE' ][ 'COUNT' ];
if ( $until && ( $until + ( $datecurend - $datecurstart )) < $firstdaytoshow ) continue ; // We discard repeatable event that end before start date to show
2014-09-28 15:33:13 +02:00
if ( $datecurstart >= $lastdaytoshow ) continue ; // We discard repeatable event that start after end date to show
2012-01-21 14:10:22 +01:00
2012-01-22 02:12:11 +01:00
$numofevent = 0 ;
2014-09-28 15:33:13 +02:00
while (( $datecurstart < $lastdaytoshow ) && ( empty ( $maxrepeat ) || ( $numofevent < $maxrepeat )))
2012-01-22 02:12:11 +01:00
{
if ( $datecurend >= $firstdaytoshow ) // We add event
{
$newevent = $icalevent ;
unset ( $newevent [ 'RRULE' ]);
if ( $icalevent [ 'DTSTART;VALUE=DATE' ])
{
$newevent [ 'DTSTART;VALUE=DATE' ] = dol_print_date ( $datecurstart , '%Y%m%d' );
$newevent [ 'DTEND;VALUE=DATE' ] = dol_print_date ( $datecurend + 1 , '%Y%m%d' );
}
else
{
$newevent [ 'DTSTART' ] = $datecurstart ;
$newevent [ 'DTEND' ] = $datecurend ;
}
$moreicalevents [] = $newevent ;
}
// Jump on next occurence
$numofevent ++ ;
$savdatecurstart = $datecurstart ;
if ( $icalevent [ 'RRULE' ][ 'FREQ' ] == 'DAILY' )
{
$datecurstart = dol_time_plus_duree ( $datecurstart , $interval , 'd' );
$datecurend = dol_time_plus_duree ( $datecurend , $interval , 'd' );
}
if ( $icalevent [ 'RRULE' ][ 'FREQ' ] == 'WEEKLY' )
{
$datecurstart = dol_time_plus_duree ( $datecurstart , $interval , 'w' );
$datecurend = dol_time_plus_duree ( $datecurend , $interval , 'w' );
}
elseif ( $icalevent [ 'RRULE' ][ 'FREQ' ] == 'MONTHLY' )
{
$datecurstart = dol_time_plus_duree ( $datecurstart , $interval , 'm' );
$datecurend = dol_time_plus_duree ( $datecurend , $interval , 'm' );
}
elseif ( $icalevent [ 'RRULE' ][ 'FREQ' ] == 'YEARLY' )
{
$datecurstart = dol_time_plus_duree ( $datecurstart , $interval , 'y' );
$datecurend = dol_time_plus_duree ( $datecurend , $interval , 'y' );
}
// Test to avoid infinite loop ($datecurstart must increase)
if ( $savdatecurstart >= $datecurstart )
{
dol_syslog ( " Found a rule freq " . $icalevent [ 'RRULE' ][ 'FREQ' ] . " not managed by dolibarr code. Assume 1 week frequency. " , LOG_ERR );
$datecurstart += 3600 * 24 * 7 ;
$datecurend += 3600 * 24 * 7 ;
}
}
2012-01-21 14:10:22 +01:00
}
}
2012-01-22 02:12:11 +01:00
$icalevents = array_merge ( $icalevents , $moreicalevents );
2012-01-21 14:10:22 +01:00
// Loop on each entry into cal file to know if entry is qualified and add an ActionComm into $eventarray
foreach ( $icalevents as $icalevent )
{
2014-05-23 04:28:57 +02:00
//var_dump($icalevent);
2012-01-21 14:10:22 +01:00
//print $icalevent['SUMMARY'].'->'.var_dump($icalevent).'<br>';exit;
2012-01-22 02:12:11 +01:00
if ( ! empty ( $icalevent [ 'RRULE' ])) continue ; // We found a repeatable event. It was already split into unitary events, so we discard general rule.
2012-01-21 14:10:22 +01:00
2011-06-11 00:05:07 +02:00
// Create a new object action
$event = new ActionComm ( $db );
$addevent = false ;
2012-07-13 11:40:06 +02:00
if ( isset ( $icalevent [ 'DTSTART;VALUE=DATE' ])) // fullday event
2011-06-11 00:05:07 +02:00
{
// For full day events, date are also GMT but they wont but converted using tz during output
$datestart = dol_stringtotime ( $icalevent [ 'DTSTART;VALUE=DATE' ], 1 );
$dateend = dol_stringtotime ( $icalevent [ 'DTEND;VALUE=DATE' ], 1 ) - 1 ; // We remove one second to get last second of day
//print 'x'.$datestart.'-'.$dateend;exit;
//print dol_print_date($dateend,'dayhour','gmt');
2017-11-25 12:11:02 +01:00
$event -> fulldayevent = 1 ;
2011-06-11 00:05:07 +02:00
$addevent = true ;
}
2014-05-23 04:28:57 +02:00
elseif ( ! is_array ( $icalevent [ 'DTSTART' ])) // not fullday event (DTSTART is not array. It is a value like '19700101T000000Z' for 00:00 in greenwitch)
2011-06-11 00:05:07 +02:00
{
$datestart = $icalevent [ 'DTSTART' ];
$dateend = $icalevent [ 'DTEND' ];
2015-07-28 18:12:45 +02:00
$datestart +=+ ( $offsettz * 3600 );
$dateend +=+ ( $offsettz * 3600 );
2011-06-11 00:05:07 +02:00
$addevent = true ;
2015-07-28 18:12:45 +02:00
//var_dump($offsettz);
//var_dump(dol_print_date($datestart, 'dayhour', 'gmt'));
2011-06-11 00:05:07 +02:00
}
2014-05-23 04:28:57 +02:00
elseif ( isset ( $icalevent [ 'DTSTART' ][ 'unixtime' ])) // File contains a local timezone + a TZ (for example when using bluemind)
{
$datestart = $icalevent [ 'DTSTART' ][ 'unixtime' ];
$dateend = $icalevent [ 'DTEND' ][ 'unixtime' ];
2015-07-28 18:12:45 +02:00
$datestart +=+ ( $offsettz * 3600 );
$dateend +=+ ( $offsettz * 3600 );
2014-05-23 04:28:57 +02:00
// $buggedfile is set to uselocalandtznodaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtznodaylight'
if ( $buggedfile === 'uselocalandtznodaylight' ) // unixtime is a local date that does not take daylight into account, TZID is +1 for example for 'Europe/Paris' in summer instead of 2
{
// TODO
}
// $buggedfile is set to uselocalandtzdaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtzdaylight' (for example with bluemind)
if ( $buggedfile === 'uselocalandtzdaylight' ) // unixtime is a local date that does take daylight into account, TZID is +2 for example for 'Europe/Paris' in summer
{
$localtzs = new DateTimeZone ( preg_replace ( '/"/' , '' , $icalevent [ 'DTSTART' ][ 'TZID' ]));
$localtze = new DateTimeZone ( preg_replace ( '/"/' , '' , $icalevent [ 'DTEND' ][ 'TZID' ]));
$localdts = new DateTime ( dol_print_date ( $datestart , 'dayrfc' , 'gmt' ), $localtzs );
$localdte = new DateTime ( dol_print_date ( $dateend , 'dayrfc' , 'gmt' ), $localtze );
$tmps =- 1 * $localtzs -> getOffset ( $localdts );
$tmpe =- 1 * $localtze -> getOffset ( $localdte );
$datestart += $tmps ;
$dateend += $tmpe ;
//var_dump($datestart);
}
$addevent = true ;
}
2011-06-11 00:05:07 +02:00
2012-01-21 14:10:22 +01:00
if ( $addevent )
2011-06-11 00:05:07 +02:00
{
$event -> id = $icalevent [ 'UID' ];
$event -> icalname = $namecal ;
$event -> icalcolor = $colorcal ;
$usertime = 0 ; // We dont modify date because we want to have date into memory datep and datef stored as GMT date. Compensation will be done during output.
$event -> datep = $datestart + $usertime ;
$event -> datef = $dateend + $usertime ;
$event -> type_code = " ICALEVENT " ;
2011-11-01 04:57:45 +01:00
2011-06-14 18:37:23 +02:00
if ( $icalevent [ 'SUMMARY' ]) $event -> libelle = $icalevent [ 'SUMMARY' ];
elseif ( $icalevent [ 'DESCRIPTION' ]) $event -> libelle = dol_nl2br ( $icalevent [ 'DESCRIPTION' ], 1 );
2012-01-22 02:12:11 +01:00
else $event -> libelle = $langs -> trans ( " ExtSiteNoLabel " );
2011-11-01 04:57:45 +01:00
2012-01-22 02:12:11 +01:00
$event -> date_start_in_calendar = $event -> datep ;
2011-06-11 00:05:07 +02:00
if ( $event -> datef != '' && $event -> datef >= $event -> datep ) $event -> date_end_in_calendar = $event -> datef ;
else $event -> date_end_in_calendar = $event -> datep ;
// Define ponctual property
if ( $event -> date_start_in_calendar == $event -> date_end_in_calendar )
{
$event -> ponctuel = 1 ;
2012-01-22 02:12:11 +01:00
//print 'x'.$datestart.'-'.$dateend;exit;
2011-06-11 00:05:07 +02:00
}
2012-01-21 14:10:22 +01:00
// Add event into $eventarray if date range are ok.
2014-09-28 15:33:13 +02:00
if ( $event -> date_end_in_calendar < $firstdaytoshow || $event -> date_start_in_calendar >= $lastdaytoshow )
2011-06-11 00:05:07 +02:00
{
2012-01-22 02:12:11 +01:00
//print 'x'.$datestart.'-'.$dateend;exit;
//print 'x'.$datestart.'-'.$dateend;exit;
//print 'x'.$datestart.'-'.$dateend;exit;
2011-06-11 00:05:07 +02:00
// This record is out of visible range
}
else
{
if ( $event -> date_start_in_calendar < $firstdaytoshow ) $event -> date_start_in_calendar = $firstdaytoshow ;
2014-09-28 15:33:13 +02:00
if ( $event -> date_end_in_calendar >= $lastdaytoshow ) $event -> date_end_in_calendar = ( $lastdaytoshow - 1 );
2011-06-11 00:05:07 +02:00
// Add an entry in actionarray for each day
$daycursor = $event -> date_start_in_calendar ;
$annee = date ( 'Y' , $daycursor );
$mois = date ( 'm' , $daycursor );
$jour = date ( 'd' , $daycursor );
// Loop on each day covered by action to prepare an index to show on calendar
$loop = true ; $j = 0 ;
// daykey must be date that represent day box in calendar so must be a user time
$daykey = dol_mktime ( 0 , 0 , 0 , $mois , $jour , $annee );
2012-02-05 15:13:31 +01:00
$daykeygmt = dol_mktime ( 0 , 0 , 0 , $mois , $jour , $annee , true , 0 );
2011-06-11 00:05:07 +02:00
do
2015-12-04 20:51:34 +01:00
{
2011-06-11 00:05:07 +02:00
//if ($event->fulldayevent) print dol_print_date($daykeygmt,'dayhour','gmt').'-'.dol_print_date($daykey,'dayhour','gmt').'-'.dol_print_date($event->date_end_in_calendar,'dayhour','gmt').' ';
$eventarray [ $daykey ][] = $event ;
$daykey += 60 * 60 * 24 ; $daykeygmt += 60 * 60 * 24 ; // Add one day
if (( $event -> fulldayevent ? $daykeygmt : $daykey ) > $event -> date_end_in_calendar ) $loop = false ;
}
while ( $loop );
}
}
}
}
}
2011-05-31 18:50:54 +02:00
}
2015-06-30 17:09:52 +02:00
// Complete $eventarray with events coming from external module
$parameters = array (); $object = null ;
$reshook = $hookmanager -> executeHooks ( 'getCalendarEvents' , $parameters , $object , $action );
2017-03-02 20:16:12 +01:00
if ( ! empty ( $hookmanager -> resArray [ 'eventarray' ])) {
foreach ( $hookmanager -> resArray [ 'eventarray' ] as $keyDate => $events ) {
if ( ! isset ( $eventarray [ $keyDate ])) {
$eventarray [ $keyDate ] = array ();
}
$eventarray [ $keyDate ] = array_merge ( $eventarray [ $keyDate ], $events );
}
}
2015-06-30 17:09:52 +02:00
2016-06-06 15:13:55 +02:00
$maxnbofchar = 0 ;
2010-11-19 23:36:49 +01:00
$cachethirdparties = array ();
2011-03-25 20:26:35 +01:00
$cachecontacts = array ();
2014-10-18 15:35:32 +02:00
$cacheusers = array ();
2010-11-19 23:36:49 +01:00
2008-04-16 03:04:12 +02:00
// Define theme_datacolor array
$color_file = DOL_DOCUMENT_ROOT . " /theme/ " . $conf -> theme . " /graph-color.php " ;
if ( is_readable ( $color_file ))
{
2012-08-23 02:04:35 +02:00
include_once $color_file ;
2008-04-16 03:04:12 +02:00
}
if ( ! is_array ( $theme_datacolor )) $theme_datacolor = array ( array ( 120 , 130 , 150 ), array ( 200 , 160 , 180 ), array ( 190 , 190 , 220 ));
2008-09-28 05:39:39 +02:00
2011-06-11 00:05:07 +02:00
if ( empty ( $action ) || $action == 'show_month' ) // View by month
2008-03-02 19:47:42 +01:00
{
2011-03-20 15:38:54 +01:00
$newparam = $param ; // newparam is for birthday links
2012-08-20 14:14:01 +02:00
$newparam = preg_replace ( '/showbirthday=/i' , 'showbirthday_=' , $newparam ); // To avoid replacement when replace day= is done
2011-03-20 15:38:54 +01:00
$newparam = preg_replace ( '/action=show_month&?/i' , '' , $newparam );
$newparam = preg_replace ( '/action=show_week&?/i' , '' , $newparam );
2012-08-20 14:14:01 +02:00
$newparam = preg_replace ( '/day=[0-9]+&?/i' , '' , $newparam );
$newparam = preg_replace ( '/month=[0-9]+&?/i' , '' , $newparam );
2011-03-20 15:38:54 +01:00
$newparam = preg_replace ( '/year=[0-9]+&?/i' , '' , $newparam );
2013-06-18 22:12:17 +02:00
$newparam = preg_replace ( '/viewcal=[0-9]+&?/i' , '' , $newparam );
2012-08-20 14:14:01 +02:00
$newparam = preg_replace ( '/showbirthday_=/i' , 'showbirthday=' , $newparam ); // Restore correct parameter
2013-06-18 22:12:17 +02:00
$newparam .= '&viewcal=1' ;
2017-12-01 12:01:17 +01:00
print '<div class="div-table-responsive-no-min">' ;
print '<table width="100%" class="noborder nocellnopadd cal_pannel cal_month">' ;
print ' <tr class="liste_titre">' ;
2011-06-11 00:05:07 +02:00
$i = 0 ;
while ( $i < 7 )
{
2016-11-06 12:16:10 +01:00
print ' <td align="center">' ;
$numdayinweek = (( $i + ( isset ( $conf -> global -> MAIN_START_WEEK ) ? $conf -> global -> MAIN_START_WEEK : 1 )) % 7 );
if ( ! empty ( $conf -> dol_optimize_smallscreen ))
{
$labelshort = array ( 0 => 'SundayMin' , 1 => 'MondayMin' , 2 => 'TuesdayMin' , 3 => 'WednesdayMin' , 4 => 'ThursdayMin' , 5 => 'FridayMin' , 6 => 'SaturdayMin' );
print $langs -> trans ( $labelshort [ $numdayinweek ]);
}
else print $langs -> trans ( " Day " . $numdayinweek );
2017-04-01 00:35:05 +02:00
print ' </td>' . " \n " ;
2011-06-11 00:05:07 +02:00
$i ++ ;
}
2017-04-01 00:35:05 +02:00
echo ' </tr>' . " \n " ;
2011-06-11 00:05:07 +02:00
2012-02-13 02:46:30 +01:00
$todayarray = dol_getdate ( $now , 'fast' );
$todaytms = dol_mktime ( 0 , 0 , 0 , $todayarray [ 'mon' ], $todayarray [ 'mday' ], $todayarray [ 'year' ]);
2011-06-11 00:05:07 +02:00
// In loops, tmpday contains day nb in current month (can be zero or negative for days of previous month)
//var_dump($eventarray);
2012-02-13 02:46:30 +01:00
for ( $iter_week = 0 ; $iter_week < 6 ; $iter_week ++ )
2011-06-11 00:05:07 +02:00
{
echo " <tr> \n " ;
2012-02-13 02:46:30 +01:00
for ( $iter_day = 0 ; $iter_day < 7 ; $iter_day ++ )
2011-06-11 00:05:07 +02:00
{
2014-10-14 00:27:23 +02:00
/* Show days before the beginning of the current month (previous month) */
2012-02-13 02:46:30 +01:00
if ( $tmpday <= 0 )
2011-06-11 00:05:07 +02:00
{
2012-02-13 02:46:30 +01:00
$style = 'cal_other_month cal_past' ;
2013-02-19 13:24:32 +01:00
if ( $iter_day == 6 ) $style .= ' cal_other_month_right' ;
2013-04-25 01:13:13 +02:00
echo ' <td class="' . $style . ' nowrap" width="14%" valign="top">' ;
2012-01-22 20:16:11 +01:00
show_day_events ( $db , $max_day_in_prev_month + $tmpday , $prev_month , $prev_year , $month , $style , $eventarray , $maxprint , $maxnbofchar , $newparam );
2011-06-11 00:05:07 +02:00
echo " </td> \n " ;
}
/* Show days of the current month */
2012-02-13 02:46:30 +01:00
elseif ( $tmpday <= $max_day_in_month )
2011-06-11 00:05:07 +02:00
{
2012-01-08 00:15:36 +01:00
$curtime = dol_mktime ( 0 , 0 , 0 , $month , $tmpday , $year );
2011-06-11 00:05:07 +02:00
$style = 'cal_current_month' ;
2013-02-19 13:24:32 +01:00
if ( $iter_day == 6 ) $style .= ' cal_current_month_right' ;
2011-06-11 05:23:42 +02:00
$today = 0 ;
if ( $todayarray [ 'mday' ] == $tmpday && $todayarray [ 'mon' ] == $month && $todayarray [ 'year' ] == $year ) $today = 1 ;
if ( $today ) $style = 'cal_today' ;
2012-02-13 02:46:30 +01:00
if ( $curtime < $todaytms ) $style .= ' cal_past' ;
2014-10-14 00:27:23 +02:00
//var_dump($todayarray['mday']."==".$tmpday." && ".$todayarray['mon']."==".$month." && ".$todayarray['year']."==".$year.' -> '.$style);
2013-04-25 01:13:13 +02:00
echo ' <td class="' . $style . ' nowrap" width="14%" valign="top">' ;
2012-01-22 20:16:11 +01:00
show_day_events ( $db , $tmpday , $month , $year , $month , $style , $eventarray , $maxprint , $maxnbofchar , $newparam );
2011-06-11 00:05:07 +02:00
echo " </td> \n " ;
}
/* Show days after the current month (next month) */
else
2014-10-14 00:27:23 +02:00
{
2011-06-11 00:05:07 +02:00
$style = 'cal_other_month' ;
2013-02-19 13:24:32 +01:00
if ( $iter_day == 6 ) $style .= ' cal_other_month_right' ;
2013-04-25 01:13:13 +02:00
echo ' <td class="' . $style . ' nowrap" width="14%" valign="top">' ;
2012-01-22 20:16:11 +01:00
show_day_events ( $db , $tmpday - $max_day_in_month , $next_month , $next_year , $month , $style , $eventarray , $maxprint , $maxnbofchar , $newparam );
2011-06-11 00:05:07 +02:00
echo " </td> \n " ;
}
$tmpday ++ ;
}
echo " </tr> \n " ;
}
2017-12-01 12:01:17 +01:00
print " </table> \n " ;
print '</div>' ;
2017-11-25 00:12:45 +01:00
2017-12-01 12:01:17 +01:00
print '<input type="hidden" name="actionmove" value="mupdate">' ;
print '<input type="hidden" name="backtopage" value="' . dol_escape_htmltag ( $_SERVER [ 'PHP_SELF' ]) . '?' . dol_escape_htmltag ( $_SERVER [ 'QUERY_STRING' ]) . '">' ;
print '<input type="hidden" name="newdate" id="newdate">' ;
2008-08-30 00:40:36 +02:00
}
2011-03-09 02:35:25 +01:00
elseif ( $action == 'show_week' ) // View by week
2011-03-08 20:39:21 +01:00
{
2011-03-20 15:38:54 +01:00
$newparam = $param ; // newparam is for birthday links
2012-08-20 14:14:01 +02:00
$newparam = preg_replace ( '/showbirthday=/i' , 'showbirthday_=' , $newparam ); // To avoid replacement when replace day= is done
2011-03-20 15:38:54 +01:00
$newparam = preg_replace ( '/action=show_month&?/i' , '' , $newparam );
$newparam = preg_replace ( '/action=show_week&?/i' , '' , $newparam );
2012-08-20 14:14:01 +02:00
$newparam = preg_replace ( '/day=[0-9]+&?/i' , '' , $newparam );
$newparam = preg_replace ( '/month=[0-9]+&?/i' , '' , $newparam );
2011-03-20 15:38:54 +01:00
$newparam = preg_replace ( '/year=[0-9]+&?/i' , '' , $newparam );
2013-06-18 22:12:17 +02:00
$newparam = preg_replace ( '/viewweek=[0-9]+&?/i' , '' , $newparam );
2012-08-20 14:14:01 +02:00
$newparam = preg_replace ( '/showbirthday_=/i' , 'showbirthday=' , $newparam ); // Restore correct parameter
2013-06-18 22:12:17 +02:00
$newparam .= '&viewweek=1' ;
2017-12-01 12:01:17 +01:00
print '<div class="div-table-responsive-no-min">' ;
print '<table width="100%" class="noborder nocellnopadd cal_pannel cal_month">' ;
print ' <tr class="liste_titre">' ;
2011-06-11 00:05:07 +02:00
$i = 0 ;
while ( $i < 7 )
{
echo ' <td align="center">' . $langs -> trans ( " Day " . (( $i + ( isset ( $conf -> global -> MAIN_START_WEEK ) ? $conf -> global -> MAIN_START_WEEK : 1 )) % 7 )) . " </td> \n " ;
$i ++ ;
}
echo " </tr> \n " ;
echo " <tr> \n " ;
2014-09-05 15:10:31 +02:00
for ( $iter_day = 0 ; $iter_day < 7 ; $iter_day ++ )
2011-06-11 00:05:07 +02:00
{
2014-09-05 15:10:31 +02:00
// Show days of the current week
$curtime = dol_time_plus_duree ( $firstdaytoshow , $iter_day , 'd' );
2014-09-18 15:28:56 +02:00
$tmparray = dol_getdate ( $curtime , true );
2014-09-05 15:10:31 +02:00
$tmpday = $tmparray [ 'mday' ];
$tmpmonth = $tmparray [ 'mon' ];
$tmpyear = $tmparray [ 'year' ];
$style = 'cal_current_month' ;
if ( $iter_day == 6 ) $style .= ' cal_other_month_right' ;
$today = 0 ;
$todayarray = dol_getdate ( $now , 'fast' );
if ( $todayarray [ 'mday' ] == $tmpday && $todayarray [ 'mon' ] == $tmpmonth && $todayarray [ 'year' ] == $tmpyear ) $today = 1 ;
if ( $today ) $style = 'cal_today' ;
2014-09-09 12:28:35 +02:00
echo ' <td class="' . $style . '" width="14%" valign="top">' ;
2014-09-05 15:10:31 +02:00
show_day_events ( $db , $tmpday , $tmpmonth , $tmpyear , $month , $style , $eventarray , 0 , $maxnbofchar , $newparam , 1 , 300 );
echo " </td> \n " ;
2011-06-11 00:05:07 +02:00
}
echo " </tr> \n " ;
2017-12-01 12:01:17 +01:00
print " </table> \n " ;
print '</div>' ;
2017-11-25 00:12:45 +01:00
echo '<input type="hidden" name="actionmove" value="mupdate">' ;
2017-06-18 21:13:48 +02:00
echo '<input type="hidden" name="backtopage" value="' . dol_escape_htmltag ( $_SERVER [ 'PHP_SELF' ]) . '?' . dol_escape_htmltag ( $_SERVER [ 'QUERY_STRING' ]) . '">' ;
2014-08-08 14:25:14 +02:00
echo '<input type="hidden" name="newdate" id="newdate">' ;
2011-03-08 20:39:21 +01:00
}
2011-06-11 00:05:07 +02:00
else // View by day
2008-08-30 00:40:36 +02:00
{
2011-03-20 15:38:54 +01:00
$newparam = $param ; // newparam is for birthday links
$newparam = preg_replace ( '/action=show_month&?/i' , '' , $newparam );
$newparam = preg_replace ( '/action=show_week&?/i' , '' , $newparam );
2013-06-18 22:12:17 +02:00
$newparam = preg_replace ( '/viewday=[0-9]+&?/i' , '' , $newparam );
$newparam .= '&viewday=1' ;
2011-03-20 15:38:54 +01:00
// Code to show just one day
2014-06-27 20:50:46 +02:00
$style = 'cal_current_month cal_current_month_oneday' ;
2011-06-11 05:31:14 +02:00
$today = 0 ;
$todayarray = dol_getdate ( $now , 'fast' );
if ( $todayarray [ 'mday' ] == $day && $todayarray [ 'mon' ] == $month && $todayarray [ 'year' ] == $year ) $today = 1 ;
2014-10-17 13:09:18 +02:00
//if ($today) $style='cal_today';
2011-06-11 05:31:14 +02:00
2011-06-11 00:05:07 +02:00
$timestamp = dol_mktime ( 12 , 0 , 0 , $month , $day , $year );
2011-12-12 01:39:55 +01:00
$arraytimestamp = dol_getdate ( $timestamp );
2017-12-01 12:01:17 +01:00
2018-03-07 11:53:30 +01:00
//echo '<table class="tagtable centpercent noborder nocellnopadd cal_pannel cal_month">';
echo '<table class="tagtable centpercent noborder nocellnopadd cal_pannel cal_month noborderbottom" style="margin-bottom: 5px !important;">' ;
echo ' <tr class="tagtr liste_titre">' ;
echo ' <td class="tagtd width100"></td>' ;
echo ' <td class="tagtd center">' . $langs -> trans ( " Day " . $arraytimestamp [ 'wday' ]) . " </td> \n " ;
echo " </td> \n " ;
/*
echo ' <div class="tagtr">' ;
echo ' <div class="tagtd width100"></div>' ;
echo ' <div class="tagtd center">' ;
echo show_day_events ( $db , $day , $month , $year , $month , $style , $eventarray , 0 , $maxnbofchar , $newparam , 1 , 300 , - 1 );
echo ' </div>' . " \n " ;
echo " </div> \n " ;
*/
2011-06-11 00:05:07 +02:00
echo '</table>' ;
2018-03-07 11:53:30 +01:00
/* WIP View per hour */
$useviewhour = 0 ;
if ( $useviewhour )
{
print '<div class="div-table-responsive-no-min borderbottom">' ; // You can use div-table-responsive-no-min if you dont need reserved height for your table
$maxheightwin = ( isset ( $_SESSION [ " dol_screenheight " ]) && $_SESSION [ " dol_screenheight " ] > 500 ) ? ( $_SESSION [ " dol_screenheight " ] - 200 ) : 660 ; // Also into index.php file
echo '<div style="max-height: ' . $maxheightwin . 'px;">' ;
echo '<div class="tagtable centpercent calendarviewcontainer">' ;
$maxnbofchar = 80 ;
$tmp = explode ( '-' , $conf -> global -> MAIN_DEFAULT_WORKING_HOURS );
$minhour = round ( $tmp [ 0 ], 0 );
$maxhour = round ( $tmp [ 1 ], 0 );
if ( $minhour > 23 ) $minhour = 23 ;
if ( $maxhour < 1 ) $maxhour = 1 ;
if ( $maxhour <= $minhour ) { $maxhour = $minhour + 1 ; }
$i = 0 ;
$j = 0 ;
while ( $i < 24 )
{
echo ' <div class="tagtr calendarviewcontainertr">' . " \n " ;
echo ' <div class="tagtd width100 tdtop">' . dol_print_date ( $i * 3600 , 'hour' , 'gmt' ) . '</div>' ;
echo ' <div class="tagtd ' . $style . ' tdtop">' ;
echo " </div> \n " ;
echo " </div> \n " ;
$i ++ ;
$j ++ ;
}
echo '</div></div>' ;
show_day_events ( $db , $day , $month , $year , $month , $style , $eventarray , 0 , $maxnbofchar , $newparam , 1 , 300 , 1 );
print '</div>' ;
}
else
{
print '<div class="div-table-responsive-no-min">' ; // You can use div-table-responsive-no-min if you dont need reserved height for your table
show_day_events ( $db , $day , $month , $year , $month , $style , $eventarray , 0 , $maxnbofchar , $newparam , 1 , 300 , 0 );
print '</div>' ;
}
2008-03-02 19:47:42 +01:00
}
2008-02-26 19:34:53 +01:00
2017-11-25 00:12:45 +01:00
print " \n " . '</form>' ;
2011-08-27 16:24:16 +02:00
llxFooter ();
2008-03-02 19:47:42 +01:00
2014-07-11 13:55:15 +02:00
$db -> close ();
2008-03-20 20:07:21 +01:00
2008-08-30 00:40:36 +02:00
/**
2010-07-22 01:45:08 +02:00
* Show event of a particular day
2012-01-08 00:15:36 +01:00
*
* @ param DoliDB $db Database handler
* @ param int $day Day
* @ param int $month Month
* @ param int $year Year
* @ param int $monthshown Current month shown in calendar view
* @ param string $style Style to use for this day
2014-10-18 15:35:32 +02:00
* @ param array $eventarray Array of events
2012-01-22 20:16:11 +01:00
* @ param int $maxprint Nb of actions to show each day on month view ( 0 means no limit )
2012-01-08 00:15:36 +01:00
* @ param int $maxnbofchar Nb of characters to show for event line
* @ param string $newparam Parameters on current URL
2014-09-09 12:28:35 +02:00
* @ param int $showinfo Add extended information ( used by day and week view )
2012-01-08 00:15:36 +01:00
* @ param int $minheight Minimum height for each event . 60 px by default .
2018-03-07 11:53:30 +01:00
* @ param string $nonew 0 = Add " new entry button " , 1 = No " new entry button " , - 1 = Only " new entry button "
2012-01-08 00:52:07 +01:00
* @ return void
2008-08-30 00:40:36 +02:00
*/
2018-03-07 11:53:30 +01:00
function show_day_events ( $db , $day , $month , $year , $monthshown , $style , & $eventarray , $maxprint = 0 , $maxnbofchar = 16 , $newparam = '' , $showinfo = 0 , $minheight = 60 , $nonew = 0 )
2008-03-02 19:47:42 +01:00
{
2011-06-11 00:05:07 +02:00
global $user , $conf , $langs ;
2018-11-30 23:25:44 +01:00
global $action , $filter , $filtert , $status , $actioncode , $usergroup ; // Filters used into search form
2011-06-11 00:05:07 +02:00
global $theme_datacolor ;
2014-10-18 15:35:32 +02:00
global $cachethirdparties , $cachecontacts , $cacheusers , $colorindexused ;
2011-06-11 00:05:07 +02:00
2017-04-01 00:35:05 +02:00
$dateint = sprintf ( " %04d " , $year ) . sprintf ( " %02d " , $month ) . sprintf ( " %02d " , $day );
2017-06-18 21:13:48 +02:00
2017-04-01 00:35:05 +02:00
print " \n " ;
2014-09-09 12:28:35 +02:00
// Line with title of day
2012-01-08 00:15:36 +01:00
$curtime = dol_mktime ( 0 , 0 , 0 , $month , $day , $year );
2017-04-01 00:35:05 +02:00
print '<div id="dayevent_' . $dateint . '" class="dayevent tagtable centpercent nobordernopadding">' . " \n " ;
2015-01-25 17:49:11 +01:00
2018-03-07 11:53:30 +01:00
if ( $nonew <= 0 )
2011-06-11 00:05:07 +02:00
{
2018-03-07 11:53:30 +01:00
print '<div class="tagtr"><div class="nowrap float">' ;
print '<a style="color: #666" href="' . DOL_URL_ROOT . '/comm/action/index.php?' ;
print 'action=show_day&day=' . str_pad ( $day , 2 , " 0 " , STR_PAD_LEFT ) . '&month=' . str_pad ( $month , 2 , " 0 " , STR_PAD_LEFT ) . '&year=' . $year ;
print $newparam ;
print '">' ;
if ( $showinfo ) print dol_print_date ( $curtime , 'daytextshort' );
else print dol_print_date ( $curtime , '%d' );
print '</a>' ;
print '</div><div class="floatright nowrap">' ;
if ( $user -> rights -> agenda -> myactions -> create || $user -> rights -> agenda -> allactions -> create )
{
$newparam .= '&month=' . str_pad ( $month , 2 , " 0 " , STR_PAD_LEFT ) . '&year=' . $year ;
//$param='month='.$monthshown.'&year='.$year;
$hourminsec = '100000' ;
print '<a href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create&datep=' . sprintf ( " %04d%02d%02d " , $year , $month , $day ) . $hourminsec . '&backtopage=' . urlencode ( $_SERVER [ " PHP_SELF " ] . ( $newparam ? '?' . $newparam : '' )) . '">' ;
print img_picto ( $langs -> trans ( " NewAction " ), 'edit_add.png' );
print '</a>' ;
}
print '</div></div>' . " \n " ;
}
2013-06-18 22:12:17 +02:00
2018-03-07 11:53:30 +01:00
if ( $nonew < 0 )
{
print '</div>' ;
return ;
2011-06-11 00:05:07 +02:00
}
2014-09-09 12:28:35 +02:00
// Line with td contains all div of each events
2017-04-01 00:35:05 +02:00
print '<div class="tagtr">' ;
print '<div class="tagtd centpercent agendacell sortable">' ;
2011-06-11 00:05:07 +02:00
//$curtime = dol_mktime (0, 0, 0, $month, $day, $year);
2017-11-25 00:12:45 +01:00
$i = 0 ; $numother = 0 ; $numbirthday = 0 ; $numical = 0 ; $numicals = array ();
2012-01-22 20:16:11 +01:00
$ymd = sprintf ( " %04d " , $year ) . sprintf ( " %02d " , $month ) . sprintf ( " %02d " , $day );
2011-06-11 00:05:07 +02:00
2017-11-25 00:12:45 +01:00
$colorindexused [ $user -> id ] = 0 ; // Color index for current user (user->id) is always 0
2018-07-09 10:05:53 +02:00
$nextindextouse = is_array ( $colorindexused ) ? count ( $colorindexused ) : 0 ; // At first run this is 0, so fist user has 0, next 1, ...
2017-11-25 00:12:45 +01:00
//var_dump($colorindexused);
2013-04-11 10:15:53 +02:00
2011-06-11 00:05:07 +02:00
foreach ( $eventarray as $daykey => $notused )
{
$annee = date ( 'Y' , $daykey );
$mois = date ( 'm' , $daykey );
$jour = date ( 'd' , $daykey );
if ( $day == $jour && $month == $mois && $year == $annee )
{
foreach ( $eventarray [ $daykey ] as $index => $event )
{
2012-01-22 20:16:11 +01:00
if ( $i < $maxprint || $maxprint == 0 || ! empty ( $conf -> global -> MAIN_JS_SWITCH_AGENDA ))
2011-06-11 00:05:07 +02:00
{
2017-04-01 00:35:05 +02:00
$keysofuserassigned = array_keys ( $event -> userassigned );
2015-12-19 10:29:56 +01:00
$ponct = ( $event -> date_start_in_calendar == $event -> date_end_in_calendar );
2012-01-22 13:10:59 +01:00
2014-09-29 13:21:03 +02:00
// Define $color (Hex string like '0088FF') and $cssclass of event
2017-11-25 00:12:45 +01:00
$color =- 1 ; $cssclass = '' ; $colorindex =- 1 ;
2017-04-01 00:35:05 +02:00
if ( in_array ( $user -> id , $keysofuserassigned ))
{
2017-11-25 00:12:45 +01:00
$cssclass = 'family_mytasks' ;
if ( empty ( $cacheusers [ $event -> userownerid ]))
{
$newuser = new User ( $db );
$newuser -> fetch ( $event -> userownerid );
$cacheusers [ $event -> userownerid ] = $newuser ;
}
//var_dump($cacheusers[$event->userownerid]->color);
// We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
if ( ! empty ( $cacheusers [ $event -> userownerid ] -> color )) $color = $cacheusers [ $event -> userownerid ] -> color ;
2012-11-13 14:44:32 +01:00
}
2015-09-26 13:49:36 +02:00
else if ( $event -> type_code == 'ICALEVENT' ) // Event come from external ical file
2013-04-11 10:15:53 +02:00
{
2012-11-13 14:44:32 +01:00
$numical ++ ;
if ( ! empty ( $event -> icalname )) {
if ( ! isset ( $numicals [ dol_string_nospecial ( $event -> icalname )])) {
$numicals [ dol_string_nospecial ( $event -> icalname )] = 0 ;
}
$numicals [ dol_string_nospecial ( $event -> icalname )] ++ ;
}
2017-11-25 00:12:45 +01:00
2015-12-19 10:29:56 +01:00
$color = ( $event -> icalcolor ? $event -> icalcolor :- 1 );
2015-09-26 13:49:36 +02:00
$cssclass = ( ! empty ( $event -> icalname ) ? 'family_ext' . md5 ( $event -> icalname ) : 'family_other' );
2012-11-13 14:44:32 +01:00
}
2014-09-29 13:21:03 +02:00
else if ( $event -> type_code == 'BIRTHDAY' )
{
2015-01-25 17:49:11 +01:00
$numbirthday ++ ; $colorindex = 2 ; $cssclass = 'family_birthday unmovable' ; $color = sprintf ( " %02x%02x%02x " , $theme_datacolor [ $colorindex ][ 0 ], $theme_datacolor [ $colorindex ][ 1 ], $theme_datacolor [ $colorindex ][ 2 ]);
2014-09-29 13:21:03 +02:00
}
else
2015-12-19 10:29:56 +01:00
{
2017-06-18 21:13:48 +02:00
$numother ++ ;
2016-06-06 15:13:55 +02:00
$color = ( $event -> icalcolor ? $event -> icalcolor :- 1 );
$cssclass = ( ! empty ( $event -> icalname ) ? 'family_ext' . md5 ( $event -> icalname ) : 'family_other' );
2017-06-18 21:13:48 +02:00
2016-06-06 15:13:55 +02:00
if ( empty ( $cacheusers [ $event -> userownerid ]))
{
$newuser = new User ( $db );
$newuser -> fetch ( $event -> userownerid );
$cacheusers [ $event -> userownerid ] = $newuser ;
}
//var_dump($cacheusers[$event->userownerid]->color);
2017-06-18 21:13:48 +02:00
2016-06-06 15:13:55 +02:00
// We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
if ( ! empty ( $cacheusers [ $event -> userownerid ] -> color )) $color = $cacheusers [ $event -> userownerid ] -> color ;
2015-12-19 10:29:56 +01:00
}
2017-11-25 00:12:45 +01:00
if ( $color < 0 ) // Color was not set on user card. Set color according to color index.
2013-04-11 10:15:53 +02:00
{
// Define color index if not yet defined
2014-09-26 12:27:18 +02:00
$idusertouse = ( $event -> userownerid ? $event -> userownerid : 0 );
2013-06-05 16:24:32 +02:00
if ( isset ( $colorindexused [ $idusertouse ]))
{
$colorindex = $colorindexused [ $idusertouse ]; // Color already assigned to this user
}
else
{
2017-11-25 00:12:45 +01:00
$colorindex = $nextindextouse ;
$colorindexused [ $idusertouse ] = $colorindex ;
2013-06-05 16:24:32 +02:00
if ( ! empty ( $theme_datacolor [ $nextindextouse + 1 ])) $nextindextouse ++ ; // Prepare to use next color
}
//print '|'.($color).'='.($idusertouse?$idusertouse:0).'='.$colorindex.'<br>';
2016-06-06 15:13:55 +02:00
// Define color
2013-04-11 10:15:53 +02:00
$color = sprintf ( " %02x%02x%02x " , $theme_datacolor [ $colorindex ][ 0 ], $theme_datacolor [ $colorindex ][ 1 ], $theme_datacolor [ $colorindex ][ 2 ]);
2015-12-19 10:29:56 +01:00
}
2012-01-22 20:16:11 +01:00
$cssclass = $cssclass . ' ' . $cssclass . '_day_' . $ymd ;
2011-06-11 00:05:07 +02:00
2014-08-14 00:57:59 +02:00
// Defined style to disable drag and drop feature
2015-01-25 17:49:11 +01:00
if ( $event -> type_code == 'AC_OTH_AUTO' )
{
$cssclass .= " unmovable " ;
}
2015-09-26 13:49:36 +02:00
else if ( $event -> type_code == 'ICALEVENT' )
{
$cssclass .= " unmovable " ;
}
2015-01-25 17:49:11 +01:00
else if ( $event -> date_end_in_calendar && date ( 'Ymd' , $event -> date_start_in_calendar ) != date ( 'Ymd' , $event -> date_end_in_calendar ))
2014-08-08 14:25:14 +02:00
{
2014-08-18 10:27:35 +02:00
$tmpyearend = date ( 'Y' , $event -> date_end_in_calendar );
$tmpmonthend = date ( 'm' , $event -> date_end_in_calendar );
$tmpdayend = date ( 'd' , $event -> date_end_in_calendar );
if ( $tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour )
2014-08-08 14:25:14 +02:00
{
2015-01-25 17:49:11 +01:00
$cssclass .= " unmovable " ;
2014-08-08 14:25:14 +02:00
}
}
2017-02-16 07:51:46 +01:00
else {
if ( $user -> rights -> agenda -> allactions -> create ||
(( $event -> authorid == $user -> id || $event -> userownerid == $user -> id ) && $user -> rights -> agenda -> myactions -> create ))
{
2017-03-31 14:21:51 +02:00
$cssclass .= " movable cursormove " ;
2017-02-16 07:51:46 +01:00
} else {
$cssclass .= " unmovable " ;
}
}
2014-08-14 00:57:59 +02:00
2014-09-09 12:28:35 +02:00
$h = '' ; $nowrapontd = 1 ;
if ( $action == 'show_day' ) { $h = 'height: 100%; ' ; $nowrapontd = 0 ; }
if ( $action == 'show_week' ) { $h = 'height: 100%; ' ; $nowrapontd = 0 ; }
2012-01-22 13:10:59 +01:00
// Show rect of event
2015-01-25 17:49:11 +01:00
print " \n " ;
2017-04-01 00:35:05 +02:00
print '<!-- start event ' . $i . ' -->' . " \n " ;
print '<div id="event_' . $ymd . '_' . $i . '" class="event ' . $cssclass . '"' ;
2014-09-09 12:28:35 +02:00
//print ' style="height: 100px;';
//print ' position: absolute; top: 40px; width: 50%;';
//print '"';
print '>' ;
2018-03-07 11:53:30 +01:00
2017-11-24 20:02:46 +01:00
//var_dump($event->userassigned);
//var_dump($event->transparency);
print '<table class="centpercent cal_event' . ( empty ( $event -> transparency ) ? ' cal_event_notbusy' : ' cal_event_busy' ) . '" style="' . $h ;
2017-11-25 00:12:45 +01:00
if ( empty ( $event -> transparency ) && empty ( $conf -> global -> AGENDA_NO_TRANSPARENT_ON_NOT_BUSY ))
2017-11-24 20:02:46 +01:00
{
print 'border: 2px solid #' . $color . ';' ;
}
else
{
print 'background: #' . $color . ';' ;
print 'background: -webkit-gradient(linear, left top, left bottom, from(#' . dol_color_minus ( $color , - 3 ) . '), to(#' . dol_color_minus ( $color , - 1 ) . '));' ;
}
2014-06-28 18:04:32 +02:00
//if (! empty($event->transparency)) print 'background: #'.$color.'; background: -webkit-gradient(linear, left top, left bottom, from(#'.$color.'), to(#'.dol_color_minus($color,1).'));';
//else print 'background-color: transparent !important; background: none; border: 1px solid #bbb;';
2017-04-01 00:35:05 +02:00
//print ' -moz-border-radius:4px;"';
//print 'border: 1px solid #ccc" width="100%"';
print '">' ;
print '<tr>' ;
print '<td class="tdoverflow nobottom centpercent ' . ( $nowrapontd ? 'nowrap ' : '' ) . 'cal_event' . ( $event -> type_code == 'BIRTHDAY' ? ' cal_event_birthday' : '' ) . '">' ;
2017-06-18 21:13:48 +02:00
2017-04-01 00:35:05 +02:00
$daterange = '' ;
2017-06-18 21:13:48 +02:00
2011-06-11 00:05:07 +02:00
if ( $event -> type_code == 'BIRTHDAY' ) // It's a birthday
{
print $event -> getNomUrl ( 1 , $maxnbofchar , 'cal_event' , 'birthday' , 'contact' );
}
if ( $event -> type_code != 'BIRTHDAY' )
{
// Picto
2011-06-11 13:01:11 +02:00
if ( empty ( $event -> fulldayevent ))
2011-02-02 15:41:31 +01:00
{
2011-06-11 13:01:11 +02:00
//print $event->getNomUrl(2).' ';
2011-02-02 15:41:31 +01:00
}
2011-06-11 00:05:07 +02:00
// Date
if ( empty ( $event -> fulldayevent ))
{
// Show hours (start ... end)
$tmpyearstart = date ( 'Y' , $event -> date_start_in_calendar );
$tmpmonthstart = date ( 'm' , $event -> date_start_in_calendar );
$tmpdaystart = date ( 'd' , $event -> date_start_in_calendar );
$tmpyearend = date ( 'Y' , $event -> date_end_in_calendar );
$tmpmonthend = date ( 'm' , $event -> date_end_in_calendar );
$tmpdayend = date ( 'd' , $event -> date_end_in_calendar );
// Hour start
if ( $tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour )
{
2015-07-28 18:12:45 +02:00
$daterange .= dol_print_date ( $event -> date_start_in_calendar , '%H:%M' ); // Il faudrait utiliser ici tzuser, mais si on ne peut pas car qd on rentre un date dans fiche action, en input la conversion local->gmt se base sur le TZ server et non user
2011-06-11 00:05:07 +02:00
if ( $event -> date_end_in_calendar && $event -> date_start_in_calendar != $event -> date_end_in_calendar )
{
if ( $tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend )
$daterange .= '-' ;
//else
//print '...';
}
}
if ( $event -> date_end_in_calendar && $event -> date_start_in_calendar != $event -> date_end_in_calendar )
{
if ( $tmpyearstart != $tmpyearend || $tmpmonthstart != $tmpmonthend || $tmpdaystart != $tmpdayend )
{
$daterange .= '...' ;
}
}
// Hour end
if ( $event -> date_end_in_calendar && $event -> date_start_in_calendar != $event -> date_end_in_calendar )
{
if ( $tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour )
2015-07-28 18:12:45 +02:00
$daterange .= dol_print_date ( $event -> date_end_in_calendar , '%H:%M' ); // Il faudrait utiliser ici tzuser, mais si on ne peut pas car qd on rentre un date dans fiche action, en input la conversion local->gmt se base sur le TZ server et non user
2011-06-11 00:05:07 +02:00
}
}
else
2014-10-20 13:07:54 +02:00
{
2012-01-22 02:12:11 +01:00
if ( $showinfo )
{
2011-06-11 13:01:11 +02:00
print $langs -> trans ( " EventOnFullDay " ) . " <br> \n " ;
2012-01-22 02:12:11 +01:00
}
2011-06-11 00:05:07 +02:00
}
2010-11-20 19:41:09 +01:00
2011-06-11 13:01:11 +02:00
// Show title
2017-04-01 00:35:05 +02:00
$titletoshow = $daterange ;
$titletoshow .= ( $titletoshow ? ' ' : '' ) . $event -> libelle ;
2017-06-18 21:13:48 +02:00
2017-04-01 00:35:05 +02:00
if ( $event -> type_code == 'ICALEVENT' ) print $titletoshow ;
2017-06-18 21:13:48 +02:00
else
2017-04-01 00:35:05 +02:00
{
2018-03-07 11:53:30 +01:00
$savlabel = $event -> label ? $event -> label : $event -> libelle ;
$event -> label = $titletoshow ;
$event -> libelle = $titletoshow ;
print $event -> getNomUrl ( 0 , $maxnbofchar , 'cal_event' , '' , 0 , 1 );
$event -> label = $savlabel ;
$event -> libelle = $savlabel ;
2017-04-01 00:35:05 +02:00
}
2011-06-11 00:05:07 +02:00
2017-04-01 00:35:05 +02:00
// Loop on each assigned user
$listofusertoshow = '' ;
$posuserassigned = 0 ;
foreach ( $event -> userassigned as $tmpid => $tmpdata )
{
if ( ! $posuserassigned && $titletoshow ) $listofusertoshow .= '<br>' ;
$posuserassigned ++ ;
if ( empty ( $cacheusers [ $tmpid ]))
{
$newuser = new User ( $db );
$newuser -> fetch ( $tmpid );
$cacheusers [ $tmpid ] = $newuser ;
}
2017-06-18 21:13:48 +02:00
2018-03-07 11:29:50 +01:00
$listofusertoshow .= $cacheusers [ $tmpid ] -> getNomUrl ( - 3 , '' , 0 , 0 , 0 , 0 , '' , 'paddingright valigntextbottom' );
2017-04-01 00:35:05 +02:00
}
print $listofusertoshow ;
2011-06-11 00:05:07 +02:00
2011-06-11 13:04:42 +02:00
if ( $event -> type_code == 'ICALEVENT' ) print '<br>(' . dol_trunc ( $event -> icalname , $maxnbofchar ) . ')' ;
2011-06-11 13:01:11 +02:00
2011-06-11 00:05:07 +02:00
// If action related to company / contact
2016-06-06 15:13:55 +02:00
$linerelatedto = '' ;
2011-04-08 11:29:15 +02:00
if ( ! empty ( $event -> societe -> id ) && $event -> societe -> id > 0 )
2010-11-19 23:36:49 +01:00
{
2012-07-13 11:40:06 +02:00
if ( ! isset ( $cachethirdparties [ $event -> societe -> id ]) || ! is_object ( $cachethirdparties [ $event -> societe -> id ]))
2010-11-19 23:36:49 +01:00
{
$thirdparty = new Societe ( $db );
2011-02-02 16:51:18 +01:00
$thirdparty -> fetch ( $event -> societe -> id );
$cachethirdparties [ $event -> societe -> id ] = $thirdparty ;
2010-11-19 23:36:49 +01:00
}
2011-03-25 20:33:18 +01:00
else $thirdparty = $cachethirdparties [ $event -> societe -> id ];
2016-06-06 15:13:55 +02:00
if ( ! empty ( $thirdparty -> id )) $linerelatedto .= $thirdparty -> getNomUrl ( 1 , '' , 0 );
2010-11-19 23:36:49 +01:00
}
2011-04-08 11:29:15 +02:00
if ( ! empty ( $event -> contact -> id ) && $event -> contact -> id > 0 )
2010-11-19 23:36:49 +01:00
{
2011-04-08 11:29:15 +02:00
if ( ! is_object ( $cachecontacts [ $event -> contact -> id ]))
2010-11-19 23:36:49 +01:00
{
$contact = new Contact ( $db );
2011-02-02 16:51:18 +01:00
$contact -> fetch ( $event -> contact -> id );
2011-03-25 20:33:18 +01:00
$cachecontacts [ $event -> contact -> id ] = $contact ;
2010-11-19 23:36:49 +01:00
}
2011-03-25 20:33:18 +01:00
else $contact = $cachecontacts [ $event -> contact -> id ];
2010-11-19 23:36:49 +01:00
if ( $linerelatedto ) $linerelatedto .= ' / ' ;
2016-06-06 15:13:55 +02:00
if ( ! empty ( $contact -> id )) $linerelatedto .= $contact -> getNomUrl ( 1 , '' , 0 );
2010-11-19 23:36:49 +01:00
}
2017-05-17 17:00:45 +02:00
if ( ! empty ( $event -> fk_element ) && $event -> fk_element > 0 && ! empty ( $event -> elementtype ) && ! empty ( $conf -> global -> AGENDA_SHOW_LINKED_OBJECT ))
{
include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
if ( $linerelatedto ) $linerelatedto .= ' / ' ;
$linerelatedto .= dolGetElementUrl ( $event -> fk_element , $event -> elementtype , 1 );
}
2011-06-11 00:05:07 +02:00
if ( $linerelatedto ) print '<br>' . $linerelatedto ;
}
// Show location
if ( $showinfo )
{
if ( $event -> location )
{
print '<br>' ;
2011-02-02 16:51:18 +01:00
print $langs -> trans ( " Location " ) . ': ' . $event -> location ;
2011-06-11 00:05:07 +02:00
}
}
print '</td>' ;
2010-11-19 22:24:48 +01:00
// Status - Percent
2017-04-01 00:35:05 +02:00
$withstatus = 0 ;
if ( $event -> type_code != 'BIRTHDAY' && $event -> type_code != 'ICALEVENT' )
{
$withstatus = 1 ;
2017-06-18 21:13:48 +02:00
if ( $event -> percentage >= 0 ) $withstatus = 2 ;
2017-04-01 00:35:05 +02:00
}
print '<td class="nobottom right nowrap cal_event_right' . ( $withstatus >= 2 ? ' cal_event_right_status' : '' ) . '">' ;
if ( $withstatus ) print $event -> getLibStatut ( 3 , 1 );
2011-06-11 00:05:07 +02:00
else print ' ' ;
print '</td></tr></table>' ;
2015-01-25 17:49:11 +01:00
print '</div><!-- end event ' . $i . ' -->' . " \n " ;
2011-06-11 00:05:07 +02:00
$i ++ ;
}
else
{
2014-09-26 12:27:18 +02:00
print '<a href="' . DOL_URL_ROOT . '/comm/action/index.php?action=' . $action . '&maxprint=0&month=' . $monthshown . '&year=' . $year ;
2011-06-11 00:05:07 +02:00
print ( $status ? '&status=' . $status : '' ) . ( $filter ? '&filter=' . $filter : '' );
2015-01-15 02:06:04 +01:00
print ( $filtert ? '&filtert=' . $filtert : '' );
2018-11-30 23:25:44 +01:00
print ( $usergroup ? '&usergroup=' . $usergroup : '' );
2013-10-15 16:42:19 +02:00
print ( $actioncode != '' ? '&actioncode=' . $actioncode : '' );
2011-06-11 00:05:07 +02:00
print '">' . img_picto ( " all " , " 1downarrow_selected.png " ) . ' ...' ;
2012-01-22 20:16:11 +01:00
print ' +' . ( count ( $eventarray [ $daykey ]) - $maxprint );
2011-06-11 00:05:07 +02:00
print '</a>' ;
break ;
//$ok=false; // To avoid to show twice the link
}
}
2012-01-22 20:16:11 +01:00
2011-06-11 00:05:07 +02:00
break ;
}
}
if ( ! $i ) print ' ' ;
2012-01-22 20:16:11 +01:00
if ( ! empty ( $conf -> global -> MAIN_JS_SWITCH_AGENDA ) && $i > $maxprint && $maxprint )
{
print '<div id="more_' . $ymd . '">' . img_picto ( " all " , " 1downarrow_selected.png " ) . ' +' . $langs -> trans ( " More " ) . '...</div>' ;
//print ' +'.(count($eventarray[$daykey])-$maxprint);
print '<script type="text/javascript">' . " \n " ;
print 'jQuery(document).ready(function () {' . " \n " ;
print 'jQuery("#more_' . $ymd . '").click(function() { reinit_day_' . $ymd . '(); });' . " \n " ;
print 'function reinit_day_' . $ymd . '() {' . " \n " ;
print 'var nb=0;' . " \n " ;
// TODO Loop on each element of day $ymd and start to toggle once $maxprint has been reached
print 'jQuery(".family_mytasks_day_' . $ymd . '").toggle();' ;
print '}' . " \n " ;
2014-08-14 00:57:59 +02:00
2012-01-22 20:16:11 +01:00
print '});' . " \n " ;
2014-08-14 00:57:59 +02:00
2012-01-22 20:16:11 +01:00
print '</script>' . " \n " ;
}
2017-04-01 00:35:05 +02:00
print '</div></div>' ; // td tr
2015-01-25 17:49:11 +01:00
2017-04-01 00:35:05 +02:00
print '</div>' ; // table
print " \n " ;
2008-03-02 19:47:42 +01:00
}
2014-09-05 21:12:01 +02:00
2013-04-11 10:15:53 +02:00
/**
* Change color with a delta
*
* @ param string $color Color
2017-10-31 23:57:37 +01:00
* @ param int $minus Delta ( 1 = 16 unit ) . Positive value = darker color , Negative value = brighter color .
2017-03-10 16:26:43 +01:00
* @ param int $minusunit Minus unit
2013-04-11 10:15:53 +02:00
* @ return string New color
*/
2017-03-10 16:26:43 +01:00
function dol_color_minus ( $color , $minus , $minusunit = 16 )
2013-02-15 10:42:35 +01:00
{
$newcolor = $color ;
2017-03-10 16:26:43 +01:00
if ( $minusunit == 16 )
{
$newcolor [ 0 ] = dechex ( max ( min ( hexdec ( $newcolor [ 0 ]) - $minus , 15 ), 0 ));
$newcolor [ 2 ] = dechex ( max ( min ( hexdec ( $newcolor [ 2 ]) - $minus , 15 ), 0 ));
$newcolor [ 4 ] = dechex ( max ( min ( hexdec ( $newcolor [ 4 ]) - $minus , 15 ), 0 ));
}
else
{
// Not yet implemented
}
2013-02-15 10:42:35 +01:00
return $newcolor ;
}