Location: PHPKode > projects > Cynus > cynus/admin_config_func.php
<?php
/**
 * @file modules/config/index.php -- Configuration Module
 * @Id $Id: admin_config_func.php,v 1.4 2004/07/29 17:03:56 jason Exp $
 *
 * Cynus - a web-based content manager
 * Copyright (C) 2003 Brett and Jason Profitt
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */
/******************
Config Module 
Used to modify the config table through the web
config
Jason Profitt
******************/


/************************
Config List Sections: string config_list_sections()
Reads the config table and finds out what sections exist.
Then, it spits those out as links so you can edit
the config variables
************************/
function config_list_sections() {
	global $config;
	$submenu=array(
		'Home' => 'index.php',
		'Config Home' => ''
	);
	$content .= cynus_submenu($submenu);
	set_page_title('Online Cynus Configuration');
	$query="SELECT * from `$config[sql_prefix]config` WHERE `field_type` != 'hidden' ORDER by `section`";
	$result=mysql_query($query);
	$last_section="";
	$content .= 'These are the sections available for you to edit:<br />' . "\n";
	while($each_var=mysql_fetch_assoc($result)) {
		if($last_section != $each_var['section']) {
			$content .= "<a href=\"admin.php?action=config&op=edit&section=$each_var[section]\">$each_var[section]</a><br />\n";
			$last_section=$each_var['section'];
		}
	}
	return $content;
}


/**************************
Config Edit Section: string config_edit_section()
Takes $_GET[section] and spits out the variables associated
with it so that the user can edit them
**************************/
function config_edit_section() {
	global $config;
	$submenu=array(
		'Home' => 'index.php',
		'Config Home' => 'admin.php?action=config',
		'Configuring Variables' => ''
	);
	$content .= cynus_submenu($submenu);
	set_page_title('Configuring Variables');
	if($_GET['section']=="") {
		cynus_error("You must select a section to edit.");
	}
	elseif($_GET['section']=='hidden') {
		cynus_error('You cannot edit hidden variables!');
	}
	elseif($_POST['sent']==1) {
		$query="SELECT * from `$config[sql_prefix]config` WHERE `section`='$_GET[section]' ORDER by `name`";
		$result=mysql_query($query);
		while($each_var=mysql_fetch_assoc($result)) {
			$var_name=$each_var[name];
			if($_POST[$var_name] != "") {
				$query="UPDATE `$config[sql_prefix]config` SET `value`='$_POST[$var_name]' WHERE `name`='$var_name'";
				mysql_query($query);
			}
		}
		$_POST['sent']="";
		//$content .= config_edit_section();
		header('Location: admin.php?action=config&op=edit&section=' . $_GET['section'] . '&done=1');
	}
	else{
		if($_GET['done']==1) {
			$content .= 'Successfully editted the variables.<br />Some changes may not come into effect until you reload Cynus.<br />';
		}
		$content .= <<<___eofh
<form method="POST" action="admin.php?action=config&op=edit&section=$_GET[section]">
<input type="hidden" name="sent" value="1">
<table class="table-general">
	<tr>
		<td class="table-header">Value</td>
		<td class="table-header">Description</td>
	</tr>\n
___eofh;

		$row='row1';
		$next_row='row2';
		$temp='row1';
		$query="SELECT * from `$config[sql_prefix]config` WHERE `section`='$_GET[section]' AND `field_type` != 'hidden' ORDER by `name`";
		$result=mysql_query($query);
		while($each_var=mysql_fetch_assoc($result)) {
			if($each_var['field_type']=='textarea') {
				$value="<textarea cols=\"50\" rows=\"6\" name=\"$each_var[name]\">$each_var[value]</textarea>\n";
			}
			elseif($each_var['field_type']=='int') {
				$value="<input type=\"text\" name=\"$each_var[name]\" value=\"$each_var[value]\" size=\"3\" />\n";
			}
			elseif($each_var['field_type']=='boolean') {
				$value="<select name=\"$each_var[name]\">\n";
				if($each_var['value']==1) {
					$value.=<<<___eofh
	<option value="0">No</option>
	<option value="1" selected>Yes</option>
</select>
___eofh;
				}
				else {
					$value.=<<<___eofh
	<option value="0" selected>No</option>
	<option value="1">Yes</option>
</select>
___eofh;
				}
				$value .= '</selected>';
			}
			else {
				$value="<input type=\"text\" name=\"$each_var[name]\" value=\"$each_var[value]\" size=\"35\"/>\n";
			}
			$content .= <<<___eofh
	<tr class="$row">
		<td style="vertical-align:middle">
			$value
		</td>
		<td>
			<span style="font-weight:bold;">$each_var[name]</span> - 
			$each_var[description]
		</td>
	</tr>\n
___eofh;
			$row=$next_row;
			$next_row=$temp;
			$temp=$row;
		}
		$content .= <<<___eofh
</table>
<input type="submit" value="Edit Variables" class="button" />
<input type="reset" value="Reset Values" class="button"/>
</form>\n
___eofh;
	}
	return $content;
}

?>
Return current item: Cynus