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/CareersController.php

<?php

App::uses('AppController', 'Controller');

class CareersController extends AppController
{
	public $components = array('Paginator', 'Session', 'Flash');
	public $helpers = array('Text');

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

	public function admin_add() {
		if ($this->request->is('post')) {
			$this->Career->create();
			$this->request->data['Career']['token'] = md5(date('Y-m-d H:i:s'));
			if ($this->Career->save($this->request->data)) {
				$this->Flash->success(__('The career has been saved.'));
				return $this->redirect(array('action' => 'add'));
			} else {
				$this->Flash->error(__('The career could not be saved. Please, try again.'));
			}
		}
		$this->Career->recursive = 0;
		$this->paginate = array('order' => 'Career.id DESC');
		$this->set('careers', $this->Paginator->paginate());
	}

	public function admin_edit($token = null) {
		//@valid token
		$this->is_empty($token);

		$options = array('conditions' => array('Career.token' => $token));
		$data = $this->Career->find('first', $options);

		if(empty($data)) {
			$this->is_empty($token);
		}
		if ($this->request->is(array('post', 'put'))) {
			$this->request->data['User']['token'] = md5(date('Y-m-d H:i:s'));

			if ($this->Career->save($this->request->data)) {
				$this->Flash->success(__('The career has been updated.'));
				return $this->redirect(array('action' => 'add'));
			} else {
				$this->Flash->error(__('The career could not be saved. Please, try again.'));
			}
		} else {
			$this->request->data = $data;
		}

		$this->Career->recursive = 0;
		$this->paginate = array('order' => 'Career.id DESC');
		$this->set('careers', $this->Paginator->paginate());
	}

	public function admin_delete($token = null){
		$id = $this->Career->field('id', array('Career.token' => $token));
		$this->is_empty($id);
		$this->request->allowMethod('post', 'delete');
		if ($this->Career->delete($id, true)) {
			$this->Flash->success(__('The career has been deleted.'));
		} else {
			$this->Flash->error(__('The career could not be deleted. It is in use.'));
		}
		$this->redirect(array('action' => 'add'));
	}

	private function is_empty($token = null){
		if(empty($token)) {
			$this->Flash->error(__('Oops !!!, you are trying with wrong data'));
			$this->redirect(array('action' => 'add'));
		}
	}
}