2001-07-28 15:17:30 +02:00
< ? php
2005-11-09 00:15:14 +01:00
/************************************************************************** \
* eGroupWare - Calendar *
* http :// www . egroupware . org *
* Based on Webcalendar by Craig Knudsen < cknudsen @ radix . net > *
* http :// www . radix . net /~ cknudsen *
* Modified by Mark Peters < skeeter @ phpgroupware . org > *
* -------------------------------------------- *
* 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 the *
* Free Software Foundation ; either version 2 of the License , or ( at your *
* option ) any later version . *
\ **************************************************************************/
2001-07-28 15:17:30 +02:00
/* $Id$ */
2005-11-09 00:15:14 +01:00
/**
* User interface for calendar holidays
*
* @ package calendar
* @ author Mark Peters < skeeter @ phpgroupware . org >
* @ license http :// opensource . org / licenses / gpl - license . php GPL - GNU General Public License
*/
2001-07-28 15:17:30 +02:00
class uiholiday
{
var $debug = False ;
var $base_url ;
var $bo ;
var $template_dir ;
var $holidays ;
var $cat_id ;
var $public_functions = array (
'admin' => True ,
'edit_locale' => True ,
'edit_holiday' => True ,
2003-02-27 20:28:25 +01:00
'copy_holiday' => True ,
2001-07-28 15:17:30 +02:00
'delete_holiday' => True ,
2003-02-27 20:28:25 +01:00
'delete_locale' => True ,
'submit' => True
2001-07-28 15:17:30 +02:00
);
function uiholiday ()
{
2005-11-09 00:15:14 +01:00
$this -> bo =& CreateObject ( 'calendar.boholiday' );
2001-07-28 19:54:59 +02:00
$this -> bo -> check_admin ();
2001-07-28 15:17:30 +02:00
$this -> base_url = $this -> bo -> base_url ;
2009-11-16 09:04:18 +01:00
$this -> template_dir = common :: get_tpl_dir ( 'calendar' );
2006-10-13 18:43:40 +02:00
$this -> sb =& CreateObject ( 'calendar.sbox' );
2003-04-21 13:00:53 +02:00
2006-03-08 16:39:53 +01:00
// calendar does not work with hidden sidebox atm.
unset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'auto_hide_sidebox' ]);
2005-11-09 00:15:14 +01:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] = $GLOBALS [ 'egw_info' ][ 'apps' ][ 'calendar' ][ 'title' ] . ' - ' . lang ( 'Holiday Management' );
2009-11-16 09:04:18 +01:00
2005-11-09 00:15:14 +01:00
$GLOBALS [ 'egw' ] -> template -> set_var ( 'help_msg' , lang ( '<b>Please note</b>: The calendar use the holidays of your country, which is set to %1. You can change it in your %2.<br />Holidays are %3 automatic installed from %4. You can changed it in %5.' ,
'<b>' . $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'country' ] . '</b>' , '<a href="' . $GLOBALS [ 'egw' ] -> link ( '/index.php' , array (
'menuaction' => 'preferences.uisettings.index' ,
'appname' => 'preferences' ,
)) . '">' . lang ( 'common preferences' ) . '</a>' , $GLOBALS [ 'egw_info' ][ 'server' ][ 'auto_load_holidays' ] ? '' : '<b>' . lang ( 'not' ) . '</b>' ,
'<b>' . $GLOBALS [ 'egw_info' ][ 'server' ][ 'holidays_url_path' ] . '</b>' ,
'<a href="' . $GLOBALS [ 'egw' ] -> link ( '/index.php' , array (
'menuaction' => 'admin.uiconfig.index' ,
'appname' => 'calendar' ,
)) . '">' . lang ( 'admin' ) . ' >> ' . lang ( 'calendar' ) . ' >> ' . lang ( 'site configuration' ) . '</a>' ));
$GLOBALS [ 'egw' ] -> template -> set_var ( 'total' , '' );
2001-07-28 15:17:30 +02:00
}
function admin ()
{
2005-11-09 00:15:14 +01:00
unset ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'noheader' ]);
unset ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'nonavbar' ]);
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'noappfooter' ] = True ;
2009-11-16 09:04:18 +01:00
common :: egw_header ();
2001-07-28 15:17:30 +02:00
2005-11-09 00:15:14 +01:00
$p = & $GLOBALS [ 'egw' ] -> template ;
2001-07-28 15:17:30 +02:00
$p -> set_file ( Array ( 'locales' => 'locales.tpl' ));
$p -> set_block ( 'locales' , 'list' , 'list' );
$p -> set_block ( 'locales' , 'row' , 'row' );
$p -> set_block ( 'locales' , 'row_empty' , 'row_empty' );
$p -> set_block ( 'locales' , 'submit_column' , 'submit_column' );
$var = Array (
2005-11-09 00:15:14 +01:00
'th_bg' => $GLOBALS [ 'egw_info' ][ 'theme' ][ 'th_bg' ],
'left_next_matchs' => $GLOBALS [ 'egw' ] -> nextmatchs -> left ( '/index.php?menuaction=calendar.uiholiday.admin' , $this -> bo -> start , $this -> bo -> total ),
'right_next_matchs' => $GLOBALS [ 'egw' ] -> nextmatchs -> right ( '/index.php?menuaction=calendar.uiholiday.admin' , $this -> bo -> start , $this -> bo -> total ),
2003-02-27 20:28:25 +01:00
'center' => '<td align="center">' . lang ( 'Countries' ) . '</td>' ,
2006-03-09 23:31:58 +01:00
'sort_name' => $GLOBALS [ 'egw' ] -> nextmatchs -> show_sort_order ( $this -> bo -> sort , 'hol_locale' , $this -> bo -> order , '/calendar/' . basename ( $SCRIPT_FILENAME ), lang ( 'Country' )),
2001-07-28 15:17:30 +02:00
'header_edit' => lang ( 'Edit' ),
'header_delete' => lang ( 'Delete' ),
2003-02-27 20:28:25 +01:00
'header_extra' => lang ( 'Submit to Repository' ),
'extra_width' => 'width="45%"' ,
'rule' => '' ,
'header_rule' => '' ,
2001-07-28 15:17:30 +02:00
'back_button' => ''
);
$p -> set_var ( $var );
$locales = $this -> bo -> get_locale_list ( $this -> bo -> sort , $this -> bo -> order , $this -> bo -> query , $this -> bo -> total );
@ reset ( $locales );
if ( ! $locales )
{
2003-08-28 16:31:11 +02:00
$p -> set_var ( 'message' , lang ( 'no matches found' ));
2001-07-28 15:17:30 +02:00
$p -> parse ( 'rows' , 'row_empty' , True );
}
else
{
$p -> set_var ( 'submit_extra' , ' width="5%"' );
while ( list (, $value ) = each ( $locales ))
{
2005-11-09 00:15:14 +01:00
$tr_color = $GLOBALS [ 'egw' ] -> nextmatchs -> alternate_row_color ( $tr_color );
2001-07-28 15:17:30 +02:00
if ( ! $value ) $value = ' ' ;
$var = Array (
'tr_color' => $tr_color ,
'group_name' => $value ,
2005-11-09 00:15:14 +01:00
'edit_link' => '<a href="' . $GLOBALS [ 'egw' ] -> link ( $this -> base_url , Array ( 'menuaction' => 'calendar.uiholiday.edit_locale' , 'locale' => $value )) . '"> ' . lang ( 'Edit' ) . ' </a>' ,
'delete_link' => '<a href="' . $GLOBALS [ 'egw' ] -> link ( $this -> base_url , Array ( 'menuaction' => 'calendar.uiholiday.delete_locale' , 'locale' => $value )) . '"> ' . lang ( 'Delete' ) . ' </a>' ,
'extra_link' => '<a href="' . $GLOBALS [ 'egw' ] -> link ( $this -> base_url , Array ( 'menuaction' => 'calendar.uiholiday.submit' , 'locale' => $value )) . '"> ' . lang ( 'Submit' ) . ' </a>' .
' <a href="' . $GLOBALS [ 'egw' ] -> link ( $this -> base_url , Array ( 'menuaction' => 'calendar.uiholiday.submit' , 'locale' => $value , 'download' => 1 )) . '"> ' . lang ( 'Download' ) . ' </a>'
2001-07-28 15:17:30 +02:00
);
$p -> set_var ( $var );
$p -> parse ( 'rows' , 'row' , True );
}
}
$var = Array (
2005-11-09 00:15:14 +01:00
'new_action' => $GLOBALS [ 'egw' ] -> link ( $this -> base_url , Array ( 'menuaction' => 'calendar.uiholiday.edit_holiday' , 'id' => 0 )),
2001-07-28 15:17:30 +02:00
'lang_add' => lang ( 'add' ),
2005-11-09 00:15:14 +01:00
'search_action' => $GLOBALS [ 'egw' ] -> link ( $this -> base_url , Array ( 'menuaction' => 'calendar.uiholiday.admin' )),
2001-07-28 15:17:30 +02:00
'lang_search' => lang ( 'search' )
);
$p -> set_var ( $var );
$p -> pparse ( 'out' , 'list' );
}
2003-02-27 20:28:25 +01:00
function edit_locale ( $locale = '' )
2001-07-28 15:17:30 +02:00
{
2003-08-28 16:31:11 +02:00
if ( $locale === '' )
{
$locale = $this -> bo -> locale ;
}
2003-02-27 20:28:25 +01:00
if ( $locale )
{
$this -> bo -> locales = array ( $locale );
$this -> bo -> total = $this -> bo -> so -> holiday_total ( $locale , $this -> bo -> query );
}
2001-07-28 15:17:30 +02:00
if ( ! $this -> bo -> total && ! isset ( $this -> bo -> query ))
{
$link_params = Array (
'menuaction' => 'calendar.uiholiday.admin'
);
2005-11-09 00:15:14 +01:00
$GLOBALS [ 'egw' ] -> redirect_link ( $this -> base_url , $link_params );
2001-07-28 15:17:30 +02:00
}
2005-11-09 00:15:14 +01:00
unset ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'noheader' ]);
unset ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'nonavbar' ]);
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'noappfooter' ] = True ;
2009-11-16 09:04:18 +01:00
common :: egw_header ();
2005-11-09 00:15:14 +01:00
$p =& $GLOBALS [ 'egw' ] -> template ;
2001-07-28 15:17:30 +02:00
$p -> set_file ( Array ( 'locale' => 'locales.tpl' ));
$p -> set_block ( 'locale' , 'list' , 'list' );
$p -> set_block ( 'locale' , 'row' , 'row' );
$p -> set_block ( 'locale' , 'row_empty' , 'row_empty' );
$p -> set_block ( 'locale' , 'back_button_form' , 'back_button_form' );
2005-11-09 00:15:14 +01:00
if ( ! is_object ( $GLOBALS [ 'egw' ] -> html ))
2003-09-22 17:01:26 +02:00
{
2005-11-09 00:15:14 +01:00
$GLOBALS [ 'egw' ] -> html =& CreateObject ( 'phpgwapi.html' );
2003-09-22 17:01:26 +02:00
}
2005-11-09 00:15:14 +01:00
$html = & $GLOBALS [ 'egw' ] -> html ;
2003-02-27 20:28:25 +01:00
$year_form = str_replace ( '<option value=""></option>' , '' , $html -> form ( $html -> sbox_submit ( $this -> sb -> getYears ( 'year' , $this -> bo -> year ), true ), array (),
$this -> base_url , Array ( 'menuaction' => 'calendar.uiholiday.edit_locale' , 'locale' => $this -> bo -> locales [ 0 ])));
unset ( $html );
$holidays = $this -> bo -> get_holiday_list ();
2003-09-22 17:01:26 +02:00
$total = count ( $holidays );
2003-02-27 20:28:25 +01:00
2001-07-28 15:17:30 +02:00
$var = Array (
2005-11-09 00:15:14 +01:00
'th_bg' => $GLOBALS [ 'egw_info' ][ 'theme' ][ 'th_bg' ],
'left_next_matchs' => $GLOBALS [ 'egw' ] -> nextmatchs -> left ( '/index.php' , $this -> bo -> start , $total , '&menuaction=calendar.uiholiday.edit_locale&locale=' . $this -> bo -> locales [ 0 ] . '&year=' . $this -> bo -> year ),
'right_next_matchs' => $GLOBALS [ 'egw' ] -> nextmatchs -> right ( '/index.php' , $this -> bo -> start , $total , '&menuaction=calendar.uiholiday.edit_locale&locale=' . $this -> bo -> locales [ 0 ] . '&year=' . $this -> bo -> year ),
2003-09-22 17:01:26 +02:00
'center' => '<td align="right">' . lang ( 'Holidays' ) . ' (' . $this -> bo -> locales [ 0 ] . ')</td><td align="left">' . $year_form . '</td>' ,
2006-03-09 23:24:55 +01:00
'sort_name' => $GLOBALS [ 'egw' ] -> nextmatchs -> show_sort_order ( $this -> bo -> sort , 'hol_name' , $this -> bo -> order , '/index.php' , lang ( 'Holiday' ), '&menuaction=calendar.uiholiday.edit_locale&locale=' . $this -> bo -> locales [ 0 ] . '&year=' . $this -> bo -> year ),
2003-09-22 17:01:26 +02:00
'header_edit' => lang ( 'Edit' ),
2001-07-28 15:17:30 +02:00
'header_delete' => lang ( 'Delete' ),
2006-03-09 23:24:55 +01:00
'header_rule' => '<td>' . $GLOBALS [ 'egw' ] -> nextmatchs -> show_sort_order ( $this -> bo -> sort , 'hol_month_num,hol_mday' , $this -> bo -> order , '/index.php' , lang ( 'Rule' ), '&menuaction=calendar.uiholiday.edit_locale&locale=' . $this -> bo -> locales [ 0 ] . '&year=' . $this -> bo -> year ) . '</td>' ,
2003-09-22 17:01:26 +02:00
'header_extra' => lang ( 'Copy' ),
'extra_width' => 'width="5%"'
2001-07-28 15:17:30 +02:00
);
$p -> set_var ( $var );
if ( ! count ( $holidays ))
{
2005-11-09 00:15:14 +01:00
$p -> set_var ( 'total' , lang ( 'no matches found' ));
//$p->parse('rows','row_empty',True);
2001-07-28 15:17:30 +02:00
}
else
{
2005-11-09 00:15:14 +01:00
$maxmatchs = $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'maxmatchs' ];
2003-09-22 17:01:26 +02:00
$end = min ( $total , $this -> bo -> start + $maxmatchs );
2005-11-09 00:15:14 +01:00
$p -> set_var ( 'total' , lang ( 'showing %1 - %2 of %3' , 1 + $this -> bo -> start , $end , $total ));
//$p->parse('rows','row_empty',True);
2003-09-22 17:01:26 +02:00
for ( $i = $this -> bo -> start ; $i < $end ; $i ++ )
2001-07-28 15:17:30 +02:00
{
2005-11-09 00:15:14 +01:00
$tr_color = $GLOBALS [ 'egw' ] -> nextmatchs -> alternate_row_color ( $tr_color );
2001-07-28 15:17:30 +02:00
if ( ! $holidays [ $i ][ 'name' ])
{
$holidays [ $i ][ 'name' ] = ' ' ;
}
2009-11-16 09:04:18 +01:00
2001-07-28 15:17:30 +02:00
$var = Array (
'tr_color' => $tr_color ,
'header_delete' => lang ( 'Delete' ),
'group_name' => $holidays [ $i ][ 'name' ],
2003-02-27 20:28:25 +01:00
'rule' => '<td>' . $this -> bo -> rule_string ( $holidays [ $i ]) . '</td>' ,
2005-11-09 00:15:14 +01:00
'edit_link' => '<a href="' . $GLOBALS [ 'egw' ] -> link ( $this -> base_url , Array ( 'menuaction' => 'calendar.uiholiday.edit_holiday' , 'locale' => $this -> bo -> locales [ 0 ], 'id' => $holidays [ $i ][ 'index' ], 'year' => $this -> bo -> year )) . '"> ' . lang ( 'Edit' ) . ' </a>' ,
'extra_link' => '<a href="' . $GLOBALS [ 'egw' ] -> link ( $this -> base_url , Array ( 'menuaction' => 'calendar.uiholiday.copy_holiday' , 'locale' => $this -> bo -> locales [ 0 ], 'id' => $holidays [ $i ][ 'index' ], 'year' => $this -> bo -> year )) . '"> ' . lang ( 'Copy' ) . ' </a>' ,
'delete_link' => '<a href="' . $GLOBALS [ 'egw' ] -> link ( $this -> base_url , Array ( 'menuaction' => 'calendar.uiholiday.delete_holiday' , 'locale' => $this -> bo -> locales [ 0 ], 'id' => $holidays [ $i ][ 'index' ], 'year' => $this -> bo -> year )) . '"> ' . lang ( 'Delete' ) . ' </a>'
2001-07-28 15:17:30 +02:00
);
$p -> set_var ( $var );
$p -> parse ( 'rows' , 'row' , True );
}
}
$var = Array (
2005-11-09 00:15:14 +01:00
'new_action' => $GLOBALS [ 'egw' ] -> link ( $this -> base_url , Array ( 'menuaction' => 'calendar.uiholiday.edit_holiday' , 'locale' => $this -> bo -> locales [ 0 ], 'id' => 0 , 'year' => $this -> bo -> year )),
2001-07-28 15:17:30 +02:00
'lang_add' => lang ( 'add' ),
2005-11-09 00:15:14 +01:00
'back_action' => $GLOBALS [ 'egw' ] -> link ( $this -> base_url , Array ( 'menuaction' => 'calendar.uiholiday.admin' )),
2001-07-28 15:17:30 +02:00
'lang_back' => lang ( 'Back' ),
2005-11-09 00:15:14 +01:00
'search_action' => $GLOBALS [ 'egw' ] -> link ( $this -> base_url , Array ( 'menuaction' => 'calendar.uiholiday.edit_locale' , 'locale' => $this -> bo -> locales [ 0 ], 'year' => $this -> bo -> year )),
2001-07-28 15:17:30 +02:00
'lang_search' => lang ( 'search' )
);
$p -> set_var ( $var );
$p -> parse ( 'back_button' , 'back_button_form' , False );
$p -> pparse ( 'out' , 'list' );
}
2003-02-27 20:28:25 +01:00
function copy_holiday ()
2001-07-28 15:17:30 +02:00
{
if ( @ $this -> bo -> id )
{
$holiday = $this -> bo -> read_entry ( $this -> bo -> id );
}
2003-02-27 20:28:25 +01:00
$this -> bo -> id = 0 ;
if ( ! $holiday [ 'occurence' ] || $holiday [ 'occurence' ] >= 1900 )
2001-07-28 15:17:30 +02:00
{
2003-02-27 20:28:25 +01:00
$holiday [ 'occurence' ] = date ( 'Y' );
2001-07-28 15:17:30 +02:00
}
2003-02-27 20:28:25 +01:00
$this -> edit_holiday ( '' , $holiday );
}
2001-07-28 15:17:30 +02:00
2003-02-27 20:28:25 +01:00
function edit_holiday ( $error = '' , $holiday = '' )
{
if ( @ $this -> bo -> id && ! $holiday )
{
$holiday = $this -> bo -> read_entry ( $this -> bo -> id );
}
2007-05-03 16:05:39 +02:00
if ( $this -> bo -> locale )
2003-02-27 20:28:25 +01:00
{
2007-05-03 16:05:39 +02:00
$holiday [ 'locale' ] = $this -> bo -> locale ;
2003-02-27 20:28:25 +01:00
}
2005-11-09 00:15:14 +01:00
unset ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'noheader' ]);
unset ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'nonavbar' ]);
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'noappfooter' ] = True ;
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] = $GLOBALS [ 'egw_info' ][ 'apps' ][ 'calendar' ][ 'title' ] . ' - ' . ( $this -> bo -> id ? lang ( 'Edit' ) : lang ( 'Add' )) . ' ' . lang ( 'Holiday' );
2009-11-16 09:04:18 +01:00
common :: egw_header ();
2001-07-28 15:17:30 +02:00
2005-11-09 00:15:14 +01:00
$t = & $GLOBALS [ 'egw' ] -> template ;
2001-07-28 15:17:30 +02:00
$t -> set_file ( Array ( 'holiday' => 'holiday.tpl' , 'form_button' => 'form_button_script.tpl' ));
$t -> set_block ( 'holiday' , 'form' , 'form' );
$t -> set_block ( 'holiday' , 'list' , 'list' );
2003-02-27 20:28:25 +01:00
if ( @ count ( $error ))
2001-07-28 15:17:30 +02:00
{
2009-11-16 09:04:18 +01:00
$message = common :: error_list ( $error );
2001-07-28 15:17:30 +02:00
}
else
{
$message = '' ;
}
2009-11-16 09:04:18 +01:00
2001-07-28 15:17:30 +02:00
$var = Array (
2004-01-04 01:47:37 +01:00
'title_holiday' => ( $this -> bo -> id ? lang ( 'Edit' ) : lang ( 'Add' )) . ' ' . lang ( 'Holiday' ),
'message' => $message ,
2005-11-09 00:15:14 +01:00
'actionurl' => $GLOBALS [ 'egw' ] -> link ( $this -> base_url , 'menuaction=calendar.boholiday.add&year=' . $this -> bo -> year ),
2004-01-04 01:47:37 +01:00
'hidden_vars' => '<input type="hidden" name="holiday[hol_id]" value="' . $this -> bo -> id . '">' . " \n "
. '<input type="hidden" name="holiday[locales]" value="' . $this -> bo -> locales [ 0 ] . '">' . " \n "
2001-07-28 15:17:30 +02:00
);
$t -> set_var ( $var );
// Locale
2004-03-22 08:59:10 +01:00
$this -> display_item ( $t , lang ( 'Country' ), $this -> sb -> form_select ( $holiday [ 'locale' ], 'holiday[locale]' ));
2001-07-28 15:17:30 +02:00
// Title/Name
2003-02-27 20:28:25 +01:00
$this -> display_item ( $t , lang ( 'title' ), '<input name="holiday[name]" size="60" maxlength="50" value="' . $holiday [ 'name' ] . '">' );
2001-07-28 15:17:30 +02:00
// Date
2009-11-16 09:04:18 +01:00
$this -> display_item ( $t , lang ( 'Date' ), common :: dateformatorder ( $this -> sb -> getYears ( 'holiday[year]' , $holiday [ 'occurence' ] > 1900 ? $holiday [ 'occurence' ] : 0 ), $this -> sb -> getMonthText ( 'holiday[month_num]' , $holiday [ 'month' ]), $this -> sb -> getDays ( 'holiday[mday]' , $holiday [ 'day' ])) .
2003-04-21 13:00:53 +02:00
' ' . lang ( 'Set a Year only for one-time / non-regular holidays.' ));
2001-07-28 15:17:30 +02:00
// Occurence
$occur = Array (
2003-02-27 20:28:25 +01:00
0 => '' ,
1 => '1.' ,
2 => '2.' ,
3 => '3.' ,
4 => '4.' ,
5 => '5.' ,
99 => lang ( 'Last' )
2001-07-28 15:17:30 +02:00
);
$out = '' ;
while ( list ( $key , $value ) = each ( $occur ))
{
$out .= '<option value="' . $key . '"' . ( $holiday [ 'occurence' ] == $key ? ' selected' : '' ) . '>' . $value . '</option>' . " \n " ;
}
$occurence_html = '<select name="holiday[occurence]">' . " \n " . $out . '</select>' . " \n " ;
$dow = Array (
0 => lang ( 'Sun' ),
1 => lang ( 'Mon' ),
2 => lang ( 'Tue' ),
3 => lang ( 'Wed' ),
4 => lang ( 'Thu' ),
5 => lang ( 'Fri' ),
6 => lang ( 'Sat' )
);
$out = '' ;
for ( $i = 0 ; $i < 7 ; $i ++ )
{
$out .= '<option value="' . $i . '"' . ( $holiday [ 'dow' ] == $i ? ' selected' : '' ) . '>' . $dow [ $i ] . '</option>' . " \n " ;
}
$dow_html = '<select name="holiday[dow]">' . " \n " . $out . '</select>' . " \n " ;
2003-04-21 13:00:53 +02:00
$this -> display_item ( $t , lang ( 'Occurence' ), $occurence_html . ' ' . $dow_html .
' ' . lang ( 'You can either set a Year or a Occurence, not both !!!' ));
$this -> display_item ( $t , lang ( 'Observance Rule' ), '<input type="checkbox" name="holiday[observance_rule]" value="True"' . ( $holiday [ 'observance_rule' ] ? ' checked' : '' ) . '>' .
' ' . lang ( 'If checked holidays falling on a weekend, are taken on the monday after.' ));
2001-07-28 15:17:30 +02:00
$t -> set_var ( 'lang_add' , lang ( 'Save' ));
$t -> set_var ( 'lang_reset' , lang ( 'Reset' ));
if ( @ $this -> bo -> locales [ 0 ])
{
$link_params = Array (
'menuaction' => 'calendar.uiholiday.edit_locale' ,
2003-04-21 13:00:53 +02:00
'year' => $this -> bo -> year ,
2001-07-28 15:17:30 +02:00
'locale' => $this -> bo -> locales [ 0 ]
);
}
else
{
$link_params = Array (
'menuaction' => 'calendar.uiholiday.admin'
);
}
2009-11-16 09:04:18 +01:00
2003-04-21 13:00:53 +02:00
$t -> set_var ( Array (
2005-11-09 00:15:14 +01:00
'action_url_button' => $GLOBALS [ 'egw' ] -> link ( $this -> base_url , $link_params ),
2001-07-28 15:17:30 +02:00
'action_text_button' => lang ( 'Cancel' ),
'action_confirm_button' => '' ,
'action_extra_field' => ''
2003-04-21 13:00:53 +02:00
));
2001-07-28 15:17:30 +02:00
$t -> parse ( 'cancel_button' , 'form_button' );
2009-11-16 09:04:18 +01:00
2003-04-21 13:00:53 +02:00
if ( $this -> bo -> id )
{
$link_params = Array (
'menuaction' => 'calendar.uiholiday.delete_holiday' ,
'year' => $this -> bo -> year ,
'locale' => $this -> bo -> locales [ 0 ],
'id' => $this -> bo -> id
);
$t -> set_var ( Array (
2005-11-09 00:15:14 +01:00
'action_url_button' => $GLOBALS [ 'egw' ] -> link ( $this -> base_url , $link_params ),
2003-04-21 13:00:53 +02:00
'action_text_button' => lang ( 'Delete' ),
'action_confirm_button' => '' ,
'action_extra_field' => ''
));
$t -> parse ( 'delete_button' , 'form_button' );
}
else
{
$t -> set_var ( 'delete_button' , ' ' );
}
2001-07-28 15:17:30 +02:00
$t -> pparse ( 'out' , 'form' );
}
function delete_locale ()
{
2006-03-15 07:43:26 +01:00
$this -> admin ();
2001-07-28 15:17:30 +02:00
2005-11-09 00:15:14 +01:00
$p =& CreateObject ( 'phpgwapi.Template' , $this -> template_dir );
2001-07-28 15:17:30 +02:00
$p -> set_file ( Array ( 'form' => 'delete_common.tpl' , 'form_button' => 'form_button_script.tpl' ));
2009-11-16 09:04:18 +01:00
2001-07-28 15:17:30 +02:00
$p -> set_var ( 'messages' , lang ( 'Are you sure you want to delete this Country ?' ) . " <br> " . $this -> bo -> locales [ 0 ]);
$var = Array (
2005-11-09 00:15:14 +01:00
'action_url_button' => $GLOBALS [ 'egw' ] -> link ( $this -> base_url , Array ( 'menuaction' => 'calendar.uiholiday.admin' )),
2001-07-28 15:17:30 +02:00
'action_text_button' => lang ( 'No' ),
'action_confirm_button' => '' ,
'action_extra_field' => ''
);
$p -> set_var ( $var );
$p -> parse ( 'no' , 'form_button' );
$var = Array (
2005-11-09 00:15:14 +01:00
'action_url_button' => $GLOBALS [ 'egw' ] -> link ( $this -> base_url , Array ( 'menuaction' => 'calendar.boholiday.delete_locale' , 'locale' => $this -> bo -> locales [ 0 ])),
2001-07-28 15:17:30 +02:00
'action_text_button' => lang ( 'Yes' ),
'action_confirm_button' => '' ,
'action_extra_field' => ''
);
$p -> set_var ( $var );
$p -> parse ( 'yes' , 'form_button' );
$p -> pparse ( 'out' , 'form' );
}
function delete_holiday ()
{
$holiday = $this -> bo -> read_entry ( $this -> bo -> id );
if ( ! $holiday )
{
2006-03-15 07:43:26 +01:00
return $this -> edit_locale ();
2001-07-28 15:17:30 +02:00
}
2009-11-16 09:04:18 +01:00
2005-11-09 00:15:14 +01:00
unset ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'noheader' ]);
unset ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'nonavbar' ]);
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'noappfooter' ] = True ;
2009-11-16 09:04:18 +01:00
common :: egw_header ();
2001-07-28 15:17:30 +02:00
2005-11-09 00:15:14 +01:00
$p =& CreateObject ( 'phpgwapi.Template' , $this -> template_dir );
2001-07-28 15:17:30 +02:00
$p -> set_file ( Array ( 'form' => 'delete_common.tpl' , 'form_button' => 'form_button_script.tpl' ));
2009-11-16 09:04:18 +01:00
2003-02-27 20:28:25 +01:00
$p -> set_var ( 'messages' , lang ( 'Are you sure you want to delete this holiday ?' ) . " <br> " . $holiday [ 'name' ] . ' (' . $this -> bo -> locales [ 0 ] . ') ' . $this -> bo -> rule_string ( $holiday ));
2001-07-28 15:17:30 +02:00
$var = Array (
2005-11-09 00:15:14 +01:00
'action_url_button' => $GLOBALS [ 'egw' ] -> link ( $this -> base_url , Array ( 'menuaction' => 'calendar.uiholiday.edit_locale' , 'locale' => $this -> bo -> locales [ 0 ], 'year' => $this -> bo -> year )),
2001-07-28 15:17:30 +02:00
'action_text_button' => lang ( 'No' ),
'action_confirm_button' => '' ,
'action_extra_field' => ''
);
$p -> set_var ( $var );
$p -> parse ( 'no' , 'form_button' );
$var = Array (
2005-11-09 00:15:14 +01:00
'action_url_button' => $GLOBALS [ 'egw' ] -> link ( $this -> base_url , Array ( 'menuaction' => 'calendar.boholiday.delete_holiday' , 'locale' => $this -> bo -> locales [ 0 ], 'id' => $this -> bo -> id , 'year' => $this -> bo -> year )),
2001-07-28 15:17:30 +02:00
'action_text_button' => lang ( 'Yes' ),
'action_confirm_button' => '' ,
'action_extra_field' => ''
);
$p -> set_var ( $var );
$p -> parse ( 'yes' , 'form_button' );
$p -> pparse ( 'out' , 'form' );
}
function submit ()
{
if ( !@ $this -> bo -> locales [ 0 ])
{
2006-03-15 07:43:26 +01:00
return $this -> admin ();
2001-07-28 15:17:30 +02:00
}
2003-02-27 20:28:25 +01:00
$this -> bo -> year = 0 ; // for a complete list with all years
2001-07-28 15:17:30 +02:00
$holidays = $this -> bo -> get_holiday_list ();
2009-11-16 09:04:18 +01:00
2005-11-09 00:15:14 +01:00
if ( ! is_array ( $holidays ) || ! count ( $holidays ))
{
$this -> admin ();
}
// sort holidays by year / occurence:
usort ( $holidays , '_holiday_cmp' );
2001-07-28 15:17:30 +02:00
2003-08-28 16:31:11 +02:00
if ( isset ( $_GET [ 'download' ]))
2003-02-27 20:28:25 +01:00
{
$locale = $this -> bo -> locales [ 0 ];
2010-01-02 14:50:32 +01:00
$browser =& CreateObject ( 'phpgwapi.browser' );
$browser -> content_header ( " holidays. $locale .csv " , 'text/text' );
unset ( $browser );
2003-02-27 20:28:25 +01:00
2009-11-16 09:04:18 +01:00
echo " charset \t " . translation :: charset () . " \n " ;
2005-11-09 00:15:14 +01:00
$last_year = - 1 ;
foreach ( $holidays as $holiday )
2003-02-27 20:28:25 +01:00
{
2005-11-09 00:15:14 +01:00
$year = $holiday [ 'occurence' ] <= 0 ? 0 : $holiday [ 'occurence' ];
if ( $year != $last_year )
{
echo " \n " . ( $year ? $year : 'regular (year=0)' ) . " : \n " ;
$last_year = $year ;
}
2003-02-27 20:28:25 +01:00
echo " $locale\t $holiday[name] \t $holiday[day] \t $holiday[month] \t $holiday[occurence] \t $holiday[dow] \t $holiday[observance_rule] \n " ;
}
2010-01-02 15:01:05 +01:00
$GLOBALS [ 'egw' ] -> common -> egw_exit ();
2003-02-27 20:28:25 +01:00
}
2005-11-09 00:15:14 +01:00
if ( $this -> debug )
2001-07-28 15:17:30 +02:00
{
2005-11-09 00:15:14 +01:00
$action = $GLOBALS [ 'egw' ] -> link ( '/calendar/egroupware.org/accept_holiday.php' );
2001-07-28 15:17:30 +02:00
}
else
{
2003-09-22 15:57:35 +02:00
$action = 'http://www.egroupware.org/cal/accept_holiday.php' ;
2001-07-28 15:17:30 +02:00
}
2005-11-09 00:15:14 +01:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'noappheader' ] = True ;
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'noappfooter' ] = True ;
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'nofooter' ] = True ;
2009-11-16 09:04:18 +01:00
common :: egw_header ();
2003-02-27 20:28:25 +01:00
echo '<body onLoad="document.submitform.submit()">' . " \n " ;
echo '<form action="' . $action . '" method="post" name="submitform">' . " \n " ;
2001-07-28 15:17:30 +02:00
echo '<input type="hidden" name="locale" value="' . $this -> bo -> locales [ 0 ] . '">' . " \n " ;
2009-11-16 09:04:18 +01:00
echo '<input type="hidden" name="charset" value="' . translation :: charset () . '">' . " \n " ;
2005-11-09 00:15:14 +01:00
foreach ( $holidays as $holiday )
2001-07-28 15:17:30 +02:00
{
2005-11-09 00:15:14 +01:00
echo '<input type="hidden" name="name[]" value="' . htmlspecialchars ( $holiday [ 'name' ]) . '">' . " \n "
. '<input type="hidden" name="day[]" value="' . $holiday [ 'day' ] . '">' . " \n "
. '<input type="hidden" name="month[]" value="' . $holiday [ 'month' ] . '">' . " \n "
. '<input type="hidden" name="occurence[]" value="' . $holiday [ 'occurence' ] . '">' . " \n "
. '<input type="hidden" name="dow[]" value="' . $holiday [ 'dow' ] . '">' . " \n "
. '<input type="hidden" name="observance[]" value="' . $holiday [ 'observance_rule' ] . '">' . " \n \n " ;
2001-07-28 15:17:30 +02:00
}
echo " </form> \n </body> \n </head> " ;
}
/* private functions */
function display_item ( & $p , $field , $data )
{
$var = Array (
2005-11-09 00:15:14 +01:00
'tr_color' => $GLOBALS [ 'egw' ] -> nextmatchs -> alternate_row_color (),
2001-07-28 15:17:30 +02:00
'field' => $field ,
'data' => $data
);
$p -> set_var ( $var );
$p -> parse ( 'rows' , 'list' , True );
}
}
?>