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