Completed
Push — master ( 1ea773...b7667b )
by Julito
63:46 queued 26:51
created
main/inc/lib/app_view.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
      * @param string  tool name (optional)
17 17
      * @param string $template_path
18 18
      */
19
-    public function __construct($toolname = '', $template_path=null)
19
+    public function __construct($toolname = '', $template_path = null)
20 20
     {
21 21
         if (!empty($toolname)) {
22 22
             if (isset($template_path)) {
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
             if (is_dir($path)) {
28 28
                 $this->tool_path = $path;
29 29
             } else {
30
-                throw new Exception('View::__construct() $path directory does not exist ' . $path);
30
+                throw new Exception('View::__construct() $path directory does not exist '.$path);
31 31
             }
32 32
         }
33 33
     }
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
     public function set_data($data)
40 40
     {
41 41
         if (!is_array($data)) {
42
-            throw new Exception('View::set_data() $data must to be an array, you have sent a' . gettype( $data ));
42
+            throw new Exception('View::set_data() $data must to be an array, you have sent a'.gettype($data));
43 43
         }
44 44
         $this->data = $data;
45 45
     }
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
      * @param string layout view
50 50
      * @param string $layout
51 51
      */
52
-    public function set_layout( $layout )
52
+    public function set_layout($layout)
53 53
     {
54 54
         $this->layout = $layout;
55 55
     }
Please login to merge, or discard this patch.
main/inc/lib/auth.lib.php 2 patches
Doc Comments   +8 added lines patch added patch discarded remove patch
@@ -183,6 +183,7 @@  discard block
 block discarded – undo
183 183
      * (moving a course to a different course category)
184 184
      * @param  int    $courseId
185 185
      * @param  int       Category id
186
+     * @param integer $newcategory
186 187
      * @return bool      True if it success
187 188
      */
188 189
     public function updateCourseCategory($courseId, $newcategory)
@@ -215,6 +216,9 @@  discard block
 block discarded – undo
215 216
      * @param   string    Direction (up/down)
216 217
      * @param   string    Course code
217 218
      * @param   int       Category id
219
+     * @param string $direction
220
+     * @param string $course2move
221
+     * @param integer $category
218 222
      * @return  bool      True if it success
219 223
      */
220 224
     public function move_course($direction, $course2move, $category)
@@ -285,6 +289,8 @@  discard block
 block discarded – undo
285 289
      * Moves the course one place up or down
286 290
      * @param string    Direction up/down
287 291
      * @param string    Category id
292
+     * @param string $direction
293
+     * @param integer $category2move
288 294
      * @return bool     True If it success
289 295
      */
290 296
     public function move_category($direction, $category2move)
@@ -348,6 +354,8 @@  discard block
 block discarded – undo
348 354
      * Updates the user course category in the chamilo_user database
349 355
      * @param   string  Category title
350 356
      * @param   int     Category id
357
+     * @param string $title
358
+     * @param integer $category_id
351 359
      * @return  bool    True if it success
352 360
      */
353 361
     public function store_edit_course_category($title, $category_id)
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -48,12 +48,12 @@  discard block
 block discarded – undo
48 48
         $special_course_list = array();
49 49
         if (Database::num_rows($result) > 0) {
50 50
             while ($result_row = Database::fetch_array($result)) {
51
-                $special_course_list[] = '"' . $result_row['item_id'] . '"';
51
+                $special_course_list[] = '"'.$result_row['item_id'].'"';
52 52
             }
53 53
         }
54 54
         $without_special_courses = '';
55 55
         if (!empty($special_course_list)) {
56
-            $without_special_courses = ' AND course.id NOT IN (' . implode(',', $special_course_list) . ')';
56
+            $without_special_courses = ' AND course.id NOT IN ('.implode(',', $special_course_list).')';
57 57
         }
58 58
 
59 59
         // Secondly we select the courses that are in a category (user_course_cat<>0) and sort these according to the sort of the category
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
                 FROM $TABLECOURS course, $TABLECOURSUSER  course_rel_user
74 74
                 WHERE
75 75
                     course.id = course_rel_user.c_id AND
76
-                    course_rel_user.relation_type<>" . COURSE_RELATION_TYPE_RRHH . " AND
77
-                    course_rel_user.user_id = '" . $user_id . "' $without_special_courses
76
+                    course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND
77
+                    course_rel_user.user_id = '" . $user_id."' $without_special_courses
78 78
                 ORDER BY course_rel_user.sort ASC";
79 79
         $result = Database::query($sql);
80 80
         $courses = array();
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
     {
107 107
         $user_id = api_get_user_id();
108 108
         $table_category = Database::get_main_table(TABLE_USER_COURSE_CATEGORY);
109
-        $sql = "SELECT * FROM " . $table_category . "
109
+        $sql = "SELECT * FROM ".$table_category."
110 110
                 WHERE user_id=$user_id
111 111
                 ORDER BY sort ASC";
112 112
         $result = Database::query($sql);
@@ -148,13 +148,13 @@  discard block
 block discarded – undo
148 148
         $special_course_list = array();
149 149
         if (Database::num_rows($result) > 0) {
150 150
             while ($result_row = Database::fetch_array($result)) {
151
-                $special_course_list[] = '"' . $result_row['item_id'] . '"';
151
+                $special_course_list[] = '"'.$result_row['item_id'].'"';
152 152
             }
153 153
         }
154 154
 
155 155
         $without_special_courses = '';
156 156
         if (!empty($special_course_list)) {
157
-            $without_special_courses = ' AND course.id NOT IN (' . implode(',', $special_course_list) . ')';
157
+            $without_special_courses = ' AND course.id NOT IN ('.implode(',', $special_course_list).')';
158 158
         }
159 159
 
160 160
         $sql = "SELECT
@@ -165,8 +165,8 @@  discard block
 block discarded – undo
165 165
                 $TABLECOURSUSER  course_rel_user
166 166
                 WHERE
167 167
                     course.id = course_rel_user.c_id AND
168
-                    course_rel_user.user_id = '" . $user_id . "' AND
169
-                    course_rel_user.relation_type <> " . COURSE_RELATION_TYPE_RRHH . "
168
+                    course_rel_user.user_id = '".$user_id."' AND
169
+                    course_rel_user.relation_type <> " . COURSE_RELATION_TYPE_RRHH."
170 170
                     $without_special_courses
171 171
                 ORDER BY course_rel_user.user_course_cat, course_rel_user.sort ASC";
172 172
         $result = Database::query($sql);
@@ -194,11 +194,11 @@  discard block
 block discarded – undo
194 194
         $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
195 195
         $max_sort_value = api_max_sort_value($newcategory, $current_user);
196 196
         $sql = "UPDATE $TABLECOURSUSER SET
197
-                    user_course_cat='" . $newcategory . "',
198
-                    sort='" . ($max_sort_value + 1) . "'
197
+                    user_course_cat='".$newcategory."',
198
+                    sort='" . ($max_sort_value + 1)."'
199 199
                 WHERE
200
-                    c_id ='" . $courseId . "' AND
201
-                    user_id='" . $current_user . "' AND
200
+                    c_id ='" . $courseId."' AND
201
+                    user_id='" . $current_user."' AND
202 202
                     relation_type<>" . COURSE_RELATION_TYPE_RRHH;
203 203
         $resultQuery = Database::query($sql);
204 204
 
@@ -257,18 +257,18 @@  discard block
 block discarded – undo
257 257
             $targetCourseId = $targetCourseInfo['real_id'];
258 258
 
259 259
             $sql = "UPDATE $table
260
-                    SET sort='" . $target_course['sort'] . "'
260
+                    SET sort='".$target_course['sort']."'
261 261
                     WHERE
262
-                        c_id = '" . $courseId . "' AND
263
-                        user_id = '" . $current_user_id . "' AND
262
+                        c_id = '" . $courseId."' AND
263
+                        user_id = '" . $current_user_id."' AND
264 264
                         relation_type<>" . COURSE_RELATION_TYPE_RRHH;
265 265
 
266 266
             $result1 = Database::query($sql);
267 267
 
268
-            $sql = "UPDATE $table SET sort='" . $source_course['sort'] . "'
268
+            $sql = "UPDATE $table SET sort='".$source_course['sort']."'
269 269
                     WHERE
270
-                        c_id ='" . $targetCourseId . "' AND
271
-                        user_id='" . $current_user_id . "' AND
270
+                        c_id ='" . $targetCourseId."' AND
271
+                        user_id='" . $current_user_id."' AND
272 272
                         relation_type<>" . COURSE_RELATION_TYPE_RRHH;
273 273
 
274 274
             $result2 = Database::query($sql);
@@ -312,10 +312,10 @@  discard block
 block discarded – undo
312 312
         }
313 313
 
314 314
         if (count($target_category) > 0 && count($source_category) > 0) {
315
-            $sql_update1 = "UPDATE $table_user_defined_category SET sort='" . Database::escape_string($target_category['sort']) . "'
316
-                            WHERE id='" . intval($source_category['id']) . "' AND user_id='" . $current_user_id . "'";
317
-            $sql_update2 = "UPDATE $table_user_defined_category SET sort='" . Database::escape_string($source_category['sort']) . "'
318
-                            WHERE id='" . intval($target_category['id']) . "' AND user_id='" . $current_user_id . "'";
315
+            $sql_update1 = "UPDATE $table_user_defined_category SET sort='".Database::escape_string($target_category['sort'])."'
316
+                            WHERE id='" . intval($source_category['id'])."' AND user_id='".$current_user_id."'";
317
+            $sql_update2 = "UPDATE $table_user_defined_category SET sort='".Database::escape_string($source_category['sort'])."'
318
+                            WHERE id='" . intval($target_category['id'])."' AND user_id='".$current_user_id."'";
319 319
 
320 320
             $result1 = Database::query($sql_update2);
321 321
             $result2 = Database::query($sql_update1);
@@ -334,8 +334,8 @@  discard block
 block discarded – undo
334 334
     {
335 335
         $current_user_id = api_get_user_id();
336 336
         $table_category = Database::get_main_table(TABLE_USER_COURSE_CATEGORY);
337
-        $sql = "SELECT * FROM " . $table_category . "
338
-                WHERE user_id='" . $current_user_id . "'
337
+        $sql = "SELECT * FROM ".$table_category."
338
+                WHERE user_id='" . $current_user_id."'
339 339
                 ORDER BY sort ASC";
340 340
         $result = Database::query($sql);
341 341
         while ($row = Database::fetch_array($result)) {
@@ -358,8 +358,8 @@  discard block
 block discarded – undo
358 358
         $result = false;
359 359
         $tucc = Database::get_main_table(TABLE_USER_COURSE_CATEGORY);
360 360
         $sql = "UPDATE $tucc
361
-                SET title='" . api_htmlentities($title, ENT_QUOTES, api_get_system_encoding()) . "'
362
-                WHERE id='" . $category_id . "'";
361
+                SET title='".api_htmlentities($title, ENT_QUOTES, api_get_system_encoding())."'
362
+                WHERE id='" . $category_id."'";
363 363
         $resultQuery = Database::query($sql);
364 364
         if (Database::affected_rows($resultQuery)) {
365 365
             $result = true;
@@ -381,8 +381,8 @@  discard block
 block discarded – undo
381 381
         $result = false;
382 382
         $sql = "DELETE FROM $tucc
383 383
                 WHERE 
384
-                    id='" . $category_id . "' AND 
385
-                    user_id='" . $current_user_id . "'";
384
+                    id='".$category_id."' AND 
385
+                    user_id='" . $current_user_id."'";
386 386
         $resultQuery = Database::query($sql);
387 387
        if (Database::affected_rows($resultQuery)) {
388 388
             $result = true;
@@ -390,9 +390,9 @@  discard block
 block discarded – undo
390 390
         $sql = "UPDATE $TABLECOURSUSER
391 391
                 SET user_course_cat='0'
392 392
                 WHERE
393
-                    user_course_cat='" . $category_id . "' AND
394
-                    user_id='" . $current_user_id . "' AND
395
-                    relation_type<>" . COURSE_RELATION_TYPE_RRHH . " ";
393
+                    user_course_cat='".$category_id."' AND
394
+                    user_id='" . $current_user_id."' AND
395
+                    relation_type<>" . COURSE_RELATION_TYPE_RRHH." ";
396 396
         Database::query($sql);
397 397
 
398 398
         return $result;
@@ -426,12 +426,12 @@  discard block
 block discarded – undo
426 426
         if (Database::num_rows($special_course_result) > 0) {
427 427
             $special_course_list = array();
428 428
             while ($result_row = Database::fetch_array($special_course_result)) {
429
-                $special_course_list[] = '"' . $result_row['item_id'] . '"';
429
+                $special_course_list[] = '"'.$result_row['item_id'].'"';
430 430
             }
431 431
         }
432 432
         $without_special_courses = '';
433 433
         if (!empty($special_course_list)) {
434
-            $without_special_courses = ' AND course.code NOT IN (' . implode(',', $special_course_list) . ')';
434
+            $without_special_courses = ' AND course.code NOT IN ('.implode(',', $special_course_list).')';
435 435
         }
436 436
 
437 437
         $visibilityCondition = $justVisible ? CourseManager::getCourseVisibilitySQLCondition('course') : '';
@@ -439,9 +439,9 @@  discard block
 block discarded – undo
439 439
         $search_term_safe = Database::escape_string($search_term);
440 440
         $sql_find = "SELECT * FROM $courseTable
441 441
                     WHERE (
442
-                            code LIKE '%" . $search_term_safe . "%' OR
443
-                            title LIKE '%" . $search_term_safe . "%' OR
444
-                            tutor_name LIKE '%" . $search_term_safe . "%'
442
+                            code LIKE '%".$search_term_safe."%' OR
443
+                            title LIKE '%" . $search_term_safe."%' OR
444
+                            tutor_name LIKE '%" . $search_term_safe."%'
445 445
                         )
446 446
                         $without_special_courses
447 447
                         $visibilityCondition
@@ -459,9 +459,9 @@  discard block
 block discarded – undo
459 459
                             ON (url_rel_course.c_id = course.id)
460 460
                             WHERE
461 461
                                 access_url_id = $url_access_id AND (
462
-                                    code LIKE '%" . $search_term_safe . "%' OR
463
-                                    title LIKE '%" . $search_term_safe . "%' OR
464
-                                    tutor_name LIKE '%" . $search_term_safe . "%'
462
+                                    code LIKE '%".$search_term_safe."%' OR
463
+                                    title LIKE '%" . $search_term_safe."%' OR
464
+                                    tutor_name LIKE '%" . $search_term_safe."%'
465 465
                                 )
466 466
                                 $without_special_courses
467 467
                                 $visibilityCondition
@@ -523,8 +523,8 @@  discard block
 block discarded – undo
523 523
         // (s)he can only delete the course
524 524
         $sql = "SELECT * FROM $tbl_course_user
525 525
                 WHERE
526
-                    user_id='" . $current_user_id . "' AND
527
-                    c_id ='" . $courseId . "' AND
526
+                    user_id='".$current_user_id."' AND
527
+                    c_id ='" . $courseId."' AND
528 528
                     status='1' ";
529 529
         $result_check = Database::query($sql);
530 530
         $number_of_rows = Database::num_rows($result_check);
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
 
554 554
         // step 1: we determine the max value of the user defined course categories
555 555
         $sql = "SELECT sort FROM $tucc 
556
-                WHERE user_id='" . $current_user_id . "' 
556
+                WHERE user_id='".$current_user_id."' 
557 557
                 ORDER BY sort DESC";
558 558
         $rs_sort = Database::query($sql);
559 559
         $maxsort = Database::fetch_array($rs_sort);
@@ -562,13 +562,13 @@  discard block
 block discarded – undo
562 562
         // step 2: we check if there is already a category with this name, if not we store it, else we give an error.
563 563
         $sql = "SELECT * FROM $tucc 
564 564
                 WHERE 
565
-                    user_id='" . $current_user_id . "' AND 
566
-                    title='" . $category_title . "'
565
+                    user_id='".$current_user_id."' AND 
566
+                    title='" . $category_title."'
567 567
                 ORDER BY sort DESC";
568 568
         $rs = Database::query($sql);
569 569
         if (Database::num_rows($rs) == 0) {
570 570
             $sql = "INSERT INTO $tucc (user_id, title,sort)
571
-                           VALUES ('" . $current_user_id . "', '" . api_htmlentities($category_title, ENT_QUOTES, api_get_system_encoding()) . "', '" . $nextsort . "')";
571
+                           VALUES ('".$current_user_id."', '".api_htmlentities($category_title, ENT_QUOTES, api_get_system_encoding())."', '".$nextsort."')";
572 572
             $resultQuery = Database::query($sql);
573 573
             if (Database::affected_rows($resultQuery)) {
574 574
                 $result = true;
@@ -652,10 +652,10 @@  discard block
 block discarded – undo
652 652
             if (isset($_POST['course_registration_code']) && $_POST['course_registration_code'] != $all_course_information['registration_code']) {
653 653
                 return false;
654 654
             }
655
-            $message = get_lang('CourseRequiresPassword') . '<br />';
655
+            $message = get_lang('CourseRequiresPassword').'<br />';
656 656
             $message .= $all_course_information['title'].' ('.$all_course_information['visual_code'].') ';
657 657
 
658
-            $action  = api_get_path(WEB_CODE_PATH) . "auth/courses.php?action=subscribe_user_with_password&sec_token=" . $_SESSION['sec_token'];
658
+            $action  = api_get_path(WEB_CODE_PATH)."auth/courses.php?action=subscribe_user_with_password&sec_token=".$_SESSION['sec_token'];
659 659
             $form = new FormValidator('subscribe_user_with_password', 'post', $action);
660 660
             $form->addElement('hidden', 'sec_token', $_SESSION['sec_token']);
661 661
             $form->addElement('hidden', 'subscribe_user_with_password', $all_course_information['code']);
Please login to merge, or discard this patch.
main/inc/lib/attendance.lib.php 2 patches
Indentation   +1695 added lines, -1695 removed lines patch added patch discarded remove patch
@@ -11,50 +11,50 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class Attendance
13 13
 {
14
-	private $session_id;
15
-	private $course_id;
16
-	private $date_time;
17
-	private $name;
18
-	private $description;
19
-	private $attendance_qualify_title;
20
-	private $attendance_weight;
21
-	private $course_int_id;
22
-	public $category_id;
23
-
24
-	// constants
25
-	const DONE_ATTENDANCE_LOG_TYPE = 'done_attendance_sheet';
26
-	const UPDATED_ATTENDANCE_LOG_TYPE = 'updated_attendance_sheet';
27
-	const LOCKED_ATTENDANCE_LOG_TYPE = 'locked_attendance_sheet';
28
-
29
-	/**
30
-	 * Constructor
31
-	 */
32
-	public function __construct()
33
-	{
34
-		//$this->course_int_id = api_get_course_int_id();
35
-	}
36
-
37
-	/**
38
-	 * Get the total number of attendance inside current course and current session
39
-	 * @see SortableTable#get_total_number_of_items()
40
-	 */
41
-	public static function get_number_of_attendances($active = -1)
42
-	{
43
-		$tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
44
-		$session_id = api_get_session_id();
45
-		$condition_session = api_get_session_condition($session_id);
46
-		$course_id = api_get_course_int_id();
47
-		$sql = "SELECT COUNT(att.id) AS total_number_of_items
14
+    private $session_id;
15
+    private $course_id;
16
+    private $date_time;
17
+    private $name;
18
+    private $description;
19
+    private $attendance_qualify_title;
20
+    private $attendance_weight;
21
+    private $course_int_id;
22
+    public $category_id;
23
+
24
+    // constants
25
+    const DONE_ATTENDANCE_LOG_TYPE = 'done_attendance_sheet';
26
+    const UPDATED_ATTENDANCE_LOG_TYPE = 'updated_attendance_sheet';
27
+    const LOCKED_ATTENDANCE_LOG_TYPE = 'locked_attendance_sheet';
28
+
29
+    /**
30
+     * Constructor
31
+     */
32
+    public function __construct()
33
+    {
34
+        //$this->course_int_id = api_get_course_int_id();
35
+    }
36
+
37
+    /**
38
+     * Get the total number of attendance inside current course and current session
39
+     * @see SortableTable#get_total_number_of_items()
40
+     */
41
+    public static function get_number_of_attendances($active = -1)
42
+    {
43
+        $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
44
+        $session_id = api_get_session_id();
45
+        $condition_session = api_get_session_condition($session_id);
46
+        $course_id = api_get_course_int_id();
47
+        $sql = "SELECT COUNT(att.id) AS total_number_of_items
48 48
 				FROM $tbl_attendance att
49 49
 		        WHERE c_id = $course_id $condition_session ";
50
-		if ($active == 1 || $active == 0) {
51
-			$sql .= "AND att.active = $active";
52
-		}
53
-		$res = Database::query($sql);
54
-		$obj = Database::fetch_object($res);
50
+        if ($active == 1 || $active == 0) {
51
+            $sql .= "AND att.active = $active";
52
+        }
53
+        $res = Database::query($sql);
54
+        $obj = Database::fetch_object($res);
55 55
 
56
-		return $obj->total_number_of_items;
57
-	}
56
+        return $obj->total_number_of_items;
57
+    }
58 58
 
59 59
     /**
60 60
      * Get attendance list only the id, name and attendance_qualify_max fields
@@ -90,36 +90,36 @@  discard block
 block discarded – undo
90 90
         return $data;
91 91
     }
92 92
 
93
-	/**
94
-	 * Get the attendaces to display on the current page (fill the sortable-table)
95
-	 * @param   int     offset of first user to recover
96
-	 * @param   int     Number of users to get
97
-	 * @param   int     Column to sort on
98
-	 * @param   string  Order (ASC,DESC)
99
-	 * @see SortableTable#get_table_data($from)
100
-	 */
101
-	public static function get_attendance_data($from, $number_of_items, $column, $direction)
102
-	{
103
-		$tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
104
-		$course_id = api_get_course_int_id();
105
-		$session_id = api_get_session_id();
106
-		$condition_session = api_get_session_condition($session_id);
107
-		$column = intval($column);
108
-		$from = intval($from);
109
-		$number_of_items = intval($number_of_items);
110
-
111
-		if (!in_array($direction, array('ASC','DESC'))) {
112
-			$direction = 'ASC';
113
-		}
114
-
115
-		$active_plus = '';
116
-		if ((isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') ||
117
-			!api_is_allowed_to_edit(null, true)
118
-		) {
119
-			$active_plus = ' AND att.active = 1';
120
-		}
121
-
122
-		$sql = "SELECT
93
+    /**
94
+     * Get the attendaces to display on the current page (fill the sortable-table)
95
+     * @param   int     offset of first user to recover
96
+     * @param   int     Number of users to get
97
+     * @param   int     Column to sort on
98
+     * @param   string  Order (ASC,DESC)
99
+     * @see SortableTable#get_table_data($from)
100
+     */
101
+    public static function get_attendance_data($from, $number_of_items, $column, $direction)
102
+    {
103
+        $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
104
+        $course_id = api_get_course_int_id();
105
+        $session_id = api_get_session_id();
106
+        $condition_session = api_get_session_condition($session_id);
107
+        $column = intval($column);
108
+        $from = intval($from);
109
+        $number_of_items = intval($number_of_items);
110
+
111
+        if (!in_array($direction, array('ASC','DESC'))) {
112
+            $direction = 'ASC';
113
+        }
114
+
115
+        $active_plus = '';
116
+        if ((isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') ||
117
+            !api_is_allowed_to_edit(null, true)
118
+        ) {
119
+            $active_plus = ' AND att.active = 1';
120
+        }
121
+
122
+        $sql = "SELECT
123 123
                     att.id AS col0,
124 124
                     att.name AS col1,
125 125
                     att.description AS col2,
@@ -134,327 +134,327 @@  discard block
 block discarded – undo
134 134
 				ORDER BY col$column $direction
135 135
 				LIMIT $from,$number_of_items ";
136 136
 
137
-		$res = Database::query($sql);
138
-		$attendances = array();
139
-		$user_info = api_get_user_info();
140
-		$allowDelete = api_get_setting('attendance.allow_delete_attendance');
141
-
142
-		while ($attendance = Database::fetch_row($res)) {
143
-			$student_param = '';
144
-			if (api_is_drh() && $_GET['student_id']) {
145
-				$student_param = '&student_id='.intval($_GET['student_id']);
146
-			}
147
-
148
-			$session_star = '';
149
-			if (api_get_session_id() == $attendance[6]) {
150
-				$session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
151
-			}
152
-			if ($attendance[5] == 1) {
153
-				$isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
154
-					api_get_user_id(),
155
-					api_get_course_info()
156
-				);
157
-
158
-				if (api_is_allowed_to_edit(null, true) || $isDrhOfCourse) {
159
-					// Link to edit
160
-					$attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star;
161
-				} else {
162
-					// Link to view
163
-					$attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list_no_edit&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star;
164
-				}
165
-			} else {
166
-				$attendance[1] = '<a class="muted" href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star;
167
-			}
168
-
169
-			if ($attendance[5] == 1) {
170
-				$attendance[3] = '<center>'.$attendance[3].'</center>';
171
-			} else {
172
-				$attendance[3] = '<center><span class="muted">'.$attendance[3].'</span></center>';
173
-			}
174
-
175
-			$attendance[3] = '<center>'.$attendance[3].'</center>';
176
-			if (api_is_allowed_to_edit(null, true)) {
177
-				$actions  = '';
178
-				$actions .= '<center>';
179
-
180
-				if (api_is_platform_admin()) {
181
-					$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].'">'.
182
-						Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
183
-					// Visible
184
-					if ($attendance[5] == 1) {
185
-						$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_set_invisible&attendance_id='.$attendance[0].'">'.
186
-							Display::return_icon('visible.png', get_lang('Hide'), array(), ICON_SIZE_SMALL).'</a>';
187
-					} else {
188
-						$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_set_visible&attendance_id='.$attendance[0].'">'.
189
-							Display::return_icon('invisible.png', get_lang('Show'), array(), ICON_SIZE_SMALL).'</a>';
190
-						$attendance[2] = '<span class="muted">'.$attendance[2].'</span>';
191
-					}
192
-					if ($allowDelete === 'true') {
193
-						$actions .= '<a href="index.php?' . api_get_cidreq() . '&action=attendance_delete&attendance_id=' . $attendance[0].'">' .
194
-							Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
195
-					}
196
-				} else {
197
-					$is_locked_attendance = self::is_locked_attendance($attendance[0]);
198
-					if ($is_locked_attendance) {
199
-						$actions .= Display::return_icon('edit_na.png', get_lang('Edit')).'&nbsp;';
200
-						$actions .= Display::return_icon('visible.png', get_lang('Hide'));
201
-					} else {
202
-						$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].'">'.
203
-							Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
204
-
205
-						if ($attendance[5] == 1) {
206
-							$actions .= ' <a href="index.php?'.api_get_cidreq().'&action=attendance_set_invisible&attendance_id='.$attendance[0].'">'.
207
-								Display::return_icon('visible.png', get_lang('Hide'), array(), ICON_SIZE_SMALL).'</a>';
208
-						} else {
209
-							$actions .= ' <a href="index.php?'.api_get_cidreq().'&action=attendance_set_visible&attendance_id='.$attendance[0].'">'.
210
-								Display::return_icon('invisible.png', get_lang('Show'), array(), ICON_SIZE_SMALL).'</a>';
211
-							$attendance[2] = '<span class="muted">'.$attendance[2].'</span>';
212
-						}
213
-						if ($allowDelete === 'true') {
214
-							$actions .= ' <a href="index.php?' . api_get_cidreq() . '&action=attendance_delete&attendance_id=' . $attendance[0].'">' .
215
-								Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
216
-						}
217
-					}
218
-				}
219
-
220
-				// display lock/unlock icon
221
-				$is_done_all_calendar = self::is_all_attendance_calendar_done($attendance[0]);
222
-
223
-				if ($is_done_all_calendar) {
224
-					$locked   = $attendance[4];
225
-					if ($locked == 0) {
226
-						if (api_is_platform_admin()) {
227
-							$message_alert = get_lang('AreYouSureToLockTheAttendance');
228
-						} else {
229
-							$message_alert = get_lang('UnlockMessageInformation');
230
-						}
231
-						$actions .= '&nbsp;<a onclick="javascript:if(!confirm(\''.$message_alert.'\')) return false;" href="index.php?'.api_get_cidreq().'&action=lock_attendance&attendance_id='.$attendance[0].'">'.
232
-								Display::return_icon('unlock.png', get_lang('LockAttendance')).'</a>';
233
-					} else {
234
-						if (api_is_platform_admin()) {
235
-							$actions .= '&nbsp;<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToUnlockTheAttendance').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=unlock_attendance&attendance_id='.$attendance[0].'">'.
236
-									Display::return_icon('locked.png', get_lang('UnlockAttendance')).'</a>';
237
-						} else {
238
-							$actions .= '&nbsp;'.Display::return_icon('locked_na.png', get_lang('LockedAttendance'));
239
-						}
240
-					}
241
-				}
242
-				$actions .= '</center>';
243
-
244
-				$attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3],$actions);
245
-			} else {
246
-				$attendance[0] = '&nbsp;';
247
-				$attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3]);
248
-			}
249
-		}
250
-
251
-		return $attendances;
252
-	}
253
-
254
-	/**
255
-	 * Get the attendances by id to display on the current page
256
-	 * @param  int     $attendance_id
257
-	 * @return array   attendance data
258
-	 */
259
-	public function get_attendance_by_id($attendance_id)
260
-	{
261
-		$tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
262
-		$attendance_id = intval($attendance_id);
263
-		$course_id = api_get_course_int_id();
264
-		$attendance_data = array();
265
-		$sql = "SELECT * FROM $tbl_attendance
137
+        $res = Database::query($sql);
138
+        $attendances = array();
139
+        $user_info = api_get_user_info();
140
+        $allowDelete = api_get_setting('attendance.allow_delete_attendance');
141
+
142
+        while ($attendance = Database::fetch_row($res)) {
143
+            $student_param = '';
144
+            if (api_is_drh() && $_GET['student_id']) {
145
+                $student_param = '&student_id='.intval($_GET['student_id']);
146
+            }
147
+
148
+            $session_star = '';
149
+            if (api_get_session_id() == $attendance[6]) {
150
+                $session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
151
+            }
152
+            if ($attendance[5] == 1) {
153
+                $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
154
+                    api_get_user_id(),
155
+                    api_get_course_info()
156
+                );
157
+
158
+                if (api_is_allowed_to_edit(null, true) || $isDrhOfCourse) {
159
+                    // Link to edit
160
+                    $attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star;
161
+                } else {
162
+                    // Link to view
163
+                    $attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list_no_edit&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star;
164
+                }
165
+            } else {
166
+                $attendance[1] = '<a class="muted" href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star;
167
+            }
168
+
169
+            if ($attendance[5] == 1) {
170
+                $attendance[3] = '<center>'.$attendance[3].'</center>';
171
+            } else {
172
+                $attendance[3] = '<center><span class="muted">'.$attendance[3].'</span></center>';
173
+            }
174
+
175
+            $attendance[3] = '<center>'.$attendance[3].'</center>';
176
+            if (api_is_allowed_to_edit(null, true)) {
177
+                $actions  = '';
178
+                $actions .= '<center>';
179
+
180
+                if (api_is_platform_admin()) {
181
+                    $actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].'">'.
182
+                        Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
183
+                    // Visible
184
+                    if ($attendance[5] == 1) {
185
+                        $actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_set_invisible&attendance_id='.$attendance[0].'">'.
186
+                            Display::return_icon('visible.png', get_lang('Hide'), array(), ICON_SIZE_SMALL).'</a>';
187
+                    } else {
188
+                        $actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_set_visible&attendance_id='.$attendance[0].'">'.
189
+                            Display::return_icon('invisible.png', get_lang('Show'), array(), ICON_SIZE_SMALL).'</a>';
190
+                        $attendance[2] = '<span class="muted">'.$attendance[2].'</span>';
191
+                    }
192
+                    if ($allowDelete === 'true') {
193
+                        $actions .= '<a href="index.php?' . api_get_cidreq() . '&action=attendance_delete&attendance_id=' . $attendance[0].'">' .
194
+                            Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
195
+                    }
196
+                } else {
197
+                    $is_locked_attendance = self::is_locked_attendance($attendance[0]);
198
+                    if ($is_locked_attendance) {
199
+                        $actions .= Display::return_icon('edit_na.png', get_lang('Edit')).'&nbsp;';
200
+                        $actions .= Display::return_icon('visible.png', get_lang('Hide'));
201
+                    } else {
202
+                        $actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].'">'.
203
+                            Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
204
+
205
+                        if ($attendance[5] == 1) {
206
+                            $actions .= ' <a href="index.php?'.api_get_cidreq().'&action=attendance_set_invisible&attendance_id='.$attendance[0].'">'.
207
+                                Display::return_icon('visible.png', get_lang('Hide'), array(), ICON_SIZE_SMALL).'</a>';
208
+                        } else {
209
+                            $actions .= ' <a href="index.php?'.api_get_cidreq().'&action=attendance_set_visible&attendance_id='.$attendance[0].'">'.
210
+                                Display::return_icon('invisible.png', get_lang('Show'), array(), ICON_SIZE_SMALL).'</a>';
211
+                            $attendance[2] = '<span class="muted">'.$attendance[2].'</span>';
212
+                        }
213
+                        if ($allowDelete === 'true') {
214
+                            $actions .= ' <a href="index.php?' . api_get_cidreq() . '&action=attendance_delete&attendance_id=' . $attendance[0].'">' .
215
+                                Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
216
+                        }
217
+                    }
218
+                }
219
+
220
+                // display lock/unlock icon
221
+                $is_done_all_calendar = self::is_all_attendance_calendar_done($attendance[0]);
222
+
223
+                if ($is_done_all_calendar) {
224
+                    $locked   = $attendance[4];
225
+                    if ($locked == 0) {
226
+                        if (api_is_platform_admin()) {
227
+                            $message_alert = get_lang('AreYouSureToLockTheAttendance');
228
+                        } else {
229
+                            $message_alert = get_lang('UnlockMessageInformation');
230
+                        }
231
+                        $actions .= '&nbsp;<a onclick="javascript:if(!confirm(\''.$message_alert.'\')) return false;" href="index.php?'.api_get_cidreq().'&action=lock_attendance&attendance_id='.$attendance[0].'">'.
232
+                                Display::return_icon('unlock.png', get_lang('LockAttendance')).'</a>';
233
+                    } else {
234
+                        if (api_is_platform_admin()) {
235
+                            $actions .= '&nbsp;<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToUnlockTheAttendance').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=unlock_attendance&attendance_id='.$attendance[0].'">'.
236
+                                    Display::return_icon('locked.png', get_lang('UnlockAttendance')).'</a>';
237
+                        } else {
238
+                            $actions .= '&nbsp;'.Display::return_icon('locked_na.png', get_lang('LockedAttendance'));
239
+                        }
240
+                    }
241
+                }
242
+                $actions .= '</center>';
243
+
244
+                $attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3],$actions);
245
+            } else {
246
+                $attendance[0] = '&nbsp;';
247
+                $attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3]);
248
+            }
249
+        }
250
+
251
+        return $attendances;
252
+    }
253
+
254
+    /**
255
+     * Get the attendances by id to display on the current page
256
+     * @param  int     $attendance_id
257
+     * @return array   attendance data
258
+     */
259
+    public function get_attendance_by_id($attendance_id)
260
+    {
261
+        $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
262
+        $attendance_id = intval($attendance_id);
263
+        $course_id = api_get_course_int_id();
264
+        $attendance_data = array();
265
+        $sql = "SELECT * FROM $tbl_attendance
266 266
 				WHERE c_id = $course_id AND id = '$attendance_id'";
267
-		$res = Database::query($sql);
268
-		if (Database::num_rows($res) > 0) {
269
-			while ($row = Database::fetch_array($res)) {
270
-				$attendance_data = $row;
271
-			}
272
-		}
273
-		return $attendance_data;
274
-	}
275
-
276
-	/**
277
-	 * Add attendances sheet inside table. This is the *list of* dates, not
278
-	 * a specific date in itself.
279
-	 * @param  bool   true for adding link in gradebook or false otherwise (optional)
280
-	 * @return int    last attendance id
281
-	 */
282
-	public function attendance_add($link_to_gradebook = false)
283
-	{
284
-		$_course = api_get_course_info();
285
-		$tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
286
-		$session_id = api_get_session_id();
287
-		$user_id = api_get_user_id();
288
-		$course_code = $_course['code'];
289
-		$course_id = $_course['real_id'];
290
-		$title_gradebook= $this->attendance_qualify_title;
291
-		$value_calification = 0;
292
-		$weight_calification = floatval($this->attendance_weight);
267
+        $res = Database::query($sql);
268
+        if (Database::num_rows($res) > 0) {
269
+            while ($row = Database::fetch_array($res)) {
270
+                $attendance_data = $row;
271
+            }
272
+        }
273
+        return $attendance_data;
274
+    }
275
+
276
+    /**
277
+     * Add attendances sheet inside table. This is the *list of* dates, not
278
+     * a specific date in itself.
279
+     * @param  bool   true for adding link in gradebook or false otherwise (optional)
280
+     * @return int    last attendance id
281
+     */
282
+    public function attendance_add($link_to_gradebook = false)
283
+    {
284
+        $_course = api_get_course_info();
285
+        $tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
286
+        $session_id = api_get_session_id();
287
+        $user_id = api_get_user_id();
288
+        $course_code = $_course['code'];
289
+        $course_id = $_course['real_id'];
290
+        $title_gradebook= $this->attendance_qualify_title;
291
+        $value_calification = 0;
292
+        $weight_calification = floatval($this->attendance_weight);
293 293
 
294 294
         $em = Database::getManager();
295 295
 
296
-		$params = [
297
-			'c_id' => $course_id,
298
-			'name' => $this->name,
299
-			'description' => $this->description,
300
-			'attendance_qualify_title' => $title_gradebook,
301
-			'attendance_weight' => $weight_calification,
302
-			'session_id' => $session_id,
303
-			'active' => 1,
304
-			'attendance_qualify_max' => 0,
305
-			'locked' => 0
306
-		];
307
-		$last_id = Database::insert($tbl_attendance, $params);
308
-
309
-		if (!empty($last_id)) {
310
-
311
-			$sql = "UPDATE $tbl_attendance SET id = iid WHERE iid = $last_id";
312
-			Database::query($sql);
313
-
314
-			api_item_property_update(
315
-				$_course,
316
-				TOOL_ATTENDANCE,
317
-				$last_id,
318
-				"AttendanceAdded",
319
-				$user_id
320
-			);
321
-
322
-		}
323
-		// add link to gradebook
324
-		if ($link_to_gradebook && !empty($this->category_id)) {
325
-			$description = '';
296
+        $params = [
297
+            'c_id' => $course_id,
298
+            'name' => $this->name,
299
+            'description' => $this->description,
300
+            'attendance_qualify_title' => $title_gradebook,
301
+            'attendance_weight' => $weight_calification,
302
+            'session_id' => $session_id,
303
+            'active' => 1,
304
+            'attendance_qualify_max' => 0,
305
+            'locked' => 0
306
+        ];
307
+        $last_id = Database::insert($tbl_attendance, $params);
308
+
309
+        if (!empty($last_id)) {
310
+
311
+            $sql = "UPDATE $tbl_attendance SET id = iid WHERE iid = $last_id";
312
+            Database::query($sql);
313
+
314
+            api_item_property_update(
315
+                $_course,
316
+                TOOL_ATTENDANCE,
317
+                $last_id,
318
+                "AttendanceAdded",
319
+                $user_id
320
+            );
321
+
322
+        }
323
+        // add link to gradebook
324
+        if ($link_to_gradebook && !empty($this->category_id)) {
325
+            $description = '';
326 326
             $link_info = GradebookUtils::is_resource_in_course_gradebook(
327 327
                 $course_code,
328 328
                 7,
329 329
                 $last_id,
330 330
                 $session_id
331 331
             );
332
-			$link_id = $link_info->getId();
333
-			if (!$link_info) {
334
-				GradebookUtils::add_resource_to_course_gradebook(
335
-					$this->category_id,
336
-					$course_code,
337
-					7,
338
-					$last_id,
339
-					$title_gradebook,
340
-					$weight_calification,
341
-					$value_calification,
342
-					$description,
343
-					1,
344
-					$session_id
345
-				);
346
-			} else {
332
+            $link_id = $link_info->getId();
333
+            if (!$link_info) {
334
+                GradebookUtils::add_resource_to_course_gradebook(
335
+                    $this->category_id,
336
+                    $course_code,
337
+                    7,
338
+                    $last_id,
339
+                    $title_gradebook,
340
+                    $weight_calification,
341
+                    $value_calification,
342
+                    $description,
343
+                    1,
344
+                    $session_id
345
+                );
346
+            } else {
347 347
                 $gradebookLink = $em->find('ChamiloCoreBundle:GradebookLink', $link_id);
348 348
                 $gradebookLink->setWeight($weight_calification);
349 349
 
350 350
                 $em->persist($gradebookLink);
351 351
                 $em-flush();
352
-			}
353
-		}
354
-		return $last_id;
355
-	}
356
-
357
-	/**
358
-	 * edit attendances inside table
359
-	 * @param 	int	   attendance id
360
-	 * @param  	bool   true for adding link in gradebook or false otherwise (optional)
361
-	 * @return 	int    last id
362
-	 */
363
-	public function attendance_edit($attendance_id, $link_to_gradebook = false)
364
-	{
365
-		$_course = api_get_course_info();
366
-		$tbl_attendance = Database:: get_course_table(TABLE_ATTENDANCE);
352
+            }
353
+        }
354
+        return $last_id;
355
+    }
356
+
357
+    /**
358
+     * edit attendances inside table
359
+     * @param 	int	   attendance id
360
+     * @param  	bool   true for adding link in gradebook or false otherwise (optional)
361
+     * @return 	int    last id
362
+     */
363
+    public function attendance_edit($attendance_id, $link_to_gradebook = false)
364
+    {
365
+        $_course = api_get_course_info();
366
+        $tbl_attendance = Database:: get_course_table(TABLE_ATTENDANCE);
367 367
 
368 368
         $em = Database::getManager();
369 369
 
370
-		$session_id = api_get_session_id();
371
-		$user_id = api_get_user_id();
372
-		$attendance_id = intval($attendance_id);
373
-		$course_code = $_course['code'];
374
-		$course_id = $_course['real_id'];
375
-		$title_gradebook = $this->attendance_qualify_title;
376
-		$value_calification = 0;
377
-		$weight_calification = floatval($this->attendance_weight);
378
-
379
-		if (!empty($attendance_id)) {
380
-
381
-			$params = [
382
-				'name' => $this->name,
383
-				'description' => $this->description,
384
-				'attendance_qualify_title' => $title_gradebook,
385
-				'attendance_weight' => $weight_calification
386
-			];
387
-			Database::update(
388
-				$tbl_attendance,
389
-				$params,
390
-				['c_id = ? AND id = ?' => [$course_id, $attendance_id]]
391
-			);
392
-
393
-			api_item_property_update(
394
-				$_course,
395
-				TOOL_ATTENDANCE,
396
-				$attendance_id,
397
-				"AttendanceUpdated",
398
-				$user_id
399
-			);
400
-
401
-			// add link to gradebook
402
-			if ($link_to_gradebook && !empty($this->category_id)) {
403
-				$description = '';
404
-				$link = GradebookUtils::is_resource_in_course_gradebook(
405
-					$course_code,
406
-					7,
407
-					$attendance_id,
408
-					$session_id
409
-				);
410
-				if (!$link) {
411
-					GradebookUtils::add_resource_to_course_gradebook(
412
-						$this->category_id,
413
-						$course_code,
414
-						7,
415
-						$attendance_id,
416
-						$title_gradebook,
417
-						$weight_calification,
418
-						$value_calification,
419
-						$description,
420
-						1,
421
-						$session_id
422
-					);
423
-				} else {
370
+        $session_id = api_get_session_id();
371
+        $user_id = api_get_user_id();
372
+        $attendance_id = intval($attendance_id);
373
+        $course_code = $_course['code'];
374
+        $course_id = $_course['real_id'];
375
+        $title_gradebook = $this->attendance_qualify_title;
376
+        $value_calification = 0;
377
+        $weight_calification = floatval($this->attendance_weight);
378
+
379
+        if (!empty($attendance_id)) {
380
+
381
+            $params = [
382
+                'name' => $this->name,
383
+                'description' => $this->description,
384
+                'attendance_qualify_title' => $title_gradebook,
385
+                'attendance_weight' => $weight_calification
386
+            ];
387
+            Database::update(
388
+                $tbl_attendance,
389
+                $params,
390
+                ['c_id = ? AND id = ?' => [$course_id, $attendance_id]]
391
+            );
392
+
393
+            api_item_property_update(
394
+                $_course,
395
+                TOOL_ATTENDANCE,
396
+                $attendance_id,
397
+                "AttendanceUpdated",
398
+                $user_id
399
+            );
400
+
401
+            // add link to gradebook
402
+            if ($link_to_gradebook && !empty($this->category_id)) {
403
+                $description = '';
404
+                $link = GradebookUtils::is_resource_in_course_gradebook(
405
+                    $course_code,
406
+                    7,
407
+                    $attendance_id,
408
+                    $session_id
409
+                );
410
+                if (!$link) {
411
+                    GradebookUtils::add_resource_to_course_gradebook(
412
+                        $this->category_id,
413
+                        $course_code,
414
+                        7,
415
+                        $attendance_id,
416
+                        $title_gradebook,
417
+                        $weight_calification,
418
+                        $value_calification,
419
+                        $description,
420
+                        1,
421
+                        $session_id
422
+                    );
423
+                } else {
424 424
                     $gradebookLink = $em->find('ChamiloCoreBundle:GradebookLink', $this->getId());
425 425
                     $gradebookLink->setWeight($weight_calification);
426 426
 
427 427
                     $em->persist($gradebookLink);
428 428
                     $em->flush();
429
-				}
430
-			}
431
-
432
-			return $attendance_id;
433
-		}
434
-
435
-		return null;
436
-	}
437
-
438
-	/**
439
-	 * Restore attendance
440
-	 * @param 	int|array	   one or many attendances id
441
-	 * @return 	int    		   affected rows
442
-	 */
443
-	public function attendance_restore($attendance_id)
444
-	{
445
-		$_course = api_get_course_info();
446
-		$tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
447
-		$user_id = api_get_user_id();
448
-		$course_id = $_course['real_id'];
449
-		if (is_array($attendance_id)) {
450
-			foreach ($attendance_id as $id) {
451
-				$id	= intval($id);
452
-				$sql = "UPDATE $tbl_attendance SET active = 1
429
+                }
430
+            }
431
+
432
+            return $attendance_id;
433
+        }
434
+
435
+        return null;
436
+    }
437
+
438
+    /**
439
+     * Restore attendance
440
+     * @param 	int|array	   one or many attendances id
441
+     * @return 	int    		   affected rows
442
+     */
443
+    public function attendance_restore($attendance_id)
444
+    {
445
+        $_course = api_get_course_info();
446
+        $tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
447
+        $user_id = api_get_user_id();
448
+        $course_id = $_course['real_id'];
449
+        if (is_array($attendance_id)) {
450
+            foreach ($attendance_id as $id) {
451
+                $id	= intval($id);
452
+                $sql = "UPDATE $tbl_attendance SET active = 1
453 453
 						WHERE c_id = $course_id AND id = '$id'";
454
-				$result = Database::query($sql);
455
-				$affected_rows = Database::affected_rows($result);
456
-				if (!empty($affected_rows)) {
457
-					// update row item property table
454
+                $result = Database::query($sql);
455
+                $affected_rows = Database::affected_rows($result);
456
+                if (!empty($affected_rows)) {
457
+                    // update row item property table
458 458
                     api_item_property_update(
459 459
                         $_course,
460 460
                         TOOL_ATTENDANCE,
@@ -462,16 +462,16 @@  discard block
 block discarded – undo
462 462
                         "restore",
463 463
                         $user_id
464 464
                     );
465
-				}
466
-			}
467
-		} else  {
468
-			$attendance_id	= intval($attendance_id);
469
-			$sql = "UPDATE $tbl_attendance SET active = 1
465
+                }
466
+            }
467
+        } else  {
468
+            $attendance_id	= intval($attendance_id);
469
+            $sql = "UPDATE $tbl_attendance SET active = 1
470 470
 					WHERE c_id = $course_id AND id = '$attendance_id'";
471
-			$result = Database::query($sql);
472
-			$affected_rows = Database::affected_rows($result);
473
-			if (!empty($affected_rows)) {
474
-				// update row item property table
471
+            $result = Database::query($sql);
472
+            $affected_rows = Database::affected_rows($result);
473
+            if (!empty($affected_rows)) {
474
+                // update row item property table
475 475
                 api_item_property_update(
476 476
                     $_course,
477 477
                     TOOL_ATTENDANCE,
@@ -479,33 +479,33 @@  discard block
 block discarded – undo
479 479
                     "restore",
480 480
                     $user_id
481 481
                 );
482
-			}
483
-		}
484
-
485
-		return $affected_rows;
486
-	}
487
-
488
-	/**
489
-	 * Delete attendances
490
-	 * @param 	int|array	$attendance_id   one or many attendances id
491
-	 * @return 	int    		   affected rows
492
-	 */
493
-	public function attendance_delete($attendance_id)
494
-	{
495
-		$_course = api_get_course_info();
496
-		$tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
482
+            }
483
+        }
484
+
485
+        return $affected_rows;
486
+    }
487
+
488
+    /**
489
+     * Delete attendances
490
+     * @param 	int|array	$attendance_id   one or many attendances id
491
+     * @return 	int    		   affected rows
492
+     */
493
+    public function attendance_delete($attendance_id)
494
+    {
495
+        $_course = api_get_course_info();
496
+        $tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
497 497
         $user_id = api_get_user_id();
498 498
         $course_id = $_course['real_id'];
499 499
 
500
-		if (is_array($attendance_id)) {
501
-			foreach ($attendance_id as $id) {
502
-				$id	= intval($id);
503
-				$sql = "UPDATE $tbl_attendance SET active = 2
500
+        if (is_array($attendance_id)) {
501
+            foreach ($attendance_id as $id) {
502
+                $id	= intval($id);
503
+                $sql = "UPDATE $tbl_attendance SET active = 2
504 504
 						WHERE c_id = $course_id AND id = '$id'";
505
-				$result = Database::query($sql);
506
-				$affected_rows = Database::affected_rows($result);
507
-				if (!empty($affected_rows)) {
508
-					// update row item property table
505
+                $result = Database::query($sql);
506
+                $affected_rows = Database::affected_rows($result);
507
+                if (!empty($affected_rows)) {
508
+                    // update row item property table
509 509
                     api_item_property_update(
510 510
                         $_course,
511 511
                         TOOL_ATTENDANCE,
@@ -513,142 +513,142 @@  discard block
 block discarded – undo
513 513
                         "delete",
514 514
                         $user_id
515 515
                     );
516
-				}
517
-			}
518
-		} else  {
519
-			$attendance_id= intval($attendance_id);
520
-			$sql = "UPDATE $tbl_attendance SET active = 2
516
+                }
517
+            }
518
+        } else  {
519
+            $attendance_id= intval($attendance_id);
520
+            $sql = "UPDATE $tbl_attendance SET active = 2
521 521
 					WHERE c_id = $course_id AND id = '$attendance_id'";
522 522
 
523
-			$result = Database::query($sql);
524
-			$affected_rows = Database::affected_rows($result);
525
-			if (!empty($affected_rows)) {
526
-				// update row item property table
527
-				api_item_property_update(
528
-					$_course,
529
-					TOOL_ATTENDANCE,
530
-					$attendance_id,
531
-					"delete",
532
-					$user_id
533
-				);
534
-			}
535
-		}
536
-
537
-		return $affected_rows;
538
-	}
539
-
540
-	/**
541
-	 * Changes visibility
542
-	 * @param int|array	$attendanceId   one or many attendances id
543
-	 * @param int status
523
+            $result = Database::query($sql);
524
+            $affected_rows = Database::affected_rows($result);
525
+            if (!empty($affected_rows)) {
526
+                // update row item property table
527
+                api_item_property_update(
528
+                    $_course,
529
+                    TOOL_ATTENDANCE,
530
+                    $attendance_id,
531
+                    "delete",
532
+                    $user_id
533
+                );
534
+            }
535
+        }
536
+
537
+        return $affected_rows;
538
+    }
539
+
540
+    /**
541
+     * Changes visibility
542
+     * @param int|array	$attendanceId   one or many attendances id
543
+     * @param int status
544 544
      *
545
-	 * @return 	int affected rows
546
-	 */
547
-	public function changeVisibility($attendanceId, $status = 1)
548
-	{
549
-		$_course = api_get_course_info();
550
-		$tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
551
-		$user_id = api_get_user_id();
552
-		$course_id = $_course['real_id'];
553
-		$status = intval($status);
554
-
555
-		$action = 'visible';
556
-		if ($status == 0) {
557
-			$action = 'invisible';
558
-		}
559
-
560
-		if (is_array($attendanceId)) {
561
-			foreach ($attendanceId as $id) {
562
-				$id	= intval($id);
563
-				$sql = "UPDATE $tbl_attendance SET active = $status
545
+     * @return 	int affected rows
546
+     */
547
+    public function changeVisibility($attendanceId, $status = 1)
548
+    {
549
+        $_course = api_get_course_info();
550
+        $tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
551
+        $user_id = api_get_user_id();
552
+        $course_id = $_course['real_id'];
553
+        $status = intval($status);
554
+
555
+        $action = 'visible';
556
+        if ($status == 0) {
557
+            $action = 'invisible';
558
+        }
559
+
560
+        if (is_array($attendanceId)) {
561
+            foreach ($attendanceId as $id) {
562
+                $id	= intval($id);
563
+                $sql = "UPDATE $tbl_attendance SET active = $status
564 564
 						WHERE c_id = $course_id AND id = '$id'";
565
-				$result = Database::query($sql);
566
-				$affected_rows = Database::affected_rows($result);
567
-				if (!empty($affected_rows)) {
568
-					// update row item property table
569
-					api_item_property_update($_course, TOOL_ATTENDANCE, $id, $action, $user_id);
570
-				}
571
-			}
572
-		} else  {
573
-			$attendanceId	= intval($attendanceId);
574
-			$sql = "UPDATE $tbl_attendance SET active = $status
565
+                $result = Database::query($sql);
566
+                $affected_rows = Database::affected_rows($result);
567
+                if (!empty($affected_rows)) {
568
+                    // update row item property table
569
+                    api_item_property_update($_course, TOOL_ATTENDANCE, $id, $action, $user_id);
570
+                }
571
+            }
572
+        } else  {
573
+            $attendanceId	= intval($attendanceId);
574
+            $sql = "UPDATE $tbl_attendance SET active = $status
575 575
 					WHERE c_id = $course_id AND id = '$attendanceId'";
576
-			$result = Database::query($sql);
577
-			$affected_rows = Database::affected_rows($result);
578
-			if (!empty($affected_rows)) {
579
-				// update row item property table
580
-				api_item_property_update(
581
-					$_course,
582
-					TOOL_ATTENDANCE,
583
-					$attendanceId,
584
-					$action,
585
-					$user_id
586
-				);
587
-			}
588
-		}
589
-
590
-		return $affected_rows;
591
-	}
592
-
593
-	/**
594
-	 * Lock or unlock an attendance
595
-	 * @param   int     attendance id
596
-	 * @param   bool    True to lock or false otherwise
597
-	 */
598
-	public function lock_attendance($attendance_id, $lock = true)
599
-	{
600
-		$tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
601
-		$course_id = api_get_course_int_id();
602
-		$attendance_id = intval($attendance_id);
603
-		$locked = ($lock)?1:0;
604
-		$upd = "UPDATE $tbl_attendance SET locked = $locked
576
+            $result = Database::query($sql);
577
+            $affected_rows = Database::affected_rows($result);
578
+            if (!empty($affected_rows)) {
579
+                // update row item property table
580
+                api_item_property_update(
581
+                    $_course,
582
+                    TOOL_ATTENDANCE,
583
+                    $attendanceId,
584
+                    $action,
585
+                    $user_id
586
+                );
587
+            }
588
+        }
589
+
590
+        return $affected_rows;
591
+    }
592
+
593
+    /**
594
+     * Lock or unlock an attendance
595
+     * @param   int     attendance id
596
+     * @param   bool    True to lock or false otherwise
597
+     */
598
+    public function lock_attendance($attendance_id, $lock = true)
599
+    {
600
+        $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
601
+        $course_id = api_get_course_int_id();
602
+        $attendance_id = intval($attendance_id);
603
+        $locked = ($lock)?1:0;
604
+        $upd = "UPDATE $tbl_attendance SET locked = $locked
605 605
 				WHERE c_id = $course_id AND id = $attendance_id";
606
-		$result = Database::query($upd);
607
-		$affected_rows = Database::affected_rows($result);
608
-		if ($affected_rows && $lock) {
609
-			// Save attendance sheet log
610
-			$lastedit_date = api_get_utc_datetime();
611
-			$lastedit_type = self::LOCKED_ATTENDANCE_LOG_TYPE;
612
-			$lastedit_user_id = api_get_user_id();
613
-			$this->save_attendance_sheet_log(
614
-				$attendance_id,
615
-				$lastedit_date,
616
-				$lastedit_type,
617
-				$lastedit_user_id
618
-			);
619
-		}
620
-		return $affected_rows;
621
-	}
622
-
623
-	/**
624
-	 * Get registered users inside current course
625
-	 * @param 	int	   $attendance_id attendance id for showing attendance result field (optional)
626
-	 * @param int $groupId
627
-	 * @return 	array  users data
628
-	 */
629
-	public function get_users_rel_course($attendance_id = 0, $groupId = null)
630
-	{
631
-		$current_session_id = api_get_session_id();
632
-		$current_course_id  = api_get_course_id();
633
-		$currentCourseIntId = api_get_course_int_id();
634
-
635
-		$studentInGroup = array();
636
-
637
-		if (!empty($current_session_id)) {
638
-			$a_course_users = CourseManager:: get_user_list_from_course_code(
639
-				$current_course_id,
640
-				$current_session_id,
641
-				'',
642
-				'lastname'
643
-			);
644
-		} else {
645
-			$a_course_users = CourseManager:: get_user_list_from_course_code(
646
-				$current_course_id,
647
-				0,
648
-				'',
649
-				'lastname'
650
-			);
651
-		}
606
+        $result = Database::query($upd);
607
+        $affected_rows = Database::affected_rows($result);
608
+        if ($affected_rows && $lock) {
609
+            // Save attendance sheet log
610
+            $lastedit_date = api_get_utc_datetime();
611
+            $lastedit_type = self::LOCKED_ATTENDANCE_LOG_TYPE;
612
+            $lastedit_user_id = api_get_user_id();
613
+            $this->save_attendance_sheet_log(
614
+                $attendance_id,
615
+                $lastedit_date,
616
+                $lastedit_type,
617
+                $lastedit_user_id
618
+            );
619
+        }
620
+        return $affected_rows;
621
+    }
622
+
623
+    /**
624
+     * Get registered users inside current course
625
+     * @param 	int	   $attendance_id attendance id for showing attendance result field (optional)
626
+     * @param int $groupId
627
+     * @return 	array  users data
628
+     */
629
+    public function get_users_rel_course($attendance_id = 0, $groupId = null)
630
+    {
631
+        $current_session_id = api_get_session_id();
632
+        $current_course_id  = api_get_course_id();
633
+        $currentCourseIntId = api_get_course_int_id();
634
+
635
+        $studentInGroup = array();
636
+
637
+        if (!empty($current_session_id)) {
638
+            $a_course_users = CourseManager:: get_user_list_from_course_code(
639
+                $current_course_id,
640
+                $current_session_id,
641
+                '',
642
+                'lastname'
643
+            );
644
+        } else {
645
+            $a_course_users = CourseManager:: get_user_list_from_course_code(
646
+                $current_course_id,
647
+                0,
648
+                '',
649
+                'lastname'
650
+            );
651
+        }
652 652
 
653 653
         if (!empty($groupId)) {
654 654
             $groupInfo = GroupManager::get_group_properties($groupId);
@@ -660,192 +660,192 @@  discard block
 block discarded – undo
660 660
             }
661 661
         }
662 662
 
663
-		// get registered users inside current course
664
-		$a_users = array();
665
-		foreach ($a_course_users as $key => $user_data) {
666
-			$value = array();
667
-			$uid = $user_data['user_id'];
668
-			$userInfo = api_get_user_info($uid);
669
-
670
-			$status = $user_data['status'];
671
-
672
-			if (!empty($groupId)) {
673
-				if (!isset($studentInGroup[$uid])) {
674
-					continue;
675
-				}
676
-			}
677
-
678
-			$user_status_in_session = null;
679
-			$user_status_in_course  = null;
680
-
681
-			if (api_get_session_id()) {
682
-				$user_status_in_session = SessionManager::get_user_status_in_course_session(
683
-					$uid,
684
-					$currentCourseIntId,
685
-					$current_session_id
686
-				);
687
-			} else {
688
-				$user_status_in_course = CourseManager::get_user_in_course_status(
689
-					$uid,
690
-					$current_course_id
691
-				);
692
-			}
693
-
694
-			// Not taking into account DRH or COURSEMANAGER
695
-			if ($uid <= 1 ||
696
-				$status == DRH ||
697
-				$user_status_in_course == COURSEMANAGER ||
698
-				$user_status_in_session == 2
699
-			) {
700
-				continue;
701
-			}
702
-
703
-			if (!empty($attendance_id)) {
704
-				$user_faults = $this->get_faults_of_user($uid, $attendance_id, $groupId);
705
-				$value['attendance_result'] = $user_faults['faults'].'/'.$user_faults['total'].' ('.$user_faults['faults_porcent'].'%)';
706
-				$value['result_color_bar'] 	= $user_faults['color_bar'];
707
-			}
663
+        // get registered users inside current course
664
+        $a_users = array();
665
+        foreach ($a_course_users as $key => $user_data) {
666
+            $value = array();
667
+            $uid = $user_data['user_id'];
668
+            $userInfo = api_get_user_info($uid);
669
+
670
+            $status = $user_data['status'];
671
+
672
+            if (!empty($groupId)) {
673
+                if (!isset($studentInGroup[$uid])) {
674
+                    continue;
675
+                }
676
+            }
677
+
678
+            $user_status_in_session = null;
679
+            $user_status_in_course  = null;
680
+
681
+            if (api_get_session_id()) {
682
+                $user_status_in_session = SessionManager::get_user_status_in_course_session(
683
+                    $uid,
684
+                    $currentCourseIntId,
685
+                    $current_session_id
686
+                );
687
+            } else {
688
+                $user_status_in_course = CourseManager::get_user_in_course_status(
689
+                    $uid,
690
+                    $current_course_id
691
+                );
692
+            }
693
+
694
+            // Not taking into account DRH or COURSEMANAGER
695
+            if ($uid <= 1 ||
696
+                $status == DRH ||
697
+                $user_status_in_course == COURSEMANAGER ||
698
+                $user_status_in_session == 2
699
+            ) {
700
+                continue;
701
+            }
702
+
703
+            if (!empty($attendance_id)) {
704
+                $user_faults = $this->get_faults_of_user($uid, $attendance_id, $groupId);
705
+                $value['attendance_result'] = $user_faults['faults'].'/'.$user_faults['total'].' ('.$user_faults['faults_porcent'].'%)';
706
+                $value['result_color_bar'] 	= $user_faults['color_bar'];
707
+            }
708 708
 
709 709
             $photo = Display::img($userInfo['avatar_small'], $userInfo['complete_name'], [], false);
710 710
 
711
-			$value['photo'] = $photo;
712
-			$value['firstname'] = $user_data['firstname'];
713
-			$value['lastname'] = $user_data['lastname'];
714
-			$value['username'] = $user_data['username'];
715
-			$value['user_id'] = $uid;
716
-
717
-			//Sending only 5 items in the array instead of 60
718
-			$a_users[$key] = $value;
719
-		}
720
-
721
-		return $a_users;
722
-	}
723
-
724
-	/**
725
-	 * add attendances sheet inside table
726
-	 * @param 	int	   $calendar_id attendance calendar id
727
-	 * @param  	array  $users_present present users during current class
728
-	 * @param	int	   $attendance_id
729
-	 * @return 	int    affected rows
730
-	 */
731
-	public function attendance_sheet_add($calendar_id, $users_present, $attendance_id)
732
-	{
733
-		$tbl_attendance_sheet 	= Database::get_course_table(TABLE_ATTENDANCE_SHEET);
734
-		$tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
735
-
736
-		$calendar_id = intval($calendar_id);
737
-		$attendance_id = intval($attendance_id);
738
-		$users = $this->get_users_rel_course();
739
-		$course_id = api_get_course_int_id();
740
-
741
-		$user_ids = array_keys($users);
742
-		$users_absent = array_diff($user_ids,$users_present);
743
-		$affected_rows = 0;
744
-
745
-		// get last edit type
746
-		$calendar_data = $this->get_attendance_calendar_by_id($calendar_id);
747
-		$lastedit_type = self::DONE_ATTENDANCE_LOG_TYPE;
748
-		if ($calendar_data['done_attendance']) {
749
-			$lastedit_type = self::UPDATED_ATTENDANCE_LOG_TYPE;
750
-		}
751
-
752
-		// save users present in class
753
-		foreach ($users_present as $user_present) {
754
-			$uid = intval($user_present);
755
-			// check if user already was registered with the $calendar_id
756
-			$sql = "SELECT user_id FROM $tbl_attendance_sheet
711
+            $value['photo'] = $photo;
712
+            $value['firstname'] = $user_data['firstname'];
713
+            $value['lastname'] = $user_data['lastname'];
714
+            $value['username'] = $user_data['username'];
715
+            $value['user_id'] = $uid;
716
+
717
+            //Sending only 5 items in the array instead of 60
718
+            $a_users[$key] = $value;
719
+        }
720
+
721
+        return $a_users;
722
+    }
723
+
724
+    /**
725
+     * add attendances sheet inside table
726
+     * @param 	int	   $calendar_id attendance calendar id
727
+     * @param  	array  $users_present present users during current class
728
+     * @param	int	   $attendance_id
729
+     * @return 	int    affected rows
730
+     */
731
+    public function attendance_sheet_add($calendar_id, $users_present, $attendance_id)
732
+    {
733
+        $tbl_attendance_sheet 	= Database::get_course_table(TABLE_ATTENDANCE_SHEET);
734
+        $tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
735
+
736
+        $calendar_id = intval($calendar_id);
737
+        $attendance_id = intval($attendance_id);
738
+        $users = $this->get_users_rel_course();
739
+        $course_id = api_get_course_int_id();
740
+
741
+        $user_ids = array_keys($users);
742
+        $users_absent = array_diff($user_ids,$users_present);
743
+        $affected_rows = 0;
744
+
745
+        // get last edit type
746
+        $calendar_data = $this->get_attendance_calendar_by_id($calendar_id);
747
+        $lastedit_type = self::DONE_ATTENDANCE_LOG_TYPE;
748
+        if ($calendar_data['done_attendance']) {
749
+            $lastedit_type = self::UPDATED_ATTENDANCE_LOG_TYPE;
750
+        }
751
+
752
+        // save users present in class
753
+        foreach ($users_present as $user_present) {
754
+            $uid = intval($user_present);
755
+            // check if user already was registered with the $calendar_id
756
+            $sql = "SELECT user_id FROM $tbl_attendance_sheet
757 757
 					WHERE c_id = $course_id AND user_id='$uid' AND attendance_calendar_id = '$calendar_id'";
758
-			$rs  = Database::query($sql);
759
-			if (Database::num_rows($rs) == 0) {
760
-				$sql = "INSERT INTO $tbl_attendance_sheet SET
758
+            $rs  = Database::query($sql);
759
+            if (Database::num_rows($rs) == 0) {
760
+                $sql = "INSERT INTO $tbl_attendance_sheet SET
761 761
 						c_id					= $course_id,
762 762
 						user_id 				= '$uid',
763 763
 						attendance_calendar_id 	= '$calendar_id',
764 764
 						presence 				= 1";
765
-				$result = Database::query($sql);
765
+                $result = Database::query($sql);
766 766
 
767
-				$affected_rows += Database::affected_rows($result);
768
-			} else {
769
-				$sql = "UPDATE $tbl_attendance_sheet SET presence = 1
767
+                $affected_rows += Database::affected_rows($result);
768
+            } else {
769
+                $sql = "UPDATE $tbl_attendance_sheet SET presence = 1
770 770
 						WHERE
771 771
 							c_id = $course_id AND
772 772
 							user_id ='$uid' AND
773 773
 							attendance_calendar_id = '$calendar_id'
774 774
 						";
775
-				$result = Database::query($sql);
776
-				$affected_rows += Database::affected_rows($result);
777
-			}
778
-		}
779
-
780
-		// save users absent in class
781
-		foreach ($users_absent as $user_absent) {
782
-			$uid = intval($user_absent);
783
-			// check if user already was registered with the $calendar_id
784
-			$sql = "SELECT user_id FROM $tbl_attendance_sheet
775
+                $result = Database::query($sql);
776
+                $affected_rows += Database::affected_rows($result);
777
+            }
778
+        }
779
+
780
+        // save users absent in class
781
+        foreach ($users_absent as $user_absent) {
782
+            $uid = intval($user_absent);
783
+            // check if user already was registered with the $calendar_id
784
+            $sql = "SELECT user_id FROM $tbl_attendance_sheet
785 785
 					WHERE c_id = $course_id AND user_id='$uid' AND attendance_calendar_id = '$calendar_id'";
786
-			$rs  = Database::query($sql);
787
-			if (Database::num_rows($rs) == 0) {
788
-				$sql = "INSERT INTO $tbl_attendance_sheet SET
786
+            $rs  = Database::query($sql);
787
+            if (Database::num_rows($rs) == 0) {
788
+                $sql = "INSERT INTO $tbl_attendance_sheet SET
789 789
 						c_id = $course_id,
790 790
 						user_id ='$uid',
791 791
 						attendance_calendar_id = '$calendar_id',
792 792
 						presence = 0";
793
-				$result = Database::query($sql);
793
+                $result = Database::query($sql);
794 794
 
795
-				Database::insert_id();
795
+                Database::insert_id();
796 796
 
797
-				$affected_rows += Database::affected_rows($result);
798
-			} else {
799
-				$sql = "UPDATE $tbl_attendance_sheet SET presence = 0
797
+                $affected_rows += Database::affected_rows($result);
798
+            } else {
799
+                $sql = "UPDATE $tbl_attendance_sheet SET presence = 0
800 800
 						WHERE
801 801
 							c_id = $course_id AND
802 802
 							user_id ='$uid' AND
803 803
 							attendance_calendar_id = '$calendar_id'";
804
-				$result = Database::query($sql);
805
-				$affected_rows += Database::affected_rows($result);
806
-			}
807
-		}
804
+                $result = Database::query($sql);
805
+                $affected_rows += Database::affected_rows($result);
806
+            }
807
+        }
808 808
 
809
-		// update done_attendance inside attendance calendar table
810
-		$sql = "UPDATE $tbl_attendance_calendar SET done_attendance = 1
809
+        // update done_attendance inside attendance calendar table
810
+        $sql = "UPDATE $tbl_attendance_calendar SET done_attendance = 1
811 811
 				WHERE  c_id = $course_id AND id = '$calendar_id'";
812
-		Database::query($sql);
813
-
814
-		// save users' results
815
-		$this->update_users_results($user_ids, $attendance_id);
816
-
817
-		if ($affected_rows) {
818
-			//save attendance sheet log
819
-			$lastedit_date = api_get_utc_datetime();
820
-			$lastedit_user_id = api_get_user_id();
821
-			$calendar_date_value = $calendar_data['date_time'];
822
-			$this->save_attendance_sheet_log(
823
-				$attendance_id,
824
-				$lastedit_date,
825
-				$lastedit_type,
826
-				$lastedit_user_id,
827
-				$calendar_date_value
828
-			);
829
-		}
830
-
831
-		return $affected_rows;
832
-	}
833
-
834
-	/**
835
-	 * update users' attendance results
836
-	 * @param 	array  $user_ids registered users inside current course
837
-	 * @param	int	   $attendance_id
838
-	 * @return 	void
839
-	 */
840
-	public function update_users_results($user_ids, $attendance_id)
841
-	{
842
-		$tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
843
-		$tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
844
-		$tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
845
-		$course_id = api_get_course_int_id();
846
-
847
-		$attendance_id = intval($attendance_id);
848
-		// fill results about presence of students
812
+        Database::query($sql);
813
+
814
+        // save users' results
815
+        $this->update_users_results($user_ids, $attendance_id);
816
+
817
+        if ($affected_rows) {
818
+            //save attendance sheet log
819
+            $lastedit_date = api_get_utc_datetime();
820
+            $lastedit_user_id = api_get_user_id();
821
+            $calendar_date_value = $calendar_data['date_time'];
822
+            $this->save_attendance_sheet_log(
823
+                $attendance_id,
824
+                $lastedit_date,
825
+                $lastedit_type,
826
+                $lastedit_user_id,
827
+                $calendar_date_value
828
+            );
829
+        }
830
+
831
+        return $affected_rows;
832
+    }
833
+
834
+    /**
835
+     * update users' attendance results
836
+     * @param 	array  $user_ids registered users inside current course
837
+     * @param	int	   $attendance_id
838
+     * @return 	void
839
+     */
840
+    public function update_users_results($user_ids, $attendance_id)
841
+    {
842
+        $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
843
+        $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
844
+        $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
845
+        $course_id = api_get_course_int_id();
846
+
847
+        $attendance_id = intval($attendance_id);
848
+        // fill results about presence of students
849 849
         $attendance_calendar = $this->get_attendance_calendar(
850 850
             $attendance_id,
851 851
             'all',
@@ -853,82 +853,82 @@  discard block
 block discarded – undo
853 853
             null,
854 854
             true
855 855
         );
856
-		$calendar_ids = array();
857
-		// get all dates from calendar by current attendance
858
-		foreach ($attendance_calendar as $cal) {
859
-			$calendar_ids[] = $cal['id'];
860
-		}
861
-
862
-		// get count of presences by users inside current attendance and save like results
863
-		if (count($user_ids) > 0) {
864
-			foreach ($user_ids as $uid) {
865
-				$count_presences = 0;
866
-				if (count($calendar_ids) > 0) {
867
-					$sql = "SELECT count(presence) as count_presences
856
+        $calendar_ids = array();
857
+        // get all dates from calendar by current attendance
858
+        foreach ($attendance_calendar as $cal) {
859
+            $calendar_ids[] = $cal['id'];
860
+        }
861
+
862
+        // get count of presences by users inside current attendance and save like results
863
+        if (count($user_ids) > 0) {
864
+            foreach ($user_ids as $uid) {
865
+                $count_presences = 0;
866
+                if (count($calendar_ids) > 0) {
867
+                    $sql = "SELECT count(presence) as count_presences
868 868
 							FROM $tbl_attendance_sheet
869 869
 					        WHERE
870 870
 					        	c_id = $course_id AND
871 871
 					        	user_id = '$uid' AND
872 872
 					        	attendance_calendar_id IN (".implode(',', $calendar_ids).") AND
873 873
 					        	presence = 1";
874
-					$rs_count  = Database::query($sql);
875
-					$row_count = Database::fetch_array($rs_count);
876
-					$count_presences = $row_count['count_presences'];
877
-				}
874
+                    $rs_count  = Database::query($sql);
875
+                    $row_count = Database::fetch_array($rs_count);
876
+                    $count_presences = $row_count['count_presences'];
877
+                }
878 878
 
879
-				// save results
880
-				$sql = "SELECT id FROM $tbl_attendance_result
879
+                // save results
880
+                $sql = "SELECT id FROM $tbl_attendance_result
881 881
 						WHERE
882 882
 							c_id = $course_id AND
883 883
 							user_id = '$uid' AND
884 884
 							attendance_id = '$attendance_id' ";
885
-				$rs_check_result = Database::query($sql);
885
+                $rs_check_result = Database::query($sql);
886 886
 
887
-				if (Database::num_rows($rs_check_result) > 0) {
888
-					// update result
889
-					$sql = "UPDATE $tbl_attendance_result SET
887
+                if (Database::num_rows($rs_check_result) > 0) {
888
+                    // update result
889
+                    $sql = "UPDATE $tbl_attendance_result SET
890 890
 							score = '$count_presences'
891 891
 							WHERE
892 892
 								c_id = $course_id AND
893 893
 								user_id='$uid' AND
894 894
 								attendance_id='$attendance_id'";
895
-					Database::query($sql);
896
-				} else {
897
-					// insert new result
898
-					$sql = "INSERT INTO $tbl_attendance_result SET
895
+                    Database::query($sql);
896
+                } else {
897
+                    // insert new result
898
+                    $sql = "INSERT INTO $tbl_attendance_result SET
899 899
 							c_id = $course_id ,
900 900
 							user_id			= '$uid',
901 901
 							attendance_id 	= '$attendance_id',
902 902
 							score			= '$count_presences'";
903
-					Database::query($sql);
903
+                    Database::query($sql);
904 904
 
905
-					$insertId = Database::insert_id();
905
+                    $insertId = Database::insert_id();
906 906
                     if ($insertId) {
907 907
                         $sql = "UPDATE $tbl_attendance_result SET id = iid WHERE iid = $insertId";
908 908
                         Database::query($sql);
909 909
                     }
910
-				}
911
-			}
912
-		}
910
+                }
911
+            }
912
+        }
913 913
 
914
-		// update attendance qualify max
915
-		$count_done_calendar = self::get_done_attendance_calendar($attendance_id);
914
+        // update attendance qualify max
915
+        $count_done_calendar = self::get_done_attendance_calendar($attendance_id);
916 916
 
917
-		$sql = "UPDATE $tbl_attendance SET
917
+        $sql = "UPDATE $tbl_attendance SET
918 918
 				attendance_qualify_max = '$count_done_calendar'
919 919
 				WHERE c_id = $course_id AND id = '$attendance_id'";
920
-		Database::query($sql);
921
-	}
922
-
923
-	/**
924
-	 * update attendance_sheet_log table, is used as history of an attendance sheet
925
-	 * @param   int     Attendance id
926
-	 * @param   string  Last edit datetime
927
-	 * @param   string  Event type ('locked_attendance', 'done_attendance_sheet' ...)
928
-	 * @param   int     Last edit user id
929
-	 * @param   string  Calendar datetime value (optional, when event type is 'done_attendance_sheet')
930
-	 * @return  int     Affected rows
931
-	 */
920
+        Database::query($sql);
921
+    }
922
+
923
+    /**
924
+     * update attendance_sheet_log table, is used as history of an attendance sheet
925
+     * @param   int     Attendance id
926
+     * @param   string  Last edit datetime
927
+     * @param   string  Event type ('locked_attendance', 'done_attendance_sheet' ...)
928
+     * @param   int     Last edit user id
929
+     * @param   string  Calendar datetime value (optional, when event type is 'done_attendance_sheet')
930
+     * @return  int     Affected rows
931
+     */
932 932
     public function save_attendance_sheet_log(
933 933
         $attendance_id,
934 934
         $lastedit_date,
@@ -936,22 +936,22 @@  discard block
 block discarded – undo
936 936
         $lastedit_user_id,
937 937
         $calendar_date_value = null
938 938
     ) {
939
-		$course_id = api_get_course_int_id();
939
+        $course_id = api_get_course_int_id();
940 940
 
941
-		// define table
942
-		$tbl_attendance_sheet_log = Database::get_course_table(TABLE_ATTENDANCE_SHEET_LOG);
941
+        // define table
942
+        $tbl_attendance_sheet_log = Database::get_course_table(TABLE_ATTENDANCE_SHEET_LOG);
943 943
 
944
-		// protect data
945
-		$attendance_id = intval($attendance_id);
946
-		$lastedit_user_id = intval($lastedit_user_id);
944
+        // protect data
945
+        $attendance_id = intval($attendance_id);
946
+        $lastedit_user_id = intval($lastedit_user_id);
947 947
 
948
-		if (isset($calendar_date_value)) {
949
-			$calendar_date_value = $calendar_date_value;
950
-		} else {
951
-			$calendar_date_value = '';
952
-		}
948
+        if (isset($calendar_date_value)) {
949
+            $calendar_date_value = $calendar_date_value;
950
+        } else {
951
+            $calendar_date_value = '';
952
+        }
953 953
 
954
-		// save data
954
+        // save data
955 955
         $params = [
956 956
             'c_id' => $course_id,
957 957
             'attendance_id' => $attendance_id,
@@ -960,228 +960,228 @@  discard block
 block discarded – undo
960 960
             'lastedit_user_id' => $lastedit_user_id,
961 961
             'calendar_date_value' => $calendar_date_value,
962 962
         ];
963
-		$insertId = Database::insert($tbl_attendance_sheet_log, $params);
963
+        $insertId = Database::insert($tbl_attendance_sheet_log, $params);
964 964
         if ($insertId) {
965 965
             $sql = "UPDATE $tbl_attendance_sheet_log SET id = iid WHERE iid = $insertId";
966 966
             Database::query($sql);
967 967
         }
968 968
 
969
-		return $insertId;
970
-	}
971
-
972
-	/**
973
-	 * Get number of done attendances inside current sheet
974
-	 * @param	int	   attendance id
975
-	 * @return 	int	   number of done attendances
976
-	 */
977
-	public static function get_done_attendance_calendar($attendance_id)
978
-	{
979
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
980
-		$attendance_id = intval($attendance_id);
981
-		$course_id = api_get_course_int_id();
982
-		$sql = "SELECT count(done_attendance) as count
969
+        return $insertId;
970
+    }
971
+
972
+    /**
973
+     * Get number of done attendances inside current sheet
974
+     * @param	int	   attendance id
975
+     * @return 	int	   number of done attendances
976
+     */
977
+    public static function get_done_attendance_calendar($attendance_id)
978
+    {
979
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
980
+        $attendance_id = intval($attendance_id);
981
+        $course_id = api_get_course_int_id();
982
+        $sql = "SELECT count(done_attendance) as count
983 983
                 FROM $tbl_attendance_calendar
984 984
                 WHERE
985 985
                     c_id = $course_id AND
986 986
                     attendance_id = '$attendance_id' AND
987 987
                     done_attendance = 1
988 988
                 ";
989
-		$rs  = Database::query($sql);
990
-		$row = Database::fetch_array($rs);
991
-		$count = $row['count'];
992
-
993
-		return $count;
994
-	}
995
-
996
-	/**
997
-	 * Get results of faults (absents) by user
998
-	 * @param int $user_id
999
-	 * @param int $attendance_id
1000
-	 * @param int $groupId
1001
-	 * @return 	array  results containing number of faults, total done attendance,
1002
-	 * percent of faults and color depend on result (red, orange)
1003
-	 */
1004
-	public function get_faults_of_user($user_id, $attendance_id, $groupId = null)
1005
-	{
989
+        $rs  = Database::query($sql);
990
+        $row = Database::fetch_array($rs);
991
+        $count = $row['count'];
992
+
993
+        return $count;
994
+    }
995
+
996
+    /**
997
+     * Get results of faults (absents) by user
998
+     * @param int $user_id
999
+     * @param int $attendance_id
1000
+     * @param int $groupId
1001
+     * @return 	array  results containing number of faults, total done attendance,
1002
+     * percent of faults and color depend on result (red, orange)
1003
+     */
1004
+    public function get_faults_of_user($user_id, $attendance_id, $groupId = null)
1005
+    {
1006 1006
         $user_id = intval($user_id);
1007 1007
         $attendance_id = intval($attendance_id);
1008
-		$results = array();
1009
-		$calendar_count = self::get_number_of_attendance_calendar($attendance_id, $groupId, NULL, $user_id);
1010
-		// $total_done_attendance 	= $attendance_data['attendance_qualify_max'];
1008
+        $results = array();
1009
+        $calendar_count = self::get_number_of_attendance_calendar($attendance_id, $groupId, NULL, $user_id);
1010
+        // $total_done_attendance 	= $attendance_data['attendance_qualify_max'];
1011 1011
         $total_done_attendance 	= self::get_number_of_attendance_calendar($attendance_id, $groupId, true, $user_id);
1012
-		$attendance_user_score  = $this->get_user_score($user_id, $attendance_id, $groupId);
1012
+        $attendance_user_score  = $this->get_user_score($user_id, $attendance_id, $groupId);
1013 1013
 
1014
-		//This is the main change of the BT#1381
1015
-		//$total_done_attendance = $calendar_count;
1014
+        //This is the main change of the BT#1381
1015
+        //$total_done_attendance = $calendar_count;
1016 1016
 
1017
-		// calculate results
1018
-		$faults = $total_done_attendance - $attendance_user_score;
1017
+        // calculate results
1018
+        $faults = $total_done_attendance - $attendance_user_score;
1019 1019
 
1020 1020
         if (empty($calendar_count)) {
1021 1021
             $faults = 0;
1022 1022
         }
1023 1023
 
1024 1024
         $faults = $faults > 0 ? $faults : 0;
1025
-		$faults_porcent = $calendar_count > 0 ?round(($faults*100)/$calendar_count,0):0;
1025
+        $faults_porcent = $calendar_count > 0 ?round(($faults*100)/$calendar_count,0):0;
1026 1026
         $results['faults'] = $faults;
1027 1027
         $results['total'] = $calendar_count;
1028 1028
         $results['faults_porcent'] = $faults_porcent;
1029
-		$color_bar = '';
1029
+        $color_bar = '';
1030 1030
 
1031 1031
         if ($faults_porcent > 25) {
1032 1032
             $color_bar = '#f28989';
1033
-		} else if ($faults_porcent > 10) {
1034
-			$color_bar = '#F90';
1035
-		}
1036
-		$results['color_bar'] = $color_bar;
1037
-
1038
-		return $results;
1039
-	}
1040
-
1041
-	/**
1042
-	 * Get results of faults average for all courses by user
1043
-	 * @param	int	   $user_id
1044
-	 * @return 	array  results containing number of faults, total done attendance,
1045
-	 * percentage of faults and color depend on result (red, orange)
1046
-	 */
1047
-	public function get_faults_average_inside_courses($user_id)
1048
-	{
1049
-		// get all courses of current user
1050
-		$courses = CourseManager::get_courses_list_by_user_id($user_id, true);
1051
-
1052
-		$user_id = intval($user_id);
1053
-		$results = array();
1054
-		$total_faults = $total_weight = $porcent = 0;
1055
-		foreach ($courses as $course) {
1056
-			//$course_code = $course['code'];
1057
-			//$course_info = api_get_course_info($course_code);
1058
-			$course_id = $course['real_id'];
1059
-			$tbl_attendance_result 	= Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1060
-
1061
-			$attendances_by_course = $this->get_attendances_list($course_id);
1062
-
1063
-			foreach ($attendances_by_course as $attendance) {
1064
-				// get total faults and total weight
1065
-				$total_done_attendance 	= $attendance['attendance_qualify_max'];
1066
-				$sql = "SELECT score
1033
+        } else if ($faults_porcent > 10) {
1034
+            $color_bar = '#F90';
1035
+        }
1036
+        $results['color_bar'] = $color_bar;
1037
+
1038
+        return $results;
1039
+    }
1040
+
1041
+    /**
1042
+     * Get results of faults average for all courses by user
1043
+     * @param	int	   $user_id
1044
+     * @return 	array  results containing number of faults, total done attendance,
1045
+     * percentage of faults and color depend on result (red, orange)
1046
+     */
1047
+    public function get_faults_average_inside_courses($user_id)
1048
+    {
1049
+        // get all courses of current user
1050
+        $courses = CourseManager::get_courses_list_by_user_id($user_id, true);
1051
+
1052
+        $user_id = intval($user_id);
1053
+        $results = array();
1054
+        $total_faults = $total_weight = $porcent = 0;
1055
+        foreach ($courses as $course) {
1056
+            //$course_code = $course['code'];
1057
+            //$course_info = api_get_course_info($course_code);
1058
+            $course_id = $course['real_id'];
1059
+            $tbl_attendance_result 	= Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1060
+
1061
+            $attendances_by_course = $this->get_attendances_list($course_id);
1062
+
1063
+            foreach ($attendances_by_course as $attendance) {
1064
+                // get total faults and total weight
1065
+                $total_done_attendance 	= $attendance['attendance_qualify_max'];
1066
+                $sql = "SELECT score
1067 1067
 						FROM $tbl_attendance_result
1068 1068
                         WHERE
1069 1069
                         	c_id = $course_id AND
1070 1070
                         	user_id = $user_id AND
1071 1071
                         	attendance_id = ".$attendance['id'];
1072
-				$rs = Database::query($sql);
1073
-				$score = 0;
1074
-				if (Database::num_rows($rs) > 0) {
1075
-					$row = Database::fetch_array($rs);
1076
-					$score = $row['score'];
1077
-				}
1078
-				$faults = $total_done_attendance-$score;
1079
-				$faults = $faults > 0 ? $faults:0;
1080
-				$total_faults += $faults;
1081
-				$total_weight += $total_done_attendance;
1082
-			}
1083
-		}
1084
-
1085
-		$porcent = $total_weight > 0 ?round(($total_faults*100)/$total_weight,0):0;
1086
-		$results['faults'] 	= $total_faults;
1087
-		$results['total']	= $total_weight;
1088
-		$results['porcent'] = $porcent;
1089
-
1090
-		return $results;
1091
-	}
1092
-
1093
-	/**
1094
-	 * Get results of faults average by course
1095
-	 * @param	int	   $user_id
1096
-	 * @param 	string	$course_code
1097
-	 * @param	int	   Session id (optional)
1098
-	 * @return 	array  results containing number of faults,
1099
-	 * total done attendance, porcent of faults and color depend on result (red, orange)
1100
-	 */
1101
-	public function get_faults_average_by_course($user_id, $course_code, $session_id = null)
1102
-	{
1103
-		// Database tables and variables
1104
-		$course_info = api_get_course_info($course_code);
1105
-		$tbl_attendance_result 	= Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1106
-		$user_id = intval($user_id);
1107
-		$results = array();
1108
-		$total_faults = $total_weight = $porcent = 0;
1109
-		$attendances_by_course = $this->get_attendances_list($course_info['real_id'], $session_id);
1110
-
1111
-		foreach ($attendances_by_course as $attendance) {
1112
-			// Get total faults and total weight
1113
-			$total_done_attendance 	= $attendance['attendance_qualify_max'];
1114
-			$sql = "SELECT score FROM $tbl_attendance_result
1115
-					WHERE
1072
+                $rs = Database::query($sql);
1073
+                $score = 0;
1074
+                if (Database::num_rows($rs) > 0) {
1075
+                    $row = Database::fetch_array($rs);
1076
+                    $score = $row['score'];
1077
+                }
1078
+                $faults = $total_done_attendance-$score;
1079
+                $faults = $faults > 0 ? $faults:0;
1080
+                $total_faults += $faults;
1081
+                $total_weight += $total_done_attendance;
1082
+            }
1083
+        }
1084
+
1085
+        $porcent = $total_weight > 0 ?round(($total_faults*100)/$total_weight,0):0;
1086
+        $results['faults'] 	= $total_faults;
1087
+        $results['total']	= $total_weight;
1088
+        $results['porcent'] = $porcent;
1089
+
1090
+        return $results;
1091
+    }
1092
+
1093
+    /**
1094
+     * Get results of faults average by course
1095
+     * @param	int	   $user_id
1096
+     * @param 	string	$course_code
1097
+     * @param	int	   Session id (optional)
1098
+     * @return 	array  results containing number of faults,
1099
+     * total done attendance, porcent of faults and color depend on result (red, orange)
1100
+     */
1101
+    public function get_faults_average_by_course($user_id, $course_code, $session_id = null)
1102
+    {
1103
+        // Database tables and variables
1104
+        $course_info = api_get_course_info($course_code);
1105
+        $tbl_attendance_result 	= Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1106
+        $user_id = intval($user_id);
1107
+        $results = array();
1108
+        $total_faults = $total_weight = $porcent = 0;
1109
+        $attendances_by_course = $this->get_attendances_list($course_info['real_id'], $session_id);
1110
+
1111
+        foreach ($attendances_by_course as $attendance) {
1112
+            // Get total faults and total weight
1113
+            $total_done_attendance 	= $attendance['attendance_qualify_max'];
1114
+            $sql = "SELECT score FROM $tbl_attendance_result
1115
+					WHERE
1116 1116
 						c_id = {$course_info['real_id']} AND
1117 1117
 						user_id = $user_id AND
1118 1118
 						attendance_id=".$attendance['id'];
1119
-			$rs = Database::query($sql);
1120
-			$score = 0;
1121
-			if (Database::num_rows($rs) > 0) {
1122
-				$row = Database::fetch_array($rs);
1123
-				$score = $row['score'];
1124
-			}
1125
-			$faults = $total_done_attendance-$score;
1126
-			$faults = $faults > 0 ? $faults:0;
1127
-			$total_faults += $faults;
1128
-			$total_weight += $total_done_attendance;
1129
-		}
1130
-
1131
-		$porcent = $total_weight > 0 ?round(($total_faults*100)/$total_weight,0):0;
1132
-		$results['faults'] 	= $total_faults;
1133
-		$results['total']	= $total_weight;
1134
-		$results['porcent'] = $porcent;
1135
-
1136
-		return $results;
1137
-	}
1138
-
1139
-	/**
1140
-	 * Get registered users' attendance sheet inside current course
1141
-	 * @param	int	   $attendance_id
1142
-	 * @param	int	   $user_id for showing data for only one user (optional)
1143
-	 * @return 	array  users attendance sheet data
1144
-	 */
1145
-	public function get_users_attendance_sheet($attendance_id, $user_id = 0, $groupId = null)
1146
-	{
1147
-		$tbl_attendance_sheet 	= Database::get_course_table(TABLE_ATTENDANCE_SHEET);
1148
-		$tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1149
-
1150
-		$attendance_calendar = $this->get_attendance_calendar($attendance_id, 'all', null, $groupId);
1151
-		$calendar_ids = array();
1152
-		// get all dates from calendar by current attendance
1153
-		foreach ($attendance_calendar as $cal) {
1154
-			$calendar_ids[] = $cal['id'];
1155
-		}
1156
-
1157
-		$course_id = api_get_course_int_id();
1158
-
1159
-		$data = array();
1160
-		if (empty($user_id)) {
1161
-			// get all registered users inside current course
1162
-			$users = $this->get_users_rel_course();
1163
-			$user_ids = array_keys($users);
1164
-			if (count($calendar_ids) > 0 && count($user_ids) > 0) {
1165
-				foreach ($user_ids as $uid) {
1166
-					$sql = "SELECT * FROM $tbl_attendance_sheet
1119
+            $rs = Database::query($sql);
1120
+            $score = 0;
1121
+            if (Database::num_rows($rs) > 0) {
1122
+                $row = Database::fetch_array($rs);
1123
+                $score = $row['score'];
1124
+            }
1125
+            $faults = $total_done_attendance-$score;
1126
+            $faults = $faults > 0 ? $faults:0;
1127
+            $total_faults += $faults;
1128
+            $total_weight += $total_done_attendance;
1129
+        }
1130
+
1131
+        $porcent = $total_weight > 0 ?round(($total_faults*100)/$total_weight,0):0;
1132
+        $results['faults'] 	= $total_faults;
1133
+        $results['total']	= $total_weight;
1134
+        $results['porcent'] = $porcent;
1135
+
1136
+        return $results;
1137
+    }
1138
+
1139
+    /**
1140
+     * Get registered users' attendance sheet inside current course
1141
+     * @param	int	   $attendance_id
1142
+     * @param	int	   $user_id for showing data for only one user (optional)
1143
+     * @return 	array  users attendance sheet data
1144
+     */
1145
+    public function get_users_attendance_sheet($attendance_id, $user_id = 0, $groupId = null)
1146
+    {
1147
+        $tbl_attendance_sheet 	= Database::get_course_table(TABLE_ATTENDANCE_SHEET);
1148
+        $tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1149
+
1150
+        $attendance_calendar = $this->get_attendance_calendar($attendance_id, 'all', null, $groupId);
1151
+        $calendar_ids = array();
1152
+        // get all dates from calendar by current attendance
1153
+        foreach ($attendance_calendar as $cal) {
1154
+            $calendar_ids[] = $cal['id'];
1155
+        }
1156
+
1157
+        $course_id = api_get_course_int_id();
1158
+
1159
+        $data = array();
1160
+        if (empty($user_id)) {
1161
+            // get all registered users inside current course
1162
+            $users = $this->get_users_rel_course();
1163
+            $user_ids = array_keys($users);
1164
+            if (count($calendar_ids) > 0 && count($user_ids) > 0) {
1165
+                foreach ($user_ids as $uid) {
1166
+                    $sql = "SELECT * FROM $tbl_attendance_sheet
1167 1167
 					        WHERE
1168 1168
 					        	c_id = $course_id AND
1169 1169
 					        	user_id = '$uid' AND
1170 1170
 					        	attendance_calendar_id IN(".implode(',',$calendar_ids).")
1171 1171
 							";
1172
-					$res = Database::query($sql);
1173
-					if (Database::num_rows($res) > 0) {
1174
-						while ($row = Database::fetch_array($res)) {
1175
-							$data[$uid][$row['attendance_calendar_id']]['presence'] = $row['presence'];
1176
-						}
1177
-					}
1178
-				}
1179
-			}
1180
-		} else {
1181
-			// Get attendance for current user
1182
-			$user_id = intval($user_id);
1183
-			if (count($calendar_ids) > 0) {
1184
-				$sql = "SELECT cal.date_time, att.presence
1172
+                    $res = Database::query($sql);
1173
+                    if (Database::num_rows($res) > 0) {
1174
+                        while ($row = Database::fetch_array($res)) {
1175
+                            $data[$uid][$row['attendance_calendar_id']]['presence'] = $row['presence'];
1176
+                        }
1177
+                    }
1178
+                }
1179
+            }
1180
+        } else {
1181
+            // Get attendance for current user
1182
+            $user_id = intval($user_id);
1183
+            if (count($calendar_ids) > 0) {
1184
+                $sql = "SELECT cal.date_time, att.presence
1185 1185
                         FROM $tbl_attendance_sheet att
1186 1186
 						INNER JOIN  $tbl_attendance_calendar cal
1187 1187
 						ON cal.id = att.attendance_calendar_id
@@ -1191,89 +1191,89 @@  discard block
 block discarded – undo
1191 1191
 							att.user_id = '$user_id' AND
1192 1192
 							att.attendance_calendar_id IN (".implode(',',$calendar_ids).")
1193 1193
                         ORDER BY date_time";
1194
-				$res = Database::query($sql);
1195
-				if (Database::num_rows($res) > 0) {
1196
-					while ($row = Database::fetch_array($res)) {
1197
-						$row['date_time'] = api_convert_and_format_date($row['date_time'], null, date_default_timezone_get());
1198
-						$data[$user_id][] = $row;
1199
-					}
1200
-				}
1201
-			}
1202
-		}
1203
-
1204
-		return $data;
1205
-	}
1206
-
1207
-	/**
1208
-	 * Get next attendance calendar without presences (done attendances)
1209
-	 * @param	int	attendance id
1210
-	 * @return 	int attendance calendar id
1211
-	 */
1212
-	public function get_next_attendance_calendar_id($attendance_id)
1213
-	{
1214
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1215
-		$attendance_id = intval($attendance_id);
1216
-		$course_id = api_get_course_int_id();
1217
-
1218
-		$sql = "SELECT id FROM $tbl_attendance_calendar
1194
+                $res = Database::query($sql);
1195
+                if (Database::num_rows($res) > 0) {
1196
+                    while ($row = Database::fetch_array($res)) {
1197
+                        $row['date_time'] = api_convert_and_format_date($row['date_time'], null, date_default_timezone_get());
1198
+                        $data[$user_id][] = $row;
1199
+                    }
1200
+                }
1201
+            }
1202
+        }
1203
+
1204
+        return $data;
1205
+    }
1206
+
1207
+    /**
1208
+     * Get next attendance calendar without presences (done attendances)
1209
+     * @param	int	attendance id
1210
+     * @return 	int attendance calendar id
1211
+     */
1212
+    public function get_next_attendance_calendar_id($attendance_id)
1213
+    {
1214
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1215
+        $attendance_id = intval($attendance_id);
1216
+        $course_id = api_get_course_int_id();
1217
+
1218
+        $sql = "SELECT id FROM $tbl_attendance_calendar
1219 1219
 		        WHERE
1220 1220
 		        	c_id = $course_id AND
1221 1221
 		        	attendance_id = '$attendance_id' AND
1222 1222
 		        	done_attendance = 0
1223 1223
 		        ORDER BY date_time
1224 1224
 		        LIMIT 1";
1225
-		$rs = Database::query($sql);
1226
-		$next_calendar_id = 0;
1227
-		if (Database::num_rows($rs) > 0) {
1228
-			$row = Database::fetch_array($rs);
1229
-			$next_calendar_id = $row['id'];
1230
-		}
1231
-
1232
-		return $next_calendar_id;
1233
-	}
1234
-
1235
-	/**
1236
-	 * Get next attendance calendar datetime without presences (done attendances)
1237
-	 * @param	int	attendance id
1238
-	 * @return 	int UNIX time format datetime
1239
-	 */
1240
-	public function get_next_attendance_calendar_datetime($attendance_id)
1241
-	{
1242
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1243
-		$course_id = api_get_course_int_id();
1244
-		$attendance_id = intval($attendance_id);
1245
-		$sql = "SELECT id, date_time FROM $tbl_attendance_calendar
1225
+        $rs = Database::query($sql);
1226
+        $next_calendar_id = 0;
1227
+        if (Database::num_rows($rs) > 0) {
1228
+            $row = Database::fetch_array($rs);
1229
+            $next_calendar_id = $row['id'];
1230
+        }
1231
+
1232
+        return $next_calendar_id;
1233
+    }
1234
+
1235
+    /**
1236
+     * Get next attendance calendar datetime without presences (done attendances)
1237
+     * @param	int	attendance id
1238
+     * @return 	int UNIX time format datetime
1239
+     */
1240
+    public function get_next_attendance_calendar_datetime($attendance_id)
1241
+    {
1242
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1243
+        $course_id = api_get_course_int_id();
1244
+        $attendance_id = intval($attendance_id);
1245
+        $sql = "SELECT id, date_time FROM $tbl_attendance_calendar
1246 1246
 				WHERE
1247 1247
 					c_id = $course_id AND
1248 1248
 					attendance_id = '$attendance_id' AND
1249 1249
 					done_attendance = 0
1250 1250
 				ORDER BY date_time
1251 1251
 				LIMIT 1";
1252
-		$rs = Database::query($sql);
1253
-		$next_calendar_datetime = 0;
1254
-		if (Database::num_rows($rs) > 0) {
1255
-			$row = Database::fetch_array($rs);
1256
-			$next_calendar_datetime = api_get_local_time($row['date_time']);
1257
-		}
1258
-
1259
-		return $next_calendar_datetime;
1260
-	}
1261
-
1262
-	/**
1263
-	 * Get user' score from current attendance
1264
-	 * @param	int	$user_id
1265
-	 * @param	int $attendance_id
1266
-	 * @return	int score
1267
-	 */
1268
-	public function get_user_score($user_id, $attendance_id, $groupId = null)
1269
-	{
1270
-		$tbl_attendance_result 	= Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1252
+        $rs = Database::query($sql);
1253
+        $next_calendar_datetime = 0;
1254
+        if (Database::num_rows($rs) > 0) {
1255
+            $row = Database::fetch_array($rs);
1256
+            $next_calendar_datetime = api_get_local_time($row['date_time']);
1257
+        }
1258
+
1259
+        return $next_calendar_datetime;
1260
+    }
1261
+
1262
+    /**
1263
+     * Get user' score from current attendance
1264
+     * @param	int	$user_id
1265
+     * @param	int $attendance_id
1266
+     * @return	int score
1267
+     */
1268
+    public function get_user_score($user_id, $attendance_id, $groupId = null)
1269
+    {
1270
+        $tbl_attendance_result 	= Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1271 1271
         $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
1272 1272
         $tbl_attendance_cal_rel_group = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1273 1273
         $tbl_attendance_cal = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1274
-		$user_id = intval($user_id);
1275
-		$attendance_id = intval($attendance_id);
1276
-		$course_id = api_get_course_int_id();
1274
+        $user_id = intval($user_id);
1275
+        $attendance_id = intval($attendance_id);
1276
+        $course_id = api_get_course_int_id();
1277 1277
         if (empty($groupId)) {
1278 1278
             $sql = "SELECT score FROM $tbl_attendance_result
1279 1279
                     WHERE
@@ -1297,68 +1297,68 @@  discard block
 block discarded – undo
1297 1297
                         )
1298 1298
                     ";
1299 1299
         }
