Dotclear

source: plugins/userPref/index.php @ 270:48858be15bda

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

Changement d'année

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><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  .ns-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<tr>
106  <th class="nowrap">Pref ID</th>
107  <th><?php echo __('Value'); ?></th>
108  <th><?php echo __('Type'); ?></th>
109  <th class="maximal"><?php echo __('Description'); ?></th>
110</tr>
111<?php
112$prefs = array();
113
114foreach ($core->auth->user_prefs->dumpWorkspaces() as $ws => $workspace) {
115     foreach ($workspace->dumpPrefs() as $k => $v) {
116          $prefs[$ws][$k] = $v;
117     }
118}
119
120ksort($prefs);
121
122foreach ($prefs as $ws => $s)
123{
124     ksort($s);
125     echo '<tr><td colspan="4" class="ws-name">workspace: <strong>'.$ws.'</strong></td></tr>';
126     
127     foreach ($s as $k => $v)
128     {
129          echo prefLine($k,$v,$ws,'s',!$v['global']);
130     }
131}
132?>
133</table>
134<p><input type="submit" value="<?php echo __('Save'); ?>" />
135<input type="hidden" name="p" value="userPref" />
136<?php echo $core->formNonce(); ?></p>
137</form>
138</div>
139
140<div id="global" class="multi-part" title="<?php echo __('global preferences'); ?>">
141<form action="plugin.php" method="post">
142<table>
143<tr>
144  <th class="nowrap">Pref ID</th>
145  <th><?php echo __('Value'); ?></th>
146  <th><?php echo __('Type'); ?></th>
147  <th class="maximal"><?php echo __('Description'); ?></th>
148</tr>
149<?php
150$prefs = array();
151
152foreach ($core->auth->user_prefs->dumpWorkspaces() as $ws => $workspace) {
153     foreach ($workspace->dumpGlobalPrefs() as $k => $v) {
154          $prefs[$ws][$k] = $v;
155     }
156}
157
158ksort($prefs);
159
160foreach ($prefs as $ws => $s)
161{
162     ksort($s);
163     echo '<tr><td colspan="4" class="ws-name">workspace: <strong>'.$ws.'</strong></td></tr>';
164     
165     foreach ($s as $k => $v)
166     {
167          echo prefLine($k,$v,$ws,'gs',false);
168     }
169}
170?>
171</table>
172<p><input type="submit" value="<?php echo __('Save'); ?>" />
173<input type="hidden" name="p" value="userPref" />
174<?php echo $core->formNonce(); ?></p>
175</form>
176</div>
177
178</body>
179</html>
Note: See TracBrowser for help on using the repository browser.

Sites map