1 | <?php |
---|
2 | /**************************************************************************\ |
---|
3 | * eGroupWare * |
---|
4 | * http://www.egroupware.org * |
---|
5 | * The file written by Mário César Kolling <mario.kolling@serpro.gov.br> * |
---|
6 | * -------------------------------------------- * |
---|
7 | * This program is free software; you can redistribute it and/or modify it * |
---|
8 | * under the terms of the GNU General Public License as published by the * |
---|
9 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
10 | * option) any later version. * |
---|
11 | \**************************************************************************/ |
---|
12 | |
---|
13 | //TODO: Criar a Classe Widget. |
---|
14 | |
---|
15 | include_once(PHPGW_INCLUDE_ROOT.'/expressoMail1_2/inc/class.imap_functions.inc.php'); |
---|
16 | |
---|
17 | // Classe principal do Mini Mail |
---|
18 | class ui_mobilemail{ |
---|
19 | |
---|
20 | // Define as funções públicas |
---|
21 | var $public_functions = array( |
---|
22 | 'mail_list' => True, |
---|
23 | 'change_folder' => True, |
---|
24 | 'change_page' => True, |
---|
25 | 'show_msg' => True, |
---|
26 | 'send_mail' => True, |
---|
27 | //'reply_msg' => True, |
---|
28 | 'new_msg' => True, |
---|
29 | 'delete_msg' => True, |
---|
30 | 'confirm_delete_msg' => True, |
---|
31 | 'init_schedule' => true, |
---|
32 | 'add_recipients' => true, |
---|
33 | 'add_recipient' => true, |
---|
34 | 'list_folders' => true, |
---|
35 | 'save_draft' => true, |
---|
36 | 'mark_message_with_flag' => true, |
---|
37 | 'change_search_box_type' => true |
---|
38 | ); |
---|
39 | |
---|
40 | var $template; |
---|
41 | var $common; |
---|
42 | var $folders; // Pastas imap |
---|
43 | var $current_search_box_type; |
---|
44 | var $current_folder; // Pasta corrente |
---|
45 | var $current_page; // Página corrente da lista de e-mails da pasta corrente |
---|
46 | var $imap_functions; // Variável que recebe um objeto do tipo class.imap_functions.inc.php |
---|
47 | var $allowed_tags = '<p><a><br><em><strong><ol><li><ul><div><font>'; // Tags html que não serão removidas |
---|
48 | // ao mostrar corpo do e-mail |
---|
49 | |
---|
50 | |
---|
51 | /* |
---|
52 | * @function mobilemail |
---|
53 | * @abstract Método construtor da classe principal do Mini Mail |
---|
54 | * @author Mário César Kolling <mario.kolling@serpro.gov.br> |
---|
55 | */ |
---|
56 | function ui_mobilemail() |
---|
57 | { |
---|
58 | $this-> load_session(); |
---|
59 | $this->template = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); |
---|
60 | $this->common = CreateObject('mobile.common_functions'); |
---|
61 | |
---|
62 | // Recupera atributos da classe gravados na sessão |
---|
63 | $folders = $GLOBALS['phpgw']->session->appsession('mobilemail.folders','mobile'); |
---|
64 | $current_folder = $GLOBALS['phpgw']->session->appsession('mobilemail.current_folder','mobile'); |
---|
65 | $current_page = $GLOBALS['phpgw']->session->appsession('mobilemail.current_page','mobile'); |
---|
66 | $current_search_box_type = $GLOBALS['phpgw']->session->appsession('mobilemail.current_search_box_type','mobile'); |
---|
67 | |
---|
68 | // Inicializa a classe class.imap_functions.inc.php |
---|
69 | $this->imap_functions = new imap_functions(); |
---|
70 | |
---|
71 | // Testa a existência dos atributos da classe recuperadas da sessão, e as carrega ou inicializa. |
---|
72 | if ($folders) |
---|
73 | { |
---|
74 | $this->folders = $folders; |
---|
75 | } |
---|
76 | else |
---|
77 | { |
---|
78 | $this->folders = $this->imap_functions->get_folders_list(array('noSharedFolders' => true)); |
---|
79 | } |
---|
80 | |
---|
81 | if ($current_folder) |
---|
82 | { |
---|
83 | $this->current_folder = $current_folder; |
---|
84 | $current_page = 1; |
---|
85 | } |
---|
86 | else |
---|
87 | { |
---|
88 | $this->current_folder = 0; // Define o folder INBOX como o folder corrente |
---|
89 | } |
---|
90 | |
---|
91 | if ($current_page) |
---|
92 | { |
---|
93 | $this->current_page = $current_page; |
---|
94 | } |
---|
95 | else |
---|
96 | { |
---|
97 | $this->current_page = 1; // Define a primeira página como página padrão |
---|
98 | } |
---|
99 | |
---|
100 | if($current_search_box_type) |
---|
101 | { |
---|
102 | $this->current_search_box_type = $current_search_box_type; |
---|
103 | } |
---|
104 | else { |
---|
105 | $this->current_search_box_type = "all"; |
---|
106 | } |
---|
107 | |
---|
108 | } |
---|
109 | |
---|
110 | /* |
---|
111 | * @function save_session |
---|
112 | * @abstract Salva os atributos da classe na sessão |
---|
113 | * @author Mário César Kolling <mario.kolling@serpro.gov.br> |
---|
114 | */ |
---|
115 | function save_session() |
---|
116 | { |
---|
117 | $GLOBALS['phpgw']->session->appsession('mobilemail.folders','mobile',$this->folders); |
---|
118 | $GLOBALS['phpgw']->session->appsession('mobilemail.current_folder','mobile',$this->current_folder); |
---|
119 | $GLOBALS['phpgw']->session->appsession('mobilemail.current_page','mobile',$this->current_page); |
---|
120 | $GLOBALS['phpgw']->session->appsession('mobilemail.current_search_box_type','mobile',$this->current_search_box_type); |
---|
121 | } |
---|
122 | |
---|
123 | /* |
---|
124 | * @function change_page |
---|
125 | * @abstract Troca a página de exibição da lista de e-mails, e mostra a nova página |
---|
126 | * @author Mário César Kolling <mario.kolling@serpro.gov.br> |
---|
127 | */ |
---|
128 | function change_page($params) |
---|
129 | { |
---|
130 | if (isset($params['page'])) |
---|
131 | { |
---|
132 | $this->current_page = $params['page']; |
---|
133 | } |
---|
134 | $this->mail_list(); |
---|
135 | $this->save_session(); |
---|
136 | } |
---|
137 | |
---|
138 | function change_search_box_type($params) { |
---|
139 | if (isset($params['search_box_type'])) |
---|
140 | { |
---|
141 | $this->current_search_box_type = $params['search_box_type']; |
---|
142 | $this->current_page = 1; |
---|
143 | } |
---|
144 | $this->mail_list(); |
---|
145 | $this->save_session(); |
---|
146 | } |
---|
147 | |
---|
148 | /* |
---|
149 | * @function change_folder |
---|
150 | * @abstract Troca a pasta do imap, e mostra a primeira página da nova pasta |
---|
151 | * @author Mário César Kolling <mario.kolling@serpro.gov.br> |
---|
152 | */ |
---|
153 | function change_folder($params) |
---|
154 | { |
---|
155 | $folder = $params['folder']; |
---|
156 | if (isset($folder)) |
---|
157 | { |
---|
158 | $this->current_folder = $folder; |
---|
159 | $this->current_page = 1; |
---|
160 | $this->current_search_box_type = "all"; |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | $GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params["error_message"]); |
---|
165 | $this->mail_list(); |
---|
166 | $this->save_session(); |
---|
167 | } |
---|
168 | |
---|
169 | function mark_message_with_flag($params=array()) |
---|
170 | { |
---|
171 | $return = $this->imap_functions->set_messages_flag($params); |
---|
172 | |
---|
173 | if($return) |
---|
174 | header('Location: index.php?menuaction=menuaction=mobile.ui_mobilemail.change_folder&folder='.$this->current_folder); |
---|
175 | else |
---|
176 | header('Location: index.php?menuaction=menuaction=mobile.ui_mobilemail.show_msg&msg_number='.$params["msgs_to_set"].'&msg_folder='.$return["msg_folder"].'&error_message='.$return["msg"]); |
---|
177 | |
---|
178 | exit; |
---|
179 | } |
---|
180 | |
---|
181 | /* |
---|
182 | * @function show_msg |
---|
183 | * @abstract Mostra a mensagem de e-mail requisitada |
---|
184 | * @author Mário César Kolling <mario.kolling@serpro.gov.br> |
---|
185 | */ |
---|
186 | // TODO: retirar msg_folder dos parâmentros necessários no GET e usar $this->current_folder |
---|
187 | function show_msg($params = array()) |
---|
188 | { |
---|
189 | $msg = $this->imap_functions->get_info_msg($params); |
---|
190 | |
---|
191 | // Carrega o template |
---|
192 | $this->template->set_file(array('view_msg' => 'view_msg.tpl')); |
---|
193 | $this->template->set_block('view_msg', 'page'); |
---|
194 | $this->template->set_block('view_msg', 'begin_anchor'); |
---|
195 | $this->template->set_block('view_msg', 'end_anchor'); |
---|
196 | $this->template->set_var('lang_back', lang("back")); |
---|
197 | $this->template->set_var('lang_reading_message', lang("Reading Message")); |
---|
198 | |
---|
199 | // Define o cabeçalho do e-mail |
---|
200 | $this->template->set_var('lang_from', lang("From")); |
---|
201 | $this->template->set_var('from', $msg['from']['full']); |
---|
202 | $this->template->set_var('lang_cc', lang("cc")); |
---|
203 | $this->template->set_var('cc', $msg['cc']); |
---|
204 | $this->template->set_var('size', $this->common->borkb($msg['Size'])); |
---|
205 | |
---|
206 | $this->template->set_var('lang_subject', lang("Subject")); |
---|
207 | $this->template->set_var('subject', $msg['subject']); |
---|
208 | $this->template->set_var('date', $msg['msg_day']." ".$msg['msg_hour']); |
---|
209 | |
---|
210 | // Mostra o corpo do e-mail |
---|
211 | $this->template->set_var('body', strip_tags($msg['body'], $this->allowed_tags)); // Usa a função strip_tags() para filtrar |
---|
212 | // as tags que estão presentes no corpo do e-mail. |
---|
213 | $this->template->set_var('lang_link', lang("Return")); |
---|
214 | $this->template->set_var('return_link', "index.php?menuaction=mobile.ui_mobilemail.mail_list"); |
---|
215 | |
---|
216 | $this->template->set_var('lang_reply_all', lang("Reply to all")); |
---|
217 | $this->template->set_var('lang_forward', lang("Forward")); |
---|
218 | $this->template->set_var('lang_mark_as_unread', lang("mark as unread")); |
---|
219 | $this->template->set_var('lang_reply', lang("Reply")); |
---|
220 | $this->template->set_var('lang_delete', lang("Delete")); |
---|
221 | $msg_number = $params['msg_number']; |
---|
222 | $msg_folder = $params['msg_folder']; |
---|
223 | $this->template->set_var('mark_as_unread_link', "index.php?menuaction=mobile.ui_mobilemail.mark_message_with_flag&flag=unseen&msgs_to_set=$msg_number&msg_folder=$msg_folder"); |
---|
224 | $this->template->set_var('reply_link', "index.php?menuaction=mobile.ui_mobilemail.new_msg&msg_number=$msg_number&msg_folder=$msg_folder"); |
---|
225 | $this->template->set_var('delete_link', "index.php?menuaction=mobile.ui_mobilemail.confirm_delete_msg&msg_number=$msg_number&msg_folder=$msg_folder"); |
---|
226 | $this->template->set_var('reply_all_link', "index.php?menuaction=mobile.ui_mobilemail.new_msg&msg_number=$msg_number&msg_folder=$msg_folder&type=reply_all"); |
---|
227 | $this->template->set_var('forward_link', "index.php?menuaction=mobile.ui_mobilemail.new_msg&msg_number=$msg_number&msg_folder=$msg_folder&type=forward"); |
---|
228 | if (!empty($msg['attachments'])) |
---|
229 | { |
---|
230 | $attachs = "<br>".lang("This message has the follow attachments:")."<br>"; |
---|
231 | foreach($msg['attachments'] as $key => $attach) { |
---|
232 | if(is_array($attach)) { |
---|
233 | //$attachs.=$attach['name']." "; |
---|
234 | $attachs.="<a href='../expressoMail1_2/inc/gotodownload.php?msg_folder=".$msg_folder. |
---|
235 | "&msg_number=".$msg_number."&idx_file=".$key."&msg_part=".$attach['pid']. |
---|
236 | "&newfilename=".$attach['name']."&encoding=".$attach['encoding']."'>". |
---|
237 | lang('Download').": ".$attach['name']."</a><br>"; |
---|
238 | } |
---|
239 | } |
---|
240 | $this->template->set_var('attachment_message', $attachs); |
---|
241 | } |
---|
242 | else |
---|
243 | { |
---|
244 | $this->template->set_var('attachment_message', lang('This message don\'t have attachment(s)')); |
---|
245 | } |
---|
246 | |
---|
247 | $this->template->parse('view_msg_t', 'end_anchor'); |
---|
248 | $this->template->parse('view_msg_t', 'begin_anchor'); |
---|
249 | |
---|
250 | $GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params["error_message"]); |
---|
251 | $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out', 'page')); |
---|
252 | } |
---|
253 | |
---|
254 | /* |
---|
255 | * @function index |
---|
256 | * @abstract Página inicial da aplicação mobilemail, mantém o estado atual. Ou seja, mostra lista de e-mails |
---|
257 | * do folder e página definidos pelos parâmetros current_folder e current_page. |
---|
258 | * @author Mário César Kolling <mario.kolling@serpro.gov.br> |
---|
259 | */ |
---|
260 | // TODO: Talvez seja melhor voltar sempre para o Inbox e primeira página |
---|
261 | function index() |
---|
262 | { |
---|
263 | $this->print_folder_selection(); |
---|
264 | $this->mail_list(); |
---|
265 | $this->save_session(); |
---|
266 | |
---|
267 | } |
---|
268 | |
---|
269 | function load_session(){ |
---|
270 | /************************************\ |
---|
271 | * Inicialização do expressoMail1_2 * |
---|
272 | \************************************/ |
---|
273 | // Get Data from ldap_manager and emailadmin. |
---|
274 | $ldap_manager = CreateObject('contactcenter.bo_ldap_manager'); |
---|
275 | $boemailadmin = CreateObject('emailadmin.bo'); |
---|
276 | $emailadmin_profile = $boemailadmin->getProfileList(); |
---|
277 | $_SESSION['phpgw_info']['expressomail']['email_server'] = $boemailadmin->getProfile($emailadmin_profile[0]['profileID']); |
---|
278 | $_SESSION['phpgw_info']['expressomail']['user'] = $GLOBALS['phpgw_info']['user']; |
---|
279 | $_SESSION['phpgw_info']['expressomail']['server'] = $GLOBALS['phpgw_info']['server']; |
---|
280 | $_SESSION['phpgw_info']['expressomail']['ldap_server'] = $ldap_manager ? $ldap_manager->srcs[1] : null; |
---|
281 | $_SESSION['phpgw_info']['expressomail']['user']['email'] = $GLOBALS['phpgw']->preferences->values['email']; |
---|
282 | |
---|
283 | // Fix problem with cyrus delimiter changes in preferences. |
---|
284 | // Dots in names: enabled/disabled. |
---|
285 | $save_in_folder = @eregi_replace("INBOX/", "INBOX".$_SESSION['phpgw_info']['expressomail']['email_server']['imapDelimiter'], $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['save_in_folder']); |
---|
286 | $save_in_folder = @eregi_replace("INBOX.", "INBOX".$_SESSION['phpgw_info']['expressomail']['email_server']['imapDelimiter'], $save_in_folder); |
---|
287 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['save_in_folder'] = $save_in_folder; |
---|
288 | // End Fix. |
---|
289 | |
---|
290 | // Loading Admin Config Module |
---|
291 | $c = CreateObject('phpgwapi.config','expressoMail1_2'); |
---|
292 | $c->read_repository(); |
---|
293 | $current_config = $c->config_data; |
---|
294 | $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] = $current_config['expressoMail_enable_log_messages']; |
---|
295 | // Begin Set Anti-Spam options. |
---|
296 | $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_ham'] = $current_config['expressoMail_command_for_ham']; |
---|
297 | $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_spam'] = $current_config['expressoMail_command_for_spam']; |
---|
298 | $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_use_spam_filter'] = $current_config['expressoMail_use_spam_filter']; |
---|
299 | |
---|
300 | // echo '<script> var array_lang = new Array();var use_spam_filter = \''.$current_config['expressoMail_use_spam_filter'].'\' </script>'; |
---|
301 | |
---|
302 | // End Set Anti-Spam options. |
---|
303 | |
---|
304 | // Set Imap Folder names options |
---|
305 | $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'] = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'] ? $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'] : "Trash"; |
---|
306 | $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'] = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'] ? $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'] : "Drafts"; |
---|
307 | $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder'] = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder'] ? $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder'] : "Spam"; |
---|
308 | $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'] = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'] ? $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'] : "Sent"; |
---|
309 | |
---|
310 | // include("../expressoMail1_2/inc/load_lang.php"); |
---|
311 | } |
---|
312 | |
---|
313 | /* |
---|
314 | * @function print_folder_selection |
---|
315 | * @abstract Imprime o folder corrente (INBOX) |
---|
316 | * @author Mário César Kolling <mario.kolling@serpro.gov.br> |
---|
317 | */ |
---|
318 | function print_folder_selection() |
---|
319 | { |
---|
320 | $this->template->set_file(array('mobilemail_t' => 'mobilemail.tpl')); |
---|
321 | $this->template->set_block('mobilemail_t', 'inbox_folder_list'); |
---|
322 | $this->template->set_var('lang_folder', lang('Folder')); |
---|
323 | $folder = str_replace("*","",lang($this->folders[$this->current_folder]['folder_name'])); |
---|
324 | if(!$this->current_folder == 0){ |
---|
325 | $this->template->set_var('lang_inbox', $folder.' :: <a title="'.lang('Inbox').'" href="index.php?menuaction=mobile.ui_mobilemail.mail_list&folder=0">'.lang('Inbox').'</a>'); |
---|
326 | }else{ |
---|
327 | $this->template->set_var('lang_inbox', lang('Inbox')); |
---|
328 | } |
---|
329 | |
---|
330 | //$this->template->set_var('folder_items', $folder_items); |
---|
331 | $this->template->parse('mobilemail_t', 'inbox_folder_list'); |
---|
332 | //$this->template->fpf('out', 'mobilemail_t'); |
---|
333 | $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out', 'mobilemail_t')); |
---|
334 | |
---|
335 | } |
---|
336 | |
---|
337 | /* |
---|
338 | * @function old_print_folder_selection |
---|
339 | * @abstract Imprime na tela a caixa de seleção de folders |
---|
340 | * @author Mário César Kolling <mario.kolling@serpro.gov.br> |
---|
341 | */ |
---|
342 | function old_print_folder_selection() |
---|
343 | { |
---|
344 | |
---|
345 | // Processa as options |
---|
346 | $folder_items = ''; |
---|
347 | |
---|
348 | foreach ($this->folders as $i => $j) |
---|
349 | { |
---|
350 | |
---|
351 | $option_selected = ''; |
---|
352 | $this->template->set_file(array('mobilemail_t' => 'mobilemail.tpl')); |
---|
353 | $this->template->set_block('mobilemail_t', 'folder_item'); |
---|
354 | |
---|
355 | if (is_numeric($i)) |
---|
356 | { |
---|
357 | if ($i == $this->current_folder) |
---|
358 | { |
---|
359 | $option_selected = 'selected="selected"'; |
---|
360 | } |
---|
361 | |
---|
362 | $this->template->set_var('option_selected', $option_selected); |
---|
363 | $this->template->set_var('folder_id', $j['folder_id']); |
---|
364 | $this->template->set_var('folder_name', $j['folder_id']); // Mudar... provavelmente usar preg_replace |
---|
365 | // para substituir cpf pelo nome do usuário. |
---|
366 | |
---|
367 | if ($j['folder_unseen'] > 0) |
---|
368 | { |
---|
369 | $this->template->set_var('folder_unseen', ' - ('.$j['folder_unseen'].')'); |
---|
370 | } |
---|
371 | |
---|
372 | $folder_items .= $this->template->fp('mobile_t', 'folder_item'); |
---|
373 | } |
---|
374 | |
---|
375 | } |
---|
376 | |
---|
377 | // Processa o select |
---|
378 | $this->template->set_file(array('mobilemail_t' => 'mobilemail.tpl')); |
---|
379 | $this->template->set_block('mobilemail_t', 'folder_list'); |
---|
380 | $this->template->set_var('folder_items', $folder_items); |
---|
381 | $this->template->parse('mobilemail_t', 'folder_list'); |
---|
382 | //$this->template->pfp('out', 'mobilemail_t'); |
---|
383 | $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out', 'mobilemail_t')); |
---|
384 | |
---|
385 | } |
---|
386 | |
---|
387 | /* |
---|
388 | * @function mail_list |
---|
389 | * @abstract Imprime a lista de e-mails |
---|
390 | * @author Mário César Kolling <mario.kolling@serpro.gov.br> |
---|
391 | */ |
---|
392 | function mail_list() |
---|
393 | { |
---|
394 | |
---|
395 | $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); |
---|
396 | $p->set_file( |
---|
397 | Array( |
---|
398 | 'mail_t' => 'mobilemail.tpl' |
---|
399 | ) |
---|
400 | ); |
---|
401 | $p->set_var("page",$this->current_page+1); |
---|
402 | $p->set_var("folder",$this->folders[$this->current_folder]['folder_name']); |
---|
403 | $p->set_var("selected_".$this->current_search_box_type,"selected"); |
---|
404 | $p->set_var("lang_back",lang("back")); |
---|
405 | $p->set_var("lang_new_message",lang("new message")); |
---|
406 | $p->set_var("lang_search_message",lang("search message")); |
---|
407 | $p->set_var("lang_more",lang("more")); |
---|
408 | $p->set_var("lang_messages",lang("messages")); |
---|
409 | |
---|
410 | $max_per_page = |
---|
411 | isset($GLOBALS['phpgw_info']['user']['preferences']['mobile']['max_message_per_page'])? |
---|
412 | $GLOBALS['phpgw_info']['user']['preferences']['mobile']['max_message_per_page']:10; |
---|
413 | |
---|
414 | $params = array( |
---|
415 | 'folder' => $this->folders[$this->current_folder]['folder_id'], |
---|
416 | 'msg_range_begin' => 1, |
---|
417 | 'msg_range_end' => $this->current_page * $max_per_page, |
---|
418 | 'search_box_type' => $this->current_search_box_type, |
---|
419 | 'sort_box_type' => 'SORTARRIVAL', |
---|
420 | 'sort_box_reverse' => 1 |
---|
421 | ); |
---|
422 | |
---|
423 | $messages = $this->imap_functions->get_range_msgs2($params); |
---|
424 | // print_r($messages); |
---|
425 | $this->number_of_messages = $messages[num_msgs]; |
---|
426 | |
---|
427 | unset($messages["offsetToGMT"]); |
---|
428 | unset($messages["tot_unseen"]); |
---|
429 | |
---|
430 | $p->set_var('mails',$this->print_mails_list($messages,true)); |
---|
431 | |
---|
432 | $GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out','mail_t')); |
---|
433 | |
---|
434 | |
---|
435 | } |
---|
436 | |
---|
437 | /* |
---|
438 | * @function print_mails_list |
---|
439 | * @abstract Imprime a lista de mensagens |
---|
440 | * @author Mário César Kolling <mario.kolling@serpro.gov.br> |
---|
441 | * @param array Um array com a lista de mensagens recuperado por $this->imap_functions->get_range_msgs2($params) |
---|
442 | */ |
---|
443 | function print_mails_list($messages,$print_checkbox=false) |
---|
444 | { |
---|
445 | |
---|
446 | $functions = CreateObject('mobile.common_functions'); |
---|
447 | $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); |
---|
448 | $p->set_file( |
---|
449 | Array( |
---|
450 | 'mobilemail_t' => 'mails_list.tpl' |
---|
451 | ) |
---|
452 | ); |
---|
453 | $p->set_block('mobilemail_t', 'rows_mails'); |
---|
454 | $p->set_block('mobilemail_t', 'row_mails'); |
---|
455 | $p->set_block('mobilemail_t', 'no_messages'); |
---|
456 | |
---|
457 | if(count($messages)>1) { //O array de emails tem pelo menos uma posição com o total de mensagens. |
---|
458 | $bg = "par"; |
---|
459 | |
---|
460 | foreach($messages as $id => $message) { |
---|
461 | |
---|
462 | if(($id==='num_msgs') ||($id==='total_msgs')) |
---|
463 | continue; |
---|
464 | if($message['from']['name']) |
---|
465 | $from_name = $functions->strach_string($message['from']['name'],20); |
---|
466 | else |
---|
467 | $from_name = $functions->strach_string($message['from']['email'],20); |
---|
468 | |
---|
469 | $p->set_var('bg',$bg=="par"?$bg="reset-dt":$bg="par"); |
---|
470 | |
---|
471 | $pre = " "; |
---|
472 | $pos = " "; |
---|
473 | |
---|
474 | if($message["Unseen"]==="U") { |
---|
475 | $pre.="<b>"; |
---|
476 | $pos.="</b>"; |
---|
477 | } |
---|
478 | |
---|
479 | if($message["Flagged"]==="F") { |
---|
480 | $pre.= "<font color='#FF0000'>"; |
---|
481 | $pos = "</font>".$pos; |
---|
482 | } |
---|
483 | |
---|
484 | if($print_checkbox) |
---|
485 | $p->set_var('show_check','inline'); |
---|
486 | else |
---|
487 | $p->set_var('show_check','none'); |
---|
488 | |
---|
489 | $p->set_var('pre_type',$pre); |
---|
490 | $p->set_var('pos_type',$pos); |
---|
491 | $p->set_var('from',$from_name); |
---|
492 | $p->set_var('mail_time',$message['smalldate']); |
---|
493 | $p->set_var('mail_from',$functions->strach_string($message['from']['email'],23)); |
---|
494 | $p->set_var('subject',$functions->strach_string($message['subject'],25)); |
---|
495 | $p->set_var('size',$functions->borkb($message['Size'])); |
---|
496 | $p->set_var('lang_attachment',lang('ATTACHMENT')); |
---|
497 | $p->set_var('msg_number', $message['msg_number']); |
---|
498 | $p->set_var('msg_folder', isset($message['msg_folder'])? |
---|
499 | $message['msg_folder']:$this->folders[$this->current_folder]['folder_id']); |
---|
500 | if($message['attachment']['number_attachments']>0) { |
---|
501 | $p->set_var('show_attach','inline'); |
---|
502 | $p->set_var('no_attach_space','none'); |
---|
503 | } |
---|
504 | else { |
---|
505 | $p->set_var('show_attach','none'); |
---|
506 | $p->set_var('no_attach_space','block'); |
---|
507 | } |
---|
508 | |
---|
509 | $p->fp('rows','row_mails',True); |
---|
510 | } |
---|
511 | } |
---|
512 | else { |
---|
513 | $p->set_var("lang_no_results",lang("no results found")); |
---|
514 | $p->parse("rows","no_messages"); |
---|
515 | } |
---|
516 | return $p->fp('out','rows_mails'); |
---|
517 | /* |
---|
518 | // Cria a lista de e-mails |
---|
519 | $mail_rows = ''; |
---|
520 | $unread_msg_count = 0; |
---|
521 | |
---|
522 | if ($this->number_of_messages != 0) |
---|
523 | { |
---|
524 | $unread_msg_count = 0; |
---|
525 | foreach ($messages as $index => $msg) |
---|
526 | { |
---|
527 | $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); |
---|
528 | $p->set_file(array('mobilemail_t' => 'mobilemail.tpl')); |
---|
529 | $p->set_block('mobilemail_t', 'mail_row'); |
---|
530 | $p->set_block('mobilemail_t', 'end_strong'); |
---|
531 | $p->set_block('mobilemail_t', 'begin_strong'); |
---|
532 | $p->set_var('unseen_bkg', "seen_bkg"); |
---|
533 | $p->set_var('itememail_access_key', "0"); |
---|
534 | $p->set_var('str_new_message', ""); |
---|
535 | |
---|
536 | if (is_numeric($index)) |
---|
537 | { |
---|
538 | !empty($msg['from']['name']) ? $from = $msg['from']['name'] : $from = $msg['from']['email']; |
---|
539 | !empty($msg['subject']) ? $subject = $msg['subject'] : $subject = lang('[empty subject]'); |
---|
540 | if ($msg['Unseen'] == 'U') |
---|
541 | { //Setando as mensagens nao lidas |
---|
542 | $p->set_var('strong_unseen_begin', trim($p->fp('mobilemail_t', 'begin_strong'))); |
---|
543 | $p->set_var('strong_unseen_end', trim($p->fp('mobilemail_t', 'end_strong'))); |
---|
544 | $p->set_var('unseen_bkg', "unseen_bkg"); |
---|
545 | $p->set_var('itememail_access_key', "9"); |
---|
546 | $unread_msg_count = $unread_msg_count + 1; |
---|
547 | $p->set_var('str_new_message', lang("New message")); |
---|
548 | } |
---|
549 | $p->set_var('from', $from); |
---|
550 | $p->set_var('subject', $subject); |
---|
551 | $p->set_var('msg_number', $msg['msg_number']); |
---|
552 | $p->set_var('date', $msg['smalldate']); |
---|
553 | $p->set_var('msg_folder', $this->folders[$this->current_folder]['folder_id']); |
---|
554 | $p->set_var('from_label', lang('From')); |
---|
555 | $mail_rows .= $p->fp('mobilemail_t', 'mail_row'); |
---|
556 | } |
---|
557 | } |
---|
558 | |
---|
559 | // Imprime a lista de e-mails |
---|
560 | $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); |
---|
561 | $p->set_file(array('mobilemail_t' => 'mobilemail.tpl')); |
---|
562 | $p->set_block('mobilemail_t', 'mail_list'); |
---|
563 | $p->set_var('mail_rows', $mail_rows); |
---|
564 | $p->set_var('messages_total', $this->number_of_messages); |
---|
565 | $p->set_var('unread_messages_total', $unread_msg_count); |
---|
566 | if ($unread_msg_count) |
---|
567 | { |
---|
568 | $p->set_var('(unread_messages_total)', '('.$unread_msg_count.')'); |
---|
569 | } |
---|
570 | |
---|
571 | //$p->pfp('out', 'mail_list'); |
---|
572 | $GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'mail_list')); |
---|
573 | } |
---|
574 | else |
---|
575 | { |
---|
576 | // Lista de e-mails vazia |
---|
577 | $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); |
---|
578 | $p->set_file(array('mobilemail_t' => 'mobilemail.tpl')); |
---|
579 | $p->set_block('mobilemail_t', 'empty_list'); |
---|
580 | $p->set_var('empty_message', lang('Empty folder')); |
---|
581 | //$p->pfp('out', 'empty_list'); |
---|
582 | $GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'empty_list')); |
---|
583 | }*/ |
---|
584 | } |
---|
585 | |
---|
586 | /* |
---|
587 | * @funtion print_page_navigation |
---|
588 | * @abstract Imprime a barra de navegação da lista de e-mails da pasta corrente. Quem chama essa função é quem faz o controle do modelo. |
---|
589 | * @author Mário César Kolling <mario.kolling@serpro.gov.br> |
---|
590 | * @param integer Número de páginas que serão geradas |
---|
591 | * @param integer Página corrente |
---|
592 | */ |
---|
593 | // TODO: mover este método para a classe page_navigation subclasse de widget |
---|
594 | function print_page_navigation($number_of_pages, $page = 1) |
---|
595 | { |
---|
596 | |
---|
597 | $pages = ''; |
---|
598 | |
---|
599 | if ($number_of_pages != 0) |
---|
600 | { |
---|
601 | // Geração das páginas |
---|
602 | for ($i = 1; $i <= $number_of_pages ; $i++) |
---|
603 | { |
---|
604 | |
---|
605 | $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); |
---|
606 | $p->set_file(array('mobilemail_t' => 'mobilemail.tpl')); |
---|
607 | $p->set_block('mobilemail_t', 'space'); |
---|
608 | $p->set_block('mobilemail_t', 'begin_anchor'); |
---|
609 | $p->set_block('mobilemail_t', 'end_anchor'); |
---|
610 | $p->set_block('mobilemail_t', 'page_item'); |
---|
611 | $p->set_block('mobilemail_t', 'begin_strong'); |
---|
612 | $p->set_block('mobilemail_t', 'end_strong'); |
---|
613 | |
---|
614 | if ($i == $page) |
---|
615 | { |
---|
616 | // Se for a página sendo gerada for a página corrente, |
---|
617 | // não gera a âncora e destaca o número (negrito) |
---|
618 | $p->set_var('end_anchor', ''); |
---|
619 | $p->set_var('begin_anchor', ''); |
---|
620 | $p->set_var('begin_strong', trim($p->fp('mobilemail_t', 'begin_strong'))); |
---|
621 | $p->set_var('end_strong', trim($p->fp('mobilemail_t', 'end_strong'))); |
---|
622 | } |
---|
623 | else |
---|
624 | { |
---|
625 | // Senão, gera a âncora |
---|
626 | $p->set_var('begin_strong', ''); |
---|
627 | $p->set_var('end_strong', ''); |
---|
628 | $p->set_var('end_anchor', trim($p->fp('mobilemail_t', 'end_anchor'))); |
---|
629 | $p->set_var('begin_anchor_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&folder=$this->current_folder&page=$i"); |
---|
630 | $p->set_var('begin_anchor', trim($p->fp('mobilemail_t', 'begin_anchor'))); |
---|
631 | } |
---|
632 | |
---|
633 | $p->set_var('page', $i); |
---|
634 | //$pages .= trim($p->fp('mobilemail_t', 'page_item')); |
---|
635 | |
---|
636 | } |
---|
637 | $pages .= " ".$page." ".lang("of")." ".$number_of_pages." "; |
---|
638 | |
---|
639 | // Geração dos links "anterior" e "próximo" |
---|
640 | $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); |
---|
641 | $p->set_file(array('mobilemail_t' => 'mobilemail.tpl')); |
---|
642 | |
---|
643 | //$p->set_block('mobilemail_t', 'space'); |
---|
644 | $p->set_block('mobilemail_t', 'mail_footer'); |
---|
645 | $p->set_block('mobilemail_t', 'previous'); |
---|
646 | $p->set_block('mobilemail_t', 'next'); |
---|
647 | |
---|
648 | $next_page = $page + 1; |
---|
649 | $previous_page = $page - 1; |
---|
650 | |
---|
651 | if ($page == 1) |
---|
652 | { |
---|
653 | // Se for a primeira página, não imprime o link "anterior"" |
---|
654 | $p->set_var('previous', ''); |
---|
655 | if ($page == $number_of_pages) |
---|
656 | { |
---|
657 | // Se só existir uma página, não imprime o link "próximo" |
---|
658 | $p->set_var('next', ''); |
---|
659 | } |
---|
660 | else |
---|
661 | { |
---|
662 | $p->set_var('next_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&folder=$this->current_folder&page=$next_page"); |
---|
663 | $p->set_var('next', trim($p->fp('mobilemail_t', 'next'))); |
---|
664 | } |
---|
665 | |
---|
666 | } |
---|
667 | else if ($page == $number_of_pages) |
---|
668 | { |
---|
669 | // Se for a última página, não imprime o link "próximo" |
---|
670 | $p->set_var('next', ''); |
---|
671 | $p->set_var('previous_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&folder=$this->current_folder&page=$previous_page"); |
---|
672 | $p->set_var('previous', trim($p->fp('mobilemail_t', 'previous'))); |
---|
673 | } |
---|
674 | else |
---|
675 | { |
---|
676 | // Senão, imprime os links "anterior" e "próximo" |
---|
677 | $p->set_var('previous_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&folder=$this->current_folder&page=$previous_page"); |
---|
678 | $p->set_var('previous', trim($p->fp('mobilemail_t', 'previous'))); |
---|
679 | |
---|
680 | $p->set_var('next_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&folder=$this->current_folder&page=$next_page"); |
---|
681 | $p->set_var('next', trim($p->fp('mobilemail_t', 'next'))); |
---|
682 | } |
---|
683 | |
---|
684 | $p->set_var('pages', $pages); |
---|
685 | //$p->pfp('out', 'mail_footer'); |
---|
686 | $GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'mail_footer')); |
---|
687 | } |
---|
688 | |
---|
689 | } |
---|
690 | |
---|
691 | function define_action_message($type) { |
---|
692 | switch($type) { |
---|
693 | case "clk": |
---|
694 | case "cc_mob": |
---|
695 | $this->template->set_var('action_msg', lang("New message")); |
---|
696 | break; |
---|
697 | case "reply_all": |
---|
698 | $this->template->set_var('action_msg', lang("Reply All")); |
---|
699 | break; |
---|
700 | case "user_add": |
---|
701 | $this->template->set_var('action_msg', lang("Add Recipient")); |
---|
702 | break; |
---|
703 | case "forward": |
---|
704 | $this->template->set_var('action_msg', lang("Forward")); |
---|
705 | break; |
---|
706 | } |
---|
707 | } |
---|
708 | |
---|
709 | /* |
---|
710 | * @function new_msg() |
---|
711 | * @abstract Gera o formulário para criar/enviar novo e-mail ou resposta de e-mail. |
---|
712 | * @author Rommel de Brito Cysne <rommel.cysne@serpro.gov.br> |
---|
713 | */ |
---|
714 | function new_msg($params) |
---|
715 | { |
---|
716 | $this->template->set_file(array('new_msg_t' => 'new_msg.tpl')); |
---|
717 | $this->template->set_block('new_msg_t', 'page'); |
---|
718 | $this->template->set_block('new_msg_t', 'add_recipient_block'); |
---|
719 | $this->template->set_var('lang_back', lang("back")); |
---|
720 | $this->template->set_var('lang_calendar', strtoupper(lang("Calendar"))); |
---|
721 | $this->template->set_var('lang_send', strtoupper(lang("Send"))); |
---|
722 | $this->template->set_var('lang_attachment', strtoupper(lang("attachment"))); |
---|
723 | $this->template->set_var('lang_cancel', strtoupper(lang("cancel"))); |
---|
724 | $this->template->set_var('lang_save_draft', strtoupper(lang("save draft"))); |
---|
725 | $this->template->set_var('type', $_GET['type']); |
---|
726 | $this->template->set_var('lang_to', lang("To")); |
---|
727 | $this->template->set_var('lang_cc', lang("cc")); |
---|
728 | $this->template->set_var('lang_subject', lang("Subject")); |
---|
729 | $this->template->set_var('lang_mark_as_important', lang("mark as important")); |
---|
730 | $this->template->set_var('lang_read_confirmation', lang("read confirmation")); |
---|
731 | $this->template->set_var('lang_add_history', lang("add history")); |
---|
732 | |
---|
733 | |
---|
734 | $this->template->set_var('type', $_REQUEST['type']); |
---|
735 | $this->template->parse('add_recipient_box', 'add_recipient_block', true); |
---|
736 | |
---|
737 | $this->define_action_message($_REQUEST['type']); |
---|
738 | |
---|
739 | if(isset($params["error_message"])) { |
---|
740 | $this->template->set_var('to', $_POST['input_to']); |
---|
741 | $this->template->set_var('to_mail', $_POST['input_to_mail']); |
---|
742 | $this->template->set_var('cc', $_POST['input_cc']); |
---|
743 | $this->template->set_var('cc_mail', $_POST['input_cc_mail']); |
---|
744 | $this->template->set_var('subject', $_POST['input_subject']); |
---|
745 | $this->template->set_var('msg_number', $_POST['msg_number']); |
---|
746 | $this->template->set_var('msg_folder', $_POST['msg_folder']); |
---|
747 | $this->template->set_var('body_value', $_POST['body']); |
---|
748 | $this->template->set_var('msg_folder', $_POST['folder']); |
---|
749 | $this->template->set_var('msg_number', $_POST['reply_msg_number']); |
---|
750 | $this->template->set_var('from', $_POST['reply_from']); |
---|
751 | $this->template->set_var('check_important', ( ( $_POST['check_important'] ) ? "checked" : "" ) ); |
---|
752 | $this->template->set_var('check_read_confirmation', ( ( $_POST['check_read_confirmation'] ) ? "checked" : "" ) ); |
---|
753 | $this->template->set_var('check_add_history', ( ( $_POST['check_add_history'] ) ? "checked" : "" ) ); |
---|
754 | |
---|
755 | $GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params["error_message"]); |
---|
756 | } else { |
---|
757 | if (isset($_GET['msg_number'])) $msg = $this->imap_functions->get_info_msg(array('msg_number' => $_GET['msg_number'] ) ); |
---|
758 | |
---|
759 | if($_REQUEST['type']=="clk") |
---|
760 | { |
---|
761 | $this->template->set_var('to', ""); |
---|
762 | $this->template->set_var('to_mail', ""); |
---|
763 | $this->template->set_var('cc', ""); |
---|
764 | $this->template->set_var('cc_mail', ""); |
---|
765 | $this->template->set_var('subject', ""); |
---|
766 | } |
---|
767 | else if($_REQUEST['type']=="cc_mob") |
---|
768 | { |
---|
769 | $this->template->set_var('to', $_GET['input_to']); |
---|
770 | $this->template->set_var('to_mail', $_GET['input_to_mail']); |
---|
771 | $this->template->set_var('cc', $_GET['input_cc']); |
---|
772 | $this->template->set_var('cc_mail', $_GET['input_cc_mail']); |
---|
773 | $this->template->set_var('subject', ""); |
---|
774 | |
---|
775 | $this->template->set_var('msg_number', $_GET['msg_number']); |
---|
776 | $this->template->set_var('msg_folder', $_GET['msg_folder']); |
---|
777 | |
---|
778 | $this->template->set_var('read_only', 'readonly'); |
---|
779 | } |
---|
780 | else if($_REQUEST['type']=="reply_all"){ |
---|
781 | $reply_to_all = $msg['from']['full']; |
---|
782 | $reply_to_all = $msg['toaddress2'] ? $reply_to_all.','.$msg['toaddress2']:$reply_to_all; |
---|
783 | $reply_to_all = $msg['cc'] ? $reply_to_all.','.$msg['cc']:$reply_to_all; |
---|
784 | $reply_to_all = $msg['bcc'] ? $reply_to_all.','.$msg['bcc']:$reply_to_all; |
---|
785 | $names = implode(',<br/>',explode(',',$reply_to_all)); |
---|
786 | |
---|
787 | $array_emails = explode(',',$reply_to_all); |
---|
788 | $reply_to_all =''; |
---|
789 | |
---|
790 | foreach ($array_emails as $index => $email){ |
---|
791 | $flag = preg_match('/<(.*?)>/',$email,$reply); |
---|
792 | $reply_to_all .= $flag == 0 ? $email.', ':$reply[1].', '; |
---|
793 | } |
---|
794 | |
---|
795 | $this->template->set_var('to', $reply_to_all); |
---|
796 | $this->template->set_var('to_mail', $_GET['input_to_mail']); |
---|
797 | $this->template->set_var('subject', "Re:" . $msg['subject']); |
---|
798 | |
---|
799 | $this->template->set_var('msg_number', $_GET['msg_number']); |
---|
800 | $this->template->set_var('msg_folder', $_GET['msg_folder']); |
---|
801 | } |
---|
802 | else if($_REQUEST['type']=="user_add"){ |
---|
803 | $listMail = implode(',',$_SESSION['mobile_mail']); |
---|
804 | |
---|
805 | $this->template->set_var('to', $listMail); |
---|
806 | $this->template->set_var('to_mail', $listMail); |
---|
807 | $this->template->set_var('subject', $_SESSION['subject_mail']); |
---|
808 | $this->template->set_var('body_value', $_SESSION['body_mail']); |
---|
809 | |
---|
810 | $this->template->set_var('msg_number', $_GET['msg_number']); |
---|
811 | $this->template->set_var('msg_folder', $_GET['msg_folder']); |
---|
812 | } |
---|
813 | else if($_REQUEST['type']=="forward"){ |
---|
814 | $this->template->set_var('from', $msg['toaddress2']); |
---|
815 | |
---|
816 | $mail_to = $msg['from']['full']; |
---|
817 | |
---|
818 | $this->template->set_var('subject', "Enc:" . $msg['subject']); |
---|
819 | $this->template->set_var('body_value', strip_tags($msg['body'])); // Usa a função strip_tags() para filtrar |
---|
820 | // as tags que estão presentes no corpo do e-mail. |
---|
821 | |
---|
822 | $this->template->set_var('msg_number', $_GET['msg_number']); |
---|
823 | $this->template->set_var('msg_folder', $_GET['msg_folder']); |
---|
824 | } |
---|
825 | else{ |
---|
826 | $this->template->set_var('from', $msg['toaddress2']); |
---|
827 | |
---|
828 | $mail_to = $msg['from']['full']; |
---|
829 | $this->template->set_var('to', $msg['from']['name']); |
---|
830 | $this->template->set_var('to_mail', $msg['from']['email']); |
---|
831 | |
---|
832 | $this->template->set_var('subject', "Re:" . $msg['subject']); |
---|
833 | |
---|
834 | $this->template->set_var('msg_number', $_GET['msg_number']); |
---|
835 | $this->template->set_var('msg_folder', $_GET['msg_folder']); |
---|
836 | |
---|
837 | $this->template->set_var('read_only', "readonly"); |
---|
838 | } |
---|
839 | } |
---|
840 | |
---|
841 | $_SESSION['mobile_mail'] = array(); |
---|
842 | |
---|
843 | $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out', 'page')); |
---|
844 | } |
---|
845 | |
---|
846 | /* |
---|
847 | * @function save_draft() |
---|
848 | * @abstract Função que salva o email como rascunho |
---|
849 | * @author Thiago Antonius |
---|
850 | */ |
---|
851 | function save_draft($params) |
---|
852 | { |
---|
853 | $params["folder"] = "INBOX/".$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder']; |
---|
854 | $return = $this->imap_functions->save_msg($params); |
---|
855 | if($return["has_error"]) { |
---|
856 | $params["error_message"] = lang("draft not save")."<br>".lang("error") . $return["append"]; |
---|
857 | $this->new_msg( $params ); |
---|
858 | }else { |
---|
859 | $ui_home = CreateObject('mobile.ui_home'); |
---|
860 | $params["success_message"] = lang("draft saved"); |
---|
861 | $ui_home->index( $params ); |
---|
862 | } |
---|
863 | } |
---|
864 | |
---|
865 | /* |
---|
866 | * @function send_mail() |
---|
867 | * @abstract Função que realiza o envio de e-mails. |
---|
868 | * @author Rommel de Brito Cysne <rommel.cysne@serpro.gov.br> |
---|
869 | */ |
---|
870 | function send_mail() |
---|
871 | { |
---|
872 | //Chamada da classe phpmailer |
---|
873 | include_once(PHPGW_SERVER_ROOT."/expressoMail1_2/inc/class.phpmailer.php"); |
---|
874 | |
---|
875 | //Recebe os dados do form (passados pelo POST) |
---|
876 | $userName = $_POST['input_to']; //"User Someone"; |
---|
877 | $userMail = $_POST['input_to_mail']; //"user.someone@mail.com.br"; |
---|
878 | $ccUserName = $_POST['input_cc']; |
---|
879 | $ccUserMail = $_POST['input_cc_mail']; |
---|
880 | $subject = $_POST['input_subject']; //"Mail Subject"; |
---|
881 | $body = $_POST['body']; //"Mail body. Any text."; |
---|
882 | $isImportant = $_POST['check_important']; |
---|
883 | $addHistory = $_POST['check_add_history']; |
---|
884 | $readConfirmation = $_POST['check_read_confirmation']; |
---|
885 | $msgNumber = $_POST['reply_msg_number']; |
---|
886 | |
---|
887 | if($userMail == "") $userMail = $userName; |
---|
888 | if($ccUserMail == "") $ccUserMail = $ccUserName; |
---|
889 | |
---|
890 | //Cria objeto |
---|
891 | $mail = new PHPMailer(); |
---|
892 | |
---|
893 | if(!$this->imap_functions->add_recipients("to", $userMail, &$mail)) |
---|
894 | { |
---|
895 | $error_msg = lang("Some addresses in the To field were not recognized. Please make sure that all addresses are properly formed"); |
---|
896 | } |
---|
897 | |
---|
898 | if(!$this->imap_functions->add_recipients("cc", $ccUserMail, &$mail)) |
---|
899 | { |
---|
900 | $error_msg = lang("Some addresses in the CC field were not recognized. Please make sure that all addresses are properly formed"); |
---|
901 | } |
---|
902 | |
---|
903 | $mail->IsSMTP(); |
---|
904 | $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; |
---|
905 | $mail->Port = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpPort']; |
---|
906 | |
---|
907 | $mail->SaveMessageInFolder = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['save_in_folder']; |
---|
908 | //Envia os emails em formato HTML; se false -> desativa. |
---|
909 | $mail->IsHTML(true); |
---|
910 | //Email do remetente da mensagem |
---|
911 | $mail->Sender = $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
912 | //Nome do remetente do email |
---|
913 | $mail->SenderName = $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; |
---|
914 | //Assunto da mensagem |
---|
915 | $mail->Subject = $subject; |
---|
916 | //Corpo da mensagem |
---|
917 | $mail->Body .= "<br />$body<br />"; |
---|
918 | //Important message |
---|
919 | if($isImportant) $mail->isImportant(); |
---|
920 | //add history |
---|
921 | if($addHistory && $msgNumber) { |
---|
922 | $msg = $this->imap_functions->get_info_msg(array('msg_number' => $msgNumber ) ); |
---|
923 | $mail->Body .= "<br />".$msg['body']."<br />"; |
---|
924 | } |
---|
925 | //read confirmation |
---|
926 | if ($readConfirmation) $mail->ConfirmReadingTo = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
927 | |
---|
928 | //Se o e-mail nao for enviado por qualquer motivo... |
---|
929 | if(!$mail->Send()) { |
---|
930 | $params["error_message"] = lang("Message not sent")."<br>".lang("error") . $mail->ErrorInfo; |
---|
931 | $this->new_msg( $params ); |
---|
932 | }else { |
---|
933 | $ui_home = CreateObject('mobile.ui_home'); |
---|
934 | $params["success_message"] = lang("Message sent successfully"); |
---|
935 | $ui_home->index($params); |
---|
936 | } |
---|
937 | } |
---|
938 | |
---|
939 | function confirm_delete_msg() |
---|
940 | { |
---|
941 | //Cria um objeto template |
---|
942 | //Define o template para mensagens de retorno da funcao |
---|
943 | $this->template->set_file(array('delete_msg_t' => 'delete_msg.tpl')); |
---|
944 | $this->template->set_block('delete_msg_t','retorno'); |
---|
945 | $this->template->set_var('lang_delete_msg', lang("Do you like to delete this message?")); |
---|
946 | $this->template->set_var('lang_yes', lang("Yes")); |
---|
947 | $this->template->set_var('lang_no', lang("No")); |
---|
948 | $this->template->set_var('link_yes', 'index.php?menuaction=mobile.ui_mobilemail.delete_msg&msg_number='.$_GET['msg_number'].'&msg_folder='.$_GET['msg_folder']); |
---|
949 | $this->template->set_var('link_no', 'index.php?menuaction=mobile.ui_mobilemail.show_msg&msg_number='.$_GET['msg_number'].'&msg_folder='.$_GET['msg_folder']); |
---|
950 | |
---|
951 | $this->template->pfp('out','retorno'); |
---|
952 | } |
---|
953 | |
---|
954 | function delete_msg($params) |
---|
955 | { |
---|
956 | if (isset($_GET['msg_number'])) |
---|
957 | { |
---|
958 | $params = array( |
---|
959 | 'msgs_number' => $_GET['msg_number'], |
---|
960 | 'folder' => $_GET['msg_folder'], |
---|
961 | 'new_folder_name' => 'Trash', |
---|
962 | 'new_folder' => 'INBOX/Trash' |
---|
963 | ); |
---|
964 | } |
---|
965 | |
---|
966 | $this->imap_functions->move_messages($params); |
---|
967 | //Cria um objeto template |
---|
968 | //Define o template para mensagens de retorno da funcao |
---|
969 | $this->template->set_file(array('move_msg_t' => 'sent_msg.tpl')); |
---|
970 | $this->template->set_block('move_msg_t','retorno'); |
---|
971 | //@header('Refresh: 1; url=./ui_mobilemail.index?folder='.$this->current_folder); |
---|
972 | $this->template->set_var('msg', lang("The message was moved to trash")); |
---|
973 | |
---|
974 | $this->template->pfp('out','retorno'); |
---|
975 | |
---|
976 | } |
---|
977 | |
---|
978 | function get_folder_number($folder_name){ |
---|
979 | foreach($this->folders as $folderNumber => $folder){ |
---|
980 | if($folder['folder_id'] == $folder_name){ |
---|
981 | return $folderNumber; |
---|
982 | } |
---|
983 | } |
---|
984 | return 0; |
---|
985 | } |
---|
986 | |
---|
987 | function retorna() |
---|
988 | { |
---|
989 | |
---|
990 | } |
---|
991 | |
---|
992 | function init_schedule() { |
---|
993 | if($_POST['input_to'] != '' && !is_null($_POST['input_to'])) |
---|
994 | array_push($_SESSION['mobile_mail'],$_POST['input_to']); |
---|
995 | |
---|
996 | $_SESSION['subject_mail'] = $_POST['input_subject']; |
---|
997 | $_SESSION['body_mail'] = $_POST['body']; |
---|
998 | $this->add_recipients(); |
---|
999 | } |
---|
1000 | |
---|
1001 | |
---|
1002 | function add_recipients() { |
---|
1003 | |
---|
1004 | $ui_cc = CreateObject('mobile.ui_mobilecc'); |
---|
1005 | $ui_cc->contacts_list('mobilemail'); |
---|
1006 | } |
---|
1007 | |
---|
1008 | function add_recipient() { |
---|
1009 | |
---|
1010 | $participants = $_SESSION["mobile_mail"]; |
---|
1011 | |
---|
1012 | if(!is_array($participants)) |
---|
1013 | $participants = array(); |
---|
1014 | |
---|
1015 | $participants[$_GET['cn']] = $_GET['mail']; |
---|
1016 | |
---|
1017 | $_SESSION["mobile_mail"] = $participants; |
---|
1018 | $this->add_recipients(); |
---|
1019 | } |
---|
1020 | |
---|
1021 | function list_folders(){ |
---|
1022 | //Define o template para mensagens de retorno da funcao |
---|
1023 | $this->template->set_file(array('folders_t' => 'folders.tpl')); |
---|
1024 | $this->template->set_block('folders_t','retorno'); |
---|
1025 | |
---|
1026 | $folders_list = ''; |
---|
1027 | $array_folders = Array(); |
---|
1028 | $this->folders = $this->imap_functions->get_folders_list(array('noSharedFolders' => true)); |
---|
1029 | |
---|
1030 | foreach($this->folders as $id => $folder) |
---|
1031 | { |
---|
1032 | if((strpos($folder['folder_id'],'user')===true && !is_array($folder)) || !is_numeric($id)) |
---|
1033 | continue; |
---|
1034 | $array_folders[$folder['folder_id']]['id'] = $id; |
---|
1035 | $array_folders[$folder['folder_id']]['folder_name'] = $folder['folder_name']; |
---|
1036 | } |
---|
1037 | |
---|
1038 | foreach($array_folders as $folder_id => $folder) |
---|
1039 | { |
---|
1040 | if(($folder_id != $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['save_in_folder']) && ($folder['id'] != 0)){ |
---|
1041 | $folder_name = str_replace('*','',lang($folder['folder_name'])); |
---|
1042 | $folder_link = "index.php?menuaction=mobile.ui_mobilemail.mail_list&folder=".$folder['id']; |
---|
1043 | $folders_list .= "<br>:: <a href=".$folder_link.">".$folder_name."</a>"; |
---|
1044 | } |
---|
1045 | } |
---|
1046 | $this->template->set_var('folders_list', $folders_list); |
---|
1047 | $this->template->pfp('out','retorno'); |
---|
1048 | |
---|
1049 | } |
---|
1050 | |
---|
1051 | } |
---|
1052 | ?> |
---|