diff --git a/main/attendance/attendance_controller.php b/main/attendance/attendance_controller.php index 7c399567e3..7c868affec 100644 --- a/main/attendance/attendance_controller.php +++ b/main/attendance/attendance_controller.php @@ -223,7 +223,7 @@ * @param string action * @param int attendance id */ - public function attendance_sheet($action, $attendance_id, $student_id = 0) { + public function attendance_sheet($action, $attendance_id, $student_id = 0, $edit = true) { $attendance = new Attendance(); $data = array(); $data['attendance_id'] = $attendance_id; @@ -233,22 +233,31 @@ if (!empty($_REQUEST['filter'])) { $filter_type = $_REQUEST['filter']; - } - - if (api_is_allowed_to_edit(null, true)) { - $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id); - } else { - if (!empty($student_id)) { - $user_id = intval($student_id); - } else { - $user_id = api_get_user_id(); - } - $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id, $user_id); - $data['faults'] = $attendance->get_faults_of_user($user_id, $attendance_id); - - $data['user_id'] = $user_id; } - + + if ($edit == true) { + if (api_is_allowed_to_edit(null, true)) { + $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id); + } else { + + } + } else { + if (!empty($student_id)) { + $user_id = intval($student_id); + } else { + $user_id = api_get_user_id(); + } + + if (api_is_allowed_to_edit(null, true) || api_is_coach(api_get_session_id(), api_get_course_id())) { + $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id); + } else { + $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id, $user_id); + } + + $data['faults'] = $attendance->get_faults_of_user($user_id, $attendance_id); + $data['user_id'] = $user_id; + } + $data['next_attendance_calendar_id'] = $attendance->get_next_attendance_calendar_id($attendance_id); $data['next_attendance_calendar_datetime'] = $attendance->get_next_attendance_calendar_datetime($attendance_id); @@ -279,6 +288,8 @@ $data['attendant_calendar_all'] = $attendance->get_attendance_calendar($attendance_id); $data['attendant_calendar'] = $attendance->get_attendance_calendar($attendance_id, $filter_type); } + + $data['edit_table'] = intval($edit); $data['is_locked_attendance'] = $attendance->is_locked_attendance($attendance_id); $this->view->set_data($data); $this->view->set_layout('layout'); @@ -535,5 +546,4 @@ Export::export_html_to_pdf($content, $params); exit; } -} - +} \ No newline at end of file diff --git a/main/attendance/attendance_sheet.php b/main/attendance/attendance_sheet.php index a99b6fd9cd..27e59223c1 100644 --- a/main/attendance/attendance_sheet.php +++ b/main/attendance/attendance_sheet.php @@ -11,13 +11,14 @@ // protect a course script api_protect_course_script(true); -if (api_is_allowed_to_edit(null, true)) { +if (api_is_allowed_to_edit(null, true) || api_is_coach(api_get_session_id(), api_get_course_id())) { + $param_gradebook = ''; if (isset($_SESSION['gradebook'])) { $param_gradebook = '&gradebook='.$_SESSION['gradebook']; } - $form = new FormValidator('filter', 'post', 'index.php?action=attendance_sheet_add&'.api_get_cidreq().$param_gradebook.'&attendance_id='.$attendance_id, null, array('class' => 'form-search pull-left')); + $form = new FormValidator('filter', 'post', 'index.php?action=attendance_sheet_list&'.api_get_cidreq().$param_gradebook.'&attendance_id='.$attendance_id, null, array('class' => 'form-search pull-left')); $values = array( 'all' => get_lang('All'), 'today' => get_lang('Today'), @@ -56,7 +57,6 @@ if (api_is_allowed_to_edit(null, true)) { $renderer->setElementTemplate('{label} {element} '); $form->setDefaults(array('filter'=>$default_filter)); - if (!$is_locked_attendance || api_is_platform_admin()) { echo '
'; @@ -185,12 +185,14 @@ if (api_is_allowed_to_edit(null, true)) { @@ -211,127 +213,146 @@ if (api_is_allowed_to_edit(null, true)) {
+ + '; + echo ''; + echo ''; + if (count($attendant_calendar) > 0 ) { + foreach ($attendant_calendar as $calendar) { + $date = $calendar['date']; + $time = $calendar['time']; + $datetime = $date.'
'.$time; -
-
- - 0 ) { - foreach ($attendant_calendar as $calendar) { - $date = $calendar['date']; - $time = $calendar['time']; - $datetime = $date.'
'.$time; - - $img_lock = Display::return_icon('lock.gif',get_lang('DateUnLock'),array('class'=>'img_lock','id'=>'datetime_column_'.$calendar['id'])); - - if (!empty($calendar['done_attendance'])){ - $datetime = ''.$date.'
'.$time.'
'; - } - $disabled_check = 'disabled = "true"'; - $input_hidden = ''; - if ($next_attendance_calendar_id == $calendar['id']) { - $input_hidden = ''; - $disabled_check = ''; - $img_lock = Display::return_icon('unlock.gif',get_lang('DateLock'),array('class'=>'img_unlock','id'=>'datetime_column_'.$calendar['id'])); - } - - $result .= ''; - } - } + $img_lock = Display::return_icon('lock.gif',get_lang('DateUnLock'),array('class'=>'img_lock','id'=>'datetime_column_'.$calendar['id'])); + + if (!empty($calendar['done_attendance'])){ + $datetime = ''.$date.'
'.$time.'
'; + } + $disabled_check = 'disabled = "true"'; + $input_hidden = ''; + if ($next_attendance_calendar_id == $calendar['id']) { + $input_hidden = ''; + $disabled_check = ''; + $img_lock = Display::return_icon('unlock.gif',get_lang('DateLock'),array('class'=>'img_unlock','id'=>'datetime_column_'.$calendar['id'])); + } + + $result .= ''; + } + } + } + } else { + $result = ''; + } + + echo ''; + echo $result; + echo ''; + echo ''; + echo $result; + echo ''; + echo ''; + + echo ''; + $i = 0; + foreach ($users_in_course as $user) { + $class = ''; + if ($i%2 == 0) { + $class = 'row_even'; + } else { + $class = 'row_odd'; + } + echo ''; + + if (count($attendant_calendar) > 0 ) { + foreach ($attendant_calendar as $calendar) { + $checked = 'checked'; + $presence = -1; + + if (isset($users_presence[$user['user_id']][$calendar['id']]['presence'])) { + $presence = $users_presence[$user['user_id']][$calendar['id']]['presence']; + if (intval($presence) == 1) { + $checked = 'checked'; + } else { + $checked = ''; + } } else { - $result = ''; + //if the user wasn't registered at that time, consider unchecked + if ($next_attendance_calendar_datetime == 0 || $calendar['date_time'] < $next_attendance_calendar_datetime) { + $checked = ''; + } } - ?> - - - - - - - - - - - '; + echo '
'; + echo '
'; + if (api_is_allowed_to_edit(null, true)) { + if (!$is_locked_attendance || api_is_platform_admin()) { + echo ''; + echo ''; + } else { + echo $presence ? Display::return_icon('checkbox_on.gif',get_lang('Presence')) : Display::return_icon('checkbox_off.gif',get_lang('Presence')); + } } else { - $class = 'row_odd'; + switch($presence) { + case 1: + echo Display::return_icon('accept.png',get_lang('Attended')); + break; + case 0: + echo Display::return_icon('exclamation.png',get_lang('NotAttended')); + break; + case -1: + //echo Display::return_icon('warning.png',get_lang('NotAttended')); + break; + } } - ?> -
- 0 ) { - - foreach ($attendant_calendar as $calendar) { - $checked = 'checked'; - $presence = null; - - if (isset($users_presence[$user['user_id']][$calendar['id']]['presence'])) { - $presence = $users_presence[$user['user_id']][$calendar['id']]['presence']; - if (intval($presence) == 1) { - $checked = 'checked'; - } else { - $checked = ''; - } - } else { - //if the user wasn't registered at that time, consider unchecked - if ($next_attendance_calendar_datetime == 0 || $calendar['date_time'] < $next_attendance_calendar_datetime) { - $checked = ''; - } - } - $disabled = 'disabled'; - $style_td = ''; - - if ($next_attendance_calendar_id == $calendar['id']) { - if ($i%2==0) - $style_td = 'background-color:#eee;'; - else - $style_td = 'background-color:#dcdcdc;'; - $disabled = ''; - } - ?> - - - - - - - - -
'; - $result .= '
'.$datetime.' '; - $result .= ''.(!$is_locked_attendance || api_is_platform_admin()?$img_lock:'').''; - - if ($is_locked_attendance == false) { - $result .= '
'.$input_hidden.'
'; + $result .= '
'.$datetime.' '; + + if (api_is_allowed_to_edit(null, true)) { + $result .= ''.(!$is_locked_attendance || api_is_platform_admin()?$img_lock:'').''; + } + + if ($is_locked_attendance == false) { + if (api_is_allowed_to_edit(null, true)) { + $result .= '
'.$input_hidden.'
'; + $result .= Display::return_icon('attendance_calendar.png',get_lang('AttendanceCalendar'),'',ICON_SIZE_MEDIUM).' '.get_lang('GoToAttendanceCalendar').'
'; - $result .= Display::return_icon('attendance_calendar.png',get_lang('AttendanceCalendar'),'',ICON_SIZE_MEDIUM).' '.get_lang('GoToAttendanceCalendar').'
-
-
- - /> - -
-
-
-
-
 
-
-
- - + echo ''; + echo ''; + echo ''; + } + } else { + echo ''; + echo '
'; + echo '
 
+
+ '; + } + echo ''; + $i++ ; + } + echo ''; + echo ''; + ?>
- - + + +
'.get_lang('ThereAreNoRegisteredLearnersInsidetheCourse').'', false); } } else { + echo Display::page_header(get_lang('AttendanceSheetReport')); // View for students -?> -

+?>
@@ -362,7 +383,7 @@ if (api_is_allowed_to_edit(null, true)) { if (!empty($users_presence)) { $i = 0; - foreach($users_presence[$user_id] as $presence) { + foreach ($users_presence[$user_id] as $presence) { $class = ''; if ($i%2==0) {$class = 'row_even';} else {$class = 'row_odd';} diff --git a/main/attendance/index.php b/main/attendance/index.php index 8fa6f53cd7..087698b7b8 100644 --- a/main/attendance/index.php +++ b/main/attendance/index.php @@ -40,7 +40,8 @@ $actions = array( 'attendance_delete', 'attendance_delete_select', 'attendance_restore', - 'attendance_sheet_export_to_pdf' + 'attendance_sheet_export_to_pdf', + 'attendance_sheet_list_no_edit' ); $actions_calendar = array('calendar_list', 'calendar_add', 'calendar_edit', 'calendar_delete', 'calendar_all_delete'); @@ -249,9 +250,12 @@ switch ($action) { api_not_allowed(); } break; - case 'attendance_sheet_list': - $attendance_controller->attendance_sheet($action, $attendance_id, $student_id); + case 'attendance_sheet_list': + $attendance_controller->attendance_sheet($action, $attendance_id, $student_id, true); break; + case 'attendance_sheet_list_no_edit': + $attendance_controller->attendance_sheet($action, $attendance_id, $student_id, false); + break; case 'attendance_sheet_export_to_pdf': $attendance_controller->attendance_sheet_export_to_pdf($action, $attendance_id, $student_id, $course_id); break; diff --git a/main/inc/lib/attendance.lib.php b/main/inc/lib/attendance.lib.php index b482e11f24..3169be404f 100644 --- a/main/inc/lib/attendance.lib.php +++ b/main/inc/lib/attendance.lib.php @@ -106,17 +106,17 @@ class Attendance $active_plus = 'att.active = 1'; if (api_is_platform_admin()) { - $active_plus = ' 1=1 '; + $active_plus = ' 1 = 1 '; } $sql = "SELECT - att.id AS col0, - att.name AS col1, - att.description AS col2, - att.attendance_qualify_max AS col3, - att.locked AS col4, - att.active AS col5, - att.session_id + att.id AS col0, + att.name AS col1, + att.description AS col2, + att.attendance_qualify_max AS col3, + att.locked AS col4, + att.active AS col5, + att.session_id FROM $tbl_attendance att WHERE c_id = $course_id AND $active_plus $condition_session ORDER BY col$column $direction LIMIT $from,$number_of_items "; @@ -140,11 +140,18 @@ class Attendance if (api_get_session_id() == $attendance[6]) { $session_star = api_get_session_image(api_get_session_id(), $user_info['status']); } - if ($attendance[5] == 1) { - $attendance[1] = ''.$attendance[1].''.$session_star; - } else { - $attendance[1] = ''.$attendance[1].''.$session_star; - } + if ($attendance[5] == 1) { + if (api_is_allowed_to_edit(null, true)) { + //Link to edit + $attendance[1] = ''.$attendance[1].''.$session_star; + } else { + //Link to view + $attendance[1] = ''.$attendance[1].''.$session_star; + } + + } else { + $attendance[1] = ''.$attendance[1].''.$session_star; + } $attendance[3] = '
'.$attendance[3].'
'; if (api_is_allowed_to_edit(null, true)) { $actions = ''; @@ -156,7 +163,7 @@ class Attendance $actions .= ''.Display::return_icon('delete.png',get_lang('Delete'), array(), ICON_SIZE_SMALL).''; } else { $actions .= ''.Display::return_icon('invisible.png',get_lang('Restore'), array(), ICON_SIZE_SMALL).''; - $attendance[2] = ''.$attendance[2].''; + $attendance[2] = ''.$attendance[2].''; } } else { $is_locked_attendance = self::is_locked_attendance($attendance[0]); @@ -1050,30 +1057,15 @@ class Attendance return $result; } - /** * check if an attendance is locked * @param int attendance id * @param bool */ - public function is_locked_attendance($attendance_id) { + public static function is_locked_attendance($attendance_id) { //use gradebook lock $result = api_resource_is_locked_by_gradebook($attendance_id, LINK_ATTENDANCE); - return $result; - - /* - $attendance_id = intval($attendance_id); - $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE); - $course_id = api_get_course_int_id(); - - $sql = "SELECT id FROM $tbl_attendance WHERE c_id = $course_id AND id = $attendance_id AND locked = 1"; - $rs = Database::query($sql); - $result = false; - - if (Database::num_rows($rs) > 0) { - $result = true; - } - return $result;*/ + return $result; } /** diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index 8f4461876d..1acc035ced 100644 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -2616,7 +2616,7 @@ function api_is_allowed_to_session_edit($tutor = false, $coach = false) { // Get the session visibility $session_visibility = api_get_session_visibility($session_id); // if 5 the session is still available - + //@todo We could load the session_rel_course_rel_user permission to increase the level of detail. //echo api_get_user_id(); //echo api_get_course_id();