Index: branches/2.2/mobile/inc/class.ui_mobilemail.inc.php
===================================================================
--- branches/2.2/mobile/inc/class.ui_mobilemail.inc.php	(revision 3576)
+++ branches/2.2/mobile/inc/class.ui_mobilemail.inc.php	(revision 3579)
@@ -34,5 +34,6 @@
 			'list_folders' => true,
 			'save_draft' => true,
-			'mark_message_with_flag' => true
+			'mark_message_with_flag' => true,
+			'change_search_box_type' => true
 		);
 
@@ -40,4 +41,5 @@
 		var $common;
 		var $folders; // Pastas imap
+		var $current_search_box_type;
 		var $current_folder; // Pasta corrente
 		var $current_page; // Página corrente da lista de e-mails da pasta corrente
@@ -62,5 +64,6 @@
 			$current_folder = $GLOBALS['phpgw']->session->appsession('mobilemail.current_folder','mobile');
 			$current_page = $GLOBALS['phpgw']->session->appsession('mobilemail.current_page','mobile');
-
+			$current_search_box_type = $GLOBALS['phpgw']->session->appsession('mobilemail.current_search_box_type','mobile');
+			
 			// Inicializa a classe class.imap_functions.inc.php
 			$this->imap_functions = new imap_functions();
@@ -93,4 +96,12 @@
 			{
 				$this->current_page = 1; // Define a primeira página como página padrão
+			}
+			
+			if($current_search_box_type) 
+			{
+				$this->current_search_box_type = $current_search_box_type;
+			}
+			else {
+				$this->current_search_box_type = "all";
 			}
 
@@ -107,4 +118,5 @@
 			$GLOBALS['phpgw']->session->appsession('mobilemail.current_folder','mobile',$this->current_folder);
 			$GLOBALS['phpgw']->session->appsession('mobilemail.current_page','mobile',$this->current_page);
+			$GLOBALS['phpgw']->session->appsession('mobilemail.current_search_box_type','mobile',$this->current_search_box_type);
 		}
 
@@ -114,9 +126,19 @@
 		 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
 		 */
-		function change_page()
-		{
-			if (isset($_GET['page']))
-			{
-				$this->current_page = $_GET['page'];
+		function change_page($params)
+		{
+			if (isset($params['page']))
+			{
+				$this->current_page = $params['page'];
+			}
+			$this->mail_list();
+			$this->save_session();
+		}
+
+		function change_search_box_type($params) {
+			if (isset($params['search_box_type']))
+			{
+				$this->current_search_box_type = $params['search_box_type'];
+				$this->current_page = 1;
 			}
 			$this->mail_list();
@@ -136,8 +158,10 @@
 				$this->current_folder = $folder;
 				$this->current_page = 1;
-			}
-			
+				$this->current_search_box_type = "all";
+			}
+			
+				
 			$GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params["error_message"]);
-			$this->mail_list($params);
+			$this->mail_list();
 			$this->save_session();
 		}
@@ -366,48 +390,47 @@
 		 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
 		 */
