Dotclear

source: plugins/userPref/index.php @ 1293:529fcee6cbcd

Revision 1293:529fcee6cbcd, 5.6 KB checked in by Anne Kozlika <kozlika@…>, 12 years ago (diff)

SimpleMenu? moved in System menu and minor css adjustment.

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          http::redirect($p_url.'&upd=1');
39     }
40     catch (Exception $e)
41     {
42          $core->error->add($e->getMessage());
43     }
44}
45
46# Global prefs update
47if (!empty($_POST['gs']) && is_array($_POST['gs']))
48{
49     try
50     {
51          foreach ($_POST['gs'] as $ws => $s)
52          {
53               $core->auth->user_prefs->addWorkspace($ws);
54               
55               foreach ($s as $k => $v)      {
56                    $core->auth->user_prefs->$ws->put($k,$v,null,null,true,true);
57               }
58          }
59         
60          http::redirect($p_url.'&upd=1&part=global');
61     }
62     catch (Exception $e)
63     {
64          $core->error->add($e->getMessage());
65     }
66}
67
68$part = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local';
69
70function prefLine($id,$s,$ws,$field_name,$strong_label)
71{
72     if ($s['type'] == 'boolean') {
73          $field = form::combo(array($field_name.'['.$ws.']['.$id.']',$field_name.'_'.$id),
74          array(__('yes') => 1, __('no') => 0),$s['value'] ? 1 : 0);
75     } else {
76          $field = form::field(array($field_name.'['.$ws.']['.$id.']',$field_name.'_'.$id),40,null,
77          html::escapeHTML($s['value']));
78     }
79     
80     $slabel = $strong_label ? '<strong>%s</strong>' : '%s';
81     
82     return
83     '<tr>'.
84     '<td scope="raw"><label for="s_'.$id.'">'.sprintf($slabel,html::escapeHTML($id)).'</label></td>'.
85     '<td>'.$field.'</td>'.
86     '<td>'.$s['type'].'</td>'.
87     '<td>'.html::escapeHTML($s['label']).'</td>'.
88     '</tr>';
89}
90?>
91<html>
92<head>
93  <title>user:preferences</title>
94  <?php echo dcPage::jsPageTabs($part); ?>
95  <style type="text/css">
96     table.prefs { border: 1px solid #999; margin-bottom: 2em; }
97     table.prefs th { background: #f5f5f5; color: #444; padding-top: 0.3em; padding-bottom: 0.3em; }
98  </style>
99     <script type="text/javascript">
100     //<![CDATA[
101     $(function() {
102          $("#gp_submit").hide();
103          $("#lp_submit").hide();
104          $("#gp_nav").change(function() {
105               window.location = $("#gp_nav option:selected").val();
106          })
107          $("#lp_nav").change(function() {
108               window.location = $("#lp_nav option:selected").val();
109          })
110     });
111     //]]>
112     </script>
113</head>
114
115<body>
116<?php
117if (!empty($_GET['upd'])) {
118     dcPage::message(__('Preferences successfully updated'));
119}
120
121if (!empty($_GET['upda'])) {
122     dcPage::message(__('Preferences definition successfully updated'));
123}
124?>
125<h2><?php echo html::escapeHTML($core->auth->userID()); ?> &rsaquo; <span class="page-title">user:preferences</span></h2>
126
127<div id="local" class="multi-part" title="<?php echo __('user preferences'); ?>">
128
129<?php 
130$table_header = '<table class="prefs" id="%s"><caption>%s</caption>'.
131'<thead>'.
132'<tr>'."\n".
133'  <th class="nowrap">Setting ID</th>'."\n".
134'  <th>'.__('Value').'</th>'."\n".
135'  <th>'.__('Type').'</th>'."\n".
136'  <th class="maximalx">'.__('Description').'</th>'."\n".
137'</tr>'."\n".
138'</thead>'."\n".
139'<tbody>';
140$table_footer = '</tbody></table>';
141
142$prefs = array();
143foreach ($core->auth->user_prefs->dumpWorkspaces() as $ws => $workspace) {
144     foreach ($workspace->dumpPrefs() as $k => $v) {
145          $prefs[$ws][$k] = $v;
146     }
147}
148ksort($prefs);
149if (count($prefs) > 0) {
150     $ws_combo = array();
151     foreach ($prefs as $ws => $s) {
152          $ws_combo[$ws] = '#l_'.$ws;
153     }
154     echo 
155          '<form action="plugin.php" method="post">'.
156          '<p class="anchor-nav">'.
157          '<label for="lp_nav" class="classic">'.__('Goto:').'</label> '.form::combo('lp_nav',$ws_combo).
158          ' <input type="submit" value="'.__('Ok').'" id="lp_submit" />'.
159          '<input type="hidden" name="p" value="aboutConfig" />'.
160          $core->formNonce().'</p></form>';
161}
162?>
163
164<form action="plugin.php" method="post">
165
166<?php
167foreach ($prefs as $ws => $s)
168{
169     ksort($s);
170     echo sprintf($table_header,'l_'.$ws,$ws);
171     foreach ($s as $k => $v)
172     {
173          echo prefLine($k,$v,$ws,'s',!$v['global']);
174     }
175     echo $table_footer;
176}
177?>
178
179<p><input type="submit" value="<?php echo __('Save'); ?>" />
180<input type="hidden" name="p" value="userPref" />
181<?php echo $core->formNonce(); ?></p>
182</form>
183</div>
184
185<div id="global" class="multi-part" title="<?php echo __('global preferences'); ?>">
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="aboutConfig" />'.
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