85 lines
2.0 KiB
PHP
85 lines
2.0 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
include "include/globals.php";
|
|
|
|
|
|
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
|
logExit("Session is not active",$moduleName);
|
|
exit();
|
|
}
|
|
|
|
// CSRF token validation
|
|
include "include/ajax.csrfToken.php";
|
|
|
|
|
|
$return_data = array();
|
|
|
|
$moduleName = "ajax.DataRecord.Fetch.php";
|
|
// startLog($moduleName);
|
|
|
|
// Get parameters
|
|
$table_name = db_escape_string($_GET['table_name']);
|
|
$record_num = $_GET['record_num'];
|
|
|
|
// Error logging
|
|
writeLog("school_num: $school_num\n");
|
|
writeLog("table_name: $table_name\n");
|
|
writeLog("record_num: $record_num\n");
|
|
|
|
|
|
// Validate parameters
|
|
if (strlen($table_name) == 0) logExit("Invalid Access\n");
|
|
|
|
|
|
// Ensure numeric parameters are numeric
|
|
if (!is_numeric($record_num)) logExit("Invalid Access\n");
|
|
|
|
|
|
$row = array();
|
|
|
|
// Get data record
|
|
switch ($table_name) {
|
|
case 'sms_gateways':
|
|
case 'language_text':
|
|
$query = "SELECT * FROM $table_name WHERE record_num = $record_num";
|
|
break;
|
|
|
|
default:
|
|
$query = "SELECT * FROM $table_name WHERE school_num = $school_num AND record_num = $record_num";
|
|
break;
|
|
}
|
|
writeLog("query: $query\n");
|
|
|
|
$results = db_query($query);
|
|
if (db_num_rows($results)) {
|
|
$row = db_fetch_assoc($results);
|
|
$row['ajax_return_code'] = 1;
|
|
|
|
//
|
|
// Get additional data if necessary
|
|
//
|
|
switch ($table_name) {
|
|
case 'staff':
|
|
if ($row['entry_type'] == 'Staff') {
|
|
$user_num = $row['user_num'];
|
|
$query = "SELECT type FROM users WHERE school_num = $base_school_num AND record_num = $user_num";
|
|
writeLog("query: $query\n");
|
|
$row['user_type'] = db_getVal($query);
|
|
}
|
|
break;
|
|
|
|
case 'schedule_times':
|
|
$row['start_date'] = substr($row['start_time'],0,10);
|
|
$row['start_time'] = date($school_record['time_format'],strtotime($row['start_time']));
|
|
$row['end_time'] = date($school_record['time_format'],strtotime($row['end_time']));
|
|
break;
|
|
}
|
|
}
|
|
else {
|
|
$row['ajax_return_code'] = 0;
|
|
}
|
|
|
|
echo(json_encode($row));
|
|
|
|
?>
|