@@ -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 |
@@ -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 | } |
@@ -25,8 +25,8 @@ |
||
25 | 25 | // user clicked ON a hotspot |
26 | 26 | $hit = 1; |
27 | 27 | $answerId = api_substr($_GET['answerId'],22,2); |
28 | - // Save into session |
|
29 | - $_SESSION['exerciseResult'][$questionId][$answerId] = $hit; |
|
28 | + // Save into session |
|
29 | + $_SESSION['exerciseResult'][$questionId][$answerId] = $hit; |
|
30 | 30 | } |
31 | 31 | //round-up the coordinates |
32 | 32 | $coords = explode('/',$coordinates); |
@@ -20,16 +20,16 @@ |
||
20 | 20 | $exerciseId = $objExercise->selectId(); |
21 | 21 | if ($_GET['answerId'] == "0") { // click is NOT on a hotspot |
22 | 22 | $hit = 0; |
23 | - $answerId = $hotspotId; |
|
23 | + $answerId = $hotspotId; |
|
24 | 24 | |
25 | - // remove from session |
|
26 | - unset($_SESSION['exerciseResult'][$questionId][$answerId]); |
|
25 | + // remove from session |
|
26 | + unset($_SESSION['exerciseResult'][$questionId][$answerId]); |
|
27 | 27 | } else { // user clicked ON a hotspot |
28 | - $hit = 1; |
|
29 | - $answerId = $hotspotId; |
|
28 | + $hit = 1; |
|
29 | + $answerId = $hotspotId; |
|
30 | 30 | |
31 | - // Save into session |
|
32 | - $_SESSION['exerciseResult'][$questionId][$answerId] = $hit; |
|
31 | + // Save into session |
|
32 | + $_SESSION['exerciseResult'][$questionId][$answerId] = $hit; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | //round-up the coordinates |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | */ |
48 | 48 | //user has submitted a file |
49 | 49 | if (isset($_FILES['user_upload'])) { |
50 | - $upload_ok = process_uploaded_file($_FILES['user_upload']); |
|
51 | - if ($upload_ok) { |
|
52 | - //file got on the server without problems, now process it |
|
50 | + $upload_ok = process_uploaded_file($_FILES['user_upload']); |
|
51 | + if ($upload_ok) { |
|
52 | + //file got on the server without problems, now process it |
|
53 | 53 | $new_path = handle_uploaded_document( |
54 | 54 | $_course, |
55 | 55 | $_FILES['user_upload'], |
@@ -61,21 +61,21 @@ discard block |
||
61 | 61 | $_POST['unzip'], |
62 | 62 | $_POST['if_exists'] |
63 | 63 | ); |
64 | - $new_comment = isset($_POST['comment']) ? Database::escape_string(trim($_POST['comment'])) : ''; |
|
65 | - $new_title = isset($_POST['title']) ? Database::escape_string(trim($_POST['title'])) : ''; |
|
64 | + $new_comment = isset($_POST['comment']) ? Database::escape_string(trim($_POST['comment'])) : ''; |
|
65 | + $new_title = isset($_POST['title']) ? Database::escape_string(trim($_POST['title'])) : ''; |
|
66 | 66 | |
67 | - if ($new_path && ($new_comment || $new_title)) |
|
68 | - if (($docid = DocumentManager::get_document_id($_course, $new_path))) { |
|
69 | - $table_document = Database::get_course_table(TABLE_DOCUMENT); |
|
70 | - $ct = ''; |
|
67 | + if ($new_path && ($new_comment || $new_title)) |
|
68 | + if (($docid = DocumentManager::get_document_id($_course, $new_path))) { |
|
69 | + $table_document = Database::get_course_table(TABLE_DOCUMENT); |
|
70 | + $ct = ''; |
|
71 | 71 | if ($new_comment) { |
72 | 72 | $ct .= ", comment='$new_comment'"; |
73 | 73 | } |
74 | 74 | if ($new_title) { |
75 | 75 | $ct .= ", title='$new_title'"; |
76 | 76 | } |
77 | - Database::query("UPDATE $table_document SET" . substr($ct, 1) ." WHERE id = '$docid'"); |
|
78 | - } |
|
77 | + Database::query("UPDATE $table_document SET" . substr($ct, 1) ." WHERE id = '$docid'"); |
|
78 | + } |
|
79 | 79 | //check for missing images in html files |
80 | 80 | $missing_files = check_for_missing_files($base_work_dir.$_POST['curdirpath'].$new_path); |
81 | 81 | if ($missing_files) { |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | //they want to create a directory |
134 | 134 | if (isset($_POST['create_dir']) && $_POST['dirname']!='') { |
135 | 135 | $added_slash = $path == '/' ? '' : '/'; |
136 | - $dir_name = $path.$added_slash.api_replace_dangerous_char($_POST['dirname']); |
|
136 | + $dir_name = $path.$added_slash.api_replace_dangerous_char($_POST['dirname']); |
|
137 | 137 | $created_dir = create_unexisting_directory( |
138 | 138 | $_course, |
139 | 139 | api_get_user_id(), |
@@ -153,15 +153,15 @@ discard block |
||
153 | 153 | } |
154 | 154 | |
155 | 155 | if (isset($_GET['createdir'])) { |
156 | - //create the form that asks for the directory name |
|
157 | - $new_folder_text = '<form action="'.api_get_self().'" method="POST">'; |
|
158 | - $new_folder_text .= '<input type="hidden" name="curdirpath" value="'.$path.'"/>'; |
|
159 | - $new_folder_text .= get_lang('NewDir') .' '; |
|
160 | - $new_folder_text .= '<input type="text" name="dirname"/>'; |
|
161 | - $new_folder_text .= '<input type="submit" name="create_dir" value="'.get_lang('Ok').'"/>'; |
|
162 | - $new_folder_text .= '</form>'; |
|
163 | - //show the form |
|
164 | - Display::display_normal_message($new_folder_text); |
|
156 | + //create the form that asks for the directory name |
|
157 | + $new_folder_text = '<form action="'.api_get_self().'" method="POST">'; |
|
158 | + $new_folder_text .= '<input type="hidden" name="curdirpath" value="'.$path.'"/>'; |
|
159 | + $new_folder_text .= get_lang('NewDir') .' '; |
|
160 | + $new_folder_text .= '<input type="text" name="dirname"/>'; |
|
161 | + $new_folder_text .= '<input type="submit" name="create_dir" value="'.get_lang('Ok').'"/>'; |
|
162 | + $new_folder_text .= '</form>'; |
|
163 | + //show the form |
|
164 | + Display::display_normal_message($new_folder_text); |
|
165 | 165 | } else { //give them a link to create a directory |
166 | 166 | ?> |
167 | 167 | <p> |
@@ -12,31 +12,31 @@ discard block |
||
12 | 12 | **/ |
13 | 13 | class HotSpot extends Question |
14 | 14 | { |
15 | - public static $typePicture = 'hotspot.png'; |
|
16 | - public static $explanationLangVar = 'HotSpot'; |
|
15 | + public static $typePicture = 'hotspot.png'; |
|
16 | + public static $explanationLangVar = 'HotSpot'; |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * HotSpot constructor. |
20 | 20 | */ |
21 | - public function __construct() |
|
22 | - { |
|
23 | - parent::__construct(); |
|
24 | - $this->type = HOT_SPOT; |
|
25 | - } |
|
26 | - |
|
27 | - public function display() |
|
28 | - { |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * @param FormValidator $form |
|
33 | - * @param int $fck_config |
|
34 | - */ |
|
35 | - public function createForm (&$form, $fck_config=0) |
|
36 | - { |
|
37 | - parent::createForm($form, $fck_config); |
|
38 | - |
|
39 | - if (!isset($_GET['editQuestion'])) { |
|
21 | + public function __construct() |
|
22 | + { |
|
23 | + parent::__construct(); |
|
24 | + $this->type = HOT_SPOT; |
|
25 | + } |
|
26 | + |
|
27 | + public function display() |
|
28 | + { |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * @param FormValidator $form |
|
33 | + * @param int $fck_config |
|
34 | + */ |
|
35 | + public function createForm (&$form, $fck_config=0) |
|
36 | + { |
|
37 | + parent::createForm($form, $fck_config); |
|
38 | + |
|
39 | + if (!isset($_GET['editQuestion'])) { |
|
40 | 40 | $form->addElement( |
41 | 41 | 'file', |
42 | 42 | 'imageUpload', |
@@ -46,54 +46,54 @@ discard block |
||
46 | 46 | ) |
47 | 47 | ); |
48 | 48 | |
49 | - // setting the save button here and not in the question class.php |
|
50 | - // Saving a question |
|
51 | - $form->addButtonSave(get_lang('GoToQuestion'), 'submitQuestion'); |
|
52 | - //$form->addButtonSave(get_lang('GoToQuestion'), 'submitQuestion'); |
|
53 | - $form->addRule('imageUpload', get_lang('OnlyImagesAllowed'), 'filetype', array ('jpg', 'jpeg', 'png', 'gif')); |
|
54 | - $form->addRule('imageUpload', get_lang('NoImage'), 'uploadedfile'); |
|
55 | - } else { |
|
56 | - // setting the save button here and not in the question class.php |
|
57 | - // Editing a question |
|
58 | - $form->addButtonUpdate(get_lang('ModifyExercise'), 'submitQuestion'); |
|
59 | - } |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * @param FormValidator $form |
|
64 | - * @param null $objExercise |
|
65 | - * @return null|false |
|
66 | - */ |
|
67 | - public function processCreation($form, $objExercise = null) |
|
68 | - { |
|
69 | - $file_info = $form->getSubmitValue('imageUpload'); |
|
70 | - $_course = api_get_course_info(); |
|
71 | - parent::processCreation($form, $objExercise); |
|
72 | - |
|
73 | - if(!empty($file_info['tmp_name'])) { |
|
74 | - $this->uploadPicture($file_info['tmp_name'], $file_info['name']); |
|
75 | - $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'; |
|
76 | - $picturePath = $documentPath.'/images'; |
|
77 | - |
|
78 | - // fixed width ang height |
|
79 | - if (file_exists($picturePath.'/'.$this->picture)) { |
|
80 | - $this->resizePicture('width', 800); |
|
81 | - $this->save(); |
|
82 | - } else { |
|
83 | - return false; |
|
84 | - } |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - function createAnswersForm($form) |
|
89 | - { |
|
90 | - // nothing |
|
91 | - } |
|
92 | - |
|
93 | - function processAnswersCreation($form) |
|
94 | - { |
|
95 | - // nothing |
|
96 | - } |
|
49 | + // setting the save button here and not in the question class.php |
|
50 | + // Saving a question |
|
51 | + $form->addButtonSave(get_lang('GoToQuestion'), 'submitQuestion'); |
|
52 | + //$form->addButtonSave(get_lang('GoToQuestion'), 'submitQuestion'); |
|
53 | + $form->addRule('imageUpload', get_lang('OnlyImagesAllowed'), 'filetype', array ('jpg', 'jpeg', 'png', 'gif')); |
|
54 | + $form->addRule('imageUpload', get_lang('NoImage'), 'uploadedfile'); |
|
55 | + } else { |
|
56 | + // setting the save button here and not in the question class.php |
|
57 | + // Editing a question |
|
58 | + $form->addButtonUpdate(get_lang('ModifyExercise'), 'submitQuestion'); |
|
59 | + } |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * @param FormValidator $form |
|
64 | + * @param null $objExercise |
|
65 | + * @return null|false |
|
66 | + */ |
|
67 | + public function processCreation($form, $objExercise = null) |
|
68 | + { |
|
69 | + $file_info = $form->getSubmitValue('imageUpload'); |
|
70 | + $_course = api_get_course_info(); |
|
71 | + parent::processCreation($form, $objExercise); |
|
72 | + |
|
73 | + if(!empty($file_info['tmp_name'])) { |
|
74 | + $this->uploadPicture($file_info['tmp_name'], $file_info['name']); |
|
75 | + $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'; |
|
76 | + $picturePath = $documentPath.'/images'; |
|
77 | + |
|
78 | + // fixed width ang height |
|
79 | + if (file_exists($picturePath.'/'.$this->picture)) { |
|
80 | + $this->resizePicture('width', 800); |
|
81 | + $this->save(); |
|
82 | + } else { |
|
83 | + return false; |
|
84 | + } |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + function createAnswersForm($form) |
|
89 | + { |
|
90 | + // nothing |
|
91 | + } |
|
92 | + |
|
93 | + function processAnswersCreation($form) |
|
94 | + { |
|
95 | + // nothing |
|
96 | + } |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -101,38 +101,38 @@ discard block |
||
101 | 101 | */ |
102 | 102 | class HotSpotDelineation extends HotSpot |
103 | 103 | { |
104 | - public static $typePicture = 'hotspot-delineation.png'; |
|
105 | - public static $explanationLangVar = 'HotspotDelineation'; |
|
104 | + public static $typePicture = 'hotspot-delineation.png'; |
|
105 | + public static $explanationLangVar = 'HotspotDelineation'; |
|
106 | 106 | |
107 | 107 | /** |
108 | 108 | * HotSpotDelineation constructor. |
109 | 109 | */ |
110 | - public function __construct() |
|
111 | - { |
|
112 | - parent::__construct(); |
|
113 | - $this -> type = HOT_SPOT_DELINEATION; |
|
114 | - |
|
115 | - } |
|
116 | - |
|
117 | - function createForm(&$form, $fck_config=0) |
|
118 | - { |
|
119 | - parent::createForm ($form, $fck_config); |
|
120 | - } |
|
121 | - |
|
122 | - function processCreation ($form, $objExercise = null) |
|
123 | - { |
|
124 | - $file_info = $form -> getSubmitValue('imageUpload'); |
|
125 | - parent::processCreation ($form, $objExercise); |
|
126 | - } |
|
127 | - |
|
128 | - function createAnswersForm ($form) |
|
129 | - { |
|
130 | - parent::createAnswersForm ($form); |
|
131 | - } |
|
132 | - |
|
133 | - function processAnswersCreation ($form) |
|
134 | - { |
|
135 | - parent::processAnswersCreation ($form); |
|
136 | - } |
|
110 | + public function __construct() |
|
111 | + { |
|
112 | + parent::__construct(); |
|
113 | + $this -> type = HOT_SPOT_DELINEATION; |
|
114 | + |
|
115 | + } |
|
116 | + |
|
117 | + function createForm(&$form, $fck_config=0) |
|
118 | + { |
|
119 | + parent::createForm ($form, $fck_config); |
|
120 | + } |
|
121 | + |
|
122 | + function processCreation ($form, $objExercise = null) |
|
123 | + { |
|
124 | + $file_info = $form -> getSubmitValue('imageUpload'); |
|
125 | + parent::processCreation ($form, $objExercise); |
|
126 | + } |
|
127 | + |
|
128 | + function createAnswersForm ($form) |
|
129 | + { |
|
130 | + parent::createAnswersForm ($form); |
|
131 | + } |
|
132 | + |
|
133 | + function processAnswersCreation ($form) |
|
134 | + { |
|
135 | + parent::processAnswersCreation ($form); |
|
136 | + } |
|
137 | 137 | } |
138 | 138 |
@@ -51,15 +51,15 @@ discard block |
||
51 | 51 | /** |
52 | 52 | * Displays the title + grid |
53 | 53 | */ |
54 | - public function display() |
|
54 | + public function display() |
|
55 | 55 | { |
56 | - // action links |
|
57 | - echo '<div class="actions" style="margin-bottom:20px">'; |
|
56 | + // action links |
|
57 | + echo '<div class="actions" style="margin-bottom:20px">'; |
|
58 | 58 | echo '<a href="grade_models.php">'.Display::return_icon('back.png',get_lang('Back'),'', ICON_SIZE_MEDIUM).'</a>'; |
59 | - echo '<a href="'.api_get_self().'?action=add">'.Display::return_icon('add.png', get_lang('Add'), '', ICON_SIZE_MEDIUM).'</a>'; |
|
60 | - echo '</div>'; |
|
59 | + echo '<a href="'.api_get_self().'?action=add">'.Display::return_icon('add.png', get_lang('Add'), '', ICON_SIZE_MEDIUM).'</a>'; |
|
60 | + echo '</div>'; |
|
61 | 61 | echo Display::grid_html('grade_model'); |
62 | - } |
|
62 | + } |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * Returns a Form validator Obj |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | } |
118 | 118 | |
119 | 119 | $form->addElement('hidden', 'maxvalue', '100'); |
120 | - $form->addElement('hidden', 'minvalue', '0'); |
|
120 | + $form->addElement('hidden', 'minvalue', '0'); |
|
121 | 121 | $renderer = & $form->defaultRenderer(); |
122 | 122 | |
123 | 123 | $component_array = array(); |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | // Setting the rules |
193 | 193 | $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required'); |
194 | 194 | |
195 | - return $form; |
|
195 | + return $form; |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | */ |
256 | 256 | public function delete($id) |
257 | 257 | { |
258 | - parent::delete($id); |
|
258 | + parent::delete($id); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
@@ -309,11 +309,11 @@ discard block |
||
309 | 309 | /** |
310 | 310 | * GradeModelComponents constructor. |
311 | 311 | */ |
312 | - public function __construct() |
|
312 | + public function __construct() |
|
313 | 313 | { |
314 | 314 | parent::__construct(); |
315 | 315 | $this->table = Database::get_main_table(TABLE_GRADE_MODEL_COMPONENTS); |
316 | - } |
|
316 | + } |
|
317 | 317 | |
318 | 318 | /** |
319 | 319 | * @param array $params |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | */ |
323 | 323 | public function save($params, $show_query = false) |
324 | 324 | { |
325 | - $id = parent::save($params, $show_query); |
|
325 | + $id = parent::save($params, $show_query); |
|
326 | 326 | |
327 | 327 | return $id; |
328 | 328 | } |