<?php

/*

  osCommRes, Services Online
  http://www.oscommres.com

  Copyright (c) 2005 osCommRes

  Released under the GNU General Public License
  Freeway eCommerce from ZacWare
http://www.zac-ware.com/freeway

Copyright 2007 ZacWare Pty. Ltd 
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );
	require('includes/application_top.php');
	tep_get_last_access_file();
	require('includes/classes/pdfTable.php');
	require('includes/languages/'. $language .'/reports_events_surveys.php');
	require('includes/languages/'. $language .'/reports_events_surveys_file.php');

	// get the type of action
	/*$action=isset($HTTP_POST_VARS["post_action"])?$HTTP_POST_VARS["post_action"]:'';
	
	if ($action!=""){
		$events_id=isset($HTTP_POST_VARS["select_id"])?(int)$HTTP_POST_VARS["select_id"]:0;
$events_id=3;
		$survey_type=isset($HTTP_POST_VARS["survey_type"])?$HTTP_POST_VARS["survey_type"]:'RV';
		$only_content = (isset($HTTP_GET_VARS['only_content']) ? $HTTP_GET_VARS['only_content'] : 'N');
			
		$tx_report_from=isset($HTTP_POST_VARS["survey_report_from"])?$HTTP_POST_VARS["survey_report_from"]:'';
		$tx_report_to=isset($HTTP_POST_VARS["survey_report_to"])?$HTTP_POST_VARS["survey_report_to"]:'';
			
		// build the additional options to query
		$add_option="";
		if ($tx_report_from!="") $add_option=" and suf.survey_flag_date>='" . tep_convert_date_raw($tx_report_from) . "' ";
		if ($tx_report_to!="") $add_option.=" and suf.survey_flag_date<='" . tep_convert_date_raw($tx_report_to) . "' ";

		// find the survey id 
		$survey_detail_query=tep_db_query("SELECT survey_name,survey_id from " . TABLE_EVENTS_SURVEYS . " where events_id='" . $events_id . "' and survey_type='" . $survey_type . "'");

		$question_found=false;
		$found_results=SURVEY_NO_DETAILS;
		if (tep_db_num_rows($survey_detail_query)>0) {
			$survey_detail_result=tep_db_fetch_array($survey_detail_query);
			$survey_flag_query=tep_db_query("SELECT survey_flag_id from " . TABLE_EVENTS_SURVEYS_FLAG . " suf where suf.survey_id='" . $survey_detail_result["survey_id"] . "' " . $add_option);
			
			if (tep_db_num_rows($survey_flag_query)>0)  {
				$survey_found=true;
				$found_results="SURVEY";
				// get the questions for selected survey
				$question_query=tep_db_query("SELECT * from " . TABLE_EVENTS_SURVEYS_QUESTION . " where survey_id='" . $survey_detail_result["survey_id"] . "' and (question_type=6 or question_type<4) order by question_id");
				if (tep_db_num_rows($question_query)){
					$question_found=true;
				} else {
					$found_results=SURVEY_NO_QUESTIONS;
				}
			}
		}
		
	} */ 
	
	$action=isset($HTTP_POST_VARS["post_action"])?$HTTP_POST_VARS["post_action"]:'';
	$survey_in=isset($HTTP_GET_VARS["survey_in"])?$HTTP_GET_VARS["survey_in"]:0;
	
	if ($survey_in==1){ 
		$events_id=($HTTP_GET_VARS["events_id"])?(int)$HTTP_GET_VARS["events_id"]:0;
		$survey_type=($HTTP_GET_VARS["survey_type"])?$HTTP_GET_VARS["survey_type"]:'CD';
		$action="screen";
	}
	if ($action!="" || $action==""){
		if ($survey_in!=1){
			$events_id=isset($HTTP_POST_VARS["select_id"])?(int)$HTTP_POST_VARS["select_id"]:0;

			$survey_type=isset($HTTP_POST_VARS["survey_type"])?$HTTP_POST_VARS["survey_type"]:'RV';
		}
		$only_content = (isset($HTTP_GET_VARS['only_content']) ? $HTTP_GET_VARS['only_content'] : 'N');
		$tx_report_type=isset($HTTP_POST_VARS["survey_report_type"])?(int)$HTTP_POST_VARS["survey_report_type"]:1;
		$tx_report_from=isset($HTTP_POST_VARS["survey_report_from"])?tep_convert_date_raw($HTTP_POST_VARS["survey_report_from"]):'';
		$tx_report_to=isset($HTTP_POST_VARS["survey_report_to"])?tep_convert_date_raw($HTTP_POST_VARS["survey_report_to"]):'';
		//Fill display headers
		$display_header ="";
		$display_header .= SURVEY_DATE_FROM.'&nbsp;&nbsp;'.$tx_report_from ."\t"; 
		$display_header .= SURVEY_DATE_TO . '&nbsp;&nbsp;'. $tx_report_to ."\t";	
		//echo "select events_name from ".TABLE_EVENTS_DESCRIPTION." where events_id= '". $events_id ."' " ;
		$event_name_query=tep_db_query("select events_name from ".TABLE_EVENTS_DESCRIPTION." where events_id= '". $events_id ."' "); 
		$event_name=tep_db_fetch_array($event_name_query);
		$display_header .= SURVEY_EVENT.':'.'&nbsp;' .$event_name['events_name']."\t";
		// build the additional options to query
		$add_option="";
		if ($tx_report_from!="") $add_option=" and suf.survey_flag_date>='" . $tx_report_from . "' ";
		if ($tx_report_to!="") $add_option.=" and suf.survey_flag_date<='" . $tx_report_to . "' ";


		// find the survey id
		$survey_detail_query=tep_db_query("SELECT survey_name,survey_id,survey_type from " . TABLE_EVENTS_SURVEYS . " where events_id='" . $events_id . "' and survey_type='" . $survey_type . "'");
		$survey_found=false;
		$question_found=false;
		$found_results=SURVEY_NO_DETAILS;

		if (tep_db_num_rows($survey_detail_query)>0) {
			$survey_detail_result=tep_db_fetch_array($survey_detail_query);
			$survey_found=true;
			//Fill the display header
			if($survey_detail_result['survey_type']=='RV')
			   $display_header .=SURVEY_TYPE .'&nbsp;&nbsp;'. TEXT_RV;
			elseif($survey_detail_result['survey_type']=='WV') 
			    $display_header .=SURVEY_TYPE .'&nbsp;&nbsp;'. TEXT_WV;    
			elseif($survey_detail_result['survey_type']=='FV')
			     $display_header .=SURVEY_TYPE .'&nbsp;&nbsp;'. TEXT_FV;
			else	 
				 $display_header .=SURVEY_TYPE .'&nbsp;&nbsp;'. TEXT_CD;	
				 
			// get the questions for selected survey
			/*$question_query=tep_db_query("SELECT * from " . TABLE_EVENTS_SURVEYS_QUESTION . " where survey_id='" . $survey_detail_result["survey_id"] . "' and (question_type=6 or question_type<4) order by question_id");
			if (tep_db_num_rows($question_query)){
				$question_found=true;*/
				
				
				$survey_flag_query=tep_db_query("SELECT survey_flag_id from " . TABLE_EVENTS_SURVEYS_FLAG . " suf where suf.survey_id='" . $survey_detail_result["survey_id"] . "' " . $add_option);
			
			if (tep_db_num_rows($survey_flag_query)>0)  {
				$survey_found=true;
				$found_results="SURVEY";
				
				
				// get the questions for selected survey
			$question_query=tep_db_query("SELECT * from " . TABLE_EVENTS_SURVEYS_QUESTION . " where survey_id='" . $survey_detail_result["survey_id"] . "' and (question_type=6 or question_type<4) order by question_id");
			if (tep_db_num_rows($question_query)){
				$question_found=true;
			}
			else {
					$found_results=SURVEY_NO_QUESTIONS;
				}
			}
		}
		
	} 




		// find the survey id
		/*$survey_detail_query=tep_db_query("SELECT survey_name,survey_id,survey_type from " . TABLE_EVENTS_SURVEYS . " where events_id='" . $events_id . "' and survey_type='" . $survey_type . "'");
		//$survey_found=false;
		$question_found=false;
		$found_results=SURVEY_NO_DETAILS;
		if (tep_db_num_rows($survey_detail_query)>0) {
			$survey_detail_result=tep_db_fetch_array($survey_detail_query);
			$survey_found=true;
			$survey_flag_query=tep_db_query("SELECT survey_flag_id from " . TABLE_EVENTS_SURVEYS_FLAG . " suf where suf.survey_id='" . $survey_detail_result["survey_id"] . "' " . $add_option);
			
			if (tep_db_num_rows($survey_flag_query)>0)  {
				$survey_found=true;
				$found_results="SURVEY";
				
				
				// get the questions for selected survey
			$question_query=tep_db_query("SELECT * from " . TABLE_EVENTS_SURVEYS_QUESTION . " where survey_id='" . $survey_detail_result["survey_id"] . "' and (question_type=6 or question_type<4) order by question_id");
			if (tep_db_num_rows($question_query)){
				$question_found=true;
			}
			else {
					$found_results=SURVEY_NO_QUESTIONS;
				}
			//Fill the display header
			/*if($survey_detail_result['survey_type']=='RV')
			   $display_header .=SURVEY_TYPE .'&nbsp;&nbsp;'. TEXT_RV;
			elseif($survey_detail_result['survey_type']=='WV') 
			    $display_header .=SURVEY_TYPE .'&nbsp;&nbsp;'. TEXT_WV;    
			elseif($survey_detail_result['survey_type']=='FV')
			     $display_header .=SURVEY_TYPE .'&nbsp;&nbsp;'. TEXT_FV;
			else	 
				 $display_header .=SURVEY_TYPE .'&nbsp;&nbsp;'. TEXT_CD;	
				 
			
		}
	}	
	}*/ 
	
	
	$report_filename=sprintf("survey_reports_summary_%s_%s",$login_id,time());
	
	if ($action=="excel"){
			// create csv file
			$file_path=DIR_FS_CATALOG . "images/".$report_filename.".csv";
			$handle=fopen($file_path,"w");
			if ($handle){
				$result=output_detail();
				fwrite($handle,$result,strlen($result));
				fclose($handle);
			}
			tep_redirect(DIR_WS_CATALOG . "images/".$report_filename.".csv");
	}
	if($action=="pdf"){
	    generate_pdf();
		 tep_redirect(DIR_WS_CATALOG . "images/".$report_filename.".pdf");
		 return;
	}tep_delete_temp_files("survey_reports_summary_" . $login_id);
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onLoad="SetFocus();">
<div id="spiffycalendar" class="text"></div>
<!-- header //-->
<?php if ($only_content!='Y') require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->
<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
	<tr>
		<?php if ($only_content!='Y') {?> 
		<?php } ?>
		<!-- body_text //-->
		<td width="100%" valign="top">
		<table border="0" width="100%" cellspacing="0" cellpadding="2">
				<tr>
					<td><?php 
							require(DIR_WS_LANGUAGES . $language . "/" . FILENAME_EVENTS_REPORTS_SURVEYS);
							require(FILENAME_EVENTS_REPORTS_SURVEYS);

						?></td>
				</tr>
