<?php

include("kurs/datenbankanbindung.php"); // f&uuml;gt die Datenbankanbindung ein: Sys:\php\includes\kurs\datenbankanbindung.php
$uid1=$_COOKIE["uid1"];

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

require_once('as_utf_class.php');
require_once("table_def.inc");
$pdf=new utfFPDF();


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

$pdf->AddPage();

$db = dbconnect();

$res_hs = $db->query("SELECT mtknr, nachname, vorname, postrasse, poort, poplz, hs FROM stud WHERE uid='$uid1'");
$row_hs = $res_hs->fetch_array();


#$pagecount = $pdf->setSourceFile("praxisstellen.pdf");
#$pdf->addPage();
#$pdf->useTemplate($tplidx,0,0,0);
$pdf->SetFont('Arial', '', 11);
$pdf->SetY(26);
$pdf->SetX(24);
$pdf->Cell(0, 3, "Matrikelnr.: $row_hs[mtknr]" , 0, 0, 'L');


$pdf->SetFont('Arial', '', 7);
$pdf->SetY(52);
$pdf->SetX(24);
$pdf->Cell(0, 3, "$row_hs[vorname] $row_hs[nachname]  -  $row_hs[postrasse]  -  $row_hs[poplz] $row_hs[poort]", 0, 0, 'L');


$pdf->SetLineWidth(0.2);

// Linie zeichnen
$pdf->Line(23, 55, 100, 55); 


## Falzmarken
$pdf->SetLineWidth(0.2);

$pdf->Line(5.3, 105, 9, 105); 
$pdf->Line(5.3, 148.5, 11.5, 148.5); 
$pdf->Line(5.3, 211, 9, 211); 
##


$pdf->SetFont('Arial', '', 11);
$pdf->SetY(61.3);
$pdf->SetX(24);
if($row_hs['hs'] == 'K' or $row_hs['hs'] == 'k'){
  $pdf->MultiCell(0, 4.5, "Hochschule Kehl\nPostfach 1549\n77675 Kehl", 0, 'L');
}else{
  $pdf->MultiCell(0, 4.5, "Hochschule Ludwigsburg\nZulassungsamt\nReuteallee 36\n71634 Ludwigsburg", 0, 'L');
}




$pdf->SetFont('Arial', 'B', 12);
$pdf->SetY(97);
$pdf->SetX(24);
$pdf->MultiCell(0, 4.5, "Praktische Ausbildung im Vorbereitungsdienst", 0, 'L');


$pdf->SetFont('Arial', 'B', 12);
$pdf->SetY(107);
$pdf->SetX(24);
$pdf->MultiCell(0, 4.5, "Antrag auf Zuweisung zu den Ausbildungsstellen", 0, 'L');


$columns = 5; //five columns

#$pdf->SetX(30);
$pdf->SetY(120);
	//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'] = 5;
	$header_type[1]['WIDTH'] = 40;
	$header_type[2]['WIDTH'] = 40;
	$header_type[3]['WIDTH'] = 40;
	$header_type[4]['WIDTH'] = 40;
	
	$header_type[0]['TEXT'] = "";
	$header_type[1]['TEXT'] = "Ausbildungsstelle Anschrift";
	$header_type[2]['TEXT'] = "Vertiefungsbereich";
	$header_type[3]['TEXT'] = "Zeitraum";
	$header_type[4]['TEXT'] = "AG-Standorte";
	
	#$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 t1.dst_id
                       , t1.vert_bereich
                       , DATE_FORMAT(t1.beginn, '%d.%m.%Y') beginn
                       , DATE_FORMAT(t1.beginn, '%Y%m%d') beginnform
                       , DATE_FORMAT(t1.ende, '%d.%m.%Y') ende
                       , t1.saaid saaid
                       , t1.aendid
                       , t1.status
	            FROM stan_antrag t1
	           WHERE t1.status = (
	                               SELECT MAX(t2.status)
	                                 FROM stan_antrag t2
	                                WHERE t1.aendid = t2.aendid
	                                  AND t2.status != '2'
	                                  AND t2.status != '-1'
	                              )
                      AND t1.uid = '$uid1'
                      AND (t1.zuweisung is NULL OR t1.zuweisung='Z')
                    ORDER BY beginnform";
