diff options
author | Michael Gapczynski <GapczynskiM@gmail.com> | 2011-07-28 15:31:52 -0400 |
---|---|---|
committer | Michael Gapczynski <GapczynskiM@gmail.com> | 2011-07-28 15:31:52 -0400 |
commit | 31a067b5a39ee9132054d9e5338ad6d745136a3b (patch) | |
tree | a6593082a21bad436d36f62414665bd44e587e82 | |
parent | d36850f0f2b507b566e57de3befb3fb8e2dd5c5a (diff) | |
download | nextcloud-server-31a067b5a39ee9132054d9e5338ad6d745136a3b.tar.gz nextcloud-server-31a067b5a39ee9132054d9e5338ad6d745136a3b.zip |
Add support for sharing multiple files from share dialog, move loops outside of OC_SHARE
-rw-r--r-- | apps/files_sharing/ajax/share.php | 10 | ||||
-rw-r--r-- | apps/files_sharing/ajax/unshare.php | 2 | ||||
-rw-r--r-- | apps/files_sharing/js/share.js | 11 | ||||
-rw-r--r-- | apps/files_sharing/lib_share.php | 48 |
4 files changed, 37 insertions, 34 deletions
diff --git a/apps/files_sharing/ajax/share.php b/apps/files_sharing/ajax/share.php index 7007d26f8be..b2c3a477958 100644 --- a/apps/files_sharing/ajax/share.php +++ b/apps/files_sharing/ajax/share.php @@ -4,9 +4,13 @@ $RUNTIME_NOAPPS = true; require_once('../../../lib/base.php'); require_once('../lib_share.php'); -$source = $_GET['source']; -$uid_shared_with = array($_GET['uid_shared_with']); +$sources = $_GET['sources']; +$uid_shared_with = $_GET['uid_shared_with']; $permissions = $_GET['permissions']; -new OC_SHARE($source, $uid_shared_with, $permissions); +foreach ($sources as $source) { + foreach ($uid_shared_with as $uid) { + new OC_SHARE($source, $uid, $permissions); + } +} ?>
\ No newline at end of file diff --git a/apps/files_sharing/ajax/unshare.php b/apps/files_sharing/ajax/unshare.php index d70cf44c3eb..4d83d332257 100644 --- a/apps/files_sharing/ajax/unshare.php +++ b/apps/files_sharing/ajax/unshare.php @@ -5,7 +5,7 @@ require_once('../../../lib/base.php'); require_once('../lib_share.php'); $source = $_GET['source']; -$uid_shared_with = array($_GET['uid_shared_with']); +$uid_shared_with = $_GET['uid_shared_with']; OC_SHARE::unshare($source, $uid_shared_with); ?>
\ No newline at end of file diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index c77c2aa77db..32926c6811e 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -11,7 +11,7 @@ $(document).ready(function() { html += "<br />"; html += "<a id='toggle-private-advanced'>Advanced</a>"; html += "<br />"; - html += "<div id='private-advanced' style='display: none'>"; + html += "<div id='private-advanced' style='display: none; text-align: left'>"; html += "<label><input type='checkbox' name='share_permissions' value='read' checked='checked' disabled='disable' /> Read</label><br />"; html += "<label><input type='checkbox' name='share_permissions' value='write' /> Write</label><br />"; html += "<label><input type='checkbox' name='share_permissions' value='rename' /> Rename</label><br />"; @@ -72,10 +72,15 @@ $(document).ready(function() { // TODO Construct public link } else { // TODO Check all inputs are valid - var source = $('#dir').val()+"/"+getSelectedFiles('name'); + var sources = ""; + var files = getSelectedFiles('name'); + var length = files.length; + for (var i = 0; i < length; i++) { + sources += "&sources[]=" + $('#dir').val() + "/" + files[i]; + } var uid_shared_with = $('.uid_shared_with').val(); var permissions = 0; - var data = 'source='+source+'&uid_shared_with='+uid_shared_with+'&permissions='+permissions; + var data = sources+'&uid_shared_with[]='+uid_shared_with+'&permissions='+permissions; $.ajax({ type: 'GET', url: '../apps/files_sharing/ajax/share.php', diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 44babc73a76..c0e940754ec 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -43,29 +43,27 @@ class OC_SHARE { $token = sha1("$uid_owner-$item"); } else { $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"); - foreach ($uid_shared_with as $uid) { - $target = "/".$uid."/files/Share/".basename($source); - $check = OC_DB::prepare("SELECT target FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?"); - $result = $check->execute(array($target, $uid))->fetchAll(); - // Check if target already exists for the user, if it does append a number to the name - if (count($result) > 0) { - if ($pos = strrpos($target, ".")) { - $name = substr($target, 0, $pos); - $ext = substr($target, $pos); - } else { - $name = $target; - $ext = ""; - } - $counter = 1; - while (count($result) > 0) { - $newTarget = $name."_".$counter.$ext; - $result = $check->execute(array($newTarget, $uid))->fetchAll(); - $counter++; - } - $target = $newTarget; + $target = "/".$uid_shared_with."/files/Share/".basename($source); + $check = OC_DB::prepare("SELECT target FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?"); + $result = $check->execute(array($target, $uid_shared_with))->fetchAll(); + // Check if target already exists for the user, if it does append a number to the name + if (count($result) > 0) { + if ($pos = strrpos($target, ".")) { + $name = substr($target, 0, $pos); + $ext = substr($target, $pos); + } else { + $name = $target; + $ext = ""; } - $query->execute(array($uid_owner, $uid, $source, $target, $permissions)); + $counter = 1; + while (count($result) > 0) { + $newTarget = $name."_".$counter.$ext; + $result = $check->execute(array($newTarget, $uid_shared_with))->fetchAll(); + $counter++; + } + $target = $newTarget; } + $query->execute(array($uid_owner, $uid_shared_with, $source, $target, $permissions)); } } } @@ -232,9 +230,7 @@ class OC_SHARE { */ public static function setIsWriteable($source, $uid_shared_with, $is_writeable) { $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET is_writeable = ? WHERE SUBSTR(source, 1, ?) = ? AND uid_shared_with = ? AND uid_owner = ?"); - foreach ($uid_shared_with as $uid) { - $query->execute(array($is_writeable, strlen($source), $source, $uid_shared_with, OC_USER::getUser())); - } + $query->execute(array($is_writeable, strlen($source), $source, $uid_shared_with, OC_USER::getUser())); } /** @@ -247,9 +243,7 @@ class OC_SHARE { */ public static function unshare($source, $uid_shared_with) { $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? AND uid_shared_with = ? AND uid_owner = ?"); - foreach ($uid_shared_with as $uid) { - $query->execute(array(strlen($source), $source, $uid, OC_USER::getUser())); - } + $query->execute(array(strlen($source), $source, $uid_shared_with, OC_USER::getUser())); } /** |