Dotclear

source: plugins/aboutConfig/index.php @ 581:dbfb5e376275

Revision 581:dbfb5e376275, 4.3 KB checked in by Franck <carnet.franck.paul@…>, 14 years ago (diff)

Mise en accessibilité des tables (about:Config et user:Prefs)

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2011 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 scope="raw"><label for="s_'.$id.'">'.sprintf($slabel,html::escapeHTML($id)).'</label></td>'.
79     '<td>'.$field.'</td>'.
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  table.settings { border: 1px solid #999; margin-bottom: 2em; }
91  table.settings th { background: #f5f5f5; color: #444; padding-top: 0.3em; padding-bottom: 0.3em; }
92  </style>
93</head>
94
95<body>
96<?php
97if (!empty($_GET['upd'])) {
98     echo '<p class="message">'.__('Configuration successfully updated').'</p>';
99}
100
101if (!empty($_GET['upda'])) {
102     echo '<p class="message">'.__('Settings definition successfully updated').'</p>';
103}
104?>
105<h2><?php echo html::escapeHTML($core->blog->name); ?> &rsaquo; <span class="page-title">about:config</span></h2>
106
107<div id="local" class="multi-part" title="<?php echo __('blog settings'); ?>">
108<form action="plugin.php" method="post">
109
110<?php 
111
112$table_header = '<table class="settings"><caption>%s</caption>'.
113'<thead>'.
114'<tr>'."\n".
115'  <th class="nowrap">Setting ID</th>'."\n".
116'  <th>'.__('Value').'</th>'."\n".
117'  <th>'.__('Type').'</th>'."\n".
118'  <th class="maximalx">'.__('Description').'</th>'."\n".
119'</tr>'."\n".
120'</thead>'."\n".
121'<tbody>';
122$table_footer = '</tbody></table>';
123
124$settings = array();
125
126foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {
127     foreach ($namespace->dumpSettings() as $k => $v) {
128          $settings[$ns][$k] = $v;
129     }
130}
131
132ksort($settings);
133
134foreach ($settings as $ns => $s)
135{
136     ksort($s);
137     echo sprintf($table_header,$ns);
138     foreach ($s as $k => $v)
139     {
140          echo settingLine($k,$v,$ns,'s',!$v['global']);
141     }
142     echo $table_footer;
143}
144?>
145
146<p><input type="submit" value="<?php echo __('Save'); ?>" />
147<input type="hidden" name="p" value="aboutConfig" />
148<?php echo $core->formNonce(); ?></p>
149</form>
150</div>
151
152<div id="global" class="multi-part" title="<?php echo __('global settings'); ?>">
153<form action="plugin.php" method="post">
154<?php
155$settings = array();
156
157foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {
158     foreach ($namespace->dumpGlobalSettings() as $k => $v) {
159          $settings[$ns][$k] = $v;
160     }
161}
162
163ksort($settings);
164
165foreach ($settings as $ns => $s)
166{
167     ksort($s);
168     echo sprintf($table_header,$ns);
169     foreach ($s as $k => $v)
170     {
171          echo settingLine($k,$v,$ns,'gs',false);
172     }
173     echo $table_footer;
174}
175?>
176
177<p><input type="submit" value="<?php echo __('Save'); ?>" />
178<input type="hidden" name="p" value="aboutConfig" />
179<?php echo $core->formNonce(); ?></p>
180</form>
181</div>
182
183</body>
184</html>
Note: See TracBrowser for help on using the repository browser.

Sites map