/////////////////////////////////////////// // script.js.php // Copyright (c) 2017 Wavestore Global Ltd /////////////////////////////////////////// $(document).ready(function() { var btn_disable = true; var total_anlogue_channel = new Array(); var total_ip_channel = new Array(); var available_anlogue_cams = new Array(); var available_ip_cams = new Array(); var error1 = "Empty"; var error2 = "Empty"; var error3 = "Empty"; /**Activation Code**/ $(document).on("blur","#activation_code",function(){ var pattern = /^[a-z0-9]$/; if($(this).val() == "" || pattern.test($(this).val())) { $(this).parent().addClass("has-error"); $(this).next().remove(); $("#ip_max").text(""); $("#anlogue_max").text(""); $("#licence_type_progress").html(""); $("Empty").insertAfter(this); } else { $(this).parent().removeClass("has-error"); $(this).next().remove(); var act_code = $(this).val(); $.ajax({ type: 'POST', url: 'activation_code_validation.php', data: {act_code:act_code}, dataType: 'json', beforeSend:function() { $('#licence_type_progress').html('Processing...'); }, success:function(data) { if(data.licence_type != "") { total_anlogue_channel[0] = data.anlogue_channel; total_ip_channel[0] = data.ip_channel; $("#machine_id").removeAttr("disabled"); $("#anlogue_channel").removeAttr("disabled"); $("#ip_channel").removeAttr("disabled"); $("#serial_number").removeAttr("disabled"); $("#site_notes").removeAttr("disabled"); $('#licence_type_progress').html(''+data.licence_type+''); $("#anlogue_max").text(""); $("#anlogue_max").text("(maximum available "+ data.anlogue_channel+")"); $("#ip_max").text(""); $("#ip_max").text("(maximum available "+ data.ip_channel+")"); /** $("#ssa").next().remove(); $("#ssa").after("("+ data.ip_channel+")"); **/ } else { $('#licence_type_progress').html('Activation code does not exist.'); } }, error:function() { $('#licence_type_progress').html('Something Went Wrong.'); } }); } }); /**Validating Machine ID**/ $(document).on("blur","#machine_id",function(){ var pattern1 = /^[A-Z]{12}$/; var pattern2 = /^[A-Z]{4}-[A-Z]{4}-[A-Z]{4,5}$/; if(!pattern1.test($(this).val()) && !pattern2.test($(this).val())) { error1 = "invalid"; $(this).next().remove(); $(this).parent().addClass("has-error"); $("Invalid").insertAfter(this); } else { error1 = null; $(this).parent().removeClass("has-error"); $(this).next().remove(); var machine_id = $("#machine_id").val(); $.ajax({ type: 'POST', url:'macheine_id_to_ipcam_analoguecam.php', data:{machine_id:machine_id}, dataType:'json', beforeSend:function() { $('.analoguecam').html('Processing...'); $('.ipcam').html('Processing...'); }, success:function(data) { available_anlogue_cams[0] = data.analogcams; available_ip_cams[0] = data.ipcams; $(".analoguecam").html("(existing "+data.analogcams+" + additional --)"); $(".ipcam").html("(existing "+data.ipcams+" + additional --)"); }, error:function(err) { console.log(err); } }); } if(error1 == null && error2 == null && error3 == null) $("#generate_submit").removeAttr("disabled"); else $("#generate_submit").attr("disabled","disabled"); }); /**Validating analogue channels**/ $(document).on("blur","#anlogue_channel",function(){ if($(this).val() == "") { error2 = "Empty"; $(".anlogue-channel").remove(); $(this).parent().addClass("has-error"); $("Empty").insertAfter(this); }else if(isNaN($(this).val())) { error2 = "Invalid"; $(".anlogue-channel").remove(); $(this).parent().addClass("has-error"); $("Invalid").insertAfter(this); }else if(Number($(this).val()) < 0 || Number($(this).val()) - Number(available_anlogue_cams[0]) > Number(total_anlogue_channel[0]) || Number(available_anlogue_cams[0]) > Number($(this).val())) { error2 = "Invalid"; $(".anlogue-channel").remove(); $(this).parent().addClass("has-error"); $("Invalid").insertAfter(this); } else { error2 = null; $(this).parent().removeClass("has-error"); $(".anlogue-channel").remove(); var machine_id = $("#machine_id").val(); $.ajax({ type: 'POST', url:'macheine_id_to_ipcam_analoguecam.php', data:{machine_id:machine_id}, dataType:'json', beforeSend:function() { $(".analoguecam").html("Processing..."); }, success:function(data) { var additional_analogue = $('#anlogue_channel').val() - data.analogcams; if(Number(data.analogcams) > Number($('#anlogue_channel').val())) $(".analoguecam").html("Invalid"); else $(".analoguecam").html("(existing "+data.analogcams+" + additional "+additional_analogue+")"); }, error:function(err) { console.log(err); } }); } if(error1 == null && error2 == null && error3 == null) $("#generate_submit").removeAttr("disabled"); else $("#generate_submit").attr("disabled","disabled"); }); /**Validating IP channels**/ $(document).on("blur","#ip_channel",function(){ if($(this).val() == "") { error3 = "Empty"; $(".ip-channel").remove(); $(this).parent().addClass("has-error"); $("Empty").insertAfter(this); }else if(isNaN($(this).val())) { error3 = "Invalid"; $(".ip-channel").remove(); $(this).parent().addClass("has-error"); $("Invalid").insertAfter(this); }else if(Number($(this).val()) < 0 || Number($(this).val()) - Number(available_ip_cams[0]) > Number(total_ip_channel[0]) || Number(available_ip_cams[0]) > Number($(this).val())) { error3 = "Invalid"; $(".ip-channel").remove(); $(this).parent().addClass("has-error"); $("Invalid").insertAfter(this); } else { error3 = null; $(this).parent().removeClass("has-error"); $(".ip-channel").remove(); var machine_id = $("#machine_id").val(); $.ajax({ type: 'POST', url:'macheine_id_to_ipcam_analoguecam.php', data:{machine_id:machine_id}, dataType:'json', beforeSend:function() { $('.ipcam').html("Processing..."); }, success:function(data) { var additional_ip = $('#ip_channel').val() - data.ipcams; if(Number(data.ipcams) > Number($('#ip_channel').val())) $(".ipcam").html("Invalid"); else $(".ipcam").html("(existing "+data.ipcams+" + additional "+additional_ip+")"); }, error:function(err) { console.log(err); } }); } if(error1 == null && error2 == null && error3 == null) $("#generate_submit").removeAttr("disabled"); else $("#generate_submit").attr("disabled","disabled"); }); $(document).on("click","#generate_submit",function(){ var actcode = $("#activation_code").val(); var actcode = actcode; var machine_id = $("#machine_id").val(); var anlogue_channel = $("#anlogue_channel").val(); var ip_channel = $("#ip_channel").val(); var ssa = $("#ssa").val(); var serial_no = $("#serial_number").val(); var site_notes = $("#site_notes").val(); $.ajax({ type: 'POST', url: 'generate_licence.php', dataType:'json', data: { activation_code:actcode, machine_id:machine_id, anlogue_cams:anlogue_channel, ip_cams:ip_channel, ssa:ssa, serial_no:serial_no, site_notes:site_notes }, beforeSend:function() { $('#generate_licence_success').html('Processing...'); }, success:function(data) { if(data.error) $('#generate_licence_success').html('Something Went Wrong.: '+data.error+''); else $("#generate_licence_success").html(""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ "
Machine IDServer LicenseLicence Flags
"+data.machine_id+""+data.server_licence+""+data.licence_flags+"
"); $("#generate_submit").attr("disabled","disabled"); console.log(data.debug); }, error:function() { $('#generate_licence_success').html('Something Went Wrong.'); } }); }); }); $(document).ready(function() { $(document).on("click","a[href='#add_distributor']",function() { $("#addDistributorForm").find("input,select,checkbox").val(""); $("#addDistributorAction").removeAttr("disabled"); $('#addDistributorNotification').html(''); $.ajax({ type: 'POST', url: 'get_distributor.php', data: {level:1}, dataType: 'json', beforeSend:function() { $('#owner_id').attr('disabled','disabled'); }, success:function(data) { $('#owner_id').removeAttr("disabled"); $('.distributor option').remove(); $('.distributor').append($("").attr("value","").text("Select")); $.each(data, function(id,companyname) { $('.distributor').append($("").attr("value",id).text(companyname)); }); }, error:function() { console.log("Something Went Wrong."); } }); $.ajax({ type: 'POST', url: 'get_currencies.php', dataType: 'json', beforeSend:function() { $('#distributor_currency').attr('disabled','disabled'); }, success:function(data) { $('#distributor_currency').removeAttr("disabled"); $('.currency option').remove(); $('.currency').append($("").attr("value","").text("Select")); $.each(data, function(id,currency) { $('.currency').append($("").attr("value",id).text(currency)); }); }, error:function() { console.log("Something Went Wrong."); } }); }); $(document).on("submit","#addDistributorForm",function(e) { e.preventDefault(); var company_name = $("#company_name").val(); var owner_id = $("#owner_id").val(); var distributor_currency = $("#distributor_currency").val(); $.ajax({ type: 'POST', url: 'add_distributor.php', data: {company_name:company_name, owner_id:owner_id,distributor_currency:distributor_currency}, dataType: 'json', beforeSend:function() { $('#addDistributorNotification').html('Processing...'); }, success:function(data) { if(data.success != "") { $("input, select").parent().removeClass("has-error"); $("input, select").next().remove(); $('#addDistributorNotification').html(data.success); $("#addDistributorAction").attr("disabled","disabled"); } else { $('#addDistributorNotification').html(''); var error = $.parseJSON(data.errors); $.each(error, function(index,error) { $("#"+index).parent().addClass("has-error"); $("#"+index).next().remove(); $(""+error+"").insertAfter("#"+index); }); } }, error:function() { $('#addDistributorNotification').html('Something Went Wrong.'); } }); }); }); $(document).ready(function() { $(document).on("click","a[href='#add_user']",function() { $("#addUsersForm").find("input,select,checkbox").val(""); $("#distributor").removeAttr("selected"); $("#administrator").removeAttr("checked"); $("#addUsersAction").removeAttr("disabled"); $('#addUsersNotification').html(''); $.ajax({ type: 'POST', url: 'get_distributor.php', dataType: 'json', success:function(data) { $('.distributor option').remove(); $('.distributor').append($("").attr("value","").text("Select")); $.each(data, function(id,companyname) { $('.distributor').append($("").attr("value",id).text(companyname)); }); }, error:function() { console.log("Something Went Wrong."); } }); }); $(document).on("submit","#addUsersForm",function(e) { e.preventDefault(); var distributor = $("#distributor").val(); var new_username = $("#new_username").val(); var new_password = $("#new_password").val(); var administrator; if($("#administrator").is(":checked")) administrator = 1; else administrator = 0; $.ajax({ type: 'POST', url: 'add_users.php', data: { distributor:distributor, new_username:new_username, new_password:new_password, administrator:administrator }, dataType: 'json', beforeSend:function() { $('#addUsersNotification').html('Processing...'); }, success:function(data) { if(data.success != "") { $("input").parent().removeClass("has-error"); $("input").next().remove(); $('#addUsersNotification').html(data.success); $("#addUsersAction").attr("disabled","disabled"); } else { $('#addUsersNotification').html(''); var error = $.parseJSON(data.errors); $.each(error, function(index,error) { if(error != "") { $("#"+index).parent().addClass("has-error"); $("#"+index).next().remove(); $(""+error+"").insertAfter("#"+index); }else { $("#"+index).parent().removeClass("has-error"); $("#"+index).next().remove(); } }); } }, error:function() { $('#addUsersNotification').html('Something Went Wrong.'); } }); }); }); $(document).ready(function() { $(document).on("click","a[href='#list_user']",function() { $('#listUsersNotification').html(''); $.ajax({ type: 'POST', url: 'get_distributor.php', dataType: 'json', beforeSend:function() { $('.distributor').attr("disabled","disabled"); }, success:function(data) { $('.distributor option').remove(); $('.distributor').append($("").attr("value","").text("Select")); $.each(data, function(id,companyname) { $('.distributor').append($("").attr("value",id).text(companyname)); }); $('.distributor').removeAttr("disabled"); }, error:function() { console.log("Something Went Wrong."); } }); }); $(document).on("submit","#listUsersForm",function(e) { e.preventDefault(); var distributor = $("#listdistributor").val(); $.ajax({ type: 'POST', url: 'list_users.php', data: { distributor:distributor, }, dataType: 'json', beforeSend:function() { $('#listUsersNotification').html('

