Dotclear

source: plugins/userPref/index.php @ 3709:c88e69474c34

Revision 3709:c88e69474c34, 6.9 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

use strict and no more linter warnings/errors as far as possible, switch from inline js to separate loaded file

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 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 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
24# Local prefs update
25if (!empty($_POST['s']) && is_array($_POST['s'])) {
26    try
27    {
28        foreach ($_POST['s'] as $ws => $s) {
29            $core->auth->user_prefs->addWorkspace($ws);
30            foreach ($s as $k => $v) {
31                if ($_POST['s_type'][$ws][$k] == 'array') {
32                    $v = json_decode($v, true);
33                }
34                $core->auth->user_prefs->$ws->put($k, $v);
35            }
36        }
37
38        dcPage::addSuccessNotice(__('Preferences successfully updated'));
39        http::redirect($p_url);
40    } catch (Exception $e) {
41        $core->error->add($e->getMessage());
42    }
43}
44
45# Global prefs update
46if (!empty($_POST['gs']) && is_array($_POST['gs'])) {
47    try
48    {
49        foreach ($_POST['gs'] as $ws => $s) {
50            $core->auth->user_prefs->addWorkspace($ws);
51            foreach ($s as $k => $v) {
52                if ($_POST['gs_type'][$ws][$k] == 'array') {
53                    $v = json_decode($v, true);
54                }
55                $core->auth->user_prefs->$ws->put($k, $v, null, null, true, true);
56            }
57        }
58
59        dcPage::addSuccessNotice(__('Preferences successfully updated'));
60        http::redirect($p_url . '&part=global');
61    } catch (Exception $e) {
62        $core->error->add($e->getMessage());
63    }
64}
65
66$part = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local';
67
68function prefLine($id, $s, $ws, $field_name, $strong_label)
69{
70    if ($s['type'] == 'boolean') {
71        $field = form::combo(array($field_name . '[' . $ws . '][' . $id . ']', $field_name . '_' . $ws . '_' . $id),
72            array(__('yes') => 1, __('no') => 0), $s['value'] ? 1 : 0);
73    } else {
74        if ($s['type'] == 'array') {
75            $field = form::field(array($field_name . '[' . $ws . '][' . $id . ']', $field_name . '_' . $ws . '_' . $id), 40, null,
76                html::escapeHTML(json_encode($s['value'])));
77        } else {
78            $field = form::field(array($field_name . '[' . $ws . '][' . $id . ']', $field_name . '_' . $ws . '_' . $id), 40, null,
79                html::escapeHTML($s['value']));
80        }
81    }
82    $type = form::hidden(array($field_name . '_type' . '[' . $ws . '][' . $id . ']', $field_name . '_' . $ws . '_' . $id . '_type'),
83        html::escapeHTML($s['type']));
84
85    $slabel = $strong_label ? '<strong>%s</strong>' : '%s';
86
87    return
88    '<tr class="line">' .
89    '<td scope="row"><label for="' . $field_name . '_' . $ws . '_' . $id . '">' . sprintf($slabel, html::escapeHTML($id)) . '</label></td>' .
90    '<td>' . $field . '</td>' .
91    '<td>' . $s['type'] . $type . '</td>' .
92    '<td>' . html::escapeHTML($s['label']) . '</td>' .
93        '</tr>';
94}
95?>
96<html>
97<head>
98  <title>user:preferences</title>
99  <?php echo dcPage::jsPageTabs($part) . dcPage::jsLoad(dcPage::getPF('userPref/js/index.js')); ?>
100</head>
101
102<body>
103<?php
104echo dcPage::breadcrumb(
105    array(
106        __('System')                            => '',
107        html::escapeHTML($core->auth->userID()) => '',
108        __('user:preferences')                  => ''
109    )) .
110dcPage::notices();
111
112?>
113
114<div id="local" class="multi-part" title="<?php echo __('User preferences'); ?>">
115<h3 class="out-of-screen-if-js"><?php echo __('User preferences'); ?></h3>
116
117<?php
118$table_header = '<div class="table-outer"><table class="prefs" id="%s"><caption class="as_h3">%s</caption>' .
119'<thead>' .
120'<tr>' . "\n" .
121'  <th class="nowrap">' . __('Setting ID') . '</th>' . "\n" .
122'  <th>' . __('Value') . '</th>' . "\n" .
123'  <th>' . __('Type') . '</th>' . "\n" .
124'  <th class="maximalx">' . __('Description') . '</th>' . "\n" .
125    '</tr>' . "\n" .
126    '</thead>' . "\n" .
127    '<tbody>';
128$table_footer = '</tbody></table></div>';
129
130$prefs = array();
131foreach ($core->auth->user_prefs->dumpWorkspaces() as $ws => $workspace) {
132    foreach ($workspace->dumpPrefs() as $k => $v) {
133        $prefs[$ws][$k] = $v;
134    }
135}
136ksort($prefs);
137if (count($prefs) > 0) {
138    $ws_combo = array();
139    foreach ($prefs as $ws => $s) {
140        $ws_combo[$ws] = '#l_' . $ws;
141    }
142    echo
143    '<form action="' . $core->adminurl->get('admin.plugin') . '" method="post">' .
144    '<p class="anchor-nav">' .
145    '<label for="lp_nav" class="classic">' . __('Goto:') . '</label> ' .
146    form::combo('lp_nav', $ws_combo, array('class' => 'navigation')) .
147    ' <input type="submit" value="' . __('Ok') . '" id="lp_submit" />' .
148    '<input type="hidden" name="p" value="userPref" />' .
149    $core->formNonce() . '</p></form>';
150}
151?>
152
153<form action="<?php echo $core->adminurl->get('admin.plugin'); ?>" method="post">
154
155<?php
156foreach ($prefs as $ws => $s) {
157    ksort($s);
158    echo sprintf($table_header, 'l_' . $ws, $ws);
159    foreach ($s as $k => $v) {
160        echo prefLine($k, $v, $ws, 's', !$v['global']);
161    }
162    echo $table_footer;
163}
164?>
165
166<p><input type="submit" value="<?php echo __('Save'); ?>" />
167<input type="hidden" name="p" value="userPref" />
168<?php echo $core->formNonce(); ?></p>
169</form>
170</div>
171
172<div id="global" class="multi-part" title="<?php echo __('Global preferences'); ?>">
173<h3 class="out-of-screen-if-js"><?php echo __('Global preferences'); ?></h3>
174
175<?php
176$prefs = array();
177
178foreach ($core->auth->user_prefs->dumpWorkspaces() as $ws => $workspace) {
179    foreach ($workspace->dumpGlobalPrefs() as $k => $v) {
180        $prefs[$ws][$k] = $v;
181    }
182}
183
184ksort($prefs);
185
186if (count($prefs) > 0) {
187    $ws_combo = array();
188    foreach ($prefs as $ws => $s) {
189        $ws_combo[$ws] = '#g_' . $ws;
190    }
191    echo
192    '<form action="' . $core->adminurl->get('admin.plugin') . '" method="post">' .
193    '<p class="anchor-nav">' .
194    '<label for="gp_nav" class="classic">' . __('Goto:') . '</label> ' .
195    form::combo('gp_nav', $ws_combo, array('class' => 'navigation')) .
196    ' <input type="submit" value="' . __('Ok') . '" id="gp_submit" />' .
197    '<input type="hidden" name="p" value="userPref" />' .
198    $core->formNonce() . '</p></form>';
199}
200?>
201
202<form action="<?php echo $core->adminurl->get('admin.plugin'); ?>" method="post">
203
204<?php
205foreach ($prefs as $ws => $s) {
206    ksort($s);
207    echo sprintf($table_header, 'g_' . $ws, $ws);
208    foreach ($s as $k => $v) {
209        echo prefLine($k, $v, $ws, 'gs', false);
210    }
211    echo $table_footer;
212}
213?>
214
215<p><input type="submit" value="<?php echo __('Save'); ?>" />
216<input type="hidden" name="p" value="userPref" />
217<?php echo $core->formNonce(); ?></p>
218</form>
219</div>
220
221<?php dcPage::helpBlock('userPref');?>
222
223</body>
224</html>
Note: See TracBrowser for help on using the repository browser.

Sites map