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

Revision 5620, 46.6 KB checked in by cristiano, 12 years ago (diff)

Ticket #2497 - Nova estrategia para o salvamento automatico de rascunhos

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