225 lines
6.6 KiB
PHP
225 lines
6.6 KiB
PHP
<?php
|
|
require_once("include/globals.php");
|
|
|
|
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
|
header("Location: /");
|
|
exit();
|
|
}
|
|
|
|
|
|
// Start the template and output buffering
|
|
startTemplate();
|
|
$templatePageTitle = getLanguageText('TEXT-DELIVERY-LOCATIONS');
|
|
$headerArgs = "";
|
|
|
|
|
|
// Ensure that only valid user types have access to this module
|
|
$AllowedUserTypes = array('SuperUser','System Administrator');
|
|
if (checkPermission($AllowedUserTypes) != 1) {
|
|
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
|
$action = '';
|
|
$naction = '';
|
|
header("Location: /?action=$action&naction=$naction$headerArgs&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
|
|
exit();
|
|
}
|
|
|
|
?>
|
|
<script>
|
|
$(document).ready(function() {
|
|
|
|
<?php include "include/ajax.Setup.php" ?>
|
|
|
|
var tableName = "meal_locations";
|
|
var tableAction = "meal-locations";
|
|
var sequenceFlag = 'Y';
|
|
var tableID = "meal-locations-table";
|
|
|
|
$.ajaxSetup({ cache: false });
|
|
|
|
$("#data-dialog").dialog({
|
|
autoOpen: false,
|
|
minWidth: 400,
|
|
modal: true,
|
|
position: { my: 'center', at: 'center' }
|
|
});
|
|
|
|
$("#view-categories").hide();
|
|
|
|
// Load initial data set
|
|
loadData();
|
|
|
|
function loadData() {
|
|
loadDynamicData(tableName, tableAction, sequenceFlag, tableID, "");
|
|
}
|
|
|
|
$("#list-data").click(function(e) {
|
|
e.preventDefault();
|
|
loadData();
|
|
});
|
|
|
|
|
|
function loadDynamicData(table_name,action,sequence_flag,table_id,custom_data) {
|
|
$("#dynamic-table-div").html("<p><b>Loading...</b></p>");
|
|
|
|
// Format parameters
|
|
var data = "table_name="+table_name+
|
|
"&sequence_flag="+sequence_flag+
|
|
"&action="+action+
|
|
"&table_id="+table_id+
|
|
custom_data;
|
|
|
|
// Get data table
|
|
$.getJSON( "ajax.DataTable.Fetch.php",data,
|
|
function(results) {
|
|
$("#dynamic-table-div").html(results.content);
|
|
if (sequence_flag == 'Y') {
|
|
$("#"+table_id).tableDnD({
|
|
onDrop: function(table, row) {
|
|
var rows = table.tBodies[0].rows;
|
|
var data = "&table="+table_name+"&school_num=<?php echo($school_num) ?>";
|
|
for (var i=0; i<rows.length; i++) {
|
|
var rowid = rows[i].id;
|
|
data += "&row_ids[]="+rowid;
|
|
|
|
// Update row classes
|
|
$("#"+rowid).removeClass("data-even");
|
|
$("#"+rowid).removeClass("data-odd");
|
|
if (i % 2) $("#"+rowid).addClass("data-even");
|
|
else $("#"+rowid).addClass("data-odd");
|
|
}
|
|
$.ajax({
|
|
url: "ajax.SequenceRecords.php",
|
|
data: data
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
|
|
|
|
//
|
|
// Form actions
|
|
//
|
|
$("#insert-data").click(function(e) {
|
|
e.preventDefault();
|
|
|
|
// Display data
|
|
$("#location").val('');
|
|
$("#record_num").val(0);
|
|
$("#data-dialog").dialog("open");
|
|
});
|
|
|
|
$(document).on("click", ".edit-data", function(e) {
|
|
e.preventDefault();
|
|
|
|
var record_num = $(this).attr('rnum');
|
|
$.getJSON("ajax.DataRecord.Fetch.php",
|
|
{
|
|
table_name: tableName,
|
|
record_num: record_num
|
|
},
|
|
function(results) {
|
|
// Check for errors
|
|
if (results.ajax_return_code == 0) {
|
|
alert("<?php displayLanguageText('RECORD-NOT-FOUND-MSG'); ?>");
|
|
return;
|
|
}
|
|
|
|
// Display data
|
|
$("#location").val(results.location);
|
|
$("#record_num").val(results.record_num);
|
|
$("#data-dialog").dialog("open");
|
|
}
|
|
);
|
|
});
|
|
|
|
$(document).on("click", ".delete-data", function(e) {
|
|
e.preventDefault();
|
|
|
|
var dflag = $(this).attr('dflag');
|
|
if (dflag == 'N') {
|
|
alert("<?php displayLanguageText('TEXT-UNABLE-TO-DELETE-ENTRY'); ?>");
|
|
return;
|
|
}
|
|
|
|
var msg = "<?php displayLanguageText('TEXT-CONFIRM-DELETE'); ?>";
|
|
var ans = confirm(msg);
|
|
var record_num = $(this).attr('rnum');
|
|
|
|
if (ans) {
|
|
// Delete entry
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: "ajax.DataRecord.Delete.php",
|
|
data: { table_name: tableName, record_num: record_num }
|
|
}).done(function(data) {
|
|
// Display new data
|
|
loadData();
|
|
});
|
|
}
|
|
});
|
|
|
|
$("#cancelBtn").click(function(e) {
|
|
e.preventDefault();
|
|
$("#data-dialog").dialog("close");
|
|
});
|
|
|
|
$("#saveBtn").click(function(e) {
|
|
e.preventDefault();
|
|
saveFormData();
|
|
});
|
|
|
|
$("#dialogForm").submit(function(e) {
|
|
e.preventDefault();
|
|
saveFormData();
|
|
});
|
|
|
|
function saveFormData() {
|
|
// Save the form data
|
|
var record_num = $("#record_num").val();
|
|
var formdata = $("#dialogForm").serialize();
|
|
var data = formdata+"&table_name="+tableName+"&sequence_flag="+sequenceFlag+"&record_num="+record_num;
|
|
$.getJSON("ajax.DataRecord.Update.php", data,
|
|
function(results) {
|
|
$("#data-dialog").dialog("close");
|
|
|
|
// Display new data
|
|
loadData();
|
|
}
|
|
);
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
<div id='dynamic-table-div'></div>
|
|
|
|
<br>
|
|
<p><a href='#' id='insert-data' class='btn btn--primary>'><?php displayLanguageText('TEXT-INSERT-NEW'); ?></a></p>
|
|
|
|
<div id='data-dialog' title='<?php echo($templatePageTitle); ?>'>
|
|
<center>
|
|
<form id='dialogForm' method='post'>
|
|
<table width='100%' border='0'>
|
|
<tr>
|
|
<td align='left'>
|
|
<p class='align-left'><label for='location'><b><?php displayLanguageText('TEXT-ALTERNATE-LOCATION'); ?>:</b></label><br>
|
|
<input name='location' id='location' size='40' class="text ui-widget-content ui-corner-all"></p>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<button id='cancelBtn' class='btn btn--outline btn--xsmall'> <?php displayLanguageText('TEXT-CLOSE-WINDOW'); ?> </button>
|
|
<button id='saveBtn' class='btn btn--primary btn--xsmall'> <?php displayLanguageText('TEXT-INSERT'); ?> </button>
|
|
<input type='hidden' name='record_num' id='record_num'>
|
|
</form>
|
|
</center>
|
|
</div>
|
|
|
|
<?php
|
|
endTemplate();
|
|
?>
|