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

Revision 3791, 44.0 KB checked in by thiagoaos, 13 years ago (diff)

Ticket #1556 - Resolvido erro na exibição do ícone do anexo no expresso mini.

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