Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

<?php
App::uses('AppController', 'Controller');
/**
 * Agents Controller
 *
 * @property Agent $Agent
 * @property PaginatorComponent $Paginator
 */
class AgentsController extends AppController {

/**
 * Components
 *
 * @var array
 */
        public $components = array('Paginator');

/**
 * index method
 *
 * @return void
 */
        public function index() {
                $this->Agent->recursive = 0;
                $this->set('agents', $this->Paginator->paginate());
        }

/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function view($id = null) {
                if (!$this->Agent->exists($id)) {
                        throw new NotFoundException(__('Invalid agent'));
                }
                $options = array('conditions' => array('Agent.' . $this->Agent->primaryKey => $id));
                $this->set('agent', $this->Agent->find('first', $options));
        }

/**
 * add method
 *
 * @return void
 */
        public function add() {
                if ($this->request->is('post')) {
                        $this->Agent->create();
                        if ($this->Agent->save($this->request->data)) {
                                $this->Session->setFlash(__('The agent has been saved.'));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The agent could not be saved. Please, try again.'));
                        }
                }
        }

/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function edit($id = null) {
                if (!$this->Agent->exists($id)) {
                        throw new NotFoundException(__('Invalid agent'));
                }
                if ($this->request->is(array('post', 'put'))) {
                        if ($this->Agent->save($this->request->data)) {
                                $this->Session->setFlash(__('The agent has been saved.'));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The agent could not be saved. Please, try again.'));
                        }
                } else {
                        $options = array('conditions' => array('Agent.' . $this->Agent->primaryKey => $id));
                        $this->request->data = $this->Agent->find('first', $options);
                }
        }

/**
 * delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function delete($id = null) {
                $this->Agent->id = $id;
                if (!$this->Agent->exists()) {
                        throw new NotFoundException(__('Invalid agent'));
                }
                $this->request->onlyAllow('post', 'delete');
                if ($this->Agent->delete()) {
                        $this->Session->setFlash(__('The agent has been deleted.'));
                } else {
                        $this->Session->setFlash(__('The agent could not be deleted. Please, try again.'));
                }
                return $this->redirect(array('action' => 'index'));
        }

/**
 * admin_index method
 *
 * @return void
 */
        public function admin_index() {
                $this->Agent->recursive = 0;
                $this->set('agents', $this->Paginator->paginate());
        }

/**
 * admin_view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function admin_view($id = null) {
                if (!$this->Agent->exists($id)) {
                        throw new NotFoundException(__('Invalid agent'));
                }
                $options = array('conditions' => array('Agent.' . $this->Agent->primaryKey => $id));
                $this->set('agent', $this->Agent->find('first', $options));
        }

/**
 * admin_add method
 *
 * @return void
 */
        public function admin_add() {
                if ($this->request->is('post')) {
                        $this->Agent->create();
                        if ($this->Agent->save($this->request->data)) {
                                $this->Session->setFlash(__('The agent has been saved.'));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The agent could not be saved. Please, try again.'));
                        }
                }
        }

/**
 * admin_edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function admin_edit($id = null) {
                if (!$this->Agent->exists($id)) {
                        throw new NotFoundException(__('Invalid agent'));
                }
                if ($this->request->is(array('post', 'put'))) {
                        if ($this->Agent->save($this->request->data)) {
                                $this->Session->setFlash(__('The agent has been saved.'));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The agent could not be saved. Please, try again.'));
                        }
                } else {
                        $options = array('conditions' => array('Agent.' . $this->Agent->primaryKey => $id));
                        $this->request->data = $this->Agent->find('first', $options);
                }
        }

/**
 * admin_delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function admin_delete($id = null) {
                $this->Agent->id = $id;
                if (!$this->Agent->exists()) {
                        throw new NotFoundException(__('Invalid agent'));
                }
                $this->request->onlyAllow('post', 'delete');
                if ($this->Agent->delete()) {
                        $this->Session->setFlash(__('The agent has been deleted.'));
                } else {
                        $this->Session->setFlash(__('The agent could not be deleted. Please, try again.'));
                }
                return $this->redirect(array('action' => 'index'));
        }
        public function authenticate(){
                $this->log(print_r($this->request->data,1),'authenticatication');
                $this->response->type('json');
                $this->layout = 'ajax';
                $this->User->recursive = -1;
                $email=$this->request->data['email'])
                $password=$this->request->data['password'])
                $role=$this->request->data['role'])
        }
}