From ccff9ce8d8a2818699ce4e20a310986fc95ea022 Mon Sep 17 00:00:00 2001 From: Nicolas BERNSTEIN Date: Sun, 18 Mar 2012 14:08:31 +0100 Subject: Added a way of classifying images in folders. --- lib/image/delfld.php | 16 ++++++++++++++++ lib/image/editfld.php | 44 +++++++++++++++++++++++++++++++++++++++++++ lib/image/editinfo.php | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/image/folder.php | 43 ++++++++++++++++++++++++++++++++++++++++++ lib/image/index.php | 14 ++++++++++++-- lib/image/newfld.php | 32 +++++++++++++++++++++++++++++++ lib/image/rename.php | 32 ------------------------------- 7 files changed, 198 insertions(+), 34 deletions(-) create mode 100644 lib/image/delfld.php create mode 100644 lib/image/editfld.php create mode 100644 lib/image/editinfo.php create mode 100644 lib/image/folder.php create mode 100644 lib/image/newfld.php delete mode 100644 lib/image/rename.php (limited to 'lib/image') diff --git a/lib/image/delfld.php b/lib/image/delfld.php new file mode 100644 index 0000000..a018b7a --- /dev/null +++ b/lib/image/delfld.php @@ -0,0 +1,16 @@ += 3, 'image'); +$fldid = intval($args[2]); + +$fld = mysql_fetch_assoc(sql( + "SELECT id, name, comment, public, owner ". + "FROM img_folders WHERE id = $fldid" + )); +assert_error($fld && $fld['owner'] == $user['id'], + "This folder does not exist, or you are not allowed to edit it."); + +token_validate("Do you really want to delete this folder ?", "folder-image-$fldid"); +sql("DELETE FROM img_folders WHERE id = $fldid"); +sql("UPDATE images SET folder = 0 WHERE folder = $fldid"); +header("location: image"); diff --git a/lib/image/editfld.php b/lib/image/editfld.php new file mode 100644 index 0000000..a0bef1f --- /dev/null +++ b/lib/image/editfld.php @@ -0,0 +1,44 @@ + "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"); + diff --git a/lib/image/editinfo.php b/lib/image/editinfo.php new file mode 100644 index 0000000..8223c18 --- /dev/null +++ b/lib/image/editinfo.php @@ -0,0 +1,51 @@ + "[no folder]"); +$r = sql("SELECT id, name FROM img_folders WHERE owner = " . $user['id'] . " ORDER BY name ASC"); +while ($n = mysql_fetch_array($r)) + $folders[$n['id']] = $n['name']; + +$title = "Edit image info : " . $info['name']; +$fields = array( + array("label" => "Name : ", "name" => "name", "value" => $name), + array("label" => "Folder : ", "type" => "select", "name" => "folder", "choices" => $folders, "value" => $folder), + array("label" => "Comment : ", "name" => "comment", "value" => $comment, "type" => "textarea"), +); +$validate = "Save"; + +require("tpl/general/form.php"); diff --git a/lib/image/folder.php b/lib/image/folder.php new file mode 100644 index 0000000..56166d8 --- /dev/null +++ b/lib/image/folder.php @@ -0,0 +1,43 @@ += $apps['image']['editfld'] && $user['id'] = $fld['owner']); +$is_owner = ($user['id'] == $fld['owner']); + +$filters = array ( + "order" => array ( + "name" => "title", + "upl_date" => "date uploaded", + ), + "way" => $ord_ways, +); +$fdefaults = array ( + "order" => "name", + "way" => "ASC", +); + +$title = $fld["name"]; + +$images = array(); +$files = sql("SELECT images.id AS id, images.name AS name, images.extension AS extension, images.upl_date AS upl_date, ". + "images.comment_html AS comment_html FROM images WHERE images.folder = $fldid"); +while ($img = mysql_fetch_assoc($files)) $images[] = $img; + +$s = sql("SELECT id, name FROM img_folders WHERE owner = " . $fld['owner'] . ($fld['owner'] == $user['id'] ? '' : " AND public != 0"). " ORDER BY name ASC"); +$folers = array(); +while ($f = mysql_fetch_assoc($s)) $folders[] = $f; + +require("tpl/image/folder.php"); diff --git a/lib/image/index.php b/lib/image/index.php index 59a304d..b9748dc 100644 --- a/lib/image/index.php +++ b/lib/image/index.php @@ -6,6 +6,7 @@ $filters = array ( "order" => array ( "name" => "title", "upl_date" => "date uploaded", + "folder_name" => "folder", ), "way" => $ord_ways, ); @@ -17,7 +18,10 @@ $fdefaults = array ( $title = "Image upload"; $images = array(); -$files = sql("SELECT * FROM images WHERE owner = " . $user['id'] . +$files = sql("SELECT images.id AS id, images.name AS name, images.extension AS extension, images.upl_date AS upl_date, ". + "images.comment_html AS comment_html, img_folders.id AS folder_id, img_folders.name AS folder_name ". + " FROM images LEFT JOIN img_folders ON img_folders.id = images.folder ". + "WHERE images.owner = " . $user['id'] . " ORDER BY " . get_filter('order') . " " . get_filter('way')); while ($img = mysql_fetch_assoc($files)) $images[] = $img; @@ -33,7 +37,13 @@ if ($user['priv'] < $apps['image']['upload']) { $can_upload = true; } +$folders = array(); +$r = sql("SELECT id, name FROM img_folders WHERE owner = " . $user['id'] . " ORDER BY name ASC"); +while ($f = mysql_fetch_assoc($r)) { + $folders[] = $f; +} + $can_delete = ($user['priv'] >= $apps['image']['delete'] && $user['id'] != 0); -$can_rename = ($user['priv'] >= $apps['image']['rename'] && $user['id'] != 0); +$can_rename = ($user['priv'] >= $apps['image']['editinfo'] && $user['id'] != 0); require("tpl/image/index.php"); diff --git a/lib/image/newfld.php b/lib/image/newfld.php new file mode 100644 index 0000000..63afd17 --- /dev/null +++ b/lib/image/newfld.php @@ -0,0 +1,32 @@ + "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 = "Create folder"; + +require("tpl/general/form.php"); diff --git a/lib/image/rename.php b/lib/image/rename.php deleted file mode 100644 index 0fbc442..0000000 --- a/lib/image/rename.php +++ /dev/null @@ -1,32 +0,0 @@ - "New name : ", "name" => "name", "value" => $name), -); -$validate = "Rename"; - -require("tpl/general/form.php"); -- cgit v1.2.3