<?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 CComments extends CPlugin{
	
	var $tplvars; 

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

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

		parent::DoEvents();

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

			//read the module
			$this->tpl_module = $this->module->plugins["modules"]->LoadDefaultModule("comments");
			
			switch ($sub) {
				case "landing":
					$data = new CSQLAdmin($sub, $this->__parent_templates,$this->db,$this->tables,$extra);
					$this->PrepareFields($data->forms["forms"]);
					return $data->DoEvents();
				break;

				case "settings":
					urlredirect("index.php?mod=modules&sub=default&action=details&module_id={$this->tpl_module[module_id]}&t=u");
				break;

				case "action.delete":
					if (is_array($_POST["comment_id"])) {
						$this->db->Query(
							"DELETE FROM {$this->tables['plugin:comments']} WHERE comment_id IN (" . implode("," , $_POST["comment_id"]). ")"
						);
					}

					return "1";
					
				break;

				case "action.approve":
					if (is_array($_POST["comment_id"])) {
						$this->db->Query(
							"UPDATE {$this->tables['plugin:comments']} SET comment_status=2 WHERE comment_id IN (" . implode("," , $_POST["comment_id"]). ")"
						);
					}

					return "1";
					
				break;

			}
		}
	}


	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	function DashboardWidgets() {
		global $base , $_CONF;

		$module = $this->module->plugins["modules"]->LoadDefaultModule("comments");
		$_CONF["forms"]["adminpath"] = _MODPATH . "comments/forms/";
		$latest = new CSQLAdmin("dashboard/latest", $this->__parent_templates,$this->db,$this->tables,$extra);
		$content = $latest->DoEvents();
		if (!(stristr($content , "No available records."))) {
			return array(
				array(
					"width"	=> "6",
					"type"	=> "widget",
					"pos"	=> "1",
					"body"	=> $content
				),
			);
		}
	}


}

?>