Dotclear

source: plugins/aboutConfig/index.php @ 1358:f117338392dc

Revision 1358:f117338392dc, 5.6 KB checked in by franck <carnet.franck.paul@…>, 11 years ago (diff)

Messages are now displayed below the breadcrumb, fixes #1528

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 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 navigation
15if (!empty($_POST['gs_nav'])) {
16     http::redirect($p_url.$_POST['gs_nav']);
17     exit;
18}
19if (!empty($_POST['ls_nav'])) {
20     http::redirect($p_url.$_POST['ls_nav']);
21     exit;
22}
23
24# Local settings update
25if (!empty($_POST['s']) && is_array($_POST['s']))
26{
27     try
28     {
29          foreach ($_POST['s'] as $ns => $s)
30          {
31               $core->blog->settings->addNamespace($ns);
32               
33               foreach ($s as $k => $v)      {
34                    $core->blog->settings->$ns->put($k,$v);
35               }
36               
37               $core->blog->triggerBlog();
38          }
39         
40          http::redirect($p_url.'&upd=1');
41     }
42     catch (Exception $e)
43     {
44          $core->error->add($e->getMessage());
45     }
46}
47
48# Global settings update
49if (!empty($_POST['gs']) && is_array($_POST['gs']))
50{
51     try
52     {
53          foreach ($_POST['gs'] as $ns => $s)
54          {
55               $core->blog->settings->addNamespace($ns);
56               
57               foreach ($s as $k => $v)      {
58                    $core->blog->settings->$ns->put($k,$v,null,null,true,true);
59               }
60               
61               $core->blog->triggerBlog();
62          }
63         
64          http::redirect($p_url.'&upd=1&part=global');
65     }
66     catch (Exception $e)
67     {
68          $core->error->add($e->getMessage());
69     }
70}
71
72$part = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local';
73
74function settingLine($id,$s,$ns,$field_name,$strong_label)
75{
76     if ($s['type'] == 'boolean') {
77          $field = form::combo(array($field_name.'['.$ns.']['.$id.']',$field_name.'_'.$id),
78          array(__('yes') => 1, __('no') => 0),$s['value'] ? 1 : 0);
79     } else {
80          $field = form::field(array($field_name.'['.$ns.']['.$id.']',$field_name.'_'.$id),40,null,
81          html::escapeHTML($s['value']));
82     }
83     
84     $slabel = $strong_label ? '<strong>%s</strong>' : '%s';
85     
86     return
87     '<tr class="line">'.
88     '<td scope="raw"><label for="s_'.$id.'">'.sprintf($slabel,html::escapeHTML($id)).'</label></td>'.
89     '<td>'.$field.'</td>'.
90     '<td>'.$s['type'].'</td>'.
91     '<td>'.html::escapeHTML($s['label']).'</td>'.
92     '</tr>';
93}
94?>
95<html>
96<head>
97  <title>about:config</title>
98  <?php echo dcPage::jsPageTabs($part); ?>
99  <script type="text/javascript">
100     //<![CDATA[
101     $(function() {
102          $("#gs_submit").hide();
103          $("#ls_submit").hide();
104          $("#gs_nav").change(function() {
105               window.location = $("#gs_nav option:selected").val();
106          })
107          $("#ls_nav").change(function() {
108               window.location = $("#ls_nav option:selected").val();
109          })
110     });
111     //]]>
112     </script>
113</head>
114
115<body>
116<?php
117echo dcPage::breadcrumb(
118     array(
119          __('System') => '',
120          html::escapeHTML($core->blog->name) => '',
121          '<span class="page-title">'.__('about:config').'</span>' => ''
122     ));
123if (!empty($_GET['upd'])) {
124     dcPage::message(__('Configuration successfully updated'));
125}
126
127if (!empty($_GET['upda'])) {
128     dcPage::message(__('Settings definition successfully updated'));
129}
130?>
131
132<div id="local" class="multi-part" title="<?php echo sprintf(__('Settings for %s'),html::escapeHTML($core->blog->name)); ?>">
133
134
135<?php
136$table_header = '<table class="settings" id="%s"><caption class="as_h3">%s</caption>'.
137'<thead>'.
138'<tr>'."\n".
139'  <th class="nowrap">Setting ID</th>'."\n".
140'  <th>'.__('Value').'</th>'."\n".
141'  <th>'.__('Type').'</th>'."\n".
142'  <th class="maximalx">'.__('Description').'</th>'."\n".
143'</tr>'."\n".
144'</thead>'."\n".
145'<tbody>';
146$table_footer = '</tbody></table>';
147
148$settings = array();
149foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {
150     foreach ($namespace->dumpSettings() as $k => $v) {
151          $settings[$ns][$k] = $v;
152     }
153}
154ksort($settings);
155if (count($settings) > 0) {
156     $ns_combo = array();
157     foreach ($settings as $ns => $s) {
158          $ns_combo[$ns] = '#l_'.$ns;
159     }
160     echo 
161          '<form action="plugin.php" method="post">'.
162          '<p class="anchor-nav">'.
163          '<label for="ls_nav" class="classic">'.__('Goto:').'</label> '.form::combo('ls_nav',$ns_combo).
164          ' <input type="submit" value="'.__('Ok').'" id="ls_submit" />'.
165          '<input type="hidden" name="p" value="aboutConfig" />'.
166          $core->formNonce().'</p></form>';
167}
168?>
169
170<form action="plugin.php" method="post">
171
172<?php
173foreach ($settings as $ns => $s)
174{
175     ksort($s);
176     echo sprintf($table_header,'l_'.$ns,$ns);
177     foreach ($s as $k => $v)
178     {
179          echo settingLine($k,$v,$ns,'s',!$v['global']);
180     }
181     echo $table_footer;
182}
183?>
184
185<p><input type="submit" value="<?php echo __('Save'); ?>" />
186<input type="hidden" name="p" value="aboutConfig" />
187<?php echo $core->formNonce(); ?></p>
188</form>
189</div>
190
191<div id="global" class="multi-part" title="<?php echo __('global settings'); ?>">
192
193<?php
194$settings = array();
195
196foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {
197     foreach ($namespace->dumpGlobalSettings() as $k => $v) {
198          $settings[$ns][$k] = $v;
199     }
200}
201
202ksort($settings);
203
204if (count($settings) > 0) {
205     $ns_combo = array();
206     foreach ($settings as $ns => $s) {
207          $ns_combo[$ns] = '#g_'.$ns;
208     }
209     echo 
210          '<form action="plugin.php" method="post">'.
211          '<p class="anchor-nav">'.
212          '<label for="gs_nav" class="classic">'.__('Goto:').'</label> '.form::combo('gs_nav',$ns_combo).
213          ' <input type="submit" value="'.__('Ok').'" id="gs_submit" />'.
214          '<input type="hidden" name="p" value="aboutConfig" />'.
215          $core->formNonce().'</p></form>';
216}
217?>
218
219<form action="plugin.php" method="post">
220
221<?php
222foreach ($settings as $ns => $s)
223{
224     ksort($s);
225     echo sprintf($table_header,'g_'.$ns,$ns);
226     foreach ($s as $k => $v)
227     {
228          echo settingLine($k,$v,$ns,'gs',false);
229     }
230     echo $table_footer;
231}
232?>
233
234<p><input type="submit" value="<?php echo __('Save'); ?>" />
235<input type="hidden" name="p" value="aboutConfig" />
236<?php echo $core->formNonce(); ?></p>
237</form>
238</div>
239
240</body>
241</html>
Note: See TracBrowser for help on using the repository browser.

Sites map