From f042e85d412fb323e5d3bb3e70d9d4ffa00a7907 Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Thu, 3 Mar 2011 23:08:54 +0100 Subject: [PATCH] Beginning of some ajax features and an admin page for files --- files/admin.php | 39 ++++++++++++++++++++++++ files/ajax/delete.php | 27 +++++++++++++++++ files/ajax/list.php | 36 ++++++++++++++++++++++ files/ajax/rename.php | 28 +++++++++++++++++ files/download.php | 45 +++++++++++++++++++++++++++ files/settings.php | 64 +++++++++++++++++++++++++++++++++++++++ files/templates/admin.php | 19 ++++++++++++ 7 files changed, 258 insertions(+) create mode 100644 files/admin.php create mode 100644 files/ajax/delete.php create mode 100644 files/ajax/list.php create mode 100644 files/ajax/rename.php create mode 100644 files/download.php create mode 100644 files/settings.php create mode 100644 files/templates/admin.php diff --git a/files/admin.php b/files/admin.php new file mode 100644 index 0000000000..4c442c4b11 --- /dev/null +++ b/files/admin.php @@ -0,0 +1,39 @@ +. +* +*/ + + +// Init owncloud +require_once('../lib/base.php'); +oc_require( 'template.php' ); + +// Check if we are a user +if( !OC_USER::isLoggedIn() || !OC_USER::ingroup( $_SESSION['username'], 'admin' )){ + header( "Location: ".OC_HELPER::linkTo( "index.php" )); + exit(); +} + +// return template +$tmpl = new OC_TEMPLATE( "files", "admin", "admin" ); +$tmpl->printPage(); + +?> diff --git a/files/ajax/delete.php b/files/ajax/delete.php new file mode 100644 index 0000000000..113476f025 --- /dev/null +++ b/files/ajax/delete.php @@ -0,0 +1,27 @@ + "error", "data" => array( "message" => "Authentication error" ))); + exit(); +} + +// Get data +$dir = $_GET["dir"]; +$file = $_GET["file"]; + +// Delete +if( OC_FILES::delete( $dir, $file )){ + echo json_encode( array( "status" => "success", "data" => array( "dir" => $dir, "file" => $file ))); +} +else{ + echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to delete file" ))); +} + +?> diff --git a/files/ajax/list.php b/files/ajax/list.php new file mode 100644 index 0000000000..4694f84283 --- /dev/null +++ b/files/ajax/list.php @@ -0,0 +1,36 @@ + "error", "data" => array( "message" => "Authentication error" ))); + exit(); +} + +// Load the files +$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : ''; + +$files = array(); +foreach( OC_FILES::getdirectorycontent( $dir ) as $i ){ + $i["date"] = date( $CONFIG_DATEFORMAT, $i["mtime"] ); + $files[] = $i; +} + +// Make breadcrumb +$breadcrumb = array(); +$pathtohere = "/"; +foreach( explode( "/", $dir ) as $i ){ + if( $i != "" ){ + $pathtohere .= "$i/"; + $breadcrumb[] = array( "dir" => $pathtohere, "name" => $i ); + } +} + +echo json_encode( array( "status" => "success", "data" => array( "files" => $files, "breadcrumb" => $breadcrumb ))); + +?> diff --git a/files/ajax/rename.php b/files/ajax/rename.php new file mode 100644 index 0000000000..86cb7944a8 --- /dev/null +++ b/files/ajax/rename.php @@ -0,0 +1,28 @@ + "error", "data" => "Authentication error" )); + exit(); +} + +// Get data +$dir = $_GET["dir"]; +$file = $_GET["file"]; +$newname = $_GET["newname"]; + +// Delete +if( OC_FILES::move( $dir, $file, $dir, $newname )) { + echo json_encode( array( "status" => "success", "data" => array( "dir" => $dir, "file" => $file, "newname" => $newname ))); +} +else{ + echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to rename file" ))); +} + +?> diff --git a/files/download.php b/files/download.php new file mode 100644 index 0000000000..d6d39c8212 --- /dev/null +++ b/files/download.php @@ -0,0 +1,45 @@ +. +* +*/ + +// Init owncloud +require_once('../lib/base.php'); +oc_require( 'template.php' ); + +// Check if we are a user +if( !OC_USER::isLoggedIn()){ + header( "Location: ".OC_HELPER::linkTo( "index.php" )); + exit(); +} + +$filename = $_GET["file"]; + +$ftype=OC_FILESYSTEM::getMimeType( $filename ); + +header('Content-Type:'.$ftype); +header('Expires: 0'); +header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); +header('Pragma: public'); +header('Content-Length: '.OC_FILESYSTEM::filesize($filename)); + +OC_FILESYSTEM::readfile( $filename ); +?> diff --git a/files/settings.php b/files/settings.php new file mode 100644 index 0000000000..25a9f0297d --- /dev/null +++ b/files/settings.php @@ -0,0 +1,64 @@ +. +* +*/ + + +// Init owncloud +require_once('../lib/base.php'); +oc_require( 'template.php' ); + +// Check if we are a user +if( !OC_USER::isLoggedIn()){ + header( "Location: ".OC_HELPER::linkTo( "index.php" )); + exit(); +} + +// Load the files we need +OC_UTIL::addStyle( "files", "files" ); +OC_UTIL::addScript( "files", "files" ); + +// Load the files +$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : ''; + +$files = array(); +foreach( OC_FILES::getdirectorycontent( $dir ) as $i ){ + $i["date"] = date( $CONFIG_DATEFORMAT, $i["mtime"] ); + $files[] = $i; +} + +// Make breadcrumb +$breadcrumb = array(); +$pathtohere = "/"; +foreach( explode( "/", $dir ) as $i ){ + if( $i != "" ){ + $pathtohere .= "$i/"; + $breadcrumb[] = array( "dir" => $pathtohere, "name" => $i ); + } +} + +// return template +$tmpl = new OC_TEMPLATE( "files", "index", "user" ); +$tmpl->assign( "files", $files ); +$tmpl->assign( "breadcrumb", $breadcrumb ); +$tmpl->printPage(); + +?> diff --git a/files/templates/admin.php b/files/templates/admin.php new file mode 100644 index 0000000000..811b48af02 --- /dev/null +++ b/files/templates/admin.php @@ -0,0 +1,19 @@ + +

Admin

+ +
+ Allow public folders
+ + (if public is enabled)
+ separated from webdav storage
+ let the user decide
+ folder "/public" in webdav storage
+ (endif)
+ + Allow downloading shared files
+ Allow uploading in shared directory
+