<?php
/*
	DevSaver web framework
	copyright (c) 2013-2013 DevSaver
		web:  www.oxylus.ro
		mail: support@oxylus.ro		

	$Id: name.php,v 0.0.1 dd/mm/yyyy hh:mm:ss oxylus Exp $
	description
*/

// dependencies

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

	function __construct() {
		//$this->CPlugin($db, $tables , $templates);
		$this->name = "popups";
	}

	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 = "items";

				case "items":					
				case "logs":					
					$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;

				case "reset":
					return $this->ResetCapping();
				break;

			}
		}
	}

	


	function ShortcodesBrowser() {
		global $_LANG_ID , $base;

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

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

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

				$tmp = explode("," , $val["popup_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"				=> "Pop-ups",//$this->tpl_module["module_name"] , 
			"html"				=> $base->html->Table(
				$tpl, 
				"" , 
				$items
			)
		);
		
	}

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


	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	function ResetCapping() {

		$this->db->QueryUpdate(
			$this->tables["plugin:popups"],
			array(
				"popup_code"	=> md5(time()),
			),
			"popup_id={$_GET[popup_id]}"
		);

		urlredirect($_GET["returnURL"]);
	}
	
}

?>