Processing...

'); }, success:function(data) { if(data.success == 1) { $("select").parent().removeClass("has-error"); $("select").next().remove(); var list_output = null; $.each($.parseJSON(data.success_data), function(username,admin){ list_output += "
"+username+"
"+admin+"
"; }); $('#listUsersNotification').html(list_output); } else { $('#listUsersNotification').html(''); var error = $.parseJSON(data.errors); $.each(error, function(index,error) { if(error != "") { $("#"+index).parent().addClass("has-error"); $("#"+index).next().remove(); $(""+error+"").insertAfter("#"+index); }else { $("#"+index).parent().removeClass("has-error"); $("#"+index).next().remove(); } }); } }, error:function() { $('#listUsersNotification').html('

Something Went Wrong.

'); } }); }); }); $(document).ready(function() { $(document).on("click","a[href='#change_password']",function() { $("#changePasswordForm").find("input,select,checkbox").val(""); $("#changePasswordAction").removeAttr("disabled"); $('#changePasswordNotification').html(''); $.ajax({ type: 'POST', url: 'get_distributor.php', dataType: 'json', beforeSend:function() { $('.distributor').attr("disabled","disabled"); }, success:function(data) { $('.distributor option').remove(); $('.distributor').append($("").attr("value","").text("Select")); $.each(data, function(id,companyname) { $('.distributor').append($("").attr("value",id).text(companyname)); }); $('.distributor').removeAttr("disabled"); }, error:function() { console.log("Something Went Wrong."); } }); }); $(document).on("change","#distributorInChangePassword",function() { if($(this).val() != "") { var companyid = $(this).val(); $.ajax({ type: 'POST', url: 'get_users.php', data: {company_id:companyid}, dataType: 'json', beforeSend:function() { $('#usernameInChangePassword').attr("disabled","disabled"); }, success:function(data) { $("#usernameInChangePassword option").remove(); $('#usernameInChangePassword').append($("").attr("value","").text("Select")); $.each(data, function(id,username) { $('#usernameInChangePassword').append($("").attr("value",username).text(username)); }); $('#usernameInChangePassword').removeAttr("disabled"); }, error:function() { console.log("Something Went Wrong."); } }); } }); $(document).on("submit","#changePasswordForm",function(e) { e.preventDefault(); var distributor = $("#distributorInChangePassword").val(); var new_username = $("#usernameInChangePassword").val(); var new_password = $("#change_new_password").val(); $.ajax({ type: 'POST', url: 'change_users_password.php', data: { distributor:distributor, new_username:new_username, new_password:new_password, }, dataType: 'json', beforeSend:function() { $('#changePasswordNotification').html('Processing...'); }, success:function(data) { if(data.success != "") { $("input").parent().removeClass("has-error"); $("input").next().remove(); $('#changePasswordNotification').html(data.success); $("#changePasswordAction").attr("disabled","disabled"); } else { $('#changePasswordNotification').html(''); var error = $.parseJSON(data.errors); $.each(error, function(index,error) { if(error != "") { $("#"+index).parent().addClass("has-error"); $("#"+index).next().remove(); $(""+error+"").insertAfter("#"+index); }else { $("#"+index).parent().removeClass("has-error"); $("#"+index).next().remove(); } }); } }, error:function() { $('#changePasswordNotification').html('Something Went Wrong.'); } }); }); }); $(document).ready(function() { $(document).on("click","a[href='#change_admin_permission']",function() { $("#changePermissionForm").find("input,select,checkbox").val(""); $("#changePermissionAction").removeAttr("disabled"); $('#changeAdministratorNotification').html(''); $("#change_admin").removeAttr("checked"); $.ajax({ type: 'POST', url: 'get_distributor.php', dataType: 'json', beforeSend:function() { $('.distributor').attr("disabled","disabled"); }, success:function(data) { $('.distributor option').remove(); $('.distributor').append($("").attr("value","").text("Select")); $.each(data, function(id,companyname) { $('.distributor').append($("").attr("value",id).text(companyname)); }); $('.distributor').removeAttr("disabled"); }, error:function() { console.log("Something Went Wrong."); } }); }); $(document).on("change","#distributorInChangePermission",function() { if($(this).val() != "") { var companyid = $(this).val(); $.ajax({ type: 'POST', url: 'get_users.php', data: {company_id:companyid}, dataType: 'json', beforeSend:function() { $('#usernameInChangePermission').attr("disabled","disabled"); }, success:function(data) { $("#usernameInChangePermission option").remove(); $('#usernameInChangePermission').append($("").attr("value","").text("Select")); $.each(data, function(id,username) { $('#usernameInChangePermission').append($("").attr("value",username).text(username)); }); $('#usernameInChangePermission').removeAttr("disabled"); }, error:function() { console.log("Something Went Wrong."); } }); } }); $(document).on("submit","#changePermissionForm",function(e) { e.preventDefault(); var distributor = $("#distributorInChangePermission").val(); var new_username = $("#usernameInChangePermission").val(); var administrator; if($("#change_admin").is(":checked")) administrator = 1; else administrator = 0; $.ajax({ type: 'POST', url: 'change_users_permission.php', data: { distributor:distributor, new_username:new_username, administrator:administrator, }, dataType: 'json', beforeSend:function() { $('#changeAdministratorNotification').html('Processing...'); }, success:function(data) { if(data.success != "") { $("input").parent().removeClass("has-error"); $("input").next().remove(); $('#changeAdministratorNotification').html(data.success); $("#changePermissionAction").attr("disabled","disabled"); } else { $('#changeAdministratorNotification').html(''); var error = $.parseJSON(data.errors); $.each(error, function(index,error) { if(error != "") { $("#"+index).parent().addClass("has-error"); $("#"+index).next().remove(); $(""+error+"").insertAfter("#"+index); }else { $("#"+index).parent().removeClass("has-error"); $("#"+index).next().remove(); } }); } }, error:function() { $('#changeAdministratorNotification').html('Something Went Wrong.'); } }); }); }); $(document).ready(function() { $(document).on("click","a[href='#delete_user']",function() { $("#deleteUserForm").find("input,select,checkbox").val(""); $("#deleteUserAction").removeAttr("disabled"); $('#deleteUserNotification').html(''); $.ajax({ type: 'POST', url: 'get_distributor.php', dataType: 'json', beforeSend:function() { $('.distributor').attr("disabled","disabled"); }, success:function(data) { $('.distributor option').remove(); $('.distributor').append($("").attr("value","").text("Select")); $.each(data, function(id,companyname) { $('.distributor').append($("").attr("value",id).text(companyname)); }); $('.distributor').removeAttr("disabled"); }, error:function() { console.log("Something Went Wrong."); } }); }); $(document).on("change","#distributorInDeleteUser",function() { if($(this).val() != "") { var companyid = $(this).val(); $.ajax({ type: 'POST', url: 'get_users.php', data: {company_id:companyid}, dataType: 'json', beforeSend:function() { $('#usernameInDeleteUser').attr("disabled","disabled"); }, success:function(data) { $('#usernameInDeleteUser option').remove(); $('#usernameInDeleteUser').append($("").attr("value","").text("Select")); $.each(data, function(id,username) { $('#usernameInDeleteUser').append($("").attr("value",username).text(username)); }); $('#usernameInDeleteUser').removeAttr("disabled"); }, error:function() { console.log("Something Went Wrong."); } }); } }); $(document).on("submit","#deleteUserForm",function(e) { e.preventDefault(); var distributor = $("#distributorInDeleteUser").val(); var new_username = $("#usernameInDeleteUser").val(); $.ajax({ type: 'POST', url: 'delete_users.php', data: { distributor:distributor, new_username:new_username }, dataType: 'json', beforeSend:function() { $('#deleteUserNotification').html('Processing...'); }, success:function(data) { if(data.success != "") { $("input").parent().removeClass("has-error"); $("input").next().remove(); $('#deleteUserNotification').html(data.success); $("#deleteUserAction").attr("disabled","disabled"); } else { $('#deleteUserNotification').html(''); var error = $.parseJSON(data.errors); $.each(error, function(index,error) { if(error != "") { $("#"+index).parent().addClass("has-error"); $("#"+index).next().remove(); $(""+error+"").insertAfter("#"+index); }else { $("#"+index).parent().removeClass("has-error"); $("#"+index).next().remove(); } }); } }, error:function() { $('#deleteUserNotification').html('Something Went Wrong.'); } }); }); }); $(document).ready(function() { $(document).on("click","a[href='#transfer_credit']",function() { $('#transferCreditNotification').html(''); $("select, input").val(''); $("#transferCreditAction").removeAttr("disabled"); $.ajax({ type: 'POST', url: 'get_distributor.php', dataType: 'json', beforeSend:function() { $('.distributor').attr("disabled","disabled"); }, success:function(data) { $('.distributor option').remove(); $('.distributor').append($("").attr("value","").text("Select")); $.each(data, function(id,companyname) { $('.distributor').append($("").attr("value",id).text(companyname)); }); $('.distributor').removeAttr("disabled"); }, error:function() { console.log("Something Went Wrong."); } }); }); $(document).on("submit","#transferCreditForm",function(e) { e.preventDefault(); var distributor = $("#distributorInCreditTransfer").val(); var credits = $("#creditsInCreditTransfer").val(); $.ajax({ type: 'POST', url: 'transfer_credits.php', data: { distributor:distributor, credits:credits }, dataType: 'json', beforeSend:function() { $('#transferCreditNotification').html('

