Index: /trunk/mobile/inc/class.ui_mobilecalendar.inc.php
===================================================================
--- /trunk/mobile/inc/class.ui_mobilecalendar.inc.php	(revision 588)
+++ /trunk/mobile/inc/class.ui_mobilecalendar.inc.php	(revision 623)
@@ -4,5 +4,5 @@
 		var $bo;
 		var $cat;
-		var $link_tpl;
+		var $link_tpl;		
 		
 		var $public_functions = array(
@@ -18,5 +18,5 @@
 		
 		function ui_mobilecalendar() {
-			$this->bo = CreateObject('calendar.bocalendar',1);
+			$this->bo = CreateObject('calendar.bocalendar',1);			
 			$this->cat = &$this->bo->cat;
 			$GLOBALS['phpgw']->nextmatchs = CreateObject('phpgwapi.nextmatchs');
@@ -37,5 +37,95 @@
 		
 		function index() {
-			$GLOBALS['phpgw']->redirect_link('calendar.php');
+			$accountId = $GLOBALS['phpgw_info']['user']['account_id'];
+			$uicalendar = CreateObject("calendar.uicalendar");
+			$daysofWeek = array(lang('Sunday'), lang('Monday'),lang('Tuesday'),lang('Wednesday'),lang('Thursday'),lang('Friday'),lang('Saturday'));
+			$year = $uicalendar->bo->year;
+			$month = $uicalendar->bo->month;
+			$day = $uicalendar->bo->day;
+			$start = $GLOBALS['phpgw']->datetime->get_weekday_start($year, $month, $day) + $GLOBALS['phpgw']->datetime->tz_offset;
+			$tstart = $start - $GLOBALS['phpgw']->datetime->tz_offset;
+			$tstop = $tstart + 604800;
+			$uicalendar->bo->so->owner = $accountId;
+			$uicalendar->bo->so->open_box($accountId);
+			$uicalendar->bo->store_to_cache(
+				Array(
+					'syear'  => date('Y',$tstart),
+					'owner'	=> $accountId,
+					'smonth' => date('m',$tstart),
+					'sday'   => date('d',$tstart),
+					'eyear'  => date('Y',$tstop),
+					'emonth' => date('m',$tstop),
+					'eday'   => date('d',$tstop)
+				)
+			);
+			$daily = $uicalendar->bo->cached_events;
+			$p = CreateObject('phpgwapi.Template', "../mobile/templates/".$GLOBALS['phpgw_info']['server']['template_set']);
+			$p->set_file(Array('view' => 'calendar.tpl'));
+			$data[] = array();
+			@ksort($daily);
+			$p->set_block("view","body");
+			if($daily){
+				$p->set_block('view','view_event');
+				foreach($daily as $date => $day_params)	{
+					$year  = (int)substr($date,0,4);
+					$month = (int)substr($date,4,2);
+					$day   = (int)substr($date,6,2);
+					$day_of_week = $daysofWeek[$GLOBALS['phpgw']->datetime->day_of_week($year,$month,$day)];
+					$p->set_var("header_date",$day_of_week." - ".$day."/".$month."/".$year);
+					for($i = 0; $i < count($day_params);$i++)
+					{
+		
+						//Verifica se o usuario conectado é o dono do agendamento, se for não serão exibidos os links
+						//Aceitar e Rejeitar
+						$display = "";
+						if($accountId == $day_params[$i]['owner'])
+						{
+							$display = "none";
+						}
+		
+						$vars = $uicalendar->bo->event2array($day_params[$i]);
+						$data  = array (
+									"title_field"		=> $vars['title']['field'],
+									"title_data"		=> $vars['title']['data'],
+									"location_field"	=> $vars['location']['field'],
+									"location_data"		=> $vars['location']['data'] ? $vars['location']['data'] : "&nbsp;",
+									"startdate_field"	=> $vars['startdate']['field'],
+									"startdate_data" 	=> substr($vars['startdate']['data'],13, 17),
+									"enddate_field" 	=> $vars['enddate']['field'],
+									"enddate_data" 		=> substr($vars['enddate']['data'],13, 17),
+									"description_field"	=> $vars['description']['field'],
+									"description_data"	=> $vars['description']['data'] ? $vars['description']['data'] : "&nbsp;",
+									//Links Aceitar e Rejeitar o compromisso
+									"accept_title"		=> lang("Accept"),
+									"accept_data"		=> "index.php?menuaction=mobile.ui_mobilemail.set_action&cal_id=" . $day_params[$i]['id'] . "&action=3",
+									"reject_title"		=> lang("Reject"),
+									"reject_data"		=> "index.php?menuaction=mobile.ui_mobilemail.set_action&cal_id=" . $day_params[$i]['id'] . "&action=0",
+									"display"		=> $display
+									);
+		
+			//			print_r($vars);
+				    	 	$p->set_var($data);
+				    	 	$p->parse('views','view_event',True);
+					}
+				}
+				$p->parse('events','views');
+				//$p->pfp('out','views');
+			}
+			else {
+				$p->set_block('view','no_event');
+				$syear  = date('Y',$tstart);
+				$smonth = date('m',$tstart);
+				$sday   = date('d',$tstart);
+				$eyear  = date('Y',$tstop);
+				$emonth = date('m',$tstop);
+				$eday	= date('d',$tstop);
+				$p->set_var("start_date",$sday."/".$smonth."/".$syear);
+				$p->set_var("end_date", $eday."/".$emonth."/".$eyear);
+				$p->parse('events','no_event');
+		//		$p->pfp('out','no_event');
+			}
+			$p->set_var("lang_schedule",lang("schedule"));
+			//$p->pfp('out','body');
+			$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out','body'));
 		}
 		
@@ -105,5 +195,6 @@
 			$p->set_var('lang_add_participants',lang('keep add participants'));
 			$p->set_var('lang_continue',lang('continue scheduling'));
-			$p->pfp('out','body');
+			//$p->pfp('out','body');
+			$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out','body'));
 		}
 		
@@ -484,4 +575,5 @@
 				$p->set_var($var);
 				$delete_button = $p->fp('out','form_button');
+				
 			}
 			$p->set_var('delete_button',$delete_button);
