Dotclear

source: plugins/userPref/index.php @ 457:e2c2754452b1

Revision 457:e2c2754452b1, 4.5 KB checked in by Tomtom33 <tbouron@…>, 14 years ago (diff)

Fixed tables in admin pages - step 2, closes #1068,#1069

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2010 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     '<th scope="row"><label for="s_'.$id.'">'.sprintf($slabel,html::escapeHTML($id)).'</label></th>'.
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  .ws-name { background: #ccc; color: #000; padding-top: 0.3em; padding-bottom: 0.3em; font-size: 1.1em; }
87  </style>
88</head>
89
90<body>
91<?php
92if (!empty($_GET['upd'])) {
93     echo '<p class="message">'.__('Preferences successfully updated').'</p>';
94}
95
96if (!empty($_GET['upda'])) {
97     echo '<p class="message">'.__('Preferences definition successfully updated').'</p>';
98}
99?>
100<h2><?php echo html::escapeHTML($core->auth->userID()); ?> &rsaquo; user:preferences</h2>
101
102<div id="local" class="multi-part" title="<?php echo __('user preferences'); ?>">
103<form action="plugin.php" method="post">
104<table>
105<caption><?php echo __('Local user preferences list'); ?></caption>
106<thead>
107<tr>
108  <th scope="col" class="nowrap">Pref ID</th>
109  <th scope="col"><?php echo __('Value'); ?></th>
110  <th scope="col"><?php echo __('Type'); ?></th>
111  <th scope="col" class="maximal"><?php echo __('Description'); ?></th>
112</tr>
113</thead>
114<tbody>
115<?php
116$prefs = array();
117
118foreach ($core->auth->user_prefs->dumpWorkspaces() as $ws => $workspace) {
119     foreach ($workspace->dumpPrefs() as $k => $v) {
120          $prefs[$ws][$k] = $v;
121     }
122}
123
124ksort($prefs);
125
126foreach ($prefs as $ws => $s)
127{
128     ksort($s);
129     echo '<tr><th scope="row" colspan="4" class="ws-name">workspace: <strong>'.$ws.'</strong></th></tr>';
130     
131     foreach ($s as $k => $v)
132     {
133          echo prefLine($k,$v,$ws,'s',!$v['global']);
134     }
135}
136?>
137</tbody>
138</table>
139<p><input type="submit" value="<?php echo __('Save'); ?>" />
140<input type="hidden" name="p" value="userPref" />
141<?php echo $core->formNonce(); ?></p>
142</form>
143</div>
144
145<div id="global" class="multi-part" title="<?php echo __('global preferences'); ?>">
146<form action="plugin.php" method="post">
147<table>
148<caption><?php echo __('Global user preferences list'); ?></caption>
149<thead>
150<tr>
151  <th scope="col" class="nowrap">Pref ID</th>
152  <th scope="col"><?php echo __('Value'); ?></th>
153  <th scope="col"><?php echo __('Type'); ?></th>
154  <th scope="col" class="maximal"><?php echo __('Description'); ?></th>
155</tr>
156</thead>
157<tbody>
158<?php
159$prefs = array();
160
161foreach ($core->auth->user_prefs->dumpWorkspaces() as $ws => $workspace) {
162     foreach ($workspace->dumpGlobalPrefs() as $k => $v) {
163          $prefs[$ws][$k] = $v;
164     }
165}
166
167ksort($prefs);
168
169foreach ($prefs as $ws => $s)
170{
171     ksort($s);
172     echo '<tr><th scope="row" colspan="4" class="ws-name">workspace: <strong>'.$ws.'</strong></th></tr>';
173     
174     foreach ($s as $k => $v)
175     {
176          echo prefLine($k,$v,$ws,'gs',false);
177     }
178}
179?>
180</tbody>
181</table>
182<p><input type="submit" value="<?php echo __('Save'); ?>" />
183<input type="hidden" name="p" value="userPref" />
184<?php echo $core->formNonce(); ?></p>
185</form>
186</div>
187
188</body>
189</html>
Note: See TracBrowser for help on using the repository browser.

Sites map