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

if (!defined("STPBase")) {
	die("This file can't be accessed directly!");
}
// dependencies

/**
* description
*
* @library	
* @author	
* @since	
*/
class CStatusQuo extends CPlugin{

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

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

		if ($_GET["mod"] == "statusquo") {

			$this->__init();

			switch ($_GET["sub"]) {
				case "ping":
					return $this->Pong();
				break;

				case "token-set":
					return $this->TokenSet();
				break;

				case "token-get":
					return $this->TokenGet();
				break;

			}
		}		
	}


	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	function Pong() {
		echo $this->plugins["common"]->Json(array("ping" => "pong"));
		die();
	}

	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	function TokenSet() {
		global $_PAGE; 

		CFile::Save("upload/tmp/statusquo.token" , md5($_GET["token"]));		

		//redirect to a 404 page so no robot can get the confirmation this page actualy exists
		$_PAGE = "shared";
		return $this->module->plugins["redirects"]->ErrorPage("404" , true , false);		
	}

	/**
	* description
	*
	* @param
	*
	* @return
	*
	* @access
	*/
	function TokenGet() {
		global $_PAGE; 

		$token = CFile::Get("upload/tmp/statusquo.token");		

		if ($token == $_GET["token"]) {
			echo $this->plugins["common"]->Json(array("token" => $token));
			die();
		}

		//redirect to a 404 page so no robot can get the confirmation this page actualy exists
		$_PAGE = "shared";
		return $this->module->plugins["redirects"]->ErrorPage("404" , true , false);		
	}
	
	
}