Skip to content

Commit 91c0f15

Browse files
committed
Adding setting "allow_redirect_to_main_page_after_work_upload" BT#13567
Redirect to home work tool after uploading a student publication or a adding a comment
1 parent f3f49dc commit 91c0f15

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

main/inc/lib/formvalidator/FormValidator.class.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,11 +1561,12 @@ public function addTextAlphanumericAndSpaces(
15611561

15621562
/**
15631563
* @param string $url
1564+
* @param string $urlToRedirect after upload redirect to this page
15641565
*/
1565-
public function addMultipleUpload($url)
1566+
public function addMultipleUpload($url, $urlToRedirect = '')
15661567
{
15671568
$inputName = 'input_file_upload';
1568-
$this->addMultipleUploadJavascript($url, $inputName);
1569+
$this->addMultipleUploadJavascript($url, $inputName, $urlToRedirect);
15691570

15701571
$this->addHtml('
15711572
<div class="description-upload">
@@ -1595,9 +1596,14 @@ public function addMultipleUpload($url)
15951596
*
15961597
* @param string $url page that will handle the upload
15971598
* @param string $inputName
1599+
* @param string $urlToRedirect
15981600
*/
1599-
private function addMultipleUploadJavascript($url, $inputName)
1601+
private function addMultipleUploadJavascript($url, $inputName, $urlToRedirect = '')
16001602
{
1603+
$redirectCondition = '';
1604+
if (!empty($urlToRedirect)) {
1605+
$redirectCondition = "window.location.replace('$urlToRedirect'); ";
1606+
}
16011607
$icon = Display::return_icon('file_txt.gif');
16021608
$this->addHtml("
16031609
<script>
@@ -1683,13 +1689,14 @@ private function addMultipleUploadJavascript($url, $inputName)
16831689
// Update file name with new one from Chamilo
16841690
$(data.context.children()[index]).parent().find('.file_name').html(file.name);
16851691
var successMessage = $('<div class=\"col-sm-3\">').html($('<span class=\"alert alert-success\"/>').text('".addslashes(get_lang('UplUploadSucceeded'))."'));
1686-
$(data.context.children()[index]).parent().append(successMessage);
1692+
$(data.context.children()[index]).parent().append(successMessage);
16871693
} else if (file.error) {
16881694
var error = $('<div class=\"col-sm-3\">').html($('<span class=\"alert alert-danger\"/>').text(file.error));
1689-
$(data.context.children()[index]).parent().append(error);
1695+
$(data.context.children()[index]).parent().append(error);
16901696
}
1691-
});
1692-
$('#dropzone').removeClass('hover');
1697+
});
1698+
$('#dropzone').removeClass('hover');
1699+
".$redirectCondition."
16931700
}).on('fileuploadfail', function (e, data) {
16941701
$.each(data.files, function (index) {
16951702
var failedMessage = '" . addslashes(get_lang('UplUploadFailed'))."';

main/install/configuration.dist.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,3 +673,5 @@
673673
//$_configuration['disable_js_in_lp_view'] = true;
674674
// Show all sessions (old, current, future) in my course page
675675
//$_configuration['show_all_sessions_on_my_course_page'] = true;
676+
// Redirect to home tool after uploading a student publication or a adding a comment
677+
//$_configuration['allow_redirect_to_main_page_after_work_upload'] = false;

main/work/upload.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@
8888
$form->addElement('hidden', 'id', $work_id);
8989
$form->addElement('hidden', 'sec_token', $token);
9090

91+
$allowRedirect = api_get_configuration_value('allow_redirect_to_main_page_after_work_upload');
92+
$urlToRedirect = '';
93+
if ($allowRedirect) {
94+
$urlToRedirect = api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq();
95+
}
96+
9197
$succeed = false;
9298
if ($form->validate()) {
9399
if ($student_can_edit_in_session && $check) {
@@ -103,6 +109,13 @@
103109
$_FILES['file'],
104110
api_get_configuration_value('assignment_prevent_duplicate_upload')
105111
);
112+
113+
114+
if ($allowRedirect) {
115+
header('Location: '.$urlToRedirect);
116+
exit;
117+
}
118+
106119
$script = 'work_list.php';
107120
if ($is_allowed_to_edit) {
108121
$script = 'work_list_all.php';
@@ -133,7 +146,7 @@
133146
);
134147

135148
$multipleForm = new FormValidator('post');
136-
$multipleForm->addMultipleUpload($url);
149+
$multipleForm->addMultipleUpload($url, $urlToRedirect);
137150

138151
$tabs = Display::tabs(
139152
$headers,

main/work/view.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@
6868
$url = api_get_path(WEB_CODE_PATH).'work/edit.php?id='.$my_folder_data['id'].'&item_id='.$work['id'].'&'.api_get_cidreq();
6969
} else {
7070
$url = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$work['id'].'&'.api_get_cidreq();
71+
72+
$allowRedirect = api_get_configuration_value('allow_redirect_to_main_page_after_work_upload');
73+
$urlToRedirect = '';
74+
if ($allowRedirect) {
75+
$url = api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq();
76+
}
7177
}
7278

7379
switch ($action) {

0 commit comments

Comments
 (0)