* * http://www.radix.net/~cknudsen * * Modified by Mark Peters * * -------------------------------------------- * * 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. * \**************************************************************************/ 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, 'copy_holiday' => True, 'delete_holiday' => True, 'delete_locale' => True, 'submit' => True ); function uiholiday() { $GLOBALS['phpgw']->nextmatchs = CreateObject('phpgwapi.nextmatchs'); $this->bo = CreateObject('calendar.boholiday'); $this->bo->check_admin(); $this->base_url = $this->bo->base_url; $this->template_dir = $GLOBALS['phpgw']->common->get_tpl_dir('calendar'); $this->sb = CreateObject('phpgwapi.sbox'); $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Holiday Management'); } function admin() { if (!$GLOBALS['phpgw']->acl->check('run',1,'admin')) { $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/admin/index.php')); } unset($GLOBALS['phpgw_info']['flags']['noheader']); unset($GLOBALS['phpgw_info']['flags']['nonavbar']); $GLOBALS['phpgw_info']['flags']['noappfooter'] = True; $GLOBALS['phpgw']->common->phpgw_header(); $p = &$GLOBALS['phpgw']->template; $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( 'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'], 'left_next_matchs' => $GLOBALS['phpgw']->nextmatchs->left('/index.php?menuaction=calendar.uiholiday.admin',$this->bo->start,$this->bo->total), 'right_next_matchs' => $GLOBALS['phpgw']->nextmatchs->right('/index.php?menuaction=calendar.uiholiday.admin',$this->bo->start,$this->bo->total), 'center' => ''.lang('Countries').'', 'sort_name' => $GLOBALS['phpgw']->nextmatchs->show_sort_order($this->bo->sort,'locale',$this->bo->order,'/calendar/'.basename($SCRIPT_FILENAME),lang('Country')), 'header_edit' => lang('Edit'), 'header_delete' => lang('Delete'), 'header_extra' => lang('Submit to Repository'), 'extra_width' => 'width="45%"', 'rule' => '', 'header_rule' => '', '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) { $p->set_var('message',lang('no matches found')); $p->parse('rows','row_empty',True); } else { $p->set_var('submit_extra',' width="5%"'); while (list(,$value) = each($locales)) { $tr_color = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($tr_color); if (! $value) $value = ' '; $var = Array( 'tr_color' => $tr_color, 'group_name' => $value, 'edit_link' => ' '.lang('Edit').' ', 'delete_link' => ' '.lang('Delete').' ', 'extra_link' => ' '.lang('Submit').' '. '     '.lang('Download').' ' ); $p->set_var($var); $p->parse('rows','row',True); } } $var = Array( 'new_action' => $GLOBALS['phpgw']->link($this->base_url,Array('menuaction'=>'calendar.uiholiday.edit_holiday','id'=>0)), 'lang_add' => lang('add'), 'search_action' => $GLOBALS['phpgw']->link($this->base_url,Array('menuaction'=>'calendar.uiholiday.admin')), 'lang_search' => lang('search') ); $p->set_var($var); $p->pparse('out','list'); } function edit_locale($locale='') { if ($locale === '') { $locale = $this->bo->locale; } if ($locale) { $this->bo->locales = array($locale); $this->bo->total = $this->bo->so->holiday_total($locale,$this->bo->query); } if(!$this->bo->total && !isset($this->bo->query)) { $link_params = Array( 'menuaction' => 'calendar.uiholiday.admin' ); $GLOBALS['phpgw']->redirect_link($this->base_url,$link_params); } unset($GLOBALS['phpgw_info']['flags']['noheader']); unset($GLOBALS['phpgw_info']['flags']['nonavbar']); $GLOBALS['phpgw_info']['flags']['noappfooter'] = True; $GLOBALS['phpgw']->common->phpgw_header(); $p = CreateObject('phpgwapi.Template',$this->template_dir); $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'); if (!is_object($GLOBALS['phpgw']->html)) { $GLOBALS['phpgw']->html = CreateObject('phpgwapi.html'); } $html = &$GLOBALS['phpgw']->html; $year_form = str_replace('','',$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(); $total = count($holidays); $var = Array( 'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'], 'left_next_matchs' => $GLOBALS['phpgw']->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['phpgw']->nextmatchs->right('/index.php',$this->bo->start,$total,'&menuaction=calendar.uiholiday.edit_locale&locale='.$this->bo->locales[0].'&year='.$this->bo->year), 'center' => ''.lang('Holidays').' ('.$this->bo->locales[0].')'.$year_form.'', 'sort_name' => $GLOBALS['phpgw']->nextmatchs->show_sort_order($this->bo->sort,'name',$this->bo->order,'/index.php',lang('Holiday'),'&menuaction=calendar.uiholiday.edit_locale&locale='.$this->bo->locales[0].'&year='.$this->bo->year), 'header_edit' => lang('Edit'), 'header_delete' => lang('Delete'), 'header_rule' => ''.$GLOBALS['phpgw']->nextmatchs->show_sort_order($this->bo->sort,'month_num,mday',$this->bo->order,'/index.php',lang('Rule'),'&menuaction=calendar.uiholiday.edit_locale&locale='.$this->bo->locales[0].'&year='.$this->bo->year).'', 'header_extra' => lang('Copy'), 'extra_width' => 'width="5%"' ); $p->set_var($var); if (!count($holidays)) { $p->set_var('message',lang('no matches found')); $p->parse('rows','row_empty',True); } else { $maxmatchs = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']; $end = min($total,$this->bo->start+$maxmatchs); $p->set_var('rows',lang('showing %1 - %2 of %3',1+$this->bo->start,$end,$total)); for($i=$this->bo->start; $i < $end; $i++) { $tr_color = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($tr_color); if (!$holidays[$i]['name']) { $holidays[$i]['name'] = ' '; } $var = Array( 'tr_color' => $tr_color, 'header_delete'=> lang('Delete'), 'group_name' => $holidays[$i]['name'], 'rule' => ''.$this->bo->rule_string($holidays[$i]).'', 'edit_link' => ' '.lang('Edit').' ', 'extra_link' => ' '.lang('Copy').' ', 'delete_link' => ' '.lang('Delete').' ' ); $p->set_var($var); $p->parse('rows','row',True); } } $var = Array( 'new_action' => $GLOBALS['phpgw']->link($this->base_url,Array('menuaction'=>'calendar.uiholiday.edit_holiday','locale'=>$this->bo->locales[0],'id'=>0,'year'=>$this->bo->year)), 'lang_add' => lang('add'), 'back_action' => $GLOBALS['phpgw']->link($this->base_url,Array('menuaction'=>'calendar.uiholiday.admin')), 'lang_back' => lang('Back'), 'search_action'=> $GLOBALS['phpgw']->link($this->base_url,Array('menuaction'=>'calendar.uiholiday.edit_locale','locale'=>$this->bo->locales[0],'year'=>$this->bo->year)), 'lang_search' => lang('search') ); $p->set_var($var); $p->parse('back_button','back_button_form',False); $p->pparse('out','list'); } function copy_holiday() { if(@$this->bo->id) { $holiday = $this->bo->read_entry($this->bo->id); } $this->bo->id = 0; if (!$holiday['occurence'] || $holiday['occurence'] >= 1900) { $holiday['occurence'] = date('Y'); } $this->edit_holiday('',$holiday); } function edit_holiday($error='',$holiday='') { if(@$this->bo->id && !$holiday) { $holiday = $this->bo->read_entry($this->bo->id); } if ($this->locale) { $holiday['locale'] = $this->locale; } unset($GLOBALS['phpgw_info']['flags']['noheader']); unset($GLOBALS['phpgw_info']['flags']['nonavbar']); $GLOBALS['phpgw_info']['flags']['noappfooter'] = True; $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.($this->bo->id ? lang('Edit') : lang('Add')).' '.lang('Holiday'); $GLOBALS['phpgw']->common->phpgw_header(); $t = &$GLOBALS['phpgw']->template; $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'); if (@count($error)) { $message = $GLOBALS['phpgw']->common->error_list($error); } else { $message = ''; } $var = Array( 'title_holiday' => ($this->bo->id ? lang('Edit') : lang('Add')).' '.lang('Holiday'), 'message' => $message, 'actionurl' => $GLOBALS['phpgw']->link($this->base_url,'menuaction=calendar.boholiday.add&year='.$this->bo->year), 'hidden_vars' => ''."\n" . ''."\n" ); $t->set_var($var); // Locale $this->display_item($t,lang('Country'),$this->sb->form_select($holiday['locale'],'holiday[locale]')); // Title/Name $this->display_item($t,lang('title'),''); // Date $this->display_item($t,lang('Date'),$GLOBALS['phpgw']->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'])). ' '.lang('Set a Year only for one-time / non-regular holidays.')); // Occurence $occur = Array( 0 => '', 1 => '1.', 2 => '2.', 3 => '3.', 4 => '4.', 5 => '5.', 99 => lang('Last') ); $out = ''; while(list($key,$value) = each($occur)) { $out .= ''."\n"; } $occurence_html = ''."\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 .= ''."\n"; } $dow_html = ''."\n"; $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'),''. ' '.lang('If checked holidays falling on a weekend, are taken on the monday after.')); $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', 'year' => $this->bo->year, 'locale' => $this->bo->locales[0] ); } else { $link_params = Array( 'menuaction' => 'calendar.uiholiday.admin' ); } $t->set_var(Array( 'action_url_button' => $GLOBALS['phpgw']->link($this->base_url,$link_params), 'action_text_button' => lang('Cancel'), 'action_confirm_button' => '', 'action_extra_field' => '' )); $t->parse('cancel_button','form_button'); 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( 'action_url_button' => $GLOBALS['phpgw']->link($this->base_url,$link_params), 'action_text_button' => lang('Delete'), 'action_confirm_button' => '', 'action_extra_field' => '' )); $t->parse('delete_button','form_button'); } else { $t->set_var('delete_button',' '); } $t->pparse('out','form'); } function delete_locale() { if(!$this->bo->total) { $this->admin(); } unset($GLOBALS['phpgw_info']['flags']['noheader']); unset($GLOBALS['phpgw_info']['flags']['nonavbar']); $GLOBALS['phpgw_info']['flags']['noappfooter'] = True; $GLOBALS['phpgw']->common->phpgw_header(); $p = CreateObject('phpgwapi.Template',$this->template_dir); $p->set_file(Array('form'=>'delete_common.tpl','form_button'=>'form_button_script.tpl')); $p->set_var('messages',lang('Are you sure want to delete this Country?')."
".$this->bo->locales[0]); $var = Array( 'action_url_button' => $GLOBALS['phpgw']->link($this->base_url,Array('menuaction'=>'calendar.uiholiday.admin')), 'action_text_button' => lang('No'), 'action_confirm_button' => '', 'action_extra_field' => '' ); $p->set_var($var); $p->parse('no','form_button'); $var = Array( 'action_url_button' => $GLOBALS['phpgw']->link($this->base_url,Array('menuaction'=>'calendar.boholiday.delete_locale','locale'=>$this->bo->locales[0])), '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) { $this->edit_locale(); } unset($GLOBALS['phpgw_info']['flags']['noheader']); unset($GLOBALS['phpgw_info']['flags']['nonavbar']); $GLOBALS['phpgw_info']['flags']['noappfooter'] = True; $GLOBALS['phpgw']->common->phpgw_header(); $p = CreateObject('phpgwapi.Template',$this->template_dir); $p->set_file(Array('form'=>'delete_common.tpl','form_button'=>'form_button_script.tpl')); $p->set_var('messages',lang('Are you sure want to delete this holiday?')."
".$holiday['name'].' ('.$this->bo->locales[0].') '.$this->bo->rule_string($holiday)); $var = Array( 'action_url_button' => $GLOBALS['phpgw']->link($this->base_url,Array('menuaction'=>'calendar.uiholiday.edit_locale','locale'=>$this->bo->locales[0],'year'=>$this->bo->year)), 'action_text_button' => lang('No'), 'action_confirm_button' => '', 'action_extra_field' => '' ); $p->set_var($var); $p->parse('no','form_button'); $var = Array( 'action_url_button' => $GLOBALS['phpgw']->link($this->base_url,Array('menuaction'=>'calendar.boholiday.delete_holiday','locale'=>$this->bo->locales[0],'id'=>$this->bo->id,'year'=>$this->bo->year)), '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]) { $this->admin(); } $this->bo->year = 0; // for a complete list with all years $holidays = $this->bo->get_holiday_list(); if (isset($_GET['download'])) { $locale = $this->bo->locales[0]; $browser = CreateObject('phpgwapi.browser'); $browser->content_header("holidays.$locale.csv",'text/text'); unset($browser); while (list(,$holiday) = @each($holidays)) { echo "$locale\t$holiday[name]\t$holiday[day]\t$holiday[month]\t$holiday[occurence]\t$holiday[dow]\t$holiday[observance_rule]\n"; } $GLOBALS['phpgw']->common->phpgw_exit(); } elseif($this->debug) { $action = $GLOBALS['phpgw']->link('/calendar/phpgroupware.org/accept_holiday.php'); } else { $action = 'http://www.egroupware.org/cal/accept_holiday.php'; } $GLOBALS['phpgw_info']['flags']['noappheader'] = True; $GLOBALS['phpgw_info']['flags']['noappfooter'] = True; $GLOBALS['phpgw_info']['flags']['nofooter'] = True; $GLOBALS['phpgw']->common->phpgw_header(); echo ''."\n"; echo '
'."\n"; $c_holidays = count($holidays); echo ''."\n"; for($i=0;$i<$c_holidays;$i++) { echo ''."\n" . ''."\n" . ''."\n" . ''."\n" . ''."\n" . ''."\n"; } echo "
\n\n"; } /* private functions */ function display_item(&$p,$field,$data) { $var = Array( 'tr_color' => $GLOBALS['phpgw']->nextmatchs->alternate_row_color(), 'field' => $field, 'data' => $data ); $p->set_var($var); $p->parse('rows','list',True); } } ?>