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

// Rechte&uuml;berpr&uuml;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 ver_admin_rechte, ver_admin_rechte_zuord , ver_admin where ver_admin_rechte.ver_admin_rolle = ver_admin_rechte_zuord.ver_admin_rolle AND ver_admin_rechte_zuord.vaid = ver_admin.vaid AND ver_admin.user = '$user_admin' AND ver_admin_rechte_zuord.ver_admin_rolle = 'a_mailadr'");
$row = $result->fetch_array();
if ($row[0] != 1){ include("kurs/rechte.php"); exit;}
// Rechte&uuml;berpr&uuml;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>Mailadressen</title>
<SCRIPT LANGUAGE=\"JavaScript\"><!--
function initForm()
 {
       // Wenn man mit history.back zur&uuml;ckgeht werden wurden die disabled Felder ignoriert, daher nochmals pr&uuml;fen,
       // ob Innenverwaltung gesamt angeklickt ist
       if(document.passback.I.checked)
       {
          document.passback.Zweig[0].disabled=true;
          document.passback.Zweig[1].disabled=true;
       }
 }
//-->
</SCRIPT>
</head>
<body onload=initForm()>
<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\">Mailadressen selektieren</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=ausgabe1"; echo" method=\"POST\" name=\"passback\">";
                      echo "
                        <table cellspacing=\"1\" cellpadding=\"1\" width=\"100%\" border=\"0\">
		          <tr>
		            <td class=\"formdesc\" width=\"60%\">
		              Studiengang:
		            </td>
		                                   <SCRIPT LANGUAGE=\"JavaScript\"><!--
			                           function codename() {
			                           
			                           if(document.passback.I.checked)
			                           {
			                           document.passback.Zweig[0].disabled=true;
			                           document.passback.Zweig[1].disabled=true;
			                           }
			                           else
			                           {
			                           document.passback.Zweig[0].disabled=false;
			                           document.passback.Zweig[1].disabled=false;
			                           }
			                            }
			                           //-->
			                           </SCRIPT>
		            <td width=\"40%\">
		              <label for=\"I\"><input type=\"checkbox\" onclick=\"codename()\" name=\"I\" value=\"I\" id=\"I\"> Innenverwaltung</label><br>
		           <!--   <label for=\"r1\"><input type=\"radio\" name=\"Zweig\" value=\"V\" id=\"r1\"> Nur Innenverwaltung V-Zweig</label><br>
		              <label for=\"r2\"><input type=\"radio\" name=\"Zweig\" value=\"W\" id=\"r2\"> Nur Innenverwaltung W-Zweig</label><br> -->
				<label for=\"D\"><input type=\"checkbox\" name=\"D\" value=\"D\" id=\"D\"> Dig. Verw.management</label><br>		             
 				<label for=\"R\"><input type=\"checkbox\" name=\"R\" value=\"R\" id=\"R\"> Rentenversicherung</label><br>
		              <label for=\"F\"><input type=\"checkbox\" name=\"F\" value=\"F\" id=\"F\"> Allgemeine Finanzverwaltung</label><br>
		              <label for=\"S\"><input type=\"checkbox\" name=\"S\" value=\"S\" id=\"S\"> Steuerverwaltung</label>
		            </td>
		          </tr>
		          <tr>
		            <td class=\"formdesc\" width=\"60%\">
		              AG:<br>
                              <font size=\"1\">(Strg-Taste f&uuml;r Mehrfachauswahl)</font>
		            </td>
		            <td width=\"40%\">";
		              $db = dbconnect();
                              $query = "SELECT AG FROM stud GROUP BY AG";
                              $result = $db->query ($query)
                                        or die ("Cannot execute query");
                              echo "<p align=\"left\"><select size=\"4\" name=\"ag[]\" multiple>";
                              while ($row = $result->fetch_array()){
                                echo "<option value=\"".$row['AG']."\">".$row['AG']."&nbsp;&nbsp;</option>\n";
                              }
                              echo "</select>
                            </td>
		          </tr>
		          <tr>
		            <td class=\"formdesc\" width=\"60%\">
		              Jahrgang:<br>
                              <font size=\"1\">(Strg-Taste f&uuml;r Mehrfachauswahl)</font>
		            </td>
		            <td width=\"40%\">";
		              $db = dbconnect();
                              $query = "SELECT Jahrgang FROM stud GROUP BY Jahrgang";
                              $result = $db->query ($query)
                                        or die ("Cannot execute query");
                              echo "<p align=\"left\"><select size=\"4\" name=\"jahr[]\" multiple>";
                              while ($row = $result->fetch_array()){
                                echo "<option value=\"".$row['Jahrgang']."\">".$row['Jahrgang']."&nbsp;&nbsp;</option>\n";
                              }
                              echo "</select>
                            </td>
		          </tr>
		          <tr>
		            <td align=\"center\" colspan=\"2\">
		              &nbsp;  
		            </td>
		          </tr>
		          <tr>
		            <td align='center' colspan=\"2\">
		              <input title=\"Suchen\" type=\"image\" src=\"../images/suchen.gif\" border=\"0\">
		            </td>
		          </tr>
		             </td>
		          </tr>
                        </table>
                    <br>
                    </form>
                    <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>";

