summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--design/style.css30
-rw-r--r--lib/conf/apps.php36
-rw-r--r--lib/deck/add.php5
-rw-r--r--lib/deck/addent.php46
-rw-r--r--lib/deck/edent.php44
-rw-r--r--lib/deck/edit.php42
-rw-r--r--lib/deck/index.php25
-rw-r--r--lib/deck/mvent.php32
-rw-r--r--lib/deck/new.php32
-rw-r--r--lib/deck/rment.php18
-rw-r--r--lib/deck/view.php34
-rw-r--r--lib/functions.php61
-rw-r--r--lib/notes/index.php14
-rw-r--r--lib/study/deck.php5
-rw-r--r--lib/study/deckadd.php5
-rw-r--r--lib/study/index.php3
-rw-r--r--schema.sql40
-rw-r--r--tpl/deck/ef.php16
-rw-r--r--tpl/deck/index.php20
-rw-r--r--tpl/deck/new.php8
-rw-r--r--tpl/deck/view.php33
-rw-r--r--tpl/general/top.php9
-rw-r--r--tpl/notes/index.php2
-rw-r--r--tpl/study/index.php16
-rw-r--r--tpl/study/lib_sidebar.php18
25 files changed, 582 insertions, 12 deletions
diff --git a/design/style.css b/design/style.css
index d186eda..64571fa 100644
--- a/design/style.css
+++ b/design/style.css
@@ -54,6 +54,8 @@ h1 {
.menu a {
min-width: 100px;
padding: 4px;
+ padding-left: 20px;
+ padding-right: 20px;
}
}
@@ -125,7 +127,7 @@ iframe, textarea {
iframe, textarea {
border: 1px solid gray;
width: 98%;
- height: 400px;
+ height: 300px;
}
textarea {
@@ -177,6 +179,13 @@ iframe, textarea {
font-style: italic;
}
+.ordering_links {
+ font-size: 0.8em;
+ margin-top: 10px;
+ margin-left: 50px;
+ color: #444;
+}
+
table {
margin: 8px;
width: 99%;
@@ -199,6 +208,25 @@ th {
text-align: center;
}
+code {
+ font-size: 1.2em;
+}
+
abbr {
border-bottom: 1px dashed #999;
}
+
+
+/* CARDS */
+
+.study_card {
+ margin: 16px;
+ border-left: 1px solid #ccc;
+ border-bottom: 1px solid #ccc;
+ padding: 8px;
+}
+
+.study_card code {
+ margin-left: 16px;
+ margin-bottom: 8px;
+}
diff --git a/lib/conf/apps.php b/lib/conf/apps.php
index fc714ca..734bfca 100644
--- a/lib/conf/apps.php
+++ b/lib/conf/apps.php
@@ -3,12 +3,20 @@
$homepage = "notes";
$apps = array(
+
+ // Image upload application
"image" => array(
"index" => 1,
"delete" => 1,
- "upload" => 0),
+ "upload" => 0,
+ ),
+
+ // Account application
"account" => array(
- "new" => 0),
+ "new" => 0,
+ ),
+
+ // Notebook application
"notes" => array(
"index" => 0,
"user" => 0,
@@ -17,5 +25,25 @@ $apps = array(
"edit" => 1,
"delete" => 1,
"move" => 1,
- "source" => 0),
- );
+ "source" => 0,
+ ),
+
+ // Studies application
+ "deck" => array(
+ "index" => 0,
+ "new" => 1,
+ "view" => 0,
+ // function called for editing
+ "edit" => 1, // change title, comment
+ "addent" => 1, // add card
+ "rment" => 1, // remove card
+ "edent" => 1, // edit card
+ "mvent" => 1, // move card
+ ),
+ "study" => array (
+ "index" => 1,
+ "deckadd" => 1,
+ "deck" => 1,
+ ),
+
+);
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 @@
+<?php
+
+$title = "olol";
+$message = 'Placeholder. Go to <a href="deck">study decks</a>.';
+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 @@
+<?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");
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");
+
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 @@
+<?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, account.id AS owner_id ".
+ "FROM decks LEFT JOIN account ON account.id = decks.owner ".
+ "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.");
+
+$deck_name = $deck['name'];
+$deck_comment = $deck['comment'];
+if (isset($_POST['name']) && isset($_POST['comment'])) {
+ $deck_name = esca($_POST['name']);
+ $deck_comment = esca($_POST['comment']);
+ $deck_comment_html = Markdown($deck_comment);
+ if ($deck_name == "") {
+ $error = "You must enter a name for your deck.";
+ } else if (mysql_fetch_assoc(sql("SELECT id FROM decks WHERE owner = " . $user['id'] . " AND name = '" . escs($deck_name) . "' AND id != $deckid"))) {
+ $error = "You already have a deck with that title.";
+ } else if ($deck_comment == "") {
+ $error = "Please enter a comment on your deck.";
+ } else {
+ sql("UPDATE decks SET name = '" . escs($deck_name) . "', comment_md = '" . escs($deck_comment) .
+ "', comment_html = '" . escs($deck_comment_html) . "' WHERE id = $deckid");
+ header("Location: view-deck-" . $deckid);
+ die();
+ }
+}
+
+$title = "Edit : " . $deck['name'];
+$fields = array(
+ array("label" => "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 @@
+<?php
+
+$filters = array (
+ "order" => 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 @@
+<?php
+
+require("lib/markdown.php");
+
+assert_redir(count($args) == 4, 'deck');
+$cardid = intval($args[2]);
+$pos = intval($args[3]);
+
+$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.");
+$deck = array("id" => $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 @@
+<?php
+
+require("lib/markdown.php");
+
+$deck_name = "";
+$deck_comment = "";
+if (isset($_POST["name"]) && isset($_POST['comment'])) {
+ $deck_name = esca($_POST['name']);
+ $deck_comment = esca($_POST['comment']);
+ $deck_comment_html = Markdown($deck_comment);
+ if ($deck_name == "") {
+ $error = "You must enter a name for your deck.";
+ } else if (mysql_fetch_assoc(sql("SELECT id FROM decks WHERE owner = " . $user['id'] . " AND name = '" . escs($deck_name) . "'"))) {
+ $error = "You already have a deck with that title.";
+ } else if ($deck_comment == "") {
+ $error = "Please enter a comment on your deck.";
+ } else {
+ sql("INSERT INTO decks(owner, name, comment_md, comment_html) ".
+ "VALUES(" . $user['id'] . ", '" . escs($deck_name) . "', '" . escs($deck_comment) . "', '" . escs($deck_comment_html) . "')");
+ header("Location: view-deck-" . mysql_insert_id());
+ die();
+ }
+}
+
+$title = "Create deck";
+$fields = array(
+ array("label" => "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 @@
+<?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']);
+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 @@
+<?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_html AS comment, account.login AS owner, account.id AS owner_id ".
+ "FROM decks LEFT JOIN account ON account.id = decks.owner ".
+ "WHERE decks.id = $deckid"));
+assert_error($deck, "This deck does not exist.");
+
+$filters = array (
+ "order" => 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");
diff --git a/lib/functions.php b/lib/functions.php
index 549ed3b..6190818 100644
--- a/lib/functions.php
+++ b/lib/functions.php
@@ -50,3 +50,64 @@ function assert_error($a, $e, $t = "") {
die();
}
}
+
+
+// **** DISPLAY FILTERS *******
+
+function get_filter($name) {
+ global $filters, $fdefaults;
+ if (!isset($filters[$name])) return "";
+ $v = (isset($_GET[$name]) ? $_GET[$name] : "");
+ if (!isset($filters[$name][$v])) return $fdefaults[$name];
+ return $v;
+}
+
+function filter_html_entry($name, $entry) {
+ global $filters, $filters_defaults, $url;
+ if (!isset($filters[$name])) return "";
+ if (!isset($filters[$name][$entry])) return "";
+ $rurl = array("p=".$url, $name . "=" . $entry);
+ foreach ($filters as $filter => $n) {
+ if ($filter != $name) {
+ $rurl[] = ($filter . "=" . get_filter($filter));
+ }
+ }
+ return '<a href="index.php?' . implode("&", $rurl) . '">' . $filters[$name][$entry] . '</a>';
+}
+
+function filter_html($name) {
+ global $filters, $filters_defaults;
+ if (!isset($filters[$name])) return "";
+ $r = array();
+ foreach ($filters[$name] as $v => $t) {
+ if (get_filter($name) == $v) {
+ $r[] = "<b>" . $t . "</b>";
+ } else {
+ $r[] = filter_html_entry($name, $v);
+ }
+ }
+ return implode(", ", $r);
+}
+
+function filters_html() {
+ global $filters;
+ $r = array();
+ foreach ($filters as $k => $filter) {
+ $r[$k] = filter_html($k);
+ }
+ return $r;
+}
+
+function filters_html_full() {
+ global $filters_names;
+ $r = array();
+ foreach (filters_html() as $f => $h) {
+ $r[] = $f . " (" . $h . ")";
+ }
+ return implode(", ", $r);
+}
+
+$ord_ways = array (
+ "ASC" => "ascending",
+ "DESC" => "descending"
+);
diff --git a/lib/notes/index.php b/lib/notes/index.php
index 3c81f46..3089605 100644
--- a/lib/notes/index.php
+++ b/lib/notes/index.php
@@ -1,9 +1,21 @@
<?php
+$filters = array (
+ "order" => array (
+ "nbNotes" => "number of notes",
+ "name" => "username",
+ ),
+ "way" => $ord_ways,
+);
+$fdefaults = array (
+ "order" => "nbNotes",
+ "way" => "DESC",
+);
+
$users = array();
$n = sql("SELECT account.id AS id, login AS name, COUNT(notes.id) AS nbNotes FROM account ".
"LEFT JOIN notes ON notes.owner = account.id ".
"WHERE notes.public != 0 AND notes.id != 0 ".
- "GROUP BY account.id ORDER BY nbNotes DESC");
+ "GROUP BY account.id ORDER BY " . get_filter("order") . " " . get_filter("way"));
while ($nn = mysql_fetch_assoc($n)) $users[] = $nn;
require("tpl/notes/index.php");
diff --git a/lib/study/deck.php b/lib/study/deck.php
new file mode 100644
index 0000000..d7f8e9f
--- /dev/null
+++ b/lib/study/deck.php
@@ -0,0 +1,5 @@
+<?php
+
+$title = "olol";
+$message = 'Placeholder. Go to <a href="deck">study decks</a>.';
+require("tpl/general/empty.php");
diff --git a/lib/study/deckadd.php b/lib/study/deckadd.php
new file mode 100644
index 0000000..d7f8e9f
--- /dev/null
+++ b/lib/study/deckadd.php
@@ -0,0 +1,5 @@
+<?php
+
+$title = "olol";
+$message = 'Placeholder. Go to <a href="deck">study decks</a>.';
+require("tpl/general/empty.php");
diff --git a/lib/study/index.php b/lib/study/index.php
new file mode 100644
index 0000000..e6cec20
--- /dev/null
+++ b/lib/study/index.php
@@ -0,0 +1,3 @@
+<?php
+
+require("tpl/study/index.php");
diff --git a/schema.sql b/schema.sql
index 7ad8eeb..2058771 100644
--- a/schema.sql
+++ b/schema.sql
@@ -3,7 +3,7 @@
-- http://www.phpmyadmin.net
--
-- Client: localhost
--- Généré le : Sam 17 Septembre 2011 à 16:45
+-- Généré le : Sam 17 Septembre 2011 à 19:36
-- Version du serveur: 5.5.15
-- Version de PHP: 5.3.8
@@ -33,7 +33,41 @@ CREATE TABLE IF NOT EXISTS `account` (
`priv` int(11) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`),
UNIQUE KEY `login` (`login`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;
+
+-- --------------------------------------------------------
+
+--
+-- Structure de la table `cards`
+--
+
+CREATE TABLE IF NOT EXISTS `cards` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `deck` int(11) NOT NULL,
+ `number` int(11) NOT NULL,
+ `name` varchar(255) NOT NULL,
+ `text_md` text NOT NULL,
+ `text_html` text NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `unique_name` (`deck`,`name`),
+ UNIQUE KEY `unique_number` (`deck`,`number`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
+
+-- --------------------------------------------------------
+
+--
+-- Structure de la table `decks`
+--
+
+CREATE TABLE IF NOT EXISTS `decks` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `owner` int(11) NOT NULL,
+ `name` varchar(255) NOT NULL,
+ `comment_md` text NOT NULL,
+ `comment_html` text NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `unique_name` (`owner`,`name`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
-- --------------------------------------------------------
@@ -65,4 +99,4 @@ CREATE TABLE IF NOT EXISTS `notes` (
`public` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
KEY `owner` (`owner`,`parent`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=32 ;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=34 ;
diff --git a/tpl/deck/ef.php b/tpl/deck/ef.php
new file mode 100644
index 0000000..40d0ecc
--- /dev/null
+++ b/tpl/deck/ef.php
@@ -0,0 +1,16 @@
+
+<?php
+require("tpl/general/top.php");
+
+if (isset($fields))
+ require("tpl/general/inc_form.php");
+
+echo '</div><div class="contents-left">';
+
+echo '<h1>' . $deck['name'] . '</h1>';
+echo '<ul><li><a href="view-deck-' . $deck['id'] . '">Back to deck</a></li>';
+echo '<li><a href="edit-deck-' . $deck['id'] . '">Edit deck</a></li>';
+echo '<li><a href="addent-deck-' . $deck['id'] . '">Add card to deck</a></li>';
+echo '</ul>';
+
+require("tpl/general/bottom.php");
diff --git a/tpl/deck/index.php b/tpl/deck/index.php
new file mode 100644
index 0000000..b8e9a76
--- /dev/null
+++ b/tpl/deck/index.php
@@ -0,0 +1,20 @@
+<?php
+
+$title = "Study decks";
+
+if ($user['id'] == 0) $message = "Hey, you should create an account so that you can study with us!";
+
+require("tpl/general/top.php");
+
+echo '<div class="ordering_links">' . filters_html_full() . '</div>';
+
+echo "<table><tr><th>Name</th><th>Users</th>";
+foreach ($decks as $deck) {
+ echo '<tr><td><code>' . $deck["owner"] . ':<a href="view-deck-' . $deck['id'] . '">' . $deck["name"] . '</a></code></td>';
+ echo '<td>' . $deck["nbUsers"] . '</td></tr>';
+}
+echo "</table>";
+
+require("tpl/study/lib_sidebar.php");
+
+require("tpl/general/bottom.php");
diff --git a/tpl/deck/new.php b/tpl/deck/new.php
new file mode 100644
index 0000000..1f7e81e
--- /dev/null
+++ b/tpl/deck/new.php
@@ -0,0 +1,8 @@
+<?php
+require("tpl/general/top.php");
+
+require("tpl/general/inc_form.php");
+
+require("tpl/study/lib_sidebar.php");
+
+require("tpl/general/bottom.php");
diff --git a/tpl/deck/view.php b/tpl/deck/view.php
new file mode 100644
index 0000000..f54da3d
--- /dev/null
+++ b/tpl/deck/view.php
@@ -0,0 +1,33 @@
+<?php
+
+$title = $deck["owner"] . ':' . $deck["name"];
+
+require("tpl/general/top.php");
+
+if ($can_edit) {
+ echo '<div class="small_right"><a href="edit-deck-' . $deck['id'] . '">edit</a> | ';
+ echo '<a href="addent-deck-' . $deck['id'] . '">add card</a></div>';
+}
+
+echo '<h3>Description</h3>';
+echo $deck["comment"];
+
+echo '<h3>Cards</h3>';
+echo '<div class="ordering_links">' . filters_html_full() . '</div>';
+foreach ($cards as $card) {
+ echo '<div class="study_card">';
+ if ($can_edit) {
+ echo '<div class="small_right"><a href="edent-deck-' . $card['id'] . '">edit</a> | <a href="rment-deck-' . $card['id'] . '">remove</a> | ';
+ echo '<a href="#" onclick="if (pos = prompt(\'What position do you want to move this card to ?\', ' . $card['number'] . ')) { window.location = \'mvent-deck-' . $card['id'] . '-\' + pos; }">move</a>';
+ echo '</div>';
+ }
+ echo '<code>#' . $card["number"] . ": " . $card["name"] . '</code>';
+ echo '<br />' . $card['text'];
+ echo '</div>';
+}
+if ($can_edit)
+ echo '<a class="tool_link" href="addent-deck-' . $deck['id'] . '">[+] add card</a>';
+
+require("tpl/study/lib_sidebar.php");
+
+require("tpl/general/bottom.php");
diff --git a/tpl/general/top.php b/tpl/general/top.php
index e87e466..28a9658 100644
--- a/tpl/general/top.php
+++ b/tpl/general/top.php
@@ -24,9 +24,12 @@ if ($user['id'] == 0) {
<a href="notes">Notebooks</a>
<?php
if ($user['id'] != 0) {
- echo '<a href="image">Uploaded images</a>';
-} elseif ($user['priv'] >= $apps['image']['upload']) {
- echo '<a href="upload-image">Upload image</a>';
+ echo '<a href="image">Uploaded images</a><a href="study">My studies</a>';
+} else {
+ if ($user['priv'] >= $apps['image']['upload']) {
+ echo '<a href="upload-image">Upload image</a>';
+ }
+ echo '<a href="deck">Study decks</a>';
}
?>
</div>
diff --git a/tpl/notes/index.php b/tpl/notes/index.php
index 1be4cd5..6c0eb99 100644
--- a/tpl/notes/index.php
+++ b/tpl/notes/index.php
@@ -2,6 +2,8 @@
$title = "User's notebooks";
require("tpl/general/top.php");
+echo '<div class="ordering_links">' . filters_html_full() . '</div>';
+
echo "<ul>";
foreach($users as $u) {
echo '<li><a href="user-notes-' . $u['id'] . '">' . $u['name'] . '</a> (' . $u['nbNotes'] . ' notes)</li>';
diff --git a/tpl/study/index.php b/tpl/study/index.php
new file mode 100644
index 0000000..26ecd6d
--- /dev/null
+++ b/tpl/study/index.php
@@ -0,0 +1,16 @@
+<?php
+
+$title = "My studies";
+require("tpl/general/top.php");
+
+?>
+
+<p>Welcome to the <em>My studies section</em>. This is a simple study program based on
+decks of cards, keeping track of your progress and everything.</p>
+
+<p>Please take a look in the <a href="deck">List of decks</a> and look at whatever you want to learn.</p>
+
+<?php
+
+require ("lib_sidebar.php");
+require("tpl/general/bottom.php");
diff --git a/tpl/study/lib_sidebar.php b/tpl/study/lib_sidebar.php
new file mode 100644
index 0000000..61bb11a
--- /dev/null
+++ b/tpl/study/lib_sidebar.php
@@ -0,0 +1,18 @@
+<?php
+
+if ($user['id'] != 0) {
+ $my_decks = array();
+ $d = sql("SELECT id, name FROM decks WHERE owner = " . $user['id']);
+ while ($dd = mysql_fetch_assoc($d)) $my_decks[] = $dd;
+
+ echo '</div><div class="contents-left">';
+ echo '<h1>Studying decks</h1><ul>';
+ //LIST
+ echo '<li><a class="tool_link" href="deck">[+] Show all decks</a></li></ul>';
+
+ echo '<h1>My decks</h1><ul>';
+ foreach($my_decks as $deck) {
+ echo '<li><a href="view-deck-' . $deck['id'] . '">' . $deck['name'] . '</a></li>';
+ }
+ echo '<li><a class="tool_link" href="new-deck">[+] Create deck</a></li></ul>';
+}