c_personAdmin.php 2.2 KB
<?php

require_once PICTOOL_SAVANT;
require_once LIBDIR . 'c_mysqlDb.php';
require_once LIBDIR . 'errException.php';
require_once LIBDIR . 'c_person.php';

class c_personAdmin extends c_picToolSavant
{
	private $dbHandle = NULL;
	private $_persons;

	function __construct ($locale = NULL)
	{
		parent::__construct ();

		setErrExceptionMapping ();

		try
		{
			$this->dbHandle = new c_mysqlDb (
				self::DBHOST, self::DBUSER, self::DBPASS, self::DBNAME);

			if (is_string ($locale))
				$this->dbHandle->setLocale ($locale);
		}
		catch (Exception $e)
		{
			if ($this->dbHandle !== NULL)
				unset ($this->dbHandle);

			print "<pre>\n";
			print "Konnte Datenbank nicht initialisieren!\n";
			print $e;
			print "</pre>\n";
			exit (1);
		}

		resetErrExceptionMapping ();

		$this->_persons = $this->getPersons ();
	}

	function __destruct ()
	{
		if (isset ($this->persons))
			unset ($this->persons);

		if ($this->dbHandle !== NULL)
			unset ($this->dbHandle);
	}

	//private function getPersons ()
	function getPersons ()
	{
		$result = NULL;

		setErrExceptionMapping ();
		try
		{
			$resId = $this->dbHandle->query (
				'SELECT * from personsView ORDER BY surname, firstname');
			$_result = $this->dbHandle->getObject (
				$resId, 'c_person', array (NULL));
			$this->dbHandle->freeResult ($resId);
		}
		catch (Exception $e)
		{
			print "jokus<br/>";
			if (isset ($_result))
				unset ($_result);
			if (isset ($resId))
				$this->dbHandle->freeResult ($resId);

			print "<pre>";
			print $e;
			print "</pre>";
		}
		resetErrExceptionMapping ();

		foreach ($_result as $res)
			$result[$res->get_personId ()] = $res;
		unset ($_result);

		return $result;
	}
	
	function personSearch ()
	{
		$names = array ();

		foreach ($this->_persons as $person)
			$names[$person->get_surname ()][] = 
				array ($person->get_firstname (), $person);

		$this->assign ('names', $names);

		return $this->fetch ('personAdmin/personSearch.tpl.php');
	}

	function personForm ()
	{
		return $this->fetch ('personAdmin/personForm.tpl.php');
	}

	function show ()
	{
		$this->assign ('personSearch', $this->personSearch ());
		$this->assign ('personForm', $this->personForm ());

		$this->display ('personAdmin/personAdmin.tpl.php');
	}
};

?>