Location: PHPKode > projects > phpHamLog > phphamlog/phphamlog/writelog.php
<?php
/***************************************************************************
 phpHamLog

 $Id: writelog.php,v 1.1 2006/04/29 02:56:41 kc9aop Exp $

 Copyright (c) 2005 KC9AOP

 ***************************************************************************/

################################
# Summary submit form
#
# Copyright 2002 N4FWD
# Released under the GNU GPL License
################################
#include ("configure.php");
include ("auth.php");

#if the user is not logged in, kick them out
$loggedin = false;

session_start();
$result = session_is_registered("logcallid");

switch ($program) {
	case "FIELDDAY":
		if ($result) {
			$tmpcall = $HTTP_SESSION_VARS["logcallid"];
			$sql = "SELECT logcallid, storage FROM cookies WHERE logcallid = '$tmpcall' ";
			$result = mysql_query ($sql, $db)
  				or error_die ("Could not get 'cookies' data from database");
			$myrow = mysql_fetch_array($result);
		}
		break;
	default:
		$sql = "SELECT storage FROM cookies WHERE storeid = '1' ";	
		$result = mysql_query ($sql, $db)
  			or error_die ("Could not check cookie data in database");
		$myrow = mysql_fetch_array($result);
}

switch ($myrow[storage]) {
	case 'Y':
		$loggedin = TRUE;
		break;
	default:
		$loggedin = FALSE;
}

if ($loggedin == false) {
	header("Location: index.php");
}

	$sql = "SELECT powercat, claimedscore FROM cabrillo WHERE cabid = '1'";
  	$result = mysql_query ($sql, $db)
  		or error_die ("Could not get cabrillo data from database");
  	$myrow = mysql_fetch_array($result);
  	
	switch ($myrow[powercat]) {
		case "QRP":
			$clscore = ($myrow[claimedscore] * 5);
			break;
		case "LOW":
			$clscore = ($myrow[claimedscore] * 2);
			break;
		default:
			$clscore = $myrow[claimedscore];
	}
	
$search_call = "";
?>
<html>
<head>
<title>phpHamLog: Summary routine </title>
<meta http-equiv="pragma" content="no-cache">
</head>
<body <?php echo "bgcolor = \"$pagebackground\""; ?>>

<font face="Arial" size="6"><center><b>Writing Summary Log file for 
<?php 
switch ($program) {
	case "FIELDDAY":
		echo $mastercall;
		break;
	default:
		echo $mycallsign; 
} 
?>
</b></center></font><br><br>
<font face="Arial" size="+1"><em>Final Score:</em>

<?php
 echo "$clscore <br>\n";
 ?>

<font face="Arial" size="+2">Writing file <?php echo $mastercall; ?>.log</font>
<?php
$fileout = "/tmp/".$mastercall.".log";

@$fp = fopen($fileout, "w");
if (!$fp) {
	echo "<br> Unable to open ".$fileout.".<br><br>\n";
	exit;
}

$sql = "SELECT * FROM cabrillo WHERE cabid = '1'";
$result = mysql_query ($sql, $db)
  	or error_die ("Could not get cabrillo data from database");
$myrow = mysql_fetch_array($result);

$temp = "START-OF-LOG: ".$myrow[startoflog]."\n";
fwrite($fp, $temp);

$section = $myrow[arrlsection];
$myexchange = $myrow[myexchange];

$temp = "ARRL-SECTION: ".$myrow[arrlsection]."\n";
fwrite($fp, $temp);

$temp = "CONTEST: ".$myrow[contest]."\n";
fwrite($fp, $temp);

$temp = "CALLSIGN: ".$myrow[callsign]."\n";
fwrite($fp, $temp);

$temp = "CATEGORY: ".$myrow[category]." ".$myrow[powercat]."\n";
fwrite($fp, $temp);

$temp = "CLAIMED-SCORE: ".$clscore."\n";
fwrite($fp, $temp);

$sql = "SELECT count(*) AS total FROM cookies";
$result = mysql_query ($sql, $db)
	or error_die ("Could not get count from database");
$fdnames = mysql_fetch_array($result);
$totalcount = $fdnames[total];
$temp = "OPERATORS: ";
if ($totalcount > 1) {
	for ($loopvar=2; $loopvar <= $totalcount; $loopvar++ ) {
		$sql = "SELECT logcallid FROM cookies WHERE storeid = '$loopvar' ";
		$result = mysql_query ($sql, $db)
  			or error_die ("Could not get 'operator' data from database");
		$fdnames = mysql_fetch_array($result);
		$temp = $temp." ".$fdnames[logcallid];
	}
} else {
	$temp = $temp." ".$mastercall;
}
$temp = $temp."\n";
fwrite($fp, $temp);

