@@ -8,94 +8,94 @@ discard block |
||
8 | 8 | */ |
9 | 9 | class SurveyLink extends AbstractLink |
10 | 10 | { |
11 | - private $survey_table = null; |
|
12 | - |
|
13 | - /** |
|
14 | - * Constructor |
|
15 | - */ |
|
16 | - public function __construct() |
|
17 | - { |
|
18 | - parent::__construct(); |
|
19 | - $this->set_type(LINK_SURVEY); |
|
20 | - } |
|
21 | - |
|
22 | - public function get_name() |
|
23 | - { |
|
24 | - $this->get_survey_data(); |
|
25 | - return $this->survey_data['code'].': '.self::html_to_text($this->survey_data['title']); |
|
26 | - } |
|
27 | - |
|
28 | - public function get_description() |
|
29 | - { |
|
30 | - $this->get_survey_data(); |
|
31 | - return $this->survey_data['subtitle']; |
|
32 | - } |
|
33 | - |
|
34 | - public function get_type_name() |
|
35 | - { |
|
36 | - return get_lang('Survey'); |
|
37 | - } |
|
38 | - |
|
39 | - public function is_allowed_to_change_name() |
|
40 | - { |
|
41 | - return false; |
|
42 | - } |
|
43 | - |
|
44 | - public function needs_name_and_description() |
|
45 | - { |
|
46 | - return false; |
|
47 | - } |
|
48 | - |
|
49 | - public function needs_max() |
|
50 | - { |
|
51 | - return false; |
|
52 | - } |
|
53 | - |
|
54 | - public function needs_results() |
|
55 | - { |
|
56 | - return false; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Generates an array of all surveys available. |
|
61 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
62 | - */ |
|
63 | - public function get_all_links() |
|
64 | - { |
|
65 | - if (empty($this->course_code)) { |
|
66 | - die('Error in get_all_links() : course code not set'); |
|
67 | - } |
|
68 | - $tbl_survey = $this->get_survey_table(); |
|
69 | - $session_id = api_get_session_id(); |
|
70 | - $course_id = api_get_course_int_id(); |
|
71 | - $sql = 'SELECT survey_id, title, code FROM '.$tbl_survey.' |
|
11 | + private $survey_table = null; |
|
12 | + |
|
13 | + /** |
|
14 | + * Constructor |
|
15 | + */ |
|
16 | + public function __construct() |
|
17 | + { |
|
18 | + parent::__construct(); |
|
19 | + $this->set_type(LINK_SURVEY); |
|
20 | + } |
|
21 | + |
|
22 | + public function get_name() |
|
23 | + { |
|
24 | + $this->get_survey_data(); |
|
25 | + return $this->survey_data['code'].': '.self::html_to_text($this->survey_data['title']); |
|
26 | + } |
|
27 | + |
|
28 | + public function get_description() |
|
29 | + { |
|
30 | + $this->get_survey_data(); |
|
31 | + return $this->survey_data['subtitle']; |
|
32 | + } |
|
33 | + |
|
34 | + public function get_type_name() |
|
35 | + { |
|
36 | + return get_lang('Survey'); |
|
37 | + } |
|
38 | + |
|
39 | + public function is_allowed_to_change_name() |
|
40 | + { |
|
41 | + return false; |
|
42 | + } |
|
43 | + |
|
44 | + public function needs_name_and_description() |
|
45 | + { |
|
46 | + return false; |
|
47 | + } |
|
48 | + |
|
49 | + public function needs_max() |
|
50 | + { |
|
51 | + return false; |
|
52 | + } |
|
53 | + |
|
54 | + public function needs_results() |
|
55 | + { |
|
56 | + return false; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Generates an array of all surveys available. |
|
61 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
62 | + */ |
|
63 | + public function get_all_links() |
|
64 | + { |
|
65 | + if (empty($this->course_code)) { |
|
66 | + die('Error in get_all_links() : course code not set'); |
|
67 | + } |
|
68 | + $tbl_survey = $this->get_survey_table(); |
|
69 | + $session_id = api_get_session_id(); |
|
70 | + $course_id = api_get_course_int_id(); |
|
71 | + $sql = 'SELECT survey_id, title, code FROM '.$tbl_survey.' |
|
72 | 72 | WHERE c_id = '.$course_id.' AND session_id = '.intval($session_id).''; |
73 | - $result = Database::query($sql); |
|
74 | - while ($data = Database::fetch_array($result)) { |
|
75 | - $links[] = array( |
|
76 | - $data['survey_id'], |
|
77 | - api_trunc_str( |
|
78 | - $data['code'] . ': ' . self::html_to_text($data['title']), |
|
79 | - 80 |
|
80 | - ) |
|
81 | - ); |
|
82 | - } |
|
83 | - |
|
84 | - return isset($links) ? $links : null; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Generates an array of surveys that a teacher hasn't created a link for. |
|
89 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
90 | - */ |
|
91 | - public function get_not_created_links() |
|
92 | - { |
|
93 | - if (empty($this->course_code)) { |
|
94 | - die('Error in get_not_created_links() : course code not set'); |
|
95 | - } |
|
96 | - $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
97 | - |
|
98 | - $sql = 'SELECT survey_id, title, code |
|
73 | + $result = Database::query($sql); |
|
74 | + while ($data = Database::fetch_array($result)) { |
|
75 | + $links[] = array( |
|
76 | + $data['survey_id'], |
|
77 | + api_trunc_str( |
|
78 | + $data['code'] . ': ' . self::html_to_text($data['title']), |
|
79 | + 80 |
|
80 | + ) |
|
81 | + ); |
|
82 | + } |
|
83 | + |
|
84 | + return isset($links) ? $links : null; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Generates an array of surveys that a teacher hasn't created a link for. |
|
89 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
90 | + */ |
|
91 | + public function get_not_created_links() |
|
92 | + { |
|
93 | + if (empty($this->course_code)) { |
|
94 | + die('Error in get_not_created_links() : course code not set'); |
|
95 | + } |
|
96 | + $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
97 | + |
|
98 | + $sql = 'SELECT survey_id, title, code |
|
99 | 99 | FROM '.$this->get_survey_table().' AS srv |
100 | 100 | WHERE survey_id NOT IN |
101 | 101 | ( |
@@ -106,28 +106,28 @@ discard block |
||
106 | 106 | ) |
107 | 107 | AND srv.session_id = '.api_get_session_id(); |
108 | 108 | |
109 | - $result = Database::query($sql); |
|
110 | - |
|
111 | - $links = array(); |
|
112 | - while ($data = Database::fetch_array($result)) { |
|
113 | - $links[] = array( |
|
114 | - $data['survey_id'], |
|
115 | - api_trunc_str($data['code'].': '.self::html_to_text($data['title']), 80) |
|
116 | - ); |
|
117 | - } |
|
118 | - return $links; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Has anyone done this survey yet? |
|
123 | - */ |
|
124 | - public function has_results($stud_id=null) |
|
125 | - { |
|
126 | - $ref_id = intval($this->get_ref_id()); |
|
127 | - $session_id = api_get_session_id(); |
|
128 | - $tbl_survey = Database::get_course_table(TABLE_SURVEY); |
|
129 | - $tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION); |
|
130 | - $sql = "SELECT |
|
109 | + $result = Database::query($sql); |
|
110 | + |
|
111 | + $links = array(); |
|
112 | + while ($data = Database::fetch_array($result)) { |
|
113 | + $links[] = array( |
|
114 | + $data['survey_id'], |
|
115 | + api_trunc_str($data['code'].': '.self::html_to_text($data['title']), 80) |
|
116 | + ); |
|
117 | + } |
|
118 | + return $links; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Has anyone done this survey yet? |
|
123 | + */ |
|
124 | + public function has_results($stud_id=null) |
|
125 | + { |
|
126 | + $ref_id = intval($this->get_ref_id()); |
|
127 | + $session_id = api_get_session_id(); |
|
128 | + $tbl_survey = Database::get_course_table(TABLE_SURVEY); |
|
129 | + $tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION); |
|
130 | + $sql = "SELECT |
|
131 | 131 | COUNT(i.answered) |
132 | 132 | FROM $tbl_survey AS s |
133 | 133 | JOIN $tbl_survey_invitation AS i ON s.code = i.survey_code |
@@ -137,30 +137,30 @@ discard block |
||
137 | 137 | s.survey_id = $ref_id AND |
138 | 138 | i.session_id = $session_id"; |
139 | 139 | |
140 | - $sql_result = Database::query($sql); |
|
141 | - $data = Database::fetch_array($sql_result); |
|
140 | + $sql_result = Database::query($sql); |
|
141 | + $data = Database::fetch_array($sql_result); |
|
142 | 142 | |
143 | - return ($data[0] != 0); |
|
144 | - } |
|
143 | + return ($data[0] != 0); |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * @param int $stud_id |
|
148 | - * @return array|null |
|
149 | - */ |
|
150 | - public function calc_score($stud_id = null, $type = null) |
|
151 | - { |
|
152 | - // Note: Max score is assumed to be always 1 for surveys, |
|
153 | - // only student's participation is to be taken into account. |
|
154 | - $max_score = 1; |
|
146 | + /** |
|
147 | + * @param int $stud_id |
|
148 | + * @return array|null |
|
149 | + */ |
|
150 | + public function calc_score($stud_id = null, $type = null) |
|
151 | + { |
|
152 | + // Note: Max score is assumed to be always 1 for surveys, |
|
153 | + // only student's participation is to be taken into account. |
|
154 | + $max_score = 1; |
|
155 | 155 | |
156 | - $ref_id = intval($this->get_ref_id()); |
|
157 | - $session_id = api_get_session_id(); |
|
158 | - $tbl_survey = Database::get_course_table(TABLE_SURVEY); |
|
159 | - $tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION); |
|
156 | + $ref_id = intval($this->get_ref_id()); |
|
157 | + $session_id = api_get_session_id(); |
|
158 | + $tbl_survey = Database::get_course_table(TABLE_SURVEY); |
|
159 | + $tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION); |
|
160 | 160 | |
161 | - $get_individual_score = !is_null($stud_id); |
|
161 | + $get_individual_score = !is_null($stud_id); |
|
162 | 162 | |
163 | - $sql = "SELECT i.answered |
|
163 | + $sql = "SELECT i.answered |
|
164 | 164 | FROM $tbl_survey AS s |
165 | 165 | JOIN $tbl_survey_invitation AS i |
166 | 166 | ON s.code = i.survey_code |
@@ -171,131 +171,131 @@ discard block |
||
171 | 171 | i.session_id = $session_id |
172 | 172 | "; |
173 | 173 | |
174 | - if ($get_individual_score) { |
|
175 | - $sql .= ' AND i.user = '.intval($stud_id); |
|
176 | - } |
|
177 | - |
|
178 | - $sql_result = Database::query($sql); |
|
179 | - |
|
180 | - if ($get_individual_score) { |
|
181 | - // for 1 student |
|
182 | - if ($data = Database::fetch_array($sql_result)) { |
|
183 | - return array($data['answered'] ? $max_score : 0, $max_score); |
|
184 | - } |
|
185 | - return array(0, $max_score); |
|
186 | - } else { |
|
187 | - // for all the students -> get average |
|
188 | - $rescount = 0; |
|
189 | - $sum = 0; |
|
190 | - $bestResult = 0; |
|
191 | - $weight = 0; |
|
192 | - while ($data = Database::fetch_array($sql_result)) { |
|
193 | - $sum += $data['answered'] ? $max_score : 0; |
|
194 | - $rescount++; |
|
195 | - if ($data['answered'] > $bestResult) { |
|
196 | - $bestResult = $data['answered']; |
|
197 | - $weight = $assignment['qualification']; |
|
198 | - } |
|
199 | - } |
|
200 | - $sum = $sum / $max_score; |
|
201 | - |
|
202 | - if ($rescount == 0) { |
|
203 | - return null; |
|
204 | - } |
|
205 | - |
|
206 | - switch ($type) { |
|
207 | - case 'best': |
|
208 | - return array($bestResult, $rescount); |
|
209 | - break; |
|
210 | - case 'average': |
|
211 | - return array($sum, $rescount); |
|
212 | - break; |
|
213 | - case 'ranking': |
|
214 | - return null; |
|
215 | - break; |
|
216 | - default: |
|
217 | - return array($sum, $rescount); |
|
218 | - break; |
|
219 | - } |
|
220 | - } |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Lazy load function to get the database table of the surveys |
|
225 | - */ |
|
226 | - private function get_survey_table() |
|
227 | - { |
|
228 | - $this->survey_table = Database :: get_course_table(TABLE_SURVEY); |
|
229 | - return $this->survey_table; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Check if this still links to a survey |
|
234 | - */ |
|
235 | - public function is_valid_link() |
|
236 | - { |
|
237 | - $session_id = api_get_session_id(); |
|
238 | - $sql = 'SELECT count(survey_id) FROM '.$this->get_survey_table().' |
|
174 | + if ($get_individual_score) { |
|
175 | + $sql .= ' AND i.user = '.intval($stud_id); |
|
176 | + } |
|
177 | + |
|
178 | + $sql_result = Database::query($sql); |
|
179 | + |
|
180 | + if ($get_individual_score) { |
|
181 | + // for 1 student |
|
182 | + if ($data = Database::fetch_array($sql_result)) { |
|
183 | + return array($data['answered'] ? $max_score : 0, $max_score); |
|
184 | + } |
|
185 | + return array(0, $max_score); |
|
186 | + } else { |
|
187 | + // for all the students -> get average |
|
188 | + $rescount = 0; |
|
189 | + $sum = 0; |
|
190 | + $bestResult = 0; |
|
191 | + $weight = 0; |
|
192 | + while ($data = Database::fetch_array($sql_result)) { |
|
193 | + $sum += $data['answered'] ? $max_score : 0; |
|
194 | + $rescount++; |
|
195 | + if ($data['answered'] > $bestResult) { |
|
196 | + $bestResult = $data['answered']; |
|
197 | + $weight = $assignment['qualification']; |
|
198 | + } |
|
199 | + } |
|
200 | + $sum = $sum / $max_score; |
|
201 | + |
|
202 | + if ($rescount == 0) { |
|
203 | + return null; |
|
204 | + } |
|
205 | + |
|
206 | + switch ($type) { |
|
207 | + case 'best': |
|
208 | + return array($bestResult, $rescount); |
|
209 | + break; |
|
210 | + case 'average': |
|
211 | + return array($sum, $rescount); |
|
212 | + break; |
|
213 | + case 'ranking': |
|
214 | + return null; |
|
215 | + break; |
|
216 | + default: |
|
217 | + return array($sum, $rescount); |
|
218 | + break; |
|
219 | + } |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Lazy load function to get the database table of the surveys |
|
225 | + */ |
|
226 | + private function get_survey_table() |
|
227 | + { |
|
228 | + $this->survey_table = Database :: get_course_table(TABLE_SURVEY); |
|
229 | + return $this->survey_table; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Check if this still links to a survey |
|
234 | + */ |
|
235 | + public function is_valid_link() |
|
236 | + { |
|
237 | + $session_id = api_get_session_id(); |
|
238 | + $sql = 'SELECT count(survey_id) FROM '.$this->get_survey_table().' |
|
239 | 239 | WHERE |
240 | 240 | c_id = '.$this->course_id.' AND |
241 | 241 | survey_id = '.intval($this->get_ref_id()).' AND |
242 | 242 | session_id='.intval($session_id).''; |
243 | - $result = Database::query($sql); |
|
244 | - $number = Database::fetch_row($result); |
|
245 | - return ($number[0] != 0); |
|
246 | - } |
|
247 | - |
|
248 | - public function get_test_id() |
|
249 | - { |
|
250 | - return 'DEBUG:ID'; |
|
251 | - } |
|
252 | - |
|
253 | - public function get_link() |
|
254 | - { |
|
255 | - if (api_is_allowed_to_edit()) { // Let students make access only through "Surveys" tool. |
|
256 | - $tbl_name = $this->get_survey_table(); |
|
257 | - $session_id = api_get_session_id(); |
|
258 | - if ($tbl_name != '') { |
|
259 | - $sql = 'SELECT survey_id FROM '.$this->get_survey_table().' |
|
243 | + $result = Database::query($sql); |
|
244 | + $number = Database::fetch_row($result); |
|
245 | + return ($number[0] != 0); |
|
246 | + } |
|
247 | + |
|
248 | + public function get_test_id() |
|
249 | + { |
|
250 | + return 'DEBUG:ID'; |
|
251 | + } |
|
252 | + |
|
253 | + public function get_link() |
|
254 | + { |
|
255 | + if (api_is_allowed_to_edit()) { // Let students make access only through "Surveys" tool. |
|
256 | + $tbl_name = $this->get_survey_table(); |
|
257 | + $session_id = api_get_session_id(); |
|
258 | + if ($tbl_name != '') { |
|
259 | + $sql = 'SELECT survey_id FROM '.$this->get_survey_table().' |
|
260 | 260 | WHERE |
261 | 261 | c_id = '.$this->course_id.' AND |
262 | 262 | survey_id = '.intval($this->get_ref_id()).' AND |
263 | 263 | session_id = '.intval($session_id).' '; |
264 | - $result = Database::query($sql); |
|
265 | - $row = Database::fetch_array($result, 'ASSOC'); |
|
266 | - $survey_id = $row['survey_id']; |
|
267 | - return api_get_path(WEB_PATH).'main/survey/reporting.php?cidReq='.$this->get_course_code().'&survey_id='.$survey_id; |
|
268 | - } |
|
269 | - } |
|
270 | - return null; |
|
271 | - } |
|
272 | - |
|
273 | - private function get_survey_data() |
|
274 | - { |
|
275 | - $tbl_name = $this->get_survey_table(); |
|
276 | - $session_id = api_get_session_id(); |
|
277 | - if ($tbl_name == '') { |
|
278 | - return false; |
|
279 | - } elseif (!isset($this->survey_data)) { |
|
280 | - $sql = 'SELECT * FROM '.$tbl_name.' |
|
264 | + $result = Database::query($sql); |
|
265 | + $row = Database::fetch_array($result, 'ASSOC'); |
|
266 | + $survey_id = $row['survey_id']; |
|
267 | + return api_get_path(WEB_PATH).'main/survey/reporting.php?cidReq='.$this->get_course_code().'&survey_id='.$survey_id; |
|
268 | + } |
|
269 | + } |
|
270 | + return null; |
|
271 | + } |
|
272 | + |
|
273 | + private function get_survey_data() |
|
274 | + { |
|
275 | + $tbl_name = $this->get_survey_table(); |
|
276 | + $session_id = api_get_session_id(); |
|
277 | + if ($tbl_name == '') { |
|
278 | + return false; |
|
279 | + } elseif (!isset($this->survey_data)) { |
|
280 | + $sql = 'SELECT * FROM '.$tbl_name.' |
|
281 | 281 | WHERE |
282 | 282 | c_id = '.$this->course_id.' AND |
283 | 283 | survey_id = '.intval($this->get_ref_id()).' AND |
284 | 284 | session_id='.intval($session_id).''; |
285 | - $query = Database::query($sql); |
|
286 | - $this->survey_data = Database::fetch_array($query); |
|
287 | - } |
|
288 | - return $this->survey_data; |
|
289 | - } |
|
290 | - |
|
291 | - public function get_icon_name() |
|
292 | - { |
|
293 | - return 'survey'; |
|
294 | - } |
|
295 | - |
|
296 | - private static function html_to_text($string) |
|
297 | - { |
|
298 | - return strip_tags($string); |
|
299 | - //return trim(api_html_entity_decode(strip_tags(str_ireplace(array('<p>', '</p>', '<br />', '<br/>', '<br>'), array('', ' ', ' ', ' ', ' '), $string)), ENT_QUOTES)); |
|
300 | - } |
|
285 | + $query = Database::query($sql); |
|
286 | + $this->survey_data = Database::fetch_array($query); |
|
287 | + } |
|
288 | + return $this->survey_data; |
|
289 | + } |
|
290 | + |
|
291 | + public function get_icon_name() |
|
292 | + { |
|
293 | + return 'survey'; |
|
294 | + } |
|
295 | + |
|
296 | + private static function html_to_text($string) |
|
297 | + { |
|
298 | + return strip_tags($string); |
|
299 | + //return trim(api_html_entity_decode(strip_tags(str_ireplace(array('<p>', '</p>', '<br />', '<br/>', '<br>'), array('', ' ', ' ', ' ', ' '), $string)), ENT_QUOTES)); |
|
300 | + } |
|
301 | 301 | } |
@@ -9,260 +9,260 @@ |
||
9 | 9 | */ |
10 | 10 | class LearnpathLink extends AbstractLink |
11 | 11 | { |
12 | - private $course_info = null; |
|
13 | - private $learnpath_table = null; |
|
14 | - private $learnpath_data = null; |
|
15 | - |
|
16 | - /** |
|
17 | - * Constructor |
|
18 | - */ |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - parent::__construct(); |
|
22 | - $this->set_type(LINK_LEARNPATH); |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * Generate an array of learnpaths that a teacher hasn't created a link for. |
|
27 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
28 | - */ |
|
29 | - public function get_not_created_links() |
|
30 | - { |
|
31 | - return false; |
|
32 | - if (empty($this->course_code)) |
|
33 | - die('Error in get_not_created_links() : course code not set'); |
|
34 | - |
|
35 | - $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
36 | - |
|
37 | - $sql = 'SELECT id, name from '.$this->get_learnpath_table().' lp |
|
12 | + private $course_info = null; |
|
13 | + private $learnpath_table = null; |
|
14 | + private $learnpath_data = null; |
|
15 | + |
|
16 | + /** |
|
17 | + * Constructor |
|
18 | + */ |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + parent::__construct(); |
|
22 | + $this->set_type(LINK_LEARNPATH); |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * Generate an array of learnpaths that a teacher hasn't created a link for. |
|
27 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
28 | + */ |
|
29 | + public function get_not_created_links() |
|
30 | + { |
|
31 | + return false; |
|
32 | + if (empty($this->course_code)) |
|
33 | + die('Error in get_not_created_links() : course code not set'); |
|
34 | + |
|
35 | + $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
36 | + |
|
37 | + $sql = 'SELECT id, name from '.$this->get_learnpath_table().' lp |
|
38 | 38 | WHERE c_id = '.$this->course_id.' AND id NOT IN ' |
39 | - .' (SELECT ref_id FROM '.$tbl_grade_links |
|
40 | - .' WHERE type = '.LINK_LEARNPATH |
|
41 | - ." AND course_code = '".$this->get_course_code()."'" |
|
42 | - .') AND lp.session_id='.api_get_session_id().''; |
|
43 | - |
|
44 | - $result = Database::query($sql); |
|
45 | - |
|
46 | - $cats=array(); |
|
47 | - while ($data=Database::fetch_array($result)) { |
|
48 | - $cats[] = array ($data['id'], $data['name']); |
|
49 | - } |
|
50 | - |
|
51 | - return $cats; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Generate an array of all learnpaths available. |
|
56 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
57 | - */ |
|
58 | - public function get_all_links() |
|
59 | - { |
|
60 | - if (empty($this->course_code)) |
|
61 | - die('Error in get_not_created_links() : course code not set'); |
|
62 | - |
|
63 | - $session_id = api_get_session_id(); |
|
64 | - if (empty($session_id)) { |
|
65 | - $session_condition = api_get_session_condition(0, true); |
|
66 | - } else { |
|
67 | - $session_condition = api_get_session_condition($session_id, true, true); |
|
68 | - } |
|
69 | - |
|
70 | - $sql = 'SELECT id, name FROM '.$this->get_learnpath_table().' |
|
39 | + .' (SELECT ref_id FROM '.$tbl_grade_links |
|
40 | + .' WHERE type = '.LINK_LEARNPATH |
|
41 | + ." AND course_code = '".$this->get_course_code()."'" |
|
42 | + .') AND lp.session_id='.api_get_session_id().''; |
|
43 | + |
|
44 | + $result = Database::query($sql); |
|
45 | + |
|
46 | + $cats=array(); |
|
47 | + while ($data=Database::fetch_array($result)) { |
|
48 | + $cats[] = array ($data['id'], $data['name']); |
|
49 | + } |
|
50 | + |
|
51 | + return $cats; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Generate an array of all learnpaths available. |
|
56 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
57 | + */ |
|
58 | + public function get_all_links() |
|
59 | + { |
|
60 | + if (empty($this->course_code)) |
|
61 | + die('Error in get_not_created_links() : course code not set'); |
|
62 | + |
|
63 | + $session_id = api_get_session_id(); |
|
64 | + if (empty($session_id)) { |
|
65 | + $session_condition = api_get_session_condition(0, true); |
|
66 | + } else { |
|
67 | + $session_condition = api_get_session_condition($session_id, true, true); |
|
68 | + } |
|
69 | + |
|
70 | + $sql = 'SELECT id, name FROM '.$this->get_learnpath_table().' |
|
71 | 71 | WHERE c_id = '.$this->course_id.' '.$session_condition.' '; |
72 | - $result = Database::query($sql); |
|
72 | + $result = Database::query($sql); |
|
73 | 73 | |
74 | - $cats = array(); |
|
75 | - while ($data=Database::fetch_array($result)) { |
|
76 | - $cats[] = array ($data['id'], $data['name']); |
|
77 | - } |
|
74 | + $cats = array(); |
|
75 | + while ($data=Database::fetch_array($result)) { |
|
76 | + $cats[] = array ($data['id'], $data['name']); |
|
77 | + } |
|
78 | 78 | |
79 | - return $cats; |
|
80 | - } |
|
79 | + return $cats; |
|
80 | + } |
|
81 | 81 | |
82 | 82 | |
83 | - /** |
|
84 | - * Has anyone used this learnpath yet ? |
|
85 | - */ |
|
86 | - public function has_results() |
|
87 | - { |
|
88 | - $tbl_stats = Database::get_course_table(TABLE_LP_VIEW); |
|
89 | - $sql = "SELECT count(id) AS number FROM $tbl_stats |
|
83 | + /** |
|
84 | + * Has anyone used this learnpath yet ? |
|
85 | + */ |
|
86 | + public function has_results() |
|
87 | + { |
|
88 | + $tbl_stats = Database::get_course_table(TABLE_LP_VIEW); |
|
89 | + $sql = "SELECT count(id) AS number FROM $tbl_stats |
|
90 | 90 | WHERE c_id = ".$this->course_id." AND lp_id = ".$this->get_ref_id(); |
91 | - $result = Database::query($sql); |
|
92 | - $number = Database::fetch_array($result,'NUM'); |
|
93 | - return ($number[0] != 0); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Get the progress of this learnpath. Only the last attempt are taken into account. |
|
98 | - * @param $stud_id student id (default: all students who have results - then the average is returned) |
|
99 | - * @return array (score, max) if student is given |
|
100 | - * array (sum of scores, number of scores) otherwise |
|
101 | - * or null if no scores available |
|
102 | - */ |
|
103 | - public function calc_score($stud_id = null, $type = null) |
|
104 | - { |
|
105 | - $tbl_stats = Database::get_course_table(TABLE_LP_VIEW); |
|
106 | - $session_id = api_get_session_id(); |
|
107 | - |
|
108 | - $sql = "SELECT * FROM $tbl_stats |
|
91 | + $result = Database::query($sql); |
|
92 | + $number = Database::fetch_array($result,'NUM'); |
|
93 | + return ($number[0] != 0); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Get the progress of this learnpath. Only the last attempt are taken into account. |
|
98 | + * @param $stud_id student id (default: all students who have results - then the average is returned) |
|
99 | + * @return array (score, max) if student is given |
|
100 | + * array (sum of scores, number of scores) otherwise |
|
101 | + * or null if no scores available |
|
102 | + */ |
|
103 | + public function calc_score($stud_id = null, $type = null) |
|
104 | + { |
|
105 | + $tbl_stats = Database::get_course_table(TABLE_LP_VIEW); |
|
106 | + $session_id = api_get_session_id(); |
|
107 | + |
|
108 | + $sql = "SELECT * FROM $tbl_stats |
|
109 | 109 | WHERE |
110 | 110 | c_id = ".$this->course_id." AND |
111 | 111 | lp_id = ".$this->get_ref_id()." AND |
112 | 112 | session_id = $session_id "; |
113 | 113 | |
114 | - if (isset($stud_id)) |
|
115 | - $sql .= ' AND user_id = '.intval($stud_id); |
|
116 | - |
|
117 | - // order by id, that way the student's first attempt is accessed first |
|
118 | - $sql .= ' ORDER BY view_count DESC'; |
|
119 | - |
|
120 | - $scores = Database::query($sql); |
|
121 | - // for 1 student |
|
122 | - if (isset($stud_id)) { |
|
123 | - if ($data = Database::fetch_array($scores)) { |
|
124 | - return array ($data['progress'], 100); |
|
125 | - } else |
|
126 | - return null; |
|
127 | - } else { |
|
128 | - // all students -> get average |
|
129 | - $students = array(); // user list, needed to make sure we only |
|
130 | - // take first attempts into account |
|
131 | - $rescount = 0; |
|
132 | - $sum = 0; |
|
133 | - $bestResult = 0; |
|
134 | - $sumResult = 0; |
|
135 | - while ($data = Database::fetch_array($scores)) { |
|
136 | - if (!(array_key_exists($data['user_id'], $students))) { |
|
137 | - $students[$data['user_id']] = $data['progress']; |
|
138 | - $rescount++; |
|
139 | - $sum += $data['progress'] / 100; |
|
140 | - $sumResult += $data['progress']; |
|
141 | - |
|
142 | - if ($data['progress'] > $bestResult) { |
|
143 | - $bestResult = $data['progress']; |
|
144 | - } |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - if ($rescount == 0) { |
|
149 | - return null; |
|
150 | - } else { |
|
151 | - |
|
152 | - switch ($type) { |
|
153 | - case 'best': |
|
154 | - return array($bestResult, 100); |
|
155 | - break; |
|
156 | - case 'average': |
|
157 | - return array($sumResult/$rescount, 100); |
|
158 | - break; |
|
159 | - case 'ranking': |
|
160 | - return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
161 | - break; |
|
162 | - default: |
|
163 | - return array($sum, $rescount); |
|
164 | - break; |
|
165 | - } |
|
166 | - } |
|
167 | - } |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Get URL where to go to if the user clicks on the link. |
|
172 | - */ |
|
173 | - public function get_link() |
|
174 | - { |
|
175 | - $url = api_get_path(WEB_PATH).'main/newscorm/lp_controller.php?cidReq='.$this->get_course_code().'&gradebook=view'; |
|
176 | - $session_id = api_get_session_id(); |
|
177 | - if (!api_is_allowed_to_edit() || $this->calc_score(api_get_user_id()) == null) { |
|
178 | - $url .= '&action=view&session_id='.$session_id.'&lp_id='.$this->get_ref_id(); |
|
179 | - } else { |
|
180 | - $url .= '&action=build&session_id='.$session_id.'&lp_id='.$this->get_ref_id(); |
|
181 | - } |
|
182 | - return $url; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Get name to display: same as learnpath title |
|
187 | - */ |
|
188 | - public function get_name() |
|
189 | - { |
|
190 | - $data = $this->get_learnpath_data(); |
|
191 | - return $data['name']; |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Get description to display: same as learnpath description |
|
196 | - */ |
|
197 | - public function get_description() |
|
198 | - { |
|
199 | - $data = $this->get_learnpath_data(); |
|
200 | - return $data['description']; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Check if this still links to a learnpath |
|
205 | - */ |
|
206 | - public function is_valid_link() { |
|
207 | - $sql = 'SELECT count(id) FROM '.$this->get_learnpath_table().' |
|
114 | + if (isset($stud_id)) |
|
115 | + $sql .= ' AND user_id = '.intval($stud_id); |
|
116 | + |
|
117 | + // order by id, that way the student's first attempt is accessed first |
|
118 | + $sql .= ' ORDER BY view_count DESC'; |
|
119 | + |
|
120 | + $scores = Database::query($sql); |
|
121 | + // for 1 student |
|
122 | + if (isset($stud_id)) { |
|
123 | + if ($data = Database::fetch_array($scores)) { |
|
124 | + return array ($data['progress'], 100); |
|
125 | + } else |
|
126 | + return null; |
|
127 | + } else { |
|
128 | + // all students -> get average |
|
129 | + $students = array(); // user list, needed to make sure we only |
|
130 | + // take first attempts into account |
|
131 | + $rescount = 0; |
|
132 | + $sum = 0; |
|
133 | + $bestResult = 0; |
|
134 | + $sumResult = 0; |
|
135 | + while ($data = Database::fetch_array($scores)) { |
|
136 | + if (!(array_key_exists($data['user_id'], $students))) { |
|
137 | + $students[$data['user_id']] = $data['progress']; |
|
138 | + $rescount++; |
|
139 | + $sum += $data['progress'] / 100; |
|
140 | + $sumResult += $data['progress']; |
|
141 | + |
|
142 | + if ($data['progress'] > $bestResult) { |
|
143 | + $bestResult = $data['progress']; |
|
144 | + } |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + if ($rescount == 0) { |
|
149 | + return null; |
|
150 | + } else { |
|
151 | + |
|
152 | + switch ($type) { |
|
153 | + case 'best': |
|
154 | + return array($bestResult, 100); |
|
155 | + break; |
|
156 | + case 'average': |
|
157 | + return array($sumResult/$rescount, 100); |
|
158 | + break; |
|
159 | + case 'ranking': |
|
160 | + return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
161 | + break; |
|
162 | + default: |
|
163 | + return array($sum, $rescount); |
|
164 | + break; |
|
165 | + } |
|
166 | + } |
|
167 | + } |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Get URL where to go to if the user clicks on the link. |
|
172 | + */ |
|
173 | + public function get_link() |
|
174 | + { |
|
175 | + $url = api_get_path(WEB_PATH).'main/newscorm/lp_controller.php?cidReq='.$this->get_course_code().'&gradebook=view'; |
|
176 | + $session_id = api_get_session_id(); |
|
177 | + if (!api_is_allowed_to_edit() || $this->calc_score(api_get_user_id()) == null) { |
|
178 | + $url .= '&action=view&session_id='.$session_id.'&lp_id='.$this->get_ref_id(); |
|
179 | + } else { |
|
180 | + $url .= '&action=build&session_id='.$session_id.'&lp_id='.$this->get_ref_id(); |
|
181 | + } |
|
182 | + return $url; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Get name to display: same as learnpath title |
|
187 | + */ |
|
188 | + public function get_name() |
|
189 | + { |
|
190 | + $data = $this->get_learnpath_data(); |
|
191 | + return $data['name']; |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Get description to display: same as learnpath description |
|
196 | + */ |
|
197 | + public function get_description() |
|
198 | + { |
|
199 | + $data = $this->get_learnpath_data(); |
|
200 | + return $data['description']; |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Check if this still links to a learnpath |
|
205 | + */ |
|
206 | + public function is_valid_link() { |
|
207 | + $sql = 'SELECT count(id) FROM '.$this->get_learnpath_table().' |
|
208 | 208 | WHERE c_id = '.$this->course_id.' AND id = '.$this->get_ref_id().' '; |
209 | - $result = Database::query($sql); |
|
210 | - $number = Database::fetch_row($result,'NUM'); |
|
211 | - return ($number[0] != 0); |
|
212 | - } |
|
213 | - |
|
214 | - public function get_type_name() |
|
215 | - { |
|
216 | - return get_lang('LearningPaths'); |
|
217 | - } |
|
218 | - |
|
219 | - public function needs_name_and_description() |
|
220 | - { |
|
221 | - return false; |
|
222 | - } |
|
223 | - |
|
224 | - public function needs_max() |
|
225 | - { |
|
226 | - return false; |
|
227 | - } |
|
228 | - |
|
229 | - public function needs_results() |
|
230 | - { |
|
231 | - return false; |
|
232 | - } |
|
233 | - |
|
234 | - public function is_allowed_to_change_name() |
|
235 | - { |
|
236 | - return false; |
|
237 | - } |
|
238 | - |
|
239 | - // INTERNAL FUNCTIONS |
|
240 | - |
|
241 | - /** |
|
242 | - * Lazy load function to get the database table of the learnpath |
|
243 | - */ |
|
244 | - private function get_learnpath_table() |
|
245 | - { |
|
246 | - $this->learnpath_table = Database :: get_course_table(TABLE_LP_MAIN); |
|
247 | - return $this->learnpath_table; |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Lazy load function to get the database contents of this learnpath |
|
252 | - */ |
|
253 | - private function get_learnpath_data() |
|
254 | - { |
|
255 | - if (!isset($this->learnpath_data)) { |
|
256 | - $sql = 'SELECT * FROM '.$this->get_learnpath_table().' |
|
209 | + $result = Database::query($sql); |
|
210 | + $number = Database::fetch_row($result,'NUM'); |
|
211 | + return ($number[0] != 0); |
|
212 | + } |
|
213 | + |
|
214 | + public function get_type_name() |
|
215 | + { |
|
216 | + return get_lang('LearningPaths'); |
|
217 | + } |
|
218 | + |
|
219 | + public function needs_name_and_description() |
|
220 | + { |
|
221 | + return false; |
|
222 | + } |
|
223 | + |
|
224 | + public function needs_max() |
|
225 | + { |
|
226 | + return false; |
|
227 | + } |
|
228 | + |
|
229 | + public function needs_results() |
|
230 | + { |
|
231 | + return false; |
|
232 | + } |
|
233 | + |
|
234 | + public function is_allowed_to_change_name() |
|
235 | + { |
|
236 | + return false; |
|
237 | + } |
|
238 | + |
|
239 | + // INTERNAL FUNCTIONS |
|
240 | + |
|
241 | + /** |
|
242 | + * Lazy load function to get the database table of the learnpath |
|
243 | + */ |
|
244 | + private function get_learnpath_table() |
|
245 | + { |
|
246 | + $this->learnpath_table = Database :: get_course_table(TABLE_LP_MAIN); |
|
247 | + return $this->learnpath_table; |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Lazy load function to get the database contents of this learnpath |
|
252 | + */ |
|
253 | + private function get_learnpath_data() |
|
254 | + { |
|
255 | + if (!isset($this->learnpath_data)) { |
|
256 | + $sql = 'SELECT * FROM '.$this->get_learnpath_table().' |
|
257 | 257 | WHERE c_id = '.$this->course_id.' AND id = '.$this->get_ref_id().' '; |
258 | - $result = Database::query($sql); |
|
259 | - $this->learnpath_data = Database::fetch_array($result); |
|
260 | - } |
|
261 | - return $this->learnpath_data; |
|
262 | - } |
|
263 | - |
|
264 | - public function get_icon_name() |
|
265 | - { |
|
266 | - return 'learnpath'; |
|
267 | - } |
|
258 | + $result = Database::query($sql); |
|
259 | + $this->learnpath_data = Database::fetch_array($result); |
|
260 | + } |
|
261 | + return $this->learnpath_data; |
|
262 | + } |
|
263 | + |
|
264 | + public function get_icon_name() |
|
265 | + { |
|
266 | + return 'learnpath'; |
|
267 | + } |
|
268 | 268 | } |
@@ -10,54 +10,54 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class ForumThreadLink extends AbstractLink |
12 | 12 | { |
13 | - private $forum_thread_table = null; |
|
14 | - private $itemprop_table = null; |
|
15 | - |
|
16 | - /** |
|
17 | - * Constructor |
|
18 | - */ |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - parent::__construct(); |
|
22 | - $this->set_type(LINK_FORUM_THREAD); |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * @return string |
|
27 | - */ |
|
28 | - public function get_type_name() |
|
29 | - { |
|
30 | - return get_lang('ForumThreads'); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - public function is_allowed_to_change_name() |
|
37 | - { |
|
38 | - return false; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Generate an array of exercises that a teacher hasn't created a link for. |
|
43 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
44 | - */ |
|
45 | - public function get_not_created_links() |
|
46 | - { |
|
47 | - if (empty($this->course_code)) { |
|
48 | - die('Error in get_not_created_links() : course code not set'); |
|
49 | - } |
|
50 | - |
|
51 | - $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
52 | - |
|
53 | - $sql = 'SELECT thread_id,thread_title,thread_title_qualify FROM '.$this->get_forum_thread_table() |
|
54 | - .' forum_thread WHERE thread_id NOT IN' |
|
55 | - .' (SELECT ref_id FROM '.$tbl_grade_links |
|
56 | - .' WHERE type = '.LINK_FORUM_THREAD |
|
57 | - ." AND c_id = ".intval($this->course_id) |
|
58 | - .') AND forum_thread.session_id='.api_get_session_id().''; |
|
59 | - |
|
60 | - $result = Database::query($sql); |
|
13 | + private $forum_thread_table = null; |
|
14 | + private $itemprop_table = null; |
|
15 | + |
|
16 | + /** |
|
17 | + * Constructor |
|
18 | + */ |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + parent::__construct(); |
|
22 | + $this->set_type(LINK_FORUM_THREAD); |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public function get_type_name() |
|
29 | + { |
|
30 | + return get_lang('ForumThreads'); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + public function is_allowed_to_change_name() |
|
37 | + { |
|
38 | + return false; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Generate an array of exercises that a teacher hasn't created a link for. |
|
43 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
44 | + */ |
|
45 | + public function get_not_created_links() |
|
46 | + { |
|
47 | + if (empty($this->course_code)) { |
|
48 | + die('Error in get_not_created_links() : course code not set'); |
|
49 | + } |
|
50 | + |
|
51 | + $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
52 | + |
|
53 | + $sql = 'SELECT thread_id,thread_title,thread_title_qualify FROM '.$this->get_forum_thread_table() |
|
54 | + .' forum_thread WHERE thread_id NOT IN' |
|
55 | + .' (SELECT ref_id FROM '.$tbl_grade_links |
|
56 | + .' WHERE type = '.LINK_FORUM_THREAD |
|
57 | + ." AND c_id = ".intval($this->course_id) |
|
58 | + .') AND forum_thread.session_id='.api_get_session_id().''; |
|
59 | + |
|
60 | + $result = Database::query($sql); |
|
61 | 61 | |
62 | 62 | $cats = array(); |
63 | 63 | while ($data = Database::fetch_array($result)) { |
@@ -72,29 +72,29 @@ discard block |
||
72 | 72 | } |
73 | 73 | |
74 | 74 | return $cats; |
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Generate an array of all exercises available. |
|
79 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
80 | - */ |
|
81 | - public function get_all_links() |
|
82 | - { |
|
83 | - if (empty($this->course_code)) { |
|
84 | - die('Error in get_not_created_links() : course code not set'); |
|
85 | - } |
|
86 | - |
|
87 | - $tbl_grade_links = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
88 | - $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
|
89 | - $session_id = api_get_session_id(); |
|
90 | - |
|
91 | - if ($session_id) { |
|
92 | - $session_condition = 'tl.session_id='.api_get_session_id(); |
|
93 | - } else { |
|
94 | - $session_condition = '(tl.session_id = 0 OR tl.session_id IS NULL)'; |
|
95 | - } |
|
96 | - |
|
97 | - $sql = 'SELECT tl.thread_id, tl.thread_title, tl.thread_title_qualify |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Generate an array of all exercises available. |
|
79 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
80 | + */ |
|
81 | + public function get_all_links() |
|
82 | + { |
|
83 | + if (empty($this->course_code)) { |
|
84 | + die('Error in get_not_created_links() : course code not set'); |
|
85 | + } |
|
86 | + |
|
87 | + $tbl_grade_links = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
88 | + $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
|
89 | + $session_id = api_get_session_id(); |
|
90 | + |
|
91 | + if ($session_id) { |
|
92 | + $session_condition = 'tl.session_id='.api_get_session_id(); |
|
93 | + } else { |
|
94 | + $session_condition = '(tl.session_id = 0 OR tl.session_id IS NULL)'; |
|
95 | + } |
|
96 | + |
|
97 | + $sql = 'SELECT tl.thread_id, tl.thread_title, tl.thread_title_qualify |
|
98 | 98 | FROM '.$tbl_grade_links.' tl INNER JOIN '.$tbl_item_property.' ip |
99 | 99 | ON (tl.thread_id = ip.ref AND tl.c_id = ip.c_id ) |
100 | 100 | WHERE |
@@ -105,24 +105,24 @@ discard block |
||
105 | 105 | '.$session_condition.' |
106 | 106 | '; |
107 | 107 | |
108 | - $result = Database::query($sql); |
|
108 | + $result = Database::query($sql); |
|
109 | 109 | |
110 | - while ($data = Database::fetch_array($result)) { |
|
111 | - if ( isset($data['thread_title_qualify']) and $data['thread_title_qualify']!=""){ |
|
112 | - $cats[] = array ($data['thread_id'], $data['thread_title_qualify']); |
|
113 | - } else { |
|
114 | - $cats[] = array ($data['thread_id'], $data['thread_title']); |
|
115 | - } |
|
116 | - } |
|
117 | - $my_cats = isset($cats) ? $cats : null; |
|
110 | + while ($data = Database::fetch_array($result)) { |
|
111 | + if ( isset($data['thread_title_qualify']) and $data['thread_title_qualify']!=""){ |
|
112 | + $cats[] = array ($data['thread_id'], $data['thread_title_qualify']); |
|
113 | + } else { |
|
114 | + $cats[] = array ($data['thread_id'], $data['thread_title']); |
|
115 | + } |
|
116 | + } |
|
117 | + $my_cats = isset($cats) ? $cats : null; |
|
118 | 118 | |
119 | - return $my_cats; |
|
120 | - } |
|
119 | + return $my_cats; |
|
120 | + } |
|
121 | 121 | |
122 | 122 | /** |
123 | - * Has anyone done this exercise yet ? |
|
124 | - * @return int |
|
125 | - */ |
|
123 | + * Has anyone done this exercise yet ? |
|
124 | + * @return int |
|
125 | + */ |
|
126 | 126 | public function has_results() |
127 | 127 | { |
128 | 128 | $table = Database :: get_course_table(TABLE_FORUM_POST); |
@@ -134,40 +134,40 @@ discard block |
||
134 | 134 | $number = Database::fetch_row($result); |
135 | 135 | |
136 | 136 | return $number[0] != 0; |
137 | - } |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * @param int $stud_id |
|
139 | + /** |
|
140 | + * @param int $stud_id |
|
141 | 141 | * @param string $type |
142 | 142 | * |
143 | - * @return array|null |
|
144 | - */ |
|
145 | - public function calc_score($stud_id = null, $type = null) |
|
146 | - { |
|
143 | + * @return array|null |
|
144 | + */ |
|
145 | + public function calc_score($stud_id = null, $type = null) |
|
146 | + { |
|
147 | 147 | require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php'; |
148 | 148 | $threadInfo = get_thread_information($this->get_ref_id()); |
149 | 149 | |
150 | - $thread_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY); |
|
150 | + $thread_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY); |
|
151 | 151 | |
152 | - $sql = 'SELECT thread_qualify_max |
|
152 | + $sql = 'SELECT thread_qualify_max |
|
153 | 153 | FROM '.Database :: get_course_table(TABLE_FORUM_THREAD)." |
154 | 154 | WHERE c_id = ".$this->course_id." AND thread_id = '".$this->get_ref_id()."'"; |
155 | - $query = Database::query($sql); |
|
156 | - $assignment = Database::fetch_array($query); |
|
155 | + $query = Database::query($sql); |
|
156 | + $assignment = Database::fetch_array($query); |
|
157 | 157 | |
158 | - $sql = "SELECT * FROM $thread_qualify |
|
158 | + $sql = "SELECT * FROM $thread_qualify |
|
159 | 159 | WHERE c_id = ".$this->course_id." AND thread_id = ".$this->get_ref_id(); |
160 | - if (isset($stud_id)) { |
|
161 | - $sql .= ' AND user_id = '.intval($stud_id); |
|
162 | - } |
|
160 | + if (isset($stud_id)) { |
|
161 | + $sql .= ' AND user_id = '.intval($stud_id); |
|
162 | + } |
|
163 | 163 | |
164 | - // order by id, that way the student's first attempt is accessed first |
|
165 | - $sql .= ' ORDER BY qualify_time DESC'; |
|
164 | + // order by id, that way the student's first attempt is accessed first |
|
165 | + $sql .= ' ORDER BY qualify_time DESC'; |
|
166 | 166 | |
167 | - $scores = Database::query($sql); |
|
167 | + $scores = Database::query($sql); |
|
168 | 168 | |
169 | - // for 1 student |
|
170 | - if (isset($stud_id)) { |
|
169 | + // for 1 student |
|
170 | + if (isset($stud_id)) { |
|
171 | 171 | if ($threadInfo['thread_peer_qualify'] == 0) { |
172 | 172 | // Classic way of calculate score |
173 | 173 | if ($data = Database::fetch_array($scores)) { |
@@ -195,174 +195,174 @@ discard block |
||
195 | 195 | } |
196 | 196 | return [$score/$counter, $assignment['thread_qualify_max']]; |
197 | 197 | } |
198 | - } else { |
|
199 | - // All students -> get average |
|
200 | - $students = array(); // user list, needed to make sure we only |
|
201 | - // take first attempts into account |
|
202 | - $counter = 0; |
|
203 | - $sum = 0; |
|
204 | - $bestResult = 0; |
|
205 | - $weight = 0; |
|
206 | - $sumResult = 0; |
|
207 | - |
|
208 | - while ($data = Database::fetch_array($scores)) { |
|
209 | - if (!(array_key_exists($data['user_id'], $students))) { |
|
210 | - if ($assignment['thread_qualify_max'] != 0) { |
|
211 | - $students[$data['user_id']] = $data['qualify']; |
|
212 | - $counter++; |
|
213 | - $sum += $data['qualify'] / $assignment['thread_qualify_max']; |
|
214 | - $sumResult += $data['qualify']; |
|
215 | - if ($data['qualify'] > $bestResult) { |
|
216 | - $bestResult = $data['qualify']; |
|
217 | - } |
|
218 | - $weight = $assignment['thread_qualify_max']; |
|
219 | - } |
|
220 | - } |
|
221 | - } |
|
222 | - |
|
223 | - if ($counter == 0) { |
|
224 | - return null; |
|
225 | - } else { |
|
226 | - switch ($type) { |
|
227 | - case 'best': |
|
228 | - return array($bestResult, $weight); |
|
229 | - break; |
|
230 | - case 'average': |
|
231 | - return array($sumResult/$counter, $weight); |
|
232 | - break; |
|
233 | - case 'ranking': |
|
234 | - return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
235 | - break; |
|
236 | - default: |
|
237 | - return array($sum, $counter); |
|
238 | - break; |
|
239 | - } |
|
240 | - } |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * Lazy load function to get the database table of the student publications |
|
246 | - */ |
|
247 | - private function get_forum_thread_table() |
|
248 | - { |
|
249 | - return $this->forum_thread_table = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
250 | - } |
|
251 | - |
|
252 | - public function needs_name_and_description() |
|
253 | - { |
|
254 | - return false; |
|
255 | - } |
|
256 | - |
|
257 | - public function needs_max() |
|
258 | - { |
|
259 | - return false; |
|
260 | - } |
|
261 | - |
|
262 | - public function needs_results() |
|
263 | - { |
|
264 | - return false; |
|
265 | - } |
|
198 | + } else { |
|
199 | + // All students -> get average |
|
200 | + $students = array(); // user list, needed to make sure we only |
|
201 | + // take first attempts into account |
|
202 | + $counter = 0; |
|
203 | + $sum = 0; |
|
204 | + $bestResult = 0; |
|
205 | + $weight = 0; |
|
206 | + $sumResult = 0; |
|
207 | + |
|
208 | + while ($data = Database::fetch_array($scores)) { |
|
209 | + if (!(array_key_exists($data['user_id'], $students))) { |
|
210 | + if ($assignment['thread_qualify_max'] != 0) { |
|
211 | + $students[$data['user_id']] = $data['qualify']; |
|
212 | + $counter++; |
|
213 | + $sum += $data['qualify'] / $assignment['thread_qualify_max']; |
|
214 | + $sumResult += $data['qualify']; |
|
215 | + if ($data['qualify'] > $bestResult) { |
|
216 | + $bestResult = $data['qualify']; |
|
217 | + } |
|
218 | + $weight = $assignment['thread_qualify_max']; |
|
219 | + } |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + if ($counter == 0) { |
|
224 | + return null; |
|
225 | + } else { |
|
226 | + switch ($type) { |
|
227 | + case 'best': |
|
228 | + return array($bestResult, $weight); |
|
229 | + break; |
|
230 | + case 'average': |
|
231 | + return array($sumResult/$counter, $weight); |
|
232 | + break; |
|
233 | + case 'ranking': |
|
234 | + return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
235 | + break; |
|
236 | + default: |
|
237 | + return array($sum, $counter); |
|
238 | + break; |
|
239 | + } |
|
240 | + } |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * Lazy load function to get the database table of the student publications |
|
246 | + */ |
|
247 | + private function get_forum_thread_table() |
|
248 | + { |
|
249 | + return $this->forum_thread_table = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
250 | + } |
|
251 | + |
|
252 | + public function needs_name_and_description() |
|
253 | + { |
|
254 | + return false; |
|
255 | + } |
|
256 | + |
|
257 | + public function needs_max() |
|
258 | + { |
|
259 | + return false; |
|
260 | + } |
|
261 | + |
|
262 | + public function needs_results() |
|
263 | + { |
|
264 | + return false; |
|
265 | + } |
|
266 | 266 | |
267 | 267 | /** |
268 | 268 | * @return string |
269 | 269 | */ |
270 | - public function get_name() |
|
271 | - { |
|
272 | - $this->get_exercise_data(); |
|
273 | - $thread_title=isset($this->exercise_data['thread_title']) ? $this->exercise_data['thread_title'] : ''; |
|
274 | - $thread_title_qualify=isset($this->exercise_data['thread_title_qualify']) ? $this->exercise_data['thread_title_qualify'] : ''; |
|
275 | - if ( isset($thread_title_qualify) && $thread_title_qualify!="") { |
|
276 | - return $this->exercise_data['thread_title_qualify']; |
|
277 | - } else { |
|
278 | - return $thread_title; |
|
279 | - } |
|
280 | - } |
|
270 | + public function get_name() |
|
271 | + { |
|
272 | + $this->get_exercise_data(); |
|
273 | + $thread_title=isset($this->exercise_data['thread_title']) ? $this->exercise_data['thread_title'] : ''; |
|
274 | + $thread_title_qualify=isset($this->exercise_data['thread_title_qualify']) ? $this->exercise_data['thread_title_qualify'] : ''; |
|
275 | + if ( isset($thread_title_qualify) && $thread_title_qualify!="") { |
|
276 | + return $this->exercise_data['thread_title_qualify']; |
|
277 | + } else { |
|
278 | + return $thread_title; |
|
279 | + } |
|
280 | + } |
|
281 | 281 | |
282 | 282 | /** |
283 | 283 | * @return string |
284 | 284 | */ |
285 | - public function get_description() |
|
286 | - { |
|
287 | - return '';//$this->exercise_data['description']; |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Check if this still links to an exercise |
|
292 | - */ |
|
293 | - public function is_valid_link() |
|
294 | - { |
|
295 | - $sql = 'SELECT count(id) from '.$this->get_forum_thread_table().' |
|
285 | + public function get_description() |
|
286 | + { |
|
287 | + return '';//$this->exercise_data['description']; |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Check if this still links to an exercise |
|
292 | + */ |
|
293 | + public function is_valid_link() |
|
294 | + { |
|
295 | + $sql = 'SELECT count(id) from '.$this->get_forum_thread_table().' |
|
296 | 296 | WHERE c_id = '.$this->course_id.' AND thread_id = '.$this->get_ref_id().' AND session_id='.api_get_session_id().''; |
297 | - $result = Database::query($sql); |
|
298 | - $number = Database::fetch_row($result); |
|
299 | - return ($number[0] != 0); |
|
300 | - } |
|
301 | - |
|
302 | - public function get_test_id() |
|
303 | - { |
|
304 | - return 'DEBUG:ID'; |
|
305 | - } |
|
306 | - |
|
307 | - public function get_link() |
|
308 | - { |
|
309 | - //it was extracts the forum id |
|
310 | - $sql = 'SELECT * FROM '.$this->get_forum_thread_table()." |
|
297 | + $result = Database::query($sql); |
|
298 | + $number = Database::fetch_row($result); |
|
299 | + return ($number[0] != 0); |
|
300 | + } |
|
301 | + |
|
302 | + public function get_test_id() |
|
303 | + { |
|
304 | + return 'DEBUG:ID'; |
|
305 | + } |
|
306 | + |
|
307 | + public function get_link() |
|
308 | + { |
|
309 | + //it was extracts the forum id |
|
310 | + $sql = 'SELECT * FROM '.$this->get_forum_thread_table()." |
|
311 | 311 | WHERE c_id = '.$this->course_id.' AND thread_id = '".$this->get_ref_id()."' AND session_id = ".api_get_session_id().""; |
312 | - $result = Database::query($sql); |
|
313 | - $row = Database::fetch_array($result,'ASSOC'); |
|
314 | - $forum_id=$row['forum_id']; |
|
315 | - |
|
316 | - $url = api_get_path(WEB_PATH).'main/forum/viewthread.php?cidReq='.$this->get_course_code().'&thread='.$this->get_ref_id().'&gradebook=view&forum='.$forum_id; |
|
317 | - return $url; |
|
318 | - } |
|
319 | - |
|
320 | - private function get_exercise_data() |
|
321 | - { |
|
322 | - $session_id = api_get_session_id(); |
|
323 | - if ($session_id) { |
|
324 | - $session_condition = 'session_id='.api_get_session_id(); |
|
325 | - } else { |
|
326 | - $session_condition = '(session_id = 0 OR session_id IS NULL)'; |
|
327 | - } |
|
328 | - |
|
329 | - if (!isset($this->exercise_data)) { |
|
330 | - $sql = 'SELECT * FROM '.$this->get_forum_thread_table().' |
|
312 | + $result = Database::query($sql); |
|
313 | + $row = Database::fetch_array($result,'ASSOC'); |
|
314 | + $forum_id=$row['forum_id']; |
|
315 | + |
|
316 | + $url = api_get_path(WEB_PATH).'main/forum/viewthread.php?cidReq='.$this->get_course_code().'&thread='.$this->get_ref_id().'&gradebook=view&forum='.$forum_id; |
|
317 | + return $url; |
|
318 | + } |
|
319 | + |
|
320 | + private function get_exercise_data() |
|
321 | + { |
|
322 | + $session_id = api_get_session_id(); |
|
323 | + if ($session_id) { |
|
324 | + $session_condition = 'session_id='.api_get_session_id(); |
|
325 | + } else { |
|
326 | + $session_condition = '(session_id = 0 OR session_id IS NULL)'; |
|
327 | + } |
|
328 | + |
|
329 | + if (!isset($this->exercise_data)) { |
|
330 | + $sql = 'SELECT * FROM '.$this->get_forum_thread_table().' |
|
331 | 331 | WHERE c_id = '.$this->course_id.' AND thread_id = '.$this->get_ref_id().' AND '.$session_condition; |
332 | - $query = Database::query($sql); |
|
333 | - $this->exercise_data = Database::fetch_array($query); |
|
334 | - } |
|
335 | - return $this->exercise_data; |
|
336 | - } |
|
337 | - |
|
338 | - public function get_icon_name() |
|
339 | - { |
|
340 | - return 'forum'; |
|
341 | - } |
|
342 | - |
|
343 | - function save_linked_data() |
|
344 | - { |
|
345 | - $weight = (float)$this->get_weight(); |
|
346 | - $ref_id = $this->get_ref_id(); |
|
347 | - |
|
348 | - if (!empty($ref_id)) { |
|
349 | - $sql = 'UPDATE '.$this->get_forum_thread_table().' SET thread_weight='.$weight.' |
|
332 | + $query = Database::query($sql); |
|
333 | + $this->exercise_data = Database::fetch_array($query); |
|
334 | + } |
|
335 | + return $this->exercise_data; |
|
336 | + } |
|
337 | + |
|
338 | + public function get_icon_name() |
|
339 | + { |
|
340 | + return 'forum'; |
|
341 | + } |
|
342 | + |
|
343 | + function save_linked_data() |
|
344 | + { |
|
345 | + $weight = (float)$this->get_weight(); |
|
346 | + $ref_id = $this->get_ref_id(); |
|
347 | + |
|
348 | + if (!empty($ref_id)) { |
|
349 | + $sql = 'UPDATE '.$this->get_forum_thread_table().' SET thread_weight='.$weight.' |
|
350 | 350 | WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id; |
351 | - Database::query($sql); |
|
352 | - } |
|
353 | - } |
|
354 | - |
|
355 | - function delete_linked_data() |
|
356 | - { |
|
357 | - $ref_id = $this->get_ref_id(); |
|
358 | - if (!empty($ref_id)) { |
|
359 | - //Cleans forum |
|
360 | - $sql = 'UPDATE '.$this->get_forum_thread_table().' SET |
|
351 | + Database::query($sql); |
|
352 | + } |
|
353 | + } |
|
354 | + |
|
355 | + function delete_linked_data() |
|
356 | + { |
|
357 | + $ref_id = $this->get_ref_id(); |
|
358 | + if (!empty($ref_id)) { |
|
359 | + //Cleans forum |
|
360 | + $sql = 'UPDATE '.$this->get_forum_thread_table().' SET |
|
361 | 361 | thread_qualify_max = 0, |
362 | 362 | thread_weight = 0, |
363 | 363 | thread_title_qualify = "" |
364 | 364 | WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id; |
365 | - Database::query($sql); |
|
366 | - } |
|
367 | - } |
|
365 | + Database::query($sql); |
|
366 | + } |
|
367 | + } |
|
368 | 368 | } |
@@ -8,102 +8,102 @@ discard block |
||
8 | 8 | */ |
9 | 9 | class StudentPublicationLink extends AbstractLink |
10 | 10 | { |
11 | - private $studpub_table = null; |
|
12 | - private $itemprop_table = null; |
|
13 | - |
|
14 | - /** |
|
15 | - * Constructor |
|
16 | - */ |
|
17 | - public function __construct() |
|
18 | - { |
|
19 | - parent::__construct(); |
|
20 | - $this->set_type(LINK_STUDENTPUBLICATION); |
|
21 | - } |
|
22 | - |
|
23 | - /** |
|
24 | - * |
|
25 | - * Returns the URL of a document |
|
26 | - * This function is loaded when using a gradebook as a tab (gradebook = -1) |
|
27 | - * see issue #2705 |
|
28 | - * |
|
29 | - */ |
|
30 | - public function get_view_url($stud_id) |
|
31 | - { |
|
32 | - // find a file uploaded by the given student, |
|
33 | - // with the same title as the evaluation name |
|
34 | - |
|
35 | - $eval = $this->get_evaluation(); |
|
36 | - $stud_id = intval($stud_id); |
|
37 | - |
|
38 | - $sql = 'SELECT pub.url |
|
11 | + private $studpub_table = null; |
|
12 | + private $itemprop_table = null; |
|
13 | + |
|
14 | + /** |
|
15 | + * Constructor |
|
16 | + */ |
|
17 | + public function __construct() |
|
18 | + { |
|
19 | + parent::__construct(); |
|
20 | + $this->set_type(LINK_STUDENTPUBLICATION); |
|
21 | + } |
|
22 | + |
|
23 | + /** |
|
24 | + * |
|
25 | + * Returns the URL of a document |
|
26 | + * This function is loaded when using a gradebook as a tab (gradebook = -1) |
|
27 | + * see issue #2705 |
|
28 | + * |
|
29 | + */ |
|
30 | + public function get_view_url($stud_id) |
|
31 | + { |
|
32 | + // find a file uploaded by the given student, |
|
33 | + // with the same title as the evaluation name |
|
34 | + |
|
35 | + $eval = $this->get_evaluation(); |
|
36 | + $stud_id = intval($stud_id); |
|
37 | + |
|
38 | + $sql = 'SELECT pub.url |
|
39 | 39 | FROM '.$this->get_itemprop_table().' prop, '.$this->get_studpub_table().' pub' |
40 | - ." WHERE |
|
40 | + ." WHERE |
|
41 | 41 | prop.c_id = ".$this->course_id." AND |
42 | 42 | pub.c_id = ".$this->course_id." AND |
43 | 43 | prop.tool = 'work'" |
44 | - .' AND prop.insert_user_id = '.$stud_id |
|
45 | - .' AND prop.ref = pub.id' |
|
46 | - ." AND pub.title = '".Database::escape_string($eval->get_name())."' AND pub.session_id=".api_get_session_id().""; |
|
47 | - |
|
48 | - $result = Database::query($sql); |
|
49 | - if ($fileurl = Database::fetch_row($result)) { |
|
50 | - return null; |
|
51 | - } else { |
|
52 | - return null; |
|
53 | - } |
|
54 | - } |
|
55 | - |
|
56 | - public function get_type_name() |
|
57 | - { |
|
58 | - return get_lang('Works'); |
|
59 | - } |
|
60 | - |
|
61 | - public function is_allowed_to_change_name() |
|
62 | - { |
|
63 | - return false; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Generate an array of exercises that a teacher hasn't created a link for. |
|
68 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
69 | - */ |
|
70 | - public function get_not_created_links() |
|
71 | - { |
|
72 | - return false; |
|
73 | - if (empty($this->course_code)) { |
|
74 | - die('Error in get_not_created_links() : course code not set'); |
|
75 | - } |
|
76 | - $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
77 | - |
|
78 | - $sql = 'SELECT id, url from '.$this->get_studpub_table() |
|
79 | - .' pup WHERE c_id = '.$this->course_id.' AND has_properties != '."''".' AND id NOT IN' |
|
80 | - .' (SELECT ref_id FROM '.$tbl_grade_links |
|
81 | - .' WHERE type = '.LINK_STUDENTPUBLICATION |
|
82 | - ." AND course_code = '".Database::escape_string($this->get_course_code())."'" |
|
83 | - .') AND pub.session_id='.api_get_session_id().''; |
|
84 | - |
|
85 | - $result = Database::query($sql); |
|
86 | - |
|
87 | - $cats=array(); |
|
88 | - while ($data=Database::fetch_array($result)) { |
|
89 | - $cats[] = array ($data['id'], $data['url']); |
|
90 | - } |
|
91 | - return $cats; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Generate an array of all exercises available. |
|
96 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
97 | - */ |
|
98 | - public function get_all_links() |
|
99 | - { |
|
100 | - if (empty($this->course_code)) { |
|
101 | - die('Error in get_not_created_links() : course code not set'); |
|
102 | - } |
|
103 | - $tbl_grade_links = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); |
|
104 | - |
|
105 | - $session_id = api_get_session_id(); |
|
106 | - /* |
|
44 | + .' AND prop.insert_user_id = '.$stud_id |
|
45 | + .' AND prop.ref = pub.id' |
|
46 | + ." AND pub.title = '".Database::escape_string($eval->get_name())."' AND pub.session_id=".api_get_session_id().""; |
|
47 | + |
|
48 | + $result = Database::query($sql); |
|
49 | + if ($fileurl = Database::fetch_row($result)) { |
|
50 | + return null; |
|
51 | + } else { |
|
52 | + return null; |
|
53 | + } |
|
54 | + } |
|
55 | + |
|
56 | + public function get_type_name() |
|
57 | + { |
|
58 | + return get_lang('Works'); |
|
59 | + } |
|
60 | + |
|
61 | + public function is_allowed_to_change_name() |
|
62 | + { |
|
63 | + return false; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Generate an array of exercises that a teacher hasn't created a link for. |
|
68 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
69 | + */ |
|
70 | + public function get_not_created_links() |
|
71 | + { |
|
72 | + return false; |
|
73 | + if (empty($this->course_code)) { |
|
74 | + die('Error in get_not_created_links() : course code not set'); |
|
75 | + } |
|
76 | + $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
77 | + |
|
78 | + $sql = 'SELECT id, url from '.$this->get_studpub_table() |
|
79 | + .' pup WHERE c_id = '.$this->course_id.' AND has_properties != '."''".' AND id NOT IN' |
|
80 | + .' (SELECT ref_id FROM '.$tbl_grade_links |
|
81 | + .' WHERE type = '.LINK_STUDENTPUBLICATION |
|
82 | + ." AND course_code = '".Database::escape_string($this->get_course_code())."'" |
|
83 | + .') AND pub.session_id='.api_get_session_id().''; |
|
84 | + |
|
85 | + $result = Database::query($sql); |
|
86 | + |
|
87 | + $cats=array(); |
|
88 | + while ($data=Database::fetch_array($result)) { |
|
89 | + $cats[] = array ($data['id'], $data['url']); |
|
90 | + } |
|
91 | + return $cats; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Generate an array of all exercises available. |
|
96 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
97 | + */ |
|
98 | + public function get_all_links() |
|
99 | + { |
|
100 | + if (empty($this->course_code)) { |
|
101 | + die('Error in get_not_created_links() : course code not set'); |
|
102 | + } |
|
103 | + $tbl_grade_links = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); |
|
104 | + |
|
105 | + $session_id = api_get_session_id(); |
|
106 | + /* |
|
107 | 107 | if (empty($session_id)) { |
108 | 108 | $session_condition = api_get_session_condition(0, true); |
109 | 109 | } else { |
@@ -112,68 +112,68 @@ discard block |
||
112 | 112 | $sql = "SELECT id, url, title FROM $tbl_grade_links |
113 | 113 | WHERE c_id = {$this->course_id} AND filetype='folder' AND active = 1 $session_condition ";*/ |
114 | 114 | |
115 | - //Only show works from the session |
|
116 | - //AND has_properties != '' |
|
117 | - $sql = "SELECT id, url, title FROM $tbl_grade_links |
|
115 | + //Only show works from the session |
|
116 | + //AND has_properties != '' |
|
117 | + $sql = "SELECT id, url, title FROM $tbl_grade_links |
|
118 | 118 | WHERE |
119 | 119 | c_id = {$this->course_id} AND |
120 | 120 | active = 1 AND |
121 | 121 | filetype='folder' AND |
122 | 122 | session_id = ".api_get_session_id().""; |
123 | 123 | |
124 | - $result = Database::query($sql); |
|
125 | - while ($data = Database::fetch_array($result)) { |
|
126 | - $work_name = $data['title']; |
|
127 | - if (empty($work_name)) { |
|
128 | - $work_name = basename($data['url']); |
|
129 | - } |
|
130 | - $cats[] = array ($data['id'], $work_name); |
|
131 | - } |
|
132 | - $cats=isset($cats) ? $cats : array(); |
|
133 | - return $cats; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Has anyone done this exercise yet ? |
|
138 | - */ |
|
139 | - public function has_results() |
|
140 | - { |
|
141 | - $tbl_grade_links = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); |
|
142 | - $sql = 'SELECT count(*) AS number FROM '.$tbl_grade_links." |
|
124 | + $result = Database::query($sql); |
|
125 | + while ($data = Database::fetch_array($result)) { |
|
126 | + $work_name = $data['title']; |
|
127 | + if (empty($work_name)) { |
|
128 | + $work_name = basename($data['url']); |
|
129 | + } |
|
130 | + $cats[] = array ($data['id'], $work_name); |
|
131 | + } |
|
132 | + $cats=isset($cats) ? $cats : array(); |
|
133 | + return $cats; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Has anyone done this exercise yet ? |
|
138 | + */ |
|
139 | + public function has_results() |
|
140 | + { |
|
141 | + $tbl_grade_links = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); |
|
142 | + $sql = 'SELECT count(*) AS number FROM '.$tbl_grade_links." |
|
143 | 143 | WHERE c_id = {$this->course_id} AND |
144 | 144 | parent_id = '".intval($this->get_ref_id())."' AND |
145 | 145 | session_id =".api_get_session_id().""; |
146 | - $result = Database::query($sql); |
|
147 | - $number = Database::fetch_row($result); |
|
148 | - return ($number[0] != 0); |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * @param null $stud_id |
|
153 | - * @return array|null |
|
154 | - */ |
|
155 | - public function calc_score($stud_id = null, $type = null) |
|
156 | - { |
|
157 | - $stud_id = intval($stud_id); |
|
158 | - $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); |
|
159 | - $sql = 'SELECT * FROM '.$table." |
|
146 | + $result = Database::query($sql); |
|
147 | + $number = Database::fetch_row($result); |
|
148 | + return ($number[0] != 0); |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * @param null $stud_id |
|
153 | + * @return array|null |
|
154 | + */ |
|
155 | + public function calc_score($stud_id = null, $type = null) |
|
156 | + { |
|
157 | + $stud_id = intval($stud_id); |
|
158 | + $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); |
|
159 | + $sql = 'SELECT * FROM '.$table." |
|
160 | 160 | WHERE |
161 | 161 | c_id = {$this->course_id} AND |
162 | 162 | id = '".intval($this->get_ref_id())."' AND |
163 | 163 | session_id = ".api_get_session_id()." |
164 | 164 | " |
165 | - ; |
|
165 | + ; |
|
166 | 166 | |
167 | - $query = Database::query($sql); |
|
168 | - $assignment = Database::fetch_array($query); |
|
167 | + $query = Database::query($sql); |
|
168 | + $assignment = Database::fetch_array($query); |
|
169 | 169 | |
170 | - if (count($assignment) == 0) { |
|
171 | - $parentId = '0'; |
|
172 | - } else { |
|
173 | - $parentId = $assignment['id']; |
|
174 | - } |
|
170 | + if (count($assignment) == 0) { |
|
171 | + $parentId = '0'; |
|
172 | + } else { |
|
173 | + $parentId = $assignment['id']; |
|
174 | + } |
|
175 | 175 | |
176 | - $sql = 'SELECT * FROM '.$table.' |
|
176 | + $sql = 'SELECT * FROM '.$table.' |
|
177 | 177 | WHERE |
178 | 178 | c_id = '.$this->course_id.' AND |
179 | 179 | active = 1 AND |
@@ -181,190 +181,190 @@ discard block |
||
181 | 181 | session_id = '.api_get_session_id() .' AND |
182 | 182 | qualificator_id <> 0 |
183 | 183 | '; |
184 | - if (!empty($stud_id)) { |
|
185 | - $sql .= " AND user_id = $stud_id "; |
|
186 | - } |
|
187 | - |
|
188 | - $order = api_get_setting('student_publication_to_take_in_gradebook'); |
|
189 | - |
|
190 | - switch ($order) { |
|
191 | - case 'last': |
|
192 | - // latest attempt |
|
193 | - $sql .= ' ORDER BY sent_date DESC'; |
|
194 | - break; |
|
195 | - case 'first': |
|
196 | - default: |
|
197 | - // first attempt |
|
198 | - $sql .= ' ORDER BY id'; |
|
199 | - break; |
|
200 | - } |
|
201 | - |
|
202 | - $scores = Database::query($sql); |
|
203 | - |
|
204 | - // for 1 student |
|
205 | - if (!empty($stud_id)) { |
|
206 | - if ($data = Database::fetch_array($scores)) { |
|
207 | - return array( |
|
208 | - $data['qualification'], |
|
209 | - $assignment['qualification'] |
|
210 | - ); |
|
211 | - } else { |
|
212 | - return ''; |
|
213 | - } |
|
214 | - } else { |
|
215 | - $students = array(); // user list, needed to make sure we only |
|
216 | - // take first attempts into account |
|
217 | - $rescount = 0; |
|
218 | - $sum = 0; |
|
219 | - $bestResult = 0; |
|
220 | - $weight = 0; |
|
221 | - $sumResult = 0; |
|
222 | - $myResult = 0; |
|
223 | - |
|
224 | - while ($data = Database::fetch_array($scores)) { |
|
225 | - if (!(array_key_exists($data['user_id'], $students))) { |
|
226 | - if ($assignment['qualification'] != 0) { |
|
227 | - $students[$data['user_id']] = $data['qualification']; |
|
228 | - $rescount++; |
|
229 | - $sum += $data['qualification'] / $assignment['qualification']; |
|
230 | - $sumResult += $data['qualification']; |
|
231 | - |
|
232 | - if ($data['qualification'] > $bestResult) { |
|
233 | - $bestResult = $data['qualification']; |
|
234 | - } |
|
235 | - $weight = $assignment['qualification']; |
|
236 | - } |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - if ($rescount == 0) { |
|
241 | - return null; |
|
242 | - } else { |
|
243 | - switch ($type) { |
|
244 | - case 'best': |
|
245 | - return array($bestResult, $weight); |
|
246 | - break; |
|
247 | - case 'average': |
|
248 | - return array($sumResult/$rescount, $weight); |
|
249 | - break; |
|
250 | - case 'ranking': |
|
251 | - return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
252 | - break; |
|
253 | - default: |
|
254 | - return array($sum, $rescount); |
|
255 | - break; |
|
256 | - } |
|
257 | - } |
|
258 | - } |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * Lazy load function to get the database table of the student publications |
|
263 | - */ |
|
264 | - private function get_studpub_table() |
|
265 | - { |
|
266 | - return $this->studpub_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * Lazy load function to get the database table of the item properties |
|
271 | - */ |
|
272 | - private function get_itemprop_table() |
|
273 | - { |
|
274 | - return $this->itemprop_table = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
|
275 | - } |
|
276 | - |
|
277 | - public function needs_name_and_description() |
|
278 | - { |
|
279 | - return false; |
|
280 | - } |
|
281 | - |
|
282 | - public function get_name() |
|
283 | - { |
|
284 | - $this->get_exercise_data(); |
|
285 | - return (isset($this->exercise_data['title']) && !empty($this->exercise_data['title'])) ? $this->exercise_data['title'] : get_lang('Untitled'); |
|
286 | - } |
|
287 | - |
|
288 | - public function get_description() |
|
289 | - { |
|
290 | - $this->get_exercise_data(); |
|
291 | - return isset($this->exercise_data['description']) ? $this->exercise_data['description'] : null; |
|
292 | - } |
|
293 | - |
|
294 | - public function get_test_id() |
|
295 | - { |
|
296 | - return 'DEBUG:ID'; |
|
297 | - } |
|
298 | - |
|
299 | - public function get_link() |
|
300 | - { |
|
301 | - $session_id = api_get_session_id(); |
|
302 | - $url = api_get_path(WEB_PATH).'main/work/work.php?session_id='.$session_id.'&cidReq='.$this->get_course_code().'&id='.$this->exercise_data['id'].'&gradebook=view'; |
|
303 | - return $url; |
|
304 | - } |
|
305 | - |
|
306 | - private function get_exercise_data() |
|
307 | - { |
|
308 | - $tbl_name = $this->get_studpub_table(); |
|
309 | - $course_info = api_get_course_info($this->get_course_code()); |
|
310 | - if ($tbl_name=='') { |
|
311 | - return false; |
|
312 | - } elseif (!isset($this->exercise_data)) { |
|
313 | - $sql = 'SELECT * FROM '.$this->get_studpub_table()." |
|
184 | + if (!empty($stud_id)) { |
|
185 | + $sql .= " AND user_id = $stud_id "; |
|
186 | + } |
|
187 | + |
|
188 | + $order = api_get_setting('student_publication_to_take_in_gradebook'); |
|
189 | + |
|
190 | + switch ($order) { |
|
191 | + case 'last': |
|
192 | + // latest attempt |
|
193 | + $sql .= ' ORDER BY sent_date DESC'; |
|
194 | + break; |
|
195 | + case 'first': |
|
196 | + default: |
|
197 | + // first attempt |
|
198 | + $sql .= ' ORDER BY id'; |
|
199 | + break; |
|
200 | + } |
|
201 | + |
|
202 | + $scores = Database::query($sql); |
|
203 | + |
|
204 | + // for 1 student |
|
205 | + if (!empty($stud_id)) { |
|
206 | + if ($data = Database::fetch_array($scores)) { |
|
207 | + return array( |
|
208 | + $data['qualification'], |
|
209 | + $assignment['qualification'] |
|
210 | + ); |
|
211 | + } else { |
|
212 | + return ''; |
|
213 | + } |
|
214 | + } else { |
|
215 | + $students = array(); // user list, needed to make sure we only |
|
216 | + // take first attempts into account |
|
217 | + $rescount = 0; |
|
218 | + $sum = 0; |
|
219 | + $bestResult = 0; |
|
220 | + $weight = 0; |
|
221 | + $sumResult = 0; |
|
222 | + $myResult = 0; |
|
223 | + |
|
224 | + while ($data = Database::fetch_array($scores)) { |
|
225 | + if (!(array_key_exists($data['user_id'], $students))) { |
|
226 | + if ($assignment['qualification'] != 0) { |
|
227 | + $students[$data['user_id']] = $data['qualification']; |
|
228 | + $rescount++; |
|
229 | + $sum += $data['qualification'] / $assignment['qualification']; |
|
230 | + $sumResult += $data['qualification']; |
|
231 | + |
|
232 | + if ($data['qualification'] > $bestResult) { |
|
233 | + $bestResult = $data['qualification']; |
|
234 | + } |
|
235 | + $weight = $assignment['qualification']; |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + if ($rescount == 0) { |
|
241 | + return null; |
|
242 | + } else { |
|
243 | + switch ($type) { |
|
244 | + case 'best': |
|
245 | + return array($bestResult, $weight); |
|
246 | + break; |
|
247 | + case 'average': |
|
248 | + return array($sumResult/$rescount, $weight); |
|
249 | + break; |
|
250 | + case 'ranking': |
|
251 | + return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
252 | + break; |
|
253 | + default: |
|
254 | + return array($sum, $rescount); |
|
255 | + break; |
|
256 | + } |
|
257 | + } |
|
258 | + } |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * Lazy load function to get the database table of the student publications |
|
263 | + */ |
|
264 | + private function get_studpub_table() |
|
265 | + { |
|
266 | + return $this->studpub_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * Lazy load function to get the database table of the item properties |
|
271 | + */ |
|
272 | + private function get_itemprop_table() |
|
273 | + { |
|
274 | + return $this->itemprop_table = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
|
275 | + } |
|
276 | + |
|
277 | + public function needs_name_and_description() |
|
278 | + { |
|
279 | + return false; |
|
280 | + } |
|
281 | + |
|
282 | + public function get_name() |
|
283 | + { |
|
284 | + $this->get_exercise_data(); |
|
285 | + return (isset($this->exercise_data['title']) && !empty($this->exercise_data['title'])) ? $this->exercise_data['title'] : get_lang('Untitled'); |
|
286 | + } |
|
287 | + |
|
288 | + public function get_description() |
|
289 | + { |
|
290 | + $this->get_exercise_data(); |
|
291 | + return isset($this->exercise_data['description']) ? $this->exercise_data['description'] : null; |
|
292 | + } |
|
293 | + |
|
294 | + public function get_test_id() |
|
295 | + { |
|
296 | + return 'DEBUG:ID'; |
|
297 | + } |
|
298 | + |
|
299 | + public function get_link() |
|
300 | + { |
|
301 | + $session_id = api_get_session_id(); |
|
302 | + $url = api_get_path(WEB_PATH).'main/work/work.php?session_id='.$session_id.'&cidReq='.$this->get_course_code().'&id='.$this->exercise_data['id'].'&gradebook=view'; |
|
303 | + return $url; |
|
304 | + } |
|
305 | + |
|
306 | + private function get_exercise_data() |
|
307 | + { |
|
308 | + $tbl_name = $this->get_studpub_table(); |
|
309 | + $course_info = api_get_course_info($this->get_course_code()); |
|
310 | + if ($tbl_name=='') { |
|
311 | + return false; |
|
312 | + } elseif (!isset($this->exercise_data)) { |
|
313 | + $sql = 'SELECT * FROM '.$this->get_studpub_table()." |
|
314 | 314 | WHERE |
315 | 315 | c_id ='".$course_info['real_id']."' AND |
316 | 316 | id = '".intval($this->get_ref_id())."' "; |
317 | - $query = Database::query($sql); |
|
318 | - $this->exercise_data = Database::fetch_array($query); |
|
319 | - } |
|
320 | - return $this->exercise_data; |
|
321 | - } |
|
322 | - |
|
323 | - public function needs_max() |
|
324 | - { |
|
325 | - return false; |
|
326 | - } |
|
327 | - |
|
328 | - public function needs_results() |
|
329 | - { |
|
330 | - return false; |
|
331 | - } |
|
332 | - |
|
333 | - public function is_valid_link() |
|
334 | - { |
|
335 | - $sql = 'SELECT count(id) FROM '.$this->get_studpub_table().' |
|
317 | + $query = Database::query($sql); |
|
318 | + $this->exercise_data = Database::fetch_array($query); |
|
319 | + } |
|
320 | + return $this->exercise_data; |
|
321 | + } |
|
322 | + |
|
323 | + public function needs_max() |
|
324 | + { |
|
325 | + return false; |
|
326 | + } |
|
327 | + |
|
328 | + public function needs_results() |
|
329 | + { |
|
330 | + return false; |
|
331 | + } |
|
332 | + |
|
333 | + public function is_valid_link() |
|
334 | + { |
|
335 | + $sql = 'SELECT count(id) FROM '.$this->get_studpub_table().' |
|
336 | 336 | WHERE c_id = "'.$this->course_id.'" AND id = '.intval($this->get_ref_id()).''; |
337 | - $result = Database::query($sql); |
|
338 | - $number = Database::fetch_row($result); |
|
339 | - return ($number[0] != 0); |
|
340 | - } |
|
341 | - |
|
342 | - public function get_icon_name() |
|
343 | - { |
|
344 | - return 'studentpublication'; |
|
345 | - } |
|
346 | - |
|
347 | - public function save_linked_data() |
|
348 | - { |
|
349 | - $weight = (float)$this->get_weight(); |
|
350 | - $ref_id = $this->get_ref_id(); |
|
351 | - |
|
352 | - if (!empty($ref_id)) { |
|
353 | - //Cleans works |
|
354 | - $sql = 'UPDATE '.$this->get_studpub_table().' SET weight= '.$weight.' |
|
337 | + $result = Database::query($sql); |
|
338 | + $number = Database::fetch_row($result); |
|
339 | + return ($number[0] != 0); |
|
340 | + } |
|
341 | + |
|
342 | + public function get_icon_name() |
|
343 | + { |
|
344 | + return 'studentpublication'; |
|
345 | + } |
|
346 | + |
|
347 | + public function save_linked_data() |
|
348 | + { |
|
349 | + $weight = (float)$this->get_weight(); |
|
350 | + $ref_id = $this->get_ref_id(); |
|
351 | + |
|
352 | + if (!empty($ref_id)) { |
|
353 | + //Cleans works |
|
354 | + $sql = 'UPDATE '.$this->get_studpub_table().' SET weight= '.$weight.' |
|
355 | 355 | WHERE c_id = '.$this->course_id.' AND id ='.$ref_id; |
356 | - Database::query($sql); |
|
357 | - } |
|
358 | - } |
|
359 | - |
|
360 | - public function delete_linked_data() |
|
361 | - { |
|
362 | - $ref_id = $this->get_ref_id(); |
|
363 | - if (!empty($ref_id)) { |
|
364 | - //Cleans works |
|
365 | - $sql = 'UPDATE '.$this->get_studpub_table().' SET weight=0 |
|
356 | + Database::query($sql); |
|
357 | + } |
|
358 | + } |
|
359 | + |
|
360 | + public function delete_linked_data() |
|
361 | + { |
|
362 | + $ref_id = $this->get_ref_id(); |
|
363 | + if (!empty($ref_id)) { |
|
364 | + //Cleans works |
|
365 | + $sql = 'UPDATE '.$this->get_studpub_table().' SET weight=0 |
|
366 | 366 | WHERE c_id = '.$this->course_id.' AND id ='.$ref_id; |
367 | - Database::query($sql); |
|
368 | - } |
|
369 | - } |
|
367 | + Database::query($sql); |
|
368 | + } |
|
369 | + } |
|
370 | 370 | } |
@@ -9,364 +9,364 @@ discard block |
||
9 | 9 | */ |
10 | 10 | class Evaluation implements GradebookItem |
11 | 11 | { |
12 | - private $id; |
|
13 | - private $name; |
|
14 | - private $description; |
|
15 | - private $user_id; |
|
16 | - private $course_code; |
|
17 | - /** @var Category */ |
|
18 | - private $category; |
|
19 | - private $created_at; |
|
20 | - private $weight; |
|
21 | - private $eval_max; |
|
22 | - private $visible; |
|
23 | - private $sessionId; |
|
24 | - public $studentList; |
|
25 | - |
|
26 | - /** |
|
27 | - * Construct |
|
28 | - */ |
|
29 | - public function __construct() |
|
30 | - { |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @return Category |
|
35 | - */ |
|
36 | - public function getCategory() |
|
37 | - { |
|
38 | - return $this->category; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @param Category $category |
|
43 | - */ |
|
44 | - public function setCategory($category) |
|
45 | - { |
|
46 | - $this->category = $category; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * @return int |
|
51 | - */ |
|
52 | - public function get_category_id() |
|
53 | - { |
|
54 | - return $this->category->get_id(); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param int $category_id |
|
59 | - */ |
|
60 | - public function set_category_id($category_id) |
|
61 | - { |
|
62 | - $categories = Category::load($category_id); |
|
63 | - if (isset($categories[0])) { |
|
64 | - $this->setCategory($categories[0]); |
|
65 | - } |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @return int |
|
70 | - */ |
|
71 | - public function get_id() |
|
72 | - { |
|
73 | - return $this->id; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function get_name() |
|
80 | - { |
|
81 | - return $this->name; |
|
82 | - } |
|
83 | - |
|
84 | - public function get_description() |
|
85 | - { |
|
86 | - return $this->description; |
|
87 | - } |
|
88 | - |
|
89 | - public function get_user_id() |
|
90 | - { |
|
91 | - return $this->user_id; |
|
92 | - } |
|
93 | - |
|
94 | - public function get_course_code() |
|
95 | - { |
|
96 | - return $this->course_code; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @return int |
|
101 | - */ |
|
102 | - public function getSessionId() |
|
103 | - { |
|
104 | - return $this->sessionId; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @param int $sessionId |
|
109 | - */ |
|
110 | - public function setSessionId($sessionId) |
|
111 | - { |
|
112 | - $this->sessionId = intval($sessionId); |
|
113 | - } |
|
114 | - |
|
115 | - public function get_date() |
|
116 | - { |
|
117 | - return $this->created_at; |
|
118 | - } |
|
119 | - |
|
120 | - public function get_weight() |
|
121 | - { |
|
122 | - return $this->weight; |
|
123 | - } |
|
124 | - |
|
125 | - public function get_max() |
|
126 | - { |
|
127 | - return $this->eval_max; |
|
128 | - } |
|
129 | - |
|
130 | - public function get_type() |
|
131 | - { |
|
132 | - return $this->type; |
|
133 | - } |
|
134 | - |
|
135 | - public function is_visible() |
|
136 | - { |
|
137 | - return $this->visible; |
|
138 | - } |
|
139 | - |
|
140 | - public function get_locked() |
|
141 | - { |
|
142 | - return $this->locked; |
|
143 | - } |
|
144 | - |
|
145 | - public function is_locked() |
|
146 | - { |
|
147 | - return isset($this->locked) && $this->locked == 1 ? true : false; |
|
148 | - } |
|
149 | - |
|
150 | - public function set_id($id) |
|
151 | - { |
|
152 | - $this->id = $id; |
|
153 | - } |
|
154 | - |
|
155 | - public function set_name($name) |
|
156 | - { |
|
157 | - $this->name = $name; |
|
158 | - } |
|
159 | - |
|
160 | - public function set_description($description) |
|
161 | - { |
|
162 | - $this->description = $description; |
|
163 | - } |
|
164 | - |
|
165 | - public function set_user_id($user_id) |
|
166 | - { |
|
167 | - $this->user_id = $user_id; |
|
168 | - } |
|
169 | - |
|
170 | - public function set_course_code($course_code) |
|
171 | - { |
|
172 | - $this->course_code = $course_code; |
|
173 | - } |
|
174 | - |
|
175 | - public function set_date($date) |
|
176 | - { |
|
177 | - $this->created_at = $date; |
|
178 | - } |
|
179 | - |
|
180 | - public function set_weight($weight) |
|
181 | - { |
|
182 | - $this->weight = $weight; |
|
183 | - } |
|
184 | - |
|
185 | - public function set_max($max) |
|
186 | - { |
|
187 | - $this->eval_max = $max; |
|
188 | - } |
|
189 | - |
|
190 | - public function set_visible($visible) |
|
191 | - { |
|
192 | - $this->visible = $visible; |
|
193 | - } |
|
194 | - |
|
195 | - public function set_type($type) |
|
196 | - { |
|
197 | - $this->type = $type; |
|
198 | - } |
|
199 | - |
|
200 | - public function set_locked($locked) |
|
201 | - { |
|
202 | - $this->locked = $locked; |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Retrieve evaluations and return them as an array of Evaluation objects |
|
207 | - * @param int $id evaluation id |
|
208 | - * @param int $user_id user id (evaluation owner) |
|
209 | - * @param string $course_code course code |
|
210 | - * @param int $category_id parent category |
|
211 | - * @param $visible visible |
|
212 | - */ |
|
213 | - public static function load( |
|
214 | - $id = null, |
|
215 | - $user_id = null, |
|
216 | - $course_code = null, |
|
217 | - $category_id = null, |
|
218 | - $visible = null, |
|
219 | - $locked = null |
|
220 | - ) { |
|
221 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
222 | - $sql = 'SELECT * FROM '.$tbl_grade_evaluations; |
|
223 | - $paramcount = 0; |
|
224 | - |
|
225 | - if (isset ($id)) { |
|
226 | - $sql.= ' WHERE id = '.intval($id); |
|
227 | - $paramcount ++; |
|
228 | - } |
|
229 | - |
|
230 | - if (isset ($user_id)) { |
|
231 | - if ($paramcount != 0) $sql .= ' AND'; |
|
232 | - else $sql .= ' WHERE'; |
|
233 | - $sql .= ' user_id = '.intval($user_id); |
|
234 | - $paramcount ++; |
|
235 | - } |
|
236 | - |
|
237 | - if (isset ($course_code) && $course_code <> '-1') { |
|
238 | - if ($paramcount != 0) $sql .= ' AND'; |
|
239 | - else $sql .= ' WHERE'; |
|
240 | - $sql .= " course_code = '".Database::escape_string($course_code)."'"; |
|
241 | - $paramcount ++; |
|
242 | - } |
|
243 | - |
|
244 | - if (isset ($category_id)) { |
|
245 | - if ($paramcount != 0) $sql .= ' AND'; |
|
246 | - else $sql .= ' WHERE'; |
|
247 | - $sql .= ' category_id = '.intval($category_id); |
|
248 | - $paramcount ++; |
|
249 | - } |
|
250 | - |
|
251 | - if (isset ($visible)) { |
|
252 | - if ($paramcount != 0) $sql .= ' AND'; |
|
253 | - else $sql .= ' WHERE'; |
|
254 | - $sql .= ' visible = '.intval($visible); |
|
255 | - $paramcount ++; |
|
256 | - } |
|
257 | - |
|
258 | - if (isset ($locked)) { |
|
259 | - if ($paramcount != 0) $sql .= ' AND'; |
|
260 | - else $sql .= ' WHERE'; |
|
261 | - $sql .= ' locked = '.intval($locked); |
|
262 | - } |
|
263 | - |
|
264 | - $result = Database::query($sql); |
|
265 | - $alleval = Evaluation::create_evaluation_objects_from_sql_result($result); |
|
266 | - |
|
267 | - return $alleval; |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * @param array $result |
|
274 | - * @return array |
|
275 | - */ |
|
276 | - private static function create_evaluation_objects_from_sql_result($result) |
|
277 | - { |
|
278 | - $alleval = array(); |
|
279 | - if (Database::num_rows($result)) { |
|
280 | - while ($data = Database::fetch_array($result)) { |
|
281 | - $eval= new Evaluation(); |
|
282 | - $eval->set_id($data['id']); |
|
283 | - $eval->set_name($data['name']); |
|
284 | - $eval->set_description($data['description']); |
|
285 | - $eval->set_user_id($data['user_id']); |
|
286 | - $eval->set_course_code($data['course_code']); |
|
287 | - $eval->set_category_id($data['category_id']); |
|
288 | - $eval->set_date(api_get_local_time($data['created_at'])); |
|
289 | - $eval->set_weight($data['weight']); |
|
290 | - $eval->set_max($data['max']); |
|
291 | - $eval->set_visible($data['visible']); |
|
292 | - $eval->set_type($data['type']); |
|
293 | - $eval->set_locked($data['locked']); |
|
294 | - $eval->setSessionId(api_get_session_id()); |
|
295 | - |
|
296 | - $alleval[] = $eval; |
|
297 | - } |
|
298 | - } |
|
299 | - |
|
300 | - return $alleval; |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * Insert this evaluation into the database |
|
305 | - */ |
|
306 | - public function add() |
|
307 | - { |
|
308 | - if (isset($this->name) && |
|
309 | - isset($this->user_id) && |
|
310 | - isset($this->weight) && |
|
311 | - isset ($this->eval_max) && |
|
312 | - isset($this->visible) |
|
313 | - ) { |
|
314 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
315 | - |
|
316 | - $sql = 'INSERT INTO '.$tbl_grade_evaluations |
|
317 | - .' (name, user_id, weight, max, visible'; |
|
318 | - if (isset($this->description)) { |
|
319 | - $sql .= ',description'; |
|
320 | - } |
|
321 | - if (isset($this->course_code)) { |
|
322 | - $sql .= ', course_code'; |
|
323 | - } |
|
324 | - if (isset($this->category)) { |
|
325 | - $sql .= ', category_id'; |
|
326 | - } |
|
327 | - $sql .= ', created_at'; |
|
328 | - $sql .= ',type'; |
|
329 | - $sql .= ") VALUES ('".Database::escape_string($this->get_name())."'" |
|
330 | - .','.intval($this->get_user_id()) |
|
331 | - .','.floatval($this->get_weight()) |
|
332 | - .','.intval($this->get_max()) |
|
333 | - .','.intval($this->is_visible()); |
|
334 | - if (isset($this->description)) { |
|
335 | - $sql .= ",'".Database::escape_string($this->get_description())."'"; |
|
336 | - } |
|
337 | - if (isset($this->course_code)) { |
|
338 | - $sql .= ",'".Database::escape_string($this->get_course_code())."'"; |
|
339 | - } |
|
340 | - if (isset($this->category)) { |
|
341 | - $sql .= ','.intval($this->get_category_id()); |
|
342 | - } |
|
343 | - if (empty($this->type)) { |
|
344 | - $this->type = 'evaluation'; |
|
345 | - } |
|
346 | - $sql .= ", '".api_get_utc_datetime()."'"; |
|
347 | - $sql .= ',\''.Database::escape_string($this->type).'\''; |
|
348 | - $sql .= ")"; |
|
349 | - |
|
350 | - Database::query($sql); |
|
351 | - $this->set_id(Database::insert_id()); |
|
352 | - } else { |
|
353 | - die('Error in Evaluation add: required field empty'); |
|
354 | - } |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * @param int $idevaluation |
|
359 | - */ |
|
360 | - public function add_evaluation_log($idevaluation) |
|
361 | - { |
|
362 | - if (!empty($idevaluation)) { |
|
363 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
364 | - $tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG); |
|
365 | - $eval = new Evaluation(); |
|
366 | - $dateobject = $eval->load($idevaluation,null,null,null,null); |
|
367 | - $arreval = get_object_vars($dateobject[0]); |
|
368 | - if (!empty($arreval['id'])) { |
|
369 | - $sql = 'SELECT weight from '.$tbl_grade_evaluations.' |
|
12 | + private $id; |
|
13 | + private $name; |
|
14 | + private $description; |
|
15 | + private $user_id; |
|
16 | + private $course_code; |
|
17 | + /** @var Category */ |
|
18 | + private $category; |
|
19 | + private $created_at; |
|
20 | + private $weight; |
|
21 | + private $eval_max; |
|
22 | + private $visible; |
|
23 | + private $sessionId; |
|
24 | + public $studentList; |
|
25 | + |
|
26 | + /** |
|
27 | + * Construct |
|
28 | + */ |
|
29 | + public function __construct() |
|
30 | + { |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @return Category |
|
35 | + */ |
|
36 | + public function getCategory() |
|
37 | + { |
|
38 | + return $this->category; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @param Category $category |
|
43 | + */ |
|
44 | + public function setCategory($category) |
|
45 | + { |
|
46 | + $this->category = $category; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * @return int |
|
51 | + */ |
|
52 | + public function get_category_id() |
|
53 | + { |
|
54 | + return $this->category->get_id(); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param int $category_id |
|
59 | + */ |
|
60 | + public function set_category_id($category_id) |
|
61 | + { |
|
62 | + $categories = Category::load($category_id); |
|
63 | + if (isset($categories[0])) { |
|
64 | + $this->setCategory($categories[0]); |
|
65 | + } |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @return int |
|
70 | + */ |
|
71 | + public function get_id() |
|
72 | + { |
|
73 | + return $this->id; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function get_name() |
|
80 | + { |
|
81 | + return $this->name; |
|
82 | + } |
|
83 | + |
|
84 | + public function get_description() |
|
85 | + { |
|
86 | + return $this->description; |
|
87 | + } |
|
88 | + |
|
89 | + public function get_user_id() |
|
90 | + { |
|
91 | + return $this->user_id; |
|
92 | + } |
|
93 | + |
|
94 | + public function get_course_code() |
|
95 | + { |
|
96 | + return $this->course_code; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @return int |
|
101 | + */ |
|
102 | + public function getSessionId() |
|
103 | + { |
|
104 | + return $this->sessionId; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @param int $sessionId |
|
109 | + */ |
|
110 | + public function setSessionId($sessionId) |
|
111 | + { |
|
112 | + $this->sessionId = intval($sessionId); |
|
113 | + } |
|
114 | + |
|
115 | + public function get_date() |
|
116 | + { |
|
117 | + return $this->created_at; |
|
118 | + } |
|
119 | + |
|
120 | + public function get_weight() |
|
121 | + { |
|
122 | + return $this->weight; |
|
123 | + } |
|
124 | + |
|
125 | + public function get_max() |
|
126 | + { |
|
127 | + return $this->eval_max; |
|
128 | + } |
|
129 | + |
|
130 | + public function get_type() |
|
131 | + { |
|
132 | + return $this->type; |
|
133 | + } |
|
134 | + |
|
135 | + public function is_visible() |
|
136 | + { |
|
137 | + return $this->visible; |
|
138 | + } |
|
139 | + |
|
140 | + public function get_locked() |
|
141 | + { |
|
142 | + return $this->locked; |
|
143 | + } |
|
144 | + |
|
145 | + public function is_locked() |
|
146 | + { |
|
147 | + return isset($this->locked) && $this->locked == 1 ? true : false; |
|
148 | + } |
|
149 | + |
|
150 | + public function set_id($id) |
|
151 | + { |
|
152 | + $this->id = $id; |
|
153 | + } |
|
154 | + |
|
155 | + public function set_name($name) |
|
156 | + { |
|
157 | + $this->name = $name; |
|
158 | + } |
|
159 | + |
|
160 | + public function set_description($description) |
|
161 | + { |
|
162 | + $this->description = $description; |
|
163 | + } |
|
164 | + |
|
165 | + public function set_user_id($user_id) |
|
166 | + { |
|
167 | + $this->user_id = $user_id; |
|
168 | + } |
|
169 | + |
|
170 | + public function set_course_code($course_code) |
|
171 | + { |
|
172 | + $this->course_code = $course_code; |
|
173 | + } |
|
174 | + |
|
175 | + public function set_date($date) |
|
176 | + { |
|
177 | + $this->created_at = $date; |
|
178 | + } |
|
179 | + |
|
180 | + public function set_weight($weight) |
|
181 | + { |
|
182 | + $this->weight = $weight; |
|
183 | + } |
|
184 | + |
|
185 | + public function set_max($max) |
|
186 | + { |
|
187 | + $this->eval_max = $max; |
|
188 | + } |
|
189 | + |
|
190 | + public function set_visible($visible) |
|
191 | + { |
|
192 | + $this->visible = $visible; |
|
193 | + } |
|
194 | + |
|
195 | + public function set_type($type) |
|
196 | + { |
|
197 | + $this->type = $type; |
|
198 | + } |
|
199 | + |
|
200 | + public function set_locked($locked) |
|
201 | + { |
|
202 | + $this->locked = $locked; |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Retrieve evaluations and return them as an array of Evaluation objects |
|
207 | + * @param int $id evaluation id |
|
208 | + * @param int $user_id user id (evaluation owner) |
|
209 | + * @param string $course_code course code |
|
210 | + * @param int $category_id parent category |
|
211 | + * @param $visible visible |
|
212 | + */ |
|
213 | + public static function load( |
|
214 | + $id = null, |
|
215 | + $user_id = null, |
|
216 | + $course_code = null, |
|
217 | + $category_id = null, |
|
218 | + $visible = null, |
|
219 | + $locked = null |
|
220 | + ) { |
|
221 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
222 | + $sql = 'SELECT * FROM '.$tbl_grade_evaluations; |
|
223 | + $paramcount = 0; |
|
224 | + |
|
225 | + if (isset ($id)) { |
|
226 | + $sql.= ' WHERE id = '.intval($id); |
|
227 | + $paramcount ++; |
|
228 | + } |
|
229 | + |
|
230 | + if (isset ($user_id)) { |
|
231 | + if ($paramcount != 0) $sql .= ' AND'; |
|
232 | + else $sql .= ' WHERE'; |
|
233 | + $sql .= ' user_id = '.intval($user_id); |
|
234 | + $paramcount ++; |
|
235 | + } |
|
236 | + |
|
237 | + if (isset ($course_code) && $course_code <> '-1') { |
|
238 | + if ($paramcount != 0) $sql .= ' AND'; |
|
239 | + else $sql .= ' WHERE'; |
|
240 | + $sql .= " course_code = '".Database::escape_string($course_code)."'"; |
|
241 | + $paramcount ++; |
|
242 | + } |
|
243 | + |
|
244 | + if (isset ($category_id)) { |
|
245 | + if ($paramcount != 0) $sql .= ' AND'; |
|
246 | + else $sql .= ' WHERE'; |
|
247 | + $sql .= ' category_id = '.intval($category_id); |
|
248 | + $paramcount ++; |
|
249 | + } |
|
250 | + |
|
251 | + if (isset ($visible)) { |
|
252 | + if ($paramcount != 0) $sql .= ' AND'; |
|
253 | + else $sql .= ' WHERE'; |
|
254 | + $sql .= ' visible = '.intval($visible); |
|
255 | + $paramcount ++; |
|
256 | + } |
|
257 | + |
|
258 | + if (isset ($locked)) { |
|
259 | + if ($paramcount != 0) $sql .= ' AND'; |
|
260 | + else $sql .= ' WHERE'; |
|
261 | + $sql .= ' locked = '.intval($locked); |
|
262 | + } |
|
263 | + |
|
264 | + $result = Database::query($sql); |
|
265 | + $alleval = Evaluation::create_evaluation_objects_from_sql_result($result); |
|
266 | + |
|
267 | + return $alleval; |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * @param array $result |
|
274 | + * @return array |
|
275 | + */ |
|
276 | + private static function create_evaluation_objects_from_sql_result($result) |
|
277 | + { |
|
278 | + $alleval = array(); |
|
279 | + if (Database::num_rows($result)) { |
|
280 | + while ($data = Database::fetch_array($result)) { |
|
281 | + $eval= new Evaluation(); |
|
282 | + $eval->set_id($data['id']); |
|
283 | + $eval->set_name($data['name']); |
|
284 | + $eval->set_description($data['description']); |
|
285 | + $eval->set_user_id($data['user_id']); |
|
286 | + $eval->set_course_code($data['course_code']); |
|
287 | + $eval->set_category_id($data['category_id']); |
|
288 | + $eval->set_date(api_get_local_time($data['created_at'])); |
|
289 | + $eval->set_weight($data['weight']); |
|
290 | + $eval->set_max($data['max']); |
|
291 | + $eval->set_visible($data['visible']); |
|
292 | + $eval->set_type($data['type']); |
|
293 | + $eval->set_locked($data['locked']); |
|
294 | + $eval->setSessionId(api_get_session_id()); |
|
295 | + |
|
296 | + $alleval[] = $eval; |
|
297 | + } |
|
298 | + } |
|
299 | + |
|
300 | + return $alleval; |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * Insert this evaluation into the database |
|
305 | + */ |
|
306 | + public function add() |
|
307 | + { |
|
308 | + if (isset($this->name) && |
|
309 | + isset($this->user_id) && |
|
310 | + isset($this->weight) && |
|
311 | + isset ($this->eval_max) && |
|
312 | + isset($this->visible) |
|
313 | + ) { |
|
314 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
315 | + |
|
316 | + $sql = 'INSERT INTO '.$tbl_grade_evaluations |
|
317 | + .' (name, user_id, weight, max, visible'; |
|
318 | + if (isset($this->description)) { |
|
319 | + $sql .= ',description'; |
|
320 | + } |
|
321 | + if (isset($this->course_code)) { |
|
322 | + $sql .= ', course_code'; |
|
323 | + } |
|
324 | + if (isset($this->category)) { |
|
325 | + $sql .= ', category_id'; |
|
326 | + } |
|
327 | + $sql .= ', created_at'; |
|
328 | + $sql .= ',type'; |
|
329 | + $sql .= ") VALUES ('".Database::escape_string($this->get_name())."'" |
|
330 | + .','.intval($this->get_user_id()) |
|
331 | + .','.floatval($this->get_weight()) |
|
332 | + .','.intval($this->get_max()) |
|
333 | + .','.intval($this->is_visible()); |
|
334 | + if (isset($this->description)) { |
|
335 | + $sql .= ",'".Database::escape_string($this->get_description())."'"; |
|
336 | + } |
|
337 | + if (isset($this->course_code)) { |
|
338 | + $sql .= ",'".Database::escape_string($this->get_course_code())."'"; |
|
339 | + } |
|
340 | + if (isset($this->category)) { |
|
341 | + $sql .= ','.intval($this->get_category_id()); |
|
342 | + } |
|
343 | + if (empty($this->type)) { |
|
344 | + $this->type = 'evaluation'; |
|
345 | + } |
|
346 | + $sql .= ", '".api_get_utc_datetime()."'"; |
|
347 | + $sql .= ',\''.Database::escape_string($this->type).'\''; |
|
348 | + $sql .= ")"; |
|
349 | + |
|
350 | + Database::query($sql); |
|
351 | + $this->set_id(Database::insert_id()); |
|
352 | + } else { |
|
353 | + die('Error in Evaluation add: required field empty'); |
|
354 | + } |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * @param int $idevaluation |
|
359 | + */ |
|
360 | + public function add_evaluation_log($idevaluation) |
|
361 | + { |
|
362 | + if (!empty($idevaluation)) { |
|
363 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
364 | + $tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG); |
|
365 | + $eval = new Evaluation(); |
|
366 | + $dateobject = $eval->load($idevaluation,null,null,null,null); |
|
367 | + $arreval = get_object_vars($dateobject[0]); |
|
368 | + if (!empty($arreval['id'])) { |
|
369 | + $sql = 'SELECT weight from '.$tbl_grade_evaluations.' |
|
370 | 370 | WHERE id='.$arreval['id']; |
371 | 371 | $rs = Database::query($sql); |
372 | 372 | $row_old_weight = Database::fetch_array($rs, 'ASSOC'); |
@@ -382,425 +382,425 @@ discard block |
||
382 | 382 | 'user_id_log' => api_get_user_id() |
383 | 383 | ]; |
384 | 384 | Database::insert($tbl_grade_linkeval_log, $params); |
385 | - } |
|
386 | - } |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Update the properties of this evaluation in the database |
|
391 | - */ |
|
392 | - public function save() |
|
393 | - { |
|
394 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
395 | - $sql = 'UPDATE '.$tbl_grade_evaluations |
|
396 | - ." SET name = '".Database::escape_string($this->get_name())."'" |
|
397 | - .', description = '; |
|
398 | - if (isset($this->description)) { |
|
399 | - $sql .= "'".Database::escape_string($this->get_description())."'"; |
|
400 | - }else { |
|
401 | - $sql .= 'null'; |
|
402 | - } |
|
403 | - $sql .= ', user_id = '.intval($this->get_user_id()) |
|
404 | - .', course_code = '; |
|
405 | - if (isset($this->course_code)) { |
|
406 | - $sql .= "'".Database::escape_string($this->get_course_code())."'"; |
|
407 | - } else { |
|
408 | - $sql .= 'null'; |
|
409 | - } |
|
410 | - $sql .= ', category_id = '; |
|
411 | - if (isset($this->category)) { |
|
412 | - $sql .= intval($this->get_category_id()); |
|
413 | - } else { |
|
414 | - $sql .= 'null'; |
|
415 | - } |
|
416 | - $sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" ' |
|
417 | - .', max = '.intval($this->get_max()) |
|
418 | - .', visible = '.intval($this->is_visible()) |
|
419 | - .' WHERE id = '.intval($this->id); |
|
420 | - //recorded history |
|
421 | - |
|
422 | - $eval_log = new Evaluation(); |
|
423 | - $eval_log->add_evaluation_log($this->id); |
|
424 | - Database::query($sql); |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Delete this evaluation from the database |
|
429 | - */ |
|
430 | - public function delete() |
|
431 | - { |
|
432 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
433 | - $sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id); |
|
434 | - Database::query($sql); |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * Check if an evaluation name (with the same parent category) already exists |
|
439 | - * @param $name name to check (if not given, the name property of this object will be checked) |
|
440 | - * @param $parent parent category |
|
441 | - */ |
|
442 | - public function does_name_exist($name, $parent) |
|
443 | - { |
|
444 | - if (!isset ($name)) { |
|
445 | - $name = $this->name; |
|
446 | - $parent = $this->category; |
|
447 | - } |
|
448 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
449 | - $sql = 'SELECT count(id) AS number' |
|
450 | - .' FROM '.$tbl_grade_evaluations |
|
451 | - ." WHERE name = '".Database::escape_string($name)."'"; |
|
452 | - |
|
453 | - if (api_is_allowed_to_edit()) { |
|
454 | - $parent = Category::load($parent); |
|
455 | - $code = $parent[0]->get_course_code(); |
|
456 | - $courseInfo = api_get_course_info($code); |
|
457 | - $courseId = $courseInfo['real_id']; |
|
458 | - |
|
459 | - if (isset($code) && $code != '0') { |
|
460 | - $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); |
|
461 | - $sql .= ' AND user_id IN ( |
|
385 | + } |
|
386 | + } |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Update the properties of this evaluation in the database |
|
391 | + */ |
|
392 | + public function save() |
|
393 | + { |
|
394 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
395 | + $sql = 'UPDATE '.$tbl_grade_evaluations |
|
396 | + ." SET name = '".Database::escape_string($this->get_name())."'" |
|
397 | + .', description = '; |
|
398 | + if (isset($this->description)) { |
|
399 | + $sql .= "'".Database::escape_string($this->get_description())."'"; |
|
400 | + }else { |
|
401 | + $sql .= 'null'; |
|
402 | + } |
|
403 | + $sql .= ', user_id = '.intval($this->get_user_id()) |
|
404 | + .', course_code = '; |
|
405 | + if (isset($this->course_code)) { |
|
406 | + $sql .= "'".Database::escape_string($this->get_course_code())."'"; |
|
407 | + } else { |
|
408 | + $sql .= 'null'; |
|
409 | + } |
|
410 | + $sql .= ', category_id = '; |
|
411 | + if (isset($this->category)) { |
|
412 | + $sql .= intval($this->get_category_id()); |
|
413 | + } else { |
|
414 | + $sql .= 'null'; |
|
415 | + } |
|
416 | + $sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" ' |
|
417 | + .', max = '.intval($this->get_max()) |
|
418 | + .', visible = '.intval($this->is_visible()) |
|
419 | + .' WHERE id = '.intval($this->id); |
|
420 | + //recorded history |
|
421 | + |
|
422 | + $eval_log = new Evaluation(); |
|
423 | + $eval_log->add_evaluation_log($this->id); |
|
424 | + Database::query($sql); |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * Delete this evaluation from the database |
|
429 | + */ |
|
430 | + public function delete() |
|
431 | + { |
|
432 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
433 | + $sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id); |
|
434 | + Database::query($sql); |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * Check if an evaluation name (with the same parent category) already exists |
|
439 | + * @param $name name to check (if not given, the name property of this object will be checked) |
|
440 | + * @param $parent parent category |
|
441 | + */ |
|
442 | + public function does_name_exist($name, $parent) |
|
443 | + { |
|
444 | + if (!isset ($name)) { |
|
445 | + $name = $this->name; |
|
446 | + $parent = $this->category; |
|
447 | + } |
|
448 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
449 | + $sql = 'SELECT count(id) AS number' |
|
450 | + .' FROM '.$tbl_grade_evaluations |
|
451 | + ." WHERE name = '".Database::escape_string($name)."'"; |
|
452 | + |
|
453 | + if (api_is_allowed_to_edit()) { |
|
454 | + $parent = Category::load($parent); |
|
455 | + $code = $parent[0]->get_course_code(); |
|
456 | + $courseInfo = api_get_course_info($code); |
|
457 | + $courseId = $courseInfo['real_id']; |
|
458 | + |
|
459 | + if (isset($code) && $code != '0') { |
|
460 | + $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); |
|
461 | + $sql .= ' AND user_id IN ( |
|
462 | 462 | SELECT user_id FROM '.$main_course_user_table.' |
463 | 463 | WHERE |
464 | 464 | c_id = '.$courseId.' AND |
465 | 465 | status = '.COURSEMANAGER.' |
466 | 466 | )'; |
467 | - } else { |
|
468 | - $sql .= ' AND user_id = '.api_get_user_id(); |
|
469 | - } |
|
470 | - |
|
471 | - }else { |
|
472 | - $sql .= ' AND user_id = '.api_get_user_id(); |
|
473 | - } |
|
474 | - |
|
475 | - if (!isset ($parent)) { |
|
476 | - $sql.= ' AND category_id is null'; |
|
477 | - } else { |
|
478 | - $sql.= ' AND category_id = '.intval($parent); |
|
479 | - } |
|
480 | - $result = Database::query($sql); |
|
481 | - $number=Database::fetch_row($result); |
|
482 | - |
|
483 | - return $number[0] != 0; |
|
484 | - } |
|
485 | - |
|
486 | - /** |
|
487 | - * Are there any results for this evaluation yet ? |
|
488 | - * The 'max' property should not be changed then. |
|
489 | - */ |
|
490 | - public function has_results() |
|
491 | - { |
|
492 | - $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
493 | - $sql = 'SELECT count(id) AS number |
|
467 | + } else { |
|
468 | + $sql .= ' AND user_id = '.api_get_user_id(); |
|
469 | + } |
|
470 | + |
|
471 | + }else { |
|
472 | + $sql .= ' AND user_id = '.api_get_user_id(); |
|
473 | + } |
|
474 | + |
|
475 | + if (!isset ($parent)) { |
|
476 | + $sql.= ' AND category_id is null'; |
|
477 | + } else { |
|
478 | + $sql.= ' AND category_id = '.intval($parent); |
|
479 | + } |
|
480 | + $result = Database::query($sql); |
|
481 | + $number=Database::fetch_row($result); |
|
482 | + |
|
483 | + return $number[0] != 0; |
|
484 | + } |
|
485 | + |
|
486 | + /** |
|
487 | + * Are there any results for this evaluation yet ? |
|
488 | + * The 'max' property should not be changed then. |
|
489 | + */ |
|
490 | + public function has_results() |
|
491 | + { |
|
492 | + $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
493 | + $sql = 'SELECT count(id) AS number |
|
494 | 494 | FROM '.$tbl_grade_results.' |
495 | 495 | WHERE evaluation_id = '.intval($this->id); |
496 | - $result = Database::query($sql); |
|
497 | - $number=Database::fetch_row($result); |
|
498 | - |
|
499 | - return ($number[0] != 0); |
|
500 | - } |
|
501 | - |
|
502 | - /** |
|
503 | - * Delete all results for this evaluation |
|
504 | - */ |
|
505 | - public function delete_results() |
|
506 | - { |
|
507 | - $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
508 | - $sql = 'DELETE FROM '.$tbl_grade_results.' |
|
496 | + $result = Database::query($sql); |
|
497 | + $number=Database::fetch_row($result); |
|
498 | + |
|
499 | + return ($number[0] != 0); |
|
500 | + } |
|
501 | + |
|
502 | + /** |
|
503 | + * Delete all results for this evaluation |
|
504 | + */ |
|
505 | + public function delete_results() |
|
506 | + { |
|
507 | + $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
508 | + $sql = 'DELETE FROM '.$tbl_grade_results.' |
|
509 | 509 | WHERE evaluation_id = '.intval($this->id); |
510 | - Database::query($sql); |
|
511 | - } |
|
512 | - |
|
513 | - /** |
|
514 | - * Delete this evaluation and all underlying results. |
|
515 | - */ |
|
516 | - public function delete_with_results() |
|
517 | - { |
|
518 | - $this->delete_results(); |
|
519 | - $this->delete(); |
|
520 | - } |
|
521 | - |
|
522 | - /** |
|
523 | - * Check if the given score is possible for this evaluation |
|
524 | - */ |
|
525 | - public function is_valid_score($score) |
|
526 | - { |
|
527 | - return is_numeric($score) && $score >= 0 && $score <= $this->eval_max; |
|
528 | - } |
|
529 | - |
|
530 | - /** |
|
531 | - * Calculate the score of this evaluation |
|
532 | - * @param int $stud_id (default: all students who have results for this eval - then the average is returned) |
|
533 | - * @param string $type (best, average, ranking) |
|
534 | - * @return array (score, max) if student is given |
|
535 | - * array (sum of scores, number of scores) otherwise |
|
536 | - * or null if no scores available |
|
537 | - */ |
|
538 | - public function calc_score($stud_id = null, $type = null) |
|
539 | - { |
|
510 | + Database::query($sql); |
|
511 | + } |
|
512 | + |
|
513 | + /** |
|
514 | + * Delete this evaluation and all underlying results. |
|
515 | + */ |
|
516 | + public function delete_with_results() |
|
517 | + { |
|
518 | + $this->delete_results(); |
|
519 | + $this->delete(); |
|
520 | + } |
|
521 | + |
|
522 | + /** |
|
523 | + * Check if the given score is possible for this evaluation |
|
524 | + */ |
|
525 | + public function is_valid_score($score) |
|
526 | + { |
|
527 | + return is_numeric($score) && $score >= 0 && $score <= $this->eval_max; |
|
528 | + } |
|
529 | + |
|
530 | + /** |
|
531 | + * Calculate the score of this evaluation |
|
532 | + * @param int $stud_id (default: all students who have results for this eval - then the average is returned) |
|
533 | + * @param string $type (best, average, ranking) |
|
534 | + * @return array (score, max) if student is given |
|
535 | + * array (sum of scores, number of scores) otherwise |
|
536 | + * or null if no scores available |
|
537 | + */ |
|
538 | + public function calc_score($stud_id = null, $type = null) |
|
539 | + { |
|
540 | 540 | $useSession = true; |
541 | - if (isset($stud_id) && empty($type)) { |
|
542 | - $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id; |
|
543 | - $data = Session::read('calc_score'); |
|
541 | + if (isset($stud_id) && empty($type)) { |
|
542 | + $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id; |
|
543 | + $data = Session::read('calc_score'); |
|
544 | 544 | $results = isset($data[$key]) ? $data[$key] : null; |
545 | 545 | |
546 | 546 | if ($useSession == false) { |
547 | 547 | $results = null; |
548 | 548 | } |
549 | - if (empty($results)) { |
|
550 | - $results = Result::load(null, $stud_id, $this->id); |
|
551 | - Session::write('calc_score', array($key => $results)); |
|
552 | - } |
|
553 | - |
|
554 | - $score = 0; |
|
555 | - /** @var Result $res */ |
|
556 | - foreach ($results as $res) { |
|
557 | - $score = $res->get_score(); |
|
558 | - } |
|
559 | - |
|
560 | - return array($score, $this->get_max()); |
|
561 | - } else { |
|
562 | - |
|
563 | - $count = 0; |
|
564 | - $sum = 0; |
|
565 | - $bestResult = 0; |
|
566 | - $weight = 0; |
|
567 | - $sumResult = 0; |
|
568 | - |
|
569 | - $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id; |
|
549 | + if (empty($results)) { |
|
550 | + $results = Result::load(null, $stud_id, $this->id); |
|
551 | + Session::write('calc_score', array($key => $results)); |
|
552 | + } |
|
553 | + |
|
554 | + $score = 0; |
|
555 | + /** @var Result $res */ |
|
556 | + foreach ($results as $res) { |
|
557 | + $score = $res->get_score(); |
|
558 | + } |
|
559 | + |
|
560 | + return array($score, $this->get_max()); |
|
561 | + } else { |
|
562 | + |
|
563 | + $count = 0; |
|
564 | + $sum = 0; |
|
565 | + $bestResult = 0; |
|
566 | + $weight = 0; |
|
567 | + $sumResult = 0; |
|
568 | + |
|
569 | + $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id; |
|
570 | 570 | $data = Session::read('calc_score'); |
571 | 571 | $allResults = isset($data[$key]) ? $data[$key] : null; |
572 | 572 | if ($useSession == false) { |
573 | 573 | $allResults = null; |
574 | 574 | } |
575 | - if (empty($allResults)) { |
|
576 | - $allResults = Result::load(null, null, $this->id); |
|
577 | - Session::write($key, $allResults); |
|
578 | - } |
|
579 | - |
|
580 | - $students = array(); |
|
581 | - /** @var Result $res */ |
|
582 | - foreach ($allResults as $res) { |
|
583 | - $score = $res->get_score(); |
|
584 | - if (!empty($score) || $score == '0') { |
|
585 | - $count++; |
|
586 | - $sum += $score / $this->get_max(); |
|
587 | - $sumResult += $score; |
|
588 | - if ($score > $bestResult) { |
|
589 | - $bestResult = $score; |
|
590 | - } |
|
591 | - $weight = $this->get_max(); |
|
592 | - } |
|
593 | - $students[$res->get_user_id()] = $score; |
|
594 | - } |
|
595 | - |
|
596 | - if (empty($count)) { |
|
597 | - return null; |
|
598 | - } |
|
599 | - |
|
600 | - switch ($type) { |
|
601 | - case 'best': |
|
602 | - return array($bestResult, $weight); |
|
603 | - break; |
|
604 | - case 'average': |
|
605 | - return array($sumResult/$count, $weight); |
|
606 | - break; |
|
607 | - case 'ranking': |
|
575 | + if (empty($allResults)) { |
|
576 | + $allResults = Result::load(null, null, $this->id); |
|
577 | + Session::write($key, $allResults); |
|
578 | + } |
|
579 | + |
|
580 | + $students = array(); |
|
581 | + /** @var Result $res */ |
|
582 | + foreach ($allResults as $res) { |
|
583 | + $score = $res->get_score(); |
|
584 | + if (!empty($score) || $score == '0') { |
|
585 | + $count++; |
|
586 | + $sum += $score / $this->get_max(); |
|
587 | + $sumResult += $score; |
|
588 | + if ($score > $bestResult) { |
|
589 | + $bestResult = $score; |
|
590 | + } |
|
591 | + $weight = $this->get_max(); |
|
592 | + } |
|
593 | + $students[$res->get_user_id()] = $score; |
|
594 | + } |
|
595 | + |
|
596 | + if (empty($count)) { |
|
597 | + return null; |
|
598 | + } |
|
599 | + |
|
600 | + switch ($type) { |
|
601 | + case 'best': |
|
602 | + return array($bestResult, $weight); |
|
603 | + break; |
|
604 | + case 'average': |
|
605 | + return array($sumResult/$count, $weight); |
|
606 | + break; |
|
607 | + case 'ranking': |
|
608 | 608 | $students = array(); |
609 | 609 | /** @var Result $res */ |
610 | 610 | foreach ($allResults as $res) { |
611 | 611 | $score = $res->get_score(); |
612 | 612 | $students[$res->get_user_id()] = $score; |
613 | 613 | } |
614 | - return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
615 | - break; |
|
616 | - default: |
|
617 | - return array($sum, $count); |
|
618 | - break; |
|
619 | - } |
|
620 | - } |
|
621 | - } |
|
622 | - |
|
623 | - /** |
|
624 | - * Generate an array of possible categories where this evaluation can be moved to. |
|
625 | - * Notice: its own parent will be included in the list: it's up to the frontend |
|
626 | - * to disable this element. |
|
627 | - * @return array 2-dimensional array - every element contains 3 subelements (id, name, level) |
|
628 | - */ |
|
629 | - public function get_target_categories() |
|
630 | - { |
|
631 | - // - course independent evaluation |
|
632 | - // -> movable to root or other course independent categories |
|
633 | - // - evaluation inside a course |
|
634 | - // -> movable to root, independent categories or categories inside the course |
|
635 | - $user = (api_is_platform_admin() ? null : api_get_user_id()); |
|
636 | - $targets = array(); |
|
637 | - $level = 0; |
|
638 | - |
|
639 | - $root = array(0, get_lang('RootCat'), $level); |
|
640 | - $targets[] = $root; |
|
641 | - |
|
642 | - if (isset($this->course_code) && !empty($this->course_code)) { |
|
643 | - $crscats = Category::load(null,null,$this->course_code,0); |
|
644 | - foreach ($crscats as $cat) { |
|
645 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
646 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
647 | - } |
|
648 | - } |
|
649 | - |
|
650 | - $indcats = Category::load(null,$user,0,0); |
|
651 | - foreach ($indcats as $cat) { |
|
652 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
653 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
654 | - } |
|
655 | - |
|
656 | - return $targets; |
|
657 | - } |
|
658 | - |
|
659 | - /** |
|
660 | - * Internal function used by get_target_categories() |
|
661 | - */ |
|
662 | - private function add_target_subcategories($targets, $level, $catid) |
|
663 | - { |
|
664 | - $subcats = Category::load(null,null,null,$catid); |
|
665 | - foreach ($subcats as $cat) { |
|
666 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
667 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
668 | - } |
|
669 | - return $targets; |
|
670 | - } |
|
671 | - |
|
672 | - /** |
|
673 | - * Move this evaluation to the given category. |
|
674 | - * If this evaluation moves from inside a course to outside, |
|
675 | - * its course code is also changed. |
|
676 | - */ |
|
677 | - public function move_to_cat($cat) |
|
678 | - { |
|
679 | - $this->set_category_id($cat->get_id()); |
|
680 | - if ($this->get_course_code() != $cat->get_course_code()) { |
|
681 | - $this->set_course_code($cat->get_course_code()); |
|
682 | - } |
|
683 | - $this->save(); |
|
684 | - } |
|
685 | - |
|
686 | - /** |
|
687 | - * Retrieve evaluations where a student has results for |
|
688 | - * and return them as an array of Evaluation objects |
|
689 | - * @param int $cat_id parent category (use 'null' to retrieve them in all categories) |
|
690 | - * @param int $stud_id student id |
|
691 | - */ |
|
692 | - public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id) |
|
693 | - { |
|
694 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
695 | - $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
696 | - |
|
697 | - $sql = 'SELECT * FROM '.$tbl_grade_evaluations.' |
|
614 | + return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
615 | + break; |
|
616 | + default: |
|
617 | + return array($sum, $count); |
|
618 | + break; |
|
619 | + } |
|
620 | + } |
|
621 | + } |
|
622 | + |
|
623 | + /** |
|
624 | + * Generate an array of possible categories where this evaluation can be moved to. |
|
625 | + * Notice: its own parent will be included in the list: it's up to the frontend |
|
626 | + * to disable this element. |
|
627 | + * @return array 2-dimensional array - every element contains 3 subelements (id, name, level) |
|
628 | + */ |
|
629 | + public function get_target_categories() |
|
630 | + { |
|
631 | + // - course independent evaluation |
|
632 | + // -> movable to root or other course independent categories |
|
633 | + // - evaluation inside a course |
|
634 | + // -> movable to root, independent categories or categories inside the course |
|
635 | + $user = (api_is_platform_admin() ? null : api_get_user_id()); |
|
636 | + $targets = array(); |
|
637 | + $level = 0; |
|
638 | + |
|
639 | + $root = array(0, get_lang('RootCat'), $level); |
|
640 | + $targets[] = $root; |
|
641 | + |
|
642 | + if (isset($this->course_code) && !empty($this->course_code)) { |
|
643 | + $crscats = Category::load(null,null,$this->course_code,0); |
|
644 | + foreach ($crscats as $cat) { |
|
645 | + $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
646 | + $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
647 | + } |
|
648 | + } |
|
649 | + |
|
650 | + $indcats = Category::load(null,$user,0,0); |
|
651 | + foreach ($indcats as $cat) { |
|
652 | + $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
653 | + $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
654 | + } |
|
655 | + |
|
656 | + return $targets; |
|
657 | + } |
|
658 | + |
|
659 | + /** |
|
660 | + * Internal function used by get_target_categories() |
|
661 | + */ |
|
662 | + private function add_target_subcategories($targets, $level, $catid) |
|
663 | + { |
|
664 | + $subcats = Category::load(null,null,null,$catid); |
|
665 | + foreach ($subcats as $cat) { |
|
666 | + $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
667 | + $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
668 | + } |
|
669 | + return $targets; |
|
670 | + } |
|
671 | + |
|
672 | + /** |
|
673 | + * Move this evaluation to the given category. |
|
674 | + * If this evaluation moves from inside a course to outside, |
|
675 | + * its course code is also changed. |
|
676 | + */ |
|
677 | + public function move_to_cat($cat) |
|
678 | + { |
|
679 | + $this->set_category_id($cat->get_id()); |
|
680 | + if ($this->get_course_code() != $cat->get_course_code()) { |
|
681 | + $this->set_course_code($cat->get_course_code()); |
|
682 | + } |
|
683 | + $this->save(); |
|
684 | + } |
|
685 | + |
|
686 | + /** |
|
687 | + * Retrieve evaluations where a student has results for |
|
688 | + * and return them as an array of Evaluation objects |
|
689 | + * @param int $cat_id parent category (use 'null' to retrieve them in all categories) |
|
690 | + * @param int $stud_id student id |
|
691 | + */ |
|
692 | + public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id) |
|
693 | + { |
|
694 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
695 | + $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
696 | + |
|
697 | + $sql = 'SELECT * FROM '.$tbl_grade_evaluations.' |
|
698 | 698 | WHERE id IN ( |
699 | 699 | SELECT evaluation_id FROM '.$tbl_grade_results.' |
700 | 700 | WHERE user_id = '.intval($stud_id).' AND score IS NOT NULL |
701 | 701 | )'; |
702 | - if (!api_is_allowed_to_edit()) { |
|
703 | - $sql .= ' AND visible = 1'; |
|
704 | - } |
|
705 | - if (isset($cat_id)) { |
|
706 | - $sql .= ' AND category_id = '.intval($cat_id); |
|
707 | - } else { |
|
708 | - $sql .= ' AND category_id >= 0'; |
|
709 | - } |
|
710 | - |
|
711 | - $result = Database::query($sql); |
|
712 | - $alleval = Evaluation::create_evaluation_objects_from_sql_result($result); |
|
713 | - |
|
714 | - return $alleval; |
|
715 | - } |
|
716 | - |
|
717 | - /** |
|
718 | - * Get a list of students that do not have a result record for this evaluation |
|
719 | - */ |
|
720 | - public function get_not_subscribed_students($first_letter_user = '') |
|
721 | - { |
|
722 | - $tbl_user = Database :: get_main_table(TABLE_MAIN_USER); |
|
723 | - $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
724 | - |
|
725 | - $sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user |
|
726 | - ." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'" |
|
727 | - .' AND status = '.STUDENT |
|
728 | - .' AND user_id NOT IN' |
|
729 | - .' (SELECT user_id FROM '.$tbl_grade_results |
|
730 | - .' WHERE evaluation_id = '.intval($this->id) |
|
731 | - .' )' |
|
732 | - .' ORDER BY lastname'; |
|
733 | - |
|
734 | - $result = Database::query($sql); |
|
735 | - $users = Database::store_result($result); |
|
736 | - |
|
737 | - return $users; |
|
738 | - } |
|
739 | - |
|
740 | - /** |
|
741 | - * Find evaluations by name |
|
742 | - * @param string $name_mask search string |
|
743 | - * @return array evaluation objects matching the search criterium |
|
744 | - * @todo can be written more efficiently using a new (but very complex) sql query |
|
745 | - */ |
|
746 | - public function find_evaluations($name_mask,$selectcat) |
|
747 | - { |
|
748 | - $rootcat = Category::load($selectcat); |
|
749 | - $evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true); |
|
750 | - $foundevals = array(); |
|
751 | - foreach ($evals as $eval) { |
|
752 | - if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) { |
|
753 | - $foundevals[] = $eval; |
|
754 | - } |
|
755 | - } |
|
756 | - return $foundevals; |
|
757 | - } |
|
758 | - |
|
759 | - public function get_item_type() |
|
760 | - { |
|
761 | - return 'E'; |
|
762 | - } |
|
763 | - |
|
764 | - public function get_icon_name() |
|
765 | - { |
|
766 | - return $this->has_results() ? 'evalnotempty' : 'evalempty'; |
|
767 | - } |
|
768 | - |
|
769 | - /** |
|
770 | - * Locks an evaluation, only one who can unlock it is the platform administrator. |
|
771 | - * @param int locked 1 or unlocked 0 |
|
772 | - * |
|
773 | - **/ |
|
774 | - function lock($locked) |
|
775 | - { |
|
776 | - $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
777 | - $sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'"; |
|
778 | - Database::query($sql); |
|
779 | - } |
|
780 | - |
|
781 | - function check_lock_permissions() |
|
782 | - { |
|
783 | - if (api_is_platform_admin()) { |
|
784 | - return true; |
|
785 | - } else { |
|
786 | - if ($this->is_locked()) { |
|
787 | - api_not_allowed(); |
|
788 | - } |
|
789 | - } |
|
790 | - } |
|
791 | - |
|
792 | - function delete_linked_data() |
|
793 | - { |
|
794 | - |
|
795 | - } |
|
702 | + if (!api_is_allowed_to_edit()) { |
|
703 | + $sql .= ' AND visible = 1'; |
|
704 | + } |
|
705 | + if (isset($cat_id)) { |
|
706 | + $sql .= ' AND category_id = '.intval($cat_id); |
|
707 | + } else { |
|
708 | + $sql .= ' AND category_id >= 0'; |
|
709 | + } |
|
710 | + |
|
711 | + $result = Database::query($sql); |
|
712 | + $alleval = Evaluation::create_evaluation_objects_from_sql_result($result); |
|
713 | + |
|
714 | + return $alleval; |
|
715 | + } |
|
716 | + |
|
717 | + /** |
|
718 | + * Get a list of students that do not have a result record for this evaluation |
|
719 | + */ |
|
720 | + public function get_not_subscribed_students($first_letter_user = '') |
|
721 | + { |
|
722 | + $tbl_user = Database :: get_main_table(TABLE_MAIN_USER); |
|
723 | + $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
724 | + |
|
725 | + $sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user |
|
726 | + ." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'" |
|
727 | + .' AND status = '.STUDENT |
|
728 | + .' AND user_id NOT IN' |
|
729 | + .' (SELECT user_id FROM '.$tbl_grade_results |
|
730 | + .' WHERE evaluation_id = '.intval($this->id) |
|
731 | + .' )' |
|
732 | + .' ORDER BY lastname'; |
|
733 | + |
|
734 | + $result = Database::query($sql); |
|
735 | + $users = Database::store_result($result); |
|
736 | + |
|
737 | + return $users; |
|
738 | + } |
|
739 | + |
|
740 | + /** |
|
741 | + * Find evaluations by name |
|
742 | + * @param string $name_mask search string |
|
743 | + * @return array evaluation objects matching the search criterium |
|
744 | + * @todo can be written more efficiently using a new (but very complex) sql query |
|
745 | + */ |
|
746 | + public function find_evaluations($name_mask,$selectcat) |
|
747 | + { |
|
748 | + $rootcat = Category::load($selectcat); |
|
749 | + $evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true); |
|
750 | + $foundevals = array(); |
|
751 | + foreach ($evals as $eval) { |
|
752 | + if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) { |
|
753 | + $foundevals[] = $eval; |
|
754 | + } |
|
755 | + } |
|
756 | + return $foundevals; |
|
757 | + } |
|
758 | + |
|
759 | + public function get_item_type() |
|
760 | + { |
|
761 | + return 'E'; |
|
762 | + } |
|
763 | + |
|
764 | + public function get_icon_name() |
|
765 | + { |
|
766 | + return $this->has_results() ? 'evalnotempty' : 'evalempty'; |
|
767 | + } |
|
768 | + |
|
769 | + /** |
|
770 | + * Locks an evaluation, only one who can unlock it is the platform administrator. |
|
771 | + * @param int locked 1 or unlocked 0 |
|
772 | + * |
|
773 | + **/ |
|
774 | + function lock($locked) |
|
775 | + { |
|
776 | + $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
777 | + $sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'"; |
|
778 | + Database::query($sql); |
|
779 | + } |
|
780 | + |
|
781 | + function check_lock_permissions() |
|
782 | + { |
|
783 | + if (api_is_platform_admin()) { |
|
784 | + return true; |
|
785 | + } else { |
|
786 | + if ($this->is_locked()) { |
|
787 | + api_not_allowed(); |
|
788 | + } |
|
789 | + } |
|
790 | + } |
|
791 | + |
|
792 | + function delete_linked_data() |
|
793 | + { |
|
794 | + |
|
795 | + } |
|
796 | 796 | |
797 | 797 | public function getStudentList() |
798 | 798 | { |
799 | 799 | return $this->studentList; |
800 | 800 | } |
801 | 801 | |
802 | - public function setStudentList($list) |
|
803 | - { |
|
804 | - $this->studentList = $list; |
|
805 | - } |
|
802 | + public function setStudentList($list) |
|
803 | + { |
|
804 | + $this->studentList = $list; |
|
805 | + } |
|
806 | 806 | } |
@@ -249,7 +249,7 @@ |
||
249 | 249 | } |
250 | 250 | } |
251 | 251 | |
252 | - $modify_icons .= '<a href="gradebook_edit_all.php?selectcat=' .$cat->get_id() . '&cidReq=' . $cat->get_course_code() . '&id_session='.$cat->get_session_id().'">' . |
|
252 | + $modify_icons .= '<a href="gradebook_edit_all.php?selectcat=' .$cat->get_id() . '&cidReq=' . $cat->get_course_code() . '&id_session='.$cat->get_session_id().'">' . |
|
253 | 253 | Display::return_icon( |
254 | 254 | 'percentage.png', |
255 | 255 | get_lang('EditAllWeights'), |
@@ -17,35 +17,35 @@ discard block |
||
17 | 17 | */ |
18 | 18 | function home_tabs($file_logged_in) |
19 | 19 | { |
20 | - $post = strpos($file_logged_in, "_logged_in"); |
|
21 | - if ($post !== false) { |
|
22 | - $file_logged_out = str_replace('_logged_in','', $file_logged_in); |
|
23 | - //variables initialization |
|
24 | - $data_logged_out = array(); |
|
25 | - $data_logged_in = array(); |
|
26 | - |
|
27 | - //we read the file with all links |
|
28 | - $file = file($file_logged_in); |
|
29 | - foreach ($file as $line) { |
|
30 | - $line = str_replace("\n", '',$line); |
|
31 | - //not logged user only sees public links |
|
32 | - if (!preg_match('/::private/',$line)) { |
|
33 | - $data_logged_out[] = $line; |
|
34 | - } |
|
35 | - //logged user only sees all links |
|
36 | - $data_logged_in[] = $line; |
|
37 | - } |
|
38 | - //tabs file for logged out users |
|
39 | - if (file_exists($file_logged_out)) { |
|
40 | - $fp = fopen($file_logged_out, 'w'); |
|
41 | - fputs($fp, implode("\n", $data_logged_out)); |
|
42 | - fclose($fp); |
|
43 | - } |
|
44 | - //tabs file for logged in users |
|
45 | - $fp = fopen($file_logged_in, 'w'); |
|
46 | - fputs($fp, implode("\n", $data_logged_in)); |
|
47 | - fclose($fp); |
|
48 | - } |
|
20 | + $post = strpos($file_logged_in, "_logged_in"); |
|
21 | + if ($post !== false) { |
|
22 | + $file_logged_out = str_replace('_logged_in','', $file_logged_in); |
|
23 | + //variables initialization |
|
24 | + $data_logged_out = array(); |
|
25 | + $data_logged_in = array(); |
|
26 | + |
|
27 | + //we read the file with all links |
|
28 | + $file = file($file_logged_in); |
|
29 | + foreach ($file as $line) { |
|
30 | + $line = str_replace("\n", '',$line); |
|
31 | + //not logged user only sees public links |
|
32 | + if (!preg_match('/::private/',$line)) { |
|
33 | + $data_logged_out[] = $line; |
|
34 | + } |
|
35 | + //logged user only sees all links |
|
36 | + $data_logged_in[] = $line; |
|
37 | + } |
|
38 | + //tabs file for logged out users |
|
39 | + if (file_exists($file_logged_out)) { |
|
40 | + $fp = fopen($file_logged_out, 'w'); |
|
41 | + fputs($fp, implode("\n", $data_logged_out)); |
|
42 | + fclose($fp); |
|
43 | + } |
|
44 | + //tabs file for logged in users |
|
45 | + $fp = fopen($file_logged_in, 'w'); |
|
46 | + fputs($fp, implode("\n", $data_logged_in)); |
|
47 | + fclose($fp); |
|
48 | + } |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | $cidReset = true; |
@@ -76,39 +76,39 @@ discard block |
||
76 | 76 | $_languages = api_get_languages(); |
77 | 77 | |
78 | 78 | $interbreadcrumb[] = array( |
79 | - 'url' => 'index.php', |
|
80 | - 'name' => get_lang('PlatformAdmin') |
|
79 | + 'url' => 'index.php', |
|
80 | + 'name' => get_lang('PlatformAdmin') |
|
81 | 81 | ); |
82 | 82 | |
83 | 83 | if (!empty($action)) { |
84 | - $interbreadcrumb[] = array( |
|
85 | - 'url' => 'configure_homepage.php', |
|
86 | - 'name' => get_lang('ConfigureHomePage') |
|
87 | - ); |
|
88 | - |
|
89 | - switch ($action) { |
|
90 | - case 'edit_top': |
|
91 | - $tool_name = get_lang('EditHomePage'); |
|
92 | - break; |
|
93 | - case 'edit_news': |
|
94 | - $tool_name = get_lang('EditNews'); |
|
95 | - break; |
|
96 | - case 'edit_notice': |
|
97 | - $tool_name = get_lang('EditNotice'); |
|
98 | - break; |
|
99 | - case 'insert_link': |
|
100 | - $tool_name = get_lang('InsertLink'); |
|
101 | - break; |
|
102 | - case 'edit_link': |
|
103 | - $tool_name = get_lang('EditLink'); |
|
104 | - break; |
|
105 | - case 'insert_tabs': |
|
106 | - $tool_name = get_lang('InsertTabs'); |
|
107 | - break; |
|
108 | - case 'edit_tabs': |
|
109 | - $tool_name = get_lang('EditTabs'); |
|
110 | - break; |
|
111 | - } |
|
84 | + $interbreadcrumb[] = array( |
|
85 | + 'url' => 'configure_homepage.php', |
|
86 | + 'name' => get_lang('ConfigureHomePage') |
|
87 | + ); |
|
88 | + |
|
89 | + switch ($action) { |
|
90 | + case 'edit_top': |
|
91 | + $tool_name = get_lang('EditHomePage'); |
|
92 | + break; |
|
93 | + case 'edit_news': |
|
94 | + $tool_name = get_lang('EditNews'); |
|
95 | + break; |
|
96 | + case 'edit_notice': |
|
97 | + $tool_name = get_lang('EditNotice'); |
|
98 | + break; |
|
99 | + case 'insert_link': |
|
100 | + $tool_name = get_lang('InsertLink'); |
|
101 | + break; |
|
102 | + case 'edit_link': |
|
103 | + $tool_name = get_lang('EditLink'); |
|
104 | + break; |
|
105 | + case 'insert_tabs': |
|
106 | + $tool_name = get_lang('InsertTabs'); |
|
107 | + break; |
|
108 | + case 'edit_tabs': |
|
109 | + $tool_name = get_lang('EditTabs'); |
|
110 | + break; |
|
111 | + } |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | // The global logic for language priorities should be: |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | |
132 | 132 | $lang = ''; //el for "Edit Language" |
133 | 133 | if (!empty($_SESSION['user_language_choice'])) { |
134 | - $lang = $_SESSION['user_language_choice']; |
|
134 | + $lang = $_SESSION['user_language_choice']; |
|
135 | 135 | } elseif (!empty($_SESSION['_user']['language'])) { |
136 | - $lang = $_SESSION['_user']['language']; |
|
136 | + $lang = $_SESSION['_user']['language']; |
|
137 | 137 | } else { |
138 | - $lang = api_get_setting('platformLanguage'); |
|
138 | + $lang = api_get_setting('platformLanguage'); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | $languageGet = isset($_GET['language']) ? Security::remove_XSS($_GET['language']) : $lang; |
@@ -144,25 +144,25 @@ discard block |
||
144 | 144 | $homePath = api_get_path(SYS_APP_PATH).'home/'; |
145 | 145 | |
146 | 146 | if (api_is_multiple_url_enabled()) { |
147 | - $access_url_id = api_get_current_access_url_id(); |
|
148 | - if ($access_url_id != -1) { |
|
149 | - $url_info = api_get_access_url($access_url_id); |
|
150 | - $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url'])); |
|
151 | - $clean_url = api_replace_dangerous_char($url); |
|
152 | - $clean_url = str_replace('/', '-', $clean_url); |
|
153 | - $clean_url .= '/'; |
|
154 | - |
|
155 | - $homep = $homePath; //homep for Home Path |
|
156 | - $homep_new = $homePath.$clean_url; //homep for Home Path added the url |
|
157 | - $new_url_dir = $homePath.$clean_url; |
|
158 | - //we create the new dir for the new sites |
|
159 | - if (!is_dir($new_url_dir)) { |
|
160 | - mkdir($new_url_dir, api_get_permissions_for_new_directories()); |
|
161 | - } |
|
162 | - } |
|
147 | + $access_url_id = api_get_current_access_url_id(); |
|
148 | + if ($access_url_id != -1) { |
|
149 | + $url_info = api_get_access_url($access_url_id); |
|
150 | + $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url'])); |
|
151 | + $clean_url = api_replace_dangerous_char($url); |
|
152 | + $clean_url = str_replace('/', '-', $clean_url); |
|
153 | + $clean_url .= '/'; |
|
154 | + |
|
155 | + $homep = $homePath; //homep for Home Path |
|
156 | + $homep_new = $homePath.$clean_url; //homep for Home Path added the url |
|
157 | + $new_url_dir = $homePath.$clean_url; |
|
158 | + //we create the new dir for the new sites |
|
159 | + if (!is_dir($new_url_dir)) { |
|
160 | + mkdir($new_url_dir, api_get_permissions_for_new_directories()); |
|
161 | + } |
|
162 | + } |
|
163 | 163 | } else { |
164 | - $homep_new = ''; |
|
165 | - $homep = $homePath; //homep for Home Path |
|
164 | + $homep_new = ''; |
|
165 | + $homep = $homePath; //homep for Home Path |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | $menuf = 'home_menu'; //menuf for Menu File |
@@ -177,25 +177,25 @@ discard block |
||
177 | 177 | |
178 | 178 | // If language-specific file does not exist, create it by copying default file |
179 | 179 | foreach ($homef as $my_file) { |
180 | - if (api_is_multiple_url_enabled()) { |
|
181 | - if (!file_exists($homep_new.$my_file.'_'.$lang.$ext)) { |
|
182 | - if (!file_exists($homep.$my_file.$ext)) { |
|
183 | - touch($homep.$my_file.$ext); |
|
184 | - } |
|
185 | - @copy($homep.$my_file.$ext, $homep_new.$my_file.'_'.$lang.$ext); |
|
186 | - } |
|
187 | - } else { |
|
188 | - if (!file_exists($homep.$my_file.'_'.$lang.$ext)) { |
|
189 | - if (!file_exists($homep.$my_file.$ext)) { |
|
190 | - touch($homep.$my_file.$ext); |
|
191 | - } |
|
192 | - @copy($homep.$my_file.$ext, $homep.$my_file.'_'.$lang.$ext); |
|
193 | - } |
|
194 | - } |
|
180 | + if (api_is_multiple_url_enabled()) { |
|
181 | + if (!file_exists($homep_new.$my_file.'_'.$lang.$ext)) { |
|
182 | + if (!file_exists($homep.$my_file.$ext)) { |
|
183 | + touch($homep.$my_file.$ext); |
|
184 | + } |
|
185 | + @copy($homep.$my_file.$ext, $homep_new.$my_file.'_'.$lang.$ext); |
|
186 | + } |
|
187 | + } else { |
|
188 | + if (!file_exists($homep.$my_file.'_'.$lang.$ext)) { |
|
189 | + if (!file_exists($homep.$my_file.$ext)) { |
|
190 | + touch($homep.$my_file.$ext); |
|
191 | + } |
|
192 | + @copy($homep.$my_file.$ext, $homep.$my_file.'_'.$lang.$ext); |
|
193 | + } |
|
194 | + } |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | if (api_is_multiple_url_enabled()) { |
198 | - $homep = $homep_new; |
|
198 | + $homep = $homep_new; |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | // Check WCAG settings and prepare edition using WCAG |
@@ -204,576 +204,576 @@ discard block |
||
204 | 204 | // Filter link param |
205 | 205 | $link = ''; |
206 | 206 | if (!empty($_GET['link'])) { |
207 | - $link = $_GET['link']; |
|
208 | - // If the link parameter is suspicious, empty it |
|
209 | - if (strstr($link, '/') || !strstr($link, '.html') || strstr($link, '\\')) { |
|
210 | - $link = ''; |
|
211 | - $action = ''; |
|
212 | - } |
|
207 | + $link = $_GET['link']; |
|
208 | + // If the link parameter is suspicious, empty it |
|
209 | + if (strstr($link, '/') || !strstr($link, '.html') || strstr($link, '\\')) { |
|
210 | + $link = ''; |
|
211 | + $action = ''; |
|
212 | + } |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | // Start analysing requested actions |
216 | 216 | if (!empty($action)) { |
217 | - if (!empty($_POST['formSent'])) { |
|
218 | - // Variables used are $homep for home path, $menuf for menu file, $newsf |
|
219 | - // for news file, $topf for top file, $noticef for noticefile, |
|
220 | - // $ext for '.html' |
|
221 | - switch ($action) { |
|
222 | - case 'edit_top': |
|
223 | - // Filter |
|
224 | - $home_top = trim(stripslashes($_POST['home_top'])); |
|
225 | - |
|
226 | - // Write |
|
227 | - if (is_writable($homep)) { |
|
228 | - // Default |
|
229 | - if (is_writable($homep.$topf.'_'.$lang.$ext)) { |
|
230 | - $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w'); |
|
231 | - fputs($fp, $home_top); |
|
232 | - fclose($fp); |
|
233 | - |
|
234 | - // Language |
|
235 | - foreach ($_languages['name'] as $key => $value) { |
|
236 | - $lang_name = $_languages['folder'][$key]; |
|
237 | - if (isset($_POST[$lang_name])) { |
|
238 | - $fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w'); |
|
239 | - fputs($fp, $home_top); |
|
240 | - fclose($fp); |
|
241 | - } |
|
242 | - } |
|
243 | - } else { |
|
244 | - $errorMsg = get_lang('HomePageFilesNotWritable'); |
|
245 | - } |
|
246 | - } else { |
|
247 | - //File does not exist |
|
248 | - $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w'); |
|
249 | - fputs($fp, $home_top); |
|
250 | - fclose($fp); |
|
251 | - |
|
252 | - foreach ($_languages['name'] as $key => $value) { |
|
253 | - $lang_name = $_languages['folder'][$key]; |
|
254 | - if (isset($_POST[$lang_name])) { |
|
255 | - if (file_exists($homep.$topf.'_'.$lang_name.$ext)) { |
|
256 | - $fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w'); |
|
257 | - fputs($fp, $home_top); |
|
258 | - fclose($fp); |
|
259 | - } |
|
260 | - } |
|
261 | - } |
|
262 | - } |
|
263 | - |
|
264 | - if (EventsMail::check_if_using_class('portal_homepage_edited')) { |
|
265 | - EventsDispatcher::events('portal_homepage_edited',array('about_user' => api_get_user_id())); |
|
266 | - } |
|
267 | - Event::addEvent( |
|
268 | - LOG_HOMEPAGE_CHANGED, |
|
269 | - 'edit_top', |
|
270 | - cut(strip_tags($home_top), 254), |
|
271 | - api_get_utc_datetime(), |
|
272 | - api_get_user_id() |
|
273 | - ); |
|
274 | - break; |
|
275 | - case 'edit_notice': |
|
276 | - // Filter |
|
277 | - $notice_title = trim(strip_tags(stripslashes($_POST['notice_title']))); |
|
278 | - $notice_text = trim(str_replace(array("\r", "\n"), array('', '<br />'), strip_tags(stripslashes($_POST['notice_text']), '<a>'))); |
|
279 | - if (empty($notice_title) || empty($notice_text)) { |
|
280 | - $errorMsg = get_lang('NoticeWillBeNotDisplayed'); |
|
281 | - } |
|
282 | - // Write |
|
283 | - if (file_exists($homep.$noticef.'_'.$lang.$ext)) { |
|
284 | - if (is_writable($homep.$noticef.'_'.$lang.$ext)) { |
|
285 | - $fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w'); |
|
286 | - if ($errorMsg == '') { |
|
287 | - fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text"); |
|
288 | - |
|
289 | - foreach ($_languages['name'] as $key => $value) { |
|
290 | - $lang_name = $_languages['folder'][$key]; |
|
291 | - if (isset($_POST[$lang_name])) { |
|
292 | - if (file_exists($homep.$noticef.'_'.$lang_name.$ext)) { |
|
293 | - if (is_writable($homep.$noticef.'_'.$lang_name.$ext)) { |
|
294 | - $fp = fopen($homep.$noticef.'_'.$lang_name.$ext, 'w'); |
|
295 | - fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text"); |
|
296 | - fclose($fp); |
|
297 | - } |
|
298 | - } |
|
299 | - } |
|
300 | - } |
|
301 | - } else { |
|
302 | - fputs($fp, ''); |
|
303 | - |
|
304 | - foreach ($_languages['name'] as $key => $value) { |
|
305 | - $lang_name = $_languages['folder'][$key]; |
|
306 | - if (isset($_POST[$lang_name])) { |
|
307 | - if (file_exists($homep.$noticef.'_'.$lang_name.$ext)) { |
|
308 | - $fp1 = fopen($homep.$noticef.'_'.$lang_name.$ext, 'w'); |
|
309 | - fputs($fp1, ''); |
|
310 | - fclose($fp1); |
|
311 | - } |
|
312 | - } |
|
313 | - } |
|
314 | - } |
|
315 | - fclose($fp); |
|
316 | - } else { |
|
317 | - $errorMsg .= "<br/>\n".get_lang('HomePageFilesNotWritable'); |
|
318 | - } |
|
319 | - } else { |
|
320 | - //File does not exist |
|
321 | - $fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w'); |
|
322 | - fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text"); |
|
323 | - fclose($fp); |
|
324 | - } |
|
325 | - Event::addEvent( |
|
217 | + if (!empty($_POST['formSent'])) { |
|
218 | + // Variables used are $homep for home path, $menuf for menu file, $newsf |
|
219 | + // for news file, $topf for top file, $noticef for noticefile, |
|
220 | + // $ext for '.html' |
|
221 | + switch ($action) { |
|
222 | + case 'edit_top': |
|
223 | + // Filter |
|
224 | + $home_top = trim(stripslashes($_POST['home_top'])); |
|
225 | + |
|
226 | + // Write |
|
227 | + if (is_writable($homep)) { |
|
228 | + // Default |
|
229 | + if (is_writable($homep.$topf.'_'.$lang.$ext)) { |
|
230 | + $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w'); |
|
231 | + fputs($fp, $home_top); |
|
232 | + fclose($fp); |
|
233 | + |
|
234 | + // Language |
|
235 | + foreach ($_languages['name'] as $key => $value) { |
|
236 | + $lang_name = $_languages['folder'][$key]; |
|
237 | + if (isset($_POST[$lang_name])) { |
|
238 | + $fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w'); |
|
239 | + fputs($fp, $home_top); |
|
240 | + fclose($fp); |
|
241 | + } |
|
242 | + } |
|
243 | + } else { |
|
244 | + $errorMsg = get_lang('HomePageFilesNotWritable'); |
|
245 | + } |
|
246 | + } else { |
|
247 | + //File does not exist |
|
248 | + $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w'); |
|
249 | + fputs($fp, $home_top); |
|
250 | + fclose($fp); |
|
251 | + |
|
252 | + foreach ($_languages['name'] as $key => $value) { |
|
253 | + $lang_name = $_languages['folder'][$key]; |
|
254 | + if (isset($_POST[$lang_name])) { |
|
255 | + if (file_exists($homep.$topf.'_'.$lang_name.$ext)) { |
|
256 | + $fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w'); |
|
257 | + fputs($fp, $home_top); |
|
258 | + fclose($fp); |
|
259 | + } |
|
260 | + } |
|
261 | + } |
|
262 | + } |
|
263 | + |
|
264 | + if (EventsMail::check_if_using_class('portal_homepage_edited')) { |
|
265 | + EventsDispatcher::events('portal_homepage_edited',array('about_user' => api_get_user_id())); |
|
266 | + } |
|
267 | + Event::addEvent( |
|
268 | + LOG_HOMEPAGE_CHANGED, |
|
269 | + 'edit_top', |
|
270 | + cut(strip_tags($home_top), 254), |
|
271 | + api_get_utc_datetime(), |
|
272 | + api_get_user_id() |
|
273 | + ); |
|
274 | + break; |
|
275 | + case 'edit_notice': |
|
276 | + // Filter |
|
277 | + $notice_title = trim(strip_tags(stripslashes($_POST['notice_title']))); |
|
278 | + $notice_text = trim(str_replace(array("\r", "\n"), array('', '<br />'), strip_tags(stripslashes($_POST['notice_text']), '<a>'))); |
|
279 | + if (empty($notice_title) || empty($notice_text)) { |
|
280 | + $errorMsg = get_lang('NoticeWillBeNotDisplayed'); |
|
281 | + } |
|
282 | + // Write |
|
283 | + if (file_exists($homep.$noticef.'_'.$lang.$ext)) { |
|
284 | + if (is_writable($homep.$noticef.'_'.$lang.$ext)) { |
|
285 | + $fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w'); |
|
286 | + if ($errorMsg == '') { |
|
287 | + fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text"); |
|
288 | + |
|
289 | + foreach ($_languages['name'] as $key => $value) { |
|
290 | + $lang_name = $_languages['folder'][$key]; |
|
291 | + if (isset($_POST[$lang_name])) { |
|
292 | + if (file_exists($homep.$noticef.'_'.$lang_name.$ext)) { |
|
293 | + if (is_writable($homep.$noticef.'_'.$lang_name.$ext)) { |
|
294 | + $fp = fopen($homep.$noticef.'_'.$lang_name.$ext, 'w'); |
|
295 | + fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text"); |
|
296 | + fclose($fp); |
|
297 | + } |
|
298 | + } |
|
299 | + } |
|
300 | + } |
|
301 | + } else { |
|
302 | + fputs($fp, ''); |
|
303 | + |
|
304 | + foreach ($_languages['name'] as $key => $value) { |
|
305 | + $lang_name = $_languages['folder'][$key]; |
|
306 | + if (isset($_POST[$lang_name])) { |
|
307 | + if (file_exists($homep.$noticef.'_'.$lang_name.$ext)) { |
|
308 | + $fp1 = fopen($homep.$noticef.'_'.$lang_name.$ext, 'w'); |
|
309 | + fputs($fp1, ''); |
|
310 | + fclose($fp1); |
|
311 | + } |
|
312 | + } |
|
313 | + } |
|
314 | + } |
|
315 | + fclose($fp); |
|
316 | + } else { |
|
317 | + $errorMsg .= "<br/>\n".get_lang('HomePageFilesNotWritable'); |
|
318 | + } |
|
319 | + } else { |
|
320 | + //File does not exist |
|
321 | + $fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w'); |
|
322 | + fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text"); |
|
323 | + fclose($fp); |
|
324 | + } |
|
325 | + Event::addEvent( |
|
326 | 326 | LOG_HOMEPAGE_CHANGED, |
327 | 327 | 'edit_notice', |
328 | 328 | cut(strip_tags($notice_title), 254), |
329 | 329 | api_get_utc_datetime(), |
330 | 330 | api_get_user_id() |
331 | 331 | ); |
332 | - break; |
|
333 | - case 'edit_news': |
|
334 | - //Filter |
|
335 | - $home_news = trim(stripslashes($_POST['home_news'])); |
|
336 | - |
|
337 | - //Write |
|
338 | - if ($s_languages_news != 'all') { |
|
339 | - if (file_exists($homep.$newsf.'_'.$s_languages_news.$ext)) { |
|
340 | - if (is_writable($homep.$newsf.'_'.$s_languages_news.$ext)) { |
|
341 | - $fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w'); |
|
342 | - fputs($fp, $home_news); |
|
343 | - fclose($fp); |
|
344 | - } else { |
|
345 | - $errorMsg = get_lang('HomePageFilesNotWritable'); |
|
346 | - } |
|
347 | - } else { |
|
348 | - // File does not exist |
|
349 | - $fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w'); |
|
350 | - fputs($fp, $home_news); |
|
351 | - fclose($fp); |
|
352 | - } |
|
353 | - } else { |
|
354 | - // We update all the news file |
|
355 | - foreach ($_languages['name'] as $key => $value) { |
|
356 | - $english_name = $_languages['folder'][$key]; |
|
357 | - if (file_exists($homep.$newsf.'_'.$english_name.$ext)) { |
|
358 | - if (is_writable($homep.$newsf.'_'.$english_name.$ext)) { |
|
359 | - $fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w'); |
|
360 | - fputs($fp, $home_news); |
|
361 | - fclose($fp); |
|
362 | - } else { |
|
363 | - $errorMsg = get_lang('HomePageFilesNotWritable'); |
|
364 | - } |
|
365 | - } else { |
|
366 | - // File does not exist |
|
367 | - $fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w'); |
|
368 | - fputs($fp, $home_news); |
|
369 | - fclose($fp); |
|
370 | - } |
|
371 | - } |
|
372 | - } |
|
373 | - Event::addEvent( |
|
332 | + break; |
|
333 | + case 'edit_news': |
|
334 | + //Filter |
|
335 | + $home_news = trim(stripslashes($_POST['home_news'])); |
|
336 | + |
|
337 | + //Write |
|
338 | + if ($s_languages_news != 'all') { |
|
339 | + if (file_exists($homep.$newsf.'_'.$s_languages_news.$ext)) { |
|
340 | + if (is_writable($homep.$newsf.'_'.$s_languages_news.$ext)) { |
|
341 | + $fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w'); |
|
342 | + fputs($fp, $home_news); |
|
343 | + fclose($fp); |
|
344 | + } else { |
|
345 | + $errorMsg = get_lang('HomePageFilesNotWritable'); |
|
346 | + } |
|
347 | + } else { |
|
348 | + // File does not exist |
|
349 | + $fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w'); |
|
350 | + fputs($fp, $home_news); |
|
351 | + fclose($fp); |
|
352 | + } |
|
353 | + } else { |
|
354 | + // We update all the news file |
|
355 | + foreach ($_languages['name'] as $key => $value) { |
|
356 | + $english_name = $_languages['folder'][$key]; |
|
357 | + if (file_exists($homep.$newsf.'_'.$english_name.$ext)) { |
|
358 | + if (is_writable($homep.$newsf.'_'.$english_name.$ext)) { |
|
359 | + $fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w'); |
|
360 | + fputs($fp, $home_news); |
|
361 | + fclose($fp); |
|
362 | + } else { |
|
363 | + $errorMsg = get_lang('HomePageFilesNotWritable'); |
|
364 | + } |
|
365 | + } else { |
|
366 | + // File does not exist |
|
367 | + $fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w'); |
|
368 | + fputs($fp, $home_news); |
|
369 | + fclose($fp); |
|
370 | + } |
|
371 | + } |
|
372 | + } |
|
373 | + Event::addEvent( |
|
374 | 374 | LOG_HOMEPAGE_CHANGED, |
375 | 375 | 'edit_news', |
376 | 376 | strip_tags(cut($home_news, 254)), |
377 | 377 | api_get_utc_datetime(), |
378 | 378 | api_get_user_id() |
379 | 379 | ); |
380 | - break; |
|
381 | - case 'insert_tabs': |
|
382 | - case 'edit_tabs': |
|
383 | - case 'insert_link': |
|
384 | - case 'edit_link': |
|
385 | - $link_index = intval($_POST['link_index']); |
|
386 | - $insert_where = intval($_POST['insert_where']); |
|
387 | - $link_name = trim(stripslashes($_POST['link_name'])); |
|
388 | - $link_url = trim(stripslashes($_POST['link_url'])); |
|
389 | - $add_in_tab = intval($_POST['add_in_tab']); |
|
390 | - $link_html = trim(stripslashes($_POST['link_html'])); |
|
391 | - $filename = trim(stripslashes($_POST['filename'])); |
|
392 | - $target_blank = $_POST['target_blank'] ? true : false; |
|
393 | - |
|
394 | - if ($link_url == 'http://' || $link_url == 'https://') { |
|
395 | - $link_url = ''; |
|
396 | - } elseif (!empty($link_url) && !strstr($link_url, '://')) { |
|
397 | - $link_url='http://'.$link_url; |
|
398 | - } |
|
399 | - $menuf = ($action == 'insert_tabs' || $action == 'edit_tabs')? $mtloggedin : $menuf; |
|
400 | - |
|
401 | - if (!is_writable($homep.$menuf.'_'.$lang.$ext)) { |
|
402 | - $errorMsg = get_lang('HomePageFilesNotWritable'); |
|
403 | - } elseif (empty($link_name)) { |
|
404 | - $errorMsg = get_lang('PleaseEnterLinkName'); |
|
405 | - } else { |
|
406 | - // New links are added as new files in the home/ directory |
|
407 | - if ($action == 'insert_link' || $action == 'insert_tabs' || empty($filename) || strstr($filename, '/') || !strstr($filename, '.html')) { |
|
408 | - $filename = api_replace_dangerous_char($link_name).'.html'; |
|
409 | - } |
|
410 | - |
|
411 | - // "home_" prefix for links are renamed to "user_" prefix (to avoid name clash with existing home page files) |
|
412 | - if (!empty($filename)) { |
|
413 | - $filename = str_replace('home_', 'user_', $filename); |
|
414 | - } |
|
415 | - // If the typical language suffix is not found in the file name, |
|
416 | - // replace the ".html" suffix by "_en.html" or the active menu language |
|
417 | - if (!strstr($filename,'_'.$lang.$ext)) { |
|
418 | - $filename = str_replace($ext, '_'.$lang.$ext, $filename); |
|
419 | - } |
|
420 | - // Get the contents of home_menu_en.html (or active menu language |
|
421 | - // version) into $home_menu as an array of one entry per line |
|
422 | - $home_menu = file($homep.$menuf.'_'.$lang.$ext); |
|
423 | - $home_menu = implode("\n", $home_menu); |
|
424 | - $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
|
425 | - $home_menu = explode("\n", $home_menu); |
|
426 | - $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen')); |
|
427 | - // Prepare place to insert the new link into (default is end of file) |
|
428 | - if ($insert_where < -1 || $insert_where > (sizeof($home_menu) - 1)) { |
|
429 | - $insert_where = sizeof($home_menu) - 1; |
|
430 | - } |
|
431 | - // |
|
432 | - // For each line of the file, remove trailing spaces and special chars |
|
433 | - //foreach ($home_menu as $key => $enreg) { |
|
434 | - // $home_menu[$key] = trim($enreg); |
|
435 | - //} |
|
436 | - // |
|
437 | - // If the given link url is empty, then replace the link url by a link to the link file created |
|
438 | - |
|
439 | - if (empty($link_url) || $link_url == 'http://' || $link_url == 'https://') { |
|
440 | - $link_url = api_get_path(WEB_PATH).'index.php?include='.urlencode($filename); |
|
441 | - // If the file doesn't exist, then create it and |
|
442 | - // fill it with default text |
|
443 | - |
|
444 | - $fp = @fopen($homep.$filename, 'w'); |
|
445 | - if ($fp) { |
|
446 | - if (empty($link_html)) { |
|
447 | - fputs($fp, get_lang('MyTextHere')); |
|
448 | - home_tabs($homep.$filename); |
|
449 | - } else { |
|
450 | - fputs($fp, $link_html); |
|
451 | - home_tabs($homep.$filename); |
|
452 | - } |
|
453 | - fclose($fp); |
|
454 | - } |
|
455 | - } |
|
456 | - // If the requested action is to edit a link, open the file and |
|
457 | - // write to it (if the file doesn't exist, create it) |
|
458 | - if (in_array($action, array('edit_link')) && !empty($link_html)) { |
|
459 | - $fp = @fopen($homep.$filename, 'w'); |
|
460 | - if ($fp) { |
|
461 | - fputs($fp, $link_html); |
|
462 | - home_tabs($homep.$filename); |
|
463 | - fclose($fp); |
|
464 | - } |
|
465 | - } |
|
466 | - |
|
467 | - $class_add_in_tab = 'class="show_menu"'; |
|
468 | - if (!$add_in_tab) { |
|
469 | - $class_add_in_tab = 'class="hide_menu"'; |
|
470 | - } |
|
471 | - |
|
472 | - // If the requested action is to create a link, make some room |
|
473 | - // for the new link in the home_menu array at the requested place |
|
474 | - // and insert the new link there |
|
380 | + break; |
|
381 | + case 'insert_tabs': |
|
382 | + case 'edit_tabs': |
|
383 | + case 'insert_link': |
|
384 | + case 'edit_link': |
|
385 | + $link_index = intval($_POST['link_index']); |
|
386 | + $insert_where = intval($_POST['insert_where']); |
|
387 | + $link_name = trim(stripslashes($_POST['link_name'])); |
|
388 | + $link_url = trim(stripslashes($_POST['link_url'])); |
|
389 | + $add_in_tab = intval($_POST['add_in_tab']); |
|
390 | + $link_html = trim(stripslashes($_POST['link_html'])); |
|
391 | + $filename = trim(stripslashes($_POST['filename'])); |
|
392 | + $target_blank = $_POST['target_blank'] ? true : false; |
|
393 | + |
|
394 | + if ($link_url == 'http://' || $link_url == 'https://') { |
|
395 | + $link_url = ''; |
|
396 | + } elseif (!empty($link_url) && !strstr($link_url, '://')) { |
|
397 | + $link_url='http://'.$link_url; |
|
398 | + } |
|
399 | + $menuf = ($action == 'insert_tabs' || $action == 'edit_tabs')? $mtloggedin : $menuf; |
|
400 | + |
|
401 | + if (!is_writable($homep.$menuf.'_'.$lang.$ext)) { |
|
402 | + $errorMsg = get_lang('HomePageFilesNotWritable'); |
|
403 | + } elseif (empty($link_name)) { |
|
404 | + $errorMsg = get_lang('PleaseEnterLinkName'); |
|
405 | + } else { |
|
406 | + // New links are added as new files in the home/ directory |
|
407 | + if ($action == 'insert_link' || $action == 'insert_tabs' || empty($filename) || strstr($filename, '/') || !strstr($filename, '.html')) { |
|
408 | + $filename = api_replace_dangerous_char($link_name).'.html'; |
|
409 | + } |
|
410 | + |
|
411 | + // "home_" prefix for links are renamed to "user_" prefix (to avoid name clash with existing home page files) |
|
412 | + if (!empty($filename)) { |
|
413 | + $filename = str_replace('home_', 'user_', $filename); |
|
414 | + } |
|
415 | + // If the typical language suffix is not found in the file name, |
|
416 | + // replace the ".html" suffix by "_en.html" or the active menu language |
|
417 | + if (!strstr($filename,'_'.$lang.$ext)) { |
|
418 | + $filename = str_replace($ext, '_'.$lang.$ext, $filename); |
|
419 | + } |
|
420 | + // Get the contents of home_menu_en.html (or active menu language |
|
421 | + // version) into $home_menu as an array of one entry per line |
|
422 | + $home_menu = file($homep.$menuf.'_'.$lang.$ext); |
|
423 | + $home_menu = implode("\n", $home_menu); |
|
424 | + $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
|
425 | + $home_menu = explode("\n", $home_menu); |
|
426 | + $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen')); |
|
427 | + // Prepare place to insert the new link into (default is end of file) |
|
428 | + if ($insert_where < -1 || $insert_where > (sizeof($home_menu) - 1)) { |
|
429 | + $insert_where = sizeof($home_menu) - 1; |
|
430 | + } |
|
431 | + // |
|
432 | + // For each line of the file, remove trailing spaces and special chars |
|
433 | + //foreach ($home_menu as $key => $enreg) { |
|
434 | + // $home_menu[$key] = trim($enreg); |
|
435 | + //} |
|
436 | + // |
|
437 | + // If the given link url is empty, then replace the link url by a link to the link file created |
|
438 | + |
|
439 | + if (empty($link_url) || $link_url == 'http://' || $link_url == 'https://') { |
|
440 | + $link_url = api_get_path(WEB_PATH).'index.php?include='.urlencode($filename); |
|
441 | + // If the file doesn't exist, then create it and |
|
442 | + // fill it with default text |
|
443 | + |
|
444 | + $fp = @fopen($homep.$filename, 'w'); |
|
445 | + if ($fp) { |
|
446 | + if (empty($link_html)) { |
|
447 | + fputs($fp, get_lang('MyTextHere')); |
|
448 | + home_tabs($homep.$filename); |
|
449 | + } else { |
|
450 | + fputs($fp, $link_html); |
|
451 | + home_tabs($homep.$filename); |
|
452 | + } |
|
453 | + fclose($fp); |
|
454 | + } |
|
455 | + } |
|
456 | + // If the requested action is to edit a link, open the file and |
|
457 | + // write to it (if the file doesn't exist, create it) |
|
458 | + if (in_array($action, array('edit_link')) && !empty($link_html)) { |
|
459 | + $fp = @fopen($homep.$filename, 'w'); |
|
460 | + if ($fp) { |
|
461 | + fputs($fp, $link_html); |
|
462 | + home_tabs($homep.$filename); |
|
463 | + fclose($fp); |
|
464 | + } |
|
465 | + } |
|
466 | + |
|
467 | + $class_add_in_tab = 'class="show_menu"'; |
|
468 | + if (!$add_in_tab) { |
|
469 | + $class_add_in_tab = 'class="hide_menu"'; |
|
470 | + } |
|
471 | + |
|
472 | + // If the requested action is to create a link, make some room |
|
473 | + // for the new link in the home_menu array at the requested place |
|
474 | + // and insert the new link there |
|
475 | 475 | $icon = '<em class="fa fa-external-link"></em>'; |
476 | - if ($action == 'insert_link' || $action == 'insert_tabs') { |
|
477 | - for ($i = sizeof($home_menu); $i; $i--) { |
|
478 | - if ($i > $insert_where) { |
|
479 | - $home_menu[$i] = $home_menu[$i - 1]; |
|
480 | - } else { |
|
481 | - break; |
|
482 | - } |
|
483 | - } |
|
484 | - $home_menu[$insert_where + 1] = '<li '.$class_add_in_tab.'><a href="'.$link_url.'" target="'.($target_blank ? '_blank' : '_self').'">'.$icon.' '.$link_name.'</a></li>'; |
|
485 | - } else { |
|
486 | - // If the request is about a link edition, change the link |
|
487 | - $home_menu[$link_index]='<li '.$class_add_in_tab.'><a href="'.$link_url.'" target="'.($target_blank?'_blank':'_self').'">'.$icon.' '.$link_name.'</a></li>'; |
|
488 | - } |
|
489 | - // Re-build the file from the home_menu array |
|
490 | - $home_menu = implode("\n", $home_menu); |
|
491 | - // Write |
|
492 | - if (file_exists($homep.$menuf.'_'.$lang.$ext)) { |
|
493 | - if (is_writable($homep.$menuf.'_'.$lang.$ext)) { |
|
494 | - $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w'); |
|
495 | - fputs($fp, $home_menu); |
|
496 | - home_tabs($homep.$menuf.'_'.$lang.$ext); |
|
497 | - fclose($fp); |
|
498 | - |
|
499 | - foreach ($_languages['name'] as $key => $value) { |
|
500 | - $lang_name = $_languages['folder'][$key]; |
|
501 | - if (isset($_POST[$lang_name])) { |
|
502 | - $fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w'); |
|
503 | - fputs($fp, $home_menu); |
|
504 | - home_tabs($homep.$menuf.'_'.$lang_name.$ext); |
|
505 | - fclose($fp); |
|
506 | - } |
|
507 | - } |
|
508 | - |
|
509 | - if (file_exists($homep.$menuf.$ext)) { |
|
510 | - if (is_writable($homep.$menuf.$ext)) { |
|
511 | - $fpo = fopen($homep.$menuf.$ext, 'w'); |
|
512 | - fputs($fpo, $home_menu); |
|
513 | - home_tabs($homep.$menuf.$ext); |
|
514 | - fclose($fpo); |
|
515 | - } |
|
516 | - } |
|
517 | - } else { |
|
518 | - $errorMsg = get_lang('HomePageFilesNotWritable'); |
|
519 | - } |
|
520 | - } else { |
|
521 | - //File does not exist |
|
522 | - $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w'); |
|
523 | - fputs($fp, $home_menu); |
|
524 | - home_tabs($homep.$menuf.'_'.$lang.$ext); |
|
525 | - fclose($fp); |
|
526 | - |
|
527 | - foreach ($_languages['name'] as $key => $value) { |
|
528 | - $lang_name = $_languages['folder'][$key]; |
|
529 | - if (isset($_POST[$lang_name])) { |
|
530 | - $fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w'); |
|
531 | - fputs($fp, $home_menu); |
|
532 | - home_tabs($homep.$menuf.'_'.$lang_name.$ext); |
|
533 | - fclose($fp); |
|
534 | - } |
|
535 | - } |
|
536 | - } |
|
537 | - } |
|
538 | - Event::addEvent( |
|
539 | - LOG_HOMEPAGE_CHANGED, |
|
540 | - $action, |
|
541 | - cut($link_name . ':' . $link_url, 254), |
|
542 | - api_get_utc_datetime(), |
|
543 | - api_get_user_id() |
|
544 | - ); |
|
545 | - break; |
|
546 | - } //end of switch($action) |
|
547 | - |
|
548 | - if (empty($errorMsg)) { |
|
549 | - header('Location: '.api_get_self().'?language='.$languageGet); |
|
550 | - exit(); |
|
551 | - } |
|
552 | - } else { |
|
553 | - //if POST[formSent] is not set |
|
554 | - switch ($action) { |
|
555 | - case 'open_link': |
|
556 | - // Previously, filtering of GET['link'] was done here but it left |
|
557 | - // a security threat. Filtering has now been moved outside conditions |
|
558 | - break; |
|
559 | - case 'delete_tabs': |
|
560 | - case 'delete_link': |
|
561 | - // A link is deleted by getting the file into an array, removing the |
|
562 | - // link and re-writing the array to the file |
|
563 | - $link_index = intval($_GET['link_index']); |
|
564 | - $menuf = ($action == 'delete_tabs')? $mtloggedin : $menuf; |
|
565 | - $home_menu = @file($homep.$menuf.'_'.$lang.$ext); |
|
566 | - if (empty($home_menu)) { |
|
567 | - $home_menu = array(); |
|
568 | - } |
|
569 | - foreach ($home_menu as $key => $enreg) { |
|
570 | - if ($key == $link_index) { |
|
571 | - unset($home_menu[$key]); |
|
572 | - } else { |
|
573 | - $home_menu[$key] = trim($enreg); |
|
574 | - } |
|
575 | - } |
|
576 | - $home_menu = implode("\n", $home_menu); |
|
577 | - $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
|
578 | - |
|
579 | - $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w'); |
|
580 | - fputs($fp, $home_menu); |
|
581 | - home_tabs($homep.$menuf.'_'.$lang.$ext); |
|
582 | - fclose($fp); |
|
583 | - if (file_exists($homep.$menuf.$ext)) { |
|
584 | - if (is_writable($homep.$menuf.$ext)) { |
|
585 | - $fpo = fopen($homep.$menuf.$ext,'w'); |
|
586 | - fputs($fpo, $home_menu); |
|
587 | - home_tabs($homep.$menuf.$ext); |
|
588 | - fclose($fpo); |
|
589 | - } |
|
590 | - } |
|
591 | - header('Location: '.api_get_self()); |
|
592 | - exit(); |
|
593 | - break; |
|
594 | - case 'edit_top': |
|
595 | - // This request is only the preparation for the update of the home_top |
|
596 | - $home_top = ''; |
|
597 | - if (is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) { |
|
598 | - $home_top = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext); |
|
599 | - } elseif (is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) { |
|
600 | - $home_top = @(string)file_get_contents($homep.$topf.$lang.$ext); |
|
601 | - } else { |
|
602 | - $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
603 | - } |
|
604 | - $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top))); |
|
605 | - break; |
|
606 | - case 'edit_notice': |
|
607 | - // This request is only the preparation for the update of the home_notice |
|
608 | - $home_notice = ''; |
|
609 | - if (is_file($homep.$noticef.'_'.$lang.$ext) && is_readable($homep.$noticef.'_'.$lang.$ext)) { |
|
610 | - $home_notice = @file($homep.$noticef.'_'.$lang.$ext); |
|
611 | - } elseif (is_file($homep.$noticef.$lang.$ext) && is_readable($homep.$noticef.$lang.$ext)) { |
|
612 | - $home_notice = @file($homep.$noticef.$lang.$ext); |
|
613 | - } else { |
|
614 | - $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
615 | - } |
|
616 | - if (empty($home_notice)) { |
|
617 | - $home_notice = array(); |
|
618 | - } |
|
619 | - $notice_title = strip_tags($home_notice[0]); |
|
620 | - $notice_title = api_to_system_encoding($notice_title, api_detect_encoding($notice_title)); |
|
621 | - $notice_text = strip_tags(str_replace('<br />', "\n", $home_notice[1]), '<a>'); |
|
622 | - $notice_text = api_to_system_encoding($notice_text, api_detect_encoding(strip_tags($notice_text))); |
|
623 | - break; |
|
624 | - case 'edit_news': |
|
625 | - // This request is the preparation for the update of the home_news page |
|
626 | - $home_news = ''; |
|
627 | - if (is_file($homep.$newsf.'_'.$lang.$ext) && is_readable($homep.$newsf.'_'.$lang.$ext)) { |
|
628 | - $home_news = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext); |
|
629 | - } elseif (is_file($homep.$newsf.$lang.$ext) && is_readable($homep.$newsf.$lang.$ext)) { |
|
630 | - $home_news = @(string)file_get_contents($homep.$newsf.$lang.$ext); |
|
631 | - } else { |
|
632 | - $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
633 | - } |
|
634 | - $home_news = api_to_system_encoding($home_news, api_detect_encoding(strip_tags($home_news))); |
|
635 | - break; |
|
636 | - case 'insert_link': |
|
637 | - // This request is the preparation for the addition of an item in home_menu |
|
638 | - $home_menu = ''; |
|
639 | - $menuf = ($action == 'edit_tabs')? $mtloggedin : $menuf; |
|
640 | - if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) { |
|
641 | - $home_menu = @file($homep.$menuf.'_'.$lang.$ext); |
|
642 | - } elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) { |
|
643 | - $home_menu = @file($homep.$menuf.$lang.$ext); |
|
644 | - } else { |
|
645 | - $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
646 | - } |
|
647 | - if (empty($home_menu)) { |
|
648 | - $home_menu = array(); |
|
649 | - } |
|
650 | - if (!empty($home_menu)) { |
|
651 | - $home_menu = implode("\n", $home_menu); |
|
652 | - $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
|
653 | - $home_menu = explode("\n", $home_menu); |
|
654 | - } |
|
655 | - $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen')); |
|
656 | - break; |
|
657 | - case 'insert_tabs': |
|
658 | - // This request is the preparation for the addition of an item in home_menu |
|
659 | - $home_menu = ''; |
|
660 | - if (is_file($homep.$mtloggedin.'_'.$lang.$ext) && is_readable($homep.$mtloggedin.'_'.$lang.$ext)) { |
|
661 | - $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext); |
|
662 | - } elseif (is_file($homep.$mtloggedin.$lang.$ext) && is_readable($homep.$mtloggedin.$lang.$ext)) { |
|
663 | - $home_menu = @file($homep.$mtloggedin.$lang.$ext); |
|
664 | - } elseif (touch($homep.$mtloggedin.'_'.$lang.$ext)) { |
|
665 | - $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext); |
|
666 | - } else { |
|
667 | - $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
668 | - } |
|
669 | - if (empty($home_menu)) { |
|
670 | - $home_menu = array(); |
|
671 | - } |
|
672 | - if (!empty($home_menu)) { |
|
673 | - $home_menu = implode("\n", $home_menu); |
|
674 | - $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
|
675 | - $home_menu = explode("\n", $home_menu); |
|
676 | - } |
|
677 | - $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen')); |
|
678 | - break; |
|
679 | - case 'edit_tabs': |
|
680 | - case 'edit_link': |
|
681 | - // This request is the preparation for the edition of the links array |
|
682 | - $home_menu = ''; |
|
683 | - $menuf = ($action == 'edit_tabs')? $mtloggedin : $menuf; |
|
684 | - if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) { |
|
685 | - $home_menu = @file($homep.$menuf.'_'.$lang.$ext); |
|
686 | - } elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) { |
|
687 | - $home_menu = @file($homep.$menuf.$lang.$ext); |
|
688 | - } else { |
|
689 | - $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
690 | - } |
|
691 | - |
|
692 | - if (empty($home_menu)) { |
|
693 | - if (file_exists($homep.$menutabs.'_'.$lang.$ext)) { |
|
694 | - $home_menu = @file($homep.$menutabs.'_'.$lang.$ext); |
|
695 | - } |
|
696 | - } |
|
697 | - |
|
698 | - if (empty($home_menu)) { |
|
699 | - $home_menu = array(); |
|
700 | - } |
|
701 | - if (!empty($home_menu)) { |
|
702 | - $home_menu = implode("\n", $home_menu); |
|
703 | - $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
|
704 | - $home_menu = explode("\n", $home_menu); |
|
705 | - } |
|
706 | - |
|
707 | - $link_index = intval($_GET['link_index']); |
|
708 | - |
|
709 | - $target_blank = false; |
|
710 | - $link_name = ''; |
|
711 | - $link_url = ''; |
|
712 | - |
|
713 | - //$home_menu_new = array(); |
|
714 | - // |
|
715 | - //Cleaning array |
|
716 | - //foreach ($home_menu as $item) { |
|
717 | - // if(!empty($item)) { |
|
718 | - // $home_menu_new[] = $item; |
|
719 | - // } |
|
720 | - //} |
|
721 | - //$home_menu = $home_menu_new; |
|
722 | - |
|
723 | - // Cleaning the array |
|
724 | - $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen')); |
|
725 | - |
|
726 | - // For each line of the home_menu file |
|
727 | - foreach ($home_menu as $key => $enreg) { |
|
728 | - |
|
729 | - // Check if the current item is the one we want to update |
|
730 | - if ($key == $link_index) { |
|
731 | - // This is the link we want to update |
|
732 | - // Check if the target should be "_blank" |
|
733 | - if (strstr($enreg, 'target="_blank"')) { |
|
734 | - $target_blank = true; |
|
735 | - } |
|
736 | - |
|
737 | - if (strstr($enreg, 'hide_menu')) { |
|
738 | - $add_in_tab = false; |
|
739 | - } else { |
|
740 | - $add_in_tab = true; |
|
741 | - } |
|
742 | - |
|
743 | - // Remove dangerous HTML tags from the link itself (this is an |
|
744 | - // additional measure in case a link previously contained |
|
745 | - // unsecure tags) |
|
746 | - $link_name = strip_tags($enreg); |
|
747 | - |
|
748 | - // Get the contents of "href" attribute in $link_url |
|
749 | - $enreg = explode('href="',$enreg); |
|
750 | - list($link_url) = explode('"', $enreg[sizeof($enreg) - 1]); |
|
751 | - |
|
752 | - // If the link contains the web root of this portal, then strip |
|
753 | - // it off and keep only the name of the file that needs edition |
|
754 | - if (strstr($link_url, '?include=')) { |
|
755 | - $link_url = explode('?include=', $link_url); |
|
756 | - |
|
757 | - $filename = $link_url[sizeof($link_url) - 1]; |
|
758 | - |
|
759 | - if (!strstr($filename, '/') && strstr($filename, '.html')) { |
|
760 | - // Get oonly the contents of the link file |
|
761 | - $link_html = @file($homep.$filename); |
|
762 | - $link_html = implode('', $link_html); |
|
763 | - $link_url = ''; |
|
764 | - } else { |
|
765 | - $filename = ''; |
|
766 | - } |
|
767 | - } |
|
768 | - break; |
|
769 | - } |
|
770 | - } |
|
771 | - break; |
|
772 | - }//end of second switch($action) (when POST['formSent'] was not set, yet) |
|
773 | - }// end of "else" in if($_POST['formSent']) condition |
|
476 | + if ($action == 'insert_link' || $action == 'insert_tabs') { |
|
477 | + for ($i = sizeof($home_menu); $i; $i--) { |
|
478 | + if ($i > $insert_where) { |
|
479 | + $home_menu[$i] = $home_menu[$i - 1]; |
|
480 | + } else { |
|
481 | + break; |
|
482 | + } |
|
483 | + } |
|
484 | + $home_menu[$insert_where + 1] = '<li '.$class_add_in_tab.'><a href="'.$link_url.'" target="'.($target_blank ? '_blank' : '_self').'">'.$icon.' '.$link_name.'</a></li>'; |
|
485 | + } else { |
|
486 | + // If the request is about a link edition, change the link |
|
487 | + $home_menu[$link_index]='<li '.$class_add_in_tab.'><a href="'.$link_url.'" target="'.($target_blank?'_blank':'_self').'">'.$icon.' '.$link_name.'</a></li>'; |
|
488 | + } |
|
489 | + // Re-build the file from the home_menu array |
|
490 | + $home_menu = implode("\n", $home_menu); |
|
491 | + // Write |
|
492 | + if (file_exists($homep.$menuf.'_'.$lang.$ext)) { |
|
493 | + if (is_writable($homep.$menuf.'_'.$lang.$ext)) { |
|
494 | + $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w'); |
|
495 | + fputs($fp, $home_menu); |
|
496 | + home_tabs($homep.$menuf.'_'.$lang.$ext); |
|
497 | + fclose($fp); |
|
498 | + |
|
499 | + foreach ($_languages['name'] as $key => $value) { |
|
500 | + $lang_name = $_languages['folder'][$key]; |
|
501 | + if (isset($_POST[$lang_name])) { |
|
502 | + $fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w'); |
|
503 | + fputs($fp, $home_menu); |
|
504 | + home_tabs($homep.$menuf.'_'.$lang_name.$ext); |
|
505 | + fclose($fp); |
|
506 | + } |
|
507 | + } |
|
508 | + |
|
509 | + if (file_exists($homep.$menuf.$ext)) { |
|
510 | + if (is_writable($homep.$menuf.$ext)) { |
|
511 | + $fpo = fopen($homep.$menuf.$ext, 'w'); |
|
512 | + fputs($fpo, $home_menu); |
|
513 | + home_tabs($homep.$menuf.$ext); |
|
514 | + fclose($fpo); |
|
515 | + } |
|
516 | + } |
|
517 | + } else { |
|
518 | + $errorMsg = get_lang('HomePageFilesNotWritable'); |
|
519 | + } |
|
520 | + } else { |
|
521 | + //File does not exist |
|
522 | + $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w'); |
|
523 | + fputs($fp, $home_menu); |
|
524 | + home_tabs($homep.$menuf.'_'.$lang.$ext); |
|
525 | + fclose($fp); |
|
526 | + |
|
527 | + foreach ($_languages['name'] as $key => $value) { |
|
528 | + $lang_name = $_languages['folder'][$key]; |
|
529 | + if (isset($_POST[$lang_name])) { |
|
530 | + $fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w'); |
|
531 | + fputs($fp, $home_menu); |
|
532 | + home_tabs($homep.$menuf.'_'.$lang_name.$ext); |
|
533 | + fclose($fp); |
|
534 | + } |
|
535 | + } |
|
536 | + } |
|
537 | + } |
|
538 | + Event::addEvent( |
|
539 | + LOG_HOMEPAGE_CHANGED, |
|
540 | + $action, |
|
541 | + cut($link_name . ':' . $link_url, 254), |
|
542 | + api_get_utc_datetime(), |
|
543 | + api_get_user_id() |
|
544 | + ); |
|
545 | + break; |
|
546 | + } //end of switch($action) |
|
547 | + |
|
548 | + if (empty($errorMsg)) { |
|
549 | + header('Location: '.api_get_self().'?language='.$languageGet); |
|
550 | + exit(); |
|
551 | + } |
|
552 | + } else { |
|
553 | + //if POST[formSent] is not set |
|
554 | + switch ($action) { |
|
555 | + case 'open_link': |
|
556 | + // Previously, filtering of GET['link'] was done here but it left |
|
557 | + // a security threat. Filtering has now been moved outside conditions |
|
558 | + break; |
|
559 | + case 'delete_tabs': |
|
560 | + case 'delete_link': |
|
561 | + // A link is deleted by getting the file into an array, removing the |
|
562 | + // link and re-writing the array to the file |
|
563 | + $link_index = intval($_GET['link_index']); |
|
564 | + $menuf = ($action == 'delete_tabs')? $mtloggedin : $menuf; |
|
565 | + $home_menu = @file($homep.$menuf.'_'.$lang.$ext); |
|
566 | + if (empty($home_menu)) { |
|
567 | + $home_menu = array(); |
|
568 | + } |
|
569 | + foreach ($home_menu as $key => $enreg) { |
|
570 | + if ($key == $link_index) { |
|
571 | + unset($home_menu[$key]); |
|
572 | + } else { |
|
573 | + $home_menu[$key] = trim($enreg); |
|
574 | + } |
|
575 | + } |
|
576 | + $home_menu = implode("\n", $home_menu); |
|
577 | + $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
|
578 | + |
|
579 | + $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w'); |
|
580 | + fputs($fp, $home_menu); |
|
581 | + home_tabs($homep.$menuf.'_'.$lang.$ext); |
|
582 | + fclose($fp); |
|
583 | + if (file_exists($homep.$menuf.$ext)) { |
|
584 | + if (is_writable($homep.$menuf.$ext)) { |
|
585 | + $fpo = fopen($homep.$menuf.$ext,'w'); |
|
586 | + fputs($fpo, $home_menu); |
|
587 | + home_tabs($homep.$menuf.$ext); |
|
588 | + fclose($fpo); |
|
589 | + } |
|
590 | + } |
|
591 | + header('Location: '.api_get_self()); |
|
592 | + exit(); |
|
593 | + break; |
|
594 | + case 'edit_top': |
|
595 | + // This request is only the preparation for the update of the home_top |
|
596 | + $home_top = ''; |
|
597 | + if (is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) { |
|
598 | + $home_top = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext); |
|
599 | + } elseif (is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) { |
|
600 | + $home_top = @(string)file_get_contents($homep.$topf.$lang.$ext); |
|
601 | + } else { |
|
602 | + $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
603 | + } |
|
604 | + $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top))); |
|
605 | + break; |
|
606 | + case 'edit_notice': |
|
607 | + // This request is only the preparation for the update of the home_notice |
|
608 | + $home_notice = ''; |
|
609 | + if (is_file($homep.$noticef.'_'.$lang.$ext) && is_readable($homep.$noticef.'_'.$lang.$ext)) { |
|
610 | + $home_notice = @file($homep.$noticef.'_'.$lang.$ext); |
|
611 | + } elseif (is_file($homep.$noticef.$lang.$ext) && is_readable($homep.$noticef.$lang.$ext)) { |
|
612 | + $home_notice = @file($homep.$noticef.$lang.$ext); |
|
613 | + } else { |
|
614 | + $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
615 | + } |
|
616 | + if (empty($home_notice)) { |
|
617 | + $home_notice = array(); |
|
618 | + } |
|
619 | + $notice_title = strip_tags($home_notice[0]); |
|
620 | + $notice_title = api_to_system_encoding($notice_title, api_detect_encoding($notice_title)); |
|
621 | + $notice_text = strip_tags(str_replace('<br />', "\n", $home_notice[1]), '<a>'); |
|
622 | + $notice_text = api_to_system_encoding($notice_text, api_detect_encoding(strip_tags($notice_text))); |
|
623 | + break; |
|
624 | + case 'edit_news': |
|
625 | + // This request is the preparation for the update of the home_news page |
|
626 | + $home_news = ''; |
|
627 | + if (is_file($homep.$newsf.'_'.$lang.$ext) && is_readable($homep.$newsf.'_'.$lang.$ext)) { |
|
628 | + $home_news = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext); |
|
629 | + } elseif (is_file($homep.$newsf.$lang.$ext) && is_readable($homep.$newsf.$lang.$ext)) { |
|
630 | + $home_news = @(string)file_get_contents($homep.$newsf.$lang.$ext); |
|
631 | + } else { |
|
632 | + $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
633 | + } |
|
634 | + $home_news = api_to_system_encoding($home_news, api_detect_encoding(strip_tags($home_news))); |
|
635 | + break; |
|
636 | + case 'insert_link': |
|
637 | + // This request is the preparation for the addition of an item in home_menu |
|
638 | + $home_menu = ''; |
|
639 | + $menuf = ($action == 'edit_tabs')? $mtloggedin : $menuf; |
|
640 | + if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) { |
|
641 | + $home_menu = @file($homep.$menuf.'_'.$lang.$ext); |
|
642 | + } elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) { |
|
643 | + $home_menu = @file($homep.$menuf.$lang.$ext); |
|
644 | + } else { |
|
645 | + $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
646 | + } |
|
647 | + if (empty($home_menu)) { |
|
648 | + $home_menu = array(); |
|
649 | + } |
|
650 | + if (!empty($home_menu)) { |
|
651 | + $home_menu = implode("\n", $home_menu); |
|
652 | + $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
|
653 | + $home_menu = explode("\n", $home_menu); |
|
654 | + } |
|
655 | + $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen')); |
|
656 | + break; |
|
657 | + case 'insert_tabs': |
|
658 | + // This request is the preparation for the addition of an item in home_menu |
|
659 | + $home_menu = ''; |
|
660 | + if (is_file($homep.$mtloggedin.'_'.$lang.$ext) && is_readable($homep.$mtloggedin.'_'.$lang.$ext)) { |
|
661 | + $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext); |
|
662 | + } elseif (is_file($homep.$mtloggedin.$lang.$ext) && is_readable($homep.$mtloggedin.$lang.$ext)) { |
|
663 | + $home_menu = @file($homep.$mtloggedin.$lang.$ext); |
|
664 | + } elseif (touch($homep.$mtloggedin.'_'.$lang.$ext)) { |
|
665 | + $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext); |
|
666 | + } else { |
|
667 | + $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
668 | + } |
|
669 | + if (empty($home_menu)) { |
|
670 | + $home_menu = array(); |
|
671 | + } |
|
672 | + if (!empty($home_menu)) { |
|
673 | + $home_menu = implode("\n", $home_menu); |
|
674 | + $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
|
675 | + $home_menu = explode("\n", $home_menu); |
|
676 | + } |
|
677 | + $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen')); |
|
678 | + break; |
|
679 | + case 'edit_tabs': |
|
680 | + case 'edit_link': |
|
681 | + // This request is the preparation for the edition of the links array |
|
682 | + $home_menu = ''; |
|
683 | + $menuf = ($action == 'edit_tabs')? $mtloggedin : $menuf; |
|
684 | + if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) { |
|
685 | + $home_menu = @file($homep.$menuf.'_'.$lang.$ext); |
|
686 | + } elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) { |
|
687 | + $home_menu = @file($homep.$menuf.$lang.$ext); |
|
688 | + } else { |
|
689 | + $errorMsg = get_lang('HomePageFilesNotReadable'); |
|
690 | + } |
|
691 | + |
|
692 | + if (empty($home_menu)) { |
|
693 | + if (file_exists($homep.$menutabs.'_'.$lang.$ext)) { |
|
694 | + $home_menu = @file($homep.$menutabs.'_'.$lang.$ext); |
|
695 | + } |
|
696 | + } |
|
697 | + |
|
698 | + if (empty($home_menu)) { |
|
699 | + $home_menu = array(); |
|
700 | + } |
|
701 | + if (!empty($home_menu)) { |
|
702 | + $home_menu = implode("\n", $home_menu); |
|
703 | + $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
|
704 | + $home_menu = explode("\n", $home_menu); |
|
705 | + } |
|
706 | + |
|
707 | + $link_index = intval($_GET['link_index']); |
|
708 | + |
|
709 | + $target_blank = false; |
|
710 | + $link_name = ''; |
|
711 | + $link_url = ''; |
|
712 | + |
|
713 | + //$home_menu_new = array(); |
|
714 | + // |
|
715 | + //Cleaning array |
|
716 | + //foreach ($home_menu as $item) { |
|
717 | + // if(!empty($item)) { |
|
718 | + // $home_menu_new[] = $item; |
|
719 | + // } |
|
720 | + //} |
|
721 | + //$home_menu = $home_menu_new; |
|
722 | + |
|
723 | + // Cleaning the array |
|
724 | + $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen')); |
|
725 | + |
|
726 | + // For each line of the home_menu file |
|
727 | + foreach ($home_menu as $key => $enreg) { |
|
728 | + |
|
729 | + // Check if the current item is the one we want to update |
|
730 | + if ($key == $link_index) { |
|
731 | + // This is the link we want to update |
|
732 | + // Check if the target should be "_blank" |
|
733 | + if (strstr($enreg, 'target="_blank"')) { |
|
734 | + $target_blank = true; |
|
735 | + } |
|
736 | + |
|
737 | + if (strstr($enreg, 'hide_menu')) { |
|
738 | + $add_in_tab = false; |
|
739 | + } else { |
|
740 | + $add_in_tab = true; |
|
741 | + } |
|
742 | + |
|
743 | + // Remove dangerous HTML tags from the link itself (this is an |
|
744 | + // additional measure in case a link previously contained |
|
745 | + // unsecure tags) |
|
746 | + $link_name = strip_tags($enreg); |
|
747 | + |
|
748 | + // Get the contents of "href" attribute in $link_url |
|
749 | + $enreg = explode('href="',$enreg); |
|
750 | + list($link_url) = explode('"', $enreg[sizeof($enreg) - 1]); |
|
751 | + |
|
752 | + // If the link contains the web root of this portal, then strip |
|
753 | + // it off and keep only the name of the file that needs edition |
|
754 | + if (strstr($link_url, '?include=')) { |
|
755 | + $link_url = explode('?include=', $link_url); |
|
756 | + |
|
757 | + $filename = $link_url[sizeof($link_url) - 1]; |
|
758 | + |
|
759 | + if (!strstr($filename, '/') && strstr($filename, '.html')) { |
|
760 | + // Get oonly the contents of the link file |
|
761 | + $link_html = @file($homep.$filename); |
|
762 | + $link_html = implode('', $link_html); |
|
763 | + $link_url = ''; |
|
764 | + } else { |
|
765 | + $filename = ''; |
|
766 | + } |
|
767 | + } |
|
768 | + break; |
|
769 | + } |
|
770 | + } |
|
771 | + break; |
|
772 | + }//end of second switch($action) (when POST['formSent'] was not set, yet) |
|
773 | + }// end of "else" in if($_POST['formSent']) condition |
|
774 | 774 | } else { |
775 | - //if $action is empty, then prepare a list of the course categories to display (?) |
|
776 | - $Categories = getCategoriesToDisplayInHomePage(); |
|
775 | + //if $action is empty, then prepare a list of the course categories to display (?) |
|
776 | + $Categories = getCategoriesToDisplayInHomePage(); |
|
777 | 777 | } |
778 | 778 | |
779 | 779 | // Display section |
@@ -781,25 +781,25 @@ discard block |
||
781 | 781 | Display::display_header($tool_name); |
782 | 782 | |
783 | 783 | switch ($action) { |
784 | - case 'open_link': |
|
785 | - if (!empty($link)) { |
|
786 | - // $link is only set in case of action=open_link and is filtered |
|
787 | - $open = @(string)file_get_contents($homep.$link); |
|
788 | - $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); |
|
789 | - echo $open; |
|
790 | - } |
|
791 | - break; |
|
792 | - case 'edit_notice': |
|
793 | - // Display for edit_notice case |
|
794 | - ?> |
|
784 | + case 'open_link': |
|
785 | + if (!empty($link)) { |
|
786 | + // $link is only set in case of action=open_link and is filtered |
|
787 | + $open = @(string)file_get_contents($homep.$link); |
|
788 | + $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); |
|
789 | + echo $open; |
|
790 | + } |
|
791 | + break; |
|
792 | + case 'edit_notice': |
|
793 | + // Display for edit_notice case |
|
794 | + ?> |
|
795 | 795 | <form action="<?php echo api_get_self(); ?>?action=<?php echo $action; ?>" method="post" class="form-horizontal"> |
796 | 796 | <legend><?php echo $tool_name; ?></legend> |
797 | 797 | <input type="hidden" name="formSent" value="1"/> |
798 | 798 | <?php |
799 | - if (!empty($errorMsg)) { |
|
800 | - Display::display_normal_message($errorMsg); |
|
801 | - } |
|
802 | - ?> |
|
799 | + if (!empty($errorMsg)) { |
|
800 | + Display::display_normal_message($errorMsg); |
|
801 | + } |
|
802 | + ?> |
|
803 | 803 | <div class="row"> |
804 | 804 | <div class="col-md-12"> |
805 | 805 | <p><?php echo get_lang('LetThoseFieldsEmptyToHideTheNotice'); ?></p> |
@@ -837,170 +837,170 @@ discard block |
||
837 | 837 | </div> |
838 | 838 | </form> |
839 | 839 | <?php |
840 | - break; |
|
841 | - case 'insert_tabs': |
|
842 | - case 'edit_tabs': |
|
843 | - case 'insert_link': |
|
844 | - case 'edit_link': |
|
845 | - $menuf = ($action == 'insert_tabs' || $action == 'edit_tabs') ? $mtloggedin : $menuf; |
|
846 | - if (!empty($errorMsg)) { |
|
847 | - Display::display_normal_message($errorMsg); |
|
848 | - } |
|
849 | - $default = array(); |
|
850 | - $form = new FormValidator('configure_homepage_'.$action, 'post', api_get_self().'?action='.$action, '', array('style' => 'margin: 0px;')); |
|
851 | - $renderer =& $form->defaultRenderer(); |
|
852 | - |
|
853 | - $form->addElement('header', '', $tool_name); |
|
854 | - $form->addElement('hidden', 'formSent', '1'); |
|
855 | - $form->addElement('hidden', 'link_index', ($action == 'edit_link' || $action == 'edit_tabs') ? $link_index : '0'); |
|
856 | - $form->addElement('hidden', 'filename', ($action == 'edit_link' || $action == 'edit_tabs') ? (!empty($filename) ? $filename : '') : ''); |
|
857 | - |
|
858 | - $form->addElement('text', 'link_name', get_lang('LinkName'), array('size' => '30', 'maxlength' => '50')); |
|
859 | - if (!empty($link_name)) { |
|
860 | - $default['link_name'] = $link_name; |
|
861 | - } |
|
862 | - $default['link_url'] = empty($link_url) ? 'http://' : api_htmlentities($link_url, ENT_QUOTES); |
|
863 | - $linkUrlComment = ($action == 'insert_tabs') ? get_lang('Optional').'<br />'.get_lang('GlobalLinkUseDoubleColumnPrivateToShowPrivately') : ''; |
|
864 | - $form->addElement('text', 'link_url', array(get_lang('LinkURL'), $linkUrlComment), array('size' => '30', 'maxlength' => '100', 'style' => 'width: 350px;')); |
|
865 | - |
|
866 | - $options = array('-1' => get_lang('FirstPlace')); |
|
867 | - |
|
868 | - $selected = ''; |
|
869 | - |
|
870 | - if ($action == 'insert_link' || $action == 'insert_tabs') { |
|
871 | - $add_in_tab = 1; |
|
872 | - if (is_array($home_menu)){ |
|
873 | - foreach ($home_menu as $key => $enreg) { |
|
874 | - if (strlen($enreg = trim(strip_tags($enreg))) > 0) { |
|
875 | - $options[$key] = get_lang('After').' "'.$enreg.'"'; |
|
876 | - $formSentCheck = (!empty($_POST['formSent']) ? true : false); |
|
877 | - $selected = $formSentCheck && $insert_where == $key ? $key : ''; |
|
878 | - } |
|
879 | - } |
|
880 | - } |
|
881 | - $default['insert_link'] = $selected; |
|
882 | - $form->addElement('select', 'insert_where', get_lang('InsertThisLink') , $options); |
|
883 | - } |
|
884 | - |
|
885 | - $target_blank_checkbox = $form->addElement('checkbox', 'target_blank', null, get_lang('OpenInNewWindow'), 1); |
|
886 | - |
|
887 | - if ($action == 'insert_tabs' || $action == 'edit_tabs') { |
|
888 | - $form->addElement('checkbox', 'add_in_tab', null, get_lang('AddInMenu'), 1); |
|
889 | - $default['add_in_tab'] = $add_in_tab; |
|
890 | - } |
|
891 | - |
|
892 | - if (!empty($target_blank)) { $target_blank_checkbox->setChecked(true); } |
|
893 | - |
|
894 | - if ($action == 'edit_link' && (empty($link_url) || $link_url == 'http://' || $link_url == 'https://')) { |
|
895 | - $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : $link_html; |
|
896 | - $form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400')); |
|
840 | + break; |
|
841 | + case 'insert_tabs': |
|
842 | + case 'edit_tabs': |
|
843 | + case 'insert_link': |
|
844 | + case 'edit_link': |
|
845 | + $menuf = ($action == 'insert_tabs' || $action == 'edit_tabs') ? $mtloggedin : $menuf; |
|
846 | + if (!empty($errorMsg)) { |
|
847 | + Display::display_normal_message($errorMsg); |
|
848 | + } |
|
849 | + $default = array(); |
|
850 | + $form = new FormValidator('configure_homepage_'.$action, 'post', api_get_self().'?action='.$action, '', array('style' => 'margin: 0px;')); |
|
851 | + $renderer =& $form->defaultRenderer(); |
|
852 | + |
|
853 | + $form->addElement('header', '', $tool_name); |
|
854 | + $form->addElement('hidden', 'formSent', '1'); |
|
855 | + $form->addElement('hidden', 'link_index', ($action == 'edit_link' || $action == 'edit_tabs') ? $link_index : '0'); |
|
856 | + $form->addElement('hidden', 'filename', ($action == 'edit_link' || $action == 'edit_tabs') ? (!empty($filename) ? $filename : '') : ''); |
|
857 | + |
|
858 | + $form->addElement('text', 'link_name', get_lang('LinkName'), array('size' => '30', 'maxlength' => '50')); |
|
859 | + if (!empty($link_name)) { |
|
860 | + $default['link_name'] = $link_name; |
|
861 | + } |
|
862 | + $default['link_url'] = empty($link_url) ? 'http://' : api_htmlentities($link_url, ENT_QUOTES); |
|
863 | + $linkUrlComment = ($action == 'insert_tabs') ? get_lang('Optional').'<br />'.get_lang('GlobalLinkUseDoubleColumnPrivateToShowPrivately') : ''; |
|
864 | + $form->addElement('text', 'link_url', array(get_lang('LinkURL'), $linkUrlComment), array('size' => '30', 'maxlength' => '100', 'style' => 'width: 350px;')); |
|
865 | + |
|
866 | + $options = array('-1' => get_lang('FirstPlace')); |
|
867 | + |
|
868 | + $selected = ''; |
|
869 | + |
|
870 | + if ($action == 'insert_link' || $action == 'insert_tabs') { |
|
871 | + $add_in_tab = 1; |
|
872 | + if (is_array($home_menu)){ |
|
873 | + foreach ($home_menu as $key => $enreg) { |
|
874 | + if (strlen($enreg = trim(strip_tags($enreg))) > 0) { |
|
875 | + $options[$key] = get_lang('After').' "'.$enreg.'"'; |
|
876 | + $formSentCheck = (!empty($_POST['formSent']) ? true : false); |
|
877 | + $selected = $formSentCheck && $insert_where == $key ? $key : ''; |
|
878 | + } |
|
879 | + } |
|
880 | + } |
|
881 | + $default['insert_link'] = $selected; |
|
882 | + $form->addElement('select', 'insert_where', get_lang('InsertThisLink') , $options); |
|
883 | + } |
|
884 | + |
|
885 | + $target_blank_checkbox = $form->addElement('checkbox', 'target_blank', null, get_lang('OpenInNewWindow'), 1); |
|
886 | + |
|
887 | + if ($action == 'insert_tabs' || $action == 'edit_tabs') { |
|
888 | + $form->addElement('checkbox', 'add_in_tab', null, get_lang('AddInMenu'), 1); |
|
889 | + $default['add_in_tab'] = $add_in_tab; |
|
890 | + } |
|
891 | + |
|
892 | + if (!empty($target_blank)) { $target_blank_checkbox->setChecked(true); } |
|
893 | + |
|
894 | + if ($action == 'edit_link' && (empty($link_url) || $link_url == 'http://' || $link_url == 'https://')) { |
|
895 | + $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : $link_html; |
|
896 | + $form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400')); |
|
897 | 897 | $form->addButtonSave(get_lang('Save'),'submit'); |
898 | 898 | |
899 | - } else { |
|
900 | - if (in_array($action, array('edit_tabs','insert_tabs'))) { |
|
901 | - $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : (!empty($link_html) ? $link_html : ''); |
|
902 | - $form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400')); |
|
903 | - } |
|
904 | - $form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'), array('id' => 'all_langs')); |
|
905 | - $form->addElement('html','<table id="table_langs" style="margin-left:159px;"><tr>'); |
|
906 | - $i = 0; |
|
907 | - foreach ($_languages['name'] as $key => $value) { |
|
908 | - $i++; |
|
909 | - $lang_name = $_languages['folder'][$key]; |
|
910 | - $html_langs = '<td width="300">'; |
|
911 | - $html_langs .= '<label><input type="checkbox" id="lang" name="'.$lang_name.'" /> '.$lang_name.'<label/>'; |
|
912 | - $html_langs .= '</td>'; |
|
913 | - if ($i % 5 == 0) { |
|
914 | - $html_langs .= '</tr><tr>'; |
|
915 | - } |
|
916 | - $form->addElement('html', $html_langs); |
|
917 | - } |
|
918 | - $form->addElement('html','</tr></table><br/>'); |
|
899 | + } else { |
|
900 | + if (in_array($action, array('edit_tabs','insert_tabs'))) { |
|
901 | + $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : (!empty($link_html) ? $link_html : ''); |
|
902 | + $form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400')); |
|
903 | + } |
|
904 | + $form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'), array('id' => 'all_langs')); |
|
905 | + $form->addElement('html','<table id="table_langs" style="margin-left:159px;"><tr>'); |
|
906 | + $i = 0; |
|
907 | + foreach ($_languages['name'] as $key => $value) { |
|
908 | + $i++; |
|
909 | + $lang_name = $_languages['folder'][$key]; |
|
910 | + $html_langs = '<td width="300">'; |
|
911 | + $html_langs .= '<label><input type="checkbox" id="lang" name="'.$lang_name.'" /> '.$lang_name.'<label/>'; |
|
912 | + $html_langs .= '</td>'; |
|
913 | + if ($i % 5 == 0) { |
|
914 | + $html_langs .= '</tr><tr>'; |
|
915 | + } |
|
916 | + $form->addElement('html', $html_langs); |
|
917 | + } |
|
918 | + $form->addElement('html','</tr></table><br/>'); |
|
919 | 919 | $form->addButtonSave(get_lang('Save'),'submit'); |
920 | - } |
|
921 | - |
|
922 | - $form->setDefaults($default); |
|
923 | - $form->display(); |
|
924 | - |
|
925 | - break; |
|
926 | - case 'edit_top': |
|
927 | - case 'edit_news': |
|
928 | - if ($action == 'edit_top') { |
|
929 | - $name = $topf; |
|
930 | - $open = $home_top; |
|
931 | - } else { |
|
932 | - $name = $newsf; |
|
933 | - $open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext); |
|
934 | - } |
|
935 | - $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); |
|
936 | - |
|
937 | - if (!empty($errorMsg)) { |
|
938 | - Display::display_normal_message($errorMsg); //main API |
|
939 | - } |
|
940 | - |
|
941 | - $default = array(); |
|
942 | - $form = new FormValidator( |
|
943 | - 'configure_homepage_'.$action, |
|
944 | - 'post', |
|
945 | - api_get_self().'?action='.$action, |
|
946 | - '', |
|
947 | - array('style' => 'margin: 0px;') |
|
948 | - ); |
|
949 | - $renderer =& $form->defaultRenderer(); |
|
950 | - $renderer->setHeaderTemplate(''); |
|
951 | - $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>'); |
|
952 | - $renderer->setCustomElementTemplate('<tr><td>{element}</td></tr>'); |
|
953 | - $renderer->setRequiredNoteTemplate(''); |
|
954 | - $form->addElement('hidden', 'formSent', '1'); |
|
955 | - |
|
956 | - if ($action == 'edit_news') { |
|
957 | - $_languages = api_get_languages(); |
|
958 | - $html = '<tr><td>'.get_lang('ChooseNewsLanguage').' : '; |
|
959 | - $html .= '<select name="news_languages">'; |
|
960 | - $html .= '<option value="all">'.get_lang('ApplyAllLanguages').'</option>'; |
|
961 | - foreach ($_languages['name'] as $key => $value) { |
|
962 | - $english_name = $_languages['folder'][$key]; |
|
963 | - if ($language == $english_name) { |
|
964 | - $html .= '<option value="'.$english_name.'" selected="selected">'.$value.'</option>'; |
|
965 | - } else { |
|
966 | - $html .= '<option value="'.$english_name.'">'.$value.'</option>'; |
|
967 | - } |
|
968 | - } |
|
969 | - $html .= '</select></td></tr>'; |
|
970 | - $form->addElement('html', $html); |
|
971 | - } |
|
972 | - |
|
973 | - $default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open); |
|
974 | - $form->addHtmlEditor($name, '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400')); |
|
975 | - $form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'),array('id' => 'all_langs')); |
|
976 | - $form->addElement('html','<table id="table_langs" style="margin-left:5px;"><tr>'); |
|
977 | - |
|
978 | - $currentLanguage = api_get_interface_language(); |
|
979 | - $i = 0; |
|
980 | - foreach ($_languages['name'] as $key => $value) { |
|
981 | - $lang_name = $_languages['folder'][$key]; |
|
982 | - $i++; |
|
983 | - |
|
984 | - $checked = null; |
|
985 | - if ($languageGet == $lang_name) { |
|
986 | - $checked = "checked"; |
|
987 | - } |
|
988 | - $html_langs = '<td width="300">'; |
|
989 | - $html_langs .= '<label><input type="checkbox" '.$checked.' id="lang" name="'.$lang_name.'" /> '.$value.'<label/>'; |
|
990 | - $html_langs .= '</td>'; |
|
991 | - if ($i % 5 == 0) { |
|
992 | - $html_langs .= '</tr><tr>'; |
|
993 | - } |
|
994 | - $form->addElement('html', $html_langs); |
|
995 | - } |
|
996 | - $form->addElement('html','</tr></table><br/>'); |
|
997 | - $form->addButtonSave(get_lang('Save')); |
|
998 | - $form->setDefaults($default); |
|
999 | - $form->display(); |
|
1000 | - |
|
1001 | - break; |
|
1002 | - default: // When no action applies, default page to update campus homepage |
|
1003 | - ?> |
|
920 | + } |
|
921 | + |
|
922 | + $form->setDefaults($default); |
|
923 | + $form->display(); |
|
924 | + |
|
925 | + break; |
|
926 | + case 'edit_top': |
|
927 | + case 'edit_news': |
|
928 | + if ($action == 'edit_top') { |
|
929 | + $name = $topf; |
|
930 | + $open = $home_top; |
|
931 | + } else { |
|
932 | + $name = $newsf; |
|
933 | + $open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext); |
|
934 | + } |
|
935 | + $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); |
|
936 | + |
|
937 | + if (!empty($errorMsg)) { |
|
938 | + Display::display_normal_message($errorMsg); //main API |
|
939 | + } |
|
940 | + |
|
941 | + $default = array(); |
|
942 | + $form = new FormValidator( |
|
943 | + 'configure_homepage_'.$action, |
|
944 | + 'post', |
|
945 | + api_get_self().'?action='.$action, |
|
946 | + '', |
|
947 | + array('style' => 'margin: 0px;') |
|
948 | + ); |
|
949 | + $renderer =& $form->defaultRenderer(); |
|
950 | + $renderer->setHeaderTemplate(''); |
|
951 | + $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>'); |
|
952 | + $renderer->setCustomElementTemplate('<tr><td>{element}</td></tr>'); |
|
953 | + $renderer->setRequiredNoteTemplate(''); |
|
954 | + $form->addElement('hidden', 'formSent', '1'); |
|
955 | + |
|
956 | + if ($action == 'edit_news') { |
|
957 | + $_languages = api_get_languages(); |
|
958 | + $html = '<tr><td>'.get_lang('ChooseNewsLanguage').' : '; |
|
959 | + $html .= '<select name="news_languages">'; |
|
960 | + $html .= '<option value="all">'.get_lang('ApplyAllLanguages').'</option>'; |
|
961 | + foreach ($_languages['name'] as $key => $value) { |
|
962 | + $english_name = $_languages['folder'][$key]; |
|
963 | + if ($language == $english_name) { |
|
964 | + $html .= '<option value="'.$english_name.'" selected="selected">'.$value.'</option>'; |
|
965 | + } else { |
|
966 | + $html .= '<option value="'.$english_name.'">'.$value.'</option>'; |
|
967 | + } |
|
968 | + } |
|
969 | + $html .= '</select></td></tr>'; |
|
970 | + $form->addElement('html', $html); |
|
971 | + } |
|
972 | + |
|
973 | + $default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open); |
|
974 | + $form->addHtmlEditor($name, '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400')); |
|
975 | + $form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'),array('id' => 'all_langs')); |
|
976 | + $form->addElement('html','<table id="table_langs" style="margin-left:5px;"><tr>'); |
|
977 | + |
|
978 | + $currentLanguage = api_get_interface_language(); |
|
979 | + $i = 0; |
|
980 | + foreach ($_languages['name'] as $key => $value) { |
|
981 | + $lang_name = $_languages['folder'][$key]; |
|
982 | + $i++; |
|
983 | + |
|
984 | + $checked = null; |
|
985 | + if ($languageGet == $lang_name) { |
|
986 | + $checked = "checked"; |
|
987 | + } |
|
988 | + $html_langs = '<td width="300">'; |
|
989 | + $html_langs .= '<label><input type="checkbox" '.$checked.' id="lang" name="'.$lang_name.'" /> '.$value.'<label/>'; |
|
990 | + $html_langs .= '</td>'; |
|
991 | + if ($i % 5 == 0) { |
|
992 | + $html_langs .= '</tr><tr>'; |
|
993 | + } |
|
994 | + $form->addElement('html', $html_langs); |
|
995 | + } |
|
996 | + $form->addElement('html','</tr></table><br/>'); |
|
997 | + $form->addButtonSave(get_lang('Save')); |
|
998 | + $form->setDefaults($default); |
|
999 | + $form->display(); |
|
1000 | + |
|
1001 | + break; |
|
1002 | + default: // When no action applies, default page to update campus homepage |
|
1003 | + ?> |
|
1004 | 1004 | |
1005 | 1005 | <section id="page-home"> |
1006 | 1006 | <div class="row"> |
@@ -1158,53 +1158,53 @@ discard block |
||
1158 | 1158 | ?> |
1159 | 1159 | |
1160 | 1160 | <?php |
1161 | - if (file_exists($homep.$newsf.'_'.$lang.$ext)) { |
|
1161 | + if (file_exists($homep.$newsf.'_'.$lang.$ext)) { |
|
1162 | 1162 | $open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext); |
1163 | 1163 | $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); |
1164 | 1164 | echo $open; |
1165 | - } else { |
|
1165 | + } else { |
|
1166 | 1166 | $open = @(string)file_get_contents($homep.$newsf.$ext); |
1167 | 1167 | $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); |
1168 | 1168 | echo $open; |
1169 | - } |
|
1169 | + } |
|
1170 | 1170 | ?> |
1171 | 1171 | |
1172 | 1172 | <?php |
1173 | 1173 | // Add new page |
1174 | - $home_menu = ''; |
|
1175 | - if (file_exists($homep.$mtloggedin.'_'.$lang.$ext)) { |
|
1174 | + $home_menu = ''; |
|
1175 | + if (file_exists($homep.$mtloggedin.'_'.$lang.$ext)) { |
|
1176 | 1176 | $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext); |
1177 | - } else { |
|
1177 | + } else { |
|
1178 | 1178 | $home_menu = @file($homep.$mtloggedin.$ext); |
1179 | - } |
|
1180 | - if (empty($home_menu)) { |
|
1179 | + } |
|
1180 | + if (empty($home_menu)) { |
|
1181 | 1181 | if (file_exists($homep.$menutabs.'_'.$lang.$ext)) { |
1182 | - $home_menu = @file($homep.$menutabs.'_'.$lang.$ext); |
|
1182 | + $home_menu = @file($homep.$menutabs.'_'.$lang.$ext); |
|
1183 | 1183 | } |
1184 | - } |
|
1185 | - if (empty($home_menu)) { |
|
1184 | + } |
|
1185 | + if (empty($home_menu)) { |
|
1186 | 1186 | $home_menu = array(); |
1187 | - } |
|
1188 | - if (!empty($home_menu)) { |
|
1187 | + } |
|
1188 | + if (!empty($home_menu)) { |
|
1189 | 1189 | $home_menu = implode("\n", $home_menu); |
1190 | 1190 | $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
1191 | 1191 | $home_menu = explode("\n", $home_menu); |
1192 | - } |
|
1193 | - $link_list = ''; |
|
1194 | - $tab_counter = 0; |
|
1192 | + } |
|
1193 | + $link_list = ''; |
|
1194 | + $tab_counter = 0; |
|
1195 | 1195 | foreach ($home_menu as $enreg) { |
1196 | 1196 | $enreg = trim($enreg); |
1197 | - if (!empty($enreg)) { |
|
1197 | + if (!empty($enreg)) { |
|
1198 | 1198 | $edit_link = ' <a href="'.api_get_self().'?action=edit_tabs&link_index='.$tab_counter.'" ><span>'.Display::return_icon('edit.gif', get_lang('Edit')).'</span></a>'; |
1199 | 1199 | $delete_link = ' <a href="'.api_get_self().'?action=delete_tabs&link_index='.$tab_counter.'" onclick="javascript: if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)).'\')) return false;"><span>'.Display::return_icon('delete.gif', get_lang('Delete')).'</span></a>'; |
1200 | 1200 | $tab_string = str_replace(array('href="'.api_get_path(WEB_PATH).'index.php?include=', '</li>'), |
1201 | 1201 | array('href="'.api_get_path(WEB_CODE_PATH).'admin/'.basename(api_get_self()).'?action=open_link&link=', $edit_link.$delete_link.'</li>'), |
1202 | - $enreg); |
|
1202 | + $enreg); |
|
1203 | 1203 | $tab_string = str_replace(array('<li>', '</li>','class="hide_menu"', 'hide_menu'), '', $tab_string); |
1204 | - $link_list .= Display::tag('li', $tab_string, array('class' => 'list-group-item')); |
|
1205 | - $tab_counter++; |
|
1206 | - } |
|
1207 | - } |
|
1204 | + $link_list .= Display::tag('li', $tab_string, array('class' => 'list-group-item')); |
|
1205 | + $tab_counter++; |
|
1206 | + } |
|
1207 | + } |
|
1208 | 1208 | ?> |
1209 | 1209 | <div class="actions"> |
1210 | 1210 | <a href="<?php echo api_get_self(); ?>?action=insert_tabs"> |
@@ -1212,9 +1212,9 @@ discard block |
||
1212 | 1212 | </a> |
1213 | 1213 | </div> |
1214 | 1214 | <?php |
1215 | - echo '<ul id="list-hiperlink" class="list-group">'; |
|
1216 | - echo $link_list; |
|
1217 | - echo '</ul>'; |
|
1215 | + echo '<ul id="list-hiperlink" class="list-group">'; |
|
1216 | + echo $link_list; |
|
1217 | + echo '</ul>'; |
|
1218 | 1218 | ?> |
1219 | 1219 | </div> |
1220 | 1220 | </div> |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | array('name'=>'name', 'index'=>'name', 'width'=>'80', 'align'=>'left'), |
81 | 81 | array('name'=>'description', 'index'=>'description', 'width'=>'500', 'align'=>'left','sortable'=>'false'), |
82 | 82 | array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false') |
83 | - ); |
|
83 | + ); |
|
84 | 84 | //Autowidth |
85 | 85 | $extra_params['autowidth'] = 'true'; |
86 | 86 | //height auto |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | //With this function we can add actions to the jgrid (edit, delete, etc) |
90 | 90 | $action_links = 'function action_formatter(cellvalue, options, rowObject) { |
91 | 91 | return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'. |
92 | - ' <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'. |
|
93 | - '\'; |
|
92 | + ' <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'. |
|
93 | + '\'; |
|
94 | 94 | }'; |
95 | 95 | ?> |
96 | 96 | <script> |
@@ -87,7 +87,7 @@ |
||
87 | 87 | <?php |
88 | 88 | echo Display::get_alphabet_options($firstLetterUserGroup); |
89 | 89 | echo Display::get_numeric_options(0, 9, $firstLetterUserGroup); |
90 | - ?> |
|
90 | + ?> |
|
91 | 91 | </select> |
92 | 92 | </td> |
93 | 93 | <td width="20%"> </td> |