public function action_pdf()
{
$this->auto_render = false;
$sheet = Model_Attendance::get($this->request->param('id'));
$tcpdf = new Kohana_KTcpdf(TRUE);
$tcpdf->setTitle(ucfirst(__('attendance sheet')) . ' "'
. $sheet->eventsRel->eventstypesRel->name . ' '
. $sheet->eventsRel->name . '" - '
. $sheet->eventsRel->date . ' '
. $sheet->eventsRel->begin);
$html = '<table style="width: 100%;">';
$html .= '<thead style="width: 100%;">';
$html .= '<tr style="width: 100%;">';
$html .= '<th style="width: 15%; background-color: #ccc; height: 24px;">'.ucfirst(__('student')).'</th>';
$html .= '<th style="width: 15%; background-color: #ccc; height: 24px;">'.ucfirst(__('state')).'</th>';
$html .= '<th style="width: 60%; background-color: #ccc; height: 24px;">'.ucfirst(__('comment')).'</th>';
$html .= '</tr>';
$html .= '</thead>';
$html .= '<tbody>';
$states = Kohana::$config->load('attendance.states');
$students = DB_ORM::select('attendancelists')
->join('right', 'students')
->on('attendance_lists.id_student', '=', 'students.id')
->where('id_attendance', '=', $sheet->id)
->order_by('students.login')
->query();
foreach ($students AS $student)
{
if ($student->state == 2)
$color = "orange";
else if ($student->state == 3)
$color = "red";
else
$color = "black";
$html .= '<tr style="width: 100%; color: '.$color.';">';
$html .= '<td style="height: 20px;width: 15%; border-bottom: 1px dotted #ccc;">'.HTML::chars($student->studentsRel->login).'</td>';
$html .= '<td style="height: 20px;width: 15%; border-bottom: 1px dotted #ccc;">'.$states[$student->state].'</td>';
$html .= '<td style="height: 20px;width: 60%; border-bottom: 1px dotted #ccc;">'.HTML::chars($student->comment).'</td>';
$html .= '</tr>';
}
$html .= '</tbody>';
$html .= '</table>';
$tcpdf->setContent($html);
$tcpdf->generate();
}