Changeset 3703:53c8bef8608a for plugins/userPref/index.php
- Timestamp:
- 02/15/18 16:39:52 (8 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/userPref/index.php
r3421 r3703 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_CONTEXT_ADMIN')) { return;}12 if (!defined('DC_CONTEXT_ADMIN')) {return;} 13 13 14 14 # Local navigation 15 15 if (!empty($_POST['gp_nav'])) { 16 http::redirect($p_url.$_POST['gp_nav']);17 16 http::redirect($p_url . $_POST['gp_nav']); 17 exit; 18 18 } 19 19 if (!empty($_POST['lp_nav'])) { 20 http::redirect($p_url.$_POST['lp_nav']);21 20 http::redirect($p_url . $_POST['lp_nav']); 21 exit; 22 22 } 23 23 24 24 # Local prefs update 25 if (!empty($_POST['s']) && is_array($_POST['s'])) 25 if (!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 46 if (!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 68 function prefLine($id, $s, $ws, $field_name, $strong_label) 26 69 { 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>'; 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>'; 100 94 } 101 95 ?> … … 104 98 <title>user:preferences</title> 105 99 <?php echo dcPage::jsPageTabs($part); ?> 106 107 108 109 110 111 112 113 114 115 116 117 118 119 100 <script type="text/javascript"> 101 $(function() { 102 $("#gp_submit,#lp_submit").hide(); 103 $('#part-local,#part-global').tabload(function() { 104 $('.multi-part.active select.navigation option:first').attr('selected',true); 105 }); 106 $("#gp_nav").change(function() { 107 window.location = $("#gp_nav option:selected").val(); 108 }); 109 $("#lp_nav").change(function() { 110 window.location = $("#lp_nav option:selected").val(); 111 }); 112 }); 113 </script> 120 114 </head> 121 115 … … 123 117 <?php 124 118 echo dcPage::breadcrumb( 125 126 __('System')=> '',127 128 __('user:preferences')=> ''129 )).130 119 array( 120 __('System') => '', 121 html::escapeHTML($core->auth->userID()) => '', 122 __('user:preferences') => '' 123 )) . 124 dcPage::notices(); 131 125 132 126 ?> … … 136 130 137 131 <?php 138 $table_header = '<div class="table-outer"><table class="prefs" id="%s"><caption class="as_h3">%s</caption>' .139 '<thead>' .140 '<tr>' ."\n".141 ' <th class="nowrap">' .__('Setting ID').'</th>'."\n".142 ' <th>' .__('Value').'</th>'."\n".143 ' <th>' .__('Type').'</th>'."\n".144 ' <th class="maximalx">' .__('Description').'</th>'."\n".145 '</tr>'."\n".146 '</thead>'."\n".147 '<tbody>';132 $table_header = '<div class="table-outer"><table class="prefs" id="%s"><caption class="as_h3">%s</caption>' . 133 '<thead>' . 134 '<tr>' . "\n" . 135 ' <th class="nowrap">' . __('Setting ID') . '</th>' . "\n" . 136 ' <th>' . __('Value') . '</th>' . "\n" . 137 ' <th>' . __('Type') . '</th>' . "\n" . 138 ' <th class="maximalx">' . __('Description') . '</th>' . "\n" . 139 '</tr>' . "\n" . 140 '</thead>' . "\n" . 141 '<tbody>'; 148 142 $table_footer = '</tbody></table></div>'; 149 143 150 144 $prefs = array(); 151 145 foreach ($core->auth->user_prefs->dumpWorkspaces() as $ws => $workspace) { 152 153 154 146 foreach ($workspace->dumpPrefs() as $k => $v) { 147 $prefs[$ws][$k] = $v; 148 } 155 149 } 156 150 ksort($prefs); 157 151 if (count($prefs) > 0) { 158 $ws_combo = array(); 159 foreach ($prefs as $ws => $s) { 160 $ws_combo[$ws] = '#l_'.$ws; 161 } 162 echo 163 '<form action="'.$core->adminurl->get('admin.plugin').'" method="post">'. 164 '<p class="anchor-nav">'. 165 '<label for="lp_nav" class="classic">'.__('Goto:').'</label> '.form::combo('lp_nav',$ws_combo,'','navigation'). 166 ' <input type="submit" value="'.__('Ok').'" id="lp_submit" />'. 167 '<input type="hidden" name="p" value="userPref" />'. 168 $core->formNonce().'</p></form>'; 152 $ws_combo = array(); 153 foreach ($prefs as $ws => $s) { 154 $ws_combo[$ws] = '#l_' . $ws; 155 } 156 echo 157 '<form action="' . $core->adminurl->get('admin.plugin') . '" method="post">' . 158 '<p class="anchor-nav">' . 159 '<label for="lp_nav" class="classic">' . __('Goto:') . '</label> ' . 160 form::combo('lp_nav', $ws_combo, array('class' => 'navigation')) . 161 ' <input type="submit" value="' . __('Ok') . '" id="lp_submit" />' . 162 '<input type="hidden" name="p" value="userPref" />' . 163 $core->formNonce() . '</p></form>'; 169 164 } 170 165 ?> … … 173 168 174 169 <?php 175 foreach ($prefs as $ws => $s) 176 { 177 ksort($s); 178 echo sprintf($table_header,'l_'.$ws,$ws); 179 foreach ($s as $k => $v) 180 { 181 echo prefLine($k,$v,$ws,'s',!$v['global']); 182 } 183 echo $table_footer; 170 foreach ($prefs as $ws => $s) { 171 ksort($s); 172 echo sprintf($table_header, 'l_' . $ws, $ws); 173 foreach ($s as $k => $v) { 174 echo prefLine($k, $v, $ws, 's', !$v['global']); 175 } 176 echo $table_footer; 184 177 } 185 178 ?> … … 198 191 199 192 foreach ($core->auth->user_prefs->dumpWorkspaces() as $ws => $workspace) { 200 201 202 193 foreach ($workspace->dumpGlobalPrefs() as $k => $v) { 194 $prefs[$ws][$k] = $v; 195 } 203 196 } 204 197 … … 206 199 207 200 if (count($prefs) > 0) { 208 $ws_combo = array(); 209 foreach ($prefs as $ws => $s) { 210 $ws_combo[$ws] = '#g_'.$ws; 211 } 212 echo 213 '<form action="'.$core->adminurl->get('admin.plugin').'" method="post">'. 214 '<p class="anchor-nav">'. 215 '<label for="gp_nav" class="classic">'.__('Goto:').'</label> '.form::combo('gp_nav',$ws_combo,'','navigation'). 216 ' <input type="submit" value="'.__('Ok').'" id="gp_submit" />'. 217 '<input type="hidden" name="p" value="userPref" />'. 218 $core->formNonce().'</p></form>'; 201 $ws_combo = array(); 202 foreach ($prefs as $ws => $s) { 203 $ws_combo[$ws] = '#g_' . $ws; 204 } 205 echo 206 '<form action="' . $core->adminurl->get('admin.plugin') . '" method="post">' . 207 '<p class="anchor-nav">' . 208 '<label for="gp_nav" class="classic">' . __('Goto:') . '</label> ' . 209 form::combo('gp_nav', $ws_combo, array('class' => 'navigation')) . 210 ' <input type="submit" value="' . __('Ok') . '" id="gp_submit" />' . 211 '<input type="hidden" name="p" value="userPref" />' . 212 $core->formNonce() . '</p></form>'; 219 213 } 220 214 ?> … … 223 217 224 218 <?php 225 foreach ($prefs as $ws => $s) 226 { 227 ksort($s); 228 echo sprintf($table_header,'g_'.$ws,$ws); 229 foreach ($s as $k => $v) 230 { 231 echo prefLine($k,$v,$ws,'gs',false); 232 } 233 echo $table_footer; 219 foreach ($prefs as $ws => $s) { 220 ksort($s); 221 echo sprintf($table_header, 'g_' . $ws, $ws); 222 foreach ($s as $k => $v) { 223 echo prefLine($k, $v, $ws, 'gs', false); 224 } 225 echo $table_footer; 234 226 } 235 227 ?> … … 241 233 </div> 242 234 243 <?php dcPage::helpBlock('userPref'); 235 <?php dcPage::helpBlock('userPref');?> 244 236 245 237 </body>
Note: See TracChangeset
for help on using the changeset viewer.