Subversion Repositories travelsized

Rev

Rev 487 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * This file is part of Travelsized CMS
 *              A content management system with modules, based on wiki syntax
 *
 * Author: Dan Jensen <admin@leinir.dk>
 * Copyright 2003/2004
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * The GNU General Public License is available at: http://www.gnu.org/copyleft/
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


/**
 * Will spot the first module command name of $moduleCommandName in $page_data, and return the parameters
 *
\code
$loopcontrol = 0;
$moduleCommandName = "profilegallerylist";
while( $parameters = spotModuleCommand( $page_data, $moduleCommandName, $loopcontrol ) )
{
        if( $parameters == " " )
                $parameters = "";
       
        $page_data = str_replace( "\\$moduleCommandName($parameters)", $replaceData, $page_data );
}
\endcode
 * @param   page_data           The page data to look through
 * @param   moduleCommandName   The name of the command to look for
 * @param   loopcontrol         A variable used for loop control. Pass ByRef!
 * @param   loopcontrollimit    How many loops do we accept before bailing - defaults to 1000
 *
 * @return  mixed                 The command parameters, or false if the module command was not found
 */

function spotModuleCommand( $page_data, $moduleCommandName, $loopcontrol, &$loopcontrollimit = 1000 )
{
        if( $loopcontrol++ == $loopcontrollimit ) // If we've gotten all the way up to 1000 hits, it is an error - bail!
        {
                die( "An error occured while parsing the $moduleCommandName tags - please look at your entry. We tried parsing more than $loopcontrollimit entries - this is almost certainly an error." );
                return false;
        }
       
        $len = strlen( $moduleCommandName ) + 1;
        $begpos = strpos( $page_data, "\\$moduleCommandName(" ); //where does the first command begin
        if( $begpos === false ) //all commands have been found, no need to check more
                return false;
       
        $endpos = strpos( $page_data, ")", $begpos + $len ); //feed end
        if( $endpos === false ) // The command was not terminated properly - bail!
        {
                die( "At least one of the $moduleCommandName tags was not terminated properly - please edit the entry and attempt to fix this!" );
                return false;
        }
       
        $parameters = trim( substr( $page_data, $begpos + $len + 1, ( $endpos - $begpos ) - ( $len + 1 ) ) );
        if( $parameters == "" ) // Make sure the parameters aren't empty, to avoid boolean conversion problems
                $parameters = " ";
       
        return $parameters;
}

/**
 * Draws a command link
 *
 * @param     title          The command link title
 * @param     description    Optional. The description of the command link
 * @param     url            The URL the command link should call
 * @param     extraClass     Optional. Extra class information (Will be added after the command class)
 *
 * @return    string         A string containing the rendered command link
 */

function drawCommand( $title, $description = "", $url, $extraClass = "", $target = "" )
{
        if( $description == "" )
                $description = i18n( "No further description of ##0##", array($title) );
        $theTarget = "";
        if( $target != "" )
                $theTarget = " target=\"$target\"";
       
        $link = "<a class=\"command$extraClass\" href=\"$url\" title=\"$description\"$theTarget>[";
        $link .= $title;
        $link .= "]</a>";
       
        return $link;
}

//! The setupPage class, used to make sure all the setup pages are rendered in a consistent manner
class setupPage
{
        var $contents;             ///< string  The contents of the setup page
        var $breadcrumbs;          ///< array   An array of breadcrumbs data. This always has the top level defined, so no need to add that
        var $commands;             ///< array   An array containing commands. Optional
       
        /**
         * The setupPage constructor
         */

        function setupPage()
        {
                global $language;
                // Make the empty arrays
                $this->commands = array();
                $this->breadcrumbs = array();
                // Add the top parent
                $this->addBreadcrumb( i18n("Setup"), globalIDtoURL("setup") );
        }
       
        /**
         * Adds a breadcrumb to the end of the breadcrumbs trail
         *
         * @param  $title        What to show in the breadcrumbs trail
         * @param  $url          The url to invoke upon activation of the breadcrumbs trail
         */

        function addBreadcrumb( $title, $url )
        {
                $this->breadcrumbs[] = array(
                        "title" => $title,
                        "url" => $url
                        );
        }
       
        /**
         * Adds a new command to the left of the commands
         *
         * @param  $title        The short title of the command
         * @param  $description  The longer tooltip description of the command
         * @param  $url          The url to invoke when the command is activated
         */

        function addCommand( $title, $description, $url )
        {
                $this->commands[] = array(
                        "title" => $title,
                        "description" => $description,
                        "url" => $url
                        );
        }
       
        /**
         * Renders the setup page as defined by the current instance
         *
         * @return   string      The rendered setup page
         */

