<?php
class eventsBase
{
	var $events = array();
	var $maps = array();
	function exists($event, $table = "")
	{
		if($table == "")
			return (array_key_exists($event,$this->events)!==FALSE);
		else
			return isset($this->events[$event]) && isset($this->events[$event][$table]);
	}

	function existsMap($page)
	{
		return (array_key_exists($page,$this->maps)!==FALSE);
	}
}

class class_GlobalEvents extends eventsBase
{
	function __construct()
	{
	// fill list of events
		$this->events["AfterSuccessfulLogin"]=true;

		$this->events["AfterUnsuccessfulLogin"]=true;

		$this->events["AfterLogout"]=true;

		$this->events["BeforeLogin"]=true;

		$this->events["BeforeShowMenu"]=true;

		$this->events["ModifyMenuItem"]=true;


//	onscreen events
		$this->events["ac_snippet"] = true;



		}

//	handlers

		
		
		
		
		
		
				// After successful login
function AfterSuccessfulLogin($username, $password, &$data, &$pageObject)
{

		

// Place event code here.
// Use "Add Action" button to add code snippets.

$_SESSION["user_name"]=$username ;
$_SESSION["disc"]=$data["ac_discount"] ;
$_SESSION["parts_discount"]=$data["parts_discount"] ;

$_SESSION["user_role"]=$data["role"] ;



//  HOW  TO  WRITE  INTO  TXT  FILE
//$myfile = fopen("1  log_file.txt", "w") or die("Unable to open file!");
//fwrite($myfile, "discount = ".$_SESSION["disc"]." \n");
//fwrite($myfile, "DONE  \n");
//fclose($myfile);

;		
} // function AfterSuccessfulLogin

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
				// After unsuccessful login
function AfterUnsuccessfulLogin($username, $password, &$message, &$pageObject, &$userdata)
{

		

// Place event code here.
// Use "Add Action" button to add code snippets.

$_SESSION["user_name"]="";
$_SESSION["disc"]=1 ;
$_SESSION["parts_discount"]=1 ;
$_SESSION["user_role"]="";
;		
} // function AfterUnsuccessfulLogin

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
				// After Logout
function AfterLogout($username)
{

		

// Place event code here.
// Use "Add Action" button to add code snippets.

$_SESSION["user_name"] = "" ;
$_SESSION["disc"] = 1 ;
$_SESSION["parts_discount"] = 1 ;
$_SESSION["user_role"]="";
;		
} // function AfterLogout

		
		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
				// Before login
function BeforeLogin(&$username, &$password, &$message, &$pageObject, &$values)
{

		

// Place event code here.
// Use "Add Action" button to add code snippets.


$username = strtoupper($username);


return true;
;		
} // function BeforeLogin

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
				// Before display
function BeforeShowMenu(&$xt, &$templatefile, &$pageObject)
{

		

// Place event code here.
// Use "Add Action" button to add code snippets.

if ($_SESSION["user_name"]=="CLIENT")
{
   $pageObject->hideItem("changepassword_link");

}


;		
} // function BeforeShowMenu

		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
				// Menu item: Modify
function ModifyMenuItem(&$menuItem)
{

		

// Place event code here.
// Use "Add Action" button to add code snippets.

//  HOW  TO  WRITE  INTO  TXT  FILE
$myfile = fopen("1  log_file ac.txt", "w") or die("Unable to open file!");
fwrite($myfile, "role = ".$_SESSION["userRole"]." \n");
fwrite($myfile, "DONE  \n");
fclose($myfile);


if ($_SESSION["user_role"] != "ADMIN") 
{
    $title = $menuItem->getTitle();
		if ($title == " Hidden AC") return false;



		//switch (true) {
		  //case $_SESSION["user_is_member"] ==  "FULL_ACCESS" : 
        // NOTHING TO HIDE   
			 // break;

		//  case $_SESSION["user_is_member"] ==  "READ_ONLY" :
	//			  $title = $menuItem->getTitle();
		//			if ($title == "  Activate Users") return false;
		//	    if ($title == "Configuration") return false;
		//		  break;

		//  case $_SESSION["user_is_member"] ==  "NO" :
		//		  $title = $menuItem->getTitle();
		//		  if ($title == "  Archived Events") return false;
          //  Rename Users to profile in menu
			//		if ($title=="  Users")
		//			    $title = $menuItem->setTitle("  Profile");
		//	    break;



	//	}

}
return true;
;		
} // function ModifyMenuItem

		

//	onscreen events
	function event_ac_snippet(&$params)
	{
	// Put your code here.
//echo nl2br("SPECS: ".$_SESSION["SPECS"]);

echo nl2br($_SESSION["SPECS"]);

// The nl2br() function is used in PHP to convert newline characters (\n) into HTML <br> tags, which helps preserve formatting when displaying text on a webpage.
	;
}




}
?>
