<?php
include("postget.php");
include_once("common.php");
checklevel(2,$_REQUEST['clientid']);

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


<table width="98%" class="table table-bordered">
		<tr>
		<td align="center" width="100%">
';
echo ucfirst(_FAQ);
echo '
		</td>
		</tr>
';

echo '
			<tr valign="top">
				<td>

';

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





if ($_REQUEST['o']=="C") {
//	$data = query("SELECT max(position) FROM hd_faq_category WHERE langs LIKE '%".$currentlang."%'",1);
//	$lastorder = $data[0];
//	$data = query("SELECT min(position) FROM hd_faq_category WHERE langs LIKE '%".$currentlang."%'",1);
//	$firstorder = $data[0];
//
//	if ($option == 'move_up') {
//		$query = "SELECT * FROM hd_faq_category WHERE position = ".$current_order." AND langs LIKE '%".$currentlang."%'";
//		$result = mysql_query ($query);
//		$data = mysql_fetch_array ($result);
//		$premid = $data['id'];
//		$order1 = $current_order - 1;
//		$query = "UPDATE hd_faq_category SET position = ".$current_order." WHERE position = ".$order1."";
//		$result = mysql_query ($query);
//		$query = "UPDATE hd_faq_category SET position = ".$order1." WHERE id = ".$premid."";
//		$result = mysql_query ($query);
//	}
//	if ($option == 'move_down') {
//		$query = "SELECT * FROM hd_faq_category WHERE position = ".$current_order." AND langs LIKE '%".$currentlang."%'";
//		$result = mysql_query ($query);
//		$data = mysql_fetch_array ($result);
//		$premid = $data['id'];
//		$order1 = $current_order + 1;
//		$query = "UPDATE hd_faq_category SET position = ".$current_order." WHERE position = ".$order1."";
//		$result = mysql_query ($query);
//		$query = "UPDATE hd_faq_category SET position = ".$order1." WHERE id = ".$premid."";
//		$result = mysql_query ($query);
//	}






}elseif ($_REQUEST['o']=="S") {


	if (!$_REQUEST['category']) {
		print("
		<form method='POST'><b>".ucfirst(_CATEGORY).":</b>
		<select name='category' onChange='this.form.submit()'>");
		$query="SELECT id, name FROM hd_faq_category WHERE langs LIKE '%".$currentlang."%' ORDER BY position";
		$cats=mysql_query($query,$db_link);
		print ("<option value=''>** ".ucfirst(_SELECT_AN_OPTION)." **</option>");
		while($categ=mysql_fetch_array($cats)) {
			if ($_POST['category']) {
				print ("<option value='".$categ[id]."' ".sele($_POST['category'],$categ[id]).">".$categ[name]."</option>");
			}else{
				print ("<option value='".$categ[id]."' ".sele($row[category],$categ[id]).">".$categ[name]."</option>");
			}
		};
		print("</select>
	</form>
	");
	}

//	if ($_REQUEST['category']) {
//		$data = query("SELECT max(position) FROM hd_faq_subcategory WHERE category = ".$_REQUEST['category']." AND langs LIKE '%".$currentlang."%'",1);
//		$lastorder = $data[0];
//		$data = query("SELECT min(position) FROM hd_faq_subcategory WHERE category = ".$_REQUEST['category']." AND langs LIKE '%".$currentlang."%'",1);
//		$firstorder = $data[0];

//		if ($option == 'move_up') {
//			$query = "SELECT * FROM hd_faq_subcategory WHERE position = ".$current_order." AND category = ".$_REQUEST['category']." AND langs LIKE '%".$currentlang."%'";
//			$result = mysql_query ($query);
//			$data = mysql_fetch_array ($result);
//			$premid = $data['id'];
//			$order1 = $current_order - 1;
//			$query = "UPDATE hd_faq_subcategory SET position = ".$current_order." WHERE position = ".$order1." AND category = ".$data['category']." AND langs LIKE '%".$currentlang."%'";
//			$result = mysql_query ($query);
//			$query = "UPDATE hd_faq_subcategory SET position = ".$order1." WHERE id = ".$premid." AND category = ".$data['category']." AND langs LIKE '%".$currentlang."%'";
//			$result = mysql_query ($query);
//		}
//		if ($option == 'move_down') {
//			$query = "SELECT * FROM hd_faq_subcategory WHERE position = ".$current_order." AND category = ".$_REQUEST['category']." AND langs LIKE '%".$currentlang."%' AND langs LIKE '%".$currentlang."%'";
//			$result = mysql_query ($query);
//			$data = mysql_fetch_array ($result);
//			$premid = $data['id'];
//			$order1 = $current_order + 1;
//			$query = "UPDATE hd_faq_subcategory SET position = ".$current_order." WHERE position = ".$order1." AND category = ".$data['category']." AND langs LIKE '%".$currentlang."%'";
//			$result = mysql_query ($query);
//			$query = "UPDATE hd_faq_subcategory SET position = ".$order1." WHERE id = ".$premid." AND category = ".$data['category']." AND langs LIKE '%".$currentlang."%'";
//			$result = mysql_query ($query);
//		}
//	}






}elseif ($_REQUEST['o']=="I") {


	//	test('categoria',$_REQUEST['category']);
	//	test('subcategoria',$_REQUEST['subcategory']);

	print("<form method='POST'>");

	if (!$_REQUEST['category']) {
		print("
		<b>".ucfirst(_CATEGORY).":</b>
		<select name='category' onChange='this.form.submit()'>");
		$query="SELECT id, name FROM hd_faq_category WHERE numfaqs > 1 AND langs LIKE '%".$currentlang."%' ORDER BY position";
		$cats=mysql_query($query,$db_link);
		print ("<option value=''>** ".ucfirst(_SELECT_AN_OPTION)." **</option>");
		while($categ=mysql_fetch_array($cats)) {
			if ($_REQUEST['category']) {
				print ("<option value='".$categ[id]."' ".sele($_REQUEST['category'],$categ[id]).">".$categ[name]."</option>");
			}else{
				print ("<option value='".$categ[id]."' ".sele($row[category],$categ[id]).">".$categ[name]."</option>");
			}
		};
		print("</select>");
	}else{
		print("
		<b>".ucfirst(_CATEGORY).":</b>
		<select name='category' disabled>");
		$query="SELECT id, name FROM hd_faq_category WHERE langs LIKE '%".$currentlang."%' ORDER BY position";
		$cats=mysql_query($query,$db_link);
		print ("<option value=''>** ".ucfirst(_SELECT_AN_OPTION)." **</option>");
		while($categ=mysql_fetch_array($cats)) {
			if ($_REQUEST['category']) {
				print ("<option value='".$categ[id]."' ".sele($_REQUEST['category'],$categ[id]).">".$categ[name]."</option>");
			}else{
				print ("<option value='".$categ[id]."' ".sele($row[category],$categ[id]).">".$categ[name]."</option>");
			}
		};
		print("</select>");

	}

	if ($_REQUEST['category']){
		print("
			<b>".ucfirst(_SUB_CATEGORY).":</b>
			<input name='category' type='hidden' value='".$_REQUEST[category]."'>
			<select name='subcategory' onChange='this.form.submit()'>");
		$query="SELECT id, name FROM hd_faq_subcategory WHERE numfaqs > 1 AND category='".$_REQUEST[category]."' AND langs LIKE '%".$currentlang."%' ORDER BY position";
		$subcats=mysql_query($query,$db_link);
		print ("<option value=''>** ".ucfirst(_NONE)." **</option>");
		while($subcateg=mysql_fetch_array($subcats)) {
			if ($_REQUEST['subcategory']) {
				print ("<option value='".$subcateg[id]."' ".sele($_REQUEST['subcategory'],$subcateg[id]).">".$subcateg[name]."</option>");
			}else{
				print ("<option value='".$subcateg[id]."' ".sele($row[subcategory],$subcateg[id]).">".$subcateg[name]."</option>");
			}
		};
		print("</select>");
	}
	print("</form>");



//	if ($_REQUEST['category']) {

//		if ($_REQUEST['subcategory']) {
//			$condicion = " subcategory = ".$_REQUEST['subcategory']." AND langs LIKE '%".$currentlang."%'";
//		}else{
//			$condicion = " category = ".$_REQUEST['category']." AND subcategory=0 AND langs LIKE '%".$currentlang."%'";
//		}
		//test('condicion',$condicion);
//		$data = query("SELECT max(position) FROM hd_faq WHERE ".$condicion,1);
//		$lastorder = $data[0];
//		$data = query("SELECT min(position) FROM hd_faq WHERE ".$condicion,1);
//		$firstorder = $data[0];
//	}
//	if ($option == 'move_up') {
//		$query = "SELECT * FROM hd_faq WHERE position = ".$current_order." AND ".$condicion."";
//		$result = mysql_query ($query);
//		$data = mysql_fetch_array ($result);
//		$premid = $data['id'];
//		$order1 = $current_order - 1;
//		$query = "UPDATE hd_faq SET position = ".$current_order." WHERE position = ".$order1." AND category = ".$data['category']." AND subcategory = ".$data['subcategory']." AND langs LIKE '%".$currentlang."%'";
//		$result = mysql_query ($query);
//		$query = "UPDATE hd_faq SET position = ".$order1." WHERE id = ".$premid." AND category = ".$data['category']." AND subcategory = ".$data['subcategory']." AND langs LIKE '%".$currentlang."%'";
//		$result = mysql_query ($query);
//	}
//	if ($option == 'move_down') {
//		$query = "SELECT * FROM hd_faq WHERE position = ".$current_order." AND ".$condicion."";
//		$result = mysql_query ($query);
//		$data = mysql_fetch_array ($result);
//		$premid = $data['id'];
//		$order1 = $current_order + 1;
//		$query = "UPDATE hd_faq SET position = ".$current_order." WHERE position = ".$order1." AND category = ".$data['category']." AND subcategory = ".$data['subcategory']." AND langs LIKE '%".$currentlang."%'";
//		$result = mysql_query ($query);
//		$query = "UPDATE hd_faq SET position = ".$order1." WHERE id = ".$premid." AND category = ".$data['category']." AND subcategory = ".$data['subcategory']." AND langs LIKE '%".$currentlang."%'";
//		$result = mysql_query ($query);
//	}

}

























if ($_REQUEST['o']=="C" OR $_REQUEST['category']) {

	if ($_REQUEST['o']=="C") {
		print("<table id='table-1' width='100%' border=0>");
		print("<tr id='0' class='nodrop nodrag'>
		<th>".ucfirst(_SORT)."&nbsp;</th>
		<th colspan=6>".ucfirst(_CATEGORIES)."</th> 
		</tr>");

	}elseif ($_REQUEST['o']=="S") {
		print("<table id='table-1' width='100%' border=0>");
		print("<tr id='0' class='nodrop nodrag'>
		<th>".ucfirst(_SORT)."&nbsp;</th>
		<th colspan=6>".ucfirst(_CATEGORIES)." / ".ucfirst(_SUB_CATEGORIES)."</th> 
		</tr>");

	}elseif ($_REQUEST['o']=="I") {
		print("<table id='table-1' width='100%' border=0>");
		print("<tr id='0' class='nodrop nodrag'>
		<th>".ucfirst(_SORT)."&nbsp;</th>
		<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>
		</tr>");
	}


	if ($_REQUEST['category']) {
		$cat = query("SELECT * FROM hd_faq_category WHERE id=".$_REQUEST['category']." AND langs LIKE '%".$currentlang."%' ORDER by position",0);
	}else{
		$cat = query("SELECT * FROM hd_faq_category WHERE langs LIKE '%".$currentlang."%' ORDER by position",0);
	}
	
	$_SESSION['ordenar'] = "[hd_faq_category]{position}(id)<and langs LIKE '%".$currentlang."%'>";
	while($rowC=mysql_fetch_array($cat)) {

		print("<tr><td class='dragHandle'>&nbsp;</td>");
		print("<td colspan='6'>");
		print("<b>".ucfirst($rowC[name]));
		print("</b> (".$rowC[numfaqs]." ".strtolower(_FAQS).")");
		print("</td>");

		print("</tr>");
		if (($_REQUEST['o']=="S" OR $_REQUEST['o']=="I") AND $_REQUEST['category']) {
			$subcat = query("SELECT * FROM hd_faq_subcategory WHERE category=".$_REQUEST['category']." AND langs LIKE '%".$currentlang."%' ORDER by position",0);
			$_SESSION['ordenar'] = "[hd_faq_subcategory]{position}(id)<and langs LIKE '%".$currentlang."%'>";
			while($rowS=mysql_fetch_array($subcat)) {
				print("<tr><td class='dragHandle'>&nbsp;</td>");
				print("<td colspan='6'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
				print("<b>".ucfirst($rowS[name]));
				print("</b> (".$rowS[numfaqs]." ".strtolower(_FAQS).")");
				print("</td>");

				print("</tr>");

				if ($_REQUEST['o']=="I" AND $_REQUEST['category'] AND $_REQUEST['subcategory']) {
					$item = query("SELECT * FROM hd_faq WHERE category=".$rowC[id]." AND subcategory=".$rowS[id]." AND langs LIKE '%".$currentlang."%' ORDER by position",0);
					$_SESSION['ordenar'] = "[hd_faq]{position}(id)<and langs LIKE '%".$currentlang."%'>";
					while($rowI=mysql_fetch_array($item)) {
						if ($rowS[id]==$_REQUEST['subcategory']) {
							print("<tr><td class='dragHandle'>&nbsp;</td>");
							print("<td>");
							print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
							print("".strip_tags($rowI[question])."</td>");
							print("<td>".substr(strip_tags($rowI[answer]),0,100)."</td>");
							print("<td align='center'>".ucfirst($rowI[editor])."</td>");
							print("<td align='center'>".ucfirst($rowI[views])."</td>");
							print("<td align='center'>".ucfirst($rowI[rating])."</td>");
							print("<td align='center'>"); if ($rowI[onlyclients]==1) {print("<img class='sprites green_status' src='images/transparent.gif' border='0'>");} print("</td>");
							print("</td></tr>");
						}
					}
				}
			}
		}
		if ($_REQUEST['o']=="I" AND $_REQUEST['category'] AND !$_REQUEST['subcategory']) {
			$item = query("SELECT * FROM hd_faq WHERE category=".$rowC[id]." AND subcategory=0 AND langs LIKE '%".$currentlang."%' ORDER by position",0);
			$_SESSION['ordenar'] = "[hd_faq]{position}(id)<and langs LIKE '%".$currentlang."%'>";
			while($rowI=mysql_fetch_array($item)) {
				print("<tr><td class='dragHandle'>&nbsp;</td>");
				print("<td>");
				print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
				print("".$rowI[question]."</td>");
				print("<td>".substr(strip_tags($rowI[answer]),0,100)."</td>");
				print("<td align='center'>".ucfirst($rowI[editor])."</td>");
				print("<td align='center'>".ucfirst($rowI[views])."</td>");
				print("<td align='center'>".ucfirst($rowI[rating])."</td>");
				print("<td align='center'>"); if ($rowI[onlyclients]==1) {print("<img class='sprites green_status' src='images/transparent.gif' border='0'>");} print("</td>");
				print("</td></tr>");
			}
		}
	}
	print("</table>");
}


echo '
		</td>
		</tr>
		</table>
</div>
</div>
';

include("foot_template.php");
?>
	
