Location: PHPKode > projects > Modular Site Manager > htdocs/inc/downloads.inc.php
<?php
     $gcat = $_GET['subsec'];
     $gid = $_GET['id'];
     $gdl = $_GET['dl'];
     //	$mysql = new mysql(DB_MAIN);
     if(empty($gcat) && empty($gid) && !isset($gdl))
     {
     $list = $mysql->select(PRE."config", "id='2'", "id");
echo '<ul>';
	while($l = mysql_fetch_array($list))
	{
	$xpl1 = explode("~", $l['setting']);
	$xpl2 = explode("~", $l['setting2']);
	$all = array_combine($xpl1, $xpl2);
	foreach($all as $url => $name)
	{
	echo "<li><a href=\"Downloads/".$url."/\">".$name."</a></li>";
	}
	}
	echo '</ul>';
}
if(!empty($gcat) && empty($gid) && !isset($gdl))
{
$list = $mysql->select(PRE."config", "id='2'", "id");
while($l = mysql_fetch_array($list))
{
$xpl1 = explode("~", $l['setting']);
$xpl2 = explode("~", $l['setting2']);
$all = array_combine($xpl1, $xpl2);
foreach($all as $url => $name)

{
echo "<a href=\"Downloads/".$url."/\">".$name."</a> &brvbar; ";
}
echo "<a href=\"Downloads/\">Main</a><hr />";
}
// Pagination crap..
if(empty($_GET['view']) || !isset($_GET['view']))
{
$view = 1;
} else {
$view = $_GET['view'];
}
$limit = getuserinfo('pglimit');
if ($limit == 0)
{
$limit = 10;
}
$totalrows	= mysql_num_rows($mysql->select(PRE."downloads", "cat='".$_GET['subsec']."'", "id"));
$limitvalue = $view * $limit - ($limit);
// end pagination crap

$dlq = $mysql->select(PRE."downloads", "cat='".$gcat."'", "id", "DESC", $limitvalue.",".$limit);
$dlno = mysql_num_rows($dlq);
if($dlno == "0")
{
echo "There are no downloads in this category yet!";
} else {
while($dlr = mysql_fetch_array($dlq))
{
$name = $dlr['name'];
$submitter = $dlr['author'];
$date = date(DATE, $dlr['date']);
$link = "Downloads/".$dlr['cat']."/".str_replace(array(' ', '+'), "_", urlencode($dlr['name']))."/";
$dllink = "Downloads/".$dlr['cat']."/".str_replace(array(' ', '+'), "_", urlencode($dlr['name']))."/dl/";
$desc = $dlr['descr'];
$downloaded = $dlr['clicks'];

echo "<div style=\"margin-bottom: 10px;\" class=\"row1\"><a href=\"".$link."\">".$name."</a><br />\nSubmitted by: ".$submitter." <br />\n Submitted on: ".$date." <br />\nDownloaded ".$downloaded." time(s)<br />\n <a href=\"".$link."\">More Info</a><br />\n<a href=\"".$dllink."\">Download</a><br />\nDescription: ".nl2br($desc)."</div>";
}
// More pagination crap..
echo '<div style="font-weight:bold;text-align:center;">';
	if($view != 1)
	{
	$pageprev = $view-1;
	echo '<a href="Downloads/'.$_GET['subsec'].'&amp;view='.$pageprev.'">&lt;&lt;</a> ';
	}
	$numofpages = $totalrows / $limit;
	for($i = 1; $i <= $numofpages; $i++)
			  {
			  if($i == $view)
			  {
			  echo $i." ";
			  } else {
			  echo '<a href="Downloads/'.$_GET['subsec'].'&amp;view='.$i.'">'.$i.'</a> ';
			  }
			  }
			  if(($totalrows % $limit) != 0)
			  {
			  if($i == $view)
			  {
			  echo $i.' ';
			  } else {
			  echo '<a href="Downloads/'.$_GET['subsec'].'&amp;view='.$i.'">'.$i.'</a> ';
			  }
			  }
			  if(($totalrows - ($limit * $view)) > 0)
			  {
			  $pagenext = $view+1;
			  echo '<a href="Downloads/'.$_GET['subsec'].'&amp;view='.$pagenext.'">&gt;&gt;</a>';
			  }
			  echo '</div>';
		  // end more pagination crap
		  }
		  }

		  if(!empty($gcat) && !empty($gid) && !isset($gdl))
		  {
		  $list = $mysql->select(PRE."config", "id='2'", "id");
		  while($l = mysql_fetch_array($list))
		  {
		  $xpl1 = explode("~", $l['setting']);
		  $xpl2 = explode("~", $l['setting2']);
		  $all = array_combine($xpl1, $xpl2);
		  foreach($all as $url => $name)
		  {
		  echo "<a href=\"Downloads/".$url."/\">".$name."</a> &brvbar; ";
		  }
		  echo "<a href=\"Downloads/\">Main</a><hr />";
		  }
		  $dlqid = $mysql->select(PRE."downloads", "cat='".$gcat."' AND name='".str_replace('_', ' ', $gid)."'", "id", "DESC");
		  if(!$dlqid)
		  {
		  echo "No such download. <a href=\"javascript:history.go(-1);\">Go Back</a>";
		  }
		  else
		  {
		  while($dlr = mysql_fetch_array($dlqid))
		  {
		  $name = $dlr['name'];
		  $submitter = $dlr['author'];
		  $date = date(DATE, $dlr['date']);
		  $dllink = "Downloads/".$dlr['cat']."/".str_replace(array(' ', '+'), "_", urlencode($dlr['name']))."/dl/";
		  $longdesc = $dlr['longdesc'];
		  $size = cut(filesize("../".$dlr['relativelink'])/1024/1024,6,'');
		  $sizeKb = cut(filesize("../".$dlr['relativelink'])/1024,6,'');
		  $downloaded = $dlr['clicks'];

		  echo "<div><a href=\"".$dllink."\">".$name."</a><br />\nSubmitted by: ".$submitter." <br />\n Submitted on: ".$date." <br />\n File size: ".$size." MB (".$sizeKb." KB)<br />\nDownloaded ".$downloaded." time(s)<br />\n<a href=\"$dllink\">Download</a><br />\nDescription: ".nl2br($longdesc)."</div>";
		  }
		  }
		  }
		  if(isset($gdl))
		  {
		  $dlqg = $mysql->select(PRE."downloads", "cat='".$gcat."' AND name='".str_replace('_', ' ', $gid)."'", "id", "DESC");
		  while($dlget=mysql_fetch_array($dlqg))
		  {
		  $truelink = $dlget['link'];
		  $plusone = $dlget['clicks']+1;
		  if(!isset($_COOKIE['dl-'.$dlget['id']]))
		  {
		  setcookie("dl-".$dlget['id'], "viewed", time()+604800);
		  $mysql->update(PRE."downloads", "clicks='".$plusone."'", "id='".$dlget['id']."'");
		  }
		  header("Location: ".SITE_URL.$truelink);
		  }
		  }
		  //	$mysql->close();
				//	unset($mysql);
?>
Return current item: Modular Site Manager