oedl_ctrl.php 2.91 KB
<?php
	// Guestbook Kram
	require_once (OEDL_DIR . 'libs/guestbook.php');
	// get all stuff about menus
	require_once (OEDL_DIR . 'libs/menu.php');
	// get GNURU_WISDOM constant
	require_once (OEDL_DIR . 'libs/gnuru.php');
	// get Savant2 baseclass
	require_once ('/usr/share/php/Savant2.php');

	// now create out controller
	class OEDLController extends Savant2 
	{
		/*** private member ***/
		private $menu;       /* a reference to a menu object */
		private $gnuru;		/* a reference to a gnuru object */
		private $gb;         /* mein Gästebuch */


		/*** public methods ***/

		/*
		 * Constructor
		 */
		function __construct () 
		{
			$this->addPath ('template', OEDL_DIR . 'templates');
			$this->addPath ('resource', SAVANT_DIR);
			$this->addPath ('resource', OEDL_DIR . 'resources');

			error_reporting (E_ALL);

			try
			{
				$this->menu  =& new menu;
				$this->gnuru =& new gnuru;
				$this->gb    =& new Guestbook;
			}
			catch (MyException $e)
			{
				$this->display ('init_err.tpl.php');
				exit (1);
			}

			$this->assign  ('gnuruWisdom', $this->gnuru->getWisdom ());
		}

		/*
		 * doRequest: processes a request. The only public function beneath the
		 * constructor (well, at the moment)
		 *
		 * @param: request array containing the request (normally $_REQUEST)
		 */
		function doRequest ($request)
		{
			$content = isset($request['cont']) ? $request['cont'] : 'about';

			$this->assign ('menuItems',   $this->menu->menuGet ());
			$this->assign ('contentId',   $content);
			$this->assign ('contentHead', $this->menu->menuGetTextById ($content));
			$this->assign ('contentTpl',  $this->menu->menuGetTplById ($content));

			$action = isset($request['action']) ? $request['action'] : 'view';

			switch ($content)
			{
				case 'guestbook':
					switch ($action)
					{
						/* all actions that could accure will be handles here */

						case 'add':
							// adding a guestbook entry
							$this->assign ($this->gb->getFormData ());
							break;
						case 'submit':
							// submitting a guestbook entry
							$this->gb->mungeFormData($_POST);
							if($this->gb->isValidForm($_POST)) 
							{
								try
								{
									$this->gb->addEntry($_POST);
									$this->assign ('data', $this->gb->getEntries());
								}
								catch (MyException $e)
								{
									$this->assign ('contentId',   $content);
									$this->assign ('contentHead', _('Error'));
									$this->assign ('contentTpl',  'error.tpl.php');
								}
							} 
							else 
							{
								$this->assign ($this->gb->getFormData($_POST));
							}
							break;
						case 'view':
						default:
							try {
								$this->assign ('data', $this->gb->getEntries());
							}
							catch (MyException $e)
							{
								$this->assign ('contentId',   $content);
								$this->assign ('contentHead', _('Error'));
								$this->assign ('contentTpl',  'error.tpl.php');
							}
							break;   
					}
			}

			$this->display ('frame.tpl.php');
		}
	}
?>