source: branches/2.2.0.1/mobile/inc/class.mobiletemplate.inc.php @ 3988

Revision 3988, 7.7 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #1726 - Corrigido url do link (voltar) do mobile, r3987

  • 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                        $this->template = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
15                       
16                        $template = $GLOBALS['phpgw']->session->appsession('mobile.layout','mobile');
17                       
18                        if($template == "mini_desktop") {
19                                $this->template->set_file(array('home_t' => 'pc_template.tpl'));
20                                $this->template->set_file(array('home_t_search_bar' => 'search_bar.tpl'));
21                                $this->template->set_block('home_t_search_bar','search_bar');
22                                $this->template->set_var('search',$this->template->fp('out','search_bar'));
23                                $this->template->set_var('lang_mini_mobile', lang('mini mobile'));
24                                $this->template->set_var('lang_search_error_message',lang("need choose one option"));
25                                $this->template->set_var('lang_search_error_message_four_digits',lang("search word need not be empty and has more then four char"));
26                        }       else {
27                                $this->template->set_file(array('home_t' => 'template.tpl'));
28                                $this->template->set_var('lang_mini_desktop', lang('mini desktop'));
29                        }
30                       
31
32                       
33                        $this->template->set_block('home_t', 'mobile_home');
34                        $this->template->set_block('home_t','success_message');
35                        $this->template->set_block('home_t','error_message');
36                }
37
38                /*
39                * @function set_content
40                * @abstract Carrega o atributo "content" do template principal
41                * @author Nilton Emilio Buhrer Neto <niltonneto@celepar.pr.gov.br>
42                */             
43                public function set_content($content){
44                        $pre_content = $this->template->get_var("content");
45                        $this->template->set_var("content", $pre_content.$content);
46                }
47               
48                /*
49                * @function set_home
50                * @abstract Carrega o atributo "home" do template principal para PC.
51                * @author Diógenes Ribeiro Duarte <diogenes.duarte@prodeb.ba.gov.br>
52                */     
53                public function set_home($content) {
54                        $pre_content = $this->template->get_var("home");
55                        $this->template->set_var("home", $pre_content.$content);
56                }
57               
58                /*
59                * @function set_msg
60                * @abstract Seta a mensagem de sucesso ou error a depender do tipo.
61                * @author Thiago Antonius
62                */             
63                public function set_msg($msg, $type){
64                        if(isset($msg) && trim($msg)!="") {
65                                $this->template->set_var("message", $msg);
66                                $this->template->parse("message_box", $type."_message", true);
67                        }
68                }
69               
70                /*
71                * @function set_success_msg
72                * @abstract Seta a mensagem de sucesso.
73                * @author Thiago Antonius
74                */             
75                public function set_success_msg($msg){
76                        $this->set_msg($msg, "success");
77                }
78
79                        /*
80                * @function set_error_msg
81                * @abstract Seta a mensagem de erro
82                * @author Thiago Antonius
83                */             
84                public function set_error_msg($msg){
85                        $this->set_msg($msg, "error");
86                }               
87
88                /*
89                * @function print_all
90                * @abstract Imprime toda tela do Expresso Mini
91                * @author Nilton Emilio Buhrer Neto <niltonneto@celepar.pr.gov.br>
92                */
93                public function print_page($class, $method){
94                        $this->print_header();
95                        $this->init_mobile();
96                        if(!($class == 'ui_home' && $method == 'index')) $this->print_navbar();
97                        $filename = 'inc/class.'.$class.'.inc.php';
98                        include_once($filename);
99                        $obj = new $class();           
100                        $obj -> $method($_REQUEST);
101                       
102                        if($GLOBALS['phpgw']->session->appsession('mobile.layout','mobile') == "mini_desktop") {
103                                $ui_home = CreateObject('mobile.ui_home');
104                                $ui_home->index($_REQUEST);
105                        }
106                       
107                        $this->template->pfp('out', 'mobile_home');
108                }
109               
110                public function init_mobile() {
111                        $ui_mobilemail = CreateObject('mobile.ui_mobilemail');
112                        $obj = createobject("expressoMail1_2.functions");
113      // setting timezone preference
114      $zones = $obj->getTimezones();
115      $_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));
116                       
117                        $this->template->set_var('global_title', lang('expresso mini'));
118                        $this->template->set_var('lang_logout', lang('logout'));
119                        $this->template->set_var('lang_search', lang('search'));
120                       
121                        $this->template->set_var('href_logout', 'login.php?cd=1');
122                }
123               
124                /*
125                * @function print_navbar
126                * @abstract Imprime o início da tela do Expresso Mini => barra de navegação
127                * @author Mário César Kolling <mario.kolling@serpro.gov.br>
128                */
129                private function print_navbar(){
130                        $this->template->set_var('lang_back', lang('Back'));
131                        $this->template->set_var('lang_home', lang('home'));
132                        $this->template->set_var('lang_email', lang('E-mail'));
133                        $this->template->set_var('lang_contacts', lang('Contact Center'));
134                        $this->template->set_var('lang_calendar', lang('Calendar'));
135                        $this->template->set_var('href_cc', 'index.php?menuaction=mobile.ui_mobilecc.init_cc');
136                        $this->template->set_var('href_email', "index.php?menuaction=mobile.ui_mobilemail.change_folder&folder=0");
137                        $this->template->set_var('href_calendar', "index.php?menuaction=mobile.ui_mobilecalendar.index");
138                        $this->template->set_var('href_home', "index.php?menuaction=mobile.ui_home.index");
139                }
140
141                private function process_back_link() {
142                        $trace = $GLOBALS['phpgw']->session->appsession('mobile.trace_urls','mobile');
143
144                        $trace_idx = 0;
145
146                        if($trace) {
147                                $trace_idx = sizeof($trace)-1;
148
149                                if($_REQUEST["is_back_link"])
150                                        $trace_idx = $trace_idx - 2;
151
152                                if($trace_idx < 0) $trace_idx = 0;
153
154                                $url = $trace[$trace_idx]["url"];
155                                $params = $trace[$trace_idx]["request"];
156
157                                $this->href_back = $this->build_url($url, $params);
158                        } else {
159                                $trace = array();
160                                $this->href_back = '';
161                        }
162                       
163                        if(!$_REQUEST["is_back_link"]) {
164                                $current_url = $_SERVER["SCRIPT_NAME"];
165                                $current_params = $_REQUEST;
166
167                                unset($current_params['sessionid']);
168                                unset($current_params['domain']);
169                                unset($current_params['last_loginid']);
170                                unset($current_params['last_domain']);
171                                unset($current_params['kp3']);
172                                unset($current_params['showHeader']);
173
174                                $built_current_url = $this->build_url($current_url, $current_params);
175
176                                //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
177                                if(str_replace("&is_back_link=true","",$built_current_url) != str_replace("&is_back_link=true","",$this->href_back))
178                                        $trace[sizeof($trace)] = array("url" => $current_url, "request" => $current_params);
179                                else {
180                                        if($trace_idx >= 1) $trace_idx--;
181                                        $this->href_back = $this->build_url($trace[$trace_idx]["url"], $trace[$trace_idx]["request"]);
182                                }
183                        } else {
184                                if(sizeof($trace) > 1)
185                                        unset($trace[sizeof($trace)-1]);
186                        }
187                       
188                        if(sizeof($trace) > 0)
189                                $GLOBALS['phpgw']->session->appsession('mobile.trace_urls','mobile',$trace);
190                        else
191                                $GLOBALS['phpgw']->session->appsession('mobile.trace_urls','mobile',null);
192                       
193                        $this->template->set_var('href_back', $this->href_back);
194                }
195               
196                private function build_url($url, $params) {
197                        $query_string = "";
198                       
199                        foreach ($params as $key => $value) {
200                                $query_string .= "&".$key."=".$value;
201                        }
202
203                        if($query_string != "")
204                                $url .= "?".substr($query_string,1);
205                       
206                        if(!$params["is_back_link"])
207                                $url .= "&is_back_link=true";
208                       
209                        return $url;
210                }
211
212                function get_back_link(){
213                        return $this->href_back;
214                }
215
216                /*
217                * @function print_header
218                * @abstract Imprime o início da tela do Expresso Mini => headers html
219                * @author Mário César Kolling <mario.kolling@serpro.gov.br>
220                */             
221                private function print_header(){
222                        $GLOBALS['phpgw']->accounts->read_repository();
223                        $var  = Array('title' => lang("expresso mini"));
224                        $this->template->set_var($var);
225                        $this->process_back_link();
226                }
227
228        }
229?>
Note: See TracBrowser for help on using the repository browser.