diff options
author | Nicolas BERNSTEIN <alexis211@gmail.com> | 2011-09-17 19:36:41 +0200 |
---|---|---|
committer | Nicolas BERNSTEIN <alexis211@gmail.com> | 2011-09-17 19:36:41 +0200 |
commit | 8d9321225140a3db0b72796d4d0236d6cacfeb8a (patch) | |
tree | 766e25ed98b86ed4cbf6d0517d9daaecc5ce3c18 /lib/deck/addent.php | |
parent | b6b341d949437c913fcce3d1a7c302945f67b22b (diff) | |
download | Bits-8d9321225140a3db0b72796d4d0236d6cacfeb8a.tar.gz Bits-8d9321225140a3db0b72796d4d0236d6cacfeb8a.zip |
Started working on a study program.
Diffstat (limited to 'lib/deck/addent.php')
-rw-r--r-- | lib/deck/addent.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/deck/addent.php b/lib/deck/addent.php new file mode 100644 index 0000000..a860df1 --- /dev/null +++ b/lib/deck/addent.php @@ -0,0 +1,46 @@ +<?php + +require("lib/markdown.php"); + +assert_redir(count($args) == 3, 'deck'); +$deckid = intval($args[2]); + +$deck = mysql_fetch_assoc(sql( + "SELECT decks.id AS id, decks.name AS name, decks.comment_md AS comment, decks.owner AS owner_id ". + "FROM decks ". + "WHERE decks.id = $deckid")); +assert_error($deck && $deck['owner_id'] == $user['id'], + "This deck does not exist, or you are not allowed to edit it."); + +$card_name = ""; +$card_text = ""; +if (isset($_POST['name']) && isset($_POST['text'])) { + $card_name = esca($_POST['name']); + $card_text = esca($_POST['text']); + $card_text_html = Markdown($card_text); + if ($card_name == "") { + $error = "You must give your card a name."; + } else if ($card_text == "") { + $error = "You must put some text in your card."; + } else if (mysql_fetch_assoc(sql("SELECT id FROM cards WHERE deck = $deckid AND name = '" . escs($card_name)."'"))) { + $error = "You already have a card using that name."; + } else { + $n = mysql_fetch_assoc(sql("SELECT MAX(number) AS n FROM cards WHERE deck = $deckid")); + $number = $n['n'] + 1; + sql( + "INSERT INTO cards(deck, number, name, text_md, text_html) ". + "VALUES($deckid, $number, '" . escs($card_name) . "', '" . escs($card_text) . "', '" . escs($card_text_html). "')"); + header("Location: view-deck-$deckid"); + die(); + } +} + +$title = "Add card to " . $deck['name']; +$message = "Your card will be added at the end of the deck. You can always move it afterwards."; +$fields = array( + array("label" => "Name : ", "name" => "name", "value" => $card_name), + array("label" => "Text : ", "name" => "text", "type" => "textarea", "value" => $card_text), +); +$validate = "Add card"; + +require("tpl/deck/ef.php"); |