source: branches/2.2/mobile/inc/class.ui_mobilemail.inc.php @ 3576

Revision 3576, 37.2 KB checked in by eduardoalex, 13 years ago (diff)

Ticket #1409 - Modificado o layout da tela de visualizacao do expresso mini.

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