<?php
namespace PHPMaker2020\project2;

/**
 * Class for index
 */
class index
{

	// Project ID
	public $ProjectID = "{AA140015-983A-47F7-B2DB-866F9851A082}";

	// Messages
	private $_message = "";
	private $_failureMessage = "";
	private $_successMessage = "";
	private $_warningMessage = "";

	// Get message
	public function getMessage()
	{
		return isset($_SESSION[SESSION_MESSAGE]) ? $_SESSION[SESSION_MESSAGE] : $this->_message;
	}

	// Set message
	public function setMessage($v)
	{
		AddMessage($this->_message, $v);
		$_SESSION[SESSION_MESSAGE] = $this->_message;
	}

	// Get failure message
	public function getFailureMessage()
	{
		return isset($_SESSION[SESSION_FAILURE_MESSAGE]) ? $_SESSION[SESSION_FAILURE_MESSAGE] : $this->_failureMessage;
	}

	// Set failure message
	public function setFailureMessage($v)
	{
		AddMessage($this->_failureMessage, $v);
		$_SESSION[SESSION_FAILURE_MESSAGE] = $this->_failureMessage;
	}

	// Get success message
	public function getSuccessMessage()
	{
		return isset($_SESSION[SESSION_SUCCESS_MESSAGE]) ? $_SESSION[SESSION_SUCCESS_MESSAGE] : $this->_successMessage;
	}

	// Set success message
	public function setSuccessMessage($v)
	{
		AddMessage($this->_successMessage, $v);
		$_SESSION[SESSION_SUCCESS_MESSAGE] = $this->_successMessage;
	}

	// Get warning message
	public function getWarningMessage()
	{
		return isset($_SESSION[SESSION_WARNING_MESSAGE]) ? $_SESSION[SESSION_WARNING_MESSAGE] : $this->_warningMessage;
	}

	// Set warning message
	public function setWarningMessage($v)
	{
		AddMessage($this->_warningMessage, $v);
		$_SESSION[SESSION_WARNING_MESSAGE] = $this->_warningMessage;
	}

	// Clear message
	public function clearMessage()
	{
		$this->_message = "";
		$_SESSION[SESSION_MESSAGE] = "";
	}

	// Clear failure message
	public function clearFailureMessage()
	{
		$this->_failureMessage = "";
		$_SESSION[SESSION_FAILURE_MESSAGE] = "";
	}

	// Clear success message
	public function clearSuccessMessage()
	{
		$this->_successMessage = "";
		$_SESSION[SESSION_SUCCESS_MESSAGE] = "";
	}

	// Clear warning message
	public function clearWarningMessage()
	{
		$this->_warningMessage = "";
		$_SESSION[SESSION_WARNING_MESSAGE] = "";
	}

	// Clear messages
	public function clearMessages()
	{
		$this->clearMessage();
		$this->clearFailureMessage();
		$this->clearSuccessMessage();
		$this->clearWarningMessage();
	}

	// Show message
	public function showMessage()
	{
		$hidden = TRUE;
		$html = "";

		// Message
		$message = $this->getMessage();
		if (method_exists($this, "Message_Showing"))
			$this->Message_Showing($message, "");
		if ($message != "") { // Message in Session, display
			if (!$hidden)
				$message = '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' . $message;
			$html .= '<div class="alert alert-info alert-dismissible ew-info"><i class="icon fas fa-info"></i>' . $message . '</div>';
			$_SESSION[SESSION_MESSAGE] = ""; // Clear message in Session
		}

		// Warning message
		$warningMessage = $this->getWarningMessage();
		if (method_exists($this, "Message_Showing"))
			$this->Message_Showing($warningMessage, "warning");
		if ($warningMessage != "") { // Message in Session, display
			if (!$hidden)
				$warningMessage = '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' . $warningMessage;
			$html .= '<div class="alert alert-warning alert-dismissible ew-warning"><i class="icon fas fa-exclamation"></i>' . $warningMessage . '</div>';
			$_SESSION[SESSION_WARNING_MESSAGE] = ""; // Clear message in Session
		}

		// Success message
		$successMessage = $this->getSuccessMessage();
		if (method_exists($this, "Message_Showing"))
			$this->Message_Showing($successMessage, "success");
		if ($successMessage != "") { // Message in Session, display
			if (!$hidden)
				$successMessage = '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' . $successMessage;
			$html .= '<div class="alert alert-success alert-dismissible ew-success"><i class="icon fas fa-check"></i>' . $successMessage . '</div>';
			$_SESSION[SESSION_SUCCESS_MESSAGE] = ""; // Clear message in Session
		}

		// Failure message
		$errorMessage = $this->getFailureMessage();
		if (method_exists($this, "Message_Showing"))
			$this->Message_Showing($errorMessage, "failure");
		if ($errorMessage != "") { // Message in Session, display
			if (!$hidden)
				$errorMessage = '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' . $errorMessage;
			$html .= '<div class="alert alert-danger alert-dismissible ew-error"><i class="icon fas fa-ban"></i>' . $errorMessage . '</div>';
			$_SESSION[SESSION_FAILURE_MESSAGE] = ""; // Clear message in Session
		}
		echo '<div class="ew-message-dialog' . (($hidden) ? ' d-none' : "") . '">' . $html . '</div>';
	}

