Browse Source

PDF awards (based on existing templates)

master
Fabian Kurz 2 years ago
parent
commit
dea7116d5b
  1. 23
      api.php
  2. 54
      functions.php
  3. 36
      pdf/cwops-aca.fdf
  4. 32
      pdf/cwops-cma.fdf
  5. 32
      pdf/cwops-dxcc.fdf
  6. 32
      pdf/cwops-wae.fdf
  7. 32
      pdf/cwops-was.fdf
  8. 32
      pdf/cwops-waz.fdf

23
api.php

@ -375,11 +375,26 @@
}
function award_pdf () {
$callsign = validate_get('callsign');
$type = validate_get('type');
header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=\"$callsign-$type.pdf\"");
echo create_award ($callsign, $type, 1000, "2019-01-01");
$callsign = $_SESSION['callsign'];
if ($type && $callsign) {
# query score...
global $db;
$q = mysqli_query($db, "select $type from cwops_scores where uid=".$_SESSION['id']);
if ($r = mysqli_fetch_row($q)) {
$score = $r[0];
}
header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=\"$callsign-$type.pdf\"");
echo create_award ($callsign, $_SESSION['id'], $type, $score, date("Y-m-d"));
}
else {
echo "wrong type or callsign";
}
}

54
functions.php

@ -45,13 +45,13 @@ function stats($c) {
?>
<h2>Statistics for <?=$_SESSION['callsign'];?></h2>
<table>
<tr><th>Award</th><th>Score</th><th>Details</th></tr>
<tr><td>ACA</td> <td><?=$aca?></td> <td><?=award_details('aca', 0);?></td></tr>
<tr><td>CMA</td> <td><?=$cma?></td> <td><?=award_details('cma', 0);?></td></tr>
<tr><td>WAS</td> <td><?=$was?></td> <td><?=award_details('was', 1);?></td></tr>
<tr><td>DXCC</td><td><?=$dxcc?></td><td><?=award_details('dxcc', 1);?></td></tr>
<tr><td>WAE</td><td><?=$wae?></td><td><?=award_details('wae', 1);?></td></tr>
<tr><td>WAZ</td> <td><?=$waz?></td> <td><?=award_details('waz', 1);?></td></tr>
<tr><th>Award</th><th>Score</th><th>Details</th><th>PDF</th></tr>
<tr><td>ACA</td> <td><?=$aca?></td> <td><?=award_details('aca', 0);?></td><td><a href="/api.php?action=award_pdf&type=aca">Download PDF award</a></td></tr>
<tr><td>CMA</td> <td><?=$cma?></td> <td><?=award_details('cma', 0);?></td><td><a href="/api.php?action=award_pdf&type=cma">Download PDF award</a></td></tr>
<tr><td>WAS</td> <td><?=$was?></td> <td><?=award_details('was', 1);?></td><td><a href="/api.php?action=award_pdf&type=was">Download PDF award</a></td></tr>
<tr><td>DXCC</td><td><?=$dxcc?></td><td><?=award_details('dxcc', 1);?></td><td><a href="/api.php?action=award_pdf&type=dxcc">Download PDF award</a></td></tr>
<tr><td>WAE</td><td><?=$wae?></td><td><?=award_details('wae', 1);?></td><td><a href="/api.php?action=award_pdf&type=wae">Download PDF award</a></td></tr>
<tr><td>WAZ</td> <td><?=$waz?></td> <td><?=award_details('waz', 1);?></td><td><a href="/api.php?action=award_pdf&type=waz">Download PDF award</a></td></tr>
</table>
<br>
@ -923,7 +923,6 @@ function validate ($type, $value) {
case 'callsign':
case 'hiscall':
case 'mycall':
case 'type':
$value = strtoupper($value);
if (preg_match('/^[A-Z0-9\/]+$/', $value)) {
return $value;
@ -932,6 +931,15 @@ function validate ($type, $value) {
return "";
}
break;
case 'type':
$value = strtoupper($value);
if (in_array($value, array("ACA", "CMA", "WAZ", "WAS", "WAE", "DXCC"))) {
return $value;
}
else {
return "";
}
break;
case 'nr':
case 'dxcc':
case 'waz':
@ -1038,10 +1046,34 @@ function get_joindate($callsign) {
}
function create_award ($callsign, $type, $score, $date) {
function create_award ($callsign, $uid, $type, $score, $date) {
global $db;
error_log("create_award: $callsign, $uid, $type, $score, $date");
# validated in api.php
if ($type == "") {
echo "Invalid type.";
}
$type = strtolower($type);
$fdf = sprintf(file_get_contents("pdf/cwops-$type.fdf"), $callsign, date("Y"), 1234, $date, $score);
$filename = "/tmp/award-".$_SESSION['id']."-$type";
# get CWops number
$q = mysqli_query($db, "select nr from cwops_members where `callsign`='$callsign'");
$nr = 0;
if ($r = mysqli_fetch_row($q)) {
$nr = $r[0];
}
$template = file_get_contents("pdf/cwops-$type.fdf");
if ($type == "aca") {
$fdf = sprintf($template, $callsign, date("Y"), $nr, $date, $score);
}
else {
$fdf = sprintf($template, $callsign, $nr, $date, $score);
}
$filename = "/tmp/award-$uid-$type";
file_put_contents("$filename.fdf", $fdf);
system("pdftk pdf/cwops-$type.pdf fill_form $filename.fdf output $filename.pdf");
return file_get_contents("$filename.pdf");

36
pdf/cwops-aca.fdf

@ -0,0 +1,36 @@
%%FDF-1.2
%%âãÏÓ
1 0 obj
<<
/FDF
<<
/Fields [
<<
/T (Call)
/V (%s)
>>
<<
/T (Year)
/V (%s)
>>
<<
/T (CWops ID)
/V (%s)
>>
<<
/T (Issue Date)
/V (%s)
>>
<<
/T (ACA)
/V (%s)
>>]
>>
>>
endobj
trailer
<<
/Root 1 0 R
>>
%%%%EOF

32
pdf/cwops-cma.fdf

@ -0,0 +1,32 @@
%%FDF-1.2
%%âãÏÓ
1 0 obj
<<
/FDF
<<
/Fields [
<<
/T (Call)
/V (%s)
>>
<<
/T (CWops ID)
/V (%d)
>>
<<
/T (Issue Date)
/V (%s)
>>
<<
/T (Members)
/V (%s)
>>]
>>
>>
endobj
trailer
<<
/Root 1 0 R
>>
%%%%EOF

32
pdf/cwops-dxcc.fdf

@ -0,0 +1,32 @@
%%FDF-1.2
%%âãÏÓ
1 0 obj
<<
/FDF
<<
/Fields [
<<
/T (Call)
/V (%s)
>>
<<
/T (CWops ID)
/V (%s)
>>
<<
/T (Issue Date)
/V (%s)
>>
<<
/T (DXCC)
/V (%s)
>>]
>>
>>
endobj
trailer
<<
/Root 1 0 R
>>
%%%%EOF

32
pdf/cwops-wae.fdf

@ -0,0 +1,32 @@
%%FDF-1.2
%%âãÏÓ
1 0 obj
<<
/FDF
<<
/Fields [
<<
/T (Call)
/V (%s)
>>
<<
/T (CWops ID)
/V (%s)
>>
<<
/T (Issue Date)
/V (%s)
>>
<<
/T (WAE)
/V (%s)
>>]
>>
>>
endobj
trailer
<<
/Root 1 0 R
>>
%%%%EOF

32
pdf/cwops-was.fdf

@ -0,0 +1,32 @@
%%FDF-1.2
%%âãÏÓ
1 0 obj
<<
/FDF
<<
/Fields [
<<
/T (Call)
/V (%s)
>>
<<
/T (CWops ID)
/V (%s)
>>
<<
/T (Issue Date)
/V (%s)
>>
<<
/T (WAS)
/V (%s)
>>]
>>
>>
endobj
trailer
<<
/Root 1 0 R
>>
%%%%EOF

32
pdf/cwops-waz.fdf

@ -0,0 +1,32 @@
%%FDF-1.2
%%âãÏÓ
1 0 obj
<<
/FDF
<<
/Fields [
<<
/T (Call)
/V (%s)
>>
<<
/T (CWops ID)
/V (%s)
>>
<<
/T (Issue Date)
/V (%s)
>>
<<
/T (WAZ)
/V (%s)
>>]
>>
>>
endobj
trailer
<<
/Root 1 0 R
>>
%%%%EOF
Loading…
Cancel
Save