<?php
/*---------------------------------------------------+
| PHP-Fusion 6 Content Management System
+----------------------------------------------------+
| Copyright ê 2002 - 2006 Nick Jones
| http://www.php-fusion.co.uk/
+----------------------------------------------------+
| NextGen Downloads v1.3 (C) 2007
| by Ñòàíèñëàâ Ôåäîòîâ aka SAF 
| http://compgdev.com
+----------------------------------------------------+
| Released under the terms & conditions of v2 of the
| GNU General Public License. For details refer to
| the included gpl.txt file or visit http://gnu.org
+----------------------------------------------------*/
require_once "maincore.php";
require_once "subheader.php";
require_once "side_left.php";
include LOCALE.LOCALESET."themes.php";

if (isset($themes_id) && !isNum($themes_id)) fallback("index.php");

if (isset($themes_id)) {
	$res = 0;
	if ($data = dbarray(dbquery("SELECT themes_url,themes_cat FROM ".$db_prefix."themes WHERE themes_id='$themes_id'"))) {
		$cdata = dbarray(dbquery("SELECT * FROM ".$db_prefix."themes_cats WHERE themes_cat_id='".$data['themes_cat']."'"));
		if (checkgroup($cdata['themes_cat_access'])) {
			$res = 1;
			$result = dbquery("UPDATE ".$db_prefix."themes SET themes_count=themes_count+1 WHERE themes_id='$themes_id'");
			redirect($data['themes_url']);
		}
	}
	if ($res == 0) redirect(BASEDIR."themes.php");
}

