<?php
$user_admin=$_COOKIE["user_admin"];
$jahrgang=$_COOKIE["jahrgang"];
$hs=$_COOKIE["ck_hs"];


if ($jahrgang == ""){ require("jahrgang.php"); exit;} //Wenn man kein Jahrgang ausgew&auml;hlt hat wird die Jahrgangsauswahlseite geladen

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

// 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_dblatt'");
$row = $result->fetch_array();
if ($row[0] != 1){ include("kurs/rechte.php"); exit;}
// Rechte&uuml;berpr&uuml;fung ende

// Rechteüberprüfung ende


if (isset($_GET['action']))
   $action = $_GET['action'];
else
   $action = "";

switch($action){
default:

echo "
<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
<link rel=\"stylesheet\" href=\"../styles_pc.css\" type=\"text/css\">
<title>Datenblatt</title>
</head>
<body onload=\"if(document.einzel)document.einzel.user1.focus();return false;\">
<table border=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellpadding=\"0\" height=\"100%\" id=\"table1\">
    <tr>
        <td>
        <div align=\"center\">
            <table cellspacing=\"0\" cellpadding=\"0\" width=\"550\" border=\"0\">
                <tr>
                    <td width=\"10\" background=\"../images/box_e1.gif\">
                    <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"3%\" background=\"../images/box_top.gif\" valign=\"top\"></td>
                    <td width=\"95%\" background=\"../images/box_top.gif\">
                    <img height=\"10\" src=\"../images/blank.gif\" width=\"1\"><br>
                    <font class=\"hd\">Datenblatt</font><br>
                    <font class=\"sh\">Übersicht über pers. Daten und zugew. Praxisstellen</font><br>
                    <img height=\"5\" src=\"../images/blank.gif\" width=\"1\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e2.gif\">
                    <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td width=\"1%\" background=\"../images/box_l.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td colspan=\"2\"><br>
              <form action="; echo $_SERVER['PHP_SELF'] . "?action=ubersicht"; echo" method=\"POST\" name=\"einzel\">
			  <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; border-width: 0\" bordercolor=\"#111111\" width=\"100%\" id=\"AutoNumber1\" height=\"115\">
			    <tr>
			      <td width=\"25%\" height=\"17\">
			      </td>
			      <td width=\"25%\" height=\"17\">&nbsp;</td>
			      <td width=\"25%\" height=\"17\">
			      <p>&nbsp;</p>
			      </td>
			      <td width=\"25%\" height=\"17\">
			      <p></p>
			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			      <p></p>
			      </td>
			      <td width=\"50%\" height=\"17\">&nbsp;</td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			        Bitte Matrikelnr. eingeben:
			      <p></p>
			      </td>
			      <td width=\"50%\" height=\"17\">
			      <p align=\"left\">
                                <input type='text' size='10' name='user1'>
			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			        &nbsp;
			      <p></p>
			      </td>
			      <td width=\"50%\" height=\"17\">
			      <p align=\"center\">
                                &nbsp;
			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			      &nbsp;
			      </td>
			      <td width=\"50%\" align=\"left\" height=\"17\">
			      oder
			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			        &nbsp;
			      <p></p>
			      </td>
			      <td width=\"50%\" height=\"17\">
			      <p align=\"center\">
                                &nbsp;
			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			      Benutzer auswählen
			      </td>
			      <td width=\"50%\" align=\"left\" height=\"17\">
			    			      ";
			    			      
			    
			    			      $db = dbconnect();
			    			      $query = "SELECT mtknr, vorname, nachname, durchgefallen
			    			                  FROM stud
			    			                 WHERE jahrgang='$jahrgang'
			    			                   AND uid IN (SELECT uid FROM stan_antrag)
			    			                   and hs='$hs'
			    			                 ORDER BY nachname";
			    			      $result = $db->query ($query)
			    			         or die ("Cannot execute query");
			    			      echo "<select size=\"5\" name=\"user2\">";
			    			      while ($row = $result->fetch_array()){
			                                    echo "<option value=\"".$row['mtknr']."\">$row[nachname], $row[vorname]";
			                                    if ($row['durchgefallen'] == "Y"){
			                                      echo " *";
			                                    }
			                                    echo "
			                                    &nbsp;&nbsp;&nbsp;</option>\n";
			    			      }
			    			      echo "</select>";
			    
			      echo "
			      <br>
			      * = inaktiver Bewerber
			      
			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			      &nbsp;
			      </td>
			      <td width=\"50%\" align=\"left\" height=\"17\">
			      &nbsp;
			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			      Ausgabeformat
			      </td>
			      <td width=\"50%\" align=\"left\" height=\"17\">
			      <label for=\"r1\"><input type=\"radio\" name=\"ansicht\" value=\"0\" id=\"r1\" checked> Detailansicht</label><br>
			      <label for=\"r2\"><input type=\"radio\" name=\"ansicht\" value=\"1\" id=\"r2\"> Kompaktansicht</label><br>
			      </td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"17\">
			      &nbsp;
			      </td>
			      <td width=\"50%\" align=\"left\" height=\"17\">
			      &nbsp;
			      </td>
			    </tr>
			    <tr>
			      <td width=\"100%\" \" colspan='2' align=\"center\">
			      <input type=\"submit\" value=\"Abschicken\" name=\"B1\"></td>
			    </tr>
			    <tr>
			      <td width=\"50%\"  height=\"18\">
			      </td>
			      <td width=\"50%\">
			        &nbsp;
			      </td>

			    </tr>
                            <tr>
                              <td width=\"50%\">
                              </td>
                              <td width=\"50%\" align=\"center\">
                              </td>
                            </tr>
                            <tr>
                              <td width=\"50%\">
                              </td>
                              <td width=\"50%\" align=\"center\">
                                &nbsp;
                              </td>
                            </tr>
			  </table>
			  </form>
                    </td>
                    <td width=\"1%\" background=\"../images/box_r.gif\">
                    <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                </tr>
                <tr>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../images/box_e3.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../images/box_bottom.gif\" colspan=\"2\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"8\"></td>
                    <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e4.gif\">
                    <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"> </td>
                </tr>
            </table>
        </div>
        </td>
    </tr>
</table>
</body>
</html>";
break;
case "ubersicht":


$user = $_POST['user2'];

if($_POST['user1'] != ''){  // Wenn Matrikelnummer eingegeben, dann prüfen, ob es diese im System gibt

  $user = $_POST['user1']; // vorrangig die Matrikelnr bei Eingabe behandeln

  $result = $db->query("SELECT 1
                           FROM stud
                          WHERE mtknr ='$user1'");
  $row = $result->fetch_array();
  $bewerber = $row['bid'];
  
  if($row[0] == ''){
  echo "
  <html>
  <head>
  <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
  <link rel=\"stylesheet\" href=\"../styles_pc.css\" type=\"text/css\">
  <title>Falsche Eingabe</title>
  </head>
  <body>
  <table border=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellpadding=\"0\" height=\"100%\" id=\"table1\">
     <tr>
         <td>
         <div align=\"center\">
             <table cellspacing=\"0\" cellpadding=\"0\" width=\"550\" border=\"0\">
                 <tr>
                     <td width=\"10\" background=\"../images/box_e1.gif\">
                     <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                     <td nowrap=\"nowrap\" align=\"left\" width=\"3%\" background=\"../images/box_top.gif\" valign=\"top\"></td>
                     <td width=\"95%\" background=\"../images/box_top.gif\">
                     <img height=\"10\" src=\"../images/blank.gif\" width=\"1\"><br>
                     <span class=\"sh\">Falsche Eingabe</span><br>
                     <img height=\"5\" src=\"../images/blank.gif\" width=\"1\"></td>
                     <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e2.gif\">
                     <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                 </tr>
                 <tr>
                     <td width=\"1%\" background=\"../images/box_l.gif\">
                     <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                     <td colspan=\"2\"><br>
                     <p align=\"center\"><b>Die Matrikelnummer ist im System nicht vorhanden</p></b>
                     </p>
                     <p align=\"center\"><a href=\"javascript:history.back()\">
                     <img border=\"0\" src=\"../images/zurueck.gif\" width=\"77\" height=\"22\"></a><br>
                     </p>
                     <p></p>
                     <p></p>
                     <p></p>
                     <p></p>
                     <p><br>
                     </p>
                     </td>
                     <td width=\"1%\" background=\"../images/box_r.gif\">
                     <img height=\"1\" src=\"../images/blank.gif\" width=\"22\"></td>
                 </tr>
                 <tr>
                     <td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../images/box_e3.gif\">
                     <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"></td>
                     <td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../images/box_bottom.gif\" colspan=\"2\">
                     <img height=\"16\" src=\"../images/blank.gif\" width=\"8\"></td>
                     <td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../images/box_e4.gif\">
                     <img height=\"16\" src=\"../images/blank.gif\" width=\"22\"> </td>
                 </tr>
             </table>
         </div>
         </td>
     </tr>
  </table>
  </body>
  </html>";
  exit;
  }
}

#############################################################
## Kompaktansicht Anfang
#############################################################


if($_POST['ansicht'] == 1){
$res = $db->query("SELECT uid FROM stud WHERE mtknr='$user'");
$row = $res->fetch_array();

$res_ansp = $db->query("SELECT wert1 name, wert2 mail FROM parameter WHERE pid='6'");
$row_ansp = $res_ansp->fetch_array();

$res_kontakt = $db->query("SELECT wert1 tel, wert2 fax FROM parameter WHERE pid='5'");
$row_kontakt = $res_kontakt->fetch_array();

$uid1 = $row['uid'];

chdir("./anschreiben");

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("blanko_ludwigsburg.pdf");

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

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


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

$pdf->Image('logo.png', 116, 10,64); #https://www.fpdf.de/funktionsreferenz/?funktion=Image

$heute_format = date("d.m.Y", mktime(0, 0, 0, date("m"), date("d"), date("Y")));  // ISO-8601 Format wie in der Datenbank: Formatierung f&uuml;r Vergleiche erforderlich

$pdf->SetFont('Arial', 'B', 10);
$pdf->SetY(56);
$pdf->SetX(117.9);
$pdf->MultiCell(47, 3, "Zulassung", 0, 'L');


$pdf->SetFont('Arial', '', 8);
$pos=$pdf->GetY()+3.7;
$pdf->SetY($pos);
$pdf->SetX(117.9);
$pdf->MultiCell(47, 3, "Ludwigsburg,", 0, 'L');


$pdf->SetFont('Arial', '', 8);
$pdf->SetY($pos);
$pdf->SetX(143.1);
$pdf->MultiCell(47, 3, "$heute_format", 0, 'R');

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

$pdf->SetFont('Arial', '', 8);
$pdf->SetY($pos);
$pdf->SetX(117.9);
$pdf->MultiCell(47, 3, "Bearbeiterin", 0, 'L');

$pdf->SetFont('Arial', '', 8);
$pdf->SetY($pos);
$pdf->SetX(143.1);
$pdf->MultiCell(47, 3, "$row_ansp[name]", 0, 'R');


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

$pdf->SetFont('Arial', '', 8);
$pdf->SetY($pos);
$pdf->SetX(117.9);
$pdf->MultiCell(47, 3, "Telefon", 0, 'L');

$pdf->SetFont('Arial', '', 8);
$pdf->SetY($pos);
$pdf->SetX(143.1);
$pdf->MultiCell(47, 3, "$row_kontakt[tel]", 0, 'R');


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

$pdf->SetFont('Arial', '', 8);
$pdf->SetY($pos);
$pdf->SetX(117.9);
$pdf->MultiCell(47, 3, "Fax", 0, 'L');

$pdf->SetFont('Arial', '', 8);
$pdf->SetY($pos);
$pdf->SetX(143.1);
$pdf->MultiCell(47, 3, "$row_kontakt[fax]", 0, 'R');


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

$pdf->SetFont('Arial', '', 8);
$pdf->SetY($pos);
$pdf->SetX(117.9);
$pdf->MultiCell(47, 3, "e-mail", 0, 'L');

$pdf->SetFont('Arial', '', 8);
$pdf->SetY($pos);
$pdf->SetX(143.1);
$pdf->MultiCell(47, 3, "$row_ansp[mail]", 0, 'R');

$pdf->SetFont('Arial', '', 8);
$pdf->SetY(45);
$pdf->SetX(23);
$pdf->MultiCell(80, 3, "HS Ludwigsburg ".uchr(149)." Postfach 0489 ".uchr(149)." 71604 Ludwigsburg", 0, 'L');


########Kontaktdaten HS Ende #####################


$pdf->SetFont('Times', 'BI', 14);
$pdf->SetY(56);
$pdf->SetX(23);
$pdf->Cell(0, 3, "Übersicht Praxisstellen", 0, 0, 'L');

$db = dbconnect();
$res = $db->query("SELECT nachname, vorname, stg, Jahrgang FROM stud WHERE uid='$uid1'");
$row = $res->fetch_array();

$pdf->SetFont('Times', 'B', 12);
$pdf->SetY(100);
$pdf->SetX(23);
$pdf->MultiCell(0, 4.5, "Praxisstellenübersicht für $row[vorname] $row[nachname]", 0, 'L');



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

$columns = 3; //five columns

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

	$header_type[0]['WIDTH'] = 40;
	$header_type[1]['WIDTH'] = 61;
	$header_type[2]['WIDTH'] = 61;

	
	$header_type[0]['TEXT'] = "Zeitraum";
	$header_type[1]['TEXT'] = "Ausbildungsstelle";
	$header_type[2]['TEXT'] = "Vertiefungsbereich";
	
	#$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.saaid
                       , t1.vert_bereich
                       , t1.uid
                       , DATE_FORMAT(t1.beginn, '%d.%m.%Y') beginn
                       , DATE_FORMAT(t1.ende, '%d.%m.%Y') ende
                       , t1.dst_id
                    FROM stan_antrag t1
                   WHERE t1.status = (
                                      SELECT MAX(t2.status)
                                        FROM stan_antrag t2
                                       WHERE t1.aendid = t2.aendid
                                         AND t2.status !='2' #hinzugefügt am 10.06.2009, weil Status 2 angezeigt wurde
                                      )
                     AND t1.uid ='$uid1'
                     AND t1.zuweisung='Z'
                   ORDER BY DATE_FORMAT(t1.beginn, '%Y%m%d') ASC";
        $result = $db->query ($query)
           or die ("Cannot execute query");
 
        while ($row = $result->fetch_array())
	{
		$data = Array();
		
		$res2 = $db->query("SELECT bezeichnung FROM stan_vertiefungsbereich WHERE vbid='$row[vert_bereich]'");
		$row2 = $res2->fetch_array();
		
		
                $result5 = $db->query("SELECT concat(bezeichnung, ' ',name) name
                                          FROM stan_dienststellen
                                         WHERE dst_id ='$row[dst_id]'");
                $row5 = $result5->fetch_array();

                $result6 = $db->query("SELECT bez
                                          FROM stan_dienststellen_tmp
                                         WHERE dst_id ='$row[dst_id]'");
                $row6 = $result6->fetch_array();

                if($row5['name'] != '' and $row6['bez'] == ''){
                  $bezeichnung = $row5['name'];
                }


                if($row5['name'] == '' and $row6['bez'] != ''){
                  $bezeichnung = $row6['bez'];
                }

                if($row5['name'] == '' and $row6['bez'] == ''){
                  
                  if($row2['bezeichnung'] == 'Antragszeitraum Beginn' or $row2['bezeichnung'] == 'Antragszeitraum Ende'){
                    $bezeichnung = $row2['bezeichnung'];
                  }else{
                    $bezeichnung = '<i>Zeitraum vorgemerkt</i>';
                  }
                }

/* 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[beginn] - $row[ende]";
			$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'] = "$bezeichnung";
			$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";
			


		$pdf->Draw_Data($data);
	}

	$pdf->Draw_Table_Border();



$pdf->Output("$uid1-Datenblatt.pdf","D");
$pdf->closeParsers();
exit;
} 

#############################################################
## Kompaktansicht Ende
#############################################################














#############################################################
## DETAILANSICHT ANFANG
#############################################################

if(isset($_GET['mtknr'])){ // Bei Quereinsteiger (offene Erstanträge, offene Änderungsanträge)
  $user = $_GET['mtknr'];
}



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



$db = dbconnect();
$res = $db->query("SELECT uid, mtknr, nachname, vorname, postrasse, poplz, poort, mail, mail2, stg FROM stud WHERE mtknr='$user'");
$row = $res->fetch_array();

$uid1 = "$row[uid]";

$pdf->addPage();
$pdf->SetFont('Arial', 'BU', 16);
$pdf->SetY(24);
$pdf->SetX(24);
$pdf->Cell(0, 3, "Datenblatt über zugewiesene Praxisstellen", 0, 0, 'L');

$pdf->SetFont('Arial', 'B', 11);
$pdf->SetY(37);
$pdf->SetX(24);
$pdf->Cell(0, 3, "Persönliche Daten", 0, 0, 'L');

$pdf->SetFont('Arial', '', 11);
$pdf->SetY(45);
$pdf->SetX(24);
$pdf->Cell(0, 3, "Name:", 0, 0, 'L');

$pdf->SetFont('Arial', '', 11);
$pdf->SetY(45);
$pdf->SetX(80);
$pdf->Cell(0, 3, "$row[vorname] $row[nachname]", 0, 0, 'L');

$pdf->SetFont('Arial', '', 11);
$pdf->SetY(53);
$pdf->SetX(24);
$pdf->Cell(0, 3, "Straße:", 0, 0, 'L');

$pdf->SetFont('Arial', '', 11);
$pdf->SetY(53);
$pdf->SetX(80);
$pdf->Cell(0, 3, "$row[postrasse]", 0, 0, 'L');

$pdf->SetFont('Arial', '', 11);
$pdf->SetY(61);
$pdf->SetX(24);
$pdf->Cell(0, 3, "PLZ / Ort:", 0, 0, 'L');

$pdf->SetFont('Arial', '', 11);
$pdf->SetY(61);
$pdf->SetX(80);
$pdf->Cell(0, 3, "$row[poplz] $row[poort]", 0, 0, 'L');

$pdf->SetFont('Arial', '', 11);
$pdf->SetY(69);
$pdf->SetX(24);
$pdf->Cell(0, 3, "Email1:", 0, 0, 'L');

$pdf->SetFont('Arial', '', 11);
$pdf->SetY(69);
$pdf->SetX(80);
$pdf->Cell(0, 3, "$row[mail]", 0, 0, 'L');

$pdf->SetFont('Arial', '', 11);
$pdf->SetY(77);
$pdf->SetX(24);
$pdf->Cell(0, 3, "Email2:", 0, 0, 'L');

$pdf->SetFont('Arial', '', 11);
$pdf->SetY(77);
$pdf->SetX(80);
$pdf->Cell(0, 3, "$row[mail2]", 0, 0, 'L');

$pdf->SetFont('Arial', '', 11);
$pdf->SetY(85);
$pdf->SetX(24);
$pdf->Cell(0, 3, "Matrikelnummer:", 0, 0, 'L');

$pdf->SetFont('Arial', '', 11);
$pdf->SetY(85);
$pdf->SetX(80);
$pdf->Cell(0, 3, "$row[mtknr]", 0, 0, 'L');

$pdf->SetFont('Arial', '', 11);
$pdf->SetY(93);
$pdf->SetX(24);
$pdf->Cell(0, 3, "Studienzweig:", 0, 0, 'L');

$pdf->SetFont('Arial', '', 11);
$pdf->SetY(93);
$pdf->SetX(80);

if ($row['stg'] == 'I'){
  $pdf->Cell(0, 3, "Innenverwaltung", 0, 0, 'L');
}
elseif($row['stg'] == 'V'){
  $pdf->Cell(0, 3, "Innenverwaltung V-Zweig", 0, 0, 'L');
}elseif($row['stg'] == 'W'){
  $pdf->Cell(0, 3, "Innenverwaltung W-Zweig", 0, 0, 'L');
}



$query = "SELECT t1.saaid
                       , t1.vert_bereich
                       , t1.uid
                       , DATE_FORMAT(t1.beginn, '%d.%m.%Y') beginn
                       , DATE_FORMAT(t1.ende, '%d.%m.%Y') ende
                       , t1.dst_id
                       , abteilung
                       , tel_abteilung
                    FROM stan_antrag t1
                   WHERE t1.status = (
                                      SELECT MAX(t2.status)
                                        FROM stan_antrag t2
                                       WHERE t1.aendid = t2.aendid
                                         AND t2.status !='2' #hinzugefügt am 10.06.2009, weil Status 2 angezeigt wurde
                                      )
                     AND t1.uid ='$uid1'
                     AND t1.zuweisung='Z'
                   ORDER BY DATE_FORMAT(t1.beginn, '%Y%m%d') ASC";
         
$result = $db->query ($query)
   or die ("Cannot execute query");

$ln_number = 0;

while ($row1 = $result->fetch_array()){
  $pdf->addPage();
  
  $result_zuw1 = $db->query("SELECT 1,wagsid
                               FROM stan_ag_standort_wunsch
                              WHERE saaid ='$row1[saaid]'
                                AND prio='1'");
                                
  $row_zuw1 = $result_zuw1->fetch_array();
    
  $result_standort1 = $db->query("SELECT standort
                                     FROM stan_ag_standort a, stan_standort b
                                    WHERE a.sid=b.sid
                                      AND a.agsid ='$row_zuw1[wagsid]'");

  $row_s1 = $result_standort1->fetch_array();

  $res2 = $db->query("SELECT bezeichnung FROM stan_vertiefungsbereich WHERE vbid='$row1[vert_bereich]'");
  $row2 = $res2->fetch_array();
  

  $result5 = $db->query("SELECT concat(bezeichnung, ' ',name) name, str, plz, postfach, plz_postfach, ort, bundesland
                            FROM stan_dienststellen
                           WHERE dst_id ='$row1[dst_id]'");
  $row5 = $result5->fetch_array();
  
  $result6 = $db->query("SELECT bez, str, plz, postfach, plz_postfach, ort, bundesland
                            FROM stan_dienststellen_tmp
                           WHERE dst_id ='$row1[dst_id]'");
  $row6 = $result6->fetch_array();
  
  if($row5['name'] != '' and $row6['bez'] == ''){
    $bezeichnung = $row5['name'];
    $str = $row5['str'];
    $plz = $row5['plz'];
    $postfach = $row5['postfach'];
    $plz_postfach = $row5['plz_postfach'];
    $ort = $row5['ort'];
    $bundesland = $row5['bundesland'];
  }
  
  
  if($row5['name'] == '' and $row6['bez'] != ''){
   $bezeichnung = $row6['bez'];
    $str = $row6['str'];
    $plz = $row6['plz'];
    $postfach = $row6['postfach'];
    $plz_postfach = $row6['plz_postfach'];
    $ort = $row6['ort'];
    $bundesland = $row6['bundesland'];
  }
  
  if($row5['name'] == '' and $row6['bez'] == ''){
    
    if($row2['bezeichnung'] == 'Antragszeitraum Beginn' or $row2['bezeichnung'] == 'Antragszeitraum Ende'){
      $bezeichnung = $row2['bezeichnung'];
    }else{
     $bezeichnung = '<i>Zeitraum vorgemerkt</i>';
    }
  }
 
  $ln_number = $ln_number + 1;
  
  $pdf->SetY(24);
  $pdf->SetX(24);
  $pdf->SetFont('Arial', 'B', 11);
  $pdf->MultiCell(160, 3,"Praxisstelle $ln_number", 0, 'L');

  
  $pdf->SetY(36);
  $pdf->SetX(24);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"Bezeichnung:", 0, 'L');
  
  $pdf->SetY(36);
  $pdf->SetX(80);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"$bezeichnung", 0, 'L');
  
  if($str != ''){
  $pos = $pdf->GetY()+8;
  $pdf->SetY($pos);
  $pdf->SetX(24);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"Straße:", 0, 'L');
  
  
  $pdf->SetY($pos);
  $pdf->SetX(80);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"$str", 0, 'L');
  }
  
  if($plz != ''){
  $pos = $pdf->GetY()+8;
  $pdf->SetY($pos);
  $pdf->SetX(24);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"PLZ::", 0, 'L');
  
  
  $pdf->SetY($pos);
  $pdf->SetX(80);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"$plz", 0, 'L');
  }
  
  
  if($postfach != ''){
  $pos = $pdf->GetY()+8;
  $pdf->SetY($pos);
  $pdf->SetX(24);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"Postfach:", 0, 'L');
  
  
  $pdf->SetY($pos);
  $pdf->SetX(80);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"$postfach", 0, 'L');
  }
  
  
  if($plz_postfach != ''){
  $pos = $pdf->GetY()+8;
  $pdf->SetY($pos);
  $pdf->SetX(24);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"PLZ Postfach:", 0, 'L');
  
  
  $pdf->SetY($pos);
  $pdf->SetX(80);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"$plz_postfach", 0, 'L');
  }
  
  if($ort != ''){
  $pos = $pdf->GetY()+8;
  $pdf->SetY($pos);
  $pdf->SetX(24);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"Ort:", 0, 'L');
  
  
  $pdf->SetY($pos);
  $pdf->SetX(80);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"$ort", 0, 'L');
  }
  
  
  if($bundesland != ''){
  $pos = $pdf->GetY()+8;
  $pdf->SetY($pos);
  $pdf->SetX(24);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"Bundesland:", 0, 'L');
  
  
  $pdf->SetY($pos);
  $pdf->SetX(80);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"$bundesland", 0, 'L');
  }
  
  
  $pos = $pdf->GetY()+8;
  $pdf->SetY($pos);
  $pdf->SetX(24);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"Zeitraum:", 0, 'L');
  

  $pdf->SetY($pos);
  $pdf->SetX(80);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"$row1[beginn] - $row1[ende]", 0, 'L');
  
  if($row1['abteilung'] != ''){
  $pos = $pdf->GetY()+8;
  $pdf->SetY($pos);
  $pdf->SetX(24);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"Abteilung:", 0, 'L');
  
  
  $pdf->SetY($pos);
  $pdf->SetX(80);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"$row1[abteilung]", 0, 'L');
  }
  
  if($row1['tel_abteilung'] != ''){
  $pos = $pdf->GetY()+8;
  $pdf->SetY($pos);
  $pdf->SetX(24);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"Tel. Abteilung:", 0, 'L');
  
  
  $pdf->SetY($pos);
  $pdf->SetX(80);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"$row1[tel_abteilung]", 0, 'L');
  }
  
  
  
  if($row2['bezeichnung'] != ''){
  $pos = $pdf->GetY()+8;
  $pdf->SetY($pos);
  $pdf->SetX(24);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"Vertiefungsbereich:", 0, 'L');
  
  
  $pdf->SetY($pos);
  $pdf->SetX(80);
  $pdf->SetFont('Arial', '', 11);
  $pdf->MultiCell(160, 3,"$row2[bezeichnung]", 0, 'L');
  }
  
}


$pdf->addPage();

$columns = 4; //five columns
$pos=$pdf->GetY()+10;
$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;
	
	
	for($i=0; $i<$columns; $i++) $header_type[$i] = $table_default_header_type;

	
	$header_type[0]['WIDTH'] = 36;
	$header_type[1]['WIDTH'] = 43;
	$header_type[2]['WIDTH'] = 43;
	$header_type[3]['WIDTH'] = 43;
	
	$header_type[0]['TEXT'] = "Vertiefungsbereich";
	$header_type[1]['TEXT'] = "Adminpriorität";
	$header_type[2]['TEXT'] = "Priorität 1";
	$header_type[3]['TEXT'] = "Priorität 2";
	
	
	#$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 distinct t1.vert_bereich
	            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')";

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

 
        while ($row = $result->fetch_array())
	{
		$data = Array();
		

		$res2 = $db->query("SELECT bezeichnung FROM stan_vertiefungsbereich WHERE vbid='$row[vert_bereich]'");
		$row2 = $res2->fetch_array();

		$res_prio0 = $db->query("SELECT standort, abdatum, b.block, pendler
                                            FROM stan_ag_standort a, stan_ag_standort_wunsch b, stan_standort c
                                           WHERE a.agsid = b.wagsid
                                             AND c.sid = a.sid
                                             AND b.uid = '$uid1'
                                             AND a.vbid='$row[vert_bereich]'
                                             AND b.prio='0'");
		$row_prio0 = $res_prio0->fetch_array();
		
		
		$res_prio1 = $db->query("SELECT standort, abdatum, b.block, pendler
                                            FROM stan_ag_standort a, stan_ag_standort_wunsch b, stan_standort c
                                           WHERE a.agsid = b.wagsid
                                             AND c.sid = a.sid
                                             AND b.uid = '$uid1'
                                             AND a.vbid='$row[vert_bereich]'
                                             AND b.prio='1'");
		$row_prio1 = $res_prio1->fetch_array();
		
		

		
		$res_prio2 = $db->query("SELECT standort, abdatum, b.block, pendler
                                            FROM stan_ag_standort a, stan_ag_standort_wunsch b, stan_standort c
                                           WHERE a.agsid = b.wagsid
                                             AND c.sid = a.sid
                                             AND b.uid = '$uid1'
                                             AND a.vbid='$row[vert_bereich]'
                                             AND b.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);
*/
                 if($row_prio1['block'] != ''){

			$data[0]['TEXT'] = "$row2[bezeichnung]";
			$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
			if($dst_bez != ''){
			 $dst_bez = "$dst_bez\n";
			}
			if($str != ''){
			 $str = "$str\n";
			}
			$data[1]['TEXT'] = "$row_prio0[standort] (Block $row_prio0[block]) ab $row_prio0[abdatum] ($row_prio0[pendler])";
			$data[1]['T_ALIGN'] = "L";
			$data[1]['V_ALIGN'] = "M";
			
			
			$data[2]['TEXT'] = "$row_prio1[standort] (Block $row_prio1[block]) ab $row_prio1[abdatum] ($row_prio1[pendler])";
			$data[2]['T_ALIGN'] = "L";
			$data[2]['V_ALIGN'] = "M";
			
			$data[3]['TEXT'] = "$row_prio2[standort] (Block $row_prio2[block]) ab $row_prio2[abdatum] ($row_prio2[pendler])";
			$data[3]['T_ALIGN'] = "L";
			$data[3]['V_ALIGN'] = "M";
	 	
	 	
		  $pdf->Draw_Data($data);
		}
	}

	$pdf->Draw_Table_Border();	



$pdf->Output("newpdf.pdf","i");
$pdf->closeParsers();

#############################################################
## DETAILANSICHT Ende
#############################################################

} // Ende Action script
?>