X-Git-Url: http://git.treefish.org/banana.git/blobdiff_plain/3f75cb10d008938dca476577d6256765093d1932..HEAD:/include/session.inc?ds=sidebyside diff --git a/include/session.inc b/include/session.inc index c31441e..46802f4 100644 --- a/include/session.inc +++ b/include/session.inc @@ -1,28 +1,36 @@ 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; + $SESSIONS_n = 0; - 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']; + } + $SESSIONS_n++; } - } - 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; + $SESSIONS_totex_nextinc = 0; + if(isset($SESSIONS)) { + foreach ($SESSIONS as $session) { + if( (! isset($SESSIONS_next)) || $session['id'] < $SESSIONS_next ) { $SESSIONS_totex += $session['nexamples']; } + if( (! isset($SESSIONS_actual)) || $session['id'] != $SESSIONS_actual ) { $SESSIONS_last = $session['id']; } + if( (! isset($SESSIONS_next)) || $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']; } } ?>