addBreadCrumb(['link' => DOWNLOADS."downloads_admin.php".$aidlink, 'title' => $locale['download_0001']]);
add_to_title($locale['download_0001']);
$allowed_section = ["downloads", "download_form", "download_settings", "download_category", "submissions"];
$_GET['section'] = isset($_GET['section']) && in_array($_GET['section'], $allowed_section) ? $_GET['section'] : 'downloads';
$_GET['download_cat_id'] = isset($_GET['download_cat_id']) && isnum($_GET['download_cat_id']) ? $_GET['download_cat_id'] : 0;
$edit = (isset($_GET['action']) && $_GET['action'] == 'edit') && isset($_GET['download_id']) ? TRUE : FALSE;
$catEdit = isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['cat_id']) ? TRUE : FALSE;
// master template
$tab['title'][] = $locale['download_0000'];
$tab['id'][] = "downloads";
$tab['icon'][] = "fa fa-cloud-download";
$tab['title'][] = $edit ? $locale['download_0003'] : $locale['download_0002'];
$tab['id'][] = "download_form";
$tab['icon'][] = $edit ? "fa fa-pencil" : "fa fa-plus";
$tab['title'][] = $catEdit ? $locale['download_0021'] : $locale['download_0022'];
$tab['id'][] = "download_category";
$tab['icon'][] = $catEdit ? "fa fa-pencil" : "fa fa-folder";
$tab['title'][] = $locale['download_0049']." ".dbcount("(submit_id)", DB_SUBMISSIONS, "submit_type='d'")."";
$tab['id'][] = "submissions";
$tab['icon'][] = "fa fa-inbox";
$tab['title'][] = $locale['download_0006'];
$tab['id'][] = "download_settings";
$tab['icon'][] = "fa fa-cogs";
opentable($locale['download_0001']);
echo opentab($tab, $_GET['section'], "download_admin", TRUE);
switch ($_GET['section']) {
case "download_form":
if (dbcount("('download_cat_id')", DB_DOWNLOAD_CATS, "")) {
include "admin/downloads.php";
} else {
echo "
\n";
echo $locale['download_0251']."
\n".$locale['download_0252']."
\n";
echo "
".$locale['download_0253']."".$locale['download_0254'];
echo "
\n";
}
BreadCrumbs::getInstance()->addBreadCrumb(['link' => FUSION_REQUEST, 'title' => $locale['download_0002']]);
break;
case "download_category":
include "admin/download_cats.php";
BreadCrumbs::getInstance()->addBreadCrumb(['link' => FUSION_REQUEST, 'title' => $locale['download_0022']]);
break;
case "download_settings":
include "admin/download_settings.php";
BreadCrumbs::getInstance()->addBreadCrumb(['link' => FUSION_REQUEST, 'title' => $locale['download_0006']]);
break;
case "submissions":
include "admin/download_submissions.php";
BreadCrumbs::getInstance()->addBreadCrumb(["link" => FUSION_REQUEST, "title" => $locale['download_0049']]);
break;
default:
download_listing();
break;
}
echo closetab();
closetable();
require_once THEMES.'templates/footer.php';
/* Download Listing */
function download_listing() {
$aidlink = fusion_get_aidlink();
$locale = fusion_get_locale();
$limit = 15;
$total_rows = dbcount("(download_id)", DB_DOWNLOADS, "");
$rowstart = isset($_GET['rowstart']) && ($_GET['rowstart'] <= $total_rows) ? $_GET['rowstart'] : 0;
// add a filter browser
$catOpts['all'] = $locale['download_0004'];
$categories = dbquery("select download_cat_id, download_cat_name from ".DB_DOWNLOAD_CATS." ".(multilang_table("DL") ? "WHERE ".in_group('download_cat_language', LANGUAGE) : "")."");
if (dbrows($categories) > 0) {
while ($cat_data = dbarray($categories)) {
$catOpts[$cat_data['download_cat_id']] = $cat_data['download_cat_name'];
}
}
// prevent xss
$catFilter = "";
if (isset($_GET['filter_cid']) && isnum($_GET['filter_cid']) && isset($catOpts[$_GET['filter_cid']])) {
if ($_GET['filter_cid'] > 0) {
$catFilter = "download_cat='".intval($_GET['filter_cid'])."'";
}
}
$langFilter = multilang_table("DL") ? in_group('download_cat_language', LANGUAGE) : "";
if ($catFilter && $langFilter) {
$filter = $catFilter." AND ".$langFilter;
} else {
$filter = $catFilter.$langFilter;
}
$result = dbquery("SELECT d.*, dc.download_cat_id, dc.download_cat_name
FROM ".DB_DOWNLOADS." d
INNER JOIN ".DB_DOWNLOAD_CATS." dc on d.download_cat = dc.download_cat_id
".($filter ? "WHERE $filter " : "")."
ORDER BY d.download_datestamp DESC LIMIT $rowstart, $limit");
$rows = dbrows($result);
echo "\n";
echo "
".sprintf($locale['download_0005'], $rows, $total_rows)."\n";
if (!empty($catOpts) > 0 && $total_rows > 0) {
echo "
\n";
}
if ($total_rows > $rows) {
echo makepagenav($rowstart, $limit, $total_rows, $limit, clean_request("", ["aid", "section"], TRUE)."&");
}
echo "
\n";
echo "\n";
if ($total_rows > $rows) {
echo makepagenav($rowstart, $limit, $total_rows, $limit, clean_request("", ["aid", "section"], TRUE)."&");
}
}