Initial checkin
This commit is contained in:
commit
954ef3d036
95 files changed
+43476
No files matched your search
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
|
||||
function EmitPlaceForm() {
|
||||
global $PlacesPath, $PlaceFormFields;
|
||||
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "", TR_ENTRY);
|
||||
$args = [
|
||||
'FormID' => 'NewHeaderForm', // must be unique
|
||||
'ActionValue' => 'PlaceEdit',
|
||||
'Field1Label' => 'New Place',
|
||||
'Input1Name' => 'PlaceName',
|
||||
'Field2Label' => 'Edit Place',
|
||||
'Select1Name' => 'ExistingPlace',
|
||||
'DocPath' => $PlacesPath,
|
||||
'FormFields' => $PlaceFormFields,
|
||||
'dbKey' => 'PlaceName',
|
||||
];
|
||||
EmitAdminFormType2($args);
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "", TR_EXIT);
|
||||
}
|
||||
|
||||
|
||||
// X Action=PlaceEdit
|
||||
// X PlaceName=<restaurant name>
|
||||
// # ExistingPlace=<restaurant name>
|
||||
//
|
||||
function ShowPlaceForm() {
|
||||
global $PlacesPath, $PlaceFormFields;
|
||||
global $ckEditor_FQFN, $allowedTypes, $UploadPath;
|
||||
global $CleanRequestData, $CleanFiles;
|
||||
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "", TR_ENTRY);
|
||||
$actDelete = 'DeletePlaceItem';
|
||||
$FormData = array();
|
||||
$Action = $CleanRequestData['Action'] ?? '';
|
||||
$PlaceName = '';
|
||||
// Form Submission could be new or edit existing
|
||||
$formSubmission = false;
|
||||
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, print_r($CleanRequestData, true));
|
||||
if (isset($CleanRequestData['PlaceName']) && $CleanRequestData['PlaceName'] != "") {
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, $CleanRequestData['PlaceName']);
|
||||
$PlaceName = $ProgramFolder = $CleanRequestData['PlaceName'];
|
||||
} else {
|
||||
$ProgramFolder = $CleanRequestData['ExistingPlace'] ?? '';
|
||||
}
|
||||
$PlacePath = $PlacesPath .'/'. MakeValidFolderName($ProgramFolder);
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "PlacePath: '$PlacePath'");
|
||||
if (!is_dir($PlacePath)) {
|
||||
if (mkdir($PlacePath, 0777, true)) {
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "mkdir '$PlacePath'");
|
||||
} else {
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "Failed to mkdir '$PlacePath'");
|
||||
}
|
||||
}
|
||||
|
||||
if ($Action == $actDelete) {
|
||||
$item = $CleanRequestData['Item'] ?? '';
|
||||
$success = ReadTableData($PlacePath, $PlaceformFields, $evData);
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, $success);
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, print_r($evData, true));
|
||||
$fqfn = $evData[$item];
|
||||
$targetFile = $PlacePath . '/' . $fqfn;
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "unlink '$targetFile'");
|
||||
unlink($targetFile);
|
||||
echo "ok";
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "", TR_EXIT);
|
||||
exit();
|
||||
}
|
||||
if (($Action == 'PlaceEdit') && ($PlaceName != '')) {
|
||||
// Form Submission could be new place or edit existing
|
||||
|
||||
// FILE Submissions
|
||||
foreach ($CleanFiles as $fileKey => $fileInfo) {
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "Check ". print_r($fileKey, true));
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "Check ". print_r($fileInfo, true));
|
||||
if (in_array($fileInfo['type'], array_keys($allowedTypes))) {
|
||||
$basename = basename($fileInfo['name']);
|
||||
$filename = $fileKey . $allowedTypes[$fileInfo['type']];
|
||||
if ($PlaceFormFields[$fileKey]['FieldType'] == 'pix') {
|
||||
$targetFile = $PlacePath . '/' . $filename;
|
||||
$un = $PlacePath . '/' . $fileKey . ".*";
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "unlink $un");
|
||||
deleteFilesWithWildcard($PlacePath, $fileKey . ".*");
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "target $targetFile");
|
||||
if (!is_uploaded_file($fileInfo['tmp_name']) || !@copy($fileInfo['tmp_name'], $targetFile)) {
|
||||
$err = error_get_last();
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, $err);
|
||||
} else {
|
||||
$FormData[$fileKey] = $filename;
|
||||
$formSubmission = true;
|
||||
}
|
||||
@unlink($fileInfo['tmp_name']);
|
||||
} else {
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "$basename not legitimate for a pix upload");
|
||||
}
|
||||
} else {
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "Nothing to upload");
|
||||
}
|
||||
}
|
||||
// Form Submissions
|
||||
foreach ($CleanRequestData as $key => $value) {
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "check $key");
|
||||
if (isset($PlaceFormFields[$key])) {
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "$key => $value");
|
||||
$FormData[$key] = $value;
|
||||
$formSubmission = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($formSubmission) {
|
||||
SaveTableData($PlacePath, $PlaceFormFields, $FormData);
|
||||
MoveFiles($UploadPath, $PlacePath);
|
||||
}
|
||||
|
||||
// Read the event file if it exists
|
||||
$success = ReadTableData($PlacePath, $PlaceFormFields, $FormData);
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, ($success) ? 'ReadTableData() success' : 'ReadTableData() fail');
|
||||
EmitHTMLStart("Place Editor");
|
||||
EmitBodyStart();
|
||||
EmitPageHeader("Place Editor");
|
||||
?>
|
||||
<form action='' method='post' id='PlaceForm' enctype='multipart/form-data' >
|
||||
<input type='hidden' name='Action' value='PlaceSubmit' />
|
||||
<?php
|
||||
$CK_EditorFieldIDs = EmitForm($PlaceFormFields, $FormData, $PlacePath, $PlaceName);
|
||||
?>
|
||||
</form>
|
||||
<script src='./inc/UploadPreview.js'></script>
|
||||
<script>
|
||||
async function DeletePix(event, item) {
|
||||
if (!confirm("Delete the " + item + " image?")) {
|
||||
return;
|
||||
}
|
||||
let currentURL = window.location.href;
|
||||
currentURL = currentURL.endsWith('?') ? currentURL.slice(0,-1) : currentURL;
|
||||
currentURL += "?Action=" + $actDelete + "&PlaceItem=" + event + "&Item=" + item;
|
||||
console.log("currentURL: " + currentURL);
|
||||
fetch(currentURL, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
})
|
||||
.then(response => {
|
||||
console.log('Success:');
|
||||
o = document.getElementById(item + "Preview");
|
||||
o.src = '';
|
||||
o.style.display = 'none';
|
||||
})
|
||||
.catch(error => console.error('Error:', error));
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
EmitBodyEnd();
|
||||
EmitHTMLEnd();
|
||||
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "", TR_EXIT);
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in new issue
Block a user