<?php
require_once(searchinc('htmlgen.inc'));

// a base class for creating custom objects with block
// charactersitics
class htmlcustom_block extends htmldiv
{
	var $_contents_populated = false;
	
	var $_attrs;
	
	function __construct($contents=null, $attrs=null)
	{
		$proc = __CLASS__.'::'.__FUNCTION__.': ';
		$this->dbgecho($proc.'('.(isset($attrs['name'])?$attrs['name']:'').') entering', DEBUG_PROC_TRACE);
		
		parent::__construct($contents, $attrs);
		if ($this->is_ok())
		{
			// save all attributes except ones consumed by div
			// TBD - automate this somehow
			unset($attrs['name']);
			unset($attrs['id']);
			unset($attrs['css_classname']);
			unset($attrs['title']);
			unset($attrs['align']);
			unset($attrs['height']);
			unset($attrs['width']);
			
			$this->_attrs = $attrs;
		}
		
		$this->dbgecho($proc.' leaving - '.($this->is_ok()?'succeeded':'failed'), DEBUG_PROC_TRACE);
		if (!$this->is_ok())
		{
			$this->trigger_error();
		}
//		return $this->is_ok();
	}
	
	// override this in derived classes to create custom contents
	function populate_contents()
	{
		$proc = __CLASS__.'::'.__FUNCTION__.': ';
		$this->dbgecho($proc.'entering', DEBUG_PROC_TRACE);
		$this->clear_error();
		
		// base class only, so no contents
		
		$this->_contents_populated = $this->is_ok();
		
		$this->dbgecho($proc.' leaving - '.($this->is_ok()?'succeeded':'failed'), DEBUG_PROC_TRACE);
		return $this->is_ok();
	}
	
	function emit_str($tag_attrs='', $flags=0)
	{
		$proc = __CLASS__.'::'.__FUNCTION__.': ';
		$this->dbgecho($proc.'entering', DEBUG_PROC_TRACE);
		$this->clear_error();
		
		if (!$this->_contents_populated) $this->populate_contents();
		if ($this->is_ok())
		{
			$str = parent::emit_str($tag_attrs, $flags);
		}
		
		$this->dbgecho($proc.' leaving - '.($this->is_ok()?'succeeded':'failed'), DEBUG_PROC_TRACE);
		return $this->is_ok($str);
	}
	
	function emit_classdefs($arr=null)
	{
		$proc = __CLASS__.'::'.__FUNCTION__.': ';
		$this->dbgecho($proc.'('.$this->_name.') entering', DEBUG_PROC_TRACE);
		$this->clear_error();
			
		if (!$this->_contents_populated) $this->populate_contents();
		if ($this->is_ok())
		{
			$str = parent::emit_classdefs($arr);
		}
		
		$this->dbgecho($proc.' leaving - '.($this->is_ok()?look_r($str):'failed'), DEBUG_PROC_TRACE);
		return $this->is_ok($str);
	}
	
	function emit_class_scripts($arr=null)
	{
		$proc = __CLASS__.'::'.__FUNCTION__.': ';
		$this->dbgecho($proc.'('.$this->_name.') entering', DEBUG_PROC_TRACE);
		$this->clear_error();
		
		if (!$this->_contents_populated) $this->populate_contents();
		if ($this->is_ok())
		{
			$str = parent::emit_class_scripts($arr);
		}
		
		$this->dbgecho($proc.' leaving - '.($this->is_ok()?'succeeded':'failed'), DEBUG_PROC_TRACE);
		return $this->is_ok($str, RETURN_NULL_OK);
	}
}

// a base class for creating custom objects with inline
// charactersitics
class htmlcustom_inline extends htmlspan
{
	var $_contents_populated = false;
	
	var $_attrs;
	
	function __construct($contents=null, $attrs=null)
	{
		$proc = __CLASS__.'::'.__FUNCTION__.': ';
		$this->dbgecho($proc.'('.$attrs['name'].') entering', DEBUG_PROC_TRACE);
		
		parent::__construct($contents, $attrs);
		if ($this->is_ok())
		{
			// save all attributes except ones consumed by div
			// TBD - automate this somehow
			unset($attrs['name']);
			unset($attrs['id']);
			unset($attrs['css_classname']);
			unset($attrs['title']);
			
			$this->_attrs = $attrs;
		}
		
		$this->dbgecho($proc.' leaving - '.($this->is_ok()?'succeeded':'failed'), DEBUG_PROC_TRACE);
		if (!$this->is_ok())
		{
			$this->trigger_error();
		}
//		return $this->is_ok();
	}
	
	// override this in derived classes to create custom contents
	function populate_contents()
	{
		$proc = __CLASS__.'::'.__FUNCTION__.': ';
		$this->dbgecho($proc.'entering', DEBUG_PROC_TRACE);
		$this->clear_error();
		
		// base class only, so no contents
		
		$this->_contents_populated = $this->is_ok();
		
		$this->dbgecho($proc.' leaving - '.($this->is_ok()?'succeeded':'failed'), DEBUG_PROC_TRACE);
		return $this->is_ok();
	}
	
	function emit_str($tag_attrs='', $flags=0)
	{
		$proc = __CLASS__.'::'.__FUNCTION__.': ';
		$this->dbgecho($proc.'entering', DEBUG_PROC_TRACE);
		$this->clear_error();
		
		if (!$this->_contents_populated) $this->populate_contents();
		if ($this->is_ok())
		{
			$str = parent::emit_str($tag_attrs, $flags);
		}
		
		$this->dbgecho($proc.' leaving - '.($this->is_ok()?'succeeded':'failed'), DEBUG_PROC_TRACE);
		return $this->is_ok($str);
	}
	
	function emit_classdefs($arr=null)
	{
		$proc = __CLASS__.'::'.__FUNCTION__.': ';
		$this->dbgecho($proc.'('.$this->_name.') entering', DEBUG_PROC_TRACE);
		$this->clear_error();
			
		if (!$this->_contents_populated) $this->populate_contents();
		if ($this->is_ok())
		{
			$str = parent::emit_classdefs($arr);
		}
		
		$this->dbgecho($proc.' leaving - '.($this->is_ok()?look_r($str):'failed'), DEBUG_PROC_TRACE);
		return $this->is_ok($str);
	}
	
	function emit_class_scripts($arr=null)
	{
		$proc = __CLASS__.'::'.__FUNCTION__.': ';
		$this->dbgecho($proc.'('.$this->_name.') entering', DEBUG_PROC_TRACE);
		$this->clear_error();
		
		if (!$this->_contents_populated) $this->populate_contents();
		if ($this->is_ok())
		{
			$str = parent::emit_class_scripts($arr);
		}
		
		$this->dbgecho($proc.' leaving - '.($this->is_ok()?'succeeded':'failed'), DEBUG_PROC_TRACE);
		return $this->is_ok($str, RETURN_NULL_OK);
	}
}
 ?>