<?php
if($_POST['rate']) {
	if (substr($_COOKIE['hd_faqrate'],-1)=='x') {
		$newvalue = $_COOKIE['hd_faqrate'].$_POST['faqid']."x";
	}else{
		$newvalue = $_COOKIE['hd_faqrate']."x".$_POST['faqid']."x";
	}
	setcookie('hd_faqrate',$newvalue,time()+15552000);
}
include_once("postget.php");
include_once("common.php");
$pagetitle = lang("_FAQ");

if ($_REQUEST['client']==1) {
	checklevel(1,$_REQUEST['clientid']);
}

moduleaccess(67);

if ($_REQUEST[id] AND !is_numeric($_REQUEST[id])) {
	messagetop(_ERROR_403,'','index.php',0);
}
if ($_REQUEST[c] AND !is_numeric($_REQUEST[c])) {
	messagetop(_ERROR_403,'','index.php',0);
}
if ($_REQUEST[s] AND !is_numeric($_REQUEST[s])) {
	messagetop(_ERROR_403,'','index.php',0);
}
if ($_REQUEST[i] AND !is_numeric($_REQUEST[i])) {
	messagetop(_ERROR_403,'','index.php',0);
}


session_start();
if ($_SESSION['hd_accesslvl']>0) {
	include("head_template.php");
	$onlycl = "";
}else{
	include("head_template_guest.php");
	$onlycl = "AND onlyclients = 0";
}


if($_POST['rate']) {
	query("UPDATE hd_faq SET rating = rating+".$_POST['rate'].", ratingcount = ratingcount+1 WHERE id=".$_POST['faqid'],0);
}

echo '
<div class="container">
<div class="row">
';

$colorbordes='white';

echo '<table class="table table-striped">';
print("<tr>

	<th>".ucfirst(_CATEGORY)." / ".ucfirst(_SUB_CATEGORY)." / ".ucfirst(_QUESTION)."</th> 
	<th width='1%'>".ucfirst(_VIEWS)."</th>
	<th width='1%'>".ucfirst(_RATING)."</th>
	</tr>");


$cat = query("SELECT * FROM hd_faq_category WHERE numfaqs > 0 AND langs LIKE '%".$currentlang."%' ORDER by position",0);
while($rowC=mysql_fetch_array($cat)) {
	print("<tr><td colspan='3'><b>
	<a href='".$PHP_SELF."?c=".$rowC[id]."#".$rowC[id]."'><font size='+1'>".ucfirst($rowC[name])."</font></a>
	<a name='".$rowC[id]."' c='".$rowC[id]."'></a></b> (".$rowC[numfaqs]." ".strtolower(_FAQS).")</td>");
	print("</tr>");

	$subcat = query("SELECT * FROM hd_faq_subcategory WHERE category=".$rowC[id]." AND numfaqs > 0 AND langs LIKE '%".$currentlang."%' ORDER by position",0);
	while($rowS=mysql_fetch_array($subcat)) {
		print("<tr><td colspan='3'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>
		<a href='".$PHP_SELF."?s=".$rowS[id]."#".$rowS[id]."'>".ucfirst($rowS[name])."</a>
		<a name='".$rowS[id]."' s='".$rowS[id]."'></a></b> (".$rowS[numfaqs]." ".strtolower(_FAQS).")</td>");
		print("</tr>");

		if ($_REQUEST['s']==$rowS[id]) {
			$item = query("SELECT * FROM hd_faq WHERE subcategory=".$rowS[id]." ".$onlycl." AND langs LIKE '%".$currentlang."%' ORDER by position",0);
			while($rowI=mysql_fetch_array($item)) {
                                echo '<tr>';
				if ($rowI['ratingcount']) {$nota = round($rowI['rating']/$rowI['ratingcount'],0);}else{$nota = 0;}

				if ($_REQUEST['i']==$rowI[id]) {
					query("UPDATE hd_faq SET views = views+1 WHERE id=".$rowI[id],0);
					print("<th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<font size='+1'>".$rowI[question]."</font>");
					print("</td>");
					print("<th align='center'>".($rowI[views]+1)."</td>");


					print("<th align='center'><font size='+1'>".$nota."</font> (".$rowI[ratingcount]." ".strtolower(_VOTES).")</td>");
					print("<tr><td colspan='2' style='border: 5px solid ".$colorbordes.";' class=manuals_faq>".stripslashes($rowI[answer])."</td>");
					print("<td nowrap style='border: 5px solid ".$colorbordes.";' valign='top' align='center'>");
					if ($nota >= 1) {print("<img class='sprites star' src='images/transparent.gif' border='0'>");}else{print("<img class='sprites staroff' src='images/transparent.gif' border='0'>");}
					if ($nota >= 2) {print("<img class='sprites star' src='images/transparent.gif' border='0'>");}else{print("<img class='sprites staroff' src='images/transparent.gif' border='0'>");}
					if ($nota >= 3) {print("<img class='sprites star' src='images/transparent.gif' border='0'>");}else{print("<img class='sprites staroff' src='images/transparent.gif' border='0'>");}
					if ($nota >= 4) {print("<img class='sprites star' src='images/transparent.gif' border='0'>");}else{print("<img class='sprites staroff' src='images/transparent.gif' border='0'>");}
					if ($nota >= 5) {print("<img class='sprites star' src='images/transparent.gif' border='0'>");}else{print("<img class='sprites staroff' src='images/transparent.gif' border='0'>");}

					if (strpos($_COOKIE['hd_faqrate'],"x".$rowI[id]."x")===false AND $_POST['faqid']<>$rowI[id]){
						print("<form method='POST' class='form'>");
						print("<select name='rate' class='input-small' onChange='this.form.submit()'>");
						print ("<option value=''>".ucfirst(_YOUR_VOTE)."</option>");
						print ("<option value='5'>".ucfirst(_EXCELLENT)."</option>");
						print ("<option value='4'>".ucfirst(_GOOD)."</option>");
						print ("<option value='3'>".ucfirst(_FAIR)."</option>");
						print ("<option value='2'>".ucfirst(_POOR)."</option>");
						print ("<option value='1'>".ucfirst(_VERY_POOR)."</option>");
						print("</select>");
						print ("<input type='hidden' name='faqid' value='".$rowI[id]."'>");
						print("</form>");
					}

					print("</td>");
					print("</tr>");

				}else{
					print("<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<a href='".$PHP_SELF."?s=".$rowS[id]."&i=".$rowI[id]."#".$rowI[id]."'>".$rowI[question]."</a>
					<a name='".$rowI[id]."' i='".$rowI[id]."'></a>");
					print("</td>");
					print("<td align='center'>".$rowI[views]."</td>");
					print("<td nowrap align='center'>");
					if ($nota >= 1) {print("<img class='sprites starmini' src='images/transparent.gif' border='0'>");}else{print("<img class='sprites staroffmini' src='images/transparent.gif' border='0'>");}
					if ($nota >= 2) {print("<img class='sprites starmini' src='images/transparent.gif' border='0'>");}else{print("<img class='sprites staroffmini' src='images/transparent.gif' border='0'>");}
					if ($nota >= 3) {print("<img class='sprites starmini' src='images/transparent.gif' border='0'>");}else{print("<img class='sprites staroffmini' src='images/transparent.gif' border='0'>");}
					if ($nota >= 4) {print("<img class='sprites starmini' src='images/transparent.gif' border='0'>");}else{print("<img class='sprites staroffmini' src='images/transparent.gif' border='0'>");}
					if ($nota >= 5) {print("<img class='sprites starmini' src='images/transparent.gif' border='0'>");}else{print("<img class='sprites staroffmini' src='images/transparent.gif' border='0'>");}
					print("</td>");
				}
				print("</tr>");
			}
		}

	}

	if ($_REQUEST['c']==$rowC[id]) {
		$item = query("SELECT * FROM hd_faq WHERE category=".$rowC[id]." ".$onlycl." AND subcategory=0 AND langs LIKE '%".$currentlang."%' ORDER by position",0);
		while($rowI=mysql_fetch_array($item)) {
                        echo '<tr>';
			if ($rowI['ratingcount']) {$nota = round($rowI['rating']/$rowI['ratingcount'],0);}else{$nota = 0;}

			if ($_REQUEST['i']==$rowI[id]) {
				query("UPDATE hd_faq SET views = views+1 WHERE id=".$rowI[id],0);
				print("<th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<font size='+1'>".$rowI[question]."</font>");
				print("</th>");
				print("<th>".($rowI[views]+1)."</th>");


				print("<th><font size='+1'>".$nota."</font> (".$rowI[ratingcount]." ".strtolower(_VOTES).")</th>");
				print("<tr><td colspan='2' style='border: 5px solid ".$colorbordes.";' class=manuals_faq>".stripslashes($rowI[answer])."</td>");
				print("<td nowrap id='rate' style='border: 5px solid ".$colorbordes.";' valign='top' align='center'>");


				if ($nota >= 1) {print("<img class='sprites star' src='images/transparent.gif' border='0'>");}else{print("<img class='sprites staroff' src='images/transparent.gif' border='0'>");}
				if ($nota >= 2) {print("<img class='sprites star' src='images/transparent.gif' border='0'>");}else{print("<img class='sprites staroff' src='images/transparent.gif' border='0'>");}
				if ($nota >= 3) {print("<img class='sprites star' src='images/transparent.gif' border='0'>");}else{print("<img class='sprites staroff' src='images/transparent.gif' border='0'>");}
				if ($nota >= 4) {print("<img class='sprites star' src='images/transparent.gif' border='0'>");}else{print("<img class='sprites staroff' src='images/transparent.gif' border='0'>");}
				if ($nota >= 5) {print("<img class='sprites star' src='images/transparent.gif' border='0'>");}else{print("<img class='sprites staroff' src='images/transparent.gif' border='0'>");}

				if (strpos($_COOKIE['hd_faqrate'],"x".$rowI[id]."x")===false AND $_POST['faqid']<>$rowI[id]){
					print("<form method='POST' class='form'>");
					print("<select name='rate' class='input-small' onChange='this.form.submit()'>");
					print ("<option value=''>".ucfirst(_YOUR_VOTE)."</option>");
					print ("<option value='5'>".ucfirst(_EXCELLENT)."</option>");
					print ("<option value='4'>".ucfirst(_GOOD)."</option>");
					print ("<option value='3'>".ucfirst(_FAIR)."</option>");
					print ("<option value='2'>".ucfirst(_POOR)."</option>");
					print ("<option value='1'>".ucfirst(_VERY_POOR)."</option>");
					print("</select>");
					print ("<input type='hidden' name='faqid' value='".$rowI[id]."'>");
					print("</form>");
				}
				print("</td>");
				print("</tr>");
			}else{
				print("<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<a href='".$PHP_SELF."?c=".$rowC[id]."&i=".$rowI[id]."#".$rowC[id]."'>".$rowI[question]."</a>
				<a name='".$rowC[id]."' c='".$rowC[id]."'></a>");
				print("</td>");
				print("<td align='center'>".$rowI[views]."</td>");
				print("<td align='center' nowrap>");
				if ($nota >= 1) {print("<img class='sprites starmini' src='images/transparent.gif' border='0'>");}else{print("<img class='sprites staroffmini' src='images/transparent.gif' border='0'>");}
				if ($nota >= 2) {print("<img class='sprites starmini' src='images/transparent.gif' border='0'>");}else{print("<img class='sprites staroffmini' src='images/transparent.gif' border='0'>");}
				if ($nota >= 3) {print("<img class='sprites starmini' src='images/transparent.gif' border='0'>");}else{print("<img class='sprites staroffmini' src='images/transparent.gif' border='0'>");}
				if ($nota >= 4) {print("<img class='sprites starmini' src='images/transparent.gif' border='0'>");}else{print("<img class='sprites staroffmini' src='images/transparent.gif' border='0'>");}
				if ($nota >= 5) {print("<img class='sprites starmini' src='images/transparent.gif' border='0'>");}else{print("<img class='sprites staroffmini' src='images/transparent.gif' border='0'>");}
				print("</td>");
			}
			print("</tr>");
		}
	}

}

print("</table>");



echo '
</div>
</div>
';
include("foot_template.php");
?>
	
