Location: PHPKode > projects > Monyet > controllers/index.php
<?php

Class Index extends ControllerBase {

	private $news;
	private $menu;

	public function __construct(){
		parent::__construct();
	}

	//function that will be invoked first. if the user click reload button, bring the latest page that 
	//is keeped in last session
	public function initiate(){
	  	if($this->session->isRegistered('last')){
			$this->xml->addRedir($this->session->get('last'));
			$this->xml->addText('reading last session','note',0);
	  		if($this->session->isRegistered('user')){
				if($this->session->get('lastadmin')==$this->session->get('last')){
					$this->xml->buildMenu($this->navigator->getMenu(2));
				}
				else{	  
					$this->xml->buildMenu($this->navigator->getMenu(1));
				}
				$this->xml->addText('Welcome '.$this->session->get('user').', ','welcome',0);
				$this->xml->addURL('logout','javascript:sndReq(\'authentication/logout\')','welcome',1);
			}
			else{
				$this->xml->buildMenu($this->navigator->getMenu(0));
			}
		}
		else{
			$this->xml->addRedir('index/index');
			$this->xml->addText('building page','note',0);
	   	$this->xml->addText(null,'welcome',0);
			$this->xml->buildMenu($this->navigator->getMenu(0));
			$this->session->set('group',GUEST);
		}
		$this->xml->addLoop('systemstat/buildmarquee',null,REFRESH);
	   $this->xml->addText(null,'submenu',0);
		$this->xml->flush();
	}

	//show latest news
	public function index(){
   	$this->news = new News();
		$this->session->set('last','index/index');	
		$this->xml->addText(SITENAME.' -home','title',0);
		$this->xml->addText(null,'panel',0);
		//build view news
		$array_news = $this->news->select(0,5);
		$table = 'Five Latest news fresh from the pan!<table cellspacing="5">';
		for($i=0;$i<sizeof($array_news);$i++){
				  $table .= '<tr><td valign="top" colspan="2"><h3>'.$array_news[$i]->title.'</h3></td></tr><tr>
							 <td valign="top">'.$array_news[$i]->posttime.'</td>
							 '.$array_news[$i]->content.'<br />Author: '.$array_news[$i]->user_id.'</td></tr>';
		}
		$table .= '</table>';
	   $this->xml->addText($table,'rightcontent',0);
		if($this->session->isRegistered('user')){
			$this->xml->buildMenu($this->navigator->getMenu(1));
		}	
		//build news
		$url = 'javascript:sndReqPOST(\'viewnews/index\')';
		$this->xml->addURL('View All News',$url,'submenu',0);
		$this->xml->flush();
	}

	public function __destruct(){
	}
}
?>
Return current item: Monyet