Dotclear

source: plugins/userPref/index.php @ 2824:c7051e56fd3c

Revision 2824:c7051e56fd3c, 5.9 KB checked in by franck <carnet.franck.paul@…>, 11 years ago (diff)

Using dcAdminURL, work in progress on plugins…

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,#lp_submit").hide();
101          $('#part-local,#part-global').tabload(function() {
102               $('.multi-part.active select.navigation option:first').attr('selected',true);
103          });
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
117echo dcPage::breadcrumb(
118     array(
119          __('System') => '',
120          html::escapeHTML($core->auth->userID()) => '',
121          __('user:preferences') => ''
122     )).
123     dcPage::notices();
124
125?>
126
127<div id="local" class="multi-part" title="<?php echo __('User preferences'); ?>">
128<h3 class="out-of-screen-if-js"><?php echo __('User preferences'); ?></h3>
129
130<?php
131$table_header = '<div class="table-outer"><table class="prefs" id="%s"><caption class="as_h3">%s</caption>'.
132'<thead>'.
133'<tr>'."\n".
134'  <th class="nowrap">Setting ID</th>'."\n".
135'  <th>'.__('Value').'</th>'."\n".
136'  <th>'.__('Type').'</th>'."\n".
137'  <th class="maximalx">'.__('Description').'</th>'."\n".
138'</tr>'."\n".
139'</thead>'."\n".
140'<tbody>';
141$table_footer = '</tbody></table></div>';
142
143$prefs = array();
144foreach ($core->auth->user_prefs->dumpWorkspaces() as $ws => $workspace) {
145     foreach ($workspace->dumpPrefs() as $k => $v) {
146          $prefs[$ws][$k] = $v;
147     }
148}
149ksort($prefs);
150if (count($prefs) > 0) {
151     $ws_combo = array();
152     foreach ($prefs as $ws => $s) {
153          $ws_combo[$ws] = '#l_'.$ws;
154     }
155     echo
156          '<form action="'.$core->adminurl->get('admin.plugin').'" method="post">'.
157          '<p class="anchor-nav">'.
158          '<label for="lp_nav" class="classic">'.__('Goto:').'</label> '.form::combo('lp_nav',$ws_combo,'','navigation').
159          ' <input type="submit" value="'.__('Ok').'" id="lp_submit" />'.
160          '<input type="hidden" name="p" value="userPref" />'.
161          $core->formNonce().'</p></form>';
162}
163?>
164
165<form action="<?php echo $core->adminurl->get('admin.plugin'); ?>" method="post">
166
167<?php
168foreach ($prefs as $ws => $s)
169{
170     ksort($s);
171     echo sprintf($table_header,'l_'.$ws,$ws);
172     foreach ($s as $k => $v)
173     {
174          echo prefLine($k,$v,$ws,'s',!$v['global']);
175     }
176     echo $table_footer;
177}
178?>
179
180<p><input type="submit" value="<?php echo __('Save'); ?>" />
181<input type="hidden" name="p" value="userPref" />
182<?php echo $core->formNonce(); ?></p>
183</form>
184</div>
185
186<div id="global" class="multi-part" title="<?php echo __('Global preferences'); ?>">
187<h3 class="out-of-screen-if-js"><?php echo __('Global preferences'); ?></h3>
188
189<?php
190$prefs = array();
191
192foreach ($core->auth->user_prefs->dumpWorkspaces() as $ws => $workspace) {
193     foreach ($workspace->dumpGlobalPrefs() as $k => $v) {
194          $prefs[$ws][$k] = $v;
195     }
196}
197
198ksort($prefs);
199
200if (count($prefs) > 0) {
201     $ws_combo = array();
202     foreach ($prefs as $ws => $s) {
203          $ws_combo[$ws] = '#g_'.$ws;
204     }
205     echo
206          '<form action="'.$core->adminurl->get('admin.plugin').'" method="post">'.
207          '<p class="anchor-nav">'.
208          '<label for="gp_nav" class="classic">'.__('Goto:').'</label> '.form::combo('gp_nav',$ws_combo,'','navigation').
209          ' <input type="submit" value="'.__('Ok').'" id="gp_submit" />'.
210          '<input type="hidden" name="p" value="userPref" />'.
211          $core->formNonce().'</p></form>';
212}
213?>
214
215<form action="<?php echo $core->adminurl->get('admin.plugin'); ?>" method="post">
216
217<?php
218foreach ($prefs as $ws => $s)
219{
220     ksort($s);
221     echo sprintf($table_header,'g_'.$ws,$ws);
222     foreach ($s as $k => $v)
223     {
224          echo prefLine($k,$v,$ws,'gs',false);
225     }
226     echo $table_footer;
227}
228?>
229
230<p><input type="submit" value="<?php echo __('Save'); ?>" />
231<input type="hidden" name="p" value="userPref" />
232<?php echo $core->formNonce(); ?></p>
233</form>
234</div>
235
236<?php dcPage::helpBlock('userPref'); ?>
237
238</body>
239</html>
Note: See TracBrowser for help on using the repository browser.

Sites map