if (!isset($cat_id)) {
	opentable($locale['400']);
	echo "<br>";
	$result = dbquery("SELECT * FROM ".$db_prefix."themes_cats WHERE ".groupaccess('themes_cat_access')." ORDER BY themes_cat_name");
	$rows = dbrows($result);
	if ($rows != 0) {
		$counter = 0; $columns = 1;
		while ($data = dbarray($result)) {
			if ($counter != 0 && ($counter % $columns == 0)) echo "<br>";
			$num = dbcount("(themes_cat)", "themes", "themes_cat='".$data['themes_cat_id']."'");
echo "<table border='0' width='95%' align='center' cellspacing='1' cellpadding='0' class='tbl-border'>
<tr>
<td class='forum-caption' colspan='2'>".$data['themes_cat_name']."</td>
</tr>";

if ($data['themes_cat_description']) {
echo "<tr>
<td class='tbl1' colspan='2' calign='top' style='padding:5px;'>";
echo "<small>".nl2br(stripinput($data['themes_cat_description']))."</small>";
echo "</td>
</tr>";
}

echo "
<td class='tbl2' align='center' width='50%'><small>".$locale['D001'].$num."</small></td>
<td class='tbl2' align='center' width='50%'><a href='".FUSION_SELF."?cat_id=".$data['themes_cat_id']."&sort=1'><small>".$locale['D002']."</small></a></td>
</tr>
</table>";
			$counter++;
		}
	echo "<br>";
	} else {
		echo "<center><br>\n".$locale['430']."<br><br>\n</center>\n";
	}
	closetable();
} else {
	include INCLUDES."comments_include.php";
	include INCLUDES."ratings_include.php";
$result = dbquery("SELECT * FROM ".$db_prefix."themes WHERE themes_id='$info_id'");
	if ($info_id) {
				while ($data = dbarray($result)) {
	opentable($locale['400']." » ".$data['themes_title']);
	echo "<br><br><table border='0' width='95%' align='center' cellspacing='1' cellpadding='0' class='tbl-border'><tr>
	<td colspan='3' class='forum-caption'>".$locale['D003']."</td>
	</tr><tr>
	<td class='tbl1' width='200' align='center' valign='middle' rowspan='8'>";
	if ($data['themes_screen']) {
	echo "<img src='".$data['themes_screen']."' alt='' width='172px' height='220px'>";
	echo "<br><br><small>[ <a href='".$data['themes_screen']."' target='_blank'>Padidinti foto</a> ]</small></td>";
	} else {
	echo "<img src='images/nonscreen.gif' alt='' width='160px' height='120px'>";
	echo "<br><br><small>[ ".$locale['D004']." ]</small></td>";
	}
	echo "<td class='tbl2' width='1%' nowrap><b>".$locale['D005']."</b></td>
	<td class='tbl1'>".$data['themes_title']."</td>
	</tr>
	<tr>
	<td class='tbl2'width='1%' nowrap><b>".$locale['D006']."</b></td>
	<td class='tbl1'>".$data['themes_author']."</td>
	</tr>
	<tr>
	<td class='tbl2'width='1%' nowrap><b>".$locale['D007']."</b></td>
	<td class='tbl1'>".$data['themes_filesize']."</td>
	</tr>
	<tr>
	<td class='tbl2'width='1%' nowrap><b>Failas patalpintas:</b></td>
	<td class='tbl1'>".showdate("%B %d %Y %H:%M:%S", $data['themes_datestamp'])."</td>
	</tr>
	<tr>
	<td class='tbl2'width='1%' nowrap><b>".$locale['D010']."</b></td>
	<td class='tbl1'>".$data['themes_count']."</td>
	</tr><tr>
	<td class='tbl2'width='1%' nowrap><b>Telefono modelis:</b></td>
	<td class='tbl1'>".$data['themes_os']."</td>
	</tr><tr>
	<td class='tbl2' align='center' height='30px' colspan='2'><small>";
	if ($data['themes_copyright']) {
	echo $data['themes_copyright'];
	} else {
	echo " ";
	}
	echo "</small></td>";
	echo "</tr></table>";
	echo "<br>";
	if ($data['themes_description']) {
	echo "<table border='0' width='95%' align='center' cellspacing='1' cellpadding='0' class='tbl-border'>
	<tr>
	<td class='forum-caption'>".$locale['D012']."</td>
	</tr>
	<tr>
	<td class='tbl1'>".nl2br(stripslashes($data['themes_description']))."</td>
	</tr>
	</table>";
	echo "<br>";
	}
	echo "<table border='0' width='95%' align='center' cellspacing='1' cellpadding='0' class='tbl-border'><tr>";
			if ($data['themes_mirror']) {
	echo "<td class='forum-caption' colspan='4'>".$locale['D013']."</td>";	
			} else {
	echo "<td class='forum-caption' colspan='3'>".$locale['D013']."</td>"; }
	echo "</tr><tr>
	<td class='tbl1' width='18%' align='center'><a href='".FUSION_SELF."?cat_id=$cat_id&themes_id=".$data['themes_id']."' target='_blank'><img src='".IMAGES."siustis.gif'> Atsisiøsti</a></td>";
		
	echo "<td class='tbl1' width='30%' align='center'><a href='".FUSION_SELF."?cat_id=$cat_id&info_id=".$data['themes_id']."&act=rate'><img src='".IMAGES."vertinti.gif'> Ávertinti</a></td>
	<td class='tbl1' width='30%' align='center'><a href='".FUSION_SELF."?cat_id=$cat_id&info_id=".$data['themes_id']."&act=comment'><img src='".IMAGES."komentaras.gif'> Komentuoti</a></td>
	</tr></table><br><br>";
closetable();
if ($act == "rate") {
showratings("T",$info_id,FUSION_SELF."?cat_id=$cat_id&info_id=$info_id&act=rate");
} 
if ($act == "comment") {
showcomments("T","themes","themes_id",$info_id,FUSION_SELF."?cat_id=$cat_id&info_id=$info_id&act=comment");
}
}
} else {
	$res = 0;
	if (!isNum($cat_id)) fallback(FUSION_SELF);
	$result = dbquery("SELECT * FROM ".$db_prefix."themes_cats WHERE themes_cat_id='$cat_id'");
	if (dbrows($result) != 0) {
		$cdata = dbarray($result);
		if (checkgroup($cdata['themes_cat_access'])) {
			$res = 1;
			opentable($locale['400']." - ".$cdata['themes_cat_name']);
				echo "<br>";
			echo "<table width='70%' align='center' cellspacing='1' cellpadding='1' class='tbl-border'>";
			echo "<tr>";
			echo "<td align='center' width='33%' class='".(FUSION_QUERY == "cat_id=$cat_id" || $sort == 1 ? "tbl1" : "tbl2")."'><span class='small'>\n";
			echo (FUSION_QUERY == "cat_id=$cat_id" || $sort == 1 ? "<b>".$locale['D014']."</b>" : "<a href='".FUSION_SELF."?cat_id=$cat_id&sort=1'>".$locale['D014']."</a>")."</span></td>\n";

			echo "<td align='center' width='33%' class='".($sort == 3 ? "tbl1" : "tbl2")."'><span class='small'>\n";
			echo ($sort == 3 ? "<b>".$locale['D015']."</b>" : "<a href='".FUSION_SELF."?cat_id=$cat_id&sort=3'>".$locale['D015']."</a>")."</span></td>\n";

			echo "<td align='center' width='33%' class='".($sort == 2 ? "tbl1" : "tbl2")."'><span class='small'>\n";
			echo ($sort == 2 ? "<b>".$locale['D016']."</b>" : "<a href='".FUSION_SELF."?cat_id=$cat_id&sort=2'>".$locale['D016']."</a>")."</span></td>\n";
			echo "</tr></table><br>";

			$rows = dbcount("(*)", "themes", "themes_cat='$cat_id'");
			if (!isset($rowstart) || !isNum($rowstart)) $rowstart = 0;
			if (!isset($sort) || !isNum($sort)) $sort = 0; 
			$sorting = $cdata['themes_cat_sorting'];
			if ($sort == 1)	$sorting = "themes_title ASC";
			if ($sort == 2)	$sorting = "themes_count DESC";
			if ($sort == 3)	$sorting = "themes_datestamp DESC, download_title ASC";
			if ($rows != 0) {
				$result = dbquery("SELECT * FROM ".$db_prefix."themes WHERE themes_cat='$cat_id' ORDER BY $sorting LIMIT $rowstart,20");

				$numrows = dbrows($result); $i = 1;
				
				while ($data = dbarray($result)) {
					if ($data['themes_datestamp']+604800 > time()+($settings['timeoffset']*3600)) {
						$new = " <span style='font-size:8px;'><blink>".$locale['410']."</blink></span>";
					} else {
						$new = "";
					}

echo "<br><br><table border='0' width='45%' align='center' cellspacing='1' cellpadding='0' class='tbl-border'><tr>
	<td colspan='3' class='forum-caption'>".$data['themes_title']." $new</td>
	</tr><tr>
	<td class='tbl1' width='150' align='center' valign='middle' rowspan='8'>";
if ($data['themes_screen']) {
	echo "<img src='".$data['themes_screen']."' alt='' width='176px' height='220px'>";
	} else {
	echo "<img src='images/nonscreen.gif' alt='' width='126px' height='170px'>";
	echo "</td>";
	}
	echo "	<tr><td class='tbl2' colspan='1' align='center' >Autorius: <small>".$data['themes_author']."</small></td></tr>

<tr><td class='tbl2' colspan='1' align='center' >Failas atsisiøstas: <small>".$data['themes_count']."</small></td></tr>
	";
$wynik = dbquery("SELECT SUM(rating_vote) FROM ".$db_prefix."ratings WHERE rating_type='T' AND rating_item_id='".$data['themes_id']."'");
$info = dbresult($wynik,0);
$num_rating = dbcount("(rating_vote)", "ratings", "rating_type='T' AND rating_item_id='".$data['themes_id']."'");
$wyn_rating = ($num_rating ? $info / $num_rating : 0);
echo "<tr><td class='tbl2' align='center' ><small>Ávertinimas<br><img src='".IMAGES."rate/".ceil($wyn_rating).".gif' alt='' style='vertical-align:middle;' title='".$locale['D019'].ceil($wyn_rating)."'></small></td></tr>
	
	<tr><td class='tbl2' colspan='1' align='center' >Telefono modelis: <small>".$data['themes_os']."</small></td></tr>
<tr><td class='tbl2' colspan='1' align='center'><a href='".FUSION_SELF."?cat_id=$cat_id&info_id=".$data['themes_id']."'><small>?iûrëti daugiau</small></a></td></tr>



</table>";

				echo ($i != $numrows ? "<br>" : "\n"); $i++;
				}
echo "<br>";
				closetable();
				if ($rows > 20) echo "<div align='center' style='margin-top:5px;'>\n".makePageNav($rowstart,20,$rows,3,FUSION_SELF."?cat_id=$cat_id&sort=$sort&")."\n</div>\n";
			} else {
				echo $locale['431']."\n";
				closetable();
			}
		}
	}

	if ($res == 0) redirect(FUSION_SELF);
}
}

require_once "side_right.php";
require_once "footer.php";
?>