        function render()
        {
                $renderedBreadcrumbs = "";
                $renderedCommands = "";
               
                foreach( $this->breadcrumbs as $key => $breadcrumb )
                {
                        if( $key > 0 )
                                $renderedBreadcrumbs .= " &raquo; ";
                        $renderedBreadcrumbs .= "<a class=\"setup-breadcrumb\" href=\"{$breadcrumb['url']}\">{$breadcrumb['title']}</a>";
                }
               
                foreach( $this->commands as $key => $command )
                        $renderedCommands .= " " . drawCommand( $command['title'], $command['description'], $command['url'] );
               
                if( strlen( $renderedCommands ) == 0 )
                        $renderedBreadcrumbs = "<td class=\"setup-breadcrumbs\" colspan=\"2\">$renderedBreadcrumbs</td>";
                else
                {
                        $renderedBreadcrumbs = "<td class=\"setup-breadcrumbs\">$renderedBreadcrumbs</td>";
                        $renderedCommands = "<td class=\"setup-commands\">$renderedCommands</td>";
                }
               
                $renderedPage = "
                <table class=\"setup-container\">
                        <tr class=\"setup-container\">
                                $renderedBreadcrumbs
                                $renderedCommands
                        </tr>
                        <tr class=\"setup-container\">
                                <td class=\"setup-contents\" colspan=\"2\">{$this->contents}</td>
                        </tr>
                </table>"
;
               
                return $renderedPage;
        }
}

/**
 * Renders an options row, from an array as defined by the following:
 *
 * array(
 *   "title" => The i18nified human name of the option, shown as the title,
 *   "tip" => A longer i18nified tip, which is shown as a comment below the name,
 *   "name" => The actual name of the option, the name of the $_POST variable,
 *   "current" => The current value of the option,
 *   "type" => Which type of option it is. Possible values are: header (special), label, text, password, textbox, pagedata, checkbox, datetime, time, date, radio, select
 *   "options" => For select you must additionally define an array element called "options" containing an array, with key/value sets with the options and descriptions of each element in the select, where current is the key of the currently chosen option
 *                For radio you must additionally define an array element called "options" containing an array, with key/value sets with the options and title ? descriptions of each element in the radio group, where current is the key of the currently chosen option. Format as such: key => array(title,description)
 *                For date and datetime, optionally choose a start year and end year as elements in an array of the format 0 => startyear, 1 => endyear
 * )
 *
 * @param       array   theOption              Option data, as defined in the function description
 * @param       string  mainVarName            Optional. If this is set, an extra array layer will be added to the $_POST data
 * @param       bool    alternateTipPosition    Optional (default false). If true, the tip will be placed under the value. By default it is placed under the option title in stead.
 *
 * @return string                 The rendered options row (table row with two cells, or spanning two cells)
 */

