function update_preferences($pref_id = 0) { /* Get current keys */ $sql = "SELECT `id`,`name`,`type` FROM `preference`"; /* If it isn't the System Account's preferences */ if ($pref_id != '-1') { $sql .= " WHERE `catagory` != 'system'"; } $db_results = Dba::read($sql); $results = array(); // Collect the current possible keys while ($r = Dba::fetch_assoc($db_results)) { $results[] = array('id' => $r['id'], 'name' => $r['name'], 'type' => $r['type']); } // end collecting keys /* Foreach through possible keys and assign them */ foreach ($results as $data) { /* Get the Value from POST/GET var called $data */ $name = $data['name']; $apply_to_all = 'check_' . $data['name']; $new_level = 'level_' . $data['name']; $id = $data['id']; $value = scrub_in($_REQUEST[$name]); /* Some preferences require some extra checks to be performed */ switch ($name) { case 'transcode_bitrate': $value = Stream::validate_bitrate($value); break; default: break; } if (preg_match('/_pass$/', $name)) { if ($value == '******') { unset($_REQUEST[$name]); } else { if (preg_match('/md5_pass$/', $name)) { $value = md5($value); } } } /* Run the update for this preference only if it's set */ if (isset($_REQUEST[$name])) { Preference::update($id, $pref_id, $value, $_REQUEST[$apply_to_all]); } if (Access::check('interface', '100') && $_REQUEST[$new_level]) { Preference::update_level($id, $_REQUEST[$new_level]); } } // end foreach preferences // Now that we've done that we need to invalidate the cached preverences Preference::clear_from_session(); }