Exemple #1
0
 public function post_associateRegistration()
 {
     $post = array();
     $post['inputCid'] = Input::get('inputCid');
     $post['inputVaName'] = Input::get('inputVaName');
     $post['inputUrl'] = Input::get('inputUrl');
     $post['inputDescription'] = Input::get('inputDescription');
     $post['inputVatsimImagePageLink'] = Input::get('inputVatsimImagePageLink');
     $post['inputCountry'] = Input::get('inputCountry');
     $post['inputName'] = Input::get('inputName');
     $post['inputEmail'] = Input::get('inputEmail');
     $post['inputPassword'] = Input::get('inputPassword');
     $post['inputPassword_confirmation'] = Input::get('inputPassword_confirmation');
     //      Format our URL field with the http before if it isn't there already
     if (!strpos($post['inputUrl'], 'http://') and !strpos($post['inputUrl'], 'https://')) {
         $post['inputUrl'] = 'http://' . $post['inputUrl'];
     }
     $validator = Validator::make(array('Cid' => $post['inputCid'], 'Va Name' => $post['inputVaName'], 'Url' => $post['inputUrl'], 'Description' => $post['inputDescription'], 'Vatsim Image Page Link' => $post['inputVatsimImagePageLink'], 'Country' => $post['inputCountry'], 'Name' => $post['inputName'], 'Email' => $post['inputEmail'], 'Password' => $post['inputPassword'], 'Password_confirmation' => $post['inputPassword_confirmation']), array('Cid' => 'required|integer|unique:vas,cid', 'Va Name' => 'required', 'Url' => 'required|url', 'Description' => 'required|max:200', 'Vatsim Image Page Link' => 'required|url', 'Country' => 'required', 'Name' => 'required', 'Email' => 'required|email|unique:vas,email', 'Password' => 'required|min:6|confirmed', 'Password_confirmation' => 'required|min:6'), array('Cid.unique' => 'There is already an account with an active virtual airline with that CID.'));
     if ($validator->fails()) {
         // The given data did not pass validation
         $messages = $validator->messages();
         $errorStr = '';
         foreach ($messages->all('<li>:message</li>') as $message) {
             $errorStr .= '<div class="alert alert-error">' . $message . '</div>';
         }
         echo $errorStr;
     } else {
         //Submit Data
         //Create an instance of our model
         $vas = new User();
         //Map our fields
         $vas->cid = $post['inputCid'];
         //This is an associate
         $vas->associate = 1;
         //Hash our password
         $vas->password = Hash::make($post['inputPassword']);
         $vas->vaname = $post['inputVaName'];
         $vas->url = $post['inputUrl'];
         $vas->description = $post['inputDescription'];
         $vas->vatsimimagepagelink = $post['inputVatsimImagePageLink'];
         $vas->country = $post['inputCountry'];
         $vas->name = $post['inputName'];
         $vas->email = $post['inputEmail'];
         //All VAs must be approved first so the default status will be 0 for unapproved or not active.
         $vas->status = '0';
         //Save our data
         //            $vas->save();
         //TODO ^^^^^^^
         die;
         //Great, now let's send our welcome email to the member
         $template = SystemEmailTemplate::find('registration_received');
         $subject = $template->subject;
         $email = $post['inputEmail'];
         $content = EmailTemplate::replaceContent($template->content, $post['inputCid']);
         //Send our email
         $data = array('name' => $post['inputName'], 'email' => $email, 'subject' => $subject);
         //Alright. Time to do some email sending.
         Mail::send('email.default', array("content" => $content), function ($message) use($data) {
             $message->to($data['email'], $data['name'])->subject($data['subject']);
         });
     }
 }
 public function post_email()
 {
     //Get our form values
     $recipients = Input::get('inputRecipients');
     $subject = Input::get('inputSubject');
     $body = Input::get('inputBody');
     //Here we go
     if ($recipients == 0) {
         $vas = User::where('status', '=', 0)->get();
     } elseif ($recipients == 1) {
         $vas = User::where('status', '=', 1)->get();
     } elseif ($recipients == 2) {
         $vas = User::where('status', '=', 0)->orWhere('status', '=', 1)->get();
     }
     if (empty($vas)) {
         //Damn them they somehow didn't select a VA what idiots
         return Redirect::route('consoleemail')->with('message', 'Please select a recipient group');
     }
     if (empty($subject)) {
         return Redirect::route('consoleemail')->with('message', 'Please enter a subject');
     }
     if (empty($body)) {
         return Redirect::route('consoleemail')->with('message', 'Please enter an email body');
     }
     $i = 0;
     foreach ($vas as $va) {
         $body = EmailTemplate::replaceContent($body, $va->cid);
         $subject = EmailTemplate::replaceContent($subject, $va->cid);
         //Replace the email body variables
         $data = array('va' => $va, 'subject' => $subject);
         //Alright. Time to do some email sending.
         Mail::send('email.default', array("content" => $body), function ($message) use($data) {
             $message->to($data['va']->email, $data['va']->name)->subject($data['subject']);
         });
         $i += 1;
     }
     return Redirect::route('consoleemail')->with('message', 'Email successfully sent to <strong>' . $i . '</strong> vas.');
 }