/** * Show and process config category form * * @param void * @return null */ function update_category() { // Access permissios if (!can_manage_configuration(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if $category = ConfigCategories::findById(get_id()); if (!$category instanceof ConfigCategory) { flash_error(lang('config category dnx')); $this->redirectToReferer(get_url('administration')); } // if if ($category->isEmpty()) { flash_error(lang('config category is empty')); $this->redirectToReferer(get_url('administration')); } // if $options = $category->getOptions(false); $categories = ConfigCategories::getAll(false); tpl_assign('category', $category); tpl_assign('options', $options); tpl_assign('config_categories', $categories); $submited_values = array_var($_POST, 'options'); if (is_array($submited_values)) { foreach ($options as $option) { //update global cache if available if (GlobalCache::isAvailable() && GlobalCache::key_exists('config_option_' . $option->getName())) { GlobalCache::delete('config_option_' . $option->getName()); } if ($option->getName() == "working_days") { $new_value = ""; foreach (array_var($submited_values, $option->getName()) as $value) { $new_value .= $value . ","; } $new_value = substr($new_value, 0, -1); } else { $new_value = array_var($submited_values, $option->getName()); if (is_null($new_value) || $new_value == $option->getValue()) { continue; } } $option->setValue($new_value); $option->save(); evt_add("config option changed", array('name' => $option->getName(), 'value' => $new_value)); } // foreach flash_success(lang('success update config category', $category->getDisplayName())); ajx_current("back"); } // if }
/** * Set value of specific user configuration option * * @param string $option_name * @param mixed $value * @param int $user_id User Id, if null logged user is taken * @return boolean */ function set_user_config_option($option_name, $value, $user_id = null) { $config_option = UserWsConfigOptions::getByName($option_name); if (!$config_option instanceof UserWsConfigOption) { return false; } // if $config_option->setUserValue($value, $user_id); // update cache if available if (GlobalCache::isAvailable() && GlobalCache::key_exists('user_config_option_' . $user_id . '_' . $option_name)) { GlobalCache::update('user_config_option_' . $user_id . '_' . $option_name, $value); } return $config_option->save(); }
/** * Update default user preferences * */ function update_default_user_preferences() { $category = UserWsConfigCategories::findById(get_id()); if (!$category instanceof UserWsConfigCategory) { flash_error(lang('config category dnx')); $this->redirectToReferer(get_url('user', 'card')); } // if if ($category->isEmpty()) { flash_error(lang('config category is empty')); $this->redirectToReferer(get_url('user', 'card')); } // if $options = $category->getUserWsOptions(false); $categories = UserWsConfigCategories::getAll(false); tpl_assign('category', $category); tpl_assign('options', $options); tpl_assign('config_categories', $categories); $submited_values = array_var($_POST, 'options'); if (is_array($submited_values)) { try { DB::beginWork(); foreach ($options as $option) { $new_value = array_var($submited_values, $option->getName()); if (is_null($new_value) || $new_value == $option->getValue()) { continue; } $option->setValue($new_value); $option->save(); if (!user_has_config_option($option->getName())) { evt_add('user preference changed', array('name' => $option->getName(), 'value' => $new_value)); // update global cache if available if (GlobalCache::isAvailable() && GlobalCache::key_exists('user_config_option_def_' . $option->getName())) { GlobalCache::update('user_config_option_def_' . $option->getName(), $new_value); } } } // foreach DB::commit(); flash_success(lang('success update config value', $category->getDisplayName())); ajx_current("back"); } catch (Exception $ex) { DB::rollback(); flash_success(lang('error update config value', $category->getDisplayName())); } } // if }