From 0894cc944c5147fe2d4fc41db859b73676396b74 Mon Sep 17 00:00:00 2001 From: jhunkeler Date: Fri, 8 Jan 2010 00:56:38 +0000 Subject: Preliminary category based download page git-svn-id: http://svn.3rd-infantry-division.org/testing/branches/Bayonet CMS v2@457 c5b2fb0a-d05d-0410-98c8-828840a80ff6 --- modules/download/index.php | 116 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 93 insertions(+), 23 deletions(-) (limited to 'modules') diff --git a/modules/download/index.php b/modules/download/index.php index 983b6f8..0c0ed2e 100644 --- a/modules/download/index.php +++ b/modules/download/index.php @@ -21,41 +21,111 @@ if(!defined("MODULE_FILE")) { die("Access denied..."); } + +function getCategoryList() +{ + global $db; + $query = sprintf("SELECT category_id, title FROM bayonet_downloads_categories"); + $result = $db->Query($query); + $categories = $db->Fetch($result); + + return $categories; +} + +function getCategoryName($category) +{ + global $db; + if(!filter_var($category, FILTER_VALIDATE_INT)) + return array(); + + $query = sprintf("SELECT category_id, title FROM bayonet_downloads_categories WHERE category_id = %d", (int)$category); + $result = $db->Query($query); + $data = $db->FetchRow($result); + + return $data['title']; + //return is_array($data) ? $data : array(); +} + +function getCategoryFiles($category) +{ + global $db; + $query = sprintf("SELECT ca.category_id, ca.title AS category, dl.name, dl.filename, dl.description FROM bayonet_downloads_categories AS ca LEFT OUTER JOIN bayonet_downloads AS dl ON dl.category_id = ca.category_id WHERE ca.category_id = %d", (int)$category); + + $result = $db->Query($query); + $downloads = $db->FetchArray($result); + decho('downloads data'); + decho($downloads); + decho('downloads data done'); + + return $downloads; +} + global $db; -$download = NULL; +$downloads = NULL; $download_relative_path = "modules/" . basename(dirname(__FILE__)) . "/files/"; $download_absolute_path = dirname(__FILE__) . "/files/"; -$download = $db->Query("SELECT `file_id`, `name`, `description`, `filename` FROM `bayonet_downloads`"); +$category = $_GET['category']; +if(isset($category) && !filter_var($category, FILTER_VALIDATE_INT)) +{ + ReportHack("Purposely invalid category entry."); + return; +} + +$downloads = getCategoryFiles($category); +decho($downloads); OpenContent(); -echo "
Downloads
"; -echo "
"; -foreach($download as $file) -{ - $download_full_path = $download_absolute_path . $file['filename']; - - if(file_exists($download_full_path)) +echo "
Categories
\n"; +echo "
\n"; + +$categoryList = getCategoryList(); + + foreach($categoryList as $categoryListItem) { echo "

"; - echo LinkInternal($file['name'], $file['filename'], $download_relative_path) . "
\n"; - echo "Filename: {$file['filename']}
\n"; - printf("Size: %.2fKB
\n", filesize($download_full_path) / 1024); - echo "MD5 Hash: " . md5_file($download_full_path) . "
\n"; - echo "Description: {$file['description']}
\n"; - echo "

"; - } - else - { - decho("File $download_absolute_path{$file['filename']} does not exist! Not listing for download."); + echo LinkModule("download", "&category={$categoryListItem['category_id']}",$categoryListItem['title']); + echo "

\n"; } -} -decho($download); -//logQueueFlush(FORCE); -echo "
"; +echo "
\n\n"; CloseContent(); +OpenContent(); +echo "
" . getCategoryName($category) . "
\n"; +echo "
\n"; + + OpenContent(); + echo "
Files
\n"; + echo "
\n"; + + if(empty($downloads)) + { + echo "No downloads available.\n"; + return; + } + + foreach($downloads as $file) + { + $download_full_path = $download_absolute_path . $file['filename']; + + if(!file_exists($download_full_path)) $broken = "(Broken link detected)"; + echo "

"; + echo LinkInternal($file['name'], $file['filename'], $download_relative_path) . " $broken
\n"; + echo "Filename: {$file['filename']}
\n"; + printf("Size: %.2fKB
\n", filesize($download_full_path) / 1024); + echo "MD5 Hash: " . md5_file($download_full_path) . "
\n"; + echo "Description: {$file['description']}
\n"; + echo "

"; + + } + //logQueueFlush(FORCE); + + echo "
\n
"; + echo "\n"; + + CloseContent(); +CloseContent(); ?> -- cgit