Dotclear

source: plugins/userPref/index.php @ 582:1f624beae675

Revision 582:1f624beae675, 4.6 KB checked in by Franck <carnet.franck.paul@…>, 14 years ago (diff)

Menu d'accès rapide

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     ul.submenu {float: right; border: 1px solid #ccc; padding-right: 1em; padding-left: 1.5em; margin-top:0.5em; margin-bottom:0.5em; }
89  </style>
90</head>
91
92<body>
93<?php
94if (!empty($_GET['upd'])) {
95     echo '<p class="message">'.__('Preferences successfully updated').'</p>';
96}
97
98if (!empty($_GET['upda'])) {
99     echo '<p class="message">'.__('Preferences definition successfully updated').'</p>';
100}
101?>
102<h2><?php echo html::escapeHTML($core->auth->userID()); ?> &rsaquo; <span class="page-title">user:preferences</span></h2>
103
104<div id="local" class="multi-part" title="<?php echo __('user preferences'); ?>">
105<form action="plugin.php" method="post">
106
107<?php 
108
109$table_header = '<table class="prefs"><caption>%s</caption>'.
110'<thead>'.
111'<tr>'."\n".
112'  <th class="nowrap">Setting ID</th>'."\n".
113'  <th>'.__('Value').'</th>'."\n".
114'  <th>'.__('Type').'</th>'."\n".
115'  <th class="maximalx">'.__('Description').'</th>'."\n".
116'</tr>'."\n".
117'</thead>'."\n".
118'<tbody>';
119$table_footer = '</tbody></table>';
120
121$prefs = array();
122
123foreach ($core->auth->user_prefs->dumpWorkspaces() as $ws => $workspace) {
124     foreach ($workspace->dumpPrefs() as $k => $v) {
125          $prefs[$ws][$k] = $v;
126     }
127}
128
129ksort($prefs);
130
131if (count($prefs) > 0) {
132     echo '<ul class="submenu">';
133     foreach ($prefs as $ws => $s) {
134          echo '<li><a href="#l_'.$ws.'">'.$ws.'</a></li>';
135     }
136     echo '</ul>';
137}
138
139foreach ($prefs as $ws => $s)
140{
141     ksort($s);
142     echo sprintf($table_header,$ws);
143     foreach ($s as $k => $v)
144     {
145          echo prefLine($k,$v,$ws,'s',!$v['global']);
146     }
147     echo $table_footer;
148}
149?>
150
151<p><input type="submit" value="<?php echo __('Save'); ?>" />
152<input type="hidden" name="p" value="userPref" />
153<?php echo $core->formNonce(); ?></p>
154</form>
155</div>
156
157<div id="global" class="multi-part" title="<?php echo __('global preferences'); ?>">
158<form action="plugin.php" method="post">
159
160<?php
161$prefs = array();
162
163foreach ($core->auth->user_prefs->dumpWorkspaces() as $ws => $workspace) {
164     foreach ($workspace->dumpGlobalPrefs() as $k => $v) {
165          $prefs[$ws][$k] = $v;
166     }
167}
168
169ksort($prefs);
170
171if (count($prefs) > 0) {
172     echo '<ul class="submenu">';
173     foreach ($prefs as $ws => $s) {
174          echo '<li><a href="#g_'.$ws.'">'.$ws.'</a></li>';
175     }
176     echo '</ul>';
177}
178
179foreach ($prefs as $ws => $s)
180{
181     ksort($s);
182     echo sprintf($table_header,$ws);
183     foreach ($s as $k => $v)
184     {
185          echo prefLine($k,$v,$ws,'gs',false);
186     }
187     echo $table_footer;
188}
189?>
190
191<p><input type="submit" value="<?php echo __('Save'); ?>" />
192<input type="hidden" name="p" value="userPref" />
193<?php echo $core->formNonce(); ?></p>
194</form>
195</div>
196
197</body>
198</html>
Note: See TracBrowser for help on using the repository browser.

Sites map