cmc-sales/controllers/industries_controller.php

81 lines
2.3 KiB
PHP

<?php
class IndustriesController extends AppController {
var $name = 'Industries';
var $helpers = array('Html', 'Form');
var $paginate = array(
'Industry' => array('order' => array('ParentIndustry.name' => 'asc', 'Industry.name' => 'asc'),
'limit' => 200
));
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));
}
}
/* Parent Industries have NULL for their parent_id */
$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'));
}
}
}
?>