<?php

// print specimen value = 1 else value = 0
$specimen = 0;

$place = $_GET['plac'];
$contest = $_GET['cont'];
$mode = $_GET['mode'];
$year = $_GET['year'];
$category = $_GET['cate'];
$call = $_GET['call'];
$qsos = $_GET['qsos'];
$score = $_GET['scor'];
$plac_cont = $_GET['plac_cont'];
$plac_dxcc = $_GET['plac_dxcc'];
$plac_eu = $_GET['plac_eu'];
$mark1 = $_GET['mark1'];
$mark2 = $_GET['mark2'];
$contin = $_GET['contin'];
$cty = $_GET['cty'];



function decrypt($string, $key) {
  $result = '';
  $string = base64_decode($string);
  for($i=0; $i<strlen($string); $i++) {
    $char = substr($string, $i, 1);
    $keychar = substr($key, ($i % strlen($key))-1, 1);
    $char = chr(ord($char)-ord($keychar));
    $result.=$char;
  }
  return $result;
}

if ((strlen($place)== 0) 
	or (strlen($contest)== 0) 
	or (strlen($mode)== 0) 
	or (strlen($year)== 0) 
	or (strlen($category)== 0) 
	or (strlen($call)== 0) 
	or (strlen($qsos)== 0) 
	or (strlen($score)== 0)
	or (strlen($mark1)==0)
	or (strlen($mark2)==0)	
	or (strlen($contin)==0)
	or (strlen($cty)==0))	
{ exit("Failed to create a certificate due to missing or erroneous parameters"); }; 
// decryption
$place = decrypt($place,"Hg6(k?f");
$contest = decrypt($contest,"kv5H!?V");
$mode = decrypt($mode,"8(5AjcM");
$year = decrypt($year,"f(GK47?");
$category = decrypt($category,"Igk62?!");
$call = decrypt($call,"5!7bxD9");
$qsos = decrypt($qsos,"m5Q!3Uk");
$score = decrypt($score,"VmY6/q2");
$plac_cont = decrypt($plac_cont,"VmD6/q3");
$plac_dxcc = decrypt($plac_dxcc,"VmY2/q4");
$plac_eu = decrypt($plac_eu,"VmYk/q5");
$mark1 = decrypt($mark1,"VmY9/q6");
$mark2 = decrypt($mark2,"vMY6/q7");
$contin = decrypt($contin,"VmY6/q8");
$cty = decrypt($cty,"vMY6/q9");


// make PDF form according to content of Marker1 and Marker2
// *********************************************************

