Current File : /home/inlingua/public_html/sensoriumpsychologists.com/diagnostics/screening/question-process.php
<?php include('../franchise_back/connection.php');

$mysqli = new mysqli($host_db,$user_db,$pass_db,$name_db);

if ($mysqli -> connect_errno) {
  echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
  exit();
} 
 session_start();

 
if(isset($_POST['submit']))
{
  
 $spoint=$_POST['next']-1;
 $start=$_POST['next'];
 $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";
 
 $ref_no=$_SESSION['ref_no'];
 $franchise_id=$_SESSION['log_id'];
 $screening_id=$_SESSION['screening_id'];
 $ongoing_section_no=$_SESSION['ongoing_section_no'];
 $created_by=$_SESSION['log_id'];
 $created_ip=$_SERVER['SERVER_ADDR'];
 $created_browser=$_SERVER['HTTP_USER_AGENT'];
 //echo $_POST['next'];
 
 for($i=$spoint; $i<=$_POST['next']; $i++)
	{
		$to_check="question_".$i;
		if(isset($_POST[$to_check]))
		{
		$ques=$_POST[$to_check];
		$ans_name="ans_".$ques;
		}else{
			$ans_name=0;
		}
		if(isset($_POST[$ans_name]))
		{
		$ans=$_POST[$ans_name];
		}else{
			$ans='0';
		}
		if($ans>0)
		{
		$del="delete from shristi_questionnaires_temp_answers where franchise_id='".$franchise_id."' and ref_no='".$ref_no."' and screening_id='".$screening_id."' and main_question_id='".$ongoing_section_no."' and sub_question_id='".$ques."'";
		
		$mysqli -> query($del);
		
	 	$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('$franchise_id','$ref_no','$screening_id','$ongoing_section_no','$ques','$ans','$created_by','$created_ip','$created_browser')";
		
		$result = $mysqli -> query($prepared_statement);
		}
	}
 
}else {
$start=$_POST['next_questions'];	
}	


$end=$start+3;
$section_id=$_SESSION['ongoing_section_no'];
$prepared_statement="SELECT * FROM shristi_questionnaires_sub_questions WHERE sub_questionnaire_codes='$section_id' and short_by>$start and short_by < $end  ";
		//$res=$mysql_obj->simply_run_statement_passed($prepared_statement);
		//$result = mysql_query($prepared_statement);
		$result = $mysqli -> query($prepared_statement);
		 //echo 'TTTT-->'.$rowass = $result -> fetch_rows();
		$number = $result->num_rows;
		 //$row = $result -> fetch_assoc();
		if($number>0)
		{
	echo '<form id="nextform" action="/" >';		
	echo	'<table border="0" class="tables_fieldset" style="width:100%;font-size:14px;" cellpadding="3px" cellspacing="0">';	
		$sno=0;
		while($detail=$result -> fetch_assoc())
		{
			if($detail['type']=="questions_category")
			{
				echo("<tr>");
				echo("<td colspan=\"3\" style=\"text-decoration:underline;\">".$detail['question']."</td>");
				echo("</tr>");
			}
			else
			{
				$sno++;
				 $sno=$detail['short_by'];
				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:left;\">Q".$sno."</td>");
				echo("<td style=\"padding:0 5px;width:5px;\">:</td>");
				//echo("</tr>");
				if($detail['type']=="5")
				{
					//echo("<tr>");
					//echo("<td style=\"height:20px;\">".$detail['question']."</td>");
					//echo("</tr>");
				}
				
				
				
				
				/*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;\" />");
				}*/
				
				 if($detail['type']=="5")
				{
					//$aufile="https://shristisensorium.com/franchise/".$detail['audio_file_link'];
					echo("<td>");
					echo '<div style="margin-top:0px;">'. ''.'</div>';
					$val='message'.$detail['table_id'];
					//echo $newimg= strtoupper($detail['question']).'.png';
					$pathx = "images/quiz/";
                    $file = strtoupper($detail['question']).'.png';
                    echo '<img style="margin-left: 50px;
    margin-top: -30px;margin-right: 10px;" height="80px;" src="'.$pathx.$file.'">';
					
			echo("<input type=\"hidden\" id=\"".$val."\" value=\"".$detail['question']."\" />	");
			$link_address = 'javascript:;';
			$dattata=$detail['table_id'];
			
					echo "<a class=\"button_img\" href='".$link_address."' onClick=\"songplay('".$dattata."');\"><img height=\"50px;\" src=\"images\speak_icon.png\"></a>";
				}
				else if($detail['type']=="8")
				{
					echo("<td rowspan=\"2\">");
					echo("<table style=\"font-size:20px;\"><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 10px;\"><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:20px;\"><tr valign=\"top\">");
					echo("<td align=\"center\">".$detail['answer']."</td>");
					echo("</tr>");
					echo("<tr>");
					echo("<td colspan=\"4\" style=\"padding:10px;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")
				{
					
				$options=$detail['options'];
				$options_array=explode("!@!@",$options);
				for($i=0;$i<count($options_array);$i++)
				{
					$j=$i+1;
					echo("<tr>");
					echo("<td colspan=\"3\"><input type=\"radio\" name=\"ans_".$detail['table_id']."\" id=\"ans_".$detail['table_id']."_".$j."\" value=\"".$j."\" />	");
					echo("<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']=="7")
				{
					
				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><input type=\"text\" style=\"width:30%;\" /></td>");
				echo("</tr>");
				echo("<tr valign=\"top\">");
				echo("<td style=\"width:20px;text-align:right;\"></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 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);
				if(count($options_array)>4)
				{
				
					
						
                echo("<tr>");
				for($i=0;$i<count($options_array);$i++)
				{
					$j=$i+1;
					
					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 {
				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>");
				}
			}
		}
		
			$sno;
		//echo("<input type=\"text\" name=\"total_questions\" id=\"total_questions\" value=\"".$sno."\" />");
	
	
	

?>
<table>
<tr>
<td>
<input type="hidden"  id="nextquestions" name="next" value="<?php echo $sno; ?>" />
<input type="hidden"  id="count" name="count" value="<?php echo $number; ?>" />
<input type="hidden"   name="submit" value="1" />
</td>
</tr>
</table>
</form>
		<?php } else {
			
			echo "error"; exit;
		} ?>