Index: /trunk/mobile/login.php
===================================================================
--- /trunk/mobile/login.php	(revision 3892)
+++ /trunk/mobile/login.php	(revision 4129)
@@ -12,9 +12,9 @@
 		'noheader'               => True
 	);
-
+	
 	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)
 		start_prefered_app();
@@ -44,4 +44,22 @@
 	if(trim($cd) != "")
 		$tmpl->parse('message_box', (($_GET['cd'] == 1) ? 'success_message' : 'error_message') ,true);
+		//detect if the user has a mobile browser
+	
+	$browser = CreateObject('mobile.browser');
+	
+	switch ($browser->get_platform()) {
+		case browser::PLATFORM_IPHONE:
+		case browser::PLATFORM_IPOD:
+		case browser::PLATFORM_IPAD:
+		case browser::PLATFORM_BLACKBERRY:
+		case browser::PLATFORM_NOKIA:
+		case browser::PLATFORM_ANDROID:
+			$tmpl->set_var('os_browser',$browser->get_platform());				
+			break;
+		default:
+			$tmpl->set_var('os_browser',false);
+			//$tmpl->set_var('os_browser',$browser->get_platform());
+			break;
+	}
 
 	function check_logoutcode($code) {
@@ -50,8 +68,11 @@
 				logout();
 				return lang('You have been successfully logged out');
+
 			case 2:
 				return lang('Sorry, your login has expired');
+
 			case 4:
 				return lang('Cookies are required to login to this site.');
+
 			case 5:
 				return lang('Bad login or password');
@@ -81,4 +102,19 @@
 		$passwd_type = 'text';
 	}
+	// Automatic login from browser cookies
+	elseif(get_var('lem',array('GET','COOKIE')) && get_var('pem',array('GET','COOKIE')))
+	{
+		if(!$_GET['cd'] || $_GET['cd'] == '1' || $_GET['cd'] == '10') { 
+			$submit = True;
+			$login  = base64_decode(get_var('lem',array('GET','COOKIE')));
+			$passwd = base64_decode(get_var('pem',array('GET','COOKIE')));
+			$passwd_type = 'text';
+		}
+		else {
+			$GLOBALS['phpgw']->session->phpgw_setcookie('lem');
+			$GLOBALS['phpgw']->session->phpgw_setcookie('pem');
+		}
+	}
+	
 	else {
 		$passwd = $_POST['passwd'];
@@ -86,12 +122,16 @@
 	}
 
-	if(isset($passwd_type) || $_POST['submitit_x'] || $_POST['submitit_y'] || $submit) {
-		if(getenv('REQUEST_METHOD') != 'POST' && $_SERVER['REQUEST_METHOD'] != 'POST' &&
-			!isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['SSL_CLIENT_S_DN'])){
+	if(isset($passwd_type) || $_POST['submitit_x'] || $_POST['submitit_y'] || $submit)
+	{
+		if( !get_var('pem',array('GET','COOKIE')) && getenv('REQUEST_METHOD') != 'POST' 
+			&& $_SERVER['REQUEST_METHOD'] != 'POST' && !isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['SSL_CLIENT_S_DN']))
+		{
 			$GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link($GLOBALS['phpgw_info']['flags']['currentdir'].'/login.php','cd=5'));
 		}
 
 		if(!$submit)
+		{
 			$login = $_POST['login'];
+		}
 
 		$GLOBALS['sessionid'] = $GLOBALS['phpgw']->session->create(strtolower($login),$passwd,$passwd_type,'u');
@@ -100,9 +140,13 @@
 			$GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] .$GLOBALS['phpgw_info']['flags']['currentdir'].'/login.php?cd=' . $GLOBALS['phpgw']->session->cd_reason);
 		}
-		else {
-			if(isset($_POST['max_resolution']) && $_POST['max_resolution'] > 600) {
+		else
+		{
+			if(isset($_POST['max_resolution']) && $_POST['max_resolution'] > 600)
+			{
 				$GLOBALS['phpgw_info']['user']['preferences']['common']['default_mobile_app'] = 'mobilemail';
 				$GLOBALS['phpgw']->session->appsession('mobile.layout','mobile','mini_desktop');
-			} else {
+			}
+			else
+			{
 				$GLOBALS['phpgw']->session->appsession('mobile.layout','mobile','mini_mobile');
 			}
@@ -111,4 +155,11 @@
 			$_SESSION['phpgw_info']['user']['preferences']['expressoMail'] = $preferences['expressoMail'];
 			
+			if($_POST['save_login'] == 'yes')
+			{
+				// Time to keep values into cookies
+				$ttl = time()+15552000; // Six Months
+				$GLOBALS['phpgw']->session->phpgw_setcookie('lem', base64_encode(strtolower($login)),$ttl); // lem = login
+				$GLOBALS['phpgw']->session->phpgw_setcookie('pem', base64_encode($passwd), $ttl);			// pem = password
+			}
 			start_prefered_app();
 		}
@@ -135,5 +186,6 @@
 	$tmpl->pfp('loginout','page');
 
-	function logout(){
+	function logout()
+	{
 		$verified = $GLOBALS['phpgw']->session->verify();
 		if ($verified)
