Dotclear

source: plugins/aboutConfig/index.php @ 1334:bbbe0735f18b

Revision 1334:bbbe0735f18b, 5.7 KB checked in by franck <carnet.franck.paul@…>, 12 years ago (diff)

New dcPage::breadcrumb function, better way to use it, to be continued by me…

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>'.
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  <style type="text/css">
100  table.settings { border: 1px solid #999; margin-bottom: 2em; }
101  table.settings th { background: #f5f5f5; color: #444; padding-top: 0.3em; padding-bottom: 0.3em; }
102  </style>
103     <script type="text/javascript">
104     //<![CDATA[
105     $(function() {
106          $("#gs_submit").hide();
107          $("#ls_submit").hide();
108          $("#gs_nav").change(function() {
109               window.location = $("#gs_nav option:selected").val();
110          })
111          $("#ls_nav").change(function() {
112               window.location = $("#ls_nav option:selected").val();
113          })
114     });
115     //]]>
116     </script>
117</head>
118
119<body>
120<?php
121if (!empty($_GET['upd'])) {
122     dcPage::message(__('Configuration successfully updated'));
123}
124
125if (!empty($_GET['upda'])) {
126     dcPage::message(__('Settings definition successfully updated'));
127}
128dcPage::breadcrumb(
129     array(
130          __('System') => '',
131          '<span class="page-title">'.__('about:config').'</span>' => ''
132     ));
133?>
134
135<div id="local" class="multi-part" title="<?php echo sprintf(__('Settings for %s'),html::escapeHTML($core->blog->name)); ?>">
136
137
138<?php
139$table_header = '<table class="settings" id="%s"><caption>%s</caption>'.
140'<thead>'.
141'<tr>'."\n".
142'  <th class="nowrap">Setting ID</th>'."\n".
143'  <th>'.__('Value').'</th>'."\n".
144'  <th>'.__('Type').'</th>'."\n".
145'  <th class="maximalx">'.__('Description').'</th>'."\n".
146'</tr>'."\n".
147'</thead>'."\n".
148'<tbody>';
149$table_footer = '</tbody></table>';
150
151$settings = array();
152foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {
153     foreach ($namespace->dumpSettings() as $k => $v) {
154          $settings[$ns][$k] = $v;
155     }
156}
157ksort($settings);
158if (count($settings) > 0) {
159     $ns_combo = array();
160     foreach ($settings as $ns => $s) {
161          $ns_combo[$ns] = '#l_'.$ns;
162     }
163     echo 
164          '<form action="plugin.php" method="post">'.
165          '<p class="anchor-nav">'.
166          '<label for="ls_nav" class="classic">'.__('Goto:').'</label> '.form::combo('ls_nav',$ns_combo).
167          ' <input type="submit" value="'.__('Ok').'" id="ls_submit" />'.
168          '<input type="hidden" name="p" value="aboutConfig" />'.
169          $core->formNonce().'</p></form>';
170}
171?>
172
173<form action="plugin.php" method="post">
174
175<?php
176foreach ($settings as $ns => $s)
177{
178     ksort($s);
179     echo sprintf($table_header,'l_'.$ns,$ns);
180     foreach ($s as $k => $v)
181     {
182          echo settingLine($k,$v,$ns,'s',!$v['global']);
183     }
184     echo $table_footer;
185}
186?>
187
188<p><input type="submit" value="<?php echo __('Save'); ?>" />
189<input type="hidden" name="p" value="aboutConfig" />
190<?php echo $core->formNonce(); ?></p>
191</form>
192</div>
193
194<div id="global" class="multi-part" title="<?php echo __('global settings'); ?>">
195
196<?php
197$settings = array();
198
199foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {
200     foreach ($namespace->dumpGlobalSettings() as $k => $v) {
201          $settings[$ns][$k] = $v;
202     }
203}
204
205ksort($settings);
206
207if (count($settings) > 0) {
208     $ns_combo = array();
209     foreach ($settings as $ns => $s) {
210          $ns_combo[$ns] = '#g_'.$ns;
211     }
212     echo 
213          '<form action="plugin.php" method="post">'.
214          '<p class="anchor-nav">'.
215          '<label for="gs_nav" class="classic">'.__('Goto:').'</label> '.form::combo('gs_nav',$ns_combo).
216          ' <input type="submit" value="'.__('Ok').'" id="gs_submit" />'.
217          '<input type="hidden" name="p" value="aboutConfig" />'.
218          $core->formNonce().'</p></form>';
219}
220?>
221
222<form action="plugin.php" method="post">
223
224<?php
225foreach ($settings as $ns => $s)
226{
227     ksort($s);
228     echo sprintf($table_header,'g_'.$ns,$ns);
229     foreach ($s as $k => $v)
230     {
231          echo settingLine($k,$v,$ns,'gs',false);
232     }
233     echo $table_footer;
234}
235?>
236
237<p><input type="submit" value="<?php echo __('Save'); ?>" />
238<input type="hidden" name="p" value="aboutConfig" />
239<?php echo $core->formNonce(); ?></p>
240</form>
241</div>
242
243</body>
244</html>
Note: See TracBrowser for help on using the repository browser.

Sites map