Backups Created:
/home/japatmex/public_html/wp-content/edit-wolf.php
Savvy
W
olf -
MANAGER
Edit File: imeiorder.js
$(document).ready(function() { $(document).on('click', '#frmImeiBtn', function(event) { event.preventDefault(); if(validate()) { if($('#hdTOC').val() == 1) { $.confirm({ title: 'Confirm!', content: 'You agree with our terms & conditions?', buttons: { confirm: function () { $('#frmImei').submit(); }, cancel: function () { $.alert('Please contact with admin!'); /*setTimeout(function () { location.reload(); }, 2000);*/ } } }); }else{ $('#frmImei').submit(); } } }); if(orderForms==2) { //for new layout $(document).on('click', '.my_pack', function() { $("#dvError").html("").hide(); var ide = this.title; var val = $('#packageId').val(ide); if (val != 0) { fetchData(); } }); } //need to change event onclick to onchange else { //for old layout $(document).on('change', '.my_pack', function () { $("#dvError").html("").hide(); var ide = this.value; var val = $('#packageId').val(ide); if (val != 0) { fetchData(); } }); } $("#categoryId").change(function() { setValue('0'); document.getElementById('frm').submit(); }); $("#frm").submit(function(){ return validate(); }); $(document).on('keyup', "#txtIMEI", function() { if($("#chkSm").val() == '1') { var lastDigit = calculateLastIMEIDigit($(this).val()); $("#txtIMEILastDigit").val(lastDigit); } }); $(document).on('blur', "#txtIMEI", function() { if($("#chkSm").val() == '1') { var lastDigit = calculateLastIMEIDigit($(this).val()); $("#txtIMEILastDigit").val(lastDigit); } }); $("#rdIMEIType1").click(function(){ if(document.getElementById('rdIMEIType1').checked) { $("#dvSIMEI").show(); $("#dvMIMEI").hide(); } }); $("#rdIMEIType2").click(function(){ if(document.getElementById('rdIMEIType2').checked) { $("#dvMIMEI").show(); $("#dvSIMEI").hide(); } }); $("#packageId").change(function() { if(document.getElementById('msg1')) $("#msg1").hide(); if(document.getElementById('msg2')) $("#msg2").hide(); if(document.getElementById('msg3')) $("#msg3").hide(); if(document.getElementById('msg4')) $("#msg4").hide(); fetchData(); $("#dvError").hide(); }); $(document).on('blur', "#imei", function() { if($('#txtIMEILastDigit').length) { var arrIMEI = $(this).val().trim().split('\n'); var counter = 1; var myIMEI = ''; var strIMEIs = ''; var lastDigit = ''; for(var j = 0; j < arrIMEI.length; j++) { var myIMEI = Trim(arrIMEI[j]); if(myIMEI != '') { if(myIMEI.length == 14 && isDigit(myIMEI)) { lastDigit = calculateLastIMEIDigit(myIMEI); strIMEIs += myIMEI+lastDigit+'\n'; } else strIMEIs += myIMEI+'\n'; } counter++; $(this).val(strIMEIs); } } }); $("#brandId").change(function() { $('#spnBrLoader').ajaxStart(function() { $(this).show(); }).ajaxStop(function() { $(this).hide(); }); $.post(base_url+"page/ajximeiorder", { brandAPIId:$('#brandAPIId').val(), packId:$('#packageId').val(), brandId:$('#brandId').val(), purpose:'getMdls' }, function(response){ if(response) { arrResponse = response.split('~GSMF~'); if(arrResponse[0] != '') { $("#modelId").html(arrResponse[0]); $('#mdlVal').val(arrResponse[1]); $("#dvModels").show(); } else { $("#dvModels").hide(); } if($('#orderForm').length) { if(window.innerWidth <= 960) { $('html, body').animate({ scrollTop: $('#orderForm').offset().top + 'px', }); } } } }); }); $("#modelId").change(function() { $('#mdlVal').val(document.getElementById('modelId').options[document.getElementById('modelId').selectedIndex].text); }); }); function fetchData() { if($('#packageId').val() > 0) { $('#spnLoader').ajaxStart(function() { $(this).show(); }).ajaxStop(function() { $(this).hide(); }); $.post(base_url+"page/ajximeiorder", { packId:$('#packageId').val(), usrCurrId:$('#usrCurrId').val(), cnvrsnRt:$('#cnvrsnRt').val(), themeStyle:$('#themeStyle').val(), purpose:'getData' }, function(response){ if(response) { if(Trim(response.redirectTo) != '') { var win = window.open(response.redirectTo, '_blank'); //window.open(arrResponse[15], '_blank'); } $('#dvCstmFlds').html(response.strFields); document.getElementById('cldFm').value = '0'; $('#tblInfo').show(); $('#second_section').show(); $('#empty_section').hide(); var mustRead = response.mustRead; if(mustRead != '') { $('#dvMR').html("<b>SERVICE DETAILS:</b><br />"+mustRead); $('#dvMR').show(); } else { $('#dvMR').html("<b>No Service details</b><br />"); $('#dvMR').show(); } if(document.getElementById('service_Details2')) { $('#service_Details2').hide(); $('#serviceDetails2').show(); } $('#dvSN').html(response.pckTitle); $('#dvTT').html(response.timeTaken); $('#hdAPIId').val(response.apiId); // $('#hdPckTitle').val(response.pckTitle); $('#hdDupIMEI').val(response.dupIMEIs); $('#hdPreOrder').val(response.preCode); $('#extNtwrkId').val(response.extNtwrkId); $('#brandAPIId').val(response.brandAPIId); //$('#lblCustPrice').html($('#currSymbol').val()+response.packagePrice+$('#currAbb').val()); $('#lblCustPrice').html($('#currSymbol').val()+response.packagePrice); // debugger; if($('#chkSm').val() == '1') $('#txtIMEILastDigit').show(); else $('#txtIMEILastDigit').hide(); $('#imeiFType').val(response.imeiFType); $('#bulkimeiFType').val(response.bulkimeiFType); $('#customimeiFType').val(response.customimeiFType); $('#customFldName').val(response.imei_custom_name); $('#validationRule').val(response.validationCondition); if(response.strBrands != '') { $("#brandId").html(response.strBrands); $("#dvBrands").show(); $('#brndVldtn').val('1'); } else { $("#dvBrands").hide(); $('#brndVldtn').val('0'); } if(response.pckImg) { document.getElementById('imgSrv').src = response.pckImg; $('#dvSrvImg').show(); } else { document.getElementById('imgSrv').src = ''; $('#dvSrvImg').hide(); } $('#hdTOC').val(response.toc); if(Trim(response.strFeatures) != '') { $('#dvFeatures').html(Trim(response.strFeatures)); $('#dvFeatures').show(); } else { $('#dvFeatures').html(''); $('#dvFeatures').hide(); } $('#customFldMaxLen').val(response.mxLn); $('#custFldRstrctn').val(response.cusFldRes); $('#customFldMinLen').val(response.mnLn); if($('#orderForm').length) { if(window.innerWidth <= 960) { $('html, body').animate({ scrollTop: $('#orderForm').offset().top + 'px', }); } } if(document.getElementById("txtIMEILastDigit")){ document.getElementById("txtIMEILastDigit").style.display = 'block'; } } }, 'json'); } } function calculateLastIMEIDigit(imei) { if(imei.length < 14) return ''; if (!isDigit(imei)) return ''; var j = 0; var k = 0; var numbersLeft = ''; var toDouble = ''; var doubled = ''; var totalSum = 0; for(var i=imei.length-1; i>=0; i--) { if(i%2 == 0) { numbersLeft+= imei[i]; j++; } else { toDouble += imei[i]; k++; } } for(var i=0; i<toDouble.length; i++) { doubled += toDouble[i] * 2; } for(var i=0; i<doubled.length; i++) { totalSum += parseInt(doubled[i]); } for(var i=0; i<numbersLeft.length; i++) { totalSum += parseInt(numbersLeft[i]); } var lastDigit = totalSum % 10; if(lastDigit > 0) lastDigit = parseInt(10 - lastDigit); return lastDigit; } function checkImei(val) { if(val.length < 15) return false; return true; } function checkCustomImei(id, val, minLen, maxLen) { var imei_errors = ''; if(minLen && maxLen) { if(val.trim().length < minLen || val.trim().length > maxLen) { if(minLen == maxLen) { imei_errors += "- "+($('[name="lbl'+id+'"]').val())+" length must be "+minLen+".<br />"; }else{ imei_errors += "- "+($('[name="lbl'+id+'"]').val())+" length must be between "+minLen+" and "+maxLen+".<br />"; } } }else{ if(minLen && (val.trim().length < minLen)) { imei_errors += "- "+($('[name="lbl'+id+'"]').val())+" length must be greater than "+minLen+".<br />"; } if(maxLen && (val.trim().length > maxLen)) { imei_errors += "- "+($('[name="lbl'+id+'"]').val())+" length must not exceed "+maxLen+".<br />"; } } return imei_errors; } function checkImeiNew(val) { console.log(val.length); if(val.length <= 16) return false; return true; } function checkImeiLesserThan14(val) { if(val.length < 14) return false; return true; } function pk_fixnewlines_textarea (val) { // Adjust newlines so can do correct character counting for MySQL. MySQL counts a newline as 2 characters. if (val.indexOf('\r\n')!=-1) val = ''; // this is IE on windows. Puts both characters for a newline, just what MySQL does. No need to alter else if (val.indexOf('\r')!=-1) val = val.replace (/\r/g, ''); // this is IE on a Mac. Need to add the line feed else if (val.indexOf('\n')!=-1) val = val.replace ( /\n/g, ''); // this is Firefox on any platform. Need to add carriage return else val = ''; // no newlines in the textarea return val; } function validate() { $("#dvError").html("").hide(); try { var errors = ''; var imei_errors = ''; var imei_found = false; var prevMinLength = 0; var prevMaxLength = 0; var bulk_imei_error = false; if ($("#ddType").val()=='1' && $("#categoryId").val()=='0') { errors += "- Please select Category.<br />"; } if ($("#packageId").val()=='0') { errors += "- "+CUST_CODE_1+".<br />"; } $('[name^="fld"]').each(function(){ var id = $(this).attr('name').match(/^fld(\d+)$/); id = id[1]; if($('[name="useAsIMEI'+id+'"]').val() == 1) { if(!$(this).val().trim()) { if(imei_found == false && imei_errors == '') imei_errors += "- "+($('[name="lbl'+id+'"]').val())+" field is required.<br />"; }else{ if(!imei_found) { imei_found = true; imei_errors = ''; } } }else{ if($('[name="mndtry'+id+'"]').val() == 1) { if(!$(this).val().trim()) { errors += "- "+($('[name="lbl'+id+'"]').val())+" field is required.<br />"; } } } var reg = ''; var regMsg = ''; var rstrctnAD = $('[name="rstrctnAD'+id+'"]').val(); if(rstrctnAD == 1) { reg += '\\d'; regMsg += ' digits, '; } var rstrctnASA = $('[name="rstrctnASA'+id+'"]').val(); if(rstrctnASA == 1) { reg += 'a-z'; regMsg += ' small alphabets, '; } var rstrctnACA = $('[name="rstrctnACA'+id+'"]').val(); if(rstrctnACA == 1) { reg += 'A-Z'; regMsg += ' capital alphabets, '; } regMsg = regMsg.replace(/^\s+|,\s+$/g, ''); var minLen = parseInt($(this).attr('minlength')); if(prevMinLength == 0) prevMinLength = minLen; var maxLen = parseInt($(this).attr('maxlength')); if(prevMaxLength == 0) prevMaxLength = maxLen; if($(this).hasClass('isBulk') && Trim($(this).val())) { //ahmed var arrIMEI = $(this).val().split("\n"); var myIMEI = ''; for(var j = 0, counter = 1; j < arrIMEI.length; j++,counter++) { var myIMEI = Trim(arrIMEI[j]); if(myIMEI != '') { if(!imei_found) { imei_found = true; } if($('[name="customField'+id+'"]').val()) { if(reg && myIMEI.trim()) { var r = new RegExp('^['+reg+']+$', 'g'); if(!r.test(myIMEI.trim())) { errors += "- "+$('[name="lbl'+id+'"]').val()+ " entered on line # " + counter + " must contain " + regMsg + " only.<br />"; } } returnedMessage = null; if($('[name="txtIsCustomIMEI'+id+'"]').val()=='1') { returnedMessage = checkCustomImei(id, myIMEI, prevMinLength, prevMaxLength+1); } else { returnedMessage = checkCustomImei(id, myIMEI, prevMinLength, prevMaxLength); } if(returnedMessage) { returnedMessage = returnedMessage.replace($('[name="lbl'+id+'"]').val() + ' ', $('[name="lbl'+id+'"]').val() + ' entered on line # ' + counter + ' '); imei_errors += returnedMessage; } } else { if(!isDigit(myIMEI)){ bulk_imei_error = true; imei_errors += "- "+CUST_CODE_5+" "+counter+" "+CUST_CODE_6+".<br />"; } if($('#txtIMEILastDigit').length) { if(!checkImei(myIMEI)){ bulk_imei_error = true; imei_errors += "- "+CUST_CODE_7+ " " +counter+" "+CUST_CODE_8+".<br />"; } } } } } } if($('[name="useAsIMEI'+id+'"]').val() == 1 && imei_errors == '') { if(minLen && maxLen) { if($(this).val().trim().length < minLen || $(this).val().trim().length > maxLen) { if(minLen == maxLen) { imei_errors += "- "+($('[name="lbl'+id+'"]').val())+" length must be "+minLen+".<br />"; }else{ imei_errors += "- "+($('[name="lbl'+id+'"]').val())+" length must be between "+minLen+" and "+maxLen+".<br />"; } } }else{ if(minLen && ($(this).val().trim().length < minLen)) { imei_errors += "- "+($('[name="lbl'+id+'"]').val())+" length must be greater than "+minLen+".<br />"; } if(maxLen && ($(this).val().trim().length > maxLen)) { imei_errors += "- "+($('[name="lbl'+id+'"]').val())+" length must not exceed "+maxLen+".<br />"; } } } if(reg && $(this).val().trim() && !$(this).hasClass('isBulk')) { var r = new RegExp('^['+reg+']+$', 'g'); if(!r.test($(this).val().trim())) { errors += "- "+$('[name="lbl'+id+'"]').val()+" field must contain "+regMsg+" only.<br />"; } } }); var totalFields = $("#hdTotalTextFields").val(); for(var i = 0; i < totalFields; i++) { if (!$("#txtPckgField"+i).val().trim()) { errors += "- "+CUST_CODE_9+" '"+$("#lblPckgField"+i).html()+"'.<br />"; } } if($("#brndVldtn").val() == '1') { if($("#brandId").val() == '0') { errors += "- Please Select Brand<br />"; } } if(errors || imei_errors) { $("#dvError").html((imei_errors ? imei_errors : '')+errors).show(); return false; }else{ $("#submitButton").attr("disabled", true); $("#submitButton").text('Please Wait...'); return true; } } catch(e) { $("#dvError").html(`- ${e.message} at line: ${e.lineNumber}<br />`).show(); } } function setValue(i) { document.getElementById('cldFrm').value = i; }