summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNicolas BERNSTEIN <alexis211@gmail.com>2011-09-18 13:40:44 +0200
committerNicolas BERNSTEIN <alexis211@gmail.com>2011-09-18 13:40:44 +0200
commit8fb3d8370713f2b7b451c5ab6128736f990d62c9 (patch)
tree961423ce236a189cdb99cf30ef86ff6d719a88bc /lib
parent797a2dc9990bdd630fc1ef890ac137de074c6ff6 (diff)
downloadBits-8fb3d8370713f2b7b451c5ab6128736f990d62c9.tar.gz
Bits-8fb3d8370713f2b7b451c5ab6128736f990d62c9.zip
bugfixes.
Diffstat (limited to 'lib')
-rw-r--r--lib/deck/rment.php2
-rw-r--r--lib/study/deck.php8
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/deck/rment.php b/lib/deck/rment.php
index 6bb8300..c4f86c8 100644
--- a/lib/deck/rment.php
+++ b/lib/deck/rment.php
@@ -14,7 +14,7 @@ assert_error($card && $card["deckowner"] == $user['id'],
token_validate("Do you really want to delete this card ?", "view-deck-". $card['deckid']);
sql("DELETE FROM cards WHERE id = $cardid");
-sql("UPDATE cards SET number = number - 1 WHERE number > " . $card['number'] . " AND deck = " . $card['deckid']);
+sql("UPDATE cards SET number = number - 1 WHERE number > " . $card['number'] . " AND deck = " . $card['deckid'] . " ORDER BY number ASC");
sql("UPDATE deck_study SET need_check = 1 WHERE deck = " . $card['deckid']);
header("Location: view-deck-" . $card['deckid']);
die();
diff --git a/lib/study/deck.php b/lib/study/deck.php
index 94790e3..99119ef 100644
--- a/lib/study/deck.php
+++ b/lib/study/deck.php
@@ -12,10 +12,18 @@ assert_error($study && $study['learn_user'] == $user['id'], "You are not at the
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"));