<?php
/**
 * Configuration Manager guestbook plugin
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Gerry Weißbach <gerry.w@gammaproduction.de>
 */

if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'admin.php');

require_once(DOKU_PLUGIN.'/guestbook/basic.class.php');   // settings classes specific to these settings

/**
 * All DokuWiki plugins to extend the admin function
 * need to inherit from this class
 */
class admin_plugin_guestbook extends DokuWiki_Admin_Plugin {

    var $_SESSION_started = false;

    /**
     * return some info
     */
    function getInfo(){

        return array(
            'author' => 'Gerry Wei&szlig;bach',
            'email'  => 'gerry.w@gammaproduction.de',
            'date'   => '2006-01-28',
            'name'   => 'guestbook Plugin',
            'desc'   => 'Edit, delete and activate entrys',
            'url'    => '',
        );
    }

    function getMenuSort() { return 100; }

    /**
     * handle user request
     */
    function handle() {

			$guestbook_database = new guestbook_database();
			$guestbook_database->checkStatus($this);

			if (!empty($_POST['newEntry']))
			{
				$form = new guestbook(TRUE);
				$form->newEntry($this, intval($_POST['oldID']));
			}

			if (!empty($_POST['guestActivate']))
			{
				$form = new guestbook(TRUE);
				$form->guestActivate($this);
			}

			if (!empty($_GET['activate']))
			{
				$form = new guestbook(TRUE);
				$form->guestActivateViaMail($this);
			}

			if (!empty($_POST['guestDelete']))
			{
				$form = new guestbook(TRUE);
				$form->deleteEntry($this);
			}
    }

    /**
     * output appropriate html
     */
    function html() {
      global $lang, $_SESSION;

			$guestbook = new guestbook(TRUE);

      	print '<div id="guestbook">';

    		if(!empty($_POST['createEntry']) || !empty($_POST['guestEdit']))
					print $guestbook->form($this, intval($_POST['guestEdit']));
				else
				{
					print $this->locale_xhtml('intro');

      		print $guestbook->html($this, TRUE);
	  		}

			  print '</div>';
		}
}
