150 lines
5.2 KiB
PHP
Executable file
150 lines
5.2 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App\Http\Controllers\Settings;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Models\CMSContent;
|
|
use App\Models\EmailTemplate;
|
|
use App\Models\EmailTemplateDir;
|
|
use App\Services\Booking;
|
|
use App\Services\BookingFewo;
|
|
use App\Services\Lead;
|
|
use App\Services\Util;
|
|
use Request;
|
|
|
|
class EmailsController extends Controller
|
|
{
|
|
|
|
protected $identifier_booking_file;
|
|
protected $identifier_fewo_file;
|
|
protected $identifier_lead_file;
|
|
|
|
|
|
public function __construct()
|
|
{
|
|
$this->middleware(['superadmin', '2fa']);
|
|
|
|
$this->identifier_booking_file = 'booking-email-file';
|
|
$this->identifier_fewo_file = 'fewo-email-file';
|
|
$this->identifier_lead_file = 'lead-email-file';
|
|
}
|
|
|
|
|
|
public function index($step = false)
|
|
{
|
|
|
|
$data = [
|
|
'email_template' => EmailTemplate::all(),
|
|
'email_template_dirs' => EmailTemplateDir::all(),
|
|
'booking_email_files' => CMSContent::where('identifier', '=', $this->identifier_booking_file)->get()->sortByDesc('pos'),
|
|
'customer_mail_dirs' => Booking::getCustomerMailDirs(),
|
|
'identifier_booking_file' => $this->identifier_booking_file,
|
|
'identifier_fewo_file' => $this->identifier_fewo_file,
|
|
'identifier_lead_file' => $this->identifier_lead_file,
|
|
'fewo_email_files' => CMSContent::where('identifier', '=', $this->identifier_fewo_file)->get()->sortByDesc('pos'),
|
|
'customer_fewo_mail_dirs' => BookingFewo::getCustomerMailDirs(),
|
|
'lead_email_files' => CMSContent::where('identifier', '=', $this->identifier_lead_file)->get()->sortByDesc('pos'),
|
|
'step' => $step
|
|
|
|
];
|
|
return view('settings.emails.index', $data);
|
|
}
|
|
|
|
public function load(){
|
|
$data = Request::all();
|
|
$ret = "";
|
|
if(Request::ajax()) {
|
|
if($data['action'] === "modal-email-template") {
|
|
if($data['id'] === 'new'){
|
|
$value = new EmailTemplate();
|
|
$value->id = 0;
|
|
$value->active = 1;
|
|
}else{
|
|
$value = EmailTemplate::find($data['id']);
|
|
|
|
}
|
|
$directories = EmailTemplateDir::where('active', '=', true)->get();
|
|
$ret = view("settings.emails.modal", compact('value', 'directories'))->render();
|
|
}
|
|
}
|
|
return response()->json(['response' => $data, 'html'=>$ret]);
|
|
}
|
|
|
|
public function update(){
|
|
|
|
$data = Request::all();
|
|
$data['active'] = isset($data['active']) ? true : false;
|
|
$data['step'] = isset($data['step']) ? $data['step'] : false;
|
|
|
|
if($data['action'] === 'email_template'){
|
|
if($data['id'] === "new" || $data['id'] == 0){
|
|
$model = EmailTemplate::create($data);
|
|
}else{
|
|
$model = EmailTemplate::find($data['id']);
|
|
$model->fill($data);
|
|
$model->save();
|
|
}
|
|
}
|
|
if($data['action'] === 'email_template_dir') {
|
|
if($data['id'] === "new"){
|
|
EmailTemplateDir::create($data);
|
|
}else{
|
|
$model = EmailTemplateDir::find($data['id']);
|
|
$model->fill($data);
|
|
$model->save();
|
|
}
|
|
}
|
|
|
|
if($data['action'] === 'customer_mail_dirs') {
|
|
$data['object'] = [
|
|
'icon' => $data['icon'],
|
|
'model' => $data['model'],
|
|
'emails' => isset($data['emails']) ? Util::_explodeLines($data['emails']) : null,
|
|
];
|
|
|
|
$pos = $data['pos'];
|
|
if($pos > 9){
|
|
\Session()->flash('alert-error', 'max 9 Ordner für E-Mail Ablage');
|
|
return redirect(route('admin_settings_emails', [$data['step']]));
|
|
}
|
|
if($data['id'] === "new"){
|
|
//check ist pos
|
|
if(CMSContent::where('identifier', '=', $data['identifier'])->where('pos', '=', $pos)->count()){
|
|
\Session()->flash('alert-error', 'Die ID '.$pos.' existiert schon');
|
|
return redirect(route('admin_settings_emails', [$data['step']]));
|
|
}
|
|
CMSContent::create($data);
|
|
//store in cms old Datebase
|
|
\App\Models\Sym\CmsContent::create($data);
|
|
}else{
|
|
$model = CMSContent::find($data['id']);
|
|
if($model->pos != $pos && CMSContent::where('identifier', '=', $data['identifier'])->where('pos', '=', $pos)->count()){
|
|
\Session()->flash('alert-error', 'Die ID '.$pos.' existiert schon');
|
|
return redirect(route('admin_settings_emails', [$data['step']]));
|
|
}
|
|
$model->fill($data);
|
|
$model->save();
|
|
|
|
$m = \App\Models\Sym\CmsContent::find($data['id']);
|
|
$m->fill($data);
|
|
$m->save();
|
|
}
|
|
}
|
|
|
|
\Session()->flash('alert-save', '1');
|
|
return redirect(route('admin_settings_emails', [$data['step']]));
|
|
}
|
|
|
|
public function delete($id){
|
|
|
|
$model = EmailTemplate::findOrFail($id);
|
|
$model->delete();
|
|
\Session()->flash('alert-success', 'Eintrag gelöscht');
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|