<?php class WCRTpl {

	public $vars = array();
	public $wrap = '';

	function WCRTpl($cgi = '../../..',$theme_dir = '../') {
		$this->vars['cgi'] = $cgi;
		$this->vars['theme_dir'] = $theme_dir;
		if (file_exists($theme_dir.'/tpl/main.tpl')) { $this->wrap = $theme_dir.'/tpl/main.tpl'; }
		else { $this->wrap = $theme_dir.'/main.html'; }
		$this->vars['link_buttons'] = $this->TplContents($theme_dir.'/tpl/link_buttons.tpl');
		$this->vars['drives'] = 'ERROR.  DRIVES FUNCTIONALITY NOT CURRENTLY AVAILABLE.<br />';
		return TRUE;
	}
	
	function setWrapper($file) {
		if (file_exists($file)) {
			$this->wrap = $file;
			return TRUE;
		} else { return FALSE; }
	}

	function addVar($var,$val) {
		$this->vars[$var] = $val;
		return TRUE;
	}

	function getVar($var) {
		return $this->vars[$var];
	}

	function TplContents($file) {
		if (!file_exists($file)) { return 'ERROR.  TEMPLATE <strong>"'.$file.'"</strong> NON-EXISTANT<br />'; }
		else {
			$contents = file_get_contents($file);
			foreach($this->vars as $var => $val) {
				$contents = str_replace('<<'.$var.'>>',$val,$contents);
			}
			return $contents;
		}
	}

	function Display() {
		echo $this->TplContents($this->wrap);
	}

} ?>