summaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/ajax/undelete.php
blob: 05b5e7a5ee4885425d3ee8db58b7778f17489cea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php 

if(!OC_User::isLoggedIn()) {
	exit;
}

$files = $_REQUEST['files'];
$list = explode(';', $files);

$error = array();

$i = 0;
foreach ($list as $file) {
	$delimiter = strrpos($file, '.d');
	$filename = substr($file, 0, $delimiter);
	$timestamp =  substr($file, $delimiter+2);
	
	if ( !OCA_Trash\Trashbin::restore($filename, $timestamp) ) {
		$error[] = $filename;
	} else {
		$success[$i]['filename'] = $filename;
		$success[$i]['timestamp'] = $timestamp;
		$i++;
	}

}

if ( $error ) {
	$filelist = '';
	foreach ( $error as $e ) {
		$filelist .= $e.', ';
	}
	OCP\JSON::error(array("data" => array("message" => "Couldn't restore ".rtrim($filelist,', '), "success" => $success, "error" => $error)));
} else {
	OCP\JSON::success(array("data" => array("success" => $success)));
}