PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/Controller/ContactsController.php

https://github.com/Wargo/reddevil
PHP | 133 lines | 88 code | 45 blank | 0 comment | 16 complexity | c40ff7b9099cd88d4e529e80a1d5cf46 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1, GPL-3.0
  1. <?php
  2. class ContactsController extends AppController {
  3. function beforeFilter() {
  4. if(in_array($this->params['action'], array('feedback'))) {
  5. $this->Security->validatePost = false;
  6. $this->Security->csrfCheck = false;
  7. }
  8. return parent::beforeFilter();
  9. }
  10. function webmaster() {
  11. if ($this->request->data) {
  12. extract($this->request->data['Contact']);
  13. $must = array('name', 'email');
  14. $errors = array();
  15. foreach ($must as $field) {
  16. if (empty(${$field})) {
  17. $errors[] = $field;
  18. }
  19. }
  20. if (count($errors)) {
  21. $this->Session->setFlash(__('Ha ocurrido un error, revisa todos los datos'), 'default', array('class' => 'error'));
  22. $this->set(compact('errors'));
  23. return $this->render('/Pages/wannabe');
  24. }
  25. $this->request->data['Contact']['type'] = 'webmaster';
  26. $this->request->data['Contact']['ip'] = $_SERVER['REMOTE_ADDR'];
  27. $this->Contact->create();
  28. if ($this->Contact->save($this->request->data)) {
  29. $this->Session->setFlash(__('Formulario enviado correctamente'), 'default', array('class' => 'notification'));
  30. $this->request->data = null;
  31. } else {
  32. $this->Session->setFlash(__('Ha ocurrido un error, revisa todos los datos'), 'default', array('class' => 'error'));
  33. }
  34. }
  35. $this->render('/Pages/webmaster');
  36. }
  37. function contact() {
  38. if ($this->request->data) {
  39. extract($this->request->data['Contact']);
  40. $must = array('name', 'age', 'country', 'email');
  41. $errors = array();
  42. foreach ($must as $field) {
  43. if (empty(${$field})) {
  44. $errors[] = $field;
  45. }
  46. }
  47. if (count($errors)) {
  48. $this->Session->setFlash(__('Ha ocurrido un error, revisa todos los datos'), 'default', array('class' => 'error'));
  49. $this->set(compact('errors'));
  50. return $this->render('/Pages/wannabe');
  51. }
  52. $this->request->data['Contact']['ip'] = $_SERVER['REMOTE_ADDR'];
  53. $this->Contact->create();
  54. if ($this->Contact->save($this->request->data)) {
  55. $this->Session->setFlash(__('Formulario enviado correctamente'), 'default', array('class' => 'notification'));
  56. $this->request->data = null;
  57. } else {
  58. $this->Session->setFlash(__('Ha ocurrido un error, revisa todos los datos'), 'default', array('class' => 'error'));
  59. }
  60. }
  61. $this->render('/Pages/wannabe');
  62. }
  63. function feedback() {
  64. if ($this->request->is('ajax')) {
  65. $this->layout = 'ajax';
  66. }
  67. if ($this->request->data) {
  68. $this->Contact->create();
  69. $this->request->data['Contact']['type'] = 'feedback';
  70. $this->request->data['Contact']['ip'] = $_SERVER['REMOTE_ADDR'];
  71. $this->request->data['Contact']['country'] = $_SERVER['HTTP_USER_AGENT'];
  72. $this->request->data['Contact']['name'] = $this->Auth->user('id');
  73. $this->Contact->save($this->request->data);
  74. if (!$this->request->is('ajax')) {
  75. return $this->redirect('/');
  76. }
  77. }
  78. if (!$this->request->is('ajax')) {
  79. $this->render('/Pages/feedback');
  80. } else {
  81. $this->autoRender = false;
  82. }
  83. }
  84. function admin_index() {
  85. $contacts = $this->Contact->find('all', array('order' => array('created' => 'desc')));
  86. $this->set(compact('contacts'));
  87. }
  88. }