Once the MySQL database has been created the qsos table needs to be populated. This is achieved using an upload
HTML page (written in PHP upload.php) and a PHP upload script (readlog.php). Both files should be
saved in a secure directory on the server and as a minumum the directory password protected to prevent other people loading
data into your database!
Both Cabrillo and ADIF format log files can be loaded into the database.
The following PHP script - upload.php - creates an HTML page to prompt for the filename of the Cabrillo log
file and the callsign of the logbook. The possible callsigns are read from the database and presented as a drop down menu. The
last 10 logfiles uploaded are also displayed.
The upload.php script should be copied from the Log Search PHP scripts download page
and transferred to your server.
The following variables need to be changed in the include file dbinc.php used by the below script:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3c.org/TR/
1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title>Upload Cabrillo/ADIF Log</title>
</head>
<body>
<h2>Upload Cabrillo/ADIF Log</h2>
<p> Please select the filename of the log to be uploaded into the database.
<br><b>Only Cabrillo and ADIF format logs are accepted</b>
<p>
<table BORDER="0" CELLPADDING="5" CELLSPACING="10">
<tr>
<td BGCOLOR="lightyellow">
<form action="readlog.php" enctype="multipart/form-data" method="post">
<br>Filename: <input name="userfile" type="file">
<p>Callsign:
<select name="callsign">
<?php
include 'dbinc.php'; // Variables for DB connection
include 'error.inc'; // Error handler
// Connect to the database
if (!($connection = @ mysql_connect ($hostName,
$username,
$password)))
die ("Could not connect to database");
// Select the radiolog database
if (!mysql_select_db ($databaseName, $connection))
showerror();
// Display all the available DX callsigns in order
$query = "SELECT dxcallsign FROM dxstation order by id";
if (!($result = @ mysql_query ($query, $connection)))
showerror();
$i = 0;
// Display each DX callsign in a drop down menu.
while ($row = @ mysql_fetch_array ($result))
{
$i++;
if ($i == 1)
echo "<option value=" . $i . " selected>" . $row['dxcallsign'] . "\n";
else
echo "<option value=" . $i . ">" . $row['dxcallsign'] . "\n";
}
?>
</select>
<p><input type="reset" value="Reset">
<input type="submit" value="Upload Log">
</form>
</td>
</tr>
</table>
<?php
echo "<H3><BR><BR><BR><BR>Last 10 logs uploaded</H3>\n";
// Display the last 10 files uploaded
$query = "SELECT * FROM logfiles order by id DESC LIMIT 10";
if (!($result = @ mysql_query ($query, $connection)))
showerror();
echo "\n<table border=1 width=75% bgcolor=\"lightyellow\">";
echo "\n<tr>";
echo "\n\t<th>Filename</th>";
echo "\n\t<th>No. QSOs</th>";
echo "\n\t<th>File type</th>";
echo "\n\t<th>Date uploaded</th>";
echo "\n^lt;/tr>";
while ($row = @ mysql_fetch_array ($result))
{
echo "\n<tr>" .
"\n\t<td>{$row["filename"]}</td>" .
"\n\t<td>{$row["qsos"]}</td>" .
"\n\t<td>{$row["filetype"]}</td>" .
"\n\t<td>{$row["loaded"]}</td>";
}
echo "\n</table>";
// Disconnect from the database
if (!mysql_close ($connection))
showerror();
?>
</body>
</html>
|
The following PHP script - readlog.php - is called by the above Upload HTML page. The filename of the Cabrillo
file and the logbook callsign (numeric ID of the dxstation table) are passed to the script below. The script first checks that a log file has been uploaded and then extracts the required fields from each Cabrillo row (callsign, frequency and mode). The frequency is converted to a band and then each QSO is inserted into the database.
The readlog.php script should be copied from the Log Search PHP scripts download page
and transferred to your server.
The following variables need to be changed in the include file dbinc.php used by the below script:
<?php
include 'dbinc.php'; // Variables for DB connection
include 'error.inc'; // Error handler
// Function to read one line of QSO data from the Cabrillo file and parse according to
// the contest type
// Parameters:
// $contest_type - Cabrillo contest type (determines the number of columns in the QSO data)
// $s - the QSO: line from the Cabrillo file
// &$qso_data - array to put parsed data into
function readCabrilloQSO ($contest_type, $s, &$qso_data)
{
switch ($contest_type)
{
case "ARRL-VHF-SEP":
// This Cabrillo format has 9 columns (including QSO: column)
sscanf ($s, "%s %s %s %s %s %s %s %s %s",
&$dummy,
&$qso_data['freq'],
&$qso_data['mode'],
&$dummy,
&$dummy,
&$dummy,
&$dummy,
&$qso_data['call'],
&$dummy);
break;
case "IARU":
case "AP-SPRINT":
case "ARRL-10":
case "ARRL-160":
case "ARRL-DX":
case "CQ-WPX":
// This Cabrillo format has 11 columns (including QSO: column)
sscanf ($s, "%s %s %s %s %s %s %s %s %s %s %s",
&$dummy,
&$qso_data['freq'],
&$qso_data['mode'],
&$dummy,
&$dummy,
&$dummy,
&$dummy,
&$dummy,
&$qso_data['call'],
&$dummy,
&$dummy);
break;
case "RSGB-IOTA":
case "CQ-WW-RTTY":
// This Cabrillo format has 13 columns (including QSO: column)
sscanf ($s, "%s %s %s %s %s %s %s %s %s %s %s %s %s",
&$dummy,
&$qso_data['freq'],
&$qso_data['mode'],
&$dummy,
&$dummy,
&$dummy,
&$dummy,
&$dummy,
&$dummy,
&$qso_data['call'],
&$dummy,
&$dummy,
&$dummy);
break;
case "RSGB 21":
// This Cabrillo format has 13 columns (including QSO: column)
sscanf ($s, "%s %s %s %s %s %s %s %s %s %s %s %s %s",
&$dummy,
&$qso_data['freq'],
&$qso_data['mode'],
&$dummy,
&$dummy,
&$dummy,
&$dummy,
&$dummy,
&$qso_data['call'],
&$dummy,
&$dummy,
&$dummy,
&$dummy);
break;
case "ARRL-SS-CW":
// This Cabrillo format has 15 columns (including QSO: column)
sscanf ($s, "%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s",
&$dummy,
&$qso_data['freq'],
&$qso_data['mode'],
&$dummy,
&$dummy,
&$dummy,
&$dummy,
&$dummy,
&$dummy,
&$dummy,
&$qso_data['call'],
&$dummy,
&$dummy,
&$dummy,
&$dummy);
break;
case "DXPEDITION":
// This Cabrillo format has 9 columns (including QSO: column)
sscanf ($s, "%s %s %s %s %s %s %s %s %s",
&$dummy,
&$qso_data['freq'],
&$qso_data['mode'],
&$dummy,
&$dummy,
&$dummy,
&$dummy,
&$qso_data['call'],
&$dummy);
break;
default:
// The default Cabrillo format has 11 columns (inluding QSO: column)
sscanf ($s, "%s %s %s %s %s %s %s %s %s %s %s",
&$dummy,
&$qso_data['freq'],
&$qso_data['mode'],
&$dummy,
&$dummy,
&$dummy,
&$dummy,
&$dummy,
&$qso_data['call'],
&$dummy,
&$dummy);
break;
}
}
// Function to convert frequency (211234) to band (15)
// Only 160 to 6m
// Parameters:
// frequency to convert to band
function convertFrequencyBand ($frequency)
{
// 1.8 or 18 MHz
if (ereg('^18',$frequency))
{
if (strlen($frequency) > 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 "<p>Cabrillo Contest type is $contest_type <P>\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 "<P><EM>Error - Frequency to Band conversion
failed - frequency: $freq</EM></P>\n";
echo "<P>No QSOs loaded\n";
echo "<P><A HREF=\"uploadlog.php\">Return to Log Upload Page</A>\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 (
|