<?php
/*
	Stempora Web Framework
	Copyright (c) 2002-2014 Stempora. 
	All rights reserved.
		web:  www.stempora.com
		mail: support@stempora.com		
*/

// dependencies

/**
* description
*
* @library	
* @author	
* @since	
*/
class CFileList extends CPlugin{
	
	var $tplvars; 

	function CFileList() {
		//$this->CPlugin($db, $tables , $templates);
	}

	function DoEvents(){
		global $base, $_CONF, $_TSM , $_VARS , $_USER , $_BASE , $_SESS;

		parent::DoEvents();

		if ($_GET["mod"] == "filelist") {
			$sub = $_GET["sub"];
			$action = $_GET["action"];

			//read the module
			$this->tpl_module = $this->module->plugins["modules"]->getModuleInfo($_GET["module_id"]);
			$this->plugins["modules"]->ValidateModule($this->tpl_module);

			switch ($sub) {

				case "texts":
					return $this->__adminTexts();
				break;


				case "landing":
				case "items":
					$data = new CSQLAdmin("items", $this->__parent_templates,$this->db,$this->tables,$extra);
					$this->PrepareFields($data->forms["forms"]);
					return $data->DoEvents();
				break;

				case "download":
					return $this->Download();
				break;

			}
		}
	}

	function Download() {

		$file = $this->db->QFetchArray("SELECT * FROM {$this->tables['plugin:filelist_items']} WHERE item_id='%d'" , array($_GET["file"]));

		$mime = new CMime();
		$mime->Set("unknown");
		$mime->Filename($file["item_file_file"]);

		CFile::ReadChunked("../upload/filelist/" . $file["item_id"] . ".file");
		die();

	}


	function adminGetWidgets($module) {

		//$this->tpl_module = $this->module->plugins["modules"]->getModuleInfo($_GET["module_id"]);



		$widgets = array(
			array(
				"type"				=> "1",
				"name"				=> "Download File",
				"module_name"		=> $module["mod_name"],
				"module"			=> $module["mod_id"],
				"module_type"		=> "1",
			),

		);

		return $widgets;

	}


	
	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	function onDelete($module_data) {

		$tables  = array(
			"plugin:filelist_items" , 
			"plugin:filelist_items_lang",
		);

		foreach ($tables as $key => $val) {
			$this->db->Query(
				"DELETE FROM " . $this->tables[$val] . " WHERE module_id={$module_data[mod_id]}"
			);
		}

		parent::onDelete($module_data);	
	}

}

?>