function renderOptionsRow( $theOption, $mainVarName = "", $alternateTipPosition = false )
{
        $extralayer = "";
        if( array_key_exists( "name", $theOption ) )
        {
                if( $mainVarName != "" )
                        $extralayer = $mainVarName . "[" . $theOption["name"] . "]";
                else
                        $extralayer = $theOption["name"];
        }
       
        $theTip = $theAlternateTip = $theError = "";
        if( array_key_exists( "tip", $theOption ) && $theOption["tip"] != "" )
        {
                if( $alternateTipPosition )
                {
                        $theAlternateTip .= "<small class=\"comment\">" . $theOption["tip"] . "</small>";
                }
                else
                {
                        $theTip .= "<small class=\"comment\">" . $theOption["tip"] . "</small>";
                }
        }
       
        if( array_key_exists( "error", $theOption ) && $theOption["error"] != "" )
                $theError .= "<small class=\"error\">" . $theOption["error"] . "</small>";
       
        switch( $theOption["type"] )
        {
        case "header":
                return "
                <tr class=\"option\">
                        <th colspan=\"2\" class=\"option\">
                                "
. $theOption["title"] . "
                        </th>
                </tr>"
;
                break;
        case "label":
                return "
                <tr class=\"option\">
                        <td class=\"option\">"
. $theOption["title"] . "$theError $theTip</td>
                        <td class=\"option\"><span class=\"option_label\">{$theOption['current']}</span>$theAlternateTip</td>
                </tr>"
;
                break;
        case "text":
                return "
                <tr class=\"option\">
                        <td class=\"option\">"
. $theOption["title"] . "$theError $theTip</td>
                        <td class=\"option\"><input type=\"text\" style=\"width: 100%;\" class=\"option_text\" name=\"$extralayer\" value=\"{$theOption['current']}\" />$theAlternateTip</td>
                </tr>"
;
                break;
        case "password":
                return "
                <tr class=\"option\">
                        <td class=\"option\">"
. $theOption["title"] . "$theError $theTip</td>
                        <td class=\"option\"><input type=\"password\" style=\"width: 100%;\" class=\"option_text\" name=\"$extralayer\" value=\"{$theOption['current']}\" />$theAlternateTip</td>
                </tr>"
;
                break;
        case "file":
                return "
                <tr class=\"option\">
                        <td class=\"option\">"
. $theOption["title"] . "$theError $theTip</td>
                        <td class=\"option\"><input type=\"file\" style=\"width: 100%;\" class=\"option_file\" name=\"$extralayer\" />$theAlternateTip</td>
                </tr>"
;
                break;
        case "checkbox":
                $checked = "";
                if( $theOption["current"] == 1 )
                        $checked = " checked";
                return "
                <tr class=\"option\">
                        <td class=\"option\">"
. $theOption["title"] . "$theError $theTip</td>
                        <td class=\"option\"><label><input type=\"checkbox\" class=\"option_checkbox\" name=\"$extralayer\"$checked />"
. $theOption["title"] . "</label>$theAlternateTip</td>
                </tr>"
;
                break;
        case "textbox":
                return "
                <tr class=\"option\">
                        <td class=\"option\">"
. $theOption["title"] . "$theError $theTip</td>
                        <td class=\"option\"><textarea rows=\"4\" style=\"width: 100%;\" class=\"option_textbox\" name=\"$extralayer\">{$theOption['current']}</textarea>$theAlternateTip</td>
                </tr>"
;
                break;
        case "pagedata":
                global $formatting_toolbar;
                return "
                <tr class=\"option\">
                        <td colspan=\"2\" class=\"option\">"
. $theOption["title"] . "$theError $theTip$theAlternateTip</td>
                </tr>$formatting_toolbar
                <tr class=\"option\">
                        <td colspan=\"2\" class=\"option\"><textarea id=\"edit\" rows=\"15\" style=\"width: 100%;\" class=\"option_textbox\" name=\"$extralayer\">{$theOption['current']}</textarea></td>
                </tr>"
;
                break;
        case "datetime":
                // time is set here only when not submit data...
                $temp_year = date("Y", $theOption["current"]);
                $temp_month = date("m", $theOption["current"]);
                $temp_date = date("j", $theOption["current"]);
                $temp_hour = date("H", $theOption["current"]);
                $temp_minute = date("i", $theOption["current"]);
                $temp_second = date("s", $theOption["current"]);
               
                if( is_array( $theOption["options"] ) )
                        for ($i = $theOption["options"][0]; $i <= $theOption["options"][1]; $i++) { $allyears[] = $i; }
                else
                        for ($i = date("Y") - 50; $i <= date("Y") + 50; $i++) { $allyears[] = $i; }
                foreach ($allyears as $key => $value) {
                        if ($value == $temp_year) { $selected = " selected"; } else { $selected = ""; }
                        $temp_years .= "<option value=\"$value\"$selected>$value</option>";
                }
               
                $allmonths = array("01" => "January", "02" => "February", "03" => "March", "04" => "April", "05" => "May", "06" => "June", "07" => "July", "08" => "August", "09" => "September", "10" => "October", "11" => "November", "12" => "December");
                foreach ($allmonths as $key => $value) {
                        if ($key == $temp_month) { $selected = " selected"; } else { $selected = ""; }
                        $temp_months .= "<option value=\"$key\"$selected>$value</option>";
                }
               
                for ($i = 1; $i <= 31; $i++) { $alldates[] = $i; }
                foreach ($alldates as $key => $value) {
                        if ($value == $temp_date) { $selected = " selected"; } else { $selected = ""; }
                        $temp_days .= "<option value=\"$value\"$selected>$value</option>";
                }
               
                for ($i = 0; $i <= 23; $i++) { if (strlen($i) < 2) { $allhours[] = "0$i"; } else { $allhours[] = $i; } }
                foreach ($allhours as $key => $value) {
                        if ($value == $temp_hour) { $selected = " selected"; } else { $selected = ""; }
                        $temp_hours .= "<option value=\"$value\"$selected>$value</option>";
                }
               
                for ($i = 0; $i <= 59; $i++) { if (strlen($i) < 2) { $allminutes[] = "0$i"; } else { $allminutes[] = $i; } }
                foreach ($allminutes as $key => $value) {
                        if ($value == $temp_minute) { $selected = " selected"; } else { $selected = ""; }
                        $temp_minutes .= "<option value=\"$value\"$selected>$value</option>";
                }
                foreach ($allminutes as $key => $value) {
                        if ($value == $temp_second) { $selected = " selected"; } else { $selected = ""; }
                        $temp_seconds .= "<option value=\"$value\"$selected>$value</option>";
                }
               
                return "
                <tr class=\"option\">
                        <td class=\"option\">"
. $theOption["title"] . "$theError $theTip</td>
                        <td class=\"option\"><div style=\"width: 10%; overflow: hidden; display: inline-block;\" class=\"option_time_date\">
                                "
. i18n("On") . "</div><select style=\"width: 20%;\" name=\"" . $extralayer . "[day]\">$temp_days
                                </select><select style=\"width: 40%;\" name=\""
. $extralayer . "[month]\">$temp_months
                                </select><select style=\"width: 30%;\" name=\""
. $extralayer . "[year]\">$temp_years
                                </select><br />
                                <div style=\"width: 10%; overflow: hidden; display: inline-block;\">
                                "
. i18n("at") . "</div><select style=\"width: 30%;\" name=\"" . $extralayer . "[hour]\">$temp_hours
                                </select><select style=\"width: 30%;\" name=\""
. $extralayer . "[minute]\">$temp_minutes
                                </select><select style=\"width: 30%;\" name=\""
. $extralayer . "[second]\">$temp_seconds
                        </select>$theAlternateTip</td>
                </tr>"
;
                break;
        case "date":
                // time is set here only when not submit data...
                $temp_year = date("Y", $theOption["current"]);
                $temp_month = date("m", $theOption["current"]);
                $temp_date = date("j", $theOption["current"]);
               
                if( is_array( $theOption["options"] ) )
                        for ($i = $theOption["options"][0]; $i <= $theOption["options"][1]; $i++) { $allyears[] = $i; }
                else
                        for ($i = date("Y") - 50; $i <= date("Y") + 50; $i++) { $allyears[] = $i; }
                foreach ($allyears as $key => $value) {
                        if ($value == $temp_year) { $selected = " selected"; } else { $selected = ""; }
                        $temp_years .= "<option value=\"$value\"$selected>$value</option>";
                }
               
                $allmonths = array("01" => "January", "02" => "February", "03" => "March", "04" => "April", "05" => "May", "06" => "June", "07" => "July", "08" => "August", "09" => "September", "10" => "October", "11" => "November", "12" => "December");
                foreach ($allmonths as $key => $value) {
                        if ($key == $temp_month) { $selected = " selected"; } else { $selected = ""; }
                        $temp_months .= "<option value=\"$key\"$selected>$value</option>";
                }
               
                for ($i = 1; $i <= 31; $i++) { $alldates[] = $i; }
                foreach ($alldates as $key => $value) {
                        if ($value == $temp_date) { $selected = " selected"; } else { $selected = ""; }
                        $temp_days .= "<option value=\"$value\"$selected>$value</option>";
                }
               
                return "
                <tr class=\"option\">
                        <td class=\"option\">"
. $theOption["title"] . "$theError $theTip</td>
                        <td class=\"option\"><div style=\"width: 10%; overflow: hidden; display: inline-block;\" class=\"option_time_date\">
                                "
. i18n("On") . "</div><select style=\"width: 20%;\" name=\"" . $extralayer . "[day]\">$temp_days
                                </select><select style=\"width: 40%;\" name=\""
. $extralayer . "[month]\">$temp_months
                                </select><select style=\"width: 30%;\" name=\""
. $extralayer . "[year]\">$temp_years
                                </select>$theAlternateTip</td>
                </tr>"
;
                break;
        case "time":
                // time is set here only when not submit data...
                $temp_hour = date("H", $theOption["current"]);
                $temp_minute = date("i", $theOption["current"]);
                $temp_second = date("s", $theOption["current"]);
               
                for ($i = 0; $i <= 23; $i++) { if (strlen($i) < 2) { $allhours[] = "0$i"; } else { $allhours[] = $i; } }
                foreach ($allhours as $key => $value) {
                        if ($value == $temp_hour) { $selected = " selected"; } else { $selected = ""; }
                        $temp_hours .= "<option value=\"$value\"$selected>$value</option>";
                }
               
                for ($i = 0; $i <= 59; $i++) { if (strlen($i) < 2) { $allminutes[] = "0$i"; } else { $allminutes[] = $i; } }
                foreach ($allminutes as $key => $value) {
                        if ($value == $temp_minute) { $selected = " selected"; } else { $selected = ""; }
                        $temp_minutes .= "<option value=\"$value\"$selected>$value</option>";
                }
                foreach ($allminutes as $key => $value) {
                        if ($value == $temp_second) { $selected = " selected"; } else { $selected = ""; }
                        $temp_seconds .= "<option value=\"$value\"$selected>$value</option>";
                }
               
                return "
                <tr class=\"option\">
                        <td class=\"option\">"
. $theOption["title"] . "$theError $theTip</td>
                        <td class=\"option\">
                                <div style=\"width: 10%; overflow: hidden; display: inline-block;\">
                                "
. i18n("at") . "</div><select style=\"width: 30%;\" name=\"" . $extralayer . "[hour]\">$temp_hours
                                </select><select style=\"width: 30%;\" name=\""
. $extralayer . "[minute]\">$temp_minutes
                                </select>$theAlternateTip</td>
                </tr>"
;
                break;
        case "radio":
                if( is_array( $theOption["options"] ) )
                {
                $temp_content = "
                <tr class=\"option\">
                        <td class=\"option\">"
. $theOption["title"] . "$theError $theTip</td>
                        <td class=\"option\">"
;
                        foreach( $theOption["options"] as $key => $value )
                        {
                                $default = "";
                                if( $key == $theOption["current"] )
                                        $default = " checked";
                               
                                $temp_content .= "
                                <label><input type=\"radio\" name=\"$extralayer\" value=\"$key\"$default>{$value['title']}</label>"
. parse_page_data($value['description']);
                        }
                $temp_content .= "
                        $theAlternateTip</td>
                </tr>"
;
                }
                else
                {
                        $temp_content .= "<tr class=\"option\"><td class=\"option\" colspan=\"2\">" . i18n( "Error - The options argument is missing from the select option named &quot;##0##&quot;", array( $theOption["title"] ) ) . "</td></tr>";
                }
                return $temp_content;
                break;
        case "select":
                if( is_array( $theOption["options"] ) )
                {
                $temp_content = "
                <tr class=\"option\">
                        <td class=\"option\">"
. $theOption["title"] . "$theError $theTip</td>
                        <td class=\"option\"><select style=\"width: 100%;\" class=\"option_select\" name=\"$extralayer\">"
;
                        foreach( $theOption["options"] as $key => $value )
                        {
                                $default = "";
                                if( $key == $theOption["current"] )
                                        $default = " selected";
                               
                                $temp_content .= "
                                <option value=\"$key\"$default>$value</option>"
;
                        }
                $temp_content .= "
                        </select>$theAlternateTip</td>
                </tr>"
;
                }
                else
                {
                        $temp_content .= "<tr class=\"option\"><td class=\"option\" colspan=\"2\">" . i18n( "Error - The options argument is missing from the select option named &quot;##0##&quot;", array( $theOption["title"] ) ) . "</td></tr>";
                }
                return $temp_content;
                break;
        case "multicheck":
                if( is_array( $theOption["options"] ) )
                {
                $temp_content = "
                <tr class=\"option\">
                        <td class=\"option\">"
. $theOption["title"] . "$theError $theTip</td>
                        <td class=\"option\">"
;
                        foreach( $theOption["options"] as $key => $value )
                        {
                                $extralayer2 = "[" . $key . "]";
                               
                                $default = "";
                                if( $theOption["current"][$key] == 1 )
                                        $default = " checked";
                               
                                $temp_content .= "
                                <label><input type=\"checkbox\" name=\"$extralayer$extralayer2\" value=\"$key\"$default>{$value['title']}</label><small class=\"comment\">"
. parse_page_data($value['description']) . "</small>";
                        }
                $temp_content .= "
                        $theAlternateTip</td>
                </tr>"
;
                }
                else
                        $temp_content .= "<tr class=\"option\"><td class=\"option\" colspan=\"2\">" . i18n( "Error - The options argument is missing from the multicheck option named &quot;##0##&quot;", array( $theOption["title"] ) ) . "</td></tr>";
                return $temp_content;
                break;
        default:
                return "<tr class=\"option\"><td class=\"option\" colspan=\"2\">" . i18n("Error - this option has no type, or the type was not recognised!") . "</td></tr>";
                break;
        }
}

