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…

RevLine 
[3]1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
[1179]6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
[3]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
[589]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
[3]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);
[2566]32
[3]33               foreach ($s as $k => $v)      {
34                    $core->auth->user_prefs->$ws->put($k,$v);
35               }
36          }
[2566]37
[2256]38          dcPage::addSuccessNotice(__('Preferences successfully updated'));
39          http::redirect($p_url);
[3]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);
[2566]55
[3]56               foreach ($s as $k => $v)      {
57                    $core->auth->user_prefs->$ws->put($k,$v,null,null,true,true);
58               }
59          }
[2566]60
[2256]61          dcPage::addSuccessNotice(__('Preferences successfully updated'));
62          http::redirect($p_url.'&part=global');
[3]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') {
[2254]75          $field = form::combo(array($field_name.'['.$ws.']['.$id.']',$field_name.'_'.$ws.'_'.$id),
[1109]76          array(__('yes') => 1, __('no') => 0),$s['value'] ? 1 : 0);
[3]77     } else {
[2254]78          $field = form::field(array($field_name.'['.$ws.']['.$id.']',$field_name.'_'.$ws.'_'.$id),40,null,
[3]79          html::escapeHTML($s['value']));
80     }
[2566]81
[3]82     $slabel = $strong_label ? '<strong>%s</strong>' : '%s';
[2566]83
[3]84     return
[1348]85     '<tr class="line">'.
[2254]86     '<td scope="row"><label for="'.$field_name.'_'.$ws.'_'.$id.'">'.sprintf($slabel,html::escapeHTML($id)).'</label></td>'.
[3]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); ?>
[589]97     <script type="text/javascript">
98     //<![CDATA[
99     $(function() {
[2685]100          $("#gp_submit,#lp_submit").hide();
101          $('#part-local,#part-global').tabload(function() {
102               $('.multi-part.active select.navigation option:first').attr('selected',true);
[2815]103          });
[589]104          $("#gp_nav").change(function() {
105               window.location = $("#gp_nav option:selected").val();
[2685]106          });
[589]107          $("#lp_nav").change(function() {
108               window.location = $("#lp_nav option:selected").val();
[2685]109          });
[589]110     });
111     //]]>
112     </script>
[3]113</head>
114
115<body>
116<?php
[1358]117echo dcPage::breadcrumb(
118     array(
119          __('System') => '',
120          html::escapeHTML($core->auth->userID()) => '',
[2166]121          __('user:preferences') => ''
[2256]122     )).
123     dcPage::notices();
[1358]124
[3]125?>
126
[1338]127<div id="local" class="multi-part" title="<?php echo __('User preferences'); ?>">
[2003]128<h3 class="out-of-screen-if-js"><?php echo __('User preferences'); ?></h3>
[581]129
[2566]130<?php
[2002]131$table_header = '<div class="table-outer"><table class="prefs" id="%s"><caption class="as_h3">%s</caption>'.
[581]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>';
[2002]141$table_footer = '</tbody></table></div>';
[581]142
[3]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}
[589]149ksort($prefs);
150if (count($prefs) > 0) {
151     $ws_combo = array();
152     foreach ($prefs as $ws => $s) {
153          $ws_combo[$ws] = '#l_'.$ws;
154     }
[2566]155     echo
[2824]156          '<form action="'.$core->adminurl->get('admin.plugin').'" method="post">'.
[589]157          '<p class="anchor-nav">'.
[2685]158          '<label for="lp_nav" class="classic">'.__('Goto:').'</label> '.form::combo('lp_nav',$ws_combo,'','navigation').
[589]159          ' <input type="submit" value="'.__('Ok').'" id="lp_submit" />'.
[2168]160          '<input type="hidden" name="p" value="userPref" />'.
[589]161          $core->formNonce().'</p></form>';
162}
163?>
[3]164
[2824]165<form action="<?php echo $core->adminurl->get('admin.plugin'); ?>" method="post">
[3]166
[589]167<?php
[3]168foreach ($prefs as $ws => $s)
169{
170     ksort($s);
[589]171     echo sprintf($table_header,'l_'.$ws,$ws);
[3]172     foreach ($s as $k => $v)
173     {
174          echo prefLine($k,$v,$ws,'s',!$v['global']);
175     }
[581]176     echo $table_footer;
[3]177}
178?>
[581]179
[220]180<p><input type="submit" value="<?php echo __('Save'); ?>" />
[3]181<input type="hidden" name="p" value="userPref" />
182<?php echo $core->formNonce(); ?></p>
183</form>
184</div>
185
[1338]186<div id="global" class="multi-part" title="<?php echo __('Global preferences'); ?>">
[2003]187<h3 class="out-of-screen-if-js"><?php echo __('Global preferences'); ?></h3>
[581]188
[3]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
[582]200if (count($prefs) > 0) {
[589]201     $ws_combo = array();
[582]202     foreach ($prefs as $ws => $s) {
[589]203          $ws_combo[$ws] = '#g_'.$ws;
[582]204     }
[2566]205     echo
[2824]206          '<form action="'.$core->adminurl->get('admin.plugin').'" method="post">'.
[589]207          '<p class="anchor-nav">'.
[2685]208          '<label for="gp_nav" class="classic">'.__('Goto:').'</label> '.form::combo('gp_nav',$ws_combo,'','navigation').
[589]209          ' <input type="submit" value="'.__('Ok').'" id="gp_submit" />'.
[2168]210          '<input type="hidden" name="p" value="userPref" />'.
[589]211          $core->formNonce().'</p></form>';
[582]212}
[589]213?>
[582]214
[2824]215<form action="<?php echo $core->adminurl->get('admin.plugin'); ?>" method="post">
[589]216
217<?php
[3]218foreach ($prefs as $ws => $s)
219{
220     ksort($s);
[589]221     echo sprintf($table_header,'g_'.$ws,$ws);
[3]222     foreach ($s as $k => $v)
223     {
224          echo prefLine($k,$v,$ws,'gs',false);
225     }
[581]226     echo $table_footer;
[3]227}
228?>
[581]229
[220]230<p><input type="submit" value="<?php echo __('Save'); ?>" />
[3]231<input type="hidden" name="p" value="userPref" />
232<?php echo $core->formNonce(); ?></p>
233</form>
234</div>
235
[2322]236<?php dcPage::helpBlock('userPref'); ?>
237
[3]238</body>
[1339]239</html>
Note: See TracBrowser for help on using the repository browser.

Sites map