<?php
	// get user data
	// Option 1
	//require_once 'external/php-md/Mobile_Detect.php';
    //$detect = new Mobile_Detect;
    //$l_deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : $detect->{'isiPhone'}() ? 'iPhone' : 'phone') : 'computer');
	//$l_isMobile = $detect->isMobile();
	
	// Option 2
	$browser = get_browser(null, true);
	$l_isMobile = $browser['ismobiledevice'];
	$l_deviceType = ($l_isMobile ? 'phone' : 'computer');
	$l_os = $browser['platform'];
	$l_browser = $browser['parent'];
	
	// where did the user come from - record for our record... unreliable info from user agent
	$l_sReferer = "";
	if(isset($_POST['referer'])) {
		$l_sReferer = trim($_POST['referer']);
	} elseif (isset($_SERVER['HTTP_REFERER'])) {
		$l_sReferer = base64_encode($_SERVER['HTTP_REFERER']);
	} else {
		$l_sReferer = "";
	}

	$l_ip = ""; 
	if ( isset($_SERVER["REMOTE_ADDR"]) )    { 
		$l_ip = $_SERVER["REMOTE_ADDR"]; 
	} else if ( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) )    { 
		$l_ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; 
	} else if ( isset($_SERVER["HTTP_CLIENT_IP"]) )    { 
		$l_ip = $_SERVER["HTTP_CLIENT_IP"]; 
	} 	
	     	
	// invalidate the session
	if(!isset($_SESSION)) 
	{ 
		session_start(); 
	}
	session_unset();
	session_destroy();
	session_start();
	session_regenerate_id();
	
	// let's insert the session id into the database
	include 'common/utilities.php';
	include 'common/dbaccess.php';
	connectDB();
	$dbreturn = mysql_insert($us_database, 'sessions', array(
				'session_id' => session_id(),
				'user_agent' => $_SERVER['HTTP_USER_AGENT'],
				'referer' => $l_sReferer,
				'ismobile' => $l_isMobile,
				'device_type' => $l_deviceType,
				'ip' => $l_ip,
				'os' => $l_os,
				'browser' => $l_browser
			));
			
	disconnDB();
	if(!$dbreturn) {
		echo "\r\nerror: failed to insert result for session_id " . session_id() . 
			" error: " . mysql_error();
	}
	
	// Now see which site do we want to go
	if($l_isMobile)
	{
		//header( 'Location: http://cns.eecs.ucf.edu/projects/ocaptcha/m/sortable.html' ) ;
		//header( 'Location: http://localhost/projects/ocaptcha/m/sortable.html' ) ;
		header( 'Location: m/index.php' ) ;
		exit();
	}
	
	// Include the common header
	include "header.php"
?>
<body onLoad="SetFocus();">
<form name="form1" method="post" action="main.php" id="form1">
<p><h2>Welcome to the logiCAPTCHA User Experience Test</h2></p>
<hr></hr>
<br>
<table cellpadding="0">
  <tr align="left">
    <td colspan="3" width="800">
      <span id="msg">
	  logiCAPTCHA is an image-based test used to distinguish a human user from a computer. 
	  logiCAPTCHA presents users with a set of images, which they are asked to arrange based on a characteristic such as speed or size.
	  logiCAPTCHA utilizes drag-and-drop and is more user friendly than traditional text-based CAPTCHAs. 
	  In light of the growing prevalence of mobile and touch controlled platforms, the value of a product like logiCAPTCHA is increasingly apparent.
	  <br><br>
      </span>
    </td>
  </tr>
  <tr>
  <td bordercolor="white" width="30"></td>
  <td align="center" class="style1" valign="top">
  <frame bordercolor="blue" frameborder="2">
    <!-- Flash movie tag--> 
	<center><OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" WIDTH="585" HEIGHT="397" CODEBASE="http://active.macromedia.com/flash5/cabs/swflash.cab#version=7,0,0,0">
		<PARAM NAME=movie VALUE="video/example3.swf">
		<PARAM NAME=play VALUE=true>
		<PARAM NAME=loop VALUE=false>
		<PARAM NAME=wmode VALUE=transparent>
		<PARAM NAME=quality VALUE=low>
		<EMBED SRC="video/example3.swf" WIDTH=585 HEIGHT=397 quality=low loop=false wmode=transparent TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
		</EMBED>
	</OBJECT></center>
	</frame>
  </td>
  <td bordercolor="white" width="30"></td>
  </tr>
  <tr>
    <td colspan="3">
	  <br>You are helping to evaluate the "user experience" of logiCAPTCHA by: <br>
	  1. Complete 5 logiCAPTCHA challenges<br>
	  2. Complete 2 traditional CAPTCHA challenges<br>
	  3. Fill out a short survey <br><br>
	</td>
  </tr>	
  </table>
    <input type="submit" name="btnSubmit" value="Start Now" id="btnSubmit" />
	<script type="text/javascript">
		//<![CDATA[
		function SetFocus()
		{
			document.form1.btnSubmit.focus();
		}
		//]]>
	</script>
  </form>
  <br><br><p><small><a href="m/index.php"> Mobile Version </a></small></p>
</body>

<?php
  include "footer.php";
?>
