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

Revision 4002, 45.0 KB checked in by thiagoaos, 13 years ago (diff)

Ticket #1747 - Traduzido o nome das pastas padrões no mobile.

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