/bqregsys/app/controllers/registrations_controller.php
PHP | 191 lines | 157 code | 21 blank | 13 comment | 33 complexity | 53a064c22c72362b1e12e34a49e3646b MD5 | raw file
Possible License(s): LGPL-2.1
- <?php
- class RegistrationsController extends AppController {
-
- var $name = 'Registrations';
- var $helpers = array('Html', 'Form', 'Javascript');
- var $components = array('Email');
-
- function beforeFilter() {
- $this->Auth->allow('add');
- $this->Auth->allow('resume');
- $this->Auth->allow('edit');
- $this->Auth->allow('thank_you');
- }
-
- function resume() {
- $this->Session->destroy();
- if (!empty($this->data)) {
- $registration = $this->Registration->find('first', array('conditions'=>array('Registration.email'=>$this->data['email'], 'Registration.resumption_key'=>$this->data['resumption_key'])));
- if (!empty($registration)) {
- $this->Session->write('registration_id', $registration['Registration']['id']);
- $this->Session->write('resumption_key', $registration['Registration']['resumption_key']);
- $this->redirect(array('action'=>'edit', $registration['Registration']['id']));
- }
- else {
- $this->Session->setFlash('Email or resumption key invalid.');
- }
- }
- }
-
- function index() {
- $this->Registration->recursive = 1;
-
- $this->set('registrations', $this->paginate());
- }
-
- function view($id = null) {
- if (!$id) {
- $this->Session->setFlash(__('Invalid Registration.', true));
- $this->redirect(array('action'=>'index'));
- }
- $this->set('registration', $this->Registration->read(null, $id));
- }
-
- /*function add() {
- if (!empty($this->data)) {
- $this->Registration->create();
- if ($this->Registration->save($this->data)) {
- $this->Session->setFlash(__('The Registration has been saved', true));
- $this->redirect(array('action'=>'index'));
- } else {
- $this->Session->setFlash(__('The Registration could not be saved. Please, try again.', true));
- }
- }
- $tournaments = $this->Registration->Tournament->find('list');
- $this->set(compact('tournaments'));
- }*/
-
- function add() {
- if(!empty($this->data)) {
- $this->data['Registration']['resumption_key'] = substr(md5(uniqid(rand(), true)), 0, 12);
- if ($this->Registration->saveAll($this->data, array('validate'=>'first'))) {
- $this->Session->setFlash(__('The Registration has been saved', true));
- $this->Session->write('resumption_key', $this->data['Registration']['resumption_key']);
- $this->redirect(array('action'=>'thank_you'));
- } else {
- $this->Session->setFlash(__('The Registration could not be saved. Please, try again.', true));
- }
- }
- $tournaments = $this->Registration->Tournament->find('list');
- $this->set(compact('tournaments'));
- }
-
- function edit($id = null) {
- if (!($this->Session->read('registration_id') == $id)) {
- if (!$this->Session->check('Auth.User.id')) {
- $this->redirect(array('action'=>'resume'));
- }
- }
- if (!$id && empty($this->data)) {
- $this->Session->setFlash(__('Invalid Registration', true));
- $this->redirect(array('action'=>'index'));
- }
- if (!empty($this->data)) {
- $registration = $this->Registration->findById($id);
- $this->data['Registration']['resumption_key'] = $registration['Registration']['resumption_key'];
-
- $this->Registration->deleteAll(array('Registration.id' => $id));
- if ($this->Registration->saveAll($this->data, array('validate'=>'first'))) {
- if ($this->Session->check('Auth.User.id')) {
- $this->redirect(array('action'=>'index'));
- }
- else {
- $registration = $this->Registration->findById($id);
- $this->redirect(array('action'=>'thank_you'));
- }
- } else {
- $this->Session->setFlash('The Registration could not be saved. Please, try again.');
- $this->Session->destroy();
- }
- }
- if (empty($this->data)) {
-
- $this->data = $this->Registration->findById($id);
- $this->set('registration',$this->data);
- $this->set('registration_id', $id);
- }
- $tournaments = $this->Registration->Tournament->find('list');
- $this->set(compact('tournaments'));
- }
-
- function thank_you() {
- if (!$this->Session->check('resumption_key')) {
- $this->redirect(array('action'=>'add'));
- }
-
- $this->set('resumption_key', $this->Session->read('resumption_key'));
- $this->Session->destroy();
- }
-
- function delete($id = null) {
- if (!$id) {
- $this->Session->setFlash(__('Invalid id for Registration', true));
- $this->redirect(array('action'=>'index'));
- }
- if ($this->Registration->del($id)) {
- $this->Session->setFlash(__('Registration deleted', true));
- $this->redirect(array('action'=>'index'));
- }
- }
-
-
- function admin_index() {
- $this->Registration->recursive = 0;
- $this->set('registrations', $this->paginate());
- }
-
- function admin_view($id = null) {
- if (!$id) {
- $this->Session->setFlash(__('Invalid Registration.', true));
- $this->redirect(array('action'=>'index'));
- }
- $this->set('registration', $this->Registration->read(null, $id));
- }
-
- function admin_add() {
- if (!empty($this->data)) {
- $this->Registration->create();
- if ($this->Registration->save($this->data)) {
- $this->Session->setFlash(__('The Registration has been saved', true));
- $this->redirect(array('action'=>'index'));
- } else {
- $this->Session->setFlash(__('The Registration could not be saved. Please, try again.', true));
- }
- }
- $tournaments = $this->Registration->Tournament->find('list');
- $this->set(compact('tournaments'));
- }
-
- function admin_edit($id = null) {
- if (!$id && empty($this->data)) {
- $this->Session->setFlash(__('Invalid Registration', true));
- $this->redirect(array('action'=>'index'));
- }
- if (!empty($this->data)) {
- if ($this->Registration->save($this->data)) {
- $this->Session->setFlash(__('The Registration has been saved', true));
- $this->redirect(array('action'=>'index'));
- } else {
- $this->Session->setFlash(__('The Registration could not be saved. Please, try again.', true));
- }
- }
- if (empty($this->data)) {
- $this->data = $this->Registration->read(null, $id);
- }
- $tournaments = $this->Registration->Tournament->find('list');
- $this->set(compact('tournaments'));
- }
-
- function admin_delete($id = null) {
- if (!$id) {
- $this->Session->setFlash(__('Invalid id for Registration', true));
- $this->redirect(array('action'=>'index'));
- }
- if ($this->Registration->del($id)) {
- $this->Session->setFlash(__('Registration deleted', true));
- $this->redirect(array('action'=>'index'));
- }
- }
-
- }
- ?>