<?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 Mailversand</font><br>
                    </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("./FCKeditor/fckeditor.php") ;


$db = dbconnect();
$sel_fach = $db->query("SELECT vorname, nachname, mail FROM stan_standort_admin WHERE uid='$uid1'");  // ausw_ausg =  wpf.id
$admin = $sel_fach->fetch_array();

$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();

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>Mail an Wahlpflichtfach</title>
</head>
<body onload=\"if(document.Mail)document.Mail.betreff.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=\"100%\" 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\">Mail an Teilnehmer</font><br>
                    <span class='sh'>Termin: $row_dt[datum]
                    </span>
                    <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\">
                    <form method=POST action=$_SERVER[PHP_SELF]?action=ausgabe2 name=Mail>
                      <table width=\"100%\"  border=\"0\">
                        <tr>
                          <td width=\"30%\" valign=\"top\"><b>Absender:</b></td>
                          <td width=\"70%\" valign=\"top\"><input name=\"sender\" type=\"hidden\" value='$admin[vorname] $admin[nachname]' id=\"sender\" size=\"66\">$admin[vorname] $admin[nachname]</td>
                        </tr>
                        <tr>
                          <td width=\"30%\" valign=\"top\"><b>Mail-Adresse Absender:</b></td>
                          <td width=\"70%\" valign=\"top\"><input name=\"sendermail\" value='$admin[mail]' type=\"hidden\" id=\"sendermail\" size=\"66\">$admin[mail]</td>
                        </tr>
                        <tr>
                          <td width=\"30%\" valign=\"top\">&nbsp;</td>
                          <td width=\"70%\" valign=\"top\">&nbsp;</td>
                        </tr>
                        <tr>
                          <td width=\"30%\" valign=\"top\"><b>Mail-Adresse Empf&auml;nger:</b></td>
                          <td width=\"70%\" valign=\"top\">";
                            $db = dbconnect();

			    $query = "SELECT d.mail, d.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";
			    $result = $db->query ($query)
			       or die ("Cannot execute query1");
			  
			  while ($row = $result->fetch_array()){
	
                           $empfaenger .= "$row[mail],";
                           if($row[mail2] != ''){
                             $empfaenger .= "$row[mail2], ";
                           }
                          }
                          $empfaenger=substr($empfaenger, 0, -1); // Letztes Zeichen (das Komma) entfernen
                          echo"
                          <input type=\"hidden\" name=\"empfaenger\" id=\"empfaenger\" size=\"66\" value='$empfaenger'>$empfaenger
                          </td>
                        </tr>
                        <tr>
                          <td width=\"30%\" valign=\"top\">&nbsp;</td>
                          <td width=\"70%\" valign=\"top\">&nbsp;</td>
                        </tr>
                        <tr>
                          <td width=\"30%\" valign=\"top\"><b>Hinweis:</b></td>
                          <td width=\"70%\" valign=\"top\">
                            <i>Es können mehr Mailadressen, als Teilnehmer erscheinen.<br>Die Nachricht wird an alle im System hinterlegten Mailadressen eines Studenten versendet</i>
                          </td>
                        </tr>
                        <tr>
                          <td width=\"30%\" valign=\"top\">&nbsp;</td>
                          <td width=\"70%\" valign=\"top\">&nbsp;</td>
                        </tr>
                        <tr>
                          <td width=\"30%\" valign=\"top\"><b>Betreff:</b></td>
                          <td width=\"70%\" valign=\"top\">
                            <input name=\"betreff\" type=\"text\" id=\"betreff\" size=\"66\">
                          </td>
                        </tr>
                        <tr>
                          <td width=\"30%\" valign=\"top\">&nbsp;</td>
                          <td width=\"70%\" valign=\"top\">&nbsp;</td>
                        </tr>
                        <tr>
                          <td width=\"30%\" valign=\"top\"><b>Nachricht:</b></td>
                          <td width=\"70%\" valign=\"top\">";
                        $oFCKeditor = new FCKeditor('inhalt') ;
			$oFCKeditor->BasePath = './FCKeditor/';
			#$oFCKeditor->Value = 'Default text in editor';
			$oFCKeditor->ToolbarSet = 'Basic';
			$oFCKeditor->Width  = '100%' ;
			$oFCKeditor->Height = '200' ;
			$oFCKeditor->Create() ;
                          echo"
                          
                          </td>
                        </tr>
                        <tr>
                          <td width=\"30%\" valign=\"top\">&nbsp;</td>
                          <td width=\"70%\" valign=\"top\"><input type=checkbox NAME=\"kopie\">Kopie der Mail erhalten</td>
                        </tr>
                      </table>
                      <br>
                      <input type=\"submit\" value=\"Abschicken\" name=\"B1\" size=\"20\">
                      </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 "ausgabe2":
$mtknr=$_COOKIE["ck_mtknr1"];

$empfaenger = $_POST['empfaenger'];
$betreff = $_POST['betreff'];
$text = stripslashes( $_POST['inhalt'] );
$sender = $_POST['sender'];
$sendermail = $_POST['sendermail'];
$kopie = $_POST['kopie'];
// echo"$empfaenger<p>$betreff<p>$text<p>$sender<p>$sendermail";
// Emailversand:
if ($kopie)
{
 $empfaenger .= ", $sendermail";
}


if($text == ''){
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>Mailversand</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>
                    <font class=\"hd\">Pflichtfelder ausfüllen</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><p align=\"center\"><b>Bitte füllen Sie alle Felder aus!</b>
                    <p></p>
                    <p></p>
                    <p align=\"center\"><a href=\"javascript:history.back()\">
                    <img border=\"0\" src=\"../images/zurueck.gif\" width=\"77\" height=\"22\"></a><br>
                    </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>";

}


## Mailversand:
$headers  = "From: $sender <$sendermail>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= "Bcc: $empfaenger\n"; 
$return = @mail(NULL, $betreff, $text, $headers);



// Best&auml;tigungsseite

if ($return)
{
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>Mailversand</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>
                    <font class=\"hd\">Mailversand erfolgreich</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><p align=\"center\"><b>Die E-Mail wurde verschickt!</b>
                    <p></p>
                    <p></p>
                            <p align='center'>
                            <a href=".$_SERVER['PHP_SELF'] ."?action=default>
	                    <img border=\"0\" src=\"../images/zurueck.gif\" width=\"77\" height=\"22\"></a><br>

                    </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>";
} else {
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>Mailversand</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>
                    <font class=\"hd\">Mailversand fehlgeschlagen</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><p align=\"center\">Die E-Mail wurde <b>nicht</b> verschickt!<br><br>
                    Es trat ein unbekannter Fehler auf. Bitte wenden Sie sich an ihre Zulassungsstelle
                    <br>
                    <p></p>
                    <p></p>
                    <p align='center'>
                    <a href=".$_SERVER['PHP_SELF'] ."?action=default>
	                    <img border=\"0\" src=\"../images/zurueck.gif\" width=\"77\" height=\"22\"></a><br>
                    </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>";
} //End if
}//Ende Switchd
?>