Location: PHPKode > projects > chillyCMS > chillyCMS/admin/settings.include.php
<?php
//#################################################################################################
//	Helper functions for the settings
//#################################################################################################
//	chillyCMS - Content Management System
//	Copyright (C) 2008
//	Stefanie Wiegand <hide@address.com> & Johannes Cox <hide@address.com>
//	
//	This program is licensed under the GPL 3.0 license. For more information see LICENSE.txt.
//#################################################################################################
//	load_settings()
//	save_settings()
//#################################################################################################
defined('DOIT') or die('Restricted access');

//Load Settings////////////////////////////////////////////////////////////////////////////////////
function load_settings() {
	global $l_sett,$l_gen,$settings;
	
	$db_language		= $settings["language"];
	$db_title		= $settings["sitename"];
	$db_mail		= $settings["siteemail"];
	$db_author		= $settings["author"];
	$db_keywords		= $settings["keywords"];
	$db_description		= $settings["description"];
	$db_backendstyle	= $settings["backendstyle"];
	$db_adv_settings	= intval($settings["adv_settings"]);
	$db_session_ltime	= intval($settings["session_ltime"]);
	$db_mod_rewrite		= intval($settings["mod_rewrite"]);
	$db_tbl_prefix		= $settings["tbl_prefix"];
	$db_offline_mode	= intval($settings["offline_mode"]);
	$db_offline_msg		= $settings["offline_msg"];
	$db_allowed_ftypes	= $settings["allowed_ftypes"];
	$db_filesize_limit	= intval($settings["filesize_limit"]);
	$db_max_menudepth	= intval($settings["max_menudepth"]);
	$db_debug_mode		= intval($settings["debug_mode"]);

	$languages=array();
	//Load all language files from language folder
	$handle = opendir(PATH."/languages");
	if ($handle) {
		while (false !== ($file = readdir($handle))) {
			if ($file != "." && $file != "..") {
				if (!is_dir($file)) {
					$fileending = substr($file, strlen($file) - 4);
					if ($fileending == ".php") {
						$file = substr($file, 0, -4);
						array_push($languages,$file);
					}
				}
			}	
		}
		closedir($handle);
	}
	//If no language file was found insert standard file (en.php)
	if (empty($languages)) { array_push($languages,"en"); }
	sort($languages);
	//Build form
	$settingsform = "\t<form method='post' action='settings.site.php'>\n".
	"\t\t<div class='settings'>\n".
	"\t\t\t<h1>$l_sett[lbl_sitesettings]</h1>\n".
	"\t\t\t<table width='100%'>\n".
	"\t\t\t\t<tr><td>$l_sett[lbl_language]</td><td>\n".
	"\t\t\t\t\t<select class='select' name='language' size='1'>\n";
	foreach ($languages as $l) {
		if ($l == $db_language) {
			$settingsform .= "\t\t\t\t\t\t<option selected='selected'>$l</option>\n";
		} else {
			$settingsform .= "\t\t\t\t\t\t<option>$l</option>\n";
		}
	}
	$settingsform .= "\t\t\t\t\t</select>\n".
	"\t\t\t\t</td></tr>\n".
	"\t\t\t\t<tr><td>$l_sett[lbl_pagetitle]</td>".
	"<td><input name='title' class=\"textinput\" value='$db_title' /></td></tr>\n".
	"\t\t\t\t<tr><td>$l_sett[lbl_author]</td>".
	"<td><input name='author' class=\"textinput\" value='$db_author' /></td></tr>\n".
	"\t\t\t\t<tr><td>$l_sett[lbl_email]</td>".
	"<td><input name='mail' class=\"textinput\" value='$db_mail' /></td></tr>\n".
	"\t\t\t\t<tr><td>$l_sett[lbl_keywords]</td>".
	"<td><textarea rows='2' class=\"textinput\" cols='' name='keywords'>$db_keywords</textarea></td></tr>\n".
	"\t\t\t\t<tr><td>$l_sett[lbl_description]</td>".
	"<td><textarea rows='5' class=\"textinput\" cols='' name='description'>$db_description</textarea></td></tr>\n".
	//backendstyle
	"\t\t\t\t<tr><td>$l_sett[lbl_bestyle]</td><td>\n".
	"\t\t\t\t\t<select name='backendstyle'>\n";
	if ($handle = opendir(PATH.'/style/css')) {
	//read all backend stylesheets
	while (false !== ($file = readdir($handle))) {
		$thisstyle=substr($file,0,-4);
		if (substr($file,-4)==".css" && $file!="installation.css" && $file!="backend.css" && $file!="frontend.css") {
			if ($db_backendstyle==$thisstyle) {
				$settingsform .= "\t\t\t\t\t\t<option selected='selected'>$thisstyle</option>\n";
			} else {
				$settingsform .= "\t\t\t\t\t\t<option>$thisstyle</option>\n";
			}
		}
	}
	closedir($handle);
	}
	$settingsform .= "\t\t\t\t\t</select>\n".
	"\t\t\t\t</td></tr>\n".
	"\t\t\t</table>\n".
	"\t\t\t<input type='hidden' name='action' value='save' /><br />\n".
	"\t\t\t<input type='hidden' name='oldbackendstyle' value='$db_backendstyle' /><br />\n".
	"\t\t</div>\n".
	//Advanced Settings
	"\t\t<div class='advancedsettings'>\n".
	"\t\t\t<input class='middle' type='checkbox' name='advswitch' id='advswitch' ".
	"onclick='toggle_display(\"advswitch\",\"advanced\")'";
	if ($db_adv_settings==1) { $settingsform .= " checked='checked'"; }
	$settingsform .= "/>\n".
	"\t\t\t<span class='middle'>$l_sett[lbl_showadv]</span><br />\n".
	"\t\t\t<div id='advanced' class='advanced'>\n".
	"\t\t\t\t<h3>$l_sett[lbl_advsett]</h3><br />\n".
	"\t\t\t\t<table width='100%'>\n".
	//--Session Lifetime
	"\t\t\t\t\t<tr><td class='left'><span class='floatleft'>$l_sett[lbl_sesslt]</span>".
	"<a class='info floatright' title='$l_sett[tip_sesslt]'></a></td>".
	"<td class='left'><input type='text' class=\"textinput\" name='sesslt' value='$db_session_ltime' /></td></tr>\n".
	//--Upload Limit
	"\t\t\t\t\t<tr><td class='left'><span class='floatleft'>$l_sett[lbl_upllim]</span>".
	"<a class='info floatright' title='$l_sett[tip_upllim]'></a></td>".
	"<td class='left'><input type='text' class=\"textinput\" name='upllim' value='$db_filesize_limit' /></td></tr>\n".
	//--Upload Filetypes
	"\t\t\t\t\t<tr><td class='left'><span class='floatleft'>$l_sett[lbl_uplft]</span></td>".
	"<td class='left'>".
	"<input type='text' class=\"textinput\" name='upltyp' value='$db_allowed_ftypes' />".
	"</td></tr>\n".
	//--Maintenance Mode?
	"\t\t\t\t\t<tr><td class='left'><span class='floatleft'>$l_sett[lbl_offlmod]</span></td>".
	"<td class='left'><input type='checkbox' class='middle' name='offlmode'";
	if ($db_offline_mode==1) { $settingsform .= " checked='checked'"; }
	$settingsform .= " /></td></tr>\n".
	//--Maintenance message
	"\t\t\t\t\t<tr><td class='left'><span class='floatleft'>$l_sett[lbl_offlmsg]</span>".
	"<a class='info floatright' title='$l_sett[tip_offlmsg]'></a></td>".
	"<td class='left'><textarea class=\"textinput\" rows='5' cols='' name='offlmsg'>$db_offline_msg</textarea></td></tr>\n".	
	//--mod_rewrite	TODO
	//"\t\t\t\t\t<tr><td class='left'><span class='floatleft'>$l_sett[lbl_modrw]</span>".
	//"<a class='info floatright' title='$l_sett[tip_modrw]'></a></td>".
	//"<td class='left'><input type='checkbox' class='middle' name='modrw'";
	//if ($db_mod_rewrite==1) { $settingsform .= " checked='checked'"; }
	//$settingsform .= " /></td></tr>\n".
	//--Table prefix TODO
	//"\t\t\t\t\t<tr><td class='left'><span class='floatleft'>$l_sett[lbl_tblpf]</span>".
	//"<a class='info floatright' title='$l_sett[tip_tblpf]'></a></td>".
	//"<td class='left'><input type='text' class=\"textinput\" name='tblprefix' value='$db_tbl_prefix' /></td></tr>\n".
	//--Max Menu depth
	"\t\t\t\t\t<tr><td class='left'><span class='floatleft'>$l_sett[lbl_maxmd]</span>".
	"<a class='info floatright' title='$l_sett[tip_maxmd]'></a></td>".
	"<td class='left'><input type='text' class=\"textinput\" name='maxdep' value='$db_max_menudepth' /></td></tr>\n".
	//--Debug Mode
	"\t\t\t\t\t<tr><td class='left'><span class='floatleft'>$l_sett[lbl_debug]</span></td>".
	"<td class='left'><input type='checkbox' class='middle' name='dbgmode'";
	if ($db_debug_mode==1) { $settingsform .= " checked='checked'"; }
	$settingsform .= " /></td></tr>\n".
	
	"\t\t\t\t</table>\n".
	"\t\t\t</div>\n".
	"\t\t<script type='text/javascript' language='JavaScript'>".
	"toggle_display(\"advswitch\",\"advanced\")</script>\n".
	"\t\t</div>\n".
	"\t\t<div class='clr'></div>\n".
	//save
	"\t\t<input class='button' type='submit' value='$l_gen[lbl_save]' />\n".
	"\t</form>\n".
	//reload	
	"\t<form action='settings.site.php'><input class='button' type='submit' value='$l_gen[lbl_reload]' /></form><br /><br />\n";
	
	return $settingsform;
}
//Save Settings////////////////////////////////////////////////////////////////////////////////////
function save_settings() {
	global $l_sett,$general,$mailchars,$page;
	$error=false;
	//$db=new Database();
	$post = escape($_POST);
	$sitelanguage	= $post["language"];
	$title		= $post["title"];
	$author		= $post["author"];
	$mail		= email_chars($post["mail"]);
	if ($mail!=$post["mail"]) {
		$mailchars = implode(" ",$mailchars);
		return array("$l_gen[msg_email_error] $mailchars","bad");
	}
	$keywords	= $post["keywords"];
	$description	= $post["description"];
	$backendstyle	= $post["backendstyle"];
	//advanced settings
	if (isset($post["advswitch"]) && $post["advswitch"]=="on") { $adv_settings=1; } else { $adv_settings=0; }
	$session_ltime	= intval($post["sesslt"]);
	if ($session_ltime<60) { $session_ltime=900; }
	if (isset($post["modrw"]) && $post["modrw"]=="on") { $mod_rewrite=1; } else { $mod_rewrite=0; }
	$filesize_limit	= $post["upllim"];
	$allowed_ftypes	= $post["upltyp"];
	if (isset($post["offlmode"]) && $post["offlmode"]=="on") { $offline_mode=1; } else { $offline_mode=0; }
	$offline_msg	= $post["offlmsg"];
	if (isset($post["tblprefix"])) { $tbl_prefix = "'".$post["tblprefix"]."'"; } else { $tbl_prefix = 'null'; }
	$max_menudepth	= intval($post["maxdep"]);
	if ($max_menudepth<1 or $max_menudepth>5) { $max_menudepth=2; }
	if (isset($post["dbgmode"]) && $post["dbgmode"]=="on") { $debug_mode=1; } else { $debug_mode=0; }

	$sql="update site_settings set `value` = case `key`".
	" when 'language'	then '$sitelanguage'".
	" when 'sitename'	then '$title'".
	" when 'author'		then '$author'".
	" when 'siteemail'	then '$mail'".
	" when 'keywords'	then '$keywords'".
	" when 'description'	then '$description'".
	" when 'backendstyle'	then '$backendstyle'".
	" when 'adv_settings'	then '$adv_settings'".
	" when 'session_ltime'	then '$session_ltime'".
	" when 'mod_rewrite'	then '$mod_rewrite'".	
	" when 'filesize_limit'	then '$filesize_limit'".
	" when 'allowed_ftypes'	then '$allowed_ftypes'".
	" when 'offline_mode'	then '$offline_mode'".
	" when 'offline_msg'	then '$offline_msg'".
	" when 'tbl_prefix'	then $tbl_prefix".
	" when 'max_menudepth'	then '$max_menudepth'".
	" when 'debug_mode'	then '$debug_mode'".
	" else `value` end";
	if (!$page->query($sql)) { $error=true; }
	
	if (!$error) {
		return array($l_sett["msg_save_ok"],"good");
	} else {
		return array($l_sett["msg_save_err"],"bad");
	}
} ?>
Return current item: chillyCMS