1300
-		$rs = Database::query($sql);
1301
-		$score = 0;
1302
-		if (Database::num_rows($rs) > 0) {
1303
-			$row = Database::fetch_array($rs);
1304
-			$score = $row['score'];
1305
-		}
1306
-
1307
-		return $score;
1308
-	}
1309
-
1310
-	/**
1311
-	 * Get attendance calendar data by id
1312
-	 * @param	int	attendance calendar id
1313
-	 * @return	array attendance calendar data
1314
-	 */
1315
-	public function get_attendance_calendar_by_id($calendar_id)
1316
-	{
1317
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1318
-		$calendar_id = intval($calendar_id);
1319
-		$course_id = api_get_course_int_id();
1320
-		$sql = "SELECT * FROM $tbl_attendance_calendar
1300
+        $rs = Database::query($sql);
1301
+        $score = 0;
1302
+        if (Database::num_rows($rs) > 0) {
1303
+            $row = Database::fetch_array($rs);
1304
+            $score = $row['score'];
1305
+        }
1306
+
1307
+        return $score;
1308
+    }
1309
+
1310
+    /**
1311
+     * Get attendance calendar data by id
1312
+     * @param	int	attendance calendar id
1313
+     * @return	array attendance calendar data
1314
+     */
1315
+    public function get_attendance_calendar_by_id($calendar_id)
1316
+    {
1317
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1318
+        $calendar_id = intval($calendar_id);
1319
+        $course_id = api_get_course_int_id();
1320
+        $sql = "SELECT * FROM $tbl_attendance_calendar
1321 1321
 				WHERE c_id = $course_id AND id = '$calendar_id' ";
1322
-		$rs = Database::query($sql);
1323
-		$data = array();
1324
-		if (Database::num_rows($rs) > 0) {
1325
-			while ($row = Database::fetch_array($rs)) {
1326
-				$row['date_time'] = api_get_local_time($row['date_time']);
1327
-				$data = $row;
1328
-			}
1329
-		}
1330
-
1331
-		return $data;
1332
-	}
1333
-
1334
-	/**
1335
-	 * Get all attendance calendar data inside current attendance
1336
-	 * @param int	$attendance_id
1337
-	 * @param string $type
1338
-	 * @param int $calendar_id
1339
-	 * @param int $groupId
1340
-	 * @param bool $showAll = false show group calendar items or not
1341
-	 *
1342
-	 * @return	array attendance calendar data
1343
-	 */
1344
-	public function get_attendance_calendar(
1345
-		$attendance_id,
1346
-		$type = 'all',
1347
-		$calendar_id = null,
1348
-		$groupId = null,
1349
-		$showAll = false
1350
-	) {
1351
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1322
+        $rs = Database::query($sql);
1323
+        $data = array();
1324
+        if (Database::num_rows($rs) > 0) {
1325
+            while ($row = Database::fetch_array($rs)) {
1326
+                $row['date_time'] = api_get_local_time($row['date_time']);
1327
+                $data = $row;
1328
+            }
1329
+        }
1330
+
1331
+        return $data;
1332
+    }
1333
+
1334
+    /**
1335
+     * Get all attendance calendar data inside current attendance
1336
+     * @param int	$attendance_id
1337
+     * @param string $type
1338
+     * @param int $calendar_id
1339
+     * @param int $groupId
1340
+     * @param bool $showAll = false show group calendar items or not
1341
+     *
1342
+     * @return	array attendance calendar data
1343
+     */
1344
+    public function get_attendance_calendar(
1345
+        $attendance_id,
1346
+        $type = 'all',
1347
+        $calendar_id = null,
1348
+        $groupId = null,
1349
+        $showAll = false
1350
+    ) {
1351
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1352 1352
         $tbl_acrg = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1353
-		$attendance_id = intval($attendance_id);
1354
-		$course_id = api_get_course_int_id();
1355
-		$groupCondition = null;
1353
+        $attendance_id = intval($attendance_id);
1354
+        $course_id = api_get_course_int_id();
1355
+        $groupCondition = null;
1356 1356
 
1357
-		if ($showAll) {
1358
-			$sql = "SELECT * FROM $tbl_attendance_calendar c
1357
+        if ($showAll) {
1358
+            $sql = "SELECT * FROM $tbl_attendance_calendar c
1359 1359
 					WHERE c_id = $course_id AND attendance_id = '$attendance_id'";
1360
-		} else {
1361
-			$sql = "SELECT * FROM $tbl_attendance_calendar c
1360
+        } else {
1361
+            $sql = "SELECT * FROM $tbl_attendance_calendar c
1362 1362
 					WHERE
1363 1363
 						c_id = $course_id AND
1364 1364
 						attendance_id = '$attendance_id' AND
@@ -1367,11 +1367,11 @@  discard block
 block discarded – undo
1367 1367
 							WHERE c_id = $course_id AND group_id != 0 AND group_id IS NOT NULL
1368 1368
 						)
1369 1369
 					";
1370
-		}
1370
+        }
1371 1371
 