Processing...

'); }, success:function(data) { if(data.success != "") { $("select, input").parent().removeClass("has-error"); $("select, input").next().remove(); $('#transferCreditNotification').html(data.success); $("#transferCreditAction").attr("disabled","disabled"); } else { $('#transferCreditNotification').html(''); var error = $.parseJSON(data.errors); $.each(error, function(index,error) { if(error != "") { $("#"+index).parent().addClass("has-error"); $("#"+index).next().remove(); $(""+error+"").insertAfter("#"+index); }else { $("#"+index).parent().removeClass("has-error"); $("#"+index).next().remove(); } }); } }, error:function() { $('#transferCreditNotification').html('

Something Went Wrong.

'); } }); }); }); $(document).ready(function() { $(document).on("click","a[href='#set_creditlimit']",function() { $('#setCompanyCreditlimitNotification').html(''); $("select, input").val(''); $("#setCompanyCreditlimitAction").removeAttr("disabled"); $.ajax({ type: 'POST', url: 'get_distributor.php', dataType: 'json', beforeSend:function() { $('.distributor').attr("disabled","disabled"); }, success:function(data) { $('.distributor option').remove(); $('.distributor').append($("").attr("value","").text("Select")); $.each(data, function(id,companyname) { $('.distributor').append($("").attr("value",id).text(companyname)); }); $('.distributor').removeAttr("disabled"); }, error:function() { console.log("Something Went Wrong."); } }); }); $(document).on("submit","#setCompanyCreditlimitForm",function(e) { e.preventDefault(); var distributor = $("#distributorInCreditlimit").val(); var creditlimit = $("#creditsInCreditlimit").val(); $.ajax({ type: 'POST', url: 'set_creditlimit.php', data: { distributor:distributor, creditlimit:creditlimit }, dataType: 'json', beforeSend:function() { $('#setCompanyCreditlimitNotification').html('

