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 >
2013-04-21 12:26:44 +02:00
* Copyright ( C ) 2004 - 2013 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 >
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 ;
2012-02-13 09:51:09 +01:00
$filter = GETPOST ( " filter " , '' , 3 );
$filtera = GETPOST ( " userasked " , " int " , 3 ) ? GETPOST ( " userasked " , " int " , 3 ) : GETPOST ( " filtera " , " int " , 3 );
$filtert = GETPOST ( " usertodo " , " int " , 3 ) ? GETPOST ( " usertodo " , " int " , 3 ) : GETPOST ( " filtert " , " int " , 3 );
$filterd = GETPOST ( " userdone " , " int " , 3 ) ? GETPOST ( " userdone " , " int " , 3 ) : GETPOST ( " filterd " , " int " , 3 );
2012-01-22 20:16:11 +01:00
$showbirthday = empty ( $conf -> use_javascript_ajax ) ? GETPOST ( " showbirthday " , " int " ) : 1 ;
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 " );
2012-01-22 02:12:11 +01:00
if ( $page == - 1 ) { $page = 0 ; }
2003-08-03 14:13:38 +02:00
$limit = $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
2010-11-10 22:41:34 +01:00
$socid = GETPOST ( " socid " , " int " , 1 );
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' );
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
$filtera = $user -> id ;
$filtert = $user -> id ;
$filterd = $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' );
//$year=GETPOST("year");
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 );
2010-11-19 23:36:49 +01:00
$status = GETPOST ( " status " );
2012-07-13 11:40:06 +02:00
$type = GETPOST ( " type " );
2012-01-22 20:16:11 +01:00
$maxprint = ( isset ( $_GET [ " maxprint " ]) ? GETPOST ( " maxprint " ) : $conf -> global -> AGENDA_MAX_EVENTS_DAY_VIEW );
2013-10-15 16:42:19 +02:00
$actioncode = GETPOST ( " actioncode " , " alpha " , 3 ) ? GETPOST ( " actioncode " , " alpha " , 3 ) : ( GETPOST ( " actioncode " ) == '0' ? '0' : ( empty ( $conf -> global -> AGENDA_USE_EVENT_TYPE ) ? 'AC_OTH' : '' ));
2012-01-22 20:16:11 +01:00
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
if ( GETPOST ( 'viewweek' )) {
$action = 'show_week' ; $week = ( $week ? $week : date ( " W " )); $day = ( $day ? $day : date ( " d " ));
} // View by week
if ( GETPOST ( 'viewday' )) {
$action = 'show_day' ; $day = ( $day ? $day : date ( " d " ));
} // View by day
2011-02-02 16:51:18 +01:00
2013-02-20 21:41:50 +01:00
$langs -> load ( " agenda " );
2008-09-28 05:39:39 +02:00
$langs -> load ( " other " );
2010-09-04 02:16:41 +02:00
$langs -> load ( " commercial " );
2008-09-28 05:39:39 +02:00
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
*/
2011-02-02 17:34:43 +01:00
if ( GETPOST ( " viewlist " ))
2008-03-20 21:39:50 +01:00
{
2011-06-11 00:05:07 +02:00
$param = '' ;
foreach ( $_POST as $key => $val )
{
if ( $key == 'token' ) continue ;
$param .= '&' . $key . '=' . urlencode ( $val );
}
//print $param;
header ( " Location: " . DOL_URL_ROOT . '/comm/action/listactions.php?' . $param );
exit ;
2008-03-20 21:39:50 +01:00
}
2005-04-14 01:28:41 +02:00
2008-02-26 19:34:53 +01: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 ();
2008-03-02 19:47:42 +01:00
2012-01-22 20:16:11 +01:00
// Define list of all external calendars
$listofextcals = array ();
if ( empty ( $conf -> global -> AGENDA_DISABLE_EXT ) && $conf -> global -> AGENDA_EXT_NB > 0 )
{
$i = 0 ;
while ( $i < $conf -> global -> AGENDA_EXT_NB )
{
$i ++ ;
2012-07-13 11:40:06 +02:00
$source = 'AGENDA_EXT_SRC' . $i ;
$name = 'AGENDA_EXT_NAME' . $i ;
$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'
$listofextcals [] = array ( 'src' => $conf -> global -> $source , 'name' => $conf -> global -> $name , '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
}
}
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
// tmpday is a negative or null cursor to know how many days before the 1 to show on month view (if tmpday=0 we start on monday)
$tmpday = - date ( " w " , dol_mktime ( 0 , 0 , 0 , $month , 1 , $year )) + 2 ;
$tmpday += (( isset ( $conf -> global -> MAIN_START_WEEK ) ? $conf -> global -> MAIN_START_WEEK : 1 ) - 1 );
if ( $tmpday >= 1 ) $tmpday -= 7 ;
// Define firstdaytoshow and lastdaytoshow
$firstdaytoshow = dol_mktime ( 0 , 0 , 0 , $prev_month , $max_day_in_prev_month + $tmpday , $prev_year );
$next_day = 7 - ( $max_day_in_month + 1 - $tmpday ) % 7 ;
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' ];
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 ;
2011-03-09 17:53:30 +01:00
$next = dol_get_next_week ( $day , $week , $month , $year );
$next_year = $next [ 'year' ];
$next_month = $next [ 'month' ];
$next_day = $next [ 'day' ];
2011-03-20 15:38:54 +01:00
2011-03-09 17:53:30 +01:00
// Define firstdaytoshow and lastdaytoshow
$firstdaytoshow = dol_mktime ( 0 , 0 , 0 , $prev_month , $first_day , $prev_year );
$lastdaytoshow = dol_mktime ( 0 , 0 , 0 , $next_month , $next_day , $next_year );
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' ];
// Define firstdaytoshow and lastdaytoshow
$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 = '' ;
2012-07-13 11:40:06 +02:00
$region = '' ;
2008-09-29 02:17:40 +02:00
if ( $status ) $param = " &status= " . $status ;
if ( $filter ) $param .= " &filter= " . $filter ;
2008-03-20 23:46:52 +01:00
if ( $filtera ) $param .= " &filtera= " . $filtera ;
if ( $filtert ) $param .= " &filtert= " . $filtert ;
if ( $filterd ) $param .= " &filterd= " . $filterd ;
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 ;
2013-10-15 16:42:19 +02:00
if ( $actioncode != '' ) $param .= " &actioncode= " . $actioncode ;
2012-07-13 11:40:06 +02:00
if ( $type ) $param .= " &type= " . $type ;
2011-03-09 02:35:25 +01:00
if ( $action == 'show_day' || $action == 'show_week' ) $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' )
{
$nav = " <a href= \" ?year= " . $prev_year . " &month= " . $prev_month . " &region= " . $region . $param . " \" > " . img_previous ( $langs -> trans ( " Previous " )) . " </a> \n " ;
$nav .= " <span id= \" month_name \" > " . dol_print_date ( dol_mktime ( 0 , 0 , 0 , $month , 1 , $year ), " %b %Y " );
$nav .= " </span> \n " ;
$nav .= " <a href= \" ?year= " . $next_year . " &month= " . $next_month . " &region= " . $region . $param . " \" > " . img_next ( $langs -> trans ( " Next " )) . " </a> \n " ;
2011-05-17 12:16:24 +02:00
$picto = 'calendar' ;
2011-03-08 20:39:21 +01:00
}
if ( $action == 'show_week' )
{
2011-06-11 00:05:07 +02:00
$nav = " <a href= \" ?year= " . $prev_year . " &month= " . $prev_month . " &day= " . $prev_day . " &region= " . $region . $param . " \" > " . img_previous ( $langs -> trans ( " Previous " )) . " </a> \n " ;
$nav .= " <span id= \" month_name \" > " . dol_print_date ( dol_mktime ( 0 , 0 , 0 , $month , 1 , $year ), " %Y " ) . " , " . $langs -> trans ( " Week " ) . " " . $week ;
$nav .= " </span> \n " ;
$nav .= " <a href= \" ?year= " . $next_year . " &month= " . $next_month . " &day= " . $next_day . " &region= " . $region . $param . " \" > " . img_next ( $langs -> trans ( " Next " )) . " </a> \n " ;
$picto = 'calendarweek' ;
2011-02-02 16:51:18 +01:00
}
if ( $action == 'show_day' )
{
$nav = " <a href= \" ?year= " . $prev_year . " &month= " . $prev_month . " &day= " . $prev_day . " &region= " . $region . $param . " \" > " . img_previous ( $langs -> trans ( " Previous " )) . " </a> \n " ;
$nav .= " <span id= \" month_name \" > " . dol_print_date ( dol_mktime ( 0 , 0 , 0 , $month , $day , $year ), " daytextshort " );
$nav .= " </span> \n " ;
$nav .= " <a href= \" ?year= " . $next_year . " &month= " . $next_month . " &day= " . $next_day . " &region= " . $region . $param . " \" > " . img_next ( $langs -> trans ( " Next " )) . " </a> \n " ;
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
$head = calendars_prepare_head ( '' );
2011-05-17 12:16:24 +02:00
dol_fiche_head ( $head , 'card' , $langs -> trans ( 'Events' ), 0 , $picto );
2013-04-21 12:26:44 +02:00
print_actions_filter ( $form , $canedit , $status , $year , $month , $day , $showbirthday , $filtera , $filtert , $filterd , $pid , $socid , $listofextcals , $actioncode );
2011-05-16 19:27:20 +02:00
dol_fiche_end ();
2012-01-22 20:16:11 +01:00
$link = '' ;
2011-05-16 19:27:20 +02:00
// Add link to show birthdays
2012-01-22 20:16:11 +01:00
if ( empty ( $conf -> use_javascript_ajax ))
{
$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' ;
$link = '<a href="' . $_SERVER [ 'PHP_SELF' ];
$link .= '?' . $newparam ;
$link .= '">' ;
if ( empty ( $showbirthday )) $link .= $langs -> trans ( " AgendaShowBirthdayEvents " );
else $link .= $langs -> trans ( " AgendaHideBirthdayEvents " );
$link .= '</a>' ;
}
2011-05-16 19:27:20 +02:00
2011-06-11 04:25:05 +02:00
print_fiche_titre ( $title , $link . ' ' . $nav , '' );
2008-03-20 20:07:21 +01:00
// Get event in an array
2011-02-02 16:51:18 +01:00
$eventarray = array ();
2008-09-28 05:39:39 +02:00
2008-03-20 20:07:21 +01:00
$sql = 'SELECT a.id,a.label,' ;
2010-11-19 23:36:49 +01:00
$sql .= ' a.datep,' ;
$sql .= ' a.datep2,' ;
$sql .= ' a.datea,' ;
$sql .= ' a.datea2,' ;
2008-04-16 03:04:12 +02:00
$sql .= ' a.percent,' ;
2008-09-28 05:39:39 +02:00
$sql .= ' a.fk_user_author,a.fk_user_action,a.fk_user_done,' ;
2010-11-20 19:41:09 +01:00
$sql .= ' a.priority, a.fulldayevent, a.location,' ;
2010-11-19 23:36:49 +01:00
$sql .= ' a.fk_soc, a.fk_contact,' ;
2008-09-28 05:39:39 +02:00
$sql .= ' ca.code' ;
2013-01-10 08:27:12 +01:00
$sql .= ' FROM (' . MAIN_DB_PREFIX . 'c_actioncomm as ca,' ;
$sql .= " " . MAIN_DB_PREFIX . " actioncomm as a) " ;
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe_commerciaux as sc ON a.fk_soc = sc.fk_soc " ;
$sql .= ' WHERE a.fk_action = ca.id' ;
2014-03-22 18:59:48 +01:00
$sql .= ' AND a.entity IN (' . getEntity ( 'agenda' , 1 ) . ')' ;
2013-01-10 08:27:12 +01:00
if ( $actioncode ) $sql .= " AND ca.code=' " . $db -> escape ( $actioncode ) . " ' " ;
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 . " ) " ;
2012-02-13 02:00:03 +01:00
if ( $user -> societe_id ) $sql .= ' AND a.fk_soc = ' . $user -> societe_id ; // To limit to external user company
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 ;
2012-02-13 02:00:03 +01:00
if ( $status == 'done' ) { $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep2 <= ' " . $db -> idate ( $now ) . " ')) " ; }
if ( $status == 'todo' ) { $sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep2 > ' " . $db -> idate ( $now ) . " ')) " ; }
2008-08-30 00:40:36 +02:00
if ( $filtera > 0 || $filtert > 0 || $filterd > 0 )
2008-03-20 20:07:21 +01:00
{
2011-06-11 00:05:07 +02:00
$sql .= " AND ( " ;
if ( $filtera > 0 ) $sql .= " a.fk_user_author = " . $filtera ;
if ( $filtert > 0 ) $sql .= ( $filtera > 0 ? " OR " : " " ) . " a.fk_user_action = " . $filtert ;
if ( $filterd > 0 ) $sql .= ( $filtera > 0 || $filtert > 0 ? " OR " : " " ) . " a.fk_user_done = " . $filterd ;
$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
dol_syslog ( " comm/action/index.php sql= " . $sql , 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 );
$i = 0 ;
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
// Create a new object action
$event = new ActionComm ( $db );
$event -> id = $obj -> id ;
$event -> datep = $db -> jdate ( $obj -> datep ); // datep and datef are GMT date
$event -> datef = $db -> jdate ( $obj -> datep2 );
$event -> type_code = $obj -> code ;
$event -> libelle = $obj -> label ;
$event -> percentage = $obj -> percent ;
2013-10-15 15:17:33 +02:00
$event -> author -> id = $obj -> fk_user_author ; // user id of creator
$event -> usertodo -> id = $obj -> fk_user_action ; // user id of owner
$event -> userdone -> id = $obj -> fk_user_done ; // deprecated
// $event->userstodo=... with s after user, in future version, will be an array with all id of user assigned to event
2011-02-02 16:51:18 +01:00
$event -> priority = $obj -> priority ;
$event -> fulldayevent = $obj -> fulldayevent ;
$event -> location = $obj -> location ;
$event -> societe -> id = $obj -> fk_soc ;
$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 ||
$event -> date_start_in_calendar > $lastdaytoshow )
{
// This record is out of visible range
}
else
{
if ( $event -> date_start_in_calendar < $firstdaytoshow ) $event -> date_start_in_calendar = $firstdaytoshow ;
if ( $event -> date_end_in_calendar > $lastdaytoshow ) $event -> date_end_in_calendar = $lastdaytoshow ;
// 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
}
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 . '))' ;
2012-02-11 08:03:26 +01:00
$sql .= " AND sp.entity IN ( " . getEntity ( 'societe' , 1 ) . " ) " ;
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' ;
dol_syslog ( " comm/action/index.php sql= " . $sql , LOG_DEBUG );
$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 ;
$event -> fulldayevent = true ;
$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
}
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' ];
$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;
//if ($event->date_end_in_calendar > $lastdaytoshow) $event->date_end_in_calendar=$lastdaytoshow;
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
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 ;
while (( $datecurstart <= $lastdaytoshow ) && ( empty ( $maxrepeat ) || ( $numofevent < $maxrepeat )))
{
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');
$event -> fulldayevent = true ;
$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' ];
$addevent = true ;
}
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' ];
// $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.
2011-06-11 00:05:07 +02:00
if ( $event -> date_end_in_calendar < $firstdaytoshow || $event -> date_start_in_calendar > $lastdaytoshow )
{
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 ;
if ( $event -> date_end_in_calendar > $lastdaytoshow ) $event -> date_end_in_calendar = $lastdaytoshow ;
// 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
2012-01-22 02:12:11 +01:00
//print 'x'.$datestart.'-'.$dateend;exit;
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
}
2011-06-11 13:01:11 +02:00
$maxnbofchar = 18 ;
2010-11-19 23:36:49 +01:00
$cachethirdparties = array ();
2011-03-25 20:26:35 +01:00
$cachecontacts = 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' ;
2013-02-19 13:24:32 +01:00
echo '<table width="100%" class="nocellnopadd cal_month">' ;
2011-06-11 00:05:07 +02:00
echo ' <tr class="liste_titre">' ;
$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 " ;
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);
//print $tmpday;
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
{
/* 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' ;
2011-06-11 00:05:07 +02:00
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
{
$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 " ;
}
echo " </table> \n " ;
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' ;
2013-02-19 13:24:32 +01:00
echo '<table width="100%" class="nocellnopadd cal_month">' ;
2011-06-11 00:05:07 +02:00
echo ' <tr class="liste_titre">' ;
$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 " ;
// In loops, tmpday contains day nb in current month (can be zero or negative for days of previous month)
//var_dump($eventarray);
//print $tmpday;
echo " <tr> \n " ;
for ( $iter_day = 0 ; $iter_day < 7 ; $iter_day ++ )
{
if (( $tmpday <= $max_day_in_month ))
{
// Show days of the current week
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
2011-06-11 05:31:14 +02:00
$style = 'cal_current_month' ;
2013-02-19 13:24:32 +01:00
if ( $iter_day == 6 ) $style .= ' cal_other_month_right' ;
2011-06-11 05:31:14 +02:00
$today = 0 ;
$todayarray = dol_getdate ( $now , 'fast' );
if ( $todayarray [ 'mday' ] == $tmpday && $todayarray [ 'mon' ] == $month && $todayarray [ 'year' ] == $year ) $today = 1 ;
if ( $today ) $style = 'cal_today' ;
2011-06-11 00:05:07 +02:00
2013-04-25 01:13:13 +02:00
echo ' <td class="' . $style . ' nowrap" width="14%" valign="top">' ;
2011-06-11 13:01:11 +02:00
show_day_events ( $db , $tmpday , $month , $year , $month , $style , $eventarray , 0 , $maxnbofchar , $newparam , 1 , 300 );
2011-06-11 00:05:07 +02:00
echo " </td> \n " ;
}
else
{
$style = 'cal_current_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">' ;
2011-06-11 13:01:11 +02:00
show_day_events ( $db , $tmpday - $max_day_in_month , $next_month , $next_year , $month , $style , $eventarray , 0 , $maxnbofchar , $newparam , 1 , 300 );
2011-06-11 00:05:07 +02:00
echo " </td> \n " ;
}
$tmpday ++ ;
}
echo " </tr> \n " ;
echo " </table> \n " ;
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
2011-06-11 00:05:07 +02:00
$style = 'cal_current_month' ;
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 ;
if ( $today ) $style = 'cal_today' ;
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 );
2011-06-11 00:05:07 +02:00
echo '<table width="100%" class="nocellnopadd">' ;
echo ' <tr class="liste_titre">' ;
echo ' <td align="center">' . $langs -> trans ( " Day " . $arraytimestamp [ 'wday' ]) . " </td> \n " ;
echo " </tr> \n " ;
echo " <tr> \n " ;
2013-04-25 01:13:13 +02:00
echo ' <td class="' . $style . ' nowrap" width="14%" valign="top">' ;
2011-06-11 13:01:11 +02:00
$maxnbofchar = 80 ;
2012-01-08 00:15:36 +01:00
show_day_events ( $db , $day , $month , $year , $month , $style , $eventarray , 0 , $maxnbofchar , $newparam , 1 , 300 );
2011-06-11 00:05:07 +02:00
echo " </td> \n " ;
echo " </tr> \n " ;
echo '</table>' ;
2008-03-02 19:47:42 +01:00
}
2008-02-26 19:34:53 +01:00
2003-08-03 14:13:38 +02:00
$db -> close ();
2011-06-11 05:23:42 +02:00
/* TODO Export
2012-01-22 02:12:11 +01:00
print '
2011-06-11 05:23:42 +02:00
< a href = " " id = " actionagenda_ical_link " >< img src = " '.DOL_URL_ROOT.'/theme/common/ical.gif " border = " 0 " /></ a >
< a href = " " id = " actionagenda_vcal_link " >< img src = " '.DOL_URL_ROOT.'/theme/common/vcal.gif " border = " 0 " /></ a >
< a href = " " id = " actionagenda_rss_link " >< img src = " '.DOL_URL_ROOT.'/theme/common/rss.gif " border = " 0 " /></ a >
2011-05-16 19:27:20 +02:00
< script >
$ ( " #actionagenda_rss_link " ) . attr ( " href " , " /public/agenda/agendaexport.php?format=rss&type=ActionAgenda&exportkey=dolibarr&token= " + getToken () + " &status= " + getStatus () + " &userasked= " + getUserasked () + " &usertodo= " + getUsertodo () + " &userdone= " + getUserdone () + " &year= " + getYear () + " &month= " + getMonth () + " &day= " + getDay () + " &showbirthday= " + getShowbirthday () + " &action= " + getAction () + " &projectid= " + getProjectid () + " " );
$ ( " #actionagenda_ical_link " ) . attr ( " href " , " /public/agenda/agendaexport.php?format=ical&type=ActionAgenda&exportkey=dolibarr&token= " + getToken () + " &status= " + getStatus () + " &userasked= " + getUserasked () + " &usertodo= " + getUsertodo () + " &userdone= " + getUserdone () + " &year= " + getYear () + " &month= " + getMonth () + " &day= " + getDay () + " &showbirthday= " + getShowbirthday () + " &action= " + getAction () + " &projectid= " + getProjectid () + " " );
$ ( " #actionagenda_vcal_link " ) . attr ( " href " , " /public/agenda/agendaexport.php?format=vcal&type=ActionAgenda&exportkey=dolibarr&token= " + getToken () + " &status= " + getStatus () + " &userasked= " + getUserasked () + " &usertodo= " + getUsertodo () + " &userdone= " + getUserdone () + " &year= " + getYear () + " &month= " + getMonth () + " &day= " + getDay () + " &showbirthday= " + getShowbirthday () + " &action= " + getAction () + " &projectid= " + getProjectid () + " " );
</ script >
' ;
*/
2008-09-29 02:17:40 +02:00
2011-08-27 16:24:16 +02:00
llxFooter ();
2008-03-02 19:47:42 +01:00
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
2012-01-08 00:52:07 +01: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
* @ param int $showinfo Add extended information ( used by day view )
* @ param int $minheight Minimum height for each event . 60 px by default .
2012-01-08 00:52:07 +01:00
* @ return void
2008-08-30 00:40:36 +02:00
*/
2012-01-22 20:16:11 +01:00
function show_day_events ( $db , $day , $month , $year , $monthshown , $style , & $eventarray , $maxprint = 0 , $maxnbofchar = 16 , $newparam = '' , $showinfo = 0 , $minheight = 60 )
2008-03-02 19:47:42 +01:00
{
2011-06-11 00:05:07 +02:00
global $user , $conf , $langs ;
2013-10-15 16:42:19 +02:00
global $filter , $filtera , $filtert , $filterd , $status , $actioncode ; // Filters used into search form
2011-06-11 00:05:07 +02:00
global $theme_datacolor ;
2013-04-11 10:15:53 +02:00
global $cachethirdparties , $cachecontacts , $colorindexused ;
2011-06-11 00:05:07 +02:00
2011-06-14 09:21:41 +02:00
print '<div id="dayevent_' . sprintf ( " %04d " , $year ) . sprintf ( " %02d " , $month ) . sprintf ( " %02d " , $day ) . '" class="dayevent">' . " \n " ;
2012-01-08 00:15:36 +01:00
$curtime = dol_mktime ( 0 , 0 , 0 , $month , $day , $year );
2011-06-11 00:05:07 +02:00
print '<table class="nobordernopadding" width="100%">' ;
2013-04-25 01:13:13 +02:00
print '<tr><td align="left" class="nowrap">' ;
2011-06-11 00:05:07 +02:00
print '<a 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 , 'daytext' );
else print dol_print_date ( $curtime , '%d' );
print '</a>' ;
2013-04-25 01:13:13 +02:00
print '</td><td align="right" class="nowrap">' ;
2011-06-11 00:05:07 +02:00
if ( $user -> rights -> agenda -> myactions -> create || $user -> rights -> agenda -> allactions -> create )
{
2013-06-20 09:18:12 +02:00
$newparam .= '&month=' . str_pad ( $month , 2 , " 0 " , STR_PAD_LEFT ) . '&year=' . $year ;
2013-06-18 22:12:17 +02:00
2011-06-11 00:05:07 +02:00
//$param='month='.$monthshown.'&year='.$year;
$hourminsec = '100000' ;
print '<a href="' . DOL_URL_ROOT . '/comm/action/fiche.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 '</td></tr>' ;
2013-04-25 01:13:13 +02:00
print '<tr height="' . $minheight . '"><td valign="top" colspan="2" class="nowrap" style="padding-bottom: 2px;">' ;
2011-06-11 00:05:07 +02:00
//$curtime = dol_mktime (0, 0, 0, $month, $day, $year);
2012-01-22 20:16:11 +01:00
$i = 0 ; $nummytasks = 0 ; $numother = 0 ; $numbirthday = 0 ; $numical = 0 ; $numicals = array ();
$ymd = sprintf ( " %04d " , $year ) . sprintf ( " %02d " , $month ) . sprintf ( " %02d " , $day );
2011-06-11 00:05:07 +02:00
2013-04-11 10:15:53 +02:00
$nextindextouse = count ( $colorindexused );
//print $nextindextouse;
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
{
$ponct = ( $event -> date_start_in_calendar == $event -> date_end_in_calendar );
2012-01-22 13:10:59 +01:00
// Define $color and $cssclass of event
$color =- 1 ; $cssclass = '' ; $colorindex =- 1 ;
2012-11-13 14:44:32 +01:00
if (( ! empty ( $event -> author -> id ) && $event -> author -> id == $user -> id )
|| ( ! empty ( $event -> usertodo -> id ) && $event -> usertodo -> id == $user -> id )
2013-04-11 10:15:53 +02:00
|| ( ! empty ( $event -> userdone -> id ) && $event -> userdone -> id == $user -> id ))
{
$nummytasks ++ ; $cssclass = 'family_mytasks' ;
2013-10-15 15:17:33 +02:00
// TODO Set a color using user color
// Must defined rule to choose color of who to use.
// event->usertodo->id will still contains user id of owner
// event->userstodo will be an array in future.
2014-01-08 20:40:30 +01:00
// $color=$user->color;
2012-11-13 14:44:32 +01:00
}
2013-04-11 10:15:53 +02:00
else if ( $event -> type_code == 'ICALEVENT' )
{
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 )] ++ ;
}
$color = $event -> icalcolor ;
$cssclass = ( ! empty ( $event -> icalname ) ? 'family_' . dol_string_nospecial ( $event -> icalname ) : 'family_other' );
}
2012-01-22 20:16:11 +01:00
else if ( $event -> type_code == 'BIRTHDAY' ) { $numbirthday ++ ; $colorindex = 2 ; $cssclass = 'family_birthday' ; }
2013-04-11 10:15:53 +02:00
else { $numother ++ ; $cssclass = 'family_other' ; }
if ( $color == - 1 ) // Color was not forced. Set color according to color index.
{
// Define color index if not yet defined
$idusertouse = ( $event -> usertodo -> id ? $event -> usertodo -> id : 0 );
2013-06-05 16:24:32 +02:00
if ( isset ( $colorindexused [ $idusertouse ]))
{
$colorindex = $colorindexused [ $idusertouse ]; // Color already assigned to this user
}
else
{
$colorindex = $nextindextouse ;
$colorindexused [ $idusertouse ] = $colorindex ;
if ( ! empty ( $theme_datacolor [ $nextindextouse + 1 ])) $nextindextouse ++ ; // Prepare to use next color
}
//print '|'.($color).'='.($idusertouse?$idusertouse:0).'='.$colorindex.'<br>';
2013-04-11 10:15:53 +02:00
// Define color
$color = sprintf ( " %02x%02x%02x " , $theme_datacolor [ $colorindex ][ 0 ], $theme_datacolor [ $colorindex ][ 1 ], $theme_datacolor [ $colorindex ][ 2 ]);
}
2012-01-22 20:16:11 +01:00
$cssclass = $cssclass . ' ' . $cssclass . '_day_' . $ymd ;
2011-06-11 00:05:07 +02:00
2012-01-22 13:10:59 +01:00
// Show rect of event
2012-01-22 20:16:11 +01:00
print '<div id="event_' . $ymd . '_' . $i . '" class="event ' . $cssclass . '">' ;
2013-02-15 10:42:35 +01:00
print '<ul class="cal_event"><li class="cal_event">' ;
2013-02-19 13:24:32 +01:00
print '<table class="cal_event" style="background: #' . $color . '; -moz-border-radius:4px; background: -webkit-gradient(linear, left top, left bottom, from(#' . $color . '), to(#' . dol_color_minus ( $color , 1 ) . ')); " width="100%"><tr>' ;
2013-04-25 01:13:13 +02:00
print '<td class="nowrap cal_event">' ;
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 ))
{
2011-06-11 13:01:11 +02:00
//print '<strong>';
2011-06-11 00:05:07 +02:00
$daterange = '' ;
// 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 )
{
$daterange .= dol_print_date ( $event -> date_start_in_calendar , '%H:%M' );
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 )
$daterange .= dol_print_date ( $event -> date_end_in_calendar , '%H:%M' );
}
//print $daterange;
if ( $event -> type_code != 'ICALEVENT' )
{
$savlabel = $event -> libelle ;
$event -> libelle = $daterange ;
print $event -> getNomUrl ( 0 );
$event -> libelle = $savlabel ;
}
else
{
print $daterange ;
}
2011-06-11 13:01:11 +02:00
//print '</strong> ';
print " <br> \n " ;
2011-06-11 00:05:07 +02:00
}
else
{
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
2011-06-11 13:04:42 +02:00
if ( $event -> type_code == 'ICALEVENT' ) print dol_trunc ( $event -> libelle , $maxnbofchar );
2011-06-11 00:05:07 +02:00
else print $event -> getNomUrl ( 0 , $maxnbofchar , 'cal_event' );
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
$linerelatedto = '' ; $length = 16 ;
if ( ! empty ( $event -> societe -> id ) && ! empty ( $event -> contact -> id )) $length = round ( $length / 2 );
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 ];
2013-09-25 21:26:06 +02:00
if ( ! empty ( $thirdparty -> id )) $linerelatedto .= $thirdparty -> getNomUrl ( 1 , '' , $length );
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 .= ' / ' ;
2013-09-25 21:26:06 +02:00
if ( ! empty ( $contact -> id )) $linerelatedto .= $contact -> getNomUrl ( 1 , '' , $length );
2010-11-19 23:36:49 +01:00
}
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
2013-04-25 01:13:13 +02:00
print '<td align="right" class="nowrap">' ;
2011-06-11 00:05:07 +02:00
if ( $event -> type_code != 'BIRTHDAY' && $event -> type_code != 'ICALEVENT' ) print $event -> getLibStatut ( 3 , 1 );
else print ' ' ;
print '</td></tr></table>' ;
2013-02-15 10:42:35 +01:00
print '</li></ul>' ;
2011-06-11 00:05:07 +02:00
print '</div>' ;
$i ++ ;
}
else
{
2013-10-15 16:42:19 +02:00
print '<a href="' . DOL_URL_ROOT . '/comm/action/index.php?maxprint=0&month=' . $monthshown . '&year=' . $year ;
2011-06-11 00:05:07 +02:00
print ( $status ? '&status=' . $status : '' ) . ( $filter ? '&filter=' . $filter : '' );
2010-11-19 23:36:49 +01:00
print ( $filtera ? '&filtera=' . $filtera : '' ) . ( $filtert ? '&filtert=' . $filtert : '' ) . ( $filterd ? '&filterd=' . $filterd : '' );
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 " ;
print '});' . " \n " ;
print '</script>' . " \n " ;
}
2011-06-11 00:05:07 +02:00
print '</td></tr>' ;
print '</table>' ;
2011-06-11 05:23:42 +02:00
print '</div>' . " \n " ;
2008-03-02 19:47:42 +01:00
}
2013-04-11 10:15:53 +02:00
/**
* Change color with a delta
*
* @ param string $color Color
* @ param int $minus Delta
* @ return string New color
*/
2013-02-15 10:42:35 +01:00
function dol_color_minus ( $color , $minus )
{
$newcolor = $color ;
$newcolor [ 0 ] = (( hexdec ( $newcolor [ 0 ]) - $minus ) < 0 ) ? 0 : dechex (( hexdec ( $newcolor [ 0 ]) - $minus ));
$newcolor [ 2 ] = (( hexdec ( $newcolor [ 2 ]) - $minus ) < 0 ) ? 0 : dechex (( hexdec ( $newcolor [ 2 ]) - $minus ));
$newcolor [ 4 ] = (( hexdec ( $newcolor [ 4 ]) - $minus ) < 0 ) ? 0 : dechex (( hexdec ( $newcolor [ 4 ]) - $minus ));
return $newcolor ;
}
2003-08-03 14:13:38 +02:00
?>