Skip to content

Commit 535f381

Browse files
committed
Add certificate=true in links fixes #2341
1 parent 9f6c364 commit 535f381

File tree

3 files changed

+59
-79
lines changed

3 files changed

+59
-79
lines changed

main/document/document.php

Lines changed: 42 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
$parent_id = null;
3939
$lib_path = api_get_path(LIBRARY_PATH);
4040
$actionsRight = '';
41-
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
41+
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
4242
$allowUseTool = false;
4343

4444
if ($allowDownloadDocumentsByApiKey) {
@@ -49,9 +49,7 @@
4949

5050
$username = isset($_GET['username']) ? Security::remove_XSS($_GET['username']) : null;
5151
$apiKey = isset($_GET['api_key']) ? Security::remove_XSS($_GET['api_key']) : null;
52-
5352
$restApi = Rest::validate($username, $apiKey);
54-
5553
$allowUseTool = $restApi ? true : false;
5654
} catch (Exception $e) {
5755
$allowUseTool = false;
@@ -74,12 +72,7 @@
7472
$courseInfo = api_get_course_info();
7573
$courseId = $courseInfo['real_id'];
7674
$course_dir = $courseInfo['directory'].'/document';
77-
$sys_course_path = api_get_path(SYS_COURSE_PATH);
78-
$base_work_dir = $sys_course_path.$course_dir;
79-
$http_www = api_get_path(WEB_COURSE_PATH).$courseInfo['directory'].'/document';
80-
$document_path = $base_work_dir;
8175
$usePpt2lp = api_get_setting('service_ppt2lp', 'active') == 'true';
82-
$course_dir = $courseInfo['directory'].'/document';
8376
$sys_course_path = api_get_path(SYS_COURSE_PATH);
8477
$base_work_dir = $sys_course_path.$course_dir;
8578
$http_www = api_get_path(WEB_COURSE_PATH).$courseInfo['directory'].'/document';
@@ -95,6 +88,11 @@
9588
$is_certificate_mode = true;
9689
}
9790

91+
$certificateLink = '';
92+
if ($is_certificate_mode) {
93+
$certificateLink = '&certificate=true';
94+
}
95+
9896
// Removing sessions
9997
Session::erase('draw_dir');
10098
Session::erase('paint_dir');
@@ -130,7 +128,7 @@
130128
$moveTo = isset($_POST['move_to']) ? Security::remove_XSS($_POST['move_to']) : null;
131129
$moveFile = isset($_POST['move_file']) && is_int($_POST['move_file']) ? $_POST['move_file'] : null;
132130

133-
/* Constants and variables */
131+
/* Constants and variables */
134132
$userId = api_get_user_id();
135133
$userInfo = api_get_user_info();
136134
$sessionId = api_get_session_id();
@@ -164,7 +162,6 @@
164162

165163
// Let's assume the user cannot upload files for the group
166164
$group_member_with_upload_rights = false;
167-
168165
if ($group_properties['doc_state'] == 2) {
169166
// Documents are private
170167
if ($isAllowedToEdit || GroupManager::is_user_in_group($userId, $group_properties)) {
@@ -202,7 +199,6 @@
202199
$group_member_with_upload_rights = true;
203200
}
204201
}
205-
206202
Session::write('group_member_with_upload_rights', $group_member_with_upload_rights);
207203
} else {
208204
Session::write('group_member_with_upload_rights', false);
@@ -211,11 +207,6 @@
211207
// Actions.
212208
$document_id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
213209
$currentUrl = api_get_self().'?'.api_get_cidreq().'&id='.$document_id;
214-
215-
/*if (Portfolio::controller()->accept()) {
216-
Portfolio::controller()->run();
217-
}*/
218-
219210
$curdirpath = isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : null;
220211

221212
switch ($action) {
@@ -748,17 +739,6 @@
748739
}
749740
}
750741

