342 lines
17 KiB
PHP
Executable file
342 lines
17 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Carbon;
|
|
use Request;
|
|
use Response;
|
|
use App\Services\Util;
|
|
use App\Models\EmailTemplate;
|
|
use App\Services\Placeholder;
|
|
use App\Models\CustomerFewoFile;
|
|
use App\Models\CustomerFewoMail;
|
|
use Illuminate\Support\Facades\URL;
|
|
use App\Models\TravelUserBookingFewo;
|
|
use App\Models\TravelUserBookingFile;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use App\Repositories\BookingFewoFileRepository;
|
|
use App\Repositories\CustomerFewoFileRepository;
|
|
use App\Repositories\CustomerFewoMailRepository;
|
|
|
|
class CustomerFewoMailController extends Controller
|
|
{
|
|
|
|
protected $customerMailRepo;
|
|
|
|
public function __construct(CustomerFewoMailRepository $customerMailRepo)
|
|
{
|
|
$this->middleware(['admin', '2fa']);
|
|
$this->customerMailRepo = $customerMailRepo;
|
|
}
|
|
|
|
/* public function index()
|
|
{
|
|
$data = [
|
|
|
|
];
|
|
return view('customer.mail.index', $data);
|
|
}
|
|
|
|
public function detail($id)
|
|
{
|
|
if($id === "new") {
|
|
$customer_mail = new CustomerFewoMail();
|
|
$id = 'new';
|
|
|
|
}else{
|
|
$customer_mail = CustomerFewoMail::findOrFail($id);
|
|
$id = $customer_mail->id;
|
|
}
|
|
|
|
|
|
$data = [
|
|
'customer_mail' => $customer_mail,
|
|
'id' => $id,
|
|
'back' => URL::previous(),
|
|
];
|
|
return view('customer.mail.detail', $data);
|
|
|
|
}*/
|
|
|
|
public function store($id, $action=false)
|
|
{
|
|
$data = Request::all();
|
|
$customer_mail = CustomerFewoMail::findOrFail($id);
|
|
|
|
if($action === 'move-mail'){
|
|
$data['subdir'] = isset($data['subdir']) && $data['subdir'] ? $data['subdir'] : null;
|
|
$customer_mail->dir = $data['dir'];
|
|
$customer_mail->subdir = $data['subdir'];
|
|
$customer_mail->save();
|
|
|
|
}
|
|
return back()->with('collapse_shows', $data['collapse_shows'] ? $data['collapse_shows'] : []);
|
|
}
|
|
|
|
public function delete($id){
|
|
$customer_mail = CustomerFewoMail::find($id);
|
|
$customer_mail->dir = 12;
|
|
$customer_mail->subdir = 0;
|
|
$customer_mail->save();
|
|
|
|
\Session()->flash('alert-success', __('Mail gelöscht'));
|
|
return back();
|
|
}
|
|
|
|
|
|
public function loadModal(){
|
|
$data = Request::all();
|
|
$ret = "";
|
|
|
|
if(Request::ajax()) {
|
|
if ($data['action'] === "new-customer-mail" || $data['action'] === "reply-customer-mail" || $data['action'] === "show-customer-mail" || $data['action'] === "edit-customer-mail"){
|
|
$data['customers'] = [];
|
|
if ($data['action'] === "new-customer-mail" && isset($data['travel_user_booking_fewo_id']) && $TravelUserBookingFewo = TravelUserBookingFewo::find($data['travel_user_booking_fewo_id'])) {
|
|
$tmp = [];
|
|
$tmp['email'] = $TravelUserBookingFewo->travel_user ? $TravelUserBookingFewo->travel_user->email : "";
|
|
$tmp['name'] = $TravelUserBookingFewo->travel_user ? $TravelUserBookingFewo->travel_user->first_name . " " . $TravelUserBookingFewo->travel_user->last_name . " | " : "- | ";
|
|
$tmp['name'] .= $TravelUserBookingFewo->fewo_lodging_id ? $TravelUserBookingFewo->fewo_lodging->name . " | " : "- | ";
|
|
$data['customers'][$TravelUserBookingFewo->id] = $tmp;
|
|
}
|
|
$ret = CustomerFewoMailRepository::loadModal($data);
|
|
}
|
|
|
|
if($data['action'] === "modal-upload-booking-file") {
|
|
$ret = view("travel.user.booking.upload_modal", compact('data'))->render();
|
|
}
|
|
|
|
if($data['action'] === "upload-booking-file"){
|
|
if($data['travel_user_booking_fewo_id']){
|
|
$bookingFileRepo = new BookingFewoFileRepository(new TravelUserBookingFile());
|
|
$bookingFileRepo->_set('disk', 'booking_fewo');
|
|
$bookingFileRepo->_set('travel_user_booking_fewo_id', $data['travel_user_booking_fewo_id']);
|
|
$bookingFileRepo->_set('dir', '/files/'.date('Y/m').'/');
|
|
$bookingFileRepo->_set('identifier', 'booking');
|
|
return $bookingFileRepo->uploadFile(Request::all());
|
|
}
|
|
}
|
|
}
|
|
return response()->json(['response' => $data, 'html'=>$ret]);
|
|
}
|
|
|
|
|
|
public function sendMail(CustomerFewoMailRepository $customerFewoMailRepository){
|
|
$data = Request::all();
|
|
$customerFewoMailRepository->sendAndStore($data);
|
|
if($data['action'] == 'draft'){
|
|
\Session()->flash('alert-success', "Entwurf gespeichert!");
|
|
}else{
|
|
\Session()->flash('alert-success', "Mail gesendet!");
|
|
}
|
|
return back()->with('collapse_shows', $data['collapse_shows'] ? $data['collapse_shows'] : []);
|
|
}
|
|
|
|
public function replyMail(CustomerFewoMailRepository $customerFewoMailRepository){
|
|
$data = Request::all();
|
|
$customerFewoMailRepository->replyStore($data);
|
|
\Session()->flash('alert-success', "Mail gespeichert!");
|
|
return back()->with('collapse_shows', $data['collapse_shows'] ? $data['collapse_shows'] : []);
|
|
}
|
|
|
|
public function getEmailTemplates()
|
|
{
|
|
$query = EmailTemplate::with('email_template_dir')->select('email_templates.*')->where('active', '=', true);
|
|
|
|
if(Request::get('filter_email_templates_directory') != ""){
|
|
$query->where('email_template_dir_id', '=', Request::get('filter_email_templates_directory'));
|
|
}
|
|
|
|
return \DataTables::eloquent($query)
|
|
->addColumn('action', function (EmailTemplate $emailTemplate) {
|
|
return '<a href="javascript:void(0)" class="btn icon-btn btn-sm btn-primary email-template-action"
|
|
data-url="'.route('customer_mail_ajax').'" data-id="'.$emailTemplate->id.'" data-action="load_email_template"
|
|
title="Vorlage laden" data-placement="left" rel="tooltip"><span class="ion ion-ios-arrow-dropup"></span></a>';
|
|
})
|
|
->addColumn('email_template_dir.name', function (EmailTemplate $emailTemplate) {
|
|
return $emailTemplate->email_template_dir ? '<span class="badge badge-default" style="background-color: '.$emailTemplate->email_template_dir->color.'">'.$emailTemplate->email_template_dir->name.'</span>' : ' ';
|
|
})
|
|
->orderColumn('id', 'id $1')
|
|
->orderColumn('subject', 'subject $1')
|
|
->orderColumn('name', 'name $1')
|
|
->orderColumn('email_template_dir.name', 'email_template_dir.name $1')
|
|
->orderColumn('message', 'message $1')
|
|
->filterColumn('id', function($query, $keyword) {
|
|
if($keyword != ""){
|
|
$query->where('id', 'LIKE', '%'.$keyword.'%');
|
|
}
|
|
})
|
|
->filterColumn('subject', function($query, $keyword) {
|
|
if($keyword != ""){
|
|
$query->where('name', 'LIKE', '%'.$keyword.'%');
|
|
$query->OrWhere('subject', 'LIKE', '%'.$keyword.'%');
|
|
$query->OrWhere('message', 'LIKE', '%'.$keyword.'%');
|
|
}
|
|
})
|
|
->rawColumns(['action', 'email_template_dir.name'])
|
|
->make(true);
|
|
}
|
|
|
|
|
|
public function uploadAttachment($id){
|
|
|
|
$fileRepo = new CustomerFewoFileRepository(new CustomerFewoFile());
|
|
if($id === 'tmp'){
|
|
$fileRepo->_set('disk', 'travel_user');
|
|
$fileRepo->_set('dir', '/attachment/'.date('Y/m').'/');
|
|
$fileRepo->_set('travel_user_id', NULL);
|
|
$fileRepo->_set('customer_fewo_mail_id', NULL);
|
|
$fileRepo->_set('identifier', 'tmp');
|
|
return $fileRepo->uploadFile(Request::all());
|
|
}
|
|
|
|
return Response::json([
|
|
'error' => true,
|
|
'code' => 200
|
|
], 200);
|
|
}
|
|
|
|
public function ajax(){
|
|
$data = Request::all();
|
|
$ret = "";
|
|
$status = false;
|
|
if(Request::ajax() && isset($data['action'])){
|
|
if($data['action'] === 'load_preview_mail'){
|
|
$booking_fewo = TravelUserBookingFewo::findOrFail($data['booking_fewo_id']);
|
|
$ret = Placeholder::replaceBookingFewo($booking_fewo, $data['content']);
|
|
$data['subject'] = Placeholder::replaceBookingFewo($booking_fewo, $data['subject']);
|
|
$status = 'success';
|
|
}
|
|
if($data['action'] === 'toggle_important'){
|
|
$customer_mail = CustomerFewoMail::find($data['id']);
|
|
$customer_mail->important = ($customer_mail->important ? false : true);
|
|
$customer_mail->save();
|
|
$status = 'success';
|
|
}
|
|
if($data['action'] === 'load_email_template'){
|
|
$email_template = EmailTemplate::find($data['id']);
|
|
$ret = $email_template->message;
|
|
$data['subject'] = $email_template->subject;
|
|
$status = 'success';
|
|
}
|
|
if($data['action'] === 'delete_mail_attachment'){
|
|
$customer_file = CustomerFewoFile::find($data['id']);
|
|
$fileRepo = new CustomerFewoFileRepository($customer_file);
|
|
$fileRepo->_set('disk', 'travel_user');
|
|
$ret = $fileRepo->delete();
|
|
$status = 'success';
|
|
}
|
|
|
|
if($data['action'] === 'add_attachment'){
|
|
$arrContextOptions=array(
|
|
"ssl"=>array(
|
|
"verify_peer"=>false,
|
|
"verify_peer_name"=>false,
|
|
),
|
|
);
|
|
$contents = file_get_contents($data['target'], false, stream_context_create($arrContextOptions));
|
|
$mine = Util::getMimeFromHeader($http_response_header);
|
|
$extension = Util::getExtensionFromMime($mine);
|
|
$fileRepo = new CustomerFewoFileRepository(new CustomerFewoFile());
|
|
$fileRepo->_set('disk', 'travel_user');
|
|
$fileRepo->_set('dir', '/attachment/'.date('Y/m').'/');
|
|
$fileRepo->_set('travel_user_id', NULL);
|
|
$fileRepo->_set('customer_fewo_mail_id', NULL);
|
|
$fileRepo->_set('identifier', 'tmp');
|
|
$fileRepo->_set('originalName', $data['name']);
|
|
$fileRepo->_set('mine', $mine);
|
|
$fileRepo->_set('extension', $extension);
|
|
return $fileRepo->storeFile($contents);
|
|
}
|
|
}
|
|
return response()->json(['response' => $data, 'html'=>$ret, 'status'=>$status]);
|
|
}
|
|
|
|
private function getSearchRequests()
|
|
{
|
|
if (!Request::get('travel_user_booking_fewo_id')) {
|
|
return false;
|
|
}
|
|
$query = CustomerFewoMail::where('travel_user_booking_fewo_id', '=', Request::get('travel_user_booking_fewo_id'));
|
|
if (Request::get('customer_mail_dir') == 11) { //draft
|
|
$query->where('draft', '=', true)->where('dir', '!=', 12);
|
|
}else{
|
|
$query->where('dir', '=', Request::get('customer_mail_dir')); //with('lead'
|
|
}
|
|
if (Request::get('customer_mail_subdir')) {
|
|
$query->where('subdir', '=', Request::get('customer_mail_subdir'));
|
|
}
|
|
return $query;
|
|
}
|
|
|
|
public function getRequests(){
|
|
|
|
$query = $this->getSearchRequests();
|
|
return \DataTables::eloquent($query)
|
|
->addColumn('checkbox', function (CustomerFewoMail $customer_mail) {
|
|
return '<div class="message-checkbox mr-1">
|
|
<label class="custom-control custom-checkbox">
|
|
<input type="checkbox" class="custom-control-input">
|
|
<span class="custom-control-label"></span>
|
|
</label>
|
|
</div>';
|
|
})
|
|
->addColumn('important', function (CustomerFewoMail $customer_mail) {
|
|
$icon = ($customer_mail->important ? 'ion-md-star' : 'ion-md-star-outline');
|
|
return '<a href="javascript:void(0)" class="ion '.$icon.' d-block text-secondary text-big mr-3 customer-mail-ajax-action"
|
|
data-url="'.route('customer_fewo_mail_ajax').'" data-id="'.$customer_mail->id.'" data-important="'.$customer_mail->important.'" data-action="toggle_important"></a>';
|
|
})
|
|
->addColumn('subject', function (CustomerFewoMail $customer_mail) {
|
|
|
|
$icon = $customer_mail->reply_id ? 'ion-ios-redo' : 'ion-ios-mail';
|
|
$badge = $customer_mail->is_answer ? 'badge-next' : 'badge-secondary';
|
|
$badge = $customer_mail->draft ? 'badge-default' : $badge;
|
|
$to_icon = $customer_mail->draft ? '<i class="ion ion-ios-warning" style="opacity: 0.7"></i>' : '';
|
|
$action = $customer_mail->draft ? 'edit-customer-mail' : 'show-customer-mail';
|
|
$id = $customer_mail->draft ? $customer_mail->id : 'new';
|
|
$url = $customer_mail->draft ? route('customer_fewo_mail_send_mail') : '';
|
|
|
|
return '<a href="javascript:void(0)" class="badge '.$badge.'" data-toggle="modal"
|
|
data-target="#modals-load-content" data-id="'.$id.'" data-model="CustomerFewoMail"
|
|
data-action="'.$action.'" data-url="'.$url.'" data-redirect="back"
|
|
data-customer_mail_id="'.$customer_mail->id.'" data-route="'.route('customer_fewo_modal_load').'">
|
|
'.$to_icon.'<i class="ion '.$icon.' ui-w-30 text-center" style="opacity: 0.7"></i>'.$customer_mail->subject.'
|
|
'.($customer_mail->customer_fewo_files->count() ? ' <i class="ion ion-md-attach"> <span class="badge badge-primary indicator">'.$customer_mail->customer_fewo_files->count().'</span></i>' : '');
|
|
|
|
})
|
|
->addColumn('date', function (CustomerFewoMail $customer_mail) {
|
|
if($customer_mail->send){
|
|
return '<span class="badge badge-success" style="background-color: #94ae59"><i class="fa fa-check-circle"></i> '.$customer_mail->sent_at.'</span>';
|
|
}
|
|
return '<span class="badge badge-default"><i class="fa fa-times-circle"></i> '.$customer_mail->sent_at.'</span>';
|
|
})
|
|
->addColumn('action', function (CustomerFewoMail $customer_mail) {
|
|
$ret = '';
|
|
if(!$customer_mail->draft){
|
|
$ret = '<a href="javascript:void(0)" class="btn btn-xs btn-secondary" data-toggle="modal"
|
|
data-target="#modals-load-content" data-id="reply-send" data-model="customerMail" data-action="new-customer-mail"
|
|
data-url="'.route('customer_fewo_mail_send_mail').'" data-redirect="back" data-customer_mail_id="'.$customer_mail->id.'"
|
|
data-travel_user_booking_fewo_id="'.$customer_mail->travel_user_booking_fewo_id.'" data-route="'.route('customer_fewo_modal_load').'" data-customer_mail_dir="'.$customer_mail->dir.'" data-customer_subdir="'.$customer_mail->subdir.'">
|
|
<span title="Antwort auf E-Mail senden" data-placement="left" rel="tooltip"><i class="ion ion-ios-redo"></i> <i class="ion ion-md-mail-open"></i></span>
|
|
</a>
|
|
|
|
<a href="javascript:void(0)" class="btn btn-xs btn-default" data-toggle="modal"
|
|
data-target="#modals-load-content" data-id="reply-save" data-model="customerMail" data-action="reply-customer-mail"
|
|
data-url="'.route('customer_fewo_mail_reply_mail').'" data-redirect="back" data-customer_mail_id="'.$customer_mail->id.'"
|
|
data-travel_user_booking_fewo_id="'.$customer_mail->travel_user_booking_fewo_id.'" data-route="'.route('customer_fewo_modal_load').'" data-customer_mail_dir="'.$customer_mail->dir.'" data-customer_mail_subdir="'.$customer_mail->subdir.'">
|
|
<span title="Antwort auf E-Mail speichern" data-placement="left" rel="tooltip"><i class="ion ion-ios-redo"></i> <i class="ion ion-md-mail-unread"></i></span>
|
|
</a>
|
|
';
|
|
}
|
|
$ret .= '<a href="'.route('customer_fewo_mail_delete', [$customer_mail->id]).'" class="btn btn-xs btn-default text-danger" onclick="return confirm(\'In den Papierkorb verschieben?\');"><i class="ion ion-md-trash"></i></a>';
|
|
return '<div style="white-space: nowrap;">'.$ret.'</div>';
|
|
})
|
|
|
|
->orderColumn('date', 'sent_at $1')
|
|
->orderColumn('subject', 'subject $1')
|
|
->orderColumn('important', 'important $1')
|
|
->rawColumns(['checkbox', 'important', 'subject', 'date', 'action'])
|
|
->make(true);
|
|
}
|
|
}
|
|
|
|
|