1372
-		if (!empty($groupId)) {
1373
-			$groupId = intval($groupId);
1374
-			$sql = "SELECT c.* FROM $tbl_attendance_calendar c
1372
+        if (!empty($groupId)) {
1373
+            $groupId = intval($groupId);
1374
+            $sql = "SELECT c.* FROM $tbl_attendance_calendar c
1375 1375
 					INNER JOIN $tbl_acrg g
1376 1376
 					ON c.c_id = g.c_id AND c.id = g.calendar_id
1377 1377
 					WHERE
@@ -1379,62 +1379,62 @@  discard block
 block discarded – undo
1379 1379
 					    g.group_id = '$groupId' AND
1380 1380
 					    c.attendance_id = '$attendance_id'
1381 1381
                    ";
1382
-		}
1383
-
1384
-		if (!in_array($type, array('today', 'all', 'all_done', 'all_not_done','calendar_id'))) {
1385
-			$type = 'all';
1386
-		}
1387
-
1388
-		switch ($type) {
1389
-			case 'calendar_id':
1390
-				$calendar_id = intval($calendar_id);
1391
-				if (!empty($calendar_id)) {
1392
-					$sql.= " AND c.id = $calendar_id";
1393
-				}
1394
-				break;
1395
-			case 'today':
1396
-				//$sql .= ' AND DATE_FORMAT(date_time,"%d-%m-%Y") = DATE_FORMAT("'.api_get_utc_datetime().'", "%d-%m-%Y" )';
1397
-				break;
1398
-			case 'all_done':
1399
-				$sql .= " AND done_attendance = 1 ";
1400
-				break;
1401
-			case 'all_not_done':
1402
-				$sql .= " AND done_attendance = 0 ";
1403
-				break;
1404
-			case 'all':
1405
-			default:
1406
-				break;
1407
-		}
1408
-		$sql .= " ORDER BY date_time ";
1382
+        }
1409 1383
 
