<?php
	session_start();	
	include_once("../../config/config.php");
	ini_set("display_errors","1");
	//echo "<pre>";
	//print_r($_REQUEST);
	//print_r($_SESSION);
	//exit;
	//echo IMAGE_PATH_HTTP;exit;
	
	//page name
	$page='result_pdf_controller.php';
	
	//Including Classes
	$AddClass = array('Reuse','user','usertype','users_tests','user_info','cms_test','test','user_deficiency_tests');
	include(CONFIG_CLASS_PATH."class.php");
	
	
	
	//Get the respective data of selected user
	$step 	 = trim($_REQUEST['step']);
	$userid = trim($_REQUEST['utest_id']);//73;
	$main_test_rec_id 	 = trim($_REQUEST['main_test_rec_id']);
	
		 
	
	if($step!="")
	{
		switch($step)
		{
											
	case 'CreatePDF': 
		$redirect_to = FOLDER_PATH_HTTP."index.php";
		$re->redirectPage($redirect_to);
	break;
	case 'CreatePDFfile': 
	
	$cert_name = "tcv_certificate.pdf";
		if(isset($_REQUEST['hash']))
		{
			//echo $_REQUEST['hash'];
			$sttrhash = str_replace(" ","+",$_REQUEST['hash']);
			//echo $userid;
			$dn = decode1($sttrhash);
			if($userid != $dn)
			{
				$user_test_info = array();
				$_SESSION['Message'] = '132';
				$redirect_to = FOLDER_PATH_HTTP."index.php";
				$re->redirectPage($redirect_to);
				die();
			}
			
		}else{
			$user_test_info = array();
			$_SESSION['Message'] = '132';
			$redirect_to = FOLDER_PATH_HTTP."index.php";
			$re->redirectPage($redirect_to);
			die();
		}
	
	
	try
	{
		$user_test_info = $users_tests_manager->getSingleUsersTests_To_Show_Result($userid);
		//$user_test_info = $users_tests_manager->getSingleUsersTests($userid);
		//print_r($user_test_info);exit;
		
		$test_where_clause = " cms_type = 'T' AND tcv_test.test_id = ".$user_test_info->getTestId();
		$test_details = $test_manager->getSingleTest($test_where_clause);
		//print_r($test_details);die();
		$test_rec_id = $user_test_info->getUserTestId();
		
		try
		{
			$whereclause = " WHERE user_test_id = ".$test_rec_id." AND tcv_cms_test.cms_type = 'T'  order by group_name desc";
			$user_deficiency_tests_details = $user_deficiency_tests_manager->getAllUserDeficiencyTests_To_Show_Result($whereclause);
		}
		catch(Exception $e)
		{
			$user_deficiency_tests_details = array();
		}
		
		
		$test_cer_img = ($test_details->getTestType() == "A")?"certificate_tcv-150.jpg" : "pediatric-certificate_tcv-150.jpg"; 
		//echo '<pre>';print_r($user_deficiency_tests_details);
		
			$fname = stripslashes($user_test_info->getFname());
			$lname = stripslashes($user_test_info->getLname());// "1234";
			$name = ucwords( htmlspecialchars(substr($fname,0,20)." ".substr($lname,0,20)));
			
			$identifire =  stripslashes(htmlspecialchars($user_test_info->getIdentifier()));
			
			$age =  stripslashes(htmlspecialchars($user_test_info->getAge()));
			
			$gender =  stripslashes(htmlspecialchars($user_test_info->getGender()));
				
			$eyetested =  stripslashes(htmlspecialchars($user_test_info->getEyeTested()));
			$getuserid =  stripslashes(htmlspecialchars($user_test_info->getUserId()));
				
			$testcondition =  stripslashes(htmlspecialchars($user_test_info->getTestCondition()));
			$othertext =  stripslashes(htmlspecialchars($user_test_info->getOtherText()));
			if($user_test_info->getIsOldData())
			{
				$fname = decode($fname);
				$lname = decode($lname);
				$name = ucwords( htmlspecialchars(substr($fname,0,20)." ".substr($lname,0,20)));
				$identifire = decode($identifire);
				$age = decode($age);
				$gender = decode($gender);
				$eyetested = decode($eyetested);
				$testcondition = trim(decode($testcondition));
				$othertext =  decode($othertext);
			}	
			if($testcondition == 'O'){
				
			}else{
				$othertext =  '';
			}
			if($testcondition == 'B')
				$testcondition = 'Bright Light';
			elseif($testcondition == 'L')
				$testcondition = 'Low Light';	
			else
				$testcondition = 'Other';	
			if($testcondition == '')
				$testcondition = '--';
			if($testcondition == 'Other')
				$testcondition = '';
			if($age <= 0)
				$age = '';
			if($age == '')
				$age = '--';
			if($gender == 'F')
				$gender = 'Female';
			elseif($gender == 'M')
				$gender = 'Male';
			if($gender == '')
				$gender = '--';		
			if($eyetested == '')
				$eyetested = '--';		
			if($identifire == '')
				$identifire = '--';			
			$getusertestid =  stripslashes(htmlspecialchars($user_test_info->getUserTestId()));	
			//GET USERNAME ADDED BY Mrunal M on 12 Oct 11 starts here//
			if(trim($name) == "")
			{
				$name = wordwrap(decode($user_test_info->getUserEmail()),39,'<br />',true);
				$label = "Email Address";	
			}
			else
				$label = "User Name";	
			//GET USERNAME ADDED BY Mrunal M on 12 Oct 11 ends here//
			
			$test_title = stripslashes(htmlspecialchars($test_details->getTitle()));
			
			$total_givenques = stripslashes(decode($user_test_info->getTotalGivenAnswers()));// 
			if($total_givenques <= 0){
				$total_givenques = stripslashes($user_test_info->getNoOfQuestions());// 
			}
			$total_ques = stripslashes($user_test_info->getNoOfQuestions());//
			$correct_ans = stripslashes($user_test_info->getCorrectAnswers());// 
			$correct_ans =  decode($correct_ans,$user_test_info->getIsOldData());
			$minscore = stripslashes($user_test_info->getMinScore());// 
			$score = $correct_ans."/".($total_givenques  - $user_test_info->getTotalDemoPlatesCnt());	//modified by Mrunal M 
			$score1 = $minscore."/".($total_ques  - $user_test_info->getTotalDemoPlatesCnt());	
			//$test_taken_date = date(DEFAULT_DATE_FORMAT,strtotime($user_test_info->getTestTakenDate()));
			
			/*$date_array = explode(" ",$user_test_info->getTestTakenDate());
			$test_date = $re->convertDate1($date_array[0]);
			$test_time = $date_array[1];
			$time_string = $test_time." on ".$test_date;*/
			
			$test_taken_date = $user_test_info->getTestTakenDate();
			$datetime = strtotime($test_taken_date);
			$time_string = date("m/d/y", $datetime);
			
			if($user_test_info->getPassed() == "1")
				
					$user_result = 'Passed';
					
					
				
				else
				
					$user_result = 'Failed';
				

			$correct_ans = "Pass";//($user_test_info->getPassed()=="1"? "Pass") 
			
			$str = ""; 
			
			try
					{
						$whereclause = " WHERE user_test_id = ".$test_rec_id." AND user_id = '".$getuserid."' AND tcv_cms_test.cms_type = 'T' AND test_taken ='1' order by group_name desc ";
						$user_deficiency_tests_details = $user_deficiency_tests_manager->getAllUserDeficiencyTests_To_Show_Result_withGroup($whereclause);
					}
					catch(Exception $e)
					{
						$user_deficiency_tests_details = array();
					}
					
					/*echo '<pre>';
					print_r($user_deficiency_tests_details);*/
					//die();
					
					
					
					if(!isset($user_deficiency_tests_details) || count($user_deficiency_tests_details) == 0)
					{
						$isset_def_test = false;
					}
					else	//DEFINE DEFICINCY ADDED ON 23 Sept 11
					{
						
		
		$lowest = 0;
		$def_array_ans = array();
		$lowest_score_deftest_id = array();
		$lowest_score = array();		
		$lowest_score_group =array();
		$tri_lowest_score_deftest_id=array();		
		$def_rec_Id = array();		
		
		$diagnosis = "";
		$diagnosisequal = "";
		foreach($user_deficiency_tests_details as $key => $user_d_test)
		{
			
			if($user_d_test->getPassed() != "Pass" && $user_d_test->getGroupId() != "4")
			{
				array_push($def_array_ans, decode($user_d_test->getCorrectAnswers(),$user_d_test->getIsOldData()));			
				array_push($def_rec_Id, $user_d_test->getUserDeftestId());
				$aProDue[] = array('key' => $key, 'correct_ans' => decode($user_d_test->getCorrectAnswers(),$user_d_test->getIsOldData()));
				//echo "1 <br/>";
			}
			else if($user_d_test->getGroupId() == "4" && $user_d_test->getPassed() != "Pass")
			{
				//echo "2 <br/>";
				array_push($tri_lowest_score_deftest_id, $user_d_test->getUserDeftestId());					
			}
			
				}
					
				$lowest = $def_array_ans[0];
				
				$k=1;
				
				for($i = 0; $i < count($def_array_ans); $i++)
				{				
					if($lowest > $def_array_ans[$i])
					{
						$lowest = $def_array_ans[$i];
						
						if(!(in_array($def_rec_Id[$i], $lowest_score_deftest_id)))
						{
						
						$lowest_score_deftest_id[$k-1] = $def_rec_Id[$i];
						$k++;
						}
					}
					else if($lowest == $def_array_ans[$i])
					{						
						if(!(in_array($def_rec_Id[$i], $lowest_score_deftest_id)))
						{
						$k++;
						$lowest_score_deftest_id[$k-1] = $def_rec_Id[$i];
						}
					}						
				}		
							
					}
					
					
			if(count($user_deficiency_tests_details) > 0)
			{
				
					$str = '';	 
				foreach($user_deficiency_tests_details as $ud_test)
				{
					
							
					$str .= '<tr>
						<td colspan="4">'.decode($ud_test->getCorrectAnswers(),$ud_test->getIsOldData()).'/'.($ud_test->getNoOfQuestions()  - $ud_test->getTotalDemoPlatesCnt()).'  ';
						
						if(decode($ud_test->getCorrectAnswers(),$ud_test->getIsOldData()) >= $ud_test->getMinScore())
								{
									$str .= ' Passed';
									
								}
								else
								{
									$str .= $ud_test->getPassed();
									
								} 
								$str .= '  <br><span style="font-size:14px;">'.
								$ud_test->getGroupName().' Section ('.$ud_test->getColorName().')</span></td>
					</tr>';		
				
				
				}
				if(isset($user_deficiency_tests_details) && count($user_deficiency_tests_details) > 0)
					{/*
						foreach($user_deficiency_tests_details as $ud_test)
						{							
							if(in_array($ud_test->getUserDeftestId(), $tri_lowest_score_deftest_id) || in_array($ud_test->getUserDeftestId(), $lowest_score_deftest_id))
							{
								if($diagnosis != "")
									$diagnosis .= " and ";	
								$diagnosis .= $ud_test->getPassed()." ".$ud_test->getGroupName(); 
							
								$result_message = $result_fail_message;
							}						
						}*/
						
						foreach($user_deficiency_tests_details as $ud_test)
						{
							
							if(in_array($ud_test->getUserDeftestId(), $tri_lowest_score_deftest_id) || in_array($ud_test->getUserDeftestId(), $lowest_score_deftest_id))
							{			
								if(($ud_test->getGroupName() != 'Protan') && ($ud_test->getGroupName() != 'Deutan')){
								if($diagnosis != "")
									$diagnosis .= " and ";	
								//$diagnosis .= " <a style='text-decoration:underline; !important' href=".'"'.FOLDER_PATH_HTTP.$ud_test->getPageLink().'"> '.$ud_test->getPassed()." ".$ud_test->getGroupName().'</a> '; 
								 $diagnosis .= $ud_test->getPassed()." ".$ud_test->getGroupName(); 
								
							}
							$result_message = $result_fail_message;
				
								# Code Added by Raj
								//echo $ud_test->getGroupId();
								//echo "<pre>"; print_r($user_deficiency_tests_details);exit;
								if($ud_test->getGroupId() != 4)
								{
									//echo '<pre>';print_r($aProDue);echo '</pre>';
									if(count($aProDue) > 0)
									{
									if(count($aProDue) == 2)
									{
										if($aProDue[0]['correct_ans'] == $aProDue[1]['correct_ans'])
										{							
											$diagnosisequal = $ud_test->getPassed(). " Combination Protan/Deutan Color Deficient";	
										}
										else
										{
											$obj = null;
											if($aProDue[0]['correct_ans'] < $aProDue[1]['correct_ans'])
											{
												$obj = $user_deficiency_tests_details[$aProDue[0]['key']];
											}
											elseif($aProDue[0]['correct_ans'] > $aProDue[1]['correct_ans'])
											{
												//echo $aProDue[1]['key'];
												$obj = $user_deficiency_tests_details[$aProDue[1]['key']];
												//print_r($obj);exit;
											}
										//echo '<pre>';print_r($obj);echo '</pre>';
											if($obj)
											{	if($diagnosis != "")
													$diagnosis .= " and ";	
												//print_r($obj);
												//$diagnosis .= " <a style='text-decoration:underline; !important' href=".'"'.FOLDER_PATH_HTTP.$obj->getPageLink().'"> '.$obj->getPassed()." ".$obj->getGroupName().'</a> ';
												$diagnosis .= $obj->getPassed()." ".$obj->getGroupName();
											}
										}						
									}else{
										$obj = $user_deficiency_tests_details[$aProDue[0]['key']];
										if($obj)
											{	if($diagnosis != "")
													$diagnosis .= " and ";	
												//print_r($obj);
												//$diagnosis .= " <a style='text-decoration:underline; !important' href=".'"'.FOLDER_PATH_HTTP.$obj->getPageLink().'"> '.$obj->getPassed()." ".$obj->getGroupName().'</a> ';
												$diagnosis .= $obj->getPassed()." ".$obj->getGroupName();
											}
									}
									}
									
								}
								 
							}	
						
						}
						
						if($diagnosisequal != ""){
							if($diagnosis != "")
								$diagnosis .= " and ";	
							$diagnosis  .= $diagnosisequal;
						}
						$diagnosis = "Tested ". $diagnosis;
						/*------------------------------------------------------------------------------------------
						* RESULT NEW CODE ADDED BY MRUNAL M ON 23 Jan 12 STARTS HERE
						*--------------------------------------------------------------------------------------------*/
						if( $user_result == "Failed" && (count($def_rec_Id) == 0 && count($tri_lowest_score_deftest_id) == 0) )
						{
							$result_message = $result_fail_message;
							$diagnosis = "Tested Red/Green Color Vision Deficient.";
						}
						else if($user_result == "Passed" && count($def_rec_Id) == 0 && count($tri_lowest_score_deftest_id) == 0) 
						{
							$result_message = $result_pass_message;
							$diagnosis = "Tested Normal Color Vision.";
						}	
					}
					else	//Added by Mrunal M on 23 Jan 12
					{
						
						if($user_result == "Failed")
						{
							$result_message = $result_fail_message;
							$diagnosis = "Tested Red Green Color Deficient.";
						}
						else if($user_result == "Passed")
						{
							$result_message = $result_pass_message;
							$diagnosis = "Tested Normal Color Vision.";
						}
							
					}
					
				
			}
			else
			{
				if($user_result == "Failed")
				{
					$result_message = $result_fail_message;
					$diagnosis = "Tested Red Green Color Deficient.";//"You have a Color Vision Deficiency.";
				}
				else if($user_result == "Passed")
				{
					$result_message = $result_pass_message;
					$diagnosis = "Tested Normal Color Vision.";
				}
					
			}
		
	}
	catch(Exception $e)																							
	{
		
	}
	
	
	//echo '<br><br>'.$diagnosis.''.$diagnosisequal;exit;
//	$paper_orientation = 'potrait';
	$paper_orientation = 'landscape';

if($str == ''){	
	$str1 = '<tr><td colspan="4">&nbsp;</td></tr>
<tr><td colspan="4">&nbsp;</td></tr>
<tr><td colspan="4">&nbsp;</td></tr>';
}
	$value_to_pdf ='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<style>
body {
	margin-left:0px;
	margin-top:10px;
	font-size:14px;
	font-family: Avenir,sans-serif;
	color:#303030;
	
}

#bg {
	height:auto;
	margin:0px;
	background:	#D0D0D0 ;
	font-size:16px;
	
}
.box_rotate {
     -moz-transform: rotate(-90.0deg);  /* FF3.5+ */
       -o-transform: rotate(-90.0deg);  /* Opera 10.5 */
  -webkit-transform: rotate(-90.0deg);  /* Saf3.1+, Chrome */
 text-align:center;
}
.table { font-size:14px;border: 0mm solid black; border-collapse: collapse;}
</style>
</head>
<body>
<table class="table table-bordered table-condensed" width="100%" cellspacing="1" cellpadding="2">
<tr>
 <td colspan="5" >
 <table class="table table-bordered table-condensed" width="100%" cellspacing="1" cellpadding="2"   border="0"><tr><td width="40%"><img src="'.FOLDER_PATH_HTTP.'includes/modules/ColorDx_logo_135px.png" height="140"  ></td><td width="30%">
  <img src="'.FOLDER_PATH_HTTP.'includes/modules/image_3_1351px.png" height="140" >
 </td></tr></table>
  
 </td>
 
</tr>
<tr  >
	<td id="bg" colspan="5">
		<div style="padding:5px;margin-left:40px;">a Waggoner evaluation of color vision deficiencies</div>
	</td>
</tr>
<tr>
	<td colspan="5">
		<div style="padding:5px;margin-left:100px;font-size:36px;font-weight:bold">Color Vision Test Report</div>
	</td>
</tr>
<tr>
	<td width="20%"><div style="margin-left:40px;">'.$name.'<br><span style="font-size:14px;color:#3366CC">Patient Name</span></div></td>
	<td width="15%">'.$age.'<br><span style="font-size:14px;color:#3366CC">Age</span></td>	
	<td width="40%">'.$time_string.'<br><span style="font-size:14px;color:#3366CC">Test Date</span></td>
	<td width="20%">'.$getusertestid.'<br><span style="font-size:14px;color:#3366CC">Test ID | Plate ID</span></td>
	<td width="20%">&nbsp;</td>
</tr>
<tr>
	<td width="20%"><div style="margin-left:40px;">'.$identifire.'<br><span style="font-size:14px;color:#3366CC">Patient ID</span></div></td>
	<td width="15%">'.$gender.'<br><span style="font-size:14px;color:#3366CC">Gender</span></td>
	<td width="40%">'.$test_title.'<br><span style="font-size:14px;color:#3366CC">Method</span></td>
	<td width="20%">'.$testcondition.' '.$othertext.'<br><span style="font-size:14px;color:#3366CC">Test Condition</span></td>
	<td width="20%">&nbsp;</td>
</tr>
<tr>
	<td width="20%"><div style="margin-left:40px;">'.$eyetested.'<br><span style="font-size:14px;color:#3366CC">Eye</span></div></td>
	<td width="15%">Unknown/Online<br><span style="font-size:14px;color:#3366CC">Last Calibration Date</span></td>
	<td width="40%">&nbsp;</td>
	<td width="20%"></td>
	<td width="20%">&nbsp;</td>
</tr>
<tr>
	<td id="bg" colspan="5">
		<div style="padding:2px;margin-left:40px;">'.$test_title.'</div>
	</td>
</tr>

<tr>
<td colspan="6">
<table class="table table-bordered table-condensed" border="0" width="100%" cellspacing="1" cellpadding="5"><tr><td rowspan="6" width="5%"><img src="results.png" style="height:auto;width:20px;" height="150"></td></tr>
<tr>
	<td colspan="6">'.$score.'&nbsp;'.$user_result .'<br><span style="font-size:10px;">General Section <br> Pass Criteria : '.$score1.'</span></td>
<tr>
'.$str.'
'.$str1.'</table></td>	
</tr>

<tr>
	<td id="bg" colspan="5">
		<div style="margin-left:40px;padding:5px;"><div>'.$diagnosis.'</div></div>
	</td>
</tr>
<tr>
	<td colspan="5" >
		<img src="pdf_footer.png" style="width:80%;height:170px;" width="790">
	</td>
</tr>

</table>

</body>
</html>';

	//echo $value_to_pdf; exit;
						 
			
			
			 $html =str_replace(IMAGE_PATH_HTTP,'../../',$value_to_pdf); 
			 include("admin_create_pdf.php");
			 $dompdf->stream($cert_name);
				break;
						
		case 'Printpage': 
	
				$cert_name = "tcv_certificate.pdf";
	
				if(isset($_REQUEST['hash']))
				{
					//echo $_REQUEST['hash'];
					 $sttrhash = str_replace(" ","+",$_REQUEST['hash']);
					//echo $userid;
					  $dn = decode1($sttrhash);
					if($userid != $dn)
					{
					//	$user_test_info = array();
					//$_SESSION['Message'] = '132';
					echo $redirect_to = FOLDER_PATH_HTTP."index.php";
					//$re->redirectPage($redirect_to);
					die();
					}
					
				}else{
					//$user_test_info = array();
					//$_SESSION['Message'] = '132';
					echo $redirect_to = FOLDER_PATH_HTTP."index.php";
					//$re->redirectPage($redirect_to);
					die();
				}
	try
	{
		$user_test_info = $users_tests_manager->getSingleUsersTests_To_Show_Result($userid);
		//$user_test_info = $users_tests_manager->getSingleUsersTests($userid);
		//print_r($user_test_info);exit;
		
		$test_where_clause = " cms_type = 'T' AND tcv_test.test_id = ".$user_test_info->getTestId();
		$test_details = $test_manager->getSingleTest($test_where_clause);
		//print_r($test_details);die();
		$test_rec_id = $user_test_info->getUserTestId();
		
		try
		{
			$whereclause = " WHERE user_test_id = ".$test_rec_id." AND tcv_cms_test.cms_type = 'T'";
			$user_deficiency_tests_details = $user_deficiency_tests_manager->getAllUserDeficiencyTests_To_Show_Result($whereclause);
		}
		catch(Exception $e)
		{
			$user_deficiency_tests_details = array();
		}
		
		
		$test_cer_img = ($test_details->getTestType() == "A")?"certificate_tcv-150.jpg" : "pediatric-certificate_tcv-150.jpg"; 
		//print_r($user_deficiency_tests_details);
		
			$fname = stripslashes($user_test_info->getFname());
			$lname = stripslashes($user_test_info->getLname());// "1234";
			$name = ucwords( htmlspecialchars(substr($fname,0,20)." ".substr($lname,0,20)));
			
			$identifire =  stripslashes(htmlspecialchars($user_test_info->getIdentifier()));
			
			$age =  stripslashes(htmlspecialchars($user_test_info->getAge()));
			
			$gender =  stripslashes(htmlspecialchars($user_test_info->getGender()));
			
			$eyetested =  stripslashes(htmlspecialchars($user_test_info->getEyeTested()));
				
			$testcondition =  stripslashes(htmlspecialchars($user_test_info->getTestCondition()));
			$othertext =  stripslashes(htmlspecialchars($user_test_info->getOtherText()));
			if($user_test_info->getIsOldData())
			{
				$fname = decode($fname);
				$lname = decode($lname);
				$name = ucwords( htmlspecialchars(substr($fname,0,20)." ".substr($lname,0,20)));
				$identifire = decode($identifire);
				$age = decode($age);
				$gender = decode($gender);
				$eyetested = decode($eyetested);
				$testcondition = trim(decode($testcondition));
				$othertext =  decode($othertext);
			}	
			
			if($testcondition == 'O'){
				
			}else{
				$othertext =  '';
			}
			if($testcondition == 'B')
				$testcondition = 'Bright Light';
			elseif($testcondition == 'L')
				$testcondition = 'Low Light';	
			else
				$testcondition = 'Other';	
			if($testcondition == '')
				$testcondition = '--';
			if($testcondition == 'Other')
				$testcondition = '';
			if($gender == 'F')
				$gender = 'Female';
			elseif($gender == 'M')
				$gender = 'Male';
			if($gender == '')
				$gender = '--';		
			if($identifire == '')
				$identifire = '--';		
			if($eyetested == '')
				$eyetested = '--';		
			if($age <= 0)
				$age = '';
			if($age == '')
				$age = '--';
						
			$getusertestid =  stripslashes(htmlspecialchars($user_test_info->getUserTestId()));	
			//GET USERNAME ADDED BY Mrunal M on 12 Oct 11 starts here//
			if(trim($name) == "")
			{
				$name = wordwrap(decode($user_test_info->getUserEmail()),39,'<br />',true);
				$label = "Email Address";	
			}
			else
				$label = "User Name";	
			//GET USERNAME ADDED BY Mrunal M on 12 Oct 11 ends here//
			
			$test_title = stripslashes(htmlspecialchars($test_details->getTitle()));
			$total_givenques = stripslashes(decode($user_test_info->getTotalGivenAnswers()));// 
			if($total_givenques <= 0){
				$total_givenques = stripslashes($user_test_info->getNoOfQuestions());// 
			}
			$total_ques = stripslashes($user_test_info->getNoOfQuestions());// 
			$correct_ans = stripslashes($user_test_info->getCorrectAnswers());// 
			$correct_ans =  decode($correct_ans,$user_test_info->getIsOldData());
			$minscore = stripslashes($user_test_info->getMinScore());// 
			$score = $correct_ans."/".($total_givenques  - $user_test_info->getTotalDemoPlatesCnt());	//modified by Mrunal M 
			$score1 = $minscore."/".($total_ques  - $user_test_info->getTotalDemoPlatesCnt());	
			//$test_taken_date = date(DEFAULT_DATE_FORMAT,strtotime($user_test_info->getTestTakenDate()));
			
			/*$date_array = explode(" ",$user_test_info->getTestTakenDate());
			$test_date = $re->convertDate1($date_array[0]);
			$test_time = $date_array[1];
			$time_string = $test_time." on ".$test_date;*/
			
			$test_taken_date = $user_test_info->getTestTakenDate();
			$datetime = strtotime($test_taken_date);
			$time_string = date("m/d/y", $datetime);
			
			if($user_test_info->getPassed() == "1")
				
					$user_result = 'Passed';
					
					
				
				else
				
					$user_result = 'Failed';
				

			$correct_ans = "Pass";//($user_test_info->getPassed()=="1"? "Pass") 
			
			$str = ""; 
			
			try
					{
						$whereclause = " WHERE user_test_id = ".$test_rec_id." AND tcv_cms_test.cms_type = 'T' AND test_taken ='1' order by group_id ";
						$user_deficiency_tests_details = $user_deficiency_tests_manager->getAllUserDeficiencyTests_To_Show_Result_withGroup($whereclause);
					}
					catch(Exception $e)
					{
						$user_deficiency_tests_details = array();
					}
					
					/*echo '<pre>';
					print_r($user_deficiency_tests_details);*/
					//die();
					
					
					
					if(!isset($user_deficiency_tests_details) || count($user_deficiency_tests_details) == 0)
					{
						$isset_def_test = false;
					}
					else	//DEFINE DEFICINCY ADDED ON 23 Sept 11
					{
						//$def_test_cnt = 0;
						$lowest = 0;
						$def_array_ans = array();
						$lowest_score_deftest_id = array();
						$lowest_score = array();
						//$def_group_type = array();
						//$per_values = array();
						//$def_group_type = array();
						$lowest_score_group =array();
						$tri_lowest_score_deftest_id=array();
						//$per_values = array();
						$def_rec_Id = array();
						//$groupResultArray = array();
						
						$diagnosis = "";
						
						foreach($user_deficiency_tests_details as $user_d_test)
						{
							
							if($user_d_test->getPassed() != "Pass" && $user_d_test->getGroupId() != "4")
							{
								//array_push($def_array_ans, $user_d_test->getCorrectAnswers());
								array_push($def_array_ans, decode($user_d_test->getCorrectAnswers(),$user_d_test->getIsOldData()));
								//array_push($def_group_type, $user_d_test->getGroupName());
								array_push($def_rec_Id, $user_d_test->getUserDeftestId());
							}
							else if($user_d_test->getGroupId() == "4" && $user_d_test->getPassed() != "Pass")
							{
								array_push($tri_lowest_score_deftest_id, $user_d_test->getUserDeftestId());								
								//break;	
							}
						}
												
						$lowest = $def_array_ans[0];
					
						$k=1;
						for($i = 0; $i < count($def_array_ans); $i++)
						{							
							if($lowest > $def_array_ans[$i])
							{
								$lowest = $def_array_ans[$i];
								
								
								if(!(in_array($def_rec_Id[$i], $lowest_score_deftest_id)))
								{
								
								$lowest_score_deftest_id[$k-1] = $def_rec_Id[$i];
								$k++;
								}
							}
							else if($lowest == $def_array_ans[$i])
							{										
								if(!(in_array($def_rec_Id[$i], $lowest_score_deftest_id)))
								{
								$k++;
								$lowest_score_deftest_id[$k-1] = $def_rec_Id[$i];
								}
							}									
						}						
					}
			if(count($user_deficiency_tests_details) > 0)
			{
				
					$str = '';	 
				foreach($user_deficiency_tests_details as $ud_test)
				{
					
							
					$str .= '<tr>
						<td colspan="4">'.decode($ud_test->getCorrectAnswers(),$ud_test->getIsOldData()).'/'.($ud_test->getNoOfQuestions()  - $ud_test->getTotalDemoPlatesCnt()).'  ';
						
						if(decode($ud_test->getCorrectAnswers(),$ud_test->getIsOldData()) >= $ud_test->getMinScore())
								{
									$str .= ' Passed';
									
								}
								else
								{
									$str .= $ud_test->getPassed();
									
								} 
								$str .= '  <br><span style="font-size:14px;">'.
								$ud_test->getGroupName().' Section ('.$ud_test->getColorName().')</span></td>
					</tr>';		
				
				
				}
				if(isset($user_deficiency_tests_details) && count($user_deficiency_tests_details) > 0)
					{
						foreach($user_deficiency_tests_details as $ud_test)
						{							
							if(in_array($ud_test->getUserDeftestId(), $tri_lowest_score_deftest_id) || in_array($ud_test->getUserDeftestId(), $lowest_score_deftest_id))
							{
								if($diagnosis != "")
									$diagnosis .= " and ";	
								$diagnosis .= $ud_test->getPassed()." ".$ud_test->getGroupName(); 
							
								$result_message = $result_fail_message;
							}						
						}
						$diagnosis = "Tested ". $diagnosis;
						/*------------------------------------------------------------------------------------------
						* RESULT NEW CODE ADDED BY MRUNAL M ON 23 Jan 12 STARTS HERE
						*--------------------------------------------------------------------------------------------*/
						if( $user_result == "Failed" && (count($def_rec_Id) == 0 && count($tri_lowest_score_deftest_id) == 0) )
						{
							$result_message = $result_fail_message;
							$diagnosis = "Tested Red Green Color Deficient.";
						}
						else if($user_result == "Passed" && count($def_rec_Id) == 0 && count($tri_lowest_score_deftest_id) == 0) 
						{
							$result_message = $result_pass_message;
							$diagnosis = "Tested Normal Color Vision.";
						}	
					}
					else	//Added by Mrunal M on 23 Jan 12
					{
						
						if($user_result == "Failed")
						{
							$result_message = $result_fail_message;
							$diagnosis = "Tested Red Green Color Deficient.";
						}
						else if($user_result == "Passed")
						{
							$result_message = $result_pass_message;
							$diagnosis = "Tested Normal Color Vision.";
						}
							
					}
					
				
			}
			else
			{
				if($user_result == "Failed")
				{
					$result_message = $result_fail_message;
					$diagnosis = "Tested Red Green Color Deficient.";//"You have a Color Vision Deficiency.";
				}
				else if($user_result == "Passed")
				{
					$result_message = $result_pass_message;
					$diagnosis = "Tested Normal Color Vision.";
				}
					
			}
		
	}
	catch(Exception $e)																							
	{
		
	}
	
//	$paper_orientation = 'potrait';
	$paper_orientation = 'landscape';

if($str == ''){	
	$str1 = '<tr><td colspan="4">&nbsp;</td></tr>
<tr><td colspan="4">&nbsp;</td></tr>
<tr><td colspan="4">&nbsp;</td></tr>';
}
	$value_to_pdf ='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<style>
body {
	margin-left:0px;
	margin-top:10px;
	font-size:14px;
	font-family: Avenir,sans-serif;
	color:#303030;
	
}

#bg {
	height:auto;
	margin:0px;
	background:	#D0D0D0 ;
	font-size:16px;
	
}
.box_rotate {
     -moz-transform: rotate(-90.0deg);  /* FF3.5+ */
       -o-transform: rotate(-90.0deg);  /* Opera 10.5 */
  -webkit-transform: rotate(-90.0deg);  /* Saf3.1+, Chrome */
 text-align:center;
}
.table { font-size:15px;border: 0mm solid black; border-collapse: collapse;}
</style>
</head>
<body>
<table class="table table-bordered table-condensed" width="100%" cellspacing="1" cellpadding="2">
<tr>
 <td colspan="5" >
 <table class="table table-bordered table-condensed" width="100%" cellspacing="1" cellpadding="2"   border="0"><tr><td width="40%"><img src="'.FOLDER_PATH_HTTP.'includes/modules/ColorDx_logo_135px.png" height="140"  ></td><td width="30%">
  <img src="'.FOLDER_PATH_HTTP.'includes/modules/image_3_1351px.png" height="140" >
 </td></tr></table>
  
 </td>
 
</tr>
<tr  >
	<td id="bg" colspan="5">
		<div style="padding:5px;margin-left:40px;">a Waggoner evaluation of color vision deficiencies</div>
	</td>
</tr>
<tr>
	<td colspan="5">
		<div style="padding:5px;margin-left:100px;font-size:36px;font-weight:bold">Color Vision Test Report</div>
	</td>
</tr>
<tr>
	<td width="20%"><div style="margin-left:40px;">'.$name.'<br><span style="font-size:14px;color:#3366CC">Patient Name</span></div></td>
	<td width="20%">'.$age.'<br><span style="font-size:14px;color:#3366CC">Age</span></td>	
	<td width="20%">'.$time_string.'<br><span style="font-size:14px;color:#3366CC">Test Date</span></td>
	<td width="20%">'.$getusertestid.'<br><span style="font-size:14px;color:#3366CC">Test ID | Plate ID</span></td>
	<td width="20%">&nbsp;</td>
</tr>
<tr>
	<td width="20%"><div style="margin-left:40px;">'.$identifire.'<br><span style="font-size:14px;color:#3366CC">Patient ID</span></div></td>
	<td width="20%">'.$gender.'<br><span style="font-size:14px;color:#3366CC">Gender</span></td>
	<td width="20%">'.$test_title.'<br><span style="font-size:14px;color:#3366CC">Method</span></td>
	<td width="20%">'.$testcondition.' '.$othertext.'<br><span style="font-size:14px;color:#3366CC">Test Condition</span></td>
	<td width="20%">&nbsp;</td>
