From 029b21bf5464e52af159920cfb00dcedeb189e3b Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 20 Jul 2011 13:34:16 -0400 Subject: [PATCH] First implementation of sharing user interface --- apps/files_sharing/admin.php | 2 +- apps/files_sharing/ajax/share.php | 12 +++++++ apps/files_sharing/ajax/unshare.php | 12 +++++++ apps/files_sharing/appinfo/app.php | 4 +-- apps/files_sharing/js/list.js | 50 ++++++++++++++++++++++++++ apps/files_sharing/lib_share.php | 26 +++++++------- apps/files_sharing/list.php | 40 +++++++++++++++++++++ apps/files_sharing/templates/admin.php | 30 ---------------- apps/files_sharing/templates/list.php | 32 +++++++++++++++++ 9 files changed, 163 insertions(+), 45 deletions(-) create mode 100644 apps/files_sharing/ajax/share.php create mode 100644 apps/files_sharing/ajax/unshare.php create mode 100644 apps/files_sharing/js/list.js create mode 100644 apps/files_sharing/list.php delete mode 100644 apps/files_sharing/templates/admin.php create mode 100644 apps/files_sharing/templates/list.php diff --git a/apps/files_sharing/admin.php b/apps/files_sharing/admin.php index 0bb45731b2..9a583800ae 100644 --- a/apps/files_sharing/admin.php +++ b/apps/files_sharing/admin.php @@ -32,7 +32,7 @@ if (!OC_USER::isLoggedIn()){ OC_APP::setActiveNavigationEntry( "files_sharing_administration" ); $tmpl = new OC_TEMPLATE( "files_sharing", "admin", "admin" ); -$tmpl->assign( 'shared_items', OC_SHARE::getSharedItems()); +$tmpl->assign( 'shared_items', OC_SHARE::getMySharedItems()); $tmpl->printPage(); ?> \ No newline at end of file diff --git a/apps/files_sharing/ajax/share.php b/apps/files_sharing/ajax/share.php new file mode 100644 index 0000000000..7007d26f8b --- /dev/null +++ b/apps/files_sharing/ajax/share.php @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/apps/files_sharing/ajax/unshare.php b/apps/files_sharing/ajax/unshare.php new file mode 100644 index 0000000000..3207a972c9 --- /dev/null +++ b/apps/files_sharing/ajax/unshare.php @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index 3b4b16e484..b73f7d52e6 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -2,9 +2,9 @@ require_once('apps/files_sharing/lib_share.php'); -OC_APP::addSettingsPage( array( "id" => "files_sharing_administration", +OC_APP::addNavigationEntry( array( "id" => "files_sharing_list", "order" => 10, - "href" => OC_HELPER::linkTo( "files_sharing", "admin.php" ), + "href" => OC_HELPER::linkTo( "files_sharing", "list.php" ), "name" => "Share", "icon" => OC_HELPER::imagePath( "files_sharing", "share.png" ))); diff --git a/apps/files_sharing/js/list.js b/apps/files_sharing/js/list.js new file mode 100644 index 0000000000..5e91d57410 --- /dev/null +++ b/apps/files_sharing/js/list.js @@ -0,0 +1,50 @@ +$(document).ready(function() { + $( "#source" ).autocomplete({ + source: "../../files/ajax/autocomplete.php", + minLength: 1 + }); + $("button.delete").live('click', function( event ) { + event.preventDefault(); +// var row=$(this); + var source=$(this).attr('data-source'); + var uid_shared_with=$(this).attr('data-uid_shared_with'); + var data='source='+encodeURIComponent(source)+'&uid_shared_with='+encodeURIComponent(uid_shared_with); + $.ajax({ + type: 'GET', + url: 'ajax/unshare.php', + cache: false, + data: data +// success: function(){ +// row.remove(); +// } + }); + }); + $('#share_item').submit(function( event ){ + event.preventDefault(); + var source=$('#source').val(); + var uid_shared_with=$('#uid_shared_with').val(); + var permissions=$('#permissions').val()||0; + var data='source='+source+'&uid_shared_with='+uid_shared_with+'&permissions='+permissions; + $.ajax({ + type: 'GET', + url: 'ajax/share.php', + cache: false, + data: data, +// success: function(token){ +// if(token){ +// var html=""; +// html+=""+path+""; +// var expire=($('#expire').val())?$('#expire').val():'Never' +// html+=""+expire+"" +// html+=""+$('#baseUrl').val()+"?token="+token+"" +// html+="" +// html+="" +// $(html).insertBefore($('#newlink_row')); +// $('#expire').val(''); +// $('#expire_time').val(''); +// $('#path').val(''); +// } +// } + }); + }); +}); \ No newline at end of file diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 83e5486ddf..5b685ea390 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -36,6 +36,7 @@ class OC_SHARE { */ public function __construct($source, $uid_shared_with, $permissions, $public = false) { if ($source && OC_FILESYSTEM::file_exists($source) && OC_FILESYSTEM::is_readable($source)) { + $source = "/".$_SESSION['user_id']."/files".$source; $uid_owner = $_SESSION['user_id']; if ($public) { // TODO create token for public file @@ -43,18 +44,19 @@ class OC_SHARE { } else { $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"); foreach ($uid_shared_with as $uid) { - $target = "/".$uid."/files/Share".$source; - $check = OC_DB::prepare("SELECT COUNT(target) FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?"); - $result = $check->execute(array($target, $uid))->fetchAll(); - $counter = 1; - while (count($result > 0)) { - if ($pos = strrpos($target, ".")) { - $target = substr($target, 0, $pos)."_".$counter.substr($target, $pos); - } else { - $target .= $counter; - } - $result = $check->execute(array($target, $uid))->fetchAll(); - } + $target = "/".$uid."/files/Share/".basename($source); + // TODO Fix check if target already exists +// $check = OC_DB::prepare("SELECT target FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?"); +// $result = $check->execute(array($target, $uid))->fetchAll(); +// $counter = 1; +// while (count($result > 0)) { +// if ($pos = strrpos($target, ".")) { +// $target = substr($target, 0, $pos)."_".$counter.substr($target, $pos); +// } else { +// $target .= $counter; +// } +// $result = $check->execute(array($target, $uid))->fetchAll(); +// } $query->execute(array($uid_owner, $uid, $source, $target, $permissions)); } } diff --git a/apps/files_sharing/list.php b/apps/files_sharing/list.php new file mode 100644 index 0000000000..6c27899369 --- /dev/null +++ b/apps/files_sharing/list.php @@ -0,0 +1,40 @@ +. + * + */ + +require_once('../../lib/base.php'); +require_once('lib_share.php'); +require('template.php'); + +if (!OC_USER::isLoggedIn()){ + header( "Location: ".OC_HELPER::linkTo( "index.php" )); + exit(); +} + +OC_APP::setActiveNavigationEntry("files_sharing_list"); + +OC_UTIL::addScript("files_sharing", "list"); + +$tmpl = new OC_TEMPLATE("files_sharing", "list", "user"); +$tmpl->assign("shared_items", OC_SHARE::getMySharedItems()); +$tmpl->printPage(); + +?> \ No newline at end of file diff --git a/apps/files_sharing/templates/admin.php b/apps/files_sharing/templates/admin.php deleted file mode 100644 index 827b64143c..0000000000 --- a/apps/files_sharing/templates/admin.php +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - '> - - - - - - - - - - - - - - - - -
ItemShared WithPermissions
- \ No newline at end of file diff --git a/apps/files_sharing/templates/list.php b/apps/files_sharing/templates/list.php new file mode 100644 index 0000000000..244cd9992c --- /dev/null +++ b/apps/files_sharing/templates/list.php @@ -0,0 +1,32 @@ +
+ Your Shared Files + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ItemShared WithPermissions
+ +