//! Settings editor class
class optionsPanel
{
        var $saveTitle;   ///< @var string The string to put in the Save options button
        var $revertTitle; ///< @var string The string to put in the Revert to saved button
        var $showHeader = true; ///< @var bool Wether or not to show the headers on the panel
        var $alternateTipPosition = false; ///< @var bool Wether to put the options' descriptions below the option or the title (default)
       
        var $submitted = false; ///< @var bool This becomes true, if the options panel was submitted
       
        /// \privatesection
        var $mainVarName; ///< @var string The name of the option panel's main name, first level of the array returned as POST data
        var $options;     ///< @var array An array of optionRow items
        var $submits;     ///< @var array An array of submit buttons in addition to the standard one
       
        /**
         * Creates a new instance of the optionsPanel class
         *
         * @param       string mainVarName      The name of the main variable - used mainly if you for some reason have more than one optionsPanel on the same page
         * @param       bool    alternativeTipPosition  If set to true, the tip will be placed below the value rather than the title of the option
         *
         * @return      optionsPanel
         */

        function optionsPanel( $mainVarName, $alternateTipPosition = false )
        {
                $this->mainVarName = $mainVarName;
                $this->saveTitle = i18n("Save options");
                $this->revertTitle = i18n("Revert to saved");
                $this->alternateTipPosition = $alternateTipPosition;
               
                if( array_key_exists( "saveOptions", $_POST ) )
                        $this->submitted = key($_POST["saveOptions"]);
        }
       
