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

Revision 3571, 38.2 KB checked in by eduardoalex, 13 years ago (diff)

Ticket #1408 - Modificado o layout da tela de enviar email 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                );
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                        // Cria a lista de e-mails
435                        $mail_rows = '';
436      $unread_msg_count = 0;
437     
438                        if ($this->number_of_messages != 0)
439                        {
440                                $unread_msg_count = 0;
441                                foreach ($messages as $index => $msg)
442                                {
443                                  $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
444                                        $p->set_file(array('mobilemail_t' => 'mobilemail.tpl'));
445                                        $p->set_block('mobilemail_t', 'mail_row');
446                                        $p->set_block('mobilemail_t', 'end_strong');
447                                        $p->set_block('mobilemail_t', 'begin_strong');
448                                        $p->set_var('unseen_bkg', "seen_bkg");
449                                        $p->set_var('itememail_access_key', "0");
450                                        $p->set_var('str_new_message', "");
451
452                                        if (is_numeric($index))
453                                        {
454                                                !empty($msg['from']['name']) ? $from = $msg['from']['name'] : $from = $msg['from']['email'];
455                                                !empty($msg['subject']) ? $subject = $msg['subject'] : $subject = lang('[empty subject]');
456                                                if ($msg['Unseen'] == 'U')
457                                                { //Setando as mensagens nao lidas
458                                                        $p->set_var('strong_unseen_begin', trim($p->fp('mobilemail_t', 'begin_strong')));
459                                                        $p->set_var('strong_unseen_end', trim($p->fp('mobilemail_t', 'end_strong')));
460                                                        $p->set_var('unseen_bkg', "unseen_bkg");
461                                                        $p->set_var('itememail_access_key', "9");
462                                                        $unread_msg_count = $unread_msg_count + 1;
463                                                        $p->set_var('str_new_message', lang("New message"));
464                                                }
465                                                $p->set_var('from', $from);
466                                                $p->set_var('subject', $subject);
467                                                $p->set_var('msg_number', $msg['msg_number']);
468                                                $p->set_var('date', $msg['smalldate']);
469                                                $p->set_var('msg_folder', $this->folders[$this->current_folder]['folder_id']);
470                                                $p->set_var('from_label', lang('From'));
471                                                $mail_rows .= $p->fp('mobilemail_t', 'mail_row');
472                                        }
473                                }
474   
475                                // Imprime a lista de e-mails
476                                $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
477                                $p->set_file(array('mobilemail_t' => 'mobilemail.tpl'));
478                                $p->set_block('mobilemail_t', 'mail_list');
479                                $p->set_var('mail_rows', $mail_rows);
480                                $p->set_var('messages_total', $this->number_of_messages);
481                                $p->set_var('unread_messages_total', $unread_msg_count);
482                                if ($unread_msg_count)
483                                {
484                                        $p->set_var('(unread_messages_total)', '('.$unread_msg_count.')');
485                                }
486                               
487                                //$p->pfp('out', 'mail_list');
488                                $GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'mail_list'));
489                        }
490                        else
491                        {
492                                // Lista de e-mails vazia
493                                $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
494                                $p->set_file(array('mobilemail_t' => 'mobilemail.tpl'));
495                                $p->set_block('mobilemail_t', 'empty_list');
496                                $p->set_var('empty_message', lang('Empty folder'));                             
497                                //$p->pfp('out', 'empty_list');
498                                $GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'empty_list'));
499                        }
500                }
501
502                /*
503                 * @funtion print_page_navigation
504                 * @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.
505                 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
506                 * @param integer Número de páginas que serão geradas
507                 * @param integer Página corrente
508                 */
509                // TODO: mover este método para a classe page_navigation subclasse de widget
510                function print_page_navigation($number_of_pages, $page = 1)
511                {
512
513                        $pages = '';
514
515                        if ($number_of_pages != 0)
516                        {
517                                // Geração das páginas
518                                for ($i = 1; $i <= $number_of_pages ; $i++)
519                                {
520
521          $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
522                                        $p->set_file(array('mobilemail_t' => 'mobilemail.tpl'));
523                                        $p->set_block('mobilemail_t', 'space');
524                                        $p->set_block('mobilemail_t', 'begin_anchor');
525                                        $p->set_block('mobilemail_t', 'end_anchor');
526                                        $p->set_block('mobilemail_t', 'page_item');
527                                        $p->set_block('mobilemail_t', 'begin_strong');
528                                        $p->set_block('mobilemail_t', 'end_strong');
529
530                                        if ($i == $page)
531                                        {
532                                                // Se for a página sendo gerada for a página corrente,
533                                                // não gera a âncora e destaca o número (negrito)
534                                                $p->set_var('end_anchor', '');
535                                                $p->set_var('begin_anchor', '');
536                                                $p->set_var('begin_strong', trim($p->fp('mobilemail_t', 'begin_strong')));
537                                                $p->set_var('end_strong', trim($p->fp('mobilemail_t', 'end_strong')));
538                                        }
539                                        else
540                                        {
541                                                // Senão, gera a âncora
542                                                $p->set_var('begin_strong', '');
543                                                $p->set_var('end_strong', '');
544                                                $p->set_var('end_anchor', trim($p->fp('mobilemail_t', 'end_anchor')));
545                                                $p->set_var('begin_anchor_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&folder=$this->current_folder&page=$i");
546                                                $p->set_var('begin_anchor', trim($p->fp('mobilemail_t', 'begin_anchor')));
547                                        }
548
549                                        $p->set_var('page', $i);
550                                        //$pages .= trim($p->fp('mobilemail_t', 'page_item'));
551
552                                }
553                                $pages .= " ".$page." ".lang("of")." ".$number_of_pages." ";
554
555                                // Geração dos links "anterior" e "próximo"
556                                $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
557                                $p->set_file(array('mobilemail_t' => 'mobilemail.tpl'));
558
559                                //$p->set_block('mobilemail_t', 'space');
560                                $p->set_block('mobilemail_t', 'mail_footer');
561                                $p->set_block('mobilemail_t', 'previous');
562                                $p->set_block('mobilemail_t', 'next');
563
564                                $next_page = $page + 1;
565                                $previous_page = $page - 1;
566
567                                if ($page == 1)
568                                {
569                                        // Se for a primeira página, não imprime o link "anterior""
570                                        $p->set_var('previous', '');
571                                        if ($page == $number_of_pages)
572                                        {
573                                                // Se só existir uma página, não imprime o link "próximo"
574                                                $p->set_var('next', '');
575                                        }
576                                        else
577                                        {
578                                                $p->set_var('next_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&folder=$this->current_folder&page=$next_page");
579                                                $p->set_var('next', trim($p->fp('mobilemail_t', 'next')));
580                                        }
581
582                                }
583                                else if ($page == $number_of_pages)
584                                {
585                                        // Se for a última página, não imprime o link "próximo"
586                                        $p->set_var('next', '');
587                                        $p->set_var('previous_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&folder=$this->current_folder&page=$previous_page");
588                                        $p->set_var('previous', trim($p->fp('mobilemail_t', 'previous')));
589                                }
590                                else
591                                {
592                                        // Senão, imprime os links "anterior" e "próximo"
593                                        $p->set_var('previous_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&folder=$this->current_folder&page=$previous_page");
594                                        $p->set_var('previous', trim($p->fp('mobilemail_t', 'previous')));
595
596                                        $p->set_var('next_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&folder=$this->current_folder&page=$next_page");
597                                        $p->set_var('next', trim($p->fp('mobilemail_t', 'next')));
598                                }
599
600                                $p->set_var('pages', $pages);
601                                //$p->pfp('out', 'mail_footer');
602                                $GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'mail_footer'));
603                        }
604
605                }
606
607                function define_action_message($type) {
608                        switch($type) {
609                                case "clk":
610                                case "cc_mob":
611                                        $this->template->set_var('action_msg', lang("New message"));
612                                        break;
613                                case "reply_all":
614                                        $this->template->set_var('action_msg', lang("Reply All"));
615                                        break;
616                                case "user_add":
617                                        $this->template->set_var('action_msg', lang("Add Recipient"));
618                                        break;
619                                case "forward":
620                                        $this->template->set_var('action_msg', lang("Forward"));
621                                        break;                                         
622                        }
623                }
624               
625                /*
626                 * @function new_msg()
627                 * @abstract Gera o formulário para criar/enviar novo e-mail ou resposta de e-mail.
628                 * @author Rommel de Brito Cysne <rommel.cysne@serpro.gov.br>
629                 */
630                function new_msg($params)
631                {
632                        $this->template->set_file(array('new_msg_t' => 'new_msg.tpl'));
633                        $this->template->set_block('new_msg_t', 'page');
634                        $this->template->set_block('new_msg_t', 'add_recipient_block');
635                        $this->template->set_var('lang_back', lang("back"));
636                        $this->template->set_var('lang_calendar', strtoupper(lang("Calendar")));
637                        $this->template->set_var('lang_send', strtoupper(lang("Send")));
638                        $this->template->set_var('lang_attachment', strtoupper(lang("attachment")));
639                        $this->template->set_var('lang_cancel', strtoupper(lang("cancel")));
640                        $this->template->set_var('lang_save_draft', strtoupper(lang("save draft")));
641                        $this->template->set_var('type', $_GET['type']);
642                        $this->template->set_var('lang_to', lang("To"));
643                        $this->template->set_var('lang_cc', lang("cc"));
644                        $this->template->set_var('lang_subject', lang("Subject"));
645                        $this->template->set_var('lang_mark_as_important', lang("mark as important"));
646                        $this->template->set_var('lang_read_confirmation', lang("read confirmation"));
647                        $this->template->set_var('lang_add_history', lang("add history"));
648                       
649                       
650                        $this->template->set_var('type', $_REQUEST['type']);
651                        $this->template->parse('add_recipient_box', 'add_recipient_block', true);
652
653                        $this->define_action_message($_REQUEST['type']);
654                       
655                        if(isset($params["error_message"])) {
656                                $this->template->set_var('to', $_POST['input_to']);
657                                $this->template->set_var('to_mail', $_POST['input_to_mail']);
658                                $this->template->set_var('cc', $_POST['input_cc']);
659                                $this->template->set_var('cc_mail', $_POST['input_cc_mail']);
660                                $this->template->set_var('subject', $_POST['input_subject']);
661                                $this->template->set_var('msg_number', $_POST['msg_number']);
662                                $this->template->set_var('msg_folder', $_POST['msg_folder']);
663                                $this->template->set_var('body_value', $_POST['body']);
664                                $this->template->set_var('msg_folder', $_POST['folder']);
665                                $this->template->set_var('msg_number', $_POST['reply_msg_number']);
666                                $this->template->set_var('from', $_POST['reply_from']);
667                                $this->template->set_var('check_important', ( ( $_POST['check_important'] ) ? "checked" : "" ) );
668                                $this->template->set_var('check_read_confirmation', ( ( $_POST['check_read_confirmation'] )  ? "checked" : "" ) );
669                                $this->template->set_var('check_add_history', ( ( $_POST['check_add_history'] )  ? "checked" : "" ) );
670                               
671                                $GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params["error_message"]);
672                        } else {
673                                if (isset($_GET['msg_number'])) $msg = $this->imap_functions->get_info_msg(array('msg_number' => $_GET['msg_number'] ) );
674                               
675                                if($_REQUEST['type']=="clk")
676                                {
677                                        $this->template->set_var('to', "");
678                                        $this->template->set_var('to_mail', "");
679                                        $this->template->set_var('cc', "");
680                                        $this->template->set_var('cc_mail', "");
681                                        $this->template->set_var('subject', "");
682                                }
683                                else if($_REQUEST['type']=="cc_mob")
684                                {
685                                        $this->template->set_var('to', $_GET['input_to']);
686                                        $this->template->set_var('to_mail', $_GET['input_to_mail']);
687                                        $this->template->set_var('cc', $_GET['input_cc']);
688                                        $this->template->set_var('cc_mail', $_GET['input_cc_mail']);
689                                        $this->template->set_var('subject', "");
690       
691                                        $this->template->set_var('msg_number', $_GET['msg_number']);
692                                        $this->template->set_var('msg_folder', $_GET['msg_folder']);
693       
694                                        $this->template->set_var('read_only', 'readonly');
695                                }
696                                else if($_REQUEST['type']=="reply_all"){
697                                        $reply_to_all = $msg['from']['full'];
698                                        $reply_to_all = $msg['toaddress2'] ? $reply_to_all.','.$msg['toaddress2']:$reply_to_all;
699                                        $reply_to_all = $msg['cc'] ? $reply_to_all.','.$msg['cc']:$reply_to_all;
700                                        $reply_to_all = $msg['bcc'] ? $reply_to_all.','.$msg['bcc']:$reply_to_all;
701                                        $names = implode(',<br/>',explode(',',$reply_to_all));
702                                       
703                                        $array_emails = explode(',',$reply_to_all);
704                                        $reply_to_all ='';
705                                       
706                                        foreach ($array_emails as $index => $email){
707                                                $flag = preg_match('/&lt;(.*?)&gt;/',$email,$reply);
708                                                $reply_to_all .= $flag == 0 ? $email.', ':$reply[1].', ';
709                                        }
710                                                                       
711                                        $this->template->set_var('to', $reply_to_all);
712                                        $this->template->set_var('to_mail', $_GET['input_to_mail']);
713                                        $this->template->set_var('subject', "Re:" . $msg['subject']);
714       
715                                        $this->template->set_var('msg_number', $_GET['msg_number']);
716                                        $this->template->set_var('msg_folder', $_GET['msg_folder']);
717                                }
718                                else if($_REQUEST['type']=="user_add"){
719                                        $listMail = implode(',',$_SESSION['mobile_mail']);
720                                       
721                                        $this->template->set_var('to', $listMail);
722                                        $this->template->set_var('to_mail', $listMail);
723                                        $this->template->set_var('subject', $_SESSION['subject_mail']);
724                                        $this->template->set_var('body_value', $_SESSION['body_mail']);
725       
726                                        $this->template->set_var('msg_number', $_GET['msg_number']);
727                                        $this->template->set_var('msg_folder', $_GET['msg_folder']);                   
728                                }
729                                else if($_REQUEST['type']=="forward"){
730                                        $this->template->set_var('from', $msg['toaddress2']);
731       
732                                        $mail_to = $msg['from']['full'];
733       
734                                        $this->template->set_var('subject', "Enc:" . $msg['subject']);
735                                        $this->template->set_var('body_value', strip_tags($msg['body'])); // Usa a função strip_tags() para filtrar
736                                        // as tags que estão presentes no corpo do e-mail.
737                                       
738                                        $this->template->set_var('msg_number', $_GET['msg_number']);
739                                        $this->template->set_var('msg_folder', $_GET['msg_folder']);           
740                                }
741                                else{
742                                        $this->template->set_var('from', $msg['toaddress2']);
743       
744                                        $mail_to = $msg['from']['full'];
745                                        $this->template->set_var('to', $msg['from']['name']);
746                                        $this->template->set_var('to_mail', $msg['from']['email']);
747       
748                                        $this->template->set_var('subject', "Re:" . $msg['subject']);
749       
750                                        $this->template->set_var('msg_number', $_GET['msg_number']);
751                                        $this->template->set_var('msg_folder', $_GET['msg_folder']);
752       
753                                        $this->template->set_var('read_only', "readonly");
754                                }                               
755                        }
756                       
757                        $_SESSION['mobile_mail'] = array();
758                       
759                        $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out', 'page'));
760                }
761
762                                /*
763                 * @function save_draft()
764                 * @abstract Função que salva o email como rascunho
765                 * @author Thiago Antonius
766                 */
767                function save_draft($params)
768                {
769                        $params["folder"] = "INBOX/".$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'];
770                        $return = $this->imap_functions->save_msg($params);
771                        if($return["has_error"]) {
772                                $params["error_message"] = lang("draft not save")."<br>".lang("error") . $return["append"];
773                                $this->new_msg( $params );
774                        }else {
775                                $ui_home = CreateObject('mobile.ui_home');
776                                $params["success_message"] = lang("draft saved");
777                                $ui_home->index( $params );
778                        }                               
779                }
780               
781                /*
782                 * @function send_mail()
783                 * @abstract Função que realiza o envio de e-mails.
784                 * @author Rommel de Brito Cysne <rommel.cysne@serpro.gov.br>
785                 */
786                function send_mail()
787                {
788                        //Chamada da classe phpmailer
789                        include_once(PHPGW_SERVER_ROOT."/expressoMail1_2/inc/class.phpmailer.php");
790
791                        //Recebe os dados do form (passados pelo POST)
792                        $userName = $_POST['input_to']; //"User Someone";
793                        $userMail = $_POST['input_to_mail']; //"user.someone@mail.com.br";
794                        $ccUserName = $_POST['input_cc'];
795                        $ccUserMail = $_POST['input_cc_mail'];                 
796                        $subject = $_POST['input_subject']; //"Mail Subject";
797                        $body = $_POST['body']; //"Mail body. Any text.";
798                        $isImportant = $_POST['check_important'];
799                        $addHistory = $_POST['check_add_history'];
800                        $readConfirmation = $_POST['check_read_confirmation'];
801                        $msgNumber = $_POST['reply_msg_number'];
802
803                        if($userMail == "") $userMail = $userName;
804                        if($ccUserMail == "") $ccUserMail = $ccUserName;
805
806                        //Cria objeto
807                        $mail = new PHPMailer();
808
809                        if(!$this->imap_functions->add_recipients("to", $userMail, &$mail))
810                        {
811                                $error_msg = lang("Some addresses in the To field were not recognized. Please make sure that all addresses are properly formed");
812                        }
813                       
814                        if(!$this->imap_functions->add_recipients("cc", $ccUserMail, &$mail))
815                        {
816                                $error_msg = lang("Some addresses in the CC field were not recognized. Please make sure that all addresses are properly formed");
817                        }                       
818
819                        $mail->IsSMTP();
820                        $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer'];
821                        $mail->Port = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpPort'];
822
823                        $mail->SaveMessageInFolder = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['save_in_folder'];
824                        //Envia os emails em formato HTML; se false -> desativa.
825                        $mail->IsHTML(true);
826                        //Email do remetente da mensagem
827                        $mail->Sender = $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email'];
828                        //Nome do remetente do email
829                        $mail->SenderName = $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname'];
830                        //Assunto da mensagem
831                        $mail->Subject = $subject;
832                        //Corpo da mensagem
833                        $mail->Body .= "<br />$body<br />";
834                        //Important message
835                        if($isImportant) $mail->isImportant();
836                        //add history
837                        if($addHistory && $msgNumber) {
838                                $msg = $this->imap_functions->get_info_msg(array('msg_number' => $msgNumber ) );
839                                $mail->Body .= "<br />".$msg['body']."<br />";                                         
840                        }
841                        //read confirmation
842                        if ($readConfirmation) $mail->ConfirmReadingTo = $_SESSION['phpgw_info']['expressomail']['user']['email'];
843
844                        //Se o e-mail nao for enviado por qualquer motivo...
845                        if(!$mail->Send()) {
846                                $params["error_message"] = lang("Message not sent")."<br>".lang("error") . $mail->ErrorInfo;
847                                $this->new_msg( $params );
848                        }else {
849                                $ui_home = CreateObject('mobile.ui_home');
850                                $params["success_message"] = lang("Message sent successfully");
851                                $ui_home->index($params);
852                        }
853                }
854
855                function confirm_delete_msg()
856                {                                       
857                        //Cria um objeto template
858                        //Define o template para mensagens de retorno da funcao
859                        $this->template->set_file(array('delete_msg_t' => 'delete_msg.tpl'));
860                        $this->template->set_block('delete_msg_t','retorno');                   
861                        $this->template->set_var('lang_delete_msg', lang("Do you like to delete this message?"));                               
862                        $this->template->set_var('lang_yes', lang("Yes"));     
863                        $this->template->set_var('lang_no', lang("No"));
864                        $this->template->set_var('link_yes', 'index.php?menuaction=mobile.ui_mobilemail.delete_msg&msg_number='.$_GET['msg_number'].'&msg_folder='.$_GET['msg_folder']);
865                        $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']);   
866                       
867                        $this->template->pfp('out','retorno'); 
868                }
869
870                function delete_msg()
871                {
872                        if (isset($_GET['msg_number']))
873                        {
874                                $params = array(
875                                        'msgs_number' => $_GET['msg_number'],
876                                        'folder' => $_GET['msg_folder'],
877                                        'new_folder_name' => 'Trash',
878                                        'new_folder' => 'INBOX/Trash'
879                                );
880                        }       
881
882                        $this->imap_functions->move_messages($params);
883                        //Cria um objeto template
884                        //Define o template para mensagens de retorno da funcao
885                        $this->template->set_file(array('move_msg_t' => 'sent_msg.tpl'));
886                        $this->template->set_block('move_msg_t','retorno');
887                        //@header('Refresh: 1; url=./ui_mobilemail.index?folder='.$this->current_folder);                       
888                        $this->template->set_var('msg', lang("The message was moved to trash"));                               
889
890                        $this->template->pfp('out','retorno');                             
891                   
892                }
893               
894                function get_folder_number($folder_name){
895                        foreach($this->folders as $folderNumber => $folder){
896                                if($folder['folder_id'] == $folder_name){
897                                        return $folderNumber;
898                                }
899                        }
900                        return 0;
901                }
902
903                function retorna()
904                {
905                       
906                }
907               
908                function init_schedule() {
909                        if($_POST['input_to'] != '' && !is_null($_POST['input_to']))
910                                array_push($_SESSION['mobile_mail'],$_POST['input_to']);                       
911
912                        $_SESSION['subject_mail'] = $_POST['input_subject'];
913                        $_SESSION['body_mail'] = $_POST['body'];
914                        $this->add_recipients();
915                }
916               
917               
918                function add_recipients() {
919           
920                        $ui_cc = CreateObject('mobile.ui_mobilecc');
921                        $ui_cc->contacts_list('mobilemail');
922                }
923               
924                function add_recipient() {
925                       
926                        $participants = $_SESSION["mobile_mail"];
927                       
928                        if(!is_array($participants))
929                                $participants = array();
930                               
931                        $participants[$_GET['cn']] = $_GET['mail'];
932                       
933                        $_SESSION["mobile_mail"] = $participants;
934                        $this->add_recipients();
935                }
936               
937                function list_folders(){                       
938                        //Define o template para mensagens de retorno da funcao
939                        $this->template->set_file(array('folders_t' => 'folders.tpl'));
940                        $this->template->set_block('folders_t','retorno');
941                       
942                        $folders_list = '';
943                        $array_folders = Array();
944                        $this->folders = $this->imap_functions->get_folders_list(array('noSharedFolders' => true));             
945                       
946                        foreach($this->folders as $id => $folder)
947                        {
948                                if((strpos($folder['folder_id'],'user')===true && !is_array($folder)) || !is_numeric($id))
949                                        continue;
950                                        $array_folders[$folder['folder_id']]['id'] = $id;
951                                        $array_folders[$folder['folder_id']]['folder_name'] = $folder['folder_name'];
952                        }
953                       
954                        foreach($array_folders as $folder_id => $folder)
955                        {
956                                if(($folder_id != $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['save_in_folder']) && ($folder['id'] != 0)){
957                                        $folder_name = str_replace('*','',lang($folder['folder_name']));
958                                        $folder_link = "index.php?menuaction=mobile.ui_mobilemail.mail_list&folder=".$folder['id'];
959                                        $folders_list .= "<br>:: <a href=".$folder_link.">".$folder_name."</a>";
960                                }
961                        }
962                        $this->template->set_var('folders_list', $folders_list);
963                        $this->template->pfp('out','retorno');                             
964
965                }
966
967        }
968?>
Note: See TracBrowser for help on using the repository browser.