[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 3 * Class for auto-generating the preferences user interface and 4 * processing the forms. 5 * 6 * $Horde: framework/Prefs/Prefs/UI.php,v 1.63.2.15 2006/01/12 22:25:14 jan Exp $ 7 * 8 * Copyright 2001-2006 Chuck Hagenbuch <chuck@horde.org> 9 * 10 * See the enclosed file COPYING for license information (LGPL). If you 11 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 12 * 13 * @author Chuck Hagenbuch <chuck@horde.org> 14 * @since Horde 2.1 15 * @package Horde_Prefs 16 */ 17 class Prefs_UI { 18 19 /** 20 * Determine whether or not a preferences group is editable. 21 * 22 * @param string $group The preferences group to check. 23 * 24 * @return boolean Whether or not the group is editable. 25 */ 26 function groupIsEditable($group) 27 { 28 global $prefs, $prefGroups; 29 30 static $results = array(); 31 32 if (!isset($results[$group])) { 33 if (!empty($prefGroups[$group]['url'])) { 34 $results[$group] = true; 35 } else { 36 $results[$group] = false; 37 if (isset($prefGroups[$group]['members'])) { 38 foreach ($prefGroups[$group]['members'] as $pref) { 39 if (!$prefs->isLocked($pref)) { 40 $results[$group] = true; 41 return true; 42 } 43 } 44 } 45 } 46 } 47 48 return $results[$group]; 49 } 50 51 /** 52 * Handle a preferences form submission if there is one, updating 53 * any preferences which have been changed. 54 * 55 * @param string $group The preferences group that was edited. 56 * @param object $save The object where the changed values are 57 * saved. Must implement setValue(string, string). 58 * 59 * @return boolean Whether preferences have been updated. 60 */ 61 function handleForm(&$group, &$save) 62 { 63 global $prefs, $prefGroups, $_prefs, $notification, $registry; 64 65 $updated = false; 66 67 /* Run through the action handlers */ 68 if (Util::getPost('actionID') == 'update_prefs') { 69 if (isset($group) && Prefs_UI::groupIsEditable($group)) { 70 $updated = false; 71 72 foreach ($prefGroups[$group]['members'] as $pref) { 73 if (!$prefs->isLocked($pref) || 74 ($_prefs[$pref]['type'] == 'special')) { 75 switch ($_prefs[$pref]['type']) { 76 77 /* These either aren't set or are set in other 78 * parts of the UI. */ 79 case 'implicit': 80 case 'link': 81 break; 82 83 case 'select': 84 case 'text': 85 case 'textarea': 86 case 'password': 87 $updated = $updated | $save->setValue($pref, Util::getPost($pref)); 88 break; 89 90 case 'enum': 91 $val = Util::getPost($pref); 92 if (isset($_prefs[$pref]['enum'][$val])) { 93 $updated = $updated | $save->setValue($pref, $val); 94 } else { 95 $notification->push(_("An illegal value was specified."), 'horde.error'); 96 } 97 break; 98 99 case 'multienum': 100 $vals = Util::getPost($pref); 101 $set = array(); 102 $invalid = false; 103 if (is_array($vals)) { 104 foreach ($vals as $val) { 105 if (isset($_prefs[$pref]['enum'][$val])) { 106 $set[] = $val; 107 } else { 108 $invalid = true; 109 continue; 110 } 111 } 112 } 113 114 if ($invalid) { 115 $notification->push(_("An illegal value was specified."), 'horde.error'); 116 } else { 117 $updated = $updated | $save->setValue($pref, @serialize($set)); 118 } 119 break; 120 121 case 'number': 122 $num = Util::getPost($pref); 123 if (intval($num) != $num) { 124 $notification->push(_("This value must be a number."), 'horde.error'); 125 } elseif ($num == 0) { 126 $notification->push(_("This number must be at least one."), 'horde.error'); 127 } else { 128 $updated = $updated | $save->setValue($pref, $num); 129 } 130 break; 131 132 case 'checkbox': 133 $val = Util::getPost($pref); 134 $updated = $updated | $save->setValue($pref, isset($val) ? 1 : 0); 135 break; 136 137 case 'special': 138 /* Code for special elements must be 139 * written specifically for each 140 * application. */ 141 if (function_exists('handle_' . $pref)) { 142 $updated = $updated | call_user_func('handle_' . $pref, $updated); 143 } 144 break; 145 } 146 } 147 } 148 149 if ($updated) { 150 if (function_exists('prefs_callback')) { 151 prefs_callback(); 152 } 153 if (is_a($prefs, 'Prefs_session')) { 154 $notification->push(_("Your options have been updated for the duration of this session."), 'horde.success'); 155 } else { 156 $notification->push(_("Your options have been updated."), 'horde.success'); 157 } 158 $group = null; 159 } 160 } 161 } 162 163 return $updated; 164 } 165 166 /** 167 * Generate the UI for the preferences interface, either for a 168 * specific group, or the group selection interface. 169 * 170 * @param string $group The group to generate the UI for. 171 */ 172 function generateUI($group = null) 173 { 174 global $browser, $conf, $prefs, $prefGroups, $_prefs, $registry, $app; 175 176 /* Check if any options are actually available. */ 177 if (is_null($prefGroups)) { 178 $GLOBALS['notification']->push(_("There are no options available."), 'horde.message'); 179 } 180 181 /* Show the header. */ 182 Prefs_UI::generateHeader($group); 183 184 /* Assign variables to hold select lists. */ 185 if (!$prefs->isLocked('language')) { 186 $GLOBALS['language_options'] = $GLOBALS['nls']['languages']; 187 array_unshift($GLOBALS['language_options'], _("Default")); 188 } 189 190 if (!empty($group) && Prefs_UI::groupIsEditable($group)) { 191 foreach ($prefGroups[$group]['members'] as $pref) { 192 if (!$prefs->isLocked($pref)) { 193 /* Get the help link. */ 194 if (!empty($_prefs[$pref]['help'])) { 195 $helplink = Help::link(!empty($_prefs[$pref]['shared']) ? 'horde' : $registry->getApp(), $_prefs[$pref]['help']); 196 } else { 197 $helplink = null; 198 } 199 200 switch ($_prefs[$pref]['type']) { 201 case 'implicit': 202 break; 203 204 case 'special': 205 require $registry->get('templates', !empty($_prefs[$pref]['shared']) ? 'horde' : $registry->getApp()) . "/prefs/$pref.inc"; 206 break; 207 208 default: 209 require $registry->get('templates', 'horde') . '/prefs/' . $_prefs[$pref]['type'] . '.inc'; 210 break; 211 } 212 } 213 } 214 require $registry->get('templates', 'horde') . '/prefs/end.inc'; 215 } else { 216 $span = 100; 217 $columns = array(); 218 if (is_array($prefGroups)) { 219 foreach ($prefGroups as $group => $gvals) { 220 if (Prefs_UI::groupIsEditable($group)) { 221 $col = $gvals['column']; 222 unset($gvals['column']); 223 $columns[$col][$group] = $gvals; 224 } 225 } 226 if (count($columns)) { 227 $span = round(100 / count($columns)); 228 } 229 } 230 231 require $registry->get('templates', 'horde') . '/prefs/overview.inc'; 232 } 233 } 234 235 /** 236 * Generates the the full header of a preference screen including 237 * menu and navigation bars. 238 * 239 * @param string $group The group to generate the header for. 240 */ 241 function generateHeader($group = null) 242 { 243 global $registry, $prefGroups, $app, $perms, $prefs, $notification; 244 245 $title = _("User Options"); 246 if ($group == 'identities' && !$prefs->isLocked('default_identity')) { 247 $notification->push('newChoice()', 'javascript'); 248 } 249 require $registry->get('templates', $app) . '/common-header.inc'; 250 if (is_callable(array($app, 'getMenu'))) { 251 $menu = call_user_func(array($app, 'getMenu')); 252 require $registry->get('templates', 'horde') . '/menu/menu.inc'; 253 } else { 254 /* Use a default menu. */ 255 require_once 'Horde/Menu.php'; 256 $menu = &new Menu(); 257 require $registry->get('templates', 'horde') . '/menu/menu.inc'; 258 } 259 260 if (is_callable(array($app, 'status'))) { 261 call_user_func(array($app, 'status')); 262 } else { 263 $GLOBALS['notification']->notify(array('listeners' => 'status')); 264 } 265 266 /* Get list of accessible applications. */ 267 $apps = array(); 268 foreach ($registry->applications as $application => $params) { 269 // Make sure the app is installed and has a prefs file. 270 if (!file_exists($registry->get('fileroot', $application) . '/config/prefs.php')) { 271 continue; 272 } 273 274 if ($params['status'] == 'heading' || 275 $params['status'] == 'block') { 276 continue; 277 } 278 279 /* Check if the current user has permisson to see this 280 * application, and if the application is active. 281 * Administrators always see all applications. */ 282 if ((Auth::isAdmin() && $params['status'] != 'inactive') || 283 ($registry->hasPermission($application) && 284 ($params['status'] == 'active' || $params['status'] == 'notoolbar'))) { 285 $apps[$application] = _($params['name']); 286 } 287 } 288 asort($apps); 289 290 /* Show the current application and a form for switching 291 * applications. */ 292 require $registry->get('templates', 'horde') . '/prefs/app.inc'; 293 294 /* If there's only one prefGroup, just show it. */ 295 if (empty($group) && count($prefGroups) == 1) { 296 $group = array_keys($prefGroups); 297 $group = array_pop($group); 298 } 299 300 if (!empty($group) && Prefs_UI::groupIsEditable($group)) { 301 require $registry->get('templates', 'horde') . '/prefs/begin.inc'; 302 } 303 } 304 305 /** 306 * Generate the content of the title bar navigation cell (previous | next 307 * option group). 308 * 309 * @param string $group Current option group. 310 */ 311 function generateNavigationCell($group) 312 { 313 global $prefGroups, $registry, $app; 314 315 // Search for previous and next groups. 316 $previous = null; 317 $next = null; 318 $last = null; 319 $first = null; 320 $found = false; 321 $finish = false; 322 foreach ($prefGroups as $pgroup => $gval) { 323 if (Prefs_UI::groupIsEditable($pgroup)) { 324 if (!$first) { 325 $first = $pgroup; 326 } 327 if (!$found) { 328 if ($pgroup == $group) { 329 $previous = $last; 330 $found = true; 331 } 332 } else { 333 if (!$finish) { 334 $finish = true; 335 $next = $pgroup; 336 } 337 } 338 $last = $pgroup; 339 } 340 } 341 if (!$previous) { 342 $previous = $last; 343 } 344 if (!$next) { 345 $next = $first; 346 } 347 348 /* Don't loop if there's only one group. */ 349 if ($next == $previous) { 350 return; 351 } 352 353 echo '<ul><li>'; 354 if (!empty($prefGroups[$previous]['url'])) { 355 echo Horde::link(Horde::applicationUrl($prefGroups[$previous]['url']), 356 _("Previous options")); 357 echo '<< ' . $prefGroups[$previous]['label']; 358 } else { 359 echo Horde::link(Util::addParameter(Horde::url($registry->get('webroot', 'horde') . '/services/prefs.php'), array('group' => $previous, 'app' => $app)), 360 _("Previous options")); 361 echo '<< ' . $prefGroups[$previous]['label']; 362 } 363 echo '</a> | '; 364 if (!empty($prefGroups[$next]['url'])) { 365 echo Horde::link(Horde::applicationUrl($prefGroups[$next]['url']), 366 _("Next options")); 367 echo $prefGroups[$next]['label'] . ' >>'; 368 } else { 369 echo Horde::link(Util::addParameter(Horde::url($registry->get('webroot', 'horde') . '/services/prefs.php'), array('group' => $next, 'app' => $app)), 370 _("Next options")); 371 echo $prefGroups[$next]['label'] . ' >>'; 372 } 373 echo '</a></li></ul>'; 374 } 375 376 /** 377 * Get the default application to show preferences for. Defaults 378 * to 'horde'. 379 */ 380 function getDefaultApp() 381 { 382 $applications = $GLOBALS['registry']->listApps(null, true, PERMS_READ); 383 return isset($applications['horde']) ? 'horde' : array_shift($applications); 384 } 385 386 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |