<?php
/*
 ########################################################################
#                                                                        #
#           Version 4       /                        /   /               #
#          -----------__---/__---__------__----__---/---/-               #
#           | /| /  /___) /   ) (_ `   /   ) /___) /   /                 #
#          _|/_|/__(___ _(___/_(__)___/___/_(___ _/___/___               #
#                       Free Content / Management System                 #
#                                   /                                    #
#                                                                        #
#                                                                        #
#   Copyright 2005-2006 by webspell.org                                  #
#                                                                        #
#   visit webSPELL.org, webspell.info to get webSPELL for free           #
#   - Script runs under the GNU GENERAL PUBLIC LICENSE                   #
#   - It's NOT allowed to remove this copyright-tag                      #
#   -- http://www.fsf.org/licensing/licenses/gpl.html                    #
#                                                                        #
#   Code based on WebSPELL Clanpackage (Michael Gruber - webspell.at),   #
#   Far Development by Development Team - webspell.org                   #
#                                                                        #
#   visit webspell.org                                                   #
#                                                                        #
 ########################################################################
*/

if($_POST['save']) {
  include("_mysql.php");
	include("_settings.php");
	include("_functions.php");
  if(!isanyadmin($userID)) die('no access!');

  $demo = $_FILES[demo];
  $game = $_POST['game'];
  $clanname1 = $_POST['clanname1'];
  $clanname2 = $_POST['clanname2'];
  $clan1 = $_POST['clan1'];
  $clan2 = $_POST['clan2'];
  $hp1 = $_POST['hp1'];
  $hp2 = $_POST['hp2'];
  $country1 = $_POST['country1'];
  $country2 = $_POST['country2'];
  $league = $_POST['league'];
  $leaguehp = $_POST['leaguehp'];
  $maps = $_POST['maps'];
  $player = $_POST['player'];
  $comments = $_POST['comments'];
  $month = $_POST['month'];
  $day = $_POST['day'];
  $year = $_POST['year'];
  $link = $_POST['link'];
  
	$filepath = "./demos/";
	if ($demo[name] != "") {
        $des_file = $filepath.$demo[name];
		if(!file_exists($des_file)) {
		    move_uploaded_file($demo[tmp_name], $des_file);
			@chmod($des_file, 0755);
			$file=$demo[name];
		}	
		else die("file already exists.");
	}
	else {
	    if(eregi("http://", $link)) $file=$link;	
	}	
		
	$date=mktime(0,0,0,$month,$day,$year);
	safe_query("INSERT INTO ".PREFIX."demos ( date, game, clan1, clan2, clantag1, clantag2, url1, url2, country1, country2, league, leaguehp, maps, player, file, downloads, comments )
                values( '$date', '$game', '$clanname1', '$clanname2', '$clan1', '$clan2', '$hp1', '$hp2', '$country1', '$country2', '$league', '$leaguehp', '$maps', '$player', '$file', '0', '$comments' ) ");
	header("Location: index.php?site=demos");
}
elseif($_POST['saveedit']) {
  include("_mysql.php");
	include("_settings.php");
  include("_functions.php");
  if(!isanyadmin($userID)) die('no access!');

  $demo = $_FILES[demo];
  $demoID = $_POST['demoID'];
  $game = $_POST['game'];
  $clanname1 = $_POST['clanname1'];
  $clanname2 = $_POST['clanname2'];
  $clan1 = $_POST['clan1'];
  $clan2 = $_POST['clan2'];
  $hp1 = $_POST['hp1'];
  $hp2 = $_POST['hp2'];
  $country1 = $_POST['country1'];
  $country2 = $_POST['country2'];
  $league = $_POST['league'];
  $leaguehp = $_POST['leaguehp'];
  $maps = $_POST['maps'];
  $player = $_POST['player'];
  $comments = $_POST['comments'];
  $link = $_POST['link'];

	$filepath = "./demos/";
	if ($demo[name] != "") {
        $des_file = $filepath.$demo[name];
		if(!file_exists($des_file)) {
		    move_uploaded_file($demo[tmp_name], $des_file);
			@chmod($des_file, 0755);
			$file=$demo[name];
		}
		else die("file already exists.");
	}
	else {
	    if(eregi("http://", $link)) $file=$link;
	}

	$date=mktime(0,0,0,$_POST['month'],$_POST['day'],$_POST['year']);
	safe_query("UPDATE ".PREFIX."demos SET date='$date',
	                              game='$game',
								  clan1='$clanname1',
								  clan2='$clanname2',
								  clantag1='$clan1',
								  clantag2='$clan2',
								  url1='$hp1',
								  url2='$hp2',
								  country1='$country1',
								  country2='$country2',
								  league='$league',
								  leaguehp='$leaguehp',
								  maps='$maps',
								  player='$player',
								  file='$file',
								  comments='$comments' WHERE demoID='$demoID' ");
	header("Location: index.php?site=demos");
}
elseif($_GET['delete']) {
  include("_mysql.php");
	include("_settings.php");
  include("_functions.php");
  if(!isanyadmin($userID)) die('no access!');

  $demoID = $_GET['demoID'];
  $filepath = "./demos/";
	$ergebnis=safe_query("SELECT * FROM ".PREFIX."demos WHERE demoID='$demoID'");
	$ds=mysql_fetch_array($ergebnis);
	if(file_exists($filepath.$ds[file])) @unlink($filepath.$ds[file]);
	safe_query("DELETE FROM ".PREFIX."demos WHERE demoID='$demoID'");
	safe_query("DELETE FROM ".PREFIX."comments WHERE parentID='$demoID' AND type='de'");
	header("Location: index.php?site=demos");
}

eval ("\$title_demos = \"".gettemplate("title_demos")."\";");
echo $title_demos;

		$gamesa=safe_query("SELECT * FROM ".PREFIX."games ORDER BY name");
 		while($ds=mysql_fetch_array($gamesa)) {
		 $games.='<option value="'.$ds[tag].'">'.$ds[name].'</option>';
		}


function top5() {
	$pagebg=PAGEBG;
	$border=BORDER;
	$bghead=BGHEAD;
	$bgcat=BGCAT;
	
	echo'<table width="100%" border="0" cellspacing="0" cellpadding="0">
	       <tr><td width="49%">';
	// RATING
	$ergebnis=safe_query("SELECT * FROM ".PREFIX."demos ORDER BY rating DESC LIMIT 0,5");
	$top='TOP 5 DEMOS (rating)';
	eval ("\$top5_head = \"".gettemplate("top5_head")."\";");
	echo $top5_head;
	$n=1;
	while($ds=mysql_fetch_array($ergebnis)) {
		if($n%2) {
			$bg1=BG_1;
			$bg2=BG_2;
		}
		else {
			$bg1=BG_3;
			$bg2=BG_4;
		}
		$country1="[flag]".$ds[country1]."[/flag]";
		$country1=flags($country1);
		$country2="[flag]".$ds[country2]."[/flag]";
		$country2=flags($country2);
		$link='<a href="index.php?site=demos&action=showdemo&demoID='.$ds[demoID].'">'.$country1.' '.$ds[clantag1].' vs. '.$ds[clantag2].' '.$country2.'</a>';
		$ratings=array(0,0,0,0,0,0,0,0,0,0);
		for($i=0; $i<$ds[rating]; $i++) {
		    $ratings[$i]=1;
		}
		$ratingpic='<img src="images/icons/rating_'.$ratings[0].'_start.gif" width="1" height="5">';
		foreach($ratings as $pic) {
		    $ratingpic.='<img src="images/icons/rating_'.$pic.'.gif" width="4" height="5">';
		}
		echo'<tr> 
		       <td bgcolor="'.$bg1.'" align="center"><b>'.$n.'.</b></td>
			   <td bgcolor="'.$bg2.'" align="center">'.$ratingpic.'</td>
			   <td bgcolor="'.$bg1.'">'.$link.'</td>
			 </tr>';
		unset($ratingpic);	 
		$n++;
	}
	echo'</table>';
	echo'</td><td width="2%">&nbsp;</td><td width="49%">';
	// POINTS
	$ergebnis=safe_query("SELECT * FROM ".PREFIX."demos ORDER BY downloads DESC LIMIT 0,5");
	$top='TOP 5 DEMOS (downloads)';
	eval ("\$top5_head = \"".gettemplate("top5_head")."\";");
	echo $top5_head;
	$n=1;
	while($ds=mysql_fetch_array($ergebnis)) {
		if($n%2) {
			$bg1=BG_1;
			$bg2=BG_2;
		}
		else {
			$bg1=BG_3;
			$bg2=BG_4;
		}
		
		$country1="[flag]".$ds[country1]."[/flag]";
		$country1=flags($country1);
		$country2="[flag]".$ds[country2]."[/flag]";
		$country2=flags($country2);
		$link='<a href="index.php?site=demos&action=showdemo&demoID='.$ds[demoID].'">'.$country1.' '.$ds[clantag1].' vs. '.$ds[clantag2].' '.$country2.'</a>';
		echo'<tr> 
		       <td bgcolor="'.$bg1.'" align="center"><b>'.$n.'.</b></td>
			   <td bgcolor="'.$bg2.'" align="center">'.$ds[downloads].'</td>
			   <td bgcolor="'.$bg1.'">'.$link.'</td>
			 </tr>';
		$n++;
	}
	echo'</table></td></tr></table><br>';
}
				
if($_GET['action']=="new") {
    if(isfileadmin($userID)) {
		for($i=1; $i<32; $i++) {
		    if($i==date("d", time())) $day.='<option selected>'.$i.'</option>';
			else $day.='<option>'.$i.'</option>';
		}
		for($i=1; $i<13; $i++) {
		    if($i==date("n", time())) $month.='<option value="'.$i.'" selected>'.date("M", time()).'</option>';
			else $month.='<option value="'.$i.'">'.date("M", mktime(0,0,0,$i,1,2000)).'</option>';
		}
		for($i=2000; $i<2010; $i++) {
		    if($i==date("Y", time())) $year.='<option value="'.$i.'" selected>'.date("Y", time()).'</option>';
			else $year.='<option value="'.$i.'">'.$i.'</option>';
		}
		
		$bg1=BG_1;
		eval ("\$demo_new = \"".gettemplate("demo_new")."\";");
	    echo $demo_new;  
	}
	else redirect('index.php?site=demos', 'no access!');
}
elseif($_GET['action']=="edit") {
    $demoID = $_GET['demoID'];
    if(isfileadmin($userID)) {
	    $ds=mysql_fetch_array(safe_query("SELECT * FROM ".PREFIX."demos WHERE demoID='$demoID'"));
	    for($i=1; $i<32; $i++) {
		    if($i==date("d", $ds[date])) $day.='<option selected>'.$i.'</option>';
			else $day.='<option>'.$i.'</option>';
		}
		for($i=1; $i<13; $i++) {
		    if($i==date("n", $ds[date])) $month.='<option value="'.$i.'" selected>'.date("M", $ds[date]).'</option>';
			else $month.='<option value="'.$i.'">'.date("M", mktime(0,0,0,$i,1,2000)).'</option>';
		}
		for($i=2000; $i<2010; $i++) {
		    if($i==date("Y", $ds[date])) $year.='<option selected>'.$i.'</option>';
			else $year.='<option>'.$i.'</option>';
		}
		$games=str_replace(' selected', '', $games);
		$games=str_replace('value="'.$ds[game].'"', 'value="'.$ds[game].'" selected', $games);
		$countries=str_replace(' selected', '', $countries);
		$country1=str_replace('value="'.$ds[country1].'"', 'value="'.$ds[country1].'" selected', $countries);
		$country2=str_replace('value="'.$ds[country2].'"', 'value="'.$ds[country2].'" selected', $countries);
		$clanname1=$ds[clan1];
		$clanname2=$ds[clan2];
		$clan1=$ds[clantag1];
		$clan2=$ds[clantag2];
		$url1=$ds[url1];
		$url2=$ds[url2];
		$maps=$ds[maps];
		$player=$ds[player];
		$league=$ds[league];
		$leaguehp=$ds[leaguehp];
		if(eregi("http://", $ds[file])) $extern=$ds[file];
		else $extern='http://';
						
		$comments='<option value="0">disable comments</option><option value="1">enable user comments</option><option value="2">enable visitor comments</option>';								
		$comments=str_replace('value="'.$ds[comments].'"', 'value="'.$ds[comments].'" selected', $comments);
		
		$bg1=BG_1;
		eval ("\$demo_edit = \"".gettemplate("demo_edit")."\";");
	    echo $demo_edit;      
	}
	else redirect('index.php?site=demos', 'no access!');
}
elseif($_GET['action']=="showdemo") {
  $demoID = $_GET['demoID'];
	if(isfileadmin($userID)) echo'<input type="button" class="button" onClick="MM_goToURL(\'parent\',\'index.php?site=demos&action=new\');return document.MM_returnValue" value="new demo"> '; 
	echo'<input type="button" class="button" onClick="MM_goToURL(\'parent\',\'index.php?site=demos\');return document.MM_returnValue" value="all demos"><br><br>';
	
	$result=safe_query("SELECT * FROM ".PREFIX."demos WHERE demoID='$demoID'");
    $ds=mysql_fetch_array($result);
	$date = date("d.m.Y", $ds[date]);
	$league='<a href="'.$ds[leaguehp].'" target="_blank">'.$ds[league].'</a>';			
	$country1="[flag]".$ds[country1]."[/flag]";
	$country1=flags($country1);
	$clan1=$country1.' <a href="'.$ds[url1].'" target="_blank">'.$ds[clan1].'</a>';			
	$country2="[flag]".$ds[country2]."[/flag]";
	$country2=flags($country2);
	$clan2=$country2.' <a href="'.$ds[url2].'" target="_blank">'.$ds[clan2].'</a>';			
	$game='<img src="images/games/'.$ds[game].'.gif" width="13" height="13" border="0"> '.$ds[game];
		
	$clicks=$ds[downloads];
	$player=$ds[player];
	$maps=$ds[maps];
		
	$ratings=array(0,0,0,0,0,0,0,0,0,0);
	for($i=0; $i<$ds[rating]; $i++) {
	    $ratings[$i]=1;
	}
	$ratingpic='<img src="images/icons/rating_'.$ratings[0].'_start.gif" width="1" height="5">';
	foreach($ratings as $pic) {
	    $ratingpic.='<img src="images/icons/rating_'.$pic.'.gif" width="4" height="5">';
	}
		
	if($loggedin) {
		$download='<a href="download.php?demoID='.$ds[demoID].'"><b>download now</b></a>';
			
		$getdemos=safe_query("SELECT demos FROM ".PREFIX."user WHERE userID='$userID'");
		$found=false;
		if(mysql_num_rows($getdemos)) {
			$ga=mysql_fetch_array($getdemos);
			if($ga[demos]!="") {
    			$string=$ga[demos];
				$array=explode(":", $string);
   				$anzarray=count($array);
    				for($i=0; $i<$anzarray; $i++) {
       				if($array[$i]==$demoID) $found=true;
   				}
			}
		}
		if($found) $rateform="<br><b>You already rated this demos.</b>";	
		else $rateform='(rate with 0-10 points) <select name="rating">
							  <option>0 - poor</option>
							  <option>1</option>
							  <option>2</option>
							  <option>3</option>
							  <option>4</option>
							  <option>5</option>
							  <option>6</option>
							  <option>7</option>
							  <option>8</option>
							  <option>9</option>
							  <option>10 - perfect</option>
							</select>
							<input type="hidden" name="userID" value="'.$userID.'">
							<input type="hidden" name="type" value="de">
							<input type="hidden" name="id" value="'.$ds[demoID].'">
      							<input type="submit" name="Submit" value="rate">';
	}
	else {
	    $rateform="<b>To rate this demo you have to be registered and logged in!</b>";
		$download="<b>To download this demo you have to be registered and logged in!</b>";
	}	
		
	if(isfileadmin($userID)) 
	    $adminaction='<input type="button" class="button" onClick="MM_goToURL(\'parent\',\'index.php?site=demos&action=edit&demoID='.$ds[demoID].'\');return document.MM_returnValue" value="edit">
					  <input type="button" class="button" onClick="MM_confirm(\'really delete this demo?\', \'demos.php?delete=true&demoID='.$ds[demoID].'\')" value="delete">';	

   	$bg1=BG_1;
	$bg2=BG_2;
	$bg3=BG_3;
	$bg4=BG_4;
		
	eval ("\$demos_showdemo = \"".gettemplate("demos_showdemo")."\";");
    echo $demos_showdemo;
		
	$comments_allowed = $ds[comments];
	$parentID = $demoID;
	$type = "de";
	$referer = "index.php?site=demos&action=showdemo&demoID=$demoID";
			
	include("comments.php");
}
elseif($_GET['action']=="showgame") {
  $game = $_GET['game'];
	if(isfileadmin($userID)) echo'<input type="button" class="button" onClick="MM_goToURL(\'parent\',\'index.php?site=demos&action=new\');return document.MM_returnValue" value="new demo"><br><br>'; 
	
	$alle=safe_query("SELECT demoID FROM ".PREFIX."demos WHERE game='$game'");
	$gesamt = mysql_num_rows($alle);
	$pages=1;
	if(!isset($page)) $page = 1;
	if(!isset($sort)) $sort = "date";
	if(!isset($type)) $type = "DESC";
	
	$max=$maxdemos;
		
    for ($n=$max; $n<=$gesamt; $n+=$max) {
	    if($gesamt>$n) $pages++;
	}
		 	
	if($pages>1) $page_link = makepagelink("index.php?site=demos&action=showsgame&game=$game&sort=$sort&type=$type", $page, $pages);
		
	if ($page == "1") {
        $ergebnis = safe_query("SELECT * FROM ".PREFIX."demos WHERE game='$game' ORDER BY $sort $type LIMIT 0,$max");
	    if($type=="DESC") $n=$gesamt;
		else $n=1;
	}
	else {
	    $start=$page*$max-$max;
	    $ergebnis = safe_query("SELECT * FROM ".PREFIX."demos WHERE game='$game' ORDER BY $sort $type LIMIT $start,$max");
	    if($type=="DESC") $n = ($gesamt)-$page*$max+$max;
		else $n = ($gesamt+1)-$page*$max+$max;
	}
	if($gesamt) {
	    top5();
	    if($type=="ASC") 
		    echo'<a href="index.php?site=demos&action=showgame&game='.$game.'&page='.$page.'&sort='.$sort.'&type=DESC">Sort:</a> <img src="images/icons/asc.gif" width="9" height="7" border="0">&nbsp;&nbsp;&nbsp;';
		else 
		    echo'<a href="index.php?site=demos&action=showgame&game='.$game.'&page='.$page.'&sort='.$sort.'&type=ASC">Sort:</a> <img src="images/icons/desc.gif" width="9" height="7" border="0">&nbsp;&nbsp;&nbsp;';
		
		echo $page_link;
		echo'<br><br>';
		
		$headdate='<a class="titlelink" href="index.php?site=demos&action=showgame&game='.$game.'&page='.$page.'&sort=date&type='.$type.'">Date:</a>';
		$headgame='G:';
		$headleague='<a class="titlelink" href="index.php?site=demos&action=showgame&game='.$game.'&page='.$page.'&sort=league&type='.$type.'">League:</a>';
		$headrating='<a class="titlelink" href="index.php?site=demos&action=showgame&game='.$game.'&page='.$page.'&sort=rating&type='.$type.'">Rating:</a>';
		$headclicks='<a class="titlelink" href="index.php?site=demos&action=showgame&game='.$game.'&page='.$page.'&sort=downloads&type='.$type.'">DL:</a>';
		
		eval ("\$demos_head = \"".gettemplate("demos_head")."\";");
	    echo $demos_head;
		$n=1;
		while($ds=mysql_fetch_array($ergebnis)) {
			if($n%2) {
				$bg1=BG_1;
				$bg2=BG_2;
			}
			else {
				$bg1=BG_3;
				$bg2=BG_4;
			}
			$date=date("d.m.Y", $ds[date]);
			$league='<a href="'.$ds[leaguehp].'" target="_blank">'.$ds[league].'</a>';			
			$country1="[flag]".$ds[country1]."[/flag]";
			$country1=flags($country1);
			$clan1=$country1.' <a href="'.$ds[url1].'" target="_blank">'.$ds[clantag1].'</a>';			
			$country2="[flag]".$ds[country2]."[/flag]";
			$country2=flags($country2);
			$clan2='<a href="'.$ds[url2].'" target="_blank">'.$ds[clantag2].'</a> '.$country2;			
			$game='<img src="images/games/'.$ds[game].'.gif" width="13" height="13" border="0">';
			$clicks=$ds[downloads];
			
			$ratings=array(0,0,0,0,0,0,0,0,0,0);
		for($i=0; $i<$ds[rating]; $i++) {
		    $ratings[$i]=1;
		}
		$ratingpic='<img src="images/icons/rating_'.$ratings[0].'_start.gif" width="1" height="5">';
		foreach($ratings as $pic) {
		    $ratingpic.='<img src="images/icons/rating_'.$pic.'.gif" width="4" height="5">';
		}
						
			eval ("\$demos_content = \"".gettemplate("demos_content")."\";");
	        echo $demos_content;
			unset($ratingpic);
			$n++;
		}
		eval ("\$demos_foot = \"".gettemplate("demos_foot")."\";");
	    echo $demos_foot;
	}
	else echo'no entries';
}
else {
  $sort = $_GET['sort'];
  $type = $_GET['type'];
  $page = $_GET['page'];

	if(isfileadmin($userID)) echo'<input type="button" class="button" onClick="MM_goToURL(\'parent\',\'index.php?site=demos&action=new\');return document.MM_returnValue" value="new demo"><br><br>'; 
	$alle=safe_query("SELECT demoID FROM ".PREFIX."demos");
	$gesamt = mysql_num_rows($alle);
	$pages=1;
	if(!isset($page)) $page = 1;
	if(!isset($sort)) $sort = "date";
	if(!isset($type)) $type = "DESC";
	
	$max=$maxdemos;
		
    for ($n=$max; $n<=$gesamt; $n+=$max) {
	    if($gesamt>$n) $pages++;
	}
		 	
	if($pages>1) $page_link = makepagelink("index.php?site=demos&sort=$sort&type=$type", $page, $pages);
		
	if ($page == "1") {
        $ergebnis = safe_query("SELECT * FROM ".PREFIX."demos ORDER BY $sort $type LIMIT 0,$max");
	    if($type=="DESC") $n=$gesamt;
		else $n=1;
	}
	else {
	    $start=$page*$max-$max;
	    $ergebnis = safe_query("SELECT * FROM ".PREFIX."demos ORDER BY $sort $type LIMIT $start,$max");
	    if($type=="DESC") $n = ($gesamt)-$page*$max+$max;
		else $n = ($gesamt+1)-$page*$max+$max;
	}
	if($gesamt) {
	    top5();
	    if($type=="ASC") 
		    echo'<a href="index.php?site=demos&page='.$page.'&sort='.$sort.'&type=DESC">Sort:</a> <img src="images/icons/asc.gif" width="9" height="7" border="0">&nbsp;&nbsp;&nbsp;';
		else 
		    echo'<a href="index.php?site=demos&page='.$page.'&sort='.$sort.'&type=ASC">Sort:</a> <img src="images/icons/desc.gif" width="9" height="7" border="0">&nbsp;&nbsp;&nbsp;';
		
		echo $page_link;
		echo'<br><br>';

		$headdate='<a class="titlelink" href="index.php?site=demos&page='.$page.'&sort=date&type='.$type.'">Date:</a>';
		$headgame='<a class="titlelink" href="index.php?site=demos&page='.$page.'&sort=game&type='.$type.'">G:</a>';
		$headleague='<a class="titlelink" href="index.php?site=demos&page='.$page.'&sort=league&type='.$type.'">League:</a>';
		$headrating='<a class="titlelink" href="index.php?site=demos&page='.$page.'&sort=rating&type='.$type.'">Rating:</a>';
		$headclicks='<a class="titlelink" href="index.php?site=demos&page='.$page.'&sort=downloads&type='.$type.'">DL:</a>';		
		
		eval ("\$demos_head = \"".gettemplate("demos_head")."\";");
	    echo $demos_head;
		$n=1;
		while($ds=mysql_fetch_array($ergebnis)) {
			if($n%2) {
				$bg1=BG_1;
				$bg2=BG_2;
			}
			else {
				$bg1=BG_3;
				$bg2=BG_4;
			}
			$date=date("d.m.Y", $ds[date]);
			$league='<a href="'.$ds[leaguehp].'" target="_blank">'.$ds[league].'</a>';			
			$country1="[flag]".$ds[country1]."[/flag]";
			$country1=flags($country1);
			$clan1='<a href="'.$ds[url1].'" target="_blank">'.$ds[clantag1].'</a> '.$country1;			
			$country2="[flag]".$ds[country2]."[/flag]";
			$country2=flags($country2);
			$clan2=$country2.' <a href="'.$ds[url2].'" target="_blank">'.$ds[clantag2].'</a> ';			
			$game='<a href="index.php?site=demos&action=showgame&game='.$ds[game].'"><img src="images/games/'.$ds[game].'.gif" width="13" height="13" border="0"></a>';
			$clicks=$ds[downloads];
			
			$ratings=array(0,0,0,0,0,0,0,0,0,0);
			for($i=0; $i<$ds[rating]; $i++) {
			    $ratings[$i]=1;
			}
			$ratingpic='<img src="images/icons/rating_'.$ratings[0].'_start.gif" width="1" height="5">';
			foreach($ratings as $pic) {
			    $ratingpic.='<img src="images/icons/rating_'.$pic.'.gif" width="4" height="5">';
			}
			
			eval ("\$demos_content = \"".gettemplate("demos_content")."\";");
	        echo $demos_content;
			unset($ratingpic);
			$n++;
		}
		eval ("\$demos_foot = \"".gettemplate("demos_foot")."\";");
	    echo $demos_foot;
	}
	else echo'no demos available';
}


?>
