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

Revision 3602, 43.5 KB checked in by eduardoalex, 13 years ago (diff)

Ticket #1408 - Colocado a opção para utilizar o rascunho para enviar email.

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