+<?php
+require 'nav.inc';
+
+if(isset($_POST['submit']) && $_POST['firstname']!="" && $_POST['lastname']!=""
+ && $_POST['mnumber']!="" && $_POST['email']!="" && $_POST['password']!="")
+{
+ $firstname = $_POST['firstname'];
+ $lastname = $_POST['lastname'];
+ $mnumber = $_POST['mnumber'];
+ $email = $_POST['email'];
+ $password = $_POST['password'];
+
+ require 'createdb.inc';
+
+ // user already exists //
+ if($db->query("SELECT COUNT(*) FROM students WHERE mnumber = $mnumber")->fetch(PDO::FETCH_NUM)[0] == 1) {
+ print "<table bgcolor=\"red\">";
+ print "<tr><th><b><font color=\"white\">user already registered</font></b></th><tr>";
+ print "</table>";
+ break;
+ }
+
+ $db->query("INSERT INTO students (mnumber,firstname,lastname,email,password)
+ VALUES (\"$mnumber\",\"$firstname\",\"$lastname\",\"$email\",\"$password\")");
+
+ print "<table bgcolor=\"lightgreen\">";
+ print "<tr><th><b><font color=\"white\">registration successfull</font></b></th><tr>";
+ print "</table>";
+
+ echo "$firstname $lastname was successfully registered.<br>";
+
+ // send password-email //
+ $lec_lines = file('var/lecture.txt');
+ foreach ($lec_lines as $line_num => $line) {
+ $lecture[$line_num] = $line;
+ }
+ $nachricht = "Hello $firstname($mnumber)!\nYou registered for " . trim($lecture[0]) . " " . trim($lecture[1]) . ".\nRemember your password: $password\n\nYours,\nBanana.";
+ //$nachricht = wordwrap($nachricht,70);
+ $empfaenger = 'niemand@example.com';
+ $betreff = 'Der Betreff';
+ $header = 'From: banana@treefish.org' . "\r\n" .
+ 'Reply-To: noreply@treefish.org' . "\r\n" .
+ 'X-Mailer: PHP/' . phpversion();
+ mail($email, "Banana Registration: " . trim($lecture[0]) . " " . trim($lecture[1]), $nachricht, $header);
+
+ break;
+}
+?>
+
+<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
+ <table bgcolor="black">
+ <tr><th><b><font color="white">registration</font></b></th><tr>
+ </table>
+
+ <table>
+ <tr>
+ <th align="left">First name:</th> <th><input type="text" name="firstname"></th>
+ </tr>
+ <tr>
+ <th align="left">Last name:</th> <th><input type="text" name="lastname"></th>
+ </tr>
+ <tr>
+ <th align="left">Mat.nummer:</th> <th><input type="text" name="mnumber"></th>
+ </tr>
+ <tr>
+ <th align="left">Email:</th> <th><input type="text" name="email"></th>
+ </tr>
+ <tr>
+ <th align="left">Password:</th> <th><input type="text" name="password"></th>
+ </tr>
+
+ <tr>
+ <th></th> <th align="right"><input type="submit" name="submit" value="Register"></th>
+ </tr>
+ </table>
+</form>