summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorMichael Gapczynski <GapczynskiM@gmail.com>2011-07-20 13:34:16 -0400
committerMichael Gapczynski <GapczynskiM@gmail.com>2011-07-20 13:34:16 -0400
commit029b21bf5464e52af159920cfb00dcedeb189e3b (patch)
tree2a9ed37ea849c3f8bd0be41e16aba7e4ad357b5c /apps/files_sharing
parent61837428ba59d1c5cc4730dda7d7a12c5bbb25f8 (diff)
downloadnextcloud-server-029b21bf5464e52af159920cfb00dcedeb189e3b.tar.gz
nextcloud-server-029b21bf5464e52af159920cfb00dcedeb189e3b.zip
First implementation of sharing user interface
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/admin.php2
-rw-r--r--apps/files_sharing/ajax/share.php12
-rw-r--r--apps/files_sharing/ajax/unshare.php12
-rw-r--r--apps/files_sharing/appinfo/app.php4
-rw-r--r--apps/files_sharing/js/list.js50
-rw-r--r--apps/files_sharing/lib_share.php26
-rw-r--r--apps/files_sharing/list.php40
-rw-r--r--apps/files_sharing/templates/admin.php30
-rw-r--r--apps/files_sharing/templates/list.php32
9 files changed, 163 insertions, 45 deletions
diff --git a/apps/files_sharing/admin.php b/apps/files_sharing/admin.php
index 0bb45731b2b..9a583800ae1 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 00000000000..7007d26f8be
--- /dev/null
+++ b/apps/files_sharing/ajax/share.php
@@ -0,0 +1,12 @@
+<?php
+$RUNTIME_NOAPPS = true;
+
+require_once('../../../lib/base.php');
+require_once('../lib_share.php');
+
+$source = $_GET['source'];
+$uid_shared_with = array($_GET['uid_shared_with']);
+$permissions = $_GET['permissions'];
+new OC_SHARE($source, $uid_shared_with, $permissions);
+
+?> \ 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 00000000000..3207a972c93
--- /dev/null
+++ b/apps/files_sharing/ajax/unshare.php
@@ -0,0 +1,12 @@
+<?php
+$RUNTIME_NOAPPS = true;
+
+require_once('../../../lib/base.php');
+require_once('../lib_share.php');
+
+$source = $_GET['source'];
+$uid_shared_with = array($_GET['uid_shared_with']);
+error_log("deleteitem called".$source.$uid_shared_with);
+OC_SHARE::unshare($source, $uid_shared_with);
+
+?> \ No newline at end of file
diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php
index 3b4b16e4847..b73f7d52e60 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 00000000000..5e91d57410d
--- /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="<tr class='link' id='"+token+"'>";
+// html+="<td class='path'>"+path+"</td>";
+// var expire=($('#expire').val())?$('#expire').val():'Never'
+// html+="<td class='expire'>"+expire+"</td>"
+// html+="<td class='link'><a href='get.php?token="+token+"'>"+$('#baseUrl').val()+"?token="+token+"</a></td>"
+// html+="<td><button class='delete fancybutton' data-token='"+token+"'>Delete</button></td>"
+// html+="</tr>"
+// $(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 83e5486ddf0..5b685ea390a 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 00000000000..6c27899369d
--- /dev/null
+++ b/apps/files_sharing/list.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Michael Gapczynski
+ * @copyright 2011 Michael Gapczynski GapczynskiM@gmail.com
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+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 827b64143c5..00000000000
--- a/apps/files_sharing/templates/admin.php
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php if ($_['shared_items'] == null) {echo "You are not sharing any of your files";} else {?>
-<table id='itemlist'>
- <thead>
- <tr>
- <th>Item</th>
- <th>Shared With</th>
- <th>Permissions</th>
- </tr>
- </thead>
- <tbody>
- <?php foreach($_['shared_items'] as $item):?>
- <tr class='link' id='<?php echo $item['id'];?>'>
- <td class='item'><?php echo $item['item'];?></td>
- <td class='uid_shared_with'><?php echo $item['uid_shared_with'];?></td>
- <td class='permissions'><?php echo $item['permissions'];?></td>
- <td><button class='delete fancybutton' data-token='<?php echo $link['token'];?>'>Delete</button></td>
- </tr>
- <?php endforeach;?>
- <tr id='newlink_row'>
- <form action='#' id='newlink'>
- <input type='hidden' id='expire_time'/>
- <td class='path'><input placeholder='Item' id='path'/></td>
- <td class='expire'><input placeholder='Share With' id='expire'/></td>
- <td class='permissions'><input placeholder='Permissions' id='expire'/></td>
- <td><input type='submit' value='Share'/></td>
- </form>
- </tr>
- </tbody>
-</table>
-<?php } ?> \ 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 00000000000..244cd9992cb
--- /dev/null
+++ b/apps/files_sharing/templates/list.php
@@ -0,0 +1,32 @@
+<fieldset>
+ <legend>Your Shared Files</legend>
+ <?php if ($_['shared_items'] == null) {echo "You are not sharing any of your files";} else {?>
+ <table id='itemlist'>
+ <thead>
+ <tr>
+ <th>Item</th>
+ <th>Shared With</th>
+ <th>Permissions</th>
+ </tr>
+ </thead>
+ <tbody>
+ <?php foreach($_['shared_items'] as $item):?>
+ <tr class='item'>
+ <td class='source'><?php echo substr($item['source'], strlen("/".$_SESSION['user_id']."/files/"));?></td>
+ <td class='uid_shared_with'><?php echo $item['uid_shared_with'];?></td>
+ <td class='permissions'><?php echo $item['is_writeable'];?></td>
+ <td><button class='delete fancybutton' data-source='<?php echo $item['source'];?>' data-uid_shared_with='<?php echo $item['uid_shared_with'];?>'>Delete</button></td>
+ </tr>
+ <?php endforeach;?>
+ <tr id='share_item_row'>
+ <form action='#' id='share_item'>
+ <td class='source'><input placeholder='Item' id='source'/></td>
+ <td class='uid_shared_with'><input placeholder='Share With' id='uid_shared_with'/></td>
+ <td class='permissions'><input placeholder='Permissions' id='permissions'/></td>
+ <td><input type='submit' value='Share'/></td>
+ </form>
+ </tr>
+ </tbody>
+ </table>
+ <?php } ?>
+</fieldset>