'NewHeaderForm', // must be unique 'ActionValue' => 'HeaderEdit', 'Field1Label' => 'New Header', 'Input1Name' => 'HeaderText', 'Field2Label' => 'Edit Header', 'Select1Name' => 'ExistingHeader', 'DocPath' => $HeadersPath, 'FormFields' => $HeaderFormFields, 'dbKey' => 'HeaderText', ]; EmitAdminFormType2($args); TraceProgram(__FILE__, __FUNCTION__, __LINE__, "", TR_EXIT); } // X Action=HeaderEdit // X HeaderText= // # SubHeaderText= // function ShowHeaderForm() { global $HeadersPath, $HeaderFormFields; global $ckEditor_FQFN, $allowedTypes, $UploadPath; global $CleanRequestData, $CleanFiles; TraceProgram(__FILE__, __FUNCTION__, __LINE__, "", TR_ENTRY); $actDelete = 'DeleteHeaderItem'; $FormData = array(); $Action = $CleanRequestData['Action'] ?? ''; $HeaderName = ''; // Form Submission could be new Header or edit existing $formSubmission = false; TraceProgram(__FILE__, __FUNCTION__, __LINE__, print_r($CleanRequestData, true)); if (isset($CleanRequestData['HeaderText']) && $CleanRequestData['HeaderText'] != "") { TraceProgram(__FILE__, __FUNCTION__, __LINE__, $CleanRequestData['HeaderText']); $HeaderName = $ProgramFolder = $CleanRequestData['HeaderText']; } else { $ProgramFolder = $CleanRequestData['ExistingHeader'] ?? ''; } $HeaderPath = $HeadersPath .'/'. MakeValidFolderName($ProgramFolder); TraceProgram(__FILE__, __FUNCTION__, __LINE__, "HeaderPath: '$HeaderPath'"); if (!is_dir($HeaderPath)) { if (mkdir($HeaderPath, 0777, true)) { TraceProgram(__FILE__, __FUNCTION__, __LINE__, "mkdir '$HeaderPath'"); } else { TraceProgram(__FILE__, __FUNCTION__, __LINE__, "Failed to mkdir '$HeaderPath'"); } } if ($Action == $actDelete) { $item = $CleanRequestData['Item'] ?? ''; $success = ReadTableData($HeaderPath, $HeaderFormFields, $evData); TraceProgram(__FILE__, __FUNCTION__, __LINE__, $success); TraceProgram(__FILE__, __FUNCTION__, __LINE__, print_r($evData, true)); $fqfn = $evData[$item]; $targetFile = $HeaderPath . '/' . $fqfn; TraceProgram(__FILE__, __FUNCTION__, __LINE__, "unlink '$targetFile'"); unlink($targetFile); echo "ok"; TraceProgram(__FILE__, __FUNCTION__, __LINE__, "", TR_EXIT); exit(); } if (($Action == 'HeaderEdit') && ($HeaderName != '')) { // Form Submission could be new header 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 ($HeaderFormFields[$fileKey]['FieldType'] == 'pix') { $targetFile = $HeaderPath . '/' . $filename; $un = $HeaderPath . '/' . $fileKey . ".*"; TraceProgram(__FILE__, __FUNCTION__, __LINE__, "unlink $un"); deleteFilesWithWildcard($HeaderPath, $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($HeaderFormFields[$key])) { TraceProgram(__FILE__, __FUNCTION__, __LINE__, "$key => $value"); $FormData[$key] = $value; $formSubmission = true; } } } if ($formSubmission) { SaveTableData($HeaderPath, $HeaderFormFields, $FormData); MoveFiles($UploadPath, $HeaderPath); } // Read the event file if it exists $success = ReadTableData($HeaderPath, $HeaderFormFields, $FormData); TraceProgram(__FILE__, __FUNCTION__, __LINE__, ($success) ? 'ReadTableData() success' : 'ReadTableData() fail'); EmitHTMLStart("Header Editor"); EmitBodyStart(); EmitPageHeader("Header Editor"); ?>