<?php
session_start();
include("kurs/datenbankanbindung.php"); // f&uuml;gt die Datenbankanbindung ein: Sys:\php\includes\kurs\datenbankanbindung.php

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

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

$user_admin=$_SESSION["user_admin"];
$jahrgang=$_SESSION["jahrgang"];

# Änderungen für März Jahrgänge
$semester=$_SESSION["semester"];
$stg= $_SESSION["stg"];
if($semester == 30){
  if($stg == 'S'){$sem_klartext = 'Frühjahr';}else{$sem_klartext = '';}
  $ag_von = 30;
  $ag_bis = 39;
}else{
  if($stg == 'S'){$sem_klartext = 'Herbst';}else{$sem_klartext = '';}
  $ag_von = 0;
  $ag_bis = 29;
}

// Rechte&uuml;berpr&uuml;fung
$db = dbconnect();
if ($user_admin == ""){ require("../../index.php"); exit;} //Wenn man nicht angemeldet ist, darf man nicht auf die Seite
$result = $db->query("SELECT 1 FROM brt_admin_rechte, brt_admin_rechte_zuord , brt_admin where brt_admin_rechte.brt_admin_rolle = brt_admin_rechte_zuord.brt_admin_rolle AND brt_admin_rechte_zuord.waid = brt_admin.waid AND brt_admin.user = '$user_admin' AND brt_admin_rechte_zuord.brt_admin_rolle = 'a_listeeb'");
$row = $result->fetch_array();
if ($row[0] != 1){ echo "Sie haben keine Rechte die Seite zu öffnen"; exit;}
// Rechte&uuml;berpr&uuml;fung ende


$db = dbconnect();


$columns = 4; //five columns


$pos=$pdf->GetY()+20;


$pdf->SetY($pos);

	//we initialize the table class
	$pdf->Table_Init($columns, true, true);

	$table_subtype = $table_default_table_type;
	$pdf->Set_Table_Type($table_subtype);
	
	//TABLE HEADER SETTINGS
	$header_subtype = $table_default_header_type;
	
        $db = dbconnect();
        $query1 = "SELECT distinct doz_nr, doz_vorname, doz_name
                    FROM brt_thema a, stud b, doz c
                   WHERE a.uid = b.uid
                    AND a.eb_doz_nr = c.doz_nr
                    AND b.jahrgang = '$jahrgang'
                    AND b.ag >= $ag_von
                    AND b.ag <= $ag_bis
                    AND stg NOT LIKE '%S%'
                  ORDER BY concat( doz_name, ' ', doz_vorname) , nachname, vorname, ag";
        $result1 = $db->query ($query1)
           or die ("Cannot execute query1a");
           

 
        while ($row1 = $result1->fetch_array())
	{
	$pdf->AddPage();
	$pdf->SetFont('Arial', 'B', 18);
	$pos=$pdf->GetY()+10;
	$pdf->SetY($pos);
	$pdf->SetX(24);
        $pdf->Cell(0, 3, "Erstprüfer: $row1[doz_vorname] $row1[doz_name]" , 0, 0, 'L');
	for($i=0; $i<$columns; $i++) $header_type[$i] = $table_default_header_type;

	$pos=$pdf->GetY()+10;
	$pdf->SetY($pos);
	
	$header_type[0]['WIDTH'] = 30;
	$header_type[0]['BG_COLOR'] = array(200,200,200);
	$header_type[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$header_type[0]['V_ALIGN'] = "M"; //T=TOP, M=MIDDLE, B=BOTTOM
	$header_type[0]['TEXT'] = "Name";
	
	$header_type[1]['WIDTH'] = 10;
	$header_type[1]['BG_COLOR'] = array(200,200,200);
	$header_type[1]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$header_type[1]['V_ALIGN'] = "M"; //T=TOP, M=MIDDLE, B=BOTTOM
	$header_type[1]['TEXT'] = "AG";
	
	$header_type[2]['WIDTH'] = 100;
	$header_type[2]['BG_COLOR'] = array(200,200,200);
	$header_type[2]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$header_type[2]['V_ALIGN'] = "M"; //T=TOP, M=MIDDLE, B=BOTTOM
	$header_type[2]['TEXT'] = "Thema";
	
	$header_type[3]['WIDTH'] = 30;
	$header_type[3]['BG_COLOR'] = array(200,200,200);
	$header_type[3]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
	$header_type[3]['V_ALIGN'] = "M"; //T=TOP, M=MIDDLE, B=BOTTOM
	$header_type[3]['TEXT'] = "Zweitprüfer";
	
	#$header_type[1]['COLSPAN'] = "2";

	//set the header type
	$pdf->Set_Header_Type($header_type);
	
	$pdf->Draw_Header();
	
	//TABLE DATA SETTINGS
	$data_subtype = $table_default_data_type;
	
	$data_type = Array();//reset the array
	for ($i=0; $i<$columns; $i++) $data_type[$i] = $data_subtype;

	$pdf->Set_Data_Type($data_type);
	
#	$fsize = 10;
#	$colspan = 1;
#	$rr = 255;

        $db = dbconnect();
        $query = "SELECT concat( doz_vorname, ' ', doz_name ) Erstprüfer, Nachname, Vorname, concat( ag, '/', jahrgang ) AG, Thema, concat( zb_vorname, ' ', zb_nachname ) Zweitprüfer
                    FROM brt_thema a, stud b, doz c
                   WHERE a.uid = b.uid
                    AND a.eb_doz_nr = c.doz_nr
                    AND b.jahrgang = '$jahrgang'
                    AND b.ag >= $ag_von
                    AND b.ag <= $ag_bis
                    AND stg NOT LIKE '%S%'
                    AND doz_nr='$row1[doz_nr]'
                  ORDER BY concat( doz_name, ' ', doz_vorname) , nachname, vorname, ag";
        $result = $db->query ($query)
           or die ("Cannot execute query1");
           

 
        while ($row = $result->fetch_array())
	{


/* Schriftgröße
		$data[0]['T_SIZE'] = $fsize;
		$data[1]['T_SIZE'] = $fsize+3;
		$data[3]['T_SIZE'] = $fsize+4;
*/
/* Schriftfarbe und Zellenhintergrund
		$data[0]['T_COLOR'] = array(0,0,0); //Schriftfarbe
		$data[0]['BG_COLOR'] = array($rr,$rr,$rr);
		$data[3]['T_COLOR'] = array($rr,240,240);
		$data[3]['BG_COLOR'] = array($rr,100,135);
*/
			
			$data[0]['TEXT'] = "$row[Vorname] $row[Nachname]";
			$data[0]['T_ALIGN'] = "L";
			$data[0]['V_ALIGN'] = "M";
			
			$data[1]['TEXT'] = "$row[AG]";
			$data[1]['T_ALIGN'] = "L";
			$data[1]['V_ALIGN'] = "M";
			
			$data[2]['TEXT'] = "$row[Thema]";
			$data[2]['T_ALIGN'] = "L";
			$data[2]['V_ALIGN'] = "M";
			
			$data[3]['TEXT'] = "$row[Zweitprüfer]";
			$data[3]['T_ALIGN'] = "L";
			$data[3]['V_ALIGN'] = "M";

		$pdf->Draw_Data($data,NULL,10); // -->letzter Parameter Höhe der Datenspalte. Neu prgrammiert in prints/class.fpdf_table.php am 15.04.2009
	}
	
}
	$pdf->Draw_Table_Border();


$pdf->Output();


?>