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 '
'.print_r($rez,1).'
';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.'
'; if($cache_item=='') { $doc = $RPD->RPD_GetFOSPDF($item['id'], 0, 2); $doc['html'] = $this->prepare_html2word($doc['html'],'all'); //echo '
'.print_r($lists,1).'
'; 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'] = '

Файлы для скачивания

';//.'
'.print_r($lists,1).'
'; $out['body'] .= ''; foreach($lists as $k => $v){ $out['body'] .= ''; $out['body'] .= ''; $out['body'] .= ''; $out['body'] .= ''; $out['body'] .= ''; $out['body'] .= ''; $out['body'] .= ''; } $out['body'] .= '
'.$v['shifr'].' '.$v['name'].' '.$v['fo'].''.$v['naprav'].''.$v['program'].''.$v['god_nach_podgot'].'Скачать
'; 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 = '
'; 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 = 'Список ФОС '.date('d.m.Y').' '; $out .= '
'; return $out; } function HTML_foot(){ $out = '
'; $out .= ''; return $out; } function prepare_html2word($text,$type='all'){ $text = preg_replace('|()|isU','',$text); if($type=='all') {//для конечного результата добавим стиль $text = $this->HTML_head().'
' . $text . '
'; } 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; } } }