<?php
/*
+ ----------------------------------------------------------------------------+
|     e107 website system
|
|     ©Steve Dunstan 2001-2002
|     http://e107.org
|     jalist@e107.org
|
|     Released under the terms and conditions of the
|     GNU General Public License (http://gnu.org).
|
|     $Source: /cvs_backup/e107_0.8/e107_plugins/download/e_list.php,v $
|     $Revision: 1.1 $
|     $Date: 2009-05-04 19:57:23 $
|     $Author: bugrain $
|
+----------------------------------------------------------------------------+
*/
if (!defined('e107_INIT')) { exit; }

class list_download
{
	function list_download($parent)
	{
		$this->parent = $parent;
	}

	function getListData()
	{
		$list_caption = $this->parent->settings['caption'];
		$list_display = ($this->parent->settings['open'] ? "" : "none");

		if($this->parent->mode == "new_page" || $this->parent->mode == "new_menu" )
		{
			$qry = " AND download_datestamp>".$this->parent->getlvisit();
		}
		else
		{
			$qry = '';
		}

		$bullet = $this->parent->getBullet($this->parent->settings['icon']);

		$qry = "SELECT d.download_id, d.download_name, d.download_author, d.download_datestamp,
		   dc.download_category_id, dc.download_category_name, dc.download_category_class
		   FROM #download AS d
		   LEFT JOIN #download_category AS dc ON d.download_category=dc.download_category_id
		   WHERE dc.download_category_class REGEXP '".e_CLASS_REGEXP."' AND d.download_class REGEXP '".e_CLASS_REGEXP."' AND d.download_active != '0' ".$qry."
		   ORDER BY download_datestamp DESC LIMIT 0,".intval($this->parent->settings['amount'])." ";

		$downloads = $this->parent->e107->sql->db_Select_gen($qry);
		if($downloads == 0)
		{
			$list_data = LIST_DOWNLOAD_2;
		}
		else
		{
			$list_data = array();
			while($row = $this->parent->e107->sql->db_Fetch())
			{
				$record = array();
				$rowheading = $this->parent->parse_heading($row['download_name']);
				$record['icon'] = $bullet;
				$record['heading'] = "<a href='".e_BASE."download.php?view.".$row['download_id']."'>".$rowheading."</a>";
				$record['author'] = (varsettrue($this->parent->settings['author']) ? $row['download_author'] : "");
				$record['category'] = (varsettrue($this->parent->settings['category']) ? "<a href='".e_BASE."download.php?list.".$row['download_category_id']."'>".$row['download_category_name']."</a>" : "");
				$record['date'] = (varsettrue($this->parent->settings['date']) ? $this->parent->getListDate($row['download_datestamp']) : "");
				$record['info'] = "";

				$list_data[] = $record;
			}
		}
		//return array with 'records', (global)'caption', 'display'
		return array(
			'records'=>$list_data,
			'caption'=>$list_caption,
			'display'=>$list_display
		);
	}
}
?>