$(document).ready(function()
{
$('#imUploader,#veranstaltungform,#blogartikelform').on('change','.imageUploadData', function(e)
{
e.preventDefault();
//console.log(this.files[0].name)
var uploadInput = $(this);
var item = $(this).data('item');
var filetype = $(this).data('filetype');
// SHOW LOADER
$('.imageLoaderMessage'+$(this).data('item')).hide();
$('.imageLoader'+$(this).data('item')).show();
var formData = new FormData();
formData.append('com', 'uploadImage');
formData.append('mode', $(this).data('mode'));
formData.append('id', $(this).data('id'));
formData.append('file', this.files[0]);
formData.append('filetype', $(this).data('filetype'));
$.ajax({url: 'https://www.lueneburgaktuell.de/xadmin/scripts/lga-io.php',
type: 'POST',
cache: false,
data: formData,
contentType: false,
processData: false,
error: function(em)
{
console.log('error');
console.log(em);
//return true;
},
success: function(result)
{
//console.log('success');
//console.log(result);
var resultData = result.split('|');
if(resultData.length > 0)
{
var className = resultData[2] == 'error' ? 'imageUploadError':'imageUploadOk';
$('.imageLoaderMessage'+item).html("
"+resultData[0]+"
");
$('.imageLoaderMessage'+item).show();
}
// for all + video for fwblog
if(resultData[1].length > 0)
{
$('.imageInput'+item).val(resultData[1]);
//$('.imageSource'+item).attr('src','../../'+resultData[1]);
$('.imageSource'+item).attr('src','https://www.lueneburgaktuell.de/'+resultData[1]);
console.log(filetype);
if(filetype=='image')
{
//$('.imageContainer'+item).css({'background':'url(\'../../'+resultData[1]+'\')', 'background-position': 'center', 'background-size': 'cover', 'background-repeat':'no-repeat' });
$('.imageContainer'+item).css({'background':'url(\'https://www.lueneburgaktuell.de/'+resultData[1]+'\')', 'background-position': 'center', 'background-size': 'cover', 'background-repeat':'no-repeat' });
}
else
{
$('.video'+item).attr('src','https://www.lueneburgaktuell.de/'+resultData[1]);
var fileext = resultData[1].split('.').pop();
fileext.toLowerCase() == 'mp4' ? $('.video'+item).attr('type','video/mp4') : $('.video'+item).attr('type','video/webm');
$('.imageContainer'+item).css({'position':'relative'});
var video = $('.videoPlayer'+item);
video[0].load();
}
$('.imageContainer'+item).show();
$('.noImageContainer'+item).hide();
}
else
{
$('.imageInput'+item).val('');
$('.imageContainer'+item).hide();
$('.noImageContainer'+item).show();
}
}}).done(function(data) {
$('.imageLoader'+item).hide();
$(uploadInput).val(''); // CLEAR UPLOAD
});
});
$('#imUploader,#veranstaltungform,#blogartikelform').on('click','.imageRemove', function(e)
{
$('.imageContainer'+$(this).data('item')).hide();
$('.noImageContainer'+$(this).data('item')).show();
$('.imageInput'+$(this).data('item')).val('');
$('.imageLoaderMessage'+$(this).data('item')).hide();
});
/** EVENTS SUPPORT */
$('#payform').on('click', '.payZyklusBlock', function()
{
$('.payZyklusBlock').each(function() { $(this).removeClass('supportSelectedBlock'); });
$('.payZyklus').each(function() { $(this).attr('checked',false); });
$(this).addClass('supportSelectedBlock');
$(this).find('input').attr('checked',true);
let zyklus= $('.payZyklusBlock').find('input[name=wdata0]:checked').val();
if(zyklus==0)
{
$('#paypal-button-subscription').hide();
$('#paypal-button-pay').show();
}
else
{
$('#paypal-button-pay').hide();
$('#paypal-button-subscription').show();
}
updatePriceCalc();
});
$('#payform').on('click', '.supportPriceBlock, .supportPriceBlockOwn', function()
{
$('.supportPriceBlock').each(function() { $(this).removeClass('supportSelectedBlock'); });
$('.supportPriceBlockOwn').removeClass('supportSelectedValidateBlock');
if($(this).data('pricemode')=='fixed')
{
$(this).addClass('supportSelectedBlock');
$('.selectedPriceID').val($(this).data('priceid'));
$('.validatePrice').removeClass('supportValidatedBlockError');
$('.validatePrice').removeClass('supportValidatedBlockOK');
$('.userPrice').val('');
}
else
{
$(this).addClass('supportSelectedValidateBlock');
$('.selectedPriceID').val($(this).data('priceid'));
}
updatePriceCalc();
});
$('#payform').on('input','.userPrice, .userEmail, .userName', function()
{
if($(this).hasClass('userPrice'))
{
$('.validatePrice').removeClass('supportValidatedBlockOK');
$('.validatePrice').removeClass('supportValidatedBlockError');
if(parseInt($(this).val()) >= 5 && parseInt($(this).val()) <= 99999) {
$('.validatePrice').addClass('supportValidatedBlockOK');
}
else
{ $('.validatePrice').addClass('supportValidatedBlockError'); }
}
if($(this).hasClass('userEmail'))
{
$('.validateEmail').removeClass('supportValidatedBlockOK');
$('.validateEmail').removeClass('supportValidatedBlockError');
if(isEmail($('.userEmail').val())) { $('.validateEmail').addClass('supportValidatedBlockOK'); }
else { $('.validateEmail').addClass('supportValidatedBlockError'); }
}
if($(this).hasClass('userName'))
{
$('.validateName').removeClass('supportValidatedBlockOK');
$('.validateName').removeClass('supportValidatedBlockError');
if($('.userName').val().length >= 3) { $('.validateName').addClass('supportValidatedBlockOK'); }
else { $('.validateName').addClass('supportValidatedBlockError'); }
}
});
$('#payform').on('click','.supportPriceBlockOwn, .userEmailBlock, .userNameBlock',function()
{
/** SET FOCUS ON NEXT INPUT **/
$(this).find('input').focus();
})
}); /** END DOC READY */
/** FUNCTIONS SUPPORT */
function isEmail(email) {
var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,10})+$/;
return regex.test(email);
}
function updatePriceCalc()
{
let zyklus= $('.payZyklusBlock').find('input[name=wdata0]:checked').val();
if(zyklus==0) { zyklus=1; } // correct einmalig
let prices=[zyklus * 5, zyklus * 10, zyklus * 15]
$('.fixPrice1').html(prices[0] +' €');
$('.fixPrice2').html(prices[1] +' €');
$('.fixPrice3').html(prices[2] +' €');
let priceID = $('.selectedPriceID').val();
priceID--;
let amount = 0;
if($('.selectedPriceID').val() == 4)
{
amount = parseInt($('#wdata2').val()) >=5 && parseInt($('#wdata2').val()) <=99999 ? parseInt($('#wdata2').val()) : 0
}
else
{
amount = prices[priceID];
}
//console.log('Amount: ' + amount + ', Zyklus: ' + zyklus);
$('.selectedPrice').val(amount);
/** CHECK FOR ERRORS TO REDUCE REQUESTS TO PP */
let error = true;
isEmail($('.userEmail').val()) ? $('.emailErrorMessage').html('') : $('.emailErrorMessage').html('
- Die angegebene E-Mailadresse ist ungültig.');
amount >= 5 && amount <= 9999 ? $('.betragErrorMessage').html('') : $('.betragErrorMessage').html('
- Bitte wählen Sie oder geben Sie einen Betrag ein.');
if(amount >= 5 && amount <= 9999 && isEmail($('.userEmail').val()) && $('.userName').val().length > 0)
{
error = false;
}
return error;
}
function getPPButton(title)
{
paypal_sdk_pay.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
"amount": {
"value": $('.selectedPrice').val(),
"currency_code": "EUR",
"breakdown": {
"item_total": {
"currency_code": "EUR",
"value": $('.selectedPrice').val()
}
}
},
"items": [
{
"name": title,
//"description": "optionale beschreibung",
"unit_amount": {
"currency_code": "EUR",
"value": $('.selectedPrice').val(),
},
"quantity": "1"
}],
}],
payment_source: {
paypal: {
experience_context: {
shipping_preference: "NO_SHIPPING",
},
},
},
});
},
onClick: function()
{
return checkErrors();
},
onApprove: function(data, actions)
{
// This function captures the funds from the transaction.
return actions.order.capture().then(function(details)
{
$('.formContainer').hide();
$('#errorcontainer').hide();
$('#successcontainer').show();
var target = $('#successcontainer');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top - 40
}, 1000);
}
// write order email ajax
$.ajax({ url: 'https://www.lueneburgaktuell.de/xadmin/scripts/lga-io.php', type : 'get', async: false, cache: false, data: { com: 'sendEmailSubscription', name: $('#wdata4').val(), email: $('#wdata3').val() }}).done(function(content) {});
});
// fetch('https://www.lueneburgaktuell.de/xadmin/scripts/lga-io.php?com=sendEmailSubscription&name='+ $('#wdata4').val() + '&email=' +$('#wdata3').val() , {
// method: 'get'
// }).then(function(res) {
// $('.formContainer').hide();
// $('#errorcontainer').hide();
// $('#successcontainer').show();
// var target = $('#successcontainer');
// if (target.length) {
// $('html,body').animate({
// scrollTop: target.offset().top - 40
// }, 1000);
// }
// });
},
onCancel: function (data)
{
//$('#errorcontainer').show();
//$('#errorcontainer').html('Zahlung abgebrochen
Sie haben den Zahlvorgang abgebrochen. Bitte versuchen Sie es erneut!');
},
onError: function (err) {
// Show an error page here, when an error occurs
alert(err);
},
}).render('#paypal-button-pay');
}
function getPPSubscriptionButton()
{
paypal_sdk_subscription.Buttons({
style: {
label:'pay' //Optional text in button
},
createSubscription: async function(data, actions)
{
var form = document.getElementById("payform");
return actions.subscription.create({
plan_id: await getPlanID(form),
application_context: {
shipping_preference: "NO_SHIPPING"
}
});
},
onClick: function()
{
return checkErrors()
},
onApprove: function(data, actions)
{
fetch('https://www.lueneburgaktuell.de/xadmin/scripts/lga-io.php?com=sendEmailSubscription&name='+ $('#wdata4').val() + '&email=' +$('#wdata3').val() , {
method: 'get'
}).then(function(res) {
$('.formContainer').hide();
$('#errorcontainer').hide();
$('#successcontainer').show();
var target = $('#successcontainer');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top - 40
}, 1000);
}
});
//alert('You successfully subscribed!); // ' + data.subscriptionID);
}
}).render('#paypal-button-subscription');
}
function getPlanID(form)
{
return fetch('https://www.lueneburgaktuell.de/xadmin/scripts/lga-io.php', {
method: 'post',
body: new FormData(form)
}).then(function(res) {
//console.log(res);
return res.json();
}).then(function(serverData) {
//console.log(serverData);
return serverData.id;
//return serverData;
});
}
function checkErrors()
{
//console.log('clicked');
if(updatePriceCalc()=== true)
{
$('#errorcontainer').show();
var target = $('#errorcontainer');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top - 40
}, 1000);
}
return false;
}
else
{
return true;
}
}