'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= // # ExistingPlace= // 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"); ?>