<?

if($_SESSION['UserData']['level'] != 10){

	die(header('Location:'._RootUrl));
}

$show_configs = array('error_reporting', 'date_default_timezone_set', 'define:_defaultLanguage', 'define:_SQL', 'define:sqlconf[host]', 'define:sqlconf[port]', 'define:sqlconf[database]', 'define:sqlconf[user]', 'define:sqlconf[password]', 'define:sqlconf[error_report_email]', 'define:sqlconf[show_error]', 'define:_Template', 'define:_TemplateGraphicAdmin', 'define:_TemplateGraphicAjax', 'define:_TemplateGraphicPublic');
$conf = file_get_contents(_RootFolder.'/inc/conf.php');

if($_POST['update']){

	foreach($_POST['full'] as $k => $v){

		$old_value = $v;
		if(preg_match("/\'/i", $_POST['old_conf'][$k]))
			$new_value = str_replace($_POST['old_conf'][$k], "'".$_POST['conf'][$k]."'", $old_value);
		else if(preg_match('/\"/i', $_POST['old_conf'][$k]))
			$new_value = str_replace($_POST['old_conf'][$k], '"'.$_POST['conf'][$k].'"', $old_value);
		else
			$new_value = str_replace($_POST['old_conf'][$k], $_POST['conf'][$k], $old_value);

		$conf = str_replace($old_value, $new_value, $conf);
	}
	//$this->pre($_POST);
	file_put_contents(_RootFolder.'/inc/conf.php', $conf);
}
?>


<form method="post">
<table>
<?PHP
foreach($show_configs as $k => $v){

	$phpF = '';
	$key = '';

	list($phpF, $key) = explode(':', $v);
	$key = str_replace('[', '\[', $key);
	$key = str_replace(']', '\]', $key);

	if($phpF && $key){

		preg_match_all('/'.$phpF.'(.*?)\((.*?)\)/se', $conf, $matches);
		foreach($matches[2] as $k2 => $v2){

			if(preg_match('/\''.$key.'\'/i', $v2) || preg_match('/\"'.$key.'\"/i', $v2)){

				list($dk, $dv) = explode(',', $v2);

				echo '<tr>';

				echo '<td><b>'.$phpF.'('.str_replace("'", '', $dk).')</b></td>
				<td><input type="hidden" name="full['.$k.']" value="'.trim($matches[0][$k2]).'"/><input type="hidden" name="old_conf['.$k.']" value="'.trim($dv).'"/><input type="text" name="conf['.$k.']" value="'.trim(str_replace("'", "", $dv)).'" style="width:400px;"/></td>';

				echo '</tr>';
			}
		}
	}
	else{

		preg_match('/'.$phpF.'(.*?)\((.*?)\)/se', $conf, $match);

		echo '<tr>';

		echo '<td><b>'.$phpF.'()</b></td>
		<td><input type="hidden" name="full['.$k.']" value="'.trim($match[0]).'"/><input type="hidden" name="old_conf['.$k.']" value="'.trim($match[2]).'"/><input type="text" name="conf['.$k.']" value="'.trim(str_replace("'", "", $match[2])).'" style="width:400px;"/></td>';

		echo '</tr>';
	}
}

?>
<tr>
	<td></td>
	<td><input type="submit" name="update" value="Update"/></td>
</tr>
</table>
</form>