Index: plugins/aboutConfig/index.php
===================================================================
--- plugins/aboutConfig/index.php	(revision 2823)
+++ plugins/aboutConfig/index.php	(revision 2911)
@@ -4,5 +4,5 @@
 # This file is part of Dotclear 2.
 #
-# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
+# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear
 # Licensed under the GPL version 2.0 license.
 # See LICENSE file or
@@ -12,229 +12,136 @@
 if (!defined('DC_CONTEXT_ADMIN')) { return; }
 
-# Local navigation
-if (!empty($_POST['gs_nav'])) {
-	http::redirect($p_url.$_POST['gs_nav']);
-	exit;
-}
-if (!empty($_POST['ls_nav'])) {
-	http::redirect($p_url.$_POST['ls_nav']);
-	exit;
-}
-
-# Local settings update
-if (!empty($_POST['s']) && is_array($_POST['s']))
+class adminPageAboutConfig
 {
-	try
+	public static $p_url = 'plugin.php?p=aboutConfig';
+	
+	# Update local settings
+	public static function updLocal($form)
 	{
-		foreach ($_POST['s'] as $ns => $s)
-		{
-			$core->blog->settings->addNamespace($ns);
-
-			foreach ($s as $k => $v) 	{
-				$core->blog->settings->$ns->put($k,$v);
+		self::updSettings($form);
+	}
+	
+	# Update global settings
+	public static function updGlobal($form)
+	{
+		self::updSettings($form,true);
+	}
+	
+	# Update settings
+	protected static function updSettings($form,$global=false)
+	{
+		global $core,$_ctx;
+		
+		$part = $global ? 'global' : 'local';
+		$prefix = $part.'_';
+		
+		try {
+			foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {
+				$core->blog->settings->addNamespace($ns);
+				$ns_settings = $global ? 
+					$namespace->dumpGlobalSettings() : $namespace->dumpSettings();
+				
+				foreach ($ns_settings as $k => $v) {
+					// need to cast type
+					$f = (string) $form->{$prefix.$ns.'_'.$k};
+					settype($f,$v['type']);
+					
+					$core->blog->settings->$ns->put($k,$f,null,null,true,$global);
+					$form->{$prefix.$ns.'_'.$k} = $f;
+				}
 			}
-
 			$core->blog->triggerBlog();
+			
+			http::redirect(self::$p_url.'&upd=1&part='.$part);
 		}
-
-		dcPage::addSuccessNotice(__('Configuration successfully updated'));
-		http::redirect($p_url);
+		catch (Exception $e) {
+			$_ctx->addError($e->getMessage());
+		}
 	}
-	catch (Exception $e)
+	
+	# Set nav and settings forms
+	public static function setForms($global=false)
 	{
-		$core->error->add($e->getMessage());
+		global $core, $_ctx;
+		
+		$prefix = $global ? 'global_' : 'local_';
+		$action = $global ? 'updGlobal' : 'updLocal';
+		
+		if (!empty($_POST[$prefix.'nav'])) {
+			http::redirect(self::$p_url.$_POST[$prefix.'nav']);
+			exit;
+		}
+		
+		$nav_form = new dcForm($core,$prefix.'nav_form','plugin.php');
+		$settings_form = new dcForm($core,$prefix.'settings_form','plugin.php');
+		
+		$settings = $combo = array();
+		foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {
+			$ns_settings = $global ? 
+				$namespace->dumpGlobalSettings() : $namespace->dumpSettings();
+			
+			foreach ($ns_settings as $k => $v) {
+				$settings[$ns][$k] = $v;
+			}
+		}
+		
+		ksort($settings);
+		foreach ($settings as $ns => $s) {
+			$combo['#'.$prefix.$ns] = $ns;
+			ksort($s);
+			foreach ($s as $k => $v)	{
+				if ($v['type'] == 'boolean') {
+					$settings_form->addField(
+						new dcFieldCombo($prefix.$ns.'_'.$k,
+							'',array(1 => __('yes'),0 => __('no'))));
+				}
+				else {
+					$settings_form->addField(
+						new dcFieldText($prefix.$ns.'_'.$k,''));
+				}
+				$settings_form->{$prefix.$ns.'_'.$k} = $v['value'];
+			}
+		}
+		
+		$nav_form
+			->addField(
+				new dcFieldCombo($prefix.'nav','',$combo,array(
+					"label" => __('Goto:'))))
+			->addField(
+				new dcFieldSubmit($prefix.'nav_submit',__('OK')))
+			->addField(
+				new dcFieldHidden ('p','aboutConfig'))
+			;
+		
+		$settings_form
+			->addField(
+				new dcFieldSubmit($prefix.'submit',__('Save'),array(
+					'action' => array('adminPageAboutConfig',$action))))
+			->addField(
+				new dcFieldHidden ('p','aboutConfig'))
+			;
+		
+		$_ctx->{$prefix.'settings'} = $settings;
+		
+		$nav_form->setup();
+		$settings_form->setup();
 	}
 }
 
-# Global settings update
-if (!empty($_POST['gs']) && is_array($_POST['gs']))
-{
-	try
-	{
-		foreach ($_POST['gs'] as $ns => $s)
-		{
-			$core->blog->settings->addNamespace($ns);
+# Local settings forms
+adminPageAboutConfig::setForms();
 
-			foreach ($s as $k => $v) 	{
-				$core->blog->settings->$ns->put($k,$v,null,null,true,true);
-			}
+# Global settings forms
+adminPageAboutConfig::setForms(true);
 
-			$core->blog->triggerBlog();
-		}
-
-		dcPage::addSuccessNotice(__('Configuration successfully updated'));
-		http::redirect($p_url.'&part=global');
-	}
-	catch (Exception $e)
-	{
-		$core->error->add($e->getMessage());
-	}
+# Commons
+if (!empty($_GET['upd'])) {
+	$_ctx->setAlert(__('Configuration successfully updated'));
 }
-
-$part = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local';
-
-function settingLine($id,$s,$ns,$field_name,$strong_label)
-{
-	if ($s['type'] == 'boolean') {
-		$field = form::combo(array($field_name.'['.$ns.']['.$id.']',$field_name.'_'.$ns.'_'.$id),
-		array(__('yes') => 1, __('no') => 0),$s['value'] ? 1 : 0);
-	} else {
-		$field = form::field(array($field_name.'['.$ns.']['.$id.']',$field_name.'_'.$ns.'_'.$id),40,null,
-		html::escapeHTML($s['value']));
-	}
-
-	$slabel = $strong_label ? '<strong>%s</strong>' : '%s';
-
-	return
-	'<tr class="line">'.
-	'<td scope="row"><label for="'.$field_name.'_'.$ns.'_'.$id.'">'.sprintf($slabel,html::escapeHTML($id)).'</label></td>'.
-	'<td>'.$field.'</td>'.
-	'<td>'.$s['type'].'</td>'.
-	'<td>'.html::escapeHTML($s['label']).'</td>'.
-	'</tr>';
+if (!empty($_GET['upda'])) {
+	$_ctx->setAlert(__('Settings definition successfully updated'));
 }
+$_ctx->default_tab = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local';
+$_ctx->setBreadCrumb('about:config');
+$core->tpl->display('@aboutConfig/index.html.twig');
 ?>
-<html>
-<head>
-  <title>about:config</title>
-  <?php echo dcPage::jsPageTabs($part); ?>
-  <script type="text/javascript">
-	//<![CDATA[
-	$(function() {
-		$("#gs_submit").hide();
-		$("#ls_submit").hide();
-		$("#gs_nav").change(function() {
-			window.location = $("#gs_nav option:selected").val();
-		})
-		$("#ls_nav").change(function() {
-			window.location = $("#ls_nav option:selected").val();
-		})
-	});
-	//]]>
-	</script>
-</head>
-
-<body>
-<?php
-echo dcPage::breadcrumb(
-	array(
-		__('System') => '',
-		html::escapeHTML($core->blog->name) => '',
-		__('about:config') => ''
-	)).
-	dcPage::notices();
-?>
-
-<div id="local" class="multi-part" title="<?php echo sprintf(__('Settings for %s'),html::escapeHTML($core->blog->name)); ?>">
-<h3 class="out-of-screen-if-js"><?php echo sprintf(__('Settings for %s'),html::escapeHTML($core->blog->name)); ?></h3>
-
-<?php
-$table_header = '<div class="table-outer"><table class="settings" id="%s"><caption class="as_h3">%s</caption>'.
-'<thead>'.
-'<tr>'."\n".
-'  <th class="nowrap">Setting ID</th>'."\n".
-'  <th>'.__('Value').'</th>'."\n".
-'  <th>'.__('Type').'</th>'."\n".
-'  <th class="maximalx">'.__('Description').'</th>'."\n".
-'</tr>'."\n".
-'</thead>'."\n".
-'<tbody>';
-$table_footer = '</tbody></table></div>';
-
-$settings = array();
-foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {
-	foreach ($namespace->dumpSettings() as $k => $v) {
-		$settings[$ns][$k] = $v;
-	}
-}
-ksort($settings);
-if (count($settings) > 0) {
-	$ns_combo = array();
-	foreach ($settings as $ns => $s) {
-		$ns_combo[$ns] = '#l_'.$ns;
-	}
-	echo
-		'<form action="'.$p_url.'" method="post">'.
-		'<p class="anchor-nav">'.
-		'<label for="ls_nav" class="classic">'.__('Goto:').'</label> '.form::combo('ls_nav',$ns_combo).
-		' <input type="submit" value="'.__('Ok').'" id="ls_submit" />'.
-		'<input type="hidden" name="p" value="aboutConfig" />'.
-		$core->formNonce().'</p></form>';
-}
-?>
-
-<form action="<?php echo $p_url; ?>" method="post">
-
-<?php
-foreach ($settings as $ns => $s)
-{
-	ksort($s);
-	echo sprintf($table_header,'l_'.$ns,$ns);
-	foreach ($s as $k => $v)
-	{
-		echo settingLine($k,$v,$ns,'s',!$v['global']);
-	}
-	echo $table_footer;
-}
-?>
-
-<p><input type="submit" value="<?php echo __('Save'); ?>" />
-<input type="hidden" name="p" value="aboutConfig" />
-<?php echo $core->formNonce(); ?></p>
-</form>
-</div>
-
-<div id="global" class="multi-part" title="<?php echo __('Global settings'); ?>">
-<h3 class="out-of-screen-if-js"><?php echo __('Global settings'); ?></h3>
-
-<?php
-$settings = array();
-
-foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {
-	foreach ($namespace->dumpGlobalSettings() as $k => $v) {
-		$settings[$ns][$k] = $v;
-	}
-}
-
-ksort($settings);
-
-if (count($settings) > 0) {
-	$ns_combo = array();
-	foreach ($settings as $ns => $s) {
-		$ns_combo[$ns] = '#g_'.$ns;
-	}
-	echo
-		'<form action="'.$p_url.'" method="post">'.
-		'<p class="anchor-nav">'.
-		'<label for="gs_nav" class="classic">'.__('Goto:').'</label> '.form::combo('gs_nav',$ns_combo).' '.
-		'<input type="submit" value="'.__('Ok').'" id="gs_submit" />'.
-		'<input type="hidden" name="p" value="aboutConfig" />'.
-		$core->formNonce().'</p></form>';
-}
-?>
-
-<form action="<?php echo $p_url; ?>" method="post">
-
-<?php
-foreach ($settings as $ns => $s)
-{
-	ksort($s);
-	echo sprintf($table_header,'g_'.$ns,$ns);
-	foreach ($s as $k => $v)
-	{
-		echo settingLine($k,$v,$ns,'gs',false);
-	}
-	echo $table_footer;
-}
-?>
-
-<p><input type="submit" value="<?php echo __('Save'); ?>" />
-<input type="hidden" name="p" value="aboutConfig" />
-<?php echo $core->formNonce(); ?></p>
-</form>
-</div>
-
-<?php dcPage::helpBlock('aboutConfig'); ?>
-
-</body>
-</html>
