Get saved stock on page load + password protect

This commit is contained in:
keplyx 2019-08-01 10:34:45 +02:00
parent c4e6bd641b
commit 1e928ef85e
3 changed files with 33 additions and 12 deletions

View file

@ -1,5 +1,11 @@
<?php <?php
$relativePath = "../"; $relativePath = "../";
$file='../data/stock.json';
$fp = fopen($file, 'r');
$result = fread($fp,filesize($file));
fclose($fp);
ob_start(); ob_start();
?> ?>
<tr> <tr>
@ -63,6 +69,10 @@ ob_start();
</button> </button>
</div> </div>
<script type="text/javascript">
let json_dump = <?php echo $result; ?>;
</script>
</> </>

View file

@ -19,10 +19,20 @@ let defaultStock = [
]; ];
let currentDataset = []; let currentDataset = [];
let currentTypes = [];
function initValuesFromPHPDump() {
currentDataset = json_dump.articles; // json_dump is set using PHP
currentTypes = json_dump.types;
console.log(currentDataset);
console.log(currentTypes);
generateTable(currentDataset);
}
$(document).ready(function () { $(document).ready(function () {
currentDataset = defaultStock; initValuesFromPHPDump();
generateTable(currentDataset);
generateTypeCheckboxes(); generateTypeCheckboxes();
}); });
@ -57,12 +67,12 @@ function generateLine(item) {
} }
function generateTypeCheckboxes() { function generateTypeCheckboxes() {
for (let i = 0; i < defaultTypes.length; i++) { for (let i = 0; i < currentTypes.length; i++) {
let id = 'typeCheck_' + defaultTypes[i]; let id = 'typeCheck_' + currentTypes[i];
$('#typeCheckboxesCell').append( $('#typeCheckboxesCell').append(
'<div class="form-check">' + '<div class="form-check">' +
'<input type="checkbox" class="form-check-input" id="' + id + '">' + '<input type="checkbox" class="form-check-input" id="' + id + '">' +
'<label class="form-check-label" for="' + id + '">' + defaultTypes[i] + '</label>' + '<label class="form-check-label" for="' + id + '">' + currentTypes[i] + '</label>' +
'</div>' '</div>'
); );
} }
@ -119,19 +129,19 @@ function removeItemFromList(item) {
function getTypesChecked() { function getTypesChecked() {
let types = []; let types = [];
for (let i = 0; i < defaultTypes.length; i++) { for (let i = 0; i < currentTypes.length; i++) {
let id = 'typeCheck_' + defaultTypes[i]; let id = 'typeCheck_' + currentTypes[i];
if ($('#' + id).is(':checked')) { if ($('#' + id).is(':checked')) {
types.push(defaultTypes[i]); types.push(currentTypes[i]);
} }
} }
return types; return types;
} }
function setTypesChecked(types) { function setTypesChecked(types) {
for (let i = 0; i < defaultTypes.length; i++) { for (let i = 0; i < currentTypes.length; i++) {
let id = 'typeCheck_' + defaultTypes[i]; let id = 'typeCheck_' + currentTypes[i];
$('#' + id).prop('checked', types.indexOf(defaultTypes[i]) !== -1); $('#' + id).prop('checked', types.indexOf(currentTypes[i]) !== -1);
} }
return types; return types;
} }
@ -179,7 +189,7 @@ function isItemInputFilled() {
function saveDataset() { function saveDataset() {
let finalDataset = { let finalDataset = {
types: defaultTypes, types: currentTypes,
articles: currentDataset articles: currentDataset
}; };
console.log(finalDataset); console.log(finalDataset);

1
includes/.htpassadmin Normal file
View file

@ -0,0 +1 @@
bli:LFqJx9olAYDvk