switch ($mark1)
{
case 'ON':
    if ($mark2 == 'UBA')
	{	// ON UBA contest
		$line1= $contest.' '.$year.' - '.$mode;
		$line2= 'Category: '.$category;
		$line3= 'Place: '.$place.'        Score: '.$score;

		require('fpdf.php');
		$pdf=new FPDF('P','mm','A4');
		$pdf->AddFont('Comic','B','comicbd.php');
		$pdf->AddFont('Arial','B','arialbd.php');
		$pdf->AddPage();
		$pdf->Image('background.jpg',15,20,180,257);
		$pdf->SetFont('Arial','B',58);
		$pdf->setXY(15,61);
		$pdf->Cell(180,0,$call,0,0,'C');
		$pdf->SetFont('Arial','B',24);
		$pdf->setXY(15,92);
		$pdf->Cell(180,0,$line1,0,0,'C');
		$pdf->SetFont('Arial','B',16);
		$pdf->setXY(15,103);
		$pdf->Cell(180,0,$line2,0,0,'C');
		$pdf->setXY(15,110);
		$pdf->Cell(180,0,$line3,0,0,'C');
		If ($specimen == 1)
		{
			$pdf->SetTextColor(255,0,0);
			$pdf->SetFont('Arial','B',40);
			$pdf->setXY(15,155);
			$pdf->Cell(180,0,'S P E C I M E N',0,0,'C');
		}
		$pdf->Image('sign7ss.png',35,249,42,40);
		$pdf->Image('sign7tk.png',143,249,42,38);
		$pdf->SetFont('Arial','I',9);
		$pdf->SetTextColor(0,0,0);
		$pdf->setXY(164,270);
		$pdf->Cell(20,0,'ON7TK',0,0,'L');
		$pdf->Output();
	};
	break;
case 'DX' :	
    if ($mark2 == 'DX')
	{	// DX DX contest
		$line1= $contest.' '.$year.' - '.$mode;
		$line2= 'Category: '.$category;
		$line3= 'with ' . $score . ' points';
		$line4= 'Place ' . $place . ' Worldwide';
		$line5= 'Place ' . $plac_cont . ' in ' . $contin;
		$line6= 'Place ' . $plac_dxcc . ' in ' . $cty;

		require('fpdf.php');
		$pdf=new FPDF('P','mm','A4');
		$pdf->AddFont('Comic','B','comicbd.php');
		$pdf->AddFont('Arial','B','arialbd.php');
		$pdf->AddPage();
		$pdf->Image('background.jpg',15,20,180,257);
		$pdf->SetFont('Arial','B',58);
		$pdf->setXY(15,61);
		$pdf->Cell(180,0,$call,0,0,'C');
		$pdf->SetFont('Arial','B',24);
		$pdf->setXY(15,92);
		$pdf->Cell(180,0,$line1,0,0,'C');
		$pdf->SetFont('Arial','B',18);
		$pdf->setXY(15,103);
		$pdf->Cell(180,0,$line2,0,0,'C');
		$pdf->setXY(15,110);
		$pdf->Cell(180,0,$line3,0,0,'C');
		$pdf->setXY(15,120);
		$pdf->Cell(180,0,$line4,0,0,'C');
		$pdf->setXY(15,127);
		$pdf->Cell(180,0,$line5,0,0,'C');
		$pdf->setXY(15,134);
		$pdf->Cell(180,0,$line6,0,0,'C');
		if ($specimen == 1)
		{
			$pdf->SetTextColor(255,0,0);
			$pdf->SetFont('Arial','B',40);
			$pdf->setXY(15,155);
			$pdf->Cell(180,0,'S P E C I M E N',0,0,'C');
		}	
		$pdf->Image('sign7ss.png',35,249,42,40);
		$pdf->Image('sign7tk.png',143,249,42,38);
		$pdf->SetFont('Arial','I',9);
		$pdf->SetTextColor(0,0,0);
		$pdf->setXY(164,270);
		$pdf->Cell(20,0,'ON7TK',0,0,'L');
		$pdf->Output();
	};
	
	if ($mark2 == 'EU')
	{	// DX-EU contest
		$line1= $contest.' '.$year.' - '.$mode;
		$line2= 'Category: '.$category;
		$line3= 'with ' . $score . 'Points';
		$line4= 'Place ' . $place . ' Worldwide';
		$line5= 'Place ' . $plac_cont . ' in ' . $contin;
		$line6= 'Place ' . $plac_dxcc . ' in ' . $cty;
		$line7= 'Place ' . $plac_eu . ' in the European Union';
		
		require('fpdf.php');
		$pdf=new FPDF('P','mm','A4');
		$pdf->AddFont('Comic','B','comicbd.php');
		$pdf->AddFont('Arial','B','arialbd.php');
		$pdf->AddPage();
		$pdf->Image('background.jpg',15,20,180,257);
		$pdf->SetFont('Arial','B',58);
		$pdf->setXY(15,61);
		$pdf->Cell(180,0,$call,0,0,'C');
		$pdf->SetFont('Arial','B',24);
		$pdf->setXY(15,92);
		$pdf->Cell(180,0,$line1,0,0,'C');
		$pdf->SetFont('Arial','B',18);
		$pdf->setXY(15,103);
		$pdf->Cell(180,0,$line2,0,0,'C');
		$pdf->setXY(15,110);
		$pdf->Cell(180,0,$line3,0,0,'C');
		$pdf->setXY(15,120);
		$pdf->Cell(180,0,$line4,0,0,'C');
		$pdf->setXY(15,127);
		$pdf->Cell(180,0,$line5,0,0,'C');
		$pdf->setXY(15,134);
		$pdf->Cell(180,0,$line6,0,0,'C');
		$pdf->setXY(15,141);
		$pdf->Cell(180,0,$line7,0,0,'C');
		if ($specimen == 1)
		{
			$pdf->SetTextColor(255,0,0);
			$pdf->SetFont('Arial','B',40);
			$pdf->setXY(15,155);
			$pdf->Cell(180,0,'S P E C I M E N',0,0,'C');
		}	
		$pdf->Image('sign7ss.png',35,249,42,40);
		$pdf->Image('sign7tk.png',143,249,42,38);
		$pdf->SetFont('Arial','I',9);
		$pdf->SetTextColor(0,0,0);
		$pdf->setXY(164,270);
		$pdf->Cell(20,0,'ON7TK',0,0,'L');
		$pdf->Output();
		
	};

	break;

}
?>