Processing...

'); }, success:function(data) { if(data.success != "") { $("select, input").parent().removeClass("has-error"); $("select, input").next().remove(); $('#setCompanyCreditlimitNotification').html(data.success); $("#setCompanyCreditlimitAction").attr("disabled","disabled"); } else { $('#setCompanyCreditlimitNotification').html(''); var error = $.parseJSON(data.errors); $.each(error, function(index,error) { if(error != "") { $("#"+index).parent().addClass("has-error"); $("#"+index).next().remove(); $(""+error+"").insertAfter("#"+index); }else { $("#"+index).parent().removeClass("has-error"); $("#"+index).next().remove(); } }); } }, error:function() { $('#setCompanyCreditlimitNotification').html('

Something Went Wrong.

'); } }); }); }); $(document).ready(function() { $(document).on("click","a[href='#show_credits_tab']",function() { $.ajax({ type: 'POST', url: 'show_credits.php', dataType: 'json', beforeSend:function() { $('#current_user_credits').text("Processing..."); $('#current_user_creditlimit').text("Processing..."); $('#available_user_credits').text("Processing..."); }, success:function(data) { $('#current_user_credits').text(data.current_credits); $('#current_user_creditlimit').text(data.current_creditlimit); $('#available_user_credits').text(data.available_credits); }, error:function() { console.log("Something Went Wrong."); } }); }); }); $(document).ready(function() { $(document).on("click","a[href='#pac']",function() { $('#purchaseActivationCodeNotification').html(''); $("select, input").val(''); $("select, input").parent().removeClass("has-error"); $("select, input").next().remove(); $("#purchaseActivationCodeAction").removeAttr("disabled"); $.ajax({ type: 'POST', url: 'get_licence_type.php', dataType: 'json', beforeSend:function() { $('.licence_type').attr("disabled","disabled"); }, success:function(data) { $("#pac_list_price_of_activation_code").text(''); $('.licence_type option').remove(); $('.licence_type').append($("").attr("value","").text("Select")); $.each(data, function(id,companyname) { $('.licence_type').append($("").attr("value",id).text(companyname)); }); $('.licence_type').removeAttr("disabled"); }, error:function() { console.log("Something Went Wrong."); } }); }); $(document).on("keyup","#pac_ip_channels",function(e) { var licence_type_id = $("#pac_licence_type").val(); var analog_cams = $("#pac_analogue_channels").val(); var ip_cams = $("#pac_ip_channels").val(); $.ajax({ type: 'POST', url: 'get_activation_code_of_list_price.php', data: { licence_type_id:licence_type_id, analog_cams:analog_cams, ip_cams:ip_cams }, dataType: 'json', beforeSend:function() { $('#pac_list_price_of_activation_code').html('