        /**
         * Adds a new option to the optionsPanel
         *
         * @param       string  title   The human-readable name for the option
         * @param       string  tip     A tip to show the user, which should describe the option in further depth.
         * @param       mixed   current The current value of the option
         * @param       string  name    The internal name of the option (should be the name used elsewhere in the code also)
         * @param       string  type    The type of option. Should be one of: label, text, password, textbox, pagedata, checkbox, datetime, time, date, radio, select, multicheck
         * @param       array   options Array containing the values used by checkbox, radio and select
         * For select the options parameter is an array with key/value sets with the options and descriptions of each element in the select, where current is the key of the currently chosen option
         * For radio and multicheck containing an array, with key/value sets with the options and title & descriptions of each element in the radio group, where current is the key of the currently chosen option. Format as such: key => array(title,description)
         * For date and datetime, optionally choose a start year and end year as elements in an array of the format 0 => startyear, 1 => endyear
         */

        function addOption( $title, $tip, $current, $name, $type, $options = "" )
        {
                $this->options[$name] = array(
                                        "title" => $title,
                                        "tip" => $tip,
                                        "current" => $current,
                                        "name" => $name,
                                        "type" => $type,
                                        "options" => $options
                                        );
               
                if( $this->submitted )
                {
                        if( $type == "checkbox" )
                        {
                                if( $this->mainVarName != "" && array_key_exists( $this->mainVarName, $_POST ) && is_array( $_POST[$this->mainVarName] ) )
                                        $this->options[$name]["current"] = $_POST[$this->mainVarName][$name] ? 1 : 0;
                                else if( is_array( $_POST ) && array_key_exists( "saveOptions", $_POST ) )
                                        $this->options[$name]["current"] = $_POST[$name] ? 1 : 0;
                        }
                        else if( $type == "datetime" )
                        {
                                if( $this->mainVarName != "" && array_key_exists( $this->mainVarName, $_POST ) && is_array( $_POST[$this->mainVarName] ) &&  array_key_exists( $name, $_POST[$this->mainVarName] ) )
                                        $this->options[$name]["current"] = mktime($_POST[$this->mainVarName][$name]["hour"], $_POST[$this->mainVarName][$name]["minute"], $_POST[$this->mainVarName][$name]["second"], $_POST[$this->mainVarName][$name]["month"], $_POST[$this->mainVarName][$name]["day"], $_POST[$this->mainVarName][$name]["year"]);
                                else if( is_array( $_POST ) &&  array_key_exists( $name, $_POST ) )
                                        $this->options[$name]["current"] = mktime($_POST[$name]["hour"], $_POST[$name]["minute"], $_POST[$name]["second"], $_POST[$name]["month"], $_POST[$name]["day"], $_POST[$name]["year"]);
                        }
                        else if( $type == "time" )
                        {
                                if( $this->mainVarName != "" && array_key_exists( $this->mainVarName, $_POST ) && is_array( $_POST[$this->mainVarName] ) &&  array_key_exists( $name, $_POST[$this->mainVarName] ) )
                                        $this->options[$name]["current"] = mktime($_POST[$this->mainVarName][$name]["hour"], $_POST[$this->mainVarName][$name]["minute"], 0, 0, 0, 0);
                                else if( is_array( $_POST ) &&  array_key_exists( $name, $_POST ) )
                                        $this->options[$name]["current"] = mktime($_POST[$name]["hour"], $_POST[$name]["minute"], 0, 0, 0, 0);
                        }
                        else if( $type == "date" )
                        {
                                if( $this->mainVarName != "" && array_key_exists( $this->mainVarName, $_POST ) && is_array( $_POST[$this->mainVarName] ) &&  array_key_exists( $name, $_POST[$this->mainVarName] ) )
                                        $this->options[$name]["current"] = mktime(0, 0, 0, $_POST[$this->mainVarName][$name]["month"], $_POST[$this->mainVarName][$name]["day"], $_POST[$this->mainVarName][$name]["year"]);
                                else if( is_array( $_POST ) &&  array_key_exists( $name, $_POST ) )
                                        $this->options[$name]["current"] = mktime(0, 0, 0, $_POST[$name]["month"], $_POST[$name]["day"], $_POST[$name]["year"]);
                        }
                        else if( $type == "multicheck" )
                        {
                                if( $this->mainVarName != "" && array_key_exists( $this->mainVarName, $_POST ) && is_array( $_POST[$this->mainVarName] ) )
                                {
                                        if( is_array( $_POST[$this->mainVarName][$name] ) )
                                        {
                                                foreach( $this->options[$name]["options"] as $key => $value )
                                                        $this->options[$name]["current"][$key] = array_key_exists( $key, $_POST[$this->mainVarName][$name] ) ? 1 : 0;
                                        }
                                        else
                                        {
                                                foreach( $this->options[$name]["options"] as $key => $value )
                                                        $this->options[$name]["current"][$key] = 0;
                                        }
                                }
                                else if( is_array( $_POST ) && array_key_exists( "saveOptions", $_POST ) )
                                {
                                        if( is_array( $_POST[$name] ) )
                                        {
                                                foreach( $this->options[$name]["options"] as $key => $value )
                                                        $this->options[$name]["current"][$key] = array_key_exists( $key, $_POST[$name] ) ? 1 : 0;
                                        }
                                        else
                                        {
                                                foreach( $this->options[$name]["options"] as $key => $value )
                                                        $this->options[$name]["current"][$key] = 0;
                                        }
                                }
                        }
                        else if( $type == "pagedata" )
                        {
                                if( $this->mainVarName != "" && array_key_exists( $this->mainVarName, $_POST ) && is_array( $_POST[$this->mainVarName] ) &&  array_key_exists( $name, $_POST[$this->mainVarName] ) )
                                        $this->options[$name]["current"] = $_POST[$this->mainVarName][$name];
                                else if( is_array( $_POST ) &&  array_key_exists( $name, $_POST ) )
                                        $this->options[$name]["current"] = $_POST[$name];
                        }
                        else
                        {
                                if( $this->mainVarName != "" && array_key_exists( $this->mainVarName, $_POST ) && is_array( $_POST[$this->mainVarName] ) &&  array_key_exists( $name, $_POST[$this->mainVarName] ) )
                                        $this->options[$name]["current"] = stripslashes($_POST[$this->mainVarName][$name]);
                                else if( is_array( $_POST ) &&  array_key_exists( $name, $_POST ) )
                                        $this->options[$name]["current"] = stripslashes($_POST[$name]);
                        }
                }
        }
       
