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

Revision 3829, 44.4 KB checked in by thiagoaos, 13 years ago (diff)

Ticket #1620 - Corrigido link voltar do expresso mini. Voltando agora para o último request.

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