<?php
include("kurs/datenbankanbindung.php"); // f&uuml;gt die Datenbankanbindung ein: Sys:\php\includes\kurs\datenbankanbindung.php
$user_admin=$_COOKIE["user_admin"];
$jahrgang=$_COOKIE["jahrgang"];
$sort=$_GET["sort"];

// Rechteüberprü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 stan_admin_rechte, stan_admin_rechte_zuord , stan_admin where stan_admin_rechte.stan_admin_rolle = stan_admin_rechte_zuord.stan_admin_rolle AND stan_admin_rechte_zuord.said = stan_admin.said AND stan_admin.user = '$user_admin' AND stan_admin_rechte_zuord.stan_admin_rolle = 'a_wlist'");
$row = $result->fetch_array();
if ($row[0] != 1){ include("kurs/rechte.php"); exit;}
// Rechte&uuml;berpr&uuml;fung ende

// Rechteüberprüfung ende




define('FPDF_FONTPATH','../../stud/prints/font/');
require('../../stud/prints/as_utf_class.php');
require_once("../../stud/prints/table_def.inc");

$pdf=new utfFPDF();


#$pagecount = $pdf->setSourceFile("briefkopf_blanko.pdf");

#$tplidx = $pdf->ImportPage(1);

$pdf->SetAutoPageBreak(true, 20);
$pdf->SetTopMargin(0);
$pdf->SetRightMargin(23);
$pdf->SetTopMargin(25);



$pdf->addPage();
#$pdf->useTemplate($tplidx,0,0,0);


$pdf->SetFont('Times', 'B', 12);
$pdf->SetY(20);
$pdf->SetX(23);
$pdf->MultiCell(0, 4.5, "Studenten des W-Zweigs des Jahrgangs $jahrgang", 0, 'L');

                               

$columns = 4; //five columns

#$pdf->SetX(30);
$pdf->SetY(32);
	//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;
	
	
	for($i=0; $i<$columns; $i++) $header_type[$i] = $table_default_header_type;

	$header_type[0]['WIDTH'] = 55;
	$header_type[1]['WIDTH'] = 55;
	$header_type[2]['WIDTH'] = 25;
	$header_type[3]['WIDTH'] = 25;

	
	$header_type[0]['TEXT'] = "Name";
	$header_type[1]['TEXT'] = "Anschrift";
	$header_type[2]['TEXT'] = "Zweig";
	$header_type[3]['TEXT'] = "AG";
	
	#$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);
	


        $db = dbconnect();
        $query2 = "SELECT a.uid, a.nachname, a.vorname, a.ag, a.jahrgang, a.stg, poStrasse, poplz, poort
                            FROM stud a
                           WHERE stg = 'W'
                             AND a.jahrgang='$jahrgang'
                             AND a.durchgefallen='N'
                           ORDER BY $sort, nachname";

        $result2 = $db->query ($query2)
           or die ("Cannot execute query2");
 
        while ($row2 = $result2->fetch_array())
	{
		$data = Array();
		

			$data[0]['TEXT'] = "$row2[nachname], $row2[vorname]";
			$data[0]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
			$data[0]['V_ALIGN'] = "M"; //T=TOP, M=MIDDLE, B=BOTTOM
		       #$data[0]['T_TYPE'] = "BI"; // B=BOLD, I=ITALIC
			
			$data[1]['TEXT'] = "$row2[poStrasse]\n$row2[poplz] $row2[poort]";
			$data[1]['T_ALIGN'] = "L";
			$data[1]['V_ALIGN'] = "M";

			$data[2]['TEXT'] = "$row2[stg]";
			$data[2]['T_ALIGN'] = "C";
			$data[2]['V_ALIGN'] = "M";

			$data[3]['TEXT'] = "$row2[ag] / $row2[jahrgang]";
			$data[3]['T_ALIGN'] = "C";
			$data[3]['V_ALIGN'] = "M";


		$pdf->Draw_Data($data);
	}

	$pdf->Draw_Table_Border();








$pdf->Output("Listendruck_W-Zweig_$jahrgang.pdf","I");
$pdf->closeParsers();
?>