Beispiel #1
0
function OnGrade($answer, $userid)
{
    global $CFG, $gameid;
    $result = mysql_query("SELECT * FROM {$CFG->prefix}game WHERE id={$gameid}");
    $game = mysql_fetch_assoc($result);
    $question = $game['question'];
    if (time() < $game['timefinish'] + 2) {
        $timeout = 0;
    } else {
        $timeout = 1;
    }
    $todelete = $timeout;
    $ip = GetMyIP();
    $timehit = date('Y-m-d H:i:s');
    $query = "INSERT INTO {$CFG->prefix}hits(userid,ip,question,answer,timeout,todelete,gameid,timehit) SELECT {$userid},'{$ip}',{$question},{$answer},{$timeout},{$todelete},{$gameid},'{$timehit}'";
    mysql_query($query);
    if ($timeout) {
        echo 'Απάντηση εκτός χρόνου';
    }
    for (;;) {
        $query = "SELECT min(id) as minid,max(id) as maxid FROM {$CFG->prefix}hits WHERE question={$question} AND userid={$userid} AND todelete=0";
        $result = mysql_query($query);
        if (($rec = mysql_fetch_assoc($result)) != false) {
            if ($rec['minid'] == $rec['maxid']) {
                break;
            }
            $query = "UPDATE {$CFG->prefix}hits SET todelete=1 WHERE id=" . $rec['minid'];
            mysql_query($query);
        }
    }
}
Beispiel #2
0
function ComputeTimerStudent(&$resttime, &$question, &$questiontext, &$md5, &$infoanswer)
{
    global $CFG, $gameid;
    $userid = $_SESSION['userid'];
    $sql = "SELECT * FROM {$CFG->prefix}game WHERE id={$gameid}";
    $result = mysql_query($sql) or die("MySQL Query Error: " . mysql_error() . ' ' . $sql);
    $game = mysql_fetch_assoc($result);
    $gameid = $game['id'];
    $resttime = $game['timefinish'] - time();
    if ($resttime < 0) {
        $resttime = 0;
    }
    $question = $game['question'];
    $questiontext = $game['questiontext'];
    $md5 = $game['md5questiontext'];
    $sql = "SELECT * FROM {$CFG->prefix}users WHERE id={$userid}";
    $result = mysql_query($sql) or die("MySQL Query Error: " . mysql_error() . ' ' . $sql);
    $user = mysql_fetch_assoc($result);
    if ($user == false) {
        die($sql);
    }
    $ip = GetMyIP();
    if ($user['lastip'] != $ip) {
        die('Λάθος IP: ' . $ip . ' user='******'username']);
    }
    $sql = "SELECT * FROM {$CFG->prefix}hits WHERE question={$question} AND todelete=0 AND userid={$userid}";
    $result = mysql_query($sql) or die("MySQL Query Error: " . mysql_error() . ' ' . $sql);
    $rec = mysql_fetch_assoc($result);
    $infoanswer = '';
    if ($rec == false) {
        $infoanswer = '<b>' . $user['name'] . '</b>: Δεν δώσατε ακόμη καμία απάντηση';
    } else {
        $answer = $rec['answer'];
        $infoanswer = '<b>' . $user['name'] . '</b>: Σαν απάντηση δώσατε: <b>' . $answer . '</b>';
        if ($rec['graded']) {
            if ($rec['grade'] == 1) {
                $s = '1 βαθμός';
            } else {
                $s = $rec['grade'] . ' βαθμοί';
            }
            $infoanswer .= ' Απαντήσατε σωστά (' . $s . ')';
        }
    }
}