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

Revision 3996, 8.1 KB checked in by thiagoaos, 13 years ago (diff)

Ticket #1740 - Adicionado link no label Expresso Mini para a página inicial.

  • 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                        if($GLOBALS['phpgw']->session->appsession('mobile.layout','mobile') == "mini_desktop") {
95                                //force to don' t call ui_home.index in a mini desktop version
96                                if($class == "ui_home" && $method == "index") {
97                                        $class = "ui_mobilemail";
98                                        $method = "change_folder";
99                                        $_REQUEST["folder"] = 0;
100                                }
101                        }
102                       
103                        //need be called before invoke the action
104                        $this->print_header();
105                        $this->init_mobile();
106
107                        if(!($class == 'ui_home' && $method == 'index')) $this->print_navbar();
108                        $filename = 'inc/class.'.$class.'.inc.php';
109                        include_once($filename);
110                        $obj = new $class();
111                        $obj->$method($_REQUEST);
112
113                        if($GLOBALS['phpgw']->session->appsession('mobile.layout','mobile') == "mini_desktop") {
114                                $ui_home = CreateObject('mobile.ui_home');
115                                $ui_home->index($_REQUEST);
116                        }
117                       
118                        $this->template->pfp('out', 'mobile_home');
119                }
120
121                public function init_mobile() {
122                        $ui_mobilemail = CreateObject('mobile.ui_mobilemail');
123                        $obj = createobject("expressoMail1_2.functions");
124      // setting timezone preference
125      $zones = $obj->getTimezones();
126      $_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));
127                       
128                        $this->template->set_var('global_title', lang('expresso mini'));
129                        $this->template->set_var('lang_logout', lang('logout'));
130                        $this->template->set_var('lang_search', lang('search'));
131                       
132                        $this->template->set_var('href_logout', 'login.php?cd=1');
133                }
134               
135                /*
136                * @function print_navbar
137                * @abstract Imprime o início da tela do Expresso Mini => barra de navegação
138                * @author Mário César Kolling <mario.kolling@serpro.gov.br>
139                */
140                private function print_navbar(){
141                        $this->template->set_var('lang_back', lang('Back'));
142                        $this->template->set_var('lang_home', lang('home'));
143                        $this->template->set_var('lang_email', lang('E-mail'));
144                        $this->template->set_var('lang_contacts', lang('Contact Center'));
145                        $this->template->set_var('lang_calendar', lang('Calendar'));
146                        $this->template->set_var('href_cc', 'index.php?menuaction=mobile.ui_mobilecc.init_cc');
147                        $this->template->set_var('href_email', "index.php?menuaction=mobile.ui_mobilemail.change_folder&folder=0");
148                        $this->template->set_var('href_calendar', "index.php?menuaction=mobile.ui_mobilecalendar.index");
149                        $this->template->set_var('href_home', "index.php?menuaction=mobile.ui_home.index");
150                }
151
152                private function process_back_link() {
153                        $trace = $GLOBALS['phpgw']->session->appsession('mobile.trace_urls','mobile');
154
155                        $trace_idx = 0;
156
157                        if($trace) {
158                                $trace_idx = sizeof($trace)-1;
159
160                                if($_REQUEST["is_back_link"])
161                                        $trace_idx = $trace_idx - 2;
162
163                                if($trace_idx < 0) $trace_idx = 0;
164
165                                $url = $trace[$trace_idx]["url"];
166                                $params = $trace[$trace_idx]["request"];
167
168                                $this->href_back = $this->build_url($url, $params);
169                        } else {
170                                $trace = array();
171                                $this->href_back = '';
172                        }
173                       
174                        if(!$_REQUEST["is_back_link"]) {
175                                $current_url = $_SERVER["SCRIPT_NAME"];
176                                $current_params = $_REQUEST;
177
178                                unset($current_params['sessionid']);
179                                unset($current_params['domain']);
180                                unset($current_params['last_loginid']);
181                                unset($current_params['last_domain']);
182                                unset($current_params['kp3']);
183                                unset($current_params['showHeader']);
184
185                                $built_current_url = $this->build_url($current_url, $current_params);
186
187                                //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
188                                if(str_replace("&is_back_link=true","",$built_current_url) != str_replace("&is_back_link=true","",$this->href_back))
189                                        $trace[sizeof($trace)] = array("url" => $current_url, "request" => $current_params);
190                                else {
191                                        if($trace_idx >= 1) $trace_idx--;
192                                        $this->href_back = $this->build_url($trace[$trace_idx]["url"], $trace[$trace_idx]["request"]);
193                                }
194                        } else {
195                                if(sizeof($trace) > 1)
196                                        unset($trace[sizeof($trace)-1]);
197                        }
198                       
199                        if(sizeof($trace) > 0)
200                                $GLOBALS['phpgw']->session->appsession('mobile.trace_urls','mobile',$trace);
201                        else
202                                $GLOBALS['phpgw']->session->appsession('mobile.trace_urls','mobile',null);
203                       
204                        $this->template->set_var('href_back', $this->href_back);
205                }
206               
207                private function build_url($url, $params) {
208                        $query_string = "";
209                       
210                        foreach ($params as $key => $value) {
211                                $query_string .= "&".$key."=".$value;
212                        }
213
214                        if($query_string != "")
215                                $url .= "?".substr($query_string,1);
216                       
217                        if(!$params["is_back_link"])
218                                $url .= "&is_back_link=true";
219                       
220                        return $url;
221                }
222
223                function get_back_link(){
224                        return $this->href_back;
225                }
226
227                /*
228                * @function print_header
229                * @abstract Imprime o início da tela do Expresso Mini => headers html
230                * @author Mário César Kolling <mario.kolling@serpro.gov.br>
231                */             
232                private function print_header(){
233                        $GLOBALS['phpgw']->accounts->read_repository();
234                        $var  = Array('title' => lang("expresso mini"));
235                        $this->template->set_var($var);
236                        $this->process_back_link();
237                }
238
239        }
240?>
Note: See TracBrowser for help on using the repository browser.