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

Revision 3573, 37.3 KB checked in by eduardoalex, 13 years ago (diff)

Ticket #1406 - primeira versão da implementação da busca

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