/** * List user preferences * */ function update_user_preferences(){ $category = ContactConfigCategories::findById(get_id()); if(!($category instanceof ContactConfigCategory)) { flash_error(lang('config category dnx')); $this->redirectToReferer(get_url('contact','card')); } // if if($category->isEmpty()) { flash_error(lang('config category is empty')); $this->redirectToReferer(get_url('contact','card')); } // if $options = $category->getContactOptions(false); $categories = ContactConfigCategories::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) { // update cache if available if (GlobalCache::isAvailable()) { GlobalCache::delete('user_config_option_'.logged_user()->getId().'_'.$option->getName()); } if($option->getName() == "reminders_events" || $option->getName() == "reminders_tasks"){ $array_value = array_var($submited_values, $option->getName()); $new_value = array_var($array_value,"reminder_type") . "," . array_var($array_value,"reminder_duration") . "," . array_var($array_value,"reminder_duration_type"); }else{ $new_value = array_var($submited_values, $option->getName()); } if(is_null($new_value) || ($new_value == $option->getContactValue(logged_user()->getId()))) continue; $option->setContactValue($new_value, logged_user()->getId()); $option->save(); evt_add("user preference changed", array('name' => $option->getName(), 'value' => $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 } //list_preferences
/** * Update default user preferences * */ function update_default_user_preferences() { $category = ContactConfigCategories::findById(get_id()); if (!$category instanceof ContactConfigCategory) { 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->getContactOptions(false); $categories = ContactConfigCategories::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) { // update global cache if available if (GlobalCache::isAvailable()) { GlobalCache::delete('user_config_option_def_' . $option->getName()); } $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)); } } // 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 }