summaryrefslogtreecommitdiff
path: root/lib/deck/edent.php
diff options
context:
space:
mode:
authorNicolas BERNSTEIN <alexis211@gmail.com>2011-09-17 19:36:41 +0200
committerNicolas BERNSTEIN <alexis211@gmail.com>2011-09-17 19:36:41 +0200
commit8d9321225140a3db0b72796d4d0236d6cacfeb8a (patch)
tree766e25ed98b86ed4cbf6d0517d9daaecc5ce3c18 /lib/deck/edent.php
parentb6b341d949437c913fcce3d1a7c302945f67b22b (diff)
downloadBits-8d9321225140a3db0b72796d4d0236d6cacfeb8a.tar.gz
Bits-8d9321225140a3db0b72796d4d0236d6cacfeb8a.zip
Started working on a study program.
Diffstat (limited to 'lib/deck/edent.php')
-rw-r--r--lib/deck/edent.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/deck/edent.php b/lib/deck/edent.php
new file mode 100644
index 0000000..8bdfac3
--- /dev/null
+++ b/lib/deck/edent.php
@@ -0,0 +1,44 @@
+<?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 ".
+ "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.");
+$deck = array("id" => $card['deckid'], 'name' => $card['deckname']);
+
+$card_name = $card['name'];
+$card_text = $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 = " . $deck['id'] . " AND name = '" . escs($card_name)."' AND id != $cardid"))) {
+ $error = "You already have a card using that name.";
+ } else {
+ sql("UPDATE cards SET name = '" . escs($card_name) . "', text_md = '" . escs($card_text) . "', text_html = '" . escs($card_text_html) . "'" .
+ " WHERE id = $cardid");
+ header("Location: view-deck-" . $deck['id']);
+ die();
+ }
+}
+
+$title = "Edit card in " . $deck['name'];
+$fields = array(
+ array("label" => "Name : ", "name" => "name", "value" => $card_name),
+ array("label" => "Text : ", "name" => "text", "type" => "textarea", "value" => $card_text),
+);
+$validate = "Edit card";
+
+require("tpl/deck/ef.php");
+