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

RevLine 
[3]1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
[1179]6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
[3]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 -----------------------------------------
[3703]12if (!defined('DC_CONTEXT_ADMIN')) {return;}
[3]13
[589]14# Local navigation
15if (!empty($_POST['gp_nav'])) {
[3703]16    http::redirect($p_url . $_POST['gp_nav']);
17    exit;
[589]18}
19if (!empty($_POST['lp_nav'])) {
[3703]20    http::redirect($p_url . $_POST['lp_nav']);
21    exit;
[589]22}
23
[3]24# Local prefs update
[3703]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        }
[2566]37
[3703]38        dcPage::addSuccessNotice(__('Preferences successfully updated'));
39        http::redirect($p_url);
40    } catch (Exception $e) {
41        $core->error->add($e->getMessage());
42    }
[3]43}
44
45# Global prefs update
[3703]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        }
[2566]58
[3703]59        dcPage::addSuccessNotice(__('Preferences successfully updated'));
60        http::redirect($p_url . '&part=global');
61    } catch (Exception $e) {
62        $core->error->add($e->getMessage());
63    }
[3]64}
65
66$part = !empty($_GET['part']) && $_GET['part'] == 'global' ? 'global' : 'local';
67
[3703]68function prefLine($id, $s, $ws, $field_name, $strong_label)
[3]69{
[3703]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']));
[2566]84
[3703]85    $slabel = $strong_label ? '<strong>%s</strong>' : '%s';
[2566]86
[3703]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>';
[3]94}
95?>
96<html>
97<head>
98  <title>user:preferences</title>
[3709]99  <?php echo dcPage::jsPageTabs($part) . dcPage::jsLoad(dcPage::getPF('userPref/js/index.js')); ?>
[3]100</head>
101
102<body>
103<?php
[1358]104echo dcPage::breadcrumb(
[3703]105    array(
106        __('System')                            => '',
107        html::escapeHTML($core->auth->userID()) => '',
108        __('user:preferences')                  => ''
109    )) .
110dcPage::notices();
[1358]111
[3]112?>
113
[1338]114<div id="local" class="multi-part" title="<?php echo __('User preferences'); ?>">
[2003]115<h3 class="out-of-screen-if-js"><?php echo __('User preferences'); ?></h3>
[581]116
[2566]117<?php
[3703]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>';
[2002]128$table_footer = '</tbody></table></div>';
[581]129
[3]130$prefs = array();
131foreach ($core->auth->user_prefs->dumpWorkspaces() as $ws => $workspace) {
[3703]132    foreach ($workspace->dumpPrefs() as $k => $v) {
133        $prefs[$ws][$k] = $v;
134    }
[3]135}
[589]136ksort($prefs);
137if (count($prefs) > 0) {
[3703]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>';
[589]150}
151?>
[3]152
[2824]153<form action="<?php echo $core->adminurl->get('admin.plugin'); ?>" method="post">
[3]154
[589]155<?php
[3703]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;
[3]163}
164?>
[581]165
[220]166<p><input type="submit" value="<?php echo __('Save'); ?>" />
[3]167<input type="hidden" name="p" value="userPref" />
168<?php echo $core->formNonce(); ?></p>
169</form>
170</div>
171
[1338]172<div id="global" class="multi-part" title="<?php echo __('Global preferences'); ?>">
[2003]173<h3 class="out-of-screen-if-js"><?php echo __('Global preferences'); ?></h3>
[581]174
[3]175<?php
176$prefs = array();
177
178foreach ($core->auth->user_prefs->dumpWorkspaces() as $ws => $workspace) {
[3703]179    foreach ($workspace->dumpGlobalPrefs() as $k => $v) {
180        $prefs[$ws][$k] = $v;
181    }
[3]182}
183
184ksort($prefs);
185
[582]186if (count($prefs) > 0) {
[3703]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>';
[582]199}
[589]200?>
[582]201
[2824]202<form action="<?php echo $core->adminurl->get('admin.plugin'); ?>" method="post">
[589]203
204<?php
[3703]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;
[3]212}
213?>
[581]214
[220]215<p><input type="submit" value="<?php echo __('Save'); ?>" />
[3]216<input type="hidden" name="p" value="userPref" />
217<?php echo $core->formNonce(); ?></p>
218</form>
219</div>
220
[3703]221<?php dcPage::helpBlock('userPref');?>
[2322]222
[3]223</body>
[1339]224</html>
Note: See TracBrowser for help on using the repository browser.

Sites map