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

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

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

		parent::DoEvents();

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

			//$this->__install();

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

			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 "browser":
					return $this->Browser();
				break;

			}
		}
	}



	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	function Browser() {
		global $base;
		
		$tpl = new CTemplateDynamic($this->tpl_path . "codes.htm");

		$items = $this->db->QFetchRowArray("SELECT * FROM {$this->tables['plugin:shortcodes']}");

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

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


				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-phone"></span>';

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

		if (is_array($this->module->plugins)) {
			foreach ($this->module->plugins as $key => $val) {

				if (method_exists($this->module->plugins[$key] , "shortcodesBrowser")) {
					$shortcodes[] = $this->module->plugins[$key]->shortcodesBrowser();												
				}
				
			}			
		}

		$cnt = 1;
		if (is_array($shortcodes)) {
			foreach ($shortcodes as $key => $val) {
				$shortcodes[$key]["code"] = ++$cnt;
			}			
		}

		echo $tpl->blockReplace(
			"Main" , 
			array(
				"manual"	=> $base->html->Table(
					$tpl , 
					"" , 
					$items
				),

				"shortcodes_titles"	=> is_array($shortcodes) ? $base->html->Table(
					$tpl , 
					"Titles",
					$shortcodes
				) : "",

				"shortcodes_content"	=> is_array($shortcodes) ? $base->html->Table(
					$tpl , 
					"Content",
					$shortcodes
				) : ""

			)
		);

		die();
	}
	
}

?>