#echo $query;
#exit;
        $result = $db->query ($query)
           or die ("Cannot execute query1");
           

 
        while ($row = $result->fetch_array())
	{
		$data = Array();
		
		$res2 = $db->query("SELECT bezeichnung FROM stan_vertiefungsbereich WHERE vbid='$row[vert_bereich]'");
		$row2 = $res2->fetch_array();
		
                $res4 = $db->query("SELECT bez, ort, str, plz FROM stan_dienststellen WHERE dst_id='$row[dst_id]'");
                $row4 = $res4->fetch_array();
                if($row4[bez] != ''){
                  $dst_bez = $row4[bez]." ".$row4[name];
                  $ort = $row4[ort];
                  $str = $row4[str];
                  $plz = $row4[plz];
                }else{
                  $res5 = $db->query("SELECT bez, ort, str, plz FROM stan_dienststellen_tmp WHERE dst_id='$row[dst_id]'");
                  $row5 = $res5->fetch_array();
                  $dst_bez = $row5[bez]." ".$row5[name];
                  $ort = $row5[ort];
                  $str = $row5[str];
                  $plz = $row5[plz];
                }
		
		$j = $j+1;
		
		
		$res_prio1 = $db->query("SELECT standort
                                            FROM stan_standort a, stan_ag_standort b, stan_ag_standort_wunsch c
                                           WHERE b.agsid = c.wagsid
                                             AND b.sid = a.sid
                                             AND c.saaid='$row[saaid]'
                                             AND c.prio='1'");
		$row_prio1 = $res_prio1->fetch_array();
		
		$res_prio2 = $db->query("SELECT standort
                                            FROM stan_standort a, stan_ag_standort b, stan_ag_standort_wunsch c
                                           WHERE b.agsid = c.wagsid
                                             AND b.sid = a.sid
                                             AND c.saaid='$row[saaid]'
                                             AND c.prio='2'");
		$row_prio2 = $res_prio2->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'] = $j;
			$data[0]['T_ALIGN'] = "C"; //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
			if($dst_bez != ''){
			 $dst_bez = "$dst_bez\n";
			}
			if($str != ''){
			 $str = "$str\n";
			}
			$data[1]['TEXT'] = "$dst_bez$str$plz $ort";
			$data[1]['T_ALIGN'] = "L";
			$data[1]['V_ALIGN'] = "M";
			
			$data[2]['TEXT'] = "$row2[bezeichnung]";
			$data[2]['T_ALIGN'] = "L";
			$data[2]['V_ALIGN'] = "M";
			
			$data[3]['TEXT'] = "$row[beginn] - $row[ende]";
			$data[3]['T_ALIGN'] = "C";
			$data[3]['V_ALIGN'] = "M";
			
			$data[4]['TEXT'] = "Priorität 1: $row_prio1[standort]\nPriorität 2: $row_prio2[standort]";
			$data[4]['T_ALIGN'] = "L";
			$data[4]['V_ALIGN'] = "M";

		$pdf->Draw_Data($data);
	}

	$pdf->Draw_Table_Border();

$pos=$pdf->GetY()+10;
$pdf->SetFont('Arial', 'B', 12);
$pdf->SetY($pos);
$pdf->SetX(24);
$pdf->MultiCell(190, 5, "Persönliche Erklärung", 0, 'L');

$pos=$pdf->GetY();
$pdf->SetFont('Arial', 'B', 12);
$pdf->SetY($pos);
$pdf->SetX(24);
$pdf->MultiCell(7, 5, "1.", 0, 'L');

$pdf->SetFont('Arial', 'B', 12);
$pdf->SetY($pos);
$pdf->SetX(31);
if($row_hs['hs'] == 'K' or $row_hs['hs'] == 'k'){
  $pdf->MultiCell(160, 5, "Die Hinweise der Hochschule Kehl zur praktischen Ausbildung gem. § 23 AprOVw gD (Praxisjahr) habe ich zur Kenntnis genommen.", 0, 'L');
}else{
  $pdf->MultiCell(160, 5, "Die Hinweise der Hochschule Ludwigsburg zur praktischen Ausbildung gem. § 23 AprOVw gD (Praxisjahr) habe ich zur Kenntnis genommen.", 0, 'L');
}

/*
$pos=$pdf->GetY();

$pdf->SetFont('Arial', 'B', 12);
$pdf->SetY($pos);
$pdf->SetX(24);
$pdf->MultiCell(7, 5, "2.", 0, 'L');

$pdf->SetFont('Arial', 'B', 12);
$pdf->SetY($pos);
$pdf->SetX(31);
$pdf->MultiCell(160, 5, "Für die Zeit einer Zuweisung außerhalb Baden-Württembergs verzichte ich auf die Erstattung etwaiger Reisekosten sowie auf die Vergütung von Umzugskosten und Trennungsgeld.", 0, 'L');
*/
$pos=$pdf->GetY();

$pdf->SetFont('Arial', 'B', 12);
$pdf->SetY($pos);
$pdf->SetX(24);
$pdf->MultiCell(7, 5, "2.", 0, 'L');

$pdf->SetFont('Arial', 'B', 12);
$pdf->SetY($pos);
$pdf->SetX(31);
$pdf->MultiCell(160, 5, "Das Einverständnis aller o.a. Ausbildungsstellen liegt mir vor.", 0, 'L');


$pos=$pdf->GetY()+25;
$pdf->SetLineWidth(0.3);

// Linie zeichnen
$pdf->Line(24, $pos, 190, $pos);

$pos=$pos+2;

$pdf->SetFont('Arial', '', 12);
$pdf->SetY($pos);
$pdf->SetX(24);
$pdf->MultiCell(0, 5, "Datum, Unterschrift", 0, 'L');

$pdf->Output();

?>