Dotclear

source: plugins/userPref/index.php @ 581:dbfb5e376275

Revision 581:dbfb5e376275, 4.2 KB checked in by Franck <carnet.franck.paul@…>, 14 years ago (diff)

Mise en accessibilité des tables (about:Config et user:Prefs)

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2011 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 prefs update
15if (!empty($_POST['s']) && is_array($_POST['s']))
16{
17     try
18     {
19          foreach ($_POST['s'] as $ws => $s)
20          {
21               $core->auth->user_prefs->addWorkspace($ws);
22               
23               foreach ($s as $k => $v)      {
24                    $core->auth->user_prefs->$ws->put($k,$v);
25               }
26          }
27         
28          http::redirect($p_url.'&upd=1');
29     }
30     catch (Exception $e)
31     {
32          $core->error->add($e->getMessage());
33     }
34}
35
36# Global prefs update
37if (!empty($_POST['gs']) && is_array($_POST['gs']))
38{
39     try
40     {
41          foreach ($_POST['gs'] as $ws => $s)
42          {
43               $core->auth->user_prefs->addWorkspace($ws);
44               
45               foreach ($s as $k => $v)      {
46                    $core->auth->user_prefs->$ws->put($k,$v,null,null,true,true);
47               }
48          }
49         
50          http::redirect($p_url.'&upd=1&part=global');
51     }
52     catch (Exception $e)
53     {
54          $core->error->add($e->getMessage());
55     }
56}
57
58$part = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local';
59
60function prefLine($id,$s,$ws,$field_name,$strong_label)
61{
62     if ($s['type'] == 'boolean') {
63          $field = form::combo(array($field_name.'['.$ws.']['.$id.']',$field_name.'_'.$id),
64          array(__('yes') => 1, __('no') => 0),$s['value']);
65     } else {
66          $field = form::field(array($field_name.'['.$ws.']['.$id.']',$field_name.'_'.$id),40,null,
67          html::escapeHTML($s['value']));
68     }
69     
70     $slabel = $strong_label ? '<strong>%s</strong>' : '%s';
71     
72     return
73     '<tr>'.
74     '<td scope="raw"><label for="s_'.$id.'">'.sprintf($slabel,html::escapeHTML($id)).'</label></td>'.
75     '<td>'.$field.'</td>'.
76     '<td>'.$s['type'].'</td>'.
77     '<td>'.html::escapeHTML($s['label']).'</td>'.
78     '</tr>';
79}
80?>
81<html>
82<head>
83  <title>user:preferences</title>
84  <?php echo dcPage::jsPageTabs($part); ?>
85  <style type="text/css">
86     table.prefs { border: 1px solid #999; margin-bottom: 2em; }
87     table.prefs th { background: #f5f5f5; color: #444; padding-top: 0.3em; padding-bottom: 0.3em; }
88  </style>
89</head>
90
91<body>
92<?php
93if (!empty($_GET['upd'])) {
94     echo '<p class="message">'.__('Preferences successfully updated').'</p>';
95}
96
97if (!empty($_GET['upda'])) {
98     echo '<p class="message">'.__('Preferences definition successfully updated').'</p>';
99}
100?>
101<h2><?php echo html::escapeHTML($core->auth->userID()); ?> &rsaquo; <span class="page-title">user:preferences</span></h2>
102
103<div id="local" class="multi-part" title="<?php echo __('user preferences'); ?>">
104<form action="plugin.php" method="post">
105
106<?php 
107
108$table_header = '<table class="prefs"><caption>%s</caption>'.
109'<thead>'.
110'<tr>'."\n".
111'  <th class="nowrap">Setting ID</th>'."\n".
112'  <th>'.__('Value').'</th>'."\n".
113'  <th>'.__('Type').'</th>'."\n".
114'  <th class="maximalx">'.__('Description').'</th>'."\n".
115'</tr>'."\n".
116'</thead>'."\n".
117'<tbody>';
118$table_footer = '</tbody></table>';
119
120$prefs = array();
121
122foreach ($core->auth->user_prefs->dumpWorkspaces() as $ws => $workspace) {
123     foreach ($workspace->dumpPrefs() as $k => $v) {
124          $prefs[$ws][$k] = $v;
125     }
126}
127
128ksort($prefs);
129
130foreach ($prefs as $ws => $s)
131{
132     ksort($s);
133     echo sprintf($table_header,$ws);
134     foreach ($s as $k => $v)
135     {
136          echo prefLine($k,$v,$ws,'s',!$v['global']);
137     }
138     echo $table_footer;
139}
140?>
141
142<p><input type="submit" value="<?php echo __('Save'); ?>" />
143<input type="hidden" name="p" value="userPref" />
144<?php echo $core->formNonce(); ?></p>
145</form>
146</div>
147
148<div id="global" class="multi-part" title="<?php echo __('global preferences'); ?>">
149<form action="plugin.php" method="post">
150
151<?php
152$prefs = array();
153
154foreach ($core->auth->user_prefs->dumpWorkspaces() as $ws => $workspace) {
155     foreach ($workspace->dumpGlobalPrefs() as $k => $v) {
156          $prefs[$ws][$k] = $v;
157     }
158}
159
160ksort($prefs);
161
162foreach ($prefs as $ws => $s)
163{
164     ksort($s);
165     echo sprintf($table_header,$ws);
166     foreach ($s as $k => $v)
167     {
168          echo prefLine($k,$v,$ws,'gs',false);
169     }
170     echo $table_footer;
171}
172?>
173
174<p><input type="submit" value="<?php echo __('Save'); ?>" />
175<input type="hidden" name="p" value="userPref" />
176<?php echo $core->formNonce(); ?></p>
177</form>
178</div>
179
180</body>
181</html>
Note: See TracBrowser for help on using the repository browser.

Sites map