summaryrefslogtreecommitdiff
path: root/tpl
diff options
context:
space:
mode:
authorNicolas BERNSTEIN <alexis211@gmail.com>2011-09-17 16:48:29 +0200
committerNicolas BERNSTEIN <alexis211@gmail.com>2011-09-17 16:48:29 +0200
commitd0060968b77c39bdf8abffb071c971c166b59edb (patch)
tree0be52e00a25bd298235a0cf916fb07496d3ab95f /tpl
downloadBits-d0060968b77c39bdf8abffb071c971c166b59edb.tar.gz
Bits-d0060968b77c39bdf8abffb071c971c166b59edb.zip
First commit.
Diffstat (limited to 'tpl')
-rw-r--r--tpl/account/login.php10
-rw-r--r--tpl/general/bottom.php4
-rw-r--r--tpl/general/choice.php6
-rw-r--r--tpl/general/empty.php3
-rw-r--r--tpl/general/form.php6
-rw-r--r--tpl/general/inc_form.php26
-rw-r--r--tpl/general/inc_tree.php18
-rw-r--r--tpl/general/sqlerror.php13
-rw-r--r--tpl/general/top.php43
-rw-r--r--tpl/image/index.php34
-rw-r--r--tpl/image/upload-ok.php12
-rw-r--r--tpl/image/upload.php15
-rw-r--r--tpl/notes/edit.php17
-rw-r--r--tpl/notes/inc_relativestree.php139
-rw-r--r--tpl/notes/index.php11
-rw-r--r--tpl/notes/move.php16
-rw-r--r--tpl/notes/new.php18
-rw-r--r--tpl/notes/user.php27
-rw-r--r--tpl/notes/view.php18
19 files changed, 436 insertions, 0 deletions
diff --git a/tpl/account/login.php b/tpl/account/login.php
new file mode 100644
index 0000000..7853186
--- /dev/null
+++ b/tpl/account/login.php
@@ -0,0 +1,10 @@
+<?php
+$title = "Login";
+
+$form_message = "Please log in with your account :";
+$fields = array(
+ array ("label" => "Username : ", "name" => "login", "value" => (isset($login) ? $login : '')),
+ array ("label" => "Password : ", "name" => "pw", "type" => "password"));
+$validate = "Log in";
+
+require("tpl/general/form.php");
diff --git a/tpl/general/bottom.php b/tpl/general/bottom.php
new file mode 100644
index 0000000..b506bf0
--- /dev/null
+++ b/tpl/general/bottom.php
@@ -0,0 +1,4 @@
+ </div>
+ </body>
+</html>
+<?php die(); ?>
diff --git a/tpl/general/choice.php b/tpl/general/choice.php
new file mode 100644
index 0000000..3d54dce
--- /dev/null
+++ b/tpl/general/choice.php
@@ -0,0 +1,6 @@
+<?php
+require("top.php");
+foreach ($choice as $c => $u) {
+ echo '<button onclick="window.location=\'' . $u . '\'">' . $c . '</button>';
+}
+require("bottom.php");
diff --git a/tpl/general/empty.php b/tpl/general/empty.php
new file mode 100644
index 0000000..48b662b
--- /dev/null
+++ b/tpl/general/empty.php
@@ -0,0 +1,3 @@
+<?php
+require("top.php");
+require("bottom.php");
diff --git a/tpl/general/form.php b/tpl/general/form.php
new file mode 100644
index 0000000..1d21b8c
--- /dev/null
+++ b/tpl/general/form.php
@@ -0,0 +1,6 @@
+<?php
+require("top.php");
+
+require("inc_form.php");
+
+require("bottom.php");
diff --git a/tpl/general/inc_form.php b/tpl/general/inc_form.php
new file mode 100644
index 0000000..8cd2ad5
--- /dev/null
+++ b/tpl/general/inc_form.php
@@ -0,0 +1,26 @@
+<?php
+
+
+if (!isset($method)) $method = "POST";
+if (!isset($validate)) $validate = "Post";
+if (!isset($action)) $action = "index.php?p=$url";
+
+echo '<form method="' . $method . '" action="' . $action . '"' .
+ (isset($need_file) ? ' enctype="multipart/form-data"' : '') . '>';
+if (isset($form_message)) echo '<strong>' . $form_message . "</strong><br /><br />\n";
+
+foreach($fields as $f) {
+ if (isset($f['type']) && $f['type'] == 'textarea') {
+ echo '<label>' . $f['label'] . '</label><br />';
+ echo '<textarea name="' . $f['name'] . '">' . $f['value'] . '</textarea><br />';
+ } else {
+?>
+<label for="ff_<?php echo $f['name']; ?>"><?php echo $f['label']; ?></label>
+<input type="<?php echo (isset($f['type']) ? $f['type'] : 'text'); ?>" name="<?php echo $f['name']; ?>" <?php
+if (isset($f['value'])) echo ' value="' . $f['value'] . '"' ;
+if (isset($f['checked']) && $f['checked'] == true) echo ' checked="checked"';
+?> id="ff_<?php echo $f['name']; ?>"/><br /><?php
+ }
+}
+
+echo '<div class="empty_label">&nbsp;</div><input type="submit" value="' . $validate . '" /></form>';
diff --git a/tpl/general/inc_tree.php b/tpl/general/inc_tree.php
new file mode 100644
index 0000000..9b13d5a
--- /dev/null
+++ b/tpl/general/inc_tree.php
@@ -0,0 +1,18 @@
+<?php
+function tree_branch($tree, $id, $func) {
+ if (!isset($tree[$id])) return;
+ foreach($tree[$id] as $branch) {
+ echo '<p>'.$func($branch).'</p>';
+ if (isset($tree[$branch['id']])) {
+ echo '<div class="tree_branch">';
+ tree_branch($tree, $branch['id'], $func);
+ echo '</div>';
+ }
+ }
+}
+
+function tree($tree, $func) {
+ echo '<div class="tree_root">';
+ tree_branch($tree, 0, $func);
+ echo '</div>';
+}
diff --git a/tpl/general/sqlerror.php b/tpl/general/sqlerror.php
new file mode 100644
index 0000000..59f0806
--- /dev/null
+++ b/tpl/general/sqlerror.php
@@ -0,0 +1,13 @@
+<?php
+global $sql_min_priv_for_debug;
+require("top.php");
+
+if ($user['priv'] >= $sql_min_priv_for_debug) {
+ echo '<div class="error">An error happenned with the following SQL query :<br />';
+ echo '<code>' . $request . '</code><br />';
+ echo 'Mysql answered : ' . $sql_error . '</div>';
+} else {
+ echo '<div class="error">An internal error occurred, sorry.</div>';
+}
+
+require("bottom.php");
diff --git a/tpl/general/top.php b/tpl/general/top.php
new file mode 100644
index 0000000..e87e466
--- /dev/null
+++ b/tpl/general/top.php
@@ -0,0 +1,43 @@
+<?php
+global $user, $apps; //These might be hidden because this page is called from sql();
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <title><?php echo $title; ?></title>
+ <link href="design/style.css" rel="stylesheet" type="text/css" media="screen" />
+ </head>
+
+ <body>
+ <div class="menu">
+ <div class="right">
+ <?php
+if ($user['id'] == 0) {
+ echo '<a href="new-account">Register</a><a href="?login">Login</a>';
+} else {
+ echo '<a href="user-notes-' . $user['id'] . '">My notebook</a><a href="?logout">Logout (' . $user['name'] . ')</a>';
+}
+?>
+ </div>
+ <div class="left">
+ <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>';
+}
+?>
+ </div>
+ <div style="clear: both;"></div>
+ </div>
+
+ <div class="contents-right">
+
+ <h1><?php echo $title; ?></h1>
+
+<?php
+if (isset($message)) echo '<div class="message">' . $message . "</div>\n";
+if (isset($error)) echo '<div class="error">' . $error . "</div>\n";
+
diff --git a/tpl/image/index.php b/tpl/image/index.php
new file mode 100644
index 0000000..0f76abe
--- /dev/null
+++ b/tpl/image/index.php
@@ -0,0 +1,34 @@
+<?php
+require("tpl/general/top.php");
+
+echo '<h2>Images you have uploaded</h2>';
+
+if (count($images) == 0) {
+ echo '<div class="message">You have uploaded no images yet.</div>';
+} else {
+echo '<table><tr><th width="' . ($miniature_width) . 'px">Preview</th><th>Files</th></tr>';
+ foreach ($images as $img) {
+ $min = $baseurl . $img['id'] . "-min." . $img['extension'];
+ $imgf = $baseurl . $img['id'] . "." . $img['extension'];
+ echo '<tr><td><img src="' . $min . '" /></td>';
+ echo '<td><strong>Miniature:</strong> <a href="' . $min . '">' . $min . '</a><br />';
+ echo '<strong>Image:</strong> <a href="' . $imgf . '">' . $imgf . '</a>';
+ if ($can_delete) echo '<br /><a href="delete-image-' . $img['id'] . '">Delete this image</a>';
+ echo '</td>';
+ }
+ echo '</table>';
+}
+
+if ($can_upload) {
+?>
+</div>
+<div class="contents-left">
+<h1>Upload an image</h1>
+<form method="POST" action="index.php?p=upload-image" enctype="multipart/form-data">
+<strong>A <?php echo $miniature_width; ?>px preview will be created.</strong><br /><br />
+<input type="file" name="image" /><br />
+<input type="submit" value="Upload" /></form>
+<?php
+}
+
+require("tpl/general/bottom.php");
diff --git a/tpl/image/upload-ok.php b/tpl/image/upload-ok.php
new file mode 100644
index 0000000..1cd588c
--- /dev/null
+++ b/tpl/image/upload-ok.php
@@ -0,0 +1,12 @@
+<?php
+require("tpl/general/top.php");
+
+$minurl = $baseurl . $id . "-min." . $type;
+$imgurl = $baseurl . $id . "." . $type;
+
+?>
+ Preview : <a href="<?php echo $minurl; ?>"><?php echo $minurl; ?></a><br />
+ Image : <a href="<?php echo $imgurl; ?>"><?php echo $imgurl; ?></a><br />
+<?php
+
+require("tpl/general/bottom.php");
diff --git a/tpl/image/upload.php b/tpl/image/upload.php
new file mode 100644
index 0000000..6e9ee55
--- /dev/null
+++ b/tpl/image/upload.php
@@ -0,0 +1,15 @@
+<?php
+$title = "Upload an image";
+
+if ($user['id'] == 0) $message = "You should create an account so that you can track images you have uploaded.";
+
+$form_message = "A $miniature_width"."px preview will be created.";
+$need_file = true;
+$fields = array(
+ array("label" => "Image file : ", "type" => "file", "name" => "image")
+ );
+$validate = "Upload";
+
+require("tpl/general/form.php");
+
+
diff --git a/tpl/notes/edit.php b/tpl/notes/edit.php
new file mode 100644
index 0000000..7e4d88f
--- /dev/null
+++ b/tpl/notes/edit.php
@@ -0,0 +1,17 @@
+<?php
+
+require("tpl/general/top.php");
+
+echo '<div class="small_right"><a href="view-notes-' . $note['id'] . '">return to note</a></div>';
+
+require("tpl/general/inc_form.php");
+
+if (isset($preview)) {
+ echo '<hr /><h1>Preview</h1>';
+ echo' <div class="error">Warning : this is only a preview. Click the "Edit note" button above to save changes.</div>';
+ echo $preview;
+}
+
+$can_new = false;
+require("tpl/notes/inc_relativestree.php");
+require("tpl/general/bottom.php");
diff --git a/tpl/notes/inc_relativestree.php b/tpl/notes/inc_relativestree.php
new file mode 100644
index 0000000..be0e224
--- /dev/null
+++ b/tpl/notes/inc_relativestree.php
@@ -0,0 +1,139 @@
+<?php
+
+/* OLD WAY
+
+// ******* FETCH DATA
+
+if ($note['parent_id'] != 0) {
+ $brothers = array();
+ $n = sql("SELECT id, title, owner FROM notes WHERE parent = " . $note['parent_id'] . " ".
+ ($note['owner'] == $user['id'] ? "" : " AND public != 0 ").
+ "ORDER BY title ASC");
+ while ($nn = mysql_fetch_assoc($n)) $brothers[] = $nn;
+}
+$children = array();
+$n = sql("SELECT id, title, owner FROM notes WHERE parent = " . $note['id'] . " " .
+ ($note['owner'] == $user['id'] ? "" : " AND public != 0 ") .
+ "ORDER BY title ASC");
+while ($nn = mysql_fetch_assoc($n)) $children[] = $nn;
+
+$user_root_notes = array();
+$n = sql("SELECT id, title, owner FROM notes WHERE parent = 0 AND owner = " . $note['owner'] . " " .
+ ($note['owner'] == $user['id'] ? "" : " AND public != 0 ") .
+ "ORDER BY title ASC");
+while ($nn = mysql_fetch_assoc($n)) $user_root_notes[] = $nn;
+
+// ****** DISPLAY TREE
+
+echo '</div><div class="contents-left">';
+echo '<h1>' . $note['ownername'] . '</h1><br />';
+echo '<div class="small_right"><a href="user-notes-' . $note['owner'] . '">complete tree</a></div>';
+
+function list_brothers_and_children() {
+ global $brothers, $children, $note, $user, $can_new;
+ echo '<div class="tree_branch">';
+ foreach($brothers as $b) {
+ if ($b['id'] == $note['id']) {
+ echo '<p>' . $b['title'] . '</p><div class="tree_branch">';
+ foreach($children as $nn) {
+ echo '<p><a href="view-notes-' . $nn['id'] . '">' . $nn['title'] . '</a></p>';
+ }
+ if ($can_new) {
+ echo '<p><a class="tool_link" href="new-notes-' . $b['id'] . '">+ new note</a></p>';
+ }
+ echo '</div>';
+ } else {
+ echo '<p><a href="view-notes-' . $b['id'] .'">' . $b['title'] . '</a></p>';
+ }
+ }
+ if ($can_new) {
+ echo '<p><a class="tool_link" href="new-notes-' . $note['parent_id'] . '">+ new note</a></p>';
+ }
+ echo '</div>';
+}
+
+echo '<div class="tree_branch">';
+$did_show_up = false;
+foreach($user_root_notes as $n) {
+ if ($n['id'] == $note['id']) {
+ $did_show_up = true;
+ echo '<p>' . $n['title'] . '</p><div class="tree_branch">';
+ foreach($children as $nn) {
+ echo '<p><a href="view-notes-' . $nn['id'] . '">' . $nn['title'] . '</a></p>';
+ }
+ if ($can_new) {
+ echo '<p><a class="tool_link" href="new-notes-' . $note['id'] . '">+ new note</a></p>';
+ }
+ echo '</div>';
+ } else {
+ echo '<p><a href="view-notes-' . $n['id'] . '">' . $n['title'] . '</a></p>';
+ if ($n['id'] == $note['parent_id']) {
+ $did_show_up = true;
+ list_brothers_and_children();
+ }
+ }
+}
+if ($can_new) {
+ echo '<p><a class="tool_link" href="new-notes-0">+ new note</a></p>';
+}
+echo '</div>';
+
+if (!$did_show_up) {
+ echo '<br /><br />';
+ echo '<a href="view-notes-' . $note['parent_id'] . '">' . $note['parent_title'] . '</a>';
+ list_brothers_and_children();
+}
+
+*/
+
+// *** NEW WAY
+
+$notes_tree = array();
+$notes_parents = array();
+$n = sql("SELECT id, parent, title FROM notes ".
+ "WHERE owner = " . $note['owner'] .
+ ($note['owner'] == $user['id'] ? " " : " AND public != 0 ") .
+ "ORDER BY title ASC");
+while ($nn = mysql_fetch_assoc($n)) {
+ $notes_parents[$nn['id']] = $nn['parent'];
+ if (isset($notes_tree[$nn['parent']])) {
+ $notes_tree[$nn['parent']][] = $nn;
+ } else {
+ $notes_tree[$nn['parent']] = array($nn);
+ }
+}
+
+$notest = array(0 => @$notes_tree[0]);
+for($id = $note['id']; $id != 0; $id = $notes_parents[$id]) {
+ $notest[$id] = @$notes_tree[$id];
+}
+
+echo '</div><div class="contents-left">';
+echo '<h1>' . $note['ownername'] . '</h1><br />';
+echo '<div class="small_right"><a href="user-notes-' . $note['owner'] . '">complete tree</a></div>';
+
+function n_tree_branch($id) {
+ global $notest, $note, $can_new;
+ if (!isset($notest[$id])) return;
+ foreach($notest[$id] as $branch) {
+ if ($branch['id'] == $note['id'])
+ echo '<p>' . $branch['title'] . '</p>';
+ else
+ echo '<p><a href="view-notes-' . $branch['id'] . '">' . $branch['title'] . '</a></p>';
+ if (isset($notest[$branch['id']])) {
+ echo '<div class="tree_branch">';
+ n_tree_branch($branch['id']);
+ echo '</div>';
+ } else if ($can_new && $branch['id'] == $note['id']) {
+ echo '<div class="tree_branch">';
+ if ($can_new) echo '<p><a class="tool_link" href="new-notes-' . $branch['id'] . '">+ new note</a></p>';
+ echo '</div>';
+ }
+ }
+ if ($can_new) echo '<p><a class="tool_link" href="new-notes-' . $id . '">+ new note</a></p>';
+}
+
+echo '<div class="tree_root">';
+n_tree_branch(0);
+echo '</div>';
+
diff --git a/tpl/notes/index.php b/tpl/notes/index.php
new file mode 100644
index 0000000..1be4cd5
--- /dev/null
+++ b/tpl/notes/index.php
@@ -0,0 +1,11 @@
+<?php
+$title = "User's notebooks";
+require("tpl/general/top.php");
+
+echo "<ul>";
+foreach($users as $u) {
+ echo '<li><a href="user-notes-' . $u['id'] . '">' . $u['name'] . '</a> (' . $u['nbNotes'] . ' notes)</li>';
+}
+echo "</ul>";
+
+require("tpl/general/bottom.php");
diff --git a/tpl/notes/move.php b/tpl/notes/move.php
new file mode 100644
index 0000000..d94e745
--- /dev/null
+++ b/tpl/notes/move.php
@@ -0,0 +1,16 @@
+<?php
+
+require("tpl/general/top.php");
+
+function f($n) {
+ global $note;
+ return $n['title'] . ' - <a class="tool_link" href="move-notes-' . $note['id'] . '-' . $n['id'] . '">move here</a>';
+}
+
+require("tpl/general/inc_tree.php");
+tree($notes_tree, @f);
+echo '<a class="tool_link" href="move-notes-'.$note['id'].'-0">move to root</a>';
+
+$can_new = false;
+require("tpl/notes/inc_relativestree.php");
+require("tpl/general/bottom.php");
diff --git a/tpl/notes/new.php b/tpl/notes/new.php
new file mode 100644
index 0000000..ca17f21
--- /dev/null
+++ b/tpl/notes/new.php
@@ -0,0 +1,18 @@
+<?php
+
+require("tpl/general/top.php");
+
+if (isset($parent)) {
+ echo '<div class="small_right"><a href="view-notes-' . $parent['id'] . '">back to ' .
+ $parent['title'] . '</a></div>';
+}
+
+require("tpl/general/inc_form.php");
+
+if (isset($parent)) {
+ $note = $parent;
+ $can_new = false;
+ require("tpl/notes/inc_relativestree.php");
+}
+
+require("tpl/general/bottom.php");
diff --git a/tpl/notes/user.php b/tpl/notes/user.php
new file mode 100644
index 0000000..4da34e9
--- /dev/null
+++ b/tpl/notes/user.php
@@ -0,0 +1,27 @@
+<?php
+$title = $note_owner['name'] . "'s notebook";
+require("tpl/general/top.php");
+
+function f($n) {
+ return '<a href="view-notes-' . $n['id'] . '">' . $n['title'] . '</a>';
+}
+
+require("tpl/general/inc_tree.php");
+tree($notes_tree, @f);
+if ($note_owner['id'] == $user['id']) {
+ echo '<a class="tool_link" href="new-notes-0">create new note</a>';
+}
+
+echo '</div><div class="contents-left">';
+echo '<h1>Other users</h1>';
+echo "<ul>";
+foreach($users as $u) {
+ if ($u['id'] == $userid) {
+ echo '<li>' . $u['name'] . ' (' . $u['nbNotes'] . ' notes)</li>';
+ } else {
+ echo '<li><a href="user-notes-' . $u['id'] . '">' . $u['name'] . '</a> (' . $u['nbNotes'] . ' notes)</li>';
+ }
+}
+echo "</ul>";
+
+require("tpl/general/bottom.php");
diff --git a/tpl/notes/view.php b/tpl/notes/view.php
new file mode 100644
index 0000000..c33e836
--- /dev/null
+++ b/tpl/notes/view.php
@@ -0,0 +1,18 @@
+<?php
+$title = $note["title"];
+require("tpl/general/top.php");
+
+$t = array();
+if ($note['parent_id'] != 0) {
+ $t[] = 'parent : <a href="view-notes-'. $note['parent_id'] . '">' . $note['parent_title'] . '</a>';
+}
+if ($can_edit) $t[] = '<a href="edit-notes-' . $note['id'] . '">edit</a>';
+$t[] = '<a href="source-notes-' . $note['id'] . '">view source</a>';
+if ($can_move) $t[] = '<a href="move-notes-' . $note['id'] . '">move</a>';
+if ($can_delete) $t[] = '<a href="delete-notes-' . $note['id'] . '">delete</a>';
+echo '<div class="small_right">' . implode(' | ', $t) . '</div>';
+echo $note['html'];
+
+require("tpl/notes/inc_relativestree.php");
+
+require("tpl/general/bottom.php");