cmc-sales/app/controllers/states_controller.php

70 lines
1.8 KiB
PHP
Raw Permalink Normal View History

<?php
class StatesController extends AppController {
var $name = 'States';
var $helpers = array('Html', 'Form');
var $paginate = array(
'States' => array('order' => array('State.id' => 'asc')),
'Enquiry' => array('order' => array('Enquiry.id' => 'asc', 'limit'=> 200))
);
function index() {
$this->State->recursive = 0;
$this->set('states', $this->paginate());
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid State.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('state', $this->State->read(null, $id));
$this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.state_id' => $id)));
}
function add() {
if (!empty($this->data)) {
$this->State->create();
if ($this->State->save($this->data)) {
$this->Session->setFlash(__('The State has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The State could not be saved. Please, try again.', true));
}
}
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid State', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
if ($this->State->save($this->data)) {
$this->Session->setFlash(__('The State has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The State could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->State->read(null, $id);
}
}
function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for State', true));
$this->redirect(array('action'=>'index'));
}
if ($this->State->del($id)) {
$this->Session->setFlash(__('State deleted', true));
$this->redirect(array('action'=>'index'));
}
}
}
?>