1410
-		$rs = Database::query($sql);
1411
-		$data = array();
1412
-		if (Database::num_rows($rs) > 0) {
1413
-			while ($row = Database::fetch_array($rs,'ASSOC')) {
1414
-				$row['db_date_time'] = $row['date_time'];
1415
-				$row['date_time'] = api_get_local_time($row['date_time']);
1416
-				$row['date'] = api_format_date($row['date_time'], DATE_FORMAT_SHORT);
1417
-				$row['time'] = api_format_date($row['date_time'], TIME_NO_SEC_FORMAT);
1418
-				$row['groups'] = $this->getGroupListByAttendanceCalendar($row['id'], $course_id);
1419
-				if ($type == 'today') {
1420
-					if (date('d-m-Y', api_strtotime($row['date_time'], 'UTC')) == date('d-m-Y', time())) {
1421
-						$data[] = $row;
1422
-					}
1423
-				} else {
1424
-					$data[] = $row;
1425
-				}
1426
-			}
1427
-		}
1428
-
1429
-		return $data;
1430
-	}
1431
-
1432
-	/**
1433
-	 * Get number of attendance calendar inside current attendance
1434
-	 * @param	int	$attendance_id
1435
-	 * @param	int	$groupId
1436
-	 * @return	int number of dates in attendance calendar
1437
-	 */
1384
+        if (!in_array($type, array('today', 'all', 'all_done', 'all_not_done','calendar_id'))) {
1385
+            $type = 'all';
1386
+        }
1387
+
1388
+        switch ($type) {
1389
+            case 'calendar_id':
1390
+                $calendar_id = intval($calendar_id);
1391
+                if (!empty($calendar_id)) {
1392
+                    $sql.= " AND c.id = $calendar_id";
1393
+                }
1394
+                break;
1395
+            case 'today':
1396
+                //$sql .= ' AND DATE_FORMAT(date_time,"%d-%m-%Y") = DATE_FORMAT("'.api_get_utc_datetime().'", "%d-%m-%Y" )';
1397
+                break;
1398
+            case 'all_done':
1399
+                $sql .= " AND done_attendance = 1 ";
1400
+                break;
1401
+            case 'all_not_done':
1402
+                $sql .= " AND done_attendance = 0 ";
1403
+                break;
1404
+            case 'all':
1405
+            default:
1406
+                break;
1407
+        }
1408
+        $sql .= " ORDER BY date_time ";
1409
+
1410
+        $rs = Database::query($sql);
1411
+        $data = array();
1412
+        if (Database::num_rows($rs) > 0) {
1413
+            while ($row = Database::fetch_array($rs,'ASSOC')) {
1414
+                $row['db_date_time'] = $row['date_time'];
1415
+                $row['date_time'] = api_get_local_time($row['date_time']);
1416
+                $row['date'] = api_format_date($row['date_time'], DATE_FORMAT_SHORT);
1417
+                $row['time'] = api_format_date($row['date_time'], TIME_NO_SEC_FORMAT);
1418
+                $row['groups'] = $this->getGroupListByAttendanceCalendar($row['id'], $course_id);
1419
+                if ($type == 'today') {
1420
+                    if (date('d-m-Y', api_strtotime($row['date_time'], 'UTC')) == date('d-m-Y', time())) {
1421
+                        $data[] = $row;
1422
+                    }
1423
+                } else {
1424
+                    $data[] = $row;
1425
+                }
1426
+            }
1427
+        }
1428
+
1429
+        return $data;
1430
+    }
1431
+
1432
+    /**
1433
+     * Get number of attendance calendar inside current attendance
1434
+     * @param	int	$attendance_id
1435
+     * @param	int	$groupId
1436
+     * @return	int number of dates in attendance calendar
1437
+     */
1438 1438
     public static function get_number_of_attendance_calendar($attendance_id, $groupId = 0, $done_attendance = NULL, $userId = 0)