751-
// Is the document tool visible?
752-
// Check whether the tool is actually visible
753-
/*$table_course_tool = Database::get_course_table(TABLE_TOOL_LIST);
754-
$course_id = api_get_course_int_id();
755-
$tool_sql = 'SELECT visibility FROM '.$table_course_tool.'
756-
WHERE c_id = '.$course_id.' AND name = "'.TOOL_DOCUMENT.'"
757-
LIMIT 1';
758-
$tool_result = Database::query($tool_sql);
759-
$tool_row = Database::fetch_array($tool_result);
760-
$tool_visibility = $tool_row['visibility'];*/
761-
762742
$htmlHeadXtra[] = '<script>
763743
function confirmation (name) {
764744
if (confirm(" '.addslashes(get_lang('AreYouSureToDeleteJS')).' "+ name + " ?")) {
@@ -811,11 +791,8 @@ function convertModal (id, format) {
811791
}
812792
}
813793

814-
/* Create shared folders */
794+
/* Create shared folders */
815795
DocumentManager::createUserSharedFolder(api_get_user_id(), $courseInfo, $sessionId);
816-
817-
/* MAIN SECTION */
818-
819796
Session::write('image_files_only', '');
820797
$image_files_only = '';
821798
if ($is_certificate_mode) {
@@ -956,14 +933,12 @@ function convertModal (id, format) {
956933
// Lib for event log, stats & tracking & record of the access
957934
Event::event_access_tool(TOOL_DOCUMENT);
958935

959-
/* DISPLAY */
936+
/* DISPLAY */
960937
if ($groupId != 0) { // Add group name after for group documents
961938
$add_group_to_title = ' ('.$group_properties['name'].')';
962939
}
963-
964940
$moveForm = '';
965-
966-
/* MOVE FILE OR DIRECTORY */
941+
/* MOVE FILE OR DIRECTORY */
967942
//Only teacher and all users into their group and each user into his/her shared folder
968943
if ($isAllowedToEdit || $group_member_with_upload_rights ||
969944
DocumentManager::is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId) ||
@@ -1066,8 +1041,19 @@ function convertModal (id, format) {
10661041
$doc_id = $moveFile;
10671042
DocumentManager::updateDBInfoCloudLink($document_to_move['path'], $moveTo.'/', $doc_id);
10681043

1069-
//update database item property
1070-
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FileMoved', api_get_user_id(), $to_group_id, null, null, null, $session_id);
1044+
// Update database item property
1045+
api_item_property_update(
1046+
$_course,
1047+
TOOL_DOCUMENT,
1048+
$doc_id,
1049+
'FileMoved',
1050+
api_get_user_id(),
1051+
$to_group_id,
1052+
null,
1053+
null,
1054+
null,
1055+
$session_id
1056+
);
10711057
Display::addFlash(
10721058
Display::return_message(
10731059
get_lang('CloudLinkMoved'),
@@ -1157,7 +1143,7 @@ function convertModal (id, format) {
11571143
}
11581144
}
11591145

1160-
/* DELETE FILE OR DIRECTORY */
1146+
/* DELETE FILE OR DIRECTORY */
11611147
//Only teacher and all users into their group
11621148
if ($isAllowedToEdit ||
11631149
$group_member_with_upload_rights ||
@@ -1294,8 +1280,7 @@ function convertModal (id, format) {
12941280
}
12951281

12961282
$dirForm = '';
1297-
1298-
/* CREATE DIRECTORY */
1283+
/* CREATE DIRECTORY */
12991284
//Only teacher and all users into their group and any user into his/her shared folder
13001285
if ($isAllowedToEdit ||
13011286
$group_member_with_upload_rights ||
@@ -1305,7 +1290,6 @@ function convertModal (id, format) {
13051290
if (isset($_POST['create_dir']) && $_POST['dirname'] != '') {
13061291
// Needed for directory creation
13071292
$post_dir_name = $_POST['dirname'];
1308-
13091293
if ($post_dir_name == '../' || $post_dir_name == '.' || $post_dir_name == '..') {
13101294
$message = Display::return_message(get_lang('CannotCreateDir'), 'error');
13111295
} else {
@@ -1331,7 +1315,7 @@ function convertModal (id, format) {
13311315
}
13321316
$curdirpath = $document_data['path'];
13331317
}
1334-
$added_slash = ($curdirpath == '/') ? '' : '/';
1318+
$added_slash = $curdirpath == '/' ? '' : '/';
13351319
$dir_name = $curdirpath.$added_slash.api_replace_dangerous_char($post_dir_name);
13361320
$dir_name = disable_dangerous_file($dir_name);
13371321
$dir_check = $base_work_dir.$dir_name;
@@ -1370,7 +1354,7 @@ function convertModal (id, format) {
13701354
}
13711355
}
13721356

1373-
/* VISIBILITY COMMANDS */
1357+
/* VISIBILITY COMMANDS */
13741358
if ($isAllowedToEdit) {
13751359
if ((isset($_GET['set_invisible']) && !empty($_GET['set_invisible'])) ||
13761360
(isset($_GET['set_visible']) && !empty($_GET['set_visible']))
@@ -1424,7 +1408,7 @@ function convertModal (id, format) {
14241408
}
14251409
$templateForm = '';
14261410

1427-
/* TEMPLATE ACTION */
1411+
/* TEMPLATE ACTION */
14281412
//Only teacher and all users into their group
14291413
if ($isAllowedToEdit ||
14301414
$group_member_with_upload_rights ||
@@ -1547,7 +1531,7 @@ function convertModal (id, format) {
15471531
}
15481532
}
15491533

1550-
/* GET ALL DOCUMENT DATA FOR CURDIRPATH */
1534+
/* GET ALL DOCUMENT DATA FOR CURDIRPATH */
15511535
if (isset($_GET['keyword']) && !empty($_GET['keyword'])) {
15521536
$documentAndFolders = DocumentManager::get_all_document_data(
15531537
$courseInfo,
@@ -1597,23 +1581,21 @@ function convertModal (id, format) {
15971581
$folders = [];
15981582
}
15991583
$btngroup = ['class' => 'btn btn-default'];
1600-
16011584
/* GO TO PARENT DIRECTORY */
16021585
$actionsLeft = '';
1603-
16041586
if ($curdirpath != '/' &&
16051587
$curdirpath != $group_properties['directory'] &&
16061588
!$is_certificate_mode
16071589
) {
1608-
$actionsLeft = '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$parent_id.'">';
1590+
$actionsLeft = '<a href="'.api_get_self().'?'.api_get_cidreq().'&id='.$parent_id.$certificateLink.'">';
16091591
$actionsLeft .= Display::return_icon('folder_up.png', get_lang('Up'), '', ICON_SIZE_MEDIUM);
16101592
$actionsLeft .= '</a>';
16111593
}
16121594

16131595
if ($is_certificate_mode && $curdirpath != '/certificates') {
16141596
$actionsLeft .= Display::url(
16151597
Display::return_icon('folder_up.png', get_lang('Up'), '', ICON_SIZE_MEDIUM),
1616-
api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath
1598+
api_get_self().'?'.api_get_cidreq().'&id='.$parent_id.$certificateLink
16171599
);
16181600
}
16191601

@@ -1722,10 +1704,7 @@ function convertModal (id, format) {
17221704
);
17231705
}
17241706

1725-
/*echo '<a href="#" id="jcapture">';
1726-
echo Display::display_icon('capture.png', get_lang('CatchScreenCasts'), '', ICON_SIZE_MEDIUM).'</a>';*/
1727-
1728-
if ($capturePluginInstalled) {
1707+
if ($capturePluginInstalled && !$is_certificate_mode) {
17291708
$actionsLeft .= '<span id="appletplace"></span>';
17301709
$actionsLeft .= Display::url(
17311710
Display::return_icon('capture.png', get_lang('CatchScreenCasts'), '', ICON_SIZE_MEDIUM),
@@ -1744,22 +1723,22 @@ function convertModal (id, format) {
17441723

17451724
// "Add cloud link" icon
17461725
$fileLinkEnabled = api_get_configuration_value('enable_add_file_link');
1747-
if ($fileLinkEnabled) {
1726+
if ($fileLinkEnabled && !$is_certificate_mode) {
17481727
$actionsLeft .= Display::url(
17491728
Display::return_icon('clouddoc_new.png', get_lang('AddCloudLink'), '', ICON_SIZE_MEDIUM),
17501729
api_get_path(WEB_CODE_PATH).'document/add_link.php?'.api_get_cidreq().'&id='.$document_id
17511730
);
17521731
}
17531732
}
17541733
require 'document_slideshow.inc.php';
1755-
if (!isset($_GET['keyword'])) {
1734+
if (!isset($_GET['keyword']) && !$is_certificate_mode) {
17561735
$actionsLeft .= Display::url(
17571736
Display::return_icon('slideshow.png', get_lang('ViewSlideshow'), '', ICON_SIZE_MEDIUM),
17581737
api_get_path(WEB_CODE_PATH).'document/slideshow.php?'.api_get_cidreq().'&curdirpath='.$curdirpathurl
17591738
);
17601739
}
17611740

1762-
if ($isAllowedToEdit) {
1741+
if ($isAllowedToEdit && !$is_certificate_mode) {
17631742
$actionsLeft .= Display::url(
17641743
Display::return_icon('percentage.png', get_lang('DocumentQuota'), '', ICON_SIZE_MEDIUM),
17651744
api_get_path(WEB_CODE_PATH).'document/document_quota.php?'.api_get_cidreq()
@@ -1777,9 +1756,9 @@ function convertModal (id, format) {
17771756
FormValidator::LAYOUT_INLINE
17781757
);
17791758
$form->addText('keyword', '', false, ['class' => 'col-md-2']);
1780-
$form->addElement('hidden', 'cidReq', api_get_course_id());
1781-
$form->addElement('hidden', 'id_session', api_get_session_id());
1782-
$form->addElement('hidden', 'gidReq', $groupId);
1759+
$form->addHidden('cidReq', api_get_course_id());
1760+
$form->addHidden('id_session', api_get_session_id());
1761+
$form->addHidden('gidReq', $groupId);
17831762
$form->addButtonSearch(get_lang('Search'));
17841763
$actionsRight = $form->returnForm();
17851764
}
@@ -1794,7 +1773,6 @@ function convertModal (id, format) {
17941773
);
17951774

17961775
$getSizeURL = api_get_path(WEB_AJAX_PATH).'document.ajax.php?a=get_dir_size&'.api_get_cidreq();
1797-
17981776
if (isset($documentAndFolders) && is_array($documentAndFolders)) {
17991777
if ($groupId == 0 || $userAccess) {
18001778
$count = 1;
@@ -1813,19 +1791,15 @@ function convertModal (id, format) {
18131791
false,
18141792
$userIsSubscribed
18151793
);
1816-
18171794
$invisibility_span_open = ($is_visible == 0) ? '<span class="muted">' : '';
18181795
$invisibility_span_close = ($is_visible == 0) ? '</span>' : '';
1819-
18201796
$size = 1;
1821-
18221797
// Get the title or the basename depending on what we're using
18231798
if ($document_data['title'] != '') {
18241799
$document_name = $document_data['title'];
18251800
} else {
18261801
$document_name = basename($document_data['path']);
18271802
}
1828-
18291803
$row['name'] = $document_name;
18301804
// Data for checkbox
18311805
if (($isAllowedToEdit || $group_member_with_upload_rights) && count($documentAndFolders) > 1) {
@@ -1867,7 +1841,8 @@ function convertModal (id, format) {
18671841
$count,
18681842
$is_visible,
18691843
$size,
1870-
$isAllowedToEdit
1844+
$isAllowedToEdit,
1845+
$is_certificate_mode
18711846
);
18721847

18731848
$path_info = pathinfo($document_data['path']);
@@ -1887,7 +1862,8 @@ function convertModal (id, format) {
18871862
null,
18881863
$is_visible,
18891864
$size,
1890-
$isAllowedToEdit
1865+
$isAllowedToEdit,
1866+
$is_certificate_mode
18911867
);
18921868

18931869
// Document title with link

main/document/upload.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,20 @@ function setFocus() {
153153
$nameTools = get_lang('UplUploadDocument').$add_group_to_title;
154154
}
155155

156+
$certificateLink = '';
157+
if ($is_certificate_mode) {
158+
$certificateLink = '&certificate=true';
159+
}
160+
156161
// Breadcrumbs
157162
if ($is_certificate_mode) {
158163
$interbreadcrumb[] = [
159-
'url' => '../gradebook/index.php?'.api_get_cidreq(),
164+
'url' => '../gradebook/index.php?'.api_get_cidreq().$certificateLink,
160165
'name' => get_lang('Gradebook'),
161166
];
162167
} else {
163168
$interbreadcrumb[] = [
164-
'url' => './document.php?id='.$document_id.'&'.api_get_cidreq(),
169+
'url' => './document.php?id='.$document_id.'&'.api_get_cidreq().$certificateLink,
165170
'name' => get_lang('Documents'),
166171
];
167172
}
@@ -173,7 +178,7 @@ function setFocus() {
173178
} else {
174179
foreach ($document_data['parents'] as $document_sub_data) {
175180
$interbreadcrumb[] = [
176-
'url' => $document_sub_data['document_url'],
181+
'url' => $document_sub_data['document_url'].$certificateLink,
177182
'name' => $document_sub_data['title']
178183
];
179184
}
@@ -199,7 +204,7 @@ function setFocus() {
199204
true
200205
);
201206

202-
$redirectUrl = api_get_self().'?'.api_get_cidreq();
207+
$redirectUrl = api_get_self().'?'.api_get_cidreq().$certificateLink;
203208

204209
if ($document_data) {
205210
$redirectUrl .= '&'.http_build_query(
@@ -244,7 +249,7 @@ function setFocus() {
244249
);
245250
}
246251

247-
$action = api_get_self().'?'.api_get_cidreq().'&id='.$document_id;
252+
$action = api_get_self().'?'.api_get_cidreq().'&id='.$document_id.$certificateLink;
248253

249254
$form = new FormValidator(
250255
'upload',

0 commit comments

Comments
 (0)