<?php

/*

 osCommerce, Open Source E-Commerce Solutions 
http://www.oscommerce.com 

Copyright (c) 2003 osCommerce 

osCommRes, Services Oline 
http://www.oscommres.com 
Copyright (c) 2005 osCommRes 

Freeway eCommerce 
http://www.zac-ware.com/freeway 
Copyright (c) 2007 ZacWare

Released under the GNU General Public License
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );
require('includes/application_top.php');
require('includes/classes/split_page_results_event.php');

$command=isset($HTTP_GET_VARS['command'])?tep_db_prepare_input($HTTP_GET_VARS['command']):'';
if($command!=''){
	switch($command){
		case 'page_navigation_option':
  			echo 'page_navigation_option^';
  			load_faq_reviews();
			break;
		case 'load_details':
			echo 'load_details^';
			$faqdesk_id=isset($HTTP_GET_VARS['faqdesk_id'])?(int)$HTTP_GET_VARS['faqdesk_id']:'';
			load_details($faqdesk_id);
			break;
		case 'save_details':
			echo 'load_details^';
			$faqdesk_id=isset($HTTP_GET_VARS['faqdesk_id'])?(int)$HTTP_GET_VARS['faqdesk_id']:'';
			$reviews_text=isset($HTTP_POST_VARS['reviews_text'])?tep_db_prepare_input($HTTP_POST_VARS['reviews_text']):'';
			$reviews_rating=isset($HTTP_POST_VARS['reviews_rating'])?tep_db_prepare_input($HTTP_POST_VARS['reviews_rating']):'';
			$reviews_query=tep_db_query("select reviews_id from ".TABLE_FAQDESK_REVIEWS." where faqdesk_id='$faqdesk_id'");
			$reviews_array=tep_db_fetch_array($reviews_query);
			$reviews_id=$reviews_array['reviews_id'];
			tep_db_query("update ".TABLE_FAQDESK_REVIEWS_DESCRIPTION." set reviews_text='" . tep_db_input($reviews_text) . "' where reviews_id='$reviews_id' and languages_id='$languages_id'");
			tep_db_query("update ".TABLE_FAQDESK_REVIEWS." set reviews_rating='$reviews_rating',last_modified=curdate() where reviews_id='$reviews_id'");
			load_details($faqdesk_id);
			break;
		case 'status_change':
			echo 'status_change^';
			$faqdesk_id=isset($HTTP_GET_VARS['faqdesk_id'])?(int)$HTTP_GET_VARS['faqdesk_id']:'';
			$status=isset($HTTP_GET_VARS['status'])?tep_db_prepare_input($HTTP_GET_VARS['status']):'';
			tep_db_query("update ".TABLE_FAQDESK_REVIEWS." set approved='$status' where faqdesk_id='$faqdesk_id'");
			load_details($faqdesk_id);
			
			$faqdesk_question_query=tep_db_query("select faqdesk_question from ".TABLE_FAQDESK_DESCRIPTION." where faqdesk_id='$faqdesk_id'");
			$faqdesk_question_array=tep_db_fetch_array($faqdesk_question_query);
			echo '^&nbsp;&nbsp;';
				if($status==0)
					echo tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif');
				else
					echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif');
			echo '&nbsp;&nbsp;'.$faqdesk_question_array['faqdesk_question'];
			break;
		case 'delete_details':
			echo 'delete_details^';
			$faqdesk_id=isset($HTTP_GET_VARS['faqdesk_id'])?tep_db_prepare_input($HTTP_GET_VARS['faqdesk_id']):'';
			echo $faqdesk_id;
				$reviews_id_query=tep_db_query("select reviews_id from ".TABLE_FAQDESK_REVIEWS." where faqdesk_id='$faqdesk_id'");
				if(tep_db_num_rows($reviews_id_query)>0){
					$reviews_id_array=tep_db_fetch_array($reviews_id_query);
					$reviews_id=$reviews_id_array['reviews_id'];
				tep_db_query("delete from ".TABLE_FAQDESK_REVIEWS." where reviews_id='$reviews_id'");	
				tep_db_query("delete from ".TABLE_FAQDESK_REVIEWS_DESCRIPTION." where reviews_id='$reviews_id'");
				}
			tep_db_query("delete from ".TABLE_FAQDESK." where faqdesk_id='$faqdesk_id'");
			tep_db_query("delete from ".TABLE_FAQDESK_DESCRIPTION." where faqdesk_id='$faqdesk_id'");
			break;
			
	}
exit;
}
tep_get_last_access_file();
require('includes/functions/faqdesk_general.php');
$server_date = getServerDate(true);	
?>
<?php
	function load_faq_reviews(){
	global $page,$languages_id;
	$faqdesk_query_raw = "select  fd.faqdesk_id,fd.faqdesk_question,f.faqdesk_status,fdr.approved  from " . TABLE_FAQDESK . " f, " . TABLE_FAQDESK_DESCRIPTION . " fd, " . TABLE_FAQDESK_REVIEWS . " fdr where fdr.faqdesk_id=f.faqdesk_id and f.faqdesk_id=fd.faqdesk_id and fd.language_id='$languages_id' order by faqdesk_question";
	$faqdesk_split = new splitPageResultsEvent($page, MAX_DISPLAY_SEARCH_RESULTS, $faqdesk_query_raw, $faqdesk_numrows);	    
 	$faqdesk_query = tep_db_query($faqdesk_query_raw);
$cnt=0;
	while($faqdesk_array=tep_db_fetch_array($faqdesk_query)){
	$class_name=($cnt%2==0)?'dataTableRowEven':'dataTableRowOdd';
?>
	<tr id="faqdesk_row_<?php echo $faqdesk_array['faqdesk_id']; ?>">
	<td>
	<div id="faqdesk_<?php echo $faqdesk_array['faqdesk_id']; ?>" onClick="javascript: faqdesk_row_focus(<?php echo $faqdesk_array['faqdesk_id']; ?>);" class="<?php echo $class_name; ?>" onMouseOver="rowOverEffect(this);" onMouseOut="rowOutEffect(this);">
	&nbsp;&nbsp;<?php 
		if($faqdesk_array['approved']==1) echo tep_image(DIR_WS_IMAGES.'template/icon_active.gif');
		else echo tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif');
		echo '&nbsp;&nbsp;'.$faqdesk_array['faqdesk_question']; ?>
	</div>
	<div id="ajax_faqdesk_<?php echo $faqdesk_array['faqdesk_id']; ?>" style="display:none;">
	</div>
	</td>
	</tr>
<?php
	}
	echo '<tr><td align="right" class="main">'.$faqdesk_split->display_count($faqdesk_numrows, MAX_DISPLAY_SEARCH_RESULTS, $page, TEXT_DISPLAY_NUMBER_OF_REVIEWS).
	$faqdesk_split->display_script_links($faqdesk_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $page,1,'page_navigation(\'\'','1').
	'</td></tr>';

	} // function ends
	
	function load_details($faqdesk_id){
	echo $faqdesk_id.'^';
	$faqdesk_query=tep_db_query("select fd.faqdesk_question,fr.customers_name,fr.date_added,fr.reviews_read,fr.date_added,fr.last_modified,fr.reviews_rating,fr.approved,f.faqdesk_image,f.faqdesk_image_two,f.faqdesk_image_three,frd.reviews_text from ".TABLE_FAQDESK_DESCRIPTION." fd, ".TABLE_FAQDESK_REVIEWS ." fr, ".TABLE_FAQDESK ." f, ".TABLE_FAQDESK_REVIEWS_DESCRIPTION." frd where fr.reviews_id=frd.reviews_id and f.faqdesk_id=fr.faqdesk_id and fr.faqdesk_id=fd.faqdesk_id and fd.faqdesk_id='$faqdesk_id'");
	$faqdesk_array=tep_db_fetch_array($faqdesk_query);
?>
<table width="100%" cellpadding="0" cellspacing="0" border="0" class="openContent">
	<tr heigth="40" bgcolor="#EDF1FE">
	<td width="10" valign="top" align="center">&nbsp;</td>
	<td align="left" valign="middle" width="350" class="inner_title"><?php 
	if($faqdesk_array['approved']==1) echo '<a href="javascript:approve('.$faqdesk_id.',0)">'.tep_image(DIR_WS_IMAGES.'template/icon_active.gif').'</a>'; else echo '<a href="javascript: approve('.$faqdesk_id.',1)">'.tep_image(DIR_WS_IMAGES.'template/icon_inactive.gif').'</a>';
	echo '&nbsp;&nbsp;'.$faqdesk_array["faqdesk_question"]; ?></td>
	<td width="100" align="left" class="main" valign="top">
		<table border="0" id="header_operation" cellspacing="0" cellpadding="0" style="width:100;height:30px;display:inline;position:relative;">
		<tr class="img_move" id="img_ids">
		<td class="cell_bg_popm_left" width="10">&nbsp;</td>
		<td width="10%"><?php echo '<a onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,1);" href="javascript: edit_faq_review();">'.tep_image(DIR_WS_IMAGES.'template/img_edit.gif').'</a>'; ?></td> 
		<td width="10"><a onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,1);" href="javascript:void delete_faq_review(<?php echo $faqdesk_id; ?>);"><?php echo tep_image(DIR_WS_IMAGES.'template/img_trash.gif'); ?></a></td>
		<td class="cell_bg_popm_right" width="10">&nbsp;</td>
		</tr>
		</table>
	</td>
	<td width="400" style="visibility:hidden;" id="main_operation" align="right"><?php echo '<a id="header_edit_operation" href="javascript: save_faq_review('.$faqdesk_id.')">'.tep_image(DIR_WS_IMAGES.'template/img_savel.gif').'</a>&nbsp;&nbsp;<a href="javascript:void close_faq_review('.$faqdesk_id.')">'.tep_image(DIR_WS_IMAGES.'template/img_closel.gif').'</a>'; ?></td>
	</tr>
	<tr>
	<td id="primary_display" colspan="4">
		<table width="100%" cellpadding="5" cellspacing="5" border="0">
		<tr>
		<td width="100" align="right"><?php echo TEXT_INFO_REVIEW_AUTHOR; ?></td>
		<td width="100"><?php echo $faqdesk_array['customers_name']; ?></td>
		<td width="100" align="right"><?php echo TEXT_INFO_REVIEW_RATING; ?></td>
		<td width="100"><?php echo tep_image(HTTP_CATALOG_SERVER . DIR_WS_CATALOG_IMAGES . 'stars_' . $faqdesk_array['reviews_rating'] . '.gif'); ?></td>
		<td width="100" align="right"><?php echo TEXT_INFO_REVIEW_READ; ?></td>
		<td width="100"><?php echo $faqdesk_array['reviews_read']; ?></td>
		</tr>
		<tr>
		<td colspan="2" align="center"><?php echo tep_info_image($faqdesk_array['faqdesk_image'], $faqdesk_array['faqdesk_question'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT); ?></td>
		<td colspan="2" align="center"><?php echo tep_info_image($faqdesk_array['faqdesk_image_two'], $faqdesk_array['faqdesk_question'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT); ?></td>
		<td colspan="2" align="center"><?php echo tep_info_image($faqdesk_array['faqdesk_image_two'], $faqdesk_array['faqdesk_question'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT); ?></td>
		</tr>
		<tr>
		<td align="right"><?php echo TEXT_INFO_DATE_ADDED; ?></td>
		<td><?php echo format_date($faqdesk_array['date_added']); ?></td>
		<td align="right"><?php echo TEXT_INFO_LAST_MODIFIED; ?></td>
		<td><?php echo format_date($faqdesk_array['last_modified']); ?></td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		</tr>
		</table>
	</td>
	</tr>
	<tr id="edit_display" style="display:none;">
	<td colspan="4">
	<?php echo tep_draw_form('edit_faq_reviews',FILENAME_FAQDESK_REVIEWS,'','post'); ?>
	  	<table border="0" width="100%" cellspacing="2" cellpadding="2">
		<tr>
		<td width="150">&nbsp;</td>
		<td class="main" width="100" align="right" valign="top"><?php echo '<b>'.ENTRY_PRODUCT.'</b>'; ?></td>
		<td><?php echo $faqdesk_array['faqdesk_question']; ?></td>
		</tr>
		<tr>
		<td colspan="2" align="right"><?php echo '<b>'.ENTRY_FROM.'</b>'; ?></td>
		<td><?php echo $faqdesk_array['customers_name']; ?></td>
		</tr>
		<tr>
		<td colspan="2" align="right"><?php echo '<b>'.ENTRY_DATE.'</b>'; ?></td>
		<td><?php echo format_date($faqdesk_array['date_added']); ?></td>
		</tr>
		<tr>
		<td valign="top" colspan="2" align="right"><?php echo '<b>'.ENTRY_REVIEW.'</b>'; ?></td>
		<td><?php echo tep_draw_textarea_field('reviews_text', 'soft', '60', '15', $faqdesk_array['reviews_text']); ?></td>
		</tr>
		<tr>
		<td colspan="2" align="right"><?php echo '<b>'.ENTRY_RATING.'</b>'; ?></td>
		<td><?php echo TEXT_BAD; ?>
		&nbsp;
		<?php for ($i=1; $i<=5; $i++) echo tep_draw_radio_field('reviews_rating', $i, '', $faqdesk_array['reviews_rating']) . '&nbsp;'; echo TEXT_GOOD; ?>
		</td>
		</tr>
		</table>
	</form>
	</td>
	</tr>
	</table>

<?php } ?>

<!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>
<script language="javascript" src="includes/http.js"></script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onLoad="SetFocus();">

<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- Ajax Work Starts -->
<table width="100%" cellpadding="2" cellspacing="2" border="0">
<tr>
	<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
</tr>
<tr>
<td width="100%"><br>
	<table width="100%" id="faqdesk_table" cellpadding="2" cellspacing="2" border="0">
	<?php load_faq_reviews(); ?>
	</table>
</td>
</tr>
</table>

<!-- Ajax Work Ends -->

<div id="ajax_image_load" style="display:none;"><?php echo tep_image(DIR_WS_IMAGES.'24-1.gif'); ?></div>
<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->

</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
<script language="javascript">
var previous_faqdesk_id='';
	function faqdesk_row_focus(faqdesk_id){
		if(previous_faqdesk_id!=''){
		close_faq_review(previous_faqdesk_id);
		}
	document.getElementById('ajax_faqdesk_'+faqdesk_id).style.display='';
	document.getElementById('ajax_faqdesk_'+faqdesk_id).innerHTML=document.getElementById('ajax_image_load').innerHTML;
	var command="<?php echo tep_href_link(FILENAME_FAQDESK_REVIEWS,'command=load_details&faqdesk_id='); ?>"+faqdesk_id;
	previous_faqdesk_id=faqdesk_id;
	do_get_command(command);
	}
	function close_faq_review(faqdesk_id){
		if(document.getElementById('ajax_faqdesk_'+faqdesk_id) && document.getElementById('faqdesk_'+faqdesk_id)){
		document.getElementById('ajax_faqdesk_'+faqdesk_id).innerHTML='';
		document.getElementById('ajax_faqdesk_'+faqdesk_id).style.display='none';
		document.getElementById('faqdesk_'+faqdesk_id).style.display='';
		}
	}
	function edit_faq_review(){
	document.getElementById('edit_display').style.display='';
	document.getElementById('primary_display').style.display='none';
	document.getElementById('main_operation').style.visibility='visible';
	}
	function save_faq_review(faqdesk_id){ 
	do_post_command('edit_faq_reviews','<?php echo tep_href_link(FILENAME_FAQDESK_REVIEWS,'command=save_details&faqdesk_id='); ?>'+faqdesk_id);
	}
	function delete_faq_review(faqdesk_id){
	var command="<?php echo tep_href_link(FILENAME_FAQDESK_REVIEWS,'command=delete_details&faqdesk_id='); ?>"+faqdesk_id;
	do_get_command(command);
	}
	function approve(faqdesk_id,status){
	var command="<?php echo tep_href_link(FILENAME_FAQDESK_REVIEWS,'command=status_change&faqdesk_id='); ?>"+faqdesk_id+'&status='+status;
	do_get_command(command);
	}
	function do_result(result){
	var token=result.split('^');
	switch(token[0]){
		case 'load_details':
			faqdesk_id=token[1];
			document.getElementById('ajax_faqdesk_'+faqdesk_id).innerHTML=token[2];
			document.getElementById('faqdesk_'+faqdesk_id).style.display='none';
			break;
		case 'status_change':
			faqdesk_id=token[1];
			document.getElementById('ajax_faqdesk_'+faqdesk_id).innerHTML=token[2];
			document.getElementById('faqdesk_'+faqdesk_id).innerHTML=token[3];			
			break;
		case 'delete_details':
			faqdesk_id=token[1];
			var rowIndex=document.getElementById('faqdesk_row_'+faqdesk_id).rowIndex;
			document.getElementById('faqdesk_table').deleteRow(rowIndex);
			break;
		case 'page_navigation_option':
			document.getElementById('faqdesk_table').innerHTML=token[1];	
			break;
	}
	}
	
	function page_navigation(arg1,agr2,agr3,agr4){
		var page_no=1;
		if(agr2==1) var obj=document.getElementById("page_1");
		else if(agr2==2) var obj=document.getElementById("page_2");
		if(agr2 && agr4){
			if(obj){
 	 			page_no=parseInt(obj.options[obj.selectedIndex].value);
 	 			if(agr4=='next') {
 	 				if(obj.length==obj.selectedIndex+1) return;
 	 				page_no+=1;
 	 			}else if(agr4=='prev') {
	 	 			if(obj.selectedIndex==0) return;
 		 			page_no-=1;
 	 			}
 	 			if(page_no<=1) page_no=1;
 	 		} 	 		
		}				
		if(agr2==1) command="<?php echo tep_href_link(FILENAME_FAQDESK_REVIEWS,'command=page_navigation_option'); ?>&page="+page_no;
		else if(agr2==2) command="<?php echo tep_href_link(FILENAME_FAQDESK_REVIEWS,'command=page_navigation_attribute'); ?>&page="+page_no;		
		if(command!="") do_get_command(command);
	}
	
	function do_hover_change(element,mode){
		if (element.mode && mode==element.mode) return;
		if (mode==2)
			element.firstChild.src=element.firstChild.src.replace(".gif","_hover.gif");
		else
			element.firstChild.src=element.firstChild.src.replace("_hover.gif",".gif");
		element.mode=mode;
	}
</script>



<?php
/*

	osCommerce, Open Source E-Commerce Solutions ---- http://www.oscommerce.com
	Copyright (c) 2002 osCommerce
	Released under the GNU General Public License

	IMPORTANT NOTE:

	This script is not part of the official osC distribution but an add-on contributed to the osC community.
	Please read the NOTE and INSTALL documents that are provided with this file for further information and installation notes.

	script name:	FaqDesk
	version:		1.2.5
	date:			2003-09-01
	author:			Carsten aka moyashi
	web site:		www..com

*/
?>