Dotclear

source: plugins/userPref/index.php @ 2256:d3c3fa1723ab

Revision 2256:d3c3fa1723ab, 5.6 KB checked in by Dsls, 12 years ago (diff)

updated most of notices to new format, should fix #1710 (maintenance and daInstaller still to be updated)

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

Sites map