<?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: index.php,v 1.2 2004/03/20 18:35:00 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("admin_header.php");
$eh     = new ErrorHandler(0);
$mytree = new XoopsTree($db->prefix("mysections_cat"), "cid", "pid");
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function mysections() {
global $db;
xoops_cp_header();
OpenTable();
// Temporarily 'homeless' downloads (to be revised in index.php breakup)
$result = $db->query("SELECT COUNT(*) FROM ".$db->prefix("mysections_broken")."");
list($totalbrokendownloads) = $db->fetchRow($result);
if ($totalbrokendownloads > 0) {
        $totalbrokendownloads = "<span style='font-weight: bold'>$totalbrokendownloads</span>";
}
$result2 = $db->query("SELECT COUNT(*) FROM ".$db->prefix("mysections_mod")."");
list($totalmodrequests) = $db->fetchRow($result2);
if ($totalmodrequests > 0) {
        $totalmodrequests = "<span style='font-weight: bold'>$totalmodrequests</span>";
}
$result3 = $db->query("SELECT COUNT(*) FROM ".$db->prefix("mysections_articles")." WHERE status=0");
list($totalnewdownloads) = $db->fetchRow($result3);
if ($totalnewdownloads > 0) {
        $totalnewdownloads = "<span style='font-weight: bold'>$totalnewdownloads</span>";
}
?>
- <a href="index.php?op=mysectionsConfigAdmin"><?php echo _GENERALSETTINGS;?></a>
<br /><br />
- <a href="index.php?op=downloadsConfigMenu"><?php echo _ADDMODIFYDELETECATEGORIESFILES;?></a>
<br /><br />
- <a href="index.php?op=listNewDownloads"><?php echo _AWAITINGVALIDATION;?> (<?php echo $totalnewdownloads;?>)</a>
<br /><br />
- <a href="index.php?op=listBrokenDownloads"><?php echo _BROKENFILEREPORTS;?> (<?php echo $totalbrokendownloads;?>)</a>
<br /><br />
- <a href="index.php?op=listModReq"><?php echo _MODIFICATIONREQUESTS;?> (<?php echo $totalmodrequests;?>)</a>
<?php
$result = $db->query("SELECT COUNT(*) FROM ".$db->prefix("mysections_articles")." WHERE status>0");
list($numrows) = $db->fetchRow($result);
echo "<br /><br /><div align='center'>";
printf(_THEREARE, $numrows);
echo "</div>";
CloseTable();
xoops_cp_footer();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function listNewDownloads() {
global $db, $myts, $eh, $mytree, $bcoosConfig;
// List downloads waiting for validation
$result  = $db->query("SELECT lid, cid, title, titletip, description, url, homepage, version, size, platform, logourl, submitter FROM ".$db->prefix("mysections_articles")." WHERE status=0 ORDER BY date DESC");
$numrows = $db->getRowsNum($result);
xoops_cp_header();
OpenTable();
echo "<h4><a href='index.php'>"._MAIN."</a>: "._AWAITINGVALIDATION." ($numrows)</h4>";
if ($numrows > 0) {
        while (list($lid, $cid, $title, $titletip, $description, $url, $homepage, $version, $size, $platform, $logourl, $uid) = $db->fetchRow($result)) {
                $title       = $myts->makeTboxData4Edit($title);
                $titletip    = $myts->makeTboxData4Edit($titletip);
                $url         = $myts->makeTboxData4Edit($url);
                $homepage    = $myts->makeTboxData4Edit($homepage);
                $version     = $myts->makeTboxData4Edit($version);
                $size        = $myts->makeTboxData4Edit($size);
                $platform    = $myts->makeTboxData4Edit($platform);
                $description = $myts->makeTboxData4Edit($description);
                if ($uid != 0) {
                        $submitter = XoopsUser::getUnameFromId($uid);
                        $submitter = $myts->makeTboxData4Show($submitter);
                        } else {
                                $submitter = $myts->makeTboxData4Show($bcoosConfig['anonymous']);
                }
?>
<hr />
<form action="index.php" method="post">
<table width="100%">
<tr><td nowrap><?php echo _SUBMITTER;?></td>
<td><a href="<?php echo XOOPS_URL;?>/userinfo.php?uid=<?php echo $uid;?>"><?php echo $submitter;?></a></td>
</tr><tr>
<td nowrap><?php echo _TITLE.': ';?></td>
<td><input type="text" class="text" name="title" size="50" maxlength="60" value="<?php echo $title;?>"></td>
</tr><tr>
<td nowrap><?php echo _MD_FILETITLETIP;?></td>
<td><input type="text" class="text" name="titletip" size="50" maxlength="255" value="<?php echo $titletip;?>"></td>
</tr><tr>
<td nowrap><?php echo _CATEGORY.':';?></td>
<td><?php $mytree->makeMySelBox("title", "title", $cid);?></td>
</tr><tr>
<td valign="top" nowrap><?php echo _DESCRIPTION.':';?></td>
<td>
<?php
$desc = new XoopsFormDhtmlTextArea('', 'filedesc', $description, 10, 50);
echo $desc->render();
?>
</td>
</tr></table><br />
<table width="100%"><tr>
<td nowrap><?php echo _DOWNLOADURL;?></td>
<td><input type="text" class="text" name="url" size="50" maxlength="255" value="<?php echo $url;?>"> [ <a href="<?php echo formatURL(XOOPS_URL."/modules/mysections/cache/files/", $url);?>"><?php echo _DOWNLOAD;?></a> ]</td>
</tr><tr>
<td nowrap><?php echo _SITEURL;?></td>
<td><input type="text" class="text" name="homepage" size="50" maxlength="255" value="<?php echo $homepage;?>"> [ <a href="<?php echo $homepage;?>"><?php echo _VISIT;?></a> ]</td>
</tr><tr>
<td><?php echo _VERSION.': ';?></td>
<td><input type="text" class="text" name="version" size="10" maxlength="10" value="<?php echo $version;?>"></td>
</tr><tr>
<td><?php echo _FILESIZE.': ';?></td>
<td><input type="text" class="text" name="size" size="10" maxlength="10" value="<?php echo $size;?>"> <?php echo _BYTES;?></td>
</tr><tr>
<td><?php echo _PLATFORM.': ';?></td>
<td><input type="text" class="text" name="platform" size="45" maxlength="30" value="<?php echo $platform;?>"></td>
</tr></table>
<table width="100%"><tr>
<td align="right">
<input type="hidden" name="op" value="approve">
<input type="hidden" name="lid" value="<?php echo $lid;?>">
<input type="submit" class="button" value="<?php echo _APPROVE;?>">
</form></td>
<td align="left"><?php echo myTextForm("index.php?op=delNewDownload&lid=$lid", _DELETE);?></td>
</tr></table><hr />
<?php
        }
        } else {
                echo _NONEWSUBMITTED;
        }
CloseTable();
xoops_cp_footer();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function downloadsConfigMenu() {
global $db, $myts, $eh, $mytree;
xoops_cp_header();
$result=$db->query("SELECT COUNT(*) FROM ".$db->prefix("mysections_cat")."");
list($numrows) = $db->fetchRow($result);
if ($numrows > 0) {
        OpenTable();
        // If there is a category, add a New Download
?>
<form method="post" action="index.php" enctype="multipart/form-data">
<h4><a href="index.php"><?php echo _MAIN;?></a>: <?php echo _ADDCONTENT;?></h4><br />
<table width="100%"><tr>
<td><?php echo _TITLE.': ';?></td>
<td><input type="text" class="text" name="title" size="50" maxlength="60" /></td>
</tr><tr>
<td><?php echo _MD_FILETITLETIP;?></td>
<td><input type="text" class="text" name="titletip" size="50" maxlength="225" /></td>
</tr><tr>
<td nowrap><?php echo _CATEGORY.':';?></td>
<td><?php $mytree->makeMySelBox("title", "title");?></td>
</tr><tr>
<td valign="top" nowrap><?php echo _DESCRIPTION.':';?></td>
<td>
<?php
echo _MD_PAGEBREAK;
echo "<br /><br />";
$desc = new XoopsFormDhtmlTextArea('', 'filedesc', '', 10, 50);
echo $desc->render();
?>
</td>
</tr></table>
<hr />
<table width="100%"><tr>
<td valign="top" nowrap><?php echo _DOWNLOADURL;?></td>
<td>
<input type="text" class="text" name="url" size="50" maxlength="255" />
<?php
echo "<br />";
$upload = new Upload();
$upload->printFormField("download");
?>
</td>
</tr><tr>
<td>&nbsp;</td>
<td><?php printf(_FILEUPLOADDESCRIPTION, "modules/mysections/cache/files/");?></td>
</tr><tr>
<td nowrap><?php echo _SITEURL;?></td>
<td><input type="text" class="text" name="homepage" size="50" maxlength="255" value="http://"></td>
</tr><tr>
<td><?php echo _VERSION.': ';?></td>
<td><input type="text" class="text" name="version" size="10" maxlength="10"></td>
</tr><tr>
<td><?php echo _FILESIZE.': ';?></td>
<td><input type="text" class="text" name="size" size="10" maxlength="10"> <?php echo _BYTES;?></td>
</tr><tr>
<td><?php echo _PLATFORM.': ';?></td>
<td><input type="text" class="text" name="platform" size="45" maxlength="30"></td>
</tr></table>
<hr />
<table width="100%"><tr>
<td valign="top" nowrap><?php echo _SHOTIMAGE;?></td>
<td>
<input type="text" class="text" name="logourl" size="50" maxlength="255">
<?php
echo "<br />";
$upload->printFormField("image");
?>
</td>
</tr><tr>
<td>&nbsp;</td>
<td><?php printf(_SHOTDESCRIPTION, "modules/mysections/cache/images/shots/");?></td>
</tr></table>
<br />
<input type="hidden" name="op" value="addDownload" />
<input type="submit" class="button" value="<?php echo _ADD;?>" />
</form>
<?php
CloseTable();
echo "<br />";
OpenTable();
// Modify Download
?>
<form method="post" action="index.php">
<h4><?php echo _MODIFYCONTENTINFO;?></h4>
<?php echo _FILEID;?>
<input type="text" class="text" name="lid" size="12" maxlength="11">
<input type="hidden" name="fct" value="mysections">
<input type="hidden" name="op" value="modDownload">
<input type="submit" class="button" value="<?php echo _MODIFY;?>">
</form>
<?php
CloseTable();
echo "<br />";
OpenTable();
// Modify Category
?>
<form method="post" action="index.php">
<h4><?php echo _MODIFYCATEGORY;?></h4>
<?php echo _CATEGORY.':';?>
<?php $mytree->makeMySelBox("title", "title");?>
<input type="hidden" name="op" value="modCat">
<input type="submit" class="button" value="<?php echo _MODIFY;?>">
</form>
<?php
CloseTable();
echo "<br />";
OpenTable();
// Add a New Sub-Category
?>
<form method="post" action="index.php">
<h4><?php echo _ADDSUBCATEGORY;?></h4>
<?php echo _TITLE.':';?>
<input type="text" class="text" name="title" size="30" maxlength="60">
<?php echo _IN;?>
<?php $mytree->makeMySelBox("title", "title");?>
<input type="hidden" name="op" value="addCat">
<input type="submit" class="button" value="<?php echo _ADD;?>">
</form>
<?php
CloseTable();
echo "<br />";
}
// Add a New Main Category
OpenTable();
?>
<form method="post" action="index.php">
<h4><?php echo _ADDMAINCATEGORY;?></h4>
<?php echo _TITLE.':';?>
<input type="text" class="text" name="title" size="30" maxlength="60">
<input type="hidden" name="op" value="addCat">
<input type="submit" class="button" value="<?php echo _ADD;?>">
</form>
<?php
CloseTable();
xoops_cp_footer();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function delVote() {
global $db, $_GET, $eh;
$rid = intval($_GET['rid']);
$lid = intval($_GET['lid']);
$query = "DELETE FROM ".$db->prefix("mysections_votedata")." WHERE ratingid=$rid";
$db->query($query) or $eh->show("0013");
updaterating($lid);
redirect_header("index.php", 1, _VOTEDATADELETED);
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function listBrokenDownloads() {
global $db, $myts, $eh, $bcoosConfig;
$result = $db->query("SELECT reportid, lid, sender, ip FROM ".$db->prefix("mysections_broken")." ORDER BY reportid");
$totalbrokendownloads = $db->getRowsNum($result);
xoops_cp_header();
OpenTable();
echo "<h4><a href='index.php'>"._MAIN."</a>: "._BROKENFILEREPORTS." ($totalbrokendownloads)</h4><br />";
if ($totalbrokendownloads == 0) {
        echo _NOBROKENREPORTS;
        } else {
                $colorswitch = "bg1";
                ?>
                <center><?php echo _ONLYDELETEREPORT;?><br /><?php echo _DELETEDATAANDREPORT;?></center>
                <br /><br /><br />
                <table align="center" width="90%"><tr>
                <td><b><?php echo _TITLE.': ';?></b></td>
                <td><b><?php echo _REPORTER;?></b></td>
                <td><b><?php echo _SUBMITTER;?></b></td>
                <td><b><?php echo _IGNORE;?></b></td>
                <td><b><?php echo _EDIT;?></b></td>
                <td><b><?php echo _DELETE;?></b></td>
                </tr>
                <?php
while (list($reportid, $lid, $senderid, $ip) = $db->fetchRow($result)) {
        $result2 = $db->query("SELECT title, url, submitter FROM ".$db->prefix("mysections_articles")." WHERE lid=$lid");
        list($title, $url, $ownerid) = $db->fetchRow($result2);
        $title = $myts->makeTboxData4Show($title);
        if ($senderid != 0) {
                $sender = XoopsUser::getUnameFromId($senderid);
                $sender = $myts->makeTboxData4Show($sender);
                } else {
                        $sender = $myts->makeTboxData4Show($bcoosConfig['anonymous']);
        }
        if ($ownerid != 0) {
                $owner = XoopsUser::getUnameFromId($ownerid);
                $owner = $myts->makeTboxData4Show($owner);
                } else {
                        $owner = $myts->makeTboxData4Show($bcoosConfig['anonymous']);
        }
        echo "
        <tr>
        <td class='$colorswitch'><a href='".XOOPS_URL."/modules/mysections/singlefile.php?lid=$lid''>$title</a></td>
        <td class='$colorswitch'><a href='".XOOPS_URL."/userinfo.php?uid=$senderid'>$sender</a> ($ip)</td>
        <td class='$colorswitch'><a href='".XOOPS_URL."/userinfo.php?uid=$ownerid'>$owner</a></td>
        <td class='$colorswitch' align='center'>";
        echo myTextForm("index.php?op=ignoreBrokenDownloads&lid=$lid" , "X");
        echo "</td><td class='$colorswitch' align='center'>";
        echo myTextForm("index.php?op=modDownload&lid=$lid" , "X");
        echo "</td><td class='$colorswitch' align='center'>";
        echo myTextForm("index.php?op=delBrokenDownloads&lid=$lid" , "X");
        echo "</td></tr>";
        if ($colorswitch == "bg1") {
                $colorswitch = "bg3";
                } else {
                        $colorswitch="bg1";
                }
        }
        echo "</table>";
}
CloseTable();
xoops_cp_footer();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function delBrokenDownloads() {
global $db, $_GET, $eh;
$lid = intval($_GET['lid']);
$query = "DELETE FROM ".$db->prefix("mysections_broken")." WHERE lid=$lid";
$db->query($query) or $eh->show("0013");
$query  = "SELECT url, logourl FROM ".$db->prefix("mysections_articles")." WHERE lid=$lid";
$result = $db->query($query);
list($url, $logourl) = $db->fetchRow($result);
@unlink("../cache/files/" . basename($url));
@unlink("../cache/shots/" . basename($logourl));
$query = "DELETE FROM ".$db->prefix("mysections_articles")." WHERE lid=$lid";
$db->query($query) or $eh->show("0013");
build_rss();
redirect_header("./index.php?op=listBrokenDownloads", 1, _MD_FILEDELETED);
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function ignoreBrokenDownloads() {
global $db, $_GET, $eh;
$lid   = intval($_GET['lid']);
$query = "DELETE FROM ".$db->prefix("mysections_broken")." WHERE lid=$lid";
$db->query($query) or $eh->show("0013");
redirect_header("./index.php?op=listBrokenDownloads", 1, _BROKENFILEREPORTDELETED);
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function listModReq() {
global $db, $myts, $eh, $mytree, $mysectionsConfig;
xoops_cp_header();
OpenTable();
$sql_mod = $db->query("SELECT requestid, lid, cid, title, titletip, description, url, homepage, version, size, platform, modifysubmitter FROM ".$db->prefix("mysections_mod")." ORDER BY requestid");
$totalmodrequests = $db->getRowsNum($sql_mod);
echo "<h4><a href='index.php'>"._MAIN."</a>: "._USERMODIFICATIONREQUEST." ($totalmodrequests)</h4><br />";
if ($totalmodrequests > 0) {
        while (list($requestid, $lid, $cid, $title, $titletip, $description, $url, $homepage, $version, $size, $platform, $modifysubmitter) = $db->fetchRow($sql_mod)) {
                $cidtitle      = $mytree->getNicePathFromId($cid, "title", XOOPS_URL."/modules/mysections/viewcat.php?");
                $cidtitle      = substr($cidtitle, 0, -2);
                $title         = $myts->makeTboxData4Show($title);
                $titletip      = $myts->makeTboxData4Show($titletip);
                $url           = formatURL(XOOPS_URL."/modules/mysections/cache/files/", $myts->makeTboxData4Show($url));
                $homepage      = $myts->makeTboxData4Show($homepage);
                $version       = $myts->makeTboxData4Show($version);
                $size          = $myts->makeTboxData4Show($size);
                $platform      = $myts->makeTboxData4Show($platform);
                $description   = $myts->makeTareaData4Show($description);
                if ($modifysubmitter != 0) {
                        $submittername = XoopsUser::getUnameFromId($modifysubmitter);
                        $submittername = $myts->makeTareaData4Show($submittername);
                }
                $sql_original = $db->query("SELECT cid, title, titletip, description, url, homepage, version, size, platform, submitter FROM ".$db->prefix("mysections_articles")." WHERE lid=$lid");
                list($origcid, $origtitle, $origtitletip, $origdescription, $origurl, $orighomepage, $origversion, $origsize, $origplatform, $owner) = $db->fetchRow($sql_original);
                $origcidtitle    = $mytree->getNicePathFromId($origcid, "title", XOOPS_URL."/modules/mysections/viewcat.php?");
                $origcidtitle    = substr($origcidtitle, 0, -2);
                $origtitle       = $myts->makeTboxData4Show($origtitle);
                $origtitletip    = $myts->makeTboxData4Show($origtitletip);
                $origurl         = formatURL(XOOPS_URL."/modules/mysections/cache/files/", $myts->makeTboxData4Show($origurl));
                $orighomepage    = $myts->makeTboxData4Show($orighomepage);
                $origversion     = $myts->makeTboxData4Show($origversion);
                $origsize        = $myts->makeTboxData4Show($origsize);
                $origplatform    = $myts->makeTboxData4Show($origplatform);
                $origdescription = $myts->makeTareaData4Show($origdescription);
                if ($owner != 0) {
                        $ownername       = XoopsUser::getUnameFromId($owner);
                        $ownername       = $myts->makeTareaData4Show($ownername);
                }
?>
<hr align="center" size="1" noshade="noshade" />
<table width="100%" cellspacing="0" cellpadding="0"><tr>
<td valign="top"><?php echo _REQUESTID;?></td>
<td valign="top"><b><?php echo $requestid;?></b></td>
</tr><tr>
<td valign="top"><b><?php echo _PROPOSED;?></b></td>
<td width="50%" rowspan="8" valign="top"><?php echo _DESCRIPTION.':';?><br /><?php echo $description;?></td>
</tr><tr>
<td valign="top"><?php echo _TITLE.': ';?> <?php echo $title;?></td>
</tr><tr>
<td valign="top"><?php echo _MD_FILETITLETIP;?> <?php echo $titletip;?></td>
</tr><tr>
<td valign="top"><?php echo _DOWNLOADURL;?> <a href="<?php echo $url;?>"><?php echo $url;?></a></td>
</tr><tr>
<td valign="top"><?php echo _CATEGORY.':';?> <?php echo $cidtitle;?></td>
</tr><tr>
<td valign="top"><?php echo _SITEURL;?> <a href="<?php echo $homepage;?>"><?php echo $homepage;?></a></td>
</tr><tr>
<td valign="top"><?php echo _VERSION.': ';?> <?php echo $version;?></td>
</tr><tr>
<td valign="top"><?php echo _FILESIZE.': ';?> <?php echo $size;?></td>
</tr><tr>
<td valign="top"><?php echo _PLATFORM.': ';?> <?php echo $platform;?></td>
</tr><tr>
<td colspan="2">&nbsp;</td>
</tr><tr>
<td valign="top"><b><?php echo _ORIGINAL;?></b></td>
<td width="50%" rowspan="8" valign="top"><?php echo _DESCRIPTION.':';?><br /><?php echo $origdescription;?></td>
</tr><tr>
<td valign="top"><?php echo _TITLE.': ';?> <?php echo $origtitle;?></td>
</tr><tr>
<td valign="top"><?php echo _MD_FILETITLETIP;?> <?php echo $origtitletip;?></td>
</tr><tr>
<td valign="top"><?php echo _DOWNLOADURL;?> <a href="<?php echo $origurl;?>"><?php echo $origurl;?></a></td>
</tr><tr>
<td valign="top"><?php echo _CATEGORY.':';?> <?php echo $origcidtitle;?></td>
</tr><tr>
<td valign="top"><?php echo _SITEURL;?> <a href="<?php echo $orighomepage;?>"><?php echo $orighomepage;?></a></td>
</tr><tr>
<td valign="top"><?php echo _VERSION.': ';?> <?php echo $origversion;?></td>
</tr><tr>
<td valign="top"><?php echo _FILESIZE.': ';?> <?php echo $origsize;?></td>
</tr><tr>
<td valign="top"><?php echo _PLATFORM.': ';?> <?php echo $origplatform;?></td>
</tr><tr align="center">
<td colspan="2">
<br />
<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>
<td valign="top" width="35%"><?php echo _SUBMITTER;?> <a href="<?php echo XOOPS_URL;?>/userinfo.php?uid=<?php echo $modifysubmitter;?>"><?php echo $submittername;?></a></td>
<td valign="top" width="35%"><?php echo _OWNER;?> <a href="<?php echo XOOPS_URL;?>/userinfo.php?uid=<?php echo $owner;?>"><?php echo $ownername;?></a></td>
<td valign="top" width="5%"><?php echo myTextForm("index.php?op=changeModReq&requestid=$requestid" , _APPROVE);?></td>
<td valign="top" width="5%"><?php echo myTextForm("index.php?op=modDownload&lid=$lid" , _EDIT);?></td>
<td valign="top" width="5%"><?php echo myTextForm("index.php?op=ignoreModReq&requestid=$requestid", _IGNORE);?></td>
</tr></table>
</td>
</tr></table>
<?php
        }
        } else {
                echo _NOMODIFICATIONREQUEST;
        }
CloseTable();
xoops_cp_footer();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function changeModReq() {
global $db, $_GET, $eh, $myts;
$requestid = intval($_GET['requestid']);
$sql = "SELECT
        lid,
        cid,
        title,
        titletip,
        url,
        homepage,
        version,
        size,
        platform,
        description
        FROM ".$db->prefix("mysections_mod")."
        WHERE requestid=$requestid";
$result = $db->query($sql);
list($lid, $cid, $title, $titletip, $url, $homepage, $version, $size, $platform, $description) = $db->fetchRow($result);
$title       = $myts->oopsAddSlashesRT($title);
$titletip    = $myts->oopsAddSlashesRT($titletip);
$url         = $myts->oopsAddSlashesRT($url);
$homepage    = $myts->oopsAddSlashesRT($homepage);
$description = $myts->oopsAddSlashesRT($description);
$platform    = $myts->oopsAddSlashesRT($platform);
$sql = "UPDATE ".$db->prefix("mysections_articles")." SET
        cid=$cid,
        title='$title',
        titletip='$titletip',
        description='$description',
        url='$url',
        homepage='$homepage',
        version='$version',
        size='$size',
        platform='$platform',
        status=2,
        date=".time()."
        WHERE lid=$lid";
$db->query($sql) or $eh->show("0013");
$db->query("DELETE FROM ".$db->prefix("mysections_mod")." WHERE requestid=$requestid") or $eh->show("0013");
redirect_header("index.php?op=listModReq", 1, _UPDATED);
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function ignoreModReq() {
global $db, $_GET, $eh;
$requestid = intval($_GET['requestid']);
$query     = "DELETE FROM ".$db->prefix("mysections_mod")." WHERE requestid=$requestid";
$db->query($query) or $eh->show("0013");
redirect_header("./index.php?op=listModReq", 1, _MODIFICATIONREQUESTDELETED);
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function delDownload() {
global $db, $_GET, $eh;
$lid = intval($_GET['lid']);
$query  = "SELECT url, logourl FROM ".$db->prefix("mysections_articles")." WHERE lid=$lid";
$result = $db->query($query);
list($url, $logourl) = $db->fetchRow($result);
@unlink("../cache/files/" . basename($url));
@unlink("../cache/shots/" . basename($logourl));
$query = "DELETE FROM ".$db->prefix("mysections_articles")." WHERE lid=$lid";
$db->query($query) or $eh->show("0013");
$query = "DELETE FROM ".$db->prefix("mysections_votedata")." WHERE lid=$lid";
$db->query($query) or $eh->show("0013");
build_rss();
redirect_header("index.php", 1, _MD_FILEDELETED);
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function modCat() {
global $db, $xoopsModule, $_POST, $_GET, $myts, $eh, $mytree;
$cid = !empty($_POST["cid"]) ? intval($_POST["cid"]) : intval($_GET["cid"]);
xoops_cp_header();
OpenTable();
echo "<h4><a href='index.php'>"._MAIN."</a>: "._MODIFYCATEGORY."</h4><br />";
$result = $db->query("SELECT pid, title, imgurl, description FROM ".$db->prefix("mysections_cat")." WHERE cid=$cid");
global $desc;
list($pid, $title, $imgurl, $description) = $db->fetchRow($result);
$title  = $myts->makeTboxData4Edit($title);
$imgurl = $myts->makeTboxData4Edit($imgurl);
$desc   = $myts->makeTboxData4Edit($description);
?>
<form action="./index.php" method="post" enctype="multipart/form-data">
<?php echo _TITLE.':';?><br />
<input type="text" class="text" name="title" value="<?php echo $title;?>" size="51" maxlength="60">
<br /><br />
<input type="text" class="text" name="imgurl" value="<?php echo $imgurl;?>" size="51" maxlength="255"><br />
<?php
$upload = new Upload();
$upload->setFileName($cid);
$upload->printFormField("image");
echo "<br />".sprintf(_AM_IMGLOCATION, "modules/".$xoopsModule->dirname()."/cache/logos/");
?>
<br /><br />
<?php echo _DESCRIPTION;?>:<br />
<?php
$desc = new XoopsFormDhtmlTextArea('', 'desc', $desc, 10, 50);
echo $desc->render();
?>
<br /><br />
<?php echo _PARENTCATEGORY;?><br />
<?php $mytree->makeMySelBox("title", "title", $pid, 1, "pid");?>
<br /><br />
<input type="hidden" name="cid" value="<?php echo $cid;?>" />
<input type="hidden" name="op" value="modCatS" /><br />
<input type="submit" class="button" value="<?php echo _SAVE;?>" />
<input type="button" class="button" value="<?php echo _DELETE;?>" onclick="location='index.php?pid=<?php echo $pid;?>&cid=<?php echo $cid;?>&op=delCat';" />
<input type="button" class="button" value="<?php echo _CANCEL;?>" onclick="location='index.php';" />
</form>
<?php
CloseTable();
xoops_cp_footer();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function modCatS() {
global $db, $myts, $_POST, $_FILES;
$cid         = intval($_POST['cid']);
$pid         = intval($_POST['pid']);
$imgurl      = $myts->makeTboxData4Save($_POST['imgurl']);
$title       = $myts->makeTboxData4Save($_POST['title']);
$description = $myts->makeTboxData4Save($_POST['desc']);
if ( !empty($_FILES['image']['name']) ) {
        $upload = new Upload();
		$upload->setAllowedMimeTypes(".gif|.jpeg|.jpg|.png");
        $upload->setUploadPath(XOOPS_ROOT_PATH."/modules/mysections/cache/logos");
        $upload->setDestinationFileName('image');
		$upload->setFileName($cid);
        $result = $upload->doUpload();
		
		if ($result) {
                $imgurl = $upload->FileName.".".$upload->getFileExtension();
                } else {
					$errors = $upload->getUploadErrors();
					$errorstring = "";
					$errorstring .= "<strong>::Errors occured::</strong><br />\n";
					while(list($filename,$values) = each($errors)) {
						$errorstring .= "File: " . $filename . "<br />";
						$count = count($values);
						for($i=0; $i<$count; $i++) { $errorstring .= "==>" . $values[$i] . "<br />"; }
					}
                        redirect_header("index.php?op=modCat&cid=$cid", 3, $errorstring);
                        exit();
                }
}
$db->query("UPDATE ".$db->prefix("mysections_cat")." SET title='$title', imgurl='$imgurl', pid='$pid', description='$description' WHERE cid=$cid");
build_rss();
redirect_header("index.php?op=modCat&cid=$cid", 1, _UPDATED);
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function addCat() {
global $db, $_POST, $myts, $eh;
$pid   = intval($_POST['cid']);
$title = $myts->makeTboxData4Save($_POST["title"]);
$newid = $db->genId($db->prefix("mysections_cat")."_cid_seq");
$query = $db->query("INSERT INTO ".$db->prefix("mysections_cat")." SET cid='$newid', pid='$pid', title='$title'") or $eh->show("0013");
if ($newid == 0) {
        $newid = $db->getInsertId($query);
}
redirect_header("index.php?op=modCat&cid=$newid", 1, _NEWCATEGORYADDED);
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function delCat() {
global $db, $_GET, $mytree;
$cid = intval($_GET['cid']);
if ($_GET['ok'] == 1) {
        //get all subcategories under the specified category
        $arr  = $mytree->getAllChildId($cid);
        $size = count($arr);
        for ($i=0; $i<$size; $i++) {
                //get all downloads in each subcategory
                $result = $db->query("SELECT lid, url, logourl FROM ".$db->prefix("mysections_articles")." WHERE cid=".$arr[$i]."");
                //now for each download, delete the text data and vote ata associated with the download
                while (list($lid, $url, $logourl) = $db->fetchRow($result)) {
                        @unlink("../cache/files/" . basename($url));
                        @unlink("../cache/shots/" . basename($logourl));
                        $db->query("DELETE FROM ".$db->prefix("mysections_votedata")." WHERE lid=$lid");
                        $db->query("DELETE FROM ".$db->prefix("mysections_articles")." WHERE lid=$lid");
                }
                //all downloads for each subcategory is deleted, now delete the subcategory data
                $result = $db->query("SELECT imgurl FROM ".$db->prefix("mysections_cat")." WHERE cid=".$arr[$i]."");
                list($imgurl) = $db->fetchRow($result);
                @unlink("../cache/logos/" . basename($imgurl));
                $db->query("DELETE FROM ".$db->prefix("mysections_cat")." WHERE cid=".$arr[$i]."");
        }
        //all subcategory and associated data are deleted, now delete category data and its associated data
        $result = $db->query("SELECT lid, url, logourl FROM ".$db->prefix("mysections_articles")." WHERE cid=$cid");
        while (list($lid, $url, $logourl) = $db->fetchRow($result)) {
                @unlink("../cache/files/" . basename($url));
                @unlink("../cache/shots/" . basename($logourl));
                $db->query("DELETE FROM ".$db->prefix("mysections_votedata")." WHERE lid=$lid");
                $db->query("DELETE FROM ".$db->prefix("mysections_articles")." WHERE lid=$lid");
        }
        $result = $db->query("SELECT imgurl FROM ".$db->prefix("mysections_cat")." WHERE cid=$cid");
        list($imgurl) = $db->fetchRow($result);
        @unlink("../cache/logos/" . basename($imgurl));
        $db->query("DELETE FROM ".$db->prefix("mysections_cat")." WHERE cid=$cid");
        build_rss();
        redirect_header("index.php", 1, _CATEGORYDELETED);
        exit();
        } else {
                xoops_cp_header();
                OpenTable();
                echo "<h4>"._DELETECATEGORYANDCONTENT."</h4><br /><table><tr><td>";
                echo myTextForm("index.php?op=delCat&cid=$cid&ok=1", _YES);
                echo "</td><td>";
                echo myTextForm("index.php", _NO);
                echo "</td></tr></table>";
                CloseTable();
                xoops_cp_footer();
        }
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function addDownload() {
global $db, $myts, $xoopsUser, $eh, $_FILES, $_POST, $mysectionsConfig;
$homepage    = formatURL($myts->makeTboxData4Save($_POST["homepage"]));
$url         = $myts->makeTboxData4Save($_POST["url"]);
$logourl     = $myts->makeTboxData4Save($_POST["logourl"]);
$title       = $myts->makeTboxData4Save($_POST["title"]);
$titletip    = $myts->makeTboxData4Save($_POST["titletip"]);
$version     = $myts->makeTboxData4Save($_POST["version"]);
$size        = $myts->makeTboxData4Save($_POST["size"]);
$platform    = $myts->makeTboxData4Save($_POST["platform"]);
$description = $myts->makeTboxData4Save($_POST["filedesc"]);
$submitter   = intval($xoopsUser->uid());
$result        = $db->query("SELECT COUNT(*) FROM ".$db->prefix("mysections_articles")." WHERE url='$url'");
list($numrows) = $db->fetchRow($result);
$sql = "SELECT lid FROM `".$db->prefix("mysections_articles")."` ORDER BY lid DESC LIMIT 1";
$queryid = $db->query($sql) or $eh->show("0013");
	if ($db->getRowsNum($queryid) == 0 ) {
		$newid = 1;
	} else {
		$newid =  $db->result($queryid,0);
		$newid++;
	}
// Check if Download exist
/*if ($numrows > 0) {
        redirect_header("index.php?op=downloadsConfigMenu", 3, _ALREADYINDATABASE);
        exit();
}*/
// Check if Title is empty
if ( empty($title) ) {
        redirect_header("index.php?op=downloadsConfigMenu", 3, _EMPTYTITLE);
        exit();
}
// Check if Description is empty
if ( empty($description) ) {
        redirect_header("index.php?op=downloadsConfigMenu", 3, _EMPTYDESCRIPTION);
        exit();
}
if ( empty($size) || !is_numeric($size) ) {
        $size = 0;
}
if ( !empty($_POST['cid']) ) {
        $cid = intval($_POST['cid']);
        } else {
                $cid = 0;
        }
if ( !empty($_FILES['download']['name']) ) {
        $upload = new Upload();
	$upload->setAllowedMimeTypes($mysectionsConfig['accepted_files']);
	$upload->setUploadPath(XOOPS_ROOT_PATH."/modules/mysections/cache/files");
        $upload->setDestinationFileName('download');
        $result = $upload->doUpload();
		
		if ($result) {
			$url  = $upload->HTTP_POST_FILES[$upload->uploadFieldName]['name'];
			$size = $upload->HTTP_POST_FILES[$upload->uploadFieldName]['size'];
		} else {
			$errors = $upload->getUploadErrors();
			$errorstring = "";
			$errorstring .= "<strong>::Errors occured::</strong><br />\n";
			while(list($filename,$values) = each($errors)) {
				$errorstring .= "File: " . $filename . "<br />";
				$count = count($values);
				for($i=0; $i<$count; $i++) { $errorstring .= "==>" . $values[$i] . "<br />"; }
			}
			redirect_header("index.php?op=downloadsConfigMenu", 3, $errorstring);
			exit();
		}
		
		
 		$upload = new Upload();
		$upload->setAllowedMimeTypes(".gif|.jpeg|.jpg|.png");
		$upload->setUploadPath(XOOPS_ROOT_PATH."/modules/mysections/cache/shots");
		$upload->setDestinationFileName('image');
		$upload->setFileName($newid);
		$result = $upload->doUpload();
		
		if ( !empty($_FILES['image']['name']) ) {
			if ($result) {
                $logourl = $upload->FileName.".".$upload->getFileExtension();
			} else {
				$errors = $upload->getUploadErrors();
				$errorstring = "";
				$errorstring .= "<strong>::Errors occured::</strong><br />\n";
				while(list($filename,$values) = each($errors)) {
					$errorstring .= "File: " . $filename . "<br />";
					$count = count($values);
					for($i=0; $i<$count; $i++) { $errorstring .= "==>" . $values[$i] . "<br />"; }
				}
				redirect_header("index.php?op=downloadsConfigMenu", 3, $errorstring);
				exit();
			}
        }
}
// Check if URL is empty
/*if ( empty($url) ) {
        redirect_header("index.php?op=downloadsConfigMenu", 3, _EMPTYURL);
        exit();
}*/
$sql   = "
        INSERT INTO ".$db->prefix("mysections_articles")." SET
        lid=$newid,
        cid=$cid,
        title='$title',
        titletip='$titletip',
        description='$description',
        url='$url',
        homepage='$homepage',
        version='$version',
        size='$size',
        platform='$platform',
        logourl='$logourl',
        submitter=$submitter,
        status=1,
        date=".time().",
        hits=0,
        counter=0,
        rating=0,
        votes=0,
        comments=0";
$db->query($sql) or $eh->show("0013");
build_rss();
redirect_header("index.php", 1, _CONTENTADDED);
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function delNewDownload() {
global $db, $_GET;
$lid   = intval($_GET['lid']);
$query  = "SELECT url, logourl FROM ".$db->prefix("mysections_articles")." WHERE lid=$lid";
$result = $db->query($query);
list($url, $logourl) = $db->fetchRow($result);
@unlink("../cache/files/" . basename($url));
@unlink("../cache/shots/" . basename($logourl));
$query = "DELETE FROM ".$db->prefix("mysections_articles")." WHERE lid=$lid";
$db->query($query);
redirect_header("./index.php?op=listNewDownloads", 1, _MD_FILEDELETED);
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function modDownload() {
global $db, $_GET, $_POST, $myts, $eh, $mytree;
$lid= !empty($_POST['lid']) ? intval($_POST['lid']) : intval($_GET['lid']);
$result = $db->query("SELECT cid, title, titletip, description, url, homepage, version, size, platform, logourl FROM ".$db->prefix("mysections_articles")." WHERE lid=$lid") or $eh->show("0013");
list($cid, $title, $titletip, $description, $url, $homepage, $version, $size, $platform, $logourl) = $db->fetchRow($result);
$homepage    = $myts->makeTboxData4Edit($homepage);
$title       = $myts->makeTboxData4Edit($title);
$titletip    = $myts->makeTboxData4Edit($titletip);
$description = $myts->makeTboxData4Edit($description);
$url         = $myts->makeTboxData4Edit($url);
$version     = $myts->makeTboxData4Edit($version);
$size        = $myts->makeTboxData4Edit($size);
$platform    = $myts->makeTboxData4Edit($platform);
$logourl     = $myts->makeTboxData4Edit($logourl);
xoops_cp_header();
OpenTable();
?>
<form method="post" action="index.php" enctype="multipart/form-data">
<h4><a href="index.php"><?php echo _MAIN;?></a>: <?php echo _MODIFYCONTENTINFO;?></h4><br />
<table width="100%"><tr>
<td><?php echo _FILEID;?></td>
<td><b><?php echo $lid;?></b></td>
</tr><tr>
<td><?php echo _TITLE.': ';?></td>
<td><input type="text" class="text" name="title" value="<?php echo $title;?>" size="50" maxlength="60" /></td>
</tr><tr>
<td><?php echo _MD_FILETITLETIP;?></td>
<td><input type="text" class="text" name="titletip" value="<?php echo $titletip;?>" size="50" maxlength="255" /></td>
</tr><tr>
<td><?php echo _CATEGORY.':';?></td>
<td><?php $mytree->makeMySelBox("title", "title", $cid);?></td>
</tr><tr>
<td valign="top"><?php echo _DESCRIPTIONC;?></td>
<td>
<?php
echo _MD_PAGEBREAK;
echo "<br /><br />";
$desc = new XoopsFormDhtmlTextArea('', 'filedesc', $description, 10, 50);
echo $desc->render();
?>
</td>
</tr></table>
<hr />
<table width="100%"><tr>
<td valign="top"><?php echo _DOWNLOADURL;?></td>
<td>
<input type="text" class="text" name="url" value="<?php echo $url;?>" size="50" maxlength="255" /> [ <a href="<?php echo formatURL(XOOPS_URL."/modules/mysections/cache/files/", $url);?>><?php echo _DOWNLOAD;?></a> ]
<br />
<?php 
$upload = new Upload();
$upload->printFormField("download");
?>
</td>
</tr><tr>
<td>&nbsp;</td>
<td><?php printf(_FILEUPLOADDESCRIPTION, "modules/mysections/cache/files/");?></td>
</tr><tr>
<td><?php echo _SITEURL;?></td>
<td><input type="text" class="text" name="homepage" value="<?php echo $homepage;?>" size="50" maxlength="255" /></td>
</tr><tr>
<td><?php echo _VERSION.': ';?></td>
<td><input type="text" class="text" name="version" value="<?php echo $version;?>" size="10" maxlength="10" /></td>
</tr><tr>
<td><?php echo _FILESIZE.': ';?></td>
<td><input type="text" class="text" name="size" value="<?php echo $size;?>" size="10" maxlength="10" /> <?php echo _BYTES;?></td>
</tr><tr>
<td><?php echo _PLATFORM.': ';?></td>
<td><input type="text" class="text" name="platform" value="<?php echo $platform;?>" size="45" maxlength="30" /></td>
</tr></table>
<hr />
<table width="100%"><tr>
<td valign="top"><?php echo _SHOTIMAGE;?></td>
<td>
<input type="text" class="text" name="logourl" value="<?php echo $logourl;?>" size="50" maxlength="255" />
<br />
<?php 
$upload->printFormField("image");
?>
</td>
</tr><tr>
<td>&nbsp;</td>
<td><?php printf(_SHOTDESCRIPTION, "modules/mysections/cache/images/shots/");?></td>
</tr></table>
<table width="100%"><tr>
<td>
<input type="hidden" name="lid" value="<?php echo $lid;?>" />
<input type="hidden" name="op" value="modDownloadS" />
<input type="submit" class="button" value="<?php echo _SUBMIT;?>" />
</form>
</td>
<td>
<table><tr>
<td><?php echo myTextForm("index.php?op=delDownload&lid=$lid" , _DELETE);?></td>
<td><?php echo myTextForm("index.php?op=downloadsConfigMenu", _CANCEL);?></td>
</tr></table>
</td>
</tr></table><hr />
<?php
$result5 = $db->query("SELECT COUNT(*) FROM ".$db->prefix("mysections_votedata")."");
list($totalvotes) = $db->getRowsNum($result5);
echo "<table valign='top' width='100%'><tr><td colspan='7'><b>";
printf(_MD_DLRATINGS, $totalvotes);
echo "</b><br /><br /></td></tr>";
// Show Registered Users Votes
$result5 = $db->query("SELECT ratingid, ratinguser, rating, ratinghostname, ratingtimestamp FROM ".$db->prefix("mysections_votedata")." WHERE lid = $lid AND ratinguser != 0 ORDER BY ratingtimestamp DESC");
$votes   = $db->getRowsNum($result5);
echo "<tr><td colspan='7'><br /><br /><b>";
printf(_REGISTEREDUSERSTOTALVOTES, $votes);
echo "
</b><br /><br /></td>
</tr><tr>
<td><b>"._USER."</b></td>
<td><b>"._IPADDRESS."</b></td>
<td><b>"._RATING."</b></td>
<td><b>"._USEAVGRATING."</b></td>
<td><b>"._TOTALRATINGS."</b></td>
<td><b>"._DATE."</b></td>
<td align='center'><b>"._DELETE."</b></td>
</tr>";
if ($votes == 0) {
        echo "<tr><td align='center' colspan='7'>"._NOREGISTEREDUSERVOTES."<br /></td></tr>";
}
$x=0;
$colorswitch = "bg1";
while (list($ratingid, $ratinguser, $rating, $ratinghostname, $ratingtimestamp)=$db->fetchRow($result5)) {
        $formatted_date = formatTimestamp($ratingtimestamp, "s");
        $result2        = $db->query("SELECT rating FROM ".$db->prefix("mysections_votedata")." WHERE ratinguser=$ratinguser");
        $uservotes      = $db->getRowsNum($result2);
        $useravgrating  = 0;
        while (list($rating2) = $db->fetchRow($result2)) {
                $useravgrating = ($useravgrating + $rating2);
        }
        $useravgrating = ($useravgrating / $uservotes);
        $useravgrating = number_format($useravgrating, 1);
        $ratinguname   = XoopsUser::getUnameFromId($ratinguser);
        echo "
        <tr>
        <td class='$colorswitch'>$ratinguname</td>
        <td class='$colorswitch'>$ratinghostname</td>
        <td class='$colorswitch'>$rating</td>
        <td class='$colorswitch'>$useravgrating</td>
        <td class='$colorswitch'>$uservotes</td>
        <td class='$colorswitch'>$formatted_date</td>
        <td class='$colorswitch' align='center'>";
        echo myTextForm("index.php?op=delVote&lid=$lid&rid=$ratingid", "X");
        echo "</td></tr>";
        $x++;
        if ($colorswitch == "bg1") {
                $colorswitch = "bg3";
                } else {
                        $colorswitch = "bg1";
                }
}
// Show Unregistered Users Votes
$result5 = $db->query("SELECT ratingid, rating, ratinghostname, ratingtimestamp FROM ".$db->prefix("mysections_votedata")." WHERE lid = $lid AND ratinguser = 0 ORDER BY ratingtimestamp DESC");
$votes   = $db->getRowsNum($result5);
echo "<tr><td colspan='7'><br /><br /><b>";
printf(_ANONYMOUSUSERTOTALVOTES, $votes);
echo "
</b><br /><br /></td>
</tr><tr>
<td colspan='2'><b>"._IPADDRESS."</b></td>
<td colspan='3'><b>"._RATING."</b></td>
<td><b>"._DATE."</b></b></td>
<td align='center'><b>"._DELETE."</b></td>
</tr>";
if ($votes == 0) {
        echo "<tr><td colspan='7' align='center'>"._NOUNREGISTEREDUSERVOTES."</td></tr>";
}
$x=0;
$colorswitch = "bg1";
while (list($ratingid, $rating, $ratinghostname, $ratingtimestamp) = $db->fetchRow($result5)) {
        $formatted_date = formatTimestamp($ratingtimestamp, "s");
        echo "
        <td colspan='2' class='$colorswitch'>$ratinghostname</td>
        <td colspan='3' class='$colorswitch'>$rating</td>
        <td class='$colorswitch'>$formatted_date</td>
        <td class='$colorswitch' align='center'>";
        echo myTextForm("index.php?op=delVote&lid=$lid&rid=$ratingid", "X");
        echo "</td></tr>";
        $x++;
        if ($colorswitch == "bg1") {
                $colorswitch = "bg3";
                } else {
                        $colorswitch="bg1";
                }
}
echo "<tr><td colspan='6'>&nbsp;</td></tr></table>";
CloseTable();
xoops_cp_footer();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function modDownloadS() {
global $db, $myts, $eh, $_POST, $_FILES,$mysectionsConfig;
$cid         = intval($_POST['cid']);
$lid         = intval($_POST['lid']);
$homepage    = formatURL($myts->makeTboxData4Save($_POST["homepage"]));
$url         = $myts->makeTboxData4Save($_POST["url"]);
$logourl     = $myts->makeTboxData4Save($_POST["logourl"]);
$title       = $myts->makeTboxData4Save($_POST["title"]);
$titletip    = $myts->makeTboxData4Save($_POST["titletip"]);
$version     = $myts->makeTboxData4Save($_POST["version"]);
$platform    = $myts->makeTboxData4Save($_POST["platform"]);
$description = $myts->makeTboxData4Save($_POST["filedesc"]);
$size        = intval($_POST['size']);
// Check if Title is empty
if ( empty($title) ) {
        redirect_header("index.php?op=modDownload&lid=$lid", 3, _EMPTYTITLE);
        exit();
}
// Check if Description is empty
if ( empty($description) ) {
        redirect_header("index.php?op=modDownload&lid=$lid", 3, _EMPTYDESCRIPTION);
        exit();
}
if ( empty($size) || !is_numeric($size) ) {
        $size = 0;
}
if ( !empty($_FILES['download']['name']) || !empty($_FILES['image']['name']) ) {
        
		$upload = new Upload();
		$upload->setAllowedMimeTypes($mysectionsConfig['accepted_files']);
        $upload->setUploadPath(XOOPS_ROOT_PATH.'/modules/mysections/cache/files');
        $upload->setDestinationFileName('download');
		
		if (!empty($_FILES['download']['name'])) {
			$result = $upload->doUpload();
			if ($result) {
				$url  = $upload->HTTP_POST_FILES[$upload->uploadFieldName]['name'];
				$size = $upload->HTTP_POST_FILES[$upload->uploadFieldName]['size'];
			} else {
				$errors = $upload->getUploadErrors();
				$errorstring = "";
				$errorstring .= "<strong>::Errors occured::</strong><br />\n";
				while(list($filename,$values) = each($errors)) {
					$errorstring .= "File: " . $filename . "<br />";
					$count = count($values);
					for($i=0; $i<$count; $i++) { $errorstring .= "==>" . $values[$i] . "<br />"; }
				}
				redirect_header("index.php?op=modDownload&lid=$lid", 3, $errorstring);
				exit();
			}
        }
		
		$upload = new Upload();
		$upload->setAllowedMimeTypes(".gif|.jpeg|.jpg|.png");
        $upload->setUploadPath(XOOPS_ROOT_PATH.'/modules/mysections/cache/shots');
        $upload->setDestinationFileName('image');
		$upload->setFileName($lid);
		
        if ( !empty($_FILES['image']['name']) ) {
			$result = $upload->doUpload();
			if ($result) {
				$logourl = $upload->FileName.".".$upload->getFileExtension();
			} else {
				$errors = $upload->getUploadErrors();
				$errorstring = "";
				$errorstring .= "<strong>::Errors occured::</strong><br />\n";
				while(list($filename,$values) = each($errors)) {
					$errorstring .= "File: " . $filename . "<br />";
					$count = count($values);
					for($i=0; $i<$count; $i++) { $errorstring .= "==>" . $values[$i] . "<br />"; }
				}
				redirect_header("index.php?op=modDownload&lid=$lid", 3, $errorstring);
				exit();
			}
        }
}
// Check if URL is empty
/*if ( empty($url) ) {
        redirect_header("index.php?op=modDownload&lid=$lid", 3, _EMPTYURL);
        exit();
}*/
$sql = "
        UPDATE ".$db->prefix("mysections_articles")." SET
        cid=$cid,
        title='$title',
        titletip='$titletip',
        description='$description',
        url='$url',
        homepage='$homepage',
        version='$version',
        size='$size',
        platform='$platform',
        logourl='$logourl',
        status=2,
        date=".time()."
        WHERE lid=$lid";
$db->query($sql) or $eh->show("0013");
build_rss();
redirect_header("index.php", 1, _UPDATED);
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function approve() {
global $bcoosConfig, $db, $_POST, $myts, $eh;
$lid = intval($_POST['lid']);
$cid = intval($_POST['cid']);
if ( empty($cid) ) {
        $cid = 0;
}
$homepage    = formatURL($myts->makeTboxData4Save($_POST["homepage"]));
$url         = $myts->makeTboxData4Save($_POST["url"]);
$logourl     = $myts->makeTboxData4Save($_POST["logourl"]);
$title       = $myts->makeTboxData4Save($_POST["title"]);
$titletip    = $myts->makeTboxData4Save($_POST["titletip"]);
$version     = $myts->makeTboxData4Save($_POST["version"]);
$size        = $myts->makeTboxData4Save($_POST["size"]);
$platform    = $myts->makeTboxData4Save($_POST["platform"]);
$description = $myts->makeTboxData4Save($_POST["filedesc"]);
$query = "
        UPDATE
        ".$db->prefix("mysections_articles")."
        SET
        cid=$cid,
        title='$title',
        titletip='$titletip',
        description='$description',
        url='$url',
        homepage='$homepage',
        version='$version',
        size='$size',
        platform='$platform',
        logourl='$logourl',
        status=1,
        date=".time()."
        WHERE
        lid=$lid";
$db->query($query) or $eh->show("0013");
$result = $db->query("SELECT submitter FROM ".$db->prefix("mysections_articles")." WHERE lid=$lid");
list($submitter) = $db->fetchRow($result);
$submitter = new XoopsUser($submitter);
$subject   = sprintf(_MD_YOURFILEAT, $bcoosConfig['title']);
$message   = sprintf(_HELLO, $submitter->uname());
$message  .= "\n\n"._APPROVENOTIFY."\n\n";
$siteurl   = XOOPS_URL."/modules/mysections/";
$message  .= sprintf(_VISITUSAT, $siteurl);
$message  .= "\n\n"._THANKSSUBMIT."\n\n".$bcoosConfig['title']."\n".XOOPS_URL."\n".$bcoosConfig['adminmail']."";
$xoopsMailer =& getMailer();
$xoopsMailer->useMail();
$xoopsMailer->setToEmails($submitter->getVar("email"));
$xoopsMailer->setFromEmail($bcoosConfig['adminmail']);
$xoopsMailer->setFromName($bcoosConfig['title']);
$xoopsMailer->setSubject($subject);
$xoopsMailer->setBody($message);
$xoopsMailer->send();
build_rss();
redirect_header("./index.php?op=listNewDownloads", 1, _CONTENTADDED);
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function mysectionsConfigAdmin() {
global $myts, $mysectionsConfig;
xoops_cp_header();
OpenTable();
?>
<h4><a href="index.php"><?php echo _MAIN;?></a>: <?php echo _GENERALSETTINGS;?></h4><br />
<form action="index.php" method="post">
<table width="100%" border="0"><tr>
<td nowrap><?php echo _ITEMSPERPAGE;?></td>
<td width="100%">
<select class="select" name="perpage">
<option value="<?php echo $mysectionsConfig['perpage'];?>" selected="selected"><?php echo $mysectionsConfig['perpage'];?></option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="25">25</option>
<option value="30">30</option>
<option value="50">50</option>
</select>
</td>
</tr><tr>
<td nowrap><?php echo _HITSTOBEPOPULAR;?></td>
<td width="100%">
<select class="select" name="popular">
<option value="<?php echo $mysectionsConfig['popular'];?>" selected="selected"><?php echo $mysectionsConfig['popular'];?></option>
<option value="10">10</option>
<option value="20">20</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="500">500</option>
<option value="1000">1000</option>
</select>
</td>
</tr><tr>
<td nowrap><?php echo _MD_DLSNEW;?></td>
<td width="100%">
<select class="select" name="newdownloads">
<option value="<?php echo $mysectionsConfig['newdownloads'];?>" selected="selected"><?php echo $mysectionsConfig['newdownloads'];?></option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="25">25</option>
<option value="30">30</option>
<option value="50">50</option>
</select>
</td>
</tr><tr>
<?php
$chk1 = ''; $chk0 = '';
($mysectionsConfig['useshots'] == 1) ? $chk1 = " checked='checked'" : $chk0 = " checked='checked'";
?>
<td nowrap><?php echo _USESHOTS;?></td>
<td width="100%">
<input type="radio" class="radio" name="useshots" value="1"<?php echo $chk1;?> /> <?php echo _YES;?>
<input type="radio" class="radio" name="useshots" value="0"<?php echo $chk0;?> /> <?php echo _NO;?>
</td>
</tr>
<?/*
<tr>
<td nowrap><?php echo _SHOTIMAGEWIDTH;?></td>
<td width="100%">
<input type="text" class="text" size="10" name="shotwidth" value="<?php echo $mysectionsConfig['shotwidth'];?>" />
</td>
</tr>
*/?>
<tr>
<?php
$chk1 = ''; $chk0 = '';
($mysectionsConfig['anon_add'] == 1) ? $chk1 = " checked='checked'" : $chk0 = " checked='checked'";
?>
<td nowrap><?php echo _AM_ANON_ADD;?></td>
<td width="100%">
<input type="radio" class="radio" name="anon_add" value="1"<?php echo $chk1;?> /> <?php echo _YES;?>
<input type="radio" class="radio" name="anon_add" value="0"<?php echo $chk0;?> /> <?php echo _NO;?>
</td>
</tr><tr>
<td nowrap><?php echo _MD_NOTIFYSUBMIT;?></td>
<td>
<?php
$chk1 = ""; $chk2 = "";
$chk = ($mysectionsConfig["notifysubmit"] == 1) ?  $chk1 = "checked='checked'" : $chk2 = "checked='checked'";
?>
<input type="radio" class="radio" name="notifysubmit" value="1" <?php echo $chk1;?> /><?php echo _YES;?>
<input type="radio" class="radio" name="notifysubmit" value="0" <?php echo $chk2;?> /><?php echo _NO;?>
</td>
</tr><tr>
<?php
$chk1 = ''; $chk0 = '';
($mysectionsConfig['check_external'] == 1) ? $chk1 = " checked='checked'" : $chk0 = " checked='checked'";
?>
<td nowrap><?php echo _DENYEXTERNALINKAGE;?></td>
<td width="100%">
<input type="radio" class="radio" name="check_external" value="1"<?php echo $chk1;?> /> <?php echo _YES;?>
<input type="radio" class="radio" name="check_external" value="0"<?php echo $chk0;?> /> <?php echo _NO;?>
</td>
</tr><tr>
<td colspan="2"><hr /></td>
</tr><tr>
<?php
$chk1 = ''; $chk0 = '';
($mysectionsConfig['rss_enable'] == 1) ? $chk1 = " checked='checked'" : $chk0 = " checked='checked'";
?>
<td nowrap><?php echo _ENABLEFEEDS;?></td>
<td width="100%">
<input type="radio" class="radio" name="rss_enable" value="1"<?php echo $chk1;?> /> <?php echo _YES;?>
<input type="radio" class="radio" name="rss_enable" value="0"<?php echo $chk0;?> /> <?php echo _NO;?>
</td>
</tr><tr>
<td nowrap><?php echo _FEEDMAXITEMS;?></td>
<td width="100%">
<select class="select" name="rss_maxitems">
<option value="<?php echo $mysectionsConfig['rss_maxitems'];?>" selected="selected"><?php echo $mysectionsConfig['rss_maxitems'];?></option>
<option value="5">5</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="25">25</option>
<option value="30">30</option>
</select>
</td>
</tr><tr>
<td nowrap><?php echo _FEEDMAXDESCRIPTION;?></td>
<td width="100%">
<select class="select" name="rss_maxdescription">
<option value="<?php echo $mysectionsConfig['rss_maxdescription'];?>" selected="selected"><?php echo $mysectionsConfig['rss_maxdescription'];?></option>
<option value="50">50</option>
<option value="100">100</option>
<option value="150">150</option>
<option value="200">200</option>
<option value="250">250</option>
<option value="300">300</option>
</select>
</td>
</tr><tr>
<td colspan="2"><hr /></td>
</tr><tr>
<?php
$chk1 = ''; $chk0 = '';
($mysectionsConfig['allow_upload'] == 1) ? $chk1 = " checked='checked'" : $chk0 = " checked='checked'";
?>
<td nowrap><?php echo _UPLOADENABLE;?></td>
<td width="100%">
<input type="radio" class="radio" name="allow_upload" value="1"<?php echo $chk1;?> /> <?php echo _YES;?>
<input type="radio" class="radio" name="allow_upload" value="0"<?php echo $chk0;?> /> <?php echo _NO;?>
</td>
</tr><tr>
<td nowrap><?php echo _UPLOADACCEPTED;?></td>
<td width="100%">
<input type="text" class="text" size="30" name="accepted_files" value="<?php echo $mysectionsConfig['accepted_files'];?>" />
</td>
</tr><tr>
<td nowrap><?php echo _UPLOADLIMIT;?></td>
<td width="100%">
<input type="text" class="text" size="10" name="upload_limit" value="<?php echo $mysectionsConfig['upload_limit'];?>" /> <?php echo _BYTES;?>
</td>
</tr><tr>
<td colspan="2"><hr /></td>
</tr><tr>
<td valign="top" nowrap><?php echo _AM_INTRO;?></td>
<td width="100%">
<?php
$welcome = join('', file("../cache/welcome.txt"));
$welcome = $myts->makeTboxData4PreviewInForm($welcome);
$desc       = new XoopsFormDhtmlTextArea('', 'welcome', $welcome, 10, 50);
echo $desc->render();
?>
</td>
</tr><tr>
<td colspan="2"><hr /></td>
</tr><tr>
<td valign="top" nowrap><?php echo _AM_DISCLAIMER;?></td>
<td width="100%">
<?php
$disclaimer = join('', file("../cache/disclaimer.txt"));
$disclaimer = $myts->makeTboxData4PreviewInForm($disclaimer);
$desc       = new XoopsFormDhtmlTextArea('', 'disclaimer', $disclaimer, 10, 50);
echo $desc->render();
?>
</td>
</tr><tr>
<td colspan="2"><hr /></td>
</tr><tr>
<td colspan="2">
<input type="hidden" name="op" value="mysectionsConfigChange">
<input type="submit" class="button" value="<?php echo _SAVE;?>">
<input type="button" class="button" value="<?php echo _CANCEL;?>" onclick="javascript:history.go(-1)">
</td>
</tr></table>
</form>
<?php
CloseTable();
xoops_cp_footer();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function mysectionsConfigChange() {
global $_POST, $myts;
$content  = "<?php\n";
$content .= "\$mysectionsConfig['notifysubmit']       = ".intval($_POST['notifysubmit']).";\n";
$content .= "\$mysectionsConfig['popular']            = ".intval($_POST['popular']).";\n";
$content .= "\$mysectionsConfig['newdownloads']       = ".intval($_POST['newdownloads']).";\n";
$content .= "\$mysectionsConfig['perpage']            = ".intval($_POST['perpage']).";\n";
$content .= "\$mysectionsConfig['useshots']           = ".intval($_POST['useshots']).";\n";
$content .= "\$mysectionsConfig['shotwidth']          = ".intval($_POST['shotwidth']).";\n";
$content .= "\$mysectionsConfig['anon_add']           = ".intval($_POST['anon_add']).";\n";
$content .= "\$mysectionsConfig['check_external']     = ".intval($_POST['check_external']).";\n";
$content .= "\$mysectionsConfig['rss_enable']         = ".intval($_POST['rss_enable']).";\n";
$content .= "\$mysectionsConfig['rss_maxitems']       = ".intval($_POST['rss_maxitems']).";\n";
$content .= "\$mysectionsConfig['rss_maxdescription'] = ".intval($_POST['rss_maxdescription']).";\n";
$content .= "\$mysectionsConfig['allow_upload']       = ".intval($_POST['allow_upload']).";\n";
$content .= "\$mysectionsConfig['accepted_files']     = '".$_POST['accepted_files']."';\n";
$content .= "\$mysectionsConfig['upload_limit']       = ".intval($_POST['upload_limit']).";\n";
$content .= "?>";
$filename = "../cache/config.php";
if ( $file = fopen($filename, "w") ) {
        fwrite($file, $content);
        fclose($file);
        } else {
                redirect_header("index.php", 1, _NOTUPDATED);
                exit();
        }
$filename = "../cache/welcome.txt";
if ( $file = fopen($filename, "wb") ) {
        $welcome = $myts->oopsStripSlashesGPC($_POST['welcome']);
        fwrite($file, $welcome);
        fclose($file);
        } else {
                redirect_header("index.php", 1, _NOTUPDATED);
                exit();
        }
$filename = "../cache/disclaimer.txt";
if ( $file = fopen($filename, "wb") ) {
        $disclaimer = $myts->oopsStripSlashesGPC($_POST['disclaimer']);
        fwrite($file, $disclaimer);
        fclose($file);
        } else {
                redirect_header("index.php", 1, _NOTUPDATED);
                exit();
        }
redirect_header("index.php", 1, _UPDATED);
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function build_rss() {
global $db, $mysectionsConfig,$bcoosConfig;
if ($mysectionsConfig['rss_enable'] == 1) {
$SQL= "SELECT title, lid, version, description FROM ".$db->prefix("mysections_articles")." WHERE status !=0 ORDER BY date DESC";
$query = $db->query($SQL, $mysectionsConfig['rss_maxitems']);
	if ($query) {
		$rss = new UniversalFeedCreator();
		$rss->title = $bcoosConfig['title']." :: " . _MI_MYSECTIONS_NAME;
		$rss->link = XOOPS_URL."/modules/mysections/";
		$rss->description = $bcoosConfig['description'];
		
		$image = new FeedImage();
		$image->title = $bcoosConfig['title']." :: " . _MI_MYSECTIONS_NAME;
		$image->url = XOOPS_URL."/images/button.png"; 
		$image->link = XOOPS_URL."/modules/mysections/";
		$image->description = $bcoosConfig['description'];
		
		$rss->image = $image; 
		while ( list($title, $link, $version, $description) = $db->fetchRow($query) ) {
		
			$item = new FeedItem();
			$item->title = $title." - ".$version; 
			$item->link = XOOPS_URL.'/modules/mysections/singlefile.php?lid='.$link;
			$item->description = $description;
			
			$rss->addItem($item); 
		}
		$rsave = $rss->saveFeed("RSS0.91", XOOPS_ROOT_PATH."/modules/mysections/cache/mysections.xml",false);
    }
}
}
//---------------------------------------------------------------------------------------//
$op = !empty($_POST['op']) ? $_POST['op'] : $_GET['op'];
switch($op) {
case "delNewDownload":
        delNewDownload();
        break;
case "approve":
        approve();
        break;
case "addCat":
        addCat();
        break;
case "addSubCat":
        addSubCat();
        break;
case "addDownload":
        addDownload();
        break;
case "listBrokenDownloads":
        listBrokenDownloads();
        break;
case "delBrokenDownloads":
        delBrokenDownloads();
        break;
case "ignoreBrokenDownloads":
        ignoreBrokenDownloads();
        break;
case "listModReq":
        listModReq();
        break;
case "changeModReq":
        changeModReq();
        break;
case "ignoreModReq":
        ignoreModReq();
        break;
case "delCat":
        delCat();
        break;
case "modCat":
        modCat();
        break;
case "modCatS":
        modCatS();
        break;
case "modDownload":
        modDownload();
        break;
case "modDownloadS":
        modDownloadS();
        break;
case "delDownload":
        delDownload();
        break;
case "delVote":
        delVote();
        break;
case "mysectionsConfigAdmin":
        mysectionsConfigAdmin();
        break;
case "mysectionsConfigChange":
        mysectionsConfigChange();
        break;
case "downloadsConfigMenu":
        downloadsConfigMenu();
        break;
case "listNewDownloads":
        listNewDownloads();
        break;
default:
        mysections();
        break;
}
?>