Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 6th, 2012  |  syntax: PHP  |  size: 1.99 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.         public function action_pdf()
  2.         {
  3.                 $this->auto_render = false;
  4.                 $sheet = Model_Attendance::get($this->request->param('id'));
  5.  
  6.                 $tcpdf = new Kohana_KTcpdf(TRUE);
  7.                 $tcpdf->setTitle(ucfirst(__('attendance sheet')) . ' "'
  8.                                 . $sheet->eventsRel->eventstypesRel->name . ' '
  9.                                 . $sheet->eventsRel->name . '" - '
  10.                                 . $sheet->eventsRel->date . ' '
  11.                                 . $sheet->eventsRel->begin);
  12.  
  13.                 $html = '<table style="width: 100%;">';
  14.                         $html .= '<thead style="width: 100%;">';
  15.                                 $html .= '<tr style="width: 100%;">';
  16.                                         $html .= '<th style="width: 15%; background-color: #ccc; height: 24px;">'.ucfirst(__('student')).'</th>';
  17.                                         $html .= '<th style="width: 15%; background-color: #ccc; height: 24px;">'.ucfirst(__('state')).'</th>';
  18.                                         $html .= '<th style="width: 60%; background-color: #ccc; height: 24px;">'.ucfirst(__('comment')).'</th>';
  19.                                 $html .= '</tr>';
  20.                         $html .= '</thead>';
  21.                         $html .= '<tbody>';
  22.  
  23.                         $states = Kohana::$config->load('attendance.states');
  24.  
  25.                         $students = DB_ORM::select('attendancelists')
  26.                                                                 ->join('right', 'students')
  27.                                                                 ->on('attendance_lists.id_student', '=', 'students.id')
  28.                                                                 ->where('id_attendance', '=', $sheet->id)
  29.                                                                 ->order_by('students.login')
  30.                                                                 ->query();
  31.  
  32.                         foreach ($students AS $student)
  33.                         {
  34.                                 if ($student->state == 2)
  35.                                         $color = "orange";
  36.                                 else if ($student->state == 3)
  37.                                         $color = "red";
  38.                                 else
  39.                                         $color = "black";
  40.  
  41.                                 $html .= '<tr style="width: 100%; color: '.$color.';">';
  42.                                         $html .= '<td style="height: 20px;width: 15%; border-bottom: 1px dotted #ccc;">'.HTML::chars($student->studentsRel->login).'</td>';
  43.                                         $html .= '<td style="height: 20px;width: 15%; border-bottom: 1px dotted #ccc;">'.$states[$student->state].'</td>';
  44.                                         $html .= '<td style="height: 20px;width: 60%; border-bottom: 1px dotted #ccc;">'.HTML::chars($student->comment).'</td>';
  45.                                 $html .= '</tr>';
  46.                         }
  47.  
  48.                         $html .= '</tbody>';
  49.                 $html .= '</table>';
  50.  
  51.                 $tcpdf->setContent($html);
  52.                 $tcpdf->generate();
  53.         }