From: Alexander Schmidt Date: Thu, 27 Sep 2012 16:00:20 +0000 (+0200) Subject: ... X-Git-Url: https://git.treefish.org/banana.git/commitdiff_plain/17d5ad30f747658451fae84fe65cb1f5b66d377c ... --- diff --git a/admin/blackboard.php b/admin/blackboard.php index b683221..4066f84 100644 --- a/admin/blackboard.php +++ b/admin/blackboard.php @@ -8,6 +8,11 @@ block("lightgreen", "added blackboard"); } + if ($db->query("SELECT COUNT(*) FROM students")->fetch(PDO::FETCH_NUM)[0] == 0) { + block("red", "no students registered"); + break; + } + block("black", "add blackboard"); ?> diff --git a/admin/index.php b/admin/index.php index 74acd8b..254993a 120000 --- a/admin/index.php +++ b/admin/index.php @@ -1 +1 @@ -blackboard.php \ No newline at end of file +nextsession.php \ No newline at end of file diff --git a/admin/nextsession.php b/admin/nextsession.php index ca467fd..f438822 100644 --- a/admin/nextsession.php +++ b/admin/nextsession.php @@ -4,6 +4,11 @@ require 'include/session.inc'; require 'include/common.inc'; + if (! isset($SESSIONS_actual)) { + block("red", "no next session"); + break; + } + block("black", "summary for session " . $SESSIONS[$SESSIONS_actual]['timestr'] . " (" . $SESSIONS[$SESSIONS_actual]['examples'] . ")"); $result = $db->query("SELECT firstname, lastname, mnumber, blackboard FROM students ORDER BY lastname"); diff --git a/admin/summary.php b/admin/summary.php index 0cd5467..33658ef 100644 --- a/admin/summary.php +++ b/admin/summary.php @@ -4,6 +4,11 @@ require 'include/session.inc'; require 'include/common.inc'; + if ($db->query("SELECT COUNT(*) FROM students")->fetch(PDO::FETCH_NUM)[0] == 0) { + block("red", "no students registered"); + break; + } + block("black", "summary of everything for " . date("d.m.Y H:i")); $result = $db->query("SELECT firstname, lastname, mnumber, blackboard FROM students ORDER BY lastname"); diff --git a/include/prefs.inc b/include/prefs.inc index 58aac3e..a3e1aaa 100644 --- a/include/prefs.inc +++ b/include/prefs.inc @@ -1,9 +1,10 @@ query("SELECT key, value FROM prefs"); - while ($row = $result->fetch(PDO::FETCH_ASSOC)) { - $PREFS[$row['key']] = $row['value']; + if (! isset($PREFS)) { + $result = $db->query("SELECT key, value FROM prefs"); + while ($row = $result->fetch(PDO::FETCH_ASSOC)) { + $PREFS[$row['key']] = $row['value']; + } } - ?> diff --git a/include/session.inc b/include/session.inc index c31441e..554ac1f 100644 --- a/include/session.inc +++ b/include/session.inc @@ -1,28 +1,33 @@ query("SELECT id,examples,nexamples FROM sessions ORDER BY id"); - $SESSIONS_next = -1; - $SESSIONS_actual = -1; + require 'db.inc'; + + if ( ! isset($SESSIONS) ) { + $result=$db->query("SELECT id,examples,nexamples FROM sessions ORDER BY id"); + $SESSIONS_next = -1; + $SESSIONS_actual = -1; - while ($session = $result->fetch(PDO::FETCH_ASSOC)) { - $SESSIONS[$session['id']] = array("id" => $session['id'], "timestr" => date("d.m.Y H:i", $session['id']), - "workdone" => $db->query("SELECT COUNT(*) FROM workdone WHERE session=" . $session['id'])->fetch(PDO::FETCH_NUM)[0], - "examples" => $session['examples'], "nexamples" => $session['nexamples']); - if ( strtotime("now") < $session['id'] && ( $SESSIONS_next==-1 || $SESSIONS_next > $session['id'] ) ) { - $SESSIONS_next = $session['id']; - } - if ( strtotime("now") < $session['id'] + 3600 && ( $SESSIONS_actual==-1 || $SESSIONS_actual > $session['id'] ) ) { - $SESSIONS_actual = $session['id']; + while ($session = $result->fetch(PDO::FETCH_ASSOC)) { + $SESSIONS[$session['id']] = array("id" => $session['id'], "timestr" => date("d.m.Y H:i", $session['id']), + "workdone" => $db->query("SELECT COUNT(*) FROM workdone WHERE session=" . $session['id'])->fetch(PDO::FETCH_NUM)[0], + "examples" => $session['examples'], "nexamples" => $session['nexamples']); + if ( strtotime("now") < $session['id'] && ( $SESSIONS_next==-1 || $SESSIONS_next > $session['id'] ) ) { + $SESSIONS_next = $session['id']; + } + if ( strtotime("now") < $session['id'] + 3600 && ( $SESSIONS_actual==-1 || $SESSIONS_actual > $session['id'] ) ) { + $SESSIONS_actual = $session['id']; + } } - } - if($SESSIONS_next == -1) unset($SESSIONS_next); + if($SESSIONS_next == -1) unset($SESSIONS_next); + if($SESSIONS_actual == -1) unset($SESSIONS_actual); - $SESSIONS_totex = 0; - foreach ($SESSIONS as $session) { - if($session['id'] < $SESSIONS_next) { $SESSIONS_totex += $session['nexamples']; } - } + $SESSIONS_totex = 0; + foreach ($SESSIONS as $session) { + if($session['id'] < $SESSIONS_next) { $SESSIONS_totex += $session['nexamples']; } + } - $SESSIONS_totex_nextinc = 0; - foreach ($SESSIONS as $session) { - if($session['id'] <= $SESSIONS_next) { $SESSIONS_totex_nextinc += $session['nexamples']; } + $SESSIONS_totex_nextinc = 0; + foreach ($SESSIONS as $session) { + if($session['id'] <= $SESSIONS_next) { $SESSIONS_totex_nextinc += $session['nexamples']; } + } } ?> diff --git a/register.php b/register.php index 0a844ac..13e2aab 100644 --- a/register.php +++ b/register.php @@ -1,5 +1,6 @@ "; // 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); + $nachricht = "Hello $firstname($mnumber)!\nYou registered for " . $PREFS['exname'] . " (" . $PREFS['groupname'] . ").\nRemember your password: $password\n\nYours,\nBanana."; $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); + mail($email, "Banana Registration: " . $PREFS['exname'] . " (" . $PREFS['groupname'] . ")", $nachricht, $header); break; }