<?php
/*
copyright: copyright 2004 Sam Yapp. All Rights Reserved. You may modify this file for use on your
					site running a licenced copy of the Php Image Host scripts.
					You must not distribute this file or derivations of it.
Nullified By CrAcKlOvE
*/
class pagecontent{

	var $vars = array();

	function pagecontent(&$ace){
		$this->ace =& $ace;
	}

	function setvars($vs){
		$this->vars = array_merge($this->vars, $vs);
	}

	function getallcontent(){
		$sql = "SELECT content_id, name, description ";
		$sql .="FROM {pa_dbprefix}page_content ";
		$sql .="ORDER BY name ";
		$res = $this->ace->query($sql, 'Get Content');
		$cont = array();
		while( $c = mysql_fetch_object($res) ){
			$cont[] = $c;
		}
		return $cont;
	}

	function getcontentbyid($id){
		$sql = "SELECT * FROM {pa_dbprefix}page_content WHERE content_id=$id ";
		$res = $this->ace->query($sql, 'Get Content By Id');
		return mysql_fetch_object($res);
	}

	function getcontentbyname($name){
		$sql = "SELECT * FROM {pa_dbprefix}page_content WHERE name='".addslashes($name)."' ";
		$res = $this->ace->query($sql, 'Get Content By Name');
		return mysql_fetch_object($res);
	}

	function addcontent($name, $description){
		if( $this->getcontentbyname($name) == 0 && $name != '' ){
			$sql = "INSERT INTO {pa_dbprefix}page_content (name, description) ";
			$sql .="VALUES ('".addslashes($name)."', '".addslashes($description)."') ";
			$res = $this->ace->query($sql, 'Add Content');
			return mysql_insert_id();
		}
		return 0;
	}

	function updatecontent($id, $content){
		$sql = "UPDATE {pa_dbprefix}page_content SET content='".addslashes($content)."' WHERE content_id=$id";
		$res = $this->ace->query($sql, 'Update Content');
		return mysql_affected_rows();
	}

	function updatecontentdetails($id, $name, $description, $content){
		$cont = $this->getcontentbyname($name);
		if( $cont == 0 || $cont->content_id == $id ){
			if( $name != '' ){
				$sql = "UPDATE {pa_dbprefix}page_content SET name='".addslashes($name)."', ";
				$sql .="description='".addslashes($description)."', content='".addslashes($content)."' ";
				$sql .="WHERE content_id=$id ";
				$res = $this->ace->query($sql, 'Update Content Details');
			}
		}
		return false;
	}

	function deletecontent($id){
		$sql = "DELETE FROM {pa_dbprefix}page_content WHERE content_id=$id";
		$res = $this->ace->query($sql, 'Delete Content');
	}

	function display($name, $vars = array(), $return = false){
		if( !is_array($vars) ) $vars = array($vars);
		$vars = array_merge($this->vars, $vars);
		$c = $this->getcontentbyname($name);
		$s = array('{script}');
		$r = array($_SERVER['SCRIPT_NAME']);
		foreach( $this->vars as $n=>$v ){
			$s[] = '{'.$n.'}';
			$r[] = $v;
		}
		if( $c ){
			if( $return ){
				return str_replace($s, $r, $c->content);
			}else{
				echo str_replace($s, $r, $c->content);
			}
			return true;
		}
		return false;
	}

}

?>
