<?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/services_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/service_select.js"></script>
			<?php include(DIR_WS_INCLUDES."date_format_js.php")?>

			<script language="javascript">
				function doReport(output){
					var type=document.select_services.survey_report_type.options[document.select_services.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_REPORTS_SERVICES_SURVEYS_SUMMARY);?>";
							break;
						case "2":
							filename="<?php echo tep_href_link(FILENAME_REPORTS_SERVICES_SURVEYS_DETAIL);?>";
							break;
						case "3":
							filename="<?php echo tep_href_link(FILENAME_REPORTS_SERVICES_SURVEYS_RELATION);?>";
							break;
						case "4":
							filename="<?php echo tep_href_link(FILENAME_REPORTS_SERVICES_SURVEYS_CROSSTAB);?>";
							break;
					}
					if (output==3){
						document.select_services.post_action.value="excel";
						document.select_services.target="_new";
					} else {
						document.select_services.post_action.value="screen";
						document.select_services.target="_self";
					}
					document.select_services.action=filename;
					document.select_services.submit();
				}
			</script>
			<?php // get the survey names
			
				$services_array=tep_get_service_array_single();
				
				$survey_query=tep_db_query("SELECT survey_id,survey_name from " . TABLE_SERVICES_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'=>'RV','text'=>TEXT_RV),array('id'=>'WV','text'=>TEXT_WV),array('id'=>'FV','text'=>TEXT_FV));
				echo tep_draw_form("select_services",FILENAME_REPORTS_SERVICES_SURVEYS,'','post');
				echo tep_draw_hidden_field("post_action","screen");
			?>
			<tr>
				<td valign="top">
				<table border="0" cellspacing="0" cellpadding="0" width="100%">
					<div id="service_list" style="position:absolute;left:218px;top:177px;display:none;width:400px">
						<?php echo tep_draw_service_select_menu('select_id',$services_array,$service_id,'size=10 onClick="javascript:setListboxText(0);toggleList(0);" onFocus="javascript:toggleList(1);" onBlur="javascript:toggleList(0);" class="customerSelect" style="width:400px;"');?>
					</div>
					<tr>
						<td valign="top" align="left">
						<table border="0" cellpadding="4" cellspacing="0" width="100%" class="searchArea">
							<tr>
							<?php $_array=array('d','m','Y');  $replace_array=array('DD','MM','YYYY'); 	$date_format=str_replace($_array,$replace_array,EVENTS_DATE_FORMAT);?>
								<td align="left" valign="top" width="12%"><?php echo SURVEY_DATE_FROM;?><br><small>(YYYY-MM-DD)</small></td>
								<td width="15%" valign="top"><?php echo tep_draw_input_field("survey_report_from",format_date($tx_report_from),"size=10",false,'text',false);?>&nbsp;
								<a href="javascript:show_calendar('select_services.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 valign="top" width="13%" align="left"><?php echo SURVEY_DATE_TO;?><br><small>(YYYY-MM-DD)</small></td>
								<td width="15%" valign="top"><?php echo tep_draw_input_field("survey_report_to",format_date($tx_report_to),"size=10",false,'text',false);?>&nbsp;
								<a href="javascript:show_calendar('select_services.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="left" valign="middle" width="34%"><?php echo '&nbsp;' . SURVEY_REPORT_TYPE;?>
								<?php echo tep_draw_separator('pixel_trans.gif','10','1') . tep_draw_pull_down_menu('survey_report_type',$report_types,$tx_report_type);?>
								</td>
								
								<td valign="middle" align="right" width="40%">
									<?php echo '<a href="javascript:doReport(1);">' . tep_image_button('button_report_search.gif', IMAGE_SEARCH_DETAILS) . '</a>'; ?>
								</td>
						</tr>
						<tr><td colspan="6"><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td></tr>
						<tr>
							<td colspan="5" width="60%" nowrap="nowrap"><?php echo SURVEY_SERVICE;?>
								<?php echo tep_draw_separator('pixel_trans.gif','10','1');
									  //echo tep_draw_service_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>
							
								<?php echo '&nbsp;' . SURVEY_TYPE;?>
							
								<?php echo tep_draw_separator('pixel_trans.gif','10','1');
									  echo tep_draw_pull_down_menu('survey_type',$survey_types_array,$survey_type);
								?>
							</td>
							
							<td nowrap="nowrap" align="right" width="40%" colspan="2" 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>
			</td>
		</tr>
		</form>
			<script language="JavaScript">
				if(na6) document.select_services.select_text.addEventListener("keyup",selectList,true);
				if(iex) document.select_services.select_text.onkeyup=selectList;
				if(na6) document.select_services.select_text.addEventListener("keydown",scrollList,true);
				if(iex) document.select_services.select_text.onkeydown=scrollList;
			</script>
		</table>
