source: trunk/mobile/inc/class.ui_mobilemail.inc.php @ 5243

Revision 5243, 46.0 KB checked in by gustavo, 12 years ago (diff)

Ticket #2375 - Verificar problema ao alternar entre a interface web/mobile

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