false, 'limit' => 100, 'order'=>array('Shipment.id' => 'desc'), 'recursive' => 1 ); function index() { $this->Shipment->recursive = 0; $this->set('shipments', $this->paginate()); $principles = $this->Shipment->Principle->find('list'); $freightForwarders = $this->Shipment->FreightForwarder->find('list'); $shipmentType = $this->typeOptions(false); $shipmentTypeShort = $this->typeOptions(true); $this->set(compact('principles', 'freightForwarders', 'shipmentType', 'shipmentTypeShort')); } function view($id = null) { if (!$id) { $this->Session->setFlash(__('Invalid Shipment.', true)); $this->redirect(array('action'=>'index')); } $this->set('shipment', $this->Shipment->read(null, $id)); } function add() { $principles = $this->Shipment->Principle->find('list'); $freightForwarders = $this->Shipment->FreightForwarder->find('list'); $shipmentType = $this->typeOptions(false); $shipmentTypeShort = $this->typeOptions(true); $this->set(compact('principles', 'freightForwarders', 'shipmentType', 'shipmentTypeShort')); } function edit($id = null) { if(isset($id)) { if (empty($this->data)) { $this->data = $this->Shipment->read(null, $id); $principles = $this->Shipment->Principle->find('list'); $freightForwarders = $this->Shipment->FreightForwarder->find('list'); $shipmentType = $this->typeOptions(false); $shipmentTypeShort = $this->typeOptions(true); $this->set(compact('principles', 'freightForwarders', 'shipmentType', 'shipmentTypeShort')); } } } function ajax_edit() { $this->layout = 'ajax'; if(!empty($this->data)) { //$this->Shipment->create($this->data); if ($this->Shipment->saveAll($this->data)) { echo "SUCCESS"; } else { echo "FAILURE"; } } else { echo "NO-DATA"; } } function ajax_add() { $this->layout = 'ajax'; if(!empty($this->data)) { $this->Shipment->create($this->data); if ($this->Shipment->saveAll($this->data)) { echo "SUCCESS"; } else { echo "FAILURE"; } } else { echo "NO-DATA"; } } /* Moved the Views for Adding/Editing to elements. Called from the Index. * * function add($action = 'add') { $principles = $this->Shipment->Principle->find('list'); $freightForwarders = $this->Shipment->FreightForwarder->find('list'); $shipmentType = $this->typeOptions(); $this->set(compact('principles', 'freightForwarders', 'shipmentType')); }*/ function typeOptions($short = false) { if($short == false) { $options = array('','Import: Principle to CMC','Direct: Principle to Customer','Export','Local'); } else { $options = array('','Import','Direct','Export','Local'); } return $options; } function delete($id = null) { if (!$id) { $this->Session->setFlash(__('Invalid id for Shipment', true)); $this->redirect(array('action'=>'index')); } if ($this->Shipment->del($id)) { $this->Session->setFlash(__('Shipment deleted', true)); $this->redirect(array('action'=>'index')); } } } ?>