Issues (2130)

main/mySpace/coaches.php (1 issue)

Labels
Severity
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
ob_start();
6
$cidReset = true;
7
8
require_once __DIR__.'/../inc/global.inc.php';
9
10
$this_section = SECTION_TRACKING;
11
12
$nameTools = get_lang('Tutors');
13
14
api_block_anonymous_users();
15
$interbreadcrumb[] = ["url" => "index.php", "name" => get_lang('MySpace')];
16
17
if (isset($_GET["id_student"])) {
18
    $interbreadcrumb[] = ["url" => "student.php", "name" => get_lang('Students')];
19
}
20
21
Display::display_header($nameTools);
22
23
api_display_tool_title($nameTools);
24
25
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
26
$tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
27
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
28
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
29
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
30
$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
31
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
32
$tbl_track_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
33
34
/**
35
 * MAIN PART.
36
 */
37
if (isset($_POST['export'])) {
38
    $order_clause = api_is_western_name_order(PERSON_NAME_DATA_EXPORT) ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
39
} else {
40
    $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
41
}
42
43
if (isset($_GET["id_student"])) {
44
    $id_student = intval($_GET["id_student"]);
45
    $sql_coachs = "SELECT DISTINCT srcru.user_id as id_coach
46
		FROM $tbl_session_rel_course_rel_user as srcru
47
		WHERE srcru.user_id='$id_student' AND srcru.status=2";
48
} else {
49
    if (api_is_platform_admin()) {
50
        $sql_coachs = "SELECT DISTINCT
51
			srcru.user_id as id_coach, user_id, lastname, firstname
52
			FROM $tbl_user, $tbl_session_rel_course_rel_user srcru
53
			WHERE
54
			 	srcru.user_id=user_id AND
55
			 	srcru.status=2 ".$order_clause;
56
    } else {
57
        $sql_coachs = "SELECT DISTINCT user_id as id_coach, user.user_id, lastname, firstname
58
			FROM
59
			$tbl_user as user,
60
			$tbl_session_rel_course_user as srcu,
61
			$tbl_course_user as course_rel_user,
62
			$tbl_course as c
63
			WHERE
64
			 	c.id = course_rel_user.c_id AND
65
				c.id = srcu.c_id AND
66
				course_rel_user.status='1' AND
67
				course_rel_user.user_id='".api_get_user_id()."' AND
68
				srcu.user_id = user.user_id AND
69
				srcu.status = 2
70
				".$order_clause;
71
    }
72
}
73
74
$result_coachs = Database::query($sql_coachs);
75
76
if (api_is_western_name_order()) {
77
    echo '<table class="table table-hover table-striped data_table">
78
	    <tr>
79
            <th>'.get_lang('FirstName').'</th>
80
            <th>'.get_lang('LastName').'</th>
81
            <th>'.get_lang('ConnectionTime').'</th>
82
            <th>'.get_lang('AdminCourses').'</th>
83
            <th>'.get_lang('Students').'</th>
84
        </tr>';
85
} else {
86
    echo '<table class="table table-hover table-striped data_table">
87
	        <tr>
88
                <th>'.get_lang('LastName').'</th>
89
                <th>'.get_lang('FirstName').'</th>
90
                <th>'.get_lang('ConnectionTime').'</th>
91
                <th>'.get_lang('AdminCourses').'</th>
92
                <th>'.get_lang('Students').'</th>
93
	        </tr>';
94
}
95
96
if (api_is_western_name_order(PERSON_NAME_DATA_EXPORT)) {
97
    $header[] = get_lang('FirstName', '');
98
    $header[] = get_lang('LastName', '');
99
} else {
100
    $header[] = get_lang('LastName', '');
101
    $header[] = get_lang('FirstName', '');
102
}
103
$header[] = get_lang('ConnectionTime', '');
104
105
if (Database::num_rows($result_coachs) > 0) {
106
    while ($coachs = Database::fetch_array($result_coachs)) {
107
        $id_coach = $coachs["id_coach"];
108
109
        if (isset($_GET["id_student"])) {
110
            $sql_infos_coach = "SELECT lastname, firstname
111
            FROM $tbl_user
112
            WHERE user_id='$id_coach'";
113
            $result_coachs_infos = Database::query($sql_infos_coach);
114
            $lastname = Database::result($result_coachs_infos, 0, "lastname");
115
            $firstname = Database::result($result_coachs_infos, 0, "firstname");
116
        } else {
117
            $lastname = $coachs["lastname"];
118
            $firstname = $coachs["firstname"];
119
        }
120
121
        $sql_connection_time = "SELECT login_date, logout_date
122
        FROM $tbl_track_login
123
        WHERE login_user_id ='$id_coach' AND logout_date <> 'null'";
124
        $result_connection_time = Database::query($sql_connection_time);
125
126
        $nb_seconds = 0;
127
        while ($connections = Database::fetch_array($result_connection_time)) {
128
            $login_date = $connections["login_date"];
129
            $logout_date = $connections["logout_date"];
130
            $timestamp_login_date = strtotime($login_date);
131
            $timestamp_logout_date = strtotime($logout_date);
132
            $nb_seconds += ($timestamp_logout_date - $timestamp_login_date);
133
        }
134
135
        if ($nb_seconds == 0) {
136
            $s_connection_time = '';
137
        } else {
138
            $s_connection_time = api_time_to_hms($nb_seconds);
139
        }
140
141
        if ($i % 2 == 0) {
142
            $css_class = "row_odd";
143
            if ($i % 20 == 0 && $i != 0) {
144
                if (api_is_western_name_order()) {
145
                    echo '<tr>
146
					    <th>'.get_lang('FirstName').'</th>
147
                        <th>'.get_lang('LastName').'</th>
148
                        <th>'.get_lang('ConnectionTime').'</th>
149
                        <th>'.get_lang('AdminCourses').'</th>
150
                        <th>'.get_lang('Students').'</th>
151
					</tr>';
152
                } else {
153
                    echo '<tr>
154
					    <th>'.get_lang('LastName').'</th>
155
                        <th>'.get_lang('FirstName').'</th>
156
                        <th>'.get_lang('ConnectionTime').'</th>
157
                        <th>'.get_lang('AdminCourses').'</th>
158
                        <th>'.get_lang('Students').'</th>
159
					</tr>';
160
                }
161
            }
162
        } else {
163
            $css_class = "row_even";
164
        }
165
166
        $i++;
167
168
        if (api_is_western_name_order()) {
169
            echo '<tr class="'.$css_class.'">
170
			        <td>'.$firstname.'</td><td>'.$lastname.'</td><td>'.$s_connection_time.'</td>
171
			        <td>
172
			            <a href="course.php?type=coach&user_id='.$id_coach.'">
173
                        '.Display::return_icon('2rightarrow.png', get_lang('Details')).'
174
			            </a>
175
                    </td>
176
			        <td>
177
			            <a href="student.php?type=coach&user_id='.$id_coach.'">
178
			                '.Display::return_icon('2rightarrow.png', get_lang('Details')).'
179
			            </a>
180
			            </td>
181
                    </tr>';
182
        } else {
183
            echo '<tr class="'.$css_class.'">
184
			        <td>'.$lastname.'</td><td>'.$firstname.'</td>
185
			        <td>'.$s_connection_time.'</td>
186
			        <td>
187
			            <a href="course.php?type=coach&user_id='.$id_coach.'">
188
			            '.Display::return_icon('2rightarrow.png', get_lang('Details')).'</a></td>
189
                    <td>
190
                        <a href="student.php?type=coach&user_id='.$id_coach.'">
191
                        '.Display::return_icon('2rightarrow.png', get_lang('Details')).'</a>
192
                    </td>
193
                    </tr>';
194
        }
195
196
        if (api_is_western_name_order(PERSON_NAME_DATA_EXPORT)) {
197
            $data[$id_coach]["firstname"] = $firstname;
198
            $data[$id_coach]["lastname"] = $lastname;
199
        } else {
200
            $data[$id_coach]["lastname"] = $lastname;
201
            $data[$id_coach]["firstname"] = $firstname;
202
        }
203
        $data[$id_coach]["connection_time"] = $s_connection_time;
204
    }
205
} else {
206
    // No results
207
    echo '<tr><td colspan="5">'.get_lang("NoResult").'</td></tr>';
208
}
209
echo '</table>';
210
211
if (isset($_POST['export'])) {
212
    export_csv($header, $data, 'coaches.csv');
0 ignored issues
show
The function export_csv was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

212
    /** @scrutinizer ignore-call */ 
213
    export_csv($header, $data, 'coaches.csv');
Loading history...
213
}
214
215
echo "<br /><br />";
216
echo "
217
    <br /><br />
218
    <form method='post' action='coaches.php'>
219
        <button type='submit' class='save' name='export' value='".get_lang('ExportExcel')."'>
220
            ".get_lang('ExportExcel')."
221
        </button>
222
    <form>
223
";
224
Display::display_footer();
225