<?php
/**
 * modified for GroURL by Krzysztof Burghardt <krzysztof@burghardt.pl>
 */
/**
 * Google Analytics for DokuWiki
 * 
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Terence J. Grant<tjgrant@tatewake.com>
 */
 
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');

//--- Exported code
include_once(DOKU_PLUGIN.'geourl/code.php');
//--- Exported code

/**
 * All DokuWiki plugins to extend the admin function
 * need to inherit from this class
 */
class admin_plugin_geourl extends DokuWiki_Admin_Plugin
{
var $state = 0;
var $geourl = '';

	/**
	 * Constructor
	 */
	function admin_plugin_geourl()
	{
		$this->setupLocale();
	}

	/**
	 * return some info
	 */
	function getInfo()
	{
		return array(
			'author' => 'Terence J. Grant and Krzysztof Burghardt',
			'email'  => 'krzysztof@burghardt.pl',
			'date'   => '2006-09-14',
			'name'   => 'GeoURL Plugin',
			'desc'   => 'Plugin to embed your location into GeoURL.',
			'url'    => 'http://www.burghardt.pl/wiki/software/geourl_for_dokuwiki',
		);
	}

	/**
	 * return sort order for position in admin menu
	 */
	function getMenuSort()
	{
		return 998;
	}
	
	/**
	 *  return a menu prompt for the admin menu
	 *  NOT REQUIRED - its better to place $lang['menu'] string in localised string file
	 *  only use this function when you need to vary the string returned
	 */
	function getMenuText()
	{
		return 'GeoURL';
	}

	/**
	 * handle user request
	 */
	function handle()
	{
		$this->state = 0;
	
		if (!isset($_REQUEST['cmd'])) return;   // first time - nothing to do

		if (!is_array($_REQUEST['cmd'])) return;

		$this->geourl = $_REQUEST['geourl'];

		if (is_array($this->geourl))
		{
			$this->state = 1;
		}
	}

	/**
	 * output appropriate html
	 */
	function html()
	{
		global $conf;
		global $gu_loaded, $gu_settings;

		if ($this->state != 0)	//If we are to save now...
		{
			$gu_settings['latitude'] = $this->geourl['latitude'];
			$gu_settings['longitude'] = $this->geourl['longitude'];

			gu_save();
		}

		print $this->plugin_locale_xhtml('intro');

		ptln("<form action=\"".wl($ID)."\" method=\"post\">");
		ptln('  <input type="hidden" name="do"   value="admin" />');
		ptln('  <input type="hidden" name="page" value="'.$this->getPluginName().'" />');
		ptln('  <input type="hidden" name="cmd[geourl]" value="true" />');
		print '<center><table class="inline">';
		print '	<tr><th> '.$this->getLang('gu_item_type').' </th><th> '.$this->getLang('gu_item_option').' </th></tr>';
		print '	<tr><td> '.$this->getLang('gu_geourl_latitude').' </td><td><input type="text" name="geourl[latitude]" value="'.$gu_settings['latitude'].'"/></td></tr>';
		print '	<tr><td> '.$this->getLang('gu_geourl_longitude').' </td><td><input type="text" name="geourl[longitude]" value="'.$gu_settings['longitude'].'"/></td></tr>';
		print '</table>';
		print '<br />';
		print '<p><input type="submit" value="'.$this->getLang('gu_save').'"></p></center>';
		print '</form>';
	}
}

