<?php

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

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

   switch($action){
   default:

$db = dbconnect();
include("kurs/sta/stan_soadmonline_write.php");     // F&uuml;r Statistik, wieviele User online sind

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>Erfasste Termine</title>
</head>
<body onload=\"if(document.ver_erf)document.ver_erf.beg_tag.focus();return false;\">
<table border=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellpadding=\"0\"id=\"table2\">
    <tr>
        <td>
        <div align=\"center\">
        <form action="; echo $_SERVER['PHP_SELF'] . "?action=liste method=\"POST\" name='searchform'>
            <table cellspacing=\"0\" cellpadding=\"0\" width=\"95%\" 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=\"98%\" background=\"../../images/box_top.gif\" valign=\"top\">
                    <img height=\"10\" src=\"../../images/blank.gif\" width=\"1\"><br>
                    <font class=\"hd\">Termin wählen für Anwesenheitsliste</font><br>
                    <span class='sh'>Die Teilnehmer können sich ständig ändern. Drucken Sie sich die Listen daher zeitnah zum Veranstaltungstermin
                    </span>
                    <img height=\"5\" src=\"../../images/blank.gif\" width=\"1\"></font></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>
                      <table border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"border-width:0; border-collapse: collapse\" bordercolor=\"#111111\" width=\"100%\" id=\"AutoNumber1\" height=\"18\">
                        <tr>
                          <td width=\"5%\">
                          <b>Nr</b>
                          </td>
                          <td width=\"25%\">
                          <b>Beginn</b>
                          </td>
                          <td width=\"40%\" align=\"left\">
                           <b>Vertiefungsbereich</b>
                          </td>
                          <td width=\"25%\" align=\"center\">
                           <b>Teilnehmer</b>
                          </td>
                          <td width=\"10%\" align=\"center\">
                           <b>Auswahl</b>
                          </td>
                        </tr>";
                          $db = dbconnect();
                        $ln_zaehler = 1; // Z&auml;hler f&uuml;r Anzahl der Termine
                        
                        
                         $query = "SELECT  DATE_Format(datum, '%d.%m.%y') Datum_von
                                         , DATE_Format(datum, '%H:%i') Zeit_von
                                         , DATE_Format(datum, '%d') tag_von
                                         , DATE_Format(datum, '%m') mon_von
                                         , DATE_Format(datum, '%y') jahr_von
                                         , oertlichkeit
                                         , hinweis
                                         , status
                                         , c.bezeichnung
                                         , DatID
                                      FROM stan_ag_standort_termine a, stan_ag_standort b, stan_vertiefungsbereich c
                                     WHERE a.fagsid = b.agsid
                                       AND c.vbid = b.vbid
                                       AND b.jahr='$jahrgang'
                                       AND b.sid='$standort'
                                     ORDER BY b.vbid, a.datum ASC";

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

                        while ($row = $result->fetch_array()){
                          $res_tn = $db->query("SELECT count(*) Anz
                                                   FROM stan_ag_wunsch_vw a, stan_ag_standort b, stan_ag_standort_termine c, stud d
						  WHERE a.prio0 =b.agsid
						    AND b.agsid = c.fagsid
						    AND a.uid=d.uid
						    AND c.datid='$row[DatID]'
						    AND b.sid='$standort'
						    AND d.durchgefallen != 'Y'
						    AND d.jahrgang = '$jahrgang'
						    AND d.stg='I'
		                                ");
                          $row_tn = $res_tn->fetch_array();
                          
                          $wochentag_von = date("l", mktime(0,0,0,$row['mon_von'],$row['tag_von'],$row['jahr_von']));
                          switch($wochentag_von)
                          {
                            case 'Sunday':
                                $wochentag_von = "So.";
                                break;
                            case 'Monday':
                                $wochentag_von = "Mo.";
                                break;
                            case 'Tuesday':
                                $wochentag_von = "Di.";
                                break;
                            case 'Wednesday':
                                $wochentag_von = "Mi.";
                                break;
                            case 'Thursday':
                                $wochentag_von = "Do.";
                                break;
                            case 'Friday':
                                $wochentag_von = "Fr.";
                                break;
                            case 'Saturday':
                                $wochentag_von = "Sa.";
                                break;
                          }
                          

                          

                        echo"
                        <tr>
                          <td width=\"5%\">
                          <b>$ln_zaehler</b>
                          </td>
                          <td width=\"25%\">
                          $wochentag_von $row[Datum_von] um $row[Zeit_von] Uhr
                          </td>
                          <td width=\"40%\" align=\"left\">
                           $row[bezeichnung]
                          </td>
                          <td width=\"20%\" align=\"center\">
                           $row_tn[Anz]
                          </td>
                          <td width=\"15%\" align=\"center\">";
                            if($row_tn[Anz] != 0){
                              echo"<input type=\"radio\" name=\"termin\" value='$row[DatID]'><br>";
                            }else{
                              echo "<i>keine</i>";
                            }
                            echo"
                          </td>
                        </tr>";
                        $ln_zaehler = $ln_zaehler+1;
                       }
                       echo"
                      </table>
                    </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\">
                    <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>
            <input type=\"submit\" value=\"Abschicken\" name=\"B1\" size=\"20\">
            </form>
        </div>
        </td>
    </tr>
</table>
</body>
</html>
";





break;
case "liste":






#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(6);
$pdf->SetLeftMargin(6);
$pdf->AddPage();

$db = dbconnect();


#$pagecount = $pdf->setSourceFile("praxisstellen.pdf");
#$pdf->addPage();
#$pdf->useTemplate($tplidx,0,0,0);

$res_so = $db->query("SELECT standort, block, abdatum, pendler
                         FROM stan_standort
                        WHERE sid = '$standort'");
$row_so = $res_so->fetch_array();

$pdf->SetFont('Arial', '', 10);
$pdf->SetY(20);
$pdf->SetX(20);
$pdf->MultiCell(0,4, "AG-Standort:",0,'J',0);

$pdf->SetFont('Arial', '', 10);
$pdf->SetY(20);
$pdf->SetX(60);
$pdf->MultiCell(0,4, "$row_so[standort] (Block $row_so[block]) ab $row_so[abdatum] ($row_so[pendler])",0,'J',0);


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


$res_vt = $db->query("SELECT bezeichnung
                         FROM stan_ag_standort_termine a, stan_ag_standort b, stan_vertiefungsbereich c
                        WHERE a.fagsid =b.agsid
                          AND b.vbid = c.vbid
                          AND a.datid='$_POST[termin]'");
$row_vt = $res_vt->fetch_array();

$pdf->SetFont('Arial', '', 10);
$pdf->SetY($pos);
$pdf->SetX(20);
$pdf->MultiCell(0,4, "Vertiefungsbereich:",0,'J',0);

$pdf->SetFont('Arial', '', 10);
$pdf->SetY($pos);
$pdf->SetX(60);
$pdf->MultiCell(0,4, "$row_vt[bezeichnung]",0,'J',0);


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

$res_dt = $db->query("SELECT date_format(datum, '%d.%m.%Y') datum
                         FROM stan_ag_standort_termine
                        WHERE datid='$_POST[termin]'");
$row_dt = $res_dt->fetch_array();
$pdf->SetFont('Arial', '', 10);
$pdf->SetY($pos);
$pdf->SetX(20);
$pdf->MultiCell(0,4, "Datum:",0,'J',0);

$pdf->SetFont('Arial', '', 10);
$pdf->SetY($pos);
$pdf->SetX(60);
$pdf->MultiCell(0,4, "$row_dt[datum]",0,'J',0);





$pos=$pdf->GetY()-16;

$pdf->Rect(20,18,170,$pos);

$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'] = 10;
	$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'] = "Nr";
	
	$header_type[1]['WIDTH'] = 65;
	$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'] = "Name";
	
	
	$header_type[2]['WIDTH'] = 30;
	$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'] = "Hochschule";
	
	$header_type[3]['WIDTH'] = 65;
	$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'] = "Unterschrift";
	
	#$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 vorname, nachname, hs, mail, mail2
		    FROM stan_ag_wunsch_vw a, stan_ag_standort b, stan_ag_standort_termine c, stud d
		   WHERE a.prio0 =b.agsid
		     AND b.agsid = c.fagsid
		     AND a.uid=d.uid
		     AND c.datid='$_POST[termin]'
		     AND b.sid='$standort'
		     AND d.durchgefallen != 'Y'
		     AND d.jahrgang = '$jahrgang'
		     AND d.stg='I'
                 ORDER BY d.nachname, d.vorname";

        $result = $db->query ($query)
           or die ("Cannot execute query1");
           
 $ln_zaehler = 0;
 $ln_zaehler1 = 0;
        while ($row = $result->fetch_array())
	{
	$ln_zaehler1 = $ln_zaehler1+1;
	$ln_zaehler = $ln_zaehler+1;
		$data = Array();
		


                if($row[hs] == 'K' or $row[hs] == 'k'){
                  $hs = "Kehl";
                }else{
                  $hs = "Ludwigsburg";
                }

/* 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'] = "$ln_zaehler";
			$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'] = "$row[vorname] $row[nachname]";
			$data[1]['T_ALIGN'] = "L"; //C=CENTER, L=LEFT, R=RIGHT, J=JUSTIFY
			$data[1]['V_ALIGN'] = "M"; //T=TOP, M=MIDDLE, B=BOTTOM
		       #$data[1]['T_TYPE'] = "BI"; // B=BOLD, I=ITALIC
			
			$data[2]['TEXT'] = "$hs";
			$data[2]['T_ALIGN'] = "L";
			$data[2]['V_ALIGN'] = "M";

			$data[3]['TEXT'] = "";
			$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
		if($ln_zaehler1 == 22){ // --> Nach X Zeilen Seitenumbruch einfügen
		  $pdf->AddPage();
		  $ln_zaehler1 = 0;
		}
	}
	$pdf->Draw_Table_Border();
$pdf->Output();

}//Ende Switchd
?>