4) $band = 17; else $band = 160; } // 3.5 or 3.8 MHz elseif (ereg('^3',$frequency)) { $band = 80; } // 7.0 or 7.1 MHz elseif (ereg('^7',$frequency)) { $band = 40; } // 10.1 MHz elseif (ereg('^10',$frequency)) { $band = 30; } // 14 MHz elseif (ereg('^14',$frequency)) { $band = 20; } // 21 MHz elseif (ereg('^21',$frequency)) { $band = 15; } // 24 MHz elseif (ereg('^24',$frequency)) { $band = 12; } // 28 MHz elseif (ereg('^28',$frequency)) { $band = 10; } // 29 MHz FM elseif (ereg('^29',$frequency)) { $band = 10; } // 50 MHz elseif (ereg('^50',$frequency)) { $band = 6; } else $band = 0; return $band; } // Function to read a Cabrillo file and insert each QSO into the database // Parameters: // $file - file pointer of Cabrillo file being read // $qso_count - (global) number of QSOs read // $connection - Database connection // $dxcallsign - FK to logbook function processCabrilloFile ($file, &$qso_count, $connection, $dxcallsign) { // Initialise the array $qso_data = array ('freq' => '', 'mode' => '', 'call' => ''); // Read the Cabrillo file until we reach the "CONTEST:" tag while (fscanf ($file,"%s %s",&$tag, &$value)) { if (!strcasecmp($tag, "CONTEST:")) { // Read the contest type so that we can parse the file $contest_type = $value; echo "

Cabrillo Contest type is $contest_type

\n"; break; } else // Continue until the CONTEST: tag is reached continue; } // Keep a count of the number of QSOs added to the database $qso_count = 0; // Read each line of the log file while ($s = fgets ($file,1024)) { $line = explode (' ', $s); // Skip Cabrillo header lines if (!strcasecmp($line[0], "QSO:")) { // Read one line of QSO data from the Cabrillo file readCabrilloQSO ($contest_type, $s, &$qso_data); } else // Continue reading until the "QSO" tag continue; // Convert frequency to band $band = convertFrequencyBand ($qso_data['freq']); // Trap unknown bands error if ($band == 0) { $freq = $qso_data['freq']; echo "

Error - Frequency to Band conversion failed - frequency: $freq

\n"; echo "

No QSOs loaded\n"; echo "

