105 lines
3.3 KiB
PHP
Executable file
105 lines
3.3 KiB
PHP
Executable file
<?php
|
|
class ContactsController extends AppController {
|
|
|
|
var $name = 'Contacts';
|
|
var $helpers = array('Html', 'Form', 'Ajax');
|
|
var $components = array('RequestHandler');
|
|
var $paginate = array(
|
|
'Contact' => array('order' => array('Contact.customer_id' => 'asc')),
|
|
'Enquiry' => array('order' => array('Enquiry.id' => 'asc'))
|
|
);
|
|
|
|
function index() {
|
|
$this->Contact->recursive = 0;
|
|
$this->set('contacts', $this->paginate());
|
|
}
|
|
|
|
function view($id = null) {
|
|
if (!$id) {
|
|
$this->Session->setFlash(__('Invalid Contact.', true));
|
|
$this->redirect(array('action'=>'index'));
|
|
}
|
|
$this->set('contact', $this->Contact->read(null, $id));
|
|
//$enquiries = $this->Contact->Enquiry->findAllByContactId($id);
|
|
$this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.contact_id' => $id)));
|
|
//$this->set('enquiries', $this->paginate($enquiries));
|
|
}
|
|
|
|
|
|
|
|
function add_to_customer($customerid = null) {
|
|
|
|
if(isset($this->params['named']['customerid'])) {
|
|
$customerid = $this->params['named']['customerid'];
|
|
}
|
|
if (!$customerid && empty($this->data)) {
|
|
$this->Session->setFlash(__('Invalid Customer ID', true));
|
|
$this->redirect(array('controller'=>'Enquiries', 'action'=>'index'));
|
|
}
|
|
if (!empty($this->data)) {
|
|
|
|
$this->Contact->create();
|
|
if ($this->Contact->save($this->data)) {
|
|
$this->Session->setFlash(__('The Contact has been saved', true));
|
|
$this->redirect(array('controller' => 'Customers', 'action'=>'view/'.$this->data['Contact']['customer_id']));
|
|
} else {
|
|
$this->Session->setFlash(__('The Contact could not be saved. Please try again.', true));
|
|
}
|
|
}
|
|
|
|
$customer = $this->Contact->Customer->findById($customerid);
|
|
$this->set(compact('customer'));
|
|
}
|
|
|
|
function add_another($increment) {
|
|
$this->set('increment', $increment);
|
|
|
|
}
|
|
function remove_another($increment) {
|
|
$this->set('increment', $increment);
|
|
}
|
|
function add_one($customerid) {
|
|
$this->set('customerid', $customerid);
|
|
}
|
|
function remove_one($customerid) {
|
|
$contacts = $this->Contact->find('all', array('conditions' => array('Contact.customer_id' => $customerid)));
|
|
$contacts = Set::Combine($contacts, '{n}.Contact.id', array('{0} {1}', '{n}.Contact.first_name', '{n}.Contact.last_name'));
|
|
$this->set('contacts', $contacts);
|
|
$this->set('customerid', $customerid);
|
|
}
|
|
|
|
function edit($id = null) {
|
|
if (!$id && empty($this->data)) {
|
|
$this->Session->setFlash(__('Invalid Contact', true));
|
|
$this->redirect(array('action'=>'index'));
|
|
}
|
|
if (!empty($this->data)) {
|
|
$this->data['Contact']['name'] = $this->data['Contact']['first_name'].' '.$this->data['Contact']['last_name'];
|
|
if ($this->Contact->save($this->data)) {
|
|
$this->Session->setFlash(__('The Contact has been saved', true));
|
|
$this->redirect(array('action'=>'index'));
|
|
} else {
|
|
$this->Session->setFlash(__('The Contact could not be saved. Please, try again.', true));
|
|
}
|
|
}
|
|
if (empty($this->data)) {
|
|
$this->data = $this->Contact->read(null, $id);
|
|
}
|
|
$customers = $this->Contact->Customer->find('list');
|
|
$this->set(compact('customers'));
|
|
}
|
|
|
|
function delete($id = null) {
|
|
if (!$id) {
|
|
$this->Session->setFlash(__('Invalid id for Contact', true));
|
|
$this->redirect(array('action'=>'index'));
|
|
}
|
|
if ($this->Contact->del($id)) {
|
|
$this->Session->setFlash(__('Contact deleted', true));
|
|
$this->redirect(array('action'=>'index'));
|
|
}
|
|
}
|
|
|
|
}
|
|
?>
|