@@ -10,521 +10,521 @@ |
||
10 | 10 | */ |
11 | 11 | class WSCMCourse extends WSCM |
12 | 12 | { |
13 | - /** |
|
14 | - * Deletes a course (helper method) |
|
15 | - * |
|
16 | - * @param string Course id field name |
|
17 | - * @param string Course id value |
|
18 | - * @return mixed True if the course was successfully deleted, WSError otherwise |
|
19 | - */ |
|
20 | - protected function deleteCourseHelper($course_id_field_name, $course_id_value) { |
|
21 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
22 | - if($course_id instanceof WSCMError) { |
|
23 | - return $course_id; |
|
24 | - } else { |
|
25 | - $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
26 | - CourseManager::delete_course($course_code); |
|
27 | - return true; |
|
28 | - } |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * Deletes a course |
|
33 | - * |
|
34 | - * @param string API secret key |
|
35 | - * @param string Course id field name |
|
36 | - * @param string Course id value |
|
37 | - */ |
|
38 | - public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) { |
|
39 | - $verifKey = $this->verifyKey($secret_key); |
|
40 | - if($verifKey instanceof WSError) { |
|
41 | - $this->handleError($verifKey); |
|
42 | - } else { |
|
43 | - $result = $this->deleteCourseHelper($course_id_field_name, $course_id_value); |
|
44 | - if($result instanceof WSError) { |
|
45 | - $this->handleError($result); |
|
46 | - } |
|
47 | - } |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Deletes multiple courses |
|
52 | - * |
|
53 | - * @param string API secret key |
|
54 | - * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value') |
|
55 | - * @return array Array with elements like array('course_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). Note that if the result array contains a code different |
|
56 | - * than 0, an error occured |
|
57 | - */ |
|
58 | - public function DeleteCourses($secret_key, $courses) { |
|
59 | - $verifKey = $this->verifyKey($secret_key); |
|
60 | - if($verifKey instanceof WSError) { |
|
61 | - $this->handleError($verifKey); |
|
62 | - } else { |
|
63 | - $results = array(); |
|
64 | - foreach($courses as $course) { |
|
65 | - $result_tmp = array(); |
|
66 | - $result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']); |
|
67 | - $result_tmp['course_id_value'] = $course['course_id_value']; |
|
68 | - if($result_op instanceof WSCMError) { |
|
69 | - // Return the error in the results |
|
70 | - $result_tmp['result'] = $result_op->toArray(); |
|
71 | - } else { |
|
72 | - $result_tmp['result'] = $this->getSuccessfulResult(); |
|
73 | - } |
|
74 | - $results[] = $result_tmp; |
|
75 | - } |
|
76 | - return $results; |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Creates a course (helper method) |
|
82 | - * |
|
83 | - * @param string Title |
|
84 | - * @param string Category code |
|
85 | - * @param string Wanted code. If it's not defined, it will be generated automatically |
|
86 | - * @param string Tutor name |
|
87 | - * @param string Course admin user id field name |
|
88 | - * @param string Course admin user id value |
|
89 | - * @param string Course language |
|
90 | - * @param string Course id field name |
|
91 | - * @param string Course id value |
|
92 | - * @param array Course extra fields |
|
93 | - * @return mixed Generated id if creation was successful, WSError otherwise |
|
94 | - */ |
|
95 | - protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
|
96 | - // Add the original course id field name and value to the extra fields if needed |
|
97 | - $extras_associative = array(); |
|
98 | - if($course_id_field_name != "chamilo_course_id") { |
|
99 | - $extras_associative[$course_id_field_name] = $course_id_value; |
|
100 | - } |
|
101 | - foreach($extras as $extra) { |
|
102 | - $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
103 | - } |
|
104 | - $course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value); |
|
105 | - if($course_admin_id instanceof WSError) { |
|
106 | - return $course_admin_id; |
|
107 | - } |
|
108 | - if($wanted_code == '') { |
|
109 | - $wanted_code = CourseManager::generate_course_code($title); |
|
110 | - } |
|
111 | - $result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0); |
|
112 | - if (!$result) { |
|
113 | - return new WSError(202, 'There was an error creating the course'); |
|
114 | - } else { |
|
115 | - // Update extra fields |
|
116 | - foreach($extras_associative as $fname => $fvalue) { |
|
117 | - CourseManager::update_course_extra_field_value($result, $fname, $fvalue); |
|
118 | - } |
|
119 | - // Get course id |
|
120 | - $course_info = CourseManager::get_course_information($result); |
|
121 | - return $course_info['real_id']; |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Creates a course |
|
127 | - * |
|
128 | - * @param string API secret key |
|
129 | - * @param string Title |
|
130 | - * @param string Category code |
|
131 | - * @param string Wanted code. If it's not defined, it will be generated automatically |
|
132 | - * @param string Tutor name |
|
133 | - * @param string Course admin user id field name |
|
134 | - * @param string Course admin user id value |
|
135 | - * @param string Course language |
|
136 | - * @param string Course id field name |
|
137 | - * @param string Course id value |
|
138 | - * @param array Course extra fields |
|
139 | - * @return int Course id generated |
|
140 | - */ |
|
141 | - public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
|
142 | - // First, verify the secret key |
|
143 | - $verifKey = $this->verifyKey($secret_key); |
|
144 | - if($verifKey instanceof WSError) { |
|
145 | - $this->handleError($verifKey); |
|
146 | - } else { |
|
147 | - $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
|
148 | - if($result instanceof WSError) { |
|
149 | - $this->handleError($result); |
|
150 | - } else { |
|
151 | - return $result; |
|
152 | - } |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Create multiple courses |
|
158 | - * |
|
159 | - * @param string API secret key |
|
160 | - * @param array Courses to be created, with elements following the structure presented in CreateCourse |
|
161 | - * @return array Array with elements of the form array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful')) |
|
162 | - */ |
|
163 | - public function CreateCourses($secret_key, $courses) { |
|
164 | - // First, verify the secret key |
|
165 | - $verifKey = $this->verifyKey($secret_key); |
|
166 | - if($verifKey instanceof WSCMError) { |
|
167 | - $this->handleError($verifKey); |
|
168 | - } else { |
|
169 | - $results = array(); |
|
170 | - foreach($courses as $course) { |
|
171 | - $result_tmp = array(); |
|
172 | - //reinitialize variables just in case |
|
173 | - $title = $category_code = $wanted_code = $tutor_name = $course_admin_user_id_field_name = $course_admin_user_id_value = $language = $course_id_field_name = $course_id_value = $extras = null; |
|
174 | - extract($course); |
|
175 | - $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
|
176 | - if($result instanceof WSCMError) { |
|
177 | - $result_tmp['result'] = $result->toArray(); |
|
178 | - $result_tmp['course_id_value'] = $course_id_value; |
|
179 | - $result_tmp['course_id_generated'] = 0; |
|
180 | - } else { |
|
181 | - $result_tmp['result'] = $this->getSuccessfulResult(); |
|
182 | - $result_tmp['course_id_value'] = $course_id_value; |
|
183 | - $result_tmp['course_id_generated'] = $result; |
|
184 | - } |
|
185 | - $results[] = $result_tmp; |
|
186 | - } |
|
187 | - return $results; |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Edits a course (helper method) |
|
193 | - * |
|
194 | - * @param string Course id field name |
|
195 | - * @param string Course id value |
|
196 | - * @param string Title |
|
197 | - * @param string Category code |
|
198 | - * @param string Department name |
|
199 | - * @param string Department url |
|
200 | - * @param string Course language |
|
201 | - * @param int Visibility |
|
202 | - * @param int Subscribe (0 = denied, 1 = allowed) |
|
203 | - * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
204 | - * @param string Visual code |
|
205 | - * @param array Course extra fields |
|
206 | - * @return mixed True in case of success, WSError otherwise |
|
207 | - */ |
|
208 | - protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
209 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
210 | - if($course_id instanceof WSCMError) { |
|
211 | - return $course_id; |
|
212 | - } else { |
|
213 | - $attributes = array(); |
|
214 | - if(!empty($title)) { |
|
215 | - $attributes['title'] = $title; |
|
216 | - } |
|
217 | - if(!empty($category_code)) { |
|
218 | - $attributes['category_code'] = $category_code; |
|
219 | - } |
|
220 | - if(!empty($department_name)) { |
|
221 | - $attributes['department_name'] = $department_name; |
|
222 | - } |
|
223 | - if(!empty($department_url)) { |
|
224 | - $attributes['department_url'] = $department_url; |
|
225 | - } |
|
226 | - if(!empty($language)) { |
|
227 | - $attributes['course_language'] = $language; |
|
228 | - } |
|
229 | - if($visibility != '') { |
|
230 | - $attributes['visibility'] = (int)$visibility; |
|
231 | - } |
|
232 | - if($subscribe != '') { |
|
233 | - $attributes['subscribe'] = (int)$subscribe; |
|
234 | - } |
|
235 | - if($unsubscribe != '') { |
|
236 | - $attributes['unsubscribe'] = (int)$unsubscribe; |
|
237 | - } |
|
238 | - if(!empty($visual_code)) { |
|
239 | - $attributes['visual_code'] = $visual_code; |
|
240 | - } |
|
241 | - if(!empty($attributes)) { |
|
242 | - CourseManager::update_attributes($course_id, $attributes); |
|
243 | - } |
|
244 | - if(!empty($extras)) { |
|
245 | - $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
246 | - $extras_associative = array(); |
|
247 | - foreach($extras as $extra) { |
|
248 | - $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
249 | - } |
|
250 | - foreach($extras_associative as $fname => $fvalue) { |
|
251 | - CourseManager::update_extra_field_value($course_code, $fname, $fvalue); |
|
252 | - } |
|
253 | - } |
|
254 | - return true; |
|
255 | - } |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Edits a course |
|
260 | - * |
|
261 | - * @param string API secret key |
|
262 | - * @param string Course id field name |
|
263 | - * @param string Course id value |
|
264 | - * @param string Title |
|
265 | - * @param string Category code |
|
266 | - * @param string Department name |
|
267 | - * @param string Department url |
|
268 | - * @param string Course language |
|
269 | - * @param int Visibility |
|
270 | - * @param int Subscribe (0 = denied, 1 = allowed) |
|
271 | - * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
272 | - * @param string Visual code |
|
273 | - * @param array Course extra fields |
|
274 | - */ |
|
275 | - public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
276 | - $verifKey = $this->verifyKey($secret_key); |
|
277 | - if($verifKey instanceof WSCMError) { |
|
278 | - $this->handleError($verifKey); |
|
279 | - } else { |
|
280 | - $result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras); |
|
281 | - if($result instanceof WSCMError) { |
|
282 | - $this->handleError($result); |
|
283 | - } |
|
284 | - } |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * List courses |
|
289 | - * |
|
290 | - * @param string API secret key |
|
291 | - * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
292 | - * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility', |
|
293 | - * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id') |
|
294 | - */ |
|
295 | - public function ListCourses($secret_key, $course_id_field_name) { |
|
296 | - $verifKey = $this->verifyKey($secret_key); |
|
297 | - if($verifKey instanceof WSError) { |
|
298 | - $this->handleError($verifKey); |
|
299 | - } else { |
|
300 | - $courses_result = array(); |
|
301 | - $category_names = array(); |
|
302 | - |
|
303 | - $courses = CourseManager::get_courses_list(); |
|
304 | - foreach($courses as $course) { |
|
305 | - $course_tmp = array(); |
|
306 | - $course_tmp['id'] = $course['id']; |
|
307 | - $course_tmp['code'] = $course['code']; |
|
308 | - $course_tmp['title'] = $course['title']; |
|
309 | - $course_tmp['language'] = $course['course_language']; |
|
310 | - $course_tmp['visibility'] = $course['visibility']; |
|
311 | - |
|
312 | - // Determining category name |
|
313 | - if($category_names[$course['category_code']]) { |
|
314 | - $course_tmp['category_name'] = $category_names[$course['category_code']]; |
|
315 | - } else { |
|
316 | - $category = CourseManager::get_course_category($course['category_code']); |
|
317 | - $category_names[$course['category_code']] = $category['name']; |
|
318 | - $course_tmp['category_name'] = $category['name']; |
|
319 | - } |
|
320 | - |
|
321 | - // Determining number of students registered in course |
|
322 | - $user_list = CourseManager::get_user_list_from_course_code($course['code']); |
|
323 | - $course_tmp['number_students'] = count($user_list); |
|
324 | - |
|
325 | - // Determining external course id |
|
326 | - $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_id_field_name, $course['code']); |
|
327 | - |
|
328 | - |
|
329 | - $courses_result[] = $course_tmp; |
|
330 | - } |
|
331 | - |
|
332 | - return $courses_result; |
|
333 | - } |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * Subscribe or unsubscribe user to a course (helper method) |
|
338 | - * |
|
339 | - * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
340 | - * @param string Course id value. |
|
341 | - * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
342 | - * @param string User id value |
|
343 | - * @param int Set to 1 to subscribe, 0 to unsubscribe |
|
344 | - * @param int Status (STUDENT or TEACHER) Used for subscription only |
|
345 | - * @return mixed True if subscription or unsubscription was successful, false otherwise |
|
346 | - */ |
|
347 | - protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) { |
|
348 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
349 | - if($course_id instanceof WSError) { |
|
350 | - return $course_id; |
|
351 | - } else { |
|
352 | - $user_id = $this->getUserId($user_id_field_name, $user_id_value); |
|
353 | - if($user_id instanceof WSError) { |
|
354 | - return $user_id; |
|
355 | - } else { |
|
356 | - $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
357 | - if($state == 0) { |
|
358 | - // Unsubscribe user |
|
359 | - CourseManager::unsubscribe_user($user_id, $course_code); |
|
360 | - return true; |
|
361 | - } else { |
|
362 | - // Subscribe user |
|
363 | - if(CourseManager::subscribe_user($user_id, $course_code, $status)) { |
|
364 | - return true; |
|
365 | - } else { |
|
366 | - return new WSError(203, 'An error occured subscribing to this course'); |
|
367 | - } |
|
368 | - } |
|
369 | - } |
|
370 | - } |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * Subscribe user to a course |
|
375 | - * |
|
376 | - * @param string API secret key |
|
377 | - * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
378 | - * @param string Course id value. |
|
379 | - * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
380 | - * @param string User id value |
|
381 | - * @param int Status (1 = Teacher, 5 = Student) |
|
382 | - */ |
|
383 | - public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) { |
|
384 | - $verifKey = $this->verifyKey($secret_key); |
|
385 | - if($verifKey instanceof WSError) { |
|
386 | - $this->handleError($verifKey); |
|
387 | - } else { |
|
388 | - $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status); |
|
389 | - if($result instanceof WSError) { |
|
390 | - $this->handleError($result); |
|
391 | - } |
|
392 | - } |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Unsusbscribe user from course |
|
397 | - * |
|
398 | - * @param string API secret key |
|
399 | - * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
400 | - * @param string Course id value. |
|
401 | - * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
402 | - * @param string User id value |
|
403 | - */ |
|
404 | - public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) { |
|
405 | - $verifKey = $this->verifyKey($secret_key); |
|
406 | - if($verifKey instanceof WSError) { |
|
407 | - $this->handleError($verifKey); |
|
408 | - } else { |
|
409 | - $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0); |
|
410 | - if($result instanceof WSError) { |
|
411 | - $this->handleError($result); |
|
412 | - } |
|
413 | - } |
|
414 | - } |
|
415 | - |
|
416 | - /** |
|
417 | - * Returns the descriptions of a course, along with their id |
|
418 | - * |
|
419 | - * @param string API secret key |
|
420 | - * @param string Course id field name |
|
421 | - * @param string Course id value |
|
422 | - * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content') |
|
423 | - */ |
|
424 | - public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) { |
|
425 | - $verifKey = $this->verifyKey($secret_key); |
|
426 | - if($verifKey instanceof WSError) { |
|
427 | - $this->handleError($verifKey); |
|
428 | - } else { |
|
429 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
430 | - if($course_id instanceof WSError) { |
|
431 | - return $course_id; |
|
432 | - } else { |
|
433 | - // Course exists, get its descriptions |
|
434 | - $descriptions = CourseDescription::get_descriptions($course_id); |
|
435 | - $results = array(); |
|
436 | - foreach($descriptions as $description) { |
|
437 | - $results[] = array('course_desc_id' => $description->get_description_type(), |
|
438 | - 'course_desc_title' => $description->get_title(), |
|
439 | - 'course_desc_content' => $description->get_content()); |
|
440 | - } |
|
441 | - return $results; |
|
442 | - } |
|
443 | - } |
|
444 | - } |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * Edit course description |
|
449 | - * |
|
450 | - * @param string API secret key |
|
451 | - * @param string Course id field name |
|
452 | - * @param string Course id value |
|
453 | - * @param int Category id from course description |
|
454 | - * @param string Description title |
|
455 | - * @param string Course description content |
|
456 | - */ |
|
457 | - public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) { |
|
458 | - $verifKey = $this->verifyKey($secret_key); |
|
459 | - if($verifKey instanceof WSError) { |
|
460 | - $this->handleError($verifKey); |
|
461 | - } else { |
|
462 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
463 | - if($course_id instanceof WSError) { |
|
464 | - return $course_id; |
|
465 | - } else { |
|
466 | - // Create the new course description |
|
467 | - $cd = new CourseDescription(); |
|
468 | - $cd->set_description_type($course_desc_id); |
|
469 | - $cd->set_title($course_desc_title); |
|
470 | - $cd->set_content($course_desc_content); |
|
471 | - $cd->set_session_id(0); |
|
472 | - |
|
473 | - // Get course info |
|
13 | + /** |
|
14 | + * Deletes a course (helper method) |
|
15 | + * |
|
16 | + * @param string Course id field name |
|
17 | + * @param string Course id value |
|
18 | + * @return mixed True if the course was successfully deleted, WSError otherwise |
|
19 | + */ |
|
20 | + protected function deleteCourseHelper($course_id_field_name, $course_id_value) { |
|
21 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
22 | + if($course_id instanceof WSCMError) { |
|
23 | + return $course_id; |
|
24 | + } else { |
|
25 | + $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
26 | + CourseManager::delete_course($course_code); |
|
27 | + return true; |
|
28 | + } |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * Deletes a course |
|
33 | + * |
|
34 | + * @param string API secret key |
|
35 | + * @param string Course id field name |
|
36 | + * @param string Course id value |
|
37 | + */ |
|
38 | + public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) { |
|
39 | + $verifKey = $this->verifyKey($secret_key); |
|
40 | + if($verifKey instanceof WSError) { |
|
41 | + $this->handleError($verifKey); |
|
42 | + } else { |
|
43 | + $result = $this->deleteCourseHelper($course_id_field_name, $course_id_value); |
|
44 | + if($result instanceof WSError) { |
|
45 | + $this->handleError($result); |
|
46 | + } |
|
47 | + } |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Deletes multiple courses |
|
52 | + * |
|
53 | + * @param string API secret key |
|
54 | + * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value') |
|
55 | + * @return array Array with elements like array('course_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). Note that if the result array contains a code different |
|
56 | + * than 0, an error occured |
|
57 | + */ |
|
58 | + public function DeleteCourses($secret_key, $courses) { |
|
59 | + $verifKey = $this->verifyKey($secret_key); |
|
60 | + if($verifKey instanceof WSError) { |
|
61 | + $this->handleError($verifKey); |
|
62 | + } else { |
|
63 | + $results = array(); |
|
64 | + foreach($courses as $course) { |
|
65 | + $result_tmp = array(); |
|
66 | + $result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']); |
|
67 | + $result_tmp['course_id_value'] = $course['course_id_value']; |
|
68 | + if($result_op instanceof WSCMError) { |
|
69 | + // Return the error in the results |
|
70 | + $result_tmp['result'] = $result_op->toArray(); |
|
71 | + } else { |
|
72 | + $result_tmp['result'] = $this->getSuccessfulResult(); |
|
73 | + } |
|
74 | + $results[] = $result_tmp; |
|
75 | + } |
|
76 | + return $results; |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Creates a course (helper method) |
|
82 | + * |
|
83 | + * @param string Title |
|
84 | + * @param string Category code |
|
85 | + * @param string Wanted code. If it's not defined, it will be generated automatically |
|
86 | + * @param string Tutor name |
|
87 | + * @param string Course admin user id field name |
|
88 | + * @param string Course admin user id value |
|
89 | + * @param string Course language |
|
90 | + * @param string Course id field name |
|
91 | + * @param string Course id value |
|
92 | + * @param array Course extra fields |
|
93 | + * @return mixed Generated id if creation was successful, WSError otherwise |
|
94 | + */ |
|
95 | + protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
|
96 | + // Add the original course id field name and value to the extra fields if needed |
|
97 | + $extras_associative = array(); |
|
98 | + if($course_id_field_name != "chamilo_course_id") { |
|
99 | + $extras_associative[$course_id_field_name] = $course_id_value; |
|
100 | + } |
|
101 | + foreach($extras as $extra) { |
|
102 | + $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
103 | + } |
|
104 | + $course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value); |
|
105 | + if($course_admin_id instanceof WSError) { |
|
106 | + return $course_admin_id; |
|
107 | + } |
|
108 | + if($wanted_code == '') { |
|
109 | + $wanted_code = CourseManager::generate_course_code($title); |
|
110 | + } |
|
111 | + $result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0); |
|
112 | + if (!$result) { |
|
113 | + return new WSError(202, 'There was an error creating the course'); |
|
114 | + } else { |
|
115 | + // Update extra fields |
|
116 | + foreach($extras_associative as $fname => $fvalue) { |
|
117 | + CourseManager::update_course_extra_field_value($result, $fname, $fvalue); |
|
118 | + } |
|
119 | + // Get course id |
|
120 | + $course_info = CourseManager::get_course_information($result); |
|
121 | + return $course_info['real_id']; |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Creates a course |
|
127 | + * |
|
128 | + * @param string API secret key |
|
129 | + * @param string Title |
|
130 | + * @param string Category code |
|
131 | + * @param string Wanted code. If it's not defined, it will be generated automatically |
|
132 | + * @param string Tutor name |
|
133 | + * @param string Course admin user id field name |
|
134 | + * @param string Course admin user id value |
|
135 | + * @param string Course language |
|
136 | + * @param string Course id field name |
|
137 | + * @param string Course id value |
|
138 | + * @param array Course extra fields |
|
139 | + * @return int Course id generated |
|
140 | + */ |
|
141 | + public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
|
142 | + // First, verify the secret key |
|
143 | + $verifKey = $this->verifyKey($secret_key); |
|
144 | + if($verifKey instanceof WSError) { |
|
145 | + $this->handleError($verifKey); |
|
146 | + } else { |
|
147 | + $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
|
148 | + if($result instanceof WSError) { |
|
149 | + $this->handleError($result); |
|
150 | + } else { |
|
151 | + return $result; |
|
152 | + } |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Create multiple courses |
|
158 | + * |
|
159 | + * @param string API secret key |
|
160 | + * @param array Courses to be created, with elements following the structure presented in CreateCourse |
|
161 | + * @return array Array with elements of the form array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful')) |
|
162 | + */ |
|
163 | + public function CreateCourses($secret_key, $courses) { |
|
164 | + // First, verify the secret key |
|
165 | + $verifKey = $this->verifyKey($secret_key); |
|
166 | + if($verifKey instanceof WSCMError) { |
|
167 | + $this->handleError($verifKey); |
|
168 | + } else { |
|
169 | + $results = array(); |
|
170 | + foreach($courses as $course) { |
|
171 | + $result_tmp = array(); |
|
172 | + //reinitialize variables just in case |
|
173 | + $title = $category_code = $wanted_code = $tutor_name = $course_admin_user_id_field_name = $course_admin_user_id_value = $language = $course_id_field_name = $course_id_value = $extras = null; |
|
174 | + extract($course); |
|
175 | + $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
|
176 | + if($result instanceof WSCMError) { |
|
177 | + $result_tmp['result'] = $result->toArray(); |
|
178 | + $result_tmp['course_id_value'] = $course_id_value; |
|
179 | + $result_tmp['course_id_generated'] = 0; |
|
180 | + } else { |
|
181 | + $result_tmp['result'] = $this->getSuccessfulResult(); |
|
182 | + $result_tmp['course_id_value'] = $course_id_value; |
|
183 | + $result_tmp['course_id_generated'] = $result; |
|
184 | + } |
|
185 | + $results[] = $result_tmp; |
|
186 | + } |
|
187 | + return $results; |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Edits a course (helper method) |
|
193 | + * |
|
194 | + * @param string Course id field name |
|
195 | + * @param string Course id value |
|
196 | + * @param string Title |
|
197 | + * @param string Category code |
|
198 | + * @param string Department name |
|
199 | + * @param string Department url |
|
200 | + * @param string Course language |
|
201 | + * @param int Visibility |
|
202 | + * @param int Subscribe (0 = denied, 1 = allowed) |
|
203 | + * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
204 | + * @param string Visual code |
|
205 | + * @param array Course extra fields |
|
206 | + * @return mixed True in case of success, WSError otherwise |
|
207 | + */ |
|
208 | + protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
209 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
210 | + if($course_id instanceof WSCMError) { |
|
211 | + return $course_id; |
|
212 | + } else { |
|
213 | + $attributes = array(); |
|
214 | + if(!empty($title)) { |
|
215 | + $attributes['title'] = $title; |
|
216 | + } |
|
217 | + if(!empty($category_code)) { |
|
218 | + $attributes['category_code'] = $category_code; |
|
219 | + } |
|
220 | + if(!empty($department_name)) { |
|
221 | + $attributes['department_name'] = $department_name; |
|
222 | + } |
|
223 | + if(!empty($department_url)) { |
|
224 | + $attributes['department_url'] = $department_url; |
|
225 | + } |
|
226 | + if(!empty($language)) { |
|
227 | + $attributes['course_language'] = $language; |
|
228 | + } |
|
229 | + if($visibility != '') { |
|
230 | + $attributes['visibility'] = (int)$visibility; |
|
231 | + } |
|
232 | + if($subscribe != '') { |
|
233 | + $attributes['subscribe'] = (int)$subscribe; |
|
234 | + } |
|
235 | + if($unsubscribe != '') { |
|
236 | + $attributes['unsubscribe'] = (int)$unsubscribe; |
|
237 | + } |
|
238 | + if(!empty($visual_code)) { |
|
239 | + $attributes['visual_code'] = $visual_code; |
|
240 | + } |
|
241 | + if(!empty($attributes)) { |
|
242 | + CourseManager::update_attributes($course_id, $attributes); |
|
243 | + } |
|
244 | + if(!empty($extras)) { |
|
245 | + $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
246 | + $extras_associative = array(); |
|
247 | + foreach($extras as $extra) { |
|
248 | + $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
249 | + } |
|
250 | + foreach($extras_associative as $fname => $fvalue) { |
|
251 | + CourseManager::update_extra_field_value($course_code, $fname, $fvalue); |
|
252 | + } |
|
253 | + } |
|
254 | + return true; |
|
255 | + } |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Edits a course |
|
260 | + * |
|
261 | + * @param string API secret key |
|
262 | + * @param string Course id field name |
|
263 | + * @param string Course id value |
|
264 | + * @param string Title |
|
265 | + * @param string Category code |
|
266 | + * @param string Department name |
|
267 | + * @param string Department url |
|
268 | + * @param string Course language |
|
269 | + * @param int Visibility |
|
270 | + * @param int Subscribe (0 = denied, 1 = allowed) |
|
271 | + * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
272 | + * @param string Visual code |
|
273 | + * @param array Course extra fields |
|
274 | + */ |
|
275 | + public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
276 | + $verifKey = $this->verifyKey($secret_key); |
|
277 | + if($verifKey instanceof WSCMError) { |
|
278 | + $this->handleError($verifKey); |
|
279 | + } else { |
|
280 | + $result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras); |
|
281 | + if($result instanceof WSCMError) { |
|
282 | + $this->handleError($result); |
|
283 | + } |
|
284 | + } |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * List courses |
|
289 | + * |
|
290 | + * @param string API secret key |
|
291 | + * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
292 | + * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility', |
|
293 | + * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id') |
|
294 | + */ |
|
295 | + public function ListCourses($secret_key, $course_id_field_name) { |
|
296 | + $verifKey = $this->verifyKey($secret_key); |
|
297 | + if($verifKey instanceof WSError) { |
|
298 | + $this->handleError($verifKey); |
|
299 | + } else { |
|
300 | + $courses_result = array(); |
|
301 | + $category_names = array(); |
|
302 | + |
|
303 | + $courses = CourseManager::get_courses_list(); |
|
304 | + foreach($courses as $course) { |
|
305 | + $course_tmp = array(); |
|
306 | + $course_tmp['id'] = $course['id']; |
|
307 | + $course_tmp['code'] = $course['code']; |
|
308 | + $course_tmp['title'] = $course['title']; |
|
309 | + $course_tmp['language'] = $course['course_language']; |
|
310 | + $course_tmp['visibility'] = $course['visibility']; |
|
311 | + |
|
312 | + // Determining category name |
|
313 | + if($category_names[$course['category_code']]) { |
|
314 | + $course_tmp['category_name'] = $category_names[$course['category_code']]; |
|
315 | + } else { |
|
316 | + $category = CourseManager::get_course_category($course['category_code']); |
|
317 | + $category_names[$course['category_code']] = $category['name']; |
|
318 | + $course_tmp['category_name'] = $category['name']; |
|
319 | + } |
|
320 | + |
|
321 | + // Determining number of students registered in course |
|
322 | + $user_list = CourseManager::get_user_list_from_course_code($course['code']); |
|
323 | + $course_tmp['number_students'] = count($user_list); |
|
324 | + |
|
325 | + // Determining external course id |
|
326 | + $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_id_field_name, $course['code']); |
|
327 | + |
|
328 | + |
|
329 | + $courses_result[] = $course_tmp; |
|
330 | + } |
|
331 | + |
|
332 | + return $courses_result; |
|
333 | + } |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * Subscribe or unsubscribe user to a course (helper method) |
|
338 | + * |
|
339 | + * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
340 | + * @param string Course id value. |
|
341 | + * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
342 | + * @param string User id value |
|
343 | + * @param int Set to 1 to subscribe, 0 to unsubscribe |
|
344 | + * @param int Status (STUDENT or TEACHER) Used for subscription only |
|
345 | + * @return mixed True if subscription or unsubscription was successful, false otherwise |
|
346 | + */ |
|
347 | + protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) { |
|
348 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
349 | + if($course_id instanceof WSError) { |
|
350 | + return $course_id; |
|
351 | + } else { |
|
352 | + $user_id = $this->getUserId($user_id_field_name, $user_id_value); |
|
353 | + if($user_id instanceof WSError) { |
|
354 | + return $user_id; |
|
355 | + } else { |
|
356 | + $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
357 | + if($state == 0) { |
|
358 | + // Unsubscribe user |
|
359 | + CourseManager::unsubscribe_user($user_id, $course_code); |
|
360 | + return true; |
|
361 | + } else { |
|
362 | + // Subscribe user |
|
363 | + if(CourseManager::subscribe_user($user_id, $course_code, $status)) { |
|
364 | + return true; |
|
365 | + } else { |
|
366 | + return new WSError(203, 'An error occured subscribing to this course'); |
|
367 | + } |
|
368 | + } |
|
369 | + } |
|
370 | + } |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Subscribe user to a course |
|
375 | + * |
|
376 | + * @param string API secret key |
|
377 | + * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
378 | + * @param string Course id value. |
|
379 | + * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
380 | + * @param string User id value |
|
381 | + * @param int Status (1 = Teacher, 5 = Student) |
|
382 | + */ |
|
383 | + public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) { |
|
384 | + $verifKey = $this->verifyKey($secret_key); |
|
385 | + if($verifKey instanceof WSError) { |
|
386 | + $this->handleError($verifKey); |
|
387 | + } else { |
|
388 | + $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status); |
|
389 | + if($result instanceof WSError) { |
|
390 | + $this->handleError($result); |
|
391 | + } |
|
392 | + } |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Unsusbscribe user from course |
|
397 | + * |
|
398 | + * @param string API secret key |
|
399 | + * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
400 | + * @param string Course id value. |
|
401 | + * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
402 | + * @param string User id value |
|
403 | + */ |
|
404 | + public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) { |
|
405 | + $verifKey = $this->verifyKey($secret_key); |
|
406 | + if($verifKey instanceof WSError) { |
|
407 | + $this->handleError($verifKey); |
|
408 | + } else { |
|
409 | + $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0); |
|
410 | + if($result instanceof WSError) { |
|
411 | + $this->handleError($result); |
|
412 | + } |
|
413 | + } |
|
414 | + } |
|
415 | + |
|
416 | + /** |
|
417 | + * Returns the descriptions of a course, along with their id |
|
418 | + * |
|
419 | + * @param string API secret key |
|
420 | + * @param string Course id field name |
|
421 | + * @param string Course id value |
|
422 | + * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content') |
|
423 | + */ |
|
424 | + public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) { |
|
425 | + $verifKey = $this->verifyKey($secret_key); |
|
426 | + if($verifKey instanceof WSError) { |
|
427 | + $this->handleError($verifKey); |
|
428 | + } else { |
|
429 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
430 | + if($course_id instanceof WSError) { |
|
431 | + return $course_id; |
|
432 | + } else { |
|
433 | + // Course exists, get its descriptions |
|
434 | + $descriptions = CourseDescription::get_descriptions($course_id); |
|
435 | + $results = array(); |
|
436 | + foreach($descriptions as $description) { |
|
437 | + $results[] = array('course_desc_id' => $description->get_description_type(), |
|
438 | + 'course_desc_title' => $description->get_title(), |
|
439 | + 'course_desc_content' => $description->get_content()); |
|
440 | + } |
|
441 | + return $results; |
|
442 | + } |
|
443 | + } |
|
444 | + } |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * Edit course description |
|
449 | + * |
|
450 | + * @param string API secret key |
|
451 | + * @param string Course id field name |
|
452 | + * @param string Course id value |
|
453 | + * @param int Category id from course description |
|
454 | + * @param string Description title |
|
455 | + * @param string Course description content |
|
456 | + */ |
|
457 | + public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) { |
|
458 | + $verifKey = $this->verifyKey($secret_key); |
|
459 | + if($verifKey instanceof WSError) { |
|
460 | + $this->handleError($verifKey); |
|
461 | + } else { |
|
462 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
463 | + if($course_id instanceof WSError) { |
|
464 | + return $course_id; |
|
465 | + } else { |
|
466 | + // Create the new course description |
|
467 | + $cd = new CourseDescription(); |
|
468 | + $cd->set_description_type($course_desc_id); |
|
469 | + $cd->set_title($course_desc_title); |
|
470 | + $cd->set_content($course_desc_content); |
|
471 | + $cd->set_session_id(0); |
|
472 | + |
|
473 | + // Get course info |
|
474 | 474 | $course_info = CourseManager::get_course_information( |
475 | 475 | CourseManager::get_course_code_from_course_id($course_id) |
476 | 476 | ); |
477 | - // Check if this course description exists |
|
478 | - $descriptions = CourseDescription::get_descriptions($course_id); |
|
479 | - $exists = false; |
|
480 | - foreach($descriptions as $description) { |
|
481 | - if($description->get_description_type() == $course_desc_id) { |
|
482 | - $exists = true; |
|
483 | - } |
|
484 | - } |
|
477 | + // Check if this course description exists |
|
478 | + $descriptions = CourseDescription::get_descriptions($course_id); |
|
479 | + $exists = false; |
|
480 | + foreach($descriptions as $description) { |
|
481 | + if($description->get_description_type() == $course_desc_id) { |
|
482 | + $exists = true; |
|
483 | + } |
|
484 | + } |
|
485 | 485 | $cd->set_course_id($course_info['real_id']); |
486 | - if (!$exists) { |
|
487 | - $cd->set_progress(0); |
|
488 | - $cd->insert(); |
|
489 | - } else { |
|
490 | - $cd->update(); |
|
491 | - } |
|
492 | - } |
|
493 | - } |
|
494 | - } |
|
495 | - public function unreadMessage($username, $password) |
|
496 | - { |
|
497 | - if($this->verifyUserPass($username, $password) == "valid") |
|
498 | - { |
|
499 | - $table_message = Database::get_main_table(TABLE_MESSAGE); |
|
500 | - $user_id = UserManager::get_user_id_from_username($username); |
|
501 | - $condition_msg_status = ' msg_status = 1 '; // define('MESSAGE_STATUS_UNREAD', '1'); |
|
502 | - |
|
503 | - $sql_query = "SELECT COUNT(*) as number_messages FROM $table_message WHERE $condition_msg_status AND user_receiver_id=".$user_id; |
|
504 | - |
|
505 | - $sql_result = Database::query($sql_query); |
|
506 | - $result = Database::fetch_array($sql_result); |
|
507 | - return $result['number_messages']; |
|
508 | - } |
|
509 | - return "0"; |
|
510 | - } |
|
511 | - |
|
512 | - public function get_message_data($username, $password) |
|
513 | - { |
|
514 | - if($this->verifyUserPass($username, $password) == "valid") |
|
515 | - { |
|
516 | - $user_id = get_user_id_from_username($username); |
|
517 | - |
|
518 | - } |
|
519 | - |
|
520 | - } |
|
521 | - |
|
522 | - public function nada($username, $password) |
|
523 | - { |
|
524 | - if($this->verifyUserPass($username, $password) == "valid") |
|
525 | - return $username.$password; |
|
526 | - return $username; |
|
527 | - } |
|
486 | + if (!$exists) { |
|
487 | + $cd->set_progress(0); |
|
488 | + $cd->insert(); |
|
489 | + } else { |
|
490 | + $cd->update(); |
|
491 | + } |
|
492 | + } |
|
493 | + } |
|
494 | + } |
|
495 | + public function unreadMessage($username, $password) |
|
496 | + { |
|
497 | + if($this->verifyUserPass($username, $password) == "valid") |
|
498 | + { |
|
499 | + $table_message = Database::get_main_table(TABLE_MESSAGE); |
|
500 | + $user_id = UserManager::get_user_id_from_username($username); |
|
501 | + $condition_msg_status = ' msg_status = 1 '; // define('MESSAGE_STATUS_UNREAD', '1'); |
|
502 | + |
|
503 | + $sql_query = "SELECT COUNT(*) as number_messages FROM $table_message WHERE $condition_msg_status AND user_receiver_id=".$user_id; |
|
504 | + |
|
505 | + $sql_result = Database::query($sql_query); |
|
506 | + $result = Database::fetch_array($sql_result); |
|
507 | + return $result['number_messages']; |
|
508 | + } |
|
509 | + return "0"; |
|
510 | + } |
|
511 | + |
|
512 | + public function get_message_data($username, $password) |
|
513 | + { |
|
514 | + if($this->verifyUserPass($username, $password) == "valid") |
|
515 | + { |
|
516 | + $user_id = get_user_id_from_username($username); |
|
517 | + |
|
518 | + } |
|
519 | + |
|
520 | + } |
|
521 | + |
|
522 | + public function nada($username, $password) |
|
523 | + { |
|
524 | + if($this->verifyUserPass($username, $password) == "valid") |
|
525 | + return $username.$password; |
|
526 | + return $username; |
|
527 | + } |
|
528 | 528 | |
529 | 529 | |
530 | 530 |
@@ -12,490 +12,490 @@ |
||
12 | 12 | */ |
13 | 13 | class WSCourse extends WS |
14 | 14 | { |
15 | - /** |
|
16 | - * Deletes a course (helper method) |
|
17 | - * |
|
18 | - * @param string Course id field name |
|
19 | - * @param string Course id value |
|
20 | - * @return mixed True if the course was successfully deleted, WSError otherwise |
|
21 | - */ |
|
22 | - protected function deleteCourseHelper($course_id_field_name, $course_id_value) { |
|
23 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
24 | - if($course_id instanceof WSError) { |
|
25 | - return $course_id; |
|
26 | - } else { |
|
27 | - $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
28 | - CourseManager::delete_course($course_code); |
|
29 | - return true; |
|
30 | - } |
|
31 | - } |
|
15 | + /** |
|
16 | + * Deletes a course (helper method) |
|
17 | + * |
|
18 | + * @param string Course id field name |
|
19 | + * @param string Course id value |
|
20 | + * @return mixed True if the course was successfully deleted, WSError otherwise |
|
21 | + */ |
|
22 | + protected function deleteCourseHelper($course_id_field_name, $course_id_value) { |
|
23 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
24 | + if($course_id instanceof WSError) { |
|
25 | + return $course_id; |
|
26 | + } else { |
|
27 | + $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
28 | + CourseManager::delete_course($course_code); |
|
29 | + return true; |
|
30 | + } |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Deletes a course |
|
35 | - * |
|
36 | - * @param string API secret key |
|
37 | - * @param string Course id field name |
|
38 | - * @param string Course id value |
|
39 | - */ |
|
40 | - public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) { |
|
41 | - $verifKey = $this->verifyKey($secret_key); |
|
42 | - if($verifKey instanceof WSError) { |
|
43 | - $this->handleError($verifKey); |
|
44 | - } else { |
|
45 | - $result = $this->deleteCourseHelper($course_id_field_name, $course_id_value); |
|
46 | - if($result instanceof WSError) { |
|
47 | - $this->handleError($result); |
|
48 | - } |
|
49 | - } |
|
50 | - } |
|
33 | + /** |
|
34 | + * Deletes a course |
|
35 | + * |
|
36 | + * @param string API secret key |
|
37 | + * @param string Course id field name |
|
38 | + * @param string Course id value |
|
39 | + */ |
|
40 | + public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) { |
|
41 | + $verifKey = $this->verifyKey($secret_key); |
|
42 | + if($verifKey instanceof WSError) { |
|
43 | + $this->handleError($verifKey); |
|
44 | + } else { |
|
45 | + $result = $this->deleteCourseHelper($course_id_field_name, $course_id_value); |
|
46 | + if($result instanceof WSError) { |
|
47 | + $this->handleError($result); |
|
48 | + } |
|
49 | + } |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Deletes multiple courses |
|
54 | - * |
|
55 | - * @param string API secret key |
|
56 | - * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value') |
|
57 | - * @return array Array with elements like array('course_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). Note that if the result array contains a code different |
|
58 | - * than 0, an error occured |
|
59 | - */ |
|
60 | - public function DeleteCourses($secret_key, $courses) { |
|
61 | - $verifKey = $this->verifyKey($secret_key); |
|
62 | - if($verifKey instanceof WSError) { |
|
63 | - $this->handleError($verifKey); |
|
64 | - } else { |
|
65 | - $results = array(); |
|
66 | - foreach($courses as $course) { |
|
67 | - $result_tmp = array(); |
|
68 | - $result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']); |
|
69 | - $result_tmp['course_id_value'] = $course['course_id_value']; |
|
70 | - if($result_op instanceof WSError) { |
|
71 | - // Return the error in the results |
|
72 | - $result_tmp['result'] = $result_op->toArray(); |
|
73 | - } else { |
|
74 | - $result_tmp['result'] = $this->getSuccessfulResult(); |
|
75 | - } |
|
76 | - $results[] = $result_tmp; |
|
77 | - } |
|
78 | - return $results; |
|
79 | - } |
|
80 | - } |
|
52 | + /** |
|
53 | + * Deletes multiple courses |
|
54 | + * |
|
55 | + * @param string API secret key |
|
56 | + * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value') |
|
57 | + * @return array Array with elements like array('course_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). Note that if the result array contains a code different |
|
58 | + * than 0, an error occured |
|
59 | + */ |
|
60 | + public function DeleteCourses($secret_key, $courses) { |
|
61 | + $verifKey = $this->verifyKey($secret_key); |
|
62 | + if($verifKey instanceof WSError) { |
|
63 | + $this->handleError($verifKey); |
|
64 | + } else { |
|
65 | + $results = array(); |
|
66 | + foreach($courses as $course) { |
|
67 | + $result_tmp = array(); |
|
68 | + $result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']); |
|
69 | + $result_tmp['course_id_value'] = $course['course_id_value']; |
|
70 | + if($result_op instanceof WSError) { |
|
71 | + // Return the error in the results |
|
72 | + $result_tmp['result'] = $result_op->toArray(); |
|
73 | + } else { |
|
74 | + $result_tmp['result'] = $this->getSuccessfulResult(); |
|
75 | + } |
|
76 | + $results[] = $result_tmp; |
|
77 | + } |
|
78 | + return $results; |
|
79 | + } |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Creates a course (helper method) |
|
84 | - * |
|
85 | - * @param string Title |
|
86 | - * @param string Category code |
|
87 | - * @param string Wanted code. If it's not defined, it will be generated automatically |
|
88 | - * @param string Tutor name |
|
89 | - * @param string Course admin user id field name |
|
90 | - * @param string Course admin user id value |
|
91 | - * @param string Course language |
|
92 | - * @param string Course id field name |
|
93 | - * @param string Course id value |
|
94 | - * @param array Course extra fields |
|
95 | - * @return mixed Generated id if creation was successful, WSError otherwise |
|
96 | - */ |
|
97 | - protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
|
98 | - // Add the original course id field name and value to the extra fields if needed |
|
99 | - $extras_associative = array(); |
|
100 | - if($course_id_field_name != "chamilo_course_id") { |
|
101 | - $extras_associative[$course_id_field_name] = $course_id_value; |
|
102 | - } |
|
103 | - foreach($extras as $extra) { |
|
104 | - $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
105 | - } |
|
106 | - $course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value); |
|
107 | - if($course_admin_id instanceof WSError) { |
|
108 | - return $course_admin_id; |
|
109 | - } |
|
110 | - if($wanted_code == '') { |
|
111 | - $wanted_code = CourseManager::generate_course_code($title); |
|
112 | - } |
|
113 | - $result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0); |
|
114 | - if (!$result) { |
|
115 | - return new WSError(202, 'There was an error creating the course'); |
|
116 | - } else { |
|
117 | - // Update extra fields |
|
118 | - foreach($extras_associative as $fname => $fvalue) { |
|
119 | - CourseManager::update_course_extra_field_value($result, $fname, $fvalue); |
|
120 | - } |
|
121 | - // Get course id |
|
122 | - $course_info = CourseManager::get_course_information($result); |
|
123 | - return $course_info['real_id']; |
|
124 | - } |
|
125 | - } |
|
82 | + /** |
|
83 | + * Creates a course (helper method) |
|
84 | + * |
|
85 | + * @param string Title |
|
86 | + * @param string Category code |
|
87 | + * @param string Wanted code. If it's not defined, it will be generated automatically |
|
88 | + * @param string Tutor name |
|
89 | + * @param string Course admin user id field name |
|
90 | + * @param string Course admin user id value |
|
91 | + * @param string Course language |
|
92 | + * @param string Course id field name |
|
93 | + * @param string Course id value |
|
94 | + * @param array Course extra fields |
|
95 | + * @return mixed Generated id if creation was successful, WSError otherwise |
|
96 | + */ |
|
97 | + protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
|
98 | + // Add the original course id field name and value to the extra fields if needed |
|
99 | + $extras_associative = array(); |
|
100 | + if($course_id_field_name != "chamilo_course_id") { |
|
101 | + $extras_associative[$course_id_field_name] = $course_id_value; |
|
102 | + } |
|
103 | + foreach($extras as $extra) { |
|
104 | + $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
105 | + } |
|
106 | + $course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value); |
|
107 | + if($course_admin_id instanceof WSError) { |
|
108 | + return $course_admin_id; |
|
109 | + } |
|
110 | + if($wanted_code == '') { |
|
111 | + $wanted_code = CourseManager::generate_course_code($title); |
|
112 | + } |
|
113 | + $result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0); |
|
114 | + if (!$result) { |
|
115 | + return new WSError(202, 'There was an error creating the course'); |
|
116 | + } else { |
|
117 | + // Update extra fields |
|
118 | + foreach($extras_associative as $fname => $fvalue) { |
|
119 | + CourseManager::update_course_extra_field_value($result, $fname, $fvalue); |
|
120 | + } |
|
121 | + // Get course id |
|
122 | + $course_info = CourseManager::get_course_information($result); |
|
123 | + return $course_info['real_id']; |
|
124 | + } |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * Creates a course |
|
129 | - * |
|
130 | - * @param string API secret key |
|
131 | - * @param string Title |
|
132 | - * @param string Category code |
|
133 | - * @param string Wanted code. If it's not defined, it will be generated automatically |
|
134 | - * @param string Tutor name |
|
135 | - * @param string Course admin user id field name |
|
136 | - * @param string Course admin user id value |
|
137 | - * @param string Course language |
|
138 | - * @param string Course id field name |
|
139 | - * @param string Course id value |
|
140 | - * @param array Course extra fields |
|
141 | - * @return int Course id generated |
|
142 | - */ |
|
143 | - public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
|
144 | - // First, verify the secret key |
|
145 | - $verifKey = $this->verifyKey($secret_key); |
|
146 | - if($verifKey instanceof WSError) { |
|
147 | - $this->handleError($verifKey); |
|
148 | - } else { |
|
149 | - $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
|
150 | - if($result instanceof WSError) { |
|
151 | - $this->handleError($result); |
|
152 | - } else { |
|
153 | - return $result; |
|
154 | - } |
|
155 | - } |
|
156 | - } |
|
127 | + /** |
|
128 | + * Creates a course |
|
129 | + * |
|
130 | + * @param string API secret key |
|
131 | + * @param string Title |
|
132 | + * @param string Category code |
|
133 | + * @param string Wanted code. If it's not defined, it will be generated automatically |
|
134 | + * @param string Tutor name |
|
135 | + * @param string Course admin user id field name |
|
136 | + * @param string Course admin user id value |
|
137 | + * @param string Course language |
|
138 | + * @param string Course id field name |
|
139 | + * @param string Course id value |
|
140 | + * @param array Course extra fields |
|
141 | + * @return int Course id generated |
|
142 | + */ |
|
143 | + public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
|
144 | + // First, verify the secret key |
|
145 | + $verifKey = $this->verifyKey($secret_key); |
|
146 | + if($verifKey instanceof WSError) { |
|
147 | + $this->handleError($verifKey); |
|
148 | + } else { |
|
149 | + $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
|
150 | + if($result instanceof WSError) { |
|
151 | + $this->handleError($result); |
|
152 | + } else { |
|
153 | + return $result; |
|
154 | + } |
|
155 | + } |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * Create multiple courses |
|
160 | - * |
|
161 | - * @param string API secret key |
|
162 | - * @param array Courses to be created, with elements following the structure presented in CreateCourse |
|
163 | - * @return array Array with elements of the form array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful')) |
|
164 | - */ |
|
165 | - public function CreateCourses($secret_key, $courses) { |
|
166 | - // First, verify the secret key |
|
167 | - $verifKey = $this->verifyKey($secret_key); |
|
168 | - if($verifKey instanceof WSError) { |
|
169 | - $this->handleError($verifKey); |
|
170 | - } else { |
|
171 | - $results = array(); |
|
172 | - foreach($courses as $course) { |
|
173 | - $result_tmp = array(); |
|
158 | + /** |
|
159 | + * Create multiple courses |
|
160 | + * |
|
161 | + * @param string API secret key |
|
162 | + * @param array Courses to be created, with elements following the structure presented in CreateCourse |
|
163 | + * @return array Array with elements of the form array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful')) |
|
164 | + */ |
|
165 | + public function CreateCourses($secret_key, $courses) { |
|
166 | + // First, verify the secret key |
|
167 | + $verifKey = $this->verifyKey($secret_key); |
|
168 | + if($verifKey instanceof WSError) { |
|
169 | + $this->handleError($verifKey); |
|
170 | + } else { |
|
171 | + $results = array(); |
|
172 | + foreach($courses as $course) { |
|
173 | + $result_tmp = array(); |
|
174 | 174 | // re-initialize variables just in case |
175 | 175 | $title = $category_code = $wanted_code = $tutor_name = $course_admin_user_id_field_name = $course_admin_user_id_value = $language = $course_id_field_name = $course_id_value = $extras = 0; |
176 | - extract($course); |
|
177 | - $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
|
178 | - if($result instanceof WSError) { |
|
179 | - $result_tmp['result'] = $result->toArray(); |
|
180 | - $result_tmp['course_id_value'] = $course_id_value; |
|
181 | - $result_tmp['course_id_generated'] = 0; |
|
182 | - } else { |
|
183 | - $result_tmp['result'] = $this->getSuccessfulResult(); |
|
184 | - $result_tmp['course_id_value'] = $course_id_value; |
|
185 | - $result_tmp['course_id_generated'] = $result; |
|
186 | - } |
|
187 | - $results[] = $result_tmp; |
|
188 | - } |
|
189 | - return $results; |
|
190 | - } |
|
191 | - } |
|
176 | + extract($course); |
|
177 | + $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
|
178 | + if($result instanceof WSError) { |
|
179 | + $result_tmp['result'] = $result->toArray(); |
|
180 | + $result_tmp['course_id_value'] = $course_id_value; |
|
181 | + $result_tmp['course_id_generated'] = 0; |
|
182 | + } else { |
|
183 | + $result_tmp['result'] = $this->getSuccessfulResult(); |
|
184 | + $result_tmp['course_id_value'] = $course_id_value; |
|
185 | + $result_tmp['course_id_generated'] = $result; |
|
186 | + } |
|
187 | + $results[] = $result_tmp; |
|
188 | + } |
|
189 | + return $results; |
|
190 | + } |
|
191 | + } |
|
192 | 192 | |
193 | - /** |
|
194 | - * Edits a course (helper method) |
|
195 | - * |
|
196 | - * @param string Course id field name |
|
197 | - * @param string Course id value |
|
198 | - * @param string Title |
|
199 | - * @param string Category code |
|
200 | - * @param string Department name |
|
201 | - * @param string Department url |
|
202 | - * @param string Course language |
|
203 | - * @param int Visibility |
|
204 | - * @param int Subscribe (0 = denied, 1 = allowed) |
|
205 | - * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
206 | - * @param string Visual code |
|
207 | - * @param array Course extra fields |
|
208 | - * @return mixed True in case of success, WSError otherwise |
|
209 | - */ |
|
210 | - protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
211 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
212 | - if($course_id instanceof WSError) { |
|
213 | - return $course_id; |
|
214 | - } else { |
|
215 | - $attributes = array(); |
|
216 | - if(!empty($title)) { |
|
217 | - $attributes['title'] = $title; |
|
218 | - } |
|
219 | - if(!empty($category_code)) { |
|
220 | - $attributes['category_code'] = $category_code; |
|
221 | - } |
|
222 | - if(!empty($department_name)) { |
|
223 | - $attributes['department_name'] = $department_name; |
|
224 | - } |
|
225 | - if(!empty($department_url)) { |
|
226 | - $attributes['department_url'] = $department_url; |
|
227 | - } |
|
228 | - if(!empty($language)) { |
|
229 | - $attributes['course_language'] = $language; |
|
230 | - } |
|
231 | - if($visibility != '') { |
|
232 | - $attributes['visibility'] = (int)$visibility; |
|
233 | - } |
|
234 | - if($subscribe != '') { |
|
235 | - $attributes['subscribe'] = (int)$subscribe; |
|
236 | - } |
|
237 | - if($unsubscribe != '') { |
|
238 | - $attributes['unsubscribe'] = (int)$unsubscribe; |
|
239 | - } |
|
240 | - if(!empty($visual_code)) { |
|
241 | - $attributes['visual_code'] = $visual_code; |
|
242 | - } |
|
243 | - if(!empty($attributes)) { |
|
244 | - CourseManager::update_attributes($course_id, $attributes); |
|
245 | - } |
|
246 | - if(!empty($extras)) { |
|
247 | - $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
248 | - $extras_associative = array(); |
|
249 | - foreach($extras as $extra) { |
|
250 | - $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
251 | - } |
|
252 | - foreach($extras_associative as $fname => $fvalue) { |
|
253 | - CourseManager::update_extra_field_value($course_code, $fname, $fvalue); |
|
254 | - } |
|
255 | - } |
|
256 | - return true; |
|
257 | - } |
|
258 | - } |
|
193 | + /** |
|
194 | + * Edits a course (helper method) |
|
195 | + * |
|
196 | + * @param string Course id field name |
|
197 | + * @param string Course id value |
|
198 | + * @param string Title |
|
199 | + * @param string Category code |
|
200 | + * @param string Department name |
|
201 | + * @param string Department url |
|
202 | + * @param string Course language |
|
203 | + * @param int Visibility |
|
204 | + * @param int Subscribe (0 = denied, 1 = allowed) |
|
205 | + * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
206 | + * @param string Visual code |
|
207 | + * @param array Course extra fields |
|
208 | + * @return mixed True in case of success, WSError otherwise |
|
209 | + */ |
|
210 | + protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
211 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
212 | + if($course_id instanceof WSError) { |
|
213 | + return $course_id; |
|
214 | + } else { |
|
215 | + $attributes = array(); |
|
216 | + if(!empty($title)) { |
|
217 | + $attributes['title'] = $title; |
|
218 | + } |
|
219 | + if(!empty($category_code)) { |
|
220 | + $attributes['category_code'] = $category_code; |
|
221 | + } |
|
222 | + if(!empty($department_name)) { |
|
223 | + $attributes['department_name'] = $department_name; |
|
224 | + } |
|
225 | + if(!empty($department_url)) { |
|
226 | + $attributes['department_url'] = $department_url; |
|
227 | + } |
|
228 | + if(!empty($language)) { |
|
229 | + $attributes['course_language'] = $language; |
|
230 | + } |
|
231 | + if($visibility != '') { |
|
232 | + $attributes['visibility'] = (int)$visibility; |
|
233 | + } |
|
234 | + if($subscribe != '') { |
|
235 | + $attributes['subscribe'] = (int)$subscribe; |
|
236 | + } |
|
237 | + if($unsubscribe != '') { |
|
238 | + $attributes['unsubscribe'] = (int)$unsubscribe; |
|
239 | + } |
|
240 | + if(!empty($visual_code)) { |
|
241 | + $attributes['visual_code'] = $visual_code; |
|
242 | + } |
|
243 | + if(!empty($attributes)) { |
|
244 | + CourseManager::update_attributes($course_id, $attributes); |
|
245 | + } |
|
246 | + if(!empty($extras)) { |
|
247 | + $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
248 | + $extras_associative = array(); |
|
249 | + foreach($extras as $extra) { |
|
250 | + $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
251 | + } |
|
252 | + foreach($extras_associative as $fname => $fvalue) { |
|
253 | + CourseManager::update_extra_field_value($course_code, $fname, $fvalue); |
|
254 | + } |
|
255 | + } |
|
256 | + return true; |
|
257 | + } |
|
258 | + } |
|
259 | 259 | |
260 | - /** |
|
261 | - * Edits a course |
|
262 | - * |
|
263 | - * @param string API secret key |
|
264 | - * @param string Course id field name |
|
265 | - * @param string Course id value |
|
266 | - * @param string Title |
|
267 | - * @param string Category code |
|
268 | - * @param string Department name |
|
269 | - * @param string Department url |
|
270 | - * @param string Course language |
|
271 | - * @param int Visibility |
|
272 | - * @param int Subscribe (0 = denied, 1 = allowed) |
|
273 | - * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
274 | - * @param string Visual code |
|
275 | - * @param array Course extra fields |
|
276 | - */ |
|
277 | - public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
278 | - $verifKey = $this->verifyKey($secret_key); |
|
279 | - if($verifKey instanceof WSError) { |
|
280 | - $this->handleError($verifKey); |
|
281 | - } else { |
|
282 | - $result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras); |
|
283 | - if($result instanceof WSError) { |
|
284 | - $this->handleError($result); |
|
285 | - } |
|
286 | - } |
|
287 | - } |
|
260 | + /** |
|
261 | + * Edits a course |
|
262 | + * |
|
263 | + * @param string API secret key |
|
264 | + * @param string Course id field name |
|
265 | + * @param string Course id value |
|
266 | + * @param string Title |
|
267 | + * @param string Category code |
|
268 | + * @param string Department name |
|
269 | + * @param string Department url |
|
270 | + * @param string Course language |
|
271 | + * @param int Visibility |
|
272 | + * @param int Subscribe (0 = denied, 1 = allowed) |
|
273 | + * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
274 | + * @param string Visual code |
|
275 | + * @param array Course extra fields |
|
276 | + */ |
|
277 | + public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
278 | + $verifKey = $this->verifyKey($secret_key); |
|
279 | + if($verifKey instanceof WSError) { |
|
280 | + $this->handleError($verifKey); |
|
281 | + } else { |
|
282 | + $result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras); |
|
283 | + if($result instanceof WSError) { |
|
284 | + $this->handleError($result); |
|
285 | + } |
|
286 | + } |
|
287 | + } |
|
288 | 288 | |
289 | - /** |
|
290 | - * List courses |
|
291 | - * |
|
292 | - * @param string API secret key |
|
293 | - * @param string A list of visibility filter we want to apply |
|
294 | - * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility', |
|
295 | - * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id') |
|
296 | - */ |
|
297 | - public function ListCourses($secret_key, $visibility = 'public,public-registered,private,closed') { |
|
298 | - $verifKey = $this->verifyKey($secret_key); |
|
299 | - if($verifKey instanceof WSError) { |
|
300 | - $this->handleError($verifKey); |
|
301 | - } else { |
|
289 | + /** |
|
290 | + * List courses |
|
291 | + * |
|
292 | + * @param string API secret key |
|
293 | + * @param string A list of visibility filter we want to apply |
|
294 | + * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility', |
|
295 | + * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id') |
|
296 | + */ |
|
297 | + public function ListCourses($secret_key, $visibility = 'public,public-registered,private,closed') { |
|
298 | + $verifKey = $this->verifyKey($secret_key); |
|
299 | + if($verifKey instanceof WSError) { |
|
300 | + $this->handleError($verifKey); |
|
301 | + } else { |
|
302 | 302 | $visibilities = split(',',$visibility); |
303 | 303 | $vis = array('public' => '3', 'public-registered' => '2', 'private' => '1', 'closed' => '0'); |
304 | 304 | foreach ($visibilities as $p => $visibility) { |
305 | 305 | $visibilities[$p] = $vis[$visibility]; |
306 | 306 | } |
307 | - $courses_result = array(); |
|
308 | - $category_names = array(); |
|
307 | + $courses_result = array(); |
|
308 | + $category_names = array(); |
|
309 | 309 | |
310 | - $courses = CourseManager::get_courses_list(); |
|
311 | - foreach($courses as $course) { |
|
310 | + $courses = CourseManager::get_courses_list(); |
|
311 | + foreach($courses as $course) { |
|
312 | 312 | //skip elements that do not match required visibility |
313 | 313 | if (!in_array($course['visibility'],$visibilities)) { continue; } |
314 | - $course_tmp = array(); |
|
315 | - $course_tmp['id'] = $course['id']; |
|
316 | - $course_tmp['code'] = $course['code']; |
|
317 | - $course_tmp['title'] = $course['title']; |
|
318 | - $course_tmp['language'] = $course['course_language']; |
|
319 | - $course_tmp['visibility'] = $course['visibility']; |
|
314 | + $course_tmp = array(); |
|
315 | + $course_tmp['id'] = $course['id']; |
|
316 | + $course_tmp['code'] = $course['code']; |
|
317 | + $course_tmp['title'] = $course['title']; |
|
318 | + $course_tmp['language'] = $course['course_language']; |
|
319 | + $course_tmp['visibility'] = $course['visibility']; |
|
320 | 320 | |
321 | - // Determining category name |
|
322 | - if($category_names[$course['category_code']]) { |
|
323 | - $course_tmp['category_name'] = $category_names[$course['category_code']]; |
|
324 | - } else { |
|
325 | - $category = CourseManager::get_course_category($course['category_code']); |
|
326 | - $category_names[$course['category_code']] = $category['name']; |
|
327 | - $course_tmp['category_name'] = $category['name']; |
|
328 | - } |
|
321 | + // Determining category name |
|
322 | + if($category_names[$course['category_code']]) { |
|
323 | + $course_tmp['category_name'] = $category_names[$course['category_code']]; |
|
324 | + } else { |
|
325 | + $category = CourseManager::get_course_category($course['category_code']); |
|
326 | + $category_names[$course['category_code']] = $category['name']; |
|
327 | + $course_tmp['category_name'] = $category['name']; |
|
328 | + } |
|
329 | 329 | |
330 | - // Determining number of students registered in course |
|
331 | - $user_list = CourseManager::get_user_list_from_course_code($course['code'], 0); |
|
332 | - $course_tmp['number_students'] = count($user_list); |
|
330 | + // Determining number of students registered in course |
|
331 | + $user_list = CourseManager::get_user_list_from_course_code($course['code'], 0); |
|
332 | + $course_tmp['number_students'] = count($user_list); |
|
333 | 333 | |
334 | - // Determining external course id - this code misses the external course id field name |
|
335 | - // $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_field_name, $course['code']); |
|
334 | + // Determining external course id - this code misses the external course id field name |
|
335 | + // $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_field_name, $course['code']); |
|
336 | 336 | |
337 | 337 | |
338 | - $courses_result[] = $course_tmp; |
|
339 | - } |
|
338 | + $courses_result[] = $course_tmp; |
|
339 | + } |
|
340 | 340 | |
341 | - return $courses_result; |
|
342 | - } |
|
343 | - } |
|
341 | + return $courses_result; |
|
342 | + } |
|
343 | + } |
|
344 | 344 | |
345 | - /** |
|
346 | - * Subscribe or unsubscribe user to a course (helper method) |
|
347 | - * |
|
348 | - * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
349 | - * @param string Course id value. |
|
350 | - * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
351 | - * @param string User id value |
|
352 | - * @param int Set to 1 to subscribe, 0 to unsubscribe |
|
353 | - * @param int Status (STUDENT or TEACHER) Used for subscription only |
|
354 | - * @return mixed True if subscription or unsubscription was successful, false otherwise |
|
355 | - */ |
|
356 | - protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) { |
|
357 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
358 | - if($course_id instanceof WSError) { |
|
359 | - return $course_id; |
|
360 | - } else { |
|
361 | - $user_id = $this->getUserId($user_id_field_name, $user_id_value); |
|
362 | - if($user_id instanceof WSError) { |
|
363 | - return $user_id; |
|
364 | - } else { |
|
365 | - $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
366 | - if($state == 0) { |
|
367 | - // Unsubscribe user |
|
368 | - CourseManager::unsubscribe_user($user_id, $course_code); |
|
369 | - return true; |
|
370 | - } else { |
|
371 | - // Subscribe user |
|
372 | - if(CourseManager::subscribe_user($user_id, $course_code, $status)) { |
|
373 | - return true; |
|
374 | - } else { |
|
375 | - return new WSError(203, 'An error occured subscribing to this course'); |
|
376 | - } |
|
377 | - } |
|
378 | - } |
|
379 | - } |
|
380 | - } |
|
345 | + /** |
|
346 | + * Subscribe or unsubscribe user to a course (helper method) |
|
347 | + * |
|
348 | + * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
349 | + * @param string Course id value. |
|
350 | + * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
351 | + * @param string User id value |
|
352 | + * @param int Set to 1 to subscribe, 0 to unsubscribe |
|
353 | + * @param int Status (STUDENT or TEACHER) Used for subscription only |
|
354 | + * @return mixed True if subscription or unsubscription was successful, false otherwise |
|
355 | + */ |
|
356 | + protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) { |
|
357 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
358 | + if($course_id instanceof WSError) { |
|
359 | + return $course_id; |
|
360 | + } else { |
|
361 | + $user_id = $this->getUserId($user_id_field_name, $user_id_value); |
|
362 | + if($user_id instanceof WSError) { |
|
363 | + return $user_id; |
|
364 | + } else { |
|
365 | + $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
366 | + if($state == 0) { |
|
367 | + // Unsubscribe user |
|
368 | + CourseManager::unsubscribe_user($user_id, $course_code); |
|
369 | + return true; |
|
370 | + } else { |
|
371 | + // Subscribe user |
|
372 | + if(CourseManager::subscribe_user($user_id, $course_code, $status)) { |
|
373 | + return true; |
|
374 | + } else { |
|
375 | + return new WSError(203, 'An error occured subscribing to this course'); |
|
376 | + } |
|
377 | + } |
|
378 | + } |
|
379 | + } |
|
380 | + } |
|
381 | 381 | |
382 | - /** |
|
383 | - * Subscribe user to a course |
|
384 | - * |
|
385 | - * @param string API secret key |
|
386 | - * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
387 | - * @param string Course id value. |
|
388 | - * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
389 | - * @param string User id value |
|
390 | - * @param int Status (1 = Teacher, 5 = Student) |
|
391 | - */ |
|
392 | - public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) { |
|
393 | - $verifKey = $this->verifyKey($secret_key); |
|
394 | - if($verifKey instanceof WSError) { |
|
395 | - $this->handleError($verifKey); |
|
396 | - } else { |
|
397 | - $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status); |
|
398 | - if($result instanceof WSError) { |
|
399 | - $this->handleError($result); |
|
400 | - } |
|
401 | - } |
|
402 | - } |
|
382 | + /** |
|
383 | + * Subscribe user to a course |
|
384 | + * |
|
385 | + * @param string API secret key |
|
386 | + * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
387 | + * @param string Course id value. |
|
388 | + * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
389 | + * @param string User id value |
|
390 | + * @param int Status (1 = Teacher, 5 = Student) |
|
391 | + */ |
|
392 | + public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) { |
|
393 | + $verifKey = $this->verifyKey($secret_key); |
|
394 | + if($verifKey instanceof WSError) { |
|
395 | + $this->handleError($verifKey); |
|
396 | + } else { |
|
397 | + $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status); |
|
398 | + if($result instanceof WSError) { |
|
399 | + $this->handleError($result); |
|
400 | + } |
|
401 | + } |
|
402 | + } |
|
403 | 403 | |
404 | - /** |
|
405 | - * Unsusbscribe user from course |
|
406 | - * |
|
407 | - * @param string API secret key |
|
408 | - * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
409 | - * @param string Course id value. |
|
410 | - * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
411 | - * @param string User id value |
|
412 | - */ |
|
413 | - public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) { |
|
414 | - $verifKey = $this->verifyKey($secret_key); |
|
415 | - if($verifKey instanceof WSError) { |
|
416 | - $this->handleError($verifKey); |
|
417 | - } else { |
|
418 | - $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0); |
|
419 | - if($result instanceof WSError) { |
|
420 | - $this->handleError($result); |
|
421 | - } |
|
422 | - } |
|
423 | - } |
|
404 | + /** |
|
405 | + * Unsusbscribe user from course |
|
406 | + * |
|
407 | + * @param string API secret key |
|
408 | + * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
409 | + * @param string Course id value. |
|
410 | + * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
411 | + * @param string User id value |
|
412 | + */ |
|
413 | + public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) { |
|
414 | + $verifKey = $this->verifyKey($secret_key); |
|
415 | + if($verifKey instanceof WSError) { |
|
416 | + $this->handleError($verifKey); |
|
417 | + } else { |
|
418 | + $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0); |
|
419 | + if($result instanceof WSError) { |
|
420 | + $this->handleError($result); |
|
421 | + } |
|
422 | + } |
|
423 | + } |
|
424 | 424 | |
425 | - /** |
|
426 | - * Returns the descriptions of a course, along with their id |
|
427 | - * |
|
428 | - * @param string API secret key |
|
429 | - * @param string Course id field name |
|
430 | - * @param string Course id value |
|
431 | - * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content') |
|
432 | - */ |
|
433 | - public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) { |
|
434 | - $verifKey = $this->verifyKey($secret_key); |
|
435 | - if($verifKey instanceof WSError) { |
|
436 | - $this->handleError($verifKey); |
|
437 | - } else { |
|
438 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
439 | - if($course_id instanceof WSError) { |
|
440 | - return $course_id; |
|
441 | - } else { |
|
442 | - // Course exists, get its descriptions |
|
443 | - $descriptions = CourseDescription::get_descriptions($course_id); |
|
444 | - $results = array(); |
|
445 | - foreach($descriptions as $description) { |
|
446 | - $results[] = array('course_desc_id' => $description->get_description_type(), |
|
447 | - 'course_desc_title' => $description->get_title(), |
|
448 | - 'course_desc_content' => $description->get_content()); |
|
449 | - } |
|
450 | - return $results; |
|
451 | - } |
|
452 | - } |
|
453 | - } |
|
425 | + /** |
|
426 | + * Returns the descriptions of a course, along with their id |
|
427 | + * |
|
428 | + * @param string API secret key |
|
429 | + * @param string Course id field name |
|
430 | + * @param string Course id value |
|
431 | + * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content') |
|
432 | + */ |
|
433 | + public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) { |
|
434 | + $verifKey = $this->verifyKey($secret_key); |
|
435 | + if($verifKey instanceof WSError) { |
|
436 | + $this->handleError($verifKey); |
|
437 | + } else { |
|
438 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
439 | + if($course_id instanceof WSError) { |
|
440 | + return $course_id; |
|
441 | + } else { |
|
442 | + // Course exists, get its descriptions |
|
443 | + $descriptions = CourseDescription::get_descriptions($course_id); |
|
444 | + $results = array(); |
|
445 | + foreach($descriptions as $description) { |
|
446 | + $results[] = array('course_desc_id' => $description->get_description_type(), |
|
447 | + 'course_desc_title' => $description->get_title(), |
|
448 | + 'course_desc_content' => $description->get_content()); |
|
449 | + } |
|
450 | + return $results; |
|
451 | + } |
|
452 | + } |
|
453 | + } |
|
454 | 454 | |
455 | 455 | |
456 | - /** |
|
457 | - * Edit course description |
|
458 | - * |
|
459 | - * @param string API secret key |
|
460 | - * @param string Course id field name |
|
461 | - * @param string Course id value |
|
462 | - * @param int Category id from course description |
|
463 | - * @param string Description title |
|
464 | - * @param string Course description content |
|
465 | - */ |
|
466 | - public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) { |
|
467 | - $verifKey = $this->verifyKey($secret_key); |
|
468 | - if($verifKey instanceof WSError) { |
|
469 | - $this->handleError($verifKey); |
|
470 | - } else { |
|
471 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
472 | - if($course_id instanceof WSError) { |
|
473 | - return $course_id; |
|
474 | - } else { |
|
475 | - // Create the new course description |
|
476 | - $cd = new CourseDescription(); |
|
477 | - $cd->set_description_type($course_desc_id); |
|
478 | - $cd->set_title($course_desc_title); |
|
479 | - $cd->set_content($course_desc_content); |
|
480 | - $cd->set_session_id(0); |
|
481 | - // Get course info |
|
482 | - $course_info = CourseManager::get_course_information(CourseManager::get_course_code_from_course_id($course_id)); |
|
456 | + /** |
|
457 | + * Edit course description |
|
458 | + * |
|
459 | + * @param string API secret key |
|
460 | + * @param string Course id field name |
|
461 | + * @param string Course id value |
|
462 | + * @param int Category id from course description |
|
463 | + * @param string Description title |
|
464 | + * @param string Course description content |
|
465 | + */ |
|
466 | + public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) { |
|
467 | + $verifKey = $this->verifyKey($secret_key); |
|
468 | + if($verifKey instanceof WSError) { |
|
469 | + $this->handleError($verifKey); |
|
470 | + } else { |
|
471 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
472 | + if($course_id instanceof WSError) { |
|
473 | + return $course_id; |
|
474 | + } else { |
|
475 | + // Create the new course description |
|
476 | + $cd = new CourseDescription(); |
|
477 | + $cd->set_description_type($course_desc_id); |
|
478 | + $cd->set_title($course_desc_title); |
|
479 | + $cd->set_content($course_desc_content); |
|
480 | + $cd->set_session_id(0); |
|
481 | + // Get course info |
|
482 | + $course_info = CourseManager::get_course_information(CourseManager::get_course_code_from_course_id($course_id)); |
|
483 | 483 | $cd->set_course_id($course_info['real_id']); |
484 | - // Check if this course description exists |
|
485 | - $descriptions = CourseDescription::get_descriptions($course_id); |
|
486 | - $exists = false; |
|
487 | - foreach($descriptions as $description) { |
|
488 | - if($description->get_description_type() == $course_desc_id) { |
|
489 | - $exists = true; |
|
490 | - } |
|
491 | - } |
|
492 | - if (!$exists) { |
|
493 | - $cd->set_progress(0); |
|
494 | - $cd->insert(); |
|
495 | - } else { |
|
496 | - $cd->update(); |
|
497 | - } |
|
498 | - } |
|
499 | - } |
|
500 | - } |
|
484 | + // Check if this course description exists |
|
485 | + $descriptions = CourseDescription::get_descriptions($course_id); |
|
486 | + $exists = false; |
|
487 | + foreach($descriptions as $description) { |
|
488 | + if($description->get_description_type() == $course_desc_id) { |
|
489 | + $exists = true; |
|
490 | + } |
|
491 | + } |
|
492 | + if (!$exists) { |
|
493 | + $cd->set_progress(0); |
|
494 | + $cd->insert(); |
|
495 | + } else { |
|
496 | + $cd->update(); |
|
497 | + } |
|
498 | + } |
|
499 | + } |
|
500 | + } |
|
501 | 501 | } |
@@ -6,24 +6,24 @@ |
||
6 | 6 | */ |
7 | 7 | class HTML_QuickForm_Compare_Fields extends HTML_QuickForm_Rule_Compare |
8 | 8 | { |
9 | - /** |
|
10 | - * Function to check an array of fields |
|
11 | - * @param array of field names |
|
9 | + /** |
|
10 | + * Function to check an array of fields |
|
11 | + * @param array of field names |
|
12 | 12 | * @param string operator ==, >=, etc |
13 | 13 | * @param string the value to compare |
14 | - * @return boolean True if date is valid |
|
15 | - */ |
|
16 | - function validate($values = [], $operator_and_max_value = null) { |
|
14 | + * @return boolean True if date is valid |
|
15 | + */ |
|
16 | + function validate($values = [], $operator_and_max_value = null) { |
|
17 | 17 | if (is_array($values) && !empty($values) && !empty($operator_and_max_value)) { |
18 | - $final_value = 0; |
|
19 | - foreach ($values as $value) { |
|
20 | - $final_value += $value; |
|
21 | - } |
|
22 | - $params = explode('@', $operator_and_max_value); |
|
23 | - $operator = $params[0]; |
|
24 | - $max_value = $params[1]; |
|
25 | - return parent::validate(array($final_value, $max_value), $operator); |
|
18 | + $final_value = 0; |
|
19 | + foreach ($values as $value) { |
|
20 | + $final_value += $value; |
|
21 | + } |
|
22 | + $params = explode('@', $operator_and_max_value); |
|
23 | + $operator = $params[0]; |
|
24 | + $max_value = $params[1]; |
|
25 | + return parent::validate(array($final_value, $max_value), $operator); |
|
26 | 26 | } |
27 | 27 | return false; |
28 | - } |
|
28 | + } |
|
29 | 29 | } |
30 | 30 | \ No newline at end of file |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | |
19 | 19 | $document_data = DocumentManager::get_document_data_by_id($_GET['id'], api_get_course_id(), true); |
20 | 20 | if (empty($document_data)) { |
21 | - if (api_is_in_group()) { |
|
22 | - $group_properties = GroupManager::get_group_properties(api_get_group_id()); |
|
23 | - $document_id = DocumentManager::get_document_id(api_get_course_info(), $group_properties['directory']); |
|
24 | - $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id()); |
|
25 | - } |
|
21 | + if (api_is_in_group()) { |
|
22 | + $group_properties = GroupManager::get_group_properties(api_get_group_id()); |
|
23 | + $document_id = DocumentManager::get_document_id(api_get_course_info(), $group_properties['directory']); |
|
24 | + $document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id()); |
|
25 | + } |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | $document_id = $document_data['id']; |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | //make some vars |
32 | 32 | $wamidir = $dir; |
33 | 33 | if ($wamidir == "/") { |
34 | - $wamidir = ""; |
|
34 | + $wamidir = ""; |
|
35 | 35 | } |
36 | 36 | $wamiurlplay = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document'.$wamidir."/"; |
37 | 37 | $groupId = api_get_group_id(); |
@@ -41,48 +41,48 @@ discard block |
||
41 | 41 | // Please, do not modify this dirname formatting |
42 | 42 | |
43 | 43 | if (strstr($dir, '..')) { |
44 | - $dir = '/'; |
|
44 | + $dir = '/'; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | if ($dir[0] == '.') { |
48 | - $dir = substr($dir, 1); |
|
48 | + $dir = substr($dir, 1); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | if ($dir[0] != '/') { |
52 | - $dir = '/'.$dir; |
|
52 | + $dir = '/'.$dir; |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | if ($dir[strlen($dir) - 1] != '/') { |
56 | - $dir .= '/'; |
|
56 | + $dir .= '/'; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir; |
60 | 60 | |
61 | 61 | if (!is_dir($filepath)) { |
62 | - $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/'; |
|
63 | - $dir = '/'; |
|
62 | + $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/'; |
|
63 | + $dir = '/'; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | //groups //TODO: clean |
67 | 67 | if (!empty($groupId)) { |
68 | - $interbreadcrumb[] = array ("url" => "../group/group_space.php?".api_get_cidreq(), "name" => get_lang('GroupSpace')); |
|
69 | - $noPHP_SELF = true; |
|
70 | - $group = GroupManager :: get_group_properties($groupId); |
|
71 | - $path = explode('/', $dir); |
|
72 | - if ('/'.$path[1] != $group['directory']) { |
|
73 | - api_not_allowed(true); |
|
74 | - } |
|
68 | + $interbreadcrumb[] = array ("url" => "../group/group_space.php?".api_get_cidreq(), "name" => get_lang('GroupSpace')); |
|
69 | + $noPHP_SELF = true; |
|
70 | + $group = GroupManager :: get_group_properties($groupId); |
|
71 | + $path = explode('/', $dir); |
|
72 | + if ('/'.$path[1] != $group['directory']) { |
|
73 | + api_not_allowed(true); |
|
74 | + } |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | $interbreadcrumb[] = array("url" => "./document.php?id=".$document_id.'&'.api_get_cidreq(), "name" => get_lang('Documents')); |
78 | 78 | |
79 | 79 | if (!$is_allowed_in_course) { |
80 | - api_not_allowed(true); |
|
80 | + api_not_allowed(true); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | if (!($is_allowed_to_edit || $_SESSION['group_member_with_upload_rights'] || |
84 | - DocumentManager::is_my_shared_folder(api_get_user_id(), Security::remove_XSS($dir),api_get_session_id()))) { |
|
85 | - api_not_allowed(true); |
|
84 | + DocumentManager::is_my_shared_folder(api_get_user_id(), Security::remove_XSS($dir),api_get_session_id()))) { |
|
85 | + api_not_allowed(true); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /* Header */ |
@@ -90,26 +90,26 @@ discard block |
||
90 | 90 | |
91 | 91 | $display_dir = $dir; |
92 | 92 | if (isset ($group)) { |
93 | - $display_dir = explode('/', $dir); |
|
94 | - unset ($display_dir[0]); |
|
95 | - unset ($display_dir[1]); |
|
96 | - $display_dir = implode('/', $display_dir); |
|
93 | + $display_dir = explode('/', $dir); |
|
94 | + unset ($display_dir[0]); |
|
95 | + unset ($display_dir[1]); |
|
96 | + $display_dir = implode('/', $display_dir); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | // Interbreadcrumb for the current directory root path |
100 | 100 | $counter = 0; |
101 | 101 | if (isset($document_data['parents'])) { |
102 | - foreach($document_data['parents'] as $document_sub_data) { |
|
103 | - //fixing double group folder in breadcrumb |
|
104 | - if (api_get_group_id()) { |
|
105 | - if ($counter == 0) { |
|
106 | - $counter++; |
|
107 | - continue; |
|
108 | - } |
|
109 | - } |
|
110 | - $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']); |
|
111 | - $counter++; |
|
112 | - } |
|
102 | + foreach($document_data['parents'] as $document_sub_data) { |
|
103 | + //fixing double group folder in breadcrumb |
|
104 | + if (api_get_group_id()) { |
|
105 | + if ($counter == 0) { |
|
106 | + $counter++; |
|
107 | + continue; |
|
108 | + } |
|
109 | + } |
|
110 | + $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']); |
|
111 | + $counter++; |
|
112 | + } |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | //make some vars |
@@ -121,12 +121,12 @@ discard block |
||
121 | 121 | $htmlHeadXtra[] = '<script type="text/javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'swfobject/swfobject.js"></script>'; |
122 | 122 | |
123 | 123 | $actions = Display::toolbarButton( |
124 | - get_lang('BackTo') . ' ' . get_lang('DocumentsOverview'), |
|
125 | - 'document.php?' . api_get_cidreq() . "&id=$document_id", |
|
126 | - 'arrow-left', |
|
127 | - 'default', |
|
128 | - [], |
|
129 | - false |
|
124 | + get_lang('BackTo') . ' ' . get_lang('DocumentsOverview'), |
|
125 | + 'document.php?' . api_get_cidreq() . "&id=$document_id", |
|
126 | + 'arrow-left', |
|
127 | + 'default', |
|
128 | + [], |
|
129 | + false |
|
130 | 130 | ); |
131 | 131 | |
132 | 132 | $template = new Template($nameTools); |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | 'changeable', |
20 | 20 | 'filter', |
21 | 21 | 'extra_field_type', |
22 | - /* Enable this when field_loggeable is introduced as a table field (2.0) |
|
22 | + /* Enable this when field_loggeable is introduced as a table field (2.0) |
|
23 | 23 | 'field_loggeable', |
24 | 24 | */ |
25 | 25 | 'created_at' |
@@ -808,7 +808,7 @@ discard block |
||
808 | 808 | foreach ($orderFields as $order) { |
809 | 809 | foreach ($extra as $field_details) { |
810 | 810 | if ($order == $field_details['variable']) { |
811 | - $newOrder[] = $field_details; |
|
811 | + $newOrder[] = $field_details; |
|
812 | 812 | } |
813 | 813 | } |
814 | 814 | } |
@@ -37,11 +37,11 @@ discard block |
||
37 | 37 | set_time_limit(0); |
38 | 38 | |
39 | 39 | if (isset($_POST['formSent'])) { |
40 | - $formSent = $_POST['formSent']; |
|
41 | - $file_type = isset($_POST['file_type']) ? $_POST['file_type'] : 'csv'; |
|
42 | - $session_id = $_POST['session_id']; |
|
43 | - if (empty($session_id)) { |
|
44 | - $sql = "SELECT |
|
40 | + $formSent = $_POST['formSent']; |
|
41 | + $file_type = isset($_POST['file_type']) ? $_POST['file_type'] : 'csv'; |
|
42 | + $session_id = $_POST['session_id']; |
|
43 | + if (empty($session_id)) { |
|
44 | + $sql = "SELECT |
|
45 | 45 | s.id, |
46 | 46 | name, |
47 | 47 | id_coach, |
@@ -55,84 +55,84 @@ discard block |
||
55 | 55 | ON $tbl_user.user_id = s.id_coach |
56 | 56 | ORDER BY id"; |
57 | 57 | |
58 | - if (api_is_multiple_url_enabled()) { |
|
59 | - $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
|
60 | - $access_url_id = api_get_current_access_url_id(); |
|
61 | - if ($access_url_id != -1){ |
|
62 | - $sql = "SELECT s.id, name,id_coach,username,access_start_date,access_end_date,visibility,session_category_id |
|
58 | + if (api_is_multiple_url_enabled()) { |
|
59 | + $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
|
60 | + $access_url_id = api_get_current_access_url_id(); |
|
61 | + if ($access_url_id != -1){ |
|
62 | + $sql = "SELECT s.id, name,id_coach,username,access_start_date,access_end_date,visibility,session_category_id |
|
63 | 63 | FROM $tbl_session s |
64 | 64 | INNER JOIN $tbl_session_rel_access_url as session_rel_url |
65 | 65 | ON (s.id= session_rel_url.session_id) |
66 | 66 | INNER JOIN $tbl_user u ON (u.user_id = s.id_coach) |
67 | 67 | WHERE access_url_id = $access_url_id |
68 | 68 | ORDER BY id"; |
69 | - } |
|
70 | - } |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - $result = Database::query($sql); |
|
73 | - } else { |
|
74 | - $sql = "SELECT s.id,name,username,access_start_date,access_end_date,visibility,session_category_id |
|
72 | + $result = Database::query($sql); |
|
73 | + } else { |
|
74 | + $sql = "SELECT s.id,name,username,access_start_date,access_end_date,visibility,session_category_id |
|
75 | 75 | FROM $tbl_session s |
76 | 76 | INNER JOIN $tbl_user |
77 | 77 | ON $tbl_user.user_id = s.id_coach |
78 | 78 | WHERE id='$session_id'"; |
79 | - $result = Database::query($sql); |
|
80 | - } |
|
79 | + $result = Database::query($sql); |
|
80 | + } |
|
81 | 81 | |
82 | - if (Database::num_rows($result)) { |
|
82 | + if (Database::num_rows($result)) { |
|
83 | 83 | |
84 | 84 | |
85 | 85 | |
86 | - $sessionListToExport = []; |
|
86 | + $sessionListToExport = []; |
|
87 | 87 | |
88 | - if (in_array($file_type, ['csv', 'xls'])) { |
|
88 | + if (in_array($file_type, ['csv', 'xls'])) { |
|
89 | 89 | |
90 | - $archiveFile = 'export_sessions_'.$session_id.'_'.api_get_local_time(); |
|
90 | + $archiveFile = 'export_sessions_'.$session_id.'_'.api_get_local_time(); |
|
91 | 91 | |
92 | - $cvs = true; |
|
93 | - $sessionListToExport[] = [ |
|
94 | - 'SessionName', |
|
95 | - 'Coach', |
|
96 | - 'DateStart', |
|
97 | - 'DateEnd', |
|
98 | - 'Visibility', |
|
99 | - 'SessionCategory', |
|
100 | - 'Users', |
|
101 | - 'Courses' |
|
102 | - ]; |
|
103 | - } else { |
|
104 | - if (!file_exists($archivePath)) { |
|
105 | - mkdir($archivePath, api_get_permissions_for_new_directories(), true); |
|
106 | - } |
|
92 | + $cvs = true; |
|
93 | + $sessionListToExport[] = [ |
|
94 | + 'SessionName', |
|
95 | + 'Coach', |
|
96 | + 'DateStart', |
|
97 | + 'DateEnd', |
|
98 | + 'Visibility', |
|
99 | + 'SessionCategory', |
|
100 | + 'Users', |
|
101 | + 'Courses' |
|
102 | + ]; |
|
103 | + } else { |
|
104 | + if (!file_exists($archivePath)) { |
|
105 | + mkdir($archivePath, api_get_permissions_for_new_directories(), true); |
|
106 | + } |
|
107 | 107 | |
108 | - if (!file_exists($archivePath.'index.html')) { |
|
109 | - $fp = fopen($archivePath.'index.html', 'w'); |
|
110 | - fputs($fp, '<html><head></head><body></body></html>'); |
|
111 | - fclose($fp); |
|
112 | - } |
|
108 | + if (!file_exists($archivePath.'index.html')) { |
|
109 | + $fp = fopen($archivePath.'index.html', 'w'); |
|
110 | + fputs($fp, '<html><head></head><body></body></html>'); |
|
111 | + fclose($fp); |
|
112 | + } |
|
113 | 113 | |
114 | - $archiveFile = 'export_sessions_'.$session_id.'_'.api_get_local_time().'.'.$file_type; |
|
115 | - while (file_exists($archivePath.$archiveFile)) { |
|
116 | - $archiveFile ='export_users_'.$session_id.'_'.api_get_local_time().'_'.uniqid('').'.'.$file_type; |
|
117 | - } |
|
114 | + $archiveFile = 'export_sessions_'.$session_id.'_'.api_get_local_time().'.'.$file_type; |
|
115 | + while (file_exists($archivePath.$archiveFile)) { |
|
116 | + $archiveFile ='export_users_'.$session_id.'_'.api_get_local_time().'_'.uniqid('').'.'.$file_type; |
|
117 | + } |
|
118 | 118 | |
119 | - $cvs = false; |
|
120 | - $fp = fopen($archivePath.$archiveFile, 'w'); |
|
121 | - fputs($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Sessions>\n"); |
|
122 | - } |
|
119 | + $cvs = false; |
|
120 | + $fp = fopen($archivePath.$archiveFile, 'w'); |
|
121 | + fputs($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Sessions>\n"); |
|
122 | + } |
|
123 | 123 | |
124 | 124 | |
125 | - while ($row = Database::fetch_array($result)) { |
|
126 | - $row['name'] = str_replace(';',',',$row['name']); |
|
127 | - $row['username'] = str_replace(';',',',$row['username']); |
|
128 | - $row['access_start_date'] = str_replace(';',',',$row['access_start_date']); |
|
129 | - $row['access_end_date'] = str_replace(';',',',$row['access_end_date']); |
|
130 | - $row['visibility'] = str_replace(';',',',$row['visibility']); |
|
131 | - $row['session_category'] = str_replace(';',',',$row['session_category_id']); |
|
125 | + while ($row = Database::fetch_array($result)) { |
|
126 | + $row['name'] = str_replace(';',',',$row['name']); |
|
127 | + $row['username'] = str_replace(';',',',$row['username']); |
|
128 | + $row['access_start_date'] = str_replace(';',',',$row['access_start_date']); |
|
129 | + $row['access_end_date'] = str_replace(';',',',$row['access_end_date']); |
|
130 | + $row['visibility'] = str_replace(';',',',$row['visibility']); |
|
131 | + $row['session_category'] = str_replace(';',',',$row['session_category_id']); |
|
132 | 132 | |
133 | 133 | |
134 | - // users |
|
135 | - $sql = "SELECT DISTINCT $tbl_user.username |
|
134 | + // users |
|
135 | + $sql = "SELECT DISTINCT $tbl_user.username |
|
136 | 136 | FROM $tbl_user |
137 | 137 | INNER JOIN $tbl_session_user |
138 | 138 | ON |
@@ -140,33 +140,33 @@ discard block |
||
140 | 140 | $tbl_session_user.relation_type<>".SESSION_RELATION_TYPE_RRHH." AND |
141 | 141 | $tbl_session_user.session_id = '".$row['id']."'"; |
142 | 142 | |
143 | - $rsUsers = Database::query($sql); |
|
144 | - $users = ''; |
|
145 | - while ($rowUsers = Database::fetch_array($rsUsers)){ |
|
146 | - if($cvs){ |
|
147 | - $users .= str_replace(';',',',$rowUsers['username']).'|'; |
|
148 | - } else { |
|
149 | - $users .= "\t\t<User>$rowUsers[username]</User>\n"; |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - if (!empty($users) && $cvs) { |
|
154 | - $users = api_substr($users, 0, api_strlen($users) - 1); |
|
155 | - } |
|
156 | - |
|
157 | - // Courses |
|
158 | - $sql = "SELECT DISTINCT c.code, sc.id, c_id |
|
143 | + $rsUsers = Database::query($sql); |
|
144 | + $users = ''; |
|
145 | + while ($rowUsers = Database::fetch_array($rsUsers)){ |
|
146 | + if($cvs){ |
|
147 | + $users .= str_replace(';',',',$rowUsers['username']).'|'; |
|
148 | + } else { |
|
149 | + $users .= "\t\t<User>$rowUsers[username]</User>\n"; |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + if (!empty($users) && $cvs) { |
|
154 | + $users = api_substr($users, 0, api_strlen($users) - 1); |
|
155 | + } |
|
156 | + |
|
157 | + // Courses |
|
158 | + $sql = "SELECT DISTINCT c.code, sc.id, c_id |
|
159 | 159 | FROM $tbl_course c |
160 | 160 | INNER JOIN $tbl_session_course_user sc |
161 | 161 | ON c.id = sc.c_id |
162 | 162 | AND sc.session_id = '".$row['id']."'"; |
163 | 163 | |
164 | - $rsCourses = Database::query($sql); |
|
164 | + $rsCourses = Database::query($sql); |
|
165 | 165 | |
166 | - $courses = ''; |
|
167 | - while ($rowCourses = Database::fetch_array($rsCourses)) { |
|
168 | - // get coachs from a course |
|
169 | - $sql = "SELECT u.username |
|
166 | + $courses = ''; |
|
167 | + while ($rowCourses = Database::fetch_array($rsCourses)) { |
|
168 | + // get coachs from a course |
|
169 | + $sql = "SELECT u.username |
|
170 | 170 | FROM $tbl_session_course_user scu |
171 | 171 | INNER JOIN $tbl_user u |
172 | 172 | ON u.user_id = scu.user_id |
@@ -175,25 +175,25 @@ discard block |
||
175 | 175 | scu.session_id = '".$row['id']."' AND |
176 | 176 | scu.status = 2 "; |
177 | 177 | |
178 | - $rs_coachs = Database::query($sql); |
|
179 | - $coachs = array(); |
|
180 | - while ($row_coachs = Database::fetch_array($rs_coachs)) { |
|
181 | - $coachs[] = $row_coachs['username']; |
|
182 | - } |
|
183 | - |
|
184 | - $coachs = implode(",", $coachs); |
|
185 | - |
|
186 | - if ($cvs) { |
|
187 | - $courses .= str_replace(';',',',$rowCourses['code']); |
|
188 | - $courses .= '['.str_replace(';',',',$coachs).']['; |
|
189 | - } else { |
|
190 | - $courses .= "\t\t<Course>\n"; |
|
191 | - $courses .= "\t\t\t<CourseCode>$rowCourses[code]</CourseCode>\n"; |
|
192 | - $courses .= "\t\t\t<Coach>$coachs</Coach>\n"; |
|
193 | - } |
|
194 | - |
|
195 | - // rel user courses |
|
196 | - $sql = "SELECT DISTINCT u.username |
|
178 | + $rs_coachs = Database::query($sql); |
|
179 | + $coachs = array(); |
|
180 | + while ($row_coachs = Database::fetch_array($rs_coachs)) { |
|
181 | + $coachs[] = $row_coachs['username']; |
|
182 | + } |
|
183 | + |
|
184 | + $coachs = implode(",", $coachs); |
|
185 | + |
|
186 | + if ($cvs) { |
|
187 | + $courses .= str_replace(';',',',$rowCourses['code']); |
|
188 | + $courses .= '['.str_replace(';',',',$coachs).']['; |
|
189 | + } else { |
|
190 | + $courses .= "\t\t<Course>\n"; |
|
191 | + $courses .= "\t\t\t<CourseCode>$rowCourses[code]</CourseCode>\n"; |
|
192 | + $courses .= "\t\t\t<Coach>$coachs</Coach>\n"; |
|
193 | + } |
|
194 | + |
|
195 | + // rel user courses |
|
196 | + $sql = "SELECT DISTINCT u.username |
|
197 | 197 | FROM $tbl_session_course_user scu |
198 | 198 | INNER JOIN $tbl_session_user su |
199 | 199 | ON |
@@ -206,79 +206,79 @@ discard block |
||
206 | 206 | scu.c_id='".$rowCourses['c_id']."' AND |
207 | 207 | scu.session_id='".$row['id']."'"; |
208 | 208 | |
209 | - $rsUsersCourse = Database::query($sql); |
|
210 | - $userscourse = ''; |
|
211 | - while ($rowUsersCourse = Database::fetch_array($rsUsersCourse)){ |
|
212 | - if ($cvs) { |
|
213 | - $userscourse .= str_replace(';',',',$rowUsersCourse['username']).','; |
|
214 | - } else { |
|
215 | - $courses .= "\t\t\t<User>$rowUsersCourse[username]</User>\n"; |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - if ($cvs) { |
|
220 | - if (!empty($userscourse)) { |
|
221 | - $userscourse = api_substr( |
|
222 | - $userscourse, |
|
223 | - 0, |
|
224 | - api_strlen($userscourse) - 1 |
|
225 | - ); |
|
226 | - } |
|
227 | - |
|
228 | - $courses .= $userscourse.']|'; |
|
229 | - } else { |
|
230 | - $courses .= "\t\t</Course>\n"; |
|
231 | - } |
|
232 | - } |
|
233 | - |
|
234 | - if (!empty($courses) && $cvs) { |
|
235 | - $courses = api_substr($courses, 0, api_strlen($courses) - 1); |
|
236 | - } |
|
237 | - $add = $courses; |
|
238 | - |
|
239 | - if (in_array($file_type, ['csv', 'xls'])) { |
|
240 | - $sessionListToExport[] = [ |
|
241 | - $row['name'], |
|
242 | - $row['username'], |
|
243 | - $row['access_start_date'], |
|
244 | - $row['access_end_date'], |
|
245 | - $row['visibility'], |
|
246 | - $row['session_category'], |
|
247 | - $users, |
|
248 | - $courses |
|
249 | - ]; |
|
250 | - } else { |
|
251 | - $add = "\t<Session>\n" |
|
252 | - ."\t\t<SessionName>$row[name]</SessionName>\n" |
|
253 | - ."\t\t<Coach>$row[username]</Coach>\n" |
|
254 | - ."\t\t<DateStart>$row[access_start_date]</DateStart>\n" |
|
255 | - ."\t\t<DateEnd>$row[access_end_date]</DateEnd>\n" |
|
256 | - ."\t\t<Visibility>$row[visibility]</Visibility>\n" |
|
257 | - ."\t\t<SessionCategory>$row[session_category]</SessionCategory>\n"; |
|
258 | - } |
|
259 | - |
|
260 | - if (!$cvs) { |
|
261 | - $add .= "\t</Session>\n"; |
|
262 | - fputs($fp, $add); |
|
263 | - } |
|
264 | - } |
|
265 | - |
|
266 | - switch ($file_type) { |
|
267 | - case 'xml': |
|
268 | - fputs($fp, "</Sessions>\n"); |
|
269 | - fclose($fp); |
|
270 | - $errorMsg = get_lang('UserListHasBeenExported').'<br/> |
|
209 | + $rsUsersCourse = Database::query($sql); |
|
210 | + $userscourse = ''; |
|
211 | + while ($rowUsersCourse = Database::fetch_array($rsUsersCourse)){ |
|
212 | + if ($cvs) { |
|
213 | + $userscourse .= str_replace(';',',',$rowUsersCourse['username']).','; |
|
214 | + } else { |
|
215 | + $courses .= "\t\t\t<User>$rowUsersCourse[username]</User>\n"; |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + if ($cvs) { |
|
220 | + if (!empty($userscourse)) { |
|
221 | + $userscourse = api_substr( |
|
222 | + $userscourse, |
|
223 | + 0, |
|
224 | + api_strlen($userscourse) - 1 |
|
225 | + ); |
|
226 | + } |
|
227 | + |
|
228 | + $courses .= $userscourse.']|'; |
|
229 | + } else { |
|
230 | + $courses .= "\t\t</Course>\n"; |
|
231 | + } |
|
232 | + } |
|
233 | + |
|
234 | + if (!empty($courses) && $cvs) { |
|
235 | + $courses = api_substr($courses, 0, api_strlen($courses) - 1); |
|
236 | + } |
|
237 | + $add = $courses; |
|
238 | + |
|
239 | + if (in_array($file_type, ['csv', 'xls'])) { |
|
240 | + $sessionListToExport[] = [ |
|
241 | + $row['name'], |
|
242 | + $row['username'], |
|
243 | + $row['access_start_date'], |
|
244 | + $row['access_end_date'], |
|
245 | + $row['visibility'], |
|
246 | + $row['session_category'], |
|
247 | + $users, |
|
248 | + $courses |
|
249 | + ]; |
|
250 | + } else { |
|
251 | + $add = "\t<Session>\n" |
|
252 | + ."\t\t<SessionName>$row[name]</SessionName>\n" |
|
253 | + ."\t\t<Coach>$row[username]</Coach>\n" |
|
254 | + ."\t\t<DateStart>$row[access_start_date]</DateStart>\n" |
|
255 | + ."\t\t<DateEnd>$row[access_end_date]</DateEnd>\n" |
|
256 | + ."\t\t<Visibility>$row[visibility]</Visibility>\n" |
|
257 | + ."\t\t<SessionCategory>$row[session_category]</SessionCategory>\n"; |
|
258 | + } |
|
259 | + |
|
260 | + if (!$cvs) { |
|
261 | + $add .= "\t</Session>\n"; |
|
262 | + fputs($fp, $add); |
|
263 | + } |
|
264 | + } |
|
265 | + |
|
266 | + switch ($file_type) { |
|
267 | + case 'xml': |
|
268 | + fputs($fp, "</Sessions>\n"); |
|
269 | + fclose($fp); |
|
270 | + $errorMsg = get_lang('UserListHasBeenExported').'<br/> |
|
271 | 271 | <a class="btn btn-default" href="'.$archiveURL.$archiveFile.'">'.get_lang('ClickHereToDownloadTheFile').'</a>'; |
272 | - break; |
|
273 | - case 'csv': |
|
274 | - Export::arrayToCsv($sessionListToExport, $archiveFile); |
|
275 | - exit; |
|
276 | - case 'xls': |
|
277 | - Export::arrayToXls($sessionListToExport, $archiveFile); |
|
278 | - exit; |
|
279 | - break; |
|
280 | - } |
|
281 | - } |
|
272 | + break; |
|
273 | + case 'csv': |
|
274 | + Export::arrayToCsv($sessionListToExport, $archiveFile); |
|
275 | + exit; |
|
276 | + case 'xls': |
|
277 | + Export::arrayToXls($sessionListToExport, $archiveFile); |
|
278 | + exit; |
|
279 | + break; |
|
280 | + } |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | // display the header |
@@ -288,26 +288,26 @@ discard block |
||
288 | 288 | $sql = "SELECT id, name FROM $tbl_session ORDER BY name"; |
289 | 289 | |
290 | 290 | if (api_is_multiple_url_enabled()) { |
291 | - $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
|
292 | - $access_url_id = api_get_current_access_url_id(); |
|
293 | - if ($access_url_id != -1){ |
|
294 | - $sql = "SELECT s.id, name FROM $tbl_session s |
|
291 | + $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
|
292 | + $access_url_id = api_get_current_access_url_id(); |
|
293 | + if ($access_url_id != -1){ |
|
294 | + $sql = "SELECT s.id, name FROM $tbl_session s |
|
295 | 295 | INNER JOIN $tbl_session_rel_access_url as session_rel_url |
296 | 296 | ON (s.id = session_rel_url.session_id) |
297 | 297 | WHERE access_url_id = $access_url_id |
298 | 298 | ORDER BY name"; |
299 | - } |
|
299 | + } |
|
300 | 300 | } |
301 | 301 | $result = Database::query($sql); |
302 | 302 | $Sessions = Database::store_result($result); |
303 | 303 | |
304 | 304 | echo '<div class="actions">'; |
305 | 305 | echo '<a href="../session/session_list.php">'. |
306 | - Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('SessionList'),'',ICON_SIZE_MEDIUM).'</a>'; |
|
306 | + Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('SessionList'),'',ICON_SIZE_MEDIUM).'</a>'; |
|
307 | 307 | echo '</div>'; |
308 | 308 | |
309 | 309 | if (!empty($errorMsg)) { |
310 | - Display::display_normal_message($errorMsg, false); //main API |
|
310 | + Display::display_normal_message($errorMsg, false); //main API |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | $form = new FormValidator('session_export', 'post', api_get_self()); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | $sessionId = api_get_session_id(); |
70 | 70 | |
71 | 71 | if (api_is_in_group()) { |
72 | - $group_properties = GroupManager::get_group_properties($group_id); |
|
72 | + $group_properties = GroupManager::get_group_properties($group_id); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | $dir = '/'; |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | $_GET['id'], |
82 | 82 | api_get_course_id(), |
83 | 83 | true, |
84 | - 0 |
|
84 | + 0 |
|
85 | 85 | ); |
86 | 86 | |
87 | 87 | if (!empty($sessionId) && empty($document_data)) { |
@@ -93,13 +93,13 @@ discard block |
||
93 | 93 | ); |
94 | 94 | } |
95 | 95 | |
96 | - $document_id = $document_data['id']; |
|
97 | - $file = $document_data['path']; |
|
98 | - $parent_id = DocumentManager::get_document_id($course_info, dirname($file)); |
|
99 | - $dir = dirname($document_data['path']); |
|
100 | - $dir_original = $dir; |
|
101 | - $doc = basename($file); |
|
102 | - $readonly = $document_data['readonly']; |
|
96 | + $document_id = $document_data['id']; |
|
97 | + $file = $document_data['path']; |
|
98 | + $parent_id = DocumentManager::get_document_id($course_info, dirname($file)); |
|
99 | + $dir = dirname($document_data['path']); |
|
100 | + $dir_original = $dir; |
|
101 | + $doc = basename($file); |
|
102 | + $readonly = $document_data['readonly']; |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | if (empty($document_data)) { |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | |
122 | 122 | // Level correction for group documents. |
123 | 123 | if (!empty($group_properties['directory'])) { |
124 | - $count_dir = $count_dir > 0 ? $count_dir - 1 : 0; |
|
124 | + $count_dir = $count_dir > 0 ? $count_dir - 1 : 0; |
|
125 | 125 | } |
126 | 126 | $relative_url = ''; |
127 | 127 | for ($i = 0; $i < ($count_dir); $i++) { |
@@ -143,13 +143,13 @@ discard block |
||
143 | 143 | ); |
144 | 144 | |
145 | 145 | if ($is_certificate_mode) { |
146 | - $editorConfig['CreateDocumentDir'] = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/'; |
|
147 | - $editorConfig['CreateDocumentWebDir'] = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/'; |
|
148 | - $editorConfig['BaseHref'] = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$dir; |
|
146 | + $editorConfig['CreateDocumentDir'] = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/'; |
|
147 | + $editorConfig['CreateDocumentWebDir'] = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/'; |
|
148 | + $editorConfig['BaseHref'] = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$dir; |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | $is_allowed_to_edit = api_is_allowed_to_edit(null, true) || $_SESSION['group_member_with_upload_rights']|| |
152 | - DocumentManager::is_my_shared_folder(api_get_user_id(), $dir, $sessionId); |
|
152 | + DocumentManager::is_my_shared_folder(api_get_user_id(), $dir, $sessionId); |
|
153 | 153 | $noPHP_SELF = true; |
154 | 154 | |
155 | 155 | /* Other initialization code */ |
@@ -162,8 +162,8 @@ discard block |
||
162 | 162 | 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(), |
163 | 163 | 'name' => get_lang('GroupSpace'), |
164 | 164 | ); |
165 | - $group_document = true; |
|
166 | - $noPHP_SELF = true; |
|
165 | + $group_document = true; |
|
166 | + $noPHP_SELF = true; |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | if (!$is_certificate_mode) { |
@@ -197,9 +197,9 @@ discard block |
||
197 | 197 | |
198 | 198 | //TODO:check the below code and his funcionality |
199 | 199 | if (!api_is_allowed_to_edit()) { |
200 | - if (DocumentManager::check_readonly($course_info, $user_id, $file)) { |
|
201 | - api_not_allowed(); |
|
202 | - } |
|
200 | + if (DocumentManager::check_readonly($course_info, $user_id, $file)) { |
|
201 | + api_not_allowed(); |
|
202 | + } |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /* MAIN TOOL CODE */ |
@@ -207,18 +207,18 @@ discard block |
||
207 | 207 | /* Code to change the comment */ |
208 | 208 | |
209 | 209 | if (isset($_POST['comment'])) { |
210 | - // Fixing the path if it is wrong |
|
211 | - $comment = trim($_POST['comment']); |
|
212 | - $title = trim($_POST['title']); |
|
210 | + // Fixing the path if it is wrong |
|
211 | + $comment = trim($_POST['comment']); |
|
212 | + $title = trim($_POST['title']); |
|
213 | 213 | |
214 | 214 | // Just in case see BT#3525 |
215 | 215 | if (empty($title)) { |
216 | - $title = $document_data['title']; |
|
217 | - } |
|
216 | + $title = $document_data['title']; |
|
217 | + } |
|
218 | 218 | |
219 | - if (empty($title)) { |
|
220 | - $title = get_document_title($_POST['filename']); |
|
221 | - } |
|
219 | + if (empty($title)) { |
|
220 | + $title = get_document_title($_POST['filename']); |
|
221 | + } |
|
222 | 222 | |
223 | 223 | if (!empty($document_id)) { |
224 | 224 | $params = [ |
@@ -230,43 +230,43 @@ discard block |
||
230 | 230 | $params, |
231 | 231 | ['c_id = ? AND id = ?' => [$course_id, $document_id]] |
232 | 232 | ); |
233 | - Display::addFlash(Display::return_message(get_lang('fileModified'))); |
|
233 | + Display::addFlash(Display::return_message(get_lang('fileModified'))); |
|
234 | 234 | } |
235 | 235 | } |
236 | 236 | |
237 | 237 | /* WYSIWYG HTML EDITOR - Program Logic */ |
238 | 238 | if ($is_allowed_to_edit) { |
239 | - if (isset($_POST['formSent']) && $_POST['formSent'] == 1) { |
|
239 | + if (isset($_POST['formSent']) && $_POST['formSent'] == 1) { |
|
240 | 240 | |
241 | - $filename = stripslashes($_POST['filename']); |
|
241 | + $filename = stripslashes($_POST['filename']); |
|
242 | 242 | $extension = $_POST['extension']; |
243 | - $content = isset($_POST['content']) ? trim(str_replace(array("\r", "\n"), '', stripslashes($_POST['content']))) : null; |
|
244 | - $content = Security::remove_XSS($content, COURSEMANAGERLOWSECURITY); |
|
243 | + $content = isset($_POST['content']) ? trim(str_replace(array("\r", "\n"), '', stripslashes($_POST['content']))) : null; |
|
244 | + $content = Security::remove_XSS($content, COURSEMANAGERLOWSECURITY); |
|
245 | 245 | |
246 | 246 | if ($dir == '/') { |
247 | 247 | $dir = ''; |
248 | 248 | } |
249 | 249 | |
250 | - $file = $dir.'/'.$filename.'.'.$extension; |
|
251 | - $read_only_flag = isset($_POST['readonly']) ? $_POST['readonly'] : null; |
|
252 | - $read_only_flag = empty($read_only_flag) ? 0 : 1; |
|
250 | + $file = $dir.'/'.$filename.'.'.$extension; |
|
251 | + $read_only_flag = isset($_POST['readonly']) ? $_POST['readonly'] : null; |
|
252 | + $read_only_flag = empty($read_only_flag) ? 0 : 1; |
|
253 | 253 | |
254 | - if (empty($filename)) { |
|
254 | + if (empty($filename)) { |
|
255 | 255 | Display::addFlash(Display::return_message(get_lang('NoFileName'), 'warning')); |
256 | - } else { |
|
256 | + } else { |
|
257 | 257 | |
258 | - $file_size = filesize($document_data['absolute_path']); |
|
258 | + $file_size = filesize($document_data['absolute_path']); |
|
259 | 259 | |
260 | - if ($read_only_flag == 0) { |
|
261 | - if (!empty($content)) { |
|
262 | - if ($fp = @fopen($document_data['absolute_path'], 'w')) { |
|
263 | - // For flv player, change absolute path temporarily to prevent from erasing it in the following lines |
|
264 | - $content = str_replace(array('flv=h', 'flv=/'), array('flv=h|', 'flv=/|'), $content); |
|
265 | - fputs($fp, $content); |
|
266 | - fclose($fp); |
|
260 | + if ($read_only_flag == 0) { |
|
261 | + if (!empty($content)) { |
|
262 | + if ($fp = @fopen($document_data['absolute_path'], 'w')) { |
|
263 | + // For flv player, change absolute path temporarily to prevent from erasing it in the following lines |
|
264 | + $content = str_replace(array('flv=h', 'flv=/'), array('flv=h|', 'flv=/|'), $content); |
|
265 | + fputs($fp, $content); |
|
266 | + fclose($fp); |
|
267 | 267 | |
268 | 268 | $filepath = $document_data['absolute_parent_path']; |
269 | - /* |
|
269 | + /* |
|
270 | 270 | if (!is_dir($filepath.'css')) { |
271 | 271 | mkdir($filepath.'css', api_get_permissions_for_new_directories()); |
272 | 272 | $doc_id = add_document($_course, $dir.'css', 'folder', 0, 'css'); |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | ); |
297 | 297 | }*/ |
298 | 298 | |
299 | - /*if (!is_file($filepath.'css/frames.css')) { |
|
299 | + /*if (!is_file($filepath.'css/frames.css')) { |
|
300 | 300 | $platform_theme = api_get_setting('stylesheets'); |
301 | 301 | if (file_exists(api_get_path(SYS_CODE_PATH).'css/'.$platform_theme.'/frames.css')) { |
302 | 302 | copy(api_get_path(SYS_CODE_PATH).'css/'.$platform_theme.'/frames.css', $filepath.'css/frames.css'); |
@@ -334,54 +334,54 @@ discard block |
||
334 | 334 | } |
335 | 335 | }*/ |
336 | 336 | |
337 | - // "WHAT'S NEW" notification: update table item_property |
|
338 | - $document_id = DocumentManager::get_document_id($_course, $file); |
|
339 | - |
|
340 | - if ($document_id) { |
|
341 | - update_existing_document( |
|
342 | - $_course, |
|
343 | - $document_id, |
|
344 | - $file_size, |
|
345 | - $read_only_flag |
|
346 | - ); |
|
347 | - api_item_property_update( |
|
348 | - $_course, |
|
349 | - TOOL_DOCUMENT, |
|
350 | - $document_id, |
|
351 | - 'DocumentUpdated', |
|
352 | - api_get_user_id(), |
|
353 | - null, |
|
354 | - null, |
|
355 | - null, |
|
356 | - null, |
|
357 | - $sessionId |
|
358 | - ); |
|
359 | - // Update parent folders |
|
360 | - item_property_update_on_folder( |
|
361 | - $_course, |
|
362 | - $dir, |
|
363 | - api_get_user_id() |
|
364 | - ); |
|
365 | - header('Location: document.php?id=' . $document_data['parent_id'] . '&' . api_get_cidreq() . ($is_certificate_mode?'&curdirpath=/certificates&selectcat=1':'')); |
|
366 | - exit; |
|
367 | - } else { |
|
337 | + // "WHAT'S NEW" notification: update table item_property |
|
338 | + $document_id = DocumentManager::get_document_id($_course, $file); |
|
339 | + |
|
340 | + if ($document_id) { |
|
341 | + update_existing_document( |
|
342 | + $_course, |
|
343 | + $document_id, |
|
344 | + $file_size, |
|
345 | + $read_only_flag |
|
346 | + ); |
|
347 | + api_item_property_update( |
|
348 | + $_course, |
|
349 | + TOOL_DOCUMENT, |
|
350 | + $document_id, |
|
351 | + 'DocumentUpdated', |
|
352 | + api_get_user_id(), |
|
353 | + null, |
|
354 | + null, |
|
355 | + null, |
|
356 | + null, |
|
357 | + $sessionId |
|
358 | + ); |
|
359 | + // Update parent folders |
|
360 | + item_property_update_on_folder( |
|
361 | + $_course, |
|
362 | + $dir, |
|
363 | + api_get_user_id() |
|
364 | + ); |
|
365 | + header('Location: document.php?id=' . $document_data['parent_id'] . '&' . api_get_cidreq() . ($is_certificate_mode?'&curdirpath=/certificates&selectcat=1':'')); |
|
366 | + exit; |
|
367 | + } else { |
|
368 | 368 | Display::addFlash(Display::return_message(get_lang('Impossible'), 'warning')); |
369 | - } |
|
370 | - } else { |
|
369 | + } |
|
370 | + } else { |
|
371 | 371 | Display::addFlash(Display::return_message(get_lang('Impossible'), 'warning')); |
372 | - } |
|
373 | - } else { |
|
374 | - if ($document_id) { |
|
372 | + } |
|
373 | + } else { |
|
374 | + if ($document_id) { |
|
375 | 375 | update_existing_document($_course, $document_id, $file_size, $read_only_flag); |
376 | - } |
|
377 | - } |
|
378 | - } else { |
|
376 | + } |
|
377 | + } |
|
378 | + } else { |
|
379 | 379 | if ($document_id) { |
380 | 380 | update_existing_document($_course, $document_id, $file_size, $read_only_flag); |
381 | 381 | } |
382 | - } |
|
383 | - } |
|
384 | - } |
|
382 | + } |
|
383 | + } |
|
384 | + } |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | // Replace relative paths by absolute web paths (e.g. './' => 'http://www.chamilo.org/courses/ABC/document/') |
@@ -435,35 +435,35 @@ discard block |
||
435 | 435 | api_get_group_id() |
436 | 436 | ) |
437 | 437 | ) { |
438 | - $action = api_get_self().'?id='.$document_data['id'].'&'.api_get_cidreq(); |
|
438 | + $action = api_get_self().'?id='.$document_data['id'].'&'.api_get_cidreq(); |
|
439 | 439 | if ($is_certificate_mode) { |
440 | 440 | $action .= '&curdirpath=/certificates&selectcat=1'; |
441 | 441 | } |
442 | - $form = new FormValidator('formEdit', 'post', $action, null, array('class' => 'form-vertical')); |
|
443 | - |
|
444 | - // Form title |
|
445 | - $form->addElement('header', $nameTools); |
|
446 | - $form->addElement('hidden', 'filename'); |
|
447 | - $form->addElement('hidden', 'extension'); |
|
448 | - $form->addElement('hidden', 'file_path'); |
|
449 | - $form->addElement('hidden', 'commentPath'); |
|
450 | - $form->addElement('hidden', 'showedit'); |
|
451 | - $form->addElement('hidden', 'origin'); |
|
452 | - $form->addElement('hidden', 'origin_opt'); |
|
442 | + $form = new FormValidator('formEdit', 'post', $action, null, array('class' => 'form-vertical')); |
|
443 | + |
|
444 | + // Form title |
|
445 | + $form->addElement('header', $nameTools); |
|
446 | + $form->addElement('hidden', 'filename'); |
|
447 | + $form->addElement('hidden', 'extension'); |
|
448 | + $form->addElement('hidden', 'file_path'); |
|
449 | + $form->addElement('hidden', 'commentPath'); |
|
450 | + $form->addElement('hidden', 'showedit'); |
|
451 | + $form->addElement('hidden', 'origin'); |
|
452 | + $form->addElement('hidden', 'origin_opt'); |
|
453 | 453 | $form->addText('title', get_lang('Title'), true, array('cols-size' => [2, 10, 0], 'autofocus')); |
454 | 454 | |
455 | - $defaults['title'] = $document_data['title']; |
|
455 | + $defaults['title'] = $document_data['title']; |
|
456 | 456 | |
457 | - $form->addElement('hidden', 'formSent'); |
|
458 | - $defaults['formSent'] = 1; |
|
457 | + $form->addElement('hidden', 'formSent'); |
|
458 | + $defaults['formSent'] = 1; |
|
459 | 459 | |
460 | - $read_only_flag = isset($_POST['readonly']) ? $_POST['readonly'] : null; |
|
460 | + $read_only_flag = isset($_POST['readonly']) ? $_POST['readonly'] : null; |
|
461 | 461 | |
462 | - // Desactivation of IE proprietary commenting tags inside the text before loading it on the online editor. |
|
463 | - // This fix has been proposed by Hubert Borderiou, see Bug #573, http://support.chamilo.org/issues/573 |
|
464 | - $defaults['content'] = str_replace('<!--[', '<!-- [', $content); |
|
462 | + // Desactivation of IE proprietary commenting tags inside the text before loading it on the online editor. |
|
463 | + // This fix has been proposed by Hubert Borderiou, see Bug #573, http://support.chamilo.org/issues/573 |
|
464 | + $defaults['content'] = str_replace('<!--[', '<!-- [', $content); |
|
465 | 465 | |
466 | - // HotPotatoes tests are html files, but they should not be edited in order their functionality to be preserved. |
|
466 | + // HotPotatoes tests are html files, but they should not be edited in order their functionality to be preserved. |
|
467 | 467 | |
468 | 468 | $showSystemFolders = api_get_course_setting('show_system_folders'); |
469 | 469 | $condition = stripos($dir, '/HotPotatoes_files') === false; |
@@ -471,44 +471,44 @@ discard block |
||
471 | 471 | $condition = true; |
472 | 472 | } |
473 | 473 | |
474 | - if (($extension == 'htm' || $extension == 'html') && $condition) { |
|
475 | - if (empty($readonly) && $readonly == 0) { |
|
474 | + if (($extension == 'htm' || $extension == 'html') && $condition) { |
|
475 | + if (empty($readonly) && $readonly == 0) { |
|
476 | 476 | $form->addHtmlEditor('content', '', true, true, $editorConfig); |
477 | - } |
|
478 | - } |
|
477 | + } |
|
478 | + } |
|
479 | 479 | |
480 | - if (!$group_document && !DocumentManager::is_my_shared_folder(api_get_user_id(), $currentDirPath, $sessionId)) { |
|
481 | - // Updated on field |
|
480 | + if (!$group_document && !DocumentManager::is_my_shared_folder(api_get_user_id(), $currentDirPath, $sessionId)) { |
|
481 | + // Updated on field |
|
482 | 482 | $display_date = date_to_str_ago($last_edit_date). |
483 | - ' <span class="dropbox_date">'.api_format_date(api_get_local_time($last_edit_date)).'</span>'; |
|
484 | - $form->addElement('static', null, get_lang('UpdatedOn'), $display_date); |
|
485 | - } |
|
483 | + ' <span class="dropbox_date">'.api_format_date(api_get_local_time($last_edit_date)).'</span>'; |
|
484 | + $form->addElement('static', null, get_lang('UpdatedOn'), $display_date); |
|
485 | + } |
|
486 | 486 | |
487 | - $form->addElement('textarea', 'comment', get_lang('Comment'), ['cols-size' => [2, 10, 0]]); |
|
487 | + $form->addElement('textarea', 'comment', get_lang('Comment'), ['cols-size' => [2, 10, 0]]); |
|
488 | 488 | |
489 | - if ($owner_id == api_get_user_id() || api_is_platform_admin()) { |
|
490 | - $checked =& $form->addElement('checkbox', 'readonly', null, get_lang('ReadOnly')); |
|
491 | - if ($readonly == 1) { |
|
492 | - $checked->setChecked(true); |
|
493 | - } |
|
494 | - } |
|
489 | + if ($owner_id == api_get_user_id() || api_is_platform_admin()) { |
|
490 | + $checked =& $form->addElement('checkbox', 'readonly', null, get_lang('ReadOnly')); |
|
491 | + if ($readonly == 1) { |
|
492 | + $checked->setChecked(true); |
|
493 | + } |
|
494 | + } |
|
495 | 495 | |
496 | - if ($is_certificate_mode) { |
|
497 | - $form->addButtonUpdate(get_lang('SaveCertificate')); |
|
496 | + if ($is_certificate_mode) { |
|
497 | + $form->addButtonUpdate(get_lang('SaveCertificate')); |
|
498 | 498 | } else { |
499 | - $form->addButtonUpdate(get_lang('SaveDocument')); |
|
499 | + $form->addButtonUpdate(get_lang('SaveDocument')); |
|
500 | 500 | } |
501 | 501 | |
502 | - $defaults['filename'] = $filename; |
|
503 | - $defaults['extension'] = $extension; |
|
504 | - $defaults['file_path'] = isset($_GET['file']) ? Security::remove_XSS($_GET['file']) : null; |
|
505 | - $defaults['commentPath'] = $file; |
|
506 | - $defaults['renameTo'] = $file_name; |
|
507 | - $defaults['comment'] = $document_data['comment']; |
|
508 | - $defaults['origin'] = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : null; |
|
509 | - $defaults['origin_opt'] = isset($_GET['origin_opt']) ? Security::remove_XSS($_GET['origin_opt']) : null; |
|
502 | + $defaults['filename'] = $filename; |
|
503 | + $defaults['extension'] = $extension; |
|
504 | + $defaults['file_path'] = isset($_GET['file']) ? Security::remove_XSS($_GET['file']) : null; |
|
505 | + $defaults['commentPath'] = $file; |
|
506 | + $defaults['renameTo'] = $file_name; |
|
507 | + $defaults['comment'] = $document_data['comment']; |
|
508 | + $defaults['origin'] = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : null; |
|
509 | + $defaults['origin_opt'] = isset($_GET['origin_opt']) ? Security::remove_XSS($_GET['origin_opt']) : null; |
|
510 | 510 | |
511 | - $form->setDefaults($defaults); |
|
511 | + $form->setDefaults($defaults); |
|
512 | 512 | |
513 | 513 | show_return( |
514 | 514 | $parent_id, |
@@ -518,25 +518,25 @@ discard block |
||
518 | 518 | $is_certificate_mode |
519 | 519 | ); |
520 | 520 | |
521 | - if ($is_certificate_mode) { |
|
522 | - $all_information_by_create_certificate = DocumentManager::get_all_info_to_certificate( |
|
523 | - api_get_user_id(), |
|
524 | - api_get_course_id() |
|
525 | - ); |
|
526 | - $str_info = ''; |
|
527 | - foreach ($all_information_by_create_certificate[0] as $info_value) { |
|
528 | - $str_info .= $info_value.'<br/>'; |
|
529 | - } |
|
530 | - $create_certificate=get_lang('CreateCertificateWithTags'); |
|
531 | - Display::display_normal_message( |
|
532 | - $create_certificate.': <br /><br />'.$str_info, |
|
533 | - false |
|
534 | - ); |
|
535 | - } |
|
536 | - |
|
537 | - if ($extension=='svg' && !api_browser_support('svg') && api_get_setting('enabled_support_svg') == 'true'){ |
|
538 | - Display::display_warning_message(get_lang('BrowserDontSupportsSVG')); |
|
539 | - } |
|
521 | + if ($is_certificate_mode) { |
|
522 | + $all_information_by_create_certificate = DocumentManager::get_all_info_to_certificate( |
|
523 | + api_get_user_id(), |
|
524 | + api_get_course_id() |
|
525 | + ); |
|
526 | + $str_info = ''; |
|
527 | + foreach ($all_information_by_create_certificate[0] as $info_value) { |
|
528 | + $str_info .= $info_value.'<br/>'; |
|
529 | + } |
|
530 | + $create_certificate=get_lang('CreateCertificateWithTags'); |
|
531 | + Display::display_normal_message( |
|
532 | + $create_certificate.': <br /><br />'.$str_info, |
|
533 | + false |
|
534 | + ); |
|
535 | + } |
|
536 | + |
|
537 | + if ($extension=='svg' && !api_browser_support('svg') && api_get_setting('enabled_support_svg') == 'true'){ |
|
538 | + Display::display_warning_message(get_lang('BrowserDontSupportsSVG')); |
|
539 | + } |
|
540 | 540 | // HTML-editor |
541 | 541 | echo '<div class="page-create"> |
542 | 542 | <div class="row" style="overflow:hidden"> |
@@ -563,26 +563,26 @@ discard block |
||
563 | 563 | */ |
564 | 564 | function change_name($base_work_dir, $source_file, $rename_to, $dir, $doc) |
565 | 565 | { |
566 | - $file_name_for_change = $base_work_dir.$dir.$source_file; |
|
566 | + $file_name_for_change = $base_work_dir.$dir.$source_file; |
|
567 | 567 | $rename_to = disable_dangerous_file($rename_to); // Avoid renaming to .htaccess file |
568 | - $rename_to = my_rename($file_name_for_change, stripslashes($rename_to)); // fileManage API |
|
569 | - |
|
570 | - if ($rename_to) { |
|
571 | - if (isset($dir) && $dir != '') { |
|
572 | - $source_file = $dir.$source_file; |
|
573 | - $new_full_file_name = dirname($source_file).'/'.$rename_to; |
|
574 | - } else { |
|
575 | - $source_file = '/'.$source_file; |
|
576 | - $new_full_file_name = '/'.$rename_to; |
|
577 | - } |
|
578 | - |
|
579 | - update_db_info('update', $source_file, $new_full_file_name); // fileManage API |
|
568 | + $rename_to = my_rename($file_name_for_change, stripslashes($rename_to)); // fileManage API |
|
569 | + |
|
570 | + if ($rename_to) { |
|
571 | + if (isset($dir) && $dir != '') { |
|
572 | + $source_file = $dir.$source_file; |
|
573 | + $new_full_file_name = dirname($source_file).'/'.$rename_to; |
|
574 | + } else { |
|
575 | + $source_file = '/'.$source_file; |
|
576 | + $new_full_file_name = '/'.$rename_to; |
|
577 | + } |
|
578 | + |
|
579 | + update_db_info('update', $source_file, $new_full_file_name); // fileManage API |
|
580 | 580 | Display::addFlash(Display::return_message(get_lang('fileModified'))); |
581 | 581 | |
582 | - return true; |
|
583 | - } else { |
|
582 | + return true; |
|
583 | + } else { |
|
584 | 584 | Display::addFlash(Display::return_message(get_lang('FileExists'))); |
585 | - } |
|
585 | + } |
|
586 | 586 | } |
587 | 587 | |
588 | 588 | //return button back to |
@@ -595,32 +595,32 @@ discard block |
||
595 | 595 | global $parent_id; |
596 | 596 | $url = api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq().'&id='.$parent_id; |
597 | 597 | |
598 | - if ($is_certificate_mode) { |
|
599 | - $selectedCategory = (isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : ''); |
|
600 | - $actionsLeft .= '<a href="document.php?curdirpath='. $selectedCategory .'&selectcat=' . $selectedCategory .'">'. |
|
598 | + if ($is_certificate_mode) { |
|
599 | + $selectedCategory = (isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : ''); |
|
600 | + $actionsLeft .= '<a href="document.php?curdirpath='. $selectedCategory .'&selectcat=' . $selectedCategory .'">'. |
|
601 | 601 | Display::return_icon('back.png',get_lang('Back').' '.get_lang('To').' '.get_lang('CertificateOverview'),'',ICON_SIZE_MEDIUM).'</a>'; |
602 | 602 | $actionsLeft .= '<a id="hide_bar_template" href="#">'.Display::return_icon('expand.png',get_lang('Expand'),array('id'=>'expand'),ICON_SIZE_MEDIUM).Display::return_icon('contract.png',get_lang('Collapse'),array('id'=>'contract', 'class'=>'hide'),ICON_SIZE_MEDIUM).'</a>'; |
603 | - } elseif($call_from_tool=='slideshow') { |
|
604 | - $actionsLeft .= '<a href="'.api_get_path(WEB_PATH).'main/document/slideshow.php?slide_id='.$slide_id.'&curdirpath='.Security::remove_XSS(urlencode($_GET['curdirpath'])).'">'. |
|
603 | + } elseif($call_from_tool=='slideshow') { |
|
604 | + $actionsLeft .= '<a href="'.api_get_path(WEB_PATH).'main/document/slideshow.php?slide_id='.$slide_id.'&curdirpath='.Security::remove_XSS(urlencode($_GET['curdirpath'])).'">'. |
|
605 | 605 | Display::return_icon('slideshow.png', get_lang('BackTo').' '.get_lang('ViewSlideshow'),'',ICON_SIZE_MEDIUM).'</a>'; |
606 | - } elseif($call_from_tool=='editdraw') { |
|
607 | - $actionsLeft .= '<a href="'.$url.'">'. |
|
606 | + } elseif($call_from_tool=='editdraw') { |
|
607 | + $actionsLeft .= '<a href="'.$url.'">'. |
|
608 | 608 | Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'),'',ICON_SIZE_MEDIUM).'</a>'; |
609 | - $actionsLeft .= '<a href="javascript:history.back(1)">'.Display::return_icon('draw.png', get_lang('BackTo').' '.get_lang('Draw'), array(), 32).'</a>'; |
|
610 | - } elseif($call_from_tool=='editodf') { |
|
609 | + $actionsLeft .= '<a href="javascript:history.back(1)">'.Display::return_icon('draw.png', get_lang('BackTo').' '.get_lang('Draw'), array(), 32).'</a>'; |
|
610 | + } elseif($call_from_tool=='editodf') { |
|
611 | 611 | $actionsLeft .= '<a href="'.$url.'">'. |
612 | 612 | Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'),'',ICON_SIZE_MEDIUM).'</a>'; |
613 | 613 | $actionsLeft .= '<a href="javascript:history.back(1)">'.Display::return_icon('draw.png', get_lang('BackTo').' '.get_lang('Write'), array(), 32).'</a>'; |
614 | 614 | $actionsLeft .= '<a id="hide_bar_template" href="#">'.Display::return_icon('expand.png',get_lang('Expand'),array('id'=>'expand'),ICON_SIZE_MEDIUM).Display::return_icon('contract.png',get_lang('Collapse'),array('id'=>'contract', 'class'=>'hide'),ICON_SIZE_MEDIUM).'</a>'; |
615 | 615 | } elseif($call_from_tool=='editpaint'){ |
616 | - $actionsLeft .= '<a href="'.$url.'">'. |
|
616 | + $actionsLeft .= '<a href="'.$url.'">'. |
|
617 | 617 | Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'), array(), ICON_SIZE_MEDIUM).'</a>'; |
618 | - $actionsLeft .= '<a href="javascript:history.back(1)">'.Display::return_icon('paint.png', get_lang('BackTo').' '.get_lang('Paint'), array(), 32).'</a>'; |
|
619 | - } else { |
|
620 | - $actionsLeft .= '<a href="'.$url.'">'. |
|
618 | + $actionsLeft .= '<a href="javascript:history.back(1)">'.Display::return_icon('paint.png', get_lang('BackTo').' '.get_lang('Paint'), array(), 32).'</a>'; |
|
619 | + } else { |
|
620 | + $actionsLeft .= '<a href="'.$url.'">'. |
|
621 | 621 | Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'),'',ICON_SIZE_MEDIUM).'</a>'; |
622 | 622 | $actionsLeft .= '<a id="hide_bar_template" href="#">'.Display::return_icon('expand.png',get_lang('Expand'),array('id'=>'expand'),ICON_SIZE_MEDIUM).Display::return_icon('contract.png',get_lang('Collapse'),array('id'=>'contract', 'class'=>'hide'),ICON_SIZE_MEDIUM).'</a>'; |
623 | - } |
|
623 | + } |
|
624 | 624 | |
625 | 625 | echo $toolbar = Display::toolbarAction('actions-documents', array(0 => $actionsLeft, 1 => '')); |
626 | 626 | } |
@@ -3,121 +3,121 @@ discard block |
||
3 | 3 | * Validates imported data. |
4 | 4 | */ |
5 | 5 | function validate_data($users) { |
6 | - global $defined_auth_sources; |
|
7 | - $errors = array (); |
|
8 | - $usernames = array (); |
|
9 | - if(is_array($users)) { |
|
10 | - foreach ($users as $index => $user) { |
|
11 | - // 1. Check whether mandatory fields have been set. |
|
12 | - $mandatory_fields = array ('LastName', 'FirstName'); |
|
13 | - if (api_get_setting('registration', 'email') == 'true') { |
|
14 | - $mandatory_fields[] = 'Email'; |
|
15 | - } |
|
16 | - foreach ($mandatory_fields as $key => $field) { |
|
17 | - if (!isset ($user[$field]) || strlen($user[$field]) == 0) { |
|
18 | - $user['error'] = get_lang($field.'Mandatory'); |
|
19 | - $errors[] = $user; |
|
20 | - } |
|
21 | - } |
|
22 | - // 2. Check username. |
|
23 | - if (!UserManager::is_username_empty($user['UserName'])) { |
|
24 | - // 2.1. Check whether username was used twice in the import file. |
|
25 | - if (isset($usernames[$user['UserName']])) { |
|
26 | - $user['error'] = get_lang('UserNameUsedTwice'); |
|
27 | - $errors[] = $user; |
|
28 | - } |
|
29 | - $usernames[$user['UserName']] = 1; |
|
30 | - // 2.2. Check whether username is allready in use in database. |
|
31 | - if (!UserManager::is_username_available($user['UserName'])) { |
|
32 | - $user['error'] = get_lang('UserNameNotAvailable'); |
|
33 | - $errors[] = $user; |
|
34 | - } |
|
35 | - // 2.3. Check whether username is too long. |
|
36 | - if (UserManager::is_username_too_long($user['UserName'])) { |
|
37 | - $user['error'] = get_lang('UserNameTooLong'); |
|
38 | - $errors[] = $user; |
|
39 | - } |
|
40 | - } |
|
41 | - // 3. Check status. |
|
42 | - if (isset ($user['Status']) && !api_status_exists($user['Status'])) { |
|
43 | - $user['error'] = get_lang('WrongStatus'); |
|
44 | - $errors[] = $user; |
|
45 | - } |
|
46 | - // 5. Check authentication source. |
|
47 | - if (isset ($user['AuthSource']) && strlen($user['AuthSource']) != 0) { |
|
48 | - if (!in_array($user['AuthSource'], $defined_auth_sources)) { |
|
49 | - $user['error'] = get_lang('AuthSourceNotAvailable'); |
|
50 | - $errors[] = $user; |
|
51 | - } |
|
52 | - } |
|
53 | - } |
|
54 | - } |
|
55 | - return $errors; |
|
6 | + global $defined_auth_sources; |
|
7 | + $errors = array (); |
|
8 | + $usernames = array (); |
|
9 | + if(is_array($users)) { |
|
10 | + foreach ($users as $index => $user) { |
|
11 | + // 1. Check whether mandatory fields have been set. |
|
12 | + $mandatory_fields = array ('LastName', 'FirstName'); |
|
13 | + if (api_get_setting('registration', 'email') == 'true') { |
|
14 | + $mandatory_fields[] = 'Email'; |
|
15 | + } |
|
16 | + foreach ($mandatory_fields as $key => $field) { |
|
17 | + if (!isset ($user[$field]) || strlen($user[$field]) == 0) { |
|
18 | + $user['error'] = get_lang($field.'Mandatory'); |
|
19 | + $errors[] = $user; |
|
20 | + } |
|
21 | + } |
|
22 | + // 2. Check username. |
|
23 | + if (!UserManager::is_username_empty($user['UserName'])) { |
|
24 | + // 2.1. Check whether username was used twice in the import file. |
|
25 | + if (isset($usernames[$user['UserName']])) { |
|
26 | + $user['error'] = get_lang('UserNameUsedTwice'); |
|
27 | + $errors[] = $user; |
|
28 | + } |
|
29 | + $usernames[$user['UserName']] = 1; |
|
30 | + // 2.2. Check whether username is allready in use in database. |
|
31 | + if (!UserManager::is_username_available($user['UserName'])) { |
|
32 | + $user['error'] = get_lang('UserNameNotAvailable'); |
|
33 | + $errors[] = $user; |
|
34 | + } |
|
35 | + // 2.3. Check whether username is too long. |
|
36 | + if (UserManager::is_username_too_long($user['UserName'])) { |
|
37 | + $user['error'] = get_lang('UserNameTooLong'); |
|
38 | + $errors[] = $user; |
|
39 | + } |
|
40 | + } |
|
41 | + // 3. Check status. |
|
42 | + if (isset ($user['Status']) && !api_status_exists($user['Status'])) { |
|
43 | + $user['error'] = get_lang('WrongStatus'); |
|
44 | + $errors[] = $user; |
|
45 | + } |
|
46 | + // 5. Check authentication source. |
|
47 | + if (isset ($user['AuthSource']) && strlen($user['AuthSource']) != 0) { |
|
48 | + if (!in_array($user['AuthSource'], $defined_auth_sources)) { |
|
49 | + $user['error'] = get_lang('AuthSourceNotAvailable'); |
|
50 | + $errors[] = $user; |
|
51 | + } |
|
52 | + } |
|
53 | + } |
|
54 | + } |
|
55 | + return $errors; |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
59 | 59 | * Adds missing user-information (which isn't required, like password, username, etc). |
60 | 60 | */ |
61 | 61 | function complete_missing_data($user) { |
62 | - // 1. Create a username if necessary. |
|
63 | - if (UserManager::is_username_empty($user['UserName'])) { |
|
64 | - $user['UserName'] = UserManager::create_unique_username($user['FirstName'], $user['LastName']); |
|
65 | - } |
|
66 | - // 2. Generate a password if necessary. |
|
67 | - if (!isset ($user['Password']) || strlen($user['Password']) == 0) { |
|
68 | - $user['Password'] = api_generate_password(); |
|
69 | - } |
|
70 | - // 3. set status if not allready set. |
|
71 | - if (!isset ($user['Status']) || strlen($user['Status']) == 0) { |
|
72 | - $user['Status'] = 'user'; |
|
73 | - } |
|
74 | - // 4. Set authsource if not allready set. |
|
75 | - if (!isset ($user['AuthSource']) || strlen($user['AuthSource']) == 0) { |
|
76 | - $user['AuthSource'] = PLATFORM_AUTH_SOURCE; |
|
77 | - } |
|
78 | - return $user; |
|
62 | + // 1. Create a username if necessary. |
|
63 | + if (UserManager::is_username_empty($user['UserName'])) { |
|
64 | + $user['UserName'] = UserManager::create_unique_username($user['FirstName'], $user['LastName']); |
|
65 | + } |
|
66 | + // 2. Generate a password if necessary. |
|
67 | + if (!isset ($user['Password']) || strlen($user['Password']) == 0) { |
|
68 | + $user['Password'] = api_generate_password(); |
|
69 | + } |
|
70 | + // 3. set status if not allready set. |
|
71 | + if (!isset ($user['Status']) || strlen($user['Status']) == 0) { |
|
72 | + $user['Status'] = 'user'; |
|
73 | + } |
|
74 | + // 4. Set authsource if not allready set. |
|
75 | + if (!isset ($user['AuthSource']) || strlen($user['AuthSource']) == 0) { |
|
76 | + $user['AuthSource'] = PLATFORM_AUTH_SOURCE; |
|
77 | + } |
|
78 | + return $user; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | 82 | * Save the imported data |
83 | 83 | */ |
84 | 84 | function save_data($users) { |
85 | - $user_table = Database :: get_main_table(TABLE_MAIN_USER); |
|
86 | - if(is_array($users)) { |
|
87 | - foreach ($users as $index => $user) { |
|
88 | - $user = complete_missing_data($user); |
|
85 | + $user_table = Database :: get_main_table(TABLE_MAIN_USER); |
|
86 | + if(is_array($users)) { |
|
87 | + foreach ($users as $index => $user) { |
|
88 | + $user = complete_missing_data($user); |
|
89 | 89 | |
90 | - $user['Status'] = api_status_key($user['Status']); |
|
90 | + $user['Status'] = api_status_key($user['Status']); |
|
91 | 91 | |
92 | - $user_id = UserManager :: create_user($user['FirstName'], $user['LastName'], $user['Status'], $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], api_get_setting('PlatformLanguage'), $user['PhoneNumber'], '', $user['AuthSource']); |
|
93 | - foreach ($user['Courses'] as $index => $course) { |
|
94 | - if(CourseManager :: course_exists($course)) |
|
95 | - CourseManager :: subscribe_user($user_id, $course,$user['Status']); |
|
96 | - } |
|
92 | + $user_id = UserManager :: create_user($user['FirstName'], $user['LastName'], $user['Status'], $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], api_get_setting('PlatformLanguage'), $user['PhoneNumber'], '', $user['AuthSource']); |
|
93 | + foreach ($user['Courses'] as $index => $course) { |
|
94 | + if(CourseManager :: course_exists($course)) |
|
95 | + CourseManager :: subscribe_user($user_id, $course,$user['Status']); |
|
96 | + } |
|
97 | 97 | |
98 | - // TODO: Hard-coded French texts. |
|
98 | + // TODO: Hard-coded French texts. |
|
99 | 99 | |
100 | - // Qualite |
|
101 | - if (!empty($user['Qualite'])) { |
|
102 | - UserManager::update_extra_field_value($user_id, 'qualite', $user['Qualite']); |
|
103 | - } |
|
100 | + // Qualite |
|
101 | + if (!empty($user['Qualite'])) { |
|
102 | + UserManager::update_extra_field_value($user_id, 'qualite', $user['Qualite']); |
|
103 | + } |
|
104 | 104 | |
105 | - // Categorie |
|
106 | - if (!empty($user['Categorie'])) { |
|
107 | - UserManager::update_extra_field_value($user_id, 'categorie', $user['Categorie']); |
|
108 | - } |
|
105 | + // Categorie |
|
106 | + if (!empty($user['Categorie'])) { |
|
107 | + UserManager::update_extra_field_value($user_id, 'categorie', $user['Categorie']); |
|
108 | + } |
|
109 | 109 | |
110 | - // Etat |
|
111 | - if (!empty($user['Etat'])) { |
|
112 | - UserManager::update_extra_field_value($user_id, 'etat', $user['Etat']); |
|
113 | - } |
|
110 | + // Etat |
|
111 | + if (!empty($user['Etat'])) { |
|
112 | + UserManager::update_extra_field_value($user_id, 'etat', $user['Etat']); |
|
113 | + } |
|
114 | 114 | |
115 | - // Niveau |
|
116 | - if (!empty($user['Niveau'])) { |
|
117 | - UserManager::update_extra_field_value($user_id, 'niveau', $user['Niveau']); |
|
118 | - } |
|
119 | - } |
|
120 | - } |
|
115 | + // Niveau |
|
116 | + if (!empty($user['Niveau'])) { |
|
117 | + UserManager::update_extra_field_value($user_id, 'niveau', $user['Niveau']); |
|
118 | + } |
|
119 | + } |
|
120 | + } |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -126,12 +126,12 @@ discard block |
||
126 | 126 | * @return array All userinformation read from the file |
127 | 127 | */ |
128 | 128 | function parse_csv_data($file) { |
129 | - $users = Import :: csvToArray($file); |
|
130 | - foreach ($users as $index => $user) { |
|
131 | - if (isset ($user['Courses'])) { |
|
132 | - $user['Courses'] = explode('|', trim($user['Courses'])); |
|
133 | - } |
|
134 | - $users[$index] = $user; |
|
135 | - } |
|
136 | - return $users; |
|
129 | + $users = Import :: csvToArray($file); |
|
130 | + foreach ($users as $index => $user) { |
|
131 | + if (isset ($user['Courses'])) { |
|
132 | + $user['Courses'] = explode('|', trim($user['Courses'])); |
|
133 | + } |
|
134 | + $users[$index] = $user; |
|
135 | + } |
|
136 | + return $users; |
|
137 | 137 | } |
@@ -14,20 +14,20 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class UniqueAnswerNoOption extends Question |
16 | 16 | { |
17 | - public static $typePicture = 'mcuao.png'; |
|
18 | - public static $explanationLangVar = 'UniqueAnswerNoOption'; |
|
17 | + public static $typePicture = 'mcuao.png'; |
|
18 | + public static $explanationLangVar = 'UniqueAnswerNoOption'; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Constructor |
|
22 | - */ |
|
23 | - public function __construct() |
|
20 | + /** |
|
21 | + * Constructor |
|
22 | + */ |
|
23 | + public function __construct() |
|
24 | 24 | { |
25 | - parent::__construct(); |
|
26 | - $this -> type = UNIQUE_ANSWER_NO_OPTION; |
|
27 | - $this -> isContent = $this-> getIsContent(); |
|
28 | - } |
|
25 | + parent::__construct(); |
|
26 | + $this -> type = UNIQUE_ANSWER_NO_OPTION; |
|
27 | + $this -> isContent = $this-> getIsContent(); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
30 | + /** |
|
31 | 31 | * function which redifines Question::createAnswersForm |
32 | 32 | * @param the formvalidator instance |
33 | 33 | * @param the answers number to display |
@@ -283,37 +283,37 @@ discard block |
||
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
286 | - * Function which creates the form to create / edit the answers of the question |
|
287 | - * @param the formvalidator instance |
|
288 | - * @param the answers number to display |
|
289 | - */ |
|
290 | - function processAnswersCreation($form) |
|
286 | + * Function which creates the form to create / edit the answers of the question |
|
287 | + * @param the formvalidator instance |
|
288 | + * @param the answers number to display |
|
289 | + */ |
|
290 | + function processAnswersCreation($form) |
|
291 | 291 | { |
292 | - $questionWeighting = $nbrGoodAnswers = 0; |
|
293 | - $correct = $form -> getSubmitValue('correct'); |
|
294 | - $objAnswer = new Answer($this->id); |
|
295 | - $nb_answers = $form -> getSubmitValue('nb_answers'); |
|
296 | - $minus = 1; |
|
297 | - if ($form -> getSubmitValue('new_question')) { |
|
298 | - $minus = 0; |
|
299 | - } |
|
300 | - |
|
301 | - for ($i=1 ; $i <= $nb_answers - $minus; $i++) { |
|
302 | - $position = trim($form -> getSubmitValue('position['.$i.']')); |
|
303 | - $answer = trim($form -> getSubmitValue('answer['.$i.']')); |
|
292 | + $questionWeighting = $nbrGoodAnswers = 0; |
|
293 | + $correct = $form -> getSubmitValue('correct'); |
|
294 | + $objAnswer = new Answer($this->id); |
|
295 | + $nb_answers = $form -> getSubmitValue('nb_answers'); |
|
296 | + $minus = 1; |
|
297 | + if ($form -> getSubmitValue('new_question')) { |
|
298 | + $minus = 0; |
|
299 | + } |
|
300 | + |
|
301 | + for ($i=1 ; $i <= $nb_answers - $minus; $i++) { |
|
302 | + $position = trim($form -> getSubmitValue('position['.$i.']')); |
|
303 | + $answer = trim($form -> getSubmitValue('answer['.$i.']')); |
|
304 | 304 | $comment = trim($form -> getSubmitValue('comment['.$i.']')); |
305 | 305 | $weighting = trim($form -> getSubmitValue('weighting['.$i.']')); |
306 | 306 | $scenario = $form -> getSubmitValue('scenario'); |
307 | 307 | |
308 | - //$list_destination = $form -> getSubmitValue('destination'.$i); |
|
309 | - //$destination_str = $form -> getSubmitValue('destination'.$i); |
|
308 | + //$list_destination = $form -> getSubmitValue('destination'.$i); |
|
309 | + //$destination_str = $form -> getSubmitValue('destination'.$i); |
|
310 | 310 | |
311 | - $try = $scenario['try'.$i]; |
|
311 | + $try = $scenario['try'.$i]; |
|
312 | 312 | $lp = $scenario['lp'.$i]; |
313 | - $destination = $scenario['destination'.$i]; |
|
314 | - $url = trim($scenario['url'.$i]); |
|
313 | + $destination = $scenario['destination'.$i]; |
|
314 | + $url = trim($scenario['url'.$i]); |
|
315 | 315 | |
316 | - /* |
|
316 | + /* |
|
317 | 317 | How we are going to parse the destination value |
318 | 318 | |
319 | 319 | here we parse the destination value which is a string |
@@ -326,41 +326,41 @@ discard block |
||
326 | 326 | selected_questions= ids of questions |
327 | 327 | url= an url |
328 | 328 | */ |
329 | - /* |
|
329 | + /* |
|
330 | 330 | $destination_str=''; |
331 | 331 | foreach ($list_destination as $destination_id) |
332 | 332 | { |
333 | 333 | $destination_str.=$destination_id.';'; |
334 | 334 | }*/ |
335 | 335 | |
336 | - $goodAnswer= ($correct == $i) ? true : false; |
|
336 | + $goodAnswer= ($correct == $i) ? true : false; |
|
337 | 337 | |
338 | - if ($goodAnswer) { |
|
339 | - $nbrGoodAnswers++; |
|
340 | - $weighting = abs($weighting); |
|
341 | - if($weighting > 0) { |
|
338 | + if ($goodAnswer) { |
|
339 | + $nbrGoodAnswers++; |
|
340 | + $weighting = abs($weighting); |
|
341 | + if($weighting > 0) { |
|
342 | 342 | $questionWeighting += $weighting; |
343 | 343 | } |
344 | - } |
|
344 | + } |
|
345 | 345 | |
346 | - if (empty($try)) |
|
347 | - $try=0; |
|
346 | + if (empty($try)) |
|
347 | + $try=0; |
|
348 | 348 | |
349 | - if (empty($lp)) { |
|
350 | - $lp=0; |
|
351 | - } |
|
349 | + if (empty($lp)) { |
|
350 | + $lp=0; |
|
351 | + } |
|
352 | 352 | |
353 | - if (empty($destination)) { |
|
354 | - $destination=0; |
|
355 | - } |
|
353 | + if (empty($destination)) { |
|
354 | + $destination=0; |
|
355 | + } |
|
356 | 356 | |
357 | - if ($url=='') { |
|
358 | - $url=0; |
|
359 | - } |
|
357 | + if ($url=='') { |
|
358 | + $url=0; |
|
359 | + } |
|
360 | 360 | |
361 | - //1@@1;2;@@2;4;4;@@http://www.chamilo.org |
|
362 | - $dest= $try.'@@'.$lp.'@@'.$destination.'@@'.$url; |
|
363 | - $objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i,NULL,NULL,$dest); |
|
361 | + //1@@1;2;@@2;4;4;@@http://www.chamilo.org |
|
362 | + $dest= $try.'@@'.$lp.'@@'.$destination.'@@'.$url; |
|
363 | + $objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i,NULL,NULL,$dest); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | //Create 666 answer |
@@ -373,18 +373,18 @@ discard block |
||
373 | 373 | |
374 | 374 | $objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i,NULL,NULL,$dest); |
375 | 375 | |
376 | - // saves the answers into the data base |
|
376 | + // saves the answers into the data base |
|
377 | 377 | $objAnswer -> save(); |
378 | 378 | |
379 | 379 | // sets the total weighting of the question |
380 | 380 | $this -> updateWeighting($questionWeighting); |
381 | 381 | $this -> save(); |
382 | - } |
|
382 | + } |
|
383 | 383 | |
384 | - function return_header($feedback_type = null, $counter = null, $score = null) |
|
384 | + function return_header($feedback_type = null, $counter = null, $score = null) |
|
385 | 385 | { |
386 | - $header = parent::return_header($feedback_type, $counter, $score); |
|
387 | - $header .= '<table class="'.$this->question_table_class .'"> |
|
386 | + $header = parent::return_header($feedback_type, $counter, $score); |
|
387 | + $header .= '<table class="'.$this->question_table_class .'"> |
|
388 | 388 | <tr> |
389 | 389 | <th>'.get_lang("Choice").'</th> |
390 | 390 | <th>'. get_lang("ExpectedChoice").'</th> |
@@ -392,5 +392,5 @@ discard block |
||
392 | 392 | $header .= '<th>'.get_lang("Comment").'</th>'; |
393 | 393 | $header .= '</tr>'; |
394 | 394 | return $header; |
395 | - } |
|
395 | + } |
|
396 | 396 | } |