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

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

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

		parent::DoEvents();

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

			//read the module
			$this->tpl_module = $this->module->plugins["modules"]->LoadDefaultModule("redirects");


			switch ($sub) {

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

				case "errors-flush":
					return $this->FlushErrors();
				break;

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

				case "robots":
						$data = new CFormSettings($this->forms_path  . $sub . ".xml" ,$_CONF["forms"]["admintemplate"] , $this->db,$this->tables);

						$this->PrepareDashboard($data->form);

						if ($data->Done()) {
							$this->vars->SetVars(
								$_POST
							);
						}
						return $data->Show($this->vars->data);
				break;


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

					return "1";
					
				break;



			}
		}
	}



	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	function FlushErrors() {
		$this->db->Query("DELETE FROM  {$this->tables['plugin:redirects']} WHERE redirect_type=2");
		urlredirect($_GET["returnURL"]);
	}

}

?>
