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

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


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

////////// actualizar numnotes
$cat = query("SELECT * FROM hd_notes_category ORDER by position",0);
while($rowC=mysql_fetch_array($cat)) {
	$numnotes = query("SELECT id FROM hd_notes WHERE category=".$rowC[id],2);
	query("UPDATE hd_notes_category SET numnotes = ".$numnotes." WHERE id = ".$rowC[id]."",0);

	$subcat = query("SELECT * FROM hd_notes_subcategory WHERE category=".$rowC[id]." ORDER by position",0);
	while($rowS=mysql_fetch_array($subcat)) {
		$numnotes = query("SELECT id FROM hd_notes WHERE subcategory=".$rowS[id],2);
		query("UPDATE hd_notes_subcategory SET numnotes = ".$numnotes." WHERE id = ".$rowS[id]."",0);
	}
}
/////////////////////////////


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



graybutton("notes_C.php",_ADD_CATEGORY);
graybutton("notes_S.php",_ADD_SUB_CATEGORY);
graybutton("notes_I.php",_ADD_NOTE);



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


$cat = query("SELECT * FROM hd_notes_category ORDER by position",0);
while($rowC=mysql_fetch_array($cat)) {
	print("<thead><tr>
	<th>".ucfirst(_CATEGORY)." / ".ucfirst(_SUB_CATEGORY)." / ".ucfirst(_TITLES)."</th> 
	<th>".ucfirst(_DESCRIPTION)."</th> 
	<th>".ucfirst(_EDITOR)."</th>
	<th>".ucfirst(_VIEWS)."</th>
	<th>".ucfirst(_RATING)."</th>
	<th>".ucfirst(_ACCESS)."</th>
	<th>".ucfirst(_OPTIONS)."</th>
	</tr></thead>");


	print("<tr class='row1'>");
	print("<td colspan='6'>".ucfirst($rowC[name])." (".$rowC[numnotes]." ".strtolower(_NOTES).")</td>");
	print("<td align='left'>");
	print("<a href='".$serverurl."/notes_C.php?id=$rowC[id]'><img class='sprites edit' src='images/transparent.gif' border='0' title='"._EDIT."'></a>");
	if ($rowC[numnotes]==0) {
		print("<a href='".$serverurl."/notes_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_notes_subcategory WHERE category=".$rowC[id]." ORDER by position",0);
	while($rowS=mysql_fetch_array($subcat)) {
		print("<tr class='row1'>");
		print("<td colspan='6'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".ucfirst($rowS[name])." (".$rowS[numnotes]." ".strtolower(_NOTES).")</td>");
		print("<td align='left'>");
		print("<a href='".$serverurl."/notes_S.php?id=$rowS[id]'><img class='sprites edit' src='images/transparent.gif' border='0' title='"._EDIT."'></a>");
		if ($rowS[numnotes]==0) {
			print("<a href='".$serverurl."/notes_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_notes WHERE subcategory=".$rowS[id]." ".$onlycl." ORDER by position",0);
		while($rowI=mysql_fetch_array($item)) {
			print("<tr class='row2'>");
			print("<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".strip_tags($rowI[title])."</td>");
			print("<td>".substr(strip_tags($rowI[description]),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]==2) {
				print(ucfirst(_SUPPORT_STAFF));
			}
			if ($rowI[onlyclients]==4) {
				print(ucfirst(_ADMINISTRATOR));
			}

			print("&nbsp;</td>");

			print("<td align='left'>");
			print("<a href='".$serverurl."/notes_I.php?id=$rowI[id]'><img class='sprites edit' src='images/transparent.gif' border='0' title='"._EDIT."'></a>");
			print("<a href='".$serverurl."/notes_del.php?id=$rowI[id]&w=I&text=$rowI[title]'><img class='sprites del' src='images/transparent.gif' border='0' title='"._DELETE."'></a>");
			print("</td>
			</tr>");
		}
	}

	$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 class='row2'>");
		print("<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".strip_tags($rowI[title])."</td>");
		print("<td>".substr(strip_tags($rowI[description]),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]==2) {
			print(ucfirst(_SUPPORT_STAFF));
		}
		if ($rowI[onlyclients]==4) {
			print(ucfirst(_ADMINISTRATOR));
		}


		print("&nbsp;</td>");

		print("<td align='left'>");
		print("<a href='".$serverurl."/notes_I.php?id=$rowI[id]'><img class='sprites edit' src='images/transparent.gif' border='0' title='"._EDIT."'></a>");
		print("<a href='".$serverurl."/notes_del.php?id=$rowI[id]&w=I&text=$rowI[title]'><img class='sprites del' src='images/transparent.gif' border='0' title='"._DELETE."'></a>");
		print("</td>
			</tr>");
	}

}

print("</table>");


graybutton("notes_C.php",_ADD_CATEGORY);
graybutton("notes_S.php",_ADD_SUB_CATEGORY);
graybutton("notes_I.php",_ADD_NOTE);


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

include("foot_template.php");
?>
	
