Passed
Push — master ( 1ad423...6f484e )
by Yannick
08:39
created

public/main/session/session_course_list.php (1 issue)

Labels
Severity
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
$cidReset = true;
6
7
require_once __DIR__.'/../inc/global.inc.php';
8
9
// setting the section (for the tabs)
10
$this_section = SECTION_PLATFORM_ADMIN;
11
12
$id_session = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0;
13
$session = api_get_session_entity($id_session);
14
SessionManager::protectSession($session);
15
16
// Database Table Definitions
17
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
18
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
19
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
20
$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
21
22
if (empty($id_session)) {
23
    api_not_allowed();
24
}
25
26
$page = isset($_GET['page']) ? intval($_GET['page']) : 0;
27
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
28
$sort = isset($_GET['sort']) && in_array($_GET['sort'], ['title', 'nbr_users']) ? $_GET['sort'] : 'title';
29
30
$result = Database::query("SELECT name FROM $tbl_session WHERE id='$id_session'");
31
32
if (!list($session_name) = Database::fetch_row($result)) {
33
    header('Location: session_list.php');
34
    exit;
35
}
36
37
if ('delete' == $action) {
38
    $idChecked = $_REQUEST['idChecked'];
39
    if (is_array($idChecked) && count($idChecked) > 0) {
40
        $my_temp = [];
41
        foreach ($idChecked as $id) {
42
            $my_temp[] = Database::escape_string($id); // forcing the escape_string
43
        }
44
        $idChecked = $my_temp;
45
        $idChecked = "'".implode("','", $idChecked)."'";
46
        $result = Database::query("DELETE FROM $tbl_session_rel_course WHERE session_id='$id_session' AND c_id IN($idChecked)");
47
        $nbr_affected_rows = Database::affected_rows($result);
48
        Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE session_id='$id_session' AND c_id IN($idChecked)");
49
        Database::query("UPDATE $tbl_session SET nbr_courses=nbr_courses-$nbr_affected_rows WHERE id='$id_session'");
50
    }
51
    header('Location: '.api_get_self().'?id_session='.$id_session.'&sort='.$sort);
52
    exit();
53
}
54
55
$limit = 20;
56
$from = $page * $limit;
57
58
$sql = "SELECT c.id, c.code, c.title, nbr_users
59
		FROM $tbl_session_rel_course, $tbl_course c
60
		WHERE c_id = c.id AND session_id='$id_session'
61
		ORDER BY `$sort`
62
		LIMIT $from,".($limit + 1);
63
$result = Database::query($sql);
64
$Courses = Database::store_result($result);
65
$tool_name = api_htmlentities($session_name, ENT_QUOTES, $charset).' : '.get_lang('Courses in this session');
0 ignored issues
show
Are you sure api_htmlentities($sessio..., ENT_QUOTES, $charset) of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
$tool_name = /** @scrutinizer ignore-type */ api_htmlentities($session_name, ENT_QUOTES, $charset).' : '.get_lang('Courses in this session');
Loading history...
66
67
$interbreadcrumb[] = ['url' => "session_list.php", "name" => get_lang('Session list')];
68
$interbreadcrumb[] = ['url' => "resume_session.php?id_session=".Security::remove_XSS($_REQUEST['id_session']), "name" => get_lang('Session overview')];
69
70
Display::display_header($tool_name);
71
echo Display::page_header($tool_name);
72
?>
73
<form method="post" action="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&sort=<?php echo $sort; ?>" onsubmit="javascript:if(!confirm('<?php echo get_lang('Please confirm your choice'); ?>')) return false;">
74
<?php
75
$tableHeader = [];
76
$tableHeader[] = [' '];
77
$tableHeader[] = [get_lang('Course title')];
78
$tableHeader[] = [get_lang('Users')];
79
$tableHeader[] = [get_lang('Detail')];
80
81
$tableCourses = [];
82
83
foreach ($Courses as $key => $enreg) {
84
    $course = [];
85
    $course[] = '<input type="checkbox" name="idChecked[]" value="'.$enreg['id'].'">';
86
    $course[] = api_htmlentities($enreg['title'], ENT_QUOTES, $charset);
87
    $course[] = '<a href="session_course_user_list.php?id_session='.$id_session.'&course_code='.$enreg['code'].'">'.$enreg['nbr_users'].' '.get_lang('Users').'</a>';
88
    $course[] = '<a href="'.api_get_path(WEB_COURSE_PATH).$enreg['code'].'/?id_session='.$id_session.'">'.
89
        Display::return_icon('course_home.png', get_lang('Course')).'</a>
90
			<a href="session_course_edit.php?id_session='.$id_session.'&page=session_course_list.php&course_code='.$enreg['code'].'">'.
91
        Display::return_icon('edit.png', get_lang('Edit')).'</a>
92
			<a href="'.api_get_self().'?id_session='.$id_session.'&sort='.$sort.'&action=delete&idChecked[]='.$enreg['id'].'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("Please confirm your choice"), ENT_QUOTES, $charset)).'\')) return false;">'.
93
        Display::return_icon('delete.png', get_lang('Delete')).'</a>';
94
    $tableCourses[] = $course;
95
}
96
echo '<form method="post" action="'.api_get_self().'">';
97
Display :: display_sortable_table($tableHeader, $tableCourses, [], []);
98
echo '<select name="action">
99
	<option value="delete">'.get_lang('Unsubscribe selected courses from this session').'</option>
100
	</select>
101
	<button class="save" type="submit">'.get_lang('Validate').'</button>
102
	</form>';
103
Display::display_footer();
104