Dropbox : Allow to send or remove files already sent to users - refs #20365

pull/4476/head
Christian 3 years ago
parent 27685284a8
commit 9c16f969ff
  1. 225
      main/dropbox/dropbox_functions.inc.php
  2. 12
      main/dropbox/index.php
  3. 1
      main/inc/lib/course.lib.php
  4. 4
      main/lp/lp_update_scorm.php

@ -506,7 +506,7 @@ function display_addcategory_form($category_name = '', $id = 0, $action = '')
* *
* @version march 2006 * @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(); $course_info = api_get_course_info();
$_user = api_get_user_info(); $_user = api_get_user_info();
@ -535,11 +535,13 @@ function display_add_form($viewReceivedCategory, $viewSentCategory, $view, $id =
] ]
); );
$form->addElement('header', get_lang('UploadNewFile')); $langFormHeader = ('send_other_users' == $action ? get_lang('SendFileToOtherUsers') : get_lang('UploadNewFile'));
$maxFileSize = api_get_setting('dropbox_max_filesize'); $form->addElement('header', $langFormHeader);
$form->addElement('hidden', 'MAX_FILE_SIZE', $maxFileSize);
$form->addElement('hidden', 'sec_token', $token); $form->addElement('hidden', 'sec_token', $token);
$form->addElement('hidden', 'origin', $origin); $form->addElement('hidden', 'origin', $origin);
if ('add' == $action) {
$maxFileSize = api_get_setting('dropbox_max_filesize');
$form->addElement('hidden', 'MAX_FILE_SIZE', $maxFileSize);
$form->addElement( $form->addElement(
'file', 'file',
'file', 'file',
@ -557,6 +559,7 @@ function display_add_form($viewReceivedCategory, $viewSentCategory, $view, $id =
['id' => 'cb_overwrite'] ['id' => 'cb_overwrite']
); );
} }
}
// List of all users in this course and all virtual courses combined with it // List of all users in this course and all virtual courses combined with it
if (api_get_session_id()) { 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'); $allowUpload = api_get_setting('dropbox_allow_just_upload');
if ($allowUpload == 'true') { if ($allowUpload == 'true') {
$options['user_'.$_user['user_id']] = get_lang('JustUploadInSelect'); $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'); $form->addButtonUpload(get_lang('Upload'), 'submitWork');
$headers = [ $headers = [
get_lang('Upload'), get_lang('Upload'),
get_lang('Upload').' ('.get_lang('Simple').')', get_lang('Upload').' ('.get_lang('Simple').')',
]; ];
$multipleForm = new FormValidator( $multipleForm = new FormValidator(
'sent_multiple', 'sent_multiple',
'post', 'post',
@ -756,6 +758,84 @@ function display_add_form($viewReceivedCategory, $viewSentCategory, $view, $id =
[$multipleForm->returnForm(), $form->returnForm()], [$multipleForm->returnForm(), $form->returnForm()],
'tabs' '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'])) { if (empty($file['name'])) {
Display::addFlash(Display::return_message(get_lang('NoFileSpecified'), 'warning')); 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(''); $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)) { if (empty($work)) {
// creating the array that contains all the users who will receive the file // creating the array that contains all the users who will receive the file
$new_work_recipients = []; $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'); $b_send_mail = api_get_course_setting('email_alert_on_new_doc_dropbox');
if ($b_send_mail) {
if ($b_send_mail && empty($work)) {
foreach ($new_work_recipients as $recipient_id) { foreach ($new_work_recipients as $recipient_id) {
$recipent_temp = api_get_user_info($recipient_id); $recipent_temp = api_get_user_info($recipient_id);
$additionalParameters = [ $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)) { if (empty($work)) {
// Create new // Create new
$result = new Dropbox_SentWork( $result = new Dropbox_SentWork(
@ -1138,13 +1240,96 @@ function store_add_dropbox($file = [], $work = null)
$work->updateFile(); $work->updateFile();
$result = $work; $result = $work;
} }
}
Security::clear_token(); Security::clear_token();
Display::addFlash(Display::return_message(get_lang('FileUploadSucces'))); Display::addFlash(Display::return_message($successMessage));
return $result; 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. * Transforms the array containing all the feedback into something visually attractive.
* *

@ -59,14 +59,17 @@ if (isset($_GET['dropbox_direction']) && in_array($_GET['dropbox_direction'], ['
$sort_params = Security::remove_XSS(implode('&', $sort_params)); $sort_params = Security::remove_XSS(implode('&', $sort_params));
// Display the form for adding a new dropbox item. // Display the form for adding a new dropbox item.
if ($action == 'add') { if (in_array($action, ['add', 'send_other_users'])) {
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
api_not_allowed(); api_not_allowed();
} }
$dropboxId = isset($_GET['id']) ? (int) $_GET['id'] : 0;
display_add_form( display_add_form(
$viewReceivedCategory, $viewReceivedCategory,
$viewSentCategory, $viewSentCategory,
$view $view,
$dropboxId,
$action
); );
} }
@ -217,7 +220,7 @@ $dropbox_data_sent = [];
$movelist = []; $movelist = [];
$dropbox_data_recieved = []; $dropbox_data_recieved = [];
if ($action != 'add') { if (!in_array($action, ['add', 'send_other_users'])) {
// Getting all the categories in the dropbox for the given user // Getting all the categories in the dropbox for the given user
$dropbox_categories = get_dropbox_categories(); $dropbox_categories = get_dropbox_categories();
// Greating the arrays with the categories for the received files and for the sent files // Greating the arrays with the categories for the received files and for the sent files
@ -632,6 +635,9 @@ if ($action != 'add') {
<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/update.php?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=update&id='.$dropbox_file->id.'&'.$sort_params.'">'. <a href="'.api_get_path(WEB_CODE_PATH).'dropbox/update.php?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=update&id='.$dropbox_file->id.'&'.$sort_params.'">'.
Display::return_icon('upload_file.png', get_lang('Update'), '', ICON_SIZE_SMALL). Display::return_icon('upload_file.png', get_lang('Update'), '', ICON_SIZE_SMALL).
'</a> '</a>
<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/index.php?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=send_other_users&id='.$dropbox_file->id.'&'.$sort_params.'">'.
Display::return_icon('addworkuser.png', get_lang('SendOtherUsers'), '', ICON_SIZE_SMALL).
'</a>
<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=movesent&move_id='.$dropbox_file->id.'&'.$sort_params.'">'. <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=movesent&move_id='.$dropbox_file->id.'&'.$sort_params.'">'.
Display::return_icon('move.png', get_lang('Move'), '', ICON_SIZE_SMALL).' Display::return_icon('move.png', get_lang('Move'), '', ICON_SIZE_SMALL).'
</a> </a>

@ -5084,6 +5084,7 @@ class CourseManager
$sql = "UPDATE $tableCourse SET course_language = '$to' $sql = "UPDATE $tableCourse SET course_language = '$to'
WHERE course_language = '$from'"; WHERE course_language = '$from'";
Database::query($sql); Database::query($sql);
return true; return true;
} }

@ -48,10 +48,10 @@ $form = new FormValidator(
] ]
); );
$firstPart = explode("/", $lp->path, 2); $firstPart = explode("/", $lp->path, 2);
$zipFileName = $firstPart[0] . ".zip"; $zipFileName = $firstPart[0].".zip";
$form->addHeader(get_lang('UpdateFile')); $form->addHeader(get_lang('UpdateFile'));
$form->addHtml(Display::return_message(get_lang('TheScormPackageWillBeUpdatedYouMustUploadTheFileWithTheSameName') . " " . get_lang('FileName') . " : " . $zipFileName)); $form->addHtml(Display::return_message(get_lang('TheScormPackageWillBeUpdatedYouMustUploadTheFileWithTheSameName')." ".get_lang('FileName')." : ".$zipFileName));
$form->addLabel(null, Display::return_icon('scorm_logo.jpg', null, ['style' => 'width:230px;height:100px'])); $form->addLabel(null, Display::return_icon('scorm_logo.jpg', null, ['style' => 'width:230px;height:100px']));
$form->addElement('hidden', 'curdirpath', ''); $form->addElement('hidden', 'curdirpath', '');
$form->addElement('file', 'user_file', get_lang('FileToUpload')); $form->addElement('file', 'user_file', get_lang('FileToUpload'));

Loading…
Cancel
Save