Index: /trunk/mobile/inc/class.mobiletemplate.inc.php
===================================================================
--- /trunk/mobile/inc/class.mobiletemplate.inc.php	(revision 623)
+++ /trunk/mobile/inc/class.mobiletemplate.inc.php	(revision 623)
@@ -0,0 +1,74 @@
+<?php 
+	class mobiletemplate
+	{
+		private $template;
+		
+		/*
+		* @function mobiletemplate
+	 	* @abstract Construtor da classe, que monta o template home
+	 	* @author Nilton Emilio Buhrer Neto <niltonneto@celepar.pr.gov.br>
+	 	*/		
+		function mobiletemplate(){
+			$this->template = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
+			$this->template->set_file(Array('home_t' => 'home.tpl'));	
+			$this->template->set_block('home_t', 'mobile_home');			
+		}
+
+		/*
+		* @function set_content
+	 	* @abstract Carrega o atributo "content" do template principal
+	 	* @author Nilton Emilio Buhrer Neto <niltonneto@celepar.pr.gov.br>
+	 	*/		
+		public function set_content($content){
+			$pre_content = $this->template->get_var("content");
+			$this->template->set_var("content", $pre_content.$content);
+		}
+
+		/*
+		* @function print_all
+	 	* @abstract Imprime toda tela do Expresso Mini
+	 	* @author Nilton Emilio Buhrer Neto <niltonneto@celepar.pr.gov.br>
+	 	*/
+		public function print_page($class, $method){		
+			$this->print_header();
+			$this->print_navbar();
+			$filename = 'inc/class.'.$class.'.inc.php';
+			include_once($filename);	
+			$obj = new $class();		
+			$obj -> $method();		
+			$this->template->pfp('out', 'mobile_home');
+		}
+	
+		/*
+		* @function print_navbar
+	 	* @abstract Imprime o início da tela do Expresso Mini => barra de navegação
+	 	* @author Mário César Kolling <mario.kolling@serpro.gov.br>
+	 	*/
+		private function print_navbar(){
+			$this-> template->set_var('href_newmail', 'index.php?menuaction=mobile.ui_mobilemail.new_msg&clk=01');
+			$this-> template->set_var('lang_newmail', lang('Create mail'));
+			$this-> template->set_var('href_email', "index.php?menuaction=mobile.ui_mobilemail.mail_list");
+			$this-> template->set_var('lang_email', lang('E-mail'));
+			$this-> template->set_var('href_calendar', "index.php?menuaction=mobile.ui_mobilecalendar.index");
+			$this-> template->set_var('lang_calendar', lang('Calendar'));
+			$this-> template->set_var('href_cc', 'index.php?menuaction=mobile.ui_mobilecc.contacts_list');
+			$this-> template->set_var('lang_cc', lang('Contact Center'));		
+		}
+
+		/*
+		* @function print_header
+	 	* @abstract Imprime o início da tela do Expresso Mini => headers html
+	 	* @author Mário César Kolling <mario.kolling@serpro.gov.br>
+	 	*/		
+		private function print_header(){
+			$GLOBALS['phpgw']->accounts->read_repository();
+			$var  = Array(
+				'fullname'	=> $GLOBALS['phpgw']->accounts->data['fullname'],
+				'account_lid'	=> $GLOBALS['phpgw_info']['user']['account_lid'],
+				'lang_logout'	=> lang('Logout'),
+				'template_set'	=> $GLOBALS['phpgw_info']['server']['template_set']
+			);		
+			$this->template->set_var($var);		
+		}		
+	}
+?>
Index: /trunk/mobile/inc/class.ui_mobilemail.inc.php
===================================================================
--- /trunk/mobile/inc/class.ui_mobilemail.inc.php	(revision 623)
+++ /trunk/mobile/inc/class.ui_mobilemail.inc.php	(revision 623)
@@ -0,0 +1,829 @@
+<?php
+	/**************************************************************************\
+	* eGroupWare                                                               *
+	* http://www.egroupware.org                                                *
+	* The file written by Mário César Kolling <mario.kolling@serpro.gov.br>    *
+	* --------------------------------------------                             *
+	*  This program is free software; you can redistribute it and/or modify it *
+	*  under the terms of the GNU General Public License as published by the   *
+	*  Free Software Foundation; either version 2 of the License, or (at your  *
+	*  option) any later version.                                              *
+	\**************************************************************************/
+
+	//TODO: Criar a Classe Widget.
+
+	include_once(PHPGW_INCLUDE_ROOT.'/expressoMail1_2/inc/class.imap_functions.inc.php');
+
+	// Classe principal do Mini Mail
+	class ui_mobilemail{
+
+		// Define as funções públicas
+		var $public_functions = array(
+			'mail_list'	=> True,
+			'change_folder' => True,
+			'change_page'	=> True,
+			'show_msg'	=> True,
+			'send_mail'	=> True,
+			//'reply_msg'	=> True,
+			'new_msg'	=> True,
+		);
+
+		var $folders; // Pastas imap
+		var $current_folder; // Pasta corrente
+		var $current_page; // Página corrente da lista de e-mails da pasta corrente
+		var $imap_functions; // Variável que recebe um objeto do tipo class.imap_functions.inc.php
+		var $allowed_tags = '<p><a><br><em><strong><ol><li><ul><div><font>'; // Tags html que não serão removidas
+			// ao mostrar corpo do e-mail
+
+
+		/*
+		 * @function mobilemail
+		 * @abstract Método construtor da classe principal do Mini Mail
+		 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
+		 */
+		function ui_mobilemail()
+		{
+			
+			$this-> load_session();						
+			// Recupera atributos da classe gravados na sessão
+			$folders = $GLOBALS['phpgw']->session->appsession('mobilemail.folders','mobile');
+			$current_folder = $GLOBALS['phpgw']->session->appsession('mobilemail.current_folder','mobile');
+			$current_page = $GLOBALS['phpgw']->session->appsession('mobilemail.current_page','mobile');
+
+			// Inicializa a classe class.imap_functions.inc.php
+			$this->imap_functions = new imap_functions();
+
+			// Testa a existência dos atributos da classe recuperadas da sessão, e as carrega ou inicializa.
+			if ($folders)
+			{
+				$this->folders = $folders;
+			}
+			else
+			{
+				$this->folders = $this->imap_functions->get_folders_list();
+			}
+
+			if ($current_folder)
+			{
+				$this->current_folder = $current_folder;
+			}
+			else
+			{
+				$this->current_folder = 0; // Define o folder INBOX como o folder corrente
+			}
+
+			if ($current_page)
+			{
+				$this->current_page = $current_page;
+			}
+			else
+			{
+				$this->current_page = 1; // Define a primeira página como página padrão
+			}
+
+		}
+
+		/*
+		 * @function save_session
+		 * @abstract Salva os atributos da classe na sessão
+		 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
+		 */
+		function save_session()
+		{
+
+			$GLOBALS['phpgw']->session->appsession('mobilemail.folders','mobile',$this->folders);
+			$GLOBALS['phpgw']->session->appsession('mobilemail.current_folder','mobile',$this->current_folder);
+			$GLOBALS['phpgw']->session->appsession('mobilemail.current_page','mobile',$this->current_page);
+
+		}
+
+		/*
+		 * @function change_page
+		 * @abstract Troca a página de exibição da lista de e-mails, e mostra a nova página
+		 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
+		 */
+		function change_page()
+		{
+			if (isset($_GET['page']))
+			{
+				$this->current_page = $_GET['page'];
+			}
+			$this->mail_list();
+			$this->save_session();
+		}
+
+		/*
+		 * @function change_folder
+		 * @abstract Troca a pasta do imap, e mostra a primeira página da nova pasta
+		 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
+		 */
+		function change_folder()
+		{
+			$folder = $_GET['folder'];
+			if (isset($folder))
+			{
+				$this->current_folder = $folder;
+				$this->current_page = 1;
+			}
+			$this->mail_list();
+			$this->save_session();
+		}
+
+		/*
+		 * @function show_msg
+		 * @abstract Mostra a mensagem de e-mail requisitada
+		 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
+		 */
+		 // TODO: retirar msg_folder dos parâmentros necessários no GET e usar $this->current_folder
+		function show_msg()
+		{
+			$params = array();
+
+			//TODO: testar chamar sem parâmetros para determinar se ocorre algum problema
+			if (isset($_GET['msg_number']) && isset($_GET['msg_folder']))
+			{
+				$params = array(
+					'msg_number' => $_GET['msg_number'],
+					'msg_folder' => $_GET['msg_folder'],
+				);
+			}
+
+			$msg = $this->imap_functions->get_info_msg($params);
+
+			// Carrega o template
+			$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
+			$p->set_file(
+				Array(
+					'view_msg_t' => 'view_msg.tpl'
+				)
+			);
+			$p->set_block('view_msg_t', 'mail_header');
+			$p->set_block('view_msg_t', 'mail_body');
+			$p->set_block('view_msg_t', 'mail_footer');
+			$p->set_block('view_msg_t', 'reply_msg');
+			$p->set_block('view_msg_t', 'attachment_list');
+			$p->set_block('view_msg_t', 'begin_anchor');
+			$p->set_block('view_msg_t', 'end_anchor');
+
+			// Define o cabeçalho do e-mail
+			$p->set_var('from_label', lang("From"));
+			$p->set_var('from', $msg['from']['full']);
+			$p->set_var('to_label', lang("To"));
+
+			$p->set_var('subject_label', lang("Subject"));
+			$p->set_var('subject', $msg['subject']);
+			$p->set_var('date_label', lang("Date"));
+			$p->set_var('date', $msg['fulldate']);
+
+
+			// Mostra o corpo do e-mail
+			$p->set_var('body', strip_tags($msg['body'], $this->allowed_tags)); // Usa a função strip_tags() para filtrar
+				// as tags que estão presentes no corpo do e-mail.
+			$p->set_var('link_text', lang("Return"));
+			$p->set_var('link', "index.php?menuaction=mobile.ui_mobilemail.mail_list");
+
+
+			$p->set_var('reply_text', lang("Reply"));
+			$msg_number = $_GET['msg_number'];
+			$msg_folder = $_GET['msg_folder'];
+			$p->set_var('reply', "index.php?menuaction=mobile.ui_mobilemail.new_msg&msg_number=$msg_number&msg_folder=$msg_folder");
+
+			if (!empty($msg['attachments']) && !empty($msg['attachments']['names']))
+			{
+				$p->set_var('attachment_message', lang('This message have attachment(s)'));
+			}
+			else
+			{
+				$p->set_var('attachment_message', lang('This message don\'t have attachment(s)'));
+			}
+
+			$p->parse('view_msg_t', 'end_anchor');
+			$p->parse('view_msg_t', 'begin_anchor');
+			//$p->pfp('view_msg_t', 'mail_header');
+			/*$p->pfp('out', 'mail_header');
+			//$p->pfp('view_msg_t', 'mail_body');
+			$p->pfp('out', 'mail_body');
+			//$p->pfp('view_msg_t', 'attachment_list');
+			$p->pfp('out', 'attachment_list');
+			//$p->pfp('view_msg_t', 'mail_footer');
+			$p->pfp('out', 'reply_msg');
+			//$p->pfp('out', 'mail_footer');*/
+
+			//$p->pfp('view_msg_t', 'mail_header');
+			$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'mail_header'));
+			$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'mail_body'));
+			$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'attachment_list'));
+			$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'reply_msg'));
+		}
+
+		/*
+		 * @function index
+		 * @abstract Página inicial da aplicação mobilemail, mantém o estado atual. Ou seja, mostra lista de e-mails
+		 * do folder e página definidos pelos parâmetros current_folder e current_page.
+		 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
+		 */
+		 // TODO: Talvez seja melhor voltar sempre para o Inbox e primeira página
+		function index()
+		{						
+			$this->print_folder_selection();
+			$this->mail_list();
+			$this->save_session();
+
+		}
+		
+		function load_session(){			
+			/************************************\
+			 * Inicialização do expressoMail1_2 *
+			\************************************/
+			// Get Data from ldap_manager and emailadmin.
+			$ldap_manager = CreateObject('contactcenter.bo_ldap_manager');
+			$boemailadmin	= CreateObject('emailadmin.bo');
+			$emailadmin_profile = $boemailadmin->getProfileList();
+			$_SESSION['phpgw_info']['expressomail']['email_server'] = $boemailadmin->getProfile($emailadmin_profile[0]['profileID']);
+			$_SESSION['phpgw_info']['expressomail']['user'] = $GLOBALS['phpgw_info']['user'];
+			$_SESSION['phpgw_info']['expressomail']['server'] = $GLOBALS['phpgw_info']['server'];
+			$_SESSION['phpgw_info']['expressomail']['ldap_server'] = $ldap_manager ? $ldap_manager->srcs[1] : null;
+			$_SESSION['phpgw_info']['expressomail']['user']['email'] = $GLOBALS['phpgw']->preferences->values['email'];
+		
+			// Fix problem with cyrus delimiter changes in preferences.
+			// Dots in names: enabled/disabled.
+			$save_in_folder = @eregi_replace("INBOX/", "INBOX".$_SESSION['phpgw_info']['expressomail']['email_server']['imapDelimiter'], $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['save_in_folder']);
+			$save_in_folder = @eregi_replace("INBOX.", "INBOX".$_SESSION['phpgw_info']['expressomail']['email_server']['imapDelimiter'], $save_in_folder);
+			$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['save_in_folder'] = $save_in_folder;
+			// End Fix.
+		
+		    // Loading Admin Config Module
+		    $c = CreateObject('phpgwapi.config','expressoMail1_2');
+		    $c->read_repository();
+		    $current_config = $c->config_data;
+		    $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] = $current_config['expressoMail_enable_log_messages'];
+		    // Begin Set Anti-Spam options.
+		    $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_ham'] = $current_config['expressoMail_command_for_ham'];
+		    $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_spam'] = $current_config['expressoMail_command_for_spam'];
+		    $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_use_spam_filter'] = $current_config['expressoMail_use_spam_filter'];
+		    echo '<script> var array_lang = new Array();var use_spam_filter = \''.$current_config['expressoMail_use_spam_filter'].'\' </script>';
+			// End Set Anti-Spam options.
+		
+		    // Set Imap Folder names options
+		    $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'] 	= $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']	? $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']		: "Trash";
+		    $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'] 	= $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'] ? $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'] 	: "Drafts";
+		    $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder'] 	= $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder']	? $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder']		: "Spam";
+		    $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder']	= $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'] 	? $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'] 		: "Sent";
+			include("../expressoMail1_2/inc/load_lang.php");		    
+		}
+
+		/*
+		 * @function print_folder_selection
+		 * @abstract Imprime o folder corrente (INBOX)
+		 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
+		 */
+		function print_folder_selection()
+		{
+
+			$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
+			$p->set_file(
+				Array(
+					'mobilemail_t' => 'mobilemail.tpl'
+				)
+			);
+			$p->set_block('mobilemail_t', 'inbox_folder_list');
+			$p->set_var('lang_folder', lang('Folder'));
+			$p->set_var('lang_inbox', lang('Inbox'));
+			//$p->set_var('folder_items', $folder_items);
+			$p->parse('mobilemail_t', 'inbox_folder_list');			
+			//$p->fpf('out', 'mobilemail_t');
+			$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'mobilemail_t'));
+
+		}
+
+		/*
+		 * @function old_print_folder_selection
+		 * @abstract Imprime na tela a caixa de seleção de folders
+		 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
+		 */
+		function old_print_folder_selection()
+		{
+
+			// Processa as options
+			$folder_items = '';
+
+			foreach ($this->folders as $i => $j)
+			{
+
+				$option_selected = '';
+				$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
+				$p->set_file(
+					Array(
+						'mobilemail_t' => 'mobilemail.tpl'
+					)
+				);
+				$p->set_block('mobilemail_t', 'folder_item');
+
+				if (is_numeric($i))
+				{
+					if ($i == $this->current_folder)
+					{
+						 $option_selected = 'selected="selected"';
+					}
+
+					$p->set_var('option_selected', $option_selected);
+					$p->set_var('folder_id', $j['folder_id']);
+					$p->set_var('folder_name', $j['folder_id']); // Mudar... provavelmente usar preg_replace
+													   			 // para substituir cpf pelo nome do usuário.
+
+					if ($j['folder_unseen'] > 0)
+					{
+						$p->set_var('folder_unseen', ' - ('.$j['folder_unseen'].')');
+					}
+
+					$folder_items .= $p->fp('mobile_t', 'folder_item');
+				}
+
+			}
+
+			// Processa o select
+			$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
+			$p->set_file(
+				Array(
+					'mobilemail_t' => 'mobilemail.tpl'
+				)
+			);
+			$p->set_block('mobilemail_t', 'folder_list');
+			$p->set_var('folder_items', $folder_items);
+			$p->parse('mobilemail_t', 'folder_list');			
+			//$p->pfp('out', 'mobilemail_t');
+			$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'mobilemail_t'));
+
+		}
+
+		/*
+		 * @function mail_list
+		 * @abstract Imprime a lista de e-mails
+		 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
+		 */
+		function mail_list()
+		{
+
+			$this->messages_per_page = 10; //TODO: Pegar esse valor de preferences
+//		var $pages;
+//		var $actual_page;
+//		var $number_of_messages;
+
+			if (!isset($this->number_of_messages))
+			{
+				$params = array(
+					'folder' => $this->folders[$this->current_folder]['folder_id'],
+				);
+				$this->number_of_messages = $this->imap_functions->get_num_msgs($params);
+			}
+
+			// Recalcular as páginas
+			$this->pages = ceil($this->number_of_messages/$this->messages_per_page);
+			$page = $this->current_page;
+
+			$params = array(
+				'folder' 			=> $this->folders[$this->current_folder]['folder_id'],
+				'msg_range_begin' 	=> $this->current_page * $this->messages_per_page - ($this->messages_per_page - 1),
+				'msg_range_end'		=> $this->current_page * $this->messages_per_page,
+				'sort_box_type'		=> 'SORTARRIVAL',
+				'sort_box_reverse'	=> 1
+			);
+
+			$messages = $this->imap_functions->get_range_msgs2($params);
+			$this->print_mails_list($messages);
+			$this->print_page_navigation($this->pages, $this->current_page);
+
+		}
+
+		/*
+		 * @function print_mails_list
+		 * @abstract Imprime a lista de mensagens
+		 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
+		 * @param array Um array com a lista de mensagens recuperado por $this->imap_functions->get_range_msgs2($params)
+		 */
+		function print_mails_list($messages)
+		{
+
+			// Cria a lista de e-mails
+			$mail_rows = '';
+			if ($this->number_of_messages != 0)
+			{
+				foreach ($messages as $index => $msg)
+				{
+					$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
+					$p->set_file(
+						Array(
+							'mobilemail_t' => 'mobilemail.tpl'
+						)
+					);
+					$p->set_block('mobilemail_t', 'mail_row');
+					$p->set_block('mobilemail_t', 'end_strong');
+                                        $p->set_block('mobilemail_t', 'begin_strong');
+                                        $p->set_var('unseen_bkg', "#FFFFFF");
+
+					if (is_numeric($index))
+					{
+						!empty($msg['from']['name']) ? $from = $msg['from']['name'] : $from = $msg['from']['email'];
+						!empty($msg['subject']) ? $subject = $msg['subject'] : $subject = lang('[empty subject]');
+						if ($msg['Unseen'] == 'U'){ //Setando as mensagens nao lidas
+	                                                $p->set_var('strong_unseen_begin', trim($p->fp('mobilemail_t', 'begin_strong')));
+                                                        $p->set_var('strong_unseen_end', trim($p->fp('mobilemail_t', 'end_strong')));
+	                                                $p->set_var('unseen_bkg', "#E0ECFF");
+	                                                //$p->set_var('unseen_bkg', "#E8EEF7");
+	                                }
+						$p->set_var('from', $from);
+						$p->set_var('subject', $subject);
+						$p->set_var('msg_number', $msg['msg_number']);
+						$p->set_var('date', $msg['udate']);
+						$p->set_var('msg_folder', $this->folders[$this->current_folder]['folder_id']);
+						$p->set_var('from_label', lang('From'));
+						$mail_rows .= $p->fp('mobilemail_t', 'mail_row');
+					}
+				}
+
+				// Imprime a lista de e-mails
+				$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
+				$p->set_file(
+					Array(
+						'mobilemail_t' => 'mobilemail.tpl'
+					)
+				);
+				$p->set_block('mobilemail_t', 'mail_list');
+				$p->set_var('mail_rows', $mail_rows);
+				//$p->pfp('out', 'mail_list');
+				$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'mail_list'));
+			}
+			else
+			{
+				// Lista de e-mails vazia
+				$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
+				$p->set_file(
+					Array(
+						'mobilemail_t' => 'mobilemail.tpl'
+					)
+				);
+				$p->set_block('mobilemail_t', 'empty_list');
+				$p->set_var('empty_message', lang('Empty folder'));				
+				//$p->pfp('out', 'empty_list');
+				$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'empty_list'));
+			}
+		}
+
+		/*
+		 * @funtion print_page_navigation
+		 * @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.
+		 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
+		 * @param integer Número de páginas que serão geradas
+		 * @param integer Página corrente
+		 */
+		// TODO: mover este método para a classe page_navigation subclasse de widget
+		function print_page_navigation($number_of_pages, $page = 1)
+		{
+
+			$pages = '';
+
+			if ($number_of_pages != 0)
+			{
+				// Geração das páginas
+				for ($i = 1; $i <= $number_of_pages ; $i++)
+				{
+
+					$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
+					$p->set_file(
+						Array(
+							'mobilemail_t' => 'mobilemail.tpl'
+						)
+					);
+
+					$p->set_block('mobilemail_t', 'space');
+					$p->set_block('mobilemail_t', 'begin_anchor');
+					$p->set_block('mobilemail_t', 'end_anchor');
+					$p->set_block('mobilemail_t', 'page_item');
+					$p->set_block('mobilemail_t', 'begin_strong');
+					$p->set_block('mobilemail_t', 'end_strong');
+
+					if ($i == $page)
+					{
+						// Se for a página sendo gerada for a página corrente,
+						// não gera a âncora e destaca o número (negrito)
+						$p->set_var('end_anchor', '');
+						$p->set_var('begin_anchor', '');
+						$p->set_var('begin_strong', trim($p->fp('mobilemail_t', 'begin_strong')));
+						$p->set_var('end_strong', trim($p->fp('mobilemail_t', 'end_strong')));
+					}
+					else
+					{
+						// Senão, gera a âncora
+						$p->set_var('begin_strong', '');
+						$p->set_var('end_strong', '');
+						$p->set_var('end_anchor', trim($p->fp('mobilemail_t', 'end_anchor')));
+						$p->set_var('begin_anchor_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&page=$i");
+						$p->set_var('begin_anchor', trim($p->fp('mobilemail_t', 'begin_anchor')));
+					}
+
+					$p->set_var('page', $i);
+					//$pages .= trim($p->fp('mobilemail_t', 'page_item'));
+
+				}
+				$pages .= " ".$page." ".lang("of")." ".$number_of_pages." ";
+
+				// Geração dos links "anterior" e "próximo"
+				$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
+				$p->set_file(
+					Array(
+						'mobilemail_t' => 'mobilemail.tpl'
+					)
+				);
+
+				//$p->set_block('mobilemail_t', 'space');
+				$p->set_block('mobilemail_t', 'mail_footer');
+				$p->set_block('mobilemail_t', 'previous');
+				$p->set_block('mobilemail_t', 'next');
+
+				$next_page = $page + 1;
+				$previous_page = $page - 1;
+
+				if ($page == 1)
+				{
+					// Se for a primeira página, não imprime o link "anterior""
+					$p->set_var('previous', '');
+					if ($page == $number_of_pages)
+					{
+						// Se só existir uma página, não imprime o link "próximo"
+						$p->set_var('next', '');
+					}
+					else
+					{
+						$p->set_var('next_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&page=$next_page");
+						$p->set_var('next', trim($p->fp('mobilemail_t', 'next')));
+					}
+
+				}
+				else if ($page == $number_of_pages)
+				{
+					// Se for a última página, não imprime o link "próximo"
+					$p->set_var('next', '');
+					$p->set_var('previous_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&page=$previous_page");
+					$p->set_var('previous', trim($p->fp('mobilemail_t', 'previous')));
+				}
+				else
+				{
+					// Senão, imprime os links "anterior" e "próximo"
+					$p->set_var('previous_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&page=$previous_page");
+					$p->set_var('previous', trim($p->fp('mobilemail_t', 'previous')));
+
+					$p->set_var('next_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&page=$next_page");
+					$p->set_var('next', trim($p->fp('mobilemail_t', 'next')));
+				}
+
+				$p->set_var('pages', $pages);
+				//$p->pfp('out', 'mail_footer');
+				$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'mail_footer'));
+			}
+
+		}
+
+		/*
+		 * @function new_msg()
+		 * @abstract Gera o formulário para criar novo e-mail.
+		 * @author Rommel de Brito Cysne <rommel.cysne@serpro.gov.br>
+		 
+		function new_msg()
+		{
+			$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
+			$p->set_file(
+				Array(
+					'new_msg_t' => 'new_msg.tpl'
+				)
+			);
+
+			$p->set_block('new_msg_t', 'msg_header');
+			$p->set_block('new_msg_t', 'text');
+			$p->set_block('new_msg_t', 'begin_form');
+			$p->set_block('new_msg_t', 'end_form');
+			$p->set_block('new_msg_t', 'hidden_area');
+
+			$p->set_var('to_label', lang("To"));
+			$p->set_var('to', "");
+			$p->set_var('to_mail', "");
+
+			$p->set_var('subject_label', lang("Subject"));
+			$p->set_var('subject', "");
+
+			$p->set_var('msg_number', $_GET['msg_number']);
+			$p->set_var('msg_folder', $_GET['msg_folder']);
+
+			$p->set_var('send_label', lang("Send"));
+
+			$p->set_var('form_action', "index.php?menuaction=mobile.ui_mobilemail.send_mail");
+
+			$p->pfp('out', 'begin_form');
+			$p->pfp('out', 'msg_header');
+			$p->pfp('out', 'text');
+			$p->pfp('out', 'hidden_area');
+			$p->pfp('out', 'end_form');
+
+		
+		}
+*/
+		/*
+		 * @function new_msg()
+		 * @abstract Gera o formulário para criar/enviar novo e-mail ou resposta de e-mail.
+		 * @author Rommel de Brito Cysne <rommel.cysne@serpro.gov.br>
+		 */
+		
+		function new_msg()
+		{
+			$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
+			$p->set_file(
+				Array(
+					'new_msg_t' => 'new_msg.tpl'
+				)
+			);
+
+
+			if (isset($_GET['msg_number']))
+			{
+				$params = array(
+					'msg_number' => $_GET['msg_number'],
+				);
+
+				$msg_number = $_GET['msg_number'];
+			}
+		
+			if($params)
+				$msg = $this->imap_functions->get_info_msg($params);
+
+
+			$p->set_block('new_msg_t', 'msg_header');
+			$p->set_block('new_msg_t', 'text');
+			$p->set_block('new_msg_t', 'begin_form');
+			$p->set_block('new_msg_t', 'end_form');
+			$p->set_block('new_msg_t', 'hidden_area');
+
+			if($_GET['clk'])
+			{
+
+				$p->set_var('to_label', lang("To"));
+				$p->set_var('to', "");
+				$p->set_var('to_mail', "");
+				$p->set_var('subject_label', lang("Subject"));
+				$p->set_var('subject', "");
+
+			}
+			else if($_GET['cc_mob'])
+			{
+
+				$p->set_var('to_label', lang("To"));
+				$p->set_var('to', $_GET['input_to']);
+				$p->set_var('to_mail', $_GET['input_to_mail']);
+
+				$p->set_var('subject_label', lang("Subject"));
+				$p->set_var('subject', "");
+
+				$p->set_var('msg_number', $_GET['msg_number']);
+				$p->set_var('msg_folder', $_GET['msg_folder']);
+
+				$p->set_var('read_only', 'readonly');
+			}
+			else
+			{
+
+				$p->set_var('from_label', lang("From"));
+				$p->set_var('from', $msg['toaddress2']);
+
+				$p->set_var('to_label', lang("To"));
+				$mail_to = $msg['from']['full'];
+				$p->set_var('to', $msg['from']['name']);
+				$p->set_var('to_mail', $msg['from']['email']);
+
+				$p->set_var('subject_label', lang("Subject"));
+				$p->set_var('subject', "Re:" . $msg['subject']);
+
+				$p->set_var('msg_number', $_GET['msg_number']);
+				$p->set_var('msg_folder', $_GET['msg_folder']);
+
+				$p->set_var('read_only', "readonly");
+			}
+
+			$p->set_var('send_label', lang("Send"));
+
+			$p->set_var('form_action', "index.php?menuaction=mobile.ui_mobilemail.send_mail");
+
+			/*$p->pfp('out', 'begin_form');
+			$p->pfp('out', 'msg_header');
+			$p->pfp('out', 'text');
+			$p->pfp('out', 'hidden_area');
+			$p->pfp('out', 'end_form');
+			*/
+			$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'begin_form'));
+			$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'msg_header'));
+			$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'text'));
+			$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'hidden_area'));
+			$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'end_form'));
+		}
+
+		/*
+		 * @function send_mail()
+		 * @abstract Função que realiza o envio de e-mails.
+		 * @author Rommel de Brito Cysne <rommel.cysne@serpro.gov.br>
+		 */
+		function send_mail()
+		{
+			//Chamada da classe phpmailer
+			include_once(PHPGW_SERVER_ROOT."/phpgwapi/inc/class.phpmailer.inc.php");
+
+			//Recebe os dados do form (passados pelo POST)
+			$userName = $_POST['input_to']; //"User Someone";
+			$userMail = $_POST['input_to_mail']; //"user.someone@mail.com.br";
+			$subject = $_POST['input_subject']; //"Mail Subject";
+			$body = $_POST['body']; //"Mail body. Any text.";
+
+			if($userMail == "")
+			{
+				$userMail = $userName;
+			}
+
+			//Cria objeto
+			$mail = new PHPMailer();
+
+			if(!$this->imap_functions->add_recipients("to", $userMail, &$mail))
+			{
+				$error_msg = lang("Some addresses in the To field were not recognized. Please make sure that all addresses are properly formed");
+			}
+
+			$mail->IsSMTP();
+			$mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer'];
+			$mail->Port = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpPort'];
+
+			//Envia os emails em formato HTML; se false -> desativa.
+			$mail->IsHTML(true);
+			//Email do remetente da mensagem
+			$mail->Sender = $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email'];
+			//Nome do remetente do email
+			$mail->SenderName = $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname'];
+			//Endereço de destino do email, ou seja, pra onde a mensagem vai
+			//$mail->AddAddress("$userMail");
+			//Assunto da mensagem
+			$mail->Subject = $subject;
+			//Corpo da mensagem
+			$mail->Body .= "<br />$body<br />";
+
+			//Cria um objeto template
+			$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
+			//Define o template para mensagens de retorno da funcao
+			$p->set_file(
+				Array(
+					'sent_msg_t' => 'sent_msg.tpl'
+				)
+			);
+
+			$p->set_block('sent_msg_t','retorno');
+			@header('Refresh: 1; url=./');
+
+			//Se o e-mail nao for enviado por qualquer motivo...
+			if(!$mail->Send())
+			{
+				//... é exibida a mensagem abaixo e o respectivo erro...
+				$p->set_var('msg', lang("Message not sent"));
+				$p->set_var('erro', lang("error") . $mail->ErrorInfo);
+
+			//... caso contrário...
+			}else {
+				//... mostra mensagem de sucesso e link de retorno à lista de e-mail
+				$p->set_var('msg', lang("Message sent successfully"));
+				//$p->set_var('link_text', lang("Return"));
+				//$p->set_var('link', "mobilemail_index.php");
+
+			}
+
+			//$p->pfp('out','retorno');
+			$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out','retorno'));
+
+		}
+
+
+
+
+		//PAREI
+		function delete_msg()
+		{
+		
+			$this->username           = $_SESSION['phpgw_info']['expressomail']['user']['userid'];
+			$this->password           = $_SESSION['phpgw_info']['expressomail']['user']['passwd'];
+			$this->imap_server        = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer'];
+			$this->imap_port          = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort'];
+			$this->imap_delimiter = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDelimiter'];
+
+			$mbox_stream = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder, $this->username, $this->password) or die(serialize(array('imap_error' => imap_last_error())));
+
+
+		}
+
+		function retorna()
+		{
+			
+		}
+
+	}
+?>
Index: /trunk/mobile/inc/class.ui_mobilecc.inc.php
===================================================================
--- /trunk/mobile/inc/class.ui_mobilecc.inc.php	(revision 588)
+++ /trunk/mobile/inc/class.ui_mobilecc.inc.php	(revision 623)
@@ -3,5 +3,5 @@
 		
 		var $nextmatchs;