1439 1439
     {
1440 1440
         $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
@@ -1520,113 +1520,113 @@  discard block
 block discarded – undo
1520 1520
 
1521 1521
 
1522 1522
     /**
1523
-	 * Get count dates inside attendance calendar by attendance id
1524
-	 * @param	int	$attendance_id
1525
-	 * @return	int     count of dates
1526
-	 */
1527
-	public static function get_count_dates_inside_attendance_calendar($attendance_id)
1528
-	{
1529
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1530
-		$attendance_id = intval($attendance_id);
1531
-		$course_id = api_get_course_int_id();
1532
-		$sql = "SELECT count(id) FROM $tbl_attendance_calendar
1523
+     * Get count dates inside attendance calendar by attendance id
1524
+     * @param	int	$attendance_id
1525
+     * @return	int     count of dates
1526
+     */
1527
+    public static function get_count_dates_inside_attendance_calendar($attendance_id)
1528
+    {
1529
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1530
+        $attendance_id = intval($attendance_id);
1531
+        $course_id = api_get_course_int_id();
1532
+        $sql = "SELECT count(id) FROM $tbl_attendance_calendar
1533 1533
                 WHERE
1534 1534
                 	c_id = $course_id AND
1535 1535
                 	attendance_id = '$attendance_id'";
1536
-		$rs = Database::query($sql);
1537
-		$count = 0;
1538
-		if (Database::num_rows($rs) > 0) {
1539
-			$row = Database::fetch_row($rs);
1540
-			$count = $row[0];
1541
-		}
1542
-		return $count;
1543
-	}
1544
-
1545
-	/**
1546
-	 * check if all calendar of an attendance is done
1547
-	 * @param   int     $attendance_id
1548
-	 * @return  bool    True if all calendar is done, otherwise false
1549
-	 */
1550
-	public static function is_all_attendance_calendar_done($attendance_id)
1551
-	{
1552
-		$attendance_id = intval($attendance_id);
1553
-		$done_calendar = self::get_done_attendance_calendar($attendance_id);
1554
-		$count_dates_in_calendar = self::get_count_dates_inside_attendance_calendar($attendance_id);
1555
-		$number_of_dates = self::get_number_of_attendance_calendar($attendance_id);
1556
-
1557
-		$result = false;
1558
-		if ($number_of_dates && (intval($count_dates_in_calendar) == intval($done_calendar))) {
1559
-			$result = true;
1560
-		}
1561
-		return $result;
1562
-	}
1563
-
1564
-	/**
1565
-	 * check if an attendance is locked
1566
-	 * @param   int $attendance_id
1567
-	 * @param   bool
1568
-	 */
1569
-	public static function is_locked_attendance($attendance_id)
1570
-	{
1571
-		//use gradebook lock
1572
-		$result = api_resource_is_locked_by_gradebook($attendance_id, LINK_ATTENDANCE);
1573
-
1574
-		return $result;
1575
-	}
1576
-
1577
-	/**
1578
-	 * Add new datetime inside attendance calendar table
1579
-	 * @param	int		$attendance_id
1580
-	 * @param 	array 	$groupList
1581
-	 * @return	int affected rows
1582
-	 */
1583
-	public function attendance_calendar_add($attendance_id, $groupList = array())
1584
-	{
1585
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1586
-		$affected_rows = 0;
1587
-		$attendance_id = intval($attendance_id);
1588
-		$course_id = api_get_course_int_id();
1589
-		// check if datetime already exists inside the table
1590
-		/*$sql = "SELECT id FROM $tbl_attendance_calendar
1536
+        $rs = Database::query($sql);
1537
+        $count = 0;
1538
+        if (Database::num_rows($rs) > 0) {
1539
+            $row = Database::fetch_row($rs);
1540
+            $count = $row[0];
1541
+        }
1542
+        return $count;
1543
+    }
1544
+
1545
+    /**
1546
+     * check if all calendar of an attendance is done
1547
+     * @param   int     $attendance_id
1548
+     * @return  bool    True if all calendar is done, otherwise false
1549
+     */
1550
+    public static function is_all_attendance_calendar_done($attendance_id)
1551
+    {
1552
+        $attendance_id = intval($attendance_id);
1553
+        $done_calendar = self::get_done_attendance_calendar($attendance_id);
1554
+        $count_dates_in_calendar = self::get_count_dates_inside_attendance_calendar($attendance_id);
1555
+        $number_of_dates = self::get_number_of_attendance_calendar($attendance_id);
1556
+
1557
+        $result = false;
1558
+        if ($number_of_dates && (intval($count_dates_in_calendar) == intval($done_calendar))) {
1559
+            $result = true;
1560
+        }
1561
+        return $result;
1562
+    }
1563
+
1564
+    /**
1565
+     * check if an attendance is locked
1566
+     * @param   int $attendance_id
1567
+     * @param   bool
1568
+     */
1569
+    public static function is_locked_attendance($attendance_id)
1570
+    {
1571
+        //use gradebook lock
1572
+        $result = api_resource_is_locked_by_gradebook($attendance_id, LINK_ATTENDANCE);
1573
+
1574
+        return $result;
1575
+    }
1576
+
1577
+    /**
1578
+     * Add new datetime inside attendance calendar table
1579
+     * @param	int		$attendance_id
1580
+     * @param 	array 	$groupList
1581
+     * @return	int affected rows
1582
+     */
1583
+    public function attendance_calendar_add($attendance_id, $groupList = array())
1584
+    {
1585
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1586
+        $affected_rows = 0;
1587
+        $attendance_id = intval($attendance_id);
1588
+        $course_id = api_get_course_int_id();
1589
+        // check if datetime already exists inside the table
1590
+        /*$sql = "SELECT id FROM $tbl_attendance_calendar
1591 1591
 		        WHERE
1592 1592
 		        	c_id = $course_id AND
1593 1593
 		        	date_time='".Database::escape_string($this->date_time)."' AND
1594 1594
 		        	attendance_id = '$attendance_id'";
1595 1595
 		$rs = Database::query($sql);
1596 1596
 		if (Database::num_rows($rs) == 0) {*/
1597
-			$params = array(
1598
-				'c_id' =>  $course_id,
1599
-				'date_time' => $this->date_time,
1600
-				'attendance_id' => $attendance_id,
1597
+            $params = array(
1598
+                'c_id' =>  $course_id,
1599
+                'date_time' => $this->date_time,
1600
+                'attendance_id' => $attendance_id,
1601 1601
                 'done_attendance' => 0
1602
-			);
1603
-			$id = Database::insert($tbl_attendance_calendar, $params);
1604
-
1605
-			if ($id) {
1606
-				$sql = "UPDATE $tbl_attendance_calendar SET id = iid WHERE iid = $id";
1607
-				Database::query($sql);
1608
-				$affected_rows++;
1609
-			}
1610
-			$this->addAttendanceCalendarToGroup($id, $course_id, $groupList);
1611
-		//}
1612
-
1613
-		// update locked attendance
1614
-		$is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id);
1615
-		if (!$is_all_calendar_done) {
1616
-			self::lock_attendance($attendance_id, false);
1617
-		} else {
1618
-			self::lock_attendance($attendance_id);
1619
-		}
1620
-		return $affected_rows;
1621
-	}
1622
-
1623
-	/**
1624
-	 * @param int   $calendarId
1625
-	 * @param int 	$courseId
1626
-	 * @param array $groupList
1627
-	 */
1628
-	public function addAttendanceCalendarToGroup($calendarId, $courseId, $groupList)
1629
-	{
1602
+            );
1603
+            $id = Database::insert($tbl_attendance_calendar, $params);
1604
+
1605
+            if ($id) {
1606
+                $sql = "UPDATE $tbl_attendance_calendar SET id = iid WHERE iid = $id";
1607
+                Database::query($sql);
1608
+                $affected_rows++;
1609
+            }
1610
+            $this->addAttendanceCalendarToGroup($id, $course_id, $groupList);
1611
+        //}
1612
+
1613
+        // update locked attendance
1614
+        $is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id);
1615
+        if (!$is_all_calendar_done) {
1616
+            self::lock_attendance($attendance_id, false);
1617
+        } else {
1618
+            self::lock_attendance($attendance_id);
1619
+        }
1620
+        return $affected_rows;
1621
+    }
1622
+
1623
+    /**
1624
+     * @param int   $calendarId
1625
+     * @param int 	$courseId
1626
+     * @param array $groupList
1627
+     */
1628
+    public function addAttendanceCalendarToGroup($calendarId, $courseId, $groupList)
1629
+    {
1630 1630
         if (empty($groupList)) {
1631 1631
             return false;
1632 1632
         }
@@ -1653,507 +1653,507 @@  discard block
 block discarded – undo
1653 1653
                 Database::insert($table, $params);
1654 1654
             }
1655 1655
         }