Processing...

'); }, success:function(data) { $("#pac_list_price_of_activation_code").text('List price of this Activation Code Is :'+data.currencyname+' '+data.msrp_cost_display); }, error:function(err) { console.log(err); $('#pac_list_price_of_activation_code').html('

Something Went Wrong.

'); } }); }); $(document).on("submit","#purchaseActivationCodeForm",function(e) { e.preventDefault(); var licence_type_id = $("#pac_licence_type").val(); var analog_cams = $("#pac_analogue_channels").val(); var ip_cams = $("#pac_ip_channels").val(); var po_number = $("#pac_po").val(); $.ajax({ type: 'POST', url: 'purchase_activation_code.php', data: { licence_type_id:licence_type_id, analog_cams:analog_cams, ip_cams:ip_cams, po_number:po_number }, dataType: 'json', beforeSend:function() { $('#purchaseActivationCodeNotification').html('

Processing...

'); }, success:function(data) { if(data.success != "") { $("select, input").parent().removeClass("has-error"); $("select, input").next().remove(); $('#purchaseActivationCodeNotification').html(data.success); $("#purchaseActivationCodeAction").attr("disabled","disabled"); } else { $('#purchaseActivationCodeNotification').html(''); var error = $.parseJSON(data.errors); $.each(error, function(index,error) { if(error != "") { $("#"+index).parent().addClass("has-error"); $("#"+index).next().remove(); $(""+error+"").insertAfter("#"+index); }else { $("#"+index).parent().removeClass("has-error"); $("#"+index).next().remove(); } }); } }, error:function(err) { $('#purchaseActivationCodeNotification').html('

Something Went Wrong.

