|\x00-\x1F]~', '', $input); $input = preg_replace('/[^A-Za-z0-9._-]/', $replacement, $input); $input = preg_replace('/' . preg_quote($replacement, '/') . '+/', $replacement, $input); $input = trim($input, $replacement); if ($input === '') { return 'untitled'; } return $input; } function ReadTableData($path, $formFields, &$userData) { $success = false; TraceProgram(__FILE__, __FUNCTION__, __LINE__, "", TR_ENTRY); $path = @rtrim($path, "/"); $fqfnData = $path . '/' . 'data.txt'; if (file_exists($fqfnData)) { TraceProgram(__FILE__, __FUNCTION__, __LINE__, $fqfnData); $fh = fopen($fqfnData, "r"); while (!feof($fh)) { $line = trim(fgets($fh)); if ($line != "") { TraceProgram(__FILE__, __FUNCTION__, __LINE__, "$line"); $array = explode("=", $line, 2); $userData[$array[0]] = $array[1]; $success = true; } } fclose($fh); foreach ($formFields as $key => $value) { if ($value['FieldType'] == "pix") { if (isset($userData[$key])) { $fqfnPix = sprintf("%s/%s", $path, $userData[$key]); if ($userData[$key] == '') { // but maybe the file exists TraceProgram(__FILE__, __FUNCTION__, __LINE__, "fqfnPix: $fqfnPix, key: $key"); $candidates = glob($fqfnPix . $key . ".*"); TraceProgram(__FILE__, __FUNCTION__, __LINE__, print_r($candidates, true)); foreach ($candidates as $candidate) { TraceProgram(__FILE__, __FUNCTION__, __LINE__, $candidate); $userData[$key] = basename($candidate); } } $userData[$key] = (file_exists($fqfnPix)) ? $userData[$key] : ''; $success = true; } } } } else { TraceProgram(__FILE__, __FUNCTION__, __LINE__, "file '$fqfnData' does not exist."); } TraceProgram(__FILE__, __FUNCTION__, __LINE__, "", TR_EXIT); return $success; } function SaveTableData($path, $formFields, $formData) { TraceProgram(__FILE__, __FUNCTION__, __LINE__, "\nSaveTableData: " . print_r($formData, true), TR_ENTRY); $dataFile = $path . "/data.txt"; $fh = fopen($dataFile, "wt"); if ($fh) { foreach ($formFields as $key => $value) { fprintf($fh, "%s=%s\n", $key, isset($formData[$key]) ? $formData[$key] : $value['Default']); } fclose($fh); } TraceProgram(__FILE__, __FUNCTION__, __LINE__, "", TR_EXIT); } ?>