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