static function getUserPrefs($user) { $userPrefs = $user ? $user->preferences : session_getAnonymousPrefs(); $copy = self::$allPrefs; // Set the checked field to false / true according to user preferences foreach ($copy as $key => $value) { $copy[$key]['checked'] = false; } if ($userPrefs) { foreach (preg_split('/,/', $userPrefs) as $pref) { $copy[$pref]['checked'] = true; } } return $copy; }
<?php require_once "../phplib/util.php"; require_once "../phplib/userPreferences.php"; util_assertNotLoggedIn(); $sendButton = util_getRequestParameter('send'); if ($sendButton) { $userPrefs = util_getRequestCheckboxArray('userPrefs', ','); $skin = util_getRequestParameter('skin'); session_setAnonymousPrefs($userPrefs); if (session_isValidSkin($skin)) { session_setSkin($skin); } FlashMessage::add('Preferințele au fost salvate.', 'info'); util_redirect('preferinte'); } else { $userPrefs = session_getAnonymousPrefs(); $skin = session_getSkin(); } foreach (preg_split('/,/', $userPrefs) as $pref) { if (isset($userPreferencesSet[$pref])) { $userPreferencesSet[$pref]['checked'] = true; } } smarty_assign('userPrefs', $userPreferencesSet); smarty_assign('skin', $skin); smarty_assign('availableSkins', pref_getServerPreference('skins')); smarty_assign('page_title', 'Preferințe'); smarty_displayCommonPageWithSkin('preferinte.ihtml');
function session_sendAnonymousPrefs() { setcookie('prefs[anonymousPrefs]', session_getAnonymousPrefs(), time() + ONE_YEAR_IN_SECONDS, '/'); }