</tr>
<tr>
	<td width="20%"><div style="margin-left:40px;">'.$eyetested.'<br><span style="font-size:14px;color:#3366CC">Eye</span></div></td>
	<td width="20%">Unknown/Online<br><span style="font-size:14px;color:#3366CC">Last Calibration Date</span></td>
	<td width="20%">&nbsp;</td>
	<td width="20%"></td>
	<td width="20%">&nbsp;</td>
</tr>
<tr>
	<td id="bg" colspan="5">
		<div style="padding:2px;margin-left:40px;">'.$test_title.'</div>
	</td>
</tr>

<tr>
<td colspan="6">
<table class="table table-bordered table-condensed" border="0" width="100%" cellspacing="1" cellpadding="5"><tr><td rowspan="6" width="5%"><img src="results.png" style="height:auto;width:20px;" height="150"></td></tr>
<tr>
	<td colspan="6">'.$score.'&nbsp;'.$user_result .'<br><span style="font-size:10px;">General Section <br> Pass Criteria : '.$score1.'</span></td>
<tr>
'.$str.'
'.$str1.'</table></td>	
</tr>

<tr>
	<td id="bg" colspan="5">
		<div style="margin-left:40px;padding:5px;"><div>'.$diagnosis.'</div></div>
	</td>
</tr>
<tr>
	<td colspan="5" >
		<img src="pdf_footer.png" style="width:80%;height:170px;" width="790">
	</td>
</tr>

</table>

</body>
</html>';

//	echo $value_to_pdf; exit;
						 
			
			
			 $html =str_replace(IMAGE_PATH_HTTP,'../../',$value_to_pdf); 
			 include("admin_create_pdf.php");
			 echo FOLDER_PATH_HTTP.'tcvuploads/tcv_certificate.pdf';//$var;
			
			// $re->redirectPage(FOLDER_PATH_HTTP."test-result.php?recId=".base64_encode($main_test_rec_id));
			 
				break;		
						
						
						
				case 'SaveResultPage' :
				$value_to_pdf ="";
				$paper_orientation = 'portrait';
				
				
				$test_rec_id = $userid;
				$isset_def_test = true;
				$cert_name = "tcv_test_result.pdf";	
					try
					{
						$user_test_details = $users_tests_manager->getSingleUsersTests_To_Show_Result($test_rec_id);
						if(isset($user_test_details) && $user_test_details != 0)
						{
							$test_taken_date = $user_test_details->getTestTakenDate();
							$total_ques = stripslashes($user_test_details->getNoOfQuestions());// 
			$correct_ans = stripslashes($user_test_details->getCorrectAnswers());// 
			$minscore = stripslashes($user_test_details->getMinScore());// 
			$score = $correct_ans."/".($total_ques  - $user_test_details->getTotalDemoPlatesCnt());	//modified by Mrunal M 
			$score1 = $minscore."/".($total_ques  - $user_test_details->getTotalDemoPlatesCnt());	
							$datetime = strtotime($test_taken_date);
							$time_string = date("m/d/y", $datetime);
						$identifire =  stripslashes(htmlspecialchars($user_test_details->getIdentifier()));
			if($identifire == '')
				$identifire = '--';	
			$age =  stripslashes(htmlspecialchars($user_test_details->getAge()));
			if($age <= 0)
				$age = '';
			if($age == '')
				$age = '--';
			$gender =  stripslashes(htmlspecialchars($user_test_details->getGender()));
			if($gender == 'F')
				$gender = 'Female';
			else
				$gender = 'Male';
			if($gender == '')
				$gender = '--';			
			$eyetested =  stripslashes(htmlspecialchars($user_test_details->getEyeTested()));
			if($eyetested == '')
				$eyetested = '--';	
			$testcondition =  stripslashes(htmlspecialchars($user_test_details->getTestCondition()));
			if($testcondition == 'O'){
				$othertext =  stripslashes(htmlspecialchars($user_test_details->getOtherText()));
			}else{
				$othertext =  '';
			}
			if($testcondition == 'B')
				$testcondition = 'Bright Light';
			elseif($testcondition == 'L')
				$testcondition = 'Low Light';	
			else
				$testcondition = 'Other';	
			if($testcondition == '')
				$testcondition = '--';		
			$getusertestid =  stripslashes(htmlspecialchars($user_test_details->getUserTestId()));	
							/*$date_array = explode(" ",$test_taken_date);
							$test_date = $re->convertDate1($date_array[0]);
							$test_time = $date_array[1];
							$time_string = $test_time." on ".$test_date;*/
							
							$fname = stripslashes($user_test_details->getFname());
							$lname = stripslashes($user_test_details->getLname());// "1234";
							$name = ucwords( htmlspecialchars($fname." ".$lname));
							
							//GET USERNAME ADDED BY Mrunal M on 12 Oct 11 starts here//
							if(trim($name) == "")
							{
								$name = wordwrap($user_test_details->getUserEmail(),53,'<br />',true);
								$label = "Email Address";	
							}
							else
								$label = "User Name";	
							//GET USERNAME ADDED BY Mrunal M on 12 Oct 11 ends here//
						}
					}
					catch(Exception $e)
					{
						$user_test_detail = array();
						$_SESSION['Message'] = '132';
						//$redirect_to = FOLDER_PATH_HTTP."index.php";
						$re->redirectPage($redirect_to);
						die();
					}
					
					$result_pass_message = $user_test_details->getPassMessage();
					$result_fail_message = $user_test_details->getFailMessage();
					
					if($user_test_details->getPassed() == "1")
					{
						$user_result = 'Passed';
						
						$res_span_class = "colorgreen";
				
				
				
						//$result_message = $user_test_details->getPassMessage();
					}
					else
					{
						$user_result = 'Failed';
						$res_span_class = "red";
						//$result_message = $user_test_details->getFailMessage();
					}
				
					try
					{
						$whereclause = " WHERE user_test_id = ".$test_rec_id." AND tcv_cms_test.cms_type = 'T' AND test_taken ='1' order by group_id ";
						$user_deficiency_tests_details = $user_deficiency_tests_manager->getAllUserDeficiencyTests_To_Show_Result_withGroup($whereclause);
					}
					catch(Exception $e)
					{
						$user_deficiency_tests_details = array();
					}
					
					/*echo '<pre>';
					print_r($user_deficiency_tests_details);*/
					//die();
					
					
					
					if(!isset($user_deficiency_tests_details) || count($user_deficiency_tests_details) == 0)
					{
						$isset_def_test = false;
					}
					else	//DEFINE DEFICINCY ADDED ON 23 Sept 11
					{
						//$def_test_cnt = 0;
						$lowest = 0;
						$def_array_ans = array();
						$lowest_score_deftest_id = array();
						$lowest_score = array();
						//$def_group_type = array();
						//$per_values = array();
						//$def_group_type = array();
						$lowest_score_group =array();
						$tri_lowest_score_deftest_id=array();
						//$per_values = array();
						$def_rec_Id = array();
						//$groupResultArray = array();
						
						$diagnosis = "";
						
						foreach($user_deficiency_tests_details as $user_d_test)
						{
							
							if($user_d_test->getPassed() != "Pass" && $user_d_test->getGroupId() != "4")
							{
								//array_push($def_array_ans, $user_d_test->getCorrectAnswers());
								array_push($def_array_ans, decode($user_d_test->getCorrectAnswers(),$user_d_test->getIsOldData()));
								//array_push($def_group_type, $user_d_test->getGroupName());
								array_push($def_rec_Id, $user_d_test->getUserDeftestId());
							}
							else if($user_d_test->getGroupId() == "4" && $user_d_test->getPassed() != "Pass")
							{
								array_push($tri_lowest_score_deftest_id, $user_d_test->getUserDeftestId());								
								//break;	
							}
						}
												
						$lowest = $def_array_ans[0];
					
						$k=1;
						for($i = 0; $i < count($def_array_ans); $i++)
						{							
							if($lowest > $def_array_ans[$i])
							{
								$lowest = $def_array_ans[$i];
								
								
								if(!(in_array($def_rec_Id[$i], $lowest_score_deftest_id)))
								{
								
								$lowest_score_deftest_id[$k-1] = $def_rec_Id[$i];
								$k++;
								}
							}
							else if($lowest == $def_array_ans[$i])
							{										
								if(!(in_array($def_rec_Id[$i], $lowest_score_deftest_id)))
								{
								$k++;
								$lowest_score_deftest_id[$k-1] = $def_rec_Id[$i];
								}
							}									
						}						
					}
					
					//** Added on 10 oct 11 By Mrunal M starts here **//
					if(isset($user_deficiency_tests_details) && count($user_deficiency_tests_details) > 0)
					{
						foreach($user_deficiency_tests_details as $ud_test)
						{							
							if(in_array($ud_test->getUserDeftestId(), $tri_lowest_score_deftest_id) || in_array($ud_test->getUserDeftestId(), $lowest_score_deftest_id))
							{
								if($diagnosis != "")
									$diagnosis .= " and ";	
								$diagnosis .= $ud_test->getPassed()." ".$ud_test->getGroupName(); 
							
								$result_message = $result_fail_message;
							}						
						}
						
						/*------------------------------------------------------------------------------------------
						* RESULT NEW CODE ADDED BY MRUNAL M ON 23 Jan 12 STARTS HERE
						*--------------------------------------------------------------------------------------------*/
						if( $user_result == "Failed" && (count($def_rec_Id) == 0 && count($tri_lowest_score_deftest_id) == 0) )
						{
							$result_message = $result_fail_message;
							$diagnosis = "Questionable - Recommend additional testing.";
						}
						else if($user_result == "Passed" && count($def_rec_Id) == 0 && count($tri_lowest_score_deftest_id) == 0) 
						{
							$result_message = $result_pass_message;
							$diagnosis = "Normal Color Vision.";
						}	
					}
					else	//Added by Mrunal M on 23 Jan 12
					{
						if($user_result == "Failed")
						{
							$result_message = $result_fail_message;
							$diagnosis = "Red Green Color Deficient.";
						}
						else if($user_result == "Passed")
						{
							$result_message = $result_pass_message;
							$diagnosis = "Normal Color Vision.";
						}
							
					}
					/*------------------------------------------------------------------------------------------
					* RESULT NEW CODE ADDED BY MRUNAL M ON 23 Jan 12 ENDS HERE
					*--------------------------------------------------------------------------------------------*/
					/*if( ($user_result != "Failed" && count($def_rec_Id) > 0) || ($user_result == "Failed" && count($def_rec_Id) == 0))
					{
						$result_message = $result_fail_message;
						$diagnosis = "Questionable - Recommend additional testing.";
					}
					else if($user_result != "Failed" && count($def_rec_Id) == 0) 
					{
						$result_message = $result_pass_message;
						$diagnosis = "Normal Color Vision.";
					}*/ //commented on 30th Nov 11 by Mrunal M
					//** Added on 10 oct 11 By Mrunal M ends here **//
					
					/*-------------------------------------------------------------------------------------------
					* RESULT NEW CODE ADDED BY MRUNAL M ON 30 NOV 11 STARTS HERE
					*--------------------------------------------------------------------------------------------*/
					/*if( ($user_result != "Failed" &&( count($def_rec_Id) > 0 || count($tri_lowest_score_deftest_id) > 0)) ||($user_result == "Failed" && (count($def_rec_Id) == 0 && count($tri_lowest_score_deftest_id) == 0)) )
					{
						$result_message = $result_fail_message;
						$diagnosis = "Questionable - Recommend additional testing.";
					}
					else if($user_result != "Failed" && count($def_rec_Id) == 0 && count($tri_lowest_score_deftest_id) == 0) 
					{
						$result_message = $result_pass_message;
						$diagnosis = "Normal Color Vision.";
					}*/	//commented by Mrunal M on 23 Jan 12
					/*-------------------------------------------------------------------------------------------
					* RESULT NEW CODE ADDED BY MRUNAL M ON 30 NOV 11 ENDS HERE
					*--------------------------------------------------------------------------------------------*/
					
					$value_to_pdf = 
					'<html>
						<head>
							<title></title>
							<style type="text/css">
								#containerinn {background:url(bogybginn.jpg) center -214px repeat-x!important;} 			
								.inn {margin:0 auto; width:979px; }
								.titlewapper .slider_right {font-size:18px; color:#343434; width:558px;	margin:35px 0 0px 15px; background:none;}
								.titlewapper {overflow:hidden}
								.titlewapper .titleimg {margin-left:18px;}
								.titlewapper .slider_right {font-size:18px; color:#343434; width:558px;	margin:4px 0 0 0px;}
								.titlewapper .slider_right h3 {color:#47688d; font-size:30px; padding-bottom:5px; padding-top:3px; font-family:"Times New Roman", Times, serif; font-weight:bold}
								.titlewapper .slider_right p{ margin:2px 0 35px 0;}
								.fl {float:left}
								.fr {float:right}
								#content {padding:16px 10px 0 10px;}
								#content .leftsidebar {width:668px;	float:left; margin-top:15px; background:url("'.IMAGE_PDF_PATH.'/site/left_border.png") repeat-y top right; padding:0 0 20px 0;}
								#content .rightsidebar {width:273px; float:right; position:relative; padding: 0 0 20px;}
								#content .rightsidebar h3 {color:#47688d; font-size:20px; padding-bottom:2px; font-family:"Times New Roman", Times, serif}
								.inn-item {line-height: 24px; padding-bottom: 9px; margin-top: 15px;}
								.font22 {font-size:22px; font-weight:normal}
								.colorblue {color:#2f4e71}
								.colorgreen {color:#1d940a}
								.red {color:#FF0000}
								.font18 {font-size:18px}
								.slider_right {font-size:18px; color:#343434; width:558px;	margin:35px 0 0px 15px; background:url("'.IMAGE_PDF_PATH.'slidetext-bg.jpg") no-repeat left top;}
								.slider_right h3 {color:#47688d; font-size:30px; padding-bottom:5px; padding-top:3px; font-family:"Times New Roman", Times, serif; font-weight:bold}
								.slider_right p{ margin:2px 0 35px 0;}

							</style>
						</head>
						<body>
						<div id="containerinn">
						<div class="inn">
						  <div class="titlewapper">
						  <table>
						  <tr>
						  <td>
						   <img border="0" alt="" src="'.IMAGE_PDF_PATH.'/site/overview.jpg" class="fl titleimg"/>
						   </td>
						   <td>
							<div class="slider_right fl">
							  <h3>Tests</h3>
							  <p>Take our online test to assess your color vision.</p>
							</div>
							</td>
							</tr>
							</table>
						  </div>
';
						 
						 $user_passed = true;
														 
						 if($isset_def_test == false)
						 { 
						 $value_to_pdf .=' 
						  <div id="content" style="padding-top:110px;">
							
							  <div class="inn-item">
							
							   
							   <table width="100%" border="0" cellspacing="0" cellpadding="0" class="font22" >
							   ';
							   
							   if($result_message !="")
							   {
						$value_to_pdf .=' 
							   <tr>
									<td colspan="3"> <span class="colorblue">&nbsp;<?="'. wordwrap(strip_tags(trim($result_message)),85,'<br />',true).'"?></span></td>
							   </tr>
							  ';
							  	}
								
						$value_to_pdf .=' 
							   <tr>
									<td width="15%"><?="'.$label.'"?></td>
									<td width="1%">:</td>
									<td width="47%"><span class="colorblue"><?="'.$name.'"?></span></td>
								
							  </tr>';
							if(trim($identifire) != "")
		{
		$value_to_pdf .=' <tr>
									<td width="15%">Patient ID</td>
									<td width="1%">:</td>
									<td width="47%"><span class="colorblue"><?="'.$identifire.'"?></span></td>
								
							  </tr>';
				}
				if(trim($testcondition) != "")
		{
							   $value_to_pdf .='<tr>
									<td width="15%">Test Condition</td>
									<td width="1%">:</td>
									<td width="47%"><span class="colorblue"><?="'.$testcondition.'"?></span></td>
								
							  </tr>';
							  }

if(trim($age) != "" && $age > 0)
		{
								$value_to_pdf .='<tr>
									<td width="15%">Age</td>
									<td width="1%">:</td>
									<td width="47%"><span class="colorblue"><?="'.$age.'"?></span></td>
								
							  </tr>';
							  }
							 if(trim($eyetested) != "")
		{
		$value_to_pdf .='  <tr>
									<td width="15%">Eye Tested</td>
									<td width="1%">:</td>
									<td width="47%"><span class="colorblue"><?="'.$eyetested.'"?></span></td>
								
							  </tr>';
							  }
							$value_to_pdf .='  <tr>
									<td >Test Taken</td>
									<td>:</td>
									<td><span class="colorblue"><?="'.htmlspecialchars($user_test_details->getTestTitle()).'"?></span></td>
								
							  </tr>
							  <tr>
									<td>Date & Time</td>
									<td >:</td>
									<td ><span class="colorblue"><?="'.$time_string.'"?></span></td>
								
							  </tr>
							 <tr>
									<td align="left">Diagnosis</td>
									<td >:</td>
									<td align="left"><span class="colorblue">'; 
									
								$value_to_pdf .= $diagnosis;	
									/*if( $user_result == "Failed")
									$value_to_pdf .= "Questionable - Recommend additional testing.";
									else
									$value_to_pdf .= "Normal Color Vision.";*/
										
							$value_to_pdf .='</span></td>		
								
							  </tr>
							  <tr>
									<td>Score</td>
									<td width="1%">:</td>
									<td><span class="colorblue"><?="'.$user_test_details->getCorrectAnswers().'"?>/<?="'.($user_test_details->getNoOfQuestions() - $user_test_details->getTotalDemoPlatesCnt()).'"?> correct answers</span> (<span class="<?="'.$res_span_class.'"?>"><?="'.$user_result.'"?></span>)</td>
								
							  </tr>
							  <tr>
									<td colspan="3">&nbsp;</td>
							   </tr>
							 </table>
						  </div>
						 </div>';
						 
						 
						 }
						
						  if(isset($user_deficiency_tests_details) && count($user_deficiency_tests_details) > 0)
						  {
						   $value_to_pdf .=' 
						   <div id="content" style="padding-top:110px;">
							
							  <div class="inn-item">
							
							   
							   <table width="100%" border="0" cellspacing="0" cellpadding="0" class="font22" >
							   ';
							   
							   if($result_message !="")
							   {
						$value_to_pdf .=' 
							   <tr>
									<td colspan="3"> <span class="colorblue">&nbsp;<?="'.wordwrap(strip_tags(trim($result_message)),85,'<br />',true).'"?></span></td>
							   </tr>
							  ';
							  	}
								
						$value_to_pdf .=' 
							   <tr>
									<td width="15%"><?="'.$label.'"?></td>
									<td width="1%">:</td>
									<td width="47%"><span class="colorblue"><?="'.$name.'"?></span></td>
								
							  </tr>';
							  if(trim($identifire) != "")
		{
		$value_to_pdf .=' <tr>
									<td width="15%">Patient ID</td>
									<td width="1%">:</td>
									<td width="47%"><span class="colorblue"><?="'.$identifire.'"?></span></td>
								
							  </tr>';
				}
				if(trim($testcondition) != "")
		{
							   $value_to_pdf .='<tr>
									<td width="15%">Test Condition</td>
									<td width="1%">:</td>
									<td width="47%"><span class="colorblue"><?="'.$testcondition.'"?></span></td>
								
							  </tr>';
							  }

if(trim($age) != "" && $age > 0)
		{
								$value_to_pdf .='<tr>
									<td width="15%">Age</td>
									<td width="1%">:</td>
									<td width="47%"><span class="colorblue"><?="'.$age.'"?></span></td>
								
							  </tr>';
							  }
							 if(trim($eyetested) != "")
		{
		$value_to_pdf .='  <tr>
									<td width="15%">Eye Tested</td>
									<td width="1%">:</td>
									<td width="47%"><span class="colorblue"><?="'.$eyetested.'"?></span></td>
								
							  </tr>';
							  }
							  
							 $value_to_pdf .=' <tr>
									<td >Test Taken</td>
									<td>:</td>
									<td><span class="colorblue"><?="'.htmlspecialchars($user_test_details->getTestTitle()).'"?></span></td>
								
							  </tr>
							  <tr>
									<td>Date & Time</td>
									<td >:</td>
									<td ><span class="colorblue"><?="'.$time_string.'"?></span></td>
								
							  </tr>
							  <tr>
									<td align="left">Diagnosis</td>
									<td >:</td>
									<td align="left"><span class="colorblue">	';	
							
					
					
					
							/*foreach($user_deficiency_tests_details as $ud_test)
							{
								if(in_array($ud_test->getUserDeftestId(), $tri_lowest_score_deftest_id) || in_array($ud_test->getUserDeftestId(), $lowest_score_deftest_id))
								{
									if($diagnosis != "")
										$diagnosis .= " and ";	
									$diagnosis .= $ud_test->getPassed()." ".$ud_test->getGroupName(); 
								}	
							
							}
							
							if(count($def_rec_Id) == 0 )
							{
								if( $user_result == "Failed")
									$diagnosis = "Questionable - Recommend additional testing.";
								else
									$diagnosis = "Normal Color Vision.";
							}*/
									
					$value_to_pdf .='<span class="colorblue"><?="'.$diagnosis.'"?></span>
									</td>
								</tr>
								<tr>
									<td align="left">General Test</td>
									<td >:</td>
									<td align="left"><span class="colorblue"><?="'.$user_test_details->getCorrectAnswers().'"?>/<?="'.($user_test_details->getNoOfQuestions() - $user_test_details->getTotalDemoPlatesCnt()).'"?> </span><span class="colorblue">';	
									
					
					if($user_result == "Passed")
					{
					
						$value_to_pdf .='<span class="colorgreen">(<?="'.$user_result.'"?>)</span>';	 
					}
					else
					{
					
						$value_to_pdf .='<span class="red">(<?="'.$user_result.'"?>)</span>';
					
					}
					
						$value_to_pdf .='</td>
							  </tr>';
					
					
					foreach($user_deficiency_tests_details as $ud_test)
					{
						if($ud_test->getCorrectAnswers() >= $ud_test->getMinScore())//if($ud_test->getCorrectAnswers() == $ud_test->getNoOfQuestions())
						{
							$result_report = 'Passed';
							$def_class = "colorgreen";
						}
						else
						{
							$result_report = $ud_test->getPassed();
							$user_passed = false;
							$def_class = "red";
						}
					
					$value_to_pdf .=
								'<tr>
									<td align="left"><?="'.$ud_test->getGroupName().'"?><i class="font18">(<?="'.$ud_test->getColorName().'"?>)</i></td>
									<td >:</td>
									<td align="left"><span class="colorblue"><?="'.$ud_test->getCorrectAnswers().'"?>/<?="'.($ud_test->getNoOfQuestions() - $ud_test->getTotalDemoPlatesCnt()).'"?></span> <span style="display:none;" class="<?="'.$def_class.'"?>">(<?="'.$result_report.'"?>)</span>
									</td>
							  </tr>';
					
					}
					$value_to_pdf .=
								'<tr>
									<td colspan="3">&nbsp;</td>
							   </tr>
							 </table>
						  </div>
						 </div>';
					   }
					  
					  
					 $value_to_pdf .=
								' 
					 </div>
					
					</div>
					</body>
				</html>';
							 $html =str_replace(IMAGE_PATH_HTTP,'../../',$value_to_pdf); 
			 include("admin_create_pdf.php");	
				break;	
			 }
			 
			
		}
		function decode1($ciphertext_base64,$olddata=1)
    {  		
		$key1 = pack('H*', "2ffb2a00a3");
		define("ENCODING_KEY1",$key1);
		if($ciphertext_base64 == '')
			return $ciphertext_base64;
		if($olddata == 0 || $olddata == '')
			return $ciphertext_base64;
		$key = ENCODING_KEY1; 		
		$iv_size = @mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
  	  	$iv = @mcrypt_create_iv($iv_size, MCRYPT_RAND);
   		$ciphertext_dec = @base64_decode($ciphertext_base64);
    	$iv_dec = substr($ciphertext_dec, 0, $iv_size);
    	$ciphertext_dec = substr($ciphertext_dec, $iv_size);
	   $plaintext_dec = @mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key,$ciphertext_dec, MCRYPT_MODE_CBC, $iv_dec);    
		return trim($plaintext_dec);
    }
		
	
	
?>