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

Revision 4633, 44.8 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #2035 - Corrigido para que a visualização da mensagem siga as preferências.

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