<?php
/**
 * This file is part of 
 * pragmaMx - Web Content Management System.
 * Copyright by pragmaMx Developer Team - http://www.pragmamx.org
 *
 * pragmaMx 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 3 of the License, or
 * (at your option) any later version.
 *
 * $Revision: 1.1 $
 * $Author: tora60 $
 * $Date: 2008/07/06 12:23:16 $
 */

defined('mxMainFileLoaded') or die('access denied');
#error_reporting(E_ALL);
$mxblockcache = false;

/* Maximale Stringlaenge des Theme-Namens im Selectfeld */
$maxwordlen = 15;

/* Maximale Anzahl der Zeilen des Selectfeldes */
$maxselectlines = 5;

/* verwendete Sprachvariablen */
$lang['Theme wechseln'] = 'Theme wechseln';
$lang['Seitenstandard'] = 'Seitenstandard';


/* Standardtheme zwischenspeichern */
$defaulttheme = $GLOBALS['Default_Theme'];

/* YA Aenderung abfangen */
if (isset($_REQUEST['name']) && $_REQUEST['name']=='Your_Account' && isset($_REQUEST['op']) && $_REQUEST['op']=='edithome'  && isset($_REQUEST['theme'])) {
    if (!empty($_REQUEST['theme']) && @file_exists('themes/' . $_REQUEST['theme'] . '/theme.php')) {
        $defaulttheme = $_REQUEST['theme'];
    }
}

if (isset($_COOKIE['themetest']) && @file_exists('themes/' . $_COOKIE['themetest'] . '/theme.php')) {
    $currenttheme = $_COOKIE['themetest'];
} else {
    $currenttheme = $defaulttheme;
}

$to = basename($_SERVER['PHP_SELF']);
// / index.php ist auch php_self=modules.php, deswegen hier index.php verwenden, falls $name leer ist
if ($to == 'modules.php' && empty($_REQUEST['name'])) {
    $to = './';
}

$hidden = array();
// die GET Parameter auslesen und (später) zu einem String zusammensetzen
foreach($_GET as $key => $value) {
    // themeselect nicht nochmals anfügen
    if ($key != 'themeselect') {
        $args[] = "{$key}={$value}";
        $hidden[] = '<input type="hidden" name="' . $key . '" value="' . $value . '" />';
    }
}

if (!empty($_GET['themeselect']) && $_GET['themeselect'] != $currenttheme && @file_exists("themes/" . $_GET['themeselect'] . "/theme.php")) {
    mxSetCookie('themetest', $_GET['themeselect'], 1);
    if (isset($args)) {
        $to .= '?' . implode('&', $args) . '';
    } else {
        $to .= '';
    }
    mxRedirect($to, '', 0);
    exit;
}

foreach (glob('themes/*/theme.php', GLOB_NOSORT ) as $filename) {
    $themelist[] = basename(dirname($filename));
}
natcasesort($themelist);

foreach ($themelist as $theme) {
    $selected = ($theme == $currenttheme) ? ' selected="selected" style="font-weight: bold;"' : '';
    $title = ($theme == $GLOBALS['Default_Theme']) ? $theme . ' (' . $lang['Seitenstandard'] . ')': $theme;
    $options[] = '<option value="' . $theme . '" title="' . $title . '"' . $selected . '>' . mxCutString($theme, $maxwordlen, '..', '') . '</option>';
}

if (count($options) < $maxselectlines) {
    $maxselectlines =  count($options);
}

/* Wenn der Block links oder rechts positioniert ist, die Breite auf fast 100% stellen */
$width = ($block['position'] == 'l' || $block['position'] == 'r') ? ' style="width: 99%;"' : '';

$content = '
<form action="' . $to . '" method="get">
' . implode("\n", $hidden) . '
<select name="themeselect" size="' . $maxselectlines . '"' . $width . '>
    ' . implode("\n    ", $options) . '
</select>
<input type="submit" value="' . $lang['Theme wechseln'] . '">
</form>
';
# _CHANGETHEME onchange="showthemeimage();"
?>