Files
WTS-Public/inc/Editor_ProgChair.php
T
2026-10-27 20:22:37 -05:00

162 lines
5.6 KiB
PHP

<?php
function EmitProgChairForm() {
global $ProgChairPath, $ProgChairFormFields;
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "", TR_ENTRY);
$args = [
'FormID' => 'NewHeaderForm', // must be unique
'ActionValue' => 'ProgChairEdit',
'Field1Label' => 'New Prog Chair',
'Input1Name' => 'ProgramChair',
'Field2Label' => 'Edit Prog Chair',
'Select1Name' => 'ExistingProgChair',
'DocPath' => $ProgChairPath,
'FormFields' => $ProgChairFormFields,
'dbKey' => 'ProgramChair',
];
EmitAdminFormType2($args);
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "", TR_EXIT);
}
// X Action=ProgChairEdit
// X ProgramChair=<name>
// # ChairNotes=<notes>
//
function ShowProgChairForm() {
global $ProgChairPath, $ProgChairFormFields;
global $ckEditor_FQFN, $allowedTypes, $UploadPath;
global $CleanRequestData, $CleanFiles;
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "", TR_ENTRY);
$actDelete = 'DeleteProgChairItem';
$FormData = array();
$Action = $CleanRequestData['Action'] ?? '';
$ProgramChair = '';
// Form Submission could be new or edit existing
$formSubmission = false;
TraceProgram(__FILE__, __FUNCTION__, __LINE__, print_r($CleanRequestData, true));
if (isset($CleanRequestData['ProgramChair']) && $CleanRequestData['ProgramChair'] != "") {
TraceProgram(__FILE__, __FUNCTION__, __LINE__, $CleanRequestData['ProgramChair']);
$ProgramChair = $ProgramFolder = $CleanRequestData['ProgramChair'];
} else {
$ProgramFolder = $CleanRequestData['ExistingProgChair'] ?? '';
}
$ProgChairPath = $ProgChairPath . '/' . MakeValidFolderName($ProgramFolder);
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "ProgChairPath: '$ProgChairPath'");
if (!is_dir($ProgChairPath)) {
if (mkdir($ProgChairPath, 0777, true)) {
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "mkdir '$ProgChairPath'");
} else {
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "Failed to mkdir '$ProgChairPath'");
}
}
if ($Action == $actDelete) {
$item = $CleanRequestData['Item'] ?? '';
$success = ReadTableData($ProgChairPath, $ProgChairformFields, $evData);
TraceProgram(__FILE__, __FUNCTION__, __LINE__, $success);
TraceProgram(__FILE__, __FUNCTION__, __LINE__, print_r($evData, true));
$fqfn = $evData[$item];
$targetFile = $ProgChairPath . '/' . $fqfn;
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "unlink '$targetFile'");
unlink($targetFile);
echo "ok";
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "", TR_EXIT);
exit();
}
if (($Action == 'ProgChairEdit') && ($ProgramChair != '')) {
// Form Submission could be new ProgChair or edit existing
// check FILES and then form fields
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 ($ProgChairFormFields[$fileKey]['FieldType'] == 'pix') {
$targetFile = $ProgChairPath . '/' . $filename;
$un = $ProgChairPath . '/' . $fileKey . ".*";
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "unlink $un");
deleteFilesWithWildcard($ProgChairPath, $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 items
foreach ($CleanRequestData as $key => $value) {
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "check $key");
if (isset($ProgChairFormFields[$key])) {
TraceProgram(__FILE__, __FUNCTION__, __LINE__, "$key => $value");
$FormData[$key] = $value;
$formSubmission = true;
}
}
}
if ($formSubmission) {
SaveTableData($ProgChairPath, $ProgChairFormFields, $FormData);
MoveFiles($UploadPath, $ProgChairPath);
}
// Read the event file if it exists
$success = ReadTableData($ProgChairPath, $ProgChairFormFields, $FormData);
TraceProgram(__FILE__, __FUNCTION__, __LINE__, $success);
EmitHTMLStart("ProgChair Editor");
EmitBodyStart();
EmitPageHeader("ProgChair Editor");
?>
<form action='' method='post' id='ProgChairForm' enctype='multipart/form-data' >
<input type='hidden' name='Action' value='ProgChairEdit' />
<?php
$CK_EditorFieldIDs = EmitForm($ProgChairFormFields, $FormData, $ProgChairPath, $ProgramChair);
?>
</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 + "&ProgChairItem=" + 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);
}
?>