summaryrefslogtreecommitdiff
path: root/lib/study/brresults.php
diff options
context:
space:
mode:
authorNicolas BERNSTEIN <alexis211@gmail.com>2011-11-20 13:39:47 +0100
committerNicolas BERNSTEIN <alexis211@gmail.com>2011-11-20 13:39:47 +0100
commitd45c7f14891d951f8a6987cc6492073b97e05b5b (patch)
treed6467b1202c27f67fd8e894d25fd4aea0085b559 /lib/study/brresults.php
parent4d7e065c2d2ec407b6a7ebfc7569628bac9149d1 (diff)
downloadBits-d45c7f14891d951f8a6987cc6492073b97e05b5b.tar.gz
Bits-d45c7f14891d951f8a6987cc6492073b97e05b5b.zip
Added the bit list study system
Diffstat (limited to 'lib/study/brresults.php')
-rw-r--r--lib/study/brresults.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/study/brresults.php b/lib/study/brresults.php
new file mode 100644
index 0000000..b3e1068
--- /dev/null
+++ b/lib/study/brresults.php
@@ -0,0 +1,35 @@
+<?php
+
+assert_redir(count($args) == 3, 'study');
+$batchid = intval($args[2]);
+
+$info = mysql_fetch_assoc(sql(
+ "SELECT list_study.id AS studyid, ".
+ "batch_study.id AS bsid, batches.id AS batchid, batches.json_data AS json_data ".
+ "FROM batches LEFT JOIN list_study ON list_study.list = batches.list AND list_study.user = " . $user['id'] . " " .
+ "LEFT JOIN batch_study ON batch_study.batch = $batchid AND batch_study.user = " . $user['id'] . " " .
+ "WHERE batches.id = $batchid"));
+if (!($info)) {
+ echo "This batch does not exist";
+ die();
+}
+if (!($info['studyid'] != 0)) {
+ echo "You are not studying this list.";
+ die();
+}
+
+if ($info["bsid"] == 0) {
+ sql("INSERT INTO batch_study(user, batch, last_review) VALUES(" . $user['id'] . ", $batchid, 0)");
+ $info['bsid'] = mysql_insert_id();
+}
+
+if (isset($_POST['results']) && isset($_POST['score'])) {
+ sql("INSERT INTO batch_review(user, batch, results, score, date) ".
+ "VALUES(" . $user['id'] . ", $batchid, '" . escs(esca($_POST['results'])) . "', " . intval($_POST['score']) . ", NOW())");
+ sql("UPDATE batch_study SET last_review = " . mysql_insert_id() . " WHERE id = " . $info['bsid']);
+ echo 'Saved';
+} else {
+ echo 'Error';
+}
+
+die();