        /**
         * Add a new header to the options panel
         *
         * @param       string  title   The human-readable title of the header
         * @param       string  name    The name used to identify the header (used for later editing of the item)
         */

        function addHeader( $title, $name )
        {
                $this->options[$name] = array(
                                        "title" => $title,
                                        "type" => "header",
                                        );
        }
       
        /**
         * Adds a new command at the bottom of the optionsPanel. Essentially, it puts a new submit button in the form next to the default save options button
         *
         * @param       string  title   The text which will be shown to the user (written on the button)
         * @param       string  name    The text used internally for identifying the control. Must not be "default"!
         */

        function addCommand( $title, $name )
        {
                $this->submits[$name] = $title;
        }
       
        /**
         * Get the current value of the option with the specified name
         *
         * @param       mixed   optionName      The name of the option you wish to fetch the value for
         */

        function getValue( $optionName )
        {
                return $this->options[$optionName]["current"];
        }
       
        /**
         * Renders the optionsPanel into HTML form, including a form element
         *
         * @return      string  The optionsPanel as a HTML form - including the form element (with the post url set to currentPage())
         */

        function renderForm()
        {
                return "<form action=\"" . thisPageURL() . "\" method=\"POST\">" . $this->render() . "</form>";
        }
       
        /**
         * Render the optionsPanel into HTML form
         *
         * @return      string  The optionsPanel as a HTML form. Does not include the actual form element (wrap the returned HTML in a form element)
         */

