␉ */␊ |
␉public function index()␊ |
␉{␊ |
␉␉␊ |
␉␉$sent_emails = SentEmail::all();␊ |
␉␉$received = ReceivedEmail::all();␊ |
␊ |
␉␉$user = Auth::user()->level;␊ |
␊ |
␉␉if(!$user == 'admin')␊ |
␉␉{␊ |
␉␉␉return View::make('users.profile')␊ |
␉␉␉␉␉␉␉->with('sent', $sent_emails)␊ |
␉␉␉␉␉ ->with('received', $received);␊ |
␉␉}else␊ |
␉␉{␊ |
␉␉␉return View::make('admin.index')␊ |
␉␉␉ ->with('sent', $sent_emails)␊ |
␉␉␉ ->with('received', $received);␊ |
␉␉}␊ |
␉␉␉␉␉␉␉␉␉␉␉␉␊ |
␉}␊ |
␊ |
␊ |
|
␉ */␊ |
␉public function create()␊ |
␉{␊ |
␉␉return View::make('emails.create');␊ |
␉␉$user = Auth::user();␊ |
␊ |
␉␉return View::make('emails.create')->with('user', $user);␊ |
␉}␊ |
␊ |
␊ |
|
␉{␊ |
␉␉$user_id = Auth::id();␊ |
␉␉$from_address = Auth::user()->email;␊ |
␉␉$to_address = Input::get('to_address');␊ |
␉␉$title = Input::get('title');␊ |
␉␉$message = Input::get('message');␊ |
␊ |
␉␉$valid = Validator::make(array($to_address, $title, $message), SentEmail::$rules);␊ |
␉␉$rules = array(␊ |
␉␉␉'to' => 'required|email',␊ |
␉␉␉'subject' => 'required',␊ |
␉␉␉'message' => 'required'␊ |
␉␉);␊ |
␊ |
␉␉$valid = Validator::make(array(Input::only('to', 'subject', 'message')), $rules);␊ |
␊ |
␉␉if($valid->fails())␊ |
␉␉{␊ |
␉␉␉return Redirect::route('emails/create')␊ |
␉␉␉return Redirect::route('emails.create')␊ |
␉␉␉␉␉␉␉->withInput(Input::all())␊ |
␉␉␉␉␉␉␉->withErrors($valid);␊ |
␉␉}else␊ |
␉␉{␊ |
␉␉␉$recepient = User::where('email', '=', $to_address)->get();␊ |
␉␉␉$recepient = User::where('email', '=', Input::get('to'))->first();␊ |
␊ |
␉␉␉$response = Mail::queue('emails.email', array('name'=> $recepient->first), function($message) use ($recepient)␊ |
␉␉␉␉␉␉{␊ |
␉␉␉␉␉␉␉$message->to($to_address, $recepient->first . ' '. $recepient->last)->subject($title);␊ |
␉␉␉␉␉␉});␊ |
␊ |
␉␉␉if(!$response)␊ |
␉␉␉Mail::queue('users.welcome', array('name'=> $recepient->first), function($message) use ($recepient)␊ |
␉␉␉{␊ |
␉␉␉␉Session::flash('message', 'We were unable to send your email. Please try again later');␊ |
␊ |
␉␉␉␉return Redirect::route('emails.create')->withInput(Input::all());␊ |
␉␉␉}␊ |
␉␉␉␉$message->to($recepient->email, $recepient->first . ' '. $recepient->last)->subject(\Input::get('subject'));␊ |
␉␉␉});␊ |
␊ |
␉␉␉$sentEmail = new SentEmail;␊ |
␊ |
␉␉␉$sentEmail->user_id = $user_id;␊ |
␉␉␉$sentEmail->from_address = $from_address;␊ |
␉␉␉$sentEmail->to_address = $to_address;␊ |
␉␉␉$sentEmail->title = $title;␊ |
␉␉␉$sentEmail->message = $message;␊ |
␉␉␉$sentEmail = SentEmail::create(array(␊ |
␉␉␉␉'user_id' => $user_id,␊ |
␉␉␉␉'from_address' => $from_address,␊ |
␉␉␉␉'to_address' => Input::get('to'),␊ |
␉␉␉␉'subject' => Input::get('subject'),␊ |
␉␉␉␉'message' => Input::get('message')␊ |
␉␉␉));␊ |
␊ |
␉␉␉if($sentEmail->save())␊ |
␉␉␉{␊ |
␉␉␉␉return Redirect::route('user');␊ |
␉␉␉}else␊ |
␉␉␉{␊ |
␉␉␉␉Session::flash('message', 'Something bad happened.')␊ |
␉␉␉␉return Redirect::route('emails/create')␊ |
␉␉␉␉Session::flash('message', 'Something bad happened.');␊ |
␊ |
␉␉␉␉return Redirect::route('emails.create')␊ |
␉␉␉␉␉␉␉␉->withInput(Input::all());␊ |
␉␉␉} ␊ |
␉␉}␊ |
|
␉␉$email->delete();␊ |
␉}␊ |
␊ |
␉public function sendEmail($address, $recepient, $subject)␊ |
␉{␊ |
␉␉return;␊ |
␉}␊ |
␊ |
␊ |
}␊ |