cmc-sales/app/controllers/principle_contacts_controller.php

79 lines
2.4 KiB
PHP
Raw Permalink Normal View History

<?php
class PrincipleContactsController extends AppController {
var $name = 'PrincipleContacts';
var $helpers = array('Html', 'Form');
function index() {
$this->PrincipleContact->recursive = 0;
$this->set('principleContacts', $this->paginate());
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid PrincipleContact.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('principleContact', $this->PrincipleContact->read(null, $id));
}
function add() {
if(isset($this->params['named']['principleid'])) {
$principleid = $this->params['named']['principleid'];
}
if (!(isset($principleid)) && empty($this->data)) {
$this->Session->setFlash(__('Invalid Principle ID', true));
$this->redirect(array('controller'=>'Principles', 'action'=>'index'));
}
if (!empty($this->data)) {
$this->PrincipleContact->create();
if ($this->PrincipleContact->save($this->data)) {
2009-03-19 15:11:22 -07:00
$this->Session->setFlash(__('The Contact has been added to the Principle', true));
$principleid = $this->data['PrincipleContact']['principle_id'];
2009-03-19 15:11:22 -07:00
$this->redirect(array('controller'=>'Principles', 'action'=>'view/'.$principleid));
} else {
$this->Session->setFlash(__('The PrincipleContact could not be saved. Please, try again.', true));
}
}
$principle = $this->PrincipleContact->Principle->findById($principleid);
$this->set(compact('principle'));
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid PrincipleContact', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
if ($this->PrincipleContact->save($this->data)) {
$this->Session->setFlash(__('The PrincipleContact has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The PrincipleContact could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->PrincipleContact->read(null, $id);
}
$principles = $this->PrincipleContact->Principle->find('list');
$this->set(compact('principles'));
}
function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for PrincipleContact', true));
$this->redirect(array('action'=>'index'));
}
if ($this->PrincipleContact->del($id)) {
$this->Session->setFlash(__('PrincipleContact deleted', true));
$this->redirect(array('action'=>'index'));
}
}
}
?>