-		var $bo;
+		var $bo;		
 		var $page_info = array (
 				'actual_catalog' => false,
@@ -115,5 +115,5 @@
 			$ids = $this->bo->find($what,$rules);
 
-			foreach($ids as $id_r) { //Quero apenas os ids, como valores nas posições do array
+			if(is_array($ids)) foreach($ids as $id_r) { //Quero apenas os ids, como valores nas posições do array
 				$retorno[] = $id_r[substr($id,strpos($id,".")+1)];
 			}
@@ -262,6 +262,5 @@
 			if(!$from_calendar) {
 				$branchs = $bo_ldap_manager->get_external_ldap_sources();
-				
-				foreach($branchs as $id=>$branch) { //Ldaps externos
+				if(is_array($branchs)) foreach($branchs as $id=>$branch) { //Ldaps externos
 					$p->set_var(array('option_value'=>"bo_global_ldap_catalog#".
 							$id."#".
@@ -334,5 +333,5 @@
 							$var['row_telefone'] = $conn1['connection_value'];
 						}
-						$var['form_action'] = "index.php?menuaction=mobile.mobilemail.new_msg";
+						$var['form_action'] = "index.php?menuaction=mobile.ui_mobilemail.new_msg";
 						$p->set_var($var);
 						$p->parse('rows','row',True);
@@ -367,5 +366,5 @@
 						}
 						if(!$from_calendar)
-							$var['form_action'] = "index.php?menuaction=mobile.mobilemail.new_msg";
+							$var['form_action'] = "index.php?menuaction=mobile.ui_mobilemail.new_msg";
 						else {
 							$var['id_contact'] = $entry['uidnumber'][0].'U';
@@ -382,6 +381,6 @@
 				$p->set_var('lang_choose_the_participants',lang("choose the participants"));
 				$participants = $_SESSION['mobile_calendar'];
-				reset($participants);
-				while (($participant = current($participants))!==false) {
+				@reset($participants);
+				if(count($participants)) while (($participant = current($participants))!==false) {
 					$p->set_var('row_contact_name',$participant);
 					if(next($participants)!==false)
@@ -423,5 +422,6 @@
 			}			
 			
-			$p->pfp('out','body');
+			//$p->pfp('out','body');
+			$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out','body'));
 		}
 		
Index: /trunk/mobile/index.php
===================================================================
--- /trunk/mobile/index.php	(revision 517)
+++ /trunk/mobile/index.php	(revision 623)
@@ -4,25 +4,10 @@
 	$phpgw_info = array();
 	$GLOBALS['sessionid'] = isset($_GET['sessionid']) ? $_GET['sessionid'] : @$_COOKIE['sessionid'];
+	
 	if(!$GLOBALS['sessionid'])
-	{
-		/*if (($GLOBALS['phpgw_info']['server']['use_https'] == 2) && ($_SERVER['HTTPS'] != 'on'))
-		{
-
-			Header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
-			exit;
-		}
-		else
-		{*/
-		$location = 'Location: ' . $_SERVER['SCRIPT_URL'].'login.php';
-		Header('Location: ' . $_SERVER['SCRIPT_URL'].'login.php');
-		//Header('Location: ' . $_SERVER['SCRIPT_URL'].'login.php' .
-		//	(isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING']) ?
-		//	'?phpgw_forward='.urlencode('/index.php?'.$_SERVER['QUERY_STRING']):''));
+	{		
+		$location = 'Location: login.php';
+		Header($location);
 		exit;
-		//	Header('Location: login.php'.
-		//	(isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING']) ?
-		//	'?phpgw_forward='.urlencode('/mobile/index.php?'.$_SERVER['QUERY_STRING']):''));
-		//	exit;
-		//}
 	}
 
@@ -37,4 +22,5 @@
 		This is the menuaction driver for the multi-layered design
 	*/
+
 	if(isset($_GET['menuaction']))
 	{
@@ -47,10 +33,9 @@
 	else
 	{
-	//$phpgw->log->message('W-BadmenuactionVariable, menuaction missing or corrupt: %1',$menuaction);
-	//$phpgw->log->commit();
 		$mobileapp = 'home';
 		$invalid_data = True;
 	}
 
+	
 	$GLOBALS['phpgw_info']['flags'] = array(
 		'noheader'   => True,
@@ -62,22 +47,21 @@
 	include('../header.inc.php');
 	include('./mobile_header.inc.php');
-
+	
 	if($mobileapp == 'home')
 	{
-		Header('Location: ' . $GLOBALS['phpgw']->link('/mobile/home.php'));
+		start_prefered_app();
 	}
-
+	
 	$GLOBALS[$class] = CreateObject(sprintf('%s.%s','mobile',$class));
 	$public_functions = $GLOBALS[$class]->public_functions;
 	if((is_array($GLOBALS[$class]->public_functions) && $GLOBALS[$class]->public_functions[$method]) && ! $invalid_data)
-	//if((is_array($public_functions) && $public_functions[$method]) && ! $invalid_data)
-	{
-		execmethod($_GET['menuaction']);
-		print_header();
-		print_footer();
+	{						
+		$GLOBALS['phpgw_info']['mobiletemplate'] = CreateObject("mobile.mobiletemplate");					
+		$GLOBALS['phpgw_info']['mobiletemplate'] -> print_page($class,$method);		
 		unset($mobileapp);
 		unset($class);
 		unset($method);
 		unset($invalid_data);
+
 	}
 	else
@@ -111,6 +95,6 @@
 		{
 			$GLOBALS['phpgw']->log->commit();
-		}
-		$GLOBALS['phpgw']->redirect_link('/mobile/home.php');
+		}		
+		start_prefered_app();
 	}
 
Index: /trunk/mobile/mobile_header.inc.php
===================================================================
--- /trunk/mobile/mobile_header.inc.php	(revision 517)
+++ /trunk/mobile/mobile_header.inc.php	(revision 623)
@@ -16,6 +16,6 @@
 	//TODO: Ler do banco do expresso as preferências do usuário e definir a aplicação móvel padrão
 	// por enquanto isto será hardcoded para mobilemail.
-	$GLOBALS['phpgw_info']['user']['preferences']['common']['default_mobile_app'] = 'mobilemail';
-	//TODO: Fazer mais genérico... Parecido com o home.php do expresso.
+	$GLOBALS['phpgw_info']['flags']['currentapp'] = 'mobile';
+	$GLOBALS['phpgw_info']['user']['preferences']['common']['default_mobile_app'] = 'mobilemail'; // mobilecalendar, mobilecc ou mobilemail
 
 	/*
@@ -25,183 +25,19 @@
 	 */
 	function start_prefered_app(){
-
-		//TODO: Determinar qual a aplicação móvel preferida e iniciá-la.
-		//TODO: Costruir agenda como uma classe.
-
-		if ($GLOBALS['phpgw_info']['flags']['currentapp'] === 'mobile'){
-			$GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/'
-				. $GLOBALS['phpgw_info']['flags']['currentapp'] . '/'
-				. $GLOBALS['phpgw_info']['user']['preferences']['common']['default_mobile_app'] . '_'
-				. 'index.php'));
-		}
-
-	}
-
-	// Não será necessário implementar nada aqui
-	function print_navbar(){
-
-	}
-
-	/*
-	 * @function print_header
-	 * @abstract Imprime o início da tela do Expresso Mini, headers html e a barra de navegação
-	 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
-	 */
-	function print_header(){
-
-		$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
-		$p->set_file(
-				Array(
-					'home_t' => 'home.tpl'
-				)
-		);
-
-		$p->set_block('home_t', 'mobile_header');
-		$p->set_block('home_t', 'mobile_navbar');
-		$GLOBALS['phpgw']->accounts->read_repository();
-
-		$var  = Array(
-			'fullname'	=> $GLOBALS['phpgw']->accounts->data['fullname'],   //$GLOBALS['phpgw_info']['user']['firstname'],
-			//'last_name'		=> $GLOBALS['phpgw']->accounts->data['last_name'], //$GLOBALS['phpgw_info']['user']['lastname'],
-			'account_lid'	=> $GLOBALS['phpgw_info']['user']['account_lid'],
-			'lang_logout'	=> lang('Logout'),
-			'template_set'	=> $GLOBALS['phpgw_info']['server']['template_set']
-		);
-
-		$p->set_var($var);
-		$p->parse('home_t', 'mobile_header');
-
-		/********************************\
-		 * Cria o link para o new_mail  *
-		\********************************/
-		$q = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
-		$q->set_file(
-				Array(
-					'new_mail_t' => 'home.tpl'
-				)
-		);
-
-		$q->set_block('new_mail_t', 'new_mail');
-		$q->set_block('new_mail_t', 'begin_anchor');
-		$q->set_block('new_mail_t', 'end_anchor');
-
-		$q->set_var('href', 'index.php?menuaction=mobile.mobilemail.new_msg&clk=01');
-		$q->set_var('lang_newmail', lang('Create mail'));
-		$q->fp('new_mail_t', 'begin_anchor');
-		$q->fp('new_mail_t', 'end_anchor');
-
-		$p->set_var('newmail', trim($q->fp('new_mail_t', 'new_mail')));
-
-		/********************************\
-		 * Cria o link para o mobilemail *
-		\********************************/
-		$q = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
-		$q->set_file(
-				Array(
-					'mobilemail_t' => 'home.tpl'
-				)
-		);
-
-		$q->set_block('mobilemail_t', 'mobilemail');
-		$q->set_block('mobilemail_t', 'begin_anchor');
-		$q->set_block('mobilemail_t', 'end_anchor');
-
-		$q->set_var('href', 'mobilemail_index.php');
-		$q->set_var('lang_email', lang('E-mail'));
-		$q->fp('mobilemail_t', 'begin_anchor');
-		$q->fp('mobilemail_t', 'end_anchor');
-
-		$p->set_var('mobilemail', trim($q->fp('mobilemail_t', 'mobilemail')));
-
-		/*****************************\
-		 * Cria o link para a agenda *
-		\*****************************/
-		//TODO: Passar estes passos para um laço quando tivermos um modo de registrar aplicações mobile
-		$q = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
-		$q->set_file(
-				Array(
-					'agenda_t' => 'home.tpl'
-				)
-		);
-
-		$q->set_block('agenda_t', 'agenda');
-		$q->set_block('agenda_t', 'begin_anchor');
-		$q->set_block('agenda_t', 'end_anchor');
-
-		$q->set_var('href', 'calendar.php');
-		$q->set_var('lang_agenda', lang('Calendar'));
-		$q->fp('agenda_t', 'begin_anchor');
-		$q->fp('agenda_t', 'end_anchor');
-
-		$p->set_var('agenda', trim($q->fp('agenda_t', 'agenda')));
-
-		/********************************\
-		 * Cria o link para o mobilemail *
-		\********************************/
-/*		$q = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
-		$q->set_file(
-				Array(
-					'mobilemail_t' => 'home.tpl'
-				)
-		);
-
-		$q->set_block('mobilemail_t', 'mobilemail');
-		$q->set_block('mobilemail_t', 'begin_anchor');
-		$q->set_block('mobilemail_t', 'end_anchor');
-
-		$q->set_var('href', 'mobilemail_index.php');
-		$q->set_var('lang_email', lang('E-mail'));
-		$q->fp('mobilemail_t', 'begin_anchor');
-		$q->fp('mobilemail_t', 'end_anchor');
-
-		$p->set_var('mobilemail', trim($q->fp('mobilemail_t', 'mobilemail')));
-*/
-
-		/********************************\
-		 * Cria o link para o cc	 *
- 		\********************************/
-		$q = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
-		$q->set_file(
-			Array(
-				'cc_t' => 'home.tpl'
-			)
-		);
-
-		$q->set_block('cc_t', 'mobilecc');
-		$q->set_block('cc_t', 'begin_anchor');
-		$q->set_block('cc_t', 'end_anchor');
-		
-		$q->set_var('href', 'index.php?menuaction=mobile.ui_mobilecc.contacts_list');
-		$q->set_var('lang_cc', lang('Contact Center'));
-		$q->fp('cc_t', 'begin_anchor');
-		$q->fp('cc_t', 'end_anchor');
-		
-		$p->set_var('contactcenter', trim($q->fp('cc_t', 'mobilecc')));
-
-		/**************************************\
-		 * Termina de formar o menu e imprime *
-		\**************************************/
-		$p->parse('home_t', 'mobile_navbar', true);
-		$p->pfp('out', 'home_t');
-
-	}
-
-	/*
-	 * @function print_footer
-	 * @abstract Imprime o fim da tela do Expresso Mini, ou seja, fecha as tags <body> e <html>
-	 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
-	 */
-	function print_footer(){
-
-		$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
-		$p->set_file(
-				Array(
-					'home_t' => 'home.tpl'
-				)
-		);
-
-		$p->set_block('home_t', 'mobile_footer');
-		$p->pfp('out', 'mobile_footer');
-
+		//TODO: Determinar qual a aplicação móvel preferida e iniciá-la.			
+		switch($GLOBALS['phpgw_info']['user']['preferences']['common']['default_mobile_app']){
+			case mobilemail:
+				$link = "ui_mobilemail.mail_list";		
+				break;
+			case mobilecalendar:
+				$link = "ui_mobilecalendar.index";
+				break;
+			case mobilecc:
+				$link = "ui_mobilecc.contacts_list";
+				break;		
+			default:
+				break;		
+		}		
+		$GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link("index.php?menuaction=mobile.".$link));
 	}
 ?>
Index: /trunk/mobile/login.php
===================================================================
--- /trunk/mobile/login.php	(revision 588)
+++ /trunk/mobile/login.php	(revision 623)
@@ -11,12 +11,12 @@
 		'noheader'               => True
 	);
-
-	include('../header.inc.php');
+	
+	include('../header.inc.php');	
+	include('./mobile_header.inc.php');	
 	$GLOBALS['sessionid'] = @$_GET['sessionid'] ? $_GET['sessionid'] : @$_COOKIE['sessionid'];
+	
 	if(isset($GLOBALS['sessionid']) && $_GET['cd'] != 10 && $_GET['cd'] != 1)
-		//$GLOBALS['phpgw']->redirect_link($GLOBALS['phpgw_info']['flags']['currentdir'].'/calendar.php');
-		//session_start();
-		$GLOBALS['phpgw']->redirect_link($GLOBALS['phpgw_info']['flags']['currentdir'].'/home.php');
-	if ($GLOBALS['phpgw_info']['server']['use_https'] > 0)	{
+		start_prefered_app();		
+		if ($GLOBALS['phpgw_info']['server']['use_https'] > 0)	{
 		if ($_SERVER['HTTPS'] != 'on') {
    			Header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
@@ -24,13 +24,12 @@
 		}
 	}
-
-	$GLOBALS['phpgw']->session = CreateObject('phpgwapi.sessions');
-	//$GLOBALS['phpgw_info']['server']['template_dir'] = PHPGW_SERVER_ROOT.$GLOBALS['phpgw_info']['flags']['currentdir'].'/templates/'.$GLOBALS['phpgw_info']['login_template_set'];
-	$GLOBALS['phpgw_info']['server']['template_dir'] = PHPGW_SERVER_ROOT.$GLOBALS['phpgw_info']['flags']['currentdir'].'/templates/';
+	
+	$GLOBALS['phpgw']->session = CreateObject('phpgwapi.sessions');	
+	$GLOBALS['phpgw_info']['server']['template_dir'] = PHPGW_SERVER_ROOT.$GLOBALS['phpgw_info']['flags']['currentdir'].'/templates/'.$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'];	
 	$tmpl = CreateObject('phpgwapi.Template', $GLOBALS['phpgw_info']['server']['template_dir']);
 	$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'] = $GLOBALS['phpgw_info']['login_template_set'];
 	$tmpl->set_file(array('login_form' => 'login.tpl'));
 	$tmpl->set_var('cd',check_logoutcode($_GET['cd']));
-
+	
 	function check_logoutcode($code) {
 		switch($code) {
@@ -96,7 +95,6 @@
 			$GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] .$GLOBALS['phpgw_info']['flags']['currentdir'].'/login.php?cd=' . $GLOBALS['phpgw']->session->cd_reason);
 		}
-		else{
-			//$GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] .$GLOBALS['phpgw_info']['flags']['currentdir'].'/calendar.php');
-			$GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] .$GLOBALS['phpgw_info']['flags']['currentdir'].'/home.php');
+		else{		
+			start_prefered_app();
 		}
 	}
@@ -117,6 +115,5 @@
 	$tmpl->set_var('lang_username',"Usuário");
 	$tmpl->set_var('lang_password',"Senha");
-	$tmpl->set_var('lang_login',"Login");
-	
+	$tmpl->set_var('lang_login',"Login");	
 	$tmpl->set_var('website_title', $GLOBALS['phpgw_info']['server']['site_title']);
 	$tmpl->set_var('template_set',$GLOBALS['phpgw_info']['login_template_set']);
@@ -126,5 +123,5 @@
 	$tmpl->pfp('loginout','login_form');
 
-	function logout(){
+	function logout(){		
 		$verified = $GLOBALS['phpgw']->session->verify();
 		if ($verified)
Index: /trunk/mobile/templates/default/home.tpl
===================================================================
--- /trunk/mobile/templates/default/home.tpl	(revision 524)
+++ /trunk/mobile/templates/default/home.tpl	(revision 623)
@@ -1,55 +1,27 @@
-<!-- BEGIN mobile_header -->
+<!-- BEGIN mobile_home -->
 <html>
 <head>
-<meta http-equiv="Content-Language" content="en" />
+<meta http-equiv="Content-Language" content="pt-BR" />
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
-<!-- <LINK href="../phpgwapi/templates/{template_set}/css/{template_set}.css" type=text/css rel=StyleSheet> -->
 <LINK href="./templates/css/mobile.css" type=text/css rel=StyleSheet>
 <title>Expresso Mobile {lang_home}</title>
 </head>
 <body style="background-color:white !important">
+<!-- BEGIN mobile_home_content -->
+{content}<br>{footer}
+<!-- END mobile_home_content -->
 <p>&nbsp;&nbsp;<strong>{fullname}: [{account_lid}]</strong></p>
 <hr />
-<!-- END mobile_header -->
-
-<!-- BEGIN mobile_navbar -->
 <!-- TODO: Yep! Deveria ser flexível, não hardcoded do jeito que tá -->
 <!--<p>&nbsp;&nbsp;<strong>:: Expresso Mini</strong> </p>-->
 <p>
-:: {newmail} <br>
-:: {mobilemail} <br>
-:: {agenda} <br>
-:: {contactcenter} <br>
+:: <a href="{href_newmail}">{lang_newmail}</a> <br>
+:: <a href="{href_email}">{lang_email}</a> <br>
+:: <a href="{href_calendar}">{lang_calendar}</a> <br>
+:: <a href="{href_cc}">{lang_cc}</a> <br>
 :: <a href="./login.php?cd=1">{lang_logout}</a>
 </p>
 <hr />
-<!-- END mobile_navbar -->
-
-<!-- BEGIN new_mail -->
-{begin_anchor}{lang_newmail}{end_anchor}
-<!-- END new_mail -->
-
-<!-- BEGIN agenda -->
-{begin_anchor}{lang_agenda}{end_anchor}
-<!-- END agenda -->
-
-<!-- BEGIN mobilemail -->
-{begin_anchor}{lang_email}{end_anchor}
-<!-- END mobilemail -->
-
-<!-- BEGIN mobilecc -->
-{begin_anchor}{lang_cc}{end_anchor}
-<!-- END mobilecc -->
-
-<!-- BEGIN begin_anchor -->
-<a href="{href}">
-<!-- END begin_anchor -->
-
-<!-- BEGIN end_anchor -->
-</a>
-<!-- END end_anchor -->
-
-<!-- BEGIN mobile_footer -->
 </body>
 </html>
-<!-- END mobile_footer -->
+<!-- END mobile_home -->
Index: /trunk/mobile/templates/default/mobilemail.tpl
===================================================================
--- /trunk/mobile/templates/default/mobilemail.tpl	(revision 534)
+++ /trunk/mobile/templates/default/mobilemail.tpl	(revision 623)
@@ -24,5 +24,5 @@
 
 <!-- BEGIN mail_row -->
-<p style="background-color: {unseen_bkg}">&nbsp;&nbsp;<strong>{from_label}</strong>:  {strong_unseen_begin}<a href="index.php?menuaction=mobile.mobilemail.show_msg&msg_number={msg_number}&msg_folder={msg_folder}">{from}<br>
+<p style="background-color: {unseen_bkg}">&nbsp;&nbsp;<strong>{from_label}</strong>:  {strong_unseen_begin}<a href="index.php?menuaction=mobile.ui_mobilemail.show_msg&msg_number={msg_number}&msg_folder={msg_folder}">{from}<br>
 &nbsp;&nbsp;&nbsp;&nbsp;{subject} - {date}</a>{strong_unseen_end}</p>
 <!-- END mail_row -->
Index: /trunk/mobile/templates/css/mobile.css
===================================================================
--- /trunk/mobile/templates/css/mobile.css	(revision 612)
+++ /trunk/mobile/templates/css/mobile.css	(revision 623)
@@ -47,8 +47,4 @@
 	font-family: Arial, Helvetica, sans-serif !important;
 	border: 1px #000066 solid !important;
-}
-input:focus, textarea:focus
-{
-        background-color: #F1F8FF;
 }
 
Index: /trunk/mobile/templates/celepar/home.tpl
===================================================================
--- /trunk/mobile/templates/celepar/home.tpl	(revision 623)
+++ /trunk/mobile/templates/celepar/home.tpl	(revision 623)
@@ -0,0 +1,23 @@
+<!-- BEGIN mobile_home -->
+<html>
+<head>
+<meta http-equiv="Content-Language" content="pt-BR" />
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
+<LINK href="./templates/css/mobile.css" type=text/css rel=StyleSheet>
+<title>Expresso Mobile {lang_home}</title>
+{js_lang}
+</head>
+<body style="background-color:white !important">
+<p>&nbsp;&nbsp;<strong>{fullname}: [{account_lid}]</strong></p>
+<hr />
+<p>
+<a href="{href_newmail}">{lang_newmail}</a>:<a href="{href_email}">{lang_email}</a>
+:<a href="{href_calendar}">{lang_calendar}</a>
+:<a href="{href_cc}">{lang_cc}</a>
+:<a href="./login.php?cd=1">{lang_logout}</a>
+</p>
+<hr />
+{content}<br>{footer}
+</body>
+</html>
+<!-- END mobile_home -->
