This is the use case
If above 4 dropdowns are selected and when the "Time Period" dropdown is clicked, AJAX call for the ajax.php with data parsing and if
any matches are found the user prompted to be redirected to the view/edit page
If the user has permission he can edit, unless he can view only
This goes in the hooks/table_name-dv.js
Code: Select all
$j('#time_period').on('click', function(){
load_details();
});
function load_details(){
if (($j('#time_period-container').select2('val') == '{empty_value}') || ($j('#province-container').select2('val') == '{empty_value}') || ($j('#district-container').select2('val') == '{empty_value}') || ($j('#hospital-container').select2('val') == '{empty_value}')){
$j('#cases').val('');
}else{
time_value = $j('#time_period').val();
province_value = $j('#province').val();
district_value = $j('#district').val();
hospital_value = $j('#hospital').val();
$j.ajax({
url: 'hooks/ajax.php',
data: { time_column : time_value , province_column : province_value , district_column : district_value , hospital_column : hospital_value},
success: function(data){
if (!$j.trim(data)) {
$j('#cases').val('');
}else{
alert ("Record Exists !!! Click OK to redirect to the record view page (If you have permission you can edit)");
window.location = "COVID_cases_view.php?SelectedID="+data;
}
}
});
}
}
Code: Select all
<?php
$currDir = dirname(__FILE__) . '/..';
include("$currDir/defaultLang.php");
include("$currDir/language.php");
include("$currDir/lib.php");
$time = makesafe($_REQUEST['time_column']);
$province = makesafe($_REQUEST['province_column']);
$district = makesafe($_REQUEST['district_column']);
$hospital = makesafe($_REQUEST['hospital_column']);
$sql = "SELECT id FROM covid_cases WHERE time_period = '{$time}' AND province = '{$province}' AND district = '{$district}' AND hospital = '{$hospital}'";
$data = sqlValue($sql);
echo $data;
?>