From 8d9321225140a3db0b72796d4d0236d6cacfeb8a Mon Sep 17 00:00:00 2001 From: Nicolas BERNSTEIN Date: Sat, 17 Sep 2011 19:36:41 +0200 Subject: Started working on a study program. --- lib/deck/add.php | 5 +++++ lib/deck/addent.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ lib/deck/edent.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ lib/deck/edit.php | 42 ++++++++++++++++++++++++++++++++++++++++++ lib/deck/index.php | 25 +++++++++++++++++++++++++ lib/deck/mvent.php | 32 ++++++++++++++++++++++++++++++++ lib/deck/new.php | 32 ++++++++++++++++++++++++++++++++ lib/deck/rment.php | 18 ++++++++++++++++++ lib/deck/view.php | 34 ++++++++++++++++++++++++++++++++++ 9 files changed, 278 insertions(+) create mode 100644 lib/deck/add.php create mode 100644 lib/deck/addent.php create mode 100644 lib/deck/edent.php create mode 100644 lib/deck/edit.php create mode 100644 lib/deck/index.php create mode 100644 lib/deck/mvent.php create mode 100644 lib/deck/new.php create mode 100644 lib/deck/rment.php create mode 100644 lib/deck/view.php (limited to 'lib/deck') diff --git a/lib/deck/add.php b/lib/deck/add.php new file mode 100644 index 0000000..d7f8e9f --- /dev/null +++ b/lib/deck/add.php @@ -0,0 +1,5 @@ +study decks.'; +require("tpl/general/empty.php"); 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 @@ + "Name : ", "name" => "name", "value" => $card_name), + array("label" => "Text : ", "name" => "text", "type" => "textarea", "value" => $card_text), +); +$validate = "Add card"; + +require("tpl/deck/ef.php"); 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 @@ + $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"); + diff --git a/lib/deck/edit.php b/lib/deck/edit.php new file mode 100644 index 0000000..3d893a2 --- /dev/null +++ b/lib/deck/edit.php @@ -0,0 +1,42 @@ + "Name : ", "name" => "name", "value" => $deck_name), + array("label" => "Comment : ", "name" => "comment", "type" => "textarea", "value" => $deck_comment), +); +$validate = "Edit deck"; + +require("tpl/deck/ef.php"); diff --git a/lib/deck/index.php b/lib/deck/index.php new file mode 100644 index 0000000..7a125e2 --- /dev/null +++ b/lib/deck/index.php @@ -0,0 +1,25 @@ + array ( + "nbUsers" => "popularity", + "name" => "name", + "owner" => "author", + ), + "way" => $ord_ways, +); +$fdefaults = array ( + "order" => "nbUsers", + "way" => "DESC", +); + +$decks = array(); +$n = sql( + "SELECT decks.id AS id, decks.name AS name, account.login AS owner, 0 AS nbUsers ". + "FROM decks LEFT JOIN account ON decks.owner = account.id ". + "ORDER BY " . get_filter("order") . " " . get_filter("way") + ); +while ($nn = mysql_fetch_assoc($n)) $decks[] = $nn; + +require("tpl/deck/index.php"); + diff --git a/lib/deck/mvent.php b/lib/deck/mvent.php new file mode 100644 index 0000000..d4571e9 --- /dev/null +++ b/lib/deck/mvent.php @@ -0,0 +1,32 @@ + $card['deckid'], 'name' => $card['deckname']); +$deckid = $card['deckid']; + +$mn = mysql_fetch_assoc(sql("SELECT COUNT(*) AS c FROM cards WHERE deck = $deckid")); +$mn = $mn['c']; +if ($pos > $mn) { + $error = "That number is too big. You don't even have that much cards in your deck."; +} else if ($pos < 1) { + $error = "A position is at least one..."; +} else { + sql("UPDATE cards SET number = 0 WHERE id = $cardid"); + sql("UPDATE cards SET number = number - 1 WHERE number > " . $card['number']); + sql("UPDATE cards SET number = number + 1 WHERE number >= $pos"); + sql("UPDATE cards SET number = $pos WHERE id = $cardid"); + header("Location: view-deck-$deckid"); +} + +require("tpl/deck/ef.php"); diff --git a/lib/deck/new.php b/lib/deck/new.php new file mode 100644 index 0000000..2ff1b50 --- /dev/null +++ b/lib/deck/new.php @@ -0,0 +1,32 @@ + "Name : ", "name" => "name", "value" => $deck_name), + array("label" => "Comment : ", "name" => "comment", "type" => "textarea", "value" => $deck_comment), + ); +$validate = "Create deck"; + +require("tpl/deck/new.php"); diff --git a/lib/deck/rment.php b/lib/deck/rment.php new file mode 100644 index 0000000..d3a87e0 --- /dev/null +++ b/lib/deck/rment.php @@ -0,0 +1,18 @@ += 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']); +header("Location: view-deck-" . $card['deckid']); diff --git a/lib/deck/view.php b/lib/deck/view.php new file mode 100644 index 0000000..eda2ca0 --- /dev/null +++ b/lib/deck/view.php @@ -0,0 +1,34 @@ + array ( + "name" => "card name", + "number" => "card number", + ), + "way" => $ord_ways, +); +$fdefaults = array ( + "order" => "number", + "way" => "ASC", +); + +$cards = array(); +$n = sql( + "SELECT id, number, name, text_html AS text FROM cards WHERE deck = $deckid ". + "ORDER BY " . get_filter("order") . " " . get_filter("way") + ); +while ($nn = mysql_fetch_assoc($n)) $cards[] = $nn; + +$can_edit = false; +if ($deck["owner_id"] == $user['id']) $can_edit = true; + +require("tpl/deck/view.php"); -- cgit v1.2.3