Location: PHPKode > projects > Simple Way to Usenet > libs/core/ajax/funcs/ajx_swaptheme.class.php
<?php
/**
 * 
 * 
 * @author  Benjamin Gillissen <hide@address.com>
 * 
 *	**************************************************************

	Copyright (C) 2009  Benjamin Gillissen
	
	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.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details at:
	http://www.gnu.org/copyleft/gpl.html

 *	**************************************************************
 */
class ajx_swaptheme extends ajax {
	
	public static function swaptheme($theme){
		parent::$CB = __FUNCTION__;
		if ( FALSE === themes::istheme($theme) ){ return parent::getReply(); }
		parent::addAssign("theme_imgvar","innerHTML", self::gen_variant('img', $theme) );
		parent::addAssign("theme_cssvar","innerHTML", self::gen_variant('css', $theme) );
		return parent::getReply();
	}
	
	private static function gen_variant($var, $theme){
		$use_custum	= configs::get('themes', 'themes', Array($theme,"custum_$var") );
		$opts		= configs::get('themes', 'themes', Array($theme,'vars', $var) );
		if ( $use_custum ){
			$opts['custum'] = Array('name'=>'Custum');
			$custum = themes::get_variant_key('custum_'.$var, $theme);
		}
		$o = '<select name="'.$var.'_'.$theme.'" onchange="xajax_swapthmvariant(\''.$var.'\', this.value)">';
		$active = themes::get_variant_key($var, $theme);
		foreach($opts as $k => &$data ){
			if ( $active == $k ){ $sel = 'selected'; } else { $sel = ''; }
			$o .= '<option value="'.$k.'" '.$sel.' >'.$data['name'].'</option>';
		}
		$o .= '</select>';
		if ( $use_custum ){ $o .= '<input type="text" name="custum_'.$var.'_'.$theme.'" value="'.$custum.'" />'; }
		return $o;
	}
	
}
Return current item: Simple Way to Usenet