<?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_historie'");
$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>Druckhistorie</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\">Druckhistorie</font><br>
                    <font class=\"sh\">Treffen Sie unten eine Auswahl</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>
			  <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; border-width: 0\" bordercolor=\"#111111\" width=\"100%\" id=\"AutoNumber1\" height=\"115\">
			    <tr>
			      <td align='center'>
			      <a href=".$_SERVER['PHP_SELF'] ."?action=stud>Gedruckte Zuweisung erneut drucken</a>
			      
			      <br>
			      <br>
			      <br>";
			      
			      if($hs == 'K' or $hs == 'k'){
			        echo "<a href=pdf_gen_ges_kehl.php target='_blank'>Alle offenen Drucke der Hochschule drucken</a>";
			      }else{
			        echo "<a href=pdf_gen_ges_lubu.php target='_blank'>Alle offenen Drucke der Hochschule drucken</a>";
			      }
			      echo"
			      </td>
			    </tr>
			  </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\" 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 "stud":

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>Einzel&uuml;bersicht</title>
	<script type=\"text/javascript\" src=\"livesearch/ajax.js\"></script>
	<script type=\"text/javascript\" src=\"livesearch/ajax-dynamic-list.js\"></script>
<style type=\"text/css\">
select{
	width:250px;
}



	/* Big box with list of options */
	#ajax_listOfOptions{
		position:absolute;	/* Never change this one */
		width:320px;	/* Width of box */
		height:200px;	/* Height of box */
		overflow:auto;	/* Scrolling features */
		border:1px solid #6487DC;	/* Dark blue border */
		background-color:#FFF;	/* White background color */
		text-align:left;
		font-family		:	verdana, arial;
		z-index:10000;
	}
	#ajax_listOfOptions div{	/* General rule for both .optionDiv and .optionDivSelected */
		margin:1px;
		padding:1px;
		cursor:pointer;
		font-size:0.9em;
	}
	#ajax_listOfOptions .optionDiv{	/* Div for each item in list */

	}
	#ajax_listOfOptions .optionDivSelected{ /* Selected item in the list */
		background-color:#D6DFF7;
		color:#002276;
		font-family		:	verdana, arial;
		font-weight		:	bold;
	}
	#ajax_listOfOptions_iframe{
		background-color:#F00;
		position:absolute;
		z-index:500;
	}
</style>
</head>
<body onload=\"if(document.einzel)document.einzel.stud.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\">Studentenauswahl</font><br>
                    <font class=\"sh\">&Uuml;bersicht über die Studenten, bei denen Zuweisungsschreiben gedruckt wurden</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=ubersicht1"; 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\" id=\"stud\" name=\"stud\" value=\"\" onkeyup=\"ajax_showOptions(this,'getWord',event)\" size=\"50\">
				<input type=\"hidden\" id=\"stud_hidden\" name=\"stud_ID\"><!-- THE ID OF the textstelle will be inserted into this hidden input -->

			      </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 distinct a.uid, mtknr, vorname, nachname, durchgefallen
			    			                  FROM stud a, stan_antrag b, stan_printqueue_antrag c
			    			                 WHERE a.uid = b.uid
			    			                   AND b.saaid=c.saaid
			    			                   AND jahrgang='$jahrgang'
			    			                   AND stg = 'I'
			    			                   AND hs = '$hs'
			    			                   AND druckstatus='G'
			    			                 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[uid]."\">$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=\"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 "ubersicht1":

if($_POST[stud]!=''){
 $stud = $_POST[stud];
 $pos1 = strpos  ($stud, '(')+1;
 $pos2 = strpos  ($stud, ')')-$pos1;


 $str = substr($stud, $pos1,$pos2);

 $str = explode(",",$str);
 
 $mtknr=trim($str[0]);
 $uid1=trim($str[1]);
 
 
 
 if($_POST[stud] == ''){
   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>Falsches Datum</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\">Pflichtfelder ausfüllen</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>Bitte füllen Sie alle Pflichtfelder aus!</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;
 }
}

if($_POST[user2] != ''){ // Wenn Stud über dropdown gewählt wurde
 $db = dbconnect();
 $result = $db->query("SELECT uid, stg, vorname, nachname
                          FROM stud
                         WHERE uid ='$_POST[user2]'");
 $row_uid = $result->fetch_array();
 $mtknr=$row_uid[mtknr];
 $uid1=$row_uid[uid];
}

if(isset($_GET["uid"])){
 $uid1=$_GET["uid"];
 
 $db = dbconnect();
 $result = $db->query("SELECT uid, stg, vorname, nachname
                          FROM stud
                         WHERE uid ='$_POST[user2]'");
 $row_uid = $result->fetch_array();
 $mtknr=$row_uid[mtknr];
}

 setcookie("ck_uid1","");
 setcookie("ck_uid1",$uid1);
 
 setcookie("ck_mtknr","");
 setcookie("ck_mtknr",$mtknr);
 
 
   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>Falsches Datum</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=\"90%\" 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\">Dokumente auswählen</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>
 <form action="; echo $_SERVER['PHP_SELF'] . "?action=ubersicht2"; echo" method=\"POST\" name=\"einzel\">
<table width='100%'>
 <tr>
  <td width='10%'>
   <b>Auswahl</b>
  </td>
  <td width='50%'>
   <b>Dokument</b>
  </td>
  <td width='20%'>
   <b>Druckdatum</b>
  </td>
  <td width='20%'>
   <b>Sachbearbeiter</b>
  </td>
 </tr>";
 $query = "SELECT c.qid, c.saaid, c.zuweisung, date_format(c.datum, '%d.%m.%Y %H:%i:%s') datum, date_format(c.datum, '%Y%m%d%H%i%s') datumform, admin
             FROM stud a, stan_antrag b, stan_printqueue_antrag c
            WHERE a.uid = b.uid
              AND b.saaid=c.saaid
              AND a.uid='$uid1'
              AND druckstatus='G'
              AND c.zuweisung != 'SOZ'
            ORDER BY datumform ASC, qid ASC";
 
 
 $result = $db->query ($query)
    or die ("Cannot execute query");
  
 $zaehler=0;
 while ($row = $result->fetch_array()){
 
 if($row[zuweisung] == "EZS"){$dokument="Zuweisung Erstantrag Student";}
 if($row[zuweisung] == "EZP"){$dokument="Zuweisung Erstantrag Praxisstelle";}
 if($row[zuweisung] == "AES"){$dokument="Zuweisung Änderung Student";}
 if($row[zuweisung] == "AEP"){$dokument="Zuweisung Änderung Praxisstelle";}
 
$res_adm = $db->query("SELECT vorname, nachname FROM stan_admin WHERE user='$row[admin]'");
$row_adm = $res_adm->fetch_array();

$res_dst = $db->query("SELECT dst_id FROM stan_antrag WHERE saaid='$row[saaid]'");
$row_dst = $res_dst->fetch_array();

$result_data2 = $db->query("SELECT distinct 1 FROM stan_dienststellen WHERE dst_id= '$row_dst[dst_id]'");
$rowdata2 = $result_data2->fetch_array();

 if($rowdata2[0] == '1'){
   $result_data3 = $db->query("SELECT bez
                                     , str
                                     , plz
                                     , postfach
                                     , plz_postfach
                                     , ort
                                     , bundesland
                                     , staat
                                  FROM stan_dienststellen
                                 WHERE dst_id='$row_dst[dst_id]'");
    $rowdata3 = $result_data3->fetch_array();
    
 }else{

    $result_data3 = $db->query("SELECT bez
                                      , str
                                      , plz
                                      , postfach
                                      , plz_postfach
                                      , ort
                                      , bundesland
                                      , staat
                                   FROM stan_dienststellen_tmp
                                  WHERE dst_id='$row_dst[dst_id]'");
     $rowdata3 = $result_data3->fetch_array();
  }
  echo"
  <tr>
   <td width='10%'>
    <input type=\"checkbox\" name=\"$zaehler\" multiple value=\"$row[qid]\">
   </td>
   <td width='50%'>
    $dokument ($rowdata3[bez])
   </td>
   <td width='20%'>
    $row[datum]
   </td>
   <td width='20%'>
    $row_adm[vorname] $row_adm[nachname]
   </td>
 </tr>";
 $zaehler=$zaehler+1;;
 }
 
 
 $query = "SELECT a.qid, a.saaid, a.zuweisung, date_format(a.datum, '%d.%m.%Y %H:%i:%s') datum, date_format(a.datum, '%Y%m%d%H%i%s') datumform, admin, e.standort, f.bezeichnung
             FROM stan_printqueue_antrag a, stan_ag_standort_wunsch b, stud c, stan_ag_standort d, stan_standort e, stan_vertiefungsbereich f
            WHERE b.uid = c.uid
              AND a.saaid=b.saaid
              AND a.printed_obj=b.wagsid
              AND b.wagsid=d.agsid
              AND d.sid=e.sid
              AND d.vbid=f.vbid
              AND c.uid='$uid1'
              AND b.prio=0
              AND druckstatus='G'
              AND a.zuweisung = 'SOZ'
            ORDER BY datumform ASC, qid ASC";

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

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

  if($row2[zuweisung] == "SOZ"){$dokument="Zuweisung AG-Standort";}
  
 $res_adm2 = $db->query("SELECT vorname, nachname FROM stan_admin WHERE user='$row2[admin]'");
 $row_adm2 = $res_adm2->fetch_array();
 

   echo"
   <tr>
    <td width='10%'>
     <input type=\"checkbox\" name=\"$zaehler\" multiple value=\"$row2[qid]\">
    </td>
    <td width='50%'>
     $dokument ($row2[bezeichnung] in $row2[standort]) $row2[qid]
    </td>
    <td width='20%'>
     $row2[datum]
    </td>
    <td width='20%'>
     $row_adm2[vorname] $row_adm2[nachname]
    </td>
 </tr>";
 $zaehler=$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\" 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>
            <br>
            <input type=\"submit\" value=\"Abschicken\" name=\"B1\"></td>
            </form>
        </div>
        </td>
    </tr>
  </table>
  </body>
  </html>";
break;
case "ubersicht2":
$uid1=$_COOKIE["ck_uid1"];

$res_chk = $db->query("SELECT count(*) Anz
             FROM stud a, stan_antrag b, stan_printqueue_antrag c
            WHERE a.uid = b.uid
              AND b.saaid=c.saaid
              AND a.uid='$uid1'
              AND druckstatus='G'");
$row_chk = $res_chk->fetch_array();


$res_chk2 = $db->query("SELECT count(*) Anz
             FROM stan_printqueue_antrag a, stan_ag_standort_wunsch b, stud c, stan_ag_standort d, stan_standort e, stan_vertiefungsbereich f
            WHERE b.uid = c.uid
              AND a.saaid=b.saaid
              AND a.printed_obj=b.wagsid
              AND b.wagsid=d.agsid
              AND d.sid=e.sid
              AND d.vbid=f.vbid
              AND c.uid='$uid1'
              AND b.prio=0
              AND druckstatus='G'");
$row_chk2 = $res_chk2->fetch_array();
$anzahl = $row_chk[Anz] + $row_chk2[Anz];
$sql = $db->query("DELETE FROM stan_printqueue_hist WHERE admin= '$user_admin'");

for ($i=0;$i<$anzahl;$i++) { 
  if(isset($_POST[$i])){
   $sql = $db->query("INSERT INTO stan_printqueue_hist SELECT qid, saaid, NULL,NULL,zuweisung, datum,klartext, printed_obj,'$user_admin',hs_admin,'N',sort_order FROM stan_printqueue_antrag WHERE qid= '$_POST[$i]'");
  }
}


   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>Falsches Datum</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\">Druck der Anschreiben</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\">Bitte weisen Sie dem Student zuerst alle Anträge zu bevor Sie den Druck starten, damit auf der Zuweisung des Studenten alle Anträge aufgelistet werden<br><br></p>";
                    $queryb = $db->query ("SELECT count(a.saaid) Anz
		                              FROM stan_printqueue_hist a, stan_antrag b, stud c
		                             WHERE a.saaid=b.saaid
		                               AND b.uid=c.uid
		                               AND b.uid='$uid1'
		                               AND druckstatus ='N'");
		                               
		    $row_cur_uid_anz = $queryb->fetch_array();
		    if($row_cur_uid_anz[Anz] > 0){
                      $queryc = $db->query ("SELECT hs
		                                FROM stud
		                               WHERE uid='$uid1'");
		      $row_cur_hs = $queryc->fetch_array();
		      
		      if($row_cur_hs[hs] == 'K' or $row_cur_hs[hs] == 'k'){
		        echo "Dokument: <a href='pdf_gen_kehl.php?uid=$uid1&hist=Y' target='_blank'>drucken</a><br><br>";
		      }else{
		        echo "Dokument: <a href='pdf_gen.php?uid=$uid1&hist=Y' target='_blank'>drucken</a><br><br>";
		      }
		    }else{
		      echo "Dokument: Alle Dokumente bereits gedruckt<br><br>";
		    }

                    echo"
                    <a href='historie.php?action=ubersicht1&uid=$uid1'>Zurück zum Student</a><br><br>
                    <a href='historie.php'>Zurück zur Historie</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>";
} // Ende Action script
?>