Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.11.x' into 1.11.x
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Oct 4, 2024
2 parents 3093621 + a454244 commit f2f7262
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 33 deletions.
86 changes: 79 additions & 7 deletions main/admin/add_users_to_usergroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,44 @@ function change_select(reset) {
});
}
</script>';
$htmlHeadXtra[] = '
<script>
$(document).ready(function() {
function showLastTenUsers() {
var selectedUsers = [];
$("#elements_in option").each(function() {
selectedUsers.push($(this).val());
});
var groupId = "'.$id.'";
$.ajax({
type: "POST",
url: "'.api_get_self().'",
data: {
action: "get_last_ten_users",
excludedUsers: selectedUsers,
id: groupId
},
dataType: "json",
success: function(data) {
var select = document.getElementById("elements_not_in");
select.innerHTML = "";
$.each(data, function(index, user) {
select.append(new Option(user.username + " - " + user.firstname + " " + user.lastname, user.id));
});
},
error: function(xhr, status, error) {
console.error("Error en la solicitud AJAX: " + status + " - " + error);
}
});
}
$("#show_last_ten_users_button").click(function() {
showLastTenUsers();
});
});
</script>';

$form_sent = 0;
Expand All @@ -133,6 +171,35 @@ function change_select(reset) {
api_not_allowed(true);
}

if (ChamiloApi::isAjaxRequest() && $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'get_last_ten_users') {
$excludedUsers = isset($_POST['excludedUsers']) ? $_POST['excludedUsers'] : [];
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;

$excludedIds = !empty($excludedUsers) ? implode(",", array_map('intval', $excludedUsers)) : '0';
$sql = 'SELECT id, username, firstname, lastname
FROM user
WHERE status != '.ANONYMOUS.'
AND id NOT IN ('.$excludedIds.')
ORDER BY id DESC
LIMIT 10';

$result = Database::query($sql);
$users = [];

while ($user = Database::fetch_array($result)) {
$users[] = [
'id' => $user['id'],
'username' => $user['username'],
'firstname' => $user['firstname'],
'lastname' => $user['lastname']
];
}

header('Content-Type: application/json');
echo json_encode($users);
die();
}

$first_letter_user = '';

