EIOS/inc/rejt.php

408 lines
18 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
error_reporting(0);
session_start();
$maincontent = '';
$smarty->assign('razdel','rejtmain');
if(isset($_GET['page'])){ $page=$_GET['page']; }else{ $page='main'; }
if(isset($_GET['des'])){ $des=$_GET['des']; }else{ $des='show';}
/*
echo '<pre>'.print_r($_POST,1).'</pre>';
echo '<pre>'.print_r($_GET,1).'</pre>';
[rejt] =>
[page] => admin1
[des] => add*/
$TB['razdels'] = $ST['dbpf'].'_rejt_razdels';
$TB['items'] = $ST['dbpf'].'_rejt_items';
$TB['polyas'] = $ST['dbpf'].'_rejt_polyas';
$TB['itemspolyas'] = $ST['dbpf'].'_rejt_itemspolyas';
$TB['saves'] = $ST['dbpf'].'_rejt_saves';
$TB['savesballs'] = $ST['dbpf'].'_rejt_savesballs';
$TB['otchgods'] = $ST['dbpf'].'_rejt_otchgods';
{$sql = 'CREATE TABLE IF NOT EXISTS `'.$TB['savesballs'].'` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`data_c` int(11) NOT NULL,
`id_user` int(11) NOT NULL,
`id_item` int(11) NOT NULL,
`balls` float NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
$rez = $DB->QUR($sql);}
{$sql = 'CREATE TABLE IF NOT EXISTS `'.$TB['razdels'].'` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`descr` varchar(255) NOT NULL,
`pos` tinyint(4) NOT NULL,
`status` tinyint(4) NOT NULL,
`dostup` tinyint(4) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
$rez = $DB->QUR($sql);
}
{
$sql = 'CREATE TABLE IF NOT EXISTS `'.$TB['items'].'` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_razdel` int(11) NOT NULL,
`name` text NOT NULL,
`tip` tinyint(4) NOT NULL,
`pos` tinyint(4) NOT NULL,
`formuls` varchar(255) NOT NULL,
`descr` text NOT NULL,
`status` tinyint NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
$rez = $DB->QUR($sql);
}
{
$sql = 'CREATE TABLE IF NOT EXISTS `'.$TB['polyas'].'` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_item` int(11) NOT NULL,
`name` text NOT NULL,
`pos` tinyint(4) NOT NULL,
`value` DOUBLE NOT NULL,
`status` tinyint NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
$rez = $DB->QUR($sql);}
{
$sql = 'CREATE TABLE IF NOT EXISTS `'.$TB['itemspolyas'].'` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_item` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`pos` tinyint(4) NOT NULL,
`value` varchar(255) NOT NULL,
`status` tinyint NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
$rez = $DB->QUR($sql);}
{
$sql = 'CREATE TABLE IF NOT EXISTS `'.$TB['saves'].'` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`data_c` int(11) NOT NULL,
`id_user` int(11) NOT NULL,
`id_razdel` int(11) NOT NULL,
`id_items` int(11) NOT NULL,
`id_itemspolyas` int(11) NOT NULL,
`id_polyas` int(11) NOT NULL,
`value` text NOT NULL,
`pos` tinyint(4) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
$rez = $DB->QUR($sql);}
{$sql = 'CREATE TABLE IF NOT EXISTS `'.$TB['otchgods'].'` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`data_c` int(11) NOT NULL,
`tip` int(11) NOT NULL,
`data_s1` int(11) NOT NULL,
`data_s2` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`descrip` text NOT NULL,
`status` tinyint NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
$rez = $DB->QUR($sql);}
function rejt_get_razdels($id=0){
GLOBAL $TB,$DB; $out=array();
if($id){
$sql = 'SELECT * FROM '.$TB['razdels'].' WHERE id='.$id.' AND status=1 LIMIT 1';
}else{
$sql = 'SELECT * FROM '.$TB['razdels'].' WHERE status=1 ORDER BY pos';
}
$rez = $DB->QUR_SEL($sql);
if($rez){
foreach($rez as $key => $val)if($key){
$out[]=$val;
}
}
return $out;
}
function rejt_get_items($id=0){
GLOBAL $TB,$DB; $out=array();
if($id){
$sql = 'SELECT * FROM '.$TB['itemspolyas'].' WHERE id='.$id.' AND status=1 LIMIT 1';
}else{
$sql = 'SELECT * FROM '.$TB['itemspolyas'].' WHERE status=1 ORDER BY id_item,pos';
}
$rez = $DB->QUR_SEL($sql);
if($rez){
foreach($rez as $key => $val)if($key){
$sql1 = 'SELECT * FROM '.$TB['items'].' WHERE id='.$val['id_item'].' AND status=1';
$rez1 = $DB->QUR_SEL($sql1);
if($rez1){
$sql2 = 'SELECT * FROM '.$TB['razdels'].' WHERE id='.$rez1[1]['id_razdel'].' AND status=1';
$rez2 = $DB->QUR_SEL($sql2);
if($rez2){
$rez1[1]['razdel'] = $rez2[1];
}
$val['item'] = $rez1[1];
}
$out[]=$val;
}
}
return $out;
}
function rejt_get_useranketa(){
GLOBAL $ST,$DB,$TB;
$items=array(); $BALLS=0;
$sql = 'SELECT * FROM '.$TB['razdels'].' WHERE status=1 ORDER BY pos';
$rez = $DB->QUR_SEL($sql); //echo $sql.'<pre>'.print_r($rez,1).'</pre>';
if($rez){
foreach($rez as $key => $val)if($key){
$val['razdel']=array();
$sql1 = 'SELECT * FROM '.$TB['items'].' WHERE id_razdel='.$val['id'].' AND status=1 ORDER BY pos';
$rez1 = $DB->QUR_SEL($sql1); //echo $sql1.'<pre>'.print_r($rez1,1).'</pre>';
if($rez1){
foreach($rez1 as $key1 => $val1)if($key1){
$val1['itemspolyas']=array();
$sql2 = 'SELECT * FROM '.$TB['itemspolyas'].' WHERE id_item='.$val1['id'].' AND status=1 ORDER BY pos';
$rez2 = $DB->QUR_SEL($sql2); //echo $sql2.'<pre>'.print_r($rez2,1).'</pre>';
$kolsaves=0;
if($rez2){
foreach($rez2 as $key2 => $val2)if($key2){
$val2['polyas']=array();
//выбираем выпадающие элементы
$sql3 = 'SELECT * FROM '.$TB['polyas'].' WHERE id_item='.$val2['id'].' AND status=1 ORDER BY pos';
$rez3 = $DB->QUR_SEL($sql3); //echo $sql3.'<pre>'.print_r($rez3,1).'</pre>';
if($rez3){
foreach($rez3 as $key3 => $val3)if($key3){
$val2['polyas'][]=$val3;
}
}
$val2['saves']=array();
//выбираем сохранения в зависимости от $_SESSION['otchgods'][3]['data_s1']-$_SESSION['otchgods'][3]['data_s2']
if(isset($_SESSION['otchgods'][3])){
//$sql4 = 'SELECT * FROM '.$TB['saves'].' WHERE id_user='.$_SESSION['user']['id'].' AND id_razdel='.$val['id'].' AND id_items='.$val1['id'].' AND id_itemspolyas='.$val2['id'].' ORDER BY pos';
$sql4 = 'SELECT * FROM '.$TB['saves'].' WHERE id_user='.$_SESSION['user']['id'].' AND id_razdel='.$val['id'].' AND id_items='.$val1['id'].' AND id_itemspolyas='.$val2['id'].' AND (data_c BETWEEN '.$_SESSION['otchgods'][3]['data_s1'].' AND '.$_SESSION['otchgods'][3]['data_s2'].') ORDER BY pos';
$rez4 = $DB->QUR_SEL($sql4); //echo '1:'.$sql4.'<pre>'.print_r($rez4,1).'</pre>';
if($rez4){
if($rez4[0]>$kolsaves) $kolsaves=$rez4[0];
foreach($rez4 as $key4 => $val4)if($key4){
$val2['saves'][$val4['pos']+1]=$val4;
}
}
}
$val1['itemspolyas'][]=$val2;
}
}else{//может быть сохранения и для первого раздела!
$val2['saves']=array();
//выбираем сохранения в зависимости от $_SESSION['otchgods'][3]['data_s1']-$_SESSION['otchgods'][3]['data_s2']
if(isset($_SESSION['otchgods'][3])){
$sql4 = 'SELECT * FROM '.$TB['saves'].' WHERE id_user='.$_SESSION['user']['id'].' AND id_razdel='.$val['id'].' AND id_items='.$val1['id'].' AND id_itemspolyas=0 AND (data_c BETWEEN '.$_SESSION['otchgods'][3]['data_s1'].' AND '.$_SESSION['otchgods'][3]['data_s2'].') ORDER BY pos';
$rez4 = $DB->QUR_SEL($sql4); //echo '2:'.$sql4.'<pre>'.print_r($rez4,1).'</pre>';
if($rez4){
if($rez4[0]>$kolsaves) $kolsaves=$rez4[0];
foreach($rez4 as $key4 => $val4)if($key4){
$val2['saves'][$val4['pos']+1]=$val4;
}
}
}
$val1['itemspolyas'][]=$val2;
}
$val1['kolsaves']=$kolsaves;
$val1['formuls'] = rejt_raschet($val1['id'],$_SESSION['user']['id']);
$BALLS+=$val1['formuls']['itogo'];
$val['razdel'][]=$val1;
}
//echo '$key1='.$key1.'<br>';
}
$items[]=$val;
//echo '<pre>'.print_r($val,1).'</pre>'; //exit();
//echo '$key='.$key.'<br>';
}
//echo '111';
}
//echo '<pre>'.print_r($items,1).'</pre>';
return array('items'=>$items,'balls'=>$BALLS);
}
//echo '<pre>'.print_r($_SESSION['user'],1).'</pre>';
//if($_SESSION['user']['status']==99){
if($page=='checks'){
include 'rejt_checks.php';
}
if($page=='admin'){
$smarty->assign('page',$page);
$smarty->assign('des',$des);
$maincontent = $smarty->fetch('tpl_rejt_main.html');
}
if($page=='kart'){
$smarty->assign('page',$page);
$smarty->assign('des',$des);
$maincontent = $smarty->fetch('tpl_rejt_kart.html');
}
if($page=='admin1'){//УПРАВЛЕНИЕ ОСНОВНЫМИ РАЗДЕЛАМИ
include 'rejt_admin1.php';
}
if($page=='admin2'){//УПРАВЛЕНИЕ ПОДРАЗДЕЛАМИ
include 'rejt_admin2.php';
}
if($page=='admin3'){//УПРАВЛЕНИЕ полями в ПОДРАЗДЕЛАХ
include 'rejt_admin3.php';
}
if($page=='admin4'){//УПРАВЛЕНИЕ значениями в полях
include 'rejt_admin4.php';
}
if($page=='admin5'){//УПРАВЛЕНИЕ отчетными периодами
include 'rejt_admin5.php';
}
if($page=='xlsx'){
$otchgods=array();//выберем активный отчетный период
unset($_SESSION['otchgods'][3]);
$sql = 'SELECT * FROM '.$TB['otchgods'].' WHERE tip=3 AND status=1';
$rez = $DB->QUR_SEL($sql);
if($rez){
$otchgods = $rez[1];
$otchgods['konec'] = 0; if(time()>$otchgods['data_s2']) $otchgods['konec'] = 1;
$_SESSION['otchgods'][$otchgods['tip']] = $otchgods;//для подсчета баллов
}
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);
//$header=array('1','2','3');
//$objPHPExcel->getActiveSheet()->fromArray($header, NULL, 'A2');
/*
$objPHPExcel->getActiveSheet()->getStyle('A2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('C2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('D2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('E2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('F2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('G2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('H2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('I2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('J2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('K2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('L2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('M2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('A2')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('C2')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('D2')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('E2')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('F2')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('G2')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('H2')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('I2')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('J2')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('K2')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('L2')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('M2')->getFont()->setBold(true);
*/
$rejtuser = rejt_get_useranketa();
$items = $rejtuser['items'];
$BALLS = $rejtuser['balls'];
//echo '<pre>'.print_r($items,1).'</pre>';
$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');
//echo '<pre>'.print_r($objWriter,1).'</pre>';
exit;
}
if($page=='main'){
include 'rejt_anketa.php';
}
if($page=='maineu'){
//echo '<pre>'.print_r($_GET,1).'</pre>';
$_SESSION['rejteu'] = (int)$_GET['des'];
include 'rejt_anketa.php';
}
//}else{$maincontent = 'в разработке';}