Без опису

FeedbackController.php 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.rrp@upr.edu')
  71. ->cc('peticiones.diia@upr.edu')
  72. ->subject('Feedback for OLAS');
  73. });
  74. //peticiones.diia@upr.edu
  75. Session::flash('status', 'success');
  76. Session::flash('message', '<p>Success! Check your email for a copy of your message. Thank you for your feedback. </p>');
  77. return Redirect::back();
  78. }
  79. }
  80. }