<?php if ($action=="screen") {
?>
				<tr>
					<td class="pageHeading" align="center"><?php echo sprintf(HEADING_TITLE_RESULTS,$survey_detail_result['survey_name']); ?></td>
				</tr>
				<tr>
					<td class="main" align="center">
					<?php 	if ($tx_report_from!="") echo '<b>' . TEXT_FROM_DATE . '</b>'. $tx_report_from . '&nbsp;'; 
							if ($tx_report_to!="") echo '<b>' . TEXT_TO_DATE . '</b>' . $tx_report_to;
					?>
					</td>
				</tr>
				<tr>
					<td><?php echo tep_draw_separator('pixel_trans.gif','1','10'); ?></td>
				</tr>
				<tr>
					<td>
					<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<?php 	// get the survey_flag_dates for the given survey_id also checking dates
						
						// get all the questions to be found for this survey

						if ($found_results=="SURVEY") { // if both survey_flag and questions found
							$row=1;
							while($survey_flag=tep_db_fetch_array($survey_flag_query)){
				?>
								<tr>
									<td>
									<table border="0" cellpadding="4" cellspacing="0" class="searchArea" width="100%">
										<tr>
											<td class="tableHeading" align="center"><?php echo sprintf(SURVEY_ID,$row) ; ?></td>
										</tr>
									</table>
									</td>
								</tr>
								<tr>
									<td>
									<table border="0" cellpadding="2" cellspacing="0" width="100%">
									<?php //display the questions
										$row2=1;
										$cur_row=0;
										tep_db_data_seek($question_query,0);
										while($question=tep_db_fetch_array($question_query)){
											// display question detail
											if ($cur_row%2==0) $row_class="attributes-even";
											else $row_class="attributes-odd";
									?>
											<tr class="<?php echo $row_class;?>">
												<td><?php echo tep_draw_separator('pixel_trans.gif',1,5);?></td>
											</tr>
											<tr class="<?php echo $row_class;?>">
												<?php 	if ($question['question_type']==6) { 
															echo '<td class="main" align="center"><b>' . $question['question_text'] . '</b></td>';
														} else {
															echo '<td class="main"><b>' . $row2 . '.&nbsp;' . $question["question_text"]; 
															if ($question["question_required"]==1) echo '&nbsp;<i>' . TEXT_REQUIRED . '</i></td>';
														}
												?>
											</tr>
												<?php	// determine type and display question answer details
													$answer_text="";
													if ($question["question_type"]<=3) {// if type is single radio or pull down choice or multiple choice
														$answer_query=tep_db_query("SELECT suc.choice_text from " . TABLE_EVENTS_SURVEYS_ANSWER . " sua, " . TABLE_EVENTS_SURVEYS_CHOICE . " suc where sua.survey_flag_id='" . $survey_flag["survey_flag_id"] . "' " .
																					"and sua.question_id='" . $question["question_id"] . "' and sua.choice_id=suc.choice_id order by suc.choice_id");
														if (tep_db_num_rows($answer_query)>0){
															while($answer=tep_db_fetch_array($answer_query)){
																if ($answer_text!="") $answer_text.="<br>";
																$answer_text.=$answer["choice_text"];
															}
														} else {
															$answer_text=QUESTION_NO_ANSWER;
														}
													} else if ($question["question_type"]==4 || $question["question_type"]==5) {// if type is text answer
														$answer_query=tep_db_query("SELECT answer_text from " . TABLE_EVENTS_SURVEYS_TEXT . " where survey_flag_id='" . $survey_flag["survey_flag_id"] . "' and question_id='" . $question["question_id"] . "'");
														if (tep_db_num_rows($answer_query)>0){
															$answer=tep_db_fetch_array($answer_query);
															$answer_text=$answer["answer_text"];
														} else {
															$answer_text=QUESTION_NO_ANSWER;
														}
													}
													if ($question['question_type']!=6){
												?>
													<tr class="<?php echo $row_class;?>">
														<td>
														<table border="0" cellpadding="2" cellspacing="0" width="100%">
															<tr>
																<td width="20">&nbsp;</td>
																<td align="left" class="main"><?php echo $answer_text;?></td>
															</tr>
														</table>
														</td>
													</tr>
												<?php 	$row2++; 
													  	} // question type if
														$cur_row++;
													  } //question while 
												?>
									</table>
									</td>
								</tr>
							<?php 
								 	$row++;
								} //survey while
							?>
						</table>
						</td>
					</tr>
				<?php } else {  ?>
				<tr>
					<td>
					<table border="0" cellpadding="5" cellspacing="0" width="100%">
						<tr>
							<td class="tableHeading" align="center"><?php echo $found_results;?></td>
						</tr>
					</table>
					</td>
				</tr>
				<?php } //found results	?>
				</table>
				<td>
			</tr>
		<?php } // action?>
		</table>
		</td>
