source: trunk/calendar/templates/default/header.inc.php @ 7673

Revision 7673, 9.2 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Correcoes para Performance: Function Within Loop Declaration.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2  /**************************************************************************\
3  * eGroupWare                                                               *
4  * http://www.egroupware.org                                                *
5  * --------------------------------------------                             *
6  *  This program is free software; you can redistribute it and/or modify it *
7  *  under the terms of the GNU General Public License as published by the   *
8  *  Free Software Foundation; either version 2 of the License, or (at your  *
9  *  option) any later version.                                              *
10  \**************************************************************************/
11
12
13        function add_col(&$tpl,$str)
14        {
15                $tpl->set_var('str',$str);
16                $tpl->parse('header_column','head_col',True);
17        }
18
19        function add_image_ahref($link,$image,$alt)
20        {
21                return '<a href="'.$link.'"><img src="'.$GLOBALS['phpgw']->common->image('calendar',$image).'" alt="'.$alt.'" title="'.$alt.'" border="0"></a>';
22        }
23
24        $refer = explode('.',$_SERVER ['REQUEST_URI']);
25        $referrer = $refer[3];
26
27        $templates = Array(
28                'head_tpl'      => 'head.tpl',
29                'form_button_dropdown'  => 'form_button_dropdown.tpl',
30                'form_button_script'    => 'form_button_script.tpl'
31        );
32        $tpl->set_file($templates);
33        $tpl->set_block('head_tpl','head','head');
34        $tpl->set_block('head_tpl','head_table','head_table');
35        $tpl->set_block('head_tpl','head_col','head_col');
36        $tpl->set_block('form_button_script','form_button');
37
38        if(floor(phpversion()) >= 4)
39        {
40                $tpl->set_var('cols',8);
41        }
42        else
43        {
44                $tpl->set_var('cols',7);
45        }
46
47        $today = date('Ymd',$GLOBALS['phpgw']->datetime->users_localtime);
48
49        $col_width = 12;
50
51        add_col($tpl,'  <td width="2%">&nbsp;</td>');
52
53        add_col($tpl,'  <td width="2%">'.add_image_ahref($this->page('day','&date='.$today),'today',lang('Today')).'</td>');
54
55        add_col($tpl,'  <td width="2%" align="left">'.add_image_ahref($this->page('week','&date='.$today),'week',lang('This week')).'</td>');
56
57        add_col($tpl,'  <td width="2%" align="left">'.add_image_ahref($this->page('month','&date='.$today),'month',lang('This month')).'</td>');
58
59        add_col($tpl,'  <td width="2%" align="left">'.add_image_ahref($this->page('year','&date='.$today),'year',lang('This Year')).'</td>');
60
61        if(floor(phpversion()) >= 4)
62        {
63                add_col($tpl,'  <td width="2%" align="left">'.add_image_ahref($this->page('planner','&date='.$today),'planner',lang('Planner')).'</td>');
64                $col_width += 2;
65        }
66
67        //add_col($tpl,'  <td width="2%" align="left">'.add_image_ahref($this->page('matrixselect'),'view',lang('Daily Matrix View')).'</td>');
68
69        add_col($tpl,'  <td width="'.(100 - $col_width).'%" align="left"'.(floor(phpversion()) < 4?' colspan="2"':'').'>&nbsp;</td>');
70
71        $tpl->parse('row','head_table',True);
72
73        $tpl->set_var('header_column','');
74        $tpl->set_var('cols',$cols);
75
76        if($referrer!='view')
77        {
78                $remainder = 72;
79               
80                $date = (isset($GLOBALS['date'])?$GLOBALS['date']:'');
81                $date = (isset($GLOBALS['HTTP_GET_VARS']['date'])?$GLOBALS['HTTP_GET_VARS']['date']:$date);
82                $date = ($date=='' && isset($GLOBALS['HTTP_POST_VARS']['date'])?$GLOBALS['HTTP_POST_VARS']['date']:$date);
83
84                $base_hidden_vars = '<input type="hidden" name="from" value="'.$GLOBALS['HTTP_GET_VARS']['menuaction'].'">'."\n";
85                if(isset($GLOBALS['HTTP_GET_VARS']['cal_id']) && $GLOBALS['HTTP_GET_VARS']['cal_id'] != 0)
86                {
87                        $base_hidden_vars .= '    <input type="hidden" name="cal_id" value="'.$GLOBALS['HTTP_GET_VARS']['cal_id'].'">'."\n";
88                }
89                if(isset($GLOBALS['HTTP_POST_VARS']['keywords']) && $GLOBALS['HTTP_POST_VARS']['keywords'])
90                {
91                        $base_hidden_vars .= '    <input type="hidden" name="keywords" value="'.$GLOBALS['HTTP_POST_VARS']['keywords'].'">'."\n";
92                }
93                if(isset($GLOBALS['HTTP_POST_VARS']['matrixtype']) && $GLOBALS['HTTP_POST_VARS']['matrixtype'])
94                {
95                        $base_hidden_vars .= '    <input type="hidden" name="matrixtype" value="'.$GLOBALS['HTTP_POST_VARS']['matrixtype'].'">'."\n";
96                }
97                if($date)
98                {
99                        $base_hidden_vars .= '    <input type="hidden" name="date" value="'.$date.'">'."\n";
100                }
101                $base_hidden_vars .= '    <input type="hidden" name="month" value="'.$this->bo->month.'">'."\n";
102                $base_hidden_vars .= '    <input type="hidden" name="day" value="'.$this->bo->day.'">'."\n";
103                $base_hidden_vars .= '    <input type="hidden" name="year" value="'.$this->bo->year.'">'."\n";
104               
105                if(isset($GLOBALS['HTTP_POST_VARS']['participants']) && $GLOBALS['HTTP_POST_VARS']['participants'])
106                {
107            $globals_count = count($GLOBALS['HTTP_POST_VARS']['participants']);
108                        for ($i=0;$i<$globals_count;++$i)
109                        {
110                                $base_hidden_vars .= '    <input type="hidden" name="participants[]" value="'.$GLOBALS['HTTP_POST_VARS']['participants'][$i].'">'."\n";
111                        }
112                }
113
114                $var = Array(
115                        'form_width' => '28',
116                        'form_link'     => $this->page($referrer),
117                        'form_name'     => 'cat_id',
118                        'title' => lang('Category'),
119                        'hidden_vars'   => $base_hidden_vars,
120                        'form_options'  => '<option value="0">'.lang('All').'</option>'.$this->cat->formated_list('select','all',$this->bo->cat_id,'True'),
121                        'button_value'  => lang('Go!')
122                );
123                $tpl->set_var($var);
124                $tpl->set_var('str',$tpl->fp('out','form_button_dropdown'));
125                $tpl->parse('header_column','head_col',True);
126
127                if($GLOBALS['HTTP_GET_VARS']['menuaction'] == 'calendar.uicalendar.planner')
128                {
129                        $remainder -= 28;
130                        print_debug('Sort By',$this->bo->sortby);
131
132                        $form_options = '<option value="user"'.($this->bo->sortby=='user'?' selected':'').'>'.lang('User').'</option>'."\n";
133                        $form_options .= '     <option value="category"'.((!isset($this->bo->sortby) || !$this->bo->sortby) || $this->bo->sortby=='category'?' selected':'').'>'.lang('Category').'</option>'."\n";
134               
135                        $var = Array(
136                                'form_width' => '28',
137                                'form_link'     => $this->page($referrer),
138                                'form_name'     => 'sortby',
139                                'title' => lang('Sort By'),
140                                'hidden_vars'   => $base_hidden_vars,
141                                'form_options'  => $form_options,
142                                'button_value'  => lang('Go!')
143                        );
144                        $tpl->set_var($var);
145                        $tpl->set_var('str',$tpl->fp('out','form_button_dropdown'));
146                        $tpl->parse('header_column','head_col',True);
147                }
148
149                if($this->bo->check_perms(PHPGW_ACL_PRIVATE))
150                {
151                        $remainder -= 28;
152                        $form_options = '<option value=" all "'.($this->bo->filter==' all '?' selected':'').'>'.lang('All').'</option>'."\n";
153                        $form_options .= '     <option value=" private "'.((!isset($this->bo->filter) || !$this->bo->filter) || $this->bo->filter==' private '?' selected':'').'>'.lang('Private Only').'</option>'."\n";
154               
155                        $var = Array(
156                                'form_width' => '28',
157                                'form_link'     => $this->page($referrer),
158                                'form_name'     => 'filter',
159                                'title' => lang('Filter'),
160                                'hidden_vars'   => $base_hidden_vars,
161                                'form_options'  => $form_options,
162                                'button_value'  => lang('Go!')
163                        );
164                        $tpl->set_var($var);
165                        $tpl->set_var('str',$tpl->fp('out','form_button_dropdown'));
166                        $tpl->parse('header_column','head_col',True);
167                }
168//aqui !!
169
170                if((!isset($GLOBALS['phpgw_info']['server']['deny_user_grants_access']) || !$GLOBALS['phpgw_info']['server']['deny_user_grants_access']) && count($this->bo->grants) > 0)
171                {
172                        $form_options = '';
173                       
174                        $drop_down = $this->bo->list_cals(); //hehe
175                       
176                        foreach($drop_down as $key => $grant)
177                        {                                       
178                                if(!strstr(($grant['value']),'g_'))
179                                        $form_options .= '    <option value="'.$grant['value'].'"'.($grant['grantor']==$this->bo->owner?' selected':'').'>'.$grant['name'].'</option>'."\n";
180                        }
181               
182                        $var = Array(
183                                'form_width' => $remainder,
184                                'form_link'     => $this->page($referrer),
185                                'form_name'     => 'owner',
186                                'title' => lang('User'),
187                                'hidden_vars'   => $base_hidden_vars,
188                                'form_options'  => $form_options,
189                                'button_value'  => lang('Go!')
190                        );
191                        $tpl->set_var($var);
192                        $tpl->set_var('str',$tpl->fp('out','form_button_dropdown'));
193                        $tpl->parse('header_column','head_col',True);
194                }
195        }
196
197        $hidden_vars = '    <input type="hidden" name="from" value="'.$GLOBALS['HTTP_GET_VARS']['menuaction'].'">'."\n";
198        if(isset($GLOBALS['HTTP_GET_VARS']['date']) && $GLOBALS['HTTP_GET_VARS']['date'])
199        {
200                $hidden_vars .= '    <input type="hidden" name="date" value="'.$GLOBALS['HTTP_GET_VARS']['date'].'">'."\n";
201        }
202        $hidden_vars .= '    <input type="hidden" name="month" value="'.$this->bo->month.'">'."\n";
203        $hidden_vars .= '    <input type="hidden" name="day" value="'.$this->bo->day.'">'."\n";
204        $hidden_vars .= '    <input type="hidden" name="year" value="'.$this->bo->year.'">'."\n";
205        if(isset($this->bo->filter) && $this->bo->filter)
206        {
207                $hidden_vars .= '    <input type="hidden" name="filter" value="'.$this->bo->filter.'">'."\n";
208        }
209        if(isset($this->bo->sortby) && $this->bo->sortby)
210        {
211                $hidden_vars .= '    <input type="hidden" name="sortby" value="'.$this->bo->sortby.'">'."\n";
212        }
213        if(isset($this->bo->num_months) && $this->bo->num_months)
214        {
215                $hidden_vars .= '    <input type="hidden" name="num_months" value="'.$this->bo->num_months.'">'."\n";
216        }
217        $hidden_vars .= '    <input name="keywords"'.($GLOBALS['HTTP_POST_VARS']['keywords']?' value="'.$GLOBALS['HTTP_POST_VARS']['keywords'].'"':'').'>';
218
219        $var = Array(
220                'action_url_button'     => $this->page('search'),
221                'action_text_button'    => lang('Search'),
222                'action_confirm_button' => '',
223                'action_extra_field'    => $hidden_vars
224        );
225        $tpl->set_var($var);
226        $button = $tpl->fp('out','form_button');
227        $tpl->set_var('str','<td align="right" valign="bottom">'.$button.'</td>');
228        $tpl->parse('header_column','head_col',True);
229        $tpl->parse('row','head_table',True);
230?>
Note: See TracBrowser for help on using the repository browser.