|
|
|
|
@ -506,7 +506,7 @@ function display_addcategory_form($category_name = '', $id = 0, $action = '') |
|
|
|
|
* |
|
|
|
|
* @version march 2006 |
|
|
|
|
*/ |
|
|
|
|
function display_add_form($viewReceivedCategory, $viewSentCategory, $view, $id = 0) |
|
|
|
|
function display_add_form($viewReceivedCategory, $viewSentCategory, $view, $id = 0, $action = 'add') |
|
|
|
|
{ |
|
|
|
|
$course_info = api_get_course_info(); |
|
|
|
|
$_user = api_get_user_info(); |
|
|
|
|
@ -535,11 +535,13 @@ function display_add_form($viewReceivedCategory, $viewSentCategory, $view, $id = |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$form->addElement('header', get_lang('UploadNewFile')); |
|
|
|
|
$maxFileSize = api_get_setting('dropbox_max_filesize'); |
|
|
|
|
$form->addElement('hidden', 'MAX_FILE_SIZE', $maxFileSize); |
|
|
|
|
$langFormHeader = ('send_other_users' == $action ? get_lang('SendFileToOtherUsers') : get_lang('UploadNewFile')); |
|
|
|
|
$form->addElement('header', $langFormHeader); |
|
|
|
|
$form->addElement('hidden', 'sec_token', $token); |
|
|
|
|
$form->addElement('hidden', 'origin', $origin); |
|
|
|
|
if ('add' == $action) { |
|
|
|
|
$maxFileSize = api_get_setting('dropbox_max_filesize'); |
|
|
|
|
$form->addElement('hidden', 'MAX_FILE_SIZE', $maxFileSize); |
|
|
|
|
$form->addElement( |
|
|
|
|
'file', |
|
|
|
|
'file', |
|
|
|
|
@ -557,6 +559,7 @@ function display_add_form($viewReceivedCategory, $viewSentCategory, $view, $id = |
|
|
|
|
['id' => 'cb_overwrite'] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// List of all users in this course and all virtual courses combined with it |
|
|
|
|
if (api_get_session_id()) { |
|
|
|
|
@ -698,6 +701,7 @@ function display_add_form($viewReceivedCategory, $viewSentCategory, $view, $id = |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ('add' == $action) { |
|
|
|
|
$allowUpload = api_get_setting('dropbox_allow_just_upload'); |
|
|
|
|
if ($allowUpload == 'true') { |
|
|
|
|
$options['user_'.$_user['user_id']] = get_lang('JustUploadInSelect'); |
|
|
|
|
@ -715,12 +719,10 @@ function display_add_form($viewReceivedCategory, $viewSentCategory, $view, $id = |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
$form->addButtonUpload(get_lang('Upload'), 'submitWork'); |
|
|
|
|
|
|
|
|
|
$headers = [ |
|
|
|
|
get_lang('Upload'), |
|
|
|
|
get_lang('Upload').' ('.get_lang('Simple').')', |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$multipleForm = new FormValidator( |
|
|
|
|
'sent_multiple', |
|
|
|
|
'post', |
|
|
|
|
@ -756,6 +758,84 @@ function display_add_form($viewReceivedCategory, $viewSentCategory, $view, $id = |
|
|
|
|
[$multipleForm->returnForm(), $form->returnForm()], |
|
|
|
|
'tabs' |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
$tblDropboxPerson = Database::get_course_table(TABLE_DROPBOX_PERSON); |
|
|
|
|
$tblDropboxFile = Database::get_course_table(TABLE_DROPBOX_FILE); |
|
|
|
|
$courseId = api_get_course_int_id(); |
|
|
|
|
$optionsDpUsers = []; |
|
|
|
|
$current_user_id = api_get_user_id(); |
|
|
|
|
|
|
|
|
|
$sql = "SELECT user_id |
|
|
|
|
FROM $tblDropboxPerson |
|
|
|
|
WHERE |
|
|
|
|
c_id = $courseId AND |
|
|
|
|
file_id = $id AND user_id != $current_user_id"; |
|
|
|
|
$rs = Database::query($sql); |
|
|
|
|
if (Database::num_rows($rs) > 0) { |
|
|
|
|
while ($row = Database::fetch_array($rs)) { |
|
|
|
|
$dpUserId = $row['user_id']; |
|
|
|
|
$dpUser = api_get_user_info($dpUserId); |
|
|
|
|
$optionsDpUsers['user_'.$dpUserId] = $dpUser['complete_name']; |
|
|
|
|
if (isset($options['user_'.$dpUserId])) { |
|
|
|
|
unset($options['user_'.$dpUserId]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$form->addSelect( |
|
|
|
|
'recipients', |
|
|
|
|
get_lang('SendTo'), |
|
|
|
|
$options, |
|
|
|
|
[ |
|
|
|
|
'multiple' => 'multiple', |
|
|
|
|
'size' => '10', |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$formRemove = new FormValidator('sent_remove', 'post'); |
|
|
|
|
$formRemove->addElement('header', get_lang('RemoveFileFromSelectedUsers')); |
|
|
|
|
$formRemove->addSelect( |
|
|
|
|
'recipients', |
|
|
|
|
get_lang('Remove'), |
|
|
|
|
$optionsDpUsers, |
|
|
|
|
[ |
|
|
|
|
'multiple' => 'multiple', |
|
|
|
|
'size' => '10', |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// Current file information. |
|
|
|
|
$sql = "SELECT title, filesize |
|
|
|
|
FROM $tblDropboxFile |
|
|
|
|
WHERE |
|
|
|
|
c_id = $courseId AND |
|
|
|
|
iid = $id"; |
|
|
|
|
$rs = Database::query($sql); |
|
|
|
|
$dropboxFile = Database::fetch_array($rs); |
|
|
|
|
if (!empty($dropboxFile)) { |
|
|
|
|
$icon = DocumentManager::build_document_icon_tag('file', $dropboxFile['title']); |
|
|
|
|
$filesize = format_file_size($dropboxFile['filesize']); |
|
|
|
|
$labelFile = "$icon {$dropboxFile['title']} ($filesize)"; |
|
|
|
|
$form->addLabel(get_lang('File'), $labelFile); |
|
|
|
|
$formRemove->addLabel(get_lang('File'), $labelFile); |
|
|
|
|
} |
|
|
|
|
$form->addElement('hidden', 'file_id', $id); |
|
|
|
|
$form->addElement('hidden', 'action', $action); |
|
|
|
|
$form->addElement('hidden', 'option', 'add_users'); |
|
|
|
|
$form->addButtonUpload(get_lang('SendToUsers'), 'submitWork'); |
|
|
|
|
$formRemove->addElement('hidden', 'sec_token', $token); |
|
|
|
|
$formRemove->addElement('hidden', 'origin', $origin); |
|
|
|
|
$formRemove->addElement('hidden', 'file_id', $id); |
|
|
|
|
$formRemove->addElement('hidden', 'action', $action); |
|
|
|
|
$formRemove->addElement('hidden', 'option', 'remove_users'); |
|
|
|
|
$formRemove->addButtonUpload(get_lang('RemoveUsers'), 'submitWork'); |
|
|
|
|
|
|
|
|
|
echo Display::tabs( |
|
|
|
|
[get_lang('AddUsers'), get_lang('RemoveUsers')], |
|
|
|
|
[$form->returnForm(), $formRemove->returnForm()], |
|
|
|
|
'tabs' |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -963,6 +1043,14 @@ function store_add_dropbox($file = [], $work = null) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$fileId = 0; |
|
|
|
|
$sendToOtherUsers = false; |
|
|
|
|
if ((isset($_POST['action']) && 'send_other_users' == $_POST['action']) && isset($_POST['file_id'])) { |
|
|
|
|
$fileId = (int) $_POST['file_id']; |
|
|
|
|
$sendToOtherUsers = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!$sendToOtherUsers) { |
|
|
|
|
if (empty($file['name'])) { |
|
|
|
|
Display::addFlash(Display::return_message(get_lang('NoFileSpecified'), 'warning')); |
|
|
|
|
|
|
|
|
|
@ -1053,6 +1141,17 @@ function store_add_dropbox($file = [], $work = null) |
|
|
|
|
$dropbox_filename = $_user['username']."_".$dropbox_filename."_".uniqid(''); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isset($file['copy_file']) && $file['copy_file']) { |
|
|
|
|
@copy($dropbox_filetmpname, api_get_path(SYS_COURSE_PATH).$_course['path'].'/dropbox/'.$dropbox_filename); |
|
|
|
|
@unlink($dropbox_filetmpname); |
|
|
|
|
} else { |
|
|
|
|
@move_uploaded_file( |
|
|
|
|
$dropbox_filetmpname, |
|
|
|
|
api_get_path(SYS_COURSE_PATH).$_course['path'].'/dropbox/'.$dropbox_filename |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (empty($work)) { |
|
|
|
|
// creating the array that contains all the users who will receive the file |
|
|
|
|
$new_work_recipients = []; |
|
|
|
|
@ -1069,21 +1168,9 @@ function store_add_dropbox($file = [], $work = null) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isset($file['copy_file']) && $file['copy_file']) { |
|
|
|
|
@copy($dropbox_filetmpname, api_get_path(SYS_COURSE_PATH).$_course['path'].'/dropbox/'.$dropbox_filename); |
|
|
|
|
@unlink($dropbox_filetmpname); |
|
|
|
|
} else { |
|
|
|
|
@move_uploaded_file( |
|
|
|
|
$dropbox_filetmpname, |
|
|
|
|
api_get_path(SYS_COURSE_PATH).$_course['path'].'/dropbox/'.$dropbox_filename |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$b_send_mail = api_get_course_setting('email_alert_on_new_doc_dropbox'); |
|
|
|
|
|
|
|
|
|
if ($b_send_mail && empty($work)) { |
|
|
|
|
if ($b_send_mail) { |
|
|
|
|
foreach ($new_work_recipients as $recipient_id) { |
|
|
|
|
$recipent_temp = api_get_user_info($recipient_id); |
|
|
|
|
$additionalParameters = [ |
|
|
|
|
@ -1114,7 +1201,22 @@ function store_add_dropbox($file = [], $work = null) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$successMessage = get_lang('FileUploadSucces'); |
|
|
|
|
if ($sendToOtherUsers) { |
|
|
|
|
$result = true; |
|
|
|
|
if ('remove_users' == $_POST['option']) { |
|
|
|
|
foreach ($new_work_recipients as $userId) { |
|
|
|
|
removeUserDropboxFile($fileId, $userId); |
|
|
|
|
} |
|
|
|
|
$successMessage = get_lang('FileRemovedFromSelectedUsers'); |
|
|
|
|
} else { |
|
|
|
|
foreach ($new_work_recipients as $userId) { |
|
|
|
|
addDropBoxFileToUser($fileId, $userId); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (empty($work)) { |
|
|
|
|
// Create new |
|
|
|
|
$result = new Dropbox_SentWork( |
|
|
|
|
@ -1138,13 +1240,96 @@ function store_add_dropbox($file = [], $work = null) |
|
|
|
|
$work->updateFile(); |
|
|
|
|
$result = $work; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Security::clear_token(); |
|
|
|
|
Display::addFlash(Display::return_message(get_lang('FileUploadSucces'))); |
|
|
|
|
Display::addFlash(Display::return_message($successMessage)); |
|
|
|
|
|
|
|
|
|
return $result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* It removes a dropbox file of a selected user. |
|
|
|
|
* |
|
|
|
|
* @param $fileId |
|
|
|
|
* @param $userId |
|
|
|
|
*/ |
|
|
|
|
function removeUserDropboxFile($fileId, $userId) |
|
|
|
|
{ |
|
|
|
|
$tblDropboxPerson = Database::get_course_table(TABLE_DROPBOX_PERSON); |
|
|
|
|
$tblDropboxPost = Database::get_course_table(TABLE_DROPBOX_POST); |
|
|
|
|
$courseId = api_get_course_int_id(); |
|
|
|
|
$sessionId = api_get_session_id(); |
|
|
|
|
|
|
|
|
|
$params = [$courseId, $fileId, $userId]; |
|
|
|
|
$result = Database::delete( |
|
|
|
|
$tblDropboxPerson, |
|
|
|
|
['c_id = ? AND file_id = ? AND user_id = ?' => $params] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$params = [$courseId, $fileId, $userId, $sessionId]; |
|
|
|
|
$result = Database::delete( |
|
|
|
|
$tblDropboxPost, |
|
|
|
|
['c_id = ? AND file_id = ? AND dest_user_id = ? AND session_id = ?' => $params] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* It sends a file to a selected user. |
|
|
|
|
* |
|
|
|
|
* @param $fileId |
|
|
|
|
* @param $userId |
|
|
|
|
*/ |
|
|
|
|
function addDropBoxFileToUser($fileId, $userId) |
|
|
|
|
{ |
|
|
|
|
$tblDropboxPerson = Database::get_course_table(TABLE_DROPBOX_PERSON); |
|
|
|
|
$tblDropboxPost = Database::get_course_table(TABLE_DROPBOX_POST); |
|
|
|
|
$courseId = api_get_course_int_id(); |
|
|
|
|
$sessionId = api_get_session_id(); |
|
|
|
|
|
|
|
|
|
$sql = "SELECT count(file_id) as count |
|
|
|
|
FROM $tblDropboxPerson |
|
|
|
|
WHERE c_id = $courseId AND file_id = $fileId AND user_id = $userId"; |
|
|
|
|
$rs = Database::query($sql); |
|
|
|
|
$row = Database::fetch_array($rs); |
|
|
|
|
if (0 == $row['count']) { |
|
|
|
|
$params = [ |
|
|
|
|
'c_id' => $courseId, |
|
|
|
|
'file_id' => $fileId, |
|
|
|
|
'user_id' => $userId, |
|
|
|
|
]; |
|
|
|
|
Database::insert($tblDropboxPerson, $params); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$sql = "SELECT count(file_id) as count |
|
|
|
|
FROM $tblDropboxPost |
|
|
|
|
WHERE c_id = $courseId AND file_id = $fileId AND dest_user_id = $userId AND session_id = $sessionId"; |
|
|
|
|
$rs = Database::query($sql); |
|
|
|
|
$row = Database::fetch_array($rs); |
|
|
|
|
if (0 == $row['count']) { |
|
|
|
|
$params = [ |
|
|
|
|
'c_id' => $courseId, |
|
|
|
|
'file_id' => $fileId, |
|
|
|
|
'dest_user_id' => $userId, |
|
|
|
|
'session_id' => $sessionId, |
|
|
|
|
'feedback_date' => api_get_utc_datetime(), |
|
|
|
|
'cat_id' => 0, |
|
|
|
|
]; |
|
|
|
|
Database::insert($tblDropboxPost, $params); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Update item_property table for each recipient |
|
|
|
|
api_item_property_update( |
|
|
|
|
api_get_course_info(), |
|
|
|
|
TOOL_DROPBOX, |
|
|
|
|
$fileId, |
|
|
|
|
'DropboxFileAdded', |
|
|
|
|
api_get_user_id(), |
|
|
|
|
null, |
|
|
|
|
$userId |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Transforms the array containing all the feedback into something visually attractive. |
|
|
|
|
* |
|
|
|
|
|