summaryrefslogblamecommitdiff
path: root/lib/notes/new.php
blob: adad01502868dd8f517e5d439d025fe76ba72a19 (plain) (tree)
1
2
3
4
5
6
7
8
9







                                         
                      



                                                                                                                        
                   















                                                                                             



                                                                               













                                                                                                           
<?php

require("lib/markdown.php");

assert_redir(count($args) == 3, 'notes');
$parentid = intval($args[2]);

if ($parentid != 0) {
	$parent = sql(
		"SELECT na.id AS id, na.title AS title, na.text_html AS html, na.public AS public, na.owner AS owner, ".
		"nb.title AS parent_title, nb.id AS parent_id, account.login AS ownername FROM notes na ".
		"LEFT JOIN notes nb ON na.parent = nb.id LEFT JOIN account ON account.id = na.owner ".
		"WHERE na.id = $parentid"
	)->fetch();
	assert_error($parent && $parent['owner'] == $user['id'],
		"The selected parent does not exist, or you cannot create children for it.");
}

$note_title = "";
$note_text = "";
$note_public = (isset($parent) ? $parent['public'] : true);
if (isset($_POST['title']) && isset($_POST['text'])) {
	$note_title = esca($_POST['title']);
	$note_text = esca($_POST['text']);
	$note_html = Markdown($note_text);
	$note_public = isset($_POST['public']);
	if ($note_title == "") {
		$error = "You must enter a title for your note";
	} else {
		sql("INSERT INTO notes(owner, parent, title, text, text_html, public) ".
			"VALUES(?, ?, ?, ?, ?, ". ($note_public?'1':'0') . ")",
				$user['id'], $parentid, escs($note_title),
				escs($note_text), escs($note_html));
		header("Location: view-notes-" . $sql_conn->lastInsertId());
		die();
	}
}


$title = "New note";
$fields = array(
	array("label" => "Title : ", "name" => "title", "value" => $note_title),
	array("label" => "Public ? ", "name" => "public", "type" => "checkbox", "checked" => $note_public),
	array("label" => "Text : ", "name" => "text", "type" => "textarea", "value" => $note_text),
	);
$validate = "Create note";

require("tpl/notes/new.php");