Ingen beskrivning

FeedbackController.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. class FeedbackController extends \BaseController {
  3. /**
  4. * Show the form for creating a new resource.
  5. *
  6. * @return Response
  7. */
  8. public function create()
  9. {
  10. $title = "Feedback Form";
  11. $schools = School::orderBy('name','asc');
  12. $user = Auth::user();
  13. return View::make('global.feedback', compact('title', 'schools', 'user'));
  14. }
  15. public function send()
  16. {
  17. /** Validation rules */
  18. $validator = Validator::make(
  19. array(
  20. 'type' => Input::get('type'),
  21. 'email' => Input::get('email'),
  22. 'comment' => Input::get('comment')
  23. ),
  24. array(
  25. 'type' => 'required|numeric|integer',
  26. 'email' => 'required|email',
  27. 'comment' => 'required'
  28. )
  29. );
  30. /** If validation fails */
  31. if ($validator->fails())
  32. {
  33. /** Prepare error message */
  34. $message = '<p>Error(s) in the form</p><ul>';
  35. foreach ($validator->messages()->all('<li>:message</li>') as $validationError)
  36. {
  37. $message.=$validationError;
  38. }
  39. $message.='</ul>';
  40. /** Send error message and old data */
  41. Session::flash('status', 'warning');
  42. Session::flash('message', $message);
  43. return Redirect::back()->withInput();
  44. }
  45. else
  46. {
  47. $data = array('type'=>'', 'comment'=>'', 'email'=>'');
  48. $data['comment']=Input::get('comment');
  49. $data['email']=Input::get('email');
  50. switch (Input::get('type')) {
  51. case '0':
  52. $data['type']='Error Report';
  53. break;
  54. case '1':
  55. $data['type']='Question';
  56. break;
  57. case '2':
  58. $data['type']='Suggestion';
  59. break;
  60. case '3':
  61. $data['type']='Other';
  62. break;
  63. default:
  64. $data['type']='Other';
  65. break;
  66. }
  67. Mail::send('emails.feedback-email-copy', $data, function($message){
  68. $message
  69. ->to(Input::get('email'), Auth::user()->first_name.' '.Auth::user()->surnames)
  70. ->cc('oeae.uprrp@upr.edu')
  71. ->subject('Feedback for OLAS');
  72. });
  73. Session::flash('status', 'success');
  74. Session::flash('message', '<p>Success! Check your email for a copy of your message. Thank you for your feedback. </p>');
  75. return Redirect::back();
  76. }
  77. }
  78. }