%s ", $length,$qso_data['MyCallsign']); $qso_data['MyCallsign'] = substr($qso_data['MyCallsign'],0,$length); if ($values != 2){ sscanf ($s, "%s ", $length,$dummy,$qso_data['MyCallsign']); $qso_data['MyCallsign'] = substr($qso_data['MyCallsign'],0,$length); } } else { $qso_data['MyCallsign'] = $_POST['opcallsign']; } // Read Date if ($s = stristr($string,"%s ", $length,$qso_data['Date']); $qso_data['Date'] = substr($qso_data['Date'],0,$length); if ($values != 2){ sscanf ($s, "%s ", $length,$dummy,$qso_data['Date']); $qso_data['Date'] = substr($qso_data['Date'],0,$length); } } // Read Time if ($s = stristr($string,"%s ", $length,$qso_data['Time']); $values = sscanf ($s, "%s ", $length,$temp_time); $temp_time = substr($temp_time,0,$length); if (strlen($temp_time) == 4){ $qso_data['Time'] = $temp_time ."00"; } else { $qso_data['Time'] = $temp_time; } if ($values != 2) sscanf ($s, "%s ", $length,$dummy,$temp_time); $temp_time = substr($temp_time,0,$length); if (strlen($temp_time) == 4){ $qso_data['Time'] = $temp_time ."00"; } else { $qso_data['Time'] = $temp_time; } } // Read Callsign if ($s = stristr($string,"%s ", $length,$qso_data['Callsign']); $qso_data['Callsign'] = substr($qso_data['Callsign'],0,$length); if ($values != 2){ sscanf ($s, "%s ", $length,$dummy,$qso_data['Callsign']); $qso_data['Callsign'] = substr($qso_data['Callsign'],0,$length); } } // Read Band if ($s = stristr($string,"%s ", $length,$qso_data['Band']); $qso_data['Band'] = substr($qso_data['Band'],0,$length); if ($values != 2){ sscanf ($s, "%s ", $length,$dummy,$qso_data['Band']); $qso_data['Band'] = substr($qso_data['Band'],0,$length); } // Strip the 'M off e.g. 40M if (($pos = strpos ($qso_data['Band'], 'M')) != NULL) $qso_data['Band'][$pos] = ' '; } // Read Frequency (e.g. if Band is not present in the record) if ($s = stristr($string,"%s ", $length,$qso_data['Frequency']); $qso_data['Frequency'] = substr($qso_data['Frequency'],0,$length); if ($values != 2){ sscanf ($s, "%s ", $length,$dummy,$qso_data['Frequency']); $qso_data['Frequency'] = substr($qso_data['Frequency'],0,$length); } } // Read Mode if ($s = stristr($string,"%s ", $length,$qso_data['Mode']); $qso_data['Mode'] = substr($qso_data['Mode'],0,$length); if ($values != 2){ sscanf ($s, "%s ", $length,$dummy,$qso_data['Mode']); $qso_data['Mode'] = substr($qso_data['Mode'],0,$length); } switch ($qso_data['Mode']) { // Convert all Phone modes to SSB case "USB": case "LSB": $qso_data['Mode'] = "SSB"; break; } } // read propagation mode if ($s = stristr($string,"%s ", $length,$qso_data['Prop_Mode']); $qso_data['Prop_Mode'] = substr($qso_data['Prop_Mode'],0,$length); if ($values != 2){ sscanf ($s, "%s ", $length,$dummy,$qso_data['Prop_Mode']); $qso_data['Prop_Mode'] = substr($qso_data['Mode'],0,$length); } } // Read RSTS if ($s = stristr($string,"%s ", $length,$qso_data['RSTS']); $qso_data['RSTS'] = substr($qso_data['RSTS'],0,$length); if ($values != 2){ sscanf ($s, "%s ", $length,$dummy,$qso_data['RSTS']); $qso_data['RSTS'] = substr($qso_data['RSTS'],0,$length); } } // Read RSTR if ($s = stristr($string,"%s ", $length,$qso_data['RSTR']); $qso_data['RSTR'] = substr($qso_data['RSTR'],0,$length); if ($values != 2){ sscanf ($s, "%s ", $length,$dummy,$qso_data['RSTR']); $qso_data['RSTR'] = substr($qso_data['RSTR'],0,$length); } } } // Function to read an ADIF file and insert each QSO into the database function processADIFFile ($file, &$qso_count,$connection, $string, $dxcallsign, $usertable) { global $wpdb; $EOR = 0; $band_found = 0; $freq_found = 0; $blank_line = 1; $qso_data = array ('MyCallsign' => '', 'Date' => '', 'Time' => '', 'Callsign' => '', 'Band' => '', 'Frequency' => '', 'Mode' => '', 'Prop_Mode' => '', 'RSTS' => '', 'RSTR' => ''); 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); // Insert ref data into database if ($_POST['reference_number'] != NULL){ if ($_REQUEST['reference_id'] != NULL ) { $refid = $_REQUEST['reference_id']; } else { $refquery="INSERT INTO ".$wpdb->prefix."logbookRef (refnumber,refdescription) VALUES ('$_REQUEST[reference_number]','$_REQUEST[reference_description]')"; $wpdb->query($refquery); $refid = $wpdb->insert_id; } } $booksquery = "INSERT INTO ".$wpdb->prefix."logbookBooks SET " . "uploadDate = \"" . date(DATE_RFC822) . "\" , " . "refid = \"" . $refid . "\" "; $wpdb->query($booksquery); $booksid = $wpdb->insert_id; while (($string = fgets ($file,1024))) { // Skip any blank lines if ($string == "\n" || $string == "\r\n") continue; while (!$EOR) { readADIFQSO ($string, &$qso_data); // Check for End of Record if (stristr($string,"")) $EOR = 1; else $string = fgets($file,1024); } // Insert QSO into the database $query = "INSERT INTO ".$wpdb->prefix."logbook SET " . "MyCallsign = \"" . $qso_data['MyCallsign'] . "\" , " . "Date = \"" . $qso_data['Date'] . "\" , " . "Time = \"" . $qso_data['Time'] . "\" , " . "CallSign = \"" . $qso_data['Callsign'] . "\" , " . "Band = \"" . $qso_data['Band'] . "\" , " . "Frequency = \"" . $qso_data['Frequency'] . "\" , " . "Mode = \"" . $qso_data['Mode'] . "\" , " . "Prop_Mode = \"" . $qso_data['Prop_Mode'] . "\" , " . "RSTS = \"" . $qso_data['RSTS'] . "\" , " . "RSTR = \"" . $qso_data['RSTR'] . "\" , " . "refid = \"" . $refid . "\" , " . "booksid = \"" . $booksid . "\" "; $result = $wpdb->query($query); $band_found = 0; $freq_found = 0; $EOR = 0; $qso_data[]=''; $qso_count++; } } // Start of Main Program $valid_file = 0; $file_type = "unknown"; $qso_count = 0; // 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['Filename']['name']; $temp_name = $_FILES['Filename']['tmp_name']; if ($_REQUEST['upload']) { // Was a log file uploaded? if (is_uploaded_file ($temp_name)) { // Open the log file if (!($file1 = fopen ($temp_name, "r"))) die ("Could not open the log file $file\n"); // Check if ADIF or form contains a callsign if (empty($_POST['opcallsign'])){ $callsign_empty = 0; while ($string1 = fgets ($file1, 1024)) { if (stristr($string1,"") || stristr($string,"") || stristr($string,"Error - Unable to upload file: $browser_name\n"; echo "

Invalid ADIF file\n"; echo "

No QSOs loaded\n"; 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 echo "

"; echo "

Number of QSO's Added to the Database: $qso_count qso's.\n"; echo "

Elapsed time = $elapsed_time seconds \n"; // Count the total number of QSOs in the database $query = "SELECT id from ".$wpdb->prefix."logbook"; $result = $wpdb->query($query); $num_rows = $wpdb -> num_rows; echo "

There are now $num_rows QSOs in the database \n"; echo "

"; } else { // No file uploaded echo "

No file Uploaded

"; } }else{?>

Logbook Search Upload ADIF Log file

Use this form to upload log file qso's into the database by using an ADIF file exported from your logging program.

Please select the filename of the log to be uploaded into the database.
Only ADIF format logs are accepted.

or define a new one: