<?php
/*
	DevSaver Web Framework
	Copyright (c) 2013-2016 DevSaver. 
	All rights reserved.
		web:  www.devsaver.com
		mail: support@devsaver.com				
*/


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

	function __construct() {
		parent::__construct();
		$this->name = "banners";
	}


	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	function DoEvents(){
		global $base, $_CONF, $_TSM , $_VARS , $_USER , $_BASE , $_SESS;


		if ($_GET["mod"] == $this->name) {

			$this->tpl_module = $this->module->plugins["modules"]->LoadDefaultModule($this->name);

			parent::DoEvents();

			$sub = $_GET["sub"];
			$action = $_GET["action"];

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

				case "flush":
					return $this->FlushStats();
				break;
			}
		}
	}

	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	function __init() {
		global $_CONF;

		if ($this->__inited) {
			return "";
		}

		$this->__inited = true;
		
		$path = $this->tpl_path;

		$templates = array(
		);

		if (count($templates)) {
			foreach ($templates as $key => $val) {
				$this->private->templates[$key] = new CTemplateDynamic(
					$path . $val 
				);
			}
		}
	} 


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

		$this->tpl_module = $this->module->plugins["modules"]->LoadDefaultModule("banners");

		$items = $this->db->QFetchRowArray(
			"SELECT * FROM 
				{$this->tables['plugin:banners_cats']}
			ORDER BY cat_label ASC
			"
		);

		if (is_array($items)) {
			foreach ($items as $key => $val) {
				$items[$key]["cnt"] = ++$cnt;

				$tmp = explode("," , $val["cat_device"]);
				$data = null;


				if (in_array("1" , $tmp))
					$data[] = '<span class="f16 sign sign-desktop"></span>';

				if (in_array("2" , $tmp))
					$data[] = '<span class="f16 sign sign-tablet"></span>';

				if (in_array("3" , $tmp))
					$data[] = '<span class="f16 sign sign-mobile"></span>';

				
				if (is_Array($data)) {
					$items[$key]["devices"] = implode(", " , $data);
				} else {
					$items[$key]["devices"] = "";
				}

			}
			
		}

	

		$tpl = new CTEmplateDynamic($this->tpl_path . "admin.shortcodes.htm");

		return array(
			"title"				=> $this->tpl_module["module_name"] , 
			"html"				=> $base->html->Table(
				$tpl, 
				"" , 
				$items
			)
		);			
	}


	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/

	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	function FlushStats() {
		$this->db->Query("DELETE FROM  {$this->tables['plugin:banners_log']}");
		urlredirect($_GET["returnURL"]);
	}
	
}


?>