2009-01-12 21:13:18 -08:00
|
|
|
<?php
|
|
|
|
|
class PrinciplesController extends AppController {
|
|
|
|
|
|
2011-04-28 00:41:36 -07:00
|
|
|
var $name = 'Principles';
|
|
|
|
|
var $helpers = array('Html', 'Form');
|
2009-01-12 21:13:18 -08:00
|
|
|
|
2011-04-28 00:41:36 -07:00
|
|
|
var $paginate = array(
|
2024-04-07 17:32:06 -07:00
|
|
|
'Principle' => array('limit' => 500, 'order' => array('Principle.name' => 'asc')),
|
2011-04-28 00:41:36 -07:00
|
|
|
'Enquiry' => array('limit' => 150, 'order' => array('Enquiry.id' => 'desc'))
|
|
|
|
|
);
|
2009-01-12 21:13:18 -08:00
|
|
|
|
2011-04-28 00:41:36 -07:00
|
|
|
function index() {
|
|
|
|
|
$this->Principle->recursive = 0;
|
|
|
|
|
$this->set('principles', $this->paginate());
|
|
|
|
|
$this->set('enquiries', $this->paginate());
|
|
|
|
|
}
|
2009-01-12 21:13:18 -08:00
|
|
|
|
2011-04-28 00:41:36 -07:00
|
|
|
function view($id = null) {
|
|
|
|
|
if (!$id) {
|
|
|
|
|
$this->Session->setFlash(__('Invalid Principle.', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
$this->set('principle', $this->Principle->read(null, $id));
|
|
|
|
|
$this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.principle_id' => $id)));
|
|
|
|
|
$this->set('addresses', $this->Principle->PrincipleAddress->findAllByPrincipleId($id));
|
|
|
|
|
$this->set('principleContacts', $this->Principle->PrincipleContact->find('all', array('conditions'=>array('PrincipleContact.principle_id'=>$id))));
|
|
|
|
|
$statuses = $this->Principle->Enquiry->Status->find('all');
|
|
|
|
|
$status_list = array();
|
|
|
|
|
foreach ($statuses as $status) {
|
|
|
|
|
$status_list[] = array($status['Status']['id'], $status['Status']['name']);
|
2009-01-12 21:13:18 -08:00
|
|
|
}
|
2011-04-28 00:41:36 -07:00
|
|
|
$this->set('status_list', $status_list);
|
|
|
|
|
$this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.principle_id' => $id)));
|
|
|
|
|
|
|
|
|
|
}
|
2009-01-12 21:13:18 -08:00
|
|
|
|
2011-04-28 00:41:36 -07:00
|
|
|
function add() {
|
|
|
|
|
if (!empty($this->data)) {
|
|
|
|
|
$this->Principle->create();
|
|
|
|
|
if ($this->Principle->save($this->data)) {
|
|
|
|
|
$this->Session->setFlash(__('The Principle has been saved', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The Principle could not be saved. Please, try again.', true));
|
|
|
|
|
}
|
2009-01-12 21:13:18 -08:00
|
|
|
}
|
2011-04-28 00:41:36 -07:00
|
|
|
$countries = $this->Principle->Country->find('list');
|
|
|
|
|
$currencies = $this->Principle->Currency->find('list');
|
|
|
|
|
$this->set(compact('countries', 'currencies'));
|
|
|
|
|
}
|
2009-01-12 21:13:18 -08:00
|
|
|
|
2011-04-28 00:41:36 -07:00
|
|
|
function edit($id = null) {
|
|
|
|
|
if (!$id && empty($this->data)) {
|
|
|
|
|
$this->Session->setFlash(__('Invalid Principle', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
if (!empty($this->data)) {
|
|
|
|
|
if ($this->Principle->save($this->data)) {
|
|
|
|
|
$this->Session->setFlash(__('The Principle has been saved', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The Principle could not be saved. Please, try again.', true));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->data)) {
|
|
|
|
|
$this->data = $this->Principle->read(null, $id);
|
2009-01-12 21:13:18 -08:00
|
|
|
}
|
2011-04-28 00:41:36 -07:00
|
|
|
$countries = $this->Principle->Country->find('list');
|
|
|
|
|
$currencies = $this->Principle->Currency->find('list');
|
|
|
|
|
$this->set(compact('countries','currencies'));
|
|
|
|
|
}
|
2009-01-12 21:13:18 -08:00
|
|
|
|
|
|
|
|
|
2024-04-19 21:18:39 -07:00
|
|
|
function defaults($id = null) {
|
|
|
|
|
$this->layout = 'ajax';
|
|
|
|
|
if($id == null) {
|
|
|
|
|
echo("No ID");
|
|
|
|
|
}
|
|
|
|
|
$principle = $this->Principle->read(null, $id);
|
|
|
|
|
$principle_json = json_encode($principle);
|
|
|
|
|
$this->set('principle_json', $principle_json);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-12 21:13:18 -08:00
|
|
|
}
|
|
|
|
|
?>
|