-		function mail_list($params)
+		function mail_list()
 		{	
-		
-			if($params['folder']){
-				$this->current_folder = $params['folder'];
-			}else{
-				$this->current_folder = 0;
-			}
-			$this->print_folder_selection();
-			$this->messages_per_page = 
+				
+			$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
+			$p->set_file(
+				Array(
+					'mail_t' => 'mobilemail.tpl'
+				)
+			);
+			$p->set_var("page",$this->current_page+1);
+			$p->set_var("folder",$this->folders[$this->current_folder]['folder_name']);
+			$p->set_var("selected_".$this->current_search_box_type,"selected");
+			$p->set_var("lang_back",lang("back"));
+			$p->set_var("lang_new_message",lang("new message"));
+			$p->set_var("lang_search_message",lang("search message"));
+			$p->set_var("lang_more",lang("more"));
+			$p->set_var("lang_messages",lang("messages"));
+			
+			$max_per_page = 
 					isset($GLOBALS['phpgw_info']['user']['preferences']['mobile']['max_message_per_page'])?
 					$GLOBALS['phpgw_info']['user']['preferences']['mobile']['max_message_per_page']:10; 
-
-			if (!isset($this->number_of_messages))
-			{
-				$params_num_msg = array(
-					'folder' => $this->folders[$this->current_folder]['folder_id'],
-				);
-				$this->number_of_messages = $this->imap_functions->get_num_msgs($params_num_msg);
-			}
-
-			// Recalcular as páginas
-			$this->pages = ceil($this->number_of_messages/$this->messages_per_page);
-			$page = $this->current_page;
-			
-			if($_POST["searchEmail"]){
-				$params_mobile_search = array(
-					'filter' 	=> $_POST["searchEmail"]
-					);
-
-				$messages = $this->imap_functions->mobile_search($params_mobile_search);
-			}else{
-				$params_get_range_msgs = 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_get_range_msgs);
-			}
-			$this->print_mails_list($messages);
-			$this->print_page_navigation($this->pages, $this->current_page);
+						
+			$params = array(
+				'folder' 			=> $this->folders[$this->current_folder]['folder_id'],
+				'msg_range_begin' 	=> 1,
+				'msg_range_end'		=> $this->current_page * $max_per_page,
+				'search_box_type'	=> $this->current_search_box_type,
+				'sort_box_type'		=> 'SORTARRIVAL',
+				'sort_box_reverse'	=> 1
+			);
+			
+			$messages = $this->imap_functions->get_range_msgs2($params);
+//			print_r($messages);
+			$this->number_of_messages = $messages[num_msgs];
+			
+			unset($messages["offsetToGMT"]);
+			unset($messages["tot_unseen"]);
+			
+			$p->set_var('mails',$this->print_mails_list($messages,true));
+			
+			$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out','mail_t'));
+			
+
 		}
 
@@ -418,5 +441,5 @@
 		 * @param array Um array com a lista de mensagens recuperado por $this->imap_functions->get_range_msgs2($params)
 		 */
-		function print_mails_list($messages)
+		function print_mails_list($messages,$print_checkbox=false)
 		{
 			
@@ -444,5 +467,26 @@
 						$from_name = $functions->strach_string($message['from']['email'],20);
 					
-					$p->set_var('bg',$bg=="par"?$bg="reset-dt":$bg="par");							
+					$p->set_var('bg',$bg=="par"?$bg="reset-dt":$bg="par");
+					
+					$pre = " ";
+					$pos = " ";
+					
+					if($message["Unseen"]==="U") {
+						$pre.="<b>";
+						$pos.="</b>";
+					}
+					
+					if($message["Flagged"]==="F") {
+						$pre.= "<font color='#FF0000'>";
+						$pos = "</font>".$pos;
+					}
+					
+					if($print_checkbox)
+						$p->set_var('show_check','inline');
+					else
+						$p->set_var('show_check','none');
+					
+					$p->set_var('pre_type',$pre);
+					$p->set_var('pos_type',$pos);
 					$p->set_var('from',$from_name);
 					$p->set_var('mail_time',$message['smalldate']);
@@ -471,4 +515,71 @@
 			}
 			return $p->fp('out','rows_mails');
+/*
+			// Cria a lista de e-mails
+			$mail_rows = '';
+      $unread_msg_count = 0;
+      
+			if ($this->number_of_messages != 0)
+			{
+				$unread_msg_count = 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', "seen_bkg");
+					$p->set_var('itememail_access_key', "0");
+					$p->set_var('str_new_message', "");
+
+					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', "unseen_bkg");
+							$p->set_var('itememail_access_key', "9");
+							$unread_msg_count = $unread_msg_count + 1;
+							$p->set_var('str_new_message', lang("New message"));
+						}
+						$p->set_var('from', $from);
+						$p->set_var('subject', $subject);
+						$p->set_var('msg_number', $msg['msg_number']);
+						$p->set_var('date', $msg['smalldate']);
+						$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->set_var('messages_total', $this->number_of_messages);
+				$p->set_var('unread_messages_total', $unread_msg_count);
+				if ($unread_msg_count)
+				{
+					$p->set_var('(unread_messages_total)', '('.$unread_msg_count.')');
+				}
+				
+				//$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'));
+			}*/
 		}
 
@@ -841,5 +952,5 @@
 		}
 
-		function delete_msg()
+		function delete_msg($params)
 		{
 			if (isset($_GET['msg_number']))