$temp = "CLUB: ".$myrow[club]."\n";
fwrite($fp, $temp);

$temp = "NAME: ".$myrow[cabname]."\n";
fwrite($fp, $temp);

$token = strtok($myrow[address], "\n");
$temp = "ADDRESS: ".$token."\n";
fwrite($fp, $temp);
do {
	$token = strtok("\n");
	if (strlen($token) == 0 )
		continue;
	$temp = "ADDRESS: ".$token."\n";
	fwrite($fp, $temp);
} while (!empty($token));

$token = strtok($myrow[soapbox], "\n");
$temp = "SOAPBOX: ".$token."\n";
fwrite($fp, $temp);
do {
	$token = strtok("\n");
	if (strlen($token) == 0 )
		continue;
	$temp = "SOAPBOX: ".$token."\n";
	fwrite($fp, $temp);
} while (!empty($token));

$temp = "CREATED-BY: phphamlog\n";
fwrite($fp, $temp);

$sql = "SELECT count(*) AS total FROM fdqso";
$result = mysql_query ($sql, $db)
	or error_die ("Could not get count from database");
$myrow = mysql_fetch_array($result);
$totalcount = $myrow[total];
$qsocount = 0;

for ($loopvar=1; $loopvar <= $totalcount; $loopvar++ ) {
	/* fetch record */
	$sql = "SELECT * FROM fdqso WHERE qsoid = '$loopvar' ";
//	$sql = "SELECT * FROM fdqso ORDER BY date ASC, time ASC";
	$result = mysql_query ($sql, $db)
  		or error_die ("Could not get 'qso' list from database");
	$myrow = mysql_fetch_array($result);
	
	/* if entry was deleted via mysql, let's skip building an empty line - N4FWD */
	if (strlen($myrow[callsign]) == 0 )
		continue;
	
	$qsocount++;	
	/* Start building line */
	$temp = "QSO: ";
	
	/* check frequency format and fix as needed */
	$decimal = strpos($myrow[frequency], ".");
	if ( $decimal > 0 ) {
	/* we detected a "." so we are using Mhz */
	/* strip out decimal point */
		$kilohz = substr($myrow[frequency]."0000", ($decimal+1), 3);
		$megahz = substr($myrow[frequency], 0, $decimal);
		$temp2 = $megahz . $kilohz;
	} else {
		$temp2 = $myrow[frequency];
	}
	$temp2 = substr("   ".$temp2, -6);
	$temp = $temp . $temp2 . " ";
	
	/* Add mode data */
	switch ($myrow[mode]) {
		case "CW":
			$temp = $temp."CW ";
			break;
		case "SSB":
		case "FM":
			$temp = $temp."PH ";
			break;
		default:
			$temp = $temp."DI ";
	}
	
	/* Add Date */
	$temp = $temp.$myrow[date]." ";
	
	/* Check time format */
	$colon = strpos($myrow[time], ":");
	if ($colon > 0 ) {
		$temp2 = substr($myrow[time], 0, 5);
		$hour = substr($myrow[time],0, $colon);
		$minute = substr($temp2, -2);
		$temp2 = $hour . $minute;
	} else {
		$temp2 = $myrow[time];
	}
	$temp2 = substr("0000".$temp2, -4);
	$temp = $temp . $temp2 . " ";
	
	/* Left justify call sign */
	$temp = $temp.substr(($mastercall."          "), 0, 9)." ";

	$class = strtoupper(substr($myexchange, -1));
	$stations = substr($myexchange, 0, (strlen($myexchange)-1));
	$temp = $temp.substr(("      ".$stations), -4)." ".$class."   ".substr(("   ".$section), -3)." ";
	
	/* Left justify call sign */
	$temp = $temp.substr(($myrow[callsign]."          "), 0, 9)." ";
	$class = strtoupper(substr($myrow[exchange], -1));
	$stations = substr($myrow[exchange], 0, (strlen($myrow[exchange])-1));
	$temp = $temp.substr(("      ".$stations), -4)." ".$class."   ".substr(("   ".$myrow[arrlsec]), -3)."\n";
	
	fwrite($fp, $temp);
}

$temp = "END-OF-LOG:\n";
fwrite($fp, $temp);
fclose($fp);
echo "<br>Total QSOs: ".$qsocount."\n";
echo "<br><br>Log file written to ".$fileout."\n";

/* now clear out the cabrillo table */
	$sql = "DELETE FROM cabrillo";
  	$result = mysql_query ($sql, $db)
  		or error_die ("Could not clear cabrillo data from database");

?>
</body>
</html> 
Return current item: phpHamLog