Current File : /home/inlingua/public_html/sensoriumpsychologists.com/backup/franchise_between/screening_funcs.php
<?php
require_once("../../franchise_between/e_wallet_funcs.php");
require_once("../../franchise_back/database_func.php");
class screening_funcs
{
	private $sheet_6_vdds_error,$sheet_7_vdds_error,$sheet_8_vdds_error,$sheet_9_vdds_error,$sheet_6_vdds_total,$sheet_7_vdds_total,$sheet_8_vdds_total,$sheet_9_vdds_total,$sheet_6_vddl_error,$sheet_7_vddl_error,$sheet_8_vddl_error,$sheet_9_vddl_error,$sheet_6_vddl_total,$sheet_7_vddl_total,$sheet_8_vddl_total,$sheet_9_vddl_total,$sheet_6_vddn_error,$sheet_7_vddn_error,$sheet_8_vddn_error,$sheet_9_vddn_error,$sheet_6_vddn_total,$sheet_7_vddn_total,$sheet_8_vddn_total,$sheet_9_vddn_total,$sheet_6_vddw_error,$sheet_7_vddw_error,$sheet_8_vddw_error,$sheet_9_vddw_error,$sheet_6_vddw_total,$sheet_7_vddw_total,$sheet_8_vddw_total,$sheet_9_vddw_total;
	private $sheet_6_vdls_error,$sheet_7_vdls_error,$sheet_8_vdls_error,$sheet_9_vdls_error,$sheet_6_vdls_total,$sheet_7_vdls_total,$sheet_8_vdls_total,$sheet_9_vdls_total,$sheet_6_vdll_error,$sheet_7_vdll_error,$sheet_8_vdll_error,$sheet_9_vdll_error,$sheet_6_vdll_total,$sheet_7_vdll_total,$sheet_8_vdll_total,$sheet_9_vdll_total,$sheet_6_vdln_error,$sheet_7_vdln_error,$sheet_8_vdln_error,$sheet_9_vdln_error,$sheet_6_vdln_total,$sheet_7_vdln_total,$sheet_8_vdln_total,$sheet_9_vdln_total,$sheet_6_vdlw_error,$sheet_7_vdlw_error,$sheet_8_vdlw_error,$sheet_9_vdlw_error,$sheet_6_vdlw_total,$sheet_7_vdlw_total,$sheet_8_vdlw_total,$sheet_9_vdlw_total;
	private $franchise_id,$questionnaire_name,$questionnaire_duration,$no_of_questions,$no_of_sections,$screening_date;
	private $vdsw_error_codes_array=array();
	private $question_main;
	private $questions_array=array();
	private $answers_array=array();
	private $created_by,$created_browser,$created_ip,$updated_by,$updated_browser,$updated_ip,$updated_date;
	private function get_validity($date_str, $months)
	{
    $date = new DateTime($date_str);
    $start_day = $date->format('j');

    $date->modify("+{$months} month");
    $end_day = $date->format('j');

    if ($start_day != $end_day)
        $date->modify('last day of last month');
		
    $date->modify("-1 day");

    return $date;
	}
	public function __construct()
	{
		$this->franchise_id="";
		$this->questionnaire_name="";
		$this->questionnaire_duration="";
		$this->no_of_questions="";
		$this->no_of_sections="";
		$this->created_by="";
		$this->created_browser="";
		$this->created_ip="";
		$this->updated_by="";
		$this->updated_browser="";
		$this->updated_ip="";
		$this->updated_date="0000-00-00 00:00:00";
		$this->screening_date="0000-00-00";
		
		$this->question_main="";
	}
	public function set_value($variable_name,$new_value)
	{
		switch($variable_name)
		{
			case 'franchise_id':$this->franchise_id=$new_value;break;
			case 'questions_array':$this->questions_array=$new_value;break;
			case 'answers_array':$this->answers_array=$new_value;break;
			case 'created_by':$this->created_by=$new_value;break;
			case 'created_browser':$this->created_browser=$new_value;break;
			case 'created_ip':$this->created_ip=$new_value;break;
		}
	}
	public function get_value($variable_name)
	{
		$to_return="";
		switch($variable_name)
		{
			case 'questionnaire_duration':$to_return=$this->questionnaire_duration;break;
			case 'questionnaire_name':$to_return=$this->questionnaire_name;break;
			case 'no_of_questions':$to_return=$this->no_of_questions;break;
			case 'no_of_sections':$to_return=$this->no_of_sections;break;
			
			case 'question_main':$to_return=$this->question_main;break;
			case 'screening_date':$to_return=$this->screening_date;break;
		}
		return $to_return;
	}
	public function get_screening_name_and_duration($screening_id)
	{
		$mysql_obj=new mysql_functions_class;	
		$mysql_obj->open_connection();
		$screening_id=$mysql_obj->real_escape($screening_id);
		$prepared_statement="SELECT name,duration FROM shristi_questionnaires WHERE table_id='$screening_id'";
		$res=$mysql_obj->simply_run_statement_passed($prepared_statement);
		$mysql_obj->close_connection();
		if($res->num_rows==1)
		{
			$detail=$res->fetch_assoc();
			$this->questionnaire_name=$detail['name'];
			$this->questionnaire_duration=$detail['duration'];
		}
		else
		{
			echo("Error : questionnaire not found...");
			exit();
		}	
	}
	public function get_question_details_section($section_id)
	{
		$mysql_obj=new mysql_functions_class;	
		$mysql_obj->open_connection();
		$section_id=$mysql_obj->real_escape($section_id);
		$prepared_statement="SELECT question_paragraph FROM shristi_questionnaires_main_questions WHERE table_id='$section_id'";
		$res=$mysql_obj->simply_run_statement_passed($prepared_statement);
		$mysql_obj->close_connection();
		if($res->num_rows==1)
		{
			$detail=$res->fetch_assoc();
			$this->question_main=$detail['question_paragraph'];
		}
		else
		{
			echo("Error : section not found...");
			exit();
		}	
	}
	public function print_sub_questions($section_id)
	{
		$mysql_obj=new mysql_functions_class;	
		$mysql_obj->open_connection();
		$section_id=$mysql_obj->real_escape($section_id);
		$prepared_statement="SELECT * FROM shristi_questionnaires_sub_questions WHERE sub_questionnaire_codes='$section_id'";
		$res=$mysql_obj->simply_run_statement_passed($prepared_statement);
		$mysql_obj->close_connection();
		$sno=0;
		while($detail=$res->fetch_assoc())
		{
			if($detail['type']=="questions_category")
			{
				echo("<tr>");
				echo("<td colspan=\"3\" style=\"text-decoration:underline;\">".$detail['question']."</td>");
				echo("</tr>");
			}
			else
			{
				$sno++;
				echo("<input type=\"hidden\" value=\"".$detail['table_id']."\" name=\"question_".$sno."\" id=\"question_".$sno."\" />");
				if($detail['type']=="5")
				{
					echo("<tr>");
					echo("<td style=\"height:20px;\"></td>");
					echo("</tr>");
				}
				echo("<tr valign=\"top\">");
				echo("<td style=\"width:20px;text-align:right;\">Q".$sno."</td>");
				echo("<td style=\"padding:0 5px;width:5px;\">:</td>");
				
				/*if($detail['type']=="5")
				{
					$url="https://translate.google.com/translate_tts?tl=IN&q=".$detail['question'];
					echo("<td>");
					echo("<input type=\"hidden\" id=\"google_link_".$sno."\" value=\"".$url."\" />");
					echo("<div id=\"embed_div_".$sno."\"><embed src=\"none\" id=\"embed_".$sno."\" autostart=\"false\" width=\"2\" height=\"0\"></embed></div><noembed><bgsound src=\"none\"></noembed>");
					echo("<img src=\"images/im-listen-icon.png\" height=\"100px\" onClick=\"play_sound('".$sno."')\" volume=\"100\" style=\"cursor:pointer;\" />");
				}*/
				if($detail['type']=="5")
				{
					echo("<td>");
					//echo("<img src=\"images/im-listen-icon.png\" height=\"100px\" onClick=\"play_sound_2('".$detail['question']."')\" volume=\"100\" style=\"cursor:pointer;\" />");
					echo("<img src=\"images/im-listen-icon.png\" height=\"100px\" onClick=\"responsiveVoice.speak('".$detail['question']."')\" style=\"cursor:pointer;\" />");
				}
				/*else if($detail['type']=="5")
				{
					echo("<td>");
					echo("<audio controls>");
					echo("<source src=\"".$detail['audio_file_link']."\" type=\"audio/ogg\">");
					echo("Your browser does not support the audio element.");
					echo("</audio>");
				}*/
				else if($detail['type']=="8")
				{
					echo("<td rowspan=\"2\">");
					echo("<table style=\"font-size:40px;\"><tr>");
					$options=$detail['options'];
					$options_array=explode("!@!@",$options);
					for($i=0;$i<count($options_array);$i++)
					{
						$j=$i+1;
						echo("<td align=\"center\" style=\"padding:0 20px;\"><label for=\"ans_".$detail['table_id']."_".$j."\">".$options_array[$i]."</label><br />");
						echo("<input type=\"radio\"  name=\"ans_".$detail['table_id']."\" id=\"ans_".$detail['table_id']."_".$j."\" value=\"".$j."\" /></td>");
					}
					echo("</tr></table>");
				}
				else if($detail['type']=="50")
				{
					echo("<td rowspan=\"2\">");
					echo("<table border=\"0\" style=\"font-size:40px;\"><tr valign=\"top\">");
					echo("<td align=\"center\">".$detail['answer']."</td>");
					echo("</tr>");
					echo("<tr>");
					echo("<td colspan=\"4\" style=\"padding:20px;padding-right:0;\"><div style=\"position:relative;width:150px;height:1px;border-bottom:2px dashed #333;\"></div></td>");
					echo("</tr>");
					$options=$detail['options'];
					$options_array=explode("!@!@",$options);
					for($i=0;$i<count($options_array);$i++)
					{
						$j=$i+1;
						echo("<td align=\"center\" style=\"padding:0 20px;\"><label for=\"ans_".$detail['table_id']."_".$j."\">".$options_array[$i]."</label><br />");
						echo("<input type=\"radio\"  name=\"ans_".$detail['table_id']."\" id=\"ans_".$detail['table_id']."_".$j."\" value=\"".$j."\" /></td>");
					}
					echo("</tr></table>");
				}
				else
				{
					echo("<td>");
					echo($detail['question']."");
				}
				echo("&nbsp;&nbsp;&nbsp;<span id=\"error_span_".$detail['table_id']."\" style=\"color:#F00;display:none;\">Please select answer !!!</span></td>");
				echo("</tr>");
				if($detail['type']=="5")
				{
					echo("<tr><td colspan=\"2\"></td><td>");
					/*echo("<div>");
					echo("<a href=\"#\" id=\"start_button\" onclick=\"startDictation(event)\">Dictate</a>");
					echo("</div>");*/
					/*echo("<div id=\"results\">");
					/*echo("<span id=\"final_span\" class=\"final\"></span>");
					echo("<span id=\"interim_span\" class=\"interim\"></span>");*/
					//echo("</div>");
					echo("</td></tr>");
					echo("<tr style=\"height:30px\"><td colspan=\"3\"></td></tr>");
				$options=$detail['options'];
				$options_array=explode("!@!@",$options);
				for($i=0;$i<count($options_array);$i++)
				{
					$j=$i+1;
					echo("<tr>");
					echo("<td><input type=\"radio\" name=\"ans_".$detail['table_id']."\" id=\"ans_".$detail['table_id']."_".$j."\" value=\"".$j."\" /></td>");
					echo("<td><label for=\"ans_".$detail['table_id']."_".$j."\">".$options_array[$i]."</label></td>");
					echo("</tr>");
				}
				}
				else if($detail['type']=="50")
				{
					echo("<tr style=\"line-height:100px\"><td colspan=\"3\">&nbsp;</td></tr>");
					echo("<input type=\"hidden\" value=\"radio\" name=\"question_type_".$sno."\" id=\"question_type_".$sno."\" />");
				}
				else if($detail['type']!="8")
				{
					
				echo("<tr valign=\"top\">");
				echo("<td style=\"width:20px;text-align:right;\">Ans</td>");
				echo("<td style=\"padding:0 5px;width:5px;\">:</td>");
				echo("<td>");
				echo("<table>");
				$options=$detail['options'];
				$options_array=explode("!@!@",$options);
				for($i=0;$i<count($options_array);$i++)
				{
					$j=$i+1;
					echo("<tr>");
					echo("<td><input type=\"radio\" name=\"ans_".$detail['table_id']."\" id=\"ans_".$detail['table_id']."_".$j."\" value=\"".$j."\" /></td>");
					echo("<td><label for=\"ans_".$detail['table_id']."_".$j."\">".$options_array[$i]."</label></td>");
					echo("</tr>");
				}
				echo("</table>");
				echo("</td>");
				echo("</tr>");
				echo("<tr style=\"height:20px\"><td colspan=\"3\"></td></tr>");
				}
				else
				{
					echo("<tr style=\"line-height:150px\"><td colspan=\"3\">&nbsp;</td></tr>");
				}
			}
		}
		echo("<input type=\"hidden\" name=\"total_questions\" id=\"total_questions\" value=\"".$sno."\" />");
	}
	public function get_next_screening_section($current_section,$screening_id)
	{
		$mysql_obj=new mysql_functions_class;
		$mysql_obj->open_connection();
		$current_section=$mysql_obj->real_escape($current_section);
		$screening_id=$mysql_obj->real_escape($screening_id);
		if($current_section=="none")
		{
			$prepared_statement="SELECT table_id FROM shristi_questionnaires_main_questions WHERE questionnaires_code='$screening_id' LIMIT 0,1";
		}
		else
		{
			$prepared_statement="SELECT table_id FROM shristi_questionnaires_main_questions WHERE questionnaires_code='$screening_id' AND table_id>'$current_section' LIMIT 0,1";
		}
		$res=$mysql_obj->simply_run_statement_passed($prepared_statement);
		$mysql_obj->close_connection();
		if($res->num_rows==1)
		{
			$detail=$res->fetch_assoc();
			$to_return=$detail['table_id'];
		}
		else
		{
			$to_return="error";
		}
		return $to_return;
	}
	public function pre_screening_details($screening_id)
	{
		$mysql_obj=new mysql_functions_class;	
		$mysql_obj->open_connection();
		$screening_id=$mysql_obj->real_escape($screening_id);
		$prepared_statement="SELECT * FROM shristi_questionnaires WHERE table_id='$screening_id'";
		$res=$mysql_obj->simply_run_statement_passed($prepared_statement);
		if($res->num_rows==1)
		{
			$detail=$res->fetch_assoc();
			$this->questionnaire_name=$detail['name'];
			$this->questionnaire_duration=$detail['duration'];
		}
		else
		{
			$mysql_obj->close_connection();
			echo("Error : questionnaire not found...");
			exit();
		}
		
		$prepared_statement="SELECT COUNT(DISTINCT a.table_id) AS total_sections,COUNT(DISTINCT b.table_id) AS total_questions FROM shristi_questionnaires_main_questions a INNER JOIN shristi_questionnaires_sub_questions b ON b.sub_questionnaire_codes=a.table_id WHERE a.questionnaires_code='$screening_id' AND type!='questions_category'";
		$res=$mysql_obj->simply_run_statement_passed($prepared_statement);
		if($res->num_rows==1)
		{
			$detail=$res->fetch_assoc();
			$this->no_of_sections=$detail['total_sections'];
			$this->no_of_questions=$detail['total_questions'];
		}
		else
		{
			$mysql_obj->close_connection();
			echo("Error : Couldn't calculate no of questions and sections...");
			exit();
		}
		
		$mysql_obj->close_connection();
	}
	public function proceed_with_answers($ref_no,$franchise_id,$screening_id,$ongoing_section_no)
	{
		$prepared_statement="INSERT INTO shristi_questionnaires_temp_answers(franchise_id,ref_no,screening_id,main_question_id,sub_question_id,answer,created_by,created_ip,created_browser) VALUES";
		$mysql_obj=new mysql_functions_class;
		$mysql_obj->open_connection();
		$ref_no=$mysql_obj->real_escape($ref_no);
		$franchise_id=$mysql_obj->real_escape($franchise_id);
		$screening_id=$mysql_obj->real_escape($screening_id);
		$ongoing_section_no=$mysql_obj->real_escape($ongoing_section_no);
		$questions_array=$this->questions_array;
		$answers_array=$this->answers_array;
		$created_by=$this->created_by;
		$created_ip=$this->created_ip;
		$created_browser=$this->created_browser;
		
		for($i=0;$i<count($questions_array);$i++)
		{
			$ques=$questions_array[$i];
			$ans=$answers_array[$i];
			if($i==0)
			{
				$prepared_statement.="('$franchise_id','$ref_no','$screening_id','$ongoing_section_no','$ques','$ans','$created_by','$created_ip','$created_browser')";
			}
			else
			{
				$prepared_statement.=",('$franchise_id','$ref_no','$screening_id','$ongoing_section_no','$ques','$ans','$created_by','$created_ip','$created_browser')";
			}
		}
		if($mysql_obj->simply_run_statement_passed($prepared_statement))
		{
			$next_section=$this->get_next_screening_section($ongoing_section_no,$screening_id);
			if($next_section==="error")
			{
				$mysql_obj->close_connection();
				$this->save_answers($ref_no,$screening_id);
			}
			else
			{
				$mysql_obj->close_connection();
			}
		}
		else
		{
			$mysql_obj->close_connection();
			$next_section="error";
			echo("Error : cannot save...");
			exit();
		}
		return $next_section;
	}
	public function proceed_with_answers_timeout($ref_no,$franchise_id,$screening_id,$ongoing_section_no)
	{
		$prepared_statement="INSERT INTO shristi_questionnaires_temp_answers(franchise_id,ref_no,screening_id,main_question_id,sub_question_id,answer,created_by,created_ip,created_browser) VALUES";
		$mysql_obj=new mysql_functions_class;	
		$mysql_obj->open_connection();
		$ref_no=$mysql_obj->real_escape($ref_no);
		$franchise_id=$mysql_obj->real_escape($franchise_id);
		$screening_id=$mysql_obj->real_escape($screening_id);
		$ongoing_section_no=$mysql_obj->real_escape($ongoing_section_no);
		$questions_array=$this->questions_array;
		$answers_array=$this->answers_array;
		$created_by=$this->created_by;
		$created_ip=$this->created_ip;
		$created_browser=$this->created_browser;
		
		for($i=0;$i<count($questions_array);$i++)
		{
			$ques=$questions_array[$i];
			$ans=$answers_array[$i];
			if($i==0)
			{
				$prepared_statement.="('$franchise_id','$ref_no','$screening_id','$ongoing_section_no','$ques','$ans','$created_by','$created_ip','$created_browser')";
			}
			else
			{
				$prepared_statement.=",('$franchise_id','$ref_no','$screening_id','$ongoing_section_no','$ques','$ans','$created_by','$created_ip','$created_browser')";
			}
		}
		if($mysql_obj->simply_run_statement_passed($prepared_statement))
		{
			$this->save_answers($ref_no,$screening_id);
		}
		else
		{
			$mysql_obj->close_connection();
			$next_section="error";
			echo("Error : cannot save...");
			exit();
		}
	}
	public function save_answers($ref_no,$screening_id)
	{
		
		$mysql_obj=new mysql_functions_class;
		$mysql_obj->open_connection();
		$ref_no=$mysql_obj->real_escape($ref_no);
		$screening_id=$mysql_obj->real_escape($screening_id);
		
		$prepared_statement="START TRANSACTION";
		$mysql_obj->simply_run_statement_passed($prepared_statement);
		
		
		$prepared_statement_2="SELECT * FROM shristi_child_details WHERE table_id='$ref_no'";
		$res=$mysql_obj->simply_run_statement_passed($prepared_statement_2);
		if($res->num_rows!=1)
		{
			$mysql_obj->close_connection();
			echo("Error : Couldn't save answers 1...");
			exit();
		}
		$detail=$res->fetch_assoc();
		$std=$detail['education'];
		
		$prepared_statement_2="INSERT INTO shristi_questionnaires_permanent_answers SELECT * FROM shristi_questionnaires_temp_answers WHERE screening_id='$screening_id' AND ref_no='$ref_no'";
		if(!($mysql_obj->simply_run_statement_passed($prepared_statement_2)))
		{
			$mysql_obj->close_connection();
			echo("Error : Couldn't save answers...");
			exit();
		}
		
		$prepared_statement_2="DELETE FROM shristi_questionnaires_temp_answers WHERE screening_id='$screening_id' AND ref_no='$ref_no'";
		$mysql_obj->simply_run_statement_passed($prepared_statement_2);
		
		$mysql_obj->commit();/*very important here other wise further steps don't count percentage based on these answers*/
		$prepared_statement="START TRANSACTION";
		$mysql_obj->simply_run_statement_passed($prepared_statement);
		
$vdds_percent=0;
$vddl_percent=0;
$vddn_percent=0;
$vddw_percent=0;
$vdls_percent=0;
$vdll_percent=0;
$vdln_percent=0;
$vdlw_percent=0;
$vdsw_percent=0;
$vmc_percent=0;
$ad_percent=0;
$ac_percent=0;
$vc_percent=0;
$wrong_vdds=0;
$total_vdds=0;
$wrong_vddl=0;
$total_vddl=0;
$wrong_vddn=0;
$total_vddn=0;
$wrong_vddw=0;
$total_vddw=0;
$wrong_vdls=0;
$total_vdls=0;
$wrong_vdll=0;
$total_vdll=0;
$wrong_vdln=0;
$total_vdln=0;
$wrong_vdlw=0;
$total_vdlw=0;
$wrong_vdsw=0;
$total_vdsw=0;
$wrong_vmc=0;
$total_vmc=0;
$wrong_ad=0;
$total_ad=0;
$wrong_ac=0;
$total_ac=0;
$wrong_vc=0;
$total_vc=0;
$vdsw_error_codes_array=array();
$this->vdsw_error_codes_array=$vdsw_error_codes_array;
$this->student_questionnaire_report($ref_no,$screening_id,$vdds_percent,$vddl_percent,$vddn_percent,$vddw_percent,$vdls_percent,$vdll_percent,$vdln_percent,$vdlw_percent,$vdsw_percent,$vmc_percent,$ad_percent,$ac_percent,$vc_percent,$wrong_vdds,$total_vdds,$wrong_vddl,$total_vddl,$wrong_vddn,$total_vddn,$wrong_vddw,$total_vddw,$wrong_vdls,$total_vdls,$wrong_vdll,$total_vdll,$wrong_vdln,$total_vdln,$wrong_vdlw,$total_vdlw,$wrong_vdsw,$total_vdsw,$wrong_vmc,$total_vmc,$wrong_ad,$total_ad,$wrong_ac,$total_ac,$wrong_vc,$total_vc);
switch($std)
{
	case '1':$error_slot_1=1;$error_slot_2=1;$error_slot_3=1;$error_slot_4=1;break;
	case '2':$error_slot_1=2;$error_slot_2=1;$error_slot_3=1;$error_slot_4=1;break;
	case '3':$error_slot_1=3;$error_slot_2=2;$error_slot_3=1;$error_slot_4=1;break;
	case '4':$error_slot_1=4;$error_slot_2=3;$error_slot_3=2;$error_slot_4=1;break;
	case '5':$error_slot_1=5;$error_slot_2=4;$error_slot_3=3;$error_slot_4=2;break;
	case '6':$error_slot_1=6;$error_slot_2=5;$error_slot_3=4;$error_slot_4=3;break;
	case '7':$error_slot_1=7;$error_slot_2=6;$error_slot_3=5;$error_slot_4=4;break;
	case '8':$error_slot_1=8;$error_slot_2=7;$error_slot_3=6;$error_slot_4=5;break;
	case '9':$error_slot_1=9;$error_slot_2=8;$error_slot_3=7;$error_slot_4=6;break;
	case '10':$error_slot_1=10;$error_slot_2=9;$error_slot_3=8;$error_slot_4=7;break;
}
$array_error_type_1=array("ac");
$array_error_type_1_val=array($ac_percent);
/*$array_error_type_1=array("ac","vc");
$array_error_type_1_val=array($ac_percent,$vc_percent);*/
$array_error_type_2=array("vdds","vddl","vddn","vddw","vdls","vdll","vdln","vdlw");
$array_error_type_2_val=array($vdds_percent,$vddl_percent,$vddn_percent,$vddw_percent,$vdls_percent,$vdll_percent,$vdln_percent,$vdlw_percent);
$array_error_type_3=array("vdsw","vmc");
$array_error_type_3_val=array($vdsw_percent,$vmc_percent);
$array_error_type_4=array("ad");
$array_error_type_4_val=array($ad_percent);

$today_date=date("Y-m-d");

			$sheet_6_vdds_error=$this->sheet_6_vdds_error;
			$sheet_7_vdds_error=$this->sheet_7_vdds_error;
			$sheet_8_vdds_error=$this->sheet_8_vdds_error;
			$sheet_9_vdds_error=$this->sheet_9_vdds_error;
			$sheet_6_vdds_total=$this->sheet_6_vdds_total;
			$sheet_7_vdds_total=$this->sheet_7_vdds_total;
			$sheet_8_vdds_total=$this->sheet_8_vdds_total;
			$sheet_9_vdds_total=$this->sheet_9_vdds_total;
			
			$sheet_6_vddl_error=$this->sheet_6_vddl_error;
			$sheet_7_vddl_error=$this->sheet_7_vddl_error;
			$sheet_8_vddl_error=$this->sheet_8_vddl_error;
			$sheet_9_vddl_error=$this->sheet_9_vddl_error;
			$sheet_6_vddl_total=$this->sheet_6_vddl_total;
			$sheet_7_vddl_total=$this->sheet_7_vddl_total;
			$sheet_8_vddl_total=$this->sheet_8_vddl_total;
			$sheet_9_vddl_total=$this->sheet_9_vddl_total;
			
			$sheet_6_vddn_error=$this->sheet_6_vddn_error;
			$sheet_7_vddn_error=$this->sheet_7_vddn_error;
			$sheet_8_vddn_error=$this->sheet_8_vddn_error;
			$sheet_9_vddn_error=$this->sheet_9_vddn_error;
			$sheet_6_vddn_total=$this->sheet_6_vddn_total;
			$sheet_7_vddn_total=$this->sheet_7_vddn_total;
			$sheet_8_vddn_total=$this->sheet_8_vddn_total;
			$sheet_9_vddn_total=$this->sheet_9_vddn_total;
			
			$sheet_6_vddw_error=$this->sheet_6_vddw_error;
			$sheet_7_vddw_error=$this->sheet_7_vddw_error;
			$sheet_8_vddw_error=$this->sheet_8_vddw_error;
			$sheet_9_vddw_error=$this->sheet_9_vddw_error;
			$sheet_6_vddw_total=$this->sheet_6_vddw_total;
			$sheet_7_vddw_total=$this->sheet_7_vddw_total;
			$sheet_8_vddw_total=$this->sheet_8_vddw_total;
			$sheet_9_vddw_total=$this->sheet_9_vddw_total;
			
			
			
			
			
			$sheet_6_vdls_error=$this->sheet_6_vdls_error;
			$sheet_7_vdls_error=$this->sheet_7_vdls_error;
			$sheet_8_vdls_error=$this->sheet_8_vdls_error;
			$sheet_9_vdls_error=$this->sheet_9_vdls_error;
			$sheet_6_vdls_total=$this->sheet_6_vdls_total;
			$sheet_7_vdls_total=$this->sheet_7_vdls_total;
			$sheet_8_vdls_total=$this->sheet_8_vdls_total;
			$sheet_9_vdls_total=$this->sheet_9_vdls_total;
			
			$sheet_6_vdll_error=$this->sheet_6_vdll_error;
			$sheet_7_vdll_error=$this->sheet_7_vdll_error;
			$sheet_8_vdll_error=$this->sheet_8_vdll_error;
			$sheet_9_vdll_error=$this->sheet_9_vdll_error;
			$sheet_6_vdll_total=$this->sheet_6_vdll_total;
			$sheet_7_vdll_total=$this->sheet_7_vdll_total;
			$sheet_8_vdll_total=$this->sheet_8_vdll_total;
			$sheet_9_vdll_total=$this->sheet_9_vdll_total;
			
			$sheet_6_vdln_error=$this->sheet_6_vdln_error;
			$sheet_7_vdln_error=$this->sheet_7_vdln_error;
			$sheet_8_vdln_error=$this->sheet_8_vdln_error;
			$sheet_9_vdln_error=$this->sheet_9_vdln_error;
			$sheet_6_vdln_total=$this->sheet_6_vdln_total;
			$sheet_7_vdln_total=$this->sheet_7_vdln_total;
			$sheet_8_vdln_total=$this->sheet_8_vdln_total;
			$sheet_9_vdln_total=$this->sheet_9_vdln_total;
			
			$sheet_6_vdlw_error=$this->sheet_6_vdlw_error;
			$sheet_7_vdlw_error=$this->sheet_7_vdlw_error;
			$sheet_8_vdlw_error=$this->sheet_8_vdlw_error;
			$sheet_9_vdlw_error=$this->sheet_9_vdlw_error;
			$sheet_6_vdlw_total=$this->sheet_6_vdlw_total;
			$sheet_7_vdlw_total=$this->sheet_7_vdlw_total;
			$sheet_8_vdlw_total=$this->sheet_8_vdlw_total;
			$sheet_9_vdlw_total=$this->sheet_9_vdlw_total;
			
			
$sheet_6_error=$sheet_6_vdds_error+$sheet_6_vddl_error+$sheet_6_vddn_error+$sheet_6_vddw_error;
$sheet_7_error=$sheet_7_vdds_error+$sheet_7_vddl_error+$sheet_7_vddn_error+$sheet_7_vddw_error;
$sheet_8_error=$sheet_8_vdls_error+$sheet_8_vdll_error+$sheet_8_vdln_error+$sheet_8_vdlw_error;
$sheet_9_error=$sheet_9_vdls_error+$sheet_9_vdll_error+$sheet_9_vdln_error+$sheet_9_vdlw_error;
			
$vd_to_send_for_code=array();
if($sheet_6_error>2)
{
	if($sheet_6_vdds_error>=1)
	{
		$vd_to_send_for_code[]="vdds";
	}
	if($sheet_6_vddl_error>=1)
	{
		$vd_to_send_for_code[]="vddl";
	}
	if($sheet_6_vddn_error>=1)
	{
		$vd_to_send_for_code[]="vddn";
	}
	if($sheet_6_vddw_error>=1)
	{
		$vd_to_send_for_code[]="vddw";
	}
}

if($sheet_7_error>2)
{
	if($sheet_7_vdds_error>=1)
	{
		$vd_to_send_for_code[]="vdds";
	}
	if($sheet_7_vddl_error>=1)
	{
		$vd_to_send_for_code[]="vddl";
	}
	if($sheet_7_vddn_error>=1)
	{
		$vd_to_send_for_code[]="vddn";
	}
	if($sheet_7_vddw_error>=1)
	{
		$vd_to_send_for_code[]="vddw";
	}
}
if($sheet_8_error>2)
{
	if($sheet_8_vdls_error>=1)
	{
		$vd_to_send_for_code[]="vdls";
	}
	if($sheet_8_vdll_error>=1)
	{
		$vd_to_send_for_code[]="vdll";
	}
	if($sheet_8_vdln_error>=1)
	{
		$vd_to_send_for_code[]="vdln";
	}
	if($sheet_8_vdlw_error>=1)
	{
		$vd_to_send_for_code[]="vdlw";
	}
}
if($sheet_9_error>2)
{
	if($sheet_9_vdls_error>=1)
	{
		$vd_to_send_for_code[]="vdls";
	}
	if($sheet_9_vdll_error>=1)
	{
		$vd_to_send_for_code[]="vdll";
	}
	if($sheet_9_vdln_error>=1)
	{
		$vd_to_send_for_code[]="vdln";
	}
	if($sheet_9_vdlw_error>=1)
	{
		$vd_to_send_for_code[]="vdlw";
	}
}

for($i=0;$i<count($vd_to_send_for_code);$i++)
{
		$treatment_to_send_for=$error_slot_2;
		$code=$vd_to_send_for_code[$i];
		
		$prepared_statement_4=" SELECT * FROM shristi_treatments WHERE for_std='$treatment_to_send_for' AND code='$code' AND for_month>0 AND for_week>0 AND for_day>0 ";
		$res_temp=$mysql_obj->simply_run_statement_passed($prepared_statement_4);
		if($res_temp->num_rows>0)
		{
			while($detail_temp=$res_temp->fetch_assoc())
			{
			$treatment_id=$detail_temp['table_id'];
			
			if($detail_temp['for_month']==1)
			{
				$start_date=$today_date;
				
				$temp_3 = new DateTime();
				$temp_3->modify('+1 months');
				$end_date=$temp_3->format('Y-m-d');
			}
			else
			{
				$today_date;
				$temp_var_1=$detail_temp['for_month'];
				$temp_var_2=$temp_var_1-1;
				
				$temp_3 = new DateTime();
				$temp_3->modify('+'.$temp_var_2.' months');
				$start_date=$temp_3->format('Y-m-d');
				
				$temp_3 = new DateTime();
				$temp_3->modify('+'.$temp_var_1.' months');
				$end_date=$temp_3->format('Y-m-d');
			}
			
			$prepared_statement_3="INSERT INTO shristi_treatments_available(ref_no,treatment_id,start_date,end_date,for_week,for_day,created_by,created_ip,created_browser) VALUES('$ref_no','$treatment_id','$start_date','$end_date','{$detail_temp['for_week']}','{$detail_temp['for_day']}','{$_SESSION['log_id']}','{$_SERVER['REMOTE_ADDR']}','{$_SERVER['HTTP_USER_AGENT']}')";
			if(!($mysql_obj->simply_run_statement_passed($prepared_statement_3)))
			{
				$mysql_obj->rollback();
				$mysql_obj->close_connection();
				echo("Error : Couldn't save answers 5...");
				exit();
			}
			}
		}
		/*else
		{
			$mysql_obj->rollback();
			$mysql_obj->close_connection();
			echo("Treatment Not found for following :-<br>Code - ".$code."<br>Std - ".$treatment_to_send_for."<br>From Day : 0");
			exit();
		}*/
}

for($i=0;$i<count($array_error_type_1_val);$i++)
{
	$treatment_to_send_for="none";
	if($array_error_type_1_val[$i]>70)
	{
		$treatment_to_send_for=$error_slot_4;
	}
	else if($array_error_type_1_val[$i]>40)
	{
		$treatment_to_send_for=$error_slot_3;
	}
	else if($array_error_type_1_val[$i]>20)
	{
		$treatment_to_send_for=$error_slot_2;
	}
	
	
	if($treatment_to_send_for!="none")
	{
		$code=$array_error_type_1[$i];
		$prepared_statement_4="SELECT * FROM shristi_treatments WHERE for_std='$treatment_to_send_for' AND code='$code' AND for_month>0 AND for_week>0 AND for_day>0";
		$res_temp=$mysql_obj->simply_run_statement_passed($prepared_statement_4);
		if($res_temp->num_rows>0)
		{
			while($detail_temp=$res_temp->fetch_assoc())
			{
			$treatment_id=$detail_temp['table_id'];
			
			if($detail_temp['for_month']==1)
			{
				$start_date=$today_date;
				
				$temp_3 = new DateTime();
				$temp_3->modify('+1 months');
				$end_date=$temp_3->format('Y-m-d');
			}
			else
			{
				$today_date;
				$temp_var_1=$detail_temp['for_month'];
				$temp_var_2=$temp_var_1-1;
				
				$temp_3 = new DateTime();
				$temp_3->modify('+'.$temp_var_2.' months');
				$start_date=$temp_3->format('Y-m-d');
				
				$temp_3 = new DateTime();
				$temp_3->modify('+'.$temp_var_1.' months');
				$end_date=$temp_3->format('Y-m-d');
			}
			
			$prepared_statement_3="INSERT INTO shristi_treatments_available(ref_no,treatment_id,start_date,end_date,for_week,for_day,created_by,created_ip,created_browser) VALUES('$ref_no','$treatment_id','$start_date','$end_date','{$detail_temp['for_week']}','{$detail_temp['for_day']}','{$_SESSION['log_id']}','{$_SERVER['REMOTE_ADDR']}','{$_SERVER['HTTP_USER_AGENT']}')";
			if(!($mysql_obj->simply_run_statement_passed($prepared_statement_3)))
			{
				$mysql_obj->rollback();
				$mysql_obj->close_connection();
				echo("Error : Couldn't save answers 5...");
				exit();
			}
			}
		}
		/*else
		{
			$mysql_obj->rollback();
			$mysql_obj->close_connection();
			echo("Treatment Not found for following :-<br>Code - ".$code."<br>Std - ".$treatment_to_send_for."<br>From Day : 0");
			exit();
		}*/
	}
}

$vdsw_error_codes_array=$this->vdsw_error_codes_array;
for($i=0;$i<count($vdsw_error_codes_array);$i++)
{
	$code=$vdsw_error_codes_array[$i];
	$prepared_statement_4="SELECT * FROM shristi_treatments WHERE for_std='$treatment_to_send_for' AND code='$code' AND for_month>0 AND for_week>0 AND for_day>0";
	$res_temp=$mysql_obj->simply_run_statement_passed($prepared_statement_4);
	if($res_temp->num_rows>0)
	{
		while($detail_temp=$res_temp->fetch_assoc())
		{
			$treatment_id=$detail_temp['table_id'];
			
			if($detail_temp['for_month']==1)
			{
				$start_date=$today_date;
				
				$temp_3 = new DateTime();
				$temp_3->modify('+1 months');
				$end_date=$temp_3->format('Y-m-d');
			}
			else
			{
				$today_date;
				$temp_var_1=$detail_temp['for_month'];
				$temp_var_2=$temp_var_1-1;
				
				$temp_3 = new DateTime();
				$temp_3->modify('+'.$temp_var_2.' months');
				$start_date=$temp_3->format('Y-m-d');
				
				$temp_3 = new DateTime();
				$temp_3->modify('+'.$temp_var_1.' months');
				$end_date=$temp_3->format('Y-m-d');
			}
			
			$prepared_statement_3="INSERT INTO shristi_treatments_available(ref_no,treatment_id,start_date,end_date,for_week,for_day,created_by,created_ip,created_browser) VALUES('$ref_no','$treatment_id','$start_date','$end_date','{$detail_temp['for_week']}','{$detail_temp['for_day']}','{$_SESSION['log_id']}','{$_SERVER['REMOTE_ADDR']}','{$_SERVER['HTTP_USER_AGENT']}')";
			if(!($mysql_obj->simply_run_statement_passed($prepared_statement_3)))
			{
				$mysql_obj->rollback();
				$mysql_obj->close_connection();
				echo("Error : Couldn't save answers 5...");
				exit();
			}
		}
	}
	/*else
	{
		$mysql_obj->rollback();
		$mysql_obj->close_connection();
		echo("Treatment Not found for following :-<br>Code - ".$code);
		exit();
	}*/
}


if($vmc_percent>0)
{
	$code="VMC";
	$treatment_to_send_for=$error_slot_2;
	$prepared_statement_4="SELECT * FROM shristi_treatments WHERE for_std='$treatment_to_send_for' AND code='$code' AND for_month>0 AND for_week>0 AND for_day>0";
	$res_temp=$mysql_obj->simply_run_statement_passed($prepared_statement_4);
	if($res_temp->num_rows>0)
	{
		while($detail_temp=$res_temp->fetch_assoc())
		{
			$treatment_id=$detail_temp['table_id'];
			
			if($detail_temp['for_month']==1)
			{
				$start_date=$today_date;
				
				$temp_3 = new DateTime();
				$temp_3->modify('+1 months');
				$end_date=$temp_3->format('Y-m-d');
			}
			else
			{
				$today_date;
				$temp_var_1=$detail_temp['for_month'];
				$temp_var_2=$temp_var_1-1;
				
				$temp_3 = new DateTime();
				$temp_3->modify('+'.$temp_var_2.' months');
				$start_date=$temp_3->format('Y-m-d');
				
				$temp_3 = new DateTime();
				$temp_3->modify('+'.$temp_var_1.' months');
				$end_date=$temp_3->format('Y-m-d');
			}
			
			$prepared_statement_3="INSERT INTO shristi_treatments_available(ref_no,treatment_id,start_date,end_date,for_week,for_day,created_by,created_ip,created_browser) VALUES('$ref_no','$treatment_id','$start_date','$end_date','{$detail_temp['for_week']}','{$detail_temp['for_day']}','{$_SESSION['log_id']}','{$_SERVER['REMOTE_ADDR']}','{$_SERVER['HTTP_USER_AGENT']}')";
			if(!($mysql_obj->simply_run_statement_passed($prepared_statement_3)))
			{
				$mysql_obj->rollback();
				$mysql_obj->close_connection();
				echo("Error : Couldn't save answers 5...");
				exit();
			}
		}
	}
	/*else
	{
		$mysql_obj->rollback();
		$mysql_obj->close_connection();
		echo("Treatment Not found for following :-<br>Code - ".$code);
		exit();
	}*/
}


for($i=0;$i<count($array_error_type_4_val);$i++)
{
	$treatment_to_send_for="none";
	if($array_error_type_4_val[$i]>13.33)
	{
		$treatment_to_send_for=$error_slot_2;
	}
	
	
	if($treatment_to_send_for!="none")
	{
		$code=$array_error_type_4[$i];
		
		$prepared_statement_4="SELECT * FROM shristi_treatments WHERE for_std='$treatment_to_send_for' AND code='$code' AND for_month>0 AND for_week>0 AND for_day>0";
		$res_temp=$mysql_obj->simply_run_statement_passed($prepared_statement_4);
		if($res_temp->num_rows>0)
		{
			while($detail_temp=$res_temp->fetch_assoc())
			{
			$treatment_id=$detail_temp['table_id'];
			
			
			if($detail_temp['for_month']==1)
			{
				$start_date=$today_date;
				
				$temp_3 = new DateTime();
				$temp_3->modify('+1 months');
				$end_date=$temp_3->format('Y-m-d');
			}
			else
			{
				$today_date;
				$temp_var_1=$detail_temp['for_month'];
				$temp_var_2=$temp_var_1-1;
				
				$temp_3 = new DateTime();
				$temp_3->modify('+'.$temp_var_2.' months');
				$start_date=$temp_3->format('Y-m-d');
				
				$temp_3 = new DateTime();
				$temp_3->modify('+'.$temp_var_1.' months');
				$end_date=$temp_3->format('Y-m-d');
			}
			
			
			$prepared_statement_3="INSERT INTO shristi_treatments_available(ref_no,treatment_id,start_date,end_date,for_week,for_day,created_by,created_ip,created_browser) VALUES('$ref_no','$treatment_id','$start_date','$end_date','{$detail_temp['for_week']}','{$detail_temp['for_day']}','{$_SESSION['log_id']}','{$_SERVER['REMOTE_ADDR']}','{$_SERVER['HTTP_USER_AGENT']}')";
			if(!($mysql_obj->simply_run_statement_passed($prepared_statement_3)))
			{
				$mysql_obj->rollback();
				$mysql_obj->close_connection();
				echo("Error : Couldn't save answers 5...");
				exit();
			}
			}
		}
		/*else
		{
			$mysql_obj->rollback();
			$mysql_obj->close_connection();
			echo("Treatment Not found for following :-<br>Code - ".$code."<br>Std - ".$treatment_to_send_for."<br>From Day : 0");
			exit();
		}*/
	}
}

		
		$mysql_obj->commit();
		$mysql_obj->close_connection();
		unset($_SESSION['screening_started']);
		unset($_SESSION['ref_no']);
		unset($_SESSION['screening_id']);
		unset($_SESSION['section_count']);
		unset($_SESSION['ongoing_section_no']);
		unset($_SESSION['start_time']);
		header ("location:view_questionnaire_report.php?ref_no=".$ref_no."&screening_id=".$screening_id);
	}
	public function delete_previous_student_ans($ref_no,$screening_id)
	{
		$today_date=date("Y-m-d");
		$mysql_obj=new mysql_functions_class;
		$mysql_obj->open_connection();
		$ref_no=$mysql_obj->real_escape($ref_no);
		$screening_id=$mysql_obj->real_escape($screening_id);
		$prepared_statement="UPDATE shristi_child_details SET registration_date='$today_date' WHERE table_id='$ref_no' AND franchise_id='{$_SESSION['log_id']}' AND registration_date='0000-00-00'";
		$mysql_obj->simply_run_statement_passed($prepared_statement);
		$prepared_statement="DELETE FROM shristi_questionnaires_temp_answers WHERE ref_no='$ref_no' AND screening_id='$screening_id'";
		$mysql_obj->simply_run_statement_passed($prepared_statement);
		$prepared_statement="DELETE FROM shristi_questionnaires_permanent_answers WHERE ref_no='$ref_no' AND screening_id='$screening_id'";
		$mysql_obj->simply_run_statement_passed($prepared_statement);
		$mysql_obj->close_connection();
	}
	public function student_questionnaire_report($ref_no,$screening_id,&$vdds_percent,&$vddl_percent,&$vddn_percent,&$vddw_percent,&$vdls_percent,&$vdll_percent,&$vdln_percent,&$vdlw_percent,&$vdsw_percent,&$vmc_percent,&$ad_percent,&$ac_percent,&$vc_percent,&$wrong_vdds,&$total_vdds,&$wrong_vddl,&$total_vddl,&$wrong_vddn,&$total_vddn,&$wrong_vddw,&$total_vddw,&$wrong_vdls,&$total_vdls,&$wrong_vdll,&$total_vdll,&$wrong_vdln,&$total_vdln,&$wrong_vdlw,&$total_vdlw,&$wrong_vdsw,&$total_vdsw,&$wrong_vmc,&$total_vmc,&$wrong_ad,&$total_ad,&$wrong_ac,&$total_ac,&$wrong_vc,&$total_vc)
	{
		$mysql_obj=new mysql_functions_class;
		$mysql_obj->open_connection();
		$ref_no=$mysql_obj->real_escape($ref_no);
		$screening_id=$mysql_obj->real_escape($screening_id);
		$prepared_statement_2="SELECT DATE(created_date) AS screening_date FROM shristi_questionnaires_permanent_answers WHERE ref_no='$ref_no' AND screening_id='$screening_id' LIMIT 0,1";
		$res_2=$mysql_obj->simply_run_statement_passed($prepared_statement_2);
		if($res_2->num_rows==1)
		{
			$detail_2=$res_2->fetch_assoc();
			$dob=$detail_2['screening_date'];
			if($dob!="0000-00-00")
			{
				$date_obj = new DateTime($dob);
				$dob=$date_obj->format('d-M-Y');
				$this->screening_date=$dob;
			}
		}
		$prepared_statement="SELECT a.answer,a.sub_question_id,b.code,b.code_sub_1,b.code_sub_2,b.ans_key,b.sub_questionnaire_codes,b.wrong_keys,c.for_std FROM shristi_questionnaires_permanent_answers a INNER JOIN shristi_questionnaires_sub_questions b ON b.table_id=a.sub_question_id INNER JOIN shristi_questionnaires c ON c.table_id='$screening_id' WHERE a.ref_no='$ref_no' AND a.screening_id='$screening_id'";
		$res=$mysql_obj->simply_run_statement_passed($prepared_statement);
		$mysql_obj->close_connection();
		/*$wrong_vdds=0;
		$total_vdds=0;
		$wrong_vddl=0;
		$total_vddl=0;
		$wrong_vddn=0;
		$total_vddn=0;
		$wrong_vddw=0;
		$total_vddw=0;
		$wrong_vdsw=0;
		$total_vdsw=0;
		$wrong_vmc=0;
		$total_vmc=0;
		$wrong_ad=0;
		$total_ad=0;
		$wrong_ac=0;
		$total_ac=0;
		$wrong_vc=0;
		$total_vc=0;*/
			
			$sheet_6_vdds_error=0;
			$sheet_7_vdds_error=0;
			$sheet_8_vdds_error=0;
			$sheet_9_vdds_error=0;
			$sheet_6_vdds_total=0;
			$sheet_7_vdds_total=0;
			$sheet_8_vdds_total=0;
			$sheet_9_vdds_total=0;
			
			$sheet_6_vddl_error=0;
			$sheet_7_vddl_error=0;
			$sheet_8_vddl_error=0;
			$sheet_9_vddl_error=0;
			$sheet_6_vddl_total=0;
			$sheet_7_vddl_total=0;
			$sheet_8_vddl_total=0;
			$sheet_9_vddl_total=0;
			
			$sheet_6_vddn_error=0;
			$sheet_7_vddn_error=0;
			$sheet_8_vddn_error=0;
			$sheet_9_vddn_error=0;
			$sheet_6_vddn_total=0;
			$sheet_7_vddn_total=0;
			$sheet_8_vddn_total=0;
			$sheet_9_vddn_total=0;
			
			$sheet_6_vddw_error=0;
			$sheet_7_vddw_error=0;
			$sheet_8_vddw_error=0;
			$sheet_9_vddw_error=0;
			$sheet_6_vddw_total=0;
			$sheet_7_vddw_total=0;
			$sheet_8_vddw_total=0;
			$sheet_9_vddw_total=0;
			
			
			$sheet_6_vdls_error=0;
			$sheet_7_vdls_error=0;
			$sheet_8_vdls_error=0;
			$sheet_9_vdls_error=0;
			$sheet_6_vdls_total=0;
			$sheet_7_vdls_total=0;
			$sheet_8_vdls_total=0;
			$sheet_9_vdls_total=0;
			
			$sheet_6_vdll_error=0;
			$sheet_7_vdll_error=0;
			$sheet_8_vdll_error=0;
			$sheet_9_vdll_error=0;
			$sheet_6_vdll_total=0;
			$sheet_7_vdll_total=0;
			$sheet_8_vdll_total=0;
			$sheet_9_vdll_total=0;
			
			$sheet_6_vdln_error=0;
			$sheet_7_vdln_error=0;
			$sheet_8_vdln_error=0;
			$sheet_9_vdln_error=0;
			$sheet_6_vdln_total=0;
			$sheet_7_vdln_total=0;
			$sheet_8_vdln_total=0;
			$sheet_9_vdln_total=0;
			
			$sheet_6_vdlw_error=0;
			$sheet_7_vdlw_error=0;
			$sheet_8_vdlw_error=0;
			$sheet_9_vdlw_error=0;
			$sheet_6_vdlw_total=0;
			$sheet_7_vdlw_total=0;
			$sheet_8_vdlw_total=0;
			$sheet_9_vdlw_total=0;
			
			$sub_question_escaped_from_report=array("20");
			$vdsw_error_codes_array=$this->vdsw_error_codes_array;
		while($detail=$res->fetch_assoc())
		{
			$code_1=$detail['code'];
			$code_2=$detail['code_sub_1'];
			$code_3=$detail['code_sub_2'];
			$code_1_array=explode("!@!@",$code_1);
			
			//VDDS
			if($code_2=="VDDS")
			{
				$total_vdds++;
				if($detail['answer']!=$detail['ans_key'])
				{
					$wrong_vdds++;
					
					//1st grade
					if($detail['for_std']=="1")
					{
						if($detail['sub_questionnaire_codes']=="6")
						{
							$sheet_6_vdds_error++;
						}
					}
					
					// no question available in 2nd grade
				}
				
				//1st grade total for sheet
				if($detail['sub_questionnaire_codes']=="6")
				{
					$sheet_6_vdds_total++;
				}
			}
			
			//VDDL
			if($code_2=="VDDL")
			{
				$total_vddl++;
				if($detail['answer']!=$detail['ans_key'])
				{
					$wrong_vddl++;
					
					//1st grade
					if($detail['for_std']=="1")
					{
						if($detail['sub_questionnaire_codes']=="7")
						{
							$sheet_7_vddl_error++;
						}
					}
					// no question available in 2nd grade
				}
				
				//1st grade total for sheet
				if($detail['sub_questionnaire_codes']=="7")
				{
					$sheet_7_vddl_total++;
				}
			}
			
			//VDDN
			if($code_2=="VDDN")
			{
				$total_vddn++;
				if($detail['answer']!=$detail['ans_key'])
				{
					$wrong_vddn++;
					if($detail['for_std']=="1")
					{
						if($detail['sub_questionnaire_codes']=="6")
						{
							$sheet_6_vddn_error++;
						}
					}
					elseif($detail['for_std']=="2")
					{
						if($detail['sub_questionnaire_codes']=="15")
						{
							$sheet_6_vddn_error++;
						}
					}
					elseif($detail['for_std']=="3")
					{
						if($detail['sub_questionnaire_codes']=="24")
						{
							$sheet_6_vddn_error++;
						}
					}
					elseif($detail['for_std']=="4")
					{
						if($detail['sub_questionnaire_codes']=="32")
						{
							$sheet_6_vddn_error++;
						}
					}
				}
				
				if($detail['sub_questionnaire_codes']=="6")
				{
					$sheet_6_vddn_total++;
				}
				elseif($detail['sub_questionnaire_codes']=="15")
				{
					$sheet_6_vddn_total++;
				}
				elseif($detail['sub_questionnaire_codes']=="24")
				{
					$sheet_6_vddn_total++;
				}
				elseif($detail['sub_questionnaire_codes']=="32")
				{
					$sheet_6_vddn_total++;
				}
			}
			
			//VDDW
			if($code_2=="VDDW")
			{
				$total_vddw++;
				if($detail['answer']!=$detail['ans_key'])
				{
					$wrong_vddw++;
					if($detail['for_std']=="1")
					{
						if($detail['sub_questionnaire_codes']=="7")
						{
							$sheet_7_vddw_error++;
						}
						elseif($detail['sub_questionnaire_codes']=="15")
						{
							$sheet_6_vddw_error++;
						}
						elseif($detail['sub_questionnaire_codes']=="24")
						{
							$sheet_6_vddw_error++;
						}
						elseif($detail['sub_questionnaire_codes']=="32")
						{
							$sheet_6_vddw_error++;
						}
					}
				}
				
				if($detail['sub_questionnaire_codes']=="7")
				{
					$sheet_7_vddw_total++;
				}
				elseif($detail['sub_questionnaire_codes']=="15")
				{
					$sheet_6_vddw_total++;
				}
				elseif($detail['sub_questionnaire_codes']=="24")
				{
					$sheet_6_vddw_total++;
				}
				elseif($detail['sub_questionnaire_codes']=="32")
				{
					$sheet_6_vddw_total++;
				}
			}			
			
			//VDLS
			if($code_2=="VDLS")
			{
				$total_vdls++;
				if($detail['answer']!=$detail['ans_key'])
				{
					$wrong_vdls++;
					if($detail['for_std']=="1")
					{
						if($detail['sub_questionnaire_codes']=="8")
						{
							$sheet_8_vdls_error++;
						}
					}
				}
				
				if($detail['sub_questionnaire_codes']=="8")
				{
					$sheet_8_vdls_total++;
				}
			}
			
			//VDLN
			if($code_2=="VDLN")
			{
				$total_vdln++;
				if($detail['answer']!=$detail['ans_key'])
				{
					$wrong_vdln++;
					if($detail['for_std']=="1")
					{
						if($detail['sub_questionnaire_codes']=="8")
						{
							$sheet_8_vdln_error++;
						}
						else if($detail['sub_questionnaire_codes']=="18")
						{
							$sheet_7_vdln_error++;// 7 is correct
						}
						else if($detail['sub_questionnaire_codes']=="25")
						{
							$sheet_7_vdln_error++;// 7 is correct
						}
						else if($detail['sub_questionnaire_codes']=="33")
						{
							$sheet_7_vdln_error++;// 7 is correct
						}
					}
				}
				
				if($detail['sub_questionnaire_codes']=="8")
				{
					$sheet_8_vdln_total++;
				}
				elseif($detail['sub_questionnaire_codes']=="18")
				{
					$sheet_7_vdln_total++;// 7 is correct
				}
				elseif($detail['sub_questionnaire_codes']=="25")
				{
					$sheet_7_vdln_total++;// 7 is correct
				}
				elseif($detail['sub_questionnaire_codes']=="33")
				{
					$sheet_7_vdln_total++;// 7 is correct
				}
			}
			
			
			//VDLL
			if($code_2=="VDLL")
			{
				$total_vdll++;
				if($detail['answer']!=$detail['ans_key'])
				{
					$wrong_vdll++;
					if($detail['for_std']=="1")
					{
						if($detail['sub_questionnaire_codes']=="9")
						{
							$sheet_9_vdll_error++;
						}
					}
				}
				
				if($detail['sub_questionnaire_codes']=="9")
				{
					$sheet_9_vdll_total++;
				}
			}
			
			//VDLW
			if($code_2=="VDLW")
			{
				$total_vdlw++;
				if($detail['answer']!=$detail['ans_key'])
				{
					$wrong_vdlw++;
					if($detail['for_std']=="1")
					{
						if($detail['sub_questionnaire_codes']=="9")
						{
							$sheet_9_vdlw_error++;
						}
						elseif($detail['sub_questionnaire_codes']=="18")
						{
							$sheet_7_vdlw_error++; // 7 is correct
						}
						elseif($detail['sub_questionnaire_codes']=="25")
						{
							$sheet_7_vdlw_error++; // 7 is correct
						}
						elseif($detail['sub_questionnaire_codes']=="33")
						{
							$sheet_7_vdlw_error++; // 7 is correct
						}
					}
				}
				
				if($detail['sub_questionnaire_codes']=="9")
				{
					$sheet_9_vdlw_total++;
				}
				elseif($detail['sub_questionnaire_codes']=="18")
				{
					$sheet_7_vdlw_total++; // 7 is correct
				}
				elseif($detail['sub_questionnaire_codes']=="25")
				{
					$sheet_7_vdlw_total++; // 7 is correct
				}
				elseif($detail['sub_questionnaire_codes']=="33")
				{
					$sheet_7_vdlw_total++; // 7 is correct
				}
			}
			
			//VDSW
			if($code_2=="VDSW")
			{
				if($detail['answer']!=$detail['ans_key'])
				{
					$wrong_vdsw++;
					$code_to_add=$detail['code_sub_2'];
					if(!in_array($code_to_add,$vdsw_error_codes_array))
					{
						$vdsw_error_codes_array[]=$code_to_add;
					}
				}
				$total_vdsw++;
			}
			
			//VMC
			if($code_2=="VMC")
			{
				if(!(in_array($detail['sub_question_id'],$sub_question_escaped_from_report)))
				{
					$wrong_keys=$detail['wrong_keys'];
					$wrong_keys_array=explode("!@!@",$wrong_keys);
					if(in_array($detail['answer'],$wrong_keys_array))
					{
						$wrong_vmc++;
					}
					$total_vmc++;
				}
			}
			
			//AD
			if($code_1=="AD")
			{
				if($detail['answer']!=$detail['ans_key'])
				{
					$wrong_ad++;
				}
				$total_ad++;
			}
			
			//AC
			if($code_1=="AC")
			{
				if($detail['answer']!=$detail['ans_key'])
				{
					$wrong_ac++;
				}
				$total_ac++;
			}
			
			//VC
			if($code_1=="VC")
			{
				if($detail['answer']!=$detail['ans_key'])
				{
					$wrong_vc++;
				}
				$total_vc++;
			}
		}
			$this->vdsw_error_codes_array=$vdsw_error_codes_array;
			
			$this->sheet_6_vdds_error=$sheet_6_vdds_error;
			$this->sheet_7_vdds_error=$sheet_6_vdds_error;
			$this->sheet_8_vdds_error=$sheet_8_vdds_error;
			$this->sheet_9_vdds_error=$sheet_9_vdds_error;
			$this->sheet_6_vdds_total=$sheet_6_vdds_total;
			$this->sheet_7_vdds_total=$sheet_7_vdds_total;
			$this->sheet_8_vdds_total=$sheet_8_vdds_total;
			$this->sheet_9_vdds_total=$sheet_9_vdds_total;
			
			$this->sheet_6_vddl_error=$sheet_6_vddl_error;
			$this->sheet_7_vddl_error=$sheet_7_vddl_error;
			$this->sheet_8_vddl_error=$sheet_8_vddl_error;
			$this->sheet_9_vddl_error=$sheet_9_vddl_error;
			$this->sheet_6_vddl_total=$sheet_6_vddl_total;
			$this->sheet_7_vddl_total=$sheet_7_vddl_total;
			$this->sheet_8_vddl_total=$sheet_8_vddl_total;
			$this->sheet_9_vddl_total=$sheet_9_vddl_total;
			
			$this->sheet_6_vddn_error=$sheet_6_vddn_error;
			$this->sheet_7_vddn_error=$sheet_7_vddn_error;
			$this->sheet_8_vddn_error=$sheet_8_vddn_error;
			$this->sheet_9_vddn_error=$sheet_9_vddn_error;
			$this->sheet_6_vddn_total=$sheet_6_vddn_total;
			$this->sheet_7_vddn_total=$sheet_7_vddn_total;
			$this->sheet_8_vddn_total=$sheet_8_vddn_total;
			$this->sheet_9_vddn_total=$sheet_9_vddn_total;
			
			$this->sheet_6_vddw_error=$sheet_6_vddw_error;
			$this->sheet_7_vddw_error=$sheet_7_vddw_error;
			$this->sheet_8_vddw_error=$sheet_8_vddw_error;
			$this->sheet_9_vddw_error=$sheet_9_vddw_error;
			$this->sheet_6_vddw_total=$sheet_6_vddw_total;
			$this->sheet_7_vddw_total=$sheet_7_vddw_total;
			$this->sheet_8_vddw_total=$sheet_8_vddw_total;
			$this->sheet_9_vddw_total=$sheet_9_vddw_total;
			
			
			
			
			$this->sheet_6_vdls_error=$sheet_6_vdls_error;
			$this->sheet_7_vdls_error=$sheet_6_vdls_error;
			$this->sheet_8_vdls_error=$sheet_8_vdls_error;
			$this->sheet_9_vdls_error=$sheet_9_vdls_error;
			$this->sheet_6_vdls_total=$sheet_6_vdls_total;
			$this->sheet_7_vdls_total=$sheet_7_vdls_total;
			$this->sheet_8_vdls_total=$sheet_8_vdls_total;
			$this->sheet_9_vdls_total=$sheet_9_vdls_total;
			
			$this->sheet_6_vdll_error=$sheet_6_vdll_error;
			$this->sheet_7_vdll_error=$sheet_7_vdll_error;
			$this->sheet_8_vdll_error=$sheet_8_vdll_error;
			$this->sheet_9_vdll_error=$sheet_9_vdll_error;
			$this->sheet_6_vdll_total=$sheet_6_vdll_total;
			$this->sheet_7_vdll_total=$sheet_7_vdll_total;
			$this->sheet_8_vdll_total=$sheet_8_vdll_total;
			$this->sheet_9_vdll_total=$sheet_9_vdll_total;
			
			$this->sheet_6_vdln_error=$sheet_6_vdln_error;
			$this->sheet_7_vdln_error=$sheet_7_vdln_error;
			$this->sheet_8_vdln_error=$sheet_8_vdln_error;
			$this->sheet_9_vdln_error=$sheet_9_vdln_error;
			$this->sheet_6_vdln_total=$sheet_6_vdln_total;
			$this->sheet_7_vdln_total=$sheet_7_vdln_total;
			$this->sheet_8_vdln_total=$sheet_8_vdln_total;
			$this->sheet_9_vdln_total=$sheet_9_vdln_total;
			
			$this->sheet_6_vdlw_error=$sheet_6_vdlw_error;
			$this->sheet_7_vdlw_error=$sheet_7_vdlw_error;
			$this->sheet_8_vdlw_error=$sheet_8_vdlw_error;
			$this->sheet_9_vdlw_error=$sheet_9_vdlw_error;
			$this->sheet_6_vdlw_total=$sheet_6_vdlw_total;
			$this->sheet_7_vdlw_total=$sheet_7_vdlw_total;
			$this->sheet_8_vdlw_total=$sheet_8_vdlw_total;
			$this->sheet_9_vdlw_total=$sheet_9_vdlw_total;
			
		if(($total_vdds!="0")&&($total_vdds!=0)&&($total_vdds!=""))
		{
			$vdds_percent=round((($wrong_vdds/$total_vdds)*100),2);
		}
		if(($total_vddl!="0")&&($total_vddl!=0)&&($total_vddl!=""))
		{
			$vddl_percent=round((($wrong_vddl/$total_vddl)*100),2);
		}
		if(($total_vddn!="0")&&($total_vddn!=0)&&($total_vddn!=""))
		{
			$vddn_percent=round((($wrong_vddn/$total_vddn)*100),2);
		}
		if(($total_vddw!="0")&&($total_vddw!=0)&&($total_vddw!=""))
		{
			$vddw_percent=round((($wrong_vddw/$total_vddw)*100),2);
		}
		
		if(($total_vdls!="0")&&($total_vdls!=0)&&($total_vdls!=""))
		{
			$vdls_percent=round((($wrong_vdls/$total_vdls)*100),2);
		}
		if(($total_vdll!="0")&&($total_vdll!=0)&&($total_vdll!=""))
		{
			$vdll_percent=round((($wrong_vdll/$total_vdll)*100),2);
		}
		if(($total_vdln!="0")&&($total_vdln!=0)&&($total_vdln!=""))
		{
			$vdln_percent=round((($wrong_vdln/$total_vdln)*100),2);
		}
		if(($total_vdlw!="0")&&($total_vdlw!=0)&&($total_vdlw!=""))
		{
			$vdlw_percent=round((($wrong_vdlw/$total_vdlw)*100),2);
		}
		
		if(($total_vdsw!="0")&&($total_vdsw!=0)&&($total_vdsw!=""))
		{
			$vdsw_percent=round((($wrong_vdsw/$total_vdsw)*100),2);
		}
		if(($total_vmc!="0")&&($total_vmc!=0)&&($total_vmc!=""))
		{
			$vmc_percent=round((($wrong_vmc/$total_vmc)*100),2);
		}
		if(($total_ad!="0")&&($total_ad!=0)&&($total_ad!=""))
		{
			$ad_percent=round((($wrong_ad/$total_ad)*100),2);
		}
		if(($total_ac!="0")&&($total_ac!=0)&&($total_ac!=""))
		{
			$ac_percent=round((($wrong_ac/$total_ac)*100),2);
		}
		if(($total_vc!="0")&&($total_vc!=0)&&($total_vc!=""))
		{
			$vc_percent=round((($wrong_vc/$total_vc)*100),2);
		}
	}
}
?>