<?php
class MobileController extends AppController
{
	
	var $name = 'Mobile';
	 
	var $helpers = array('Html', 'Form');
	public $components = array('MobileDetect'); 
	
 
	public function beforeRender() {
		parent::beforeRender();
	 
		$this->layout = 'mobile';
		if($this->Session->check("homecontroller_layout")){
			//$this->layout = '';
			$this->Session->delete("homecontroller_layout");
			
		}
		
	}
	
	
	function index()
	{
	 	$uniqueURL = $this->Session->read("current_unique_url"); 
	 //	echo $uniqueURL;exit;
	 
	 	$expenseType = trim(substr($uniqueURL, 0, 1));
	 	$this->set("expenseType",$expenseType);
	 	
	 	if($expenseType == "6" || $expenseType == "7" || $expenseType == "8"){
	 		$this->loadWeb($uniqueURL);
	 	} else {
		 	$detect = new MobileDetectComponent();
		 	
		 	if ($detect->isAndroid()) {
		 		$this->set("device","android");
		 	} else if($detect->isIphone()){
		 		$this->set("device","iphone");
		 	} else if($detect->isWindows()){
		 		$this->set("device","windows");
		 	} else {
		 		$this->set("device","pc");
		 	}
		 	
		 	$this->set("unique_url",$uniqueURL);
	 	
	 	}
	 	
	 	//get user's OS and show relevant page
	 //	allplayer://expensecount.com/unique_url
	}
	
	public function loadWeb($unique_url){
		
		$this->Session->write("skip_mobile_option","yes");
		
		if(empty($unique_url)){
			$this->redirect(array('controller'=> 'Home','action'=> 'index'));
			exit;
		}
		
		 $this->redirect(array('controller'=> $unique_url));
		 exit;
		
	}
	
	
}
?>