<?php
session_start();
$jahrgang=$_SESSION["jahrgang"];
$doz_uid1=$_SESSION["doz_uid1"];


if ($jahrgang == ""){ require("jahrgang_doz.php"); exit;} //Wenn man nicht angemeldet ist soll man nichts ausw&auml;hlen k&ouml;nnen
include("kurs/datenbankanbindung.php");     // f&uuml;gt die Datenbankanbindung ein: Sys:\php\includes\kurs\datenbankanbindung.php
$db = dbconnect();
$result_doznr = $db->query("SELECT doz_nr FROM doz WHERE doz_uid = '$doz_uid1'");
$row_doznr = $result_doznr->fetch_array();
$_SESSION["doz_nr"] = $row["doz_nr"];


#require_once("class.fpdf_table.php");

define('FPDF_FONTPATH','font/');
require('as_utf_class.php');
require_once("table_def.inc");
$pdf= new utfFPDF();

$pagecount = $pdf->setSourceFile("deckblatt.pdf");
$tplidx = $pdf->ImportPage(1);


$pdf->SetAutoPageBreak(true, 20);
$pdf->SetTopMargin(0);
$pdf->SetRightMargin(23);
$pdf->SetAutoPageBreak(TRUE, 0);
  
         
$db = dbconnect();
$query = "SELECT a.uid, b.vorname, b.nachname, b.stg, a.eb_doz_nr, a.zb_nachname, a.zb_vorname, ag, jahrgang
            FROM brt_thema a, stud b
           WHERE a.uid = b.uid
             AND b.jahrgang ='$jahrgang'
             AND a.eb_doz_nr = '$row_doznr[doz_nr]'
             AND b.durchgefallen != \"Y\"
             AND b.hs='L'
           ORDER BY b.nachname ASC";

$result = $db->query ($query)
   or die ("Cannot execute query");

while ($row = $result->fetch_array()){
$pdf->addPage();
$pdf->useTemplate($tplidx,0,0,0);

#$pos=$pdf->GetY()+3;
$pdf->SetFont('Arial', '', 12);
$pdf->SetY(75);
$pdf->SetX(63.4);
$pdf->MultiCell(0, 4.5, "$row[nachname], $row[vorname] ($row[ag]/$row[jahrgang])", 0, 'J');

if($row['stg'] == 'I'){
$pdf->SetFont('Arial', '', 10);
$pdf->SetY(89.9);
$pdf->SetX(112.6);
$pdf->MultiCell(0, 4.5, "X", 0, 'J');
}

if($row['stg'] == 'R'){
$pdf->SetFont('Arial', '', 10);
$pdf->SetY(94.7);
$pdf->SetX(112.6);
$pdf->MultiCell(0, 4.5, "X", 0, 'J');
}

if($row['stg'] == 'F'){
$pdf->SetFont('Arial', '', 10);
$pdf->SetY(99.6);
$pdf->SetX(112.6);
$pdf->MultiCell(0, 4.5, "X", 0, 'J');
}

if($row['stg'] == 'S'){
$pdf->SetFont('Arial', '', 10);
$pdf->SetY(104.4);
$pdf->SetX(112.6);
$pdf->MultiCell(0, 4.5, "X", 0, 'J');
}

$result_doz = $db->query("SELECT doz_name, doz_vorname 
                             FROM doz
                            WHERE doz_nr='$row[eb_doz_nr]'");
$row_doz = $result_doz->fetch_array();

#$pos=$pdf->GetY()+3;
$pdf->SetFont('Arial', '', 12);
$pdf->SetY(129);
$pdf->SetX(63.4);
$pdf->MultiCell(0, 4.5, "$row_doz[doz_name], $row_doz[doz_vorname]", 0, 'J');

#$pos=$pdf->GetY()+3;
$pdf->SetFont('Arial', '', 12);
$pdf->SetY(169.9);
$pdf->SetX(63.4);
 if($row['zb_vorname'] != ''){
   $trenner = ',';
 }else{
   $trenner = '';
 }
$pdf->MultiCell(0, 4.5, "$row[zb_nachname]$trenner $row[zb_vorname]", 0, 'J');
}
$pdf->Output();
?>