// === GLOBAL VAR
var notifyFollow = 0;
var gCookies = [ ], cookieEssential = [ "__sholder_general" ], cookieComplementary = [ ];
var hideLoginPwd = null, hideAccountPwd = null, hidePwd = null;
var accountId;
var debug = false;
// === DOCUMENT READY (= DOM READY)
$(document).ready(function() {
// === DEBUG messages ===
// === OFFCANVAS MENU ===
// ======================
$("#offCanvasMenu").on("show.bs.offcanvas", function(event) {
$(".offcanvas-toggle, .offcanvas-toggle-cart").addClass("showing");
}).on("hide.bs.offcanvas", function(event) {
$(".offcanvas-toggle, .offcanvas-toggle-cart").removeClass("showing");
});
// === CART ===
// ============
cartRedraw();
$(".offcanvas-cart").on("show.bs.offcanvas", cartRedraw);
// --- CART | Product color change ---
$(".cart-product .color .dropdown-item").on("click", cartProductChangeColor);
// --- CART | Quantity change ---
$(".cart-product .quantity .plus").on("click", cartProductPlusOne);
$(".cart-product .quantity .minus").on("click", cartProductMinusOne);
// --- CART | Remove product ---
$(".cart-product .remove").on("click", cartProductRemove);
// --- To checkout ---
$(".offcanvas-cart .offcanvas-header.cart-checkout .buy").on("click", cartToCheckout);
// === ACCOUNT ===
// ===============
accountRedrawMenu();
$(".offcanvas-account").on("show.bs.offcanvas", accountRedrawMenu);
// === SET CURSOR POSITION ===
// ===========================
/*
$.fn.setCursorPosition = function(pos) {
this.each(function(index, elem) {
if (elem.setSelectionRange) {
elem.setSelectionRange(pos, pos);
} else if (elem.createTextRange) {
var range = elem.createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
});
return this;
};
*/
});
// === EMAIL VALIDATION ===
// ========================
function validateEmail(email) {
var reg = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/g;
return (email.length > 0) && (reg.test(String(email).toLowerCase()));
}
// === NOTIFICATIONS ===
// ========================
function notifyMsg(pType, pTitle, pMessage, pIcon, pDelay, pUrl, pTarget) {
if (typeof pMessage === 'undefined') return false;
var lMessage = pMessage;
var lDelay = (typeof pDelay !== 'undefined') ? pDelay : 5000; // ms
var lType = (typeof pType !== 'undefined') ? pType : lType; // "success" | "info" | "warning" | "danger"
var lTitle = (typeof pTitle !== 'undefined') ? pTitle : null;
var lIcon = (typeof pIcon !== 'undefined') ? pIcon : null; // "fa fa-..."
var lUrl = (typeof pUrl !== 'undefined') ? pUrl : null;
var lTarget = (typeof pTarget !== 'undefined') ? pTarget : null;
var lData1 = { title: lTitle,
message: lMessage,
icon: lIcon,
url: lUrl,
target: lTarget
};
var lData2 = { type: lType,
allow_dismiss: true,
showProgressbar: true,
placement : {
from : "top",
align: "right"
},
delay: lDelay,
animate: {
enter: 'animated fadeInUp',
exit: 'animated fadeOutDown'
},
template: '
' +
'
' +
'
{1}
' +
'
{2}
' +
'
' +
'
' +
'
'
};
$.notify(lData1, lData2);
}
// === NAV BAR ===
// ===============
function updateCartToggler() {
$.ajax({
type: "POST",
url: "_cart.php",
data: "p=" + B64.encode("get/§/"+ Math.floor(Date.now() / 1000)),
cache: false,
success: function(data) {
try {
var obj = JSON.parse(data);
}
catch(err) {
notifyMsg("danger", "Cart", "Server did not reply correctly.", "bi bi-journal-x");
return false;
}
var cartProducts, htmlData = "";
if (obj.error != 0) {
notifyMsg("danger", "Cart ("+ obj.error +")", ""+ obj.shMsg +"
"+ obj.lngMsg +"", "bi bi-journal-x");
} else {
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
notifyMsg("danger", "Internet (AJAX : "+ XMLHttpRequest.status +")", errorThrown, "bi bi-journal-x");
}
});
}
// === CART ===
// ============
function cartRedraw(event) {
$.ajax({
type: "POST",
url: "_cart.php",
data: "p=" + B64.encode("get/§/"+ Math.floor(Date.now() / 1000)),
cache: false,
success: function(data) {
try {
var obj = JSON.parse(data);
}
catch(err) {
notifyMsg("danger", "Cart", "Server did not reply correctly.", "bi bi-journal-x");
return false;
}
var cartProducts, htmlData = "";
if (obj.error != 0) {
notifyMsg("danger", "Cart ("+ obj.error +")", ""+ obj.shMsg +"
"+ obj.lngMsg +"", "bi bi-journal-x");
} else {
obj.quantity = (isNaN(Number(obj.quantity)))? 0 : Number(obj.quantity);
obj.removed = parseInt(obj.removed);
if (obj.removed > 0) {
htmlData += '';
htmlData += '
';
htmlData += '
';
htmlData += '';
htmlData += '
';
htmlData += '
'+ obj.removed +' product'+ ((obj.removed >1)? 's are': ' is') +' no more sell.
';
htmlData += ((obj.removed >1)? 'They are': 'It is') +' automatically removed from your cart.
';
htmlData += '
';
htmlData += '
';
htmlData += '
';
htmlData += '
';
}
cartProducts = obj.cart;
var page = window.location.href;
var testPage1 = page.replace("checkout-1.php", "").length < page.length;
var testPage2 = page.replace("checkout-2.php", "").length < page.length;
var testPage3 = page.replace("checkout-3.php", "").length < page.length;
var testPage4 = page.replace("paiement.php", "").length < page.length;
var testPage = (testPage1) || (testPage2) || (testPage3) || (testPage4);
if ((testPage) && (obj.quantity <= 0)) {
htmlData += '';
htmlData += '
';
htmlData += '
';
htmlData += '';
htmlData += '
';
htmlData += '
Your cart is empty.
';
htmlData += '
> Please fill your cart with choosen products.
';
htmlData += '
Go to shop
';
htmlData += '
';
htmlData += '
';
htmlData += '
';
htmlData += '
';
$(".orderSummary [productQuantity]").attr("productQuantity", 0);
$(".cart-checkout").hide();
} else {
if (cartProducts.length <= 0) {
htmlData += '';
htmlData += '
';
htmlData += '
';
htmlData += '';
htmlData += '
';
htmlData += '
Your cart is empty.
';
htmlData += '
Please fill your cart with choosen products.
';
htmlData += '
Go to shop
';
htmlData += '
';
htmlData += '
';
htmlData += '
';
htmlData += '
';
$(".orderSummary [productQuantity]").attr("productQuantity", 0);
$(".cart-checkout").hide();
} else {
cartProducts.forEach((product) => {
var colorsOptions = '', selectedColor = '', total = product.price * product.quantity;
total = total.toFixed(2).toString().replace(/\B(?';
tempHtml += '';
tempHtml += '
';
tempHtml += '
';
tempHtml += '
';
tempHtml += '

';
tempHtml += '
';
tempHtml += '
';
tempHtml += '
'+ product.price +' €
';
tempHtml += '
';
tempHtml += '
';
tempHtml += '
';
tempHtml += '
';
tempHtml += '
';
tempHtml += '
';
tempHtml += '
'+ product.shopName +'
';
tempHtml += '';
tempHtml += '';
tempHtml += '
';
tempHtml += '
Color :
';
tempHtml += '
';
tempHtml += '
';
tempHtml += '';
tempHtml += '';
tempHtml += '
';
tempHtml += '
';
tempHtml += '
';
tempHtml += '
';
tempHtml += '
Quantity :
';
tempHtml += '
';
tempHtml += '';
tempHtml += '';
tempHtml += '';
tempHtml += '
';
tempHtml += '
';
tempHtml += '';
tempHtml += '
';
tempHtml += '
';
tempHtml += '
';
tempHtml += '';
htmlData += tempHtml;
});
$(".cart-checkout").show();
}
}
// Checkout cart header
if (testPage) {
tempHtml = '';
tempHtml = '';
tempHtml += '
';
htmlData = tempHtml + htmlData;
tempHtml = '';
tempHtml = '';
tempHtml += '
';
htmlData = htmlData + tempHtml;
$(".offcanvas-cart .offcanvas-header.cart-checkout").hide();
}
// Off canvas cart
$(".offcanvas-body.cart").empty();
$(".offcanvas-body.cart").html(htmlData);
// All carts display
if (testPage) {
$(".offcanvas-cart .offcanvas-header.cart-checkout").html("Cart is locked until end of order");
$(".offcanvas-cart .cart .remove").hide();
$(".offcanvas-cart .cart .dropdown-toggle").addClass("disabled");
$(".offcanvas-cart .cart .minus").addClass("disabled");
$(".offcanvas-cart .cart .plus").addClass("disabled");
} else {
$(".cart-product .color .dropdown-item").on("click", cartProductChangeColor);
$(".cart-product .quantity .plus").on("click", cartProductPlusOne);
$(".cart-product .quantity .minus").on("click", cartProductMinusOne);
$(".cart-product .remove").on("click", cartProductRemove);
$(".cart-product .quantity input").trigger("input");
}
// Cart toggler
if (testPage) {
$(".offcanvas-toggle-cart [quantity]").attr("quantity", obj.quantity).html(obj.quantity);
$(".offcanvas-toggle-cart").removeClass("empty full").addClass("locked");
$(".offcanvas-cart .offcanvas-header.cart-checkout .buy").addClass("btn-info notAllowed").removeClass("btn-primary ready");
} else {
$(".offcanvas-toggle-cart [quantity]").attr("quantity", obj.quantity).html(obj.quantity);
if (parseInt(obj.quantity) >0) {
$(".offcanvas-toggle-cart").removeClass("empty").addClass("full");
$(".offcanvas-cart .offcanvas-header.cart-checkout .buy").addClass("btn-primary ready").removeClass("btn-info notAllowed");
} else {
$(".offcanvas-toggle-cart").removeClass("full").addClass("empty");
$(".offcanvas-cart .offcanvas-header.cart-checkout .buy").addClass("btn-info notAllowed").removeClass("btn-primary ready");
}
}
// Order summary
if (parseInt(obj.quantity) >0) {
$(".orderSummary [productQuantity]").attr("productQuantity", obj.quantity);
} else {
$(".orderSummary [productQuantity]").attr("productQuantity", 0);
}
$(".orderSummary .subTotal [subtotal]").attr("subTotal", obj.subtotal.toFixed(2).toString().replace(/\B(?0);
if ($counter) {
setIntShop = setInterval(updateCounterShop, 1000);
}
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
notifyMsg("danger", "Internet (AJAX : "+ XMLHttpRequest.status +")", errorThrown, "bi bi-journal-x");
}
});
};
function cartProductChangeColor(event) {
var $this = $(this);
var color = $this.attr("setColor");
var $product = $this.closest(".cart-product");
var btn = $this.closest(".btn-group").find(".dropdown-toggle");
btn.find("span").removeClass("selected");
btn.find("span[setColor='"+ color +"']").addClass("selected");
$.ajax({
type: "POST",
url: "_cart.php",
data: "p=" + B64.encode("update/§/"+ $product.attr("productId") +"/§/"+ $product.attr("productColor") +","+ color +"/§/"+ Math.floor(Date.now() / 1000)),
cache: false,
success: function(data) {
try {
var obj = JSON.parse(data);
}
catch(err) {
notifyMsg("danger", "Cart", "Server did not reply correctly.", "bi bi-journal-x");
return false;
}
var cartProducts, htmlData = "";
if (obj.error != 0) {
notifyMsg("danger", "Cart ("+ obj.error +")", "Product color update error
"+ obj.lngMsg +"", "bi bi-journal-x");
} else {
cartRedraw();
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
notifyMsg("danger", "Internet (AJAX : "+ XMLHttpRequest.status +")", errorThrown, "bi bi-journal-x");
}
});
};
function cartProductPlusOne(event) {
var $product = $(this).closest(".cart-product");
var $input = $(this).closest(".quantity").find("input");
var value = Number.isNaN(Number($input.val())) ? 0 : Number($input.val());
$.ajax({
type: "POST",
url: "_cart.php",
data: "p=" + B64.encode("plus/§/"+ $product.attr("productId") +",1/§/"+ $product.attr("productColor") +"/§/"+ Math.floor(Date.now() / 1000)),
cache: false,
success: function(data) {
try {
var obj = JSON.parse(data);
}
catch(err) {
notifyMsg("danger", "Cart", "Server did not reply correctly.", "bi bi-journal-x");
return false;
}
var cartProducts, htmlData = "";
if (obj.error != 0) {
notifyMsg("danger", "Cart ("+ obj.error +")", "Product not added
"+ obj.lngMsg +"", "bi bi-journal-x");
} else {
cartRedraw();
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
notifyMsg("danger", "Internet (AJAX : "+ XMLHttpRequest.status +")", errorThrown, "bi bi-journal-x");
}
});
};
function cartProductMinusOne(event) {
var $product = $(this).closest(".cart-product");
var $input = $(this).closest(".quantity").find("input");
var value = Number.isNaN(Number($input.val())) ? 0 : Number($input.val());
$.ajax({
type: "POST",
url: "_cart.php",
data: "p=" + B64.encode("minus/§/"+ $product.attr("productId") +",1/§/"+ $product.attr("productColor") +"/§/"+ Math.floor(Date.now() / 1000)),
cache: false,
success: function(data) {
try {
var obj = JSON.parse(data);
}
catch(err) {
notifyMsg("danger", "Cart", "Server did not reply correctly.", "bi bi-journal-x");
return false;
}
var cartProducts, htmlData = "";
if (obj.error != 0) {
notifyMsg("danger", "Cart ("+ obj.error +")", "Product not substracted
"+ obj.lngMsg +"", "bi bi-journal-x");
} else {
cartRedraw();
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
notifyMsg("danger", "Internet (AJAX : "+ XMLHttpRequest.status +")", errorThrown, "bi bi-journal-x");
}
});
};
function cartProductChangeQty(event) {
var $this = $(this);
var $product = $this.closest(".cart-product");
var qte = $this.val();
var productId = $this.closest(".cart-product").attr("productId");
$.ajax({
type: "POST",
url: "_cart.php",
data: "p=" + B64.encode("set/§/"+ $product.attr("productId") +","+ qte +"/§/"+ $product.attr("productColor") +"/§/"+ Math.floor(Date.now() / 1000)),
cache: false,
success: function(data) {
try {
var obj = JSON.parse(data);
}
catch(err) {
notifyMsg("danger", "Cart", "Server did not reply correctly.", "bi bi-journal-x");
return false;
}
var cartProducts, htmlData = "";
if (obj.error != 0) {
notifyMsg("danger", "Cart ("+ obj.error +")", "Product quantity not modified
"+ obj.lngMsg +"", "bi bi-journal-x");
} else {
cartRedraw();
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
notifyMsg("danger", "Internet (AJAX : "+ XMLHttpRequest.status +")", errorThrown, "bi bi-journal-x");
}
});
}
function cartProductRemove(event) {
var $product = $(this).closest(".cart-product");
swal({
title: "Are you sure?",
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-danger icon-trash",
confirmButtonText: "Remove",
cancelButtonClass: "btn-outline-primary icon-x-square-fill",
cancelButtonText: "Cancel",
closeOnConfirm: true,
closeOnCancel: true,
closeOnClickOutside: false,
closeOnEsc: false
},
function(isConfirm) {
if (isConfirm) {
$.ajax({
type: "POST",
url: "_cart.php",
data: "p=" + B64.encode("remove/§/"+ $product.attr("productId") +"/§/"+ $product.attr("productColor") +"/§/"+ Math.floor(Date.now() / 1000)),
cache: false,
success: function(data) {
try {
var obj = JSON.parse(data);
}
catch(err) {
notifyMsg("danger", "Cart", "Server did not reply correctly.", "bi bi-journal-x");
return false;
}
var cartProducts, htmlData = "";
if (obj.error != 0) {
notifyMsg("danger", "Cart ("+ obj.error +")", "Product not removed
"+ obj.lngMsg +"", "bi bi-journal-x");
} else {
cartRedraw();
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
notifyMsg("danger", "Internet (AJAX : "+ XMLHttpRequest.status +")", errorThrown, "bi bi-journal-x");
}
});
}
});
};
function cartToCheckout(event) {
$this = $(this);
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
if ($this.hasClass("notAllowed")) {
notifyMsg("danger", "Not allowed yet", "Please verify your cart content before proceeding.", "bi bi-journal-x");
return false;
} else {
$(".toCartCheckout")[0].click();
return false;
}
}
// === COUNTER ===
// ===============
function updateCounterShop() {
counterShop--;
var text = "(automatic in "+ counterShop +" second"+ ( (counterShop > 1)? "s":"" ) +")";
$(".counterShop small").html(text);
if (counterShop == 0) {
clearInterval(setIntShop);
$(".counterShop")[0].click();
}
}
// === ACCOUNT ===
// ===============
// --- ACCOUNT | Menu ---
function accountRedrawMenu(event) {
if (typeof event === "object") {
if (typeof event.stopPropagation === "function") event.stopPropagation();
if (typeof event.stopImmediatePropagation === "function") event.stopImmediatePropagation();
}
if (accountId > 0) {
$(".account").empty();
$(".account").load("_account.php", {"p":B64.encode("getAccountMenu/§/"+ Math.floor(Date.now() / 1000))}, function (response, status, xhr) {
if ( status == "error" ) {
notifyMsg("danger", "Account menu", "Server did not reply correctly.", "bi bi-journal-x");
} else {
$(".offcanvas-account .accountMenu .logout").on("click", proceedLogout);
$(".offcanvas-account .accountMenu .personalInformation").on("click", {wizard: false}, accountRedrawFormName);
$(".offcanvas-account .accountMenu .badmintonInformation").on("click", {wizard: false}, accountRedrawFormBadminton);
$(".offcanvas-account .accountMenu .myOrders").on("click", accountRedrawOrders);
$(".offcanvas-account .accountMenu .myDiscounts").on("click", accountRedrawDiscounts);
$(".offcanvas-account .accountMenu .accountSettings").on("click", accountRedrawSettings);
}
});
} else {
accountRedrawFormLogin();
}
}
// --- ACCOUNT | Log out ---
function proceedLogout(event) {
swal({
title: "Are you sure ?",
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-success icon-box-arrow-right",
confirmButtonText: "Logout",
cancelButtonClass: "btn-outline-primary icon-x-square-fill",
cancelButtonText: "Cancel",
closeOnConfirm: true,
closeOnCancel: true,
closeOnClickOutside: false,
closeOnEsc: false
},
function(isConfirm) {
if (isConfirm) {
$.ajax({
type: "POST",
url: "_account.php",
data: "p=" + B64.encode("logout/§/"+ Math.floor(Date.now() / 1000)),
cache: false,
success: function(data) {
try {
var obj = JSON.parse(data);
}
catch(err) {
notifyMsg("danger", "Logout", "Server did not reply correctly.", "bi bi-journal-x");
return false;
}
if (obj.error != 0) {
notifyMsg("danger", "Logout ("+ obj.error +")", ""+ obj.shMsg +"
"+ obj.lngMsg +"", "bi bi-journal-x");
return false;
} else {
$(".offcanvas-toggle-account").addClass("empty");
accountId = null;
$(".offcanvas-account").offcanvas("hide");
return true;
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
notifyMsg("danger", "Internet (AJAX : "+ XMLHttpRequest.status +")", errorThrown, "bi bi-journal-x");
if (deferredObj) {
deferredObj.reject(false);
} else {
return false;
}
}
});
}
});
}
// --- ACCOUNT | User account ---
function retrievePassword() {
var login = $(".account .inputLogin").val().trim();
if (!validateEmail(login)) {
$(".account .input-group.login, .account .inputLogin, .account .inputLogin + label").addClass("is-invalid");
notifyMsg("danger", "Retrieve password", "Fill Login field first.", "bi bi-journal-x");
} else {
resetPaswword(true).fail(function () {
notifyMsg("danger", "Retrieve password", "Account not found.", "bi bi-journal-x");
}).done(function (obj) {
notifyMsg("success", "Retrieve password", "If mail adress is found,
a mail is sent with a password reset link.
Do not forget to also check your spam folder if you not receive it.", "bi bi-journal-x");
});
}
}
function resetPaswword(pToBeDeffered) {
if ((typeof pToBeDeffered === "boolean") && (pToBeDeffered)) {
var deferredObj = $.Deferred();
}
$.ajax({
type: "POST",
url: "_account.php",
data: "p=" + B64.encode("resetPassword/§/"+ $(".account .inputLogin").val().trim() + "/§/"+ Math.floor(Date.now() / 1000)),
cache: false,
success: function(data) {
try {
var obj = JSON.parse(data);
}
catch(err) {
notifyMsg("danger", "Retrieve password", "Server did not reply correctly.", "bi bi-journal-x");
if (deferredObj) {
deferredObj.reject(false);
} else {
return false;
}
}
if (obj.error != 0) {
notifyMsg("danger", "Retrieve password ("+ obj.error +")", ""+ obj.shMsg +"
"+ obj.lngMsg +"", "bi bi-journal-x");
if (deferredObj) {
deferredObj.reject(obj);
} else {
return false;
}
} else {
if (deferredObj) {
deferredObj.resolve(obj);
} else {
return true;
}
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
notifyMsg("danger", "Internet (AJAX : "+ XMLHttpRequest.status +")", errorThrown, "bi bi-journal-x");
if (deferredObj) {
deferredObj.reject(false);
} else {
return false;
}
}
});
if (deferredObj) {
return deferredObj.promise();
}
}
function accountRedrawFormLogin() {
$(".account").empty();
$(".account").load("_account.php", {"p":B64.encode("getFormLogin/§/"+ Math.floor(Date.now() / 1000))}, function (response, status, xhr) {
if ( status == "error" ) {
notifyMsg("danger", "Form login", "Server did not reply correctly.", "bi bi-journal-x");
} else {
$(".account .revealPassword").on("click", revealPassword);
// --- ACCOUNT | Login or Create account inputs ---
$(".account .inputLogin, .account .inputPassword").on("input", checkPassword);
$(".account .loginButton .buy").on("click", checkLogin);
$(".account .retrievePassword").on("click", retrievePassword);
$(".account .inputMail, .account .inputPassword1, .account .inputPassword2").on("input", checkAccount);
$(".account .form-check-input").on("click", checkAccount);
$(".account .accountButton .buy").on("click", checkAccountToCreate);
$("#collapseLogin").on("shown.bs.collapse", function() {
$(".account .inputLogin").focus();
});
$("#collapseAccount").on("shown.bs.collapse", function() {
$(".account .inputMail").focus();
});
$(".account .inputLogin").focus();
}
});
}
function revealPassword(event) {
var $this = $(this);
var $group = $this.closest(".input-group");
var $input = $group.find("input");
if ($input.attr("type") == "password") {
$input.attr("type", "text");
$group.find(".bi-eye").addClass("bi-eye-slash-fill").removeClass("bi-eye");
$this.addClass("btn-warning").removeClass("btn-primary");
} else {
$input.attr("type", "password");
$group.find(".bi-eye-slash-fill").addClass("bi-eye").removeClass("bi-eye-slash-fill");
$this.addClass("btn-primary").removeClass("btn-warning");
}
if ($group.hasClass("password1")) {
$(".inputPassword2").attr("type", "password");
$(".input-group.password2 .bi-eye-slash-fill").addClass("bi-eye").removeClass("bi-eye-slash-fill");
$(".input-group.password2 .revealPassword").addClass("btn-primary").removeClass("btn-warning");
clearInterval(hideAccountPwd);
hidePwd = 1;
hideAccountPwd = setInterval(hideAccountPassword, 10000);
} else if ($group.hasClass("password2")) {
$(".inputPassword1").attr("type", "password");
$(".input-group.password1 .bi-eye-slash-fill").addClass("bi-eye").removeClass("bi-eye-slash-fill");
$(".input-group.password1 .revealPassword").addClass("btn-primary").removeClass("btn-warning");
clearInterval(hideAccountPwd);
hidePwd = 2;
hideAccountPwd = setInterval(hideAccountPassword, 10000);
} else {
clearInterval(hideLoginPwd);
hideLoginPwd = setInterval(hideLoginPassword, 10000);
}
}
function hideAccountPassword() {
clearInterval(hideAccountPwd);
$(".account .inputPassword"+ hidePwd).attr("type", "password");
$(".account .input-group.password"+ hidePwd +" .bi-eye-slash-fill").addClass("bi-eye").removeClass("bi-eye-slash-fill");
$(".account .input-group.password"+ hidePwd +" .revealPassword").addClass("btn-primary").removeClass("btn-warning");
}
function hideLoginPassword() {
clearInterval(hideLoginPwd);
$(".account .inputPassword").attr("type", "password");
$(".account .input-group.password .bi-eye-slash-fill").addClass("bi-eye").removeClass("bi-eye-slash-fill");
$(".account .input-group.password .revealPassword").addClass("btn-primary").removeClass("btn-warning");
}
function checkPassword(event) {
var $this = $(this);
var checkLogin = $(".account .inputLogin").val().trim().length >0;
var checkPassword = $(".account .inputPassword").val().trim().length >7;
if (checkLogin && checkPassword) {
$(".account .loginButton .buy").addClass("btn-primary ready").removeClass("btn-info notAllowed");
} else {
$(".account .loginButton .buy").addClass("btn-info notAllowed").removeClass("btn-primary ready");
if ($this.hasClass("inputLogin")) {
$(".account .input-group.login, .account .inputLogin, .account .inputLogin + label").removeClass("is-invalid is-valid");
}
if ($this.hasClass("inputPassword")) {
$(".account .input-group.password, .account .inputPassword, .account .inputPassword + label").removeClass("is-invalid is-valid");
}
}
}
function checkLogin(event) {
var $this = $(this);
$(".account .input-group.login, .account .inputLogin, .account .inputLogin + label").removeClass("is-invalid is-valid");
$(".account .input-group.password, .account .inputPassword, .account .inputPassword + label").removeClass("is-invalid is-valid");
if ($this.hasClass("ready")) {
$.ajax({
type: "POST",
url: "_account.php",
data: "p=" + B64.encode("checkLogin/§/"+ $(".account .inputLogin").val().trim() + "/-/"+ $(".account .inputPassword").val().trim() + "/§/"+ Math.floor(Date.now() / 1000)),
cache: false,
success: function(data) {
try {
var obj = JSON.parse(data);
}
catch(err) {
notifyMsg("danger", "Login", "Server did not reply correctly.", "bi bi-journal-x");
return false;
}
if (obj.error != 0) {
if (obj.error <0) {
notifyMsg("danger", "Login ("+ obj.error +")", ""+ obj.shMsg +"
"+ obj.lngMsg +"", "bi bi-journal-x");
} else {
notifyMsg("danger", "Login", "Login not found
Please verify id information.", "bi bi-journal-x");
}
} else {
$(".offcanvas-toggle-account").removeClass("empty");
accountId = obj.id;
accountRedrawMenu();
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
notifyMsg("danger", "Internet (AJAX : "+ XMLHttpRequest.status +")", errorThrown, "bi bi-journal-x");
}
});
} else {
var checkLogin = $(".account .inputLogin").val().trim().length >0;
var checkPassword = $(".account .inputPassword").val().trim().length >7;
if (!checkLogin) {
$(".account .input-group.login, .account .inputLogin, .account .inputLogin + label").addClass("is-invalid");
} else {
$(".account .input-group.login, .account .inputLogin, .account .inputLogin + label").addClass("is-valid");
}
if (!checkPassword) {
$(".account .input-group.password, .account .inputPassword, .account .inputPassword + label").addClass("is-invalid");
} else {
$(".account .input-group.password, .account .inputPassword, .account .inputPassword + label").addClass("is-valid");
}
}
}
function checkAccount(event) {
var $this = $(this);
var password1 = $(".account .inputPassword1").val().trim();
var password2 = $(".account .inputPassword2").val().trim();
var checkMail = validateEmail($(".account .inputMail").val().trim());
var checkPassword1 = password1.trim().length >7;
var checkPassword2 = password2.trim().length >7;
var checkPasswords = (password1 == password2);
var rule8Cars = new RegExp(".{8,}");
var ruleNoSpace = new RegExp("[\s]+");
var ruleCapital = new RegExp(".*[A-Z]");
var ruleNumber = new RegExp(".*[0-9]");
var checkRule8Cars = (checkPassword1) && (checkPassword2);
var checkRuleNoSpace = !((password1.indexOf(' ') >= 0) || (password2.indexOf(' ') >= 0)) && (password1.length >1) && (password2.length >1);
var checkRuleCapital = (ruleCapital.test(password1)) && (ruleCapital.test(password2));
var checkRuleNumber = (ruleNumber.test(password1)) && (ruleNumber.test(password2));
if (checkPassword1 && checkPassword2 && checkPasswords && checkMail && checkRule8Cars && checkRuleNoSpace && checkRuleCapital && checkRuleNumber) {
$(".account .accountButton .buy").addClass("btn-primary ready").removeClass("btn-info notAllowed");
} else {
$(".account .accountButton .buy").addClass("btn-info notAllowed").removeClass("btn-primary ready");
if ($this.hasClass("inputMail")) {
$(".account .input-group.mail, .account .inputMail, .account .inputMail + label").removeClass("is-invalid is-valid");
}
if (($this.hasClass("inputPassword1")) || ($this.hasClass("inputPassword2"))) {
$(".account .input-group.password1, .account .inputPassword1, .account .inputPassword1 + label").removeClass("is-invalid is-valid");
$(".account .input-group.password2, .account .inputPassword2, .account .inputPassword2 + label").removeClass("is-invalid is-valid");
}
}
if (checkRule8Cars) {
$(".account .pwdRule.8cars").addClass("ok").removeClass("ko");
} else {
$(".account .pwdRule.8cars").addClass("ko").removeClass("ok");
}
if (checkRuleNoSpace) {
$(".account .pwdRule.noSpace").addClass("ok").removeClass("ko");
} else {
$(".account .pwdRule.noSpace").addClass("ko").removeClass("ok");
}
if (checkRuleCapital) {
$(".account .pwdRule.capital").addClass("ok").removeClass("ko");
} else {
$(".account .pwdRule.capital").addClass("ko").removeClass("ok");
}
if (checkRuleNumber) {
$(".account .pwdRule.number").addClass("ok").removeClass("ko");
} else {
$(".account .pwdRule.number").addClass("ko").removeClass("ok");
}
}
function checkAccountToCreate() {
var $this = $(this);
$(".account .input-group.mail, .account .inputMail, .account .inputMail + label").removeClass("is-invalid is-valid");
$(".account .input-group.password1, .account .inputPassword1, .account .inputPassword1 + label").removeClass("is-invalid is-valid");
$(".account .input-group.password2, .account .inputPassword2, .account .inputPassword2 + label").removeClass("is-invalid is-valid");
if ($this.hasClass("ready")) {
createAccount(true).fail(function () {
$(".account .inputPassword, .account .inputPassword1, .account .inputPassword2").val("");
notifyMsg("danger", "Account creation", "Error during account creation.", "bi bi-journal-x");
}).done(function (obj) {
$(".account .inputPassword, .account .inputPassword1, .account .inputPassword2").val("");
accountId = obj.id;
accountRedrawFormName(true);
});
} else {
var password1 = $(".account .inputPassword1").val().trim();
var password2 = $(".account .inputPassword2").val().trim();
var checkMail = validateEmail($(".account .inputMail").val().trim());
var checkPassword1 = password1.length >7;
var checkPassword2 = password2.trim().length >7;
var checkPasswords = (password1 == password2);
if (!checkMail) {
$(".account .input-group.mail, .account .inputMail, .account .inputMail + label").addClass("is-invalid");
} else {
$(".account .input-group.mail, .account .inputMail, .account .inputMail + label").addClass("is-valid");
}
if (!checkPassword1 || !checkPasswords) {
$(".account .input-group.password1, .account .inputPassword1, .account .inputPassword1 + label").addClass("is-invalid");
} else {
$(".account .input-group.password1, .account .inputPassword1, .account .inputPassword1 + label").addClass("is-valid");
}
if (!checkPassword2 || !checkPasswords) {
$(".account .input-group.password2, .account .inputPassword2, .account .inputPassword2 + label").addClass("is-invalid");
} else {
$(".account .input-group.password2, .account .inputPassword2, .account .inputPassword2 + label").addClass("is-valid");
}
}
}
function createAccount(pToBeDeffered) {
if ((typeof pToBeDeffered === "boolean") && (pToBeDeffered)) {
var deferredObj = $.Deferred();
}
$.ajax({
type: "POST",
url: "_account.php",
data: "p=" + B64.encode("createAccount/§/"+ $(".account .inputMail").val().trim() + "/-/"+ $(".account .inputPassword1").val().trim() + "/§/"+ Math.floor(Date.now() / 1000)),
cache: false,
success: function(data) {
try {
var obj = JSON.parse(data);
}
catch(err) {
notifyMsg("danger", "Account creation", "Server did not reply correctly.", "bi bi-journal-x");
if (deferredObj) {
deferredObj.reject(false);
} else {
return false;
}
}
if (obj.error != 0) {
notifyMsg("danger", "Account creation ("+ obj.error +")", ""+ obj.shMsg +"
"+ obj.lngMsg +"", "bi bi-journal-x");
if (deferredObj) {
deferredObj.reject(obj);
} else {
return false;
}
} else {
$(".offcanvas-toggle-account").removeClass("empty");
if (deferredObj) {
deferredObj.resolve(obj);
} else {
return true;
}
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
notifyMsg("danger", "Internet (AJAX : "+ XMLHttpRequest.status +")", errorThrown, "bi bi-journal-x");
if (deferredObj) {
deferredObj.reject(false);
} else {
return false;
}
}
});
if (deferredObj) {
return deferredObj.promise();
}
}
// --- ACCOUNT | Personal information ---
function accountRedrawFormName(pWizard) {
if (typeof pWizard.stopPropagation === "function") pWizard.stopPropagation();
if (typeof pWizard.stopImmediatePropagation === "function") pWizard.stopImmediatePropagation();
if (typeof pWizard === "object") {
pWizard = pWizard.data.wizard;
}
if ((typeof pWizard === "boolean") && (pWizard)) {
var wizard = "wizard";
} else {
var wizard = Math.floor(Date.now() / 1000);
}
$(".account").empty();
$(".account").load("_account.php", {"p":B64.encode("getFormName/§/"+ wizard +"/§/"+ Math.floor(Date.now() / 1000))}, function (response, status, xhr) {
if ( status == "error" ) {
notifyMsg("danger", "Form Name", "Server did not reply correctly.", "bi bi-journal-x");
} else {
$(".account .inputName, .account .inputSurname").on("input", checkFormAccountName);
$(".account .btn.skip").on("click", {wizard: pWizard}, accountRedrawFormBadminton);
$(".account .btn.cancel").on("click", accountRedrawMenu);
$(".account .btn.next").on("click", {wizard: pWizard}, showAccountBadminton);
$(".account .form-check-input").on("click", setGender);
}
});
}
function checkFormAccountName() {
var $this = $(this);
if ($this.hasClass("form-control")) {
var $inputGroup = $this.closest(".input-group");
var $label = $inputGroup.find("label");
$this.removeClass("is-invalid is-valid");
$inputGroup.removeClass("is-invalid is-valid");
$label.removeClass("is-invalid is-valid");
}
if ($this.hasClass("form-check-input")) {
$(".account .switch").removeClass("is-invalid is-valid");
}
var checkName = $(".account .inputName").val().trim().length >0;
var checkSurname = $(".account .inputSurname").val().trim().length >0;
var isMale = $(".account .form-check-input.male").is(":checked");
var isFemale = $(".account .form-check-input.female").is(":checked");
var checkGender = isMale || isFemale;
if (checkName || checkSurname || checkGender) {
$(".account .btn.next").addClass("btn-primary ready").removeClass("btn-info notAllowed");
} else {
$(".account .btn.next").addClass("btn-info notAllowed").removeClass("btn-primary ready");
}
}
function setGender(event) {
var $this = $(this);
$(".account .switch").removeClass("is-invalid is-valid");
if ($this.is(":checked")) {
if ($this.hasClass("male")) {
$(".account .form-check-input.female").prop("checked", false);
} else {
$(".account .form-check-input.male").prop("checked", false);
}
}
checkFormAccountName();
}
function setPersonalInformation(pToBeDeffered) {
if ((typeof pToBeDeffered === "boolean") && (pToBeDeffered)) {
var deferredObj = $.Deferred();
}
var name = $(".account .inputName").val().trim();
var surname = $(".account .inputSurname").val().trim();
var isMale = $(".account .form-check-input.male").is(":checked");
var isFemale = $(".account .form-check-input.female").is(":checked");
var gender;
gender = (isMale)? "male" : null;
gender = (isFemale)? "female" : gender;
$.ajax({
type: "POST",
url: "_account.php",
data: "p=" + B64.encode("saveAccountName/§/"+ name + "/-/"+ surname +"/-/"+ gender + "/§/"+ Math.floor(Date.now() / 1000)),
cache: false,
success: function(data) {
try {
var obj = JSON.parse(data);
}
catch(err) {
notifyMsg("danger", "Personal information", "Server did not reply correctly.", "bi bi-journal-x");
if (deferredObj) {
deferredObj.reject(false);
} else {
return false;
}
}
if (obj.error != 0) {
notifyMsg("danger", "Personal information ("+ obj.error +")", ""+ obj.shMsg +"
"+ obj.lngMsg +"", "bi bi-journal-x");
if (deferredObj) {
deferredObj.reject(obj);
} else {
return false;
}
} else {
$(".offcanvas-toggle-account").removeClass("empty");
if (deferredObj) {
deferredObj.resolve(true);
} else {
return true;
}
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
notifyMsg("danger", "Internet (AJAX : "+ XMLHttpRequest.status +")", errorThrown, "bi bi-journal-x");
if (deferredObj) {
deferredObj.reject(false);
} else {
return false;
}
}
});
if (deferredObj) {
return deferredObj.promise();
}
}
function showAccountBadminton(event) {
var e = event;
var $this = $(this);
if ($this.hasClass("ready")) {
setPersonalInformation(true).fail(function () {
notifyMsg("danger", "Personal information", "Error during update.", "bi bi-journal-x");
}).done(function () {
$(".account .inputName, .account .inputSurname").val("");
$(".account .form-check-input.male, .account .form-check-input.female").prop("checked", false);
if (e.data.wizard) {
accountRedrawFormBadminton(e.data.wizard);
} else {
accountRedrawMenu();
}
});
} else {
var checkName = $(".account .inputName").val().trim().length >0;
var checkSurname = $(".account .inputSurname").val().trim().length >0;
var checkGenderMale = $(".account .form-check-input.male").is(":checked");
var checkGenderFemale = $(".account .form-check-input.female").is(":checked");
if (checkName) {
$(".account .input-group.name, .account .inputName, .account .inputName + label").addClass("is-valid").removeClass("is-invalid");
} else {
$(".account .input-group.name, .account .inputName, .account .inputName + label").addClass("is-invalid").removeClass("is-valid");
}
if (checkSurname) {
$(".account .input-group.surname, .account .inputSurname, .account .inputSurname + label").addClass("is-valid").removeClass("is-invalid");
} else {
$(".account .input-group.surname, .account .inputSurname, .account .inputSurname + label").addClass("is-invalid").removeClass("is-valid");
}
if (!checkGenderMale && !checkGenderFemale) {
$(".account .switch").addClass("is-invalid");
} else {
$(".account .switch").addClass("is-valid");
}
if (!checkName && !checkSurname && !checkGenderMale && !checkGenderFemale) notifyMsg("danger", "Personal information", "Use Skip button if you don't want to share us this information.", "bi bi-journal-x");
}
}
// --- ACCOUNT | Form Badminton ---
function accountRedrawFormBadminton(pWizard) {
if (typeof pWizard.stopPropagation === "function") pWizard.stopPropagation();
if (typeof pWizard.stopImmediatePropagation === "function") pWizard.stopImmediatePropagation();
if (typeof pWizard === "object") {
pWizard = pWizard.data.wizard;
}
if ((typeof pWizard === "boolean") && (pWizard)) {
var wizard = "wizard";
} else {
var wizard = Math.floor(Date.now() / 1000);
}
$(".account").empty();
$(".account").load("_account.php", {"p":B64.encode("getFormBadminton/§/"+ wizard +"/§/"+ Math.floor(Date.now() / 1000))}, function (response, status, xhr) {
if ( status == "error" ) {
notifyMsg("danger", "Form Badminton", "Server did not reply correctly.", "bi bi-journal-x");
} else {
$(".account .form-check-input.badminton, .account .form-check-input.rank").on("click", checkFormAccountBadmintonAndRank);
$(".account .btn.skip").on("click", { skip: true }, showAccountMenu);
$(".account .btn.cancel").on("click", accountRedrawMenu);
$(".account .btn.next").on("click", { skip: false }, showAccountMenu);
}
});
}
function checkFormAccountBadmintonAndRank() {
var $this = $(this);
var checkBadminton = false, checkRank = false;
if ($this.hasClass("rank")) {
$(".account .switch.rank").removeClass("is-invalid is-valid");
if ($this.is(":checked")) {
if (!($this.hasClass("national"))) $(".account .form-check-input.rank.national").prop("checked", false);
if (!($this.hasClass("regional"))) $(".account .form-check-input.rank.regional").prop("checked", false);
if (!($this.hasClass("departmental"))) $(".account .form-check-input.rank.departmental").prop("checked", false);
if (!($this.hasClass("noCompet"))) $(".account .form-check-input.rank.noCompet").prop("checked", false);
}
}
if ($this.hasClass("badminton")) {
$(".account .switch.badminton").removeClass("is-invalid is-valid");
}
$(".account .form-check-input.badminton").each(function () {
checkBadminton = $(this).is(":checked") || checkBadminton;
});
$(".account .form-check-input.rank").each(function () {
checkRank = $(this).is(":checked") || checkRank;
});
if (!checkBadminton && !checkRank) {
$(".account .btn.next").addClass("btn-info notAllowed").removeClass("btn-primary ready");
} else {
$(".account .btn.next").addClass("btn-primary ready").removeClass("btn-info notAllowed");
}
}
function showAccountMenu(event) {
var e = event;
var $this = $(this);
if (typeof e === "object") {
var skip = e.data.skip;
event.stopPropagation();
event.stopImmediatePropagation();
} else {
var skip = true;
}
if (skip) {
accountRedrawMenu();
} else {
if ($this.hasClass("ready")) {
setBadmintonInformation(true).fail(function () {
notifyMsg("danger", "Badminton information", "Error during update.", "bi bi-journal-x");
}).done(function () {
$(".account .inputName, .account .inputSurname").val("");
$(".account .form-check-input.male, .account .form-check-input.female").prop("checked", false);
accountRedrawMenu();
});
} else {
var checkBadminton = false, checkRank = false;
$(".account .form-check-input.badminton").each(function () {
checkBadminton = $(this).is(":checked") || checkBadminton;
});
$(".account .form-check-input.rank").each(function () {
checkRank = $(this).is(":checked") || checkRank;
});
if (!checkBadminton && !checkRank) {
$(".account .switch.badminton, .account .switch.rank").addClass("is-invalid");
}
notifyMsg("danger", "Badminton information", "Use Skip button if you don't want to share us this information.", "bi bi-journal-x");
}
}
}
function setBadmintonInformation(pToBeDeffered) {
if ((typeof pToBeDeffered === "boolean") && (pToBeDeffered)) {
var deferredObj = $.Deferred();
}
var isPlayer = $(".account .form-check-input.badminton.player").is(":checked");
var isTrainer = $(".account .form-check-input.badminton.trainer").is(":checked");
var isAdministrative = $(".account .form-check-input.badminton.administrative").is(":checked");
var isNational = $(".account .form-check-input.rank.national").is(":checked");
var isRegional = $(".account .form-check-input.rank.regional").is(":checked");
var isDepartmental = $(".account .form-check-input.rank.departmental").is(":checked");
var isNoCompet = $(".account .form-check-input.rank.noCompet").is(":checked");
var badminton = "", rank = "";
badminton += (isPlayer)? ",player" : "";
badminton += (isTrainer)? ",trainer" : "";
badminton += (isAdministrative)? ",administrative" : "";
badminton = (badminton.length >0)? badminton.substring(1) : badminton;
if (isNational) rank = "national";
if (isRegional) rank = "regional";
if (isDepartmental) rank = "departmental";
if (isNoCompet) rank = "nocompet";
$.ajax({
type: "POST",
url: "_account.php",
data: "p=" + B64.encode("saveAccountBadminton/§/"+ badminton + "/-/"+ rank +"/§/"+ Math.floor(Date.now() / 1000)),
cache: false,
success: function(data) {
try {
var obj = JSON.parse(data);
}
catch(err) {
notifyMsg("danger", "Badminton information", "Server did not reply correctly.", "bi bi-journal-x");
if (deferredObj) {
deferredObj.reject(false);
} else {
return false;
}
}
if (obj.error != 0) {
notifyMsg("danger", "Badminton information ("+ obj.error +")", ""+ obj.shMsg +"
"+ obj.lngMsg +"", "bi bi-journal-x");
if (deferredObj) {
deferredObj.reject(obj);
} else {
return false;
}
} else {
$(".offcanvas-toggle-account").removeClass("empty");
if (deferredObj) {
deferredObj.resolve(obj);
} else {
return true;
}
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
notifyMsg("danger", "Internet (AJAX : "+ XMLHttpRequest.status +")", errorThrown, "bi bi-journal-x");
if (deferredObj) {
deferredObj.reject(false);
} else {
return false;
}
}
});
if (deferredObj) {
return deferredObj.promise();
}
}
// --- ACCOUNT | Orders ---
function accountRedrawOrders(event) {
if (typeof event.stopPropagation === "function") event.stopPropagation();
if (typeof event.stopImmediatePropagation === "function") event.stopImmediatePropagation();
$(".account").empty();
$(".account").load("_account.php", {"p":B64.encode("getOrderList/§/"+ Math.floor(Date.now() / 1000))}, function (response, status, xhr) {
if ( status == "error" ) {
notifyMsg("danger", "Order list", "Server did not reply correctly.", "bi bi-journal-x");
} else {
$(".account .btn.cancel").on("click", accountRedrawMenu);
}
});
}
function accountRedrawDiscounts(event) {
if (typeof event.stopPropagation === "function") event.stopPropagation();
if (typeof event.stopImmediatePropagation === "function") event.stopImmediatePropagation();
$(".account").empty();
$(".account").load("_account.php", {"p":B64.encode("getDiscountList/§/"+ Math.floor(Date.now() / 1000))}, function (response, status, xhr) {
if ( status == "error" ) {
notifyMsg("danger", "Discount list", "Server did not reply correctly.", "bi bi-journal-x");
} else {
$(".account .btn.cancel").on("click", accountRedrawMenu);
}
});
}
function accountRedrawSettings(event) {
if (typeof event.stopPropagation === "function") event.stopPropagation();
if (typeof event.stopImmediatePropagation === "function") event.stopImmediatePropagation();
$(".account").empty();
$(".account").load("_account.php", {"p":B64.encode("getSettings/§/"+ Math.floor(Date.now() / 1000))}, function (response, status, xhr) {
if ( status == "error" ) {
notifyMsg("danger", "Account settings", "Server did not reply correctly.", "bi bi-journal-x");
} else {
$(".account .revealPassword").on("click", revealPassword);
$(".account .inputLogin, .account .inputPassword").on("input", checkPassword);
$(".account .inputPassword1, .account .inputPassword2").on("input", checkChangePassword);
$(".account .accountButton .buy.changePassword").on("click", checkPasswordToChange);
$(".account .accountButton .buy.deleteAccount").on("click", checkDeleteAccount);
$(".account .btn.cancel").on("click", accountRedrawMenu);
}
});
}
function checkChangePassword(event) {
var $this = $(this);
var password1 = $(".account .inputPassword1").val().trim();
var password2 = $(".account .inputPassword2").val().trim();
var checkPassword1 = password1.trim().length >7;
var checkPassword2 = password2.trim().length >7;
var checkPasswords = (password1 == password2);
var rule8Cars = new RegExp(".{8,}");
var ruleNoSpace = new RegExp("[\s]+");
var ruleCapital = new RegExp(".*[A-Z]");
var ruleNumber = new RegExp(".*[0-9]");
var checkRule8Cars = (checkPassword1) && (checkPassword2);
var checkRuleNoSpace = !((password1.indexOf(' ') >= 0) || (password2.indexOf(' ') >= 0)) && (password1.length >1) && (password2.length >1);
var checkRuleCapital = (ruleCapital.test(password1)) && (ruleCapital.test(password2));
var checkRuleNumber = (ruleNumber.test(password1)) && (ruleNumber.test(password2));
if (checkPassword1 && checkPassword2 && checkPasswords && checkRule8Cars && checkRuleNoSpace && checkRuleCapital && checkRuleNumber) {
$(".account .accountButton .buy").addClass("btn-primary ready").removeClass("btn-info notAllowed");
} else {
$(".account .accountButton .buy").addClass("btn-info notAllowed").removeClass("btn-primary ready");
if (($this.hasClass("inputPassword1")) || ($this.hasClass("inputPassword2"))) {
$(".account .input-group.password1, .account .inputPassword1, .account .inputPassword1 + label").removeClass("is-invalid is-valid");
$(".account .input-group.password2, .account .inputPassword2, .account .inputPassword2 + label").removeClass("is-invalid is-valid");
}
}
if (checkRule8Cars) {
$(".account .pwdRule.8cars").addClass("ok").removeClass("ko");
} else {
$(".account .pwdRule.8cars").addClass("ko").removeClass("ok");
}
if (checkRuleNoSpace) {
$(".account .pwdRule.noSpace").addClass("ok").removeClass("ko");
} else {
$(".account .pwdRule.noSpace").addClass("ko").removeClass("ok");
}
if (checkRuleCapital) {
$(".account .pwdRule.capital").addClass("ok").removeClass("ko");
} else {
$(".account .pwdRule.capital").addClass("ko").removeClass("ok");
}
if (checkRuleNumber) {
$(".account .pwdRule.number").addClass("ok").removeClass("ko");
} else {
$(".account .pwdRule.number").addClass("ko").removeClass("ok");
}
}
function checkPasswordToChange(event) {
var $this = $(this);
$(".account .input-group.password1, .account .inputPassword1, .account .inputPassword1 + label").removeClass("is-invalid is-valid");
$(".account .input-group.password2, .account .inputPassword2, .account .inputPassword2 + label").removeClass("is-invalid is-valid");
if ($this.hasClass("ready")) {
changePassword(true).fail(function () {
$(".account .inputPassword, .account .inputPassword1, .account .inputPassword2").val("");
notifyMsg("danger", "Password change", "Error during account creation.", "bi bi-journal-x");
}).done(function (obj) {
$(".account .inputPassword, .account .inputPassword1, .account .inputPassword2").val("");
accountRedrawMenu();
});
} else {
var password1 = $(".account .inputPassword1").val().trim();
var password2 = $(".account .inputPassword2").val().trim();
var checkPassword1 = password1.length >7;
var checkPassword2 = password2.trim().length >7;
var checkPasswords = (password1 == password2);
if (!checkPassword1 || !checkPasswords) {
$(".account .input-group.password1, .account .inputPassword1, .account .inputPassword1 + label").addClass("is-invalid");
} else {
$(".account .input-group.password1, .account .inputPassword1, .account .inputPassword1 + label").addClass("is-valid");
}
if (!checkPassword2 || !checkPasswords) {
$(".account .input-group.password2, .account .inputPassword2, .account .inputPassword2 + label").addClass("is-invalid");
} else {
$(".account .input-group.password2, .account .inputPassword2, .account .inputPassword2 + label").addClass("is-valid");
}
}
}
function changePassword(pToBeDeffered) {
if ((typeof pToBeDeffered === "boolean") && (pToBeDeffered)) {
var deferredObj = $.Deferred();
}
$.ajax({
type: "POST",
url: "_account.php",
data: "p=" + B64.encode("changePassword/§/"+ $(".account .inputPassword1").val().trim() + "/§/"+ Math.floor(Date.now() / 1000)),
cache: false,
success: function(data) {
try {
var obj = JSON.parse(data);
}
catch(err) {
notifyMsg("danger", "Change password", "Server did not reply correctly.", "bi bi-journal-x");
if (deferredObj) {
deferredObj.reject(false);
} else {
return false;
}
}
if (obj.error != 0) {
notifyMsg("danger", "Change password ("+ obj.error +")", ""+ obj.shMsg +"
"+ obj.lngMsg +"", "bi bi-journal-x");
if (deferredObj) {
deferredObj.reject(obj);
} else {
return false;
}
} else {
$(".offcanvas-toggle-account").removeClass("empty");
if (deferredObj) {
deferredObj.resolve(obj);
} else {
return true;
}
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
notifyMsg("danger", "Internet (AJAX : "+ XMLHttpRequest.status +")", errorThrown, "bi bi-journal-x");
if (deferredObj) {
deferredObj.reject(false);
} else {
return false;
}
}
});
if (deferredObj) {
return deferredObj.promise();
}
}
function checkDeleteAccount(event) {
swal({
title: "Are you sure ?",
type: "error",
showCancelButton: true,
confirmButtonClass: "btn-danger icon-person-x",
confirmButtonText: "Remove",
cancelButtonClass: "btn-outline-primary icon-x-square-fill",
cancelButtonText: "Cancel",
closeOnConfirm: true,
closeOnCancel: true,
closeOnClickOutside: false,
closeOnEsc: false
},
function(isConfirm) {
if (isConfirm) {
$.ajax({
type: "POST",
url: "_account.php",
data: "p=" + B64.encode("deleteAccount/§/"+ Math.floor(Date.now() / 1000)),
cache: false,
success: function(data) {
try {
var obj = JSON.parse(data);
}
catch(err) {
notifyMsg("danger", "Delete account", "Server did not reply correctly.", "bi bi-journal-x");
return false;
}
if (obj.error != 0) {
notifyMsg("danger", "Delete account ("+ obj.error +")", ""+ obj.shMsg +"
"+ obj.lngMsg +"", "bi bi-journal-x");
return false;
} else {
$(".offcanvas-toggle-account").addClass("empty");
accountId = null;
$(".offcanvas-account").offcanvas("hide");
return true;
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
notifyMsg("danger", "Internet (AJAX : "+ XMLHttpRequest.status +")", errorThrown, "bi bi-journal-x");
if (deferredObj) {
deferredObj.reject(false);
} else {
return false;
}
}
});
}
});
}
// === ===
function nullFunction() { }