Return to Log Upload Page\n"; die(); } // Cabrillo logs contain mode as "CW/PH/RY" // Convert PH to SSB if (!strcasecmp($qso_data['mode'],"PH")) $qso_data['mode'] = 'SSB'; // Convert RY to DIG if (!strcasecmp($qso_data['mode'],"RY")) $qso_data['mode'] = 'DIG'; // Insert QSO into the database $query = "INSERT INTO qsos SET id = 0, " . "callsign = \"" . $qso_data['call'] . "\" , " . "op_mode = \"" . $qso_data['mode'] . "\" , " . "band = \"" . $band . "\" , " . "fk_dxstn = \"" . $dxcallsign . "\" "; if (!(@ mysql_query ($query, $connection))) showerror(); $qso_count++; } } //-------------------------------------------------------------------------------------------------------------------------------- // Function to read one line of QSO data from the AIF file // Parameters: // $string - first valid line from file ( or // $qso_data - array to put parsed data into // $band_found - boolean flag for tag // $freq_found - boolean flag for tag // $qsl_found - function readADIFQSO ($string, &$qso_data, &$band_found, &$freq_found) { $string = strtoupper ($string); // Read Callsign if ($s = stristr($string,"%s ", $length,$qso_data['call']); if ($values != 2) sscanf ($s, "%s ", $length,$dummy,$qso_data['call']); } // Read Band if ($s = stristr($string,"%s ", $length,$qso_data['band']); if ($values != 2) sscanf ($s, "%s ", $length,$dummy,$qso_data['band']); // Strip the 'M off e.g. 40M if (($pos = strpos ($qso_data['band'], 'M')) != NULL) $qso_data['band'][$pos] = ' '; } // Read Mode if ($s = stristr($string,"%s ", $length,$qso_data['mode']); if ($values != 2) sscanf ($s, "%s ", $length,$dummy,$qso_data['mode']); switch ($qso_data['mode']) { // Convert all Digital modes to 'DIG' case "PSK31": case "PSK63": case "BPSK31": case "BPSK63": case "RTTY": case "MFSK16": case "WSJT": case "FSK441": case "JT6M": $qso_data['mode'] = "DIG"; break; // Convert all Phone modes to SSB case "USB": case "LSB": case "AM": $qso_data['mode'] = "SSB"; break; case "FM": $qso_data['mode'] = "FM"; } //---------------------------------------------dok------------------------------------------------------------- // Read NAME if ($s = stristr($string,"%s ", $length,$qso_data['dok']); if ($values != 2) sscanf ($s, "%s ", $length,$dummy,$qso_data['dok']); } //---------------------------------------------loc------------------------------------------------------------- // Read NAME if ($s = stristr($string,"%s ", $length,$qso_data['loc']); if ($values != 2) sscanf ($s, "%s ", $length,$dummy,$qso_data['loc']); } //---------------------------------------------date------------------------------------------------------------- // Read NAME if ($s = stristr($string,"%s ", $length,$qso_data['date']); if ($values != 2) sscanf ($s, "%s ", $length,$dummy,$qso_data['date']); } //---------------------------------------------rst_send------------------------------------------------------------- // Read NAME if ($s = stristr($string,"%s ", $length,$qso_data['rst_send']); if ($values != 2) sscanf ($s, "%s ", $length,$dummy,$qso_data['rst_send']); } //---------------------------------------------rst_rcvd------------------------------------------------------------- // Read NAME if ($s = stristr($string,"%s ", $length,$qso_data['rst_rcvd']); if ($values != 2) sscanf ($s, "%s ", $length,$dummy,$qso_data['rst_rcvd']); } //---------------------------------------------%s ", $length,$time); if ($values != 2) sscanf ($s, "%s ", $length,$dummy,$time); } $qso_data['time'] = $time."00"; //--------------------------------------------------------------------------------------------------------------- } // Read Frequency (e.g. if Band is not present in the record) if (($s = stristr($string,"%s ", $length,$qso_data['freq']); if ($values != 2) sscanf ($s, "%s ", $length,$dummy,$qso_data['freq']); } } // Function to read an ADIF file and insert each QSO into the database function processADIFFile ($file, &$qso_count, $connection, $string, $dxcallsign) { $EOR = 0; $band_found = 0; $freq_found = 0; $blank_line = 1; $qso_data = array ('time' => '', 'rst_send' => '', 'rst_rcvd' => '', 'date' => '', 'loc' => '', 'dok' => '', 'band' => '', 'mode' => '', 'freq' => '', 'call' => ''); // Can enter this procedure with $string set to either which is a valid QSO // which needs to be processed or set to in which case we need to read any blank // lines until the first QSO if (stristr($string,"")) // Skip any blank lines while ($string == "\n" || $string == "\r\n") $string = fgets ($file, 1024); // process the first valid ADIF line readADIFQSO ($string, &$qso_data, &$band_found, &$freq_found);// while (($string = fgets ($file,1024))) { // Skip any blank lines if ($string == "\n" || $string == "\r\n") continue; while (!$EOR) { readADIFQSO ($string, &$qso_data, &$band_found, &$freq_found);// // Check for End of Record if (stristr($string,"")) $EOR = 1; else $string = fgets($file,1024); } // End of Record. If no data has been found then // convert the frequency to band if ($band_found == 0) // Convert the frequency to band $qso_data['band'] = convertFrequencyBand ($qso_data['freq']); // Insert QSO into the database $query = "INSERT INTO qsos SET id = 0, " . "callsign = \"" . $qso_data['call'] . "\" , " . "op_mode = \"" . $qso_data['mode'] . "\" , " . "band = \"" . $qso_data['band'] . "\" , " . "dok = \"" . $qso_data['dok'] . "\" , " . "loc = \"" . $qso_data['loc'] . "\" , " . "date = \"" . $qso_data['date'] . "\" , " . "rst_send = \"" . $qso_data['rst_send'] . "\" , " . "rst_rcvd = \"" . $qso_data['rst_rcvd'] . "\" , " . "time = \"" . $qso_data['time'] . "\" , " . "fk_dxstn = \"" . $dxcallsign . "\" "; $band_found = 0; $freq_found = 0; $EOR = 0; $qso_data[]=''; if (!(@ mysql_query ($query, $connection))) showerror(); $qso_count++; } } $uploaddir = 'h:/wamp/www/logauswertung/logs/'; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_FILES['userfile']['name'])) { } else { } // Start of Main Program $valid_file = 0; $file_type = "unknown"; // Record the start time of the script $start = microtime(); sscanf ($start,"%s %s",&$microseconds,&$seconds); $start_time = $seconds + $microseconds; // Read data posted from form $browser_name = $_FILES['userfile']['name']; $temp_name = $_FILES['userfile']['tmp_name']; $dxcallsign = $_POST['callsign']; // Connect to the database if (!($connection = @ mysql_connect ($hostName, $username, $password))) die ("Could not connect to database"); if (!mysql_select_db ($databaseName, $connection)) showerror(); echo ""; echo ""; echo ""; echo "Upload Log"; echo ""; echo ""; // Was a log file uploaded? if ($_FILES['userfile']['name']) { echo "

