<?php
App::uses('AppController', 'Controller');
/**
 * Planos Controller
 *
 * @property Plano $Plano
 * @property PaginatorComponent $Paginator
 * @property SessionComponent $Session
 */
class PlanosController extends AppController {
	
/**
 * Components
 *
 * @var array
 */
	public $components = array('Paginator', 'Session');
	
/**
 * Included helpers.
 *
 * @var array
 */
	public $helpers = array('Api');

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

/**
 * admin_view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function admin_view($id = null) {
		if (!$this->Plano->exists($id)) {
			throw new NotFoundException(__('Invalid plano'));
		}
		$options = array('conditions' => array('Plano.' . $this->Plano->primaryKey => $id));
		$this->set('plano', $this->Plano->find('first', $options));
		$this->set('currentkey', $id);
	}

/**
 * admin_add method
 *
 * @return void
 */
	public function admin_add() {
		if ($this->request->is('post')) {
			$this->Plano->create();
			if ($this->Plano->save($this->request->data)) {
				$this->Session->setFlash(__('The plano has been saved.'));
				return $this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The plano could not be saved. Please, try again.'));
			}
		}
	}

/**
 * admin_edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function admin_edit($id = null) {
		$this->Plano->id = $id;
		if (!$this->Plano->exists()) {
			throw new NotFoundException(__('Invalid plano'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			if ($this->Plano->save($this->request->data)) {
				$this->Session->setFlash(__('The plano has been saved.'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The plano could not be saved. Please, try again.'));
			}
		} else {
			$this->request->data = $this->Plano->read(null, $id);
		}
	}

/**
 * admin_delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function admin_delete($id = null) {
		$this->Plano->id = $id;
		if (!$this->Plano->exists()) {
			throw new NotFoundException(__('Invalid plano'));
		}
		if ($this->Plano->delete()) {
			$this->Session->setFlash(__('The plano has been deleted.'));
		} else {
			$this->Session->setFlash(__('The plano could not be deleted. Please, try again.'));
		}
		$this->redirect(array('action' => 'index'));		
	}
}
