Add support for sharing multiple files from share dialog, move loops outside of OC_SHARE
This commit is contained in:
parent
d36850f0f2
commit
31a067b5a3
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -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);
|
||||
|
||||
?>
|
|
@ -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',
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue