<?php

# LemurCMS by Alec Gorge
#
#     This file contains the PHP functions used throught the CMS.
#
# updated: Jan. 12, 2009

class init extends themeManager {
	public $pageContent;
	public function __construct () {
		$this->db_connect();
		$this->register_site_info();
		define('HOME_PAGE_ID', $this->page_info['settings']['Home Page Id']['value']);
	}
	public function set_validation($user, $pass) {
		session_start();
		$_SESSION['username'] = sanitize_sql_string($user);
		$_SESSION['password'] = sha1(sanitize_sql_string($pass));
		echo $_SESSION['username'];
		if($this->validate() == false) {
			$_SESSION = array();
			session_destroy();
			$this->pageContent($this->adminLoginForm, 0);	
			$this->pageContent($this->message('error', 'Login Failed!', 'Login Failed. Try again.', -1));	
		}	
	}
	public function pageContent ($content, $append=0) {
		//$content = htmlspecialchars_decode(htmlentities($content, ENT_QUOTES, false)); 
		if($append == 1) {
			$this->page_info['content']['page_content'] .= $content;
		}
		if($append == -1) {
			$this->page_info['content']['page_content'] = $content.$this->page_info['content']['page_content'];
		}
		if($append == 0) {
			$this->page_info['content']['page_content'] = $content;
		}
	}
	public function pageTitle ($content, $append=0) {
		//$content = htmlspecialchars_decode(htmlentities($content, ENT_QUOTES, false)); 
		if($append == 1) {
			$this->page_info['content']['page_title'] .= $content;
		}
		if($append == -1) {
			$this->page_info['content']['page_title'] = $content.$this->page_info['content']['page_title'];
		}
		if($append == 0) {
			$this->page_info['content']['page_title'] = $content;
		}
	}
	//$this->page_info['settings']['Home Page Id']['value']
	public function displayPage ($page_id = HOME_PAGE_ID, $set = 0) {
		$sql = "SELECT * FROM ".DBTABLEPREFIX."content_pages WHERE id ='$page_id'";
		$content = $this->db_query($sql) or die(mysql_error());
		while($row = mysql_fetch_array($content)) {
			$this->pageTitle(trim(stripslashes(stripslashes(strip_tags(strip_html_tags(($row['title'])))))));
			$this->pageContent(trim(stripslashes(stripslashes(stripslashes(stripslashes($row['content']))))));
		}
		if($set == 0) {
			return $this->page_info['content']['page_content'];
		}
	}
}

?>