source: branches/2.2/mobile/inc/class.mobiletemplate.inc.php @ 4694

Revision 4694, 9.4 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #2093 - Corrigido o caminho do link para Versão Clássica dentro do mobile

  • Property svn:executable set to *
Line 
1<?php
2//include_once(PHPGW_INCLUDE_ROOT.'/mobile/inc/class.ui_mobile.inc.php');
3        class mobiletemplate
4        {
5                private $template;
6                private $href_back;
7               
8                /*
9                * @function mobiletemplate
10                * @abstract Construtor da classe, que monta o template home
11                * @author Nilton Emilio Buhrer Neto <niltonneto@celepar.pr.gov.br>
12                */             
13                function mobiletemplate()
14                {
15                        $this->template = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
16                       
17                        $template = $GLOBALS['phpgw']->session->appsession('mobile.layout','mobile');
18                       
19                        if( $template == "mini_desktop" )
20                        {
21                                $url_expresso = $GLOBALS['phpgw_info']['server']['webserver_url'];
22                                $url_expresso = ( !empty($url_expresso) ) ? $url_expresso : '/';
23               
24                                if(strrpos($url_expresso,'/') === false || strrpos($url_expresso,'/') != (strlen($url_expresso)-1))
25                                {
26                                        $url_expresso .= '/';
27                                }
28
29                                $url_expresso .= "index.php";
30                               
31                                $this->template->set_file(array('home_t' => 'pc_template.tpl'));
32                                $this->template->set_file(array('home_t_search_bar' => 'search_bar.tpl'));
33                                $this->template->set_block('home_t_search_bar','search_bar');
34                                $this->template->set_var('search',$this->template->fp('out','search_bar'));
35                                $this->template->set_var('url_expresso',$url_expresso);
36                                $this->template->set_var('lang_mini_mobile', lang('mini mobile'));
37                                $this->template->set_var('lang_search_error_message',lang("need choose one option"));
38                                $this->template->set_var('lang_search_error_message_four_digits',lang("search word need not be empty and has more then four char"));
39                        }
40                        else
41                        {
42                                $this->template->set_file(array('home_t' => 'template.tpl'));
43                                $this->template->set_var('lang_mini_desktop', lang('mini desktop'));
44
45                        }
46                       
47                        $this->template->set_block('home_t', 'mobile_home');
48                        $this->template->set_block('home_t','success_message');
49                        $this->template->set_block('home_t','error_message');
50                }
51
52                /*
53                * @function set_content
54                * @abstract Carrega o atributo "content" do template principal
55                * @author Nilton Emilio Buhrer Neto <niltonneto@celepar.pr.gov.br>
56                */             
57                public function set_content($content){
58                        $pre_content = $this->template->get_var("content");
59                        $this->template->set_var("content", $pre_content.$content);
60                }
61               
62                /*
63                * @function set_home
64                * @abstract Carrega o atributo "home" do template principal para PC.
65                * @author Diógenes Ribeiro Duarte <diogenes.duarte@prodeb.ba.gov.br>
66                */     
67                public function set_home($content) {
68                        $pre_content = $this->template->get_var("home");
69                        $this->template->set_var("home", $pre_content.$content);
70                }
71               
72                /*
73                * @function set_msg
74                * @abstract Seta a mensagem de sucesso ou error a depender do tipo.
75                * @author Thiago Antonius
76                */             
77                public function set_msg($msg, $type){
78                        if(isset($msg) && trim($msg)!="") {
79                                $this->template->set_var("message", $msg);
80                                $this->template->parse("message_box", $type."_message", true);
81                        }
82                }
83               
84                /*
85                * @function set_success_msg
86                * @abstract Seta a mensagem de sucesso.
87                * @author Thiago Antonius
88                */             
89                public function set_success_msg($msg){
90                        $this->set_msg($msg, "success");
91                }
92
93                        /*
94                * @function set_error_msg
95                * @abstract Seta a mensagem de erro
96                * @author Thiago Antonius
97                */             
98                public function set_error_msg($msg){
99                        $this->set_msg($msg, "error");
100                }               
101
102                /*
103                * @function print_all
104                * @abstract Imprime toda tela do Expresso Mini
105                * @author Nilton Emilio Buhrer Neto <niltonneto@celepar.pr.gov.br>
106                */
107                public function print_page($class, $method )
108                {
109                        if( $GLOBALS['phpgw']->session->appsession('mobile.layout','mobile') == "mini_desktop" )
110                        {
111                                //force to don' t call ui_home.index in a mini desktop version
112                                if($class == "ui_home" && $method == "index") {
113                                        $class = "ui_mobilemail";
114                                        $method = "change_folder";
115                                        $_REQUEST["folder"] = 0;
116                                }
117                        }
118                       
119                        //need be called before invoke the action
120                        $this->print_header();
121                        $this->init_mobile();
122
123                        if(!($class == 'ui_home' && $method == 'index')) $this->print_navbar();
124                        $filename = 'inc/class.'.$class.'.inc.php';
125                        include_once($filename);
126                        $obj = new $class();
127                        $obj->$method($_REQUEST);
128
129                        if($GLOBALS['phpgw']->session->appsession('mobile.layout','mobile') == "mini_desktop") {
130                                $ui_home = CreateObject('mobile.ui_home');
131                                $ui_home->index($_REQUEST);
132                        }
133                       
134                        $this->template->pfp('out', 'mobile_home');
135                }
136
137                public function init_mobile()
138                {
139                        $ui_mobilemail = CreateObject('mobile.ui_mobilemail');
140                        $obj = createobject("expressoMail1_2.functions");
141                // setting timezone preference
142                $zones = $obj->getTimezones();
143                $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['timezone'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['timezone'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['timezone'] : sprintf("%s", array_search("America/Sao_Paulo", $zones));
144                       
145                        $this->template->set_var('global_title', lang('expresso mini'));
146                        // button logout
147                        if( isset($_COOKIE['lem']) && isset($_COOKIE['pem']) )
148                        {
149                                $this->template->set_var('style_1','padding-left:65%;');
150                                $this->template->set_var('style_2','position:relative; float: right; display: none');
151                        }
152                        else
153                        {
154                                $this->template->set_var('style_1','position:absolute; float: left;');
155                                $this->template->set_var('style_2','position:relative; float: right; display: block');
156                        }
157
158                        if( isset($_SESSION['mobile']['displayIOS']) && $_SESSION['mobile']['displayIOS'] == "true" )
159                                $this->template->set_var('display_IOS', "none");
160                        else
161                                $this->template->set_var('display_IOS', "block");
162                               
163                        $this->template->set_var('lang_tips', lang('Tips'));
164                        $this->template->set_var('lang_logout', lang('logout'));
165                        $this->template->set_var('lang_search', lang('search'));
166                       
167                        $this->template->set_var('href_logout', 'login.php?cd=1');
168                }
169               
170                /*
171                * @function print_navbar
172                * @abstract Imprime o início da tela do Expresso Mini => barra de navegação
173                * @author Mário César Kolling <mario.kolling@serpro.gov.br>
174                */
175                private function print_navbar(){
176                        $this->template->set_var('lang_back', lang('Back'));
177                        $this->template->set_var('lang_home', lang('home'));
178                        $this->template->set_var('lang_email', lang('E-mail'));
179                        $this->template->set_var('lang_contacts', lang('Contact Center'));
180                        $this->template->set_var('lang_calendar', lang('Calendar'));
181                        $this->template->set_var('href_cc', 'index.php?menuaction=mobile.ui_mobilecc.init_cc');
182                        $this->template->set_var('href_email', "index.php?menuaction=mobile.ui_mobilemail.change_folder&folder=0");
183                        $this->template->set_var('href_calendar', "index.php?menuaction=mobile.ui_mobilecalendar.index");
184                        $this->template->set_var('href_home', "index.php?menuaction=mobile.ui_home.index");
185                }
186
187                private function process_back_link() {
188                        $trace = $GLOBALS['phpgw']->session->appsession('mobile.trace_urls','mobile');
189
190                        $trace_idx = 0;
191
192                        if($trace) {
193                                $trace_idx = sizeof($trace)-1;
194
195                                if($_REQUEST["is_back_link"])
196                                        $trace_idx = $trace_idx - 2;
197
198                                if($trace_idx < 0) $trace_idx = 0;
199
200                                $url = $trace[$trace_idx]["url"];
201                                $params = $trace[$trace_idx]["request"];
202
203                                $this->href_back = $this->build_url($url, $params);
204                        } else {
205                                $trace = array();
206                                $this->href_back = '';
207                        }
208                       
209                        if(!$_REQUEST["is_back_link"]) {
210                                $current_url = $_SERVER["SCRIPT_NAME"];
211                                $current_params = $_REQUEST;
212
213                                unset($current_params['sessionid']);
214                                unset($current_params['domain']);
215                                unset($current_params['last_loginid']);
216                                unset($current_params['last_domain']);
217                                unset($current_params['kp3']);
218                                unset($current_params['showHeader']);
219
220                                $built_current_url = $this->build_url($current_url, $current_params);
221                               
222                                if( (preg_match('/menuaction/i',$built_current_url)
223                                && !preg_match('/mobile\.ui_mobilemail\.(send_mail|save_draft|delete_msg)/i',$built_current_url) )
224                                && !$current_params["ignore_trace_url"] ) {
225
226                                        //se der reload não vai gravar a url e vai sobreescrever o link do botão voltar para não voltar para a mesma página
227                                        if(str_replace("&is_back_link=true","",$built_current_url) != str_replace("&is_back_link=true","",$this->href_back))
228                                                $trace[sizeof($trace)] = array("url" => $current_url, "request" => $current_params);
229                                        else {
230                                                if($trace_idx >= 1) $trace_idx--;
231                                                $this->href_back = $this->build_url($trace[$trace_idx]["url"], $trace[$trace_idx]["request"]);
232                                        }
233                                }
234                        } else {
235                                if(sizeof($trace) > 1)
236                                        unset($trace[sizeof($trace)-1]);
237                        }
238                       
239                        if(sizeof($trace) > 0)
240                                $GLOBALS['phpgw']->session->appsession('mobile.trace_urls','mobile',$trace);
241                        else
242                                $GLOBALS['phpgw']->session->appsession('mobile.trace_urls','mobile',null);
243                       
244                        $this->template->set_var('href_back', $this->href_back);
245                }
246               
247                private function build_url($url, $params) {
248                        $query_string = "";
249                       
250                        foreach ($params as $key => $value) {
251                                $query_string .= "&".$key."=".$value;
252                        }
253
254                        if($query_string != "")
255                                $url .= "?".substr($query_string,1);
256                       
257                        if(!$params["is_back_link"])
258                                $url .= "&is_back_link=true";
259                       
260                        return $url;
261                }
262
263                function get_back_link(){
264                        return $this->href_back;
265                }
266
267                /*
268                * @function print_header
269                * @abstract Imprime o início da tela do Expresso Mini => headers html
270                * @author Mário César Kolling <mario.kolling@serpro.gov.br>
271                */             
272                private function print_header(){
273                        $GLOBALS['phpgw']->accounts->read_repository();
274                        $var  = Array('title' => lang("expresso mini"));
275                        $this->template->set_var($var);
276                        $this->process_back_link();
277                }
278
279        }
280?>
Note: See TracBrowser for help on using the repository browser.