123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- * View (MVC patter) for attendance sheet (list, edit, add)
- * @author Christian Fasanando <christian1827@gmail.com>
- * @author Julio Montoya reworked 2010
- * @package chamilo.attendance
- */
- // protect a course script
- api_protect_course_script(true);
- if (api_is_allowed_to_edit(null, true) || api_is_coach(api_get_session_id(), api_get_course_int_id())) {
- $param_gradebook = '';
- if (isset($_SESSION['gradebook'])) {
- $param_gradebook = '&gradebook='.$_SESSION['gradebook'];
- }
- $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'),
- 'all_done' => get_lang('AllDone'),
- 'all_not_done' => get_lang('AllNotDone')
- );
- $today = api_convert_and_format_date(null, DATE_FORMAT_SHORT);
- $exists_attendance_today = false;
- if (!empty($attendant_calendar_all)) {
- $values[''] = '---------------';
- foreach($attendant_calendar_all as $attendance_date) {
- if ($today == $attendance_date['date']) {
- $exists_attendance_today = true;
- }
- $values[$attendance_date['id']] = $attendance_date['date_time'];
- }
- }
- if (!$exists_attendance_today) {
- Display::display_warning_message(get_lang('ThereIsNoClassScheduledTodayTryPickingAnotherDay'));
- }
- $form->addElement('select', 'filter', get_lang('Filter'), $values, array('id' => 'filter_id'));
- $form->addElement('style_submit_button', null, get_lang('Filter'), 'class="filter"');
- if (isset($_REQUEST['filter'])) {
- if (in_array($_REQUEST['filter'], array_keys($values))) {
- $default_filter = $_REQUEST['filter'];
- }
- } else {
- $default_filter = 'today';
- }
- $renderer = $form->defaultRenderer();
- $renderer->setElementTemplate('{label} {element} ');
- $form->setDefaults(array('filter'=>$default_filter));
- if (!$is_locked_attendance || api_is_platform_admin()) {
- echo '<div class="actions">';
- echo '<a style="float:left;" href="index.php?'.api_get_cidreq().'&action=calendar_list&attendance_id='.$attendance_id.$param_gradebook.'">'.
- Display::return_icon('attendance_calendar.png',get_lang('AttendanceCalendar'),'',ICON_SIZE_MEDIUM).'</a>';
- if (count($users_in_course) > 0) {
- $form->display();
- }
- echo '<a id="pdf_export" style="float:left;" href="index.php?'.api_get_cidreq().'&action=attendance_sheet_export_to_pdf&attendance_id='.$attendance_id.$param_gradebook.'&filter='.$default_filter.'">'.
- Display::return_icon('pdf.png',get_lang('ExportToPDF'),'',ICON_SIZE_MEDIUM).'</a>';
- echo '</div>';
- }
- $message_information = get_lang('AttendanceSheetDescription');
- if (!empty($message_information)) {
- $message = '<strong>'.get_lang('Information').'</strong><br />';
- $message .= $message_information;
- Display::display_normal_message($message, false);
- }
- if ($is_locked_attendance) {
- Display::display_warning_message(get_lang('TheAttendanceSheetIsLocked'), false);
- }
- $param_filter = '&filter='.Security::remove_XSS($default_filter);
- if (count($users_in_course) > 0) {
- foreach ($attendance_states as $id => $state) {
- echo $attendance_obj->get_attendance_state_button($id, true).' ';
- }
- ?>
- <script>
- var original_url = '';
- $("#filter_id").on('change', function() {
- filter = $(this).val();
- if (original_url == '') {
- original_url = $("#pdf_export").attr('href');
- }
- new_url = original_url + "&filter=" +filter
- $("#pdf_export").attr('href', new_url);
- });
- function UpdateTableHeaders() {
- $("div.divTableWithFloatingHeader").each(function() {
- var originalHeaderRow = $(".tableFloatingHeaderOriginal", this);
- var floatingHeaderRow = $(".tableFloatingHeader", this);
- var offset = $(this).offset();
- var scrollTop = $(window).scrollTop();
- if ((scrollTop > offset.top) && (scrollTop < offset.top + $(this).height())) {
- floatingHeaderRow.css("visibility", "hidden");
- var topbar = 0;
- if ($("#topbar").length != 0) {
- topbar = $("#topbar").height();
- } else {
- if ($(".subnav").length != 0) {
- topbar = $(".subnav").height();
- }
- }
- var top_value = Math.min(scrollTop - offset.top, $(this).height() - floatingHeaderRow.height()) + topbar;
- floatingHeaderRow.css("top", top_value + "px");
- // Copy cell widths from original header
- $("th", floatingHeaderRow).each(function(index) {
- var cellWidth = $("th", originalHeaderRow).eq(index).css('width');
- $(this).css('width', cellWidth);
- });
- // Copy row width from whole table
- floatingHeaderRow.css("width", $(this).css("width"));
- floatingHeaderRow.css("visibility", "visible");
- floatingHeaderRow.css("z-index", "1000");
- originalHeaderRow.css("height", "40px");
- } else {
- floatingHeaderRow.css("visibility", "hidden");
- floatingHeaderRow.css("top", "0px");
- }
- });
- }
- function save_checkboxes() {
- $('#form_attendance_sheet').submit();
- }
- $(document).ready(function() {
- $('.switch').click(function() {
- var state = 0;
- var my_class = 'btn';
- var current_class = '';
- var my_button = $(this);
- if (my_button.is('.disabled')) {
- return false;
- }
- if (my_button.is('.btn')) {
- current_class = 'btn';
- state = 1;
- my_class = 'btn-success';
- }
- if (my_button.is('.btn-success')) {
- current_class = 'btn-success';
- state = 0;
- my_class = 'btn-danger';
- }
- if (my_button.is('.btn-danger')) {
- current_class = 'btn-danger';
- state = 2;
- my_class = 'btn-info';
- }
- if (my_button.is('.btn-info')) {
- current_class = 'btn-info';
- state = 3;
- my_class = 'btn-warning';
- }
- if (my_button.is('.btn-warning')) {
- current_class = 'btn-warning';
- state = 4;
- my_class = 'btn';
- }
- var id = my_button.attr('id');
- $('#hidden_'+id).attr('value', 'state_'+state+'_'+id);
- my_button.attr('data-state', state);
- my_button.removeClass(current_class);
- my_button.addClass('btn b1');
- my_button.addClass(my_class);
- });
- $("table.tableWithFloatingHeader").each(function() {
- $(this).wrap("<div class=\"divTableWithFloatingHeader\" style=\"position:relative\"></div>");
- var originalHeaderRow = $("tr:first", this)
- originalHeaderRow.before(originalHeaderRow.clone());
- var clonedHeaderRow = $("tr:first", this)
- clonedHeaderRow.addClass("tableFloatingHeader");
- clonedHeaderRow.css("position", "absolute");
- clonedHeaderRow.css("top", "0px");
- clonedHeaderRow.css("left", $(this).css("margin-left"));
- clonedHeaderRow.css("visibility", "hidden");
- originalHeaderRow.addClass("tableFloatingHeaderOriginal");
- });
- UpdateTableHeaders();
- $(window).scroll(UpdateTableHeaders);
- $(window).resize(UpdateTableHeaders);
- });
- </script>
- <form id="form_attendance_sheet" method="post" action="index.php?action=attendance_sheet_add&<?php echo api_get_cidreq().$param_gradebook.$param_filter ?>&attendance_id=<?php echo $attendance_id?>" >
- <div class="attendance-sheet-content" style="width:100%;background-color:#E1E1E1;margin-top:20px;">
- <div class="divTableWithFloatingHeader attendance-users-table" style="width:45%;float:left;margin:0px;padding:0px;">
- <table class="tableWithFloatingHeader data_table" width="100%">
- <thead>
- <tr class="tableFloatingHeader" style="position: absolute; top: 0px; left: 0px; visibility: hidden; margin:0px;padding:0px" >
- <th width="10px"><?php echo '#'; ?></th>
- <th width="10px"><?php echo get_lang('Photo')?></th>
- <th width="100px"><?php echo get_lang('LastName')?></th>
- <th width="100px"><?php echo get_lang('FirstName')?></th>
- <th width="100px"><?php echo get_lang('AttendancesFaults')?></th>
- </tr>
- <tr class="tableFloatingHeaderOriginal" >
- <th height="65px" width="10px"><?php echo '#';?></th>
- <th width="10px"><?php echo get_lang('Photo')?></th>
- <th width="150px"><?php echo get_lang('LastName')?></th>
- <th width="140px"><?php echo get_lang('FirstName')?></th>
- <th width="92px"><?php echo get_lang('AttendancesFaults')?></th>
- </tr>
- </thead>
- <tbody>
- <?php
- $i = 1;
- $class = '';
- foreach ($users_in_course as $data) {
- $faults = 0;
- if ($i%2 == 0) {
- $class='row_odd';
- } else {
- $class='row_even';
- }
- $username = api_htmlentities(sprintf(get_lang('LoginX'), $data['username']), ENT_QUOTES);
- ?>
- <tr class="<?php echo $class ?>">
- <td><center><?php echo $i ?></center></td>
- <td><?php echo $data['photo'] ?></td>
- <td><span title="<?php echo $username ?>"><?php echo $data['lastname'] ?></span></td>
- <td><?php echo $data['firstname'] ?></td>
- <td>
- <div class="attendance-faults-bar">
- <?php echo Display::label($data['attendance_result'], $data['result_color_bar']); ?>
- </div>
- </td>
- </tr>
- <?php
- $i++;
- }
- ?>
- </tbody>
- </table>
- </div>
- <?php
- echo '<div class="divTableWithFloatingHeader attendance-calendar-table" style="margin:0px;padding:0px;float:left;width:55%;overflow:auto;overflow-y:hidden;">';
- echo '<table class="tableWithFloatingHeader data_table" width="100%">';
- echo '<thead>';
- $result = null;
- if (count($attendant_calendar) > 0 ) {
- foreach ($attendant_calendar as $calendar) {
- $date = $calendar['date'];
- $time = $calendar['time'];
- $datetime = $date.'<br />'.$time;
- $datetime = api_format_date($calendar['date_time'], DATE_FORMAT_NUMBER_NO_YEAR);
- $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 = '<font color="blue">'.$datetime.'</font>';
- }
- $disabled_check = 'disabled = "true"';
- if ($next_attendance_calendar_id == $calendar['id']) {
- $input_hidden = '<input type="hidden" id="hidden_input_'.$calendar['id'].'" name="hidden_input[]" value="'.$calendar['id'].'" />';
- $disabled_check = '';
- $img_lock = Display::return_icon('unlock.gif',get_lang('DateLock'),array('class'=>'img_unlock','id'=>'datetime_column_'.$calendar['id']));
- } else {
- $input_hidden = '<input type="hidden" id="hidden_input_'.$calendar['id'].'" name="hidden_input[]" value="" />';
- }
- $result .= '<th width="800px" style="text-align:center">';
- $result .= '<center><div style="width:40px;">'.$datetime.'<br />';
- if (api_is_allowed_to_edit(null, true)) {
- $result .= '<span id="attendance_lock" style="cursor:pointer">'.(!$is_locked_attendance || api_is_platform_admin()?$img_lock:'').'</span>';
- }
- if ($is_locked_attendance == false) {
- if (api_is_allowed_to_edit(null, true)) {
- $result .= $input_hidden.'</div><center></th>';
- }
- }
- }
- } else {
- $result = '<th width="2000px"><span><a href="index.php?'.api_get_cidreq().'&action=calendar_list&attendance_id='.$attendance_id.$param_gradebook.'">';
- $result .= Display::return_icon('attendance_calendar.png',get_lang('AttendanceCalendar'),'',ICON_SIZE_MEDIUM).' '.get_lang('GoToAttendanceCalendar').'</a></span></th>';
- }
- echo '<tr class="tableFloatingHeader row_odd" style="position: absolute; top: 0px; left: 0px; visibility: hidden; margin:0px;padding:0px">';
- echo $result;
- echo '</tr>';
- echo '<tr class="tableWithFloatingHeader row_odd">';
- echo $result;
- echo '</tr>';
- echo '</thead>';
- echo '<tbody>';
- $i = 0;
- $default_presence_value = $attendance_obj->get_default_attendance_state();
- foreach ($users_in_course as $user) {
- $class = '';
- if ($i % 2 == 0) {
- $class = 'row_even';
- } else {
- $class = 'row_odd';
- }
- echo '<tr class="'.$class.'">';
- if (count($attendant_calendar) > 0 ) {
- foreach ($attendant_calendar as $calendar) {
- $presence = $default_presence_value;
- if (isset($users_presence[$user['user_id']][$calendar['id']]['presence'])) {
- $presence = isset($users_presence[$user['user_id']][$calendar['id']]['presence']) ? $users_presence[$user['user_id']][$calendar['id']]['presence'] : $default_presence_value;
- } 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) {
- $presence = $default_presence_value;
- }
- }
- $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 = '';
- }
- echo '<td style="'.$style_td.'" class="checkboxes_col_'.$calendar['id'].'">';
- echo '<div style="text-align:center; height:20px">';
- if (api_is_allowed_to_edit(null, true)) {
- if (!$is_locked_attendance || api_is_platform_admin()) {
- //echo '<input type="checkbox" name="check_presence['.$calendar['id'].'][]" value="'.$user['user_id'].'" '.$disabled.' '.$checked.' />';
- foreach ($attendance_states as $key => $state) {
- $input_checked = null;
- if ($key == $presence) {
- $input_checked = " checked=checked";
- }
- //echo Display::tag('label', '<input type="checkbox" name="check_presence['.$calendar['id'].'][]" value = "state_'.$key.'_'.$user['user_id'].'" '.$disabled.' '.$input_checked.' /> '.$state, array('class'=> 'checkbox'));
- }
- $link_id = 'link_'.$key.'_'.$user['user_id'].'_'.$calendar['id'];
- $attributes = array('id' => $link_id, 'class' => 'switch '.$disabled);
- echo $attendance_obj->get_attendance_state_button($presence, false, $attributes);
- echo '<input id = "hidden_'.$link_id.'" type="hidden" name="check_presence['.$calendar['id'].'][]" '.$input_checked.' value="'.$presence.'" />';
- echo '<span class="anchor_'.$calendar['id'].'"></span>';
- } else {
- echo $presence ? Display::return_icon('checkbox_on.gif',get_lang('Presence')) : Display::return_icon('checkbox_off.gif',get_lang('Presence'));
- }
- } else {
- 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;
- }
- }
- echo '</div>';
- echo '</td>';
- }
- } else {
- echo '<td class="checkboxes_col_'.$calendar['id'].'">';
- echo '<div style="height:20px">';
- echo '<center> </center>
- </div>
- </td>';
- }
- echo '</tr>';
- $i++ ;
- }
- echo '</tbody></table>';
- echo '</div></div>';
- ?>
- <div class="clear"></div>
- <div style="margin-top:20px;">
- <?php if (!$is_locked_attendance || api_is_platform_admin()) {
- if (api_is_allowed_to_edit(null, true)) {
- ?>
- <button onclick="save_checkboxes();" type="button" class="save"><?php echo get_lang('Save') ?></button>
- <?php }
- }
- ?>
- </div>
- </form>
- <?php
- } else {
- echo Display::display_warning_message('<a href="'.api_get_path(WEB_CODE_PATH).'user/user.php?'.api_get_cidreq().'">'.get_lang('ThereAreNoRegisteredLearnersInsidetheCourse').'</a>', false);
- }
- } else {
- echo Display::page_header(get_lang('AttendanceSheetReport'));
- // View for students
- ?>
- <?php if(!empty($users_presence)) { ?>
- <div>
- <table width="250px;">
- <tr>
- <td><?php echo get_lang('ToAttend').': ' ?></td>
- <td><center><div class="attendance-faults-bar" style="background-color:<?php echo (!empty($faults['color_bar'])?$faults['color_bar']:'none') ?>">
- <?php echo $faults['faults'].'/'.$faults['total'].' ('.$faults['faults_porcent'].'%)' ?></div></center>
- </td>
- </tr>
- </table>
- </div>
- <?php } ?>
- <table class="data_table">
- <tr class="row_odd" >
- <th><?php echo get_lang('Attendance')?></th>
- </tr>
- <?php
- if (!empty($users_presence)) {
- $i = 0;
- foreach ($users_presence[$user_id] as $presence) {
- $class = '';
- if ($i%2==0) {
- $class = 'row_even';
- } else {
- $class = 'row_odd';
- }
- ?>
- <tr class="<?php echo $class ?>">
- <td>
- <?php
- echo $attendance_obj->get_attendance_state_button($presence['presence']);
- //echo $presence['presence']?Display::return_icon('checkbox_on.gif',get_lang('Presence')):Display::return_icon('checkbox_off.gif',get_lang('Presence'))
- echo " ".$presence['date_time'] ?>
- </td>
- </tr>
- <?php }
- } else { ?>
- <tr><td>
- <center><?php echo get_lang('YouDoNotHaveDoneAttendances')?></center></td>
- </tr>
- <?php }
- ?>
- </table>
- <?php } ?>
|