<?php
ob_start();
if(!(is_readable(realpath(dirname(__FILE__).'/../').'/include/includesroutines.inc'))) {
	die('Error - Could not open or read file '.realpath(dirname(__FILE__).'/../').'/include/includesroutines.inc');
} else {
	include_once(realpath(dirname(__FILE__).'/../').'/include/includesroutines.inc');
}

if(!(is_readable(realpath(dirname(__FILE__).'/../').'/include/bsservice.inc'))) {
	die('Error - Could not open or read file '.realpath(dirname(__FILE__).'/../').'/include/bsservice.inc');
} else {
	include_once(realpath(dirname(__FILE__).'/../').'/include/bsservice.inc');
}

if (getSetting('portal','useRights',0) == 1 && IsUserLogin() == 1){
	$cn = db_connect();
	$ticket = getAuthTicket();
	$call = sendAuthTicket($cn, $ticket);
	db_disconnect($cn);
	if ( strlen(trim($call)) > 0 ) {
		$servicemsg = "";
		$xml = simplexml_load_string($call);
		$elem = $xml->xpath('//authticket');
  		$elem = $elem[0];

		$msg = $elem->xpath('//message');
		$sz = sizeof($msg);
		if ($sz > 0){
		 	$servicemsg = $msg[0][0];
		}

		if ( $elem["auth"] != 1 ) {
			LogOut();
			echo ($sz > 0 ? $servicemsg : "authorization error!");
		}
	}
}
ob_end_flush();
?>