Skip to content

Commit 5e462b6

Browse files
committed
Merge branch 'master' of github.com:chamilo/chamilo-lms
2 parents 4185ef4 + bc850cd commit 5e462b6

File tree

13 files changed

+303
-89
lines changed

13 files changed

+303
-89
lines changed

public/main/admin/languages.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@
5959
var disabledLang = "'.$disabledLang.'"
6060
6161
if (msgLang == 1) {
62-
$("#id_content_message").html("<div class=\"warning-message alert alert-warning\">'.get_lang('There are users currently using the following language. Please disable manually.').' <br /> " + disabledLang + "</div");
62+
$("#id_content_message").html("<div class=\"warning-message alert alert-warning\">'.addslashes(get_lang('There are users currently using the following language. Please disable manually.')).' <br /> " + disabledLang + "</div");
6363
}
6464
6565
$("#disable_all_except_default").click(function () {
66-
if(confirm("'.get_lang('Please confirm your choice').'")) {
66+
if(confirm("'.addslashes(get_lang('Please confirm your choice')).'")) {
6767
$.ajax({
6868
contentType: "application/x-www-form-urlencoded",
6969
beforeSend: function(myObject) {
70-
$("#id_content_message").html("<div class=\"warning-message alert alert-warning\"><em class=\"fa fa-refresh fa-spin\"></em> '.get_lang('Loading').'</div>");
70+
$("#id_content_message").html("<div class=\"warning-message alert alert-warning\"><em class=\"fa fa-refresh fa-spin\"></em> '.addslashes(get_lang('Loading')).'</div>");
7171
},
7272
type: "GET",
7373
url: "../admin/languages.php",
@@ -93,7 +93,7 @@
9393
url: "../admin/languages.php",
9494
data: { id: link_id, visibility: currentIcon.hasClass("mdi-toggle-switch") ? 0 : 1, sent_http_request: 1 },
9595
beforeSend: function() {
96-
$("#id_content_message").html("<div class=\'warning-message alert alert-warning\'><em class=\'fa fa-refresh fa-spin\'></em>'.get_lang('Loading'). '...</div>");
96+
$("#id_content_message").html("<div class=\'warning-message alert alert-warning\'><em class=\'fa fa-refresh fa-spin\'></em>'.addslashes(get_lang('Loading')). '...</div>");
9797
},
9898
success: function(response) {
9999
if (response === "set_visible" || response === "set_hidden") {
@@ -229,7 +229,7 @@
229229
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Administration')];
230230

231231
// displaying the explanation for this tool
232-
Display::addFlash(Display::return_message(get_lang('Chamilo Portal LanguagesExplanation'), 'normal'));
232+
Display::addFlash(Display::return_message(get_lang('This tool manages the language selection menu on the login page. As a platform administrator you can decide which languages should be available for your users.'), 'normal'));
233233

234234
// including the header file (which includes the banner itself)
235235
Display::display_header($tool_name);

public/main/announcements/announcements.php

Lines changed: 81 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,21 @@
404404

405405
$to = [];
406406
if (empty($group_id)) {
407+
if (!empty($sessionId)) {
408+
$userGroups = Container::getUsergroupRepository()->findBySession($session);
409+
$groupSelectTitle = get_lang('Classes of session').' '.$session->getTitle();
410+
} else {
411+
$userGroups = Container::getUsergroupRepository()->findByCourse($course);
412+
$groupSelectTitle = get_lang('Classes of course');
413+
}
414+
415+
if (!empty($userGroups)) {
416+
$groupSelect = ['' => get_lang('Select a class')];
417+
foreach ($userGroups as $group) {
418+
$groupSelect[$group->getId()] = $group->getTitle();
419+
}
420+
$form->addSelect('usergroup_id', $groupSelectTitle, $groupSelect, ['id' => 'usergroup_id']);
421+
}
407422
if (isset($_GET['remind_inactive'])) {
408423
$email_ann = '1';
409424
$content_to_modify = sprintf(
@@ -508,41 +523,88 @@
508523
}
509524

510525
$ajaxUrl = api_get_path(WEB_AJAX_PATH).'announcement.ajax.php?'.api_get_cidreq().'&a=preview';
511-
526+
$ajaxUserGroupUrl = api_get_path(WEB_AJAX_PATH).'usergroup.ajax.php?'.api_get_cidreq();
512527
$form->addHtml("
513-
<script>
514-
$(function () {
515-
$('#announcement_preview').on('click', function() {
528+
<script>
529+
$(function () {
530+
$('#usergroup_id').on('change', function () {
531+
const groupId = $(this).val();
532+
const selected = $('#users_to');
533+
selected.empty();
534+
if (!groupId) return;
535+
$.ajax({
536+
url: '".$ajaxUserGroupUrl."',
537+
type: 'POST',
538+
data: {
539+
a: 'get_users_by_group_course',
540+
group_id: groupId,
541+
course_code: '".api_get_course_id()."',
542+
session_id: '".api_get_session_id()."'
543+
},
544+
success: function (response) {
545+
const result = JSON.parse(response);
546+
for (let user of result) {
547+
selected.append(new Option(user.name, 'USER:' + user.id));
548+
}
549+
$('#announcement_preview_result').html('');
550+
}
551+
})
552+
});
553+
554+
$('#announcement_preview').on('click', function () {
555+
const selectedClass = $('#usergroup_id').val();
556+
if (selectedClass) {
516557
var users = [];
517-
$('#users_to option').each(function() {
558+
var userLabels = [];
559+
$('#users_to option').each(function () {
518560
users.push($(this).val());
561+
userLabels.push($(this).text());
519562
});
520-
563+
if (users.length === 0) {
564+
$('#announcement_preview_result').html('');
565+
$('#announcement_preview_result').show();
566+
return;
567+
}
568+
var resultHtml = '<strong>".addslashes(get_lang('Announcement will be sent to'))."</strong><ul>';
569+
userLabels.forEach(function (name) {
570+
resultHtml += '<li>' + name + '</li>';
571+
});
572+
resultHtml += '</ul>';
573+
$('#announcement_preview_result').html(resultHtml);
574+
$('#announcement_preview_result').show();
575+
$('#send_button').show();
576+
} else {
577+
var users = [];
521578
var form = $('#announcement').serialize();
579+
$('#users_to option').each(function () {
580+
users.push($(this).val());
581+
});
522582
$.ajax({
523583
type: 'POST',
524584
dataType: 'json',
525-
url: '".$ajaxUrl."',
526-
data: {users : JSON.stringify(users), form: form},
527-
beforeSend: function() {
585+
url: '" . $ajaxUrl . "',
586+
data: {users: JSON.stringify(users), form: form},
587+
beforeSend: function () {
528588
$('#announcement_preview_result').html('<i class=\"fa fa-spinner\"></i>');
529589
$('#send_button').hide();
530590
},
531-
success: function(result) {
532-
var resultToString = '';
533-
$.each(result, function(index, value) {
534-
resultToString += '&nbsp;' + value;
535-
});
536-
$('#announcement_preview_result').html('' +
537-
'".addslashes(get_lang('Announcement will be sent to'))."<br/>' + resultToString
591+
success: function (result) {
592+
let list = '<ul>';
593+
for (let name of result) {
594+
list += '<li>' + name + '</li>';
595+
}
596+
list += '</ul>';
597+
$('#announcement_preview_result').html(
598+
'<strong>".addslashes(get_lang('Announcement will be sent to'))."</strong><br>' + list
538599
);
539600
$('#announcement_preview_result').show();
540601
$('#send_button').show();
541602
}
542603
});
543-
});
604+
}
544605
});
545-
</script>
606+
});
607+
</script>
546608
");
547609

548610
if (isset($defaults['users'])) {
@@ -671,8 +733,7 @@
671733
$notificationPeriod = $data['notification_period'] ?? [];
672734

673735
$reminders = $notificationCount ? array_map(null, $notificationCount, $notificationPeriod) : [];
674-
675-
if (isset($id) && $id) {
736+
if (!empty($id)) {
676737
// there is an Id => the announcement already exists => update mode
677738
$file_comment = $announcementAttachmentIsDisabled ? null : $_POST['file_comment'];
678739
$file = $announcementAttachmentIsDisabled ? [] : $_FILES['user_upload'];

public/main/auth/inscription.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,19 @@
119119
$htmlHeadXtra[] = api_get_password_checker_js('#username', '#pass1');
120120
// User is not allowed if Terms and Conditions are disabled and
121121
// registration is disabled too.
122-
$isNotAllowedHere = ('false' === api_get_setting('allow_terms_conditions') && 'false' === api_get_setting('allow_registration'));
123-
if ($isNotAllowedHere) {
124-
api_not_allowed(true, get_lang('Sorry, you are trying to access the registration page for this portal, but registration is currently disabled. Please contact the administrator (see contact information in the footer). If you already have an account on this site.'));
122+
$isCreatingIntroPage = isset($_GET['create_intro_page']);
123+
$isPlatformAdmin = api_is_platform_admin();
124+
125+
$isNotAllowedHere = (
126+
'false' === api_get_setting('allow_terms_conditions') &&
127+
'false' === api_get_setting('allow_registration')
128+
);
129+
130+
if ($isNotAllowedHere && !($isCreatingIntroPage && $isPlatformAdmin)) {
131+
api_not_allowed(
132+
true,
133+
get_lang('Sorry, you are trying to access the registration page for this portal, but registration is currently disabled. Please contact the administrator (see contact information in the footer). If you already have an account on this site.')
134+
);
125135
}
126136

127137
$settingConditions = api_get_setting('profile.show_conditions_to_user', true);
@@ -633,16 +643,6 @@
633643
$toolName = get_lang('Terms and Conditions');
634644
}
635645

636-
// Forbidden to self-register
637-
if ($isNotAllowedHere) {
638-
api_not_allowed(
639-
true,
640-
get_lang(
641-
'Sorry, you are trying to access the registration page for this portal, but registration is currently disabled. Please contact the administrator (see contact information in the footer). If you already have an account on this site.'
642-
)
643-
);
644-
}
645-
646646
if ('approval' === api_get_setting('allow_registration')) {
647647
$content .= Display::return_message(get_lang('Your account has to be approved'));
648648
}
@@ -658,7 +658,7 @@
658658
// Terms and conditions
659659
$infoMessage = '';
660660
if ('true' === api_get_setting('allow_terms_conditions')) {
661-
if (!api_is_platform_admin()) {
661+
if (!$isPlatformAdmin) {
662662
if ('true' === api_get_setting('ticket.show_terms_if_profile_completed')) {
663663
$userId = api_get_user_id();
664664
if (empty($userId) && isset($termRegistered['user_id'])) {
@@ -1381,7 +1381,7 @@
13811381
. '</div>' . $content;
13821382
}
13831383

1384-
if (isset($_GET['create_intro_page']) && api_is_platform_admin()) {
1384+
if ($isCreatingIntroPage && $isPlatformAdmin) {
13851385
$user = api_get_user_entity();
13861386

13871387
if ($introPage) {

public/main/gradebook/lib/fe/gradebooktable.class.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,15 @@ public function preloadData()
275275
return $defaultData;
276276
}
277277

278+
private function safeScore(array $score = null): array
279+
{
280+
$score = $score ?? [];
281+
return [
282+
$score[0] ?? 0,
283+
$score[1] ?? 1
284+
];
285+
}
286+
278287
/**
279288
* Function used by SortableTable to generate the data to display.
280289
*
@@ -507,18 +516,21 @@ public function get_table_data($from = 1, $perPage = null, $column = null, $dire
507516
$mode = SCORE_AVERAGE;
508517
if ($userExerciseScoreInCategory) {
509518
$mode = SCORE_SIMPLE;
510-
$result = ExerciseLib::convertScoreToPlatformSetting($totalAverage[0], $totalAverage[1]);
519+
list($avgScore, $avgWeight) = $this->safeScore($totalAverage);
520+
$result = ExerciseLib::convertScoreToPlatformSetting($avgScore, $avgWeight);
521+
511522
$totalAverage[0] = $result['score'];
512523
$totalAverage[1] = $result['weight'];
513524

514-
$result = ExerciseLib::convertScoreToPlatformSetting($totalResult[0], $totalResult[1]);
525+
list($resScore, $resWeight) = $this->safeScore($totalResult);
526+
$result = ExerciseLib::convertScoreToPlatformSetting($resScore, $resWeight);
527+
515528
$totalResult[0] = $result['score'];
516529
$totalResult[1] = $result['weight'];
517530

518-
$result = ExerciseLib::convertScoreToPlatformSetting(
519-
$data['result_score'][0],
520-
$data['result_score'][1]
521-
);
531+
list($safeScore, $safeWeight) = $this->safeScore($data['result_score'] ?? []);
532+
$result = ExerciseLib::convertScoreToPlatformSetting($safeScore, $safeWeight);
533+
522534
$data['my_result_no_float'][0] = $result['score'];
523535
}
524536

public/main/inc/ajax/usergroup.ajax.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,47 @@
55
/**
66
* Responses to AJAX calls.
77
*/
8+
9+
use Chamilo\CoreBundle\Framework\Container;
10+
811
require_once __DIR__.'/../global.inc.php';
912

1013
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : '';
1114
$isAllowedToEdit = api_is_allowed_to_edit();
1215

1316
switch ($action) {
17+
case 'get_users_by_group_course':
18+
$groupId = (int) $_POST['group_id'];
19+
$sessionId = (int) $_POST['session_id'];
20+
if ($groupId) {
21+
$users = Container::getUsergroupRepository()->getUsersByGroup($groupId, true);
22+
if (!empty($sessionId)) {
23+
$filtered = [];
24+
foreach ($users as $user) {
25+
$filtered[] = [
26+
'id' => $user['id'],
27+
'name' => api_get_person_name($user['firstname'], $user['lastname']),
28+
];
29+
}
30+
} else {
31+
$courseCode = $_POST['course_code'];
32+
$courseUsers = CourseManager::get_user_list_from_course_code($courseCode, 0);
33+
$courseUserIds = array_column($courseUsers, 'user_id');
34+
35+
$filtered = [];
36+
foreach ($users as $user) {
37+
if (in_array($user['id'], $courseUserIds)) {
38+
$filtered[] = [
39+
'id' => $user['id'],
40+
'name' => api_get_person_name($user['firstname'], $user['lastname']),
41+
];
42+
}
43+
}
44+
}
45+
46+
echo json_encode($filtered);
47+
}
48+
exit;
1449
case 'get_class_by_keyword':
1550
$keyword = isset($_REQUEST['q']) ? $_REQUEST['q'] : '';
1651
if (api_is_platform_admin() && !empty($keyword)) {

public/main/user/class.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,31 +131,26 @@
131131
[
132132
'name' => 'name',
133133
'index' => 'name',
134-
'width' => '35',
135134
'align' => 'left',
136135
],
137136
[
138137
'name' => 'users',
139138
'index' => 'users',
140-
'width' => '15',
141139
'align' => 'left',
142140
],
143141
[
144142
'name' => 'status',
145143
'index' => 'status',
146-
'width' => '15',
147144
'align' => 'left',
148145
],
149146
[
150147
'name' => 'group_type',
151148
'index' => 'group_type',
152-
'width' => '15',
153149
'align' => 'center',
154150
],
155151
[
156152
'name' => 'actions',
157153
'index' => 'actions',
158-
'width' => '10',
159154
'align' => 'center',
160155
'sortable' => 'false',
161156
],

src/CoreBundle/Controller/TemplateController.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,34 @@ private function formatSystemTemplates(array $systemTemplates, AssetRepository $
134134
$imageUrl = $assetRepository->getAssetUrl($template->getImage());
135135
}
136136

137+
$content = $template->getContent();
138+
$content = str_replace('<table', '<table class="responsive-table"', $content);
139+
$content = str_replace(
140+
'{CSS}',
141+
'<style>
142+
.responsive-table {
143+
width: 100%;
144+
max-width: 100%;
145+
overflow-x: auto;
146+
display: block;
147+
border-collapse: collapse;
148+
}
149+
.responsive-table th,
150+
.responsive-table td {
151+
padding: 8px;
152+
text-align: left;
153+
word-wrap: break-word;
154+
border: 1px solid #ccc;
155+
}
156+
</style>',
157+
$content
158+
);
159+
137160
return [
138161
'id' => $template->getId(),
139162
'title' => $template->getTitle(),
140163
'comment' => $template->getComment(),
141-
'content' => $template->getContent(),
164+
'content' => $content,
142165
'image' => $imageUrl,
143166
];
144167
}, $systemTemplates);

0 commit comments

Comments
 (0)