<?php

App::uses('AppController', 'Controller');

/**
 * Telefones Controller
 *
 * @property Telefone $Telefone
 */
class TelefonesController extends AppController {

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

    /**
     * admin_view method
     *
     * @param string $id
     * @return void
     */
    public function admin_view($id = null) {
        $this->Telefone->id = $id;
        if (!$this->Telefone->exists()) {
            throw new NotFoundException(__('Invalid telefone'));
        }
        $this->set('telefone', $this->Telefone->read(null, $id));
    }

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

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

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

}
