2009-01-12 21:13:18 -08:00
|
|
|
<?php
|
|
|
|
|
class AddressesController extends AppController {
|
|
|
|
|
|
|
|
|
|
var $name = 'Addresses';
|
2011-04-29 00:18:44 -07:00
|
|
|
var $helpers = array('Html', 'Form');
|
2009-02-03 17:49:44 -08:00
|
|
|
var $components = array('RequestHandler');
|
2009-01-12 21:13:18 -08:00
|
|
|
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'));
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-03 17:49:44 -08:00
|
|
|
function add_another($increment) {
|
|
|
|
|
$this->set('increment', $increment);
|
|
|
|
|
$states = $this->Address->State->find('list');
|
|
|
|
|
$countries = $this->Address->Country->find('list');
|
|
|
|
|
$this->set('states', $states);
|
|
|
|
|
$this->set('countries', $countries);
|
|
|
|
|
}
|
|
|
|
|
function remove_another($increment) {
|
|
|
|
|
$this->set('increment', $increment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-01-12 21:13:18 -08:00
|
|
|
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)) {
|
2009-02-09 21:39:26 -08:00
|
|
|
$id = $this->Address->id;
|
|
|
|
|
$address = $this->Address->findById($id);
|
2009-01-12 21:13:18 -08:00
|
|
|
$this->Session->setFlash(__('The Address has been saved', true));
|
2009-02-09 21:39:26 -08:00
|
|
|
$this->redirect(array('controller' => 'customers', 'action'=>'view/'.$address['Address']['customer_id']));
|
2009-01-12 21:13:18 -08:00
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The Address could not be saved. Please, try again.', true));
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-02-09 21:39:26 -08:00
|
|
|
|
|
|
|
|
$address = $this->Address->read(null, $id);
|
|
|
|
|
$customer = $this->Address->Customer->findById($address['Address']['customer_id']);
|
2009-01-12 21:13:18 -08:00
|
|
|
$states = $this->Address->State->find('list');
|
|
|
|
|
$countries = $this->Address->Country->find('list');
|
2009-02-09 21:39:26 -08:00
|
|
|
$this->set(compact('customer','states','countries', 'address'));
|
|
|
|
|
if (empty($this->data)) {
|
|
|
|
|
$this->data = $address;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-12 21:13:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-04-29 00:18:44 -07:00
|
|
|
|
|
|
|
|
function customerAddresses($customerID) {
|
|
|
|
|
$this->layout = 'ajax';
|
|
|
|
|
|
|
|
|
|
$this->set('addresses', $this->Address->find('all', array('conditions'=>array('Customer.id'=>$customerID))));
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-12 21:13:18 -08:00
|
|
|
}
|
|
|
|
|
?>
|