1656
-	}
1657
-
1658
-	/**
1659
-	 * @param int $calendarId
1660
-	 * @param int $courseId
1661
-	 * @param int $groupId
1662
-	 * @return array
1663
-	 */
1664
-	public function getGroupListByAttendanceCalendar($calendarId, $courseId)
1665
-	{
1666
-		$table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1667
-		return Database::select(
1668
-			'*',
1669
-			$table,
1670
-			array('where'=>
1671
-				array(
1672
-					'calendar_id = ? AND c_id = ?' => array($calendarId, $courseId)
1673
-				)
1674
-			)
1675
-		);
1676
-	}
1677
-
1678
-	/**
1679
-	 * @param int $calendarId
1680
-	 * @param int $courseId
1681
-	 * @param int $groupId
1682
-	 * @return array
1683
-	 */
1684
-	public function getAttendanceCalendarGroup($calendarId, $courseId, $groupId)
1685
-	{
1686
-		$table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1687
-		return Database::select(
1688
-			'*',
1689
-			$table,
1690
-			array('where'=>
1691
-				array(
1692
-					'calendar_id = ? AND c_id = ? AND group_id = ?' => array($calendarId, $courseId, $groupId)
1693
-				)
1694
-			)
1695
-		);
1696
-	}
1697
-
1698
-	/**
1699
-	 * @param int $calendarId
1700
-	 * @param int $courseId
1701
-	 * @param int $groupId
1656
+    }
1657
+
1658
+    /**
1659
+     * @param int $calendarId
1660
+     * @param int $courseId
1661
+     * @param int $groupId
1662
+     * @return array
1663
+     */
1664
+    public function getGroupListByAttendanceCalendar($calendarId, $courseId)
1665
+    {
1666
+        $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1667
+        return Database::select(
1668
+            '*',
1669
+            $table,
1670
+            array('where'=>
1671
+                array(
1672
+                    'calendar_id = ? AND c_id = ?' => array($calendarId, $courseId)
1673
+                )
1674
+            )
1675
+        );
1676
+    }
1677
+
1678
+    /**
1679
+     * @param int $calendarId
1680
+     * @param int $courseId
1681
+     * @param int $groupId
1682
+     * @return array
1683
+     */
1684
+    public function getAttendanceCalendarGroup($calendarId, $courseId, $groupId)
1685
+    {
1686
+        $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1687
+        return Database::select(
1688
+            '*',
1689
+            $table,
1690
+            array('where'=>
1691
+                array(
1692
+                    'calendar_id = ? AND c_id = ? AND group_id = ?' => array($calendarId, $courseId, $groupId)
1693
+                )
1694
+            )
1695
+        );
1696
+    }
1697
+
1698
+    /**
1699
+     * @param int $calendarId
1700
+     * @param int $courseId
1701
+     * @param int $groupId
1702 1702
      *
1703
-	 * @return array
1704
-	 */
1705
-	public function deleteAttendanceCalendarGroup($calendarId, $courseId)
1706
-	{
1707
-		$table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1708
-		Database::delete(
1709
-			$table,
1710
-			array(
1711
-				'calendar_id = ? AND c_id = ?' => array($calendarId, $courseId)
1712
-			)
1713
-		);
1714
-	}
1715
-
1716
-	/**
1717
-	 * save repeated date inside attendance calendar table
1718
-	 * @param int $attendance_id
1719
-	 * @param int $start_date start date in tms
1720
-	 * @param int $end_date end date in tms
1721
-	 * @param string $repeat_type daily, weekly, monthlyByDate
1722
-	 * @param array $groupList
1723
-	 */
1724
-	public function attendance_repeat_calendar_add(
1725
-		$attendance_id,
1726
-		$start_date,
1727
-		$end_date,
1728
-		$repeat_type,
1729
-		$groupList = array()
1730
-	) {
1731
-		$attendance_id = intval($attendance_id);
1732
-		// save start date
1733
-		$datetimezone = api_get_utc_datetime($start_date);
1734
-		$this->set_date_time($datetimezone);
1735
-		$this->attendance_calendar_add($attendance_id, $groupList);
1736
-
1737
-		// 86400 = 24 hours in seconds
1738
-		// 604800 = 1 week in seconds
1739
-		// Saves repeated dates
1740
-		switch ($repeat_type) {
1741
-			case 'daily':
1742
-				$j = 1;
1743
-				for ($i = $start_date + 86400; ($i <= $end_date); $i += 86400) {
1744
-					$datetimezone = api_get_utc_datetime($i);
1745
-					$this->set_date_time($datetimezone);
1746
-					$this->attendance_calendar_add($attendance_id, $groupList);
1747
-					$j++;
1748
-				}
1749
-				break;
1750
-			case 'weekly':
1751
-				$j = 1;
1752
-				for ($i = $start_date + 604800; ($i <= $end_date); $i += 604800) {
1753
-					$datetimezone = api_get_utc_datetime($i);
1754
-					$this->set_date_time($datetimezone);
1755
-					$this->attendance_calendar_add($attendance_id, $groupList);
1756
-					$j++;
1757
-				}
1758
-				break;
1759
-			case 'monthlyByDate':
1760
-				$j = 1;
1761
-				//@todo fix bug with february
1762
-				for ($i = $start_date + 2419200; ($i <= $end_date); $i += 2419200) {
1763
-					$datetimezone = api_get_utc_datetime($i);
1764
-					$this->set_date_time($datetimezone);
1765
-					$this->attendance_calendar_add($attendance_id, $groupList);
1766
-					$j++;
1767
-				}
1768
-				break;
1769
-		}
1770
-	}
1771
-
1772
-	/**
1773
-	 * Adds x months to a UNIX timestamp
1774
-	 * @param   int     The timestamp
1775
-	 * @param   int     The number of years to add
1776
-	 * @return  int     The new timestamp
1777
-	 */
1778
-	private function add_month($timestamp, $num=1)
1779
-	{
1780
-		$values = api_get_utc_datetime($timestamp);
1781
-		$values = str_replace(array(':','-',' '), '/', $values);
1782
-		list($y, $m, $d, $h, $n, $s) = split('/',$values);
1783
-		if($m+$num>12) {
1784
-			$y += floor($num/12);
1785
-			$m += $num%12;
1786
-		} else {
1787
-			$m += $num;
1788
-		}
1789
-		//date_default_timezone_set('UTC');
1790
-		// return mktime($h, $n, $s, $m, $d, $y);
1791
-		$result = api_strtotime($y.'-'.$m.'-'.$d.' '.$h.':'.$n.':'.$s, 'UTC');
1792
-		if (!empty($result)) {
1793
-			return $result;
1794
-		}
1795
-		return false;
1796
-	}
1797
-
1798
-	/**
1799
-	 * edit a datetime inside attendance calendar table
1800
-	 * @param	int	attendance calendar id
1801
-	 * @param	int	attendance id
1802
-	 * @return	int affected rows
1803
-	 */
1804
-	public function attendance_calendar_edit($calendar_id, $attendance_id)
1805
-	{
1806
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1807
-		$affected_rows = 0;
1808
-		$attendance_id = intval($attendance_id);
1809
-		$course_id = api_get_course_int_id();
1810
-		// check if datetime already exists inside the table
1811
-		$sql = "SELECT id FROM $tbl_attendance_calendar
1703
+     * @return array
1704
+     */
1705
+    public function deleteAttendanceCalendarGroup($calendarId, $courseId)
1706
+    {
1707
+        $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1708
+        Database::delete(
1709
+            $table,
1710
+            array(
1711
+                'calendar_id = ? AND c_id = ?' => array($calendarId, $courseId)
1712
+            )
1713
+        );
1714
+    }
1715
+
1716
+    /**
1717
+     * save repeated date inside attendance calendar table
1718
+     * @param int $attendance_id
1719
+     * @param int $start_date start date in tms
1720
+     * @param int $end_date end date in tms
1721
+     * @param string $repeat_type daily, weekly, monthlyByDate
1722
+     * @param array $groupList
1723
+     */
1724
+    public function attendance_repeat_calendar_add(
1725
+        $attendance_id,
1726
+        $start_date,
1727
+        $end_date,
1728
+        $repeat_type,
1729
+        $groupList = array()
1730
+    ) {
1731
+        $attendance_id = intval($attendance_id);
1732
+        // save start date
1733
+        $datetimezone = api_get_utc_datetime($start_date);
1734
+        $this->set_date_time($datetimezone);
1735
+        $this->attendance_calendar_add($attendance_id, $groupList);
1736
+
1737
+        // 86400 = 24 hours in seconds
1738
+        // 604800 = 1 week in seconds
1739
+        // Saves repeated dates
1740
+        switch ($repeat_type) {
1741
+            case 'daily':
1742
+                $j = 1;
1743
+                for ($i = $start_date + 86400; ($i <= $end_date); $i += 86400) {
1744
+                    $datetimezone = api_get_utc_datetime($i);
1745
+                    $this->set_date_time($datetimezone);
1746
+                    $this->attendance_calendar_add($attendance_id, $groupList);
1747
+                    $j++;
1748
+                }
1749
+                break;
1750
+            case 'weekly':
1751
+                $j = 1;
1752
+                for ($i = $start_date + 604800; ($i <= $end_date); $i += 604800) {
1753
+                    $datetimezone = api_get_utc_datetime($i);
1754
+                    $this->set_date_time($datetimezone);
1755
+                    $this->attendance_calendar_add($attendance_id, $groupList);
1756
+                    $j++;
1757
+                }
1758
+                break;
1759
+            case 'monthlyByDate':
1760
+                $j = 1;
1761
+                //@todo fix bug with february
1762
+                for ($i = $start_date + 2419200; ($i <= $end_date); $i += 2419200) {
1763
+                    $datetimezone = api_get_utc_datetime($i);
1764
+                    $this->set_date_time($datetimezone);
1765
+                    $this->attendance_calendar_add($attendance_id, $groupList);
1766
+                    $j++;
1767
+                }
1768
+                break;
1769
+        }
1770
+    }
1771
+
1772
+    /**
1773
+     * Adds x months to a UNIX timestamp
1774
+     * @param   int     The timestamp
1775
+     * @param   int     The number of years to add
1776
+     * @return  int     The new timestamp
1777
+     */
1778
+    private function add_month($timestamp, $num=1)
1779
+    {
1780
+        $values = api_get_utc_datetime($timestamp);
1781
+        $values = str_replace(array(':','-',' '), '/', $values);
1782
+        list($y, $m, $d, $h, $n, $s) = split('/',$values);
1783
+        if($m+$num>12) {
1784
+            $y += floor($num/12);
1785
+            $m += $num%12;
1786
+        } else {
1787
+            $m += $num;
1788
+        }
1789
+        //date_default_timezone_set('UTC');
1790
+        // return mktime($h, $n, $s, $m, $d, $y);
1791
+        $result = api_strtotime($y.'-'.$m.'-'.$d.' '.$h.':'.$n.':'.$s, 'UTC');
1792
+        if (!empty($result)) {
1793
+            return $result;
1794
+        }
1795
+        return false;
1796
+    }
1797
+
1798
+    /**
1799
+     * edit a datetime inside attendance calendar table
1800
+     * @param	int	attendance calendar id
1801
+     * @param	int	attendance id
1802
+     * @return	int affected rows
1803
+     */
1804
+    public function attendance_calendar_edit($calendar_id, $attendance_id)
1805
+    {
1806
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1807
+        $affected_rows = 0;
1808
+        $attendance_id = intval($attendance_id);
1809
+        $course_id = api_get_course_int_id();
1810
+        // check if datetime already exists inside the table
1811
+        $sql = "SELECT id FROM $tbl_attendance_calendar
1812 1812
 		        WHERE
1813 1813
 		        	c_id = $course_id AND
1814 1814
 		        	date_time = '".Database::escape_string($this->date_time)."' AND
1815 1815
 		        	attendance_id = '$attendance_id'";
1816
-		$rs = Database::query($sql);
1816
+        $rs = Database::query($sql);
1817 1817
 
1818
-		if (Database::num_rows($rs) == 0) {
1819
-			$sql = "UPDATE $tbl_attendance_calendar
1818
+        if (Database::num_rows($rs) == 0) {
1819
+            $sql = "UPDATE $tbl_attendance_calendar
1820 1820
 					SET date_time='".Database::escape_string($this->date_time)."'
1821 1821
 					WHERE c_id = $course_id AND id = '".intval($calendar_id)."'";
1822
-			Database::query($sql);
1823
-		}
1824
-
1825
-		// update locked attendance
1826
-		$is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id);
1827
-		if (!$is_all_calendar_done) {
1828
-			self::lock_attendance($attendance_id, false);
1829
-		} else {
1830
-			self::lock_attendance($attendance_id);
1831
-		}
1832
-
1833
-		return $affected_rows;
1834
-	}
1835
-
1836
-	/**
1837
-	 * delete a datetime from attendance calendar table
1838
-	 * @param	int		attendance calendar id
1839
-	 * @param	int		attendance id
1840
-	 * @param	bool	true for removing all calendar inside current attendance, false for removing by calendar id
1841
-	 * @return	int affected rows
1842
-	 */
1843
-	public function attendance_calendar_delete($calendar_id, $attendance_id , $all_delete = false)
1844
-	{
1845
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1846
-		$tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
1847
-
1848
-		$attendance_id = intval($attendance_id);
1849
-		// get all registered users inside current course
1850
-		$users = $this->get_users_rel_course();
1851
-		$user_ids = array_keys($users);
1852
-		$course_id = api_get_course_int_id();
1853
-		$affected_rows = 0;
1854
-		if ($all_delete) {
1855
-			$attendance_calendar = $this->get_attendance_calendar($attendance_id);
1856
-			// get all dates from calendar by current attendance
1857
-			if (!empty($attendance_calendar)) {
1858
-				foreach ($attendance_calendar as $cal) {
1859
-					// delete all data from attendance sheet
1860
-					$sql = "DELETE FROM $tbl_attendance_sheet
1822
+            Database::query($sql);
1823
+        }
1824
+
1825
+        // update locked attendance
1826
+        $is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id);
1827
+        if (!$is_all_calendar_done) {
1828
+            self::lock_attendance($attendance_id, false);
1829
+        } else {
1830
+            self::lock_attendance($attendance_id);
1831
+        }
1832
+
1833
+        return $affected_rows;
1834
+    }
1835
+
1836
+    /**
1837
+     * delete a datetime from attendance calendar table
1838
+     * @param	int		attendance calendar id
1839
+     * @param	int		attendance id
1840
+     * @param	bool	true for removing all calendar inside current attendance, false for removing by calendar id
1841
+     * @return	int affected rows
1842
+     */
1843
+    public function attendance_calendar_delete($calendar_id, $attendance_id , $all_delete = false)
1844
+    {
1845
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1846
+        $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
1847
+
1848
+        $attendance_id = intval($attendance_id);
1849
+        // get all registered users inside current course
1850
+        $users = $this->get_users_rel_course();
1851
+        $user_ids = array_keys($users);
1852
+        $course_id = api_get_course_int_id();
1853
+        $affected_rows = 0;
1854
+        if ($all_delete) {
1855
+            $attendance_calendar = $this->get_attendance_calendar($attendance_id);
1856
+            // get all dates from calendar by current attendance
1857
+            if (!empty($attendance_calendar)) {
1858
+                foreach ($attendance_calendar as $cal) {
1859
+                    // delete all data from attendance sheet
1860
+                    $sql = "DELETE FROM $tbl_attendance_sheet
1861 1861
 							WHERE c_id = $course_id AND attendance_calendar_id = '".intval($cal['id'])."'";
1862
-					Database::query($sql);
1863
-					// delete data from attendance calendar
1864
-					$sql = "DELETE FROM $tbl_attendance_calendar
1862
+                    Database::query($sql);
1863
+                    // delete data from attendance calendar
1864
+                    $sql = "DELETE FROM $tbl_attendance_calendar
1865 1865
 							WHERE c_id = $course_id AND id = '".intval($cal['id'])."'";
1866
-					Database::query($sql);
1867
-
1868
-					$this->deleteAttendanceCalendarGroup($cal['id'], $course_id);
1869
-					$affected_rows++;
1870
-				}
1871
-			}
1872
-		} else {
1873
-			// delete just one row from attendance sheet by the calendar id
1874
-			$sql = "DELETE FROM $tbl_attendance_sheet
1866
+                    Database::query($sql);
1867
+
1868
+                    $this->deleteAttendanceCalendarGroup($cal['id'], $course_id);
1869
+                    $affected_rows++;
1870
+                }
1871
+            }
1872
+        } else {
1873
+            // delete just one row from attendance sheet by the calendar id
1874
+            $sql = "DELETE FROM $tbl_attendance_sheet
1875 1875
 					WHERE c_id = $course_id AND attendance_calendar_id = '".intval($calendar_id)."'";
1876
-			Database::query($sql);
1877
-			// delete data from attendance calendar
1878
-			$sql = "DELETE FROM $tbl_attendance_calendar
1876
+            Database::query($sql);
1877
+            // delete data from attendance calendar
1878
+            $sql = "DELETE FROM $tbl_attendance_calendar
1879 1879
 					WHERE c_id = $course_id AND id = '".intval($calendar_id)."'";
1880
-			Database::query($sql);
1881
-
1882
-			$this->deleteAttendanceCalendarGroup($calendar_id, $course_id);
1883
-			$affected_rows++;
1884
-		}
1885
-
1886
-		// update users' results
1887
-		$this->update_users_results($user_ids, $attendance_id);
1888
-
1889
-		return $affected_rows;
1890
-	}
1891
-
1892
-	/** Setters for fields of attendances tables **/
1893
-	public function set_session_id($session_id)
1894
-	{
1895
-		$this->session_id = $session_id;
1896
-	}
1897
-
1898
-	public function set_course_id($course_id)
1899
-	{
1900
-		$this->course_id = $course_id;
1901
-	}
1902
-
1903
-	public function set_date_time($datetime)
1904
-	{
1905
-		$this->date_time = $datetime;
1906
-	}
1907
-
1908
-	public function set_name($name)
1909
-	{
1910
-		$this->name = $name;
1911
-	}
1912
-
1913
-	public function set_description($description)
1914
-	{
1915
-		$this->description = $description;
1916
-	}
1917
-
1918
-	public function set_attendance_qualify_title($attendance_qualify_title)
1919
-	{
1920
-		$this->attendance_qualify_title = $attendance_qualify_title;
1921
-	}
1922
-
1923
-	public function set_attendance_weight($attendance_weight)
1924
-	{
1925
-		$this->attendance_weight = $attendance_weight;
1926
-	}
1927
-
1928
-	/** Getters for fields of attendances tables **/
1929
-	public function get_session_id()
1930
-	{
1931
-		return $this->session_id;
1932
-	}
1933
-
1934
-	public function get_course_id()
1935
-	{
1936
-		return $this->course_id;
1937
-	}
1938
-
1939
-	public function get_date_time()
1940
-	{
1941
-		return $this->date_time;
1942
-	}
1943
-
1944
-	public function get_name()
1945
-	{
1946
-		return $this->name;
1947
-	}
1948
-
1949
-	public function get_description()
1950
-	{
1951
-		return $this->description;
1952
-	}
1953
-
1954
-	public function get_attendance_qualify_title()
1955
-	{
1956
-		return $this->attendance_qualify_title;
1957
-	}
1958
-
1959
-	public function get_attendance_weight()
1960
-	{
1961
-		return $this->attendance_weight;
1962
-	}
1963
-
1964
-	/**
1965
-	 * @param string $startDate in UTC time
1966
-	 * @param string $endDate in UTC time
1967
-	 *
1968
-	 * @return array
1969
-	 */
1970
-	public function getAttendanceLogin($startDate, $endDate)
1971
-	{
1880
+            Database::query($sql);
1881
+
1882
+            $this->deleteAttendanceCalendarGroup($calendar_id, $course_id);
1883
+            $affected_rows++;
1884
+        }
1885
+
1886
+        // update users' results
1887
+        $this->update_users_results($user_ids, $attendance_id);
1888
+
1889
+        return $affected_rows;
1890
+    }
1891
+
1892
+    /** Setters for fields of attendances tables **/
1893
+    public function set_session_id($session_id)
1894
+    {
1895
+        $this->session_id = $session_id;
1896
+    }
1897
+
1898
+    public function set_course_id($course_id)
1899
+    {
1900
+        $this->course_id = $course_id;
1901
+    }
1902
+
1903
+    public function set_date_time($datetime)
1904
+    {
1905
+        $this->date_time = $datetime;
1906
+    }
1907
+
1908
+    public function set_name($name)
1909
+    {
1910
+        $this->name = $name;
1911
+    }
1912
+
1913
+    public function set_description($description)
1914
+    {
1915
+        $this->description = $description;
1916
+    }
1917
+
1918
+    public function set_attendance_qualify_title($attendance_qualify_title)
1919
+    {
1920
+        $this->attendance_qualify_title = $attendance_qualify_title;
1921
+    }
1922
+
1923
+    public function set_attendance_weight($attendance_weight)
1924
+    {
1925
+        $this->attendance_weight = $attendance_weight;
1926
+    }
1927
+
1928
+    /** Getters for fields of attendances tables **/
1929
+    public function get_session_id()
1930
+    {
1931
+        return $this->session_id;
1932
+    }
1933
+
1934
+    public function get_course_id()
1935
+    {
1936
+        return $this->course_id;
1937
+    }
1938
+
1939
+    public function get_date_time()
1940
+    {
1941
+        return $this->date_time;
1942
+    }
1943
+
1944
+    public function get_name()
1945
+    {
1946
+        return $this->name;
1947
+    }
1948
+
1949
+    public function get_description()
1950
+    {
1951
+        return $this->description;
1952
+    }
1953
+
1954
+    public function get_attendance_qualify_title()
1955
+    {
1956
+        return $this->attendance_qualify_title;
1957
+    }
1958
+
1959
+    public function get_attendance_weight()
1960
+    {
1961
+        return $this->attendance_weight;
1962
+    }
1963
+
1964
+    /**
1965
+     * @param string $startDate in UTC time
1966
+     * @param string $endDate in UTC time
1967
+     *
1968
+     * @return array
1969
+     */
1970
+    public function getAttendanceLogin($startDate, $endDate)
1971
+    {
1972 1972
         if (
1973 1973
             empty($startDate) || $startDate == '0000-00-00' || $startDate == '0000-00-00 00:00:00' ||
1974 1974
             empty($endDate) || $endDate == '0000-00-00' || $endDate == '0000-00-00 00:00:00'
1975
-		) {
1976
-			return false;
1977
-		}
1975
+        ) {
1976
+            return false;
1977
+        }
1978 1978
 
