79 lines
2.4 KiB
PHP
79 lines
2.4 KiB
PHP
|
|
<?php
|
||
|
|
class AddressesController extends AppController {
|
||
|
|
|
||
|
|
var $name = 'Addresses';
|
||
|
|
var $helpers = array('Html', 'Form');
|
||
|
|
|
||
|
|
function index() {
|
||
|
|
$this->Address->recursive = 0;
|
||
|
|
$this->set('addresses', $this->paginate());
|
||
|
|
}
|
||
|
|
|
||
|
|
function view($id = null) {
|
||
|
|
if (!$id) {
|
||
|
|
$this->Session->setFlash(__('Invalid Address.', true));
|
||
|
|
$this->redirect(array('action'=>'index'));
|
||
|
|
}
|
||
|
|
$this->set('address', $this->Address->read(null, $id));
|
||
|
|
}
|
||
|
|
|
||
|
|
function add($customerid = null ) {
|
||
|
|
if(isset($this->params['named']['customerid'])) {
|
||
|
|
$customerid = $this->params['named']['customerid'];
|
||
|
|
}
|
||
|
|
if(!$customerid) {
|
||
|
|
$this->Session->setFlash(__('Invalid Customer ID', true));
|
||
|
|
$this->redirect(array('controller'=>'Enquiries', 'action'=>'index'));
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!empty($this->data)) {
|
||
|
|
$this->Address->create();
|
||
|
|
if ($this->Address->save($this->data)) {
|
||
|
|
$this->Session->setFlash(__('The Address has been saved', true));
|
||
|
|
$this->redirect(array('controller' => 'customers', 'action'=>'view/'.$customerid));
|
||
|
|
} else {
|
||
|
|
$this->Session->setFlash(__('The Address could not be saved. Please, try again.', true));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$customer = $this->Address->Customer->findById($customerid);
|
||
|
|
$states = $this->Address->State->find('list');
|
||
|
|
$countries = $this->Address->Country->find('list');
|
||
|
|
$this->set(compact('customer', 'states', 'countries'));
|
||
|
|
}
|
||
|
|
|
||
|
|
function edit($id = null) {
|
||
|
|
if (!$id && empty($this->data)) {
|
||
|
|
$this->Session->setFlash(__('Invalid Address', true));
|
||
|
|
$this->redirect(array('action'=>'index'));
|
||
|
|
}
|
||
|
|
if (!empty($this->data)) {
|
||
|
|
if ($this->Address->save($this->data)) {
|
||
|
|
$this->Session->setFlash(__('The Address has been saved', true));
|
||
|
|
$this->redirect(array('action'=>'index'));
|
||
|
|
} else {
|
||
|
|
$this->Session->setFlash(__('The Address could not be saved. Please, try again.', true));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (empty($this->data)) {
|
||
|
|
$this->data = $this->Address->read(null, $id);
|
||
|
|
}
|
||
|
|
$customers = $this->Address->Customer->find('list');
|
||
|
|
$states = $this->Address->State->find('list');
|
||
|
|
$countries = $this->Address->Country->find('list');
|
||
|
|
$this->set(compact('customers','states','countries'));
|
||
|
|
}
|
||
|
|
|
||
|
|
function delete($id = null) {
|
||
|
|
if (!$id) {
|
||
|
|
$this->Session->setFlash(__('Invalid id for Address', true));
|
||
|
|
$this->redirect(array('action'=>'index'));
|
||
|
|
}
|
||
|
|
if ($this->Address->del($id)) {
|
||
|
|
$this->Session->setFlash(__('Address deleted', true));
|
||
|
|
$this->redirect(array('action'=>'index'));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
?>
|