        function render()
        {
               
                $rendered_panel = "
                <table class=\"options\">"
;
               
                if( $this->showHeader )
                        $rendered_panel .= "
                <tr class=\"options\">
                        <th class=\"options\">"
. i18n("Option") . "</th>
                        <th class=\"options\">"
. i18n("Value") . "</th>
                </tr>"
;
               
                foreach( $this->options as $key => $value )
                        $rendered_panel .= renderOptionsRow( $value, $this->mainVarName, $this->alternateTipPosition );
               
                $submits = "";
                if( is_array( $this->submits ) )
                        foreach( $this->submits as $key => $value )
                                $submits .= "<input type=\"submit\" class=\"options_save\" name=\"saveOptions[$key]\" value=\"$value\" />";
               
                $rendered_panel .= "
                <tr class=\"options\">
                        <td width=\"50%\" class=\"options-bottomleft\"><input type=\"submit\" class=\"options_save\" name=\"saveOptions[default]\" value=\""
. $this->saveTitle . "\" />$submits</td>
                        <td width=\"50%\" class=\"options-bottomright\"><input type=\"reset\" class=\"options_reset\" value=\""
. $this->revertTitle . "\" /></td>
                </tr>
                </table>"
;
                return $rendered_panel;
        }
}

/**
 * Returns the pageID that corresponds to the globalID for the setup page
 *
 * @param       string  splitID The global ID to check
 *
 * @return      string  A string containing the URL corresponding to the globalID, if existing
 */

