private function createCSVEnroll() { $this->_helper->viewRenderer->setNoRender(); $this->_helper->layout->disableLayout(); $lop = new Model_Lophoc(); $idlop = $classes_id = $_GET['idlop']; $listsv = $lop->listsv($idlop); $this->view->listsv = $listsv; $lophoc = $lop->findOneLop($classes_id); $getDate = $lop->findDateByClassesID($classes_id); $this->view->getDate = $getDate; $this->view->lop = $lophoc; $schoolyears_name = $lop->findschoolyears($lophoc->schoolyears_id); $this->view->schoolyears_name = $schoolyears_name; foreach ($listsv as $sv) { $masv = $sv->student_id; $dihoc[$masv] = $lop->dihoc($idlop, $masv); } $this->view->dihoc = $dihoc; $tongsv = $lop->tongsv($idlop); $this->view->tongsv = $tongsv; for ($i = 1; $i <= $lophoc->session_number; $i++) { $buoi = $i; $sodihoc[$buoi] = $lop->sodihoc($idlop, $buoi); } $this->view->sodihoc = $sodihoc; //Create Excel file $header = "Mã SV" . ",\t"; $header .= "Tên SV" . ",\t"; $k = 0; for ($a = 1; $a <= $lophoc->session_number; $a++) { $header .= "Buổi" . $a . "(" . $getDate[$k]->date . ")" . ",\t"; $k++; } $header .= "Tổng buổi vắng" . ",\t\n"; $line = ''; foreach ($listsv as $listsv) { $value1 = str_replace('"', '""', $listsv->student_id); $value2 = str_replace('"', '""', $listsv->student_name); $setValue = '"' . $value1 . '"' . ",\t" . $value2 . ",\t"; for ($a = 0; $a < $lophoc->session_number; $a++) { if ($dihoc[$listsv->student_id][$a]['d'] != null) { $value = str_replace('"', '""', 'x'); $setValue .= $value . ",\t"; } else { $value = str_replace('"', '""', ''); $setValue .= $value . ",\t"; } } $value3 = str_replace('"', '""', $lophoc->session_number - count($dihoc[$listsv->student_id])); $setValue .= $value3 . ",\t\n"; $line .= $setValue; } $data .= trim($line) . "\n"; $data = str_replace("\r", "", $data); // output data echo $header . "\n" . $data; header('Content-Encoding: UTF-8'); header("Content-type: application/csv; name='excel';charset='UTF-8'"); header("Content-Disposition: attachment; filename=" . $lophoc->classes_name . ".csv"); header("Pragma: no-cache"); header("Expires: 0"); }
public function chitietdiemdanhAction() { $lop = new Model_Lophoc(); $idlop = $classes_id = $_GET['idlop']; $listsv = $lop->listsv($idlop); $this->view->listsv = $listsv; $lophoc = $lop->findOneLop($classes_id); $getDate = $lop->findDateByClassesID($classes_id); $this->view->getDate = $getDate; $this->view->lop = $lophoc; //var_dump($lop); foreach ($listsv as $sv) { $masv = $sv->student_id; $dihoc[$masv] = $lop->dihoc($idlop, $masv); } $this->view->dihoc = $dihoc; $tongsv = $lop->tongsv($idlop); $this->view->tongsv = $tongsv; for ($i = 1; $i <= $lophoc->session_number; $i++) { $buoi = $i; $sodihoc[$buoi] = $lop->sodihoc($idlop, $buoi); } $this->view->sodihoc = $sodihoc; //echo '<pre>'; //print_r($sodihoc); //echo '</pre>'; }