Location: PHPKode > projects > FavLinks Favorites Manager > favlinks/browse.php
<?php
	require("incs/include.php");
	//echo "<PRE>"; print_r($_GET); echo "</PRE>";
?>

<?php

	if (isset($_GET['do']) && isset($_GET['category']) && $_GET['do'] == 'browse') {
		$srch_cat    = str_replace('%', '', slashdot(htmlspecialchars($_GET['category'])));
		$srch_detail = isset($_GET['detail']) ? $_GET['detail'] : 'high';
		$srch_sort   = isset($_GET['sortby']) ? $_GET['sortby'] : 'title';
		$srch_page   = isset($_GET['page']) ? abs((int) $_GET['page']) : 1;
		$srch_rows   = isset($_GET['rows']) ? $_GET['rows'] : MIN_ROWS_PER_PAGE;

		switch($srch_rows) {
			case 10 :
			case 15 :
			case 20 :
			case 25 :
			case 50 :
			case 100: break;
			default : $srch_rows = MIN_ROWS_PER_PAGE;
		}
		switch($srch_detail) {
			case 'high' :
			case 'low'  : break;
			default     : $srch_detail = 'high';
		}
		switch($srch_sort) {
			case 'title' :
			case 'id'    :
			case 'rating':
			case 'date'  : break;
			default      : $srch_sort = 'title';
		}

		$s_query  = "SELECT SQL_CALC_FOUND_ROWS  * FROM `favlinks` WHERE `category` = '$srch_cat'";
		$s_query .= ' ORDER BY `'.$srch_sort.'` '.($srch_sort == 'rating' ? 'DESC' : 'ASC');

	/* * * * * * * * * * * * * * * * * * * * * * */
	// To check if cur_page is not exceeded its limit;
		$s_result = mysql_query($s_query);
		$n_query  = "SELECT FOUND_ROWS() AS `rows`";
		$n_result = mysql_query($n_query);
		$n_values = mysql_fetch_array($n_result);
		$max_rows = $n_values['rows'];
		$r  = (int) ($max_rows / $srch_rows);
		$r += ($max_rows % $srch_rows == 0) ? 0 : 1;

		$srch_page = ($srch_page > $r) ? $r : $srch_page;
	/* * * * * * * * * * * * * * * * * * * * * * */


		$s_query .= ' LIMIT '.$srch_rows * ($srch_page-1).', '.$srch_rows;
		$s_result = mysql_query($s_query);
		//echo "<pre>$s_query</pre>";
		$strng = (mysql_num_rows($s_result) != 0) ? "(Showing <b>".($srch_rows * ($srch_page-1) + 1)."</b> - <b>".($srch_rows * ($srch_page-1) + mysql_num_rows($s_result))."</b> links of about <b>".$max_rows."</b>)" : "&nbsp;";

		echo add_head("Browse Favlinks &#8250; ".slashtod($srch_cat), "Browse Favlinks<br><br><span class=bold>Category: ".slashtod($srch_cat)."</span>");
		echo "<br>";
		resultsbox($srch_detail, $srch_sort, $srch_rows, $max_rows, $srch_page);
		echo "<br><br><br>";
		list_results($s_result, "Category: ".slashtod($srch_cat), $strng, $srch_detail, true);
		echo "<br><br><br>";
		resultsbox($srch_detail, $srch_sort, $srch_rows, $max_rows, $srch_page);

	} else 	{

		$c_query  = "SELECT count(*) as `count` FROM `favlinks`";
		$c_result = mysql_query($c_query);
		$c_values = mysql_fetch_array($c_result, MYSQL_ASSOC);
		$total_links = $c_values['count'];
		$c_query  = "SELECT `category` , count(*) as `count` FROM `favlinks` GROUP BY `category` ORDER BY `category` ASC";
		$c_result = mysql_query($c_query);
		$rows     = mysql_num_rows($c_result);
		$total_cats = $rows;

		echo add_head('Broswe Favlinks', 'Broswe FavLinks<br><br><font color=black class=medium>(Total <b>'.$total_links.'</b> links in <b>'.$total_cats.'</b> categories)</font>');


		$cat = "";
		$getcats[0] = -1;
		if (isset($_GET['do']) && isset($_GET['cat']) && $_GET['do'] == 'expand') {
			$cat = $_GET['cat'];
			$getcats = explode('|', $cat);
		}
		for ($i=1;$i<=$rows;$i++) {
			if ($i == 1) {
				$exp = '1';
			} else {
				$exp .= '|'.$i;
			}
		}
		$i = 1;
		$sc_date = "var L_date = new Array();\n";
		$sc_desc = "var L_desc = new Array();\n";
		$sc_url  = "var L_url  = new Array();\n";
		$sc_rate = "var L_rate = new Array();\n";

		echo "\n<table align=center class=table cellpadding=0 cellspacing=1 width=90%><tr><td class=light style='padding:5pt'>";
		echo "\n<div class='tooltip small' id=tip></div>";
		echo "\n<div class=small>";
		echo "\n<span class=bold>Categories</span> &nbsp; [<a href='browse.php?do=expand&cat=$exp'>Expand all</a> | <a href='browse.php?do=expand&cat=0'>Collapse all</a>]<br>";
		echo "\n<img src='imgs/list.line_s.gif' border=0 align=absmiddle><br>";

		while ($c_values = mysql_fetch_array($c_result)) {
			if (in_array($i,$getcats)) {
				echo "\n<a href=\"browse.php?do=expand&cat=".str_replace( array("$i|","|$i","$i"), array('','',''), $cat)."\"><img src='imgs/list.minus".($rows == $i ? '_l':'' ).".gif' border=0 align=absmiddle></a>";
			} else {
				echo "\n<a href=\"browse.php?do=expand&cat=".$cat.($cat!=''?'|':'').$i."\"><img src='imgs/list.plus".($rows == $i ? '_l':'' ).".gif' border=0 align=absmiddle></a>";
			}
			echo "<img src='imgs/list.fldr.gif' border=0 align=absmiddle> ";
			echo "<b class=color>".snip($c_values['category'],60)."</b> (".$c_values['count'].") <a href=\"browse.php?do=browse&category=".$c_values['category']."&detail=high\"><img src='imgs/ext.gif' alt='Browse Category' title='Browse Category' border=0></a><br>";

			if (in_array($i,$getcats)) {
				$s_query  = "SELECT * FROM `favlinks` WHERE `category` = '".mysql_escape_string($c_values['category'])."' ORDER BY `title` ASC;";
				$s_result = mysql_query($s_query);
				$subrows  = mysql_num_rows($s_result);
				$subi 	  = 1;
				while ($s_values = mysql_fetch_array($s_result)) {
					$id = $s_values['id'];
					echo "\n<img src='imgs/list.".($rows != $i ? "line_s" : "blank").".gif' border=0 align=absmiddle>";
					if ($subrows != $subi++) {
						echo "<img src='imgs/list.line.gif' border=0 align=absmiddle>";
						echo " <a href=\"".$s_values['url']."\" target='_blank' onmouseover='s($id,this);return true;' onmouseout='h();return true;'>".snip($s_values['title'],50)."</a><br>";
					} else {
						echo "<img src='imgs/list.line_l.gif' border=0 align=absmiddle>";
						echo " <a href=\"".$s_values['url']."\" target='_blank' onmouseover='s($id,this);return true;' onmouseout='h();return true;'>".snip($s_values['title'],100) ."</a><br>";
						echo ($rows != $i ? "\n<img src='imgs/list.line_s.gif' border=0 align=absmiddle><br>" : '');
					}
					$sc_date .= "L_date[$id]=\"".date("d-M-Y", strtotime($s_values['date']))."\";\n";
					$sc_desc .= "L_desc[$id]=\"".str_replace("\r\n","",nl2br($s_values['desc']))."\";\n";
					$sc_url  .= "L_url[$id]=\"".$s_values['url']."\";\n";
					$sc_rate .= "L_rate[$id]=".$s_values['rating'].";\n";
				}
			}
			$i++;
		}
		echo "&nbsp;</div></td></tr></table>";
		echo "\n\n<script language=JavaScript>\n";
		echo $sc_url;
		echo $sc_date;
		echo $sc_desc;
		echo $sc_rate;
		echo "</script>\n\n";
		echo tipscript();
	}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function tipscript() {
$tip = <<< EOS
<script language=JavaScript>
var sto = 0;
function s(id,link) {
	//tip = document.getElementById('tip');
	LEFT = link.offsetLeft;
	TOP  = link.offsetTop;
	objt = link;
	while(objt.offsetParent != null) {
		objt = objt.offsetParent;
		LEFT += objt.offsetLeft;
		TOP  += objt.offsetTop;
	}
	document.getElementById('tip').style.left = LEFT;
	document.getElementById('tip').style.top  = TOP + 13;

	HTML = '';
	HTML += L_desc[id] + '<br>';
	HTML += '<font color=green>' + L_url[id] + '</font><br><br>';
	HTML += '<font color=gray>ID: ' + id + '&nbsp; Rating:</font>';
	var r = 1;
	for (i=0; i<L_rate[id]; i++) {
		HTML += "<img src='imgs/star.on.s.gif' width=10 height=10 hspace=2 align='absmiddle' border=0>";
		r++;
	}
	for (i=0; i<(5 - L_rate[id]); i++) {
		HTML += "<img src='imgs/star.off.s.gif' width=10 height=10 hspace=2 align='absmiddle' border=0>";
		r++;
	}
	HTML += '<font color=gray>&nbsp; Added on: ' + L_date[id] + '</font></div>';
	document.getElementById('tip').innerHTML = HTML;

	clearTimeout(sto);
	sto = setTimeout("document.getElementById('tip').style.visibility = 'visible';",100);
}

function h(id,link) {
	clearTimeout(sto);
	sto = setTimeout("document.getElementById('tip').style.visibility = 'hidden';",100);
}
</script>
EOS;
return($tip);
}

?>

<?php echo add_foot(); ?>
Return current item: FavLinks Favorites Manager