cmc-sales/controllers/industries_controller.php
Karl Cordes 5b1f72489b Rah
2009-07-06 11:25:53 +10:00

74 lines
2.1 KiB
PHP

<?php
class IndustriesController extends AppController {
var $name = 'Industries';
var $helpers = array('Html', 'Form');
function index() {
$this->Industry->recursive = 0;
$this->set('industries', $this->paginate());
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Industry.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('industry', $this->Industry->read(null, $id));
}
function add() {
if (!empty($this->data)) {
$this->Industry->create();
if ($this->Industry->save($this->data)) {
$this->Session->setFlash(__('The Industry has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Industry could not be saved. Please, try again.', true));
}
}
$parents = $this->Industry->find('list', array('conditions' => array(
'Industry.parent_id' => null)));
$this->set(compact('parents'));
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Industry', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
if ($this->Industry->save($this->data)) {
$this->Session->setFlash(__('The Industry has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Industry could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Industry->read(null, $id);
}
$parents = $this->Industry->find('list', array('conditions' => array(
'Industry.parent_id' => null,
'NOT' => array(
'Industry.id' => $this->data['Industry']['id']
))));
$customers = $this->Industry->Customer->find('list');
$this->set(compact('customers', 'parents'));
}
function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for Industry', true));
$this->redirect(array('action'=>'index'));
}
if ($this->Industry->del($id)) {
$this->Session->setFlash(__('Industry deleted', true));
$this->redirect(array('action'=>'index'));
}
}
}
?>