You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.8 KiB
83 lines
2.8 KiB
![]()
10 years ago
|
<?php
|
||
|
/* For licensing terms, see /license.txt */
|
||
|
|
||
|
/**
|
||
![]()
8 years ago
|
* Responses to AJAX calls for the document upload.
|
||
![]()
10 years ago
|
*/
|
||
![]()
9 years ago
|
require_once __DIR__.'/../global.inc.php';
|
||
![]()
10 years ago
|
require_once api_get_path(SYS_CODE_PATH).'dropbox/dropbox_functions.inc.php';
|
||
|
|
||
|
$action = $_REQUEST['a'];
|
||
|
switch ($action) {
|
||
|
case 'upload_file':
|
||
|
api_protect_course_script(true);
|
||
|
// User access same as upload.php
|
||
|
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
|
||
|
|
||
|
$recipients = isset($_POST['recipients']) ? $_POST['recipients'] : '';
|
||
![]()
8 years ago
|
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
|
||
![]()
10 years ago
|
|
||
![]()
9 years ago
|
if (empty($recipients) && empty($id)) {
|
||
![]()
6 years ago
|
$resultList[] = ['error' => get_lang('You must select at least one destinee')];
|
||
![]()
10 years ago
|
echo json_encode(['files' => $resultList]);
|
||
|
exit;
|
||
|
}
|
||
![]()
9 years ago
|
$work = null;
|
||
|
if (!empty($id)) {
|
||
|
$work = new Dropbox_SentWork($id);
|
||
|
if (empty($work)) {
|
||
|
$resultList[] = ['error' => get_lang('Error')];
|
||
|
echo json_encode(['files' => $resultList]);
|
||
|
exit;
|
||
|
}
|
||
|
}
|
||
![]()
10 years ago
|
|
||
|
if (!empty($_FILES)) {
|
||
|
$files = $_FILES['files'];
|
||
|
$fileList = [];
|
||
|
foreach ($files as $name => $array) {
|
||
|
$counter = 0;
|
||
|
foreach ($array as $data) {
|
||
|
$fileList[$counter][$name] = $data;
|
||
|
$counter++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$resultList = [];
|
||
|
foreach ($fileList as $file) {
|
||
|
$globalFile = [];
|
||
|
$globalFile['files'] = $file;
|
||
|
/** @var Dropbox_SentWork $result */
|
||
![]()
9 years ago
|
$result = store_add_dropbox($file, $work);
|
||
![]()
10 years ago
|
|
||
![]()
8 years ago
|
$json = [];
|
||
![]()
10 years ago
|
if (!empty($result)) {
|
||
|
$json['name'] = Display::url(
|
||
|
api_htmlentities($result->title),
|
||
|
api_htmlentities(api_get_path(WEB_CODE_PATH).'dropbox/index.php?'.api_get_cidreq()),
|
||
![]()
8 years ago
|
['target' => '_blank']
|
||
![]()
10 years ago
|
);
|
||
|
|
||
|
$json['url'] = api_get_path(WEB_CODE_PATH).'dropbox/index.php?'.api_get_cidreq();
|
||
|
$json['size'] = format_file_size($result->filesize);
|
||
|
$json['type'] = api_htmlentities($file['type']);
|
||
|
$json['result'] = Display::return_icon(
|
||
|
'accept.png',
|
||
![]()
6 years ago
|
get_lang('Uploaded.')
|
||
![]()
10 years ago
|
);
|
||
|
} else {
|
||
|
$json['result'] = Display::return_icon(
|
||
|
'exclamation.png',
|
||
|
get_lang('Error')
|
||
|
);
|
||
|
}
|
||
|
$resultList[] = $json;
|
||
|
}
|
||
|
|
||
|
echo json_encode(['files' => $resultList]);
|
||
|
}
|
||
|
exit;
|
||
|
break;
|
||
|
}
|
||
|
exit;
|