break;
case "ausgabe1":

 if ($_POST[I] == ""  and $_POST[R] == "" and $_POST[F] == "" and $_POST[S] == "" and $_POST[D] == "" ){    // mind. 1 Zweig muss angegeben werden. Getrennt durch and
 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>Eingabefehler</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\">Eingabefehler</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>Es muss mindestens 1 Zweig ausgef&uuml;llt werden</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[ag] == ""){    // mind. 1 AG muss angegeben werden.
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>Eingabefehler</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\">Eingabefehler</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>Es muss mindestens eine AG ausgef&uuml;llt werden</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[jahr] == ""){    // mind. 1 Jahrgang muss angegeben werden.
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>Eingabefehler</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\">Eingabefehler</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>Es muss mindestens ein Jahrgang ausgef&uuml;llt werden</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;
}
*/

$year = $_POST[jahr];
for ($i=0;$i<sizeof($year);$i++) { 
    $jahr .= "'$year[$i]', ";
}

$class = $_POST[ag];
for ($i=0;$i<sizeof($class);$i++) { 
    $ag .= "'$class[$i]', ";
}


$akt_zweig = "'$_POST[Zweig]',";

if($_POST[Zweig] != ''){$Zweig =$akt_zweig;}else{$Zweig ='';};
if($_POST[I] != ''){$Zweig .="'V','W','I',";}else{$Zweig .='';};
if($_POST[D] != ''){$Zweig.="'".$_POST[D]."',";}else{$Zweig.='';};
if($_POST[R] != ''){$Zweig.="'".$_POST[R]."',";}else{$Zweig.='';};
if($_POST[F] != ''){$Zweig.="'".$_POST[F]."',";}else{$Zweig.='';};
if($_POST[S] != ''){$Zweig.="'".$_POST[S]."',";}else{$Zweig.='';};



$jahr1 = substr($jahr,0,-2);   // ', ' --> 2 Zeichen entfernen
$ag1 = substr($ag,0,-2);       // ', ' --> 2 Zeichen entfernen
$Zweig1 = substr($Zweig,0,-1); // ','  --> 1 Zeichen entfernen


$krit_zweig = str_replace (array("'", "Array"), array(" ", ""), $Zweig1);
$krit_ag = str_replace (array("'", "Array"), array(" ", ""), $ag1);
$krit_jahr = str_replace (array("'", "Array"), array(" ", ""), $jahr1);




//In &auml;lteren PHP Versionen schreibt er array davor, obwohls keins ist, dies wird entfernt, Prob. bei der FH
$ag = str_replace("Array", '', $ag1);
$jahr = str_replace("Array", '', $jahr1);

if ($_POST[ag] == ""){    // mind. 1 AG muss angegeben werden, wenn nicht, dann alle
  $ag = "SELECT distinct AG from stud";
}


if ($_POST[jahr] == ""){    // mind. 1 Jahrgang muss angegeben werden, wenn nicht, dann alle
  $jahr = "SELECT distinct jahrgang from 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>Ausgabe Mailadressen</title>
</head>
<body onload=\"if(document.Mail)document.Mail.sender.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=\"50%\" border=\"0\">
                <tr>
                    <td align=\"left\" width=\"1%\" width=\"10\" background=\"../images/box_e1.gif\">
                    <img height=\"40\" src=\"../images/blank.gif\" width=\"22\"></td>
                    <td align=\"left\" width=\"98%\" background=\"../images/box_top.gif\" valign=\"top\" colspan=\"2\">
                    <img height=\"10\" src=\"../images/blank.gif\" width=\"1\"><br>
                    <font class=\"hd\">Mailadressen</font><br>
                    <font class=\"sh\"><b>Studienzweig:</b> $krit_zweig <br>
                                       <b>AG:</b>"; if($krit_ag == ''){ echo " alle";}else{ " $krit_ag";} echo" <br>
                                       <b>Jahrgang:</b>"; if($krit_jahr == ''){ echo " alle";}else{ " $krit_jahr";} echo" <br></font>
                    <img height=\"5\" src=\"../images/blank.gif\" width=\"1\"></td>
                    <td 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\">
                      <table width=\"100%\"  border=\"0\">";
                         $db = dbconnect();

                         $query = "SELECT mail
                                     FROM stud
                                    WHERE stg IN ($Zweig1)
                                      AND ag IN ($ag)
                                      AND jahrgang IN ($jahr)
                                      AND durchgefallen != 'Y'
                                      AND hs = 'L'
                                    ORDER BY uid";
                                    
#                         echo $query;
#                         exit;
                         
                         $result = $db->query($query)
                                or die ("Cannot execute query1");
                         while ($row = $result->fetch_array()){
                           $mail .= "$row[mail],<br>";
                         }
                         $mail2 = substr($mail,0,-5); // ','  --> 5 Zeichen entfernen ",<br>"
                         echo"
                          <tr>
                            <td width=\"100%\" valign=\"top\">$mail2</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>
            <br>
            Sie k&ouml;nnen den Inhalt der Tabelle kopieren<br>
            und in Ihrem Mailprogramm einf&uuml;gen!
            <p>
        </div>
        </td>
    </tr>
</table>
</body>
</html>";
} //Ende Action Abfrage
?>
