<?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
	defined('_FEXEC') or die();
require('includes/functions/events_tree.php');

$current_file  =stristr ($PHP_SELF,basename ($PHP_SELF));
?>
		<table border="0" width="100%" cellspacing="0" cellpadding="2">
			<tr>
				<!--<td class="pageHeading"><?php //echo HEADING_TITLE; ?></td>!-->
			</tr>
			<tr><td><?php //echo tep_draw_separator('pixel_trans.gif', '2', '10'); ?></td></tr>
			<script language="JavaScript" src="includes/date-picker.js"></script>
			<script language="JavaScript" src="includes/event_select.js"></script>
			<script language="javascript">
				function doReport(output){
					var type=document.select_event.survey_report_type.options[document.select_event.survey_report_type.selectedIndex].value;
					var filename="";
					if (output==3 && type==3) {
						alert("<?php echo addslashes(stripslashes(ERR_QUESTION_REPORT_VALID));?>");
						return;
					}
					switch(type){
						case "1":
							filename="<?php echo tep_href_link(FILENAME_EVENTS_REPORTS_SURVEYS_SUMMARY);?>";
							break;
						case "2":
							filename="<?php echo tep_href_link(FILENAME_EVENTS_REPORTS_SURVEYS_DETAIL);?>";
							break;
						case "3":
							filename="<?php echo tep_href_link(FILENAME_EVENTS_REPORTS_SURVEYS_RELATION);?>";
							break;
						case "4":
							filename="<?php echo tep_href_link(FILENAME_EVENTS_REPORTS_SURVEYS_CROSSTAB);?>";
							break;
					}
					if (output==3){
						document.select_event.post_action.value="excel";
						document.select_event.target="_new";
					} else if (output==2){
					    document.select_event.post_action.value="pdf";
						document.select_event.target="_new";
					}else {
						document.select_event.post_action.value="screen";
						document.select_event.target="_self";
					}
					document.select_event.action=filename;
					document.select_event.submit();
				}
			</script>
			<?php // get the survey names
			
				$events_array=tep_get_events_array_single();
				
				$survey_query=tep_db_query("SELECT survey_id,survey_name from " . TABLE_EVENTS_SURVEYS . " order by survey_name");
				$surveys=array();
				while($survey_result=tep_db_fetch_array($survey_query)){
					$surveys[]=array('id'=>$survey_result["survey_id"],'text'=>$survey_result["survey_name"]);
				}
				// get the report types
				$report_types=array();
				for ($icnt=1;$icnt<=3;$icnt++) $report_types[]=array('id'=>$icnt,'text'=>constant('REPORT_TYPE_' . $icnt));
				$report_to=array(array('id'=>1,'text'=>REPORT_TO_SCREEN),array('id'=>2,'text'=>REPORT_TO_FILE));
				
				$survey_types_array=array(array('id'=>'CD','text'=>TEXT_CD),array('id'=>'RV','text'=>TEXT_RV),array('id'=>'WV','text'=>TEXT_WV),array('id'=>'FV','text'=>TEXT_FV));
				echo tep_draw_form("select_event",FILENAME_EVENTS_REPORTS_SURVEYS,'','post');
				echo tep_draw_hidden_field("post_action","screen");
			?>
			<tr class="cell_bg_report_header">
				<td valign="top">
				<table border="0" cellspacing="3" cellpadding="2" width="100%" class="searchArea">
					<div id="event_list" style="position:absolute;left:210px;top:143px;display:none;width:400px">
						<?php echo tep_draw_event_select_menu('select_id',$events_array,$events_id,'size=10 onClick="javascript:setListboxText(0);toggleList(0);" onFocus="javascript:toggleList(1);" onBlur="javascript:toggleList(0);" class="customerSelect" style="width:400px;"');?>
					</div>
							<tr><?php $_array=array('d','m','Y');  $replace_array=array('DD','MM','YYYY'); 	$date_format=str_replace($_array,$replace_array,EVENTS_DATE_FORMAT);
									$default_start_date=format_date(getServerDate());
									if($tx_report_from=="")$tx_report_from = $default_start_date;
									if($tx_report_to=="")$tx_report_to = $default_start_date;
								?>
								<td align="right" width="80"><?php echo SURVEY_DATE_FROM;?></td>
								<!--<td width="150">!-->
								<td nowrap valign="top" width="100">
								<?php echo tep_draw_input_field("survey_report_from",$tx_report_from,"size=10",false,'text',false);?>
								<a href="javascript:show_calendar('select_event.survey_report_from',null,null,'<?php echo $date_format;?>');"
						          onmouseover="window.status='Date Picker';return true;"
						          onmouseout="window.status='';return true;"><img border="none" src="images/icon_calendar.gif"/>  
						        </a>
								</td>
								<!--<td align="right" width="100"><?php //echo SURVEY_DATE_TO;?></td>!-->
								<!--<td width="150">!-->
								<td align="right" width="70">	<?php echo SURVEY_DATE_TO;?></td>
								<td width="101">
								<?php echo tep_draw_input_field("survey_report_to",$tx_report_to,"size=10",false,'text',false);?>
								<a href="javascript:show_calendar('select_event.survey_report_to',null,null,'<?php echo $date_format;?>');"
						          onmouseover="window.status='Date Picker';return true;"
						          onmouseout="window.status='';return true;"><img border="none" src="images/icon_calendar.gif"/>  
						        </a>
								</td>
								<td align="right" width="100"><?php echo SURVEY_REPORT_TYPE;?></td>
								<td nowrap align="left" width="150">
								<?php echo  tep_draw_pull_down_menu('survey_report_type',$report_types,$tx_report_type);?>
								</td>
			
								<td valign="middle" align="right">
									<?php echo '<a href="javascript:doReport(1);">' . tep_image_button('button_report_search.gif', IMAGE_SEARCH_DETAILS) . '</a>'; ?>
								</td>
							</tr>
					
							<tr>
								
								<table width="100%" align="left" cellpadding="0" cellspacing="2" border="0" class="searchArea">
								<tr>
								<td>
								<table border="0" cellpadding="2" cellspacing="2" width="100%" class="searchArea">
								<tr>
							
								<!--<td align="right" width="80"><?php echo SURVEY_EVENT;?></td>!-->
								<!--<td nowrap width="150">!-->
								<td align="right" width="78"><?php echo SURVEY_EVENT;?></td>
                        		<td width="75" >
									<?php  //echo tep_draw_event_select_menu('select_text',$selected_name,'onFocus="javascript:toggleText(1);" onBlur="javascript:toggleText(0);" style="width:400px"');
									echo tep_draw_input_field('select_text',$selected_name,'onFocus="javascript:toggleText(1);" onBlur="javascript:toggleText(0);" style="width:400px"');
										?><span id="for_textbox" style="position:absolute;"></span>
								</td>
								<!--<td align="right" width="100"><?php echo SURVEY_TYPE ;?></td>
								<td width="150">!-->
								<td align="right" width="120" nowrap="nowrap"><?php echo SURVEY_TYPE ;?></td>
								<td colspan="2">
									<?php echo tep_draw_pull_down_menu('survey_type',$survey_types_array,$survey_type);?>	
								</td>
								
								<td align="right" colspan="1">
								<?php echo  '<a href="javascript:doReport(2);">' . tep_image_button('button_export_pdf.gif', IMG_EXPORT_PDF) . '</a>'; ?>
								</td>
								
								</tr>
								</table>
								</td>
								</tr>
							    <tr>
									<td>
									  <table border="0" cellpadding="2" width="100%" cellspacing="0">
										<tr>
											<td nowrap="nowrap" align="right" width="100%" colspan="2" class="main" valign="middle">
												<?php 
												echo '<a href="javascript:doReport(3);">' . tep_image_button('button_export_excel.gif', IMAGE_EXPORT_EXCEL) . '</a>'
											 ?>
											 </td>
										</tr>
									 </table>
							      </td>			 
							  </tr>				
							</table>
							
							</tr>
							
				  
					<tr><td><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td></tr>
			    </table>
			  </td>
		    </tr>
		  </form>
			<script language="JavaScript">
				if(na6) document.select_event.select_text.addEventListener("keyup",selectList,true);
				if(iex) document.select_event.select_text.onkeyup=selectList;
				if(na6) document.select_event.select_text.addEventListener("keydown",scrollList,true);
				if(iex) document.select_event.select_text.onkeydown=scrollList;
			</script>
		</table>
