<?php

/******************************************************************************
 *
 *	PROJECT: Flynax Classifieds Software
 *	VERSION: 4.0
 *	LISENSE: http://www.flynax.com/license-agreement.html
 *	PRODUCT: General Classifieds
 *	
 *	FILE: RLNOTICE.CLASS.PHP
 *
 *	This script is a commercial software and any kind of using it must be 
 *	coordinate with Flynax Owners Team and be agree to Flynax License Agreement
 *
 *	This block may not be removed from this file or any other files with out 
 *	permission of Flynax respective owners.
 *
 *	Copyrights Flynax Classifieds Software | 2012
 *	http://www.flynax.com/
 *
 ******************************************************************************/

class rlNotice extends reefless
{
	/**
	* @var language class object
	**/
	var $rlLang;
	
	/**
	* @var validator class object
	**/
	var $rlValid;
	
	/**
	* @var configurations class object
	**/
	var $rlConfig;
	
	/**
	* class constructor
	**/
	function rlNotice()
	{
		global $rlLang, $rlValid, $rlConfig;
		
		$this -> rlLang   = & $rlLang;
		$this -> rlValid  = & $rlValid;
		$this -> rlConfig = & $rlConfig;
	}
	
	/**
	* save notices in session
	*
	* @param array $message - nitice message
	*
	* @todo save notice
	**/
	function saveNotice( $message )
	{
		$sesVar = 'notice';
		if (defined('REALM'))
		{
			$sesVar = REALM . "_" . $sesVar;
		}

		if ( !empty($message) )
		{
			$_SESSION[$sesVar] = $message;
		}
		else 
		{
			return false;
		}
		
	}
	
	/**
	* reset notices from session
	*
	* @param array $message - nitice message
	*
	* @todo save notice
	**/
	function resetNotice()
	{
		$sesVar = 'notice';
		if (defined('REALM'))
		{
			$sesVar = REALM . "_" . $sesVar;
		}
		
		unset( $_SESSION[$sesVar] );
		return true;
	}
	
	/**
	* create notice block
	*
	* @param string $message - Notice message
	*
	**/
	function createNotice( $message )
	{
		$tpl = 'blocks' . RL_DS . 'notice_block_start.tpl';
		$block = $GLOBALS['rlSmarty'] -> fetch( $tpl, null, null, false );
		
		$block .= $message;
		
		$tpl = 'blocks' . RL_DS . 'notice_block_end.tpl';
		$block .= $GLOBALS['rlSmarty'] -> fetch( $tpl, null, null, false );
		
		return $block;
	}
	
	/**
	* create error block
	*
	* @param string $message - Error message
	*
	**/
	function createError( $message )
	{
		$tpl = 'blocks' . RL_DS . 'error_block_start.tpl';
		$block = $GLOBALS['rlSmarty'] -> fetch( $tpl, null, null, false );
		
		$mess_content = null;
		
		if ( is_array($message) )
		{
			foreach ( $message as $error )
			{
				$mess_content .= '- ' . $error . '<br />';
			}
			
			$block .= $mess_content;
		}
		else 
		{
			$block .= $message;
		}
		
		$mess_content = substr( $mess_content, 0, -6 );
		
		$tpl = 'blocks' . RL_DS . 'error_block_end.tpl';
		$block .= $GLOBALS['rlSmarty'] -> fetch( $tpl, null, null, false );
		
		return $block;
	}
	
	/**
	* create alert notification
	*
	* @param array/string $message - Alert message(s)
	*
	**/
	function createAlert( $message )
	{
		$tpl = 'blocks' . RL_DS . 'alert_block_start.tpl';
		$block = $GLOBALS['rlSmarty'] -> fetch( $tpl, null, null, false );
		
		$mess_content = null;
		
		if ( is_array($message) )
		{
			foreach ( $message as $alert )
			{
				$mess_content .= '- ' . $alert . '<br />';
			}
			
			$block .= $mess_content;
		}
		else 
		{
			$block .= $message;
		}
		
		$mess_content = substr( $mess_content, 0, -6 );
		
		$tpl = 'blocks' . RL_DS . 'alert_block_end.tpl';
		$block .= $GLOBALS['rlSmarty'] -> fetch( $tpl, null, null, false );
		
		return $block;
	}
}