'); } }); }); }); $(document).ready(function() { $(document).on("click","a[href='#add_pricelist']",function() { $("#addPricelistForm").find("input,select,checkbox").val(""); $("#addPricelistAction").removeAttr("disabled"); $('#addPricelistNotification').html(''); $("input,select").parent().removeClass("has-error"); $("input,select").next().remove(); //To get distributors $.ajax({ type: 'POST', url: 'get_distributor.php', data: {level:0}, dataType: 'json', beforeSend:function() { $('#add_pricelist_distributor').attr("disabled","disabled"); }, success:function(data) { $("#add_pricelist_distributor").removeAttr("disabled"); $('.distributor option').remove(); $('.distributor').append($("").attr("value","").text("Select")); $.each(data, function(id,distributor) { $('.distributor').append($("").attr("value",id).text(distributor)); }); }, error:function() { console.log("Something Went Wrong."); } }); }); $(document).on("change","#add_pricelist_distributor",function() { var company_id = $(this).val(); $.ajax({ type: 'POST', url: 'get_valid_pricelist_visiblity_classes.php', data: {company_id: company_id}, dataType: 'json', beforeSend:function() { $('#pricelist_visiblity_class').attr("disabled","disabled"); }, success:function(data) { $("#pricelist_visiblity_class").removeAttr("disabled"); $('.pricelist_class option').remove(); $('.pricelist_class').append($("").attr("value","").text("Select")); $.each(data, function(id,visiblity_class) { $('.pricelist_class').append($("").attr("value",id).text(visiblity_class)); }); }, error:function() { console.log("Something Went Wrong."); } }); }); $(document).on("submit","#addPricelistForm",function(e) { e.preventDefault(); var add_pricelist_distributor = $("#add_pricelist_distributor").val(); var pricelist_visiblity_class = $("#pricelist_visiblity_class").val(); $.ajax({ type: 'POST', url: 'add_pricelist.php', data: { add_pricelist_distributor: add_pricelist_distributor, pricelist_visiblity_class: pricelist_visiblity_class }, dataType: 'json', beforeSend:function() { $('#addPricelistNotification').html('Processing...'); }, success:function(data) { if(data.success != "") { $("input,select").parent().removeClass("has-error"); $("input,select").next().remove(); $('#addPricelistNotification').html(data.success); $("#addPricelistAction").attr("disabled","disabled"); } else { $('#addPricelistNotification').html(''); var error = $.parseJSON(data.errors); $.each(error, function(index,error) { if(error != "") { $("#"+index).parent().addClass("has-error"); $("#"+index).next().remove(); $(""+error+"").insertAfter("#"+index); }else { $("#"+index).parent().removeClass("has-error"); $("#"+index).next().remove(); } }); } }, error:function() { $('#addPricelistNotification').html('Something Went Wrong.'); } }); }); }); $(document).ready(function() { $(document).on("click","a[href='#delete_pricelist']",function() { $("#deletePricelistForm").find("input,select,checkbox").val(""); $("#pricelist_currency").text(""); $('#existing_pricelist_visiblity_class').attr("disabled","disabled"); $("#deletePricelistAction").removeAttr("disabled"); $('#deletePricelistNotification').html(''); $("input,select").parent().removeClass("has-error"); $("input,select").next().remove(); //To get distributors $.ajax({ type: 'POST', url: 'get_distributor.php', data: {level:1}, dataType: 'json', beforeSend:function() { $('#pricelist_distributor').attr("disabled","disabled"); }, success:function(data) { $("#pricelist_distributor").removeAttr("disabled"); $('.distributor option').remove(); $('.distributor').append($("").attr("value","").text("Select")); $.each(data, function(id,distributor) { $('.distributor').append($("").attr("value",id).text(distributor)); }); }, error:function() { console.log("Something Went Wrong."); } }); }); $(document).on("change","#pricelist_distributor",function() { var distributorid = $(this).val(); if(distributorid != "") { $.ajax({ type: 'POST', url: 'get_currencies.php', data: { distributorid: distributorid }, dataType: 'json', beforeSend:function() { $('#pricelist_currency').text('Processing...'); }, success:function(data) { $("#pricelist_currency").text(""); $("#pricelist_currency").text(data.currency); }, error:function() { console.log("Something Went Wrong."); } }); //To get existing Visiblity class $.ajax({ type: 'POST', url: 'get_existing_pricelist_visibility_classes.php', data: {distributorid: distributorid}, dataType: 'json', beforeSend:function() { $('#existing_pricelist_visiblity_class').attr("disabled","disabled"); }, success:function(data) { $("#existing_pricelist_visiblity_class").removeAttr("disabled"); $('.visiblity_class option').remove(); $('.visiblity_class').append($("").attr("value","").text("Select")); $.each(data, function(id,visiblity_class) { $('.visiblity_class').append($("").attr("value",id).text(visiblity_class)); }); }, error:function() { console.log("Something Went Wrong."); } }); } }); $(document).on("submit","#deletePricelistForm",function(e) { e.preventDefault(); var pricelist_distributor = $("#pricelist_distributor").val(); var existing_pricelist_visiblity_class = $("#existing_pricelist_visiblity_class").val(); $.ajax({ type: 'POST', url: 'delete_pricelist.php', data: { pricelist_distributor: pricelist_distributor, existing_pricelist_visiblity_class: existing_pricelist_visiblity_class }, dataType: 'json', beforeSend:function() { $('#deletePricelistNotification').html('Processing...'); }, success:function(data) { if(data.success != "") { $("input,select").parent().removeClass("has-error"); $("input,select").next().remove(); $('#deletePricelistNotification').html(data.success); $("#deletePricelistAction").attr("disabled","disabled"); } else { $('#deletePricelistNotification').html(''); var error = $.parseJSON(data.errors); $.each(error, function(index,error) { if(error != "") { $("#"+index).parent().addClass("has-error"); $("#"+index).next().remove(); $(""+error+"").insertAfter("#"+index); }else { $("#"+index).parent().removeClass("has-error"); $("#"+index).next().remove(); } }); } }, error:function() { $('#deletePricelistNotification').html('Something Went Wrong.'); } }); }); }); $(document).ready(function() { var btn_disable = true; var available_anlogue_cams = new Array(); var available_ip_cams = new Array(); var available_ems_cams = new Array(); var error1 = "Empty"; var error2 = "Empty"; var error3 = "Empty"; $.ajax({ type: 'POST', url:'get_licence_type.php', dataType:'json', beforeSend:function() { $("#logged_in_licence_type1").attr("disabled","disabled"); $("#logged_in_licence_type2").attr("disabled","disabled"); $("#logged_in_licence_type3").attr("disabled","disabled"); }, success:function(data) { $("#logged_in_licence_type1").removeAttr("disabled"); $("#logged_in_licence_type2").removeAttr("disabled"); $("#logged_in_licence_type3").removeAttr("disabled"); $('.licence_type option').remove(); $('.licence_type2 option').remove(); $('.licence_type').append($("").attr("value","").text("Select")); $('.licence_type2').append($("").attr("value","").text("None")); $.each(data, function(id,licence_type) { $('.licence_type, .licence_type2').append($("").attr("value",id).text(licence_type)); }); }, error:function(err) { console.log(err); } }); /**licence Type 1**/ $(document).on("change","#logged_in_licence_type1",function(){ if($(this).val() == "") { $(this).parent().addClass("has-error"); $(this).next().remove(); $("#ip_max").text(""); $("#anlogue_max").text(""); $("#licence_type_progress").html(""); $("Empty").insertAfter(this); } else { $(this).parent().removeClass("has-error"); $(this).next().remove(); var licence_type1 = $(this).val(); $("#logged_in_machine_id").removeAttr("disabled"); $("#logged_in_anlogue_channel").removeAttr("disabled"); $("#logged_in_ems_channel").removeAttr("disabled"); $("#logged_in_ip_channel").removeAttr("disabled"); $("#logged_in_serial_number").removeAttr("disabled"); } }); /**Validating Machine ID**/ $(document).on("blur","#logged_in_machine_id",function(){ var pattern1 = /^[A-Z]{12}$/; var pattern2 = /^[A-Z]{4}-[A-Z]{4}-[A-Z]{4,5}$/; if(!pattern1.test($(this).val()) && !pattern2.test($(this).val())) { error1 = "invalid"; $(this).next().remove(); $(this).parent().addClass("has-error"); $("Invalid").insertAfter(this); } else { error1 = null; $(this).parent().removeClass("has-error"); $(this).next().remove(); var machine_id = $("#logged_in_machine_id").val(); $.ajax({ type: 'POST', url:'machineid_to_fields.php', data:{machine_id:machine_id}, dataType:'json', beforeSend:function() { $('.analoguecam').html('Processing...'); $('.ipcam').html('Processing...'); $('.emscam').html('Processing...'); }, success:function(data) { available_anlogue_cams[0] = data.analogcams; available_ip_cams[0] = data.ipcams; available_ems_cams[0] = data.emscams; $(".analoguecam").html("(existing "+data.analogcams+" + additional --)"); $(".ipcam").html("(existing "+data.ipcams+" + additional --)"); $(".emscam").html("(existing "+data.emscams+" + additional --)"); }, error:function(err) { console.log(err); } }); } if(error1 == null && error2 == null && error3 == null) $("#loggedInLicenceGeneraterAction").removeAttr("disabled"); else $("#loggedInLicenceGeneraterAction").attr("disabled","disabled"); }); /**Validating analogue channels**/ $(document).on("blur","#logged_in_anlogue_channel",function(){ if($(this).val() == "") { error2 = "Empty"; $(".anlogue-channel").remove(); $(this).parent().addClass("has-error"); $("Empty").insertAfter(this); }else if(isNaN($(this).val())) { error2 = "Invalid"; $(".anlogue-channel").remove(); $(this).parent().addClass("has-error"); $("Invalid").insertAfter(this); }else if(Number($(this).val()) < 0 || Number(available_anlogue_cams[0]) > Number($(this).val())) { error2 = "Invalid"; $(".anlogue-channel").remove(); $(this).parent().addClass("has-error"); $("Invalid").insertAfter(this); } else { error2 = null; $(this).parent().removeClass("has-error"); $(".anlogue-channel").remove(); var machine_id = $("#logged_in_machine_id").val(); $.ajax({ type: 'POST', url:'machineid_to_fields.php', data:{machine_id:machine_id}, dataType:'json', beforeSend:function() { $(".analoguecam").html("Processing..."); }, success:function(data) { var additional_analogue = $('#logged_in_anlogue_channel').val() - data.analogcams; if(Number(data.analogcams) > Number($('#anlogue_channel').val())) $(".analoguecam").html("Invalid"); else $(".analoguecam").html("(existing "+data.analogcams+" + additional "+additional_analogue+")"); }, error:function(err) { console.log(err); } }); } if(error1 == null && error2 == null && error3 == null) $("#loggedInLicenceGeneraterAction").removeAttr("disabled"); else $("#loggedInLicenceGeneraterAction").attr("disabled","disabled"); }); /**Validating EMS channels**/ $(document).on("blur","#logged_in_ems_channel",function(){ if($(this).val() == "") { error2 = "Empty"; $(".ems-channel").remove(); $(this).parent().addClass("has-error"); $("Empty").insertAfter(this); }else if(isNaN($(this).val())) { error2 = "Invalid"; $(".ems-channel").remove(); $(this).parent().addClass("has-error"); $("Invalid").insertAfter(this); }else if(Number($(this).val()) < 0 || Number(available_ems_cams[0]) > Number($(this).val())) { error2 = "Invalid"; $(".ems-channel").remove(); $(this).parent().addClass("has-error"); $("Invalid").insertAfter(this); } else { error2 = null; $(this).parent().removeClass("has-error"); $(".ems-channel").remove(); var machine_id = $("#logged_in_machine_id").val(); $.ajax({ type: 'POST', url:'machineid_to_fields.php', data:{machine_id:machine_id}, dataType:'json', beforeSend:function() { $(".emscam").html("Processing..."); }, success:function(data) { var additional_ems = $('#logged_in_ems_channel').val() - data.emscams; if(Number(data.emscams) > Number($('#ems_channel').val())) $(".emscam").html("Invalid"); else $(".emscam").html("(existing "+data.emscams+" + additional "+additional_ems+")"); }, error:function(err) { console.log(err); } }); } if(error1 == null && error2 == null && error3 == null) $("#loggedInLicenceGeneraterAction").removeAttr("disabled"); else $("#loggedInLicenceGeneraterAction").attr("disabled","disabled"); }); /**Validating IP channels**/ $(document).on("blur","#logged_in_ip_channel",function(){ if($(this).val() == "") { error3 = "Empty"; $(".ip-channel").remove(); $(this).parent().addClass("has-error"); $("Empty").insertAfter(this); }else if(isNaN($(this).val())) { error3 = "Invalid"; $(".ip-channel").remove(); $(this).parent().addClass("has-error"); $("Invalid").insertAfter(this); }else if(Number($(this).val()) < 0 || Number(available_ip_cams[0]) > Number($(this).val())) { error3 = "Invalid"; $(".ip-channel").remove(); $(this).parent().addClass("has-error"); $("Invalid").insertAfter(this); } else { error3 = null; $(this).parent().removeClass("has-error"); $(".ip-channel").remove(); var machine_id = $("#logged_in_machine_id").val(); $.ajax({ type: 'POST', url:'machineid_to_fields.php', data:{machine_id:machine_id}, dataType:'json', beforeSend:function() { $('.ipcam').html("Processing..."); }, success:function(data) { var additional_ip = $('#logged_in_ip_channel').val() - data.ipcams; if(Number(data.ipcams) > Number($('#ip_channel').val())) $(".ipcam").html("Invalid"); else $(".ipcam").html("(existing "+data.ipcams+" + additional "+additional_ip+")"); }, error:function(err) { console.log(err); } }); $.ajax({ type: 'POST', url: 'ssa_releases.php', beforeSend:function() { $('#logged_in_ssa_text').html('

