Hell,
I'm relitivly new to php and have been using it in my site, to allow me to change themes by chaning a variable taht I have as $Theme (i.e for Halloween theme $Theme = 'Halloween'; ), and for a while now i've been wanting to find a script to allow me to do this, and finally found one that is close, however it pulls up .html files as themes, how would I modify this code to have it change the variable $Theme?
<?
# Root MySQL database
$base = "theme";
# MySQL user name
$user = "";
# MySQL password
$password = "";
# Host name (ex. localhost)
$host = "localhost";
$cms_template= "template";
# -----------------------------------------
# CHOOSE THE DEFAULT TEMPLATE IF NO COOKIE
# -----------------------------------------
$default_theme = "./template1.html";
?>
<?
/* ------------------------------------------------------------ */
/* Theme Selector® Copyright 2003-2004 Microcyb, Inc. */
/* Software by: Microcyb */
/* Website: http://www.microcyb.com */
/* ------------------------------------------------------------ */
# -----------------------------------------------------------------------------
# START OF NEW CODE TO CALL THE SETTINGS AND START THE MYSQL CONNECTION
# -----------------------------------------------------------------------------
include_once ("./settings.php");
$link = mysql_connect($host,$user,$password);
mysql_select_db("$base");
# -----------------------------------------------------------------------------
# START OF NEW CODE TO CALL THE TEMPLATE IF NONE IS SELECTED
# -----------------------------------------------------------------------------
if (!$filename)
{
$filename=''.$default_theme.''.$template.'';
}
if(!$fd = @fopen($filename, "r"))
{
session_start();
$filename="$default_theme";;
setCookie ("filename","", time()+30240000);
}
# -----------------------------------------------------------------------------
# START OF NEW CODE TO CALL THE TEMPLATE IF NONE IS SELECTED
# -----------------------------------------------------------------------------
$theme .= '<form METHOD="POST" style="word-spacing: 0; margin: 0">
<select name="list" onChange="showpage(this.form);" class="input">
<option value="x">--------------</option>\n';
$result = mysql_query("SELECT * FROM $cms_template") or die ("Can't execute query.");
while(($row = mysql_fetch_object($result)))
{
$theme .= '<option value="'.$row->filename.'">'.$row->name.'</option>\n';
}
$theme .= '</select></form>
<script language="JavaScript">
function showpage(form)
{
document.cookie = "filename=\'\'";
var expireDate = new Date;
expireDate.setMonth(expireDate.getMonth()+6);
document.cookie = "filename=" + document.all.list.value + "; expires=" + expireDate.toGMTString();
parent.document.location=parent.document.location;
};
</script>';
# -----------------------------------------------------------------------------
# SET THE VARIBLE $SITE_MAIN TO HAVE INFORMATION
# -----------------------------------------------------------------------------
$site_main ="<b>Hello</b>, Microcyb here!<br>This is an exmaple of changing the look of your site!";
# -----------------------------------------------------------------------------
# NOW WE WRAP THE DATA AROUND AN HTML TEMPLATE
# -----------------------------------------------------------------------------
$template = fread ($fd, filesize ($filename));
fclose ($fd);
$template = stripslashes($template);
$template = eregi_replace("{main}", "$site_main", $template);
$template = eregi_replace("{theme}", "$theme", $template);
echo "$template";
?>