172 lines
8.4 KiB
PHP
172 lines
8.4 KiB
PHP
|
<?php
|
|||
|
|
|||
|
class class_REPORTFOS{
|
|||
|
function __construct(){
|
|||
|
GLOBAL $DB,$ST;
|
|||
|
$this->DB = $DB;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
function HTML(){
|
|||
|
GLOBAL $WorkDIR;
|
|||
|
$CHPU = new class_CHPU($WorkDIR);
|
|||
|
$URLS = $CHPU->uri();
|
|||
|
|
|||
|
$smartyC = new class_smarty();
|
|||
|
$smarty = $smartyC->config(__DIR__.'\..\tpl');
|
|||
|
|
|||
|
$view = 'all';
|
|||
|
$out = array('name'=>'Отчет по ФОС','body'=>'');
|
|||
|
|
|||
|
$kafedra = $_SESSION['user']['teacher']['kafedra'];
|
|||
|
$fc = $this->file_report = $_SESSION['user']['id'].'_'.$kafedra;
|
|||
|
$this->saveFOS_inFile('','clear');
|
|||
|
|
|||
|
$lists = array();
|
|||
|
$cache = $this->cache($fc);
|
|||
|
if($cache=='') {
|
|||
|
$RPD = new class_RPD();
|
|||
|
$RPDsign = new class_RPDSign();
|
|||
|
//$out .= $this->HTML_head();
|
|||
|
//получим все РПД подписанные
|
|||
|
$rez = $RPDsign->Disciplins_for_ZAVYPKAF();
|
|||
|
//echo '<pre>'.print_r($rez,1).'</pre>';exit();
|
|||
|
if (isset($rez['items']) && count($rez['items'])) {
|
|||
|
foreach ($rez['items'] as $key => $item) {
|
|||
|
$name_item = 'rpd_fos_'.$item['id'];
|
|||
|
$cache_item = $this->cache_item($name_item,'','is');
|
|||
|
//echo $name_item.':'.$cache_item.'<br>';
|
|||
|
if($cache_item=='') {
|
|||
|
$doc = $RPD->RPD_GetFOSPDF($item['id'], 0, 2);
|
|||
|
$doc['html'] = $this->prepare_html2word($doc['html'],'all');
|
|||
|
//echo '<pre>'.print_r($lists,1).'</pre>'; exit();
|
|||
|
$this->cache_item($name_item,$doc['html']);
|
|||
|
//$out .= $doc['html'];
|
|||
|
//$this->saveFOS_inFile($doc['html']);
|
|||
|
}else{
|
|||
|
// //$out .= $cache_item;
|
|||
|
// //$doc['html'] = $this->prepare_html2word($doc['html'],'');
|
|||
|
// $this->saveFOS_inFile($cache_item);
|
|||
|
}
|
|||
|
$lists[] = array('file'=>$name_item,'name'=>$item['name'],'shifr'=> $item['shifr'],'program'=> $item['program'],'naprav'=> $item['naprav'],'god_nach_podgot'=> $item['god_nach_podgot'],'fo'=> $item['fo']);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//$out = $this->prepare_html2word($out);
|
|||
|
//$this->cache($fc,$out);
|
|||
|
}else{
|
|||
|
$out = $cache;
|
|||
|
}
|
|||
|
//$this->saveFOS_inFile('','download');
|
|||
|
//$this->file_force_download('tmp/sFOS/'.$fc.'.html');
|
|||
|
//$out['body'] = $smarty->fetch('page_library_check.html');
|
|||
|
$out['body'] = '<h2>Файлы для скачивания</h2>';//.'<pre>'.print_r($lists,1).'</pre>';
|
|||
|
$out['body'] .= '<table class="table">';
|
|||
|
foreach($lists as $k => $v){
|
|||
|
$out['body'] .= '<tr>';
|
|||
|
$out['body'] .= '<td>'.$v['shifr'].' '.$v['name'].' '.$v['fo'].'</td>';
|
|||
|
$out['body'] .= '<td>'.$v['naprav'].'</td>';
|
|||
|
$out['body'] .= '<td>'.$v['program'].'</td>';
|
|||
|
$out['body'] .= '<td>'.$v['god_nach_podgot'].'</td>';
|
|||
|
$out['body'] .= '<td><a href="/rabprog/tmp/sFOS/items/'.$v['file'].'.html" target="_blank">Скачать</a></td>';
|
|||
|
$out['body'] .= '</tr>';
|
|||
|
}
|
|||
|
$out['body'] .= '</table>';
|
|||
|
return $out;
|
|||
|
}
|
|||
|
|
|||
|
function saveFOS_inFile($html,$des='add'){
|
|||
|
if(isset($this->file_report)&&$this->file_report!=''){
|
|||
|
$file = 'tmp/sFOS/reports/'.$this->file_report.'.html';
|
|||
|
if($des=='add') {
|
|||
|
file_put_contents($file, $html, FILE_APPEND);
|
|||
|
}
|
|||
|
if($des=='clear') {
|
|||
|
unlink($file);
|
|||
|
$html = '<style type="text/css"><!-- @media print {@page {size: landscape}} @page Section1, @page WordSection1 {size:841.9pt 595.3pt;mso-page-orientation:landscape;margin:3.0cm 2.0cm 42.5pt 2.0cm;mso-header-margin:35.4pt;mso-footer-margin:35.4pt;mso-paper-source:0;} div.WordSection1 {page:WordSection1;} --> table{ width:100%; border-collapse: collapse; border:1px solid;} th{ border:1px solid; padding:2px; font-weight: bold;} td{ border:1px solid; padding:2px;}</style><div class=WordSection1>';
|
|||
|
file_put_contents($file, $html, FILE_APPEND);
|
|||
|
}
|
|||
|
if($des=='download') {
|
|||
|
$this->file_force_download($file);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function cache_item($name,$html='',$is=''){
|
|||
|
$out = '';
|
|||
|
$file = 'tmp/sFOS/items/'.$name.'.html';
|
|||
|
if(file_exists($file)){
|
|||
|
$ftime = filemtime($file);
|
|||
|
$raznica_sec = (time()-$ftime);
|
|||
|
$period = (60*60*24);//час
|
|||
|
if($raznica_sec < $period) {
|
|||
|
if($is=='')//получим содержимое
|
|||
|
$out = file_get_contents($file);
|
|||
|
else $out='1';
|
|||
|
}
|
|||
|
if($html!='') file_put_contents($file,$html);
|
|||
|
}else{
|
|||
|
//$out .= 'file not '.$file;
|
|||
|
if($html!='') file_put_contents($file,$html);
|
|||
|
}
|
|||
|
return $out;
|
|||
|
}
|
|||
|
function cache($name,$html=''){
|
|||
|
$out = '';
|
|||
|
$file = 'tmp/sFOS/'.$name.'.html';
|
|||
|
if(file_exists($file)){
|
|||
|
$ftime = filemtime($file);
|
|||
|
$raznica_sec = (time()-$ftime);
|
|||
|
$period = (60*60*24);//час
|
|||
|
if($raznica_sec < $period) {
|
|||
|
$out = file_get_contents($file);
|
|||
|
}
|
|||
|
}else{
|
|||
|
if($html!='') file_put_contents($file,$html);
|
|||
|
}
|
|||
|
return $out;
|
|||
|
}
|
|||
|
|
|||
|
function HTML_head(){
|
|||
|
$out = '<!doctype html><html lang="ru"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Список ФОС '.date('d.m.Y').'</title>
|
|||
|
<link rel="shortcut icon" href="https://eios.mkgtu.ru/rabprog/favicon.ico" type="image/x-icon"><link href="https://eios.mkgtu.ru/rabprog/tpl/css/bootstrap.css" rel="stylesheet" ><meta name="theme-color" content="#7952b3"><link href="https://eios.mkgtu.ru/rabprog/tpl/css/style.css" rel="stylesheet"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.0/font/bootstrap-icons.css"><script src="https://eios.mkgtu.ru/rabprog/tpl/js/jquery.js"></script><script src="https://eios.mkgtu.ru/rabprog/tpl/js/popper.min.js"></script><script src="https://eios.mkgtu.ru/rabprog/tpl/js/bootstrap.js"></script><script src="https://eios.mkgtu.ru/rabprog/tpl/js/scripts.js?v=2"></script></head><body>';
|
|||
|
$out .= '<div class="container-fluid"><div class="row"><div class="col-md-12">';
|
|||
|
return $out;
|
|||
|
}
|
|||
|
function HTML_foot(){
|
|||
|
$out = '</div></div></div>';
|
|||
|
$out .= '</body></html>';
|
|||
|
return $out;
|
|||
|
}
|
|||
|
|
|||
|
function prepare_html2word($text,$type='all'){
|
|||
|
$text = preg_replace('|(<style>.*</style>)|isU','',$text);
|
|||
|
if($type=='all') {//для конечного результата добавим стиль
|
|||
|
$text = $this->HTML_head().'<style type="text/css"><!-- @media print {@page {size: landscape}} @page Section1, @page WordSection1 {size:841.9pt 595.3pt;mso-page-orientation:landscape;margin:3.0cm 2.0cm 42.5pt 2.0cm;mso-header-margin:35.4pt;mso-footer-margin:35.4pt;mso-paper-source:0;} div.WordSection1 {page:WordSection1;} --> table{ width:100%; border-collapse: collapse; border:1px solid;} th{ border:1px solid; padding:2px; font-weight: bold;} td{ border:1px solid; padding:2px;}</style><div class=WordSection1>' . $text . '</div>';
|
|||
|
}
|
|||
|
return $text;
|
|||
|
}
|
|||
|
|
|||
|
function file_force_download($file) {
|
|||
|
$pi = pathinfo($file);
|
|||
|
$filename = str_replace($pi['extension'],'.doc',$file);
|
|||
|
if (file_exists($file)) {
|
|||
|
if (ob_get_level()) {
|
|||
|
ob_end_clean();
|
|||
|
}
|
|||
|
// заставляем браузер показать окно сохранения файла
|
|||
|
header('Content-Description: File Transfer');
|
|||
|
//header('Content-Type: application/octet-stream');
|
|||
|
header('Content-Type: application/vnd.ms-word; charset=cp1251');
|
|||
|
header('Content-Disposition: attachment; filename=' . basename($filename));
|
|||
|
header('Content-Transfer-Encoding: binary');
|
|||
|
header('Expires: 0');
|
|||
|
header('Cache-Control: must-revalidate');
|
|||
|
header('Pragma: public');
|
|||
|
header('Content-Length: ' . filesize($file));
|
|||
|
// читаем файл и отправляем его пользователю
|
|||
|
readfile($file);
|
|||
|
exit;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|