assign('razdel','rejt2main'); if(isset($_GET['page'])){ $page=$_GET['page']; }else{ $page='main'; } if(isset($_GET['des'])){ $des=$_GET['des']; }else{ $des='show';} $TB['items2'] = $ST['dbpf'].'_rejt2_items'; //$DB->QUR('DROP TABLE `'.$TB['items2'].'`;'); {$sql = 'CREATE TABLE IF NOT EXISTS `'.$TB['items2'].'` ( `id` int(11) NOT NULL AUTO_INCREMENT, `id_user` int(11) NOT NULL, `id_razdel` int(11) NOT NULL, `data_c` int(11) NOT NULL, `data_s` int(11) NOT NULL, `data_e` int(11) NOT NULL, `name` text NOT NULL, `hour_plan` DOUBLE NOT NULL, `hour_fakt` DOUBLE NOT NULL, `pos` int(11) NOT NULL, `status` tinyint NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;'; $rez = $DB->QUR($sql);} function rejt2_get_itemsnpr($id=0){ GLOBAL $ST,$TB,$DB; $out=array(); if($id){ $sql = 'SELECT * FROM '.$ST['dbpf'].'_rejtnpr_items WHERE id='.$id.' LIMIT 1'; }else{ $sql = 'SELECT * FROM '.$ST['dbpf'].'_rejtnpr_items ORDER BY pos'; } $rez = $DB->QUR_SEL($sql); if($rez){ foreach($rez as $key => $val)if($key){ $out[]=$val; } } return $out; } function rejt2_get_useranketa(){ GLOBAL $ST,$DB,$TB; $items=array(); $BALLS=0; $sql = 'SELECT * FROM '.$TB['items2'].' WHERE id_user='.$_SESSION['user']['id'].' ORDER BY pos'; $rez = $DB->QUR_SEL($sql); if($rez){ foreach($rez as $key => $val)if($key){ $items[]=$val; } } return $items; } //echo '
'.print_r($_SESSION['user'],1).'
'; //if($_SESSION['user']['status']==99){ /*if($page=='admin'){ $smarty->assign('page',$page); $smarty->assign('des',$des); $maincontent = $smarty->fetch('tpl_rejt_main.html'); }*/ if($page=='xlsx'){ ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); date_default_timezone_set('Europe/Moscow'); require_once 'inc/PHPExcel.php'; $objPHPExcel = new PHPExcel(); $objPHPExcel->getProperties()->setCreator("Яковлев Александр Леонидович") ->setLastModifiedBy("Яковлев Александр Леонидович") ->setTitle('Рейтинг сотрудника "'.$_SESSION['user']['fio'].'"') ->setSubject("выгрузка данных с сайта") ->setDescription("сводные данные по всем машинам") ->setKeywords("alneo.ru alneo php") ->setCategory("эффективный контракт"); $objPHPExcel->getActiveSheet()->mergeCells('A1:D1'); $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'Рейтинг сотрудника "'.$_SESSION['user']['fio'].'" '.date('H:i d.m.Y')); $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); $rejtuser = rejt_get_useranketa(); $items = $rejtuser['items']; $BALLS = $rejtuser['balls']; $row=3; foreach($items as $key => $it){ $row = $row+$key; $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$row, $it['name']); $objPHPExcel->getActiveSheet()->getStyle('A'.$row)->getFont()->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('A'.$row)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); if (count($it['razdel'])){ $row++; $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$row, $it['razdel']['name']); $objPHPExcel->getActiveSheet()->getStyle('A'.$row)->getFont()->setBold(true); //$objPHPExcel->getActiveSheet()->getStyle('A'.$row)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); foreach($it['razdel'] as $key => $rd){ if (!count($rd['itemspolyas'])){//Блок без допполей $row++; $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$row, $rd['name']); //{if $rd.name=='Ф.И.О. преподавателя'}{$user.fio}{/if} $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$row, '--'); } else{//блоки с допполями $row++; $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$row, $rd['name']); $objPHPExcel->setActiveSheetIndex(0)->setCellValue('C'.$row, $rd['formuls']['itogo']); $objPHPExcel->getActiveSheet()->getStyle('A'.$row)->getFont()->setBold(true); //$objPHPExcel->getActiveSheet()->getStyle('A'.$row)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); if ($rd['kolsaves']){//если есть сохранения for ($kol=1;$kol<=$rd['kolsaves'];$kol++){ $row++; $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$row, $rd['name'].' №'.$kol); $objPHPExcel->setActiveSheetIndex(0)->setCellValue('C'.$row, $rd['formuls'][$kol-1]); $objPHPExcel->getActiveSheet()->getStyle('C'.$row)->getFont()->setBold(true); foreach($rd['itemspolyas'] as $key2 => $ip){ $row++; $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$row, $ip['name']); if($ip['saves'][$kol]['value']!=''){ if(is_numeric($ip['saves'][$kol]['value'])){ $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$row, $ip['saves'][$kol]['value']); }else{ $urlb1 = false; $urlb2 = false; if (strpos($ip['saves'][$kol]['value'], 'upload/rejt') !== false) $urlb1 = true; if (strpos($ip['saves'][$kol]['value'], 'http') !== false) $urlb2 = true; if($urlb1){ $url = 'http://eios.mkgtu.ru'.$ip['saves'][$kol]['value']; $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$row, '=Hyperlink("'.$url.'","Скачать")'); }else{ if($urlb2){//внешние ссылки $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$row, $ip['saves'][$kol]['value']); }else{//просто текст $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$row, $ip['saves'][$kol]['value']); } } } } } } } } } } } $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true); $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true); $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true); //$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setAutoSize(true); $objPHPExcel->getActiveSheet()->setTitle('Рейтинг'); $objPHPExcel->setActiveSheetIndex(0); $file = 'Рейтинг_'.$_SESSION['user']['fio'].''; header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="'.$file.'.xlsx"'); header('Cache-Control: max-age=0'); header('Cache-Control: max-age=1'); header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header ('Pragma: public'); // HTTP/1.0 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('php://output'); exit; } if($page=='main'){ $smarty->assign('items',rejt2_get_useranketa()); $smarty->assign('itemsnprs',rejt2_get_itemsnpr()); $smarty->assign('des',$des); $maincontent = $smarty->fetch('tpl_rejt2_anketa.html'); } /*if($page=='maineu'){ //echo '
'.print_r($_GET,1).'
'; $_SESSION['rejteu'] = (int)$_GET['des']; include 'rejt_anketa.php'; }*/ //}else{$maincontent = 'в разработке';}