summaryrefslogtreecommitdiff
path: root/lib/file/editfld.php
blob: db5a3043c533f5e4392de1c13e48339ea4998d8c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php

require("lib/markdown.php");

assert_redir(count($args) == 3, 'file');
$fldid = intval($args[2]);

$fld = mysql_fetch_assoc(sql(
	"SELECT id, name, comment, public, owner ".
	"FROM folders WHERE id = $fldid"
	));
assert_error($fld && $fld['owner'] == $user['id'],
	"This folder does not exist, or you are not allowed to edit it.");

$fld_name = $fld['name'];
$fld_comment = $fld['comment'];
$fld_public = $fld['public'];
if (isset($_POST['name']) && isset($_POST['comment'])) {
	$fld_public = isset($_POST['public']);
	$fld_name = esca($_POST['name']);
	$fld_comment = esca($_POST['comment']);
	$fld_comment_html = Markdown($fld_comment);
	if ($fld_name == "") {
		$error = "You must enter a name for your folder.";
	} else {
		sql("UPDATE folders SET name = '" . escs($fld_name) . "', comment = '" . escs($fld_comment) .
			"', comment_html = '" . escs($fld_comment_html) . "', public = " . ($fld_public?'1':'0') .
			" WHERE id = $fldid");
		header("Location: folder-file-" . $fldid);
		die();
	}
	
}

$title = "Edit folder";
$fields = array(
	array("label" => "Folder name : ", "name" => "name", "value" => $fld_name),
	array("label" => "Public ? ", "name" => "public", "type" => "checkbox", "checked" => $fld_public),
	array("label" => "Comment : ", "name" => "comment", "type" => "textarea", "value" => $fld_comment),
	);
$validate = "Save";

require("tpl/general/form.php");