]> git.treefish.org Git - banana.git/commitdiff
...
authorAlexander Schmidt <alex@treefish.org>
Tue, 25 Sep 2012 15:18:25 +0000 (17:18 +0200)
committerAlexander Schmidt <alex@treefish.org>
Tue, 25 Sep 2012 15:18:25 +0000 (17:18 +0200)
createdb.inc [new file with mode: 0644]
head.inc [new file with mode: 0644]
lastsubmit.php [new file with mode: 0644]
lecture.inc [new file with mode: 0644]
nav.inc [new file with mode: 0644]
register.php [new file with mode: 0644]
session.inc [new file with mode: 0644]
submit.php [new file with mode: 0644]
usercheck.inc [new file with mode: 0644]
var/lecture.txt.sample [new file with mode: 0644]
var/sessions.txt.sample [new file with mode: 0644]

diff --git a/createdb.inc b/createdb.inc
new file mode 100644 (file)
index 0000000..05f2637
--- /dev/null
@@ -0,0 +1,8 @@
+<?php
+  if ($db = new PDO('sqlite:var/banane.db')) {
+    $db->query('CREATE TABLE IF NOT EXISTS students 
+       (mnumber int, firstname string, lastname string, email string, password string, PRIMARY KEY (mnumber))');
+    $db->query('CREATE TABLE IF NOT EXISTS workdone
+        (mnumber int, session int, manydone int, thisdone string)'); 
+  }
+?>
diff --git a/head.inc b/head.inc
new file mode 100644 (file)
index 0000000..77d7385
--- /dev/null
+++ b/head.inc
@@ -0,0 +1,15 @@
+<?php
+
+  $lec_lines = file('var/lecture.txt');
+
+  foreach ($lec_lines as $line_num => $line) {
+    $lecture[$line_num] = $line;
+  }
+
+  print "<table>";
+    print "<tr><th align=\"left\">Banana Exercise Management</th><tr>";
+    print "<tr><th bgcolor=blue><font color=white> $lecture[0] $lecture[1], Group: $lecture[2] </font></th></tr>";
+  print "</table>";
+
+  print "<br>";
+?>
\ No newline at end of file
diff --git a/lastsubmit.php b/lastsubmit.php
new file mode 100644 (file)
index 0000000..19abb2b
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+  include 'nav.inc';
+  include 'lecture.inc';
+
+  if(isset($_POST['submit']) && $_POST['mnumber']!="") {
+    require 'createdb.inc';
+    require 'session.inc';
+
+    $mnumber = trim($_POST['mnumber']);
+    $password = trim($_POST['password']);
+
+    $sessionid = strtotime(end($sessions)[0]);
+
+    if (! ( $mnumber == 007 AND $password == 007 )) {
+      require 'usercheck.inc';
+      $result = $db->query("SELECT thisdone FROM workdone WHERE mnumber = $mnumber AND session = $sessionid")->fetch(PDO::FETCH_NUM)[0];
+      if ($result == "") { 
+        print "<table bgcolor=\"red\">";
+          print "<tr><th><b><font color=\"white\">no submit</font></b></th><tr>";
+        print "</table>";
+        print "No results were submitted for " . end($sessions)[0] . ".";
+        break;
+      }
+      else {
+        print $result;
+      }
+    }
+    else {
+      $result = $db->query("SELECT students.firstname, students.lastname, students.mnumber, workdone.manydone, workdone.thisdone FROM workdone, students WHERE workdone.session = $sessionid AND workdone.mnumber = students.mnumber");
+      //print $result[0];
+
+      print "<table>";
+
+      while ($row = $result->fetch(PDO::FETCH_NUM)) {
+        print "<tr>";
+        echo "<td>$row[0] $row[1] &nbsp;&nbsp;</td> <td>$row[2] &nbsp;&nbsp;</td> <td>$row[4] &nbsp;&nbsp;</td> <td>$row[3]/$lstsession_nex </td>";
+        print "</tr>";
+      }
+
+      print "</table>";
+    }
+
+    break;
+  }
+?>
+
+<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
+  <table bgcolor="black">
+    <tr><th><b><font color="white">Last submission</font></b></th><tr>
+  </table>
+
+  <table>
+    <tr>  
+      <th align="left">Mat.nummer:</th> <th align="left"><input type="text" name="mnumber"></th>
+    </tr>
+    <tr>  
+      <th align="left">Password:</th> <th align="left"><input type="text" name="password"></th>
+    </tr>
+    <tr><th colspan=2></th></tr>
+
+    <tr>
+      <th align="left"><input type="submit" name="submit" value="Show"></th> <th></th>
+    </tr>
+  </table>
+</form>
diff --git a/lecture.inc b/lecture.inc
new file mode 100644 (file)
index 0000000..b431d8d
--- /dev/null
@@ -0,0 +1,6 @@
+<?php
+  $lec_lines = file('var/lecture.txt');
+  foreach ($lec_lines as $line_num => $line) {
+    $lecture[$line_num] = $line;
+  }
+?>
diff --git a/nav.inc b/nav.inc
new file mode 100644 (file)
index 0000000..f69d3e8
--- /dev/null
+++ b/nav.inc
@@ -0,0 +1,20 @@
+<?php
+  require "head.inc";
+?>
+
+<style type="text/css">
+  a:link { text-decoration:none; font-weight:normal; color:blue; }
+  a:visited { text-decoration:none; font-weight:normal; color:blue; }
+  a:hover { text-decoration:none; font-weight:normal; background-color:yellow; }
+  a:active { text-decoration:none; font-weight:normal; color:blue; }
+  a:focus { text-decoration:none; font-weight:normal; color:blue; }
+</style>
+
+
+<a href="submit.php">submit</a>
+ | 
+<a href="register.php">register</a>
+ | 
+<a href="lastsubmit.php">last submit</a>
+
+<br><br>
diff --git a/register.php b/register.php
new file mode 100644 (file)
index 0000000..69b99fe
--- /dev/null
@@ -0,0 +1,76 @@
+<?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>
diff --git a/session.inc b/session.inc
new file mode 100644 (file)
index 0000000..30bae4d
--- /dev/null
@@ -0,0 +1,9 @@
+<?php
+  $lines_sessions = file('var/sessions.txt');
+
+  foreach ($lines_sessions as $line_num => $line) {
+    $sessions[$line_num] = explode("\t",$line);
+  }
+
+  $lstsession_nex = count(explode(',',end($sessions)[1]));
+?>
diff --git a/submit.php b/submit.php
new file mode 100644 (file)
index 0000000..69d9ab8
--- /dev/null
@@ -0,0 +1,82 @@
+<?php
+  require 'nav.inc';
+
+  $lines = file('var/sessions.txt');
+
+  foreach ($lines as $line_num => $line) {
+    $sessions[$line_num] = explode("\t",$line);
+  }
+
+  if ( strtotime("now") > strtotime(end($sessions)[0]) ) {
+    print '<table bgcolor="red">';
+      print '<tr><th><b><font color="white">submission closed</font></b></th><tr>';
+    print '</table>';
+    break;
+  }
+
+  if(isset($_POST['submit']) && $_POST['mnumber']!="") {
+    require 'usercheck.inc';
+    
+    $exchecked = $_POST['exchecked'];
+
+    $mnumber = $_POST['mnumber'];
+    $sessionid = strtotime(end($sessions)[0]);
+
+    if($db->query("SELECT COUNT(*) FROM workdone WHERE mnumber = $mnumber AND session = $sessionid")->fetch(PDO::FETCH_NUM)[0] == 1) {
+      print '<table bgcolor="red">';
+        print '<tr><th><b><font color="white">You already submitted results for this session</font></b></th><tr>';
+      print '</table>';
+      print "You can only submit your calculated examples once!";
+      break;
+    }
+
+    $excount = count($exchecked);
+    $donestring = implode(', ', $exchecked);
+
+    $db->query("INSERT INTO workdone (mnumber,session,manydone,thisdone) 
+        VALUES (\"$mnumber\", \"$sessionid\", \"$excount\", \"$donestring\")");
+
+    print '<table bgcolor="lightgreen">';
+      print '<tr><th><b><font color="white">submitted</font></b></th><tr>';
+    print '</table>';
+    break;
+  }
+?>
+
+  <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
+  <table bgcolor="black">
+    <tr><th><b><font color="white">submit examples for <?php echo end($sessions)[0]; ?></font></b></th><tr>
+  </table>
+
+  <table>
+    <tr>  
+      <th align="left">Mat.nummer:</th> <th align="left"><input type="text" name="mnumber"></th>
+    </tr>
+    <tr>  
+      <th align="left">Password:</th> <th align="left"><input type="text" name="password"></th>
+    </tr>
+    <tr><th colspan=2></th></tr>
+
+    <tr>
+      <th align="left">Examples:</th>
+      <th>
+
+        <?php
+          $exnum=0;
+         foreach (explode(",",end($sessions)[1]) as $exid) {
+           print " <input type='checkbox' name='exchecked[]' value=$exid>$exid ";
+           $exnum++;
+           if ($exnum%3 == 0) { print ""; }
+         }
+        ?>
+      </th>    
+    </tr>
+
+    <tr><th colspan=2></th></tr>
+
+    <tr>
+      <th align="left"><input type="submit" name="submit" value="Submit"></th> <th></th>
+    </tr>
+  </table>
+</form>
diff --git a/usercheck.inc b/usercheck.inc
new file mode 100644 (file)
index 0000000..19e51d3
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+  require 'createdb.inc';
+
+  $mnumber = $_POST['mnumber'];
+  $password = $_POST['password'];
+
+  if($db->query("SELECT COUNT(*) FROM students WHERE mnumber = $mnumber")->fetch(PDO::FETCH_NUM)[0] == 0) {
+    print '<table bgcolor="red">';
+      print '<tr><th><b><font color="white">Mat.nummer not found</font></b></th><tr>';
+    print '</table>';
+    print "Mat.Nummer was not found. You have to register first!";
+    break;
+  }
+
+  if($db->query("SELECT COUNT(*) FROM students WHERE mnumber = $mnumber AND password = \"$password\"")->fetch(PDO::FETCH_NUM)[0] == 0) {
+    print '<table bgcolor="red">';
+      print '<tr><th><b><font color="white">wrong password</font></b></th><tr>';
+    print '</table>';
+    break;
+  }
+  
+?>
\ No newline at end of file
diff --git a/var/lecture.txt.sample b/var/lecture.txt.sample
new file mode 100644 (file)
index 0000000..577ca1e
--- /dev/null
@@ -0,0 +1,3 @@
+Theoretische Mechanik
+WS2012
+Alex
diff --git a/var/sessions.txt.sample b/var/sessions.txt.sample
new file mode 100644 (file)
index 0000000..25eb55d
--- /dev/null
@@ -0,0 +1 @@
+27.09.2012 10:30       1a,1b,1c,2a,2b,3