- <?php
- /*
- * Lokorin.com
- * Copyright 2004-2006
- * Licensed under the GNU LGPL. See COPYING for full terms.
- */
- /**
- * A project module that displays all download items connected to a project.
- * @author Andreas Launila
- * @version $Revision: 1.11 $
- * @package com.lokorin.lokorin.modules
- * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
- */
-
- /**
- * For access to common constants and functions.
- */
- require_once('common.php');
- doInclude('lib_projects');
- doInclude('lib_downloads');
- doInclude('lib_tables');
-
- //Check if anything should be downloaded.
- if(isset($_GET['id']) && is_numeric($_GET['id'])) {
- //Attempt to download the download item with the corresponding unique
- //identifier.
- try {
- $downloadItem = new DownloadItem($_GET['id']);
- $downloadItem->download();
- } catch(Exception $e) {
- logException(new IllegalArgumentException('An invalid download item ' .
- 'with id ('.$_GET['id'].') was requested.'));
- die('Invalid download.');
- }
- exit;
- }
-
- Page::getInstance()->setTitle('Download');
- try {
- $project = getProjectBasedOnDir();
- Page::getInstance()->setProject($project);
- } catch(Exception $e) {
- logFatalException($e);
- }
-
- //Display the actual downloads.
- $groupedDownloads = $project->getDownloadsGroupedByCategory();
- if(count($groupedDownloads) > 0) {
- $firstHeader = new Header(array('Name', 'Description', 'Size', 'Link', 'Language'));
- $restHeader = new Header(array('Name', 'Size', 'Link', 'Language'));
- $isFirstTable = true;
-
- foreach($groupedDownloads as $categoryId => $downloads) {
- try {
- $category = new DownloadCategory($categoryId);
- } catch(IllegalArgumentException $e) {
- logException(IllegalStateException("Illegal category id (".
- $categoryId.") specified."));
- continue;
- }
-
- $downloads = sortDownloadsByPopularity($downloads);
- $table = new Table();
- if($isFirstTable) {
- $table->setHeader($firstHeader);
- } else {
- $table->setHeader($restHeader);
- }
- foreach($downloads as $download) {
- $row = array();
- $row[] = $download->getName();
- if($isFirstTable){
- //Only display the description for the first table.
- $row[] = $download->getDescription();
- }
- $row[] = $download->getSizeLabel();
- $row[] = '<a href="'.SELF.'?id='.$download->getId().'">Download</a>';
- $lang = $download->getLanguage();
- $row[] = $lang->getLink();
- $table->addRow($row);
- }
-
- if(!$isFirstTable) {
- //Don't display the caption for the first table.
- echo '<h2>'.$category->getName().'</h2>';
- } else {
- $isFirstTable = false;
- }
- echo $table->getTable();
- }
- } else {
- echo 'No downloads were found.';
- }
-
- Page::getInstance()->display();
- ?>