	// Get message as array
	public function getMessages()
	{
		$ar = [];

		// Message
		$message = $this->getMessage();

		//if (method_exists($this, "Message_Showing"))
		//	$this->Message_Showing($message, "");

		if ($message != "") { // Message in Session, display
			$ar["message"] = $message;
			$_SESSION[SESSION_MESSAGE] = ""; // Clear message in Session
		}

		// Warning message
		$warningMessage = $this->getWarningMessage();

		//if (method_exists($this, "Message_Showing"))
		//	$this->Message_Showing($warningMessage, "warning");

		if ($warningMessage != "") { // Message in Session, display
			$ar["warningMessage"] = $warningMessage;
			$_SESSION[SESSION_WARNING_MESSAGE] = ""; // Clear message in Session
		}

		// Success message
		$successMessage = $this->getSuccessMessage();

		//if (method_exists($this, "Message_Showing"))
		//	$this->Message_Showing($successMessage, "success");

		if ($successMessage != "") { // Message in Session, display
			$ar["successMessage"] = $successMessage;
			$_SESSION[SESSION_SUCCESS_MESSAGE] = ""; // Clear message in Session
		}

		// Failure message
		$failureMessage = $this->getFailureMessage();

		//if (method_exists($this, "Message_Showing"))
		//	$this->Message_Showing($failureMessage, "failure");

		if ($failureMessage != "") { // Message in Session, display
			$ar["failureMessage"] = $failureMessage;
			$_SESSION[SESSION_FAILURE_MESSAGE] = ""; // Clear message in Session
		}
		return $ar;
	}

	// Token
	public $Token = "";
	public $TokenTimeout = 0;
	public $CheckToken;

	// Constructor
	public function __construct() {
		$this->CheckToken = Config("CHECK_TOKEN");
	}

	// Terminate page
	public function terminate($url = "")
	{

		// Page Unload event
		$this->Page_Unload();

		// Global Page Unloaded event (in userfn*.php)
		Page_Unloaded();

		// Page Redirecting event
		$this->Page_Redirecting($url);

		// Go to URL if specified
		if ($url != "") {
			SaveDebugMessage();
			AddHeader("Location", $url);
		}
		exit();
	}

	//
	// Page run
	//

	public function run()
	{
		global $Language, $UserProfile, $Security, $Breadcrumb;

		// Global Page Loading event (in userfn*.php)
		Page_Loading();

		// Page Load event
		$this->Page_Load();

		// Initialize
		$GLOBALS["Page"] = &$this;
		$this->TokenTimeout = SessionTimeoutTime();

		// Language object
		if (!isset($Language))
			$Language = new Language();

		// Start timer
		if (!isset($GLOBALS["DebugTimer"]))
			$GLOBALS["DebugTimer"] = new Timer();

		// User profile
		$UserProfile = new UserProfile();

		// Security object
		$Security = new AdvancedSecurity();
		if (!$Security->isLoggedIn())
			$Security->autoLogin();
		$Security->loadUserLevel(); // Load User Level

		// Breadcrumb
		$Breadcrumb = new Breadcrumb();

		// If session expired, show session expired message
		if (Get("expired") == "1")
			$this->setFailureMessage($Language->phrase("SessionExpired"));
		if (!$Security->isLoggedIn())
			$Security->autoLogin();
		if ($Security->isLoggedIn())
			$this->terminate("adminlist.php"); // Exit and go to default page
		if ($Security->isLoggedIn())
			$this->terminate("bkp_master_articuloslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("categorieslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("clienteslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("comentariolist.php");
		if ($Security->isLoggedIn())
			$this->terminate("courseslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("cuotalist.php");
		if ($Security->isLoggedIn())
			$this->terminate("detalle_cuotalist.php");
		if ($Security->isLoggedIn())
			$this->terminate("detalle_proyectolist.php");
		if ($Security->isLoggedIn())
			$this->terminate("estadoslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("imagenes_inmueblelist.php");
		if ($Security->isLoggedIn())
			$this->terminate("interesadoslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("interestedlist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_accesos_empresaslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_categorialist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_categorias_articuloslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_citaslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_clienteslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_codbarraslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_comentariolist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_disciplinalist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_empresaslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_horarioslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_lab_otlist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_lab_ot_detlist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_logslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_master_empresaslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_moduloslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_modulos_estadolist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_modulos_gruposlist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_ordeneslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_ordenes_detlist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_pagolist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_perfileslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_permisolist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_proveedoreslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_proyectolist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_tablaweblist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_ubigeoslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_ubigeos_distlist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_ubigeos_dptolist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_ubigeos_provlist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kp_usuarioslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("kt_driver_tasklist.php");
		if ($Security->isLoggedIn())
			$this->terminate("loteslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("paislist.php");
		if ($Security->isLoggedIn())
			$this->terminate("parametro_productolist.php");
		if ($Security->isLoggedIn())
			$this->terminate("procesos_nuevolist.php");
		if ($Security->isLoggedIn())
			$this->terminate("productslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("ubigeo_paislist.php");
		if ($Security->isLoggedIn())
			$this->terminate("ubigeo_peru_departmentslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("ubigeo_peru_districtslist.php");
		if ($Security->isLoggedIn())
			$this->terminate("ubigeo_peru_provinceslist.php");
		if ($Security->isLoggedIn()) {
			$this->setFailureMessage(DeniedMessage() . "<br><br><a href=\"logout.php\">" . $Language->phrase("BackToLogin") . "</a>");
		} else {
			$this->terminate("login.php"); // Exit and go to login page
		}
	}

	// Page Load event
	function Page_Load() {

		//echo "Page Load";
	}

	// Page Unload event
	function Page_Unload() {

		//echo "Page Unload";
	}

	// Page Redirecting event
	function Page_Redirecting(&$url) {

		// Example:
		//$url = "your URL";

	}

	// Message Showing event
	// $type = ''|'success'|'failure'
	function Message_Showing(&$msg, $type) {

		// Example:
		//if ($type == 'success') $msg = "your success message";

	}
}
?>