<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.4 www.bcoos.net 2006-08 GPL
//v1.3 www.exoops.info 2006/03 GPL
// $Id: viewcat.php,v 1.2 2004/03/20 18:35:12 greyhead Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: James Knickelbein
// Author Website : http://www.journeymilwaukee.com
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
// Passed on      : My Downloads
// New module name: My Sections
// Version        : 1.1
// Modified by    : Faisal
// Website        : < http://www.a-xoops.com >
// Email          : info@a-xoops.com
// ------------------------------------------------------------------------- //
include_once("header.php");
$mytree = new XoopsTree($db->prefix("mysections_cat"), "cid", "pid");
$cid    = intval($_GET['cid']);
$bcoosConfig['title'] .= " - ".$mytree->getCategoryName($cid);
include_once(XOOPS_ROOT_PATH."/header.php");
OpenTable();
mainheader();
$query = $db->query("SELECT description FROM ".$db->prefix("mysections_cat")." WHERE cid='$cid'");
list($desc) = $db->fetchRow($query);
if ($desc) {
        $myts->setType('admin');
        $desc = $myts->makeTareaData4Show($desc, 1, 1, 1);
        echo $desc."<br /><br />";
}
if ( $_GET['show'] != "" ) {
        $show = intval($_GET['show']);
        } else {
                $show = $mysectionsConfig['perpage'];
        }
if ( !isset($_GET['min']) ) {
        $min = 0;
        } else {
                $min = intval($_GET['min']);
        }
if ( !isset($max) ) {
        $max = $min + $show;
        }
if ( isset($_GET['orderby']) ) {
        $orderby = convertorderbyin($_GET['orderby']);
        } else {
                $orderby = "BINARY title ASC";
        }