1979
-		$sessionId = api_get_session_id();
1979
+        $sessionId = api_get_session_id();
1980 1980
         $courseCode = api_get_course_id();
1981
-		if (!empty($sessionId)) {
1982
-			$users = CourseManager:: get_user_list_from_course_code(
1983
-				$courseCode,
1984
-				$sessionId,
1985
-				'',
1986
-				'lastname',
1987
-				0
1988
-			);
1989
-		} else {
1990
-			$users = CourseManager:: get_user_list_from_course_code(
1991
-				$courseCode,
1992
-				0,
1993
-				'',
1994
-				'lastname',
1995
-				STUDENT
1996
-			);
1997
-		}
1998
-
1999
-		$dateTimeStartOriginal = new DateTime($startDate);
2000
-		$dateTimeStart = new DateTime($startDate);
2001
-		$dateTimeEnd= new DateTime($endDate);
2002
-		$interval = $dateTimeStart->diff($dateTimeEnd);
2003
-		$days = intval($interval->format('%a'));
2004
-
2005
-		$dateList = array($dateTimeStart->format('Y-m-d'));
2006
-		$headers = array(
2007
-			get_lang('User'),
2008
-			$dateTimeStart->format('Y-m-d')
2009
-		);
2010
-
2011
-		for ($i = 0; $i < $days; $i++) {
2012
-			$dateTimeStart = $dateTimeStart->add(new DateInterval('P1D'));
2013
-			$date = $dateTimeStart->format('Y-m-d');
2014
-			$dateList[] = $date;
2015
-			$headers[] = $date;
2016
-		}
2017
-
2018
-		$accessData = CourseManager::getCourseAccessPerCourseAndSession(
2019
-			$courseCode,
2020
-			$sessionId,
2021
-			$dateTimeStartOriginal->format('Y-m-d H:i:s'),
2022
-			$dateTimeEnd->format('Y-m-d H:i:s')
2023
-		);
2024
-
2025
-		$results = array();
2026
-		if (!empty($accessData)) {
2027
-			foreach ($accessData as $data) {
2028
-				$onlyDate = substr($data['login_course_date'], 0, 10);
2029
-				$results[$data['user_id']][$onlyDate] = true;
2030
-			}
2031
-		}
2032
-
2033
-		return array(
2034
-			'users' => $users,
2035
-			'dateList' => $dateList,
2036
-			'headers' => $headers,
2037
-			'results' => $results
2038
-		);
2039
-	}
2040
-
2041
-	/**
2042
-	 * @param string $startDate in UTC time
2043
-	 * @param string $endDate in UTC time
2044
-	 *
2045
-	 * @return string
2046
-	 */
2047
-	public function getAttendanceLoginTable($startDate, $endDate)
2048
-	{
2049
-		$data = $this->getAttendanceLogin($startDate, $endDate);
2050
-
2051
-		if (!$data) {
2052
-			return null;
2053
-		}
2054
-
2055
-		$headers = $data['headers'];
2056
-		$dateList = $data['dateList'];
2057
-		$users = $data['users'];
2058
-		$results = $data['results'];
2059
-
2060
-		$table = new HTML_Table(array('class' => 'data_table'));
2061
-		$row = 0;
2062
-		$column = 0;
2063
-		foreach ($headers as $header) {
2064
-			$table->setHeaderContents($row, $column, $header);
2065
-			$column++;
2066
-		}
2067
-		$row = 1;
2068
-		foreach ($users as $user) {
2069
-			$table->setCellContents(
2070
-				$row,
2071
-				0,
2072
-				$user['lastname'].' '.$user['firstname'].' ('.$user['username'].')'
2073
-			);
2074
-			$row ++;
2075
-		}
2076
-
2077
-		$column = 1;
2078
-		$row = 1;
2079
-		foreach ($users as $user) {
2080
-			foreach ($dateList as $date) {
2081
-				$status = null;
2082
-				if (isset($results[$user['user_id']]) &&
2083
-					isset($results[$user['user_id']][$date])
2084
-				) {
2085
-					$status = 'X';
2086
-				}
2087
-				$table->setCellContents($row, $column, $status);
2088
-				$column++;
2089
-			}
2090
-			$row++;
2091
-			$column = 1;
2092
-		}
2093
-
2094
-		return $table->toHtml();
2095
-	}
2096
-
2097
-	/**
2098
-	 * @param string $startDate in UTC time
2099
-	 * @param string $endDate in UTC time
2100
-	 *
2101
-	 * @return string
2102
-	 */
2103
-	public function exportAttendanceLogin($startDate, $endDate)
2104
-	{
2105
-		$data = $this->getAttendanceLogin($startDate, $endDate);
2106
-
2107
-		if (!$data) {
2108
-			return null;
2109
-		}
2110
-		$users = $data['users'];
2111
-		$results = $data['results'];
2112
-
2113
-		$table = new HTML_Table(array('class' => 'data_table'));
2114
-
2115
-		$table->setHeaderContents(0, 0, get_lang('User'));
2116
-		$table->setHeaderContents(0, 1, get_lang('Date'));
2117
-
2118
-		$row = 1;
2119
-		foreach ($users as $user) {
2120
-			$table->setCellContents(
2121
-				$row,
2122
-				0,
2123
-				$user['lastname'].' '.$user['firstname'].' ('.$user['username'].')'
2124
-			);
2125
-			$row++;
2126
-		}
2127
-		$table->setColAttributes(0, array('style' => 'width:28%'));
2128
-
2129
-		$row = 1;
2130
-		foreach ($users as $user) {
2131
-			if (isset($results[$user['user_id']]) &&
2132
-				!empty($results[$user['user_id']])
2133
-			) {
2134
-				$dates = implode(', ', array_keys($results[$user['user_id']]));
2135
-				$table->setCellContents($row, 1, $dates);
2136
-			}
2137
-			$row++;
2138
-		}
2139
-
2140
-		//$tableToString = null;
2141
-
2142
-		//$sessionInfo = api_get_session_info(api_get_session_id());
2143
-		//if (!empty($sessionInfo)) {
2144
-		/*$tableToString .= '<strong>'.get_lang('PeriodToDisplay').'</strong>: '.
1981
+        if (!empty($sessionId)) {
1982
+            $users = CourseManager:: get_user_list_from_course_code(
1983
+                $courseCode,
1984
+                $sessionId,
1985
+                '',
1986
+                'lastname',
1987
+                0
1988
+            );
1989
+        } else {
1990
+            $users = CourseManager:: get_user_list_from_course_code(
1991
+                $courseCode,
1992
+                0,
1993
+                '',
1994
+                'lastname',
1995
+                STUDENT
1996
+            );
1997
+        }
1998
+
1999
+        $dateTimeStartOriginal = new DateTime($startDate);
2000
+        $dateTimeStart = new DateTime($startDate);
2001
+        $dateTimeEnd= new DateTime($endDate);
2002
+        $interval = $dateTimeStart->diff($dateTimeEnd);
2003
+        $days = intval($interval->format('%a'));
2004
+
2005
+        $dateList = array($dateTimeStart->format('Y-m-d'));
2006
+        $headers = array(
2007
+            get_lang('User'),
2008
+            $dateTimeStart->format('Y-m-d')
2009
+        );
2010
+
2011
+        for ($i = 0; $i < $days; $i++) {
2012
+            $dateTimeStart = $dateTimeStart->add(new DateInterval('P1D'));
2013
+            $date = $dateTimeStart->format('Y-m-d');
2014
+            $dateList[] = $date;
2015
+            $headers[] = $date;
2016
+        }
2017
+
2018
+        $accessData = CourseManager::getCourseAccessPerCourseAndSession(
2019
+            $courseCode,
2020
+            $sessionId,
2021
+            $dateTimeStartOriginal->format('Y-m-d H:i:s'),
2022
+            $dateTimeEnd->format('Y-m-d H:i:s')
2023
+        );
2024
+
2025
+        $results = array();
2026
+        if (!empty($accessData)) {
2027
+            foreach ($accessData as $data) {
2028
+                $onlyDate = substr($data['login_course_date'], 0, 10);
2029
+                $results[$data['user_id']][$onlyDate] = true;
2030
+            }
2031
+        }
2032
+
2033
+        return array(
2034
+            'users' => $users,
2035
+            'dateList' => $dateList,
2036
+            'headers' => $headers,
2037
+            'results' => $results
2038
+        );
2039
+    }
2040
+
2041
+    /**
2042
+     * @param string $startDate in UTC time
2043
+     * @param string $endDate in UTC time
2044
+     *
2045
+     * @return string
2046
+     */
2047
+    public function getAttendanceLoginTable($startDate, $endDate)
2048
+    {
2049
+        $data = $this->getAttendanceLogin($startDate, $endDate);
2050
+
2051
+        if (!$data) {
2052
+            return null;
2053
+        }
2054
+
2055
+        $headers = $data['headers'];
2056
+        $dateList = $data['dateList'];
2057
+        $users = $data['users'];
2058
+        $results = $data['results'];
2059
+
2060
+        $table = new HTML_Table(array('class' => 'data_table'));
2061
+        $row = 0;
2062
+        $column = 0;
2063
+        foreach ($headers as $header) {
2064
+            $table->setHeaderContents($row, $column, $header);
2065
+            $column++;
2066
+        }
2067
+        $row = 1;
2068
+        foreach ($users as $user) {
2069
+            $table->setCellContents(
2070
+                $row,
2071
+                0,
2072
+                $user['lastname'].' '.$user['firstname'].' ('.$user['username'].')'
2073
+            );
2074
+            $row ++;
2075
+        }
2076
+
2077
+        $column = 1;
2078
+        $row = 1;
2079
+        foreach ($users as $user) {
2080
+            foreach ($dateList as $date) {
2081
+                $status = null;
2082
+                if (isset($results[$user['user_id']]) &&
2083
+                    isset($results[$user['user_id']][$date])
2084
+                ) {
2085
+                    $status = 'X';
2086
+                }
2087
+                $table->setCellContents($row, $column, $status);
2088
+                $column++;
2089
+            }
2090
+            $row++;
2091
+            $column = 1;
2092
+        }
2093
+
2094
+        return $table->toHtml();
2095
+    }
2096
+
2097
+    /**
2098
+     * @param string $startDate in UTC time
2099
+     * @param string $endDate in UTC time
2100
+     *
2101
+     * @return string
2102
+     */
2103
+    public function exportAttendanceLogin($startDate, $endDate)
2104
+    {
2105
+        $data = $this->getAttendanceLogin($startDate, $endDate);
2106
+
2107
+        if (!$data) {
2108
+            return null;
2109
+        }
2110
+        $users = $data['users'];
2111
+        $results = $data['results'];
2112
+
2113
+        $table = new HTML_Table(array('class' => 'data_table'));
2114
+
2115
+        $table->setHeaderContents(0, 0, get_lang('User'));
2116
+        $table->setHeaderContents(0, 1, get_lang('Date'));
2117
+
2118
+        $row = 1;
2119
+        foreach ($users as $user) {
2120
+            $table->setCellContents(
2121
+                $row,
2122
+                0,
2123
+                $user['lastname'].' '.$user['firstname'].' ('.$user['username'].')'
2124
+            );
2125
+            $row++;
2126
+        }
2127
+        $table->setColAttributes(0, array('style' => 'width:28%'));
2128
+
2129
+        $row = 1;
2130
+        foreach ($users as $user) {
2131
+            if (isset($results[$user['user_id']]) &&
2132
+                !empty($results[$user['user_id']])
2133
+            ) {
2134
+                $dates = implode(', ', array_keys($results[$user['user_id']]));
2135
+                $table->setCellContents($row, 1, $dates);
2136
+            }
2137
+            $row++;
2138
+        }
2139
+
2140
+        //$tableToString = null;
2141
+
2142
+        //$sessionInfo = api_get_session_info(api_get_session_id());
2143
+        //if (!empty($sessionInfo)) {
2144
+        /*$tableToString .= '<strong>'.get_lang('PeriodToDisplay').'</strong>: '.
2145 2145
 			sprintf(get_lang('FromDateXToDateY'), $startDate, $endDate);*/
2146
-		//}
2147
-
2148
-		$tableToString = $table->toHtml();
2149
-
2150
-		$params = array(
2151
-			'filename' => get_lang('Attendance') . '_' . api_get_utc_datetime(),
2152
-			'pdf_title' => get_lang('Attendance'),
2153
-			'course_code' => api_get_course_id(),
2154
-			'show_real_course_teachers' => true
2155
-		);
2156
-		$pdf = new PDF('A4', null, $params);
2157
-		$pdf->html_to_pdf_with_template($tableToString);
2158
-	}
2146
+        //}
2147
+
2148
+        $tableToString = $table->toHtml();
2149
+
2150
+        $params = array(
2151
+            'filename' => get_lang('Attendance') . '_' . api_get_utc_datetime(),
2152
+            'pdf_title' => get_lang('Attendance'),
2153
+            'course_code' => api_get_course_id(),
2154
+            'show_real_course_teachers' => true
2155
+        );
2156
+        $pdf = new PDF('A4', null, $params);
2157
+        $pdf->html_to_pdf_with_template($tableToString);
2158
+    }
2159 2159
 }
