/** * Get the attendaces to display on the current page (fill the sortable-table) * @param int offset of first user to recover * @param int Number of users to get * @param int Column to sort on * @param string Order (ASC,DESC) * @see SortableTable#get_table_data($from) */ static function get_attendance_data($from = 0, $number_of_items = 20, $column = 1, $direction = 'desc') { $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE); $course_id = api_get_course_int_id(); $session_id = api_get_session_id(); $condition_session = api_get_session_condition($session_id); $column = intval($column); $from = intval($from); $number_of_items = intval($number_of_items); if (!in_array($direction, array('ASC', 'DESC'))) { $direction = 'ASC'; } $att = new Attendance(); $att->set_session_id($session_id); $att->set_course_int_id($course_id); $active_plus = 'att.active = 1'; if (api_is_platform_admin()) { $active_plus = ' 1 = 1 '; } $sql = "SELECT\n att.id,\n att.name,\n att.description,\n att.attendance_qualify_max,\n att.locked,\n att.active,\n att.session_id\n\t\t\t\tFROM {$tbl_attendance} att\n\t\t\t\tWHERE c_id = {$course_id} AND {$active_plus} {$condition_session}\n\t\t\t\tORDER BY {$column} {$direction}\n LIMIT {$from}, {$number_of_items} "; $res = Database::query($sql); $attendances = array(); $param_gradebook = ''; if (isset($_SESSION['gradebook'])) { $param_gradebook = '&gradebook=' . $_SESSION['gradebook']; } $user_info = api_get_user_info(); while ($attendance = Database::fetch_array($res, 'ASSOC')) { $id = $attendance['id']; $student_param = ''; if (api_is_drh() && $_GET['student_id']) { $student_param = '&student_id=' . Security::remove_XSS($_GET['student_id']); } $session_star = ''; if (api_get_session_id() == $attendance['session_id']) { $session_star = api_get_session_image(api_get_session_id(), $user_info['status']); } if ($attendance['active'] == 0) { $attendance['name'] = "<del>" . $attendance['name'] . "</del>"; } if ($attendance['locked'] == 1) { if (api_is_allowed_to_edit(null, true)) { //Link to edit $attendance['name'] = '<a href="index.php?' . api_get_cidreq() . '&action=attendance_sheet_list&attendance_id=' . $id . $param_gradebook . $student_param . '">' . $attendance['name'] . '</a>' . $session_star; } else { //Link to view $attendance['name'] = '<a href="index.php?' . api_get_cidreq() . '&action=attendance_sheet_list_no_edit&attendance_id=' . $id . $param_gradebook . $student_param . '">' . $attendance['name'] . '</a>' . $session_star; } } else { $attendance['name'] = '<a href="index.php?' . api_get_cidreq() . '&action=attendance_sheet_list&attendance_id=' . $id . $param_gradebook . $student_param . '">' . $attendance['name'] . '</a>' . $session_star; } //description $attendance['description'] = '<center>' . $attendance['description'] . '</center>'; if (api_is_allowed_to_edit(null, true)) { $actions = ''; $actions .= '<center>'; if (api_is_platform_admin()) { $actions .= '<a href="index.php?' . api_get_cidreq() . '&action=attendance_edit&attendance_id=' . $id . $param_gradebook . '">' . Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL) . '</a> '; if ($attendance['locked'] == 0) { // $actions .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=attendance_delete&attendance_id='.$id.$param_gradebook.'">'.Display::return_icon('delete.png',get_lang('Delete'), array(), ICON_SIZE_SMALL).'</a>'; } if ($attendance['active'] == 1) { $actions .= '<a onclick="javascript:if(!confirm(\'' . get_lang('AreYouSureToDelete') . '\')) return false;" href="index.php?' . api_get_cidreq() . '&action=attendance_delete&attendance_id=' . $id . $param_gradebook . '">' . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>'; } else { $actions .= '<a onclick="javascript:if(!confirm(\'' . get_lang('AreYouSureToRestore') . '\')) return false;" href="index.php?' . api_get_cidreq() . '&action=attendance_restore&attendance_id=' . $id . $param_gradebook . '">' . Display::return_icon('invisible.png', get_lang('Restore'), array(), ICON_SIZE_SMALL) . '</a>'; } } else { $is_locked_attendance = self::is_locked_attendance($attendance['id']); if ($is_locked_attendance) { $actions .= Display::return_icon('edit_na.png', get_lang('Edit')) . ' '; $actions .= Display::return_icon('delete_na.png', get_lang('Delete')); } else { $actions .= '<a href="index.php?' . api_get_cidreq() . '&action=attendance_edit&attendance_id=' . $id . $param_gradebook . '">' . Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL) . '</a> '; $actions .= '<a onclick="javascript:if(!confirm(\'' . get_lang('AreYouSureToDelete') . '\')) return false;" href="index.php?' . api_get_cidreq() . '&action=attendance_delete&attendance_id=' . $id . $param_gradebook . '">' . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>'; } } // display lock/unlock icon $is_done_all_calendar = $att->is_all_attendance_calendar_done($id); if ($is_done_all_calendar) { $locked = $attendance['attendance_qualify_max']; if ($locked == 0) { if (api_is_platform_admin()) { $message_alert = get_lang('AreYouSureToLockTheAttendance'); } else { $message_alert = get_lang('UnlockMessageInformation'); } $actions .= ' <a onclick="javascript:if(!confirm(\'' . $message_alert . '\')) return false;" href="index.php?' . api_get_cidreq() . '&action=lock_attendance&attendance_id=' . $id . $param_gradebook . '">' . Display::return_icon('unlock.png', get_lang('LockAttendance')) . '</a>'; } else { if (api_is_platform_admin()) { $actions .= ' <a onclick="javascript:if(!confirm(\'' . get_lang('AreYouSureToUnlockTheAttendance') . '\')) return false;" href="index.php?' . api_get_cidreq() . '&action=unlock_attendance&attendance_id=' . $id . $param_gradebook . '">' . Display::return_icon('lock.png', get_lang('UnlockAttendance')) . '</a>'; } else { $actions .= ' ' . Display::return_icon('locked_na.png', get_lang('LockedAttendance')); } } } $actions .= '</center>'; $attendance['actions'] = $actions; $attendances[] = $attendance; } else { $attendances[] = $attendance; } } return $attendances; }