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

$pagetitle = _NOTES;

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


include("head_template.php");

if ($_SESSION['hd_accesslvl'] == 4) {
	$onlycl = "";
}else{
	$onlycl = "AND onlyclients = ".$_SESSION[hd_accesslvl];
}

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

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

///////////////////////////////////////////////// tabla grande, dividida en 2 partes
print("<table>
<tr>
<td 
width='45%' 
valign='top' 
background='images/borderspiralleft.jpg'
style='padding-top: 20; padding-bottom: 20; padding-left: 20; padding-right: 20;'
>");
////////////////////////////////////////////////////////////////////////////////////

print("<table width='100%'>");

print("<tr><td align='center' colspan='3'>
<form method='POST'>
<b>".ucfirst(_SEARCH).":</b> <input name='search' size=30 value=".$_REQUEST['search']."> 
<input type='submit' name='submitsearch' value='"._SEARCH."' class='btnform'>
</form>");
if ($_REQUEST['search']) {
	print ("<a href='".$serverurl."/notes.php'>".ucfirst(_RESET_SEARCH)."</a>");
}

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

if ($_REQUEST['search']) {
	print("<tr><td align='center' colspan='3'><b>".ucfirst(_RESULTS)."</b></td></tr>");

	$item = query("SELECT * FROM hd_notes 
	WHERE (`title` LIKE '%".$_REQUEST['search']."%' OR `description` LIKE '%".$_REQUEST['search']."%')  ".$onlycl." ORDER by position",0);

	//	WHERE category=".$rowC[id]." ".$onlycl." AND subcategory=0 ORDER by position",0);
	while($rowI=mysql_fetch_array($item)) {
		print("<tr>");

		if ($rowI['ratingcount']) {$nota = round($rowI['rating']/$rowI['ratingcount'],0);}else{$nota = 0;}

		if ($_REQUEST['i']==$rowI[id]) {
			query("UPDATE hd_notes SET views = views+1 WHERE id=".$rowI[id],0);
			print("<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<b>".$rowI[title]."</b>");
			$title = $rowI[title];
			print("</td>");
			print("<td align='center'>".($rowI[views]+1)." ".strtolower(_VIEWS)."</td>");


			print("<td align='center'>".ucfirst(_RATING).": <font size='+1'>".$nota."</font> (".$rowI[ratingcount]." ".strtolower(_VOTES).")");

			/////////////////////////////////////// estrellas
			if ($nota==1) {$notatitulo = _VERY_POOR;
			}elseif ($nota==2) {$notatitulo = _POOR;
			}elseif ($nota==3) {$notatitulo = _FAIR;
			}elseif ($nota==4) {$notatitulo = _GOOD;
			}elseif ($nota==5) {$notatitulo = _EXCELLENT;
			}

			if ($nota >= 1) {print("<img class='sprites star' src='images/transparent.gif' border='0' title='".ucfirst($notatitulo)."'>");}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' title='".ucfirst($notatitulo)."'>");}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' title='".ucfirst($notatitulo)."'>");}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' title='".ucfirst($notatitulo)."'>");}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' title='".ucfirst($notatitulo)."'>");}else{print("<img class='sprites staroff' src='images/transparent.gif' border='0'>");}
			/////////////////////////////////////////////////////////////

			if (strpos($_COOKIE['hd_notesrate'],"x".$rowI[id]."x")===false AND $_POST['noteid']<>$rowI[id]){
				print("<form method='POST' class='form'>");
				print("<select name='rate' 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='noteid' value='".$rowI[id]."'>");
				print("</form>");
			}


			print("</td>");


			$content = $rowI[description];
                        
		}else{
			print("<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<a href='".$PHP_SELF."?c=".$rowC[id]."&i=".$rowI[id]."&search=".$_REQUEST[search]."'><font color='blue'>".$rowI[title]."</font></a>
				");
			print("</td>");
			print("<td align='center' style='color: blue;'>".$rowI[views]." ".strtolower(_VIEWS)."</td>");
			print("<td 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>");
	}

}else{

	print("<tr><td align='center' colspan='3'><b>".ucfirst(_INDEX)."</b></td></tr>");

	/////////////////////////////////// CATEGORIAS (MANUALES)
	$cat = query("SELECT * FROM hd_notes_category WHERE numnotes > 0 ORDER by position",0);
	while($rowC=mysql_fetch_array($cat)) {
		print("<tr>");
		print("<td colspan='3'><b>
	<a href='".$PHP_SELF."?c=".$rowC[id]."'><font size='+1' color='black'>".ucfirst($rowC[name])."</font></a>
	</b> (".$rowC[numnotes]." ".strtolower(_NOTES).")</td>");
		print("</tr>");

		/////////////////////////////////// SUB CATEGORIAS (CAPITULOS)
		$subcat = query("SELECT * FROM hd_notes_subcategory WHERE category=".$rowC[id]." AND numnotes > 0 ORDER by position",0);
		while($rowS=mysql_fetch_array($subcat)) {
			print("<tr>");
			print("<td colspan='3' style='color: #666666;'>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<b>
		<a href='".$PHP_SELF."?s=".$rowS[id]."'><font color='#666666'>".ucfirst($rowS[name])."</font></a>
		</b> (".$rowS[numnotes]." ".strtolower(_NOTES).")
		</td>");
			print("</tr>");

			/////////////////////////////////// ITEMS dentro de SUB CATEGORIAS (CAPITULOS)
			if ($_REQUEST['s']==$rowS[id]) {
				$item = query("SELECT * FROM hd_notes WHERE subcategory=".$rowS[id]." ".$onlycl." ORDER by position",0);
				while($rowI=mysql_fetch_array($item)) {
					print("<tr>");

					if ($rowI['ratingcount']) {$nota = round($rowI['rating']/$rowI['ratingcount'],0);}else{$nota = 0;}

					if ($_REQUEST['i']==$rowI[id]) {
						query("UPDATE hd_notes SET views = views+1 WHERE id=".$rowI[id],0);
						print("<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<b>".$rowI[title]."</b>");
						$title = $rowI[title];
						print("</td>");
						print("<td>".($rowI[views]+1)." ".strtolower(_VIEWS)."</td>");


						print("<td>".ucfirst(_RATING).": <font size='+1'>".$nota."</font> (".$rowI[ratingcount]." ".strtolower(_VOTES).")");

						/////////////////////////////////////// estrellas
						if ($nota==1) {$notatitulo = _VERY_POOR;
						}elseif ($nota==2) {$notatitulo = _POOR;
						}elseif ($nota==3) {$notatitulo = _FAIR;
						}elseif ($nota==4) {$notatitulo = _GOOD;
						}elseif ($nota==5) {$notatitulo = _EXCELLENT;
						}

						if ($nota >= 1) {print("<img class='sprites star' src='images/transparent.gif' border='0' title='".ucfirst($notatitulo)."'>");}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' title='".ucfirst($notatitulo)."'>");}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' title='".ucfirst($notatitulo)."'>");}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' title='".ucfirst($notatitulo)."'>");}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' title='".ucfirst($notatitulo)."'>");}else{print("<img class='sprites staroff' src='images/transparent.gif' border='0'>");}

						if (strpos($_COOKIE['hd_notesrate'],"x".$rowI[id]."x")===false AND $_POST['noteid']<>$rowI[id]){
							print("<form method='POST' class='form'>");
							print("<select name='rate' 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='noteid' value='".$rowI[id]."'>");
							print("</form>");
						}
						print("</td>");

						$content = $rowI[description];

					}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]."'><font color='blue'>".$rowI[title]."</font></a>
					");
						print("</td>");
						print("<td align='center' style='color: blue;'>".$rowI[views]." ".strtolower(_VIEWS)."</td>");
						print("<td align='center' style='color: blue;'>");
						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>");
				}
			}

		}

		/////////////////////////////////// ITEMS dentro de CATEGORIAS (MANUALES)
		if ($_REQUEST['c']==$rowC[id]) {
			$item = query("SELECT * FROM hd_notes WHERE category=".$rowC[id]." ".$onlycl." AND subcategory=0 ORDER by position",0);
			while($rowI=mysql_fetch_array($item)) {
				print("<tr>");

				if ($rowI['ratingcount']) {$nota = round($rowI['rating']/$rowI['ratingcount'],0);}else{$nota = 0;}

				if ($_REQUEST['i']==$rowI[id]) {
					query("UPDATE hd_notes SET views = views+1 WHERE id=".$rowI[id],0);
					print("<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<b>".$rowI[title]."</b>");
					$title = $rowI[title];
					print("</td>");
					print("<td align='center'>".($rowI[views]+1)." ".strtolower(_VIEWS)."</td>");


					print("<td align='center'>".ucfirst(_RATING).": <font size='+1'>".$nota."</font> (".$rowI[ratingcount]." ".strtolower(_VOTES).")");

					/////////////////////////////////////// estrellas
					if ($nota==1) {$notatitulo = _VERY_POOR;
					}elseif ($nota==2) {$notatitulo = _POOR;
					}elseif ($nota==3) {$notatitulo = _FAIR;
					}elseif ($nota==4) {$notatitulo = _GOOD;
					}elseif ($nota==5) {$notatitulo = _EXCELLENT;
					}

					if ($nota >= 1) {print("<img class='sprites star' src='images/transparent.gif' border='0' title='".ucfirst($notatitulo)."'>");}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' title='".ucfirst($notatitulo)."'>");}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' title='".ucfirst($notatitulo)."'>");}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' title='".ucfirst($notatitulo)."'>");}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' title='".ucfirst($notatitulo)."'>");}else{print("<img class='sprites staroff' src='images/transparent.gif' border='0'>");}

					if (strpos($_COOKIE['hd_notesrate'],"x".$rowI[id]."x")===false AND $_POST['noteid']<>$rowI[id]){
						print("<form method='POST' class='form'>");
						print("<select name='rate' 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='noteid' value='".$rowI[id]."'>");
						print("</form>");
					}


					print("</td>");

					$content = $rowI[description];
                                        
				}else{
					print("<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<a href='".$PHP_SELF."?c=".$rowC[id]."&i=".$rowI[id]."'><font color='blue'>".$rowI[title]."</font></a>
				");
					print("</td>");
					print("<td align='center' style='color: blue;'>".$rowI[views]." ".strtolower(_VIEWS)."</td>");
					print("<td 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>");
			}
		}

	}

}
print("</table>");



///////////////////////////////////////////////// tabla grande, division en 2 partes
print("</td>
<td width='55%' 
valign='top' 
align='left' 
background='images/borderspiral.jpg' 
style='padding-top: 20; padding-bottom: 20; padding-left: 120; padding-right: 20;'
 >");
////////////////////////////////////////////////////////////////////////////////////


if (!$title) {
	print("<font size='+1' color='black'><i><b>".ucfirst(_SELECT_AN_OPTION_IN_THE_INDEX_ON_THE_LEFT)."</b></i></font>");
}else{
	if ($_REQUEST['search']) {
		$title=str_replace($_REQUEST['search'],'<font color=red><b>'.$_REQUEST['search'].'</b></font>',$title);
		$content=str_replace($_REQUEST['search'],'<font color=red><b>'.$_REQUEST['search'].'</b></font>',$content);
	}
	print("<font size='+1' color='black'><i><b>".$title."</b></i></font>");
	print("<br><font color='black' class=manuals_faq>".stripslashes($content)."</font>");
}


///////////////////////////////////////////////// tabla grande, cierre
print("</td></tr></table>");
////////////////////////////////////////////////////////////////////////////////////



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

include("foot_template.php");
?>
	
