/** * It's used to print attendance sheet * @param string action * @param int attendance id */ public function attendance_sheet_export_to_pdf($action, $attendance_id, $student_id = 0, $course_id = '') { $attendance = new Attendance(); $courseInfo = CourseManager::get_course_information($course_id); $attendance->set_course_id($courseInfo['code']); $data_array = array(); $data_array['attendance_id'] = $attendance_id; $data_array['users_in_course'] = $attendance->get_users_rel_course($attendance_id); $filter_type = 'today'; if (!empty($_REQUEST['filter'])) { $filter_type = $_REQUEST['filter']; } $my_calendar_id = null; if (is_numeric($filter_type)) { $my_calendar_id = $filter_type; $filter_type = 'calendar_id'; } $data_array['attendant_calendar'] = $attendance->get_attendance_calendar($attendance_id, $filter_type, $my_calendar_id); if (api_is_allowed_to_edit(null, true) || api_is_drh()) { $data_array['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_array['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id, $user_id); $data_array['faults'] = $attendance->get_faults_of_user($user_id, $attendance_id); $data_array['user_id'] = $user_id; } $data_array['next_attendance_calendar_id'] = $attendance->get_next_attendance_calendar_id($attendance_id); //Set headers pdf $courseCategory = CourseManager::get_course_category($courseInfo['category_code']); $teacherInfo = CourseManager::get_teacher_list_from_course_code($courseInfo['real_id']); $teacherName = null; foreach ($teacherInfo as $dados) { if ($teacherName != null) { $teacherName = $teacherName . " / "; } $teacherName .= $dados['firstname'] . " " . $dados['lastname']; } // Get data table - Marco - ordenacao fixa - just fullname $data_table = array(); $head_table = array('#', get_lang('Name')); foreach ($data_array['attendant_calendar'] as $class_day) { //$head_table[] = api_format_date($class_day['date_time'], DATE_FORMAT_SHORT).' <br />'.api_format_date($class_day['date_time'], TIME_NO_SEC_FORMAT); $head_table[] = api_format_date($class_day['date_time'], DATE_FORMAT_NUMBER_NO_YEAR); } $data_table[] = $head_table; $dataClass = array(); $max_dates_per_page = 10; $data_attendant_calendar = $data_array['attendant_calendar']; $data_users_presence = $data_array['users_presence']; $count = 1; if (!empty($data_array['users_in_course'])) { foreach ($data_array['users_in_course'] as $user) { $cols = 1; $result = array(); $result['count'] = $count; $result['full_name'] = api_get_person_name($user['firstname'], $user['lastname']); foreach ($data_array['attendant_calendar'] as $class_day) { if ($class_day['done_attendance'] == 1) { if ($data_users_presence[$user['user_id']][$class_day['id']]['presence'] == 1) { $result[$class_day['id']] = get_lang('UserAttendedSymbol'); } else { $result[$class_day['id']] = get_lang('UserNotAttendedSymbol'); } } else { $result[$class_day['id']] = " "; } $cols++; } $count++; $data_table[] = $result; } } $max_cols_per_page = 12; //10 dates + 2 name and number $max_dates_per_page = $max_dates_per_page_original = $max_cols_per_page - 2; //10 $rows = count($data_table); if ($cols > $max_cols_per_page) { $number_tables = round(($cols - 2) / $max_dates_per_page); $headers = $data_table[0]; $all = array(); $tables = array(); $changed = 1; for ($i = 0; $i <= $rows; $i++) { $row = $data_table[$i]; $key = 1; $max_dates_per_page = 10; $item = $data_table[$i]; $count_j = 0; if (!empty($item)) { foreach ($item as $value) { if ($count_j >= $max_dates_per_page) { $key++; $max_dates_per_page = $max_dates_per_page_original * $key; //magic hack $tables[$key][$i][] = $tables[1][$i][0]; $tables[$key][$i][] = $tables[1][$i][1]; } $tables[$key][$i][] = $value; $count_j++; } } } $content = null; if (!empty($tables)) { foreach ($tables as $sub_table) { $content .= Export::convert_array_to_html($sub_table) . '<br /><br />'; } } } else { $content .= Export::convert_array_to_html($data_table, array('header_attributes' => array('align' => 'center'))); } $params = array('filename' => get_lang('Attendance') . '-' . api_get_local_time(), 'pdf_title' => $courseInfo['title'], 'course_code' => $courseInfo['code'], 'add_signatures' => true, 'orientation' => 'landscape', 'pdf_teachers' => $teacherName, 'pdf_course_category' => $courseCategory['name'], 'format' => 'A4-L', 'orientation' => 'L'); Export::export_html_to_pdf($content, $params); exit; }
/** * This method is used for thematic advance control (update, insert or listing) * render to thematic_advance.php * @param string $action * */ public function thematic_advance($action) { $thematic = new Thematic(); $attendance = new Attendance(); $data = array(); $displayHeader = !empty($_REQUEST['display']) && $_REQUEST['display'] === 'no_header' ? false : true; // get data for attendance input select $attendance_list = $attendance->get_attendances_list(); $attendance_select = array(); $attendance_select[0] = get_lang('SelectAnAttendance'); foreach ($attendance_list as $attendance_id => $attendance_data) { $attendance_select[$attendance_id] = $attendance_data['name']; } $thematic_id = intval($_REQUEST['thematic_id']); $thematic_advance_id = isset($_REQUEST['thematic_advance_id']) ? intval($_REQUEST['thematic_advance_id']) : null; $thematic_advance_data = array(); switch ($action) { case 'thematic_advance_delete': if (!empty($thematic_advance_id)) { if (api_is_allowed_to_edit(null, true)) { $thematic->thematic_advance_destroy($thematic_advance_id); } header('Location: index.php'); exit; } break; case 'thematic_advance_list': if (!api_is_allowed_to_edit(null, true)) { echo ''; exit; } if (isset($_REQUEST['start_date_type']) && $_REQUEST['start_date_type'] == 1 && empty($_REQUEST['start_date_by_attendance']) || !empty($_REQUEST['duration_in_hours']) && !is_numeric($_REQUEST['duration_in_hours'])) { if ($_REQUEST['start_date_type'] == 1 && empty($_REQUEST['start_date_by_attendance'])) { $start_date_error = true; $data['start_date_error'] = $start_date_error; } if (!empty($_REQUEST['duration_in_hours']) && !is_numeric($_REQUEST['duration_in_hours'])) { $duration_error = true; $data['duration_error'] = $duration_error; } $data['action'] = $_REQUEST['action']; $data['thematic_id'] = $_REQUEST['thematic_id']; $data['attendance_select'] = $attendance_select; if (isset($_REQUEST['thematic_advance_id'])) { $data['thematic_advance_id'] = $_REQUEST['thematic_advance_id']; $thematic_advance_data = $thematic->get_thematic_advance_list($_REQUEST['thematic_advance_id']); $data['thematic_advance_data'] = $thematic_advance_data; } } else { if (api_is_allowed_to_edit(null, true)) { $thematic_advance_id = isset($_REQUEST['thematic_advance_id']) ? $_REQUEST['thematic_advance_id'] : null; $thematic_id = $_REQUEST['thematic_id']; $content = isset($_REQUEST['content']) ? $_REQUEST['content'] : null; $duration = isset($_REQUEST['duration_in_hours']) ? $_REQUEST['duration_in_hours'] : null; if (isset($_REQUEST['start_date_type']) && $_REQUEST['start_date_type'] == 2) { $start_date = $_REQUEST['custom_start_date']; $attendance_id = 0; } else { $start_date = isset($_REQUEST['start_date_by_attendance']) ? $_REQUEST['start_date_by_attendance'] : null; $attendance_id = isset($_REQUEST['attendance_select']) ? $_REQUEST['attendance_select'] : null; } $thematic->set_thematic_advance_attributes($thematic_advance_id, $thematic_id, $attendance_id, $content, $start_date, $duration); $affected_rows = $thematic->thematic_advance_save(); if ($affected_rows) { // get last done thematic advance before move thematic list $last_done_thematic_advance = $thematic->get_last_done_thematic_advance(); // update done advances with de current thematic list if (!empty($last_done_thematic_advance)) { $thematic->update_done_thematic_advances($last_done_thematic_advance); } } } } break; default: $thematic_advance_data = $thematic->get_thematic_advance_list($thematic_advance_id); break; } // get calendar select by attendance id $calendar_select = array(); if (!empty($thematic_advance_data)) { if (!empty($thematic_advance_data['attendance_id'])) { $attendance_calendar = $attendance->get_attendance_calendar($thematic_advance_data['attendance_id']); if (!empty($attendance_calendar)) { foreach ($attendance_calendar as $calendar) { $calendar_select[$calendar['date_time']] = $calendar['date_time']; } } } } $data['action'] = $action; $data['thematic_id'] = $thematic_id; $data['thematic_advance_id'] = $thematic_advance_id; $data['attendance_select'] = $attendance_select; $data['thematic_advance_data'] = $thematic_advance_data; $data['calendar_select'] = $calendar_select; $layoutName = $displayHeader ? 'layout' : 'layout_no_header'; // render to the view $this->view->set_data($data); $this->view->set_layout($layoutName); $this->view->set_template('thematic_advance'); $this->view->render(); }
if (!empty($attendance_id)) { $attendance = new Attendance(); $thematic = new Thematic(); $thematic_list = $thematic->get_thematic_list(); $my_list = $thematic_list_temp = array(); foreach ($thematic_list as $item) { $my_list = $thematic->get_thematic_advance_by_thematic_id($item['id']); $thematic_list_temp = array_merge($my_list, $thematic_list_temp); } $new_thematic_list = array(); foreach ($thematic_list_temp as $item) { if (!empty($item['attendance_id'])) { $new_thematic_list[$item['id']] = array('attendance_id' => $item['attendance_id'], 'start_date' => $item['start_date']); } } $attendance_calendar = $attendance->get_attendance_calendar($attendance_id); $label = get_lang('StartDate'); if (!empty($attendance_calendar)) { $input_select .= '<select id="start_date_select_calendar" name="start_date_by_attendance" UNIQUE size="5">'; foreach ($attendance_calendar as $calendar) { $selected = null; $insert = true; //checking if was already taken foreach ($new_thematic_list as $key => $thematic_item) { //if ($calendar['db_date_time'] == $thematic_item['start_date'] && $calendar['attendance_id'] == $thematic_item['attendance_id'] ) { if ($calendar['db_date_time'] == $thematic_item['start_date']) { $insert = false; if ($thematic_advance_id == $key) { $insert = true; $selected = 'selected'; }
// $course_id = $course['id']; // break; // } if (!empty($course_id)) { $out2 = "-- Course " . $course_id . "\n"; // Get attendances sheets from course (only one in each course) $att = $a->get_attendances_list($course_id, $session_id); if (count($att) > 0) { foreach ($att as $at) { $at_id = $at['id']; break; //get out after first result } $out3 = "---- Attendance " . $at_id . "\n"; $a->set_course_int_id($course_id); $cal_list = $a->get_attendance_calendar($at_id); $cal_count = count($cal_list); foreach ($cal_list as $cal) { $cal_id = $cal['id']; $sql = "SELECT * FROM c_attendance_sheet WHERE c_id = {$course_id} AND attendance_calendar_id = {$cal_id}"; $res_att = Database::query($sql); $att_count = Database::num_rows($res_att); if ($att_count < count($u)) { $out4 = "------ Found {$att_count} when should have found " . count($u) . " attendances for " . $cal['date_time'] . "\n"; echo $out1 . $out2 . $out3 . $out4; while ($row_att = Database::fetch_assoc($res_att)) { $atts[] = $row_att['user_id']; } $missing = array_diff($u, $atts); foreach ($missing as $u1) { $sqlu = "SELECT field_value FROM user_field_values where field_id = {$uidf} and user_id = {$u1}";