-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up mail and add back a couple missing features (#130)
- Loading branch information
1 parent
eeb579f
commit 65233b3
Showing
24 changed files
with
245 additions
and
454 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,31 +5,6 @@ | |
|
||
class EmailHelper | ||
{ | ||
/** | ||
* Send Email, checking for facility template first | ||
* | ||
* @param string|array $email | ||
* @param string $subject | ||
* @param string $template | ||
* @param array $data | ||
*/ | ||
public static function sendEmailFacilityTemplate($email, $subject, $fac, $template, $data) | ||
{ | ||
$global_templates = [ | ||
'examassigned' => "emails.exam.assign", | ||
'exampassed' => 'emails.exam.passed', | ||
'examfailed' => 'emails.exam.failed', | ||
'transferpending' => 'emails.transfers.pending' | ||
]; | ||
if (view()->exists("emails.facility.$fac." . $template)) { | ||
$template = "emails.facility.$fac.$template"; | ||
} else { | ||
$template = $global_templates[$template]; | ||
} | ||
|
||
static::sendEmail($email, $subject, $template, $data); | ||
} | ||
|
||
/** | ||
* Send an email from support | ||
* | ||
|
@@ -131,4 +106,37 @@ public static function sendEmailBCC($fromEmail, $fromName, $emails, $subject, $t | |
} | ||
} | ||
|
||
/** | ||
* @param string $email | ||
* @param string $from_email | ||
* @param string $from_name | ||
* @param string $subject | ||
* @param string $template | ||
* @param array $data | ||
*/ | ||
public static function sendEmailFrom($email, $from_email, $from_name, $subject, $template, $data) | ||
{ | ||
try { | ||
Mail::send($template, $data, function ($msg) use ($data, $from_email, $from_name, $email, $subject) { | ||
$msg->from("[email protected]", "$from_name"); | ||
$msg->replyTo($from_email, $from_name); | ||
$msg->to($email); | ||
$msg->subject("[VATUSA] $subject"); | ||
}); | ||
} catch (\Exception $exception) { | ||
// Don't do anything - temporary workaround due to mail host failures | ||
} | ||
} | ||
|
||
/** | ||
* Check if user has opted in to broadcast emails. | ||
* @param $cid | ||
* | ||
* @return int | ||
*/ | ||
public static function isOptedIn($cid) { | ||
$user = \App\Models\User::find($cid); | ||
|
||
return $user && $user->flag_broadcastOptedIn; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
<?php namespace App\Http\Controllers; | ||
|
||
use App\Helpers\AuthHelper; | ||
use App\Models\Role; | ||
use Illuminate\Http\Request; | ||
use App\Models\User; | ||
use App\Models\Facility; | ||
use App\Classes\RoleHelper; | ||
use App\Classes\EmailHelper; | ||
use Auth; | ||
use App\Classes\Helper; | ||
|
||
class EmailMgtController extends Controller { | ||
public function getIndividual($cid) { | ||
if (!AuthHelper::authACL()->canSendBroadcastEmail()) { | ||
abort(401); | ||
} | ||
return view('mgt.mail.broadcast', ['cid' => $cid]); | ||
} | ||
|
||
public function getBroadcast($cid = null) { | ||
if (!AuthHelper::authACL()->canSendBroadcastEmail()) { | ||
abort(401); | ||
} | ||
return view('mgt.mail.broadcast', ['cid' => $cid]); | ||
} | ||
|
||
public function postBroadcast(Request $request) { | ||
if (!AuthHelper::authACL()->canSendBroadcastEmail()) { | ||
abort(401); | ||
} | ||
$rcpts = $request->recipients; | ||
$subj = $request->subject; | ||
$msg = $request->email; | ||
$single = $request->single; | ||
|
||
if ((empty($rcpts) && empty($single)) || empty($subj) || empty($msg)) { | ||
return back()->with('broadcastError', 'All fields are required.'); | ||
} | ||
|
||
// Send to single person. | ||
if (empty($rcpts) && !empty($single)) { | ||
if (!EmailHelper::isOptedIn($single)) { | ||
return redirect("/mgt/mail/$single") | ||
->with('broadcastError', 'Could not send email. User is not opted in to broadcast emails.'); | ||
} | ||
$email = Helper::emailFromCID($single); | ||
EmailHelper::sendEmailFrom($email, Auth::user()->email, Auth::user()->fname . " " . Auth::user()->lname, $subj, 'emails.mass', array('msg' => nl2br(strip_tags($msg, '<b><i>')), 'init' => Auth::user()->fname . " " . Auth::user()->lname . " (" . Auth::user()->cid . ")")); | ||
return redirect("/mgt/mail/$single")->with('broadcastSuccess', 'Email sent.'); | ||
} else { | ||
// Handle Recipients | ||
// STAFF = All Staff | ||
// ALL = VATUSA Controllers | ||
// SRSTAFF = Facility Senior Staff | ||
// VATUSA = VATUSA Staff | ||
// INS = Instructional Staff (I1 + I3) | ||
// Z--/HCF[SJU/GUM] = Facility | ||
|
||
$emails = array(); | ||
|
||
if ($rcpts == "STAFF") { | ||
$rcpts = "Facility Staff"; | ||
foreach (Facility::get() as $f) { | ||
if ($f->atm && EmailHelper::isOptedIn($f->atm)) { | ||
$emails[] = $f->id . "[email protected]"; | ||
} | ||
if ($f->datm && EmailHelper::isOptedIn($f->datm)) { | ||
$emails[] = $f->id . "[email protected]"; | ||
} | ||
if ($f->ta && EmailHelper::isOptedIn($f->ta)) { | ||
$emails[] = $f->id . "[email protected]"; | ||
} | ||
if ($f->ec && EmailHelper::isOptedIn($f->ec)) { | ||
$emails[] = $f->id . "[email protected]"; | ||
} | ||
if ($f->fe && EmailHelper::isOptedIn($f->fe)) { | ||
$emails[] = $f->id . "[email protected]"; | ||
} | ||
if ($f->wm && EmailHelper::isOptedIn($f->wm)) { | ||
$emails[] = $f->id . "[email protected]"; | ||
} | ||
} | ||
} else if ($rcpts == "ALL") { | ||
$rcpts = "VATUSA"; | ||
foreach (User::where('facility', 'NOT LIKE', 'ZZN') | ||
->where('facility', 'NOT LIKE', 'ZAE') | ||
->where('flag_broadcastOptedIn', true)->get() as $u) { | ||
if ($u->email) { | ||
$emails[] = $u->email; | ||
} | ||
} | ||
} else if ($rcpts == "SRSTAFF") { | ||
$rcpts = "Facility Senior Staff"; | ||
foreach (Facility::get() as $f) { | ||
if ($f->atm && EmailHelper::isOptedIn($f->atm)) { | ||
$emails[] = $f->id . "[email protected]"; | ||
} | ||
if ($f->datm && EmailHelper::isOptedIn($f->datm)) { | ||
$emails[] = $f->id . "[email protected]"; | ||
} | ||
if ($f->ta && EmailHelper::isOptedIn($f->ta)) { | ||
$emails[] = $f->id . "[email protected]"; | ||
} | ||
} | ||
} else if ($rcpts == "DRCTR") { | ||
$rcpts = "Facility ATM/DATM"; | ||
foreach (Facility::get() as $f) { | ||
if (EmailHelper::isOptedIn($f->atm)) { | ||
$emails[] = $f->id . "[email protected]"; | ||
} | ||
if (EmailHelper::isOptedIn($f->datm)) { | ||
$emails[] = $f->id . "[email protected]"; | ||
} | ||
} | ||
} else if ($rcpts == "WM") { | ||
$rcpts = "Facility Webmasters"; | ||
foreach (Facility::get() as $f) { | ||
if (EmailHelper::isOptedIn($f->wm)) { | ||
$emails[] = $f->id . "[email protected]"; | ||
} | ||
} | ||
} else if ($rcpts == "VATUSA") { | ||
$rcpts = "VATUSA Staff"; | ||
foreach (Role::where('facility', 'ZHQ')->get() as $f) { | ||
if (EmailHelper::isOptedIn($f->cid)) { | ||
$emails[] = Helper::emailFromCID($f->cid); | ||
} | ||
} | ||
} else if ($rcpts == "INS") { | ||
$rcpts = "Instructional staff"; | ||
foreach (User::where('facility', 'NOT LIKE', 'ZZN') | ||
->where('facility', 'NOT LIKE', 'ZAE') | ||
->where('flag_broadcastOptedIn', true)->get() as $u) { | ||
if (RoleHelper::isInstructor($u->cid, $u->facility, false) && $u->email) { | ||
$emails[] = $u->email; | ||
} | ||
} | ||
} else if ($rcpts == "ACE") { | ||
$rcpts = "ACE Team Members"; | ||
foreach (Role::where('facility', 'ZHQ')->where('role', 'ACE')->get() as $f) { | ||
if (EmailHelper::isOptedIn($f->cid)) { | ||
$emails[] = Helper::emailFromCID($f->cid); | ||
} | ||
} | ||
} else { | ||
foreach (User::where('facility', $rcpts)->where('flag_broadcastOptedIn', true)->get() as $u) { | ||
$emails[] = $u->email; | ||
} | ||
} | ||
EmailHelper::sendEmailBCC(Auth::user()->email, Auth::user()->fname . " " . Auth::user()->lname, $emails, $subj, 'emails.mass', array('msg' => nl2br(strip_tags($msg, '<b><i>')), 'init' => Auth::user()->fname . " " . Auth::user()->lname . " (" . Auth::user()->cid . ")")); | ||
} | ||
$count = count($emails); | ||
if (!$count) { | ||
return redirect("/mgt/mail/broadcast")->with('broadcastError', 'No emails were sent.'); | ||
} | ||
return redirect("/mgt/mail/broadcast")->with('broadcastSuccess', 'Email sent to ' . count($emails) . ' member' . ($count == 1 ? '' : 's')); | ||
} | ||
|
||
public function getWelcome() { | ||
if (!AuthHelper::authACL()->canManageFacilityTechConfig()) { | ||
abort(401); | ||
} | ||
|
||
$fac = Facility::find(Auth::user()->facility); | ||
return view('mgt.mail.welcome', ['welcome' => $fac->welcome_text]); | ||
} | ||
|
||
public function postWelcome(Request $request) { | ||
if (!AuthHelper::authACL()->canManageFacilityTechConfig()) { | ||
abort(401); | ||
} | ||
|
||
$fac = Facility::find(Auth::user()->facility); | ||
$fac->welcome_text = $request->input("welcome"); | ||
$fac->save(); | ||
return redirect("/mgt/mail/welcome")->with("success", "Welcome email set."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
{ | ||
"/js/email.js": "/js/email.js?id=2aa9d558c844e79504573de371ecd41f", | ||
"/js/privacy.js": "/js/privacy.js?id=d6478b87fe44415810b79dcb9ea90531", | ||
"/css/vatusa.css": "/css/vatusa.css?id=f11d8db90cdca03664e60da5ee1439cc" | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.