123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\File;
- use App\Http\Services\EmailService;
- use App\Models\Account;
- use App\Models\AppSession;
- use App\Models\Invoice;
- use App\Models\FinancialTransaction;
- use App\Models\CompanyClient;
- use Illuminate\Support\Facades\Cookie;
- class EmailController extends Controller
- {
- protected $performer;
- protected $sessionKey;
- public $appUrl;
- protected $emailService;
- public $appInternalName;
- public $stringMappingConfig;
- protected $emailFromName;
- public function __construct(EmailService $emailService)
- {
- $this->sessionKey = Cookie::get('sessionKey');
- $this->performer = AppSession::where('session_key', $this->sessionKey)->first();
- $this->emailFromName = config('app.emailFromName');
- $this->appUrl = config('app.url');
- $this->emailService = $emailService;
- $this->appInternalName = config('app.internalName');
- $this->stringMappingConfig = config('constants.' . $this->appInternalName);
- }
- public function previewEmail($email = null)
- {
- $pro = @$this->performer->pro;
- if (!$pro) {
- abort(404);
- }
- $appInternalName = $this->appInternalName;
- $stringMappingConfig = $this->stringMappingConfig;
- if ($email) {
- $destinationPath = resource_path('views/emails/templates/' . $email . '.blade.php');
- if (File::exists($destinationPath)) {
- $content = File::get($destinationPath);
- $appUrl = $this->appUrl;
- $emailFromName = $this->emailFromName;
- $toEmailAddress = $this->pro ? $this->pro->email_address : 'john@doe.com';
- $toName = $this->pro ? $this->pro->displayName() : 'John Doe';
- $message = 'Client information has been updated';
- return view('emails/templates/' . $email, compact('appUrl', 'toEmailAddress', 'toName', 'message', 'stringMappingConfig', 'appInternalName', 'emailFromName'));
- } else {
- abort(404);
- }
- }
- $files = File::allFiles(resource_path('views/emails/templates/'));
- $fileNames = [];
- foreach ($files as $file) {
- $fileName = $file->getFilename();
- $fileNameParts = explode('.', $fileName);
- $fileRef = @$fileNameParts[0];
- if ($fileRef) array_push($fileNames, $fileRef);
- }
- return view('emails.preview-email', compact('fileNames'));
- }
- }
|