<?php

/**
 * SettingsController - Global settings management
 * 
 * @author Lukáš Havlíček
 * @version 1.0
 */
class Admin_SettingsController extends Zend_Controller_Action 
{
	
	
	public function init()
	{
		$this->view->topmenu = 6;
		$this->view->leftmenu = 5;
	}

	public function indexAction() 
    {
		$table = new Settings();
		$select = $table->select()
						->order('position ASC');
						
		$data = $table->fetchAll($select);
		
		if ($this->_request->isPost()) {
			
			$values = $this->_request->getPost();
			
			$update = array();
			foreach ($data as $i) {
				if ($i->input_type != 'checkbox') {
					
					$table->setValue($i->key, $values[$i->key]);
					
				} else {

					if (!isset($values[$i->key])) {
						$table->setValue($i->key, 0);
					} else {
						$table->setValue($i->key, 1);
					}
				}
			}
			
			$this->_redirect('admin/settings/index/msg/1');
		}
		
    	$this->view->data = $data;
    	
    	$msg = $this->_getParam('msg', 0);
    	$this->view->msg = $msg;
    }
}