Completed
Push — 1.10.x ( a9323e...dc10cd )
by Angel Fernando Quiroz
124:05 queued 70:15
created

main/admin/course_information.php (4 issues)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/* For licensing terms, see /license.txt */
3
/**
4
 * This script gives information about a course
5
 * @author Bart Mollet
6
 * @package chamilo.admin
7
 */
8
$cidReset = true;
9
require_once '../inc/global.inc.php';
10
$this_section = SECTION_PLATFORM_ADMIN;
11
12
api_protect_admin_script();
13
/**
14
 *
15
 */
16
function get_course_usage($course_code, $session_id = 0)
17
{
18
    $table       = Database::get_main_table(TABLE_MAIN_COURSE);
19
    $course_code = Database::escape_string($course_code);
20
    $sql         = "SELECT * FROM $table WHERE code='".$course_code."'";
21
    $res         = Database::query($sql);
22
    $course      = Database::fetch_object($res);
23
    // Learnpaths
24
    $table   = Database :: get_course_table(TABLE_LP_MAIN);
25
    $usage[] = array(
26
        get_lang(ucfirst(TOOL_LEARNPATH)),
27
        CourseManager::count_rows_course_table($table, $session_id, $course->id)
28
    );
29
    // Forums
30
    $table   = Database :: get_course_table(TABLE_FORUM);
31
    $usage[] = array(get_lang('Forums'), CourseManager::count_rows_course_table($table, $session_id, $course->id));
32
    // Quizzes
33
    $table   = Database :: get_course_table(TABLE_QUIZ_TEST);
34
    $usage[] = array(
35
        get_lang(ucfirst(TOOL_QUIZ)),
36
        CourseManager::count_rows_course_table($table, $session_id, $course->id)
37
    );
38
    // Documents
39
    $table   = Database :: get_course_table(TABLE_DOCUMENT);
40
    $usage[] = array(
41
        get_lang(ucfirst(TOOL_DOCUMENT)),
42
        CourseManager::count_rows_course_table($table, $session_id, $course->id)
43
    );
44
    // Groups
45
    $table   = Database :: get_course_table(TABLE_GROUP);
46
    $usage[] = array(
47
        get_lang(ucfirst(TOOL_GROUP)),
48
        CourseManager::count_rows_course_table($table, $session_id, $course->id)
0 ignored issues
show
Deprecated Code introduced by
The method CourseManager::count_rows_course_table() has been deprecated.

This method has been deprecated.

Loading history...
49
    );
50
    // Calendar
51
    $table   = Database :: get_course_table(TABLE_AGENDA);
52
    $usage[] = array(
53
        get_lang(ucfirst(TOOL_CALENDAR_EVENT)),
54
        CourseManager::count_rows_course_table($table, $session_id, $course->id)
0 ignored issues
show
Deprecated Code introduced by
The method CourseManager::count_rows_course_table() has been deprecated.

This method has been deprecated.

Loading history...
55
    );
56
    // Link
57
    $table   = Database::get_course_table(TABLE_LINK);
58
    $usage[] = array(
59
        get_lang(ucfirst(TOOL_LINK)),
60
        CourseManager::count_rows_course_table($table, $session_id, $course->id)
0 ignored issues
show
Deprecated Code introduced by
The method CourseManager::count_rows_course_table() has been deprecated.

This method has been deprecated.

Loading history...
61
    );
62
    // Announcements
63
    $table   = Database::get_course_table(TABLE_ANNOUNCEMENT);
64
    $usage[] = array(
65
        get_lang(ucfirst(TOOL_ANNOUNCEMENT)),
66
        CourseManager::count_rows_course_table($table, $session_id, $course->id)
0 ignored issues
show
Deprecated Code introduced by
The method CourseManager::count_rows_course_table() has been deprecated.

This method has been deprecated.

Loading history...
67
    );
68
    return $usage;
69
}
70
71
if (!isset ($_GET['code'])) {
72
    api_not_allowed();
73
}
74
$interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
75
$interbreadcrumb[] = array("url" => 'course_list.php', "name" => get_lang('Courses'));
76
$table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
77
$code = Database::escape_string($_GET['code']);
78
$sql = "SELECT * FROM $table_course WHERE code = '".$code."'";
79
$res = Database::query($sql);
80
$course = Database::fetch_object($res);
81
$courseId = $course->id;
82
$tool_name = $course->title.' ('.$course->visual_code.')';
83
Display::display_header($tool_name);
84
?>
85
    <div class="actions">
