diff options
author | root <root@adnab.me> | 2014-01-31 16:42:40 +0100 |
---|---|---|
committer | root <root@adnab.me> | 2014-01-31 16:42:40 +0100 |
commit | b0c23ea84327d48e3a4383fac3e795c2dc0a1215 (patch) | |
tree | 625a8f0882815d9442a4ff2ec15a49e669a15ed3 /lib/study | |
parent | cee55b766230837c21453f85e76a921cb5b8b89e (diff) | |
download | Bits-b0c23ea84327d48e3a4383fac3e795c2dc0a1215.tar.gz Bits-b0c23ea84327d48e3a4383fac3e795c2dc0a1215.zip |
Remove all studying apps code.
Diffstat (limited to 'lib/study')
-rw-r--r-- | lib/study/batch.php | 34 | ||||
-rw-r--r-- | lib/study/batchreview.php | 25 | ||||
-rw-r--r-- | lib/study/brresults.php | 41 | ||||
-rw-r--r-- | lib/study/deck.php | 96 | ||||
-rw-r--r-- | lib/study/deckadd.php | 13 | ||||
-rw-r--r-- | lib/study/deckrm.php | 17 | ||||
-rw-r--r-- | lib/study/index.php | 7 | ||||
-rw-r--r-- | lib/study/list.php | 43 | ||||
-rw-r--r-- | lib/study/listadd.php | 13 | ||||
-rw-r--r-- | lib/study/listrm.php | 16 | ||||
-rw-r--r-- | lib/study/setcard.php | 37 | ||||
-rw-r--r-- | lib/study/setrate.php | 19 |
12 files changed, 0 insertions, 361 deletions
diff --git a/lib/study/batch.php b/lib/study/batch.php deleted file mode 100644 index 60152f1..0000000 --- a/lib/study/batch.php +++ /dev/null @@ -1,34 +0,0 @@ -<?php - -assert_redir(count($args) == 3, 'study'); -$batchid = intval($args[2]); - -$info = mysql_fetch_assoc(sql( - "SELECT list_study.id AS studyid, batches.name AS bname, ". - "lists.name AS lname, account.login AS uname, ". - "batch_study.id AS bsid, batch_study.notes_json AS notes, ". - "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'] . " " . - "LEFT JOIN lists ON batches.list = lists.id ". - "LEFT JOIN account ON account.id = lists.owner ". - "WHERE batches.id = $batchid")); -assert_error($info, "This batch does not exist."); -assert_error($info['studyid'] != 0, "You are not studying this list."); - -if ($info["bsid"] == 0) { - sql("INSERT INTO batch_study(user, batch, last_review, notes_json) ". - "VALUES(" . $user['id'] . ", $batchid, 0, '{}')"); - $info['bsid'] = mysql_insert_id(); - $info['notes'] = '{}'; -} - -$reviews = array(); -$d = sql("SELECT results, score, date, batch FROM batch_review WHERE batch = $batchid AND user = " . $user['id'] ." ORDER BY date ASC"); -while ($r = mysql_fetch_assoc($d)) { - $reviews[] = '{"batch": ' . $r['batch'] . ', "date" : "' . $r['date'] . '", '. - '"score": ' . $r['score'] . ', "results": ' . $r['results'] . '}'; -} -$reviews = '[' . implode(', ', $reviews) . ']'; - -require("tpl/study/batch.php"); diff --git a/lib/study/batchreview.php b/lib/study/batchreview.php deleted file mode 100644 index 58fc852..0000000 --- a/lib/study/batchreview.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php - -assert_redir(count($args) == 3, 'study'); -$batchid = intval($args[2]); - -$info = mysql_fetch_assoc(sql( - "SELECT list_study.id AS studyid, batches.name AS bname, ". - "lists.name AS lname, account.login AS uname, ". - "batch_study.id AS bsid, batch_study.notes_json AS notes, ". - "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'] . " " . - "LEFT JOIN lists ON batches.list = lists.id ". - "LEFT JOIN account ON account.id = lists.owner ". - "WHERE batches.id = $batchid")); -assert_error($info, "This batch does not exist."); -assert_error($info['studyid'] != 0, "You are not studying this list."); - -if ($info["bsid"] == 0) { - sql("INSERT INTO batch_study(user, batch, last_review, notes_json) VALUES(" . $user['id'] . ", $batchid, 0, '{}')"); - $info['bsid'] = mysql_insert_id(); - $info['notes'] = '{}'; -} - -require("tpl/study/batch_review.php"); diff --git a/lib/study/brresults.php b/lib/study/brresults.php deleted file mode 100644 index 93ebfdf..0000000 --- a/lib/study/brresults.php +++ /dev/null @@ -1,41 +0,0 @@ -<?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, notes_json) ". - "VALUES(" . $user['id'] . ", $batchid, 0, '{}')"); - $info['bsid'] = mysql_insert_id(); - $info['notes'] = '{}'; -} - -if (isset($_POST['results']) && isset($_POST['score'])) { - sql("UPDATE batch_study SET before_last_review = last_review WHERE id = " . $info['bsid']); - 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 if (isset($_POST['notes'])) { - sql("UPDATE batch_study SET notes_json = '" . escs(esca($_POST['notes'])) . "' WHERE id = " . $info['bsid']); - echo 'Saved'; -} else { - echo 'Error'; -} - -die(); diff --git a/lib/study/deck.php b/lib/study/deck.php deleted file mode 100644 index 752ff98..0000000 --- a/lib/study/deck.php +++ /dev/null @@ -1,96 +0,0 @@ -<?php - -assert_redir(count($args) == 3, 'study'); -$studyid = intval($args[2]); - -$study = mysql_fetch_assoc(sql( - "SELECT decks.id AS deckid, decks.name AS deckname, account.login AS deckowner, ". - " deck_study.learn_rate AS learn_rate, deck_study.user AS learn_user, deck_study.need_check AS need_check, deck_study.last_card AS last_card ". - "FROM deck_study LEFT JOIN decks ON deck_study.deck = decks.id LEFT JOIN account ON account.id = decks.owner ". - "WHERE deck_study.id = $studyid")); -assert_error($study && $study['learn_user'] == $user['id'], "You are not at the right place here."); - -if ($study['need_check']) { - /* Algorithm : - - Delete references to deleted cards - - Check that deck_study.last_card = max(card_study.card.number) - - Check that foreach (card where card.deck = deck_study.deck && card.number < deck_study.last_card), - exists corresponding card_study, if not exist, create level 0 (skipped) - */ - $n = sql("SELECT card_study.id AS id, cards.deck AS d FROM card_study ". - "LEFT JOIN cards ON cards.id = card_study.card WHERE card_study.deck_study = $studyid"); - while ($r = mysql_fetch_assoc($n)) { - if (intval($r['d']) == 0) { - sql("DELETE FROM card_study WHERE id = " . $r['id']); - } - } - $mcn = mysql_fetch_assoc(sql("SELECT MAX(cards.number) AS mcn FROM deck_study ". - "LEFT JOIN card_study ON card_study.deck_study = deck_study.id LEFT JOIN cards ON cards.id = card_study.card ". - "WHERE deck_study.id = $studyid")); - $hasmoar = false; - if ($mcn) { - $mcn = $mcn['mcn']; - if ($study['last_card'] != $mcn) sql('UPDATE deck_study SET last_card = ' . $mcn . ' WHERE id = ' . $studyid); - - $cs = array(); - for($i = 1; $i < $mcn; $i++) $cs[$i] = 0; - - $d = sql("SELECT cards.number AS n, card_study.id AS i FROM card_study LEFT JOIN cards ON cards.id = card_study.card ". - "WHERE card_study.deck_study = $studyid"); - while($r = mysql_fetch_assoc($d)) $cs[$r['n']] = $r['i']; - - for ($i = 1; $i < $mcn; $i++) { - if ($cs[$i] == 0) { - $n = mysql_fetch_assoc(sql("SELECT cards.id AS id FROM deck_study LEFT JOIN cards ON cards.deck = deck_study.deck AND cards.number = $i ". - "WHERE deck_study.id = $studyid")); - assert_error($n, "Fucking deck inconsistency."); - sql("INSERT INTO card_study(deck_study, card, level, next_review) ". - "VALUES($studyid, " . $n['id'] . ", 0, ADDDATE(CURDATE(), INTERVAL 999999 DAY))"); - $hasmoar = true; - } - } - } - sql("UPDATE deck_study SET need_check = 0 WHERE id = $studyid"); - $message = "This deck has been checked. " . ($hasmoar ? "Some cards you hadn't studied before were added to your skipped list." : ""); -} - - -$load = mysql_fetch_assoc(sql("SELECT SUM(4 - level) AS l FROM card_study WHERE deck_study = $studyid AND level < 4 AND level > 0")); -$load = intval($load['l']); - -if ($load < $study['learn_rate']) { - $next_card = mysql_fetch_assoc(sql("SELECT * FROM cards WHERE deck = " . $study['deckid'] . " AND number = " . ($study['last_card'] + 1))); -} - - - -$filters = array( - "what" => array( - "level > 0 AND next_review <= CURDATE()" => "study today", - "level > 0 AND level < 4" => "learning", - "level > 0" => "all except skipped", - "level = 0" => "skipped", - ), - "order" => array( - "level" => "level", - "number" => "card number", - ), - "way" => $ord_ways, -); -$fdefaults = array( - "what" => "level > 0 AND next_review <= CURDATE()", - "order" => "level", - "way" => "ASC", -); - -$study_cards = array(); -$s = sql( - "SELECT cards.id AS id, cards.name AS name, cards.text_html AS text, cards.number AS number, ". - "card_study.level AS level, card_study.next_review <= CURDATE() AS must_study ". - "FROM card_study LEFT JOIN cards ON card_study.card = cards.id WHERE deck_study = $studyid AND " . get_filter("what") . - " ORDER BY " . get_filter("order") . " " . get_filter('way') . (get_filter("order") == "level" ? ", number " . get_filter("way") : "")); -while ($ss = mysql_fetch_assoc($s)) $study_cards[] = $ss; - - - -require("tpl/study/deck.php"); diff --git a/lib/study/deckadd.php b/lib/study/deckadd.php deleted file mode 100644 index b95648c..0000000 --- a/lib/study/deckadd.php +++ /dev/null @@ -1,13 +0,0 @@ -<?php - -assert_redir(count($args) == 3, 'deck'); -$deckid = intval($args[2]); -$deck = mysql_fetch_assoc(sql("SELECT id FROM decks WHERE id = $deckid")); -assert_error($deck, "This deck does not exist."); - -assert_error(!mysql_fetch_assoc(sql("SELECT id FROM deck_study WHERE deck = $deckid AND user = " . $user['id'])), - "You are already studying this deck."); - -sql("INSERT INTO deck_study(user, deck) VALUES(" . $user['id'] . ", $deckid)"); -header("Location: deck-study-".mysql_insert_id()); -die(); diff --git a/lib/study/deckrm.php b/lib/study/deckrm.php deleted file mode 100644 index 6b4e803..0000000 --- a/lib/study/deckrm.php +++ /dev/null @@ -1,17 +0,0 @@ -<?php - -assert_redir(count($args) >= 3, 'study'); -$studyid = intval($args[2]); - -$study = mysql_fetch_assoc(sql( - "SELECT ". - " deck_study.user AS learn_user ". - "FROM deck_study ". - "WHERE deck_study.id = $studyid")); -assert_error($study && $study['learn_user'] == $user['id'], "You are not at the right place here."); - -token_validate("Do you really want to remove this deck from your studies ? ALL YOUR PROGRESS WILL BE LOST!", "deck-study-$studyid"); -sql("DELETE FROM card_study WHERE deck_study = $studyid"); -sql("DELETE FROM deck_study WHERE id = $studyid"); -header("Location: study"); -die(); diff --git a/lib/study/index.php b/lib/study/index.php deleted file mode 100644 index 6b43d53..0000000 --- a/lib/study/index.php +++ /dev/null @@ -1,7 +0,0 @@ -<?php - -if ($user['id'] == 0) { - $message = "You must create an account to use this study program."; -} - -require("tpl/study/index.php"); diff --git a/lib/study/list.php b/lib/study/list.php deleted file mode 100644 index bebffa6..0000000 --- a/lib/study/list.php +++ /dev/null @@ -1,43 +0,0 @@ -<?php - -assert_redir(count($args) == 3, 'study'); -$studyid = intval($args[2]); - -$study = mysql_fetch_assoc(sql( - "SELECT lists.id AS listid, lists.name AS listname, account.login AS listowner, ". - " list_study.user AS learn_user ". - "FROM list_study LEFT JOIN lists ON list_study.list = lists.id LEFT JOIN account ON account.id = lists.owner ". - "WHERE list_study.id = $studyid")); -assert_error($study && $study['learn_user'] == $user['id'], "You are not at the right place here."); - -$filters = array( - "order" => array( - "name" => "name", - "lr_score" => "last score", - "lr_date" => "last reviewed" - ), - "way" => $ord_ways, -); -$fdefaults = array( - "order" => "name", - "way" => "ASC", -); - -$batches = array(); -$n = sql( - "SELECT batches.id AS id, batches.name AS name, ". - "batch_study.id AS bs_id, ba.date AS lr_date, TO_DAYS(NOW()) - TO_DAYS(ba.date) AS lr_days, ". - "ba.score AS lr_score, bc.date AS blr_date, bc.score AS blr_score, ". - "COUNT(bb.id) AS num_reviews ". - "FROM batches ". - "LEFT JOIN batch_study ON batch_study.batch = batches.id AND batch_study.user = " . $user['id'] . " " . - "LEFT JOIN batch_review ba ON ba.id = batch_study.last_review ". - "LEFT JOIN batch_review bb ON bb.batch = batches.id AND bb.user = " . $user['id'] . " ". - "LEFT JOIN batch_review bc ON bc.id = batch_study.before_last_review ". - "WHERE batches.list = " . $study['listid'] . " " . - "GROUP BY batches.id ". - "ORDER BY " . get_filter("order") . " " . get_filter("way") - ); -while ($b = mysql_fetch_assoc($n)) $batches[] = $b; - -require("tpl/study/list.php"); diff --git a/lib/study/listadd.php b/lib/study/listadd.php deleted file mode 100644 index 536ab1d..0000000 --- a/lib/study/listadd.php +++ /dev/null @@ -1,13 +0,0 @@ -<?php - -assert_redir(count($args) == 3, 'list'); -$listid = intval($args[2]); -$list = mysql_fetch_assoc(sql("SELECT id FROM lists WHERE id = $listid")); -assert_error($list, "This list does not exist."); - -assert_error(!mysql_fetch_assoc(sql("SELECT id FROM list_study WHERE list = $listid AND user = " . $user['id'])), - "You are already studying this list."); - -sql("INSERT INTO list_study(user, list) VALUES(" . $user['id'] . ", $listid)"); -header("Location: list-study-".mysql_insert_id()); -die(); diff --git a/lib/study/listrm.php b/lib/study/listrm.php deleted file mode 100644 index a761e97..0000000 --- a/lib/study/listrm.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php - -assert_redir(count($args) >= 3, 'study'); -$studyid = intval($args[2]); - -$study = mysql_fetch_assoc(sql( - "SELECT ". - " list_study.user AS learn_user ". - "FROM list_study ". - "WHERE list_study.id = $studyid")); -assert_error($study && $study['learn_user'] == $user['id'], "You are not at the right place here."); - -token_validate("Do you really want to remove this list from your studies ? Your progress will not be lost.", "list-study-$studyid"); -sql("DELETE FROM list_study WHERE id = $studyid"); -header("Location: study"); -die(); diff --git a/lib/study/setcard.php b/lib/study/setcard.php deleted file mode 100644 index c71bbfe..0000000 --- a/lib/study/setcard.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php - -assert_redir(count($args) == 4, 'study'); -$cardid = intval($args[2]); - -$info = mysql_fetch_assoc(sql( - "SELECT deck_study.id AS studyid, deck_study.last_card AS last_card, deck_study.need_check AS need_check, ". - "card_study.id AS csid, cards.id AS cardid, cards.number AS cardnumber ". - "FROM cards LEFT JOIN deck_study ON deck_study.deck = cards.deck AND deck_study.user = " . $user['id'] . " ". - "LEFT JOIN card_study ON card_study.deck_study = deck_study.id AND card_study.card = $cardid ". - "WHERE cards.id = $cardid" - )); -assert_error($info, "This card does not exist."); - -$studyid = intval($info['studyid']); -assert_error($studyid > 0, "You are not studying this deck."); - -assert_error($info['need_check'] == 0, - 'This deck needs checking first. Please return <a href="deck-study-'.$studyid.'">here</a> first, it should do it.'); - -assert_error($info['cardnumber'] <= $info['last_card'] + 1, "You must first add previous cards to your study list."); - -$level = intval($args[3]); -assert_error($level >= 0 && $level <= 7, "That level is invalid."); -$intervals = array(999999, 1, 2, 4, 8, 16, 32, 999999); - -if ($info['cardnumber'] == $info['last_card'] + 1) { - sql("INSERT INTO card_study(deck_study, card, level, next_review) ". - "VALUES($studyid, $cardid, $level, ADDDATE(CURDATE(), INTERVAL " . $intervals[$level] . " DAY))"); - sql("UPDATE deck_study SET last_card = last_card + 1 WHERE id = $studyid"); -} else { - assert_error($info['csid'] > 0, "Deck is inconsistent."); - sql("UPDATE card_study SET level = $level, next_review = ADDDATE(CURDATE(), INTERVAL " . $intervals[$level] . " DAY) WHERE id = " . $info['csid']); -} - -header("Location: deck-study-$studyid"); -die(); diff --git a/lib/study/setrate.php b/lib/study/setrate.php deleted file mode 100644 index f893eb9..0000000 --- a/lib/study/setrate.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php - -assert_redir(count($args) >= 3, 'study'); -$studyid = intval($args[2]); - -$study = mysql_fetch_assoc(sql( - "SELECT decks.id AS deckid, decks.name AS deckname, account.login AS deckowner, ". - " deck_study.learn_rate AS learn_rate, deck_study.user AS learn_user ". - "FROM deck_study LEFT JOIN decks ON deck_study.deck = decks.id LEFT JOIN account ON account.id = decks.owner ". - "WHERE deck_study.id = $studyid")); -assert_error($study && $study['learn_user'] == $user['id'], "You are not at the right place here."); - -if (isset($args[3]) && ($rate = intval($args[3])) > 0) { - sql("UPDATE deck_study SET learn_rate = $rate WHERE id = $studyid"); - header("Location: deck-study-$studyid"); - die(); -} - -include ("tpl/study/setrate.php"); |