]> git.treefish.org Git - banana.git/blob - passrecover.php
test2
[banana.git] / passrecover.php
1 <?php
2   require 'include/head.inc';
3   require 'include/db.inc';
4   require 'include/common.inc';
5
6   if(isset($_POST['submit']) && $_POST['mnumber']!="") {
7     $mnumber = trim($_POST['mnumber']);
8
9     if( ! is_numeric($mnumber) ) {
10       block("red", "Mat.nummer has to be numeric!");
11     }
12     else {
13       if($db->query("SELECT COUNT(*) FROM students WHERE mnumber = $mnumber")->fetch(PDO::FETCH_NUM)[0] == 0) {
14         print '<table bgcolor="red">';
15         print '<tr><th><b><font color="white">Mat.nummer not found</font></b></th><tr>';
16         print '</table>';
17       }
18       else {
19         $userinfo = $db->query("SELECT firstname,lastname,email,password FROM students WHERE mnumber=$mnumber")->fetch(PDO::FETCH_NUM);
20
21         // send password-email //
22         $nachricht = "Hello $userinfo[0]($mnumber)!\nThis is a password-recovery mail for the exercise " . $PREFS['exname'] . " (" . $PREFS['groupname'] . ").\nYour forgotten password is: $userinfo[3]\n\nYours,\nBanana.";
23         $header = 'From: banana@treefish.org' . "\r\n" .
24         'Reply-To: noreply@treefish.org' . "\r\n" .
25         'X-Mailer: PHP/' . phpversion();
26         mail($userinfo[2], "Banana password-recovery: " . $PREFS['exname'] . " (" . $PREFS['groupname'] . ")", $nachricht, $header);
27
28         print "<table bgcolor=\"lightgreen\">";
29           print "<tr><th><b><font color=\"white\">sent password to your email-address</font></b></th><tr>";
30         print "</table>";
31       }
32     }
33   }
34 ?>
35
36 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
37   <table bgcolor="black">
38     <tr><th><b><font color="white">Password recovery</font></b></th><tr>
39   </table>
40
41   <table>
42     <tr>  
43       <th align="left">Mat.nummer:</th> <th align="left"><input type="text" name="mnumber"></th>
44     </tr>
45     <tr><th colspan=2></th></tr>
46
47     <tr>
48       <th align="left"><input type="submit" name="submit" value="Recover password"></th> <th></th>
49     </tr>
50   </table>
51 </form>