<?php
App::uses('AppController', 'Controller');
/**
 * ReportFilters Controller
 *
 * @property ReportFilter $ReportFilter
 */
class ReportFiltersController extends AppController {


/**
 * admin_index method
 *
 * @return void
 */
	public function admin_index() {
		$this->ReportFilter->recursive = 0;
		$this->set('reportFilters', $this->paginate());
	}

/**
 * admin_add method
 *
 * @return void
 */
	public function admin_add() {
		if ($this->request->is('post')) {
			$this->ReportFilter->create();
			if ($this->ReportFilter->save($this->request->data)) {
				$this->Session->setFlash(__('The report filter has been saved'));
				
				$this->Session->write($this->request->data['ReportFilter']['report'],
							 explode(' ', $report['ReportFilter']['value']));
				
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The report filter could not be saved. Please, try again.'));
			}
		}
		$users = $this->ReportFilter->User->find('list');
		$this->set(compact('users'));
	}

/**
 * admin_edit method
 *
 * @param string $id
 * @return void
 */
	public function admin_edit($id = null) {
		$this->ReportFilter->id = $id;
		if (!$this->ReportFilter->exists()) {
			throw new NotFoundException(__('Invalid report filter'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			if ($this->ReportFilter->save($this->request->data)) {
				$this->Session->setFlash(__('The report filter has been saved'));
				
				$this->Session->write($this->request->data['ReportFilter']['report'],
							 $report['ReportFilter']['value']);
				
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The report filter could not be saved. Please, try again.'));
			}
		} else {
			$this->request->data = $this->ReportFilter->read(null, $id);
		}
		$users = $this->ReportFilter->User->find('list');
		$this->set(compact('users'));
	}

/**
 * admin_delete method
 *
 * @param string $id
 * @return void
 */
	public function admin_delete($id = null) {
		if (!$this->request->is('post')) {
			throw new MethodNotAllowedException();
		}
		$this->ReportFilter->id = $id;
		if (!$this->ReportFilter->exists()) {
			throw new NotFoundException(__('Invalid report filter'));
		}
		if ($this->ReportFilter->delete()) {
			$this->Session->setFlash(__('Report filter deleted'));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('Report filter was not deleted'));
		$this->redirect(array('action' => 'index'));
	}
}