function globalID_setup( $splitID )
{
        $pageID = null;
       
        if( $splitID[0] == "updates" )
                $pageID = "17";
        else if( $splitID[0] == "setup" )
        {
                switch( $splitID[1] )
                {
                case null:
                        $pageID = "3";
                        break;
                case "users":
                        $pageID = "4";
                        if( array_key_exists( 2, $splitID ) )
                                $_REQUEST["action"] = $splitID[2];
                        if( array_key_exists( 3, $splitID ) )
                                $_REQUEST["username"] = $splitID[3];
                        break;
                case "pagesetup":
                        global $theAction, $deleteID;
                        $pageID = "5";
                        if( array_key_exists( 2, $splitID ) )
                                $theAction = $splitID[2];
                        if( array_key_exists( 3, $splitID ) )
                                $deleteID = $splitID[3];
                        break;
                case "editpage":
                        if( array_key_exists( 2, $splitID ) && array_key_exists( 3, $splitID ) )
                        {
                                global $editFrontpage, $theEditID, $theEditTitle, $theEditLanguage;
                                $pageID = "6";
                                $theEditLanguage = $splitID[2];
                                if( is_numeric( $splitID[3] ) )
                                {
                                        if( (int)$splitID[3] == 0 )
                                                $editFrontpage = true;
                                        else
                                                $theEditID = $splitID[3];
                                }
                                else
                                        $theEditTitle = $splitID[3];
                        }
                        else
                                $pageID = "5"; // If we don't have a page to edit, show the list of pages in stead
                        break;
                case "menusetup":
                        global $theAction, $theMenuID, $deleteComfirm;
                        $pageID = "7";
                        if( array_key_exists( 2, $splitID ) && $splitID[2] == "assign" && array_key_exists( 3, $splitID ) )
                        {
                                $theAction = "assign";
                                $theMenuID = $splitID[3];
                        }
                        else if( array_key_exists( 2, $splitID ) && $splitID[2] == "delete" && array_key_exists( 3, $splitID ) )
                        {
                                $theAction = "delete";
                                $theMenuID = $splitID[3];
                                if( array_key_exists( 4, $splitID ) && $splitID[4] == "confirm" )
                                        $deleteComfirm = true;
                        }
                        break;
                case "editmenu":
                        global $menuEditLanguage, $menuEditID, $menuEditTitle;
                        if( array_key_exists( 2, $splitID ) && array_key_exists( 3, $splitID ) )
                        {
                                $pageID = "8";
                                $menuEditLanguage = $splitID[2];
                                $menuEditID = $splitID[3];
                        }
                        else if( array_key_exists( 2, $splitID ) )
                        {
                                $pageID = "8";
                                $menuEditTitle = $splitID[2];
                        }
                        else
                                $pageID = "7";
                        break;
                case "themesetup":
                        global $setupAction, $setupAction, $themeDelete;
                        $pageID = "9";
                        if( $splitID[2] == "options" )
                                $setupAction = "options";
                        else if( $splitID[2] == "delete" && array_key_exists( 3, $splitID ) )
                                $setupAction = "delete";
                                $themeDelete = $splitID[3];
                        break;
                case "filesetup":
                        global $theAction, $deleteFile, $renameFrom;
                        $pageID = "11";
                        if( $splitID[2] == "upload" )
                                $theAction = "upload";
                        else if( $splitID[2] == "uploadcomplete" )
                                $theAction = "uploadcomplete";
                        else if( $splitID[2] == "delete" && array_key_exists( 3, $splitID ) )
                        {
                                $theAction = "delete";
                                $deleteFile = $splitID[3];
                        }
                        else if( $splitID[2] == "confirm_delete" && array_key_exists( 3, $splitID ) )
                        {
                                $theAction = "confirm_delete";
                                $deleteFile = $splitID[3];
                        }
                        else if( $splitID[2] == "rename" && array_key_exists( 3, $splitID ) )
                        {
                                $theAction = "rename";
                                $renameFrom = $splitID[3];
                        }
                        break;
                case "modulesetup":
                        global $theModule, $theModuleSection, $theModuleSubsection, $theModuleAction, $theModuleSubaction, $theModuleSubsubaction;
                        $pageID = "12";
                        if( array_key_exists( 2, $splitID ) )
                                $theModule = $splitID[2];
                       
                        /// TODO: Make use of the following!!! - search/replace $_REQUEST["module_section"], $_REQUEST["module_subsection"], $_REQUEST["module_action"]
                        /// Done, but needs implementing into blogger, events and gallery...
                        if( array_key_exists( 3, $splitID ) )
                                $theModuleSection = $splitID[3];
                        if( array_key_exists( 4, $splitID ) )
                                $theModuleSubsection = $splitID[4];
                        if( array_key_exists( 5, $splitID ) )
                                $theModuleAction = $splitID[5];
                        if( array_key_exists( 6, $splitID ) )
                        $theModuleSubaction = $splitID[6];
                        if( array_key_exists( 7, $splitID ) )
                                $theModuleSubsubaction = $splitID[7];
                       
                        break;
                case "help":
                        $pageID = "14";
                        break;
                case "requestpassword":
                        global $username;
                        $pageID = "15";
                        $username = $splitID[2];
                        break;
                case "options":
                        $pageID = "16";
                        break;
                default:
                        // Nothing
                }
                $_REQUEST["page_id"] = ($pageID != null) ? $pageID : $_REQUEST["page_id"];
        }
       
        return $pageID;
}

$modules_globalID[] = "globalID_setup";

$postFixed = false;
if(get_magic_quotes_gpc() && !$postFixed)
{
        function stripslashes_deep($value)
        {
                $value = is_array($value) ?
                array_map('stripslashes_deep', $value) :
                stripslashes($value);
               
                return $value;
        }
       
        $_POST = array_map('stripslashes_deep', $_POST);
        $postFixed = true;
}
?>