MSV FM

dot.antimicrobial@66.96.161.157: ~ $
Path : /hermes/bosweb/b1705/silverkeyhomesinc.ca/admin_dawncs_backup/app/Controller/
File Upload :
Current < : /hermes/bosweb/b1705/silverkeyhomesinc.ca/admin_dawncs_backup/app/Controller/BanksController.php

<?php
App::uses('AppController', 'Controller');

class BanksController extends AppController
{

	public $components = array('Paginator', 'Session', 'Flash');

	public function beforeFilter()
	{
		parent::beforeFilter();
		$this->Auth->allow();
	}

	public function admin_add()
	{
		if ($this->request->is('post')) {
			$this->Bank->create();
			if ($this->Bank->save($this->request->data)) {
				$this->Flash->success(__('The Bank has been saved.'));
				$this->redirect(array('action' => 'add'));
			} else {
				$this->Flash->error(__('The Bank could not be saved. Please, try again.'));
			}
		}

		$this->Bank->recursive = 0;
		$this->set('banks', $this->Paginator->paginate());

	}

	public function admin_edit($id = null)
	{
		if (!$this->Bank->exists($id)) {
			throw new NotFoundException(__('Invalid Bank'));
		}
		if ($this->request->is(array('post', 'put'))) {

			if($this->request->data['Bank']['id'] == 1) {
				$this->request->data['Bank']['name'] = 'Cash Deposit';
			}

			if ($this->Bank->save($this->request->data)) {
				$this->Flash->success(__('The Bank has been updated.'));
				$this->redirect(array('action' => 'add'));
			} else {
				$this->Flash->error(__('The Bank could not be saved. Please, try again.'));
			}
		} else {
			$options = array('conditions' => array('Bank.' . $this->Bank->primaryKey => $id), 'recursive' => -1);
			$this->request->data = $this->Bank->find('first', $options);
		}
		$this->Bank->recursive = 0;
		$this->set('banks', $this->Paginator->paginate());
	}

	public function admin_delete($id = null)
	{
		$this->Bank->id = $id;
		if (!$this->Bank->exists()) {
			throw new NotFoundException(__('Invalid Bank'));
		}
		$this->request->allowMethod('post', 'delete');
		$is_exists = $this->Bank->AmountTransaction->find('count', array('conditions' => array('bank_id' => $id)));
		if (!$is_exists && $this->Bank->delete()) {
			$this->Flash->success(__('The Bank has been deleted.'));
		} else {
			$this->Flash->error(__('The Bank could not be deleted. It is in use.'));
		}
		$this->redirect(array('action' => 'add'));
	}
}