summaryrefslogblamecommitdiff
path: root/lib/deck/rment.php
blob: 6bb830091f0d84fc5b20d885c9e970ca77885801 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
















                                                                                                                                                          
                                                                            
                                                 
      
<?php

require("lib/markdown.php");

assert_redir(count($args) >= 3, 'deck');
$cardid = intval($args[2]);

$card = mysql_fetch_assoc(sql(
	"SELECT decks.id AS deckid, decks.owner AS deckowner, decks.name AS deckname, cards.name AS name, cards.text_md AS text, cards.number AS number ".
	"FROM cards LEFT JOIN decks ON decks.id = cards.deck ".
	"WHERE cards.id = $cardid"));
assert_error($card && $card["deckowner"] == $user['id'],
	"This card does not exist, or you are not allowed to edit it.");

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 deck_study SET need_check = 1 WHERE deck = " . $card['deckid']);
header("Location: view-deck-" . $card['deckid']);
die();