/**
  * 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
 }