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