Please login to merge, or discard this patch.
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
             $course_id = intval($course_id);
74 74
         }
75 75
 
76
-        $session_id = isset($session_id)?intval($session_id):api_get_session_id();
76
+        $session_id = isset($session_id) ? intval($session_id) : api_get_session_id();
77 77
         $condition_session = api_get_session_condition($session_id);
78 78
 
79 79
         // Get attendance data
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 		$from = intval($from);
109 109
 		$number_of_items = intval($number_of_items);
110 110
 
111
-		if (!in_array($direction, array('ASC','DESC'))) {
111
+		if (!in_array($direction, array('ASC', 'DESC'))) {
112 112
 			$direction = 'ASC';
113 113
 		}
114 114
 
@@ -190,8 +190,8 @@  discard block
 block discarded – undo
190 190
 						$attendance[2] = '<span class="muted">'.$attendance[2].'</span>';
191 191
 					}
192 192
 					if ($allowDelete === 'true') {
193
-						$actions .= '<a href="index.php?' . api_get_cidreq() . '&action=attendance_delete&attendance_id=' . $attendance[0].'">' .
194
-							Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
193
+						$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_delete&attendance_id='.$attendance[0].'">'.
194
+							Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL).'</a>';
195 195
 					}
196 196
 				} else {
197 197
 					$is_locked_attendance = self::is_locked_attendance($attendance[0]);
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
 							$attendance[2] = '<span class="muted">'.$attendance[2].'</span>';
212 212
 						}
213 213
 						if ($allowDelete === 'true') {
214
-							$actions .= ' <a href="index.php?' . api_get_cidreq() . '&action=attendance_delete&attendance_id=' . $attendance[0].'">' .
215
-								Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
214
+							$actions .= ' <a href="index.php?'.api_get_cidreq().'&action=attendance_delete&attendance_id='.$attendance[0].'">'.
215
+								Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL).'</a>';
216 216
 						}
217 217
 					}
218 218
 				}
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 				$is_done_all_calendar = self::is_all_attendance_calendar_done($attendance[0]);
222 222
 
223 223
 				if ($is_done_all_calendar) {
224
-					$locked   = $attendance[4];
224
+					$locked = $attendance[4];
225 225
 					if ($locked == 0) {
226 226
 						if (api_is_platform_admin()) {
227 227
 							$message_alert = get_lang('AreYouSureToLockTheAttendance');
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 				}
242 242
 				$actions .= '</center>';
243 243
 
244
-				$attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3],$actions);
244
+				$attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3], $actions);
245 245
 			} else {
246 246
 				$attendance[0] = '&nbsp;';
247 247
 				$attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3]);
@@ -282,12 +282,12 @@  discard block
 block discarded – undo
282 282
 	public function attendance_add($link_to_gradebook = false)
283 283
 	{
284 284
 		$_course = api_get_course_info();
285
-		$tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
285
+		$tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
286 286
 		$session_id = api_get_session_id();
287 287
 		$user_id = api_get_user_id();
288 288
 		$course_code = $_course['code'];
289 289
 		$course_id = $_course['real_id'];
290
-		$title_gradebook= $this->attendance_qualify_title;
290
+		$title_gradebook = $this->attendance_qualify_title;
291 291
 		$value_calification = 0;
292 292
 		$weight_calification = floatval($this->attendance_weight);
293 293
 
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
                 $gradebookLink->setWeight($weight_calification);
349 349
 
350 350
                 $em->persist($gradebookLink);
351
-                $em-flush();
351
+                $em - flush();
352 352
 			}
353 353
 		}
354 354
 		return $last_id;
@@ -443,12 +443,12 @@  discard block
 block discarded – undo
443 443
 	public function attendance_restore($attendance_id)
444 444
 	{
445 445
 		$_course = api_get_course_info();
446
-		$tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
446
+		$tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
447 447
 		$user_id = api_get_user_id();
448 448
 		$course_id = $_course['real_id'];
449 449
 		if (is_array($attendance_id)) {
450 450
 			foreach ($attendance_id as $id) {
451
-				$id	= intval($id);
451
+				$id = intval($id);
452 452
 				$sql = "UPDATE $tbl_attendance SET active = 1
453 453
 						WHERE c_id = $course_id AND id = '$id'";
454 454
 				$result = Database::query($sql);
@@ -464,8 +464,8 @@  discard block
 block discarded – undo
464 464
                     );
465 465
 				}
466 466
 			}
467
-		} else  {
468
-			$attendance_id	= intval($attendance_id);
467
+		} else {
468
+			$attendance_id = intval($attendance_id);
469 469
 			$sql = "UPDATE $tbl_attendance SET active = 1
470 470
 					WHERE c_id = $course_id AND id = '$attendance_id'";
471 471
 			$result = Database::query($sql);
@@ -493,13 +493,13 @@  discard block
 block discarded – undo
493 493
 	public function attendance_delete($attendance_id)
494 494
 	{
495 495
 		$_course = api_get_course_info();
496
-		$tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
496
+		$tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
497 497
         $user_id = api_get_user_id();
498 498
         $course_id = $_course['real_id'];
499 499
 
500 500
 		if (is_array($attendance_id)) {
501 501
 			foreach ($attendance_id as $id) {
502
-				$id	= intval($id);
502
+				$id = intval($id);
503 503
 				$sql = "UPDATE $tbl_attendance SET active = 2
504 504
 						WHERE c_id = $course_id AND id = '$id'";
505 505
 				$result = Database::query($sql);
@@ -515,8 +515,8 @@  discard block
 block discarded – undo
515 515
                     );
516 516
 				}
517 517
 			}
518
-		} else  {
519
-			$attendance_id= intval($attendance_id);
518
+		} else {
519
+			$attendance_id = intval($attendance_id);
520 520
 			$sql = "UPDATE $tbl_attendance SET active = 2
521 521
 					WHERE c_id = $course_id AND id = '$attendance_id'";
522 522
 
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
 	public function changeVisibility($attendanceId, $status = 1)
548 548
 	{
549 549
 		$_course = api_get_course_info();
550
-		$tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
550
+		$tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
551 551
 		$user_id = api_get_user_id();
552 552
 		$course_id = $_course['real_id'];
553 553
 		$status = intval($status);
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
 
560 560
 		if (is_array($attendanceId)) {
561 561
 			foreach ($attendanceId as $id) {
562
-				$id	= intval($id);
562
+				$id = intval($id);
563 563
 				$sql = "UPDATE $tbl_attendance SET active = $status
564 564
 						WHERE c_id = $course_id AND id = '$id'";
565 565
 				$result = Database::query($sql);
@@ -569,8 +569,8 @@  discard block
 block discarded – undo
569 569
 					api_item_property_update($_course, TOOL_ATTENDANCE, $id, $action, $user_id);
570 570
 				}
571 571
 			}
572
-		} else  {
573
-			$attendanceId	= intval($attendanceId);
572
+		} else {
573
+			$attendanceId = intval($attendanceId);
574 574
 			$sql = "UPDATE $tbl_attendance SET active = $status
575 575
 					WHERE c_id = $course_id AND id = '$attendanceId'";
576 576
 			$result = Database::query($sql);
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
 		$tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
601 601
 		$course_id = api_get_course_int_id();
602 602
 		$attendance_id = intval($attendance_id);
603
-		$locked = ($lock)?1:0;
603
+		$locked = ($lock) ? 1 : 0;
604 604
 		$upd = "UPDATE $tbl_attendance SET locked = $locked
605 605
 				WHERE c_id = $course_id AND id = $attendance_id";
606 606
 		$result = Database::query($upd);
@@ -730,8 +730,8 @@  discard block
 block discarded – undo
730 730
 	 */
731 731
 	public function attendance_sheet_add($calendar_id, $users_present, $attendance_id)
732 732
 	{
733
-		$tbl_attendance_sheet 	= Database::get_course_table(TABLE_ATTENDANCE_SHEET);
734
-		$tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
733
+		$tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
734
+		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
735 735
 
736 736
 		$calendar_id = intval($calendar_id);
737 737
 		$attendance_id = intval($attendance_id);
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
 		$course_id = api_get_course_int_id();
740 740
 
741 741
 		$user_ids = array_keys($users);
742
-		$users_absent = array_diff($user_ids,$users_present);
742
+		$users_absent = array_diff($user_ids, $users_present);
743 743
 		$affected_rows = 0;
744 744
 
745 745
 		// get last edit type
@@ -1008,8 +1008,8 @@  discard block
 block discarded – undo
1008 1008
 		$results = array();
1009 1009
 		$calendar_count = self::get_number_of_attendance_calendar($attendance_id, $groupId, NULL, $user_id);
1010 1010
 		// $total_done_attendance 	= $attendance_data['attendance_qualify_max'];
1011
-        $total_done_attendance 	= self::get_number_of_attendance_calendar($attendance_id, $groupId, true, $user_id);
1012
-		$attendance_user_score  = $this->get_user_score($user_id, $attendance_id, $groupId);
1011
+        $total_done_attendance = self::get_number_of_attendance_calendar($attendance_id, $groupId, true, $user_id);
1012
+		$attendance_user_score = $this->get_user_score($user_id, $attendance_id, $groupId);
1013 1013
 
1014 1014
 		//This is the main change of the BT#1381
1015 1015
 		//$total_done_attendance = $calendar_count;
@@ -1022,7 +1022,7 @@  discard block
 block discarded – undo
1022 1022
         }
1023 1023
 
1024 1024
         $faults = $faults > 0 ? $faults : 0;
1025
-		$faults_porcent = $calendar_count > 0 ?round(($faults*100)/$calendar_count,0):0;
1025
+		$faults_porcent = $calendar_count > 0 ? round(($faults * 100) / $calendar_count, 0) : 0;
1026 1026
         $results['faults'] = $faults;
1027 1027
         $results['total'] = $calendar_count;
1028 1028
         $results['faults_porcent'] = $faults_porcent;
@@ -1056,13 +1056,13 @@  discard block
 block discarded – undo
1056 1056
 			//$course_code = $course['code'];
1057 1057
 			//$course_info = api_get_course_info($course_code);
1058 1058
 			$course_id = $course['real_id'];
1059
-			$tbl_attendance_result 	= Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1059
+			$tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1060 1060
 
1061 1061
 			$attendances_by_course = $this->get_attendances_list($course_id);
1062 1062
 
1063 1063
 			foreach ($attendances_by_course as $attendance) {
1064 1064
 				// get total faults and total weight
1065
-				$total_done_attendance 	= $attendance['attendance_qualify_max'];
1065
+				$total_done_attendance = $attendance['attendance_qualify_max'];
1066 1066
 				$sql = "SELECT score
1067 1067
 						FROM $tbl_attendance_result
1068 1068
                         WHERE
@@ -1075,16 +1075,16 @@  discard block
 block discarded – undo
1075 1075
 					$row = Database::fetch_array($rs);
1076 1076
 					$score = $row['score'];
1077 1077
 				}
1078
-				$faults = $total_done_attendance-$score;
1079
-				$faults = $faults > 0 ? $faults:0;
1078
+				$faults = $total_done_attendance - $score;
1079
+				$faults = $faults > 0 ? $faults : 0;
1080 1080
 				$total_faults += $faults;
1081 1081
 				$total_weight += $total_done_attendance;
1082 1082
 			}
1083 1083
 		}
1084 1084
 
1085
-		$porcent = $total_weight > 0 ?round(($total_faults*100)/$total_weight,0):0;
1085
+		$porcent = $total_weight > 0 ? round(($total_faults * 100) / $total_weight, 0) : 0;
1086 1086
 		$results['faults'] 	= $total_faults;
1087
-		$results['total']	= $total_weight;
1087
+		$results['total'] = $total_weight;
1088 1088
 		$results['porcent'] = $porcent;
1089 1089
 
1090 1090
 		return $results;
@@ -1102,7 +1102,7 @@  discard block
 block discarded – undo
1102 1102
 	{
1103 1103
 		// Database tables and variables
1104 1104
 		$course_info = api_get_course_info($course_code);
1105
-		$tbl_attendance_result 	= Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1105
+		$tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1106 1106
 		$user_id = intval($user_id);
1107 1107
 		$results = array();
1108 1108
 		$total_faults = $total_weight = $porcent = 0;
@@ -1110,7 +1110,7 @@  discard block
 block discarded – undo
1110 1110
 
1111 1111
 		foreach ($attendances_by_course as $attendance) {
1112 1112
 			// Get total faults and total weight
1113
-			$total_done_attendance 	= $attendance['attendance_qualify_max'];
1113
+			$total_done_attendance = $attendance['attendance_qualify_max'];
1114 1114
 			$sql = "SELECT score FROM $tbl_attendance_result
1115 1115
 					WHERE
1116 1116
 						c_id = {$course_info['real_id']} AND
@@ -1122,15 +1122,15 @@  discard block
 block discarded – undo
1122 1122
 				$row = Database::fetch_array($rs);
1123 1123
 				$score = $row['score'];
1124 1124
 			}
1125
-			$faults = $total_done_attendance-$score;
1126
-			$faults = $faults > 0 ? $faults:0;
1125
+			$faults = $total_done_attendance - $score;
1126
+			$faults = $faults > 0 ? $faults : 0;
1127 1127
 			$total_faults += $faults;
1128 1128
 			$total_weight += $total_done_attendance;
1129 1129
 		}
1130 1130
 
1131
-		$porcent = $total_weight > 0 ?round(($total_faults*100)/$total_weight,0):0;
1131
+		$porcent = $total_weight > 0 ? round(($total_faults * 100) / $total_weight, 0) : 0;
1132 1132
 		$results['faults'] 	= $total_faults;
1133
-		$results['total']	= $total_weight;
1133
+		$results['total'] = $total_weight;
1134 1134
 		$results['porcent'] = $porcent;
1135 1135
 
1136 1136
 		return $results;
@@ -1144,8 +1144,8 @@  discard block
 block discarded – undo
1144 1144
 	 */
1145 1145
 	public function get_users_attendance_sheet($attendance_id, $user_id = 0, $groupId = null)
1146 1146
 	{
1147
-		$tbl_attendance_sheet 	= Database::get_course_table(TABLE_ATTENDANCE_SHEET);
1148
-		$tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1147
+		$tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
1148
+		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1149 1149
 
1150 1150
 		$attendance_calendar = $this->get_attendance_calendar($attendance_id, 'all', null, $groupId);
1151 1151
 		$calendar_ids = array();
@@ -1167,7 +1167,7 @@  discard block
 block discarded – undo
1167 1167
 					        WHERE
1168 1168
 					        	c_id = $course_id AND
1169 1169
 					        	user_id = '$uid' AND
1170
-					        	attendance_calendar_id IN(".implode(',',$calendar_ids).")
1170
+					        	attendance_calendar_id IN(".implode(',', $calendar_ids).")
1171 1171
 							";
1172 1172
 					$res = Database::query($sql);
1173 1173
 					if (Database::num_rows($res) > 0) {
@@ -1189,7 +1189,7 @@  discard block
 block discarded – undo
1189 1189
 							att.c_id = $course_id AND
1190 1190
 							cal.c_id =  $course_id AND
1191 1191
 							att.user_id = '$user_id' AND
1192
-							att.attendance_calendar_id IN (".implode(',',$calendar_ids).")
1192
+							att.attendance_calendar_id IN (".implode(',', $calendar_ids).")
1193 1193
                         ORDER BY date_time";
1194 1194
 				$res = Database::query($sql);
1195 1195
 				if (Database::num_rows($res) > 0) {
@@ -1267,7 +1267,7 @@  discard block
 block discarded – undo
1267 1267
 	 */
1268 1268
 	public function get_user_score($user_id, $attendance_id, $groupId = null)
1269 1269
 	{
1270
-		$tbl_attendance_result 	= Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1270
+		$tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1271 1271
         $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
1272 1272
         $tbl_attendance_cal_rel_group = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1273 1273
         $tbl_attendance_cal = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
@@ -1381,7 +1381,7 @@  discard block
 block discarded – undo
1381 1381
                    ";
1382 1382
 		}
1383 1383
 
1384
-		if (!in_array($type, array('today', 'all', 'all_done', 'all_not_done','calendar_id'))) {
1384
+		if (!in_array($type, array('today', 'all', 'all_done', 'all_not_done', 'calendar_id'))) {
1385 1385
 			$type = 'all';
1386 1386
 		}
1387 1387
 
@@ -1389,7 +1389,7 @@  discard block
 block discarded – undo
1389 1389
 			case 'calendar_id':
1390 1390
 				$calendar_id = intval($calendar_id);
1391 1391
 				if (!empty($calendar_id)) {
1392
-					$sql.= " AND c.id = $calendar_id";
1392
+					$sql .= " AND c.id = $calendar_id";
1393 1393
 				}
1394 1394
 				break;
1395 1395
 			case 'today':
@@ -1410,7 +1410,7 @@  discard block
 block discarded – undo
1410 1410
 		$rs = Database::query($sql);
1411 1411
 		$data = array();
1412 1412
 		if (Database::num_rows($rs) > 0) {
1413
-			while ($row = Database::fetch_array($rs,'ASSOC')) {
1413
+			while ($row = Database::fetch_array($rs, 'ASSOC')) {
1414 1414
 				$row['db_date_time'] = $row['date_time'];
1415 1415
 				$row['date_time'] = api_get_local_time($row['date_time']);
1416 1416
 				$row['date'] = api_format_date($row['date_time'], DATE_FORMAT_SHORT);
@@ -1775,14 +1775,14 @@  discard block
 block discarded – undo
1775 1775
 	 * @param   int     The number of years to add
1776 1776
 	 * @return  int     The new timestamp
1777 1777
 	 */
1778
-	private function add_month($timestamp, $num=1)
1778
+	private function add_month($timestamp, $num = 1)
1779 1779
 	{
1780 1780
 		$values = api_get_utc_datetime($timestamp);
1781
-		$values = str_replace(array(':','-',' '), '/', $values);
1782
-		list($y, $m, $d, $h, $n, $s) = split('/',$values);
1783
-		if($m+$num>12) {
1784
-			$y += floor($num/12);
1785
-			$m += $num%12;
1781
+		$values = str_replace(array(':', '-', ' '), '/', $values);
1782
+		list($y, $m, $d, $h, $n, $s) = split('/', $values);
1783
+		if ($m + $num > 12) {
1784
+			$y += floor($num / 12);
1785
+			$m += $num % 12;
1786 1786
 		} else {
1787 1787
 			$m += $num;
1788 1788
 		}
@@ -1840,7 +1840,7 @@  discard block
 block discarded – undo
1840 1840
 	 * @param	bool	true for removing all calendar inside current attendance, false for removing by calendar id
1841 1841
 	 * @return	int affected rows
1842 1842
 	 */
1843
-	public function attendance_calendar_delete($calendar_id, $attendance_id , $all_delete = false)
1843
+	public function attendance_calendar_delete($calendar_id, $attendance_id, $all_delete = false)
1844 1844
 	{
1845 1845
 		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1846 1846
 		$tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
@@ -1998,7 +1998,7 @@  discard block
 block discarded – undo
1998 1998
 
1999 1999
 		$dateTimeStartOriginal = new DateTime($startDate);
2000 2000
 		$dateTimeStart = new DateTime($startDate);
2001
-		$dateTimeEnd= new DateTime($endDate);
2001
+		$dateTimeEnd = new DateTime($endDate);
2002 2002
 		$interval = $dateTimeStart->diff($dateTimeEnd);
2003 2003
 		$days = intval($interval->format('%a'));
2004 2004
 
@@ -2071,7 +2071,7 @@  discard block
 block discarded – undo
2071 2071
 				0,
2072 2072
 				$user['lastname'].' '.$user['firstname'].' ('.$user['username'].')'
2073 2073
 			);
2074
-			$row ++;
2074
+			$row++;
2075 2075
 		}
2076 2076
 
2077 2077
 		$column = 1;
@@ -2148,7 +2148,7 @@  discard block
 block discarded – undo
2148 2148
 		$tableToString = $table->toHtml();
2149 2149
 
2150 2150
 		$params = array(
2151
-			'filename' => get_lang('Attendance') . '_' . api_get_utc_datetime(),
2151
+			'filename' => get_lang('Attendance').'_'.api_get_utc_datetime(),
2152 2152
 			'pdf_title' => get_lang('Attendance'),
2153 2153
 			'course_code' => api_get_course_id(),
2154 2154
 			'show_real_course_teachers' => true
Please login to merge, or discard this patch.