<?php
include("postget.php");
include_once("common.php");
$pagetitle = _FAQ;

checklevel(2,$_REQUEST['clientid']);


include("head_template.php");
echo '
<div class="container">
	<div class="row">
';

print(messagetopinthispage(_ONLY_ARE_DISPLAYED_THE_ITEMS_RELATED_TO_THE_CURRENT_LANGUAGE." (".langname($currentlang).")","",2));


////////// actualizar numfaqs
$cat = query("SELECT * FROM hd_faq_category WHERE langs LIKE '%".$currentlang."%' ORDER by position",0);
while($rowC=mysql_fetch_array($cat)) {
	$numfaqs = query("SELECT id FROM hd_faq WHERE langs LIKE '%".$currentlang."%' AND category=".$rowC[id],2);
	query("UPDATE hd_faq_category SET numfaqs = ".$numfaqs." WHERE id = ".$rowC[id]."",0);

	$subcat = query("SELECT * FROM hd_faq_subcategory WHERE category=".$rowC[id]." AND langs LIKE '%".$currentlang."%' ORDER by position",0);
	while($rowS=mysql_fetch_array($subcat)) {
		$numfaqs = query("SELECT id FROM hd_faq WHERE langs LIKE '%".$currentlang."%' AND subcategory=".$rowS[id],2);
		query("UPDATE hd_faq_subcategory SET numfaqs = ".$numfaqs." WHERE id = ".$rowS[id]."",0);
	}
}
/////////////////////////////


graybutton("faq_C.php",_ADD_CATEGORY);
graybutton("faq_S.php",_ADD_SUB_CATEGORY);
graybutton("faq_I.php",_ADD_FAQ);


echo '<table class="table table-striped">';


