<?php

App::import('Controller', array('Webval'));

class CategoriesController extends WebvalController {
	
	var $scaffold = true;
	
	function index()
	{
		$this->Category->recursive = 0;
		$this->set('categories', $this->paginate());
	}
	
	function edit($id = null) {
		$this->Category->recursive = 0;
		if (!$id && empty($this->data)) {
			$this->Session->setFlash('Neexistujúca kategória');
			$this->redirect(array('action'=>'index'));
		}
		
		if (!empty($this->data)) {
			if($this->Category->saveAll($this->data)) {
	            $this->Session->setFlash("Kategória uložená");
	            $this->redirect(array('action'=>'index'));
	        }
		}
		
		if (empty($this->data)) {
			$this->data = $this->Category->read(null, $id);
		}		
	}
	
	function add()
	{
		if (!empty($this->data)) {
			if($this->Category->saveAll($this->data)) {
	            $this->Session->setFlash("Kategória vytvorená");
	            $this->redirect(array('action'=>'index'));
	        }
		}		
	}
	
	
}

?>