find($attendanceId); } // get calendar id $calendarId = ''; $calendarEntity = null; if (isset($_GET['calendar_id'])) { $calendarId = (int) ($_GET['calendar_id']); /** @var CAttendanceCalendar $calendarEntity */ $calendarEntity = Database::getManager()->getRepository(CAttendanceCalendar::class)->find($calendarId); } $token = Security::get_token(); // instance attendance object for using like library here $attendance = new Attendance(); $htmlHeadXtra[] = ''; $tpl = new Template(get_lang('Attendance')); $student_param = ''; $student_id = null; if (api_is_drh() && isset($_GET['student_id'])) { $student_id = (int) ($_GET['student_id']); $student_param = '&student_id='.$student_id; $student_info = api_get_user_info($student_id); $interbreadcrumb[] = [ 'url' => api_get_path(WEB_CODE_PATH).'my_space/myStudents.php?student='.$student_id, 'name' => $student_info['complete_name'], ]; } if (api_is_in_gradebook()) { $interbreadcrumb[] = [ 'url' => api_get_path(WEB_CODE_PATH).'gradebook/index.php?'.api_get_cidreq(), 'name' => get_lang('Assessments'), ]; } $interbreadcrumb[] = [ 'url' => 'index.php?'.api_get_cidreq().'&action=attendance_list&'.$student_param, 'name' => get_lang('Attendances'), ]; if ($attendanceEntity) { $interbreadcrumb[] = ['url' => '#', 'name' => $attendanceEntity->getTitle()]; } if ('calendar_list' === $action || 'calendar_edit' === $action) { $interbreadcrumb[] = [ 'url' => 'index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendanceId, 'name' => $attendanceEntity->getTitle(), ]; $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Attendance calendar')]; } $allowToEdit = api_is_allowed_to_edit(null, true); $currentUrl = api_get_path(WEB_CODE_PATH).'attendance/index.php?'.api_get_cidreq(); $content = ''; switch ($action) { case 'attendance_list': if ($allowToEdit) { $actions = ''; $actions .= Display::getMdiIcon('av-timer', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Create a new attendance list')); $actions .= ''; $content .= Display::toolbarAction('toolbar', [$actions]); } if (0 === $attendance->getNumberOfAttendances()) { $attendance->set_title(get_lang('Attendances')); $attendance->set_description(get_lang('Attendances')); $attendance->attendance_add(); } $default_column = isset($default_column) ? $default_column : null; $parameters = $parameters ?? []; $table = new SortableTable( 'attendance_list', ['Attendance', 'getNumberOfAttendances'], ['Attendance', 'getAttendanceData'], $default_column ); $table->set_additional_parameters($parameters); $table->set_header(0, '', false, ['style' => 'width:20px;']); $table->set_header(1, get_lang('Name'), true); $table->set_header(2, get_lang('Description'), true); $table->set_header(3, get_lang('# attended'), true, ['style' => 'width:90px;']); if (api_is_allowed_to_edit(null, true)) { $table->set_header(4, get_lang('Detail'), false, ['style' => 'text-align:center']); $actions = [ 'attendance_set_invisible_select' => get_lang('Set invisible'), 'attendance_set_visible_select' => get_lang('Set visible'), ]; $allow = api_get_setting('allow_delete_attendance'); if ('true' === $allow) { $actions['attendance_delete_select'] = get_lang('Delete all selected attendances'); } $table->set_form_actions($actions); } if ($table->get_total_number_of_items() > 0) { $content .= $table->return_table(); } break; case 'attendance_add': if (!$allowToEdit) { api_not_allowed(true); } $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Create a new attendance list')]; $form = new FormValidator( 'attendance_add', 'POST', $currentUrl.'&action=attendance_add&' ); $attendance->setAttendanceForm($form); if ($form->validate()) { $attendance->set_title($_POST['title']); $attendance->set_description($_POST['description']); $attendance->set_attendance_qualify_title($_POST['attendance_qualify_title']); $attendance->set_attendance_weight($_POST['attendance_weight']); $link_to_gradebook = false; if (isset($_POST['attendance_qualify_gradebook']) && 1 == $_POST['attendance_qualify_gradebook'] ) { $link_to_gradebook = true; } $attendance->category_id = isset($_POST['category_id']) ? $_POST['category_id'] : 0; $attendanceId = $attendance->attendance_add($link_to_gradebook); if ($attendanceId) { SkillModel::saveSkills($form, ITEM_TYPE_ATTENDANCE, $attendanceId); header('Location: '.$currentUrl.'&action=calendar_add&attendance_id='.$attendanceId); exit; } header('Location: '.$currentUrl); exit; } else { $content = $form->returnForm(); } break; case 'attendance_edit': if (!$allowToEdit) { api_not_allowed(true); } $form = new FormValidator( 'attendance_edit', 'POST', 'index.php?action=attendance_edit&'.api_get_cidreq().'&attendance_id='.$attendanceId ); $attendance->setAttendanceForm($form, $attendanceEntity); if (!empty($_POST['title'])) { $attendance->set_title($_POST['title']); $attendance->set_description($_POST['description']); if (isset($_POST['attendance_qualify_title'])) { $attendance->set_attendance_qualify_title($_POST['attendance_qualify_title']); } if (isset($_POST['attendance_weight'])) { $attendance->set_attendance_weight($_POST['attendance_weight']); } $attendance->category_id = isset($_POST['category_id']) ? $_POST['category_id'] : ''; $link_to_gradebook = false; if (isset($_POST['attendance_qualify_gradebook']) && 1 == $_POST['attendance_qualify_gradebook'] ) { $link_to_gradebook = true; } $attendance->attendance_edit($attendanceEntity, $link_to_gradebook); SkillModel::saveSkills($form, ITEM_TYPE_ATTENDANCE, $attendanceId); Display::addFlash(Display::return_message(get_lang('Update successful'))); Security::clear_token(); header('Location:index.php?action=attendance_list&'.api_get_cidreq()); exit; } else { $content = $form->returnForm(); } break; case 'attendance_set_visible': case 'attendance_set_visible_select': if (!$allowToEdit) { api_not_allowed(true); } if (isset($_POST['id']) && is_array($_POST['id'])) { foreach ($_POST['id'] as $id) { $attendanceEntity = $repo->find($id); $attendance->changeVisibility($attendanceEntity, 1); } } else { $attendance->changeVisibility($attendanceEntity, 1); } Display::addFlash(Display::return_message(get_lang('Updated'))); header('Location: '.$currentUrl); exit; break; case 'attendance_set_invisible': case 'attendance_set_invisible_select': if (isset($_POST['id']) && is_array($_POST['id'])) { foreach ($_POST['id'] as $id) { $attendanceEntity = $repo->find($id); $attendance->changeVisibility($attendanceEntity, 0); } } else { $attendance->changeVisibility($attendanceEntity, 0); } Display::addFlash(Display::return_message(get_lang('Updated'))); header('Location: '.$currentUrl); exit; break; case 'attendance_delete_select': case 'attendance_delete': if (!$allowToEdit) { api_not_allowed(true); } if (isset($_POST['id']) && is_array($_POST['id'])) { foreach ($_POST['id'] as $id) { $attendanceEntity = $repo->find($id); $attendance->attendance_delete($attendanceEntity); } } else { $attendance->attendance_delete($attendanceEntity); } Display::addFlash(Display::return_message(get_lang('Deleted'))); header('Location: '.$currentUrl); exit; break; case 'attendance_sheet_list_no_edit': case 'attendance_sheet_list': $edit = true; if ('attendance_sheet_list_no_edit' === $action) { $edit = false; } $content = $attendance->getCalendarSheet($edit, $attendanceEntity, $student_id); $tpl->assign('table', $content); $content = $tpl->fetch('@ChamiloCore/Attendance/sheet.html.twig'); break; case 'attendance_sheet_export_to_pdf': $attendance->attendance_sheet_export_to_pdf( $attendanceId, $student_id, api_get_course_id() ); break; case 'attendance_sheet_add': if (!$allowToEdit) { api_not_allowed(true); } if (isset($_POST['hidden_input'])) { foreach ($_POST['hidden_input'] as $cal_id) { $users_present = []; if (isset($_POST['check_presence'][$cal_id])) { $users_present = $_POST['check_presence'][$cal_id]; } $attendance->attendance_sheet_add( $cal_id, $users_present, $attendanceEntity ); } } Display::addFlash(Display::return_message(get_lang('Updated'))); header('Location: '.$currentUrl.'&action=attendance_sheet_list&attendance_id='.$attendanceId); exit; break; case 'lock_attendance': case 'unlock_attendance': if (!$allowToEdit) { api_not_allowed(true); } if ('lock_attendance' === $action) { $attendance->lock($attendanceEntity); } else { $attendance->lock($attendanceEntity, false); } Display::addFlash(Display::return_message(get_lang('Updated'))); header('Location: '.$currentUrl); exit; break; case 'calendar_add': $groupList = isset($_POST['groups']) ? [$_POST['groups']] : []; $interbreadcrumb[] = [ 'url' => 'index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendanceId, 'name' => $attendanceEntity->getTitle(), ]; $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Add a date and time')]; if (!$allowToEdit) { api_not_allowed(true); } if ('POST' === strtoupper($_SERVER['REQUEST_METHOD'])) { if (!isset($_POST['cancel'])) { if (isset($_POST['repeat'])) { //@todo check this error_logs $start_datetime = api_strtotime( api_get_utc_datetime($_POST['date_time']), 'UTC' ); $end_datetime = api_strtotime(api_get_utc_datetime($_POST['end_date_time'].' 23:59:59'), 'UTC'); $checkdate = api_is_valid_date(api_get_utc_datetime($_POST['end_date_time'].' 23:59:59')); $repeat_type = $_POST['repeat_type']; if (($end_datetime > $start_datetime) && $checkdate) { $attendance->attendance_repeat_calendar_add( $attendanceEntity, $start_datetime, $end_datetime, $repeat_type, $groupList ); $action = 'calendar_list'; } else { if (!$checkdate) { $data['error_checkdate'] = true; } else { $data['error_repeat_date'] = true; } $data['repeat'] = true; $action = 'calendar_add'; } } else { $datetime = $_POST['date_time']; $datetimezone = api_get_utc_datetime($datetime); if (!empty($datetime)) { $attendance->set_date_time($datetimezone); $attendance->attendance_calendar_add($attendanceEntity, $groupList); } } } header('Location: '.$currentUrl.'&action=attendance_sheet_list&attendance_id='.$attendanceId); exit; } else { $groupList = GroupManager::get_group_list(null, null, 1); $groupIdList = ['--']; foreach ($groupList as $group) { $groupIdList[$group['iid']] = $group['title']; } // calendar add form $form = new FormValidator( 'attendance_calendar_add', 'POST', 'index.php?action=calendar_add&attendance_id='.$attendanceId.'&'.api_get_cidreq(), '' ); $form->addElement('header', get_lang('Add a date time')); $form->addDateTimePicker( 'date_time', [get_lang('Start Date')], ['id' => 'date_time'] ); $defaults['date_time'] = date('Y-m-d H:i', api_strtotime(api_get_local_time())); $form->addElement( 'checkbox', 'repeat', null, get_lang('Repeat date'), [ 'onclick' => "javascript: if(this.checked){document.getElementById('repeat-date-attendance').style.display='block';}else{document.getElementById('repeat-date-attendance').style.display='none';}", ] ); $defaults['repeat'] = isset($repeat) ? $repeat : null; if ($defaults['repeat']) { $form->addElement('html', '
'); } else { $form->addElement('html', ''); $defaults['repeat_type'] = 'weekly'; $form->addSelect('groups', get_lang('Group'), $groupIdList); $form->addButtonCreate(get_lang('Save')); $form->setDefaults($defaults); $content = $form->returnForm(); } break; case 'calendar_edit': if (!$allowToEdit) { api_not_allowed(true); } if ('POST' === strtoupper($_SERVER['REQUEST_METHOD'])) { if (!isset($_POST['cancel'])) { $attendance->set_date_time(api_get_utc_datetime($_POST['date_time'])); $attendance->attendance_calendar_edit($calendarId, $attendanceEntity); Display::addFlash(Display::return_message(get_lang('Updated'))); } header('Location: '.$currentUrl.'&action=calendar_list&attendance_id='.$attendanceId); exit; } else { // calendar edit form $content .= '
'; $form = new FormValidator( 'attendance_calendar_edit', 'POST', 'index.php?action=calendar_edit&attendance_id='.$attendanceId.'&calendar_id='.$calendarId.'&'.api_get_cidreq(), '' ); $form->addDateTimePicker( 'date_time', [get_lang('Date')], ['form_name' => 'attendance_calendar_edit'], 5 ); $defaults['date_time'] = $calendarEntity->getDateTime()->format('Y-m-d H:i:s'); $form->addButtonSave(get_lang('Save')); $form->addButtonCancel(get_lang('Cancel'), 'cancel'); $form->setDefaults($defaults); $content .= $form->returnForm(); $content .= '
'; } break; case 'calendar_all_delete': if (!$allowToEdit) { api_not_allowed(true); } $attendance->attendance_calendar_delete(0, $attendanceEntity, true); Display::addFlash(Display::return_message(get_lang('Deleted'))); header('Location: '.$currentUrl.'&action=calendar_list&attendance_id='.$attendanceId); exit; break; case 'calendar_delete': if (!$allowToEdit) { api_not_allowed(true); } $attendance->attendance_calendar_delete($calendarId, $attendanceEntity); Display::addFlash(Display::return_message(get_lang('Deleted'))); header('Location: '.$currentUrl.'&action=calendar_list&attendance_id='.$attendanceId); exit; break; case 'calendar_list': $groupList = isset($_POST['groups']) ? [$_POST['groups']] : []; $attendance_calendar = $attendance->get_attendance_calendar( $attendanceId, 'all', null, null, true ); $is_locked_attendance = $attendance->is_locked_attendance($attendanceId); if (!$is_locked_attendance || api_is_platform_admin()) { $actions = ''; if ('calendar_add' === $action) { $actions .= ''. Display::getMdiIcon(ActionIcon::BACK, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Attendance calendar')).''; } else { $actions .= ''. Display::getMdiIcon(ActionIcon::BACK, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Attendance sheet')).''; if (api_is_allowed_to_edit()) { $actions .= ''. Display::getMdiIcon(ActionIcon::ADD, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Add a date and time')).''; $actions .= ''. Display::getMdiIcon(ActionIcon::RESET, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Clean the calendar of all lists')).''; } } $content .= Display::toolbarAction('toolbar', [$actions]); } $message_information = get_lang('The attendance calendar allows you to register attendance lists (one per real session the students need to attend). Add new attendance lists here.'); if (!empty($message_information)) { $message = ''.get_lang('Information').'
'; $message .= $message_information; $content .= Display::return_message($message, 'normal', false); } if (isset($error_repeat_date) && $error_repeat_date) { $message = get_lang('End date must be more than the start date'); $content .= Display::return_message($message, 'error', false); } if (isset($error_checkdate) && $error_checkdate) { $message = get_lang('Invalid date'); $content .= Display::return_message($message, 'error', false); } // Calendar list $groupList = GroupManager::get_group_list(); $groupIdList = ['--']; foreach ($groupList as $group) { $groupIdList[$group['iid']] = $group['title']; } $content .= Display::page_subheader(get_lang('Calendar list of attendances')); $content .= ''; } break; case 'calendar_logins': if (api_is_course_admin() || api_is_drh()) { $result = $attendance->getAttendanceBaseInLogin(false, true); $actions = ''. Display::getMdiIcon(ActionIcon::BACK, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('AttendanceCalendar')). ''; $content .= Display::toolbarAction('toolbar', [$actions]); $content .= $result['form']; $content .= $result['table']; } break; } $tpl->assign('content', $content); //$tpl->assign('actions', $toolbar); $tpl->display_one_col_template();