Dotclear

source: plugins/aboutConfig/index.php @ 457:e2c2754452b1

Revision 457:e2c2754452b1, 4.6 KB checked in by Tomtom33 <tbouron@…>, 14 years ago (diff)

Fixed tables in admin pages - step 2, closes #1068,#1069

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2010 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12if (!defined('DC_CONTEXT_ADMIN')) { return; }
13
14# Local settings update
15if (!empty($_POST['s']) && is_array($_POST['s']))
16{
17     try
18     {
19          foreach ($_POST['s'] as $ns => $s)
20          {
21               $core->blog->settings->addNamespace($ns);
22               
23               foreach ($s as $k => $v)      {
24                    $core->blog->settings->$ns->put($k,$v);
25               }
26               
27               $core->blog->triggerBlog();
28          }
29         
30          http::redirect($p_url.'&upd=1');
31     }
32     catch (Exception $e)
33     {
34          $core->error->add($e->getMessage());
35     }
36}
37
38# Global settings update
39if (!empty($_POST['gs']) && is_array($_POST['gs']))
40{
41     try
42     {
43          foreach ($_POST['gs'] as $ns => $s)
44          {
45               $core->blog->settings->addNamespace($ns);
46               
47               foreach ($s as $k => $v)      {
48                    $core->blog->settings->$ns->put($k,$v,null,null,true,true);
49               }
50               
51               $core->blog->triggerBlog();
52          }
53         
54          http::redirect($p_url.'&upd=1&part=global');
55     }
56     catch (Exception $e)
57     {
58          $core->error->add($e->getMessage());
59     }
60}
61
62$part = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local';
63
64function settingLine($id,$s,$ns,$field_name,$strong_label)
65{
66     if ($s['type'] == 'boolean') {
67          $field = form::combo(array($field_name.'['.$ns.']['.$id.']',$field_name.'_'.$id),
68          array(__('yes') => 1, __('no') => 0),$s['value']);
69     } else {
70          $field = form::field(array($field_name.'['.$ns.']['.$id.']',$field_name.'_'.$id),40,null,
71          html::escapeHTML($s['value']));
72     }
73     
74     $slabel = $strong_label ? '<strong>%s</strong>' : '%s';
75     
76     return
77     '<tr>'.
78     '<td><label for="s_'.$id.'">'.sprintf($slabel,html::escapeHTML($id)).'</label></td>'.
79     '<th scope="row">'.$field.'</th>'.
80     '<td>'.$s['type'].'</td>'.
81     '<td>'.html::escapeHTML($s['label']).'</td>'.
82     '</tr>';
83}
84?>
85<html>
86<head>
87  <title>about:config</title>
88  <?php echo dcPage::jsPageTabs($part); ?>
89  <style type="text/css">
90  .ns-name { background: #dfdfdf; color: #333; padding-top: 0.3em; padding-bottom: 0.3em; font-size: 1.1em; }
91  </style>
92</head>
93
94<body>
95<?php
96if (!empty($_GET['upd'])) {
97     echo '<p class="message">'.__('Configuration successfully updated').'</p>';
98}
99
100if (!empty($_GET['upda'])) {
101     echo '<p class="message">'.__('Settings definition successfully updated').'</p>';
102}
103?>
104<h2><?php echo html::escapeHTML($core->blog->name); ?> &rsaquo; about:config</h2>
105
106<div id="local" class="multi-part" title="<?php echo __('blog settings'); ?>">
107<form action="plugin.php" method="post">
108<table>
109<caption><?php echo __('Local blog settings list'); ?></caption>
110<thead>
111<tr>
112  <th scope="col" class="nowrap">Setting ID</th>
113  <th scope="col"><?php echo __('Value'); ?></th>
114  <th scope="col"><?php echo __('Type'); ?></th>
115  <th scope="col" class="maximal"><?php echo __('Description'); ?></th>
116</tr>
117</thead>
118<tbody>
119<?php
120$settings = array();
121
122foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {
123     foreach ($namespace->dumpSettings() as $k => $v) {
124          $settings[$ns][$k] = $v;
125     }
126}
127
128ksort($settings);
129
130foreach ($settings as $ns => $s)
131{
132     ksort($s);
133     echo '<tr><th scope="row" colspan="4" class="ns-name">namespace: <strong>'.$ns.'</strong></th></tr>';
134     
135     foreach ($s as $k => $v)
136     {
137          echo settingLine($k,$v,$ns,'s',!$v['global']);
138     }
139}
140?>
141</tbody>
142</table>
143<p><input type="submit" value="<?php echo __('Save'); ?>" />
144<input type="hidden" name="p" value="aboutConfig" />
145<?php echo $core->formNonce(); ?></p>
146</form>
147</div>
148
149<div id="global" class="multi-part" title="<?php echo __('global settings'); ?>">
150<form action="plugin.php" method="post">
151<table>
152<caption><?php echo __('Global blog settings list'); ?></caption>
153<thead>
154<tr>
155  <th scope="col" class="nowrap">Setting ID</th>
156  <th scope="col"><?php echo __('Value'); ?></th>
157  <th scope="col"><?php echo __('Type'); ?></th>
158  <th scope="col" class="maximal"><?php echo __('Description'); ?></th>
159</tr>
160</thead>
161<tbody>
162<?php
163$settings = array();
164
165foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {
166     foreach ($namespace->dumpGlobalSettings() as $k => $v) {
167          $settings[$ns][$k] = $v;
168     }
169}
170
171ksort($settings);
172
173foreach ($settings as $ns => $s)
174{
175     ksort($s);
176     echo '<tr><th scope="row" colspan="4" class="ns-name">namespace: <strong>'.$ns.'</strong></th></tr>';
177     
178     foreach ($s as $k => $v)
179     {
180          echo settingLine($k,$v,$ns,'gs',false);
181     }
182}
183?>
184</tbody>
185</table>
186<p><input type="submit" value="<?php echo __('Save'); ?>" />
187<input type="hidden" name="p" value="aboutConfig" />
188<?php echo $core->formNonce(); ?></p>
189</form>
190</div>
191
192</body>
193</html>
Note: See TracBrowser for help on using the repository browser.

Sites map