source: trunk/calendar/inc/class.uiholiday.inc.php @ 2880

Revision 2880, 18.5 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1058 - Removendo reload de formulários do módulo admin.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2  /**************************************************************************\
3  * eGroupWare - Calendar                                                    *
4  * http://www.egroupware.org                                                *
5  * Based on Webcalendar by Craig Knudsen <cknudsen@radix.net>               *
6  *          http://www.radix.net/~cknudsen                                  *
7  * Modified by Mark Peters <skeeter@phpgroupware.org>                       *
8  * --------------------------------------------                             *
9  *  This program is free software; you can redistribute it and/or modify it *
10  *  under the terms of the GNU General Public License as published by the   *
11  *  Free Software Foundation; either version 2 of the License, or (at your  *
12  *  option) any later version.                                              *
13  \**************************************************************************/
14
15
16        class uiholiday
17        {
18                var $debug = False;
19                var $base_url;
20                var $bo;
21                var $template_dir;
22                var $holidays;
23                var $cat_id;
24
25                var $public_functions = array(
26                        'admin' => True,
27                        'edit_locale' => True,
28                        'edit_holiday' => True,
29                        'copy_holiday' => True,
30                        'delete_holiday' => True,
31                        'delete_locale' => True,
32                        'submit'        => True
33                );
34
35                function uiholiday()
36                {
37                        $GLOBALS['phpgw']->nextmatchs = CreateObject('phpgwapi.nextmatchs');
38
39                        $this->bo = CreateObject('calendar.boholiday');
40                        $this->bo->check_admin();
41                        $this->base_url = $this->bo->base_url;
42                        $this->template_dir = $GLOBALS['phpgw']->common->get_tpl_dir('calendar');
43                        $this->sb = CreateObject('phpgwapi.sbox');
44
45                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Holiday Management');
46                }
47
48                function admin()
49                {
50                        if (!$GLOBALS['phpgw']->acl->check('run',1,'admin'))
51                        {
52                              $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/admin/index.php'));
53                        }
54                        $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
55
56                        $p = &$GLOBALS['phpgw']->template;
57                        $p->set_file(Array('locales'=>'locales.tpl'));
58                        $p->set_block('locales','list','list');
59                        $p->set_block('locales','row','row');
60                        $p->set_block('locales','row_empty','row_empty');
61                        $p->set_block('locales','submit_column','submit_column');
62                        $p->set_block('locales','back_button_form','back_button_form');
63
64                        $var = Array(
65                                'th_bg'         => $GLOBALS['phpgw_info']['theme']['th_bg'],
66                                'left_next_matchs'      => $GLOBALS['phpgw']->nextmatchs->left('/index.php?menuaction=calendar.uiholiday.admin',$this->bo->start,$this->bo->total),
67                                'right_next_matchs'     => $GLOBALS['phpgw']->nextmatchs->right('/index.php?menuaction=calendar.uiholiday.admin',$this->bo->start,$this->bo->total),
68                                'center'                        => '<td align="center">'.lang('Countries').'</td>',
69                                'sort_name'             => $GLOBALS['phpgw']->nextmatchs->show_sort_order($this->bo->sort,'locale',$this->bo->order,'/calendar/'.basename($SCRIPT_FILENAME),lang('Country')),
70                                'header_edit'   => lang('Edit'),
71                                'header_delete' => lang('Delete'),
72                                'header_extra'  => lang('Submit to Repository'),
73                                'extra_width'  => 'width="45%"',
74                                'rule'         => '',
75                                'header_rule'  => '',
76                                'back_button'   => '',
77                                'info' => ''
78                        );
79
80                        $p->set_var($var);
81
82                        $locales = $this->bo->get_locale_list($this->bo->sort, $this->bo->order, $this->bo->query, $this->bo->total);
83                        @reset($locales);
84                        if (!$locales)
85                        {
86                                $p->set_var('message',lang('no matches found'));
87                                $p->parse('rows','row_empty',True);
88                        }
89                        else
90                        {
91                                $p->set_var('submit_extra',' width="5%"');
92                                while (list(,$value) = each($locales))
93                                {
94                                        $tr_color = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($tr_color);
95                                        if (! $value)  $value  = '&nbsp;';
96
97                                        $var = Array(
98                                                'tr_color'              => $tr_color,
99                                                'group_name'    => $value,
100                                                'edit_link'             => '<a href="'.$GLOBALS['phpgw']->link($this->base_url,Array('menuaction'=>'calendar.uiholiday.edit_locale','locale'=>$value)) . '"> '.lang('Edit').' </a>',
101                                                'delete_link'   => '<a href="'.$GLOBALS['phpgw']->link($this->base_url,Array('menuaction'=>'calendar.uiholiday.delete_locale','locale'=>$value)).'"> '.lang('Delete').' </a>',
102                                                'extra_link'    => '<a href="'.$GLOBALS['phpgw']->link($this->base_url,Array('menuaction'=>'calendar.uiholiday.submit','locale'=>$value)).'"> '.lang('Submit').' </a>'.
103                                                        ' &nbsp; &nbsp; <a href="'.$GLOBALS['phpgw']->link($this->base_url,Array('menuaction'=>'calendar.uiholiday.submit','locale'=>$value,'download'=>1)).'"> '.lang('Download').' </a>'
104                                        );
105                                        $p->set_var($var);
106                                        $p->parse('rows','row',True);
107                                }
108                        }
109
110                        $var = Array(
111                                'new_action'    => $GLOBALS[ 'phpgw' ] -> link($this->base_url,Array('menuaction'=>'calendar.uiholiday.edit_holiday','id'=>0)),
112                                'lang_add'              => lang( 'add' ),
113                                'back_action'   => $GLOBALS[ 'phpgw' ] -> link( '/admin/' ),
114                                'lang_back'             => lang( 'Back' ),
115                                'search_action' => $GLOBALS[ 'phpgw' ] -> link($this->base_url,Array('menuaction'=>'calendar.uiholiday.admin')),
116                                'lang_search'   => lang('search')
117                        );
118
119                        $p->set_var($var);
120                        $p->parse('back_button','back_button_form',False);
121                        $p->pparse('out','list');
122                }
123
124                function edit_locale($locale='')
125                {
126                        if ($locale === '')
127                        {
128                                $locale = $this->bo->locale;
129                        }
130                        if ($locale)
131                        {
132                                $this->bo->locales = array($locale);
133                                $this->bo->total = $this->bo->so->holiday_total($locale,$this->bo->query);
134                        }
135                        if(!$this->bo->total && !isset($this->bo->query))
136                        {
137                                $link_params = Array(
138                                        'menuaction'    => 'calendar.uiholiday.admin'
139                                );
140                                $GLOBALS['phpgw']->redirect_link($this->base_url,$link_params);
141                        }
142                        //unset($GLOBALS['phpgw_info']['flags']['noheader']);
143                        //unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
144                        $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
145                        //$GLOBALS['phpgw']->common->phpgw_header();
146                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
147                        $p->set_file(Array('locale'=>'locales.tpl'));
148                        $p->set_block('locale','list','list');
149                        $p->set_block('locale','row','row');
150                        $p->set_block('locale','row_empty','row_empty');
151                        $p->set_block('locale','back_button_form','back_button_form');
152
153                        if (!is_object($GLOBALS['phpgw']->html))
154                        {
155                                $GLOBALS['phpgw']->html = CreateObject('phpgwapi.html');
156                        }
157                        $html = &$GLOBALS['phpgw']->html;
158                        $year_form = str_replace('<option value=""></option>','',$html->form($html->sbox_submit($this->sb->getYears('year',$this->bo->year),true),array(),
159                                $this->base_url,Array('menuaction'=>'calendar.uiholiday.edit_locale','locale'=>$this->bo->locales[0])));
160                        unset($html);
161
162                        $holidays = $this->bo->get_holiday_list();
163                        $total = count($holidays);
164
165                        $var = Array(
166                                'th_bg'                         => $GLOBALS['phpgw_info']['theme']['th_bg'],
167                                '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),
168                                '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),
169                                'center'                        => '<td align="right">'.lang('Holidays').' ('.$this->bo->locales[0].')</td><td align="left">'.$year_form.'</td>',
170                                '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),
171                                'header_edit'           => lang('Edit'),
172                                'header_delete'         => lang('Delete'),
173                                'header_rule'           => '<td>'.$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).'</td>',
174                                'header_extra'          => lang('Copy'),
175                                'extra_width'           => 'width="5%"',
176                                'info'                          => ''
177                        );
178
179                        $p->set_var($var);
180
181                        if (!count($holidays))
182                        {
183                                $p->set_var('message',lang('no matches found'));
184                                $p->parse('rows','row_empty',True);
185                        }
186                        else
187                        {
188                                $maxmatchs = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
189                                $end = min($total,$this->bo->start+$maxmatchs);
190                                $p->set_var('info',lang('showing %1 - %2 of %3',1+$this->bo->start,$end,$total));
191                                for($i=$this->bo->start; $i < $end; $i++)
192                                {
193                                        $tr_color = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($tr_color);
194                                        if (!$holidays[$i]['name'])
195                                        {
196                                                $holidays[$i]['name'] = '&nbsp;';
197                                        }
198
199                                        $var = Array(
200                                                'tr_color'              => $tr_color,
201                                                'header_delete'=> lang('Delete'),
202                                                'group_name'    => $holidays[$i]['name'],
203                                                'rule'                  => '<td>'.$this->bo->rule_string($holidays[$i]).'</td>',
204                                                'edit_link'             => '<a href="'.$GLOBALS['phpgw']->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>',
205                                                'extra_link'    => '<a href="'.$GLOBALS['phpgw']->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>',
206                                                'delete_link'   => '<a href="'.$GLOBALS['phpgw']->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>'
207                                        );
208
209                                        $p->set_var($var);
210                                        $p->parse('rows','row',True);
211                                }
212                        }
213
214                        $var = Array(
215                                '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)),
216                                'lang_add'              => lang('add'),
217                                'back_action'   => $GLOBALS['phpgw']->link($this->base_url,Array('menuaction'=>'calendar.uiholiday.admin')),
218                                'lang_back'             => lang('Back'),
219                                'search_action'=> $GLOBALS['phpgw']->link($this->base_url,Array('menuaction'=>'calendar.uiholiday.edit_locale','locale'=>$this->bo->locales[0],'year'=>$this->bo->year)),
220                                'lang_search'   => lang('search')
221                        );
222                        $p->set_var($var);
223                        $p->parse('back_button','back_button_form',False);
224                        $p->pparse('out','list');
225                }
226
227                function copy_holiday()
228                {
229                        if(@$this->bo->id)
230                        {
231                                $holiday = $this->bo->read_entry($this->bo->id);
232                        }
233                        $this->bo->id = 0;
234
235                        if (!$holiday['occurence'] || $holiday['occurence'] >= 1900)
236                        {
237                                $holiday['occurence'] = date('Y');
238                        }
239                        $this->edit_holiday('',$holiday);
240                }
241
242                function edit_holiday($error='',$holiday='')
243                {
244                        if(@$this->bo->id && !$holiday)
245                        {
246                                $holiday = $this->bo->read_entry($this->bo->id);
247                        }
248                        if ($this->locale)
249                        {
250                                $holiday['locale'] = $this->locale;
251                        }
252                        //unset($GLOBALS['phpgw_info']['flags']['noheader']);
253                        //unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
254                        $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
255                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.($this->bo->id ? lang('Edit') : lang('Add')).' '.lang('Holiday');
256                        //$GLOBALS['phpgw']->common->phpgw_header();
257
258                        $t = &$GLOBALS['phpgw']->template;
259                        $t->set_file(Array('holiday'=>'holiday.tpl','form_button'=>'form_button_script.tpl'));
260                        $t->set_block('holiday','form','form');
261                        $t->set_block('holiday','list','list');
262
263                        if (@count($error))
264                        {
265                                $message = $GLOBALS['phpgw']->common->error_list($error);
266                        }
267                        else
268                        {
269                                $message = '';
270                        }
271
272                        $var = Array(
273                                'title_holiday' => ($this->bo->id ? lang('Edit') : lang('Add')).' '.lang('Holiday'),
274                                'message'       => $message,
275                                'actionurl'     => $GLOBALS['phpgw']->link($this->base_url,'menuaction=calendar.boholiday.add&year='.$this->bo->year),
276                                'hidden_vars'   => '<input type="hidden" name="holiday[hol_id]" value="'.$this->bo->id.'">'."\n"
277                                        . '<input type="hidden" name="holiday[locales]" value="'.$this->bo->locales[0].'">'."\n"
278                        );
279                        $t->set_var($var);
280
281// Locale
282                        $this->display_item($t,lang('Country'),$this->sb->form_select($holiday['locale'],'holiday[locale]'));
283
284// Title/Name
285                        $this->display_item($t,lang('title'),'<input name="holiday[name]" size="60" maxlength="50" value="'.$holiday['name'].'">');
286
287// Date
288                        $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'])).
289                                '&nbsp;'.lang('Set a Year only for one-time / non-regular holidays.'));
290
291// Occurence
292                        $occur = Array(
293                                0       => '',
294                                1       => '1.',
295                                2       => '2.',
296                                3       => '3.',
297                                4       => '4.',
298                                5       => '5.',
299                                99      => lang('Last')
300                        );
301                        $out = '';
302                        while(list($key,$value) = each($occur))
303                        {
304                                $out .= '<option value="'.$key.'"'.($holiday['occurence']==$key?' selected':'').'>'.$value.'</option>'."\n";
305                        }
306                        $occurence_html = '<select name="holiday[occurence]">'."\n".$out.'</select>'."\n";
307
308                        $dow = Array(
309                                0       => lang('Sun'),
310                                1       => lang('Mon'),
311                                2       => lang('Tue'),
312                                3       => lang('Wed'),
313                                4       => lang('Thu'),
314                                5       => lang('Fri'),
315                                6       => lang('Sat')
316                        );
317                        $out = '';
318                        for($i=0;$i<7;$i++)
319                        {
320                                $out .= '<option value="'.$i.'"'.($holiday['dow']==$i?' selected':'').'>'.$dow[$i].'</option>'."\n";
321                        }
322                        $dow_html = '<select name="holiday[dow]">'."\n".$out.'</select>'."\n";
323                        $this->display_item($t,lang('Occurence'),$occurence_html.'&nbsp;'.$dow_html.
324                                '&nbsp;'.lang('You can either set a Year or a Occurence, not both !!!'));
325                        $this->display_item($t,lang('Observance Rule'),'<input type="checkbox" name="holiday[observance_rule]" value="True"'.($holiday['observance_rule']?' checked':'').'>'.
326                                '&nbsp;'.lang('If checked holidays falling on a weekend, are taken on the monday after.'));
327
328                        $t->set_var('lang_add',lang('Save'));
329                        $t->set_var('lang_reset',lang('Reset'));
330
331                        if(@$this->bo->locales[0])
332                        {
333                                $link_params = Array(
334                                        'menuaction'    => 'calendar.uiholiday.edit_locale',
335                                        'year'                  => $this->bo->year,
336                                        'locale'                => $this->bo->locales[0]
337                                );
338                        }
339                        else
340                        {
341                                $link_params = Array(
342                                        'menuaction'    => 'calendar.uiholiday.admin'
343                                );
344                        }
345
346                        $t->set_var(Array(
347                                'action_cancel' => $GLOBALS['phpgw']->link($this->base_url,$link_params),
348                                'lang_cancel'   => lang('Cancel'),
349                        ));
350
351                        if ($this->bo->id)
352                        {
353                                $link_params = Array(
354                                        'menuaction'    => 'calendar.uiholiday.delete_holiday',
355                                        'year'                  => $this->bo->year,
356                                        'locale'                => $this->bo->locales[0],
357                                        'id'                    => $this->bo->id
358                                );
359                                $t->set_var(Array(
360                                        'action_url_button'     => $GLOBALS['phpgw']->link($this->base_url,$link_params),
361                                        'action_text_button'    => lang('Delete'),
362                                        'action_extra_field'    => ''
363                                ));
364                                $t->parse('delete_button','form_button');
365                        }
366                        else
367                        {
368                                $t->set_var('delete_button','&nbsp;');
369                        }
370                        $t->pparse('out','form');
371                }
372
373
374                function delete_locale()
375                {
376                        if(!$this->bo->total)
377                        {
378                                $this->admin();
379                        }
380
381                        $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
382
383                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
384                        $p->set_file( array( 'form' => 'delete_common.tpl' ) );
385
386                        $p->set_var( array(
387                                'messages' => lang( 'Are you sure want to delete this Country?' ) . '<br>' . $this->bo->locales[0],
388                                'agree_action' => $GLOBALS[ 'phpgw' ] -> link( '/', "menuaction=calendar.boholiday.delete_locale&locale={$this -> bo -> locales[ 0 ]}" ),
389                                'agree_lang' => lang('Yes'),
390                                'disagree_action' => $GLOBALS[ 'phpgw' ] -> link( '/', 'menuaction=calendar.uiholiday.admin' ),
391                                'disagree_lang' => lang('No')
392                        ) );
393
394                        $p->pparse( 'out', 'form' );
395                }
396
397                function delete_holiday()
398                {
399                        $holiday = $this->bo->read_entry($this->bo->id);
400
401                        if(!$holiday)
402                        {
403                                $this->edit_locale();
404                        }
405
406                        $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
407
408                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
409                        $p->set_file( array( 'form' => 'delete_common.tpl' ) );
410
411                        $p->set_var( array(
412                                'messages' => lang('Are you sure want to delete this holiday?') . "<br>{$holiday[ 'name' ]} ({$this -> bo -> locales[ 0 ]}) {$this -> bo -> rule_string( $holiday )}",
413                                'agree_action' => $GLOBALS[ 'phpgw' ] -> link( '/', "menuaction=calendar.boholiday.delete_holiday&locale={$this -> bo -> locales[ 0 ]}&id={$this -> bo -> id}&year={$this -> bo -> year}" ),
414                                'agree_lang' => lang('Yes'),
415                                'disagree_action' => $GLOBALS[ 'phpgw' ] -> link( '/', "menuaction=calendar.uiholiday.edit_locale&locale={$this -> bo -> locales[ 0 ]}&year={$this -> bo -> year}" ),
416                                'disagree_lang' => lang('No')
417                        ) );
418
419                        $p->pparse('out','form');
420                }
421
422                function submit()
423                {
424                        if(!@$this->bo->locales[0])
425                        {
426                                $this->admin();
427                        }
428                        $this->bo->year = 0;    // for a complete list with all years
429                        $holidays = $this->bo->get_holiday_list();
430
431                        if (isset($_GET['download']))
432                        {
433                                $locale = $this->bo->locales[0];
434                                $browser = CreateObject('phpgwapi.browser');
435                                $browser->content_header("holidays.$locale.csv",'text/text');
436                                unset($browser);
437
438                                while (list(,$holiday) = @each($holidays))
439                                {
440                                        echo "$locale\t$holiday[name]\t$holiday[day]\t$holiday[month]\t$holiday[occurence]\t$holiday[dow]\t$holiday[observance_rule]\n";
441                                }
442                                $GLOBALS['phpgw']->common->phpgw_exit();
443                        }
444                        elseif($this->debug)
445                        {
446                                $action = $GLOBALS['phpgw']->link('/calendar/phpgroupware.org/accept_holiday.php');
447                        }
448                        else
449                        {
450                                $action = 'http://www.egroupware.org/cal/accept_holiday.php';
451                        }
452                        $GLOBALS['phpgw_info']['flags']['noappheader']  = True;
453                        $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
454                        $GLOBALS['phpgw_info']['flags']['nofooter'] = True;
455                        //$GLOBALS['phpgw']->common->phpgw_header();
456
457                        echo '<body onLoad="document.submitform.submit()">'."\n";
458                        echo '<form action="'.$action.'" method="post" name="submitform">'."\n";
459
460                        $c_holidays = count($holidays);
461                        echo '<input type="hidden" name="locale" value="'.$this->bo->locales[0].'">'."\n";
462                        for($i=0;$i<$c_holidays;$i++)
463                        {
464                                echo '<input type="hidden" name="name[]" value="'.htmlspecialchars($holidays[$i]['name']).'">'."\n"
465                                        . '<input type="hidden" name="day[]" value="'.$holidays[$i]['day'].'">'."\n"
466                                        . '<input type="hidden" name="month[]" value="'.$holidays[$i]['month'].'">'."\n"
467                                        . '<input type="hidden" name="occurence[]" value="'.$holidays[$i]['occurence'].'">'."\n"
468                                        . '<input type="hidden" name="dow[]" value="'.$holidays[$i]['dow'].'">'."\n"
469                                        . '<input type="hidden" name="observance[]" value="'.$holidays[$i]['observance_rule'].'">'."\n";
470                        }
471                        echo "</form>\n</body>\n</head>";
472                }
473
474                /* private functions */
475                function display_item(&$p,$field,$data)
476                {
477                        $var = Array(
478                                'tr_color' => $GLOBALS['phpgw']->nextmatchs->alternate_row_color(),
479                                'field' => $field,
480                                'data'  => $data
481                        );
482                        $p->set_var($var);
483                        $p->parse('rows','list',True);
484                }
485        }
486?>
Note: See TracBrowser for help on using the repository browser.