<?php

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

class ProfilesController extends WebvalController {
	
	var $scaffold = true;
	
	function index()
	{
		$this->Profile->recursive = 2;
		/*$fp = FirePHP::getInstance(true);
		$fp->log($this->paginate(), 'profiles');*/
		$this->set('profiles', $this->paginate());
	}
	
	function edit($id = null) {
		$this->Profile->recursive = 2;
		if (!$id && empty($this->data)) {
			$this->Session->setFlash('Neexistujúci profil');
			$this->redirect(array('action'=>'index'));
		}
		
		if (!empty($this->data)) {
			if($this->Profile->saveAll($this->data)) {
	            $this->Session->setFlash("Profil uložený");
	            $this->redirect(array('action'=>'index'));
	        }
		}
		
		if (empty($this->data)) {
			$this->data = $this->Profile->read(null, $id);
		}		
	}
	
	function add()
	{
		$criteria = $this->Profile->ProfileCriterium->Criterium->find('list',array('fields'=>array('id','name')));
		$this->set(compact('criteria'));
		
		if (!empty($this->data)) {
			if($this->Profile->saveAll($this->data)) {
	            $this->Session->setFlash("Profil vytvorený");
	            $this->redirect(array('action'=>'index'));
	        }
		}		
	}
	
	
}

?>