/**
  * Show and process config category form
  *
  * @param void
  * @return null
  */
 function update_category()
 {
     $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);
     $submitted_values = array_var($_POST, 'options');
     if (is_array($submitted_values)) {
         foreach ($options as $option) {
             $new_value = array_var($submitted_values, $option->getName());
             if (is_null($new_value) || $new_value == $option->getValue()) {
                 continue;
             }
             $option->setValue($new_value);
             $option->save();
         }
         // foreach
         flash_success(lang('success update config category', $category->getDisplayName()));
         $this->redirectTo('administration', 'configuration');
     }
     // if
     $this->setSidebar(get_template_path('update_category_sidebar', 'config'));
 }
 /**
  * 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
 }
 /**
  * Return manager instance
  *
  * @access protected
  * @param void
  * @return ConfigCategories 
  */
 function manager()
 {
     if (!$this->manager instanceof ConfigCategories) {
         $this->manager = ConfigCategories::instance();
     }
     return $this->manager;
 }
 /**
  * Show configuration index page
  *
  * @param void
  * @return null
  */
 function configuration()
 {
     if (!can_manage_configuration(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $this->addHelper('textile');
     tpl_assign('config_categories', ConfigCategories::getAll());
 }
 /**
  * This function will return paginated result. Result is an array where first element is 
  * array of returned object and second populated pagination object that can be used for 
  * obtaining and rendering pagination data using various helpers.
  * 
  * Items and pagination array vars are indexed with 0 for items and 1 for pagination
  * because you can't use associative indexing with list() construct
  *
  * @access public
  * @param array $arguments Query argumens (@see find()) Limit and offset are ignored!
  * @param integer $items_per_page Number of items per page
  * @param integer $current_page Current page number
  * @return array
  */
 function paginate($arguments = null, $items_per_page = 10, $current_page = 1)
 {
     if (isset($this) && instance_of($this, 'ConfigCategories')) {
         return parent::paginate($arguments, $items_per_page, $current_page);
     } else {
         return ConfigCategories::instance()->paginate($arguments, $items_per_page, $current_page);
         //$instance =& ConfigCategories::instance();
         //return $instance->paginate($arguments, $items_per_page, $current_page);
     }
     // if
 }
 /**
  * Show configuration index page
  *
  * @param void
  * @return null
  */
 function configuration()
 {
     $this->addHelper('textile');
     tpl_assign('config_categories', ConfigCategories::getAll());
 }
 /**
 * Return manager instance
 *
 * @access protected
 * @param void
 * @return ConfigCategories 
 */
 function manager() {
   if(!($this->manager instanceof ConfigCategories)) $this->manager = ConfigCategories::instance();
   return $this->manager;
 } // manager
 /**
  * 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) {
             $new_value = array_var($submited_values, $option->getName());
             if (is_null($new_value) || $new_value == $option->getValue()) {
                 continue;
             }
             $option->setValue($new_value);
             $option->save();
         }
         // foreach
         flash_success(lang('success update config category', $category->getDisplayName()));
         ajx_current("back");
     }
     // if
 }