86
        <a href="<?php echo api_get_path(WEB_COURSE_PATH).$course->directory; ?>">
87
            <?php Display::display_icon('home.png', get_lang('CourseHomepage'), array(), ICON_SIZE_MEDIUM); ?>
88
        </a>
89
    </div>
90
<?php
91
92
echo Display::page_header(get_lang('CourseUsage'));
93
94
$id_session = isset($_GET['id_session']) ? $_GET['id_session'] : 0;
95
$table      = new SortableTableFromArray(get_course_usage($course->code, $id_session), 0, 20, 'usage_table');
96
$table->set_additional_parameters(array('code' => Security::remove_XSS($_GET['code'])));
97
$table->set_other_tables(array('user_table', 'class_table'));
98
$table->set_header(0, get_lang('Tool'), true);
99
$table->set_header(1, get_lang('NumberOfItems'), true);
100
$table->display();
101
102
/**
103
 * Show all users subscribed in this course
104
 */
105
echo Display::page_header(get_lang('Users'));
106
$table_course_user     = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
107
$table_user            = Database :: get_main_table(TABLE_MAIN_USER);
108
$sql = "SELECT *, cu.status as course_status
109
        FROM $table_course_user cu, $table_user u";
110
if (api_is_multiple_url_enabled()) {
111
    $sql .= " INNER JOIN ".Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER)." url_rel_user
112
        ON u.user_id = url_rel_user.user_id
113
        AND url_rel_user.access_url_id = ".intval(api_get_current_access_url_id());
114
}
115
$sql .= " WHERE
116
            cu.user_id = u.user_id AND
117
            cu.c_id = '".$courseId."' AND
118
            cu.relation_type <> ".COURSE_RELATION_TYPE_RRHH;
119
$res = Database::query($sql);
120
$is_western_name_order = api_is_western_name_order();
121
if (Database::num_rows($res) > 0) {
122
    $users = array();
123
    while ($obj = Database::fetch_object($res)) {
124
        $user   = array();
125
        $user[] = $obj->official_code;
126
        if ($is_western_name_order) {
127
            $user[] = $obj->firstname;
128
            $user[] = $obj->lastname;
129
        } else {
130
            $user[] = $obj->lastname;
131
            $user[] = $obj->firstname;
132
        }
133
        $user[]  = Display :: encrypted_mailto_link($obj->email, $obj->email);
134
        $user[]  = $obj->course_status == 5 ? get_lang('Student') : get_lang('Teacher');
135
        $user[]  = '<a href="user_information.php?user_id='.$obj->user_id.'">'.Display::return_icon('synthese_view.gif', get_lang('UserInfo')).'</a>';
136
        $users[] = $user;
137
    }
138
    $table = new SortableTableFromArray($users, 0, 20, 'user_table');
139
    $table->set_additional_parameters(array('code' => $code));
140
    $table->set_other_tables(array('usage_table', 'class_table'));
141
    $table->set_header(0, get_lang('OfficialCode'), true);
142 View Code Duplication
    if ($is_western_name_order) {
143
        $table->set_header(1, get_lang('FirstName'), true);
144
        $table->set_header(2, get_lang('LastName'), true);
145
    } else {
146
        $table->set_header(1, get_lang('LastName'), true);
147
        $table->set_header(2, get_lang('FirstName'), true);
148
    }
149
    $table->set_header(3, get_lang('Email'), true);
150
    $table->set_header(4, get_lang('Status'), true);
151
    $table->set_header(5, '', false);
152
    $table->display();
153
} else {
154
    echo get_lang('NoUsersInCourse');
155
}
156
157
$session_list = SessionManager::get_session_by_course($course->id);
158
159
$url = api_get_path(WEB_CODE_PATH);
160
if (!empty($session_list)) {
161
    foreach ($session_list as &$session) {
162
        $session[0] = Display::url($session[0], $url.'admin/resume_session.php?id_session='.$session['id']);
163
        unset($session[1]);
164
    }
165
    echo Display::page_header(get_lang('Sessions'));
166
    $table = new SortableTableFromArray($session_list, 0, 20, 'user_table');
167
    $table->display();
168
}
169
170
/*$group = new UserGroup();
171
$usegroups = $group->get_usergroup_by_course($course->id);*/
172
173
Display::display_footer();
174