@@ -90,23 +90,23 @@ discard block |
||
90 | 90 | if (is_null($id) && is_null($user_id) && !is_null($evaluation_id)) { |
91 | 91 | // Verified_if_exist_evaluation |
92 | 92 | $sql = 'SELECT COUNT(*) AS count |
93 | - FROM ' . $tbl_grade_results . ' |
|
94 | - WHERE evaluation_id="' . Database::escape_string($evaluation_id) . '";'; |
|
93 | + FROM ' . $tbl_grade_results.' |
|
94 | + WHERE evaluation_id="' . Database::escape_string($evaluation_id).'";'; |
|
95 | 95 | $result = Database::query($sql); |
96 | 96 | $existEvaluation = Database::result($result, 0, 0); |
97 | 97 | |
98 | 98 | if ($existEvaluation != 0) { |
99 | 99 | if ($sessionId) { |
100 | 100 | $sql = 'SELECT c_id, user_id as user_id, status |
101 | - FROM ' . $tbl_session_rel_course_user . ' |
|
101 | + FROM ' . $tbl_session_rel_course_user.' |
|
102 | 102 | WHERE |
103 | 103 | status= 0 AND |
104 | - c_id = "' . api_get_course_int_id() . '" AND |
|
104 | + c_id = "' . api_get_course_int_id().'" AND |
|
105 | 105 | session_id = ' . $sessionId; |
106 | 106 | } else { |
107 | 107 | $sql = 'SELECT c_id, user_id, status |
108 | - FROM ' . $tbl_course_rel_course . ' |
|
109 | - WHERE status ="' . STUDENT . '" AND c_id = "' . api_get_course_int_id() . '" '; |
|
108 | + FROM ' . $tbl_course_rel_course.' |
|
109 | + WHERE status ="' . STUDENT.'" AND c_id = "'.api_get_course_int_id().'" '; |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | $res_course_rel_user = Database::query($sql); |
@@ -116,15 +116,15 @@ discard block |
||
116 | 116 | $current_date = api_get_utc_datetime(); |
117 | 117 | for ($i = 0; $i < count($list_user_course_list); $i++) { |
118 | 118 | $sql_verified = 'SELECT COUNT(*) AS count |
119 | - FROM ' . $tbl_grade_results . ' |
|
119 | + FROM ' . $tbl_grade_results.' |
|
120 | 120 | WHERE |
121 | - user_id="' . intval($list_user_course_list[$i]['user_id']) . '" AND |
|
122 | - evaluation_id="' . intval($evaluation_id) . '";'; |
|
121 | + user_id="' . intval($list_user_course_list[$i]['user_id']).'" AND |
|
122 | + evaluation_id="' . intval($evaluation_id).'";'; |
|
123 | 123 | $res_verified = Database::query($sql_verified); |
124 | 124 | $info_verified = Database::result($res_verified, 0, 0); |
125 | 125 | if ($info_verified == 0) { |
126 | - $sql_insert = 'INSERT INTO ' . $tbl_grade_results . '(user_id,evaluation_id,created_at,score) |
|
127 | - VALUES ("' . intval($list_user_course_list[$i]['user_id']) . '","' . intval($evaluation_id) . '","' . $current_date . '",0);'; |
|
126 | + $sql_insert = 'INSERT INTO '.$tbl_grade_results.'(user_id,evaluation_id,created_at,score) |
|
127 | + VALUES ("' . intval($list_user_course_list[$i]['user_id']).'","'.intval($evaluation_id).'","'.$current_date.'",0);'; |
|
128 | 128 | Database::query($sql_insert); |
129 | 129 | } |
130 | 130 | } |
@@ -148,16 +148,16 @@ discard block |
||
148 | 148 | |
149 | 149 | $paramcount = 0; |
150 | 150 | if (!empty($id)) { |
151 | - $sql.= ' WHERE gr.id = ' . intval($id); |
|
152 | - $paramcount ++; |
|
151 | + $sql .= ' WHERE gr.id = '.intval($id); |
|
152 | + $paramcount++; |
|
153 | 153 | } |
154 | 154 | if (!empty($user_id)) { |
155 | 155 | if ($paramcount != 0) |
156 | 156 | $sql .= ' AND'; |
157 | 157 | else |
158 | 158 | $sql .= ' WHERE'; |
159 | - $sql .= ' gr.user_id = ' . intval($user_id); |
|
160 | - $paramcount ++; |
|
159 | + $sql .= ' gr.user_id = '.intval($user_id); |
|
160 | + $paramcount++; |
|
161 | 161 | } |
162 | 162 | if (!empty($evaluation_id)) { |
163 | 163 | if ($paramcount != 0) { |
@@ -165,8 +165,8 @@ discard block |
||
165 | 165 | } else { |
166 | 166 | $sql .= ' WHERE'; |
167 | 167 | } |
168 | - $sql .= ' gr.evaluation_id = ' . intval($evaluation_id); |
|
169 | - $paramcount ++; |
|
168 | + $sql .= ' gr.evaluation_id = '.intval($evaluation_id); |
|
169 | + $paramcount++; |
|
170 | 170 | } |
171 | 171 | $sql .= ' ORDER BY u.lastname, u.firstname'; |
172 | 172 | $result = Database::query($sql); |
@@ -191,17 +191,17 @@ discard block |
||
191 | 191 | { |
192 | 192 | if (isset($this->user_id) && isset($this->evaluation)) { |
193 | 193 | $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
194 | - $sql = "INSERT INTO " . $tbl_grade_results |
|
194 | + $sql = "INSERT INTO ".$tbl_grade_results |
|
195 | 195 | . " (user_id, evaluation_id, |
196 | 196 | created_at"; |
197 | 197 | if (isset($this->score)) { |
198 | 198 | $sql .= ",score"; |
199 | 199 | } |
200 | 200 | $sql .= ") VALUES |
201 | - (" . (int) $this->get_user_id() . ", " . (int) $this->get_evaluation_id() |
|
202 | - . ", '" . $this->get_date() . "' "; |
|
201 | + (" . (int) $this->get_user_id().", ".(int) $this->get_evaluation_id() |
|
202 | + . ", '".$this->get_date()."' "; |
|
203 | 203 | if (isset($this->score)) { |
204 | - $sql .= ", " . $this->get_score(); |
|
204 | + $sql .= ", ".$this->get_score(); |
|
205 | 205 | } |
206 | 206 | $sql .= ")"; |
207 | 207 | Database::query($sql); |
@@ -222,16 +222,16 @@ discard block |
||
222 | 222 | $arr_result = $result->load(null, $userid, $evaluationid); |
223 | 223 | $arr = get_object_vars($arr_result[0]); |
224 | 224 | |
225 | - $sql = 'INSERT INTO ' . $tbl_grade_results_log |
|
225 | + $sql = 'INSERT INTO '.$tbl_grade_results_log |
|
226 | 226 | . ' (id_result,user_id, evaluation_id,created_at'; |
227 | 227 | if (isset($arr['score'])) { |
228 | 228 | $sql .= ',score'; |
229 | 229 | } |
230 | 230 | $sql .= ') VALUES |
231 | - (' . (int) $arr['id'] . ',' . (int) $arr['user_id'] . ', ' . (int) $arr['evaluation'] |
|
232 | - . ", '" . api_get_utc_datetime() . "'"; |
|
231 | + (' . (int) $arr['id'].','.(int) $arr['user_id'].', '.(int) $arr['evaluation'] |
|
232 | + . ", '".api_get_utc_datetime()."'"; |
|
233 | 233 | if (isset($arr['score'])) { |
234 | - $sql .= ', ' . $arr['score']; |
|
234 | + $sql .= ', '.$arr['score']; |
|
235 | 235 | } |
236 | 236 | $sql .= ')'; |
237 | 237 | |
@@ -247,16 +247,16 @@ discard block |
||
247 | 247 | public function save() |
248 | 248 | { |
249 | 249 | $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
250 | - $sql = 'UPDATE ' . $tbl_grade_results . ' |
|
250 | + $sql = 'UPDATE '.$tbl_grade_results.' |
|
251 | 251 | SET user_id = ' . $this->get_user_id() |
252 | - . ', evaluation_id = ' . $this->get_evaluation_id() |
|
252 | + . ', evaluation_id = '.$this->get_evaluation_id() |
|
253 | 253 | . ', score = '; |
254 | 254 | if (isset($this->score)) { |
255 | 255 | $sql .= $this->get_score(); |
256 | 256 | } else { |
257 | 257 | $sql .= 'null'; |
258 | 258 | } |
259 | - $sql .= ' WHERE id = ' . $this->id; |
|
259 | + $sql .= ' WHERE id = '.$this->id; |
|
260 | 260 | // no need to update creation date |
261 | 261 | Database::query($sql); |
262 | 262 | } |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | public function delete() |
268 | 268 | { |
269 | 269 | $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
270 | - $sql = 'DELETE FROM ' . $tbl_grade_results . ' WHERE id = ' . $this->id; |
|
270 | + $sql = 'DELETE FROM '.$tbl_grade_results.' WHERE id = '.$this->id; |
|
271 | 271 | Database::query($sql); |
272 | 272 | } |
273 | 273 | } |
@@ -152,10 +152,11 @@ |
||
152 | 152 | $paramcount ++; |
153 | 153 | } |
154 | 154 | if (!empty($user_id)) { |
155 | - if ($paramcount != 0) |
|
156 | - $sql .= ' AND'; |
|
157 | - else |
|
158 | - $sql .= ' WHERE'; |
|
155 | + if ($paramcount != 0) { |
|
156 | + $sql .= ' AND'; |
|
157 | + } else { |
|
158 | + $sql .= ' WHERE'; |
|
159 | + } |
|
159 | 160 | $sql .= ' gr.user_id = ' . intval($user_id); |
160 | 161 | $paramcount ++; |
161 | 162 | } |
@@ -223,36 +223,36 @@ discard block |
||
223 | 223 | $paramcount = 0; |
224 | 224 | |
225 | 225 | if (isset ($id)) { |
226 | - $sql.= ' WHERE id = '.intval($id); |
|
227 | - $paramcount ++; |
|
226 | + $sql .= ' WHERE id = '.intval($id); |
|
227 | + $paramcount++; |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | if (isset ($user_id)) { |
231 | 231 | if ($paramcount != 0) $sql .= ' AND'; |
232 | 232 | else $sql .= ' WHERE'; |
233 | 233 | $sql .= ' user_id = '.intval($user_id); |
234 | - $paramcount ++; |
|
234 | + $paramcount++; |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | if (isset ($course_code) && $course_code <> '-1') { |
238 | 238 | if ($paramcount != 0) $sql .= ' AND'; |
239 | 239 | else $sql .= ' WHERE'; |
240 | 240 | $sql .= " course_code = '".Database::escape_string($course_code)."'"; |
241 | - $paramcount ++; |
|
241 | + $paramcount++; |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | if (isset ($category_id)) { |
245 | 245 | if ($paramcount != 0) $sql .= ' AND'; |
246 | 246 | else $sql .= ' WHERE'; |
247 | 247 | $sql .= ' category_id = '.intval($category_id); |
248 | - $paramcount ++; |
|
248 | + $paramcount++; |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | if (isset ($visible)) { |
252 | 252 | if ($paramcount != 0) $sql .= ' AND'; |
253 | 253 | else $sql .= ' WHERE'; |
254 | 254 | $sql .= ' visible = '.intval($visible); |
255 | - $paramcount ++; |
|
255 | + $paramcount++; |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | if (isset ($locked)) { |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | $alleval = array(); |
279 | 279 | if (Database::num_rows($result)) { |
280 | 280 | while ($data = Database::fetch_array($result)) { |
281 | - $eval= new Evaluation(); |
|
281 | + $eval = new Evaluation(); |
|
282 | 282 | $eval->set_id($data['id']); |
283 | 283 | $eval->set_name($data['name']); |
284 | 284 | $eval->set_description($data['description']); |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
364 | 364 | $tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG); |
365 | 365 | $eval = new Evaluation(); |
366 | - $dateobject = $eval->load($idevaluation,null,null,null,null); |
|
366 | + $dateobject = $eval->load($idevaluation, null, null, null, null); |
|
367 | 367 | $arreval = get_object_vars($dateobject[0]); |
368 | 368 | if (!empty($arreval['id'])) { |
369 | 369 | $sql = 'SELECT weight from '.$tbl_grade_evaluations.' |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | .', description = '; |
398 | 398 | if (isset($this->description)) { |
399 | 399 | $sql .= "'".Database::escape_string($this->get_description())."'"; |
400 | - }else { |
|
400 | + } else { |
|
401 | 401 | $sql .= 'null'; |
402 | 402 | } |
403 | 403 | $sql .= ', user_id = '.intval($this->get_user_id()) |
@@ -468,17 +468,17 @@ discard block |
||
468 | 468 | $sql .= ' AND user_id = '.api_get_user_id(); |
469 | 469 | } |
470 | 470 | |
471 | - }else { |
|
471 | + } else { |
|
472 | 472 | $sql .= ' AND user_id = '.api_get_user_id(); |
473 | 473 | } |
474 | 474 | |
475 | 475 | if (!isset ($parent)) { |
476 | - $sql.= ' AND category_id is null'; |
|
476 | + $sql .= ' AND category_id is null'; |
|
477 | 477 | } else { |
478 | - $sql.= ' AND category_id = '.intval($parent); |
|
478 | + $sql .= ' AND category_id = '.intval($parent); |
|
479 | 479 | } |
480 | 480 | $result = Database::query($sql); |
481 | - $number=Database::fetch_row($result); |
|
481 | + $number = Database::fetch_row($result); |
|
482 | 482 | |
483 | 483 | return $number[0] != 0; |
484 | 484 | } |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | FROM '.$tbl_grade_results.' |
495 | 495 | WHERE evaluation_id = '.intval($this->id); |
496 | 496 | $result = Database::query($sql); |
497 | - $number=Database::fetch_row($result); |
|
497 | + $number = Database::fetch_row($result); |
|
498 | 498 | |
499 | 499 | return ($number[0] != 0); |
500 | 500 | } |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | $results = isset($data[$key]) ? $data[$key] : null; |
545 | 545 | |
546 | 546 | if ($useSession == false) { |
547 | - $results = null; |
|
547 | + $results = null; |
|
548 | 548 | } |
549 | 549 | if (empty($results)) { |
550 | 550 | $results = Result::load(null, $stud_id, $this->id); |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | $data = Session::read('calc_score'); |
571 | 571 | $allResults = isset($data[$key]) ? $data[$key] : null; |
572 | 572 | if ($useSession == false) { |
573 | - $allResults = null; |
|
573 | + $allResults = null; |
|
574 | 574 | } |
575 | 575 | if (empty($allResults)) { |
576 | 576 | $allResults = Result::load(null, null, $this->id); |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | return array($bestResult, $weight); |
603 | 603 | break; |
604 | 604 | case 'average': |
605 | - return array($sumResult/$count, $weight); |
|
605 | + return array($sumResult / $count, $weight); |
|
606 | 606 | break; |
607 | 607 | case 'ranking': |
608 | 608 | $students = array(); |
@@ -640,17 +640,17 @@ discard block |
||
640 | 640 | $targets[] = $root; |
641 | 641 | |
642 | 642 | if (isset($this->course_code) && !empty($this->course_code)) { |
643 | - $crscats = Category::load(null,null,$this->course_code,0); |
|
643 | + $crscats = Category::load(null, null, $this->course_code, 0); |
|
644 | 644 | foreach ($crscats as $cat) { |
645 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
646 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
645 | + $targets[] = array($cat->get_id(), $cat->get_name(), $level + 1); |
|
646 | + $targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id()); |
|
647 | 647 | } |
648 | 648 | } |
649 | 649 | |
650 | - $indcats = Category::load(null,$user,0,0); |
|
650 | + $indcats = Category::load(null, $user, 0, 0); |
|
651 | 651 | foreach ($indcats as $cat) { |
652 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
653 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
652 | + $targets[] = array($cat->get_id(), $cat->get_name(), $level + 1); |
|
653 | + $targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id()); |
|
654 | 654 | } |
655 | 655 | |
656 | 656 | return $targets; |
@@ -661,10 +661,10 @@ discard block |
||
661 | 661 | */ |
662 | 662 | private function add_target_subcategories($targets, $level, $catid) |
663 | 663 | { |
664 | - $subcats = Category::load(null,null,null,$catid); |
|
664 | + $subcats = Category::load(null, null, null, $catid); |
|
665 | 665 | foreach ($subcats as $cat) { |
666 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
667 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
666 | + $targets[] = array($cat->get_id(), $cat->get_name(), $level + 1); |
|
667 | + $targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id()); |
|
668 | 668 | } |
669 | 669 | return $targets; |
670 | 670 | } |
@@ -743,7 +743,7 @@ discard block |
||
743 | 743 | * @return array evaluation objects matching the search criterium |
744 | 744 | * @todo can be written more efficiently using a new (but very complex) sql query |
745 | 745 | */ |
746 | - public function find_evaluations($name_mask,$selectcat) |
|
746 | + public function find_evaluations($name_mask, $selectcat) |
|
747 | 747 | { |
748 | 748 | $rootcat = Category::load($selectcat); |
749 | 749 | $evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true); |
@@ -228,36 +228,51 @@ discard block |
||
228 | 228 | } |
229 | 229 | |
230 | 230 | if (isset ($user_id)) { |
231 | - if ($paramcount != 0) $sql .= ' AND'; |
|
232 | - else $sql .= ' WHERE'; |
|
231 | + if ($paramcount != 0) { |
|
232 | + $sql .= ' AND'; |
|
233 | + } else { |
|
234 | + $sql .= ' WHERE'; |
|
235 | + } |
|
233 | 236 | $sql .= ' user_id = '.intval($user_id); |
234 | 237 | $paramcount ++; |
235 | 238 | } |
236 | 239 | |
237 | 240 | if (isset ($course_code) && $course_code <> '-1') { |
238 | - if ($paramcount != 0) $sql .= ' AND'; |
|
239 | - else $sql .= ' WHERE'; |
|
241 | + if ($paramcount != 0) { |
|
242 | + $sql .= ' AND'; |
|
243 | + } else { |
|
244 | + $sql .= ' WHERE'; |
|
245 | + } |
|
240 | 246 | $sql .= " course_code = '".Database::escape_string($course_code)."'"; |
241 | 247 | $paramcount ++; |
242 | 248 | } |
243 | 249 | |
244 | 250 | if (isset ($category_id)) { |
245 | - if ($paramcount != 0) $sql .= ' AND'; |
|
246 | - else $sql .= ' WHERE'; |
|
251 | + if ($paramcount != 0) { |
|
252 | + $sql .= ' AND'; |
|
253 | + } else { |
|
254 | + $sql .= ' WHERE'; |
|
255 | + } |
|
247 | 256 | $sql .= ' category_id = '.intval($category_id); |
248 | 257 | $paramcount ++; |
249 | 258 | } |
250 | 259 | |
251 | 260 | if (isset ($visible)) { |
252 | - if ($paramcount != 0) $sql .= ' AND'; |
|
253 | - else $sql .= ' WHERE'; |
|
261 | + if ($paramcount != 0) { |
|
262 | + $sql .= ' AND'; |
|
263 | + } else { |
|
264 | + $sql .= ' WHERE'; |
|
265 | + } |
|
254 | 266 | $sql .= ' visible = '.intval($visible); |
255 | 267 | $paramcount ++; |
256 | 268 | } |
257 | 269 | |
258 | 270 | if (isset ($locked)) { |
259 | - if ($paramcount != 0) $sql .= ' AND'; |
|
260 | - else $sql .= ' WHERE'; |
|
271 | + if ($paramcount != 0) { |
|
272 | + $sql .= ' AND'; |
|
273 | + } else { |
|
274 | + $sql .= ' WHERE'; |
|
275 | + } |
|
261 | 276 | $sql .= ' locked = '.intval($locked); |
262 | 277 | } |
263 | 278 | |
@@ -397,7 +412,7 @@ discard block |
||
397 | 412 | .', description = '; |
398 | 413 | if (isset($this->description)) { |
399 | 414 | $sql .= "'".Database::escape_string($this->get_description())."'"; |
400 | - }else { |
|
415 | + } else { |
|
401 | 416 | $sql .= 'null'; |
402 | 417 | } |
403 | 418 | $sql .= ', user_id = '.intval($this->get_user_id()) |
@@ -468,7 +483,7 @@ discard block |
||
468 | 483 | $sql .= ' AND user_id = '.api_get_user_id(); |
469 | 484 | } |
470 | 485 | |
471 | - }else { |
|
486 | + } else { |
|
472 | 487 | $sql .= ' AND user_id = '.api_get_user_id(); |
473 | 488 | } |
474 | 489 |
@@ -273,7 +273,7 @@ |
||
273 | 273 | |
274 | 274 | |
275 | 275 | /** |
276 | - * @param array $result |
|
276 | + * @param Doctrine\DBAL\Driver\Statement|null $result |
|
277 | 277 | * @return array |
278 | 278 | */ |
279 | 279 | private static function create_evaluation_objects_from_sql_result($result) |
@@ -9,365 +9,365 @@ discard block |
||
9 | 9 | */ |
10 | 10 | class Evaluation implements GradebookItem |
11 | 11 | { |
12 | - private $id; |
|
13 | - private $name; |
|
14 | - private $description; |
|
15 | - private $user_id; |
|
16 | - private $course_code; |
|
17 | - /** @var Category */ |
|
18 | - private $category; |
|
19 | - private $created_at; |
|
20 | - private $weight; |
|
21 | - private $eval_max; |
|
22 | - private $visible; |
|
23 | - private $sessionId; |
|
24 | - public $studentList; |
|
25 | - |
|
26 | - /** |
|
27 | - * Construct |
|
28 | - */ |
|
29 | - public function __construct() |
|
30 | - { |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @return Category |
|
35 | - */ |
|
36 | - public function getCategory() |
|
37 | - { |
|
38 | - return $this->category; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @param Category $category |
|
43 | - */ |
|
44 | - public function setCategory($category) |
|
45 | - { |
|
46 | - $this->category = $category; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * @return int |
|
51 | - */ |
|
52 | - public function get_category_id() |
|
53 | - { |
|
54 | - return $this->category->get_id(); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param int $category_id |
|
59 | - */ |
|
60 | - public function set_category_id($category_id) |
|
61 | - { |
|
62 | - $categories = Category::load($category_id); |
|
63 | - if (isset($categories[0])) { |
|
64 | - $this->setCategory($categories[0]); |
|
65 | - } |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @return int |
|
70 | - */ |
|
71 | - public function get_id() |
|
72 | - { |
|
73 | - return $this->id; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function get_name() |
|
80 | - { |
|
81 | - return $this->name; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - public function get_description() |
|
88 | - { |
|
89 | - return $this->description; |
|
90 | - } |
|
91 | - |
|
92 | - public function get_user_id() |
|
93 | - { |
|
94 | - return $this->user_id; |
|
95 | - } |
|
96 | - |
|
97 | - public function get_course_code() |
|
98 | - { |
|
99 | - return $this->course_code; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @return int |
|
104 | - */ |
|
105 | - public function getSessionId() |
|
106 | - { |
|
107 | - return $this->sessionId; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @param int $sessionId |
|
112 | - */ |
|
113 | - public function setSessionId($sessionId) |
|
114 | - { |
|
115 | - $this->sessionId = intval($sessionId); |
|
116 | - } |
|
117 | - |
|
118 | - public function get_date() |
|
119 | - { |
|
120 | - return $this->created_at; |
|
121 | - } |
|
122 | - |
|
123 | - public function get_weight() |
|
124 | - { |
|
125 | - return $this->weight; |
|
126 | - } |
|
127 | - |
|
128 | - public function get_max() |
|
129 | - { |
|
130 | - return $this->eval_max; |
|
131 | - } |
|
132 | - |
|
133 | - public function get_type() |
|
134 | - { |
|
135 | - return $this->type; |
|
136 | - } |
|
137 | - |
|
138 | - public function is_visible() |
|
139 | - { |
|
140 | - return $this->visible; |
|
141 | - } |
|
142 | - |
|
143 | - public function get_locked() |
|
144 | - { |
|
145 | - return $this->locked; |
|
146 | - } |
|
147 | - |
|
148 | - public function is_locked() |
|
149 | - { |
|
150 | - return isset($this->locked) && $this->locked == 1 ? true : false; |
|
151 | - } |
|
152 | - |
|
153 | - public function set_id($id) |
|
154 | - { |
|
155 | - $this->id = $id; |
|
156 | - } |
|
157 | - |
|
158 | - public function set_name($name) |
|
159 | - { |
|
160 | - $this->name = $name; |
|
161 | - } |
|
162 | - |
|
163 | - public function set_description($description) |
|
164 | - { |
|
165 | - $this->description = $description; |
|
166 | - } |
|
167 | - |
|
168 | - public function set_user_id($user_id) |
|
169 | - { |
|
170 | - $this->user_id = $user_id; |
|
171 | - } |
|
172 | - |
|
173 | - public function set_course_code($course_code) |
|
174 | - { |
|
175 | - $this->course_code = $course_code; |
|
176 | - } |
|
177 | - |
|
178 | - public function set_date($date) |
|
179 | - { |
|
180 | - $this->created_at = $date; |
|
181 | - } |
|
182 | - |
|
183 | - public function set_weight($weight) |
|
184 | - { |
|
185 | - $this->weight = $weight; |
|
186 | - } |
|
187 | - |
|
188 | - public function set_max($max) |
|
189 | - { |
|
190 | - $this->eval_max = $max; |
|
191 | - } |
|
192 | - |
|
193 | - public function set_visible($visible) |
|
194 | - { |
|
195 | - $this->visible = $visible; |
|
196 | - } |
|
197 | - |
|
198 | - public function set_type($type) |
|
199 | - { |
|
200 | - $this->type = $type; |
|
201 | - } |
|
202 | - |
|
203 | - public function set_locked($locked) |
|
204 | - { |
|
205 | - $this->locked = $locked; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Retrieve evaluations and return them as an array of Evaluation objects |
|
210 | - * @param int $id evaluation id |
|
211 | - * @param int $user_id user id (evaluation owner) |
|
212 | - * @param string $course_code course code |
|
213 | - * @param int $category_id parent category |
|
214 | - * @param integer $visible visible |
|
215 | - */ |
|
216 | - public static function load( |
|
217 | - $id = null, |
|
218 | - $user_id = null, |
|
219 | - $course_code = null, |
|
220 | - $category_id = null, |
|
221 | - $visible = null, |
|
222 | - $locked = null |
|
223 | - ) { |
|
224 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
225 | - $sql = 'SELECT * FROM '.$tbl_grade_evaluations; |
|
226 | - $paramcount = 0; |
|
227 | - |
|
228 | - if (isset ($id)) { |
|
229 | - $sql.= ' WHERE id = '.intval($id); |
|
230 | - $paramcount ++; |
|
231 | - } |
|
232 | - |
|
233 | - if (isset($user_id)) { |
|
234 | - if ($paramcount != 0) $sql .= ' AND'; |
|
235 | - else $sql .= ' WHERE'; |
|
236 | - $sql .= ' user_id = '.intval($user_id); |
|
237 | - $paramcount ++; |
|
238 | - } |
|
239 | - |
|
240 | - if (isset($course_code) && $course_code <> '-1') { |
|
241 | - if ($paramcount != 0) $sql .= ' AND'; |
|
242 | - else $sql .= ' WHERE'; |
|
243 | - $sql .= " course_code = '".Database::escape_string($course_code)."'"; |
|
244 | - $paramcount ++; |
|
245 | - } |
|
246 | - |
|
247 | - if (isset($category_id)) { |
|
248 | - if ($paramcount != 0) $sql .= ' AND'; |
|
249 | - else $sql .= ' WHERE'; |
|
250 | - $sql .= ' category_id = '.intval($category_id); |
|
251 | - $paramcount ++; |
|
252 | - } |
|
253 | - |
|
254 | - if (isset($visible)) { |
|
255 | - if ($paramcount != 0) $sql .= ' AND'; |
|
256 | - else $sql .= ' WHERE'; |
|
257 | - $sql .= ' visible = '.intval($visible); |
|
258 | - $paramcount ++; |
|
259 | - } |
|
260 | - |
|
261 | - if (isset($locked)) { |
|
262 | - if ($paramcount != 0) $sql .= ' AND'; |
|
263 | - else $sql .= ' WHERE'; |
|
264 | - $sql .= ' locked = '.intval($locked); |
|
265 | - } |
|
266 | - |
|
267 | - $result = Database::query($sql); |
|
268 | - $allEval = Evaluation::create_evaluation_objects_from_sql_result($result); |
|
269 | - |
|
270 | - return $allEval; |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * @param array $result |
|
275 | - * @return array |
|
276 | - */ |
|
277 | - private static function create_evaluation_objects_from_sql_result($result) |
|
278 | - { |
|
279 | - $alleval = array(); |
|
280 | - if (Database::num_rows($result)) { |
|
281 | - while ($data = Database::fetch_array($result)) { |
|
282 | - $eval= new Evaluation(); |
|
283 | - $eval->set_id($data['id']); |
|
284 | - $eval->set_name($data['name']); |
|
285 | - $eval->set_description($data['description']); |
|
286 | - $eval->set_user_id($data['user_id']); |
|
287 | - $eval->set_course_code($data['course_code']); |
|
288 | - $eval->set_category_id($data['category_id']); |
|
289 | - $eval->set_date(api_get_local_time($data['created_at'])); |
|
290 | - $eval->set_weight($data['weight']); |
|
291 | - $eval->set_max($data['max']); |
|
292 | - $eval->set_visible($data['visible']); |
|
293 | - $eval->set_type($data['type']); |
|
294 | - $eval->set_locked($data['locked']); |
|
295 | - $eval->setSessionId(api_get_session_id()); |
|
296 | - |
|
297 | - $alleval[] = $eval; |
|
298 | - } |
|
299 | - } |
|
300 | - |
|
301 | - return $alleval; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Insert this evaluation into the database |
|
306 | - */ |
|
12 | + private $id; |
|
13 | + private $name; |
|
14 | + private $description; |
|
15 | + private $user_id; |
|
16 | + private $course_code; |
|
17 | + /** @var Category */ |
|
18 | + private $category; |
|
19 | + private $created_at; |
|
20 | + private $weight; |
|
21 | + private $eval_max; |
|
22 | + private $visible; |
|
23 | + private $sessionId; |
|
24 | + public $studentList; |
|
25 | + |
|
26 | + /** |
|
27 | + * Construct |
|
28 | + */ |
|
29 | + public function __construct() |
|
30 | + { |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @return Category |
|
35 | + */ |
|
36 | + public function getCategory() |
|
37 | + { |
|
38 | + return $this->category; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @param Category $category |
|
43 | + */ |
|
44 | + public function setCategory($category) |
|
45 | + { |
|
46 | + $this->category = $category; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * @return int |
|
51 | + */ |
|
52 | + public function get_category_id() |
|
53 | + { |
|
54 | + return $this->category->get_id(); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param int $category_id |
|
59 | + */ |
|
60 | + public function set_category_id($category_id) |
|
61 | + { |
|
62 | + $categories = Category::load($category_id); |
|
63 | + if (isset($categories[0])) { |
|
64 | + $this->setCategory($categories[0]); |
|
65 | + } |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @return int |
|
70 | + */ |
|
71 | + public function get_id() |
|
72 | + { |
|
73 | + return $this->id; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function get_name() |
|
80 | + { |
|
81 | + return $this->name; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + public function get_description() |
|
88 | + { |
|
89 | + return $this->description; |
|
90 | + } |
|
91 | + |
|
92 | + public function get_user_id() |
|
93 | + { |
|
94 | + return $this->user_id; |
|
95 | + } |
|
96 | + |
|
97 | + public function get_course_code() |
|
98 | + { |
|
99 | + return $this->course_code; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @return int |
|
104 | + */ |
|
105 | + public function getSessionId() |
|
106 | + { |
|
107 | + return $this->sessionId; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @param int $sessionId |
|
112 | + */ |
|
113 | + public function setSessionId($sessionId) |
|
114 | + { |
|
115 | + $this->sessionId = intval($sessionId); |
|
116 | + } |
|
117 | + |
|
118 | + public function get_date() |
|
119 | + { |
|
120 | + return $this->created_at; |
|
121 | + } |
|
122 | + |
|
123 | + public function get_weight() |
|
124 | + { |
|
125 | + return $this->weight; |
|
126 | + } |
|
127 | + |
|
128 | + public function get_max() |
|
129 | + { |
|
130 | + return $this->eval_max; |
|
131 | + } |
|
132 | + |
|
133 | + public function get_type() |
|
134 | + { |
|
135 | + return $this->type; |
|
136 | + } |
|
137 | + |
|
138 | + public function is_visible() |
|
139 | + { |
|
140 | + return $this->visible; |
|
141 | + } |
|
142 | + |
|
143 | + public function get_locked() |
|
144 | + { |
|
145 | + return $this->locked; |
|
146 | + } |
|
147 | + |
|
148 | + public function is_locked() |
|
149 | + { |
|
150 | + return isset($this->locked) && $this->locked == 1 ? true : false; |
|
151 | + } |
|
152 | + |
|
153 | + public function set_id($id) |
|
154 | + { |
|
155 | + $this->id = $id; |
|
156 | + } |
|
157 | + |
|
158 | + public function set_name($name) |
|
159 | + { |
|
160 | + $this->name = $name; |
|
161 | + } |
|
162 | + |
|
163 | + public function set_description($description) |
|
164 | + { |
|
165 | + $this->description = $description; |
|
166 | + } |
|
167 | + |
|
168 | + public function set_user_id($user_id) |
|
169 | + { |
|
170 | + $this->user_id = $user_id; |
|
171 | + } |
|
172 | + |
|
173 | + public function set_course_code($course_code) |
|
174 | + { |
|
175 | + $this->course_code = $course_code; |
|
176 | + } |
|
177 | + |
|
178 | + public function set_date($date) |
|
179 | + { |
|
180 | + $this->created_at = $date; |
|
181 | + } |
|
182 | + |
|
183 | + public function set_weight($weight) |
|
184 | + { |
|
185 | + $this->weight = $weight; |
|
186 | + } |
|
187 | + |
|
188 | + public function set_max($max) |
|
189 | + { |
|
190 | + $this->eval_max = $max; |
|
191 | + } |
|
192 | + |
|
193 | + public function set_visible($visible) |
|
194 | + { |
|
195 | + $this->visible = $visible; |
|
196 | + } |
|
197 | + |
|
198 | + public function set_type($type) |
|
199 | + { |
|
200 | + $this->type = $type; |
|
201 | + } |
|
202 | + |
|
203 | + public function set_locked($locked) |
|
204 | + { |
|
205 | + $this->locked = $locked; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Retrieve evaluations and return them as an array of Evaluation objects |
|
210 | + * @param int $id evaluation id |
|
211 | + * @param int $user_id user id (evaluation owner) |
|
212 | + * @param string $course_code course code |
|
213 | + * @param int $category_id parent category |
|
214 | + * @param integer $visible visible |
|
215 | + */ |
|
216 | + public static function load( |
|
217 | + $id = null, |
|
218 | + $user_id = null, |
|
219 | + $course_code = null, |
|
220 | + $category_id = null, |
|
221 | + $visible = null, |
|
222 | + $locked = null |
|
223 | + ) { |
|
224 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
225 | + $sql = 'SELECT * FROM '.$tbl_grade_evaluations; |
|
226 | + $paramcount = 0; |
|
227 | + |
|
228 | + if (isset ($id)) { |
|
229 | + $sql.= ' WHERE id = '.intval($id); |
|
230 | + $paramcount ++; |
|
231 | + } |
|
232 | + |
|
233 | + if (isset($user_id)) { |
|
234 | + if ($paramcount != 0) $sql .= ' AND'; |
|
235 | + else $sql .= ' WHERE'; |
|
236 | + $sql .= ' user_id = '.intval($user_id); |
|
237 | + $paramcount ++; |
|
238 | + } |
|
239 | + |
|
240 | + if (isset($course_code) && $course_code <> '-1') { |
|
241 | + if ($paramcount != 0) $sql .= ' AND'; |
|
242 | + else $sql .= ' WHERE'; |
|
243 | + $sql .= " course_code = '".Database::escape_string($course_code)."'"; |
|
244 | + $paramcount ++; |
|
245 | + } |
|
246 | + |
|
247 | + if (isset($category_id)) { |
|
248 | + if ($paramcount != 0) $sql .= ' AND'; |
|
249 | + else $sql .= ' WHERE'; |
|
250 | + $sql .= ' category_id = '.intval($category_id); |
|
251 | + $paramcount ++; |
|
252 | + } |
|
253 | + |
|
254 | + if (isset($visible)) { |
|
255 | + if ($paramcount != 0) $sql .= ' AND'; |
|
256 | + else $sql .= ' WHERE'; |
|
257 | + $sql .= ' visible = '.intval($visible); |
|
258 | + $paramcount ++; |
|
259 | + } |
|
260 | + |
|
261 | + if (isset($locked)) { |
|
262 | + if ($paramcount != 0) $sql .= ' AND'; |
|
263 | + else $sql .= ' WHERE'; |
|
264 | + $sql .= ' locked = '.intval($locked); |
|
265 | + } |
|
266 | + |
|
267 | + $result = Database::query($sql); |
|
268 | + $allEval = Evaluation::create_evaluation_objects_from_sql_result($result); |
|
269 | + |
|
270 | + return $allEval; |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * @param array $result |
|
275 | + * @return array |
|
276 | + */ |
|
277 | + private static function create_evaluation_objects_from_sql_result($result) |
|
278 | + { |
|
279 | + $alleval = array(); |
|
280 | + if (Database::num_rows($result)) { |
|
281 | + while ($data = Database::fetch_array($result)) { |
|
282 | + $eval= new Evaluation(); |
|
283 | + $eval->set_id($data['id']); |
|
284 | + $eval->set_name($data['name']); |
|
285 | + $eval->set_description($data['description']); |
|
286 | + $eval->set_user_id($data['user_id']); |
|
287 | + $eval->set_course_code($data['course_code']); |
|
288 | + $eval->set_category_id($data['category_id']); |
|
289 | + $eval->set_date(api_get_local_time($data['created_at'])); |
|
290 | + $eval->set_weight($data['weight']); |
|
291 | + $eval->set_max($data['max']); |
|
292 | + $eval->set_visible($data['visible']); |
|
293 | + $eval->set_type($data['type']); |
|
294 | + $eval->set_locked($data['locked']); |
|
295 | + $eval->setSessionId(api_get_session_id()); |
|
296 | + |
|
297 | + $alleval[] = $eval; |
|
298 | + } |
|
299 | + } |
|
300 | + |
|
301 | + return $alleval; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Insert this evaluation into the database |
|
306 | + */ |
|
307 | 307 | public function add() |
308 | - { |
|
309 | - if (isset($this->name) && |
|
310 | - isset($this->user_id) && |
|
311 | - isset($this->weight) && |
|
312 | - isset ($this->eval_max) && |
|
313 | - isset($this->visible) |
|
314 | - ) { |
|
315 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
316 | - |
|
317 | - $sql = 'INSERT INTO '.$tbl_grade_evaluations |
|
318 | - .' (name, user_id, weight, max, visible'; |
|
319 | - if (isset($this->description)) { |
|
320 | - $sql .= ',description'; |
|
321 | - } |
|
322 | - if (isset($this->course_code)) { |
|
323 | - $sql .= ', course_code'; |
|
324 | - } |
|
325 | - if (isset($this->category)) { |
|
326 | - $sql .= ', category_id'; |
|
327 | - } |
|
328 | - $sql .= ', created_at'; |
|
329 | - $sql .= ',type'; |
|
330 | - $sql .= ") VALUES ('".Database::escape_string($this->get_name())."'" |
|
331 | - .','.intval($this->get_user_id()) |
|
332 | - .','.floatval($this->get_weight()) |
|
333 | - .','.intval($this->get_max()) |
|
334 | - .','.intval($this->is_visible()); |
|
335 | - if (isset($this->description)) { |
|
336 | - $sql .= ",'".Database::escape_string($this->get_description())."'"; |
|
337 | - } |
|
338 | - if (isset($this->course_code)) { |
|
339 | - $sql .= ",'".Database::escape_string($this->get_course_code())."'"; |
|
340 | - } |
|
341 | - if (isset($this->category)) { |
|
342 | - $sql .= ','.intval($this->get_category_id()); |
|
343 | - } |
|
344 | - if (empty($this->type)) { |
|
345 | - $this->type = 'evaluation'; |
|
346 | - } |
|
347 | - $sql .= ", '".api_get_utc_datetime()."'"; |
|
348 | - $sql .= ',\''.Database::escape_string($this->type).'\''; |
|
349 | - $sql .= ")"; |
|
350 | - |
|
351 | - Database::query($sql); |
|
352 | - $this->set_id(Database::insert_id()); |
|
353 | - } else { |
|
354 | - die('Error in Evaluation add: required field empty'); |
|
355 | - } |
|
356 | - } |
|
357 | - |
|
358 | - /** |
|
359 | - * @param int $idevaluation |
|
360 | - */ |
|
361 | - public function add_evaluation_log($idevaluation) |
|
362 | - { |
|
363 | - if (!empty($idevaluation)) { |
|
364 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
365 | - $tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG); |
|
366 | - $eval = new Evaluation(); |
|
367 | - $dateobject = $eval->load($idevaluation,null,null,null,null); |
|
368 | - $arreval = get_object_vars($dateobject[0]); |
|
369 | - if (!empty($arreval['id'])) { |
|
370 | - $sql = 'SELECT weight from '.$tbl_grade_evaluations.' |
|
308 | + { |
|
309 | + if (isset($this->name) && |
|
310 | + isset($this->user_id) && |
|
311 | + isset($this->weight) && |
|
312 | + isset ($this->eval_max) && |
|
313 | + isset($this->visible) |
|
314 | + ) { |
|
315 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
316 | + |
|
317 | + $sql = 'INSERT INTO '.$tbl_grade_evaluations |
|
318 | + .' (name, user_id, weight, max, visible'; |
|
319 | + if (isset($this->description)) { |
|
320 | + $sql .= ',description'; |
|
321 | + } |
|
322 | + if (isset($this->course_code)) { |
|
323 | + $sql .= ', course_code'; |
|
324 | + } |
|
325 | + if (isset($this->category)) { |
|
326 | + $sql .= ', category_id'; |
|
327 | + } |
|
328 | + $sql .= ', created_at'; |
|
329 | + $sql .= ',type'; |
|
330 | + $sql .= ") VALUES ('".Database::escape_string($this->get_name())."'" |
|
331 | + .','.intval($this->get_user_id()) |
|
332 | + .','.floatval($this->get_weight()) |
|
333 | + .','.intval($this->get_max()) |
|
334 | + .','.intval($this->is_visible()); |
|
335 | + if (isset($this->description)) { |
|
336 | + $sql .= ",'".Database::escape_string($this->get_description())."'"; |
|
337 | + } |
|
338 | + if (isset($this->course_code)) { |
|
339 | + $sql .= ",'".Database::escape_string($this->get_course_code())."'"; |
|
340 | + } |
|
341 | + if (isset($this->category)) { |
|
342 | + $sql .= ','.intval($this->get_category_id()); |
|
343 | + } |
|
344 | + if (empty($this->type)) { |
|
345 | + $this->type = 'evaluation'; |
|
346 | + } |
|
347 | + $sql .= ", '".api_get_utc_datetime()."'"; |
|
348 | + $sql .= ',\''.Database::escape_string($this->type).'\''; |
|
349 | + $sql .= ")"; |
|
350 | + |
|
351 | + Database::query($sql); |
|
352 | + $this->set_id(Database::insert_id()); |
|
353 | + } else { |
|
354 | + die('Error in Evaluation add: required field empty'); |
|
355 | + } |
|
356 | + } |
|
357 | + |
|
358 | + /** |
|
359 | + * @param int $idevaluation |
|
360 | + */ |
|
361 | + public function add_evaluation_log($idevaluation) |
|
362 | + { |
|
363 | + if (!empty($idevaluation)) { |
|
364 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
365 | + $tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG); |
|
366 | + $eval = new Evaluation(); |
|
367 | + $dateobject = $eval->load($idevaluation,null,null,null,null); |
|
368 | + $arreval = get_object_vars($dateobject[0]); |
|
369 | + if (!empty($arreval['id'])) { |
|
370 | + $sql = 'SELECT weight from '.$tbl_grade_evaluations.' |
|
371 | 371 | WHERE id='.$arreval['id']; |
372 | 372 | $rs = Database::query($sql); |
373 | 373 | $row_old_weight = Database::fetch_array($rs, 'ASSOC'); |
@@ -383,426 +383,426 @@ discard block |
||
383 | 383 | 'user_id_log' => api_get_user_id() |
384 | 384 | ]; |
385 | 385 | Database::insert($tbl_grade_linkeval_log, $params); |
386 | - } |
|
387 | - } |
|
388 | - } |
|
389 | - |
|
390 | - /** |
|
391 | - * Update the properties of this evaluation in the database |
|
392 | - */ |
|
393 | - public function save() |
|
394 | - { |
|
395 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
396 | - $sql = 'UPDATE '.$tbl_grade_evaluations |
|
397 | - ." SET name = '".Database::escape_string($this->get_name())."'" |
|
398 | - .', description = '; |
|
399 | - if (isset($this->description)) { |
|
400 | - $sql .= "'".Database::escape_string($this->get_description())."'"; |
|
401 | - }else { |
|
402 | - $sql .= 'null'; |
|
403 | - } |
|
404 | - $sql .= ', user_id = '.intval($this->get_user_id()) |
|
405 | - .', course_code = '; |
|
406 | - if (isset($this->course_code)) { |
|
407 | - $sql .= "'".Database::escape_string($this->get_course_code())."'"; |
|
408 | - } else { |
|
409 | - $sql .= 'null'; |
|
410 | - } |
|
411 | - $sql .= ', category_id = '; |
|
412 | - if (isset($this->category)) { |
|
413 | - $sql .= intval($this->get_category_id()); |
|
414 | - } else { |
|
415 | - $sql .= 'null'; |
|
416 | - } |
|
417 | - $sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" ' |
|
418 | - .', max = '.intval($this->get_max()) |
|
419 | - .', visible = '.intval($this->is_visible()) |
|
420 | - .' WHERE id = '.intval($this->id); |
|
421 | - //recorded history |
|
422 | - |
|
423 | - $eval_log = new Evaluation(); |
|
424 | - $eval_log->add_evaluation_log($this->id); |
|
425 | - Database::query($sql); |
|
426 | - } |
|
427 | - |
|
428 | - /** |
|
429 | - * Delete this evaluation from the database |
|
430 | - */ |
|
431 | - public function delete() |
|
432 | - { |
|
433 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
434 | - $sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id); |
|
435 | - Database::query($sql); |
|
436 | - } |
|
437 | - |
|
438 | - /** |
|
439 | - * Check if an evaluation name (with the same parent category) already exists |
|
440 | - * @param $name name to check (if not given, the name property of this object will be checked) |
|
441 | - * @param $parent parent category |
|
442 | - */ |
|
443 | - public function does_name_exist($name, $parent) |
|
444 | - { |
|
445 | - if (!isset ($name)) { |
|
446 | - $name = $this->name; |
|
447 | - $parent = $this->category; |
|
448 | - } |
|
449 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
450 | - $sql = 'SELECT count(id) AS number' |
|
451 | - .' FROM '.$tbl_grade_evaluations |
|
452 | - ." WHERE name = '".Database::escape_string($name)."'"; |
|
453 | - |
|
454 | - if (api_is_allowed_to_edit()) { |
|
455 | - $parent = Category::load($parent); |
|
456 | - $code = $parent[0]->get_course_code(); |
|
457 | - $courseInfo = api_get_course_info($code); |
|
458 | - $courseId = $courseInfo['real_id']; |
|
459 | - |
|
460 | - if (isset($code) && $code != '0') { |
|
461 | - $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); |
|
462 | - $sql .= ' AND user_id IN ( |
|
386 | + } |
|
387 | + } |
|
388 | + } |
|
389 | + |
|
390 | + /** |
|
391 | + * Update the properties of this evaluation in the database |
|
392 | + */ |
|
393 | + public function save() |
|
394 | + { |
|
395 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
396 | + $sql = 'UPDATE '.$tbl_grade_evaluations |
|
397 | + ." SET name = '".Database::escape_string($this->get_name())."'" |
|
398 | + .', description = '; |
|
399 | + if (isset($this->description)) { |
|
400 | + $sql .= "'".Database::escape_string($this->get_description())."'"; |
|
401 | + }else { |
|
402 | + $sql .= 'null'; |
|
403 | + } |
|
404 | + $sql .= ', user_id = '.intval($this->get_user_id()) |
|
405 | + .', course_code = '; |
|
406 | + if (isset($this->course_code)) { |
|
407 | + $sql .= "'".Database::escape_string($this->get_course_code())."'"; |
|
408 | + } else { |
|
409 | + $sql .= 'null'; |
|
410 | + } |
|
411 | + $sql .= ', category_id = '; |
|
412 | + if (isset($this->category)) { |
|
413 | + $sql .= intval($this->get_category_id()); |
|
414 | + } else { |
|
415 | + $sql .= 'null'; |
|
416 | + } |
|
417 | + $sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" ' |
|
418 | + .', max = '.intval($this->get_max()) |
|
419 | + .', visible = '.intval($this->is_visible()) |
|
420 | + .' WHERE id = '.intval($this->id); |
|
421 | + //recorded history |
|
422 | + |
|
423 | + $eval_log = new Evaluation(); |
|
424 | + $eval_log->add_evaluation_log($this->id); |
|
425 | + Database::query($sql); |
|
426 | + } |
|
427 | + |
|
428 | + /** |
|
429 | + * Delete this evaluation from the database |
|
430 | + */ |
|
431 | + public function delete() |
|
432 | + { |
|
433 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
434 | + $sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id); |
|
435 | + Database::query($sql); |
|
436 | + } |
|
437 | + |
|
438 | + /** |
|
439 | + * Check if an evaluation name (with the same parent category) already exists |
|
440 | + * @param $name name to check (if not given, the name property of this object will be checked) |
|
441 | + * @param $parent parent category |
|
442 | + */ |
|
443 | + public function does_name_exist($name, $parent) |
|
444 | + { |
|
445 | + if (!isset ($name)) { |
|
446 | + $name = $this->name; |
|
447 | + $parent = $this->category; |
|
448 | + } |
|
449 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
450 | + $sql = 'SELECT count(id) AS number' |
|
451 | + .' FROM '.$tbl_grade_evaluations |
|
452 | + ." WHERE name = '".Database::escape_string($name)."'"; |
|
453 | + |
|
454 | + if (api_is_allowed_to_edit()) { |
|
455 | + $parent = Category::load($parent); |
|
456 | + $code = $parent[0]->get_course_code(); |
|
457 | + $courseInfo = api_get_course_info($code); |
|
458 | + $courseId = $courseInfo['real_id']; |
|
459 | + |
|
460 | + if (isset($code) && $code != '0') { |
|
461 | + $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); |
|
462 | + $sql .= ' AND user_id IN ( |
|
463 | 463 | SELECT user_id FROM '.$main_course_user_table.' |
464 | 464 | WHERE |
465 | 465 | c_id = '.$courseId.' AND |
466 | 466 | status = '.COURSEMANAGER.' |
467 | 467 | )'; |
468 | - } else { |
|
469 | - $sql .= ' AND user_id = '.api_get_user_id(); |
|
470 | - } |
|
471 | - |
|
472 | - }else { |
|
473 | - $sql .= ' AND user_id = '.api_get_user_id(); |
|
474 | - } |
|
475 | - |
|
476 | - if (!isset ($parent)) { |
|
477 | - $sql.= ' AND category_id is null'; |
|
478 | - } else { |
|
479 | - $sql.= ' AND category_id = '.intval($parent); |
|
480 | - } |
|
481 | - $result = Database::query($sql); |
|
482 | - $number=Database::fetch_row($result); |
|
483 | - |
|
484 | - return $number[0] != 0; |
|
485 | - } |
|
486 | - |
|
487 | - /** |
|
488 | - * Are there any results for this evaluation yet ? |
|
489 | - * The 'max' property should not be changed then. |
|
490 | - */ |
|
491 | - public function has_results() |
|
492 | - { |
|
493 | - $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
494 | - $sql = 'SELECT count(id) AS number |
|
468 | + } else { |
|
469 | + $sql .= ' AND user_id = '.api_get_user_id(); |
|
470 | + } |
|
471 | + |
|
472 | + }else { |
|
473 | + $sql .= ' AND user_id = '.api_get_user_id(); |
|
474 | + } |
|
475 | + |
|
476 | + if (!isset ($parent)) { |
|
477 | + $sql.= ' AND category_id is null'; |
|
478 | + } else { |
|
479 | + $sql.= ' AND category_id = '.intval($parent); |
|
480 | + } |
|
481 | + $result = Database::query($sql); |
|
482 | + $number=Database::fetch_row($result); |
|
483 | + |
|
484 | + return $number[0] != 0; |
|
485 | + } |
|
486 | + |
|
487 | + /** |
|
488 | + * Are there any results for this evaluation yet ? |
|
489 | + * The 'max' property should not be changed then. |
|
490 | + */ |
|
491 | + public function has_results() |
|
492 | + { |
|
493 | + $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
494 | + $sql = 'SELECT count(id) AS number |
|
495 | 495 | FROM '.$tbl_grade_results.' |
496 | 496 | WHERE evaluation_id = '.intval($this->id); |
497 | - $result = Database::query($sql); |
|
498 | - $number=Database::fetch_row($result); |
|
499 | - |
|
500 | - return ($number[0] != 0); |
|
501 | - } |
|
502 | - |
|
503 | - /** |
|
504 | - * Delete all results for this evaluation |
|
505 | - */ |
|
506 | - public function delete_results() |
|
507 | - { |
|
508 | - $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
509 | - $sql = 'DELETE FROM '.$tbl_grade_results.' |
|
497 | + $result = Database::query($sql); |
|
498 | + $number=Database::fetch_row($result); |
|
499 | + |
|
500 | + return ($number[0] != 0); |
|
501 | + } |
|
502 | + |
|
503 | + /** |
|
504 | + * Delete all results for this evaluation |
|
505 | + */ |
|
506 | + public function delete_results() |
|
507 | + { |
|
508 | + $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
509 | + $sql = 'DELETE FROM '.$tbl_grade_results.' |
|
510 | 510 | WHERE evaluation_id = '.intval($this->id); |
511 | - Database::query($sql); |
|
512 | - } |
|
513 | - |
|
514 | - /** |
|
515 | - * Delete this evaluation and all underlying results. |
|
516 | - */ |
|
517 | - public function delete_with_results() |
|
518 | - { |
|
519 | - $this->delete_results(); |
|
520 | - $this->delete(); |
|
521 | - } |
|
522 | - |
|
523 | - /** |
|
524 | - * Check if the given score is possible for this evaluation |
|
525 | - */ |
|
526 | - public function is_valid_score($score) |
|
527 | - { |
|
528 | - return is_numeric($score) && $score >= 0 && $score <= $this->eval_max; |
|
529 | - } |
|
530 | - |
|
531 | - /** |
|
532 | - * Calculate the score of this evaluation |
|
533 | - * @param int $stud_id (default: all students who have results for this eval - then the average is returned) |
|
534 | - * @param string $type (best, average, ranking) |
|
535 | - * @return array (score, max) if student is given |
|
536 | - * array (sum of scores, number of scores) otherwise |
|
537 | - * or null if no scores available |
|
538 | - */ |
|
539 | - public function calc_score($stud_id = null, $type = null) |
|
540 | - { |
|
511 | + Database::query($sql); |
|
512 | + } |
|
513 | + |
|
514 | + /** |
|
515 | + * Delete this evaluation and all underlying results. |
|
516 | + */ |
|
517 | + public function delete_with_results() |
|
518 | + { |
|
519 | + $this->delete_results(); |
|
520 | + $this->delete(); |
|
521 | + } |
|
522 | + |
|
523 | + /** |
|
524 | + * Check if the given score is possible for this evaluation |
|
525 | + */ |
|
526 | + public function is_valid_score($score) |
|
527 | + { |
|
528 | + return is_numeric($score) && $score >= 0 && $score <= $this->eval_max; |
|
529 | + } |
|
530 | + |
|
531 | + /** |
|
532 | + * Calculate the score of this evaluation |
|
533 | + * @param int $stud_id (default: all students who have results for this eval - then the average is returned) |
|
534 | + * @param string $type (best, average, ranking) |
|
535 | + * @return array (score, max) if student is given |
|
536 | + * array (sum of scores, number of scores) otherwise |
|
537 | + * or null if no scores available |
|
538 | + */ |
|
539 | + public function calc_score($stud_id = null, $type = null) |
|
540 | + { |
|
541 | 541 | $useSession = true; |
542 | - if (isset($stud_id) && empty($type)) { |
|
543 | - $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id; |
|
544 | - $data = Session::read('calc_score'); |
|
542 | + if (isset($stud_id) && empty($type)) { |
|
543 | + $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id; |
|
544 | + $data = Session::read('calc_score'); |
|
545 | 545 | $results = isset($data[$key]) ? $data[$key] : null; |
546 | 546 | |
547 | 547 | if ($useSession == false) { |
548 | 548 | $results = null; |
549 | 549 | } |
550 | - if (empty($results)) { |
|
551 | - $results = Result::load(null, $stud_id, $this->id); |
|
552 | - Session::write('calc_score', array($key => $results)); |
|
553 | - } |
|
554 | - |
|
555 | - $score = 0; |
|
556 | - /** @var Result $res */ |
|
557 | - foreach ($results as $res) { |
|
558 | - $score = $res->get_score(); |
|
559 | - } |
|
560 | - |
|
561 | - return array($score, $this->get_max()); |
|
562 | - } else { |
|
563 | - |
|
564 | - $count = 0; |
|
565 | - $sum = 0; |
|
566 | - $bestResult = 0; |
|
567 | - $weight = 0; |
|
568 | - $sumResult = 0; |
|
569 | - |
|
570 | - $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id; |
|
550 | + if (empty($results)) { |
|
551 | + $results = Result::load(null, $stud_id, $this->id); |
|
552 | + Session::write('calc_score', array($key => $results)); |
|
553 | + } |
|
554 | + |
|
555 | + $score = 0; |
|
556 | + /** @var Result $res */ |
|
557 | + foreach ($results as $res) { |
|
558 | + $score = $res->get_score(); |
|
559 | + } |
|
560 | + |
|
561 | + return array($score, $this->get_max()); |
|
562 | + } else { |
|
563 | + |
|
564 | + $count = 0; |
|
565 | + $sum = 0; |
|
566 | + $bestResult = 0; |
|
567 | + $weight = 0; |
|
568 | + $sumResult = 0; |
|
569 | + |
|
570 | + $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id; |
|
571 | 571 | $data = Session::read('calc_score'); |
572 | 572 | $allResults = isset($data[$key]) ? $data[$key] : null; |
573 | 573 | if ($useSession == false) { |
574 | 574 | $allResults = null; |
575 | 575 | } |
576 | - if (empty($allResults)) { |
|
577 | - $allResults = Result::load(null, null, $this->id); |
|
578 | - Session::write($key, $allResults); |
|
579 | - } |
|
580 | - |
|
581 | - $students = array(); |
|
582 | - /** @var Result $res */ |
|
583 | - foreach ($allResults as $res) { |
|
584 | - $score = $res->get_score(); |
|
585 | - if (!empty($score) || $score == '0') { |
|
586 | - $count++; |
|
587 | - $sum += $score / $this->get_max(); |
|
588 | - $sumResult += $score; |
|
589 | - if ($score > $bestResult) { |
|
590 | - $bestResult = $score; |
|
591 | - } |
|
592 | - $weight = $this->get_max(); |
|
593 | - } |
|
594 | - $students[$res->get_user_id()] = $score; |
|
595 | - } |
|
596 | - |
|
597 | - if (empty($count)) { |
|
598 | - return null; |
|
599 | - } |
|
600 | - |
|
601 | - switch ($type) { |
|
602 | - case 'best': |
|
603 | - return array($bestResult, $weight); |
|
604 | - break; |
|
605 | - case 'average': |
|
606 | - return array($sumResult/$count, $weight); |
|
607 | - break; |
|
608 | - case 'ranking': |
|
576 | + if (empty($allResults)) { |
|
577 | + $allResults = Result::load(null, null, $this->id); |
|
578 | + Session::write($key, $allResults); |
|
579 | + } |
|
580 | + |
|
581 | + $students = array(); |
|
582 | + /** @var Result $res */ |
|
583 | + foreach ($allResults as $res) { |
|
584 | + $score = $res->get_score(); |
|
585 | + if (!empty($score) || $score == '0') { |
|
586 | + $count++; |
|
587 | + $sum += $score / $this->get_max(); |
|
588 | + $sumResult += $score; |
|
589 | + if ($score > $bestResult) { |
|
590 | + $bestResult = $score; |
|
591 | + } |
|
592 | + $weight = $this->get_max(); |
|
593 | + } |
|
594 | + $students[$res->get_user_id()] = $score; |
|
595 | + } |
|
596 | + |
|
597 | + if (empty($count)) { |
|
598 | + return null; |
|
599 | + } |
|
600 | + |
|
601 | + switch ($type) { |
|
602 | + case 'best': |
|
603 | + return array($bestResult, $weight); |
|
604 | + break; |
|
605 | + case 'average': |
|
606 | + return array($sumResult/$count, $weight); |
|
607 | + break; |
|
608 | + case 'ranking': |
|
609 | 609 | $students = array(); |
610 | 610 | /** @var Result $res */ |
611 | 611 | foreach ($allResults as $res) { |
612 | 612 | $score = $res->get_score(); |
613 | 613 | $students[$res->get_user_id()] = $score; |
614 | 614 | } |
615 | - return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
616 | - break; |
|
617 | - default: |
|
618 | - return array($sum, $count); |
|
619 | - break; |
|
620 | - } |
|
621 | - } |
|
622 | - } |
|
623 | - |
|
624 | - /** |
|
625 | - * Generate an array of possible categories where this evaluation can be moved to. |
|
626 | - * Notice: its own parent will be included in the list: it's up to the frontend |
|
627 | - * to disable this element. |
|
628 | - * @return array 2-dimensional array - every element contains 3 subelements (id, name, level) |
|
629 | - */ |
|
630 | - public function get_target_categories() |
|
631 | - { |
|
632 | - // - course independent evaluation |
|
633 | - // -> movable to root or other course independent categories |
|
634 | - // - evaluation inside a course |
|
635 | - // -> movable to root, independent categories or categories inside the course |
|
636 | - $user = (api_is_platform_admin() ? null : api_get_user_id()); |
|
637 | - $targets = array(); |
|
638 | - $level = 0; |
|
639 | - |
|
640 | - $root = array(0, get_lang('RootCat'), $level); |
|
641 | - $targets[] = $root; |
|
642 | - |
|
643 | - if (isset($this->course_code) && !empty($this->course_code)) { |
|
644 | - $crscats = Category::load(null,null,$this->course_code,0); |
|
645 | - foreach ($crscats as $cat) { |
|
646 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
647 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
648 | - } |
|
649 | - } |
|
650 | - |
|
651 | - $indcats = Category::load(null,$user,0,0); |
|
652 | - foreach ($indcats as $cat) { |
|
653 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
654 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
655 | - } |
|
656 | - |
|
657 | - return $targets; |
|
658 | - } |
|
659 | - |
|
660 | - /** |
|
661 | - * Internal function used by get_target_categories() |
|
662 | - * @param integer $level |
|
663 | - */ |
|
664 | - private function add_target_subcategories($targets, $level, $catid) |
|
665 | - { |
|
666 | - $subcats = Category::load(null,null,null,$catid); |
|
667 | - foreach ($subcats as $cat) { |
|
668 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
669 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
670 | - } |
|
671 | - return $targets; |
|
672 | - } |
|
673 | - |
|
674 | - /** |
|
675 | - * Move this evaluation to the given category. |
|
676 | - * If this evaluation moves from inside a course to outside, |
|
677 | - * its course code is also changed. |
|
678 | - */ |
|
679 | - public function move_to_cat($cat) |
|
680 | - { |
|
681 | - $this->set_category_id($cat->get_id()); |
|
682 | - if ($this->get_course_code() != $cat->get_course_code()) { |
|
683 | - $this->set_course_code($cat->get_course_code()); |
|
684 | - } |
|
685 | - $this->save(); |
|
686 | - } |
|
687 | - |
|
688 | - /** |
|
689 | - * Retrieve evaluations where a student has results for |
|
690 | - * and return them as an array of Evaluation objects |
|
691 | - * @param int $cat_id parent category (use 'null' to retrieve them in all categories) |
|
692 | - * @param int $stud_id student id |
|
693 | - */ |
|
694 | - public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id) |
|
695 | - { |
|
696 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
697 | - $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
698 | - |
|
699 | - $sql = 'SELECT * FROM '.$tbl_grade_evaluations.' |
|
615 | + return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
616 | + break; |
|
617 | + default: |
|
618 | + return array($sum, $count); |
|
619 | + break; |
|
620 | + } |
|
621 | + } |
|
622 | + } |
|
623 | + |
|
624 | + /** |
|
625 | + * Generate an array of possible categories where this evaluation can be moved to. |
|
626 | + * Notice: its own parent will be included in the list: it's up to the frontend |
|
627 | + * to disable this element. |
|
628 | + * @return array 2-dimensional array - every element contains 3 subelements (id, name, level) |
|
629 | + */ |
|
630 | + public function get_target_categories() |
|
631 | + { |
|
632 | + // - course independent evaluation |
|
633 | + // -> movable to root or other course independent categories |
|
634 | + // - evaluation inside a course |
|
635 | + // -> movable to root, independent categories or categories inside the course |
|
636 | + $user = (api_is_platform_admin() ? null : api_get_user_id()); |
|
637 | + $targets = array(); |
|
638 | + $level = 0; |
|
639 | + |
|
640 | + $root = array(0, get_lang('RootCat'), $level); |
|
641 | + $targets[] = $root; |
|
642 | + |
|
643 | + if (isset($this->course_code) && !empty($this->course_code)) { |
|
644 | + $crscats = Category::load(null,null,$this->course_code,0); |
|
645 | + foreach ($crscats as $cat) { |
|
646 | + $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
647 | + $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
648 | + } |
|
649 | + } |
|
650 | + |
|
651 | + $indcats = Category::load(null,$user,0,0); |
|
652 | + foreach ($indcats as $cat) { |
|
653 | + $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
654 | + $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
655 | + } |
|
656 | + |
|
657 | + return $targets; |
|
658 | + } |
|
659 | + |
|
660 | + /** |
|
661 | + * Internal function used by get_target_categories() |
|
662 | + * @param integer $level |
|
663 | + */ |
|
664 | + private function add_target_subcategories($targets, $level, $catid) |
|
665 | + { |
|
666 | + $subcats = Category::load(null,null,null,$catid); |
|
667 | + foreach ($subcats as $cat) { |
|
668 | + $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
669 | + $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
670 | + } |
|
671 | + return $targets; |
|
672 | + } |
|
673 | + |
|
674 | + /** |
|
675 | + * Move this evaluation to the given category. |
|
676 | + * If this evaluation moves from inside a course to outside, |
|
677 | + * its course code is also changed. |
|
678 | + */ |
|
679 | + public function move_to_cat($cat) |
|
680 | + { |
|
681 | + $this->set_category_id($cat->get_id()); |
|
682 | + if ($this->get_course_code() != $cat->get_course_code()) { |
|
683 | + $this->set_course_code($cat->get_course_code()); |
|
684 | + } |
|
685 | + $this->save(); |
|
686 | + } |
|
687 | + |
|
688 | + /** |
|
689 | + * Retrieve evaluations where a student has results for |
|
690 | + * and return them as an array of Evaluation objects |
|
691 | + * @param int $cat_id parent category (use 'null' to retrieve them in all categories) |
|
692 | + * @param int $stud_id student id |
|
693 | + */ |
|
694 | + public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id) |
|
695 | + { |
|
696 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
697 | + $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
698 | + |
|
699 | + $sql = 'SELECT * FROM '.$tbl_grade_evaluations.' |
|
700 | 700 | WHERE id IN ( |
701 | 701 | SELECT evaluation_id FROM '.$tbl_grade_results.' |
702 | 702 | WHERE user_id = '.intval($stud_id).' AND score IS NOT NULL |
703 | 703 | )'; |
704 | - if (!api_is_allowed_to_edit()) { |
|
705 | - $sql .= ' AND visible = 1'; |
|
706 | - } |
|
707 | - if (isset($cat_id)) { |
|
708 | - $sql .= ' AND category_id = '.intval($cat_id); |
|
709 | - } else { |
|
710 | - $sql .= ' AND category_id >= 0'; |
|
711 | - } |
|
712 | - |
|
713 | - $result = Database::query($sql); |
|
714 | - $alleval = Evaluation::create_evaluation_objects_from_sql_result($result); |
|
715 | - |
|
716 | - return $alleval; |
|
717 | - } |
|
718 | - |
|
719 | - /** |
|
720 | - * Get a list of students that do not have a result record for this evaluation |
|
721 | - */ |
|
722 | - public function get_not_subscribed_students($first_letter_user = '') |
|
723 | - { |
|
724 | - $tbl_user = Database :: get_main_table(TABLE_MAIN_USER); |
|
725 | - $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
726 | - |
|
727 | - $sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user |
|
728 | - ." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'" |
|
729 | - .' AND status = '.STUDENT |
|
730 | - .' AND user_id NOT IN' |
|
731 | - .' (SELECT user_id FROM '.$tbl_grade_results |
|
732 | - .' WHERE evaluation_id = '.intval($this->id) |
|
733 | - .' )' |
|
734 | - .' ORDER BY lastname'; |
|
735 | - |
|
736 | - $result = Database::query($sql); |
|
737 | - $users = Database::store_result($result); |
|
738 | - |
|
739 | - return $users; |
|
740 | - } |
|
741 | - |
|
742 | - /** |
|
743 | - * Find evaluations by name |
|
744 | - * @param string $name_mask search string |
|
745 | - * @return array evaluation objects matching the search criterium |
|
746 | - * @todo can be written more efficiently using a new (but very complex) sql query |
|
747 | - */ |
|
748 | - public function find_evaluations($name_mask,$selectcat) |
|
749 | - { |
|
750 | - $rootcat = Category::load($selectcat); |
|
751 | - $evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true); |
|
752 | - $foundevals = array(); |
|
753 | - foreach ($evals as $eval) { |
|
754 | - if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) { |
|
755 | - $foundevals[] = $eval; |
|
756 | - } |
|
757 | - } |
|
758 | - return $foundevals; |
|
759 | - } |
|
760 | - |
|
761 | - public function get_item_type() |
|
762 | - { |
|
763 | - return 'E'; |
|
764 | - } |
|
765 | - |
|
766 | - public function get_icon_name() |
|
767 | - { |
|
768 | - return $this->has_results() ? 'evalnotempty' : 'evalempty'; |
|
769 | - } |
|
770 | - |
|
771 | - /** |
|
772 | - * Locks an evaluation, only one who can unlock it is the platform administrator. |
|
773 | - * @param int locked 1 or unlocked 0 |
|
774 | - * |
|
775 | - **/ |
|
776 | - function lock($locked) |
|
777 | - { |
|
778 | - $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
779 | - $sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'"; |
|
780 | - Database::query($sql); |
|
781 | - } |
|
782 | - |
|
783 | - function check_lock_permissions() |
|
784 | - { |
|
785 | - if (api_is_platform_admin()) { |
|
786 | - return true; |
|
787 | - } else { |
|
788 | - if ($this->is_locked()) { |
|
789 | - api_not_allowed(); |
|
790 | - } |
|
791 | - } |
|
792 | - } |
|
793 | - |
|
794 | - function delete_linked_data() |
|
795 | - { |
|
796 | - |
|
797 | - } |
|
704 | + if (!api_is_allowed_to_edit()) { |
|
705 | + $sql .= ' AND visible = 1'; |
|
706 | + } |
|
707 | + if (isset($cat_id)) { |
|
708 | + $sql .= ' AND category_id = '.intval($cat_id); |
|
709 | + } else { |
|
710 | + $sql .= ' AND category_id >= 0'; |
|
711 | + } |
|
712 | + |
|
713 | + $result = Database::query($sql); |
|
714 | + $alleval = Evaluation::create_evaluation_objects_from_sql_result($result); |
|
715 | + |
|
716 | + return $alleval; |
|
717 | + } |
|
718 | + |
|
719 | + /** |
|
720 | + * Get a list of students that do not have a result record for this evaluation |
|
721 | + */ |
|
722 | + public function get_not_subscribed_students($first_letter_user = '') |
|
723 | + { |
|
724 | + $tbl_user = Database :: get_main_table(TABLE_MAIN_USER); |
|
725 | + $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
726 | + |
|
727 | + $sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user |
|
728 | + ." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'" |
|
729 | + .' AND status = '.STUDENT |
|
730 | + .' AND user_id NOT IN' |
|
731 | + .' (SELECT user_id FROM '.$tbl_grade_results |
|
732 | + .' WHERE evaluation_id = '.intval($this->id) |
|
733 | + .' )' |
|
734 | + .' ORDER BY lastname'; |
|
735 | + |
|
736 | + $result = Database::query($sql); |
|
737 | + $users = Database::store_result($result); |
|
738 | + |
|
739 | + return $users; |
|
740 | + } |
|
741 | + |
|
742 | + /** |
|
743 | + * Find evaluations by name |
|
744 | + * @param string $name_mask search string |
|
745 | + * @return array evaluation objects matching the search criterium |
|
746 | + * @todo can be written more efficiently using a new (but very complex) sql query |
|
747 | + */ |
|
748 | + public function find_evaluations($name_mask,$selectcat) |
|
749 | + { |
|
750 | + $rootcat = Category::load($selectcat); |
|
751 | + $evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true); |
|
752 | + $foundevals = array(); |
|
753 | + foreach ($evals as $eval) { |
|
754 | + if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) { |
|
755 | + $foundevals[] = $eval; |
|
756 | + } |
|
757 | + } |
|
758 | + return $foundevals; |
|
759 | + } |
|
760 | + |
|
761 | + public function get_item_type() |
|
762 | + { |
|
763 | + return 'E'; |
|
764 | + } |
|
765 | + |
|
766 | + public function get_icon_name() |
|
767 | + { |
|
768 | + return $this->has_results() ? 'evalnotempty' : 'evalempty'; |
|
769 | + } |
|
770 | + |
|
771 | + /** |
|
772 | + * Locks an evaluation, only one who can unlock it is the platform administrator. |
|
773 | + * @param int locked 1 or unlocked 0 |
|
774 | + * |
|
775 | + **/ |
|
776 | + function lock($locked) |
|
777 | + { |
|
778 | + $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
779 | + $sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'"; |
|
780 | + Database::query($sql); |
|
781 | + } |
|
782 | + |
|
783 | + function check_lock_permissions() |
|
784 | + { |
|
785 | + if (api_is_platform_admin()) { |
|
786 | + return true; |
|
787 | + } else { |
|
788 | + if ($this->is_locked()) { |
|
789 | + api_not_allowed(); |
|
790 | + } |
|
791 | + } |
|
792 | + } |
|
793 | + |
|
794 | + function delete_linked_data() |
|
795 | + { |
|
796 | + |
|
797 | + } |
|
798 | 798 | |
799 | 799 | public function getStudentList() |
800 | 800 | { |
801 | 801 | return $this->studentList; |
802 | 802 | } |
803 | 803 | |
804 | - public function setStudentList($list) |
|
805 | - { |
|
806 | - $this->studentList = $list; |
|
807 | - } |
|
804 | + public function setStudentList($list) |
|
805 | + { |
|
806 | + $this->studentList = $list; |
|
807 | + } |
|
808 | 808 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | /** |
39 | 39 | * Get total number of results (rows) |
40 | 40 | */ |
41 | - public function get_total_results_count () |
|
41 | + public function get_total_results_count() |
|
42 | 42 | { |
43 | 43 | return count($this->results); |
44 | 44 | } |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | * 4 ['score'] : student's score |
54 | 54 | * 5 ['display'] : custom score display (only if custom scoring enabled) |
55 | 55 | */ |
56 | - public function get_data ($sorting = 0, $start = 0, $count = null, $ignore_score_color = false, $pdf=false) |
|
56 | + public function get_data($sorting = 0, $start = 0, $count = null, $ignore_score_color = false, $pdf = false) |
|
57 | 57 | { |
58 | 58 | // do some checks on count, redefine if invalid value |
59 | 59 | $number_decimals = api_get_setting('gradebook_number_decimals'); |
60 | 60 | if (!isset($count)) { |
61 | - $count = count ($this->results) - $start; |
|
61 | + $count = count($this->results) - $start; |
|
62 | 62 | } |
63 | 63 | if ($count < 0) { |
64 | 64 | $count = 0; |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | $scoredisplay = ScoreDisplay :: instance(); |
67 | 67 | // generate actual data array |
68 | 68 | $table = array(); |
69 | - foreach($this->results as $result) { |
|
69 | + foreach ($this->results as $result) { |
|
70 | 70 | $user = array(); |
71 | 71 | $info = api_get_user_info($result->get_user_id()); |
72 | 72 | $user['id'] = $result->get_user_id(); |
73 | - if ($pdf){ |
|
73 | + if ($pdf) { |
|
74 | 74 | $user['username'] = $info['username']; |
75 | 75 | } |
76 | 76 | $user['result_id'] = $result->get_id(); |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | true |
93 | 93 | ) |
94 | 94 | ); |
95 | - if ($pdf && $number_decimals == null){ |
|
95 | + if ($pdf && $number_decimals == null) { |
|
96 | 96 | $user['scoreletter'] = $result->get_score(); |
97 | 97 | } |
98 | 98 | if ($scoredisplay->is_custom()) { |
@@ -132,13 +132,13 @@ discard block |
||
132 | 132 | * @param bool Whether we want to ignore the score color |
133 | 133 | * @result string The score as we want to show it |
134 | 134 | */ |
135 | - private function get_score_display ($score, $realscore, $ignore_score_color = false) |
|
135 | + private function get_score_display($score, $realscore, $ignore_score_color = false) |
|
136 | 136 | { |
137 | 137 | if ($score != null) { |
138 | 138 | $scoredisplay = ScoreDisplay :: instance(); |
139 | 139 | $type = SCORE_CUSTOM; |
140 | 140 | if ($realscore === true) { |
141 | - $type = SCORE_DIV_PERCENT ; |
|
141 | + $type = SCORE_DIV_PERCENT; |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | return $scoredisplay->display_score( |
@@ -172,10 +172,10 @@ discard block |
||
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
175 | - function sort_by_mask ($item1, $item2) |
|
175 | + function sort_by_mask($item1, $item2) |
|
176 | 176 | { |
177 | - $score1 = (isset($item1['score']) ? array($item1['score'],$this->evaluation->get_max()) : null); |
|
178 | - $score2 = (isset($item2['score']) ? array($item2['score'],$this->evaluation->get_max()) : null); |
|
177 | + $score1 = (isset($item1['score']) ? array($item1['score'], $this->evaluation->get_max()) : null); |
|
178 | + $score2 = (isset($item2['score']) ? array($item2['score'], $this->evaluation->get_max()) : null); |
|
179 | 179 | return ScoreDisplay :: compare_scores_by_custom_display($score1, $score2); |
180 | 180 | } |
181 | 181 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | * Code |
10 | 10 | */ |
11 | 11 | // resetting the course id |
12 | -$cidReset=true; |
|
12 | +$cidReset = true; |
|
13 | 13 | require_once('../inc/global.inc.php'); |
14 | 14 | // setting the section (for the tabs) |
15 | 15 | $this_section = SECTION_PLATFORM_ADMIN; |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | api_protect_admin_script(); |
19 | 19 | require('../auth/ldap/authldap.php'); |
20 | 20 | |
21 | -$annee_base=date('Y'); |
|
21 | +$annee_base = date('Y'); |
|
22 | 22 | |
23 | 23 | $tool_name = get_lang('LDAPImport'); |
24 | 24 | // setting breadcrumbs |
25 | -$interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin')); |
|
25 | +$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); |
|
26 | 26 | |
27 | 27 | $htmlHeadXtra[] = '<script language="JavaScript" type="text/javascript"> |
28 | 28 | var buttoncheck = 1; |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | |
49 | 49 | $annee = $_GET['annee']; |
50 | 50 | $composante = $_GET['composante']; |
51 | -$etape = $_GET['etape']; |
|
51 | +$etape = $_GET['etape']; |
|
52 | 52 | $course = $_POST['course']; |
53 | 53 | |
54 | 54 | |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | echo '</div>'; |
199 | 199 | } |
200 | 200 | */ |
201 | -elseif(!empty($annee) && empty($course)) |
|
201 | +elseif (!empty($annee) && empty($course)) |
|
202 | 202 | { |
203 | 203 | Display::display_header($tool_name); |
204 | 204 | echo '<div style="align:center">'; |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | echo '<form method="post" action="'.api_get_self().'?annee='.Security::remove_XSS($annee).'"><br />'; |
207 | 207 | echo '<select name="course">'; |
208 | 208 | $courses = CourseManager::get_courses_list(); |
209 | - foreach($courses as $row) |
|
209 | + foreach ($courses as $row) |
|
210 | 210 | { |
211 | 211 | echo '<option value="'.$row['code'].'">'.api_htmlentities($row['title']).'</option>'; |
212 | 212 | } |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | |
240 | 240 | $info = ldap_get_entries($ds, $sr); |
241 | 241 | |
242 | - for ($key = 0; $key < $info["count"]; $key ++) { |
|
242 | + for ($key = 0; $key < $info["count"]; $key++) { |
|
243 | 243 | $nom_form[] = $info[$key]["sn"][0]; |
244 | 244 | $prenom_form[] = $info[$key]["givenname"][0]; |
245 | 245 | $email_form[] = $info[$key]["mail"][0]; |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | asort($nom_form); |
260 | 260 | reset($nom_form); |
261 | 261 | |
262 | - $statut=5; |
|
262 | + $statut = 5; |
|
263 | 263 | include ('ldap_form_add_users_group.php'); |
264 | 264 | } else { |
265 | 265 | echo '<h4>'.get_lang('UnableToConnectTo').' '.$host.'</h4>'; |
@@ -270,25 +270,25 @@ discard block |
||
270 | 270 | echo '</div>'; |
271 | 271 | |
272 | 272 | } |
273 | -elseif (!empty($annee) && !empty($course) && ($_POST['confirmed']=='yes')) |
|
273 | +elseif (!empty($annee) && !empty($course) && ($_POST['confirmed'] == 'yes')) |
|
274 | 274 | { |
275 | - $id=$_POST['username_form']; |
|
276 | - $UserList=array(); |
|
275 | + $id = $_POST['username_form']; |
|
276 | + $UserList = array(); |
|
277 | 277 | $userid_match_login = array(); |
278 | 278 | foreach ($id as $form_index=>$user_id) |
279 | 279 | { |
280 | - if(is_array($_POST['checkboxes']) && in_array($form_index,array_values($_POST['checkboxes']))) |
|
280 | + if (is_array($_POST['checkboxes']) && in_array($form_index, array_values($_POST['checkboxes']))) |
|
281 | 281 | { |
282 | 282 | $tmp = ldap_add_user($user_id); |
283 | - $UserList[]= $tmp; |
|
283 | + $UserList[] = $tmp; |
|
284 | 284 | $userid_match_login[$tmp] = $user_id; |
285 | 285 | } |
286 | 286 | } |
287 | 287 | if (!empty($_POST['course'])) |
288 | 288 | { |
289 | - foreach($UserList as $user_id) |
|
289 | + foreach ($UserList as $user_id) |
|
290 | 290 | { |
291 | - CourseManager::add_user_to_course($user_id,$_POST['course']); |
|
291 | + CourseManager::add_user_to_course($user_id, $_POST['course']); |
|
292 | 292 | } |
293 | 293 | header('Location: course_information.php?code='.Security::remove_XSS($_POST['course'])); |
294 | 294 | } |
@@ -314,8 +314,8 @@ discard block |
||
314 | 314 | else |
315 | 315 | { |
316 | 316 | Display::display_header($tool_name); |
317 | - $message=get_lang('NoUserAdded'); |
|
318 | - Display :: display_normal_message($message,false); |
|
317 | + $message = get_lang('NoUserAdded'); |
|
318 | + Display :: display_normal_message($message, false); |
|
319 | 319 | } |
320 | 320 | echo '<br /><br />'; |
321 | 321 | echo '<a href="ldap_import_students.php?annee=&composante=&etape=">'.get_lang('BackToNewSearch').'</a>'; |
@@ -269,8 +269,7 @@ |
||
269 | 269 | echo '<br /><br />'; |
270 | 270 | echo '</div>'; |
271 | 271 | |
272 | -} |
|
273 | -elseif (!empty($annee) && !empty($course) && ($_POST['confirmed']=='yes')) |
|
272 | +} elseif (!empty($annee) && !empty($course) && ($_POST['confirmed']=='yes')) |
|
274 | 273 | { |
275 | 274 | $id=$_POST['username_form']; |
276 | 275 | $UserList=array(); |
@@ -56,19 +56,19 @@ discard block |
||
56 | 56 | //if ($annee == "" && $composante == "" && $etape == "") { |
57 | 57 | if (empty($annee) && empty($course)) |
58 | 58 | { |
59 | - Display::display_header($tool_name); |
|
60 | - echo '<div style="align:center">'; |
|
61 | - Display::display_icon('group.gif', get_lang('LDAPSelectFilterOnUsersOU')); |
|
62 | - echo get_lang('LDAPSelectFilterOnUsersOU'); |
|
63 | - //echo '<em>'.get_lang('ToDoThisYouMustEnterYearComponentAndComponentStep').'</em><br />'; |
|
64 | - ///echo get_lang('FollowEachOfTheseStepsStepByStep').'<br />'; |
|
65 | - |
|
66 | - echo '<form method="get" action="'.api_get_self().'"><br />'; |
|
67 | - echo '<em>'.get_lang('LDAPOUAttributeFilter').' :</em> '; |
|
68 | - echo '<input type="text" name="annee" size="4" maxlength="30" value="'.$annee_base.'"><br />'; |
|
69 | - echo '<input type="submit" value="'.get_lang('Submit').'">'; |
|
70 | - echo '</form>'; |
|
71 | - echo '</div>'; |
|
59 | + Display::display_header($tool_name); |
|
60 | + echo '<div style="align:center">'; |
|
61 | + Display::display_icon('group.gif', get_lang('LDAPSelectFilterOnUsersOU')); |
|
62 | + echo get_lang('LDAPSelectFilterOnUsersOU'); |
|
63 | + //echo '<em>'.get_lang('ToDoThisYouMustEnterYearComponentAndComponentStep').'</em><br />'; |
|
64 | + ///echo get_lang('FollowEachOfTheseStepsStepByStep').'<br />'; |
|
65 | + |
|
66 | + echo '<form method="get" action="'.api_get_self().'"><br />'; |
|
67 | + echo '<em>'.get_lang('LDAPOUAttributeFilter').' :</em> '; |
|
68 | + echo '<input type="text" name="annee" size="4" maxlength="30" value="'.$annee_base.'"><br />'; |
|
69 | + echo '<input type="submit" value="'.get_lang('Submit').'">'; |
|
70 | + echo '</form>'; |
|
71 | + echo '</div>'; |
|
72 | 72 | |
73 | 73 | } |
74 | 74 | /* |
@@ -200,71 +200,71 @@ discard block |
||
200 | 200 | */ |
201 | 201 | elseif(!empty($annee) && empty($course)) |
202 | 202 | { |
203 | - Display::display_header($tool_name); |
|
204 | - echo '<div style="align:center">'; |
|
205 | - echo Display::return_icon('course.png', get_lang('SelectCourseToImportUsersTo')).' '.get_lang('SelectCourseToImportUsersTo').'<br />'; |
|
206 | - echo '<form method="post" action="'.api_get_self().'?annee='.Security::remove_XSS($annee).'"><br />'; |
|
207 | - echo '<select name="course">'; |
|
208 | - $courses = CourseManager::get_courses_list(); |
|
209 | - foreach($courses as $row) |
|
210 | - { |
|
211 | - echo '<option value="'.$row['code'].'">'.api_htmlentities($row['title']).'</option>'; |
|
212 | - } |
|
213 | - echo '</select>'; |
|
214 | - echo '<input type="submit" value="'.get_lang('Submit').'">'; |
|
215 | - echo '</form>'; |
|
216 | - echo '</div>'; |
|
203 | + Display::display_header($tool_name); |
|
204 | + echo '<div style="align:center">'; |
|
205 | + echo Display::return_icon('course.png', get_lang('SelectCourseToImportUsersTo')).' '.get_lang('SelectCourseToImportUsersTo').'<br />'; |
|
206 | + echo '<form method="post" action="'.api_get_self().'?annee='.Security::remove_XSS($annee).'"><br />'; |
|
207 | + echo '<select name="course">'; |
|
208 | + $courses = CourseManager::get_courses_list(); |
|
209 | + foreach($courses as $row) |
|
210 | + { |
|
211 | + echo '<option value="'.$row['code'].'">'.api_htmlentities($row['title']).'</option>'; |
|
212 | + } |
|
213 | + echo '</select>'; |
|
214 | + echo '<input type="submit" value="'.get_lang('Submit').'">'; |
|
215 | + echo '</form>'; |
|
216 | + echo '</div>'; |
|
217 | 217 | } |
218 | 218 | // form4 annee != 0; composante != 0 etape != 0 |
219 | 219 | //elseif ($annee <> "" && $composante <> "" && $etape <> "" && $listeok != 'yes') { |
220 | 220 | elseif (!empty($annee) && !empty($course) && empty($_POST['confirmed'])) |
221 | 221 | { |
222 | - Display::display_header($tool_name); |
|
223 | - echo '<div style="align: center;">'; |
|
224 | - echo '<br />'; |
|
225 | - echo '<br />'; |
|
226 | - echo '<h3>'.Display::return_icon('group.gif', get_lang('SelectStudents')).' '.get_lang('SelectStudents').'</h3>'; |
|
227 | - //echo "Connection ..."; |
|
228 | - $ds = ldap_connect($ldap_host, $ldap_port) or die(get_lang('LDAPConnectionError')); |
|
229 | - ldap_set_version($ds); |
|
230 | - |
|
231 | - if ($ds) { |
|
232 | - |
|
233 | - $r = false; |
|
234 | - $res = ldap_handle_bind($ds, $r); |
|
235 | - |
|
236 | - //$sr = @ ldap_search($ds, "ou=people,$LDAPbasedn", "(|(edupersonprimaryorgunitdn=ou=$etape,ou=$annee,ou=diploma,o=Paris1,$LDAPbasedn)(edupersonprimaryorgunitdn=ou=02PEL,ou=$annee,ou=diploma,o=Paris1,$LDAPbasedn))"); |
|
237 | - //echo "(ou=*$annee,ou=$composante)"; |
|
238 | - $sr = @ ldap_search($ds, $ldap_basedn, "(ou=*$annee)"); |
|
239 | - |
|
240 | - $info = ldap_get_entries($ds, $sr); |
|
241 | - |
|
242 | - for ($key = 0; $key < $info["count"]; $key ++) { |
|
243 | - $nom_form[] = $info[$key]["sn"][0]; |
|
244 | - $prenom_form[] = $info[$key]["givenname"][0]; |
|
245 | - $email_form[] = $info[$key]["mail"][0]; |
|
246 | - // Get uid from dn |
|
247 | - //$dn_array=ldap_explode_dn($info[$key]["dn"],1); |
|
248 | - //$username_form[] = $dn_array[0]; // uid is first key |
|
249 | - $username_form[] = $info[$key]['uid'][0]; |
|
250 | - $outab[] = $info[$key]["eduPersonPrimaryAffiliation"][0]; // Ici "student" |
|
251 | - //$val = ldap_get_values_len($ds, $entry, "userPassword"); |
|
252 | - //$password_form[] = $val[0]; |
|
253 | - $password_form[] = $info[$key]['userPassword'][0]; |
|
254 | - } |
|
255 | - ldap_unbind($ds); |
|
256 | - |
|
257 | - /*-----------------------------------------------*/ |
|
258 | - |
|
259 | - asort($nom_form); |
|
260 | - reset($nom_form); |
|
261 | - |
|
262 | - $statut=5; |
|
263 | - include ('ldap_form_add_users_group.php'); |
|
264 | - } else { |
|
265 | - echo '<h4>'.get_lang('UnableToConnectTo').' '.$host.'</h4>'; |
|
266 | - } |
|
267 | - echo '<br /><br />'; |
|
222 | + Display::display_header($tool_name); |
|
223 | + echo '<div style="align: center;">'; |
|
224 | + echo '<br />'; |
|
225 | + echo '<br />'; |
|
226 | + echo '<h3>'.Display::return_icon('group.gif', get_lang('SelectStudents')).' '.get_lang('SelectStudents').'</h3>'; |
|
227 | + //echo "Connection ..."; |
|
228 | + $ds = ldap_connect($ldap_host, $ldap_port) or die(get_lang('LDAPConnectionError')); |
|
229 | + ldap_set_version($ds); |
|
230 | + |
|
231 | + if ($ds) { |
|
232 | + |
|
233 | + $r = false; |
|
234 | + $res = ldap_handle_bind($ds, $r); |
|
235 | + |
|
236 | + //$sr = @ ldap_search($ds, "ou=people,$LDAPbasedn", "(|(edupersonprimaryorgunitdn=ou=$etape,ou=$annee,ou=diploma,o=Paris1,$LDAPbasedn)(edupersonprimaryorgunitdn=ou=02PEL,ou=$annee,ou=diploma,o=Paris1,$LDAPbasedn))"); |
|
237 | + //echo "(ou=*$annee,ou=$composante)"; |
|
238 | + $sr = @ ldap_search($ds, $ldap_basedn, "(ou=*$annee)"); |
|
239 | + |
|
240 | + $info = ldap_get_entries($ds, $sr); |
|
241 | + |
|
242 | + for ($key = 0; $key < $info["count"]; $key ++) { |
|
243 | + $nom_form[] = $info[$key]["sn"][0]; |
|
244 | + $prenom_form[] = $info[$key]["givenname"][0]; |
|
245 | + $email_form[] = $info[$key]["mail"][0]; |
|
246 | + // Get uid from dn |
|
247 | + //$dn_array=ldap_explode_dn($info[$key]["dn"],1); |
|
248 | + //$username_form[] = $dn_array[0]; // uid is first key |
|
249 | + $username_form[] = $info[$key]['uid'][0]; |
|
250 | + $outab[] = $info[$key]["eduPersonPrimaryAffiliation"][0]; // Ici "student" |
|
251 | + //$val = ldap_get_values_len($ds, $entry, "userPassword"); |
|
252 | + //$password_form[] = $val[0]; |
|
253 | + $password_form[] = $info[$key]['userPassword'][0]; |
|
254 | + } |
|
255 | + ldap_unbind($ds); |
|
256 | + |
|
257 | + /*-----------------------------------------------*/ |
|
258 | + |
|
259 | + asort($nom_form); |
|
260 | + reset($nom_form); |
|
261 | + |
|
262 | + $statut=5; |
|
263 | + include ('ldap_form_add_users_group.php'); |
|
264 | + } else { |
|
265 | + echo '<h4>'.get_lang('UnableToConnectTo').' '.$host.'</h4>'; |
|
266 | + } |
|
267 | + echo '<br /><br />'; |
|
268 | 268 | echo '<a href="ldap_import_students.php?annee=&composante=&etape=">'.get_lang('BackToNewSearch').'</a>'; |
269 | 269 | echo '<br /><br />'; |
270 | 270 | echo '</div>'; |
@@ -272,27 +272,27 @@ discard block |
||
272 | 272 | } |
273 | 273 | elseif (!empty($annee) && !empty($course) && ($_POST['confirmed']=='yes')) |
274 | 274 | { |
275 | - $id=$_POST['username_form']; |
|
276 | - $UserList=array(); |
|
277 | - $userid_match_login = array(); |
|
278 | - foreach ($id as $form_index=>$user_id) |
|
279 | - { |
|
280 | - if(is_array($_POST['checkboxes']) && in_array($form_index,array_values($_POST['checkboxes']))) |
|
281 | - { |
|
282 | - $tmp = ldap_add_user($user_id); |
|
283 | - $UserList[]= $tmp; |
|
284 | - $userid_match_login[$tmp] = $user_id; |
|
285 | - } |
|
286 | - } |
|
287 | - if (!empty($_POST['course'])) |
|
288 | - { |
|
289 | - foreach($UserList as $user_id) |
|
290 | - { |
|
291 | - CourseManager::add_user_to_course($user_id,$_POST['course']); |
|
292 | - } |
|
293 | - header('Location: course_information.php?code='.Security::remove_XSS($_POST['course'])); |
|
294 | - } |
|
295 | - /* |
|
275 | + $id=$_POST['username_form']; |
|
276 | + $UserList=array(); |
|
277 | + $userid_match_login = array(); |
|
278 | + foreach ($id as $form_index=>$user_id) |
|
279 | + { |
|
280 | + if(is_array($_POST['checkboxes']) && in_array($form_index,array_values($_POST['checkboxes']))) |
|
281 | + { |
|
282 | + $tmp = ldap_add_user($user_id); |
|
283 | + $UserList[]= $tmp; |
|
284 | + $userid_match_login[$tmp] = $user_id; |
|
285 | + } |
|
286 | + } |
|
287 | + if (!empty($_POST['course'])) |
|
288 | + { |
|
289 | + foreach($UserList as $user_id) |
|
290 | + { |
|
291 | + CourseManager::add_user_to_course($user_id,$_POST['course']); |
|
292 | + } |
|
293 | + header('Location: course_information.php?code='.Security::remove_XSS($_POST['course'])); |
|
294 | + } |
|
295 | + /* |
|
296 | 296 | else |
297 | 297 | { |
298 | 298 | Display :: display_header($tool_name); |
@@ -311,13 +311,13 @@ discard block |
||
311 | 311 | Display :: display_normal_message($message,false); |
312 | 312 | } |
313 | 313 | */ |
314 | - else |
|
315 | - { |
|
316 | - Display::display_header($tool_name); |
|
317 | - $message=get_lang('NoUserAdded'); |
|
318 | - Display :: display_normal_message($message,false); |
|
319 | - } |
|
320 | - echo '<br /><br />'; |
|
314 | + else |
|
315 | + { |
|
316 | + Display::display_header($tool_name); |
|
317 | + $message=get_lang('NoUserAdded'); |
|
318 | + Display :: display_normal_message($message,false); |
|
319 | + } |
|
320 | + echo '<br /><br />'; |
|
321 | 321 | echo '<a href="ldap_import_students.php?annee=&composante=&etape=">'.get_lang('BackToNewSearch').'</a>'; |
322 | 322 | echo '<br /><br />'; |
323 | 323 | } |
@@ -87,7 +87,7 @@ |
||
87 | 87 | <?php |
88 | 88 | echo Display::get_alphabet_options($firstLetterUserGroup); |
89 | 89 | echo Display::get_numeric_options(0, 9, $firstLetterUserGroup); |
90 | - ?> |
|
90 | + ?> |
|
91 | 91 | </select> |
92 | 92 | </td> |
93 | 93 | <td width="20%"> </td> |
@@ -30,8 +30,8 @@ discard block |
||
30 | 30 | $tbl_course = Database:: get_main_table(TABLE_MAIN_COURSE); |
31 | 31 | |
32 | 32 | $tool_name = get_lang('AddUserGroupToURL'); |
33 | -$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); |
|
34 | -$interbreadcrumb[] = array ('url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs')); |
|
33 | +$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); |
|
34 | +$interbreadcrumb[] = array('url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs')); |
|
35 | 35 | |
36 | 36 | Display::display_header($tool_name); |
37 | 37 | |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | |
47 | 47 | if (isset($_POST['form_sent']) && $_POST['form_sent']) { |
48 | 48 | $form_sent = $_POST['form_sent']; |
49 | - $userGroups = is_array($_POST['user_group_list']) ? $_POST['user_group_list'] : array() ; |
|
50 | - $urlList = is_array($_POST['url_list']) ? $_POST['url_list'] : array() ; |
|
49 | + $userGroups = is_array($_POST['user_group_list']) ? $_POST['user_group_list'] : array(); |
|
50 | + $urlList = is_array($_POST['url_list']) ? $_POST['url_list'] : array(); |
|
51 | 51 | $firstLetterUserGroup = $_POST['first_letter_user_group']; |
52 | 52 | |
53 | 53 | if ($form_sent == 1) { |
@@ -99,7 +99,10 @@ discard block |
||
99 | 99 | <td width="40%" align="center"> |
100 | 100 | <select name="user_group_list[]" multiple="multiple" size="20" style="width:400px;"> |
101 | 101 | <?php foreach ($dbUserGroups as $item) { ?> |
102 | - <option value="<?php echo $item['id']; ?>" <?php if (in_array($item['id'], $courses)) echo 'selected="selected"'; ?>><?php echo $item['name']; ?> |
|
102 | + <option value="<?php echo $item['id']; ?>" <?php if (in_array($item['id'], $courses)) { |
|
103 | + echo 'selected="selected"'; |
|
104 | +} |
|
105 | +?>><?php echo $item['name']; ?> |
|
103 | 106 | </option> |
104 | 107 | <?php } ?> |
105 | 108 | </select> |
@@ -110,7 +113,10 @@ discard block |
||
110 | 113 | <td width="40%" align="center"> |
111 | 114 | <select name="url_list[]" multiple="multiple" size="20" style="width:300px;"> |
112 | 115 | <?php foreach ($db_urls as $url_obj) { ?> |
113 | - <option value="<?php echo $url_obj['id']; ?>" <?php if (in_array($url_obj['id'], $url_list)) echo 'selected="selected"'; ?>><?php echo $url_obj['url']; ?> |
|
116 | + <option value="<?php echo $url_obj['id']; ?>" <?php if (in_array($url_obj['id'], $url_list)) { |
|
117 | + echo 'selected="selected"'; |
|
118 | +} |
|
119 | +?>><?php echo $url_obj['url']; ?> |
|
114 | 120 | </option> |
115 | 121 | <?php } ?> |
116 | 122 | </select> |
@@ -114,7 +114,7 @@ |
||
114 | 114 | $from = intval($from); |
115 | 115 | $number_of_items = intval($number_of_items); |
116 | 116 | $column = intval($column); |
117 | - $direction = !in_array(strtolower(trim($direction)), ['asc','desc']) ? 'asc' : $direction; |
|
117 | + $direction = !in_array(strtolower(trim($direction)), ['asc', 'desc']) ? 'asc' : $direction; |
|
118 | 118 | |
119 | 119 | $sql = "SELECT |
120 | 120 | id AS col0, |
@@ -90,26 +90,26 @@ |
||
90 | 90 | { |
91 | 91 | $baseDir = api_get_path(SYS_ARCHIVE_PATH); |
92 | 92 | $uploadPath = 'pdfimport/'; |
93 | - $errors = array (); |
|
93 | + $errors = array(); |
|
94 | 94 | if (!is_dir($baseDir.$uploadPath)) { |
95 | 95 | @mkdir($baseDir.$uploadPath); |
96 | 96 | } |
97 | - if (!unzip_uploaded_file($_FILES['import_file'], $uploadPath, $baseDir, 1024*1024*1024)) { |
|
97 | + if (!unzip_uploaded_file($_FILES['import_file'], $uploadPath, $baseDir, 1024 * 1024 * 1024)) { |
|
98 | 98 | error_log('Could not unzip uploaded file in '.__FILE__.', line '.__LINE__); |
99 | 99 | return $errors; |
100 | 100 | } |
101 | 101 | $list = scandir($baseDir.$uploadPath); |
102 | 102 | $i = 0; |
103 | 103 | foreach ($list as $file) { |
104 | - if (substr($file,0,1) == '.' or !is_file($baseDir.$uploadPath.$file)) { |
|
104 | + if (substr($file, 0, 1) == '.' or !is_file($baseDir.$uploadPath.$file)) { |
|
105 | 105 | continue; |
106 | 106 | } |
107 | - $parts = preg_split('/_/',$file); |
|
107 | + $parts = preg_split('/_/', $file); |
|
108 | 108 | $course = api_get_course_info($parts[0]); |
109 | 109 | if (count($course) > 0) { |
110 | 110 | // Build file info because handle_uploaded_document() needs it (name, type, size, tmp_name) |
111 | 111 | $fileSize = filesize($baseDir.$uploadPath.$file); |
112 | - $docId = add_document($course, $subDir.'/'.$file, 'file', $fileSize, $parts[1].' '.substr($parts[2],0,-4)); |
|
112 | + $docId = add_document($course, $subDir.'/'.$file, 'file', $fileSize, $parts[1].' '.substr($parts[2], 0, -4)); |
|
113 | 113 | if ($docId > 0) { |
114 | 114 | if (!is_file($baseDir.$uploadPath.$file)) { |
115 | 115 | error_log($baseDir.$uploadPath.$file.' does not exists in '.__FILE__); |
@@ -229,31 +229,31 @@ discard block |
||
229 | 229 | <td align="center"> |
230 | 230 | <div id="content_source"> |
231 | 231 | <?php |
232 | - if (!($add_type=='multiple')) { |
|
232 | + if (!($add_type=='multiple')) { |
|
233 | 233 | ?> |
234 | 234 | <input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')" /> |
235 | 235 | <div id="ajax_list_users_single"></div> |
236 | 236 | <?php |
237 | - } else { |
|
238 | - ?> |
|
237 | + } else { |
|
238 | + ?> |
|
239 | 239 | <div id="ajax_list_multiple"> |
240 | 240 | <?php echo Display::select('elements_not_in_name', $elements_not_in, '', array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'elements_not_in','size'=>'15px'),false); ?> |
241 | 241 | </div> |
242 | 242 | <?php |
243 | - } |
|
244 | - ?> |
|
243 | + } |
|
244 | + ?> |
|
245 | 245 | </div> |
246 | 246 | </td> |
247 | 247 | <td width="10%" valign="middle" align="center"> |
248 | 248 | <?php |
249 | - if ($ajax_search) { |
|
250 | - ?> |
|
249 | + if ($ajax_search) { |
|
250 | + ?> |
|
251 | 251 | <button class="btn bt-default" type="button" onclick="remove_item(document.getElementById('elements_in'))" > |
252 | 252 | <em class="fa fa-arrow-left"></em> |
253 | 253 | </button> |
254 | 254 | <?php |
255 | - } else { |
|
256 | - ?> |
|
255 | + } else { |
|
256 | + ?> |
|
257 | 257 | <button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))"> |
258 | 258 | <em class="fa fa-arrow-right"></em> |
259 | 259 | </button> |
@@ -262,8 +262,8 @@ discard block |
||
262 | 262 | <em class="fa fa-arrow-left"></em> |
263 | 263 | </button> |
264 | 264 | <?php |
265 | - } |
|
266 | - ?> |
|
265 | + } |
|
266 | + ?> |
|
267 | 267 | <br /><br /><br /><br /><br /><br /> |
268 | 268 | </td> |
269 | 269 | <td align="center"> |
@@ -144,7 +144,10 @@ |
||
144 | 144 | echo '</div>'; |
145 | 145 | ?> |
146 | 146 | |
147 | -<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?id=<?php echo $id; if(!empty($_GET['add'])) echo '&add=true' ; ?>" style="margin:0px;" <?php if($ajax_search){echo ' onsubmit="valide();"';}?>> |
|
147 | +<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?id=<?php echo $id; if(!empty($_GET['add'])) { |
|
148 | + echo '&add=true' ; |
|
149 | +} |
|
150 | +?>" style="margin:0px;" <?php if($ajax_search){echo ' onsubmit="valide();"';}?>> |
|
148 | 151 | <?php echo '<legend>'.$tool_name.' '.$promotion_data['name'].'</legend>'; |
149 | 152 | |
150 | 153 | if ($add_type=='multiple') { |
@@ -19,14 +19,14 @@ discard block |
||
19 | 19 | api_protect_admin_script(true); |
20 | 20 | |
21 | 21 | // Setting breadcrumbs. |
22 | -$interbreadcrumb[] = array('url' => 'index.php','name' => get_lang('PlatformAdmin')); |
|
23 | -$interbreadcrumb[] = array('url' => 'usergroups.php','name' => get_lang('Classes')); |
|
22 | +$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); |
|
23 | +$interbreadcrumb[] = array('url' => 'usergroups.php', 'name' => get_lang('Classes')); |
|
24 | 24 | |
25 | 25 | // Setting the name of the tool. |
26 | 26 | $tool_name = get_lang('SubscribeClassToCourses'); |
27 | 27 | |
28 | 28 | $add_type = 'multiple'; |
29 | -if (isset($_REQUEST['add_type']) && $_REQUEST['add_type']!=''){ |
|
29 | +if (isset($_REQUEST['add_type']) && $_REQUEST['add_type'] != '') { |
|
30 | 30 | $add_type = Security::remove_XSS($_REQUEST['add_type']); |
31 | 31 | } |
32 | 32 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | |
98 | 98 | $searchForm = new FormValidator('search', 'get', api_get_self().'?id='.$id); |
99 | 99 | $searchForm->addHeader(get_lang('AdvancedSearch')); |
100 | -$renderer =& $searchForm->defaultRenderer(); |
|
100 | +$renderer = & $searchForm->defaultRenderer(); |
|
101 | 101 | $searchForm->addElement('hidden', 'id', $id); |
102 | 102 | foreach ($filters as $param) { |
103 | 103 | $searchForm->addElement($param['type'], $param['name'], $param['label']); |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | |
142 | 142 | //checking for extra field with filter on |
143 | 143 | |
144 | -function search($needle,$type) |
|
144 | +function search($needle, $type) |
|
145 | 145 | { |
146 | 146 | global $elements_in; |
147 | 147 | $xajax_response = new xajaxResponse(); |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | } |
181 | 181 | |
182 | 182 | echo '<div class="actions">'; |
183 | -echo '<a href="usergroups.php">'.Display::return_icon('back.png',get_lang('Back'), array(), ICON_SIZE_MEDIUM).'</a>'; |
|
183 | +echo '<a href="usergroups.php">'.Display::return_icon('back.png', get_lang('Back'), array(), ICON_SIZE_MEDIUM).'</a>'; |
|
184 | 184 | echo Display::url(get_lang('AdvancedSearch'), '#', array('class' => 'advanced_options', 'id' => 'advanced_search')); |
185 | 185 | echo '</div>'; |
186 | 186 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | |
191 | 191 | ?> |
192 | 192 | |
193 | -<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?id=<?php echo $id; if(!empty($_GET['add'])) echo '&add=true' ; ?>" style="margin:0px;" <?php if($ajax_search){echo ' onsubmit="valide();"';}?>> |
|
193 | +<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?id=<?php echo $id; if (!empty($_GET['add'])) echo '&add=true'; ?>" style="margin:0px;" <?php if ($ajax_search) {echo ' onsubmit="valide();"'; }?>> |
|
194 | 194 | |
195 | 195 | <?php echo '<legend>'.$data['name'].': '.$tool_name.'</legend>'; |
196 | 196 | echo Display::input('hidden', 'id', $id); |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | <td align="center"><b><?php echo get_lang('CoursesInGroup') ?> :</b></td> |
210 | 210 | </tr> |
211 | 211 | |
212 | -<?php if ($add_type=='multiple') { ?> |
|
212 | +<?php if ($add_type == 'multiple') { ?> |
|
213 | 213 | <tr> |
214 | 214 | <td align="center"> |
215 | 215 | <?php echo get_lang('FirstLetterCourseTitle'); ?> : |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | <td align="center"> |
228 | 228 | <div id="content_source"> |
229 | 229 | <?php |
230 | - if (!($add_type=='multiple')) { |
|
230 | + if (!($add_type == 'multiple')) { |
|
231 | 231 | ?> |
232 | 232 | <input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')" /> |
233 | 233 | <div id="ajax_list_users_single"></div> |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | } else { |
236 | 236 | ?> |
237 | 237 | <div id="ajax_list_multiple"> |
238 | - <?php echo Display::select('elements_not_in_name', $elements_not_in, '', array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'elements_not_in','size'=>'15px'),false); ?> |
|
238 | + <?php echo Display::select('elements_not_in_name', $elements_not_in, '', array('style'=>'width:360px', 'multiple'=>'multiple', 'id'=>'elements_not_in', 'size'=>'15px'), false); ?> |
|
239 | 239 | </div> |
240 | 240 | <?php |
241 | 241 | } |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | </td> |
267 | 267 | <td align="center"> |
268 | 268 | <?php |
269 | - echo Display::select('elements_in_name[]', $elements_in, '', array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'elements_in','size'=>'15px'),false ); |
|
269 | + echo Display::select('elements_in_name[]', $elements_in, '', array('style'=>'width:360px', 'multiple'=>'multiple', 'id'=>'elements_in', 'size'=>'15px'), false); |
|
270 | 270 | unset($sessionUsersList); |
271 | 271 | ?> |
272 | 272 | </td> |
@@ -22,16 +22,16 @@ discard block |
||
22 | 22 | |
23 | 23 | set_time_limit(0); |
24 | 24 | |
25 | -$courses = array (); |
|
25 | +$courses = array(); |
|
26 | 26 | $courses[''] = '--'; |
27 | 27 | $sql = "SELECT code,visual_code,title FROM $course_table ORDER BY visual_code"; |
28 | 28 | |
29 | 29 | global $_configuration; |
30 | 30 | |
31 | 31 | if (api_is_multiple_url_enabled()) { |
32 | - $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); |
|
32 | + $tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); |
|
33 | 33 | $access_url_id = api_get_current_access_url_id(); |
34 | - if ($access_url_id != -1){ |
|
34 | + if ($access_url_id != -1) { |
|
35 | 35 | $sql = "SELECT code,visual_code,title |
36 | 36 | FROM $course_table as c |
37 | 37 | INNER JOIN $tbl_course_rel_access_url as course_rel_url |
@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | } |
47 | 47 | $form = new FormValidator('export_users'); |
48 | 48 | $form->addElement('header', $tool_name); |
49 | -$form->addElement('radio', 'file_type', get_lang('OutputFileType'), 'XML','xml'); |
|
49 | +$form->addElement('radio', 'file_type', get_lang('OutputFileType'), 'XML', 'xml'); |
|
50 | 50 | $form->addElement('radio', 'file_type', null, 'CSV', 'csv'); |
51 | 51 | $form->addElement('radio', 'file_type', null, 'XLS', 'xls'); |
52 | 52 | |
53 | -$form->addElement('checkbox', 'addcsvheader', get_lang('AddCSVHeader'), get_lang('YesAddCSVHeader'),'1'); |
|
53 | +$form->addElement('checkbox', 'addcsvheader', get_lang('AddCSVHeader'), get_lang('YesAddCSVHeader'), '1'); |
|
54 | 54 | $form->addElement('select', 'course_code', get_lang('OnlyUsersFromCourse'), $courses); |
55 | 55 | $form->addButtonExport(get_lang('Export')); |
56 | 56 | $form->setDefaults(array('file_type' => 'csv')); |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | u.firstname AS FirstName, |
69 | 69 | u.email AS Email, |
70 | 70 | u.username AS UserName, |
71 | - ".(($_configuration['password_encryption']!='none')?" ":"u.password AS Password, ")." |
|
71 | + ".(($_configuration['password_encryption'] != 'none') ? " " : "u.password AS Password, ")." |
|
72 | 72 | u.auth_source AS AuthSource, |
73 | 73 | u.status AS Status, |
74 | 74 | u.official_code AS OfficialCode, |
@@ -83,10 +83,10 @@ discard block |
||
83 | 83 | $filename = 'export_users_'.$course_code.'_'.api_get_local_time(); |
84 | 84 | } else { |
85 | 85 | if (api_is_multiple_url_enabled()) { |
86 | - $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
|
86 | + $tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
|
87 | 87 | $access_url_id = api_get_current_access_url_id(); |
88 | 88 | if ($access_url_id != -1) { |
89 | - $sql.= " FROM $user_table u |
|
89 | + $sql .= " FROM $user_table u |
|
90 | 90 | INNER JOIN $tbl_user_rel_access_url as user_rel_url |
91 | 91 | ON (u.user_id= user_rel_url.user_id) |
92 | 92 | WHERE access_url_id = $access_url_id |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | $filename = 'export_users_'.api_get_local_time(); |
99 | 99 | } |
100 | 100 | $data = array(); |
101 | - $extra_fields = UserManager::get_extra_fields(0, 0, 5, 'ASC',false); |
|
102 | - if ($export['addcsvheader']=='1' AND $export['file_type']=='csv') { |
|
101 | + $extra_fields = UserManager::get_extra_fields(0, 0, 5, 'ASC', false); |
|
102 | + if ($export['addcsvheader'] == '1' AND $export['file_type'] == 'csv') { |
|
103 | 103 | if ($_configuration['password_encryption'] != 'none') { |
104 | 104 | $data[] = array( |
105 | 105 | 'UserId', |
@@ -127,19 +127,19 @@ discard block |
||
127 | 127 | ); |
128 | 128 | } |
129 | 129 | |
130 | - foreach($extra_fields as $extra) { |
|
131 | - $data[0][]=$extra[1]; |
|
130 | + foreach ($extra_fields as $extra) { |
|
131 | + $data[0][] = $extra[1]; |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
135 | 135 | $res = Database::query($sql); |
136 | - while($user = Database::fetch_array($res,'ASSOC')) { |
|
136 | + while ($user = Database::fetch_array($res, 'ASSOC')) { |
|
137 | 137 | $student_data = UserManager:: get_extra_user_data( |
138 | 138 | $user['UserId'], |
139 | 139 | true, |
140 | 140 | false |
141 | 141 | ); |
142 | - foreach($student_data as $key=>$value) { |
|
142 | + foreach ($student_data as $key=>$value) { |
|
143 | 143 | $key = substr($key, 6); |
144 | 144 | if (is_array($value)) { |
145 | 145 | $user[$key] = $value[$key]; |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $user[$key] = $value; |
148 | 148 | } |
149 | 149 | } |
150 | - $data[] = $user ; |
|
150 | + $data[] = $user; |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | switch ($file_type) { |
@@ -29,20 +29,20 @@ discard block |
||
29 | 29 | global $_configuration; |
30 | 30 | |
31 | 31 | if (api_is_multiple_url_enabled()) { |
32 | - $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); |
|
33 | - $access_url_id = api_get_current_access_url_id(); |
|
34 | - if ($access_url_id != -1){ |
|
35 | - $sql = "SELECT code,visual_code,title |
|
32 | + $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); |
|
33 | + $access_url_id = api_get_current_access_url_id(); |
|
34 | + if ($access_url_id != -1){ |
|
35 | + $sql = "SELECT code,visual_code,title |
|
36 | 36 | FROM $course_table as c |
37 | 37 | INNER JOIN $tbl_course_rel_access_url as course_rel_url |
38 | 38 | ON (c.id = course_rel_url.c_id) |
39 | 39 | WHERE access_url_id = $access_url_id |
40 | 40 | ORDER BY visual_code"; |
41 | - } |
|
41 | + } |
|
42 | 42 | } |
43 | 43 | $result = Database::query($sql); |
44 | 44 | while ($course = Database::fetch_object($result)) { |
45 | - $courses[$course->code] = $course->visual_code.' - '.$course->title; |
|
45 | + $courses[$course->code] = $course->visual_code.' - '.$course->title; |
|
46 | 46 | } |
47 | 47 | $form = new FormValidator('export_users'); |
48 | 48 | $form->addElement('header', $tool_name); |
@@ -56,13 +56,13 @@ discard block |
||
56 | 56 | $form->setDefaults(array('file_type' => 'csv')); |
57 | 57 | |
58 | 58 | if ($form->validate()) { |
59 | - $export = $form->exportValues(); |
|
60 | - $file_type = $export['file_type']; |
|
61 | - $course_code = Database::escape_string($export['course_code']); |
|
62 | - $courseInfo = api_get_course_info($course_code); |
|
63 | - $courseId = $courseInfo['real_id']; |
|
59 | + $export = $form->exportValues(); |
|
60 | + $file_type = $export['file_type']; |
|
61 | + $course_code = Database::escape_string($export['course_code']); |
|
62 | + $courseInfo = api_get_course_info($course_code); |
|
63 | + $courseId = $courseInfo['real_id']; |
|
64 | 64 | |
65 | - $sql = "SELECT |
|
65 | + $sql = "SELECT |
|
66 | 66 | u.user_id AS UserId, |
67 | 67 | u.lastname AS LastName, |
68 | 68 | u.firstname AS FirstName, |
@@ -73,96 +73,96 @@ discard block |
||
73 | 73 | u.status AS Status, |
74 | 74 | u.official_code AS OfficialCode, |
75 | 75 | u.phone AS Phone"; |
76 | - if (strlen($course_code) > 0) { |
|
77 | - $sql .= " FROM $user_table u, $course_user_table cu |
|
76 | + if (strlen($course_code) > 0) { |
|
77 | + $sql .= " FROM $user_table u, $course_user_table cu |
|
78 | 78 | WHERE |
79 | 79 | u.user_id = cu.user_id AND |
80 | 80 | cu.c_id = $courseId AND |
81 | 81 | cu.relation_type<>".COURSE_RELATION_TYPE_RRHH." |
82 | 82 | ORDER BY lastname,firstname"; |
83 | - $filename = 'export_users_'.$course_code.'_'.api_get_local_time(); |
|
84 | - } else { |
|
85 | - if (api_is_multiple_url_enabled()) { |
|
86 | - $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
|
87 | - $access_url_id = api_get_current_access_url_id(); |
|
88 | - if ($access_url_id != -1) { |
|
89 | - $sql.= " FROM $user_table u |
|
83 | + $filename = 'export_users_'.$course_code.'_'.api_get_local_time(); |
|
84 | + } else { |
|
85 | + if (api_is_multiple_url_enabled()) { |
|
86 | + $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
|
87 | + $access_url_id = api_get_current_access_url_id(); |
|
88 | + if ($access_url_id != -1) { |
|
89 | + $sql.= " FROM $user_table u |
|
90 | 90 | INNER JOIN $tbl_user_rel_access_url as user_rel_url |
91 | 91 | ON (u.user_id= user_rel_url.user_id) |
92 | 92 | WHERE access_url_id = $access_url_id |
93 | 93 | ORDER BY lastname,firstname"; |
94 | - } |
|
95 | - } else { |
|
96 | - $sql .= " FROM $user_table u ORDER BY lastname,firstname"; |
|
97 | - } |
|
98 | - $filename = 'export_users_'.api_get_local_time(); |
|
99 | - } |
|
100 | - $data = array(); |
|
101 | - $extra_fields = UserManager::get_extra_fields(0, 0, 5, 'ASC',false); |
|
102 | - if ($export['addcsvheader']=='1' AND $export['file_type']=='csv') { |
|
103 | - if ($_configuration['password_encryption'] != 'none') { |
|
104 | - $data[] = array( |
|
105 | - 'UserId', |
|
106 | - 'LastName', |
|
107 | - 'FirstName', |
|
108 | - 'Email', |
|
109 | - 'UserName', |
|
110 | - 'AuthSource', |
|
111 | - 'Status', |
|
112 | - 'OfficialCode', |
|
113 | - 'PhoneNumber', |
|
114 | - ); |
|
115 | - } else { |
|
116 | - $data[] = array( |
|
117 | - 'UserId', |
|
118 | - 'LastName', |
|
119 | - 'FirstName', |
|
120 | - 'Email', |
|
121 | - 'UserName', |
|
122 | - 'Password', |
|
123 | - 'AuthSource', |
|
124 | - 'Status', |
|
125 | - 'OfficialCode', |
|
126 | - 'PhoneNumber', |
|
127 | - ); |
|
128 | - } |
|
129 | - |
|
130 | - foreach($extra_fields as $extra) { |
|
131 | - $data[0][]=$extra[1]; |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - $res = Database::query($sql); |
|
136 | - while($user = Database::fetch_array($res,'ASSOC')) { |
|
137 | - $student_data = UserManager:: get_extra_user_data( |
|
138 | - $user['UserId'], |
|
139 | - true, |
|
140 | - false |
|
141 | - ); |
|
142 | - foreach($student_data as $key=>$value) { |
|
143 | - $key = substr($key, 6); |
|
144 | - if (is_array($value)) { |
|
145 | - $user[$key] = $value[$key]; |
|
146 | - } else { |
|
147 | - $user[$key] = $value; |
|
148 | - } |
|
149 | - } |
|
150 | - $data[] = $user ; |
|
151 | - } |
|
152 | - |
|
153 | - switch ($file_type) { |
|
154 | - case 'xml': |
|
155 | - Export::arrayToXml($data, $filename, 'Contact', 'Contacts'); |
|
156 | - exit; |
|
157 | - break; |
|
158 | - case 'csv': |
|
159 | - Export::arrayToCsv($data, $filename); |
|
160 | - exit; |
|
161 | - case 'xls': |
|
162 | - Export::arrayToXls($data, $filename); |
|
163 | - exit; |
|
164 | - break; |
|
165 | - } |
|
94 | + } |
|
95 | + } else { |
|
96 | + $sql .= " FROM $user_table u ORDER BY lastname,firstname"; |
|
97 | + } |
|
98 | + $filename = 'export_users_'.api_get_local_time(); |
|
99 | + } |
|
100 | + $data = array(); |
|
101 | + $extra_fields = UserManager::get_extra_fields(0, 0, 5, 'ASC',false); |
|
102 | + if ($export['addcsvheader']=='1' AND $export['file_type']=='csv') { |
|
103 | + if ($_configuration['password_encryption'] != 'none') { |
|
104 | + $data[] = array( |
|
105 | + 'UserId', |
|
106 | + 'LastName', |
|
107 | + 'FirstName', |
|
108 | + 'Email', |
|
109 | + 'UserName', |
|
110 | + 'AuthSource', |
|
111 | + 'Status', |
|
112 | + 'OfficialCode', |
|
113 | + 'PhoneNumber', |
|
114 | + ); |
|
115 | + } else { |
|
116 | + $data[] = array( |
|
117 | + 'UserId', |
|
118 | + 'LastName', |
|
119 | + 'FirstName', |
|
120 | + 'Email', |
|
121 | + 'UserName', |
|
122 | + 'Password', |
|
123 | + 'AuthSource', |
|
124 | + 'Status', |
|
125 | + 'OfficialCode', |
|
126 | + 'PhoneNumber', |
|
127 | + ); |
|
128 | + } |
|
129 | + |
|
130 | + foreach($extra_fields as $extra) { |
|
131 | + $data[0][]=$extra[1]; |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + $res = Database::query($sql); |
|
136 | + while($user = Database::fetch_array($res,'ASSOC')) { |
|
137 | + $student_data = UserManager:: get_extra_user_data( |
|
138 | + $user['UserId'], |
|
139 | + true, |
|
140 | + false |
|
141 | + ); |
|
142 | + foreach($student_data as $key=>$value) { |
|
143 | + $key = substr($key, 6); |
|
144 | + if (is_array($value)) { |
|
145 | + $user[$key] = $value[$key]; |
|
146 | + } else { |
|
147 | + $user[$key] = $value; |
|
148 | + } |
|
149 | + } |
|
150 | + $data[] = $user ; |
|
151 | + } |
|
152 | + |
|
153 | + switch ($file_type) { |
|
154 | + case 'xml': |
|
155 | + Export::arrayToXml($data, $filename, 'Contact', 'Contacts'); |
|
156 | + exit; |
|
157 | + break; |
|
158 | + case 'csv': |
|
159 | + Export::arrayToCsv($data, $filename); |
|
160 | + exit; |
|
161 | + case 'xls': |
|
162 | + Export::arrayToXls($data, $filename); |
|
163 | + exit; |
|
164 | + break; |
|
165 | + } |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | Display :: display_header($tool_name); |