<?php

	//Security
	if( ! defined( 'IS_INIT' ) )
	{
		die( 'Unauthorized Access');
	}
	
class functions 
{
	private $Handler;	
	
	public function __construct()
	{
		global $Handler;
		$this->Handler = $Handler;
	}
	public function News()
	{
		$ret = null;
		$file = THEME_PATH . "text/news.txt";
		$fp = fopen( $file , 'r' );
		$i = 0;
		while ( (! feof( $fp ) ) && $i < 8 )
		{
			$buffer = fgets( $fp );
			$lines = explode( '|', $buffer );
			
			$ret .= '<h3><a href="#">'.$lines[0].'<span style="float:right">' . $lines[1] . '</span></a></h3><div>' . $lines[2] . '</div>';
			$i++;
		}
		fclose( $fp );
		
		return $ret;
	} 
	
	public function ShopItems()
	{
            $do = sqlsrv_query( $this->Handler->database->conn , "Select * from Account.dbo.tMallItems where canbuy = 'true';" );
            if( sqlsrv_has_rows( $do ) ) 
            {
                    $ret = null;

                    while( $row = sqlsrv_fetch_array( $do , SQLSRV_FETCH_ASSOC ) )
                    {
                            $ret .= '<h3><a href="#">'.$row['displayname'].'<span style="float:right">Price : <span style="color:red;">' . $row['price'] . ' </span></span></a></h3>
                            <div>' . $row['description'] . '<br /><span>Amount : <span style="color:red;">' . $row['pieces'] . '</span></span><br /><form method="post"><input type="hidden" value="' . $row['itemid'] . '" name="id" /><input type="submit" value="Buy" name="mall"/></form></div>';
                    }

                    return $ret;
            }
            else
            {
                    return "No items in the mall";
            }
	}
} 

?>