toDB($tmp[1])),'list');
$id = intval($tmp[2]);
$view = intval($tmp[3]);
$order = preg_replace("#\W#", "", $tp -> toDB($tmp[4]));
$sort = preg_replace("#\W#", "", $tp -> toDB($tmp[5]));
}
else
{
$action = preg_replace("#\W#", "", $tp -> toDB($tmp[0]));
$id = intval($tmp[1]);
$errnum = intval(varset($tmp[2],0));
}
switch ($action)
{
case 'list' : // Category-based listing
if (isset($_POST['view'])) extract($_POST);
if (!isset($dl_from)) $dl_from = 0;
// Get category type, page title
if ($sql->db_Select("download_category", "download_category_name,download_category_description,download_category_parent,download_category_class", "(download_category_id='{$id}') AND (download_category_class IN (".USERCLASS_LIST."))") )
{
$row = $sql->db_Fetch();
extract($row);
$type = $download_category_name;
$type .= ($download_category_description) ? " [ ".$download_category_description." ]" : "";
define("e_PAGETITLE", PAGE_NAME." / ".$download_category_name);
}
else
{ // No access to this category
define("e_PAGETITLE", PAGE_NAME);
require_once(HEADERF);
$ns->tablerender(LAN_dl_18, "
".LAN_dl_3."
");
require_once(FOOTERF);
exit;
}
if ($download_category_parent == 0)
{ // It's a main category - change the listing type required
$action = 'maincats';
$maincatval = $id;
}
break;
case 'view' : // Details of individual download
break;
case 'report' :
break;
case 'mirror' :
break;
case 'error' : // Errors passed from request.php
define("e_PAGETITLE", PAGE_NAME);
require_once(HEADERF);
switch ($errnum)
{
case 1 :
$errmsg = LAN_dl_63; // No permissions
break;
case 2 :
$errmsg = LAN_dl_62; // Quota exceeded
break;
default:
$errmsg = LAN_dl_61." ".$errnum; // Generic error - shouldn't happen
}
$ns->tablerender(LAN_dl_61, "".$errmsg."
");
require_once(FOOTERF);
exit;
}
}
if (!isset($order)) $order = varset($pref['download_order'],"download_datestamp");
if (!isset($sort)) $sort = varset($pref['download_sort'], "DESC");
if (!isset($view)) $view = varset($pref['download_view'], "10");
//--------------------------------------------------
// GENERATE DISPLAY TEXT
//--------------------------------------------------
switch ($action)
{ // Displaying main category or categories
case 'maincats' :
require_once(HEADERF);
if ($cacheData = $e107cache->retrieve("download_cat".$maincatval,720)) // expires every 12 hours.
{
echo $cacheData;
require_once(FOOTERF);
exit;
}
// Load the theme
$load_template = 'download_template';
if (!isset($DOWNLOAD_CAT_PARENT_TABLE)) eval($template_load_core);
if(!defined("DL_IMAGESTYLE")){ define("DL_IMAGESTYLE","border:1px solid blue");}
// Read in tree of categories which this user is allowed to see
$dl = new down_cat_handler(varset($pref['download_subsub'],1),USERCLASS_LIST,$maincatval,varset($pref['download_incinfo'],FALSE));
if ($dl->down_count == 0)
{
$ns->tablerender(LAN_dl_18, "".LAN_dl_2."
");
require_once(FOOTERF);
exit;
}
else
{
$download_cat_table_string = ""; // Notice removal
foreach($dl->cat_tree as $row)
{ // Display main category headings, then sub-categories, optionally with sub-sub categories expanded
$download_cat_table_string .= parse_download_cat_parent_table($row);
foreach($row['subcats'] as $crow)
{
$download_cat_table_string .= parse_download_cat_child_table($crow);
}
}
}
$download_cat_table_start = preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_CAT_TABLE_START);
$DOWNLOAD_CAT_NEWDOWNLOAD_TEXT = " ".LAN_dl_36;
$DOWNLOAD_CAT_SEARCH = "
";
$download_cat_table_end = preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_CAT_TABLE_END);
$dl_text = $download_cat_table_start.$download_cat_table_string.$download_cat_table_end;
ob_start();
if(isset($DOWNLOAD_CAT_TABLE_RENDERPLAIN) && $DOWNLOAD_CAT_TABLE_RENDERPLAIN)
{
echo $dl_text;
}
else
{
$ns->tablerender(LAN_dl_18, $dl_text);
}
$cache_data = ob_get_flush();
$e107cache->set("download_cat".$maincatval, $cache_data);
require_once(FOOTERF);
exit;
// Add other 'cases' here
} // End switch ($action)
if (isset($_POST['commentsubmit']))
{
if (!$sql->db_Select("download", "download_comment", "download_id = '{$id}' "))
{
header("location:".e_BASE."index.php");
exit;
}
else
{
$row = $sql->db_Fetch();
if ($row['download_comment'] && (ANON === TRUE || USER === TRUE))
{
$clean_authorname = $_POST['author_name'];
$clean_comment = $_POST['comment'];
$clean_subject = $_POST['subject'];
$cobj->enter_comment($clean_authorname, $clean_comment, "download", $id, $pid, $clean_subject);
// $e107cache->clear("comment.download.{$sub_action}"); $sub_action not used here
$e107cache->clear("comment.download");
}
}
}
//====================================================
// LIST
//====================================================
if ($action == "list")
{
$total_downloads = $sql->db_Count("download", "(*)", "WHERE download_category = '{$id}' AND download_active > 0 AND download_visible REGEXP '".e_CLASS_REGEXP."'");
require_once(HEADERF);
/* SHOW SUBCATS ... */
if($sql -> db_Select("download_category", "download_category_id", "download_category_parent='{$id}' "))
{
/* there are subcats - display them ... */
$qry = "
SELECT dc.*, dc2.download_category_name AS parent_name, dc2.download_category_icon as parent_icon, SUM(d.download_filesize) AS d_size,
COUNT(d.download_id) AS d_count,
MAX(d.download_datestamp) as d_last,
SUM(d.download_requested) as d_requests
FROM #download_category AS dc
LEFT JOIN #download AS d ON dc.download_category_id = d.download_category AND d.download_active > 0 AND d.download_visible IN (".USERCLASS_LIST.")
LEFT JOIN #download_category as dc2 ON dc2.download_category_id='{$id}'
WHERE dc.download_category_class IN (".USERCLASS_LIST.") AND dc.download_category_parent='{$id}'
GROUP by dc.download_category_id ORDER by dc.download_category_order
";
$sql->db_Select_gen($qry);
$scArray = $sql -> db_getList();
$load_template = 'download_template';
if (!isset($DOWNLOAD_CAT_PARENT_TABLE)) eval($template_load_core);
if(!defined("DL_IMAGESTYLE")){ define("DL_IMAGESTYLE","border:1px solid blue");}
foreach($scArray as $row)
{
$download_cat_table_string .= parse_download_cat_child_table($row, FALSE);
}
if(strstr($row['parent_icon'], chr(1))) {
list($download_category_icon, $download_category_icon_empty) = explode(chr(1), $row['parent_icon']);
}
$DOWNLOAD_CAT_MAIN_ICON = ($download_category_icon ? "" : " ");
$DOWNLOAD_CAT_MAIN_NAME = $tp->toHTML($row['parent_name']);
$download_cat_table_start = preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_CAT_TABLE_START);
$DOWNLOAD_CAT_NEWDOWNLOAD_TEXT = " ".LAN_dl_36;
$download_cat_table_end = preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_CAT_TABLE_END);
$text = $download_cat_table_start.$download_cat_table_string.$download_cat_table_end;
if($DOWNLOAD_CAT_TABLE_RENDERPLAIN)
{
echo $text;
}
else
{
$ns->tablerender($type, $text);
}
$text = ""; // If other files, show in a separate block
$type = ""; // Cancel title once displayed
} // End of subcategory display
// Now display individual downloads
$core_total = $sql->db_Count("download WHERE download_category='{$id}' AND download_active > 0 AND download_visible IN (".USERCLASS_LIST.")");
if (!check_class($download_category_class))
{
$ns->tablerender(LAN_dl_18, "".LAN_dl_3."
");
require_once(FOOTERF);
exit;
}
if(strstr($download_category_icon, chr(1)))
{
list($download_category_icon, $download_category_icon_empty) = explode(chr(1), $download_category_icon);
}
$DOWNLOAD_CATEGORY_ICON = ($download_category_icon ? "" : " ");
$DOWNLOAD_CATEGORY = $tp->toHTML($download_category_name,FALSE,"emotes_off, no_make_clickable");
$DOWNLOAD_CATEGORY_DESCRIPTION = $tp -> toHTML($download_category_description, TRUE,'description');
$load_template = 'download_template';
if (!isset($DOWNLOAD_LIST_TABLE)) eval($template_load_core);
if(!defined("DL_IMAGESTYLE")){ define("DL_IMAGESTYLE","border:1px solid blue");}
$gen = new convert;
require_once(e_HANDLER."rate_class.php");
$rater = new rater;
$tdownloads = 0;
$filetotal = $sql->db_Select("download", "*", "download_category='{$id}' AND download_active > 0 AND download_visible IN (".USERCLASS_LIST.") ORDER BY {$order} {$sort} LIMIT {$dl_from}, {$view}");
$ft = ($filetotal < $view ? $filetotal : $view);
while ($row = $sql->db_Fetch()) {
extract($row);
$download_list_table_string .= parse_download_list_table($row);
$tdownloads += $download_requested;
}
$DOWNLOAD_LIST_TOTAL_AMOUNT = $tdownloads." ".LAN_dl_16;
$DOWNLOAD_LIST_TOTAL_FILES = $ft." ".LAN_dl_17;
$download_list_table_start = preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_LIST_TABLE_START);
$download_list_table_end = preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_LIST_TABLE_END);
$text .= $download_list_table_start.$download_list_table_string.$download_list_table_end;
if ($filetotal)
{ // Only show list if some files in it
if($DOWNLOAD_LIST_TABLE_RENDERPLAIN)
{
echo $text;
}
else
{
$ns->tablerender($type, $text);
}
}
if(!isset($DOWNLOAD_LIST_NEXTPREV))
{
$sc_style['DOWNLOAD_LIST_NEXTPREV']['pre'] = "";
$sc_style['DOWNLOAD_LIST_NEXTPREV']['post'] = "
";
$DOWNLOAD_LIST_NEXTPREV = "
{DOWNLOAD_BACK_TO_CATEGORY_LIST}
{DOWNLOAD_LIST_NEXTPREV}
";
}
$nextprev_parms = $total_downloads.",".$view.",".$dl_from.",".e_SELF."?[FROM].list.{$id}.{$view}.{$order}.{$sort}.";
echo $tp->parseTemplate($DOWNLOAD_LIST_NEXTPREV, TRUE, $download_shortcodes);
require_once(FOOTERF);
exit;
} // end of action=="list"
//====================================================
// VIEW
//====================================================
if ($action == "view")
{
$gen = new convert;
$highlight_search = FALSE;
if (isset($_POST['highlight_search'])) {
$highlight_search = TRUE;
}
$query = "
SELECT d.*, dc.* FROM #download AS d
LEFT JOIN #download_category AS dc ON d.download_category = dc.download_category_id
WHERE d.download_id = {$id} AND d.download_active > 0
AND d.download_visible IN (".USERCLASS_LIST.")
AND dc.download_category_class IN (".USERCLASS_LIST.")
LIMIT 1";
if(!$sql -> db_Select_gen($query)){
require_once(HEADERF);
$ns->tablerender(LAN_dl_18, "".LAN_dl_3."
");
require_once(FOOTERF);
exit;
}
$dl = $sql -> db_Fetch();
$load_template = 'download_template';
if (!isset($DOWNLOAD_VIEW_TABLE)) eval($template_load_core);
if(!defined("DL_IMAGESTYLE")){ define("DL_IMAGESTYLE","border:0px");}
if(!isset($DL_VIEW_PAGETITLE))
{
$DL_VIEW_PAGETITLE = PAGE_NAME." / {DOWNLOAD_CATEGORY} / {DOWNLOAD_VIEW_NAME}";
}
$DL_TITLE = $tp->parseTemplate($DL_VIEW_PAGETITLE, TRUE, $download_shortcodes);
define("e_PAGETITLE", $DL_TITLE);
require_once(HEADERF);
$DL_TEMPLATE = $DOWNLOAD_VIEW_TABLE_START.$DOWNLOAD_VIEW_TABLE.$DOWNLOAD_VIEW_TABLE_END;
$text = $tp->parseTemplate($DL_TEMPLATE, TRUE, $download_shortcodes);
if(!isset($DL_VIEW_CAPTION))
{
$DL_VIEW_CAPTION = "{DOWNLOAD_VIEW_CAPTION}";
}
if(!isset($DL_VIEW_NEXTPREV))
{
$DL_VIEW_NEXTPREV = "
{DOWNLOAD_VIEW_PREV} |
{DOWNLOAD_BACK_TO_LIST} |
{DOWNLOAD_VIEW_NEXT} |
";
}
// ------- Next/Prev -----------
$text .= $tp->parseTemplate($DL_VIEW_NEXTPREV,TRUE,$download_shortcodes);
$caption = $tp->parseTemplate($DL_VIEW_CAPTION,TRUE,$download_shortcodes);
if($DOWNLOAD_VIEW_TABLE_RENDERPLAIN) {
echo $text;
} else {
$ns->tablerender($caption, $text);
}
unset($text);
if ($dl['download_comment']) {
$cobj->compose_comment("download", "comment", $id, $width,$dl['download_name'], $showrate=FALSE);
}
require_once(FOOTERF);
exit;
}
//====================================================
// REPORT BROKEN LINKS
//====================================================
if ($action == "report" && check_class($pref['download_reportbroken']))
{
if (!$sql->db_Select("download", "*", "download_id = {$id} AND download_active > 0")) {
require_once(HEADERF);
require_once(FOOTERF);
exit;
}
$row = $sql -> db_Fetch();
extract($row);
if (isset($_POST['report_download'])) {
$report_add = $tp -> toDB($_POST['report_add']);
$download_name = $tp -> toDB($download_name);
$user = USER ? USERNAME : LAN_dl_52;
if ($pref['download_email']) { // this needs to be moved into the NOTIFY, with an event.
require_once(e_HANDLER."mail.php");
$subject = LAN_dl_60." ".SITENAME;
$report = LAN_dl_58." ".SITENAME.":\n".(substr(SITEURL, -1) == "/" ? SITEURL : SITEURL."/")."download.php?view.".$download_id."\n
".LAN_dl_59." ".$user."\n".$report_add;
sendemail(SITEADMINEMAIL, $subject, $report);
}
$sql->db_Insert('generic', "0, 'Broken Download', ".time().",'".USERID."', '{$download_name}', {$id}, '{$report_add}'");
define("e_PAGETITLE", PAGE_NAME." / ".LAN_dl_47);
require_once(HEADERF);
$text = LAN_dl_48."
".LAN_dl_49."tablerender(LAN_dl_50, $text);
} else {
define("e_PAGETITLE", PAGE_NAME." / ".LAN_dl_51." ".$download_name);
require_once(HEADERF);
$text = "