File Upload $browser_name

"; echo "

Filename - $browser_name\n"; echo "
DX Callsign - $dxcallsign\n"; // Open the log file if (!($file = fopen ($uploaddir .$_FILES['userfile']['name'], "r")))//uploaddir added die ("Could not open the log file $file\n"); //anderungen ende // Read the first line $string = fgets ($file, 1024); // Check that it is a Cabrillo File if (stristr($string, "START-OF-LOG:")) { // Process Cabrillo file processCabrilloFile ($file,&$qso_count, $connection, $dxcallsign); $file_type = "CABRILLO"; } // Check if it is an ADIF file elseif (stristr($string, "") || stristr($string,"") || stristr($string,"Error - Unable to upload file: $browser_name\n"; echo "

Invalid Cabrillo or ADIF file\n"; echo "

No QSOs loaded\n"; echo '

Return to Log Upload Page'; die(); } } // Record the end time of the script $end = microtime(); sscanf ($end,"%s %s",&$microseconds,&$seconds); $end_time = $seconds + $microseconds; // Calculate elapsed time for the script $elapsed = $end_time - $start_time; sscanf ($elapsed,"%5f", &$elapsed_time); // Determine the callsign for these logs $query = "SELECT dxcallsign from dxstation where id=$dxcallsign"; if (!($result = @ mysql_query ($query, $connection))) showerror(); $row = @ mysql_fetch_array ($result); $callsign = $row['dxcallsign']; echo "

File type loaded: $file_type"; echo "

A total of $qso_count QSOs were added to the database "; echo "for callsign $callsign

"; echo "Elapsed time = $elapsed_time seconds"; // Count the total number of QSOs in the database $query = "SELECT count(*) from qsos"; if (!($result = @ mysql_query ($query, $connection))) showerror(); $row = @ mysql_fetch_array ($result); $total_qso_count = $row['count(*)']; echo "

There are now $total_qso_count QSOs in the database

"; // Save details of the uploaded file $query = "INSERT INTO logfiles SET id = 0, " . "filename = \"" . $browser_name . "\" , " . "qsos = \"" . $qso_count . "\" , " . "filetype = \"" . $file_type . "\" , " . "loaded = NOW()"; if (!(@ mysql_query ($query, $connection))) showerror(); } else { // No file uploaded echo "

No file Uploaded

"; } echo 'Return to Log Upload Page

'; if (!mysql_close ($connection)) showerror(); echo ""; echo ""; ?>