function isValidIMEI(imei)
{
if (!/^[0-9]{15}$/.test(imei))
{
return false;
}
var sum = 0, factor = 2, checkDigit, multipliedDigit;
for (var i = 13, li = 0; i >= li; i--)
{
multipliedDigit = parseInt(imei.charAt(i), 10) * factor;
sum += (multipliedDigit >= 10 ? ((multipliedDigit % 10) + 1) : multipliedDigit);
(factor === 1 ? factor++ : factor--);
}
checkDigit = ((10 - (sum % 10)) % 10);
return !(checkDigit !== parseInt(imei.charAt(14), 10));
}
function changePerPage(pager_items_count)
{
$.post
(
"/common_form_js.php",
{
"todo" : "changePerPage",
"pager_items_count" : pager_items_count,
}
);
}
function loadSocietyForm(st_id, mode)
{
$("body").append("
");
$.ajax({
method: 'POST',
url: 'index.php',
data: {
"todo" : "loadSocietyForm",
"st_id": st_id,
"mode" : mode
}
})
.done(function( data ) {
$("#_st_form").html(data)
.dialog(
{
title : "Manage account",
width : 800,
height : 760,
closeOnEscape: false,
});
$(".ui-dialog-titlebar-close").hide();
var initialCountry = document.getElementById("st_country").value;
set_telephone_area_code('st_telephone_indicator',initialCountry);
});
};
function loadSocietyFormNew(st_id, mode)
{
$.ajax({
method: 'POST',
url: 'society.php',
data: {
"todo" : "loadSocietyFormNew",
"st_id": st_id
}
})
.done(function( msg ) {
try {
$("body").append(""+msg+"
");
$("#_st_form").dialog(
{
title : "Gestion de compte 2",
width : 800,
height : 760,
dialogClass: "dlgfixed"
,buttons: {
/*
btnValid: {
text: 'Save',
click : function (){
//saveSiteComment(s_id);
}
},
*/
Close: {
text: 'Close',
click : function (){
$("#_st_form").remove();
}
}
}
});
$(".dlgfixed").center(true);
//$("div[aria-describedby=_st_form]").css("z-index",10001);
}
catch(e) {
$.popMessage("Error occurs! Result of ajax: " + msg + '\n' +e);
}
});
};
function isValidSiret(siret)
{
// return true;
if ((siret.length != 14) || (isNaN(siret)))
{
return false;
}
var somme = 0;
var tmp;
for (var cpt = 0; cpt < siret.length; cpt++)
{
if ((cpt % 2) == 0)
{
// Les positions impaires : 1er, 3è, 5è, etc...
tmp = siret.charAt(cpt) * 2; // On le multiplie par 2
if (tmp > 9)
{
tmp -= 9; // Si le résultat est supérieur à 9, on lui soustrait 9
}
}
else
{
tmp = siret.charAt(cpt);
somme += parseInt(tmp);
}
}
return ((somme % 10) == 0);
};
function saveSociety(st_id, mode)
{
reg_siret=/[0-9]{14}/;
reg_imei=/[0-9]{15}/;
reg_postcode=/[0-9]{4,5}/;
if($("#st_name").val()=='')
{
return $.popMessage("Complete all mandatory fields", true);
}
if($("#st_domain").val()==0)
{
return $.popMessage("Complete all mandatory fields", true);
}
/*if(($("#st_reference").val()!='') && !isValidSiret($("#st_reference").val()))
{
return $.popMessage("Co.Reg N° is incorrect", true);
}*/
if($("#st_address1").val()=='')
{
return $.popMessage("Complete all mandatory fields", true);
}
if($("#st_postcode").val()=='')
{
return $.popMessage("Postcode incorrect", true);
}
if($("#st_city").val()=='')
{
return $.popMessage("Complete all mandatory fields", true);
}
if($("#st_telephone").val()=='')
{
return $.popMessage("Telephone number is incorrect", true);
}
if($("#st_mobile").val()=='')
{
return $.popMessage("Mobile number incorrect", true);
}
if(!reg_email.test($("#st_email").val()))
{
return $.popMessage("Email is incorrect", true);
}
/*if($("#st_fax").val() && !reg_telephone.test($("#st_fax").val()))
{
return $.popMessage("Fax number is incorrect", true);
}*/
/*
// Vân-Anh CURTY : 21/05/19 17:03 //
if(mode==0)
{
if(!isValidIMEI($("#st_imei").val()))
{
return $.popMessage("Product ID non compliant", true);
}
}
*/
if($("#_form_login input[id='l_lastname']").val()=='' || $("#_form_login input[id='l_firstname']").val()=='')
{
return $.popMessage("Complete all mandatory fields", true);
}
if(!reg_email.test($("#_form_login input[id='l_email']").val()))
{
return $.popMessage("Email is incorrect", true);
}
if($("#_form_login input[id='l_password']").val()==''){
return $.popMessage("Complete all mandatory fields", true);
}
if($("#_form_login input[id='l_password']").val() != $("#_form_login input[id='l_confirm']").val())
{
return $.popMessage("Please confirm password", true);
}
$.ajax({
method: 'POST',
url: 'index.php',
data: {
"todo" : (st_id ? "modifySociety" : "addSociety"),
"st_id" : st_id,
"st_imei" : $("#st_imei").val(),
"society" : $("#_form_society").getFormDatas(),
"login" : $("#_form_login").getFormDatas(),
"mode" : mode,
}
})
.done(function( msg ) {
try {
var result = JSON.parse(msg);
if(st_id==0)
{
if(result.Error==0)
{
$("#_st_form").remove();
if(mode<2)
{
$.popMessage("Your account is set-up", false);
}
if(mode==2)
{
loadClientsList();
}
}
if(result.Error==1)
{
$.popMessage("IMEI entered is not in our database", true);
}
else if(result.Error==2)
{
$.popMessage("Incorrect telephone number format ");
}
/*
* VAC_11/01/2018 : vérification du email de client lors qu'on crée un nouveau client
* Mantis n° 863
*/
else if(result.Error==3)
{
$.popMessage("Email already exists, choose another ! ");
}
}
else
{
if(result.Error==0)
{
$("#_st_form").remove();
}
else if(result.Error==2)
{
$.popMessage("Incorrect telephone number format ");
}
}
}
catch(e) {
$.popMessage("Error occurs! Result of ajax: " + msg + '\n' +e);
}
});
}
function legalNotices()
{
/*
$delete.post
(
"index.php",
{
"todo" : "legalNotices",
},
function(data)
{
$("body").append(""+data+"
");
$("#_form_legal_notices").dialog(
{
title : "Legalities",
width : 720,
height :800,
});
}
);
*/
$.ajax({
method: 'POST',
url: 'index.php',
data: {
"todo" : "legalNotices",
}
})
.done(function( data ) {
$("body").append(""+data+"
");
$("#_form_legal_notices").dialog(
{
title : "Legalities",
width : 720,
height :800,
});
});
}
function AboutBatiConnect()
{
/*
$delete.post
(
"index.php",
{
"todo" : "AboutBatiConnect",
},
function(data)
{
$("body").append(""+data+"
");
$("#_form_about").dialog(
{
title : "About",
width : 640,
height :480,
});
}
);
*/
$.ajax({
method: 'POST',
url: 'index.php',
data: {
"todo" : "AboutBatiConnect",
}
})
.done(function( data ) {
$("body").append(""+data+"
");
$("#_form_about").dialog(
{
title : "About",
width : 640,
height :480,
});
});
}
function popCondition()
{
$("#_condition_message").dialog({
modal:true,
width:800,
height:600,
close: function( event, ui ) {$(this).dialog('destroy');}
}).loadData("condition_utilisation.php",{});
}
function loadPortaclefComboForm(d_type)
{
/*
$delete.post
(
"portaclef.php",
{
"todo" : "loadPortaclefComboForm",
"d_type" : d_type
},
function(data)
{
$("body").append(""+data+"
");
$("#_form_pf_combo").dialog(
{
title : "Configuration of combo",
width : 400,
height :280,
});
}
);
*/
$.ajax({
method: 'POST',
url: 'portaclef.php',
data: {
"todo" : "loadPortaclefComboForm",
"d_type" : d_type
}
})
.done(function( data ) {
$("body").append(""+data+"
");
$("#_form_pf_combo").dialog(
{
title : "Configuration of combo",
width : 400,
height :280,
});
});
}
function changeLanguage(language, is_index)
{
/*
$delete.post
(
"index.php",
{
"todo" : "changeLanguage",
"l_language" : language
},
function(json)
{
var result=JSON.parse(json);
if(result.Error==0)
{
if(typeof(is_index)=="undefined")
{
window.location="index.php";
}
else
{
$("body").loadData("society.php");
loadSocietyInformation(1);
}
}
}
);
*/
$.ajax({
method: 'POST',
url: 'index.php',
data: {
"todo" : "changeLanguage",
"l_language" : language
}
})
.done(function( msg ) {
try {
var result = JSON.parse(msg);
if(result.Error==0)
{
if(typeof(is_index)=="undefined")
{
//alert("common_form_js.php+> CAS 1");
window.location="index.php";
}
else
{
//alert("common_form_js.php+> CAS 2");
window.location="society.php";
/*
$("body").loadData("society.php");
loadSocietyInformation(1);
*/
}
}
}
catch(e) {
$.popMessage("Error occurs! Result of ajax: " + msg + '\n' +e);
}
});
}
function changeLanguagePartenaire(language, is_index)
{
/*
$delete.post
(
"partenaire.php",
{
"todo" : "changeLanguagePartenaire",
"l_language" : language
},
function(json)
{
var result=JSON.parse(json);
if(result.Error==0)
{
window.location="partenaire.php";
}
}
);
*/
$.ajax({
method: 'POST',
url: 'partenaire.php',
data: {
"todo" : "changeLanguagePartenaire",
"l_language" : language
}
})
.done(function( msg ) {
try {
var result = JSON.parse(msg);
if(result.Error==0) {
window.location="partenaire.php";
}
}
catch(e) {
$.popMessage("Error occurs! Result of ajax: " + msg + '\n' +e);
}
});
}
function set_country_code(country_code_id, country_id)
{
var country_codes={
"0":"BE","1":"FR","2":"GB","3":"CH","4":"DE","5":"ES","6":"GP","7":"GF","8":"IE","9":"IT","10":"LU","11":"MQ","12":"NL","13":"PT","14":"RE","15":"AT","16":"MC","17":"IL","-1":"", };
document.getElementById(country_code_id).innerHTML = country_codes[country_id];
}
function getCountryId(country_code)
{
var country_ids={
"BE":0,"FR":1,"GB":2,"CH":3,"DE":4,"ES":5,"GP":6,"GF":7,"IE":8,"IT":9,"LU":10,"MQ":11,"NL":12,"PT":13,"RE":14,"AT":15,"MC":16,"IL":17,"":-1, };
return country_ids[country_code];
}
function set_telephone_area_code(area_code_id,country_id)
{
var countries_area_code={
"1":"0033","4":"0049","0":"0032","5":"0034","6":"00590","7":"00594","8":"00353","9":"0039","10":"00352","11":"00596","12":"0031","13":"00351","14":"00262","2":"0044","3":"0041","-1":"00", };
var country_area_code = "00";
if(countries_area_code[country_id] !== undefined){
country_area_code = countries_area_code[country_id];
}
document.getElementById(area_code_id).innerHTML = country_area_code;
}
function set_telephone_area_code_service(area_code_id,country_id)
{
var countries_area_code={
"1":"0033","4":"0049","0":"0032","5":"0034","6":"00590","7":"00594","8":"00353","9":"0039","10":"00352","11":"00596","12":"0031","13":"00351","14":"00262","2":"0044","3":"0041","15":"0043","16":"00377","17":"00972","-1":"00", };
var country_area_code = "00";
if(countries_area_code[country_id] !== undefined){
country_area_code = countries_area_code[country_id];
}
document.getElementById(area_code_id).innerHTML = country_area_code;
}
// Détermine le code pays à partir de l'objet javascript navigator.language
function getNavigatorCountryCode() {
// Le code de langue est de la forme "fr-FR" où la partie après le "-" représente le pays
country_code = navigator.language.substring(3,5);
// Le code de langue peut aussi être de la forme "fr", avec juste la langue mais pas le pays. Dans ce cas, on prend les 2 premiers caractères, donc la langue (c'est mieux que rien).
if(country_code.length === 0) {
country_code = navigator.language.substring(0,3);
}
return country_code;
}
// Vân-Anh CURTY : 19/02/20 15:18 //
function showFormSAVBC(type_device,id_device) {
// type_device : 11 : PP4G, 8; NPH400, 6: PORTAPHONE, 1 : MODEM
var isNoralsy = 0;
$("body").append("");
if (isNoralsy==1) {
$("#_form_sav_bc").dialog(
{
title : "Information about Product in SAV",
width : 400,
height : 250,
dialogClass: 'dlgfixed',
position: "center",
beforeClose : function(event, ui)
{
clearInterval(uf_d_t);
}
,buttons: {
btnValid: {
text: 'Save',
click : function (){
saveSAVBC(type_device,id_device);
}
},
Close: {
text: 'Cancel',
click : function (){
$(this).dialog("close");
}
}
}
}).loadData(
"site.php",
{
"todo" : "showFormSAVBC",
"type_device" : type_device,
"id_device" : id_device
});
}
else {
$("#_form_sav_bc").dialog(
{
title : "Information about Product in SAV",
width : 400,
height : 250,
dialogClass: 'dlgfixed',
position: "center",
beforeClose : function(event, ui)
{
clearInterval(uf_d_t);
}
,buttons: {
Close: {
text: 'Cancel',
click : function (){
$(this).dialog("close");
}
}
}
}).loadData(
"site.php",
{
"todo" : "showFormSAVBC",
"type_device" : type_device,
"id_device" : id_device
});
}
$(".dlgfixed").center(true);
} // end of function showFormSAVBC
// Vân-Anh CURTY : 19/02/20 15:48 //
function saveSAVBC(type_device,id_device) {
// type_device : 11 : PP4G, 8; NPH400, 6: PORTAPHONE, 1 : MODEM
$.ajax({
method: "POST",
url: "site.php",
data: {
"todo": "saveSAVBC"
,"datas" : $("div#_form_sav_bc").getFormDatas()
},
async : false
})
.done(function( msg ) {
var result = JSON.parse(msg);
if (result.Error==1) { // identifiant existe pas dans la table octal_new
return $.popMessage("Product ID is incorrect",true);
}
else if (result.Error==2) { // identifiant déjà déclaré dans un autre client
return $.popMessage("Product ID entered is incorrect or already used, please check.
Please contact your system provider",true);
}
else if (result.Error==3) { // identifiant sim n'existe pas dans la bd BC
return $.popMessage("SIM card number not valid",true);
}
else {
$("#_form_sav_bc").dialog("close");
var s_id = result.s_id;
loadSiteInformation(s_id);
loadDevicesList_s(1,s_id);
if (type_device==11) { // PP4G
loadPP4GFormNew(id_device,0,0);
}
if (type_device==12) { // 4GMini Touch
load4GTouchFormNew(id_device,0);
}
else if (type_device==8) { // NPH400
loadNPH400FormNew(id_device,0,'',0);
}
else if (type_device==6) { // PORTAPHONE
loadPortaphoneFormNew(id_device,0,0);
}
else if (type_device==1) { // MODEM
var m_sub_type = result.m_sub_type;
loadModemFormNew(id_device, m_sub_type,0);
}
else {
}
}
});
}
// Vân-Anh CURTY 15/11/2021 14:11
function saveAccountSociety(st_id) {
alert("call saveAccountSociety");
reg_siret=/[0-9]{14}/;
reg_imei=/[0-9]{15}/;
reg_postcode=/[0-9]{4,5}/;
if($("#st_name").val()=='')
{
return $.popMessage("Complete all mandatory fields", true);
}
if($("#st_domain").val()==0)
{
return $.popMessage("Complete all mandatory fields", true);
}
if($("#st_address1").val()=='')
{
return $.popMessage("Complete all mandatory fields", true);
}
if($("#st_postcode").val()=='')
{
return $.popMessage("Postcode incorrect", true);
}
if($("#st_city").val()=='')
{
return $.popMessage("Complete all mandatory fields", true);
}
if($("#st_telephone").val()=='')
{
return $.popMessage("Telephone number is incorrect", true);
}
if($("#st_mobile").val()=='')
{
return $.popMessage("Mobile number incorrect", true);
}
if(!reg_email.test($("#st_email").val()))
{
return $.popMessage("Email is incorrect", true);
}
$.ajax({
method: 'POST',
url: 'society.php',
data: {
"todo" : "saveAccountSociety",
"st_id" : st_id,
"society" : $("#_form_society").getFormDatas()
}
})
.done(function( msg ) {
try {
var result = JSON.parse(msg);
if(result.Error==0) {
$.popMessage("Les données de l\'onglet Société ont bien été modifié", false);
}
else if(result.Error==1){
$.popMessage("Incorrect telephone number format ");
}
}
catch(e) {
$.popMessage("Error occurs! Result of ajax: " + msg + '\n' +e);
}
});
} // end of saveAccountSociety
// Vân-Anh CURTY 15/11/2021 14:11
function saveAccountUser(l_id) {
if($("#_form_login input[id='l_lastname']").val()=='' || $("#_form_login input[id='l_firstname']").val()=='')
{
return $.popMessage("Complete all mandatory fields", true);
}
if(!reg_email.test($("#_form_login input[id='l_email']").val()))
{
return $.popMessage("Email is incorrect", true);
}
if($("#_form_login input[id='l_password']").val()==''){
return $.popMessage("Complete all mandatory fields", true);
}
if($("#_form_login input[id='l_password']").val() != $("#_form_login input[id='l_confirm']").val())
{
return $.popMessage("Please confirm password", true);
}
$.ajax({
method: 'POST',
url: 'society.php',
data: {
"todo" : "saveAccountUser",
"l_id" : l_id,
"login" : $("#_form_login").getFormDatas()
}
})
.done(function( msg ) {
try {
var result = JSON.parse(msg);
if(result.Error==0) {
$.popMessage("Les données de l\'onglet Utilisateur ont bien été modifié", false);
}
else if(result.Error==1){
$.popMessage("Email already exists, choose another ! ");
}
}
catch(e) {
$.popMessage("Error occurs! Result of ajax: " + msg + '\n' +e);
}
});
}