echo "
<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td align='center'>
<table width='100%' cellspacing='1' cellpadding='2' border='0' class='bg3'><tr><td>";
$str_path  = "<a href='index.php'>"._MODIFYCATEGORY."</a>&nbsp;:&nbsp;";
$str_path .= $mytree->getNicePathFromId($cid, "title", "viewcat.php?");
echo "<b>".$str_path."</b></td></tr></table>";
// get child category objects
$arr = array();
$arr = $mytree->getFirstChild($cid, "title");
if ( count($arr) > 0 ) {
        echo "
        </td></tr>
        <tr><td><h4>"._CATEGORIES."</h4></td></tr>
        <tr><td align='center'>";
        $scount = 0;
        echo "<table width='90%'><tr>";
        foreach($arr as $ele) {
                $title = $myts->makeTboxData4Show($ele['title']);
                $totaldownload = getTotalItems($ele['cid'], 1);
                echo "<td><b><a href=viewcat.php?cid=".$ele['cid'].">$title</a></b>&nbsp;($totaldownload)</td>";
                $scount++;
                if ( $scount == 4 ) {
                        echo "</tr><tr>";
                        $scount = 0;
                        }
        }
        echo "</tr></table><br /><hr />";
}
$fullcountresult=$db->query("SELECT COUNT(*) FROM ".$db->prefix("mysections_articles")." WHERE cid=$cid AND status>0");
list($numrows) = $db->fetchRow($fullcountresult);
if ($numrows>0) {
        //if 2 or more items in result, show the sort menu
        if ($numrows>1) {
                $orderbyTrans = convertorderbytrans($orderby);
                echo "
                <br /><center>"._SORTBY."&nbsp;&nbsp;
                "._TITLE." (<a href='viewcat.php?cid=$cid&orderby=titleA'><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."up.gif' border='0' align='middle' alt='' /></a><a href='viewcat.php?cid=$cid&orderby=titleD'><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."down.gif' border='0' align='middle' alt='' /></a>)
                "._DATE." (<a href='viewcat.php?cid=$cid&orderby=dateA'><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."up.gif' border='0' align='middle' alt='' /></a><a href='viewcat.php?cid=$cid&orderby=dateD'><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."down.gif' border='0' align='middle' alt='' /></a>)
                "._RATING." (<a href='viewcat.php?cid=$cid&orderby=ratingA'><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."up.gif' border='0' align='middle' alt='' /></a><a href='viewcat.php?cid=$cid&orderby=ratingD'><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."down.gif' border='0' align='middle' alt='' /></a>)
                "._POPULARITY." (<a href='viewcat.php?cid=$cid&orderby=counterA'><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."up.gif' border='0' align='middle' alt='' /></a><a href='viewcat.php?cid=$cid&orderby=counterD'><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."down.gif' border='0' align='middle' alt='' /></a>)
                <b><br />";
                printf(_MD_CURSORTBY, $orderbyTrans);
                echo "</b></center><br />";
                }
        if ($numrows>0) {
                echo "<br />
                <table width='100%' border='0' cellspacing='1' cellpadding='0' class='bg2'><tr><td>
                <table width='100%' border='0' cellspacing='1' cellpadding='4' class='bg1'><tr class='bg2'>
                <td>"._MD_ARTICLE."</td><td align='center'>"._READS."</td><td align='center'>"._RATING.':'."</td><td>&nbsp;</td></tr>";
                }
        $sql = "
                SELECT
                lid,
                title,
                titletip,
                url,
                homepage,
                version,
                size,
                platform,
                logourl,
                status,
                date,
                hits,
                counter,
                rating,
                votes,
                comments,
                description
                FROM
                ".$db->prefix("mysections_articles")."
                WHERE
                cid=$cid
                AND
                status>0
                ORDER BY
                $orderby";
        $result = $db->query($sql, $show, $min);
        while (list($lid, $dtitle, $titletip, $url, $homepage, $version, $size, $platform, $logourl, $status, $time, $hits, $counter, $rating, $votes, $comments, $description)=$db->fetchRow($result)) {
                $rating      = number_format($rating, 2);
                $dtitle      = $myts->makeTboxData4Show($dtitle);
                $titletip    = $myts->makeTboxData4Show($titletip);
                $url         = $myts->makeTboxData4Show($url);
                $homepage    = $myts->makeTboxData4Show($homepage);
                $version     = $myts->makeTboxData4Show($version);
                $size        = $myts->makeTboxData4Show($size);
                $platform    = $myts->makeTboxData4Show($platform);
                $logourl     = $myts->makeTboxData4Show($logourl);
                $datetime    = formatTimestamp($time, "s");
                $description = $myts->makeTareaData4Show($description, 1, 1, 1);
                include("include/catformat.php");
        }
        $orderby       = convertorderbyout($orderby);
        //Calculates how many pages exist.  Which page one should be on, etc...
        $downloadpages = ceil($numrows / $show);
        //Page Numbering
        if ($downloadpages != 1 && $downloadpages != 0) {
                echo "</table></td></tr></table>";
                echo "<br /><br />";
                $prev = ($min - $show);
                if ($prev >= 0) {
                        echo "
                        &nbsp;<a href='viewcat.php?cid=$cid&min=$prev&orderby=$orderby&show=$show'>
                        <b>&lt; "._PREVIOUS." </b></a>&nbsp;";
                        }
                $counter = 1;
                $currentpage = ($max / $show);
                while ( $counter <= $downloadpages ) {
                        $mintemp = (($show * $counter) - $show);
                        if ($counter == $currentpage) {
                                echo "<b>$counter</b>&nbsp;";
                                } else {
                                        echo "<a href='viewcat.php?cid=$cid&min=$mintemp&orderby=$orderby&show=$show'>$counter</a>&nbsp;";
                                }
                        $counter++;
                }
                if ( $numrows>$max ) {
                        echo "
                        &nbsp;<a href='viewcat.php?cid=$cid&min=$max&orderby=$orderby&show=$show'>
                        <b> "._NEXT." &gt;</b></a>";
                        }
                }
}
echo "</td></tr></table>";
CloseTable();
include_once("footer.php");
?>