var expiry_message = "Session expired or data lost, you will be redirected to home page !";
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 : "Manage account",
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("Product ID entered is not in our database", true);
}
else if(result.Error==2)
{
$.popMessage("Incorrect telephone number format ");
}
else if(result.Error==3)
{
$.popMessage("The country code could not be found in our database ");
}
/*
* 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==4)
{
$.popMessage("Email already exists, choose another ! ");
}
}
else
{
if(result.Error==0)
{
$("#_st_form").remove();
}
else if(result.Error==2)
{
$.popMessage("Incorrect telephone number format ");
}
else if(result.Error==3)
{
$.popMessage("Country code not found ");
}
else if(result.Error==4)
{
$.popMessage("Email already exists ");
}
}
}
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)
{
$.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";
}
}
}
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","18":"YT","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,"YT":18,"NL":12,"PT":13,"RE":14,"AT":15,"MC":16,"IL":17,"":-1, };
return country_ids[country_code];
}
function set_telephone_area_code_old(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","18":"00262","12":"0031","13":"00351","14":"00262","2":"0044","3":"0041","-1":"00","15":"0043","16":"00377","17":"00972","19":"00359","20":"00357","21":"00385","22":"0045","23":"00372","24":"00358","25":"0030","26":"0036","27":"00371","28":"00370","29":"00356","30":"0048","31":"00420","32":"0040","33":"00421","34":"00386","35":"0046", };
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;
} // end of set_telephone_area_code_old
function set_telephone_area_code(area_code_id,country_id)
{
$.ajax({
method: "POST",
url: "index.php",
data: { "todo": "getCountryTelIndicatif"
,"country_id" : country_id
},
async : true
})
.done(function( msg ) {
document.getElementById(area_code_id).innerHTML = msg;
});
} // end of set_telephone_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("Company tab data has been modified", false);
}
else if(result.Error == 1){
$.popMessage("Incorrect telephone number format ");
}
else if(result.Error == 2){
$.popMessage("Country code not found ");
}
}
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("User tab data has been modified", false);
}
else if(result.Error==1){
$.popMessage("Email already exists, choose another ! ");
}
}
catch(e) {
$.popMessage("Error occurs! Result of ajax: " + msg + '\n' +e);
}
});
}
function showTabBadgeDigitalPeriph(typeP,idP){
//alert("showTabBadgeDigital");
$.ajax({
method: 'POST',
url: 'centrale.php',
data: {
'todo': 'showTabBadgeDigitalPeriph'
,'typeP' : typeP
,'idP' : idP
},
async : true
})
.done(function( msg ) {
$('div#tabs-badgeDigital').html(msg);
});
}
function showPopupAddPeriph(s_id,type_device,id_product){
if (type_device==1) {
var title = "Devices connected to modem";
}
else if (type_device==6) {
var title = "Devices connected to 3G product (not UK)";
}
else {
var title ="Devices connected to IPGUARD 4G";
}
$("body").append("");
var btnOui = 0;
$("#_form_addperiph").dialog(
{
title : title,
width : 500,
height : 350,
dialogClass: 'dlgfixed',
position: "center",
beforeClose : function(event, ui)
{
clearInterval(uf_d_t);
}
,buttons: {
btnValid: {
text: 'Yes',
click : function (){
var val_cl = $('#periph_cl').val();
var val_hf = $('#periph_hf').val();
var val_pc = $('#periph_pc').val();
var val_pf = $('#periph_pf').val();
if (val_cl > 10
|| val_hf > 10
|| val_pc > 10
|| val_pf > 10
) {
return $.popMessage("The quantity of devices must be less than 10", true);
}
if ($('#n4_nonerelaicentrale').length > 0) {
if ($('#n4_nonerelaicentrale').is(':checked')) var n4_nonerelaicentrale = 0;
else var n4_nonerelaicentrale = 1;
} else var n4_nonerelaicentrale = 1;
saveAddPeriph(type_device,id_product,val_cl,val_hf,val_pc,val_pf,s_id,n4_nonerelaicentrale);
btnOui = 1;
$("#_form_addperiph").dialog("close");
}
},
Close: {
text: 'No',
click : function (){
$("#_form_addperiph").dialog("close");
}
}
}
,close: function() {
if (btnOui==0) {
if (type_device==11 || type_device==12) {
// on doit supprimer le centrale 1 qui est créé par défault
deleteCentraleFromPP4G(s_id,type_device,id_product);
loadDevicesList_s(1,s_id);
}
else {
//loadSiteInformation(s_id);
loadDevicesList_s(1,s_id);
}
}
}
}).loadData(
"modem.php",
{
"todo" : "showPopupAddPeriph",
"type_device": type_device,
"id_product" : id_product
});
$(".dlgfixed").center(true);
$("div[aria-describedby=_form_confirm_del]").css("z-index",20000);
} // end of showPopupAddPeriph
function deleteCentraleFromPP4G(s_id,type_device,id_product) {
$.ajax({
method: 'POST',
url: 'nph400.php',
data: {
'todo': 'deleteCentraleFromPP4G'
,'id_product' : id_product
},
async : true
})
.done(function( msg ) {
var result = JSON.parse(msg);
var isEmptyIdentifiant = result.isEmptyIdentifiant;
if (parseInt(isEmptyIdentifiant)==0) {
// on ouvre le formulaire si l'identifiant est bien saisit
switch(type_device) {
case 8 :
loadNPH400FormNew(id_product,0,'',0,0);
break;
case 11:
loadPP4GFormNew(id_product,0,0,0);
break;
case 12:
load4GTouchFormNew(id_product,0,0);
break;
} // end switch
}
//loadSiteInformation(s_id);
loadDevicesList_s(1,s_id);
});
}
function saveAddPeriph(type_device,id_product,val_cl,val_hf,val_pc,val_pf,s_id,n4_nonerelaicentrale) {
$.ajax({
method: 'POST',
url: 'nph400.php',
data: {
'todo': 'saveAddPeriph'
,'type_device' : type_device
,'id_product' : id_product
,"nb_cl" : val_cl
,"nb_hf" : val_hf
,"nb_pc" : val_pc
,"nb_pf" : val_pf
,"n4_nonerelaicentrale":n4_nonerelaicentrale
},
async : true
})
.done(function( msg ) {
$("#_form_addperiph").dialog("close");
$("#_form_addperiph").remove();
var result = JSON.parse(msg);
var isEmptyIdentifiant = result.isEmptyIdentifiant;
if (parseInt(isEmptyIdentifiant)==0) {
// on ouvre le formulaire si l'identifiant est bien saisit
switch(type_device) {
case 8 :
loadNPH400FormNew(id_product,0,'',0,0);
break;
case 11:
loadPP4GFormNew(id_product,0,0,0);
break;
case 12:
load4GTouchFormNew(id_product,0,0);
break;
} // end switch
}
//loadSiteInformation(s_id);
loadDevicesList_s(1,s_id);
return $.popMessage("Addition of devices successful");
});
} // end of saveAddPeriph
/**
* Vân-Anh CURTY 04/07/2022 11:00
* @param {int} type_device
* @param {string} $serial_number
*/
function showListContractSiteForm4G(type_device,serial_number,ct_ref,d_id) {
if (ct_ref===undefined) ct_ref ='';
if (d_id===undefined) d_id =0;
$.ajax({
method: "POST",
url: "pp4g.php",
data: { "todo": "showListContractSiteForm4G"
,"type_device": type_device
,"serial_number" : serial_number
,"ct_ref" : ct_ref
,"d_id" : d_id
},
async : false
})
.done(function( msg ) {
//var result = JSON.parse(msg);
var label = "Contract associated (*) : ";
$("#showLabelContrat").html(label);
$("#showZoneSelectContrat").html(msg);
});
} // end of showListContractSiteForm4G
function checkIdentifiant4GForAddNewDevice(device_type,device_identifiant) {
// 0: 4Gmini, 1: 4G%ini Touch; 2: 4G Pro; 3: ANDY4G
return $.ajax({
method: "POST",
url: "nph400.php",
data: { "todo": "checkIdentifiant4GForAddNewDevice"
,"device_type": device_type
,"device_identifiant" : device_identifiant
},
async : true
})
.done(function( json ) {
// 0 : inexistant, 1: déjà déclaré; 2 : dispo pour ajouter
var result = JSON.parse(json);
if (!device_type && typeof result.device_type !== undefined){
device_type = result.device_type;
$('#device_type').val(device_type);
}
$('#divInfoPlusIdentifiant_2').html('');
if (result.Error==0) { //existant
var msg = "Product ID does not exist";
$('#divInfoPlusIdentifiant_2').html(msg);
$('#device_hasError').val(1);
$('#showLabelContrat').html('');
$('#showZoneSelectContrat').html('');
$('#show4GModel').empty();
}
else if (result.Error==1) { //déjà déclaré
var msg = "Product ID entered is already used on this site";
$('#divInfoPlusIdentifiant_2').html(msg);
$('#device_hasError').val(1);
$('#showLabelContrat').html('');
$('#showZoneSelectContrat').html('');
$('#show4GModel').empty();
}
else if (result.Error==2) { // pas dans le même type sélectionné
var msg = "Product ID relates to a different product type than that selected";
$('#divInfoPlusIdentifiant_2').html(msg);
$('#device_hasError').val(1);
$('#showLabelContrat').html('');
$('#showZoneSelectContrat').html('');
$('#show4GModel').empty();
}
else if (result.Error==4) { // pas dans le même type sélectionné dans 4G mais on ne bloque pas de la déclaration
var msg = "Product ID relates to a different product type than that selected";
$('#divInfoPlusIdentifiant_2').html(msg);
$('#device_hasError').val(0);
$('#showLabelContrat').html('');
$('#showZoneSelectContrat').html('');
var serial_number = result.serial_number;
var typeProduit = 8;
if (device_type==0 || device_type==1 || device_type==2) {
if (device_type==1) typeProduit = 11;
}
showListContractSiteForm4G(typeProduit,serial_number);
}
else { // 3 : c dispo pour ajouter
var serial_number = result.serial_number;
//var msg = "Product ID is correct";
//$('#tdDivInfoPlusIdentifiant_2').css({'color':'#0099FF'});
//$('#divInfoPlusIdentifiant_2').html(msg);
$('#device_hasError').val(0);
var typeProduit = 8;
if (device_type==0 || device_type==1 || device_type==2) {
if (device_type==1) {
typeProduit = 11;
}
}
else {
typeProduit = 5;
}
showListContractSiteForm4G(typeProduit,serial_number);
}
return result;
});
} // end of checkIdentifiant4GForAddNewDevice
/*
function checkCentraleExists(serial_number) {
return $.ajax({
method: "GET",
url: "api/v1/cacSettings",
data: {
"serial_number" : serial_number,
},
dataType : 'json',
headers: {'X-CSRF-TOKEN': 'b8c5n0aj1UmXma3r8zCRj7R18WTSu2WnjqYxWk7A'},
async : true
})
.done(function( json ) {
var result = JSON.parse(json);
return result;
});
} */
// 0 if ok, 1 or other positive int for error :
function checkFormatSerial(serial_number) {
if (
serial_number.length > 15 && // Too long
serial_number.substring(0,3).toUpperCase()!='NOR' &&
serial_number.substring(0,3).toUpperCase()!='TBE' &&
serial_number.indexOf(':') == -1) {
return 1;
} else {
if (
serial_number.length == 15 || // XXXX-XXXXXXXXX format
(serial_number.substring(0,3).toUpperCase()=='NOR' && serial_number.length == 13) || // NOR-XX... format
(serial_number.substring(0,3).toUpperCase()=='TBE' && serial_number.length == 18) || // TBS-XX... format
serial_number.indexOf(':') != -1) { // MAC adress format
return 0;
} else {
if (serial_number != '') {
return 1;
}
}
}
return 0;
}
function checkIdentifiantCacForAddNewDevice(device_type, device_identifiant, success_cb, failure_cbk) {
return $.ajax({
method: "GET",
url: "api/v1/octal",
data: {
"item_serial" : device_identifiant,
"item_type" : device_type
},
dataType : 'json',
headers: {'X-CSRF-TOKEN': 'b8c5n0aj1UmXma3r8zCRj7R18WTSu2WnjqYxWk7A'},
async : true
})
.done(function( result ) {
// 0 : inexistant, 1: déjà déclaré; 2 : dispo pour ajouter
if (device_type==11) {
// We check if centrale already exists, which would be very wrong
if (result?.cac_setting?.cs_id) {
if (failure_cbk) failure_cbk("Identifiant déjà déclaré");
return;
}
}
if (success_cb) success_cb(result);
})
.fail(function(e){
//handle errors
//console.log(e);
if (failure_cbk) failure_cbk("Identifiant non valide");
});
} // end of checkIdentifiantCacForAddNewDevice
function callAddNewContractFromDevices(s_id,type_device,serial_number) {
$.ajax({
method: 'POST',
url: 'site.php',
data: {
"todo" : "loadAddContractSiteForm",
"s_id": s_id
}
})
.done(function( msg ) {
try {
$("body").append("");
$("#_form_t").dialog(
{
title : "Add a contract to site",
width : 420,
height : 200,
dialogClass: "dlgfixed"
,buttons: {
btnValid: {
text: 'Save',
click : function (){
saveContractSiteFromDevices(s_id,type_device,serial_number);
}
},
Close: {
text: 'Cancel',
click : function (){
$("#_form_t").remove();
}
}
}
});
$(".dlgfixed").center(true);
$("div[aria-describedby=_form_t]").css("z-index",10001);
}
catch(e) {
$.popMessage("Error occurs! Result of ajax: " + msg + '\n' +e);
}
});
} // end of callAddNewContractFromDevices
function saveContractSiteFromDevices(s_id,type_device,serial_number) {
var ct_ref = $("#ct_refAdd").val();
if (ct_ref=='') {
$("#ct_ref").css("border","1px solid #f70421");
return $.popMessage("Enter the contract number",true);
}
$("#ct_ref").css("border","1px solid #CCC");
$.ajax({
method: 'POST',
url: 'site.php',
data: {
"todo" : "saveContractSite",
"s_id": s_id,
"ct_ref": ct_ref
}
})
.done(function( msg ) {
try{
var result = JSON.parse(msg);
/*
if(result.Error==0) {
$("#_form_t").remove();
showListContractSiteForm4G(type_device,serial_number,ct_ref);
}
else if (result.Error==1) {
$("#ct_ref").css("border","1px solid #f70421");
return $.popMessage("Contract number does not exist",true);
}
else if (result.Error==2) {
$("#ct_ref").css("border","1px solid #f70421");
return $.popMessage("Contract number exists elsewhere",true);
}
*/
if(result.Error==0) {
$("#_form_t").remove();
showListContractSiteForm4G(type_device,serial_number,ct_ref);
}
else if (result.Error==1) {
$("#ct_refAdd").css("border","1px solid #f70421");
var msg = "Contract number does not exist";
$("#divWarningAddCtRef").html(msg);
}
else if (result.Error==2) {
$("#ct_refAdd").css("border","1px solid #f70421");
var msg = "Contract number already exists on this site";
$("#divWarningAddCtRef").html(msg);
}
else if (result.Error==3) {
$("#ct_refAdd").css("border","1px solid #f70421");
var msg = "Contract number already used on another site";
$("#divWarningAddCtRef").html(msg);
}
else if (result.Error==4) {
$("#ct_refAdd").css("border","1px solid #f70421");
var msg = "Contract number already in use with another client";
$("#divWarningAddCtRef").html(msg);
}
}
catch(e) {
$.popMessage("Error occurs! Result of ajax: " + msg + '\n' +e);
}
});
} // end of saveContractSite
function idCheckFailureCbk(msg) {
$('#divInfoPlusIdentifiant_2').html('');
$('#divInfoPlusIdentifiant_2').html(msg);
$('#device_hasError').val(2);
$('#showLabelContrat').html('');
$('#showZoneSelectContrat').html('');
}
function showCACDeviceDetails(device_type) {
var device_cac_id;
var device_cac_imei;
var device_cac_ssid;
var device_type_sylob;
if(device_type == 3){
device_cac_id = 'cl_cac_id';
device_cac_imei = 'cl_cac_imei';
device_cac_ssid = 'cl_cac_ssid';
device_type_sylob = 11;
}
else if(device_type == 4){
device_cac_id = 'hf_cac_id';
device_cac_imei = 'hf_cac_imei';
device_cac_ssid = 'hf_cac_ssid';
device_type_sylob = 10;
}
var device_identifiant = $('#' + device_cac_id).val();
checkIdentifiantCacForAddNewDevice(
device_type_sylob,
device_identifiant,
function(result){
$('#divInfoPlusIdentifiant_2').html('');
$('#device_hasError').val(0);
if (result.o_imei) $('#'+device_cac_imei).html(result.o_imei);
if (result.o_ssid) $('#'+device_cac_ssid).html(result.o_ssid);
},
idCheckFailureCbk
)
}