if ((isset($_POST['form_sent']) && $_POST['form_sent']) || isset($_REQUEST['firstLetterUser'])) {
Expand Down Expand Up @@ -453,13 +520,18 @@ function formatCompleteName(array $userInfo, bool $orderListByOfficialCode): str
placeholder="<?php echo get_lang('Search'); ?>"
onkeydown="return 13 !== event.keyCode;">
<span class="input-group-btn">
<button class="btn btn-default" type="button" onclick="change_select();">
<?php echo get_lang('Filter'); ?>
</button>
<button class="btn btn-default" type="button" onclick="change_select(true);">
<?php echo get_lang('Reset'); ?>
</button>
</span>
<button class="btn btn-default" type="button" onclick="change_select();">
<?php echo get_lang('Filter'); ?>
</button>
<button class="btn btn-default" type="button" onclick="change_select(true);">
<?php echo get_lang('Reset'); ?>
</button>
</span>
<span class="input-group-btn">
<button class="btn btn-default" type="button" id="show_last_ten_users_button" title="<?php echo get_lang('ShowLastTenUsers') ?>">
<i class="fa fa-clock-o"></i>
</button>
</span>
</div>
</div>
<?php
Expand Down
14 changes: 13 additions & 1 deletion main/auth/sort_my_courses.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,19 @@
$user_course_categories = CourseManager::get_user_course_categories(api_get_user_id());
$courses_in_category = $auth->getCoursesInCategory(false);

$action = isset($_REQUEST['action']) ? Security::remove_XSS($_REQUEST['action']) : '';
// Only authorized actions
$authorizedActions = [
'edit_category',
'edit_course_category',
'deletecoursecategory',
'createcoursecategory',
'set_collapsable',
'unsubscribe'
];
if (in_array(trim($_REQUEST['action']), $authorizedActions)) {
$action = trim($_REQUEST['action']);
}

$currentUrl = api_get_self();

$interbreadcrumb[] = [
Expand Down
10 changes: 6 additions & 4 deletions main/document/document.php
Original file line number Diff line number Diff line change
Expand Up @@ -1785,10 +1785,12 @@ function convertModal (id, format) {
.'&id='.$current_folder_id.'&certificate=true'
);
} else {
$actionsLeft .= Display::url(
Display::return_icon('upload_file.png', get_lang('UplUploadDocument'), '', ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'document/upload.php?'.api_get_cidreq().'&id='.$current_folder_id
);
if (!(api_get_configuration_value('session_hide_document_upload') === true && (isset($sessionId) && $sessionId != 0))) {
$actionsLeft .= Display::url(
Display::return_icon('upload_file.png', get_lang('UplUploadDocument'), '', ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'document/upload.php?'.api_get_cidreq().'&id='.$current_folder_id
);
}
}

// Create directory
Expand Down
7 changes: 7 additions & 0 deletions main/install/configuration.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2565,6 +2565,13 @@
// Define the default time in seconds to be registered if the user does logout from a course and there is no recent entry in track_e_course_access.
//$_configuration['tracking_default_course_extra_time_on_logout'] = 600;

// Set to true to hide lp creation icon on lp list if in a session
//$_configuration['session_hide_lp_creation'] = false;
// Set to true to hide lp copy icon on lp list if in a session
//$_configuration['session_hide_lp_copy'] = false;
// Set to true to hide document upload icon on document list if in a session
//$_configuration['session_hide_document_upload'] = false;

// Define a special path token for the Common Cartridge export content.
// Due to changes in naming by the responsible organization, the Chamilo default
// is '$1EdTech-CC-FILEBASE$' (the latest), but previous versions of the standard
Expand Down
41 changes: 22 additions & 19 deletions main/lp/lp_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,26 @@ function confirmation(name) {

if ($is_allowed_to_edit) {
$actionLeft = '';
$actionLeft .= Display::url(
Display::return_icon(
'new_learnpath.png',
get_lang('LearnpathAddLearnpath'),
'',
ICON_SIZE_MEDIUM
),
api_get_self().'?'.api_get_cidreq().'&action=add_lp'
);
$actionLeft .= Display::url(
Display::return_icon(
'import_scorm.png',
get_lang('UploadScorm'),
'',
ICON_SIZE_MEDIUM
),
'../upload/index.php?'.api_get_cidreq().'&curdirpath=/&tool='.TOOL_LEARNPATH
);
if (!(api_get_configuration_value('session_hide_lp_creation') === true && (isset($sessionId) && $sessionId != 0))) {
$actionLeft .= Display::url(
Display::return_icon(
'new_learnpath.png',
get_lang('LearnpathAddLearnpath'),
'',
ICON_SIZE_MEDIUM
),
api_get_self().'?'.api_get_cidreq().'&action=add_lp'
);
$actionLeft .= Display::url(
Display::return_icon(
'import_scorm.png',
get_lang('UploadScorm'),
'',
ICON_SIZE_MEDIUM
),
'../upload/index.php?'.api_get_cidreq().'&curdirpath=/&tool='.TOOL_LEARNPATH
);
}

if (api_get_setting('service_ppt2lp', 'active') === 'true') {
$actionLeft .= Display::url(
Expand Down Expand Up @@ -200,6 +202,7 @@ function confirmation(name) {
$hideScormExportLink = api_get_setting('hide_scorm_export_link');
$hideScormCopyLink = api_get_setting('hide_scorm_copy_link');
$hideScormPdfLink = api_get_setting('hide_scorm_pdf_link');
$hideLpCopyInSession = (api_get_configuration_value('session_hide_lp_copy') === true && (isset($sessionId) && $sessionId != 0));
$options = learnpath::getIconSelect();
$cidReq = api_get_cidreq();

Expand Down Expand Up @@ -925,7 +928,7 @@ function confirmation(name) {
$dsp_disk = null;
}

if ($hideScormCopyLink === 'true') {
if ($hideScormCopyLink === 'true' || $hideLpCopyInSession) {
$copy = null;
}

Expand Down
119 changes: 117 additions & 2 deletions main/session/add_users_to_session.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @package chamilo.admin
*/
// resetting the course id
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;

$cidReset = true;

require_once __DIR__.'/../inc/global.inc.php';
Expand All @@ -14,8 +16,8 @@
// setting the section (for the tabs)
$this_section = SECTION_PLATFORM_ADMIN;

$id_session = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0;
$addProcess = isset($_GET['add']) && 'true' === $_GET['add'] ? 'true' : null;
$id_session = isset($_REQUEST['id_session']) ? (int) $_REQUEST['id_session'] : 0;
$addProcess = isset($_REQUEST['add']) && 'true' === $_REQUEST['add'] ? 'true' : null;

SessionManager::protectSession($id_session);

Expand Down Expand Up @@ -65,6 +67,40 @@
}
}

if (ChamiloApi::isAjaxRequest() && isset($_POST['action'])) {
$id_session = isset($_POST['id_session']) ? (int) $_POST['id_session'] : 0;
$excludedUsers = isset($_POST['excludedUsers']) ? $_POST['excludedUsers'] : [];

$excludedUsersList = count($excludedUsers) > 0 ? implode(",", array_map('intval', $excludedUsers)) : '0';

if ($_POST['action'] == 'get_last_ten_users') {
$sql = "SELECT u.id, u.username, u.firstname, u.lastname
FROM $tbl_user u
LEFT JOIN $tbl_session_rel_user sru ON (u.id = sru.user_id AND sru.session_id = $id_session)
WHERE sru.user_id IS NULL
AND u.id NOT IN ($excludedUsersList)
ORDER BY u.id DESC
LIMIT 10";
} elseif ($_POST['action'] == 'get_all_users') {
$sql = "SELECT u.id, u.username, u.firstname, u.lastname
FROM $tbl_user u
LEFT JOIN $tbl_session_rel_user sru ON (u.id = sru.user_id AND sru.session_id = $id_session)
WHERE sru.user_id IS NULL
AND u.id NOT IN ($excludedUsersList)
ORDER BY u.lastname ASC, u.firstname ASC";
}

$result = Database::query($sql);
$users = [];
while ($row = Database::fetch_assoc($result)) {
$users[] = $row;
}

header('Content-Type: application/json');
echo json_encode($users);
die();
}

function search_users($needle, $type)
{
global $id_session;
Expand Down Expand Up @@ -304,6 +340,77 @@ function change_select(val) {
xajax_search_users(val,"multiple");
}
</script>';
$htmlHeadXtra[] = '
<script>
function showLastTenUsers() {
var selectedUsers = [];
$("#destination_users option").each(function() {
selectedUsers.push($(this).val());
});
if (selectedUsers.length === 0) {
selectedUsers.push(0);
}
var idSession = "'.(int) $id_session.'";
$.post("'.api_get_self().'",
{
action: "get_last_ten_users",
excludedUsers: selectedUsers,
id_session: idSession,
add: "",
add_type: "multiple"
}, function(data) {
console.log(data);
var select = document.getElementById("origin_users");
select.innerHTML = "";
$.each(data, function(index, user) {
select.append(new Option(user.username + " - " + user.firstname + " " + user.lastname, user.id));
});
}, "json").fail(function(xhr, status, error) {
console.error("Error en la solicitud AJAX: " + error);
console.log(xhr.responseText);
});
}
function loadAllUsers() {
var selectedUsers = [];
$("#destination_users option").each(function() {
selectedUsers.push($(this).val());
});
if (selectedUsers.length === 0) {
selectedUsers.push(0);
}
var idSession = "'.(int) $id_session.'";
$.post("'.api_get_self().'",
{
action: "get_all_users",
excludedUsers: selectedUsers,
id_session: idSession,
add: "",
add_type: "multiple"
}, function(data) {
var select = document.getElementById("origin_users");
select.innerHTML = "";
$.each(data, function(index, user) {
select.append(new Option(user.username + " - " + user.firstname + " " + user.lastname, user.id));
});
}, "json").fail(function(xhr, status, error) {
console.error("Error en la solicitud AJAX: " + error);
});
}
$(document).ready(function() {
loadAllUsers();
$("#show_last_ten_users_button").on("click", showLastTenUsers);
$("#reset_users_button").on("click", loadAllUsers);
});
</script>
';

$form_sent = 0;
$errorMsg = $firstLetterUser = $firstLetterSession = '';
Expand Down Expand Up @@ -691,6 +798,14 @@ class="form-control">
<?php
echo Display::get_alphabet_options(); ?>
</select>
<span class="input-group-btn">
<button class="btn btn-default" type="button" id="show_last_ten_users_button" title="<?php echo get_lang('ShowLastTenUsers') ?>">
<i class="fa fa-clock-o"></i>
</button>
<button class="btn btn-default" type="button" id="reset_users_button" title="<?php echo get_lang('Reset') ?>">
<i class="fa fa-refresh"></i>
</button>
</span>
<br/>
<br/>
<?php
Expand Down

0 comments on commit f2f7262

Please sign in to comment.