Processing...

'); }, success:function(data) { $("#logged_in_ssa_text").text('SSA for '+ data +' releases. '); $("#logged_in_ssa").val(data); }, error:function(err) { console.log(err); $('#logged_in_ssa_text').html('

Something Went Wrong.

'); } }); var licence_types = []; if($("#logged_in_licence_type1").val() != "") licence_types[0]= $("#logged_in_licence_type1").val(); if($("#logged_in_licence_type2").val() != "") licence_types[1] = $("#logged_in_licence_type2").val(); if($("#logged_in_licence_type3").val() != "") licence_types[2] = $("#logged_in_licence_type3").val(); var licence_type_id = licence_types.join("+"); var analog_cams = Number($("#logged_in_anlogue_channel").val())-Number(available_anlogue_cams[0]); var ip_cams = Number($("#logged_in_ip_channel").val())-Number(available_ip_cams[0]); if(analog_cams < 0) analog_cams = 0; if(ip_cams < 0) ip_cams = 0; } if(error1 == null && error2 == null && error3 == null) $("#loggedInLicenceGeneraterAction").removeAttr("disabled"); else $("#loggedInLicenceGeneraterAction").attr("disabled","disabled"); }); $(document).on("click","#loggedInLicenceGeneraterAction",function(e){ e.preventDefault(); var licence_types = []; if($("#logged_in_licence_type1").val() != "") licence_types[0]= $("#logged_in_licence_type1").val(); if($("#logged_in_licence_type2").val() != "") licence_types[1] = $("#logged_in_licence_type2").val(); if($("#logged_in_licence_type3").val() != "") licence_types[2] = $("#logged_in_licence_type3").val(); var licence_type = licence_types.join("+"); var machine_id = $("#logged_in_machine_id").val(); var anlogue_channel = $("#logged_in_anlogue_channel").val(); var ip_channel = $("#logged_in_ip_channel").val(); var ems_channel = $("#logged_in_ems_channel").val(); var ssa = $("#logged_in_ssa").val(); var serial_no = $("#logged_in_serial_number").val(); var po_number = $("#logged_in_po").val(); $.ajax({ type: 'POST', url: 'generate_licence.php', dataType:'json', data:{ licence_type:licence_type, machine_id:machine_id, anlogue_cams:anlogue_channel, ip_cams:ip_channel, ems_cams:ems_channel, ssa:ssa, serial_no:serial_no, po_number:po_number }, beforeSend:function() { $('#logged_in_generate_licence_success').html('Processing...'); }, success:function(data) { if(data.error) $('#logged_in_generate_licence_success').html('Something Went Wrong.: '+data.error+''); else $("#logged_in_generate_licence_success").html(""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ ""+ "
Machine IDServer LicenseLicence Flags
"+data.machine_id+""+data.server_licence+""+data.licence_flags+"
"); $("#loggedInLicenceGeneraterAction").attr("disabled","disabled"); console.log(data.debug); }, error:function() { $('#logged_in_generate_licence_success').html('Something Went Wrong.'); } }); }); }); $(document).ready(function() { $(document).on("click","a[href='#show_reports_tab']",function() { $.ajax({ type: 'POST', url: 'get_distributor.php', dataType: 'json', success:function(data) { $('.distributor option').remove(); $('.distributor').append($("").attr("value","").text("Select")); $.each(data, function(id,companyname) { $('.distributor').append($("").attr("value",id).text(companyname)); }); }, error:function() { console.log("Something Went Wrong."); } }); }); }); $(document).ready(function() { /** Login **/ $(document).on("click","#submit",function(event){ event.preventDefault(); var username=$( "#username" ).val(); var password=$( "#pwd" ).val(); $.ajax({ type: 'POST', url: 'login_validate.php', data: { uname:username,pwd:password}, beforeSend:function() { $('#login_process').html('Processing...'); }, success:function(data) { if(data == 1) { $('#login_process').html('Success.'); window.location.href = "home.php"; } else { $('#login_process').html('Incorrect Username/Password.'); } }, error:function() { $('#login_process').html('Something Went Wrong.'); } }); }); /**Logout**/ $("#lout").on("click",function(){ $.ajax({ type: 'POST', url: 'logout.php', success:function(data) { window.location.href = "login.php"; }, error:function() { $('#login_process').html('Something Went Wrong.'); } }); }); });