<!-- body_text_eof //-->
	 </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); 

	 function output_detail(){
	 	global $add_option,$question_query,$found_results,$survey_flag_query;	
		
		$row=1;
		if ($found_results!='SURVEY'){
			$result.=sprintf("\"%s\",,,\n",$found_results);
			return $result;
		}
		while($survey_flag=tep_db_fetch_array($survey_flag_query)){
			$result.=sprintf("\"%s\"\n",SURVEY_ID . $row);
			$row2=1;
			$cur_row=0;
			tep_db_data_seek($question_query,0);
			while($question=tep_db_fetch_array($question_query)){
				// display question detail
				if ($question['question_type']==6) { 
					$result.=sprintf("\"%s\"\n",$question['question_text']);
				} else {
					$result.=sprintf("\"%d. %s\"\n",$row2,$question["question_text"] . ($question["question_required"]==1?TEXT_REQUIRED:''));
				}
				$answer_text="";
				if ($question["question_type"]<=3) {// if type is single radio or pull down choice or multiple choice
					$answer_query=tep_db_query("SELECT suc.choice_text from " . TABLE_EVENTS_SURVEYS_ANSWER . " sua, " . TABLE_EVENTS_SURVEYS_CHOICE . " suc where sua.survey_flag_id='" . $survey_flag["survey_flag_id"] . "' " .
												"and sua.question_id='" . $question["question_id"] . "' and sua.choice_id=suc.choice_id order by suc.choice_id");
					if (tep_db_num_rows($answer_query)>0){
						while($answer=tep_db_fetch_array($answer_query)){
							if ($answer_text!="") $answer_text.=", ";
							$answer_text.=$answer["choice_text"];
						}
					} else {
						$answer_text=QUESTION_NO_ANSWER;
					}
				} else if ($question["question_type"]==4 || $question["question_type"]==5) {// if type is text answer
					$answer_query=tep_db_query("SELECT answer_text from " . TABLE_EVENTS_SURVEYS_TEXT . " where survey_flag_id='" . $survey_flag["survey_flag_id"] . "' and question_id='" . $question["question_id"] . "'");
					if (tep_db_num_rows($answer_query)>0){
						$answer=tep_db_fetch_array($answer_query);
						$answer_text=$answer["answer_text"];
					} else {
						$answer_text=QUESTION_NO_ANSWER;
					}
				}
				if ($question['question_type']!=6) {
					$result.=sprintf("\"%s\"\n",$answer_text);
					$row2++; 
				} // question type if
			$cur_row++;
			} //question while
			$row++;
		} //survey while
		return $result;
	 }
	 
	 // function to create pdf content
	function generate_pdf(){
		global $question_query,$question_found,$survey_found,$display_header,$report_filename;
		
		// set initial params
		$table=new pdfTable("A4","l");
		$table->left_margin=20;
		$table->top_margin=20;
		$table->right_margin=20;
		$table->bottom_margin=20;
		$table->pdfInit();
		
		// Add the styles
		$table->AddStyle("heading","color:#727272;bgcolor:#ffffff;font:Arial;size:18;style:B");
		$table->AddStyle("user","color:#000000;bgcolor:#f1f9fe;font:Arial;size:14;style:B;border-color:#7b9ebd");
		$table->AddStyle("subhead","color:#000000;bgcolor:#7b9ebd;font:Arial;size:10;style:B");
		$table->AddStyle("headrow","color:#000000;bgcolor:#C9C9C9;font:Arial;size:10;style:B");
		$table->AddStyle("row","color:#000000;bgcolor:#F0F1F1;font:Arial;size:10");
		$table->AddStyle("query","color:#000000;bgcolor:#FFFFFF;font:Arial;size:11");
		$table->AddStyle("subrow","color:#000000;bgcolor:#FFFFFF;font:Arial;size:10");
		$table->AddStyle("subrowhead","color:#000000;bgcolor:#FFFFFF;font:Arial;size:10;style:B");

		
		$table->headers["text"]=$display_header;
		$table->headers["style"]="query";
		$table->headers["height"]=15;
		$table->headers["width"]="100%";
		$table->headers["cols"]=4;

		//define the column width
		$widths[0]=$table->width*5/100;
		$widths[2]=$table->width*30/100;
		$widths[3]=$table->width*10/100;
		$widths[4]=$table->width*10/100;

		$widths[1]=$table->width-($widths[0]+$widths[2]+$widths[3]+$widths[4]);
		// create the table header columns
		$cols=array();
		if(!$survey_found){
		  $cols[]=array("text"=>TEXT_NO_RECORDS_FOUND);
		  $table->tableheaders["text"]=$cols;
		  unset($cols);
		}
		if(!$question_found){
		  $cols[]=array("text"=>SURVEY_NO_QUESTIONS);
		  $table->tableheaders["text"]=$cols;
		  unset($cols);
		 } 
		  
		$cols[]=array("text"=>SUMMARY_CHOICE,"width"=>$widths[1],"align"=>"L","style"=>"headrow","valign"=>"M");
		$cols[]=array("text"=>SUMMARY_TOTAL,"width"=>$widths[0],"align"=>"L","style"=>"headrow","valign"=>"M");
		$cols[]=array("text"=>SUMMARY_PERCENT,"width"=>$widths[4],"align"=>"L","style"=>"headrow","valign"=>"M");
		$table->tableheaders["text"]=$cols;
		unset($cols);
		if($question_found){
		while($question=tep_db_fetch_array($question_query)){
			if ( $question["question_type"]==6){ // if question type is heading
				$cols[]=array("text"=>$question["question_text"],"width"=>$widths[1],"align"=>"L","style"=>"row","valign"=>"M");
				$found_question=true;
			} else if ($question["question_type"]<4) { // if question type is multiple choice
				$cols[]=array("text"=>$question["question_text"] . ($question["question_required"]==1?TEXT_REQUIRED:''),"width"=>$widths[1],"align"=>"L","style"=>"row","valign"=>"M");
				$cols[]=array("text"=>'',"width"=>$widths[4],"align"=>"L","style"=>"row","valign"=>"M");
				$table->OutputRowMultiple($cols,15);
				unset($cols);
				// get the total count of choice for current question
				$total_query=tep_db_query("SELECT count(sua.choice_id) as total from " . TABLE_EVENTS_SURVEYS_FLAG . " suf, " . TABLE_EVENTS_SURVEYS_ANSWER . " sua where sua.question_id='" . $question['question_id'] . "' " . $add_option . " and suf.survey_flag_id=sua.survey_flag_id group by sua.question_id");
				$total_result=tep_db_fetch_array($total_query);
				$total_count=(int)$total_result["total"];
				// get the choices for the question
				$choice_query=tep_db_query("SELECT choice_id,choice_text from " . TABLE_EVENTS_SURVEYS_CHOICE . " where question_id='" . $question["question_id"] . "' order by choice_id");
				if (tep_db_num_rows($choice_query)>0) {
					$row2=0;
					while($choice=tep_db_fetch_array($choice_query)){
						// get the total for the current choice
						$choice_total_query=tep_db_query("SELECT count(sua.choice_id) as total from " . TABLE_EVENTS_SURVEYS_FLAG . " suf, " . TABLE_EVENTS_SURVEYS_ANSWER . " sua where sua.choice_id='" . $choice['choice_id'] . "' " . $add_option . " and suf.survey_flag_id=sua.survey_flag_id group by sua.choice_id");
						$choice_total_result=tep_db_fetch_array($choice_total_query);
						$choice_total_count=(int)$choice_total_result['total'];
						$percent=0;
						if ($total_count>0)
							$percent=number_format($choice_total_count/$total_count*100,0);
						$cols[]=array("text"=>$choice["choice_text"],"width"=>$widths[1],"align"=>"L","style"=>"row","valign"=>"M");
						$cols[]=array("text"=>$choice_total_count.'',"width"=>$widths[0],"align"=>"L","style"=>"row","valign"=>"M");
						$cols[]=array("text"=>$percent.'%',"width"=>$widths[4],"align"=>"L","style"=>"row","valign"=>"M");
						$row2++; 
						$table->OutputRowMultiple($cols,15);
						unset($cols);
					}
					$cols[]=array("text"=>TOTAL_CHOICE_QUESTIONS,"width"=>$widths[1],"align"=>"L","style"=>"row","valign"=>"M");
					$cols[]=array("text"=>$total_count.'',"width"=>$widths[4],"align"=>"L","style"=>"row","valign"=>"M");
					$table->OutputRowMultiple($cols,15);
						unset($cols);
				}
				$found_question=true;
			}
			 if ($question['question_type']!=6)$row++;
		}
 	}else{
			$cols[]=array("text"=>TEXT_NO_RECORDS_FOUND,"width"=>"100%","align"=>"C","style"=>"subrow","valign"=>"M");
			$table->OutputRow($cols,15);
			unset($cols);
			}
	$table->Render($report_filename.".pdf");
}
?>