$cat = query("SELECT * FROM hd_faq_category WHERE langs LIKE '%".$currentlang."%' ORDER by position",0);
while($rowC=mysql_fetch_array($cat)) {
	print("<tr>
	<th>".ucfirst(_QUESTION)."</th> 
	<th>".ucfirst(_ANSWER)."</th> 
	<th>".ucfirst(_EDITOR)."</th>
	<th>".ucfirst(_VIEWS)."</th>
	<th>".ucfirst(_RATING)."</th>
	<th>".ucfirst(_ONLY_CLIENTS)."</th>
	<th>".ucfirst(_OPTIONS)."</th>
	</tr>");


	print("<tr class='row1'>");
	print("<td colspan='6' style='border: 1px solid black;'><b><font size='+1'>".ucfirst($rowC[name])."</font></b> (".$rowC[numfaqs]." ".strtolower(_FAQS).")</td>");
	print("<td align='left' style='border: 1px solid black;'>");
	print("<a href='".$serverurl."/faq_C.php?id=$rowC[id]'><img class='sprites edit' src='images/transparent.gif' border='0' title='"._EDIT."'></a>");
	if ($rowC[numfaqs]==0) {
		print("<a href='".$serverurl."/faq_del.php?id=$rowC[id]&w=C&text=$rowC[name]'><img class='sprites del' src='images/transparent.gif' border='0' title='"._DELETE."'></a>");
	}
	print("</td>
	</tr>");

	$subcat = query("SELECT * FROM hd_faq_subcategory WHERE category=".$rowC[id]." AND langs LIKE '%".$currentlang."%' ORDER by position",0);
	while($rowS=mysql_fetch_array($subcat)) {
		print("<tr class='row1'>");
		print("<td colspan='6' style='border: 1px solid gray;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>".ucfirst($rowS[name])."</b> (".$rowS[numfaqs]." ".strtolower(_FAQS).")</td>");
		print("<td align='left' style='border: 1px solid gray;'>");
		print("<a href='".$serverurl."/faq_S.php?id=$rowS[id]'><img class='sprites edit' src='images/transparent.gif' border='0' title='"._EDIT."'></a>");
		if ($rowS[numfaqs]==0) {
			print("<a href='".$serverurl."/faq_del.php?id=$rowS[id]&w=S&text=$rowS[name]'><img class='sprites del' src='images/transparent.gif' border='0' title='"._DELETE."'></a>");
		}
		print("</td>
		</tr>");

		$item = query("SELECT * FROM hd_faq WHERE subcategory=".$rowS[id]." AND langs LIKE '%".$currentlang."%' ORDER by position",0);
		while($rowI=mysql_fetch_array($item)) {

			if ($_REQUEST['rellenar'] == 'y') {
				$visitas = rand(101,850);
				query("UPDATE hd_faq SET views = ".$visitas." WHERE id=".$rowI[id],0);
				$myporcentaje =  rand(30,90) / 100; // porcentaje de visitas que califican
				$myratingcount = $visitas * $myporcentaje; 
				$myrate = rand(2,5);
				$myrating = $myrate * $myratingcount; 
				query("UPDATE hd_faq SET rating = ".$myrating.", ratingcount = ".$myratingcount." WHERE id=".$rowI[id],0);
			}


			print("<tr class='row2'>");
			print("<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".strip_tags($rowI[question])."</td>");
			print("<td>".substr(strip_tags($rowI[answer]),0,100)."...</td>");
			print("<td align='center'>".ucfirst($rowI[editor])."<br>(".date($df,$rowI[editeddate]).")</td>");
			print("<td align='center'>".$rowI[views]."</td>");
			print("<td align='center' nowrap>");
			if ($rowI['ratingcount']) {$nota = round($rowI['rating']/$rowI['ratingcount'],0);}else{$nota = 0;}
			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("<td align='center'>"); if ($rowI[onlyclients]==1) {print("<img class='sprites green_status' src='images/transparent.gif' border='0'>");} print("&nbsp;</td>");

			print("<td align='left'>");
			print("<a href='".$serverurl."/faq_I.php?id=$rowI[id]'><img class='sprites edit' src='images/transparent.gif' border='0' title='"._EDIT."'></a>");
			print("<a href='".$serverurl."/faq_del.php?id=$rowI[id]&w=I&text=$rowI[question]'><img class='sprites del' src='images/transparent.gif' border='0' title='"._DELETE."'></a>");
			// print("<a href='".$serverurl."/manuals_I.php?newquestion64=".str_replace('=','|',base64_encode($rowI[question]))."&newanswer64=".str_replace('=','|',base64_encode($rowI[answer]))."'><img class='sprites right_arrow' src='images/transparent.gif' border='0' title='"._COPY_TO_MANUALS."'></a>");
			print("<a href='".$serverurl."/manuals_I.php?faqid=$rowI[id]'><img class='sprites right_arrow' src='images/transparent.gif' border='0' title='"._COPY_TO_MANUALS."'></a>");
			print("</td>
			</tr>");
		}
	}

	$item = query("SELECT * FROM hd_faq WHERE category=".$rowC[id]." AND subcategory=0 AND langs LIKE '%".$currentlang."%' ORDER by position",0);
	while($rowI=mysql_fetch_array($item)) {
		
		if ($_REQUEST['rellenar'] == 'y') {
			$visitas = rand(2018,8500);
			query("UPDATE hd_faq SET views = ".$visitas." WHERE id=".$rowI[id],0);
			$myporcentaje =  rand(30,90) / 100; // porcentaje de visitas que califican
			$myratingcount = $visitas * $myporcentaje; 
			$myrate = rand(2,5);
			$myrating = $myrate * $myratingcount; 
			query("UPDATE hd_faq SET rating = ".$myrating.", ratingcount = ".$myratingcount." WHERE id=".$rowI[id],0);
		}
		
		print("<tr class='row2'>");
		print("<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".strip_tags($rowI[question])."</td>");
		print("<td>".substr(strip_tags($rowI[answer]),0,100)."...</td>");
		print("<td align='center'>".ucfirst($rowI[editor])."<br>(".date($df,$rowI[editeddate]).")</td>");
		print("<td align='center'>".$rowI[views]."</td>");
		print("<td align='center' nowrap>");
		if ($rowI['ratingcount']) {$nota = round($rowI['rating']/$rowI['ratingcount'],0);}else{$nota = 0;}
		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("<td align='center'>"); if ($rowI[onlyclients]==1) {print("<img class='sprites green_status' src='images/transparent.gif' border='0'>");} print("&nbsp;</td>");

		print("<td align='left'>");
		print("<a href='".$serverurl."/faq_I.php?id=$rowI[id]'><img class='sprites edit' src='images/transparent.gif' border='0' title='"._EDIT."'></a>");
		print("<a href='".$serverurl."/faq_del.php?id=$rowI[id]&w=I&text=$rowI[question]'><img class='sprites del' src='images/transparent.gif' border='0' title='"._DELETE."'></a>");
		// print("<a href='".$serverurl."/manuals_I.php?newquestion64=".str_replace('=','|',base64_encode($rowI[question]))."&newanswer64=".str_replace('=','|',base64_encode($rowI[answer]))."'><img class='sprites right_arrow' src='images/transparent.gif' border='0' title='"._COPY_TO_MANUALS."'></a>");
		print("<a href='".$serverurl."/manuals_I.php?faqid=$rowI[id]'><img class='sprites right_arrow' src='images/transparent.gif' border='0' title='"._COPY_TO_MANUALS."'></a>");
		print("</td>
			</tr>");
	}

}






print("</table>");


graybutton("faq_C.php",_ADD_CATEGORY);
graybutton("faq_S.php",_ADD_SUB_CATEGORY);
graybutton("faq_I.php",_ADD_FAQ);

echo '
</div>
</div>
';

include("foot_template.php");
?>
	
