|
|
|
|
@ -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,27 +535,30 @@ 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); |
|
|
|
|
$form->addElement( |
|
|
|
|
'file', |
|
|
|
|
'file', |
|
|
|
|
get_lang('UploadFile'), |
|
|
|
|
['onChange' => 'javascript: checkfile(this.value);'] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$allowOverwrite = api_get_setting('dropbox_allow_overwrite'); |
|
|
|
|
if ($allowOverwrite == 'true' && empty($idCondition)) { |
|
|
|
|
if ('add' == $action) { |
|
|
|
|
$maxFileSize = api_get_setting('dropbox_max_filesize'); |
|
|
|
|
$form->addElement('hidden', 'MAX_FILE_SIZE', $maxFileSize); |
|
|
|
|
$form->addElement( |
|
|
|
|
'checkbox', |
|
|
|
|
'cb_overwrite', |
|
|
|
|
null, |
|
|
|
|
get_lang('OverwriteFile'), |
|
|
|
|
['id' => 'cb_overwrite'] |
|
|
|
|
'file', |
|
|
|
|
'file', |
|
|
|
|
get_lang('UploadFile'), |
|
|
|
|
['onChange' => 'javascript: checkfile(this.value);'] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$allowOverwrite = api_get_setting('dropbox_allow_overwrite'); |
|
|
|
|
if ($allowOverwrite == 'true' && empty($idCondition)) { |
|
|
|
|
$form->addElement( |
|
|
|
|
'checkbox', |
|
|
|
|
'cb_overwrite', |
|
|
|
|
null, |
|
|
|
|
get_lang('OverwriteFile'), |
|
|
|
|
['id' => 'cb_overwrite'] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// List of all users in this course and all virtual courses combined with it |
|
|
|
|
@ -698,12 +701,87 @@ function display_add_form($viewReceivedCategory, $viewSentCategory, $view, $id = |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$allowUpload = api_get_setting('dropbox_allow_just_upload'); |
|
|
|
|
if ($allowUpload == 'true') { |
|
|
|
|
$options['user_'.$_user['user_id']] = get_lang('JustUploadInSelect'); |
|
|
|
|
} |
|
|
|
|
if ('add' == $action) { |
|
|
|
|
$allowUpload = api_get_setting('dropbox_allow_just_upload'); |
|
|
|
|
if ($allowUpload == 'true') { |
|
|
|
|
$options['user_'.$_user['user_id']] = get_lang('JustUploadInSelect'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (empty($idCondition)) { |
|
|
|
|
$form->addSelect( |
|
|
|
|
'recipients', |
|
|
|
|
get_lang('SendTo'), |
|
|
|
|
$options, |
|
|
|
|
[ |
|
|
|
|
'multiple' => 'multiple', |
|
|
|
|
'size' => '10', |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
$form->addButtonUpload(get_lang('Upload'), 'submitWork'); |
|
|
|
|
$headers = [ |
|
|
|
|
get_lang('Upload'), |
|
|
|
|
get_lang('Upload').' ('.get_lang('Simple').')', |
|
|
|
|
]; |
|
|
|
|
$multipleForm = new FormValidator( |
|
|
|
|
'sent_multiple', |
|
|
|
|
'post', |
|
|
|
|
'#', |
|
|
|
|
null, |
|
|
|
|
['enctype' => 'multipart/form-data', 'id' => 'fileupload'] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if (empty($idCondition)) { |
|
|
|
|
$multipleForm->addSelect( |
|
|
|
|
'recipients', |
|
|
|
|
get_lang('SendTo'), |
|
|
|
|
$options, |
|
|
|
|
[ |
|
|
|
|
'multiple' => 'multiple', |
|
|
|
|
'size' => '10', |
|
|
|
|
'id' => 'recipient_form', |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$url = api_get_path(WEB_AJAX_PATH).'dropbox.ajax.php?'.api_get_cidreq().'&a=upload_file&'.$idCondition; |
|
|
|
|
if (empty($idCondition)) { |
|
|
|
|
$multipleForm->addHtml('<div id="multiple_form" style="display:none">'); |
|
|
|
|
} |
|
|
|
|
$multipleForm->addMultipleUpload($url); |
|
|
|
|
if (empty($idCondition)) { |
|
|
|
|
$multipleForm->addHtml('</div>'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
echo Display::tabs( |
|
|
|
|
$headers, |
|
|
|
|
[$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]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (empty($idCondition)) { |
|
|
|
|
$form->addSelect( |
|
|
|
|
'recipients', |
|
|
|
|
get_lang('SendTo'), |
|
|
|
|
@ -713,49 +791,51 @@ function display_add_form($viewReceivedCategory, $viewSentCategory, $view, $id = |
|
|
|
|
'size' => '10', |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
$form->addButtonUpload(get_lang('Upload'), 'submitWork'); |
|
|
|
|
|
|
|
|
|
$headers = [ |
|
|
|
|
get_lang('Upload'), |
|
|
|
|
get_lang('Upload').' ('.get_lang('Simple').')', |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$multipleForm = new FormValidator( |
|
|
|
|
'sent_multiple', |
|
|
|
|
'post', |
|
|
|
|
'#', |
|
|
|
|
null, |
|
|
|
|
['enctype' => 'multipart/form-data', 'id' => 'fileupload'] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if (empty($idCondition)) { |
|
|
|
|
$multipleForm->addSelect( |
|
|
|
|
$formRemove = new FormValidator('sent_remove', 'post'); |
|
|
|
|
$formRemove->addElement('header', get_lang('RemoveFileFromSelectedUsers')); |
|
|
|
|
$formRemove->addSelect( |
|
|
|
|
'recipients', |
|
|
|
|
get_lang('SendTo'), |
|
|
|
|
$options, |
|
|
|
|
get_lang('Remove'), |
|
|
|
|
$optionsDpUsers, |
|
|
|
|
[ |
|
|
|
|
'multiple' => 'multiple', |
|
|
|
|
'size' => '10', |
|
|
|
|
'id' => 'recipient_form', |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$url = api_get_path(WEB_AJAX_PATH).'dropbox.ajax.php?'.api_get_cidreq().'&a=upload_file&'.$idCondition; |
|
|
|
|
if (empty($idCondition)) { |
|
|
|
|
$multipleForm->addHtml('<div id="multiple_form" style="display:none">'); |
|
|
|
|
} |
|
|
|
|
$multipleForm->addMultipleUpload($url); |
|
|
|
|
if (empty($idCondition)) { |
|
|
|
|
$multipleForm->addHtml('</div>'); |
|
|
|
|
// 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' |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
echo Display::tabs( |
|
|
|
|
$headers, |
|
|
|
|
[$multipleForm->returnForm(), $form->returnForm()], |
|
|
|
|
'tabs' |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -963,94 +1043,113 @@ function store_add_dropbox($file = [], $work = null) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (empty($file['name'])) { |
|
|
|
|
Display::addFlash(Display::return_message(get_lang('NoFileSpecified'), 'warning')); |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
$fileId = 0; |
|
|
|
|
$sendToOtherUsers = false; |
|
|
|
|
if ((isset($_POST['action']) && 'send_other_users' == $_POST['action']) && isset($_POST['file_id'])) { |
|
|
|
|
$fileId = (int) $_POST['file_id']; |
|
|
|
|
$sendToOtherUsers = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// are we overwriting a previous file or sending a new one |
|
|
|
|
$dropbox_overwrite = false; |
|
|
|
|
if (isset($_POST['cb_overwrite']) && $_POST['cb_overwrite']) { |
|
|
|
|
$dropbox_overwrite = true; |
|
|
|
|
} |
|
|
|
|
if (!$sendToOtherUsers) { |
|
|
|
|
if (empty($file['name'])) { |
|
|
|
|
Display::addFlash(Display::return_message(get_lang('NoFileSpecified'), 'warning')); |
|
|
|
|
|
|
|
|
|
// doing the upload |
|
|
|
|
$dropbox_filename = $file['name']; |
|
|
|
|
$dropbox_filesize = $file['size']; |
|
|
|
|
$dropbox_filetype = $file['type']; |
|
|
|
|
$dropbox_filetmpname = $file['tmp_name']; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// check if the filesize does not exceed the allowed size. |
|
|
|
|
$maxFileSize = api_get_setting('dropbox_max_filesize'); |
|
|
|
|
if ($dropbox_filesize <= 0 || $dropbox_filesize > $maxFileSize) { |
|
|
|
|
Display::addFlash(Display::return_message(get_lang('DropboxFileTooBig'), 'warning')); |
|
|
|
|
// are we overwriting a previous file or sending a new one |
|
|
|
|
$dropbox_overwrite = false; |
|
|
|
|
if (isset($_POST['cb_overwrite']) && $_POST['cb_overwrite']) { |
|
|
|
|
$dropbox_overwrite = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
// doing the upload |
|
|
|
|
$dropbox_filename = $file['name']; |
|
|
|
|
$dropbox_filesize = $file['size']; |
|
|
|
|
$dropbox_filetype = $file['type']; |
|
|
|
|
$dropbox_filetmpname = $file['tmp_name']; |
|
|
|
|
|
|
|
|
|
// check if the file is actually uploaded |
|
|
|
|
if (!isset($file['copy_file']) && !is_uploaded_file($dropbox_filetmpname)) { // check user fraud : no clean error msg. |
|
|
|
|
Display::addFlash(Display::return_message(get_lang('TheFileIsNotUploaded'), 'warning')); |
|
|
|
|
// check if the filesize does not exceed the allowed size. |
|
|
|
|
$maxFileSize = api_get_setting('dropbox_max_filesize'); |
|
|
|
|
if ($dropbox_filesize <= 0 || $dropbox_filesize > $maxFileSize) { |
|
|
|
|
Display::addFlash(Display::return_message(get_lang('DropboxFileTooBig'), 'warning')); |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$upload_ok = process_uploaded_file($file, true); |
|
|
|
|
// check if the file is actually uploaded |
|
|
|
|
if (!isset($file['copy_file']) && !is_uploaded_file($dropbox_filetmpname)) { // check user fraud : no clean error msg. |
|
|
|
|
Display::addFlash(Display::return_message(get_lang('TheFileIsNotUploaded'), 'warning')); |
|
|
|
|
|
|
|
|
|
if (!$upload_ok) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Try to add an extension to the file if it hasn't got one |
|
|
|
|
$dropbox_filename = add_ext_on_mime($dropbox_filename, $dropbox_filetype); |
|
|
|
|
// Replace dangerous characters |
|
|
|
|
$dropbox_filename = api_replace_dangerous_char($dropbox_filename); |
|
|
|
|
// Transform any .php file in .phps fo security |
|
|
|
|
$dropbox_filename = php2phps($dropbox_filename); |
|
|
|
|
|
|
|
|
|
//filter extension |
|
|
|
|
if (!filter_extension($dropbox_filename)) { |
|
|
|
|
Display::addFlash( |
|
|
|
|
Display::return_message( |
|
|
|
|
get_lang('UplUnableToSaveFileFilteredExtension'), |
|
|
|
|
'warning' |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
$upload_ok = process_uploaded_file($file, true); |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
if (!$upload_ok) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// set title |
|
|
|
|
$dropbox_title = $dropbox_filename; |
|
|
|
|
// note: I think we could better migrate everything from here on to |
|
|
|
|
// separate functions: store_new_dropbox, store_new_mailing, store_just_upload |
|
|
|
|
if ($dropbox_overwrite && empty($work)) { |
|
|
|
|
$dropbox_person = new Dropbox_Person( |
|
|
|
|
$_user['user_id'], |
|
|
|
|
api_is_course_admin(), |
|
|
|
|
api_is_course_tutor() |
|
|
|
|
); |
|
|
|
|
$mailId = get_mail_id_base(); |
|
|
|
|
foreach ($dropbox_person->sentWork as $w) { |
|
|
|
|
if ($w->title == $dropbox_filename) { |
|
|
|
|
if (($w->recipients[0]['id'] > $mailId) xor $thisIsAMailing) { |
|
|
|
|
Display::addFlash(Display::return_message(get_lang('MailingNonMailingError'), 'warning')); |
|
|
|
|
// Try to add an extension to the file if it hasn't got one |
|
|
|
|
$dropbox_filename = add_ext_on_mime($dropbox_filename, $dropbox_filetype); |
|
|
|
|
// Replace dangerous characters |
|
|
|
|
$dropbox_filename = api_replace_dangerous_char($dropbox_filename); |
|
|
|
|
// Transform any .php file in .phps fo security |
|
|
|
|
$dropbox_filename = php2phps($dropbox_filename); |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
if (($w->recipients[0]['id'] == $_user['user_id']) xor $thisIsJustUpload) { |
|
|
|
|
Display::addFlash(Display::return_message(get_lang('MailingJustUploadSelectNoOther'), 'warning')); |
|
|
|
|
//filter extension |
|
|
|
|
if (!filter_extension($dropbox_filename)) { |
|
|
|
|
Display::addFlash( |
|
|
|
|
Display::return_message( |
|
|
|
|
get_lang('UplUnableToSaveFileFilteredExtension'), |
|
|
|
|
'warning' |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// set title |
|
|
|
|
$dropbox_title = $dropbox_filename; |
|
|
|
|
// note: I think we could better migrate everything from here on to |
|
|
|
|
// separate functions: store_new_dropbox, store_new_mailing, store_just_upload |
|
|
|
|
if ($dropbox_overwrite && empty($work)) { |
|
|
|
|
$dropbox_person = new Dropbox_Person( |
|
|
|
|
$_user['user_id'], |
|
|
|
|
api_is_course_admin(), |
|
|
|
|
api_is_course_tutor() |
|
|
|
|
); |
|
|
|
|
$mailId = get_mail_id_base(); |
|
|
|
|
foreach ($dropbox_person->sentWork as $w) { |
|
|
|
|
if ($w->title == $dropbox_filename) { |
|
|
|
|
if (($w->recipients[0]['id'] > $mailId) xor $thisIsAMailing) { |
|
|
|
|
Display::addFlash(Display::return_message(get_lang('MailingNonMailingError'), 'warning')); |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
if (($w->recipients[0]['id'] == $_user['user_id']) xor $thisIsJustUpload) { |
|
|
|
|
Display::addFlash(Display::return_message(get_lang('MailingJustUploadSelectNoOther'), 'warning')); |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
$dropbox_filename = $w->filename; |
|
|
|
|
$found = true; // note: do we still need this? |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
$dropbox_filename = $w->filename; |
|
|
|
|
$found = true; // note: do we still need this? |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} else { // rename file to login_filename_uniqueId format |
|
|
|
|
$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 |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} else { // rename file to login_filename_uniqueId format |
|
|
|
|
$dropbox_filename = $_user['username']."_".$dropbox_filename."_".uniqid(''); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (empty($work)) { |
|
|
|
|
@ -1069,80 +1168,166 @@ function store_add_dropbox($file = [], $work = null) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$b_send_mail = api_get_course_setting('email_alert_on_new_doc_dropbox'); |
|
|
|
|
if ($b_send_mail) { |
|
|
|
|
foreach ($new_work_recipients as $recipient_id) { |
|
|
|
|
$recipent_temp = api_get_user_info($recipient_id); |
|
|
|
|
$additionalParameters = [ |
|
|
|
|
'smsType' => SmsPlugin::NEW_FILE_SHARED_COURSE_BY, |
|
|
|
|
'userId' => $recipient_id, |
|
|
|
|
'courseTitle' => $_course['title'], |
|
|
|
|
'userUsername' => $recipent_temp['username'], |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$message = get_lang('NewDropboxFileUploadedContent'). |
|
|
|
|
' <a href="'.api_get_path(WEB_CODE_PATH).'dropbox/index.php?'.api_get_cidreq().'">'.get_lang('SeeFile').'</a>'. |
|
|
|
|
"\n\n". |
|
|
|
|
api_get_person_name( |
|
|
|
|
$_user['firstName'], |
|
|
|
|
$_user['lastName'], |
|
|
|
|
null, |
|
|
|
|
PERSON_NAME_EMAIL_ADDRESS |
|
|
|
|
)."\n".get_lang('Email')." : ".$_user['mail']; |
|
|
|
|
|
|
|
|
|
MessageManager::send_message_simple( |
|
|
|
|
$recipient_id, |
|
|
|
|
get_lang('NewDropboxFileUploaded'), |
|
|
|
|
$message, |
|
|
|
|
$_user['user_id'], |
|
|
|
|
false, |
|
|
|
|
false, |
|
|
|
|
$additionalParameters |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
$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 { |
|
|
|
|
@move_uploaded_file( |
|
|
|
|
$dropbox_filetmpname, |
|
|
|
|
api_get_path(SYS_COURSE_PATH).$_course['path'].'/dropbox/'.$dropbox_filename |
|
|
|
|
); |
|
|
|
|
if (empty($work)) { |
|
|
|
|
// Create new |
|
|
|
|
$result = new Dropbox_SentWork( |
|
|
|
|
$_user['user_id'], |
|
|
|
|
$dropbox_title, |
|
|
|
|
isset($_POST['description']) ? $_POST['description'] : '', |
|
|
|
|
api_get_user_id(), |
|
|
|
|
$dropbox_filename, |
|
|
|
|
$dropbox_filesize, |
|
|
|
|
$new_work_recipients |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
// Update |
|
|
|
|
$work->title = $dropbox_title; |
|
|
|
|
$work->filename = $dropbox_filename; |
|
|
|
|
$work->filesize = $dropbox_filesize; |
|
|
|
|
$work->upload_date = api_get_utc_datetime(); |
|
|
|
|
$work->last_upload_date = api_get_utc_datetime(); |
|
|
|
|
$work->description = isset($_POST['description']) ? $_POST['description'] : ''; |
|
|
|
|
$work->uploader_id = api_get_user_id(); |
|
|
|
|
$work->updateFile(); |
|
|
|
|
$result = $work; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$b_send_mail = api_get_course_setting('email_alert_on_new_doc_dropbox'); |
|
|
|
|
Security::clear_token(); |
|
|
|
|
Display::addFlash(Display::return_message($successMessage)); |
|
|
|
|
|
|
|
|
|
if ($b_send_mail && empty($work)) { |
|
|
|
|
foreach ($new_work_recipients as $recipient_id) { |
|
|
|
|
$recipent_temp = api_get_user_info($recipient_id); |
|
|
|
|
$additionalParameters = [ |
|
|
|
|
'smsType' => SmsPlugin::NEW_FILE_SHARED_COURSE_BY, |
|
|
|
|
'userId' => $recipient_id, |
|
|
|
|
'courseTitle' => $_course['title'], |
|
|
|
|
'userUsername' => $recipent_temp['username'], |
|
|
|
|
]; |
|
|
|
|
return $result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$message = get_lang('NewDropboxFileUploadedContent'). |
|
|
|
|
' <a href="'.api_get_path(WEB_CODE_PATH).'dropbox/index.php?'.api_get_cidreq().'">'.get_lang('SeeFile').'</a>'. |
|
|
|
|
"\n\n". |
|
|
|
|
api_get_person_name( |
|
|
|
|
$_user['firstName'], |
|
|
|
|
$_user['lastName'], |
|
|
|
|
null, |
|
|
|
|
PERSON_NAME_EMAIL_ADDRESS |
|
|
|
|
)."\n".get_lang('Email')." : ".$_user['mail']; |
|
|
|
|
/** |
|
|
|
|
* 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] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
MessageManager::send_message_simple( |
|
|
|
|
$recipient_id, |
|
|
|
|
get_lang('NewDropboxFileUploaded'), |
|
|
|
|
$message, |
|
|
|
|
$_user['user_id'], |
|
|
|
|
false, |
|
|
|
|
false, |
|
|
|
|
$additionalParameters |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$params = [$courseId, $fileId, $userId, $sessionId]; |
|
|
|
|
$result = Database::delete( |
|
|
|
|
$tblDropboxPost, |
|
|
|
|
['c_id = ? AND file_id = ? AND dest_user_id = ? AND session_id = ?' => $params] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (empty($work)) { |
|
|
|
|
// Create new |
|
|
|
|
$result = new Dropbox_SentWork( |
|
|
|
|
$_user['user_id'], |
|
|
|
|
$dropbox_title, |
|
|
|
|
isset($_POST['description']) ? $_POST['description'] : '', |
|
|
|
|
api_get_user_id(), |
|
|
|
|
$dropbox_filename, |
|
|
|
|
$dropbox_filesize, |
|
|
|
|
$new_work_recipients |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
// Update |
|
|
|
|
$work->title = $dropbox_title; |
|
|
|
|
$work->filename = $dropbox_filename; |
|
|
|
|
$work->filesize = $dropbox_filesize; |
|
|
|
|
$work->upload_date = api_get_utc_datetime(); |
|
|
|
|
$work->last_upload_date = api_get_utc_datetime(); |
|
|
|
|
$work->description = isset($_POST['description']) ? $_POST['description'] : ''; |
|
|
|
|
$work->uploader_id = api_get_user_id(); |
|
|
|
|
$work->updateFile(); |
|
|
|
|
$result = $work; |
|
|
|
|
/** |
|
|
|
|
* 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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Security::clear_token(); |
|
|
|
|
Display::addFlash(Display::return_message(get_lang('FileUploadSucces'))); |
|
|
|
|
$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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $result; |
|
|
|
|
// 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 |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|