123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- <?
- header("Expires: 0");
- session_start();
- require_once 'PHPExcel-1.8.2/Classes/PHPExcel.php';
- include 'auth.php';
- include 'functions.php';
- function cellColor($cells,$color){
- global $objPHPExcel;
- $objPHPExcel->getActiveSheet()->getStyle($cells)->getFill()->applyFromArray(array(
- 'type' => PHPExcel_Style_Fill::FILL_SOLID,
- 'startcolor' => array(
- 'rgb' => $color
- )
- ));
- }
- $styleBorder = array(
- 'borders' => array(
- 'allborders' => array(
- 'style' => PHPExcel_Style_Border::BORDER_THIN
- )
- )
- );
- foreach (array_keys($_REQUEST) as $var)
- {
- ${$var}=$_REQUEST[$var];
- //echo "<b>$var:</b> ${$var} <br>";
- }
- $array_children = $_SESSION['array_children'];
- $array_parent = $_SESSION['array_parent'];
- $activeid = $_SESSION['actid'];
- $res_parent = $array_parent[$activeid];
- $namedesc = GetTaskNameAndDesc($res_parent['type']);
- $proj = GetProject($res_parent['input_id']);
- $depo = $proj['depo'];
- $depo_service = $proj['depo_service'];
- $finished = $res_parent['created'];
- // Create new PHPExcel object
- $objPHPExcel = new PHPExcel();
- // Set document properties
- $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
- ->setLastModifiedBy("Maarten Balliauw")
- ->setTitle("Office 2007 XLSX Report Document")
- ->setSubject("Office 2007 XLSX Report Document")
- ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
- ->setKeywords("office 2007 openxml php")
- ->setCategory("Report result file");
- $styleCenter = array(
- 'alignment' => array(
- 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
- )
- );
- $styleLeft = array(
- 'alignment' => array(
- 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
- )
- );
- $styleVertCenter = array(
- 'alignment' => array(
- 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
- )
- );
- $sheet = $objPHPExcel->getActiveSheet();
- $sheet->getDefaultStyle()->getFont()->setName('Times New Roman')->setSize(12);
- $sheet->mergeCells("A2:B2");
- $sheet->mergeCells("A3:B3");
- $sheet->mergeCells("A5:B5");
- $sheet->mergeCells("A19:B19");
- $sheet->mergeCells("A14:B14");
- $sheet->getStyle("A2:A3")->applyFromArray($styleCenter);
- $sheet->getStyle('A5')->getFont()->setUnderline(true);
- $sheet->getStyle('A14')->getFont()->setUnderline(true);
- $sheet->getStyle('A19')->getFont()->setUnderline(true);
- $sheet->getStyle("A5")->applyFromArray($styleCenter);
- $sheet->getStyle("A14")->applyFromArray($styleCenter);
- $sheet->getStyle("A19")->applyFromArray($styleCenter);
- $sheet->getStyle('A2')->getFont()->setBold(TRUE);
- $sheet->getStyle('A5')->getFont()->setBold(TRUE);
- $sheet->getStyle('A14')->getFont()->setBold(TRUE);
- $sheet->getStyle('A19')->getFont()->setBold(TRUE);
- $sheet->getStyle('A7:A12')->getFont()->setBold(TRUE);
- $sheet->getStyle("A2")->getFont()->setSize(18);
- $sheet->getStyle("A5")->getFont()->setSize(16);
- $sheet->getStyle("A14")->getFont()->setSize(16);
- $sheet->getStyle("A19")->getFont()->setSize(16);
- //$sheet->getStyle("A7:A9")->applyFromArray($style1);
- //$sheet->getDefaultStyle()->applyFromArray($style);
- // $sheet->getStyle('B11:D11')->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
- $sheet->getStyle('A7:B12')->applyFromArray($styleBorder);
- $sheet->getStyle("A7:B12")->getAlignment()->setWrapText(true);
- $sheet->getStyle('A7:B12')->applyFromArray($styleVertCenter);
- $sheet->getStyle("A10:M10")->applyFromArray($styleVertCenter);
- $sheet->getStyle('A16:B17')->applyFromArray($styleBorder);
- //cellColor('B11:D11', 'f2f2f2');
- $sheet->getRowDimension('2')->setRowHeight(31.5);
- $sheet->getRowDimension('6')->setRowHeight(31.5);
- $sheet->getRowDimension('7')->setRowHeight(31.5);
- $sheet->getRowDimension('8')->setRowHeight(31.5);
- $sheet->getRowDimension('9')->setRowHeight(31.5);
- $sheet->getRowDimension('10')->setRowHeight(31.5);
- $sheet->getRowDimension('11')->setRowHeight(31.5);
- $sheet->getRowDimension('12')->setRowHeight(31.5);
- $sheet->getRowDimension('14')->setRowHeight(31.5);
- $sheet->getRowDimension('18')->setRowHeight(31.5);
- $sheet->getRowDimension('19')->setRowHeight(31.5);
- $sheet->setCellValue('A2', 'Дефектная Ведомость Инспекции');
- $sheet->setCellValue('A3', $proj['id'].' от '.$proj['created']);
- $sheet->setCellValue('A5', 'Общая информация');
- $sheet->setCellValue('A7', 'Пользователь Отчета об инспекции объекта осмотра:');
- $sheet->setCellValue('A8', 'Наименование Исполнителя:');
- $sheet->setCellValue('A9', 'ФИО Инспектора:');
- $sheet->setCellValue('A10', 'Дата проведения инспекции объекта осмотра:');
- $sheet->setCellValue('A11', 'Срок проведения инспекции объекта осмотра:');
- $sheet->setCellValue('A12', 'Дата составления Отчета об инспекции объекта осмотра:');
- $sheet->setCellValue('A14', 'Объект осмотра');
- $sheet->setCellValue('A16', 'Код объекта:');
- $sheet->setCellValue('A17', 'Наименование объекта:');
- $sheet->setCellValue('A19', 'Перечень выявленных дефектов');
- $sheet->setCellValue('B7', '<Компания - заказчик, заполняется вручную>');
- $sheet->setCellValue('B8', '<Компания - исполнитель, заполняется вручную>');
- $sheet->setCellValue('B10', date("d-m-Y", strtotime($finished)));
- $sheet->setCellValue('B11', "c ".date("d-m-Y", strtotime($finished))." по ".date("d-m-Y") );
- $sheet->setCellValue('B12', date("d-m-Y"));
- $sheet->setCellValue('B16', $proj['loco_number']);
- $sheet->getStyle("B16")->applyFromArray($styleLeft);
- $sheet->setCellValue('B17', "Локомотив серии ".$proj['loco_type']);
- $i=22;
- foreach ($array_children as $parent_id => $children)
- {
- if ($activeid != $parent_id)
- {
- continue;
- }
- foreach ($children as $res1) {
- $taskid = $res1['id'];
- $type = $res1['type'];
- $created = $res1['created'];
- $accepted = $res1['accepted_time'];
- $finished = $res1['finished_time'];
- $assignee = $res1['assignees_arr'];
- $assignee_names = GetAccount($assignee)['name'];
- if ($finished == '')
- $finished = 'не завершена';
- if ($accepted == '')
- $accepted = 'не принята';
- $namedesc = GetTaskNameAndDesc($type);
- $sheet->mergeCells("A$i:A".($i+2));
- $sheet->getStyle("A$i:B".($i+2))->applyFromArray($styleBorder);
- $sheet->getStyle("A$i")->applyFromArray($styleVertCenter);
- $sheet->getStyle("A$i")->getFont()->setBold(TRUE);
- $sheet->setCellValue("A$i", $namedesc[0]);
- $sheet->setCellValue("B".($i+1), "Замер:");
- $sheet->getStyle("A$i")->getAlignment()->setWrapText(true);
- // $sheet->setCellValueByColumnAndRow(0, $i, $taskid);
- // $sheet->setCellValueByColumnAndRow(1, $i, $namedesc[0]);
- // $sheet->setCellValueByColumnAndRow(2, $i, $namedesc[1]);
- // $sheet->setCellValueByColumnAndRow(3, $i, $finished);
- // $sheet->setCellValueByColumnAndRow(4, $i, $assignee_names);
- // $sheet->setCellValueByColumnAndRow(5, $i, $namedesc[1]);
- // $sheet->setCellValueByColumnAndRow(6, $i, $assignee_names);
- $notes = FindTaskNotes($taskid);
- if (sizeof($notes) > 0) {
- $nn = 1;
- foreach ($notes as $note) {
- $notedate = $note['date'];
- $noteid = $note['id'];
- $notetext = $note['text'];
- //$sheet->setCellValueByColumnAndRow($nn, $i, $noteid." [".$notedate."] ".$notetext);
- $b = $i+2;
- $imgpath = GetImagePathFromTask($res1);
- $files1 = scandir($imgpath);
- if (sizeof($files1) > 2)
- {
- $sheet->setCellValueByColumnAndRow($nn, $i, "Есть записи");
- }
- if (intval($notetext) > 0) //счетчик
- {
- $notetext = "Значение: ".$notetext;
- $b = $i;
- }
- else
- $notetext = "Выявлены недостатки: ".$notetext;
- $sheet->getStyle("B$b")->getAlignment()->setWrapText(true);
- $sheet->setCellValueByColumnAndRow($nn, $b, $notetext);
- $sheet->setCellValue("B".($i+1), "Замер:");
- continue;
- $nn++;
- }
- }
- $i+=3;
- }
- }
- $i+=2;
- $sheet->mergeCells("A$i:B$i");
- $sheet->getStyle("A$i")->getFont()->setSize(16);
- $sheet->getStyle("A$i")->getFont()->setBold(TRUE);
- $sheet->getStyle("A$i")->applyFromArray($styleCenter);
- $sheet->setCellValueByColumnAndRow(0, $i, 'Фотографии выявленных дефектов');
- $i++;
- foreach ($array_children as $parent_id => $children) {
- if ($activeid != $parent_id) {
- continue;
- }
- foreach ($children as $res1) {
- $imgpath = GetImagePathFromTask($res1);
- $files1 = scandir($imgpath);
- if (sizeof($files1) > 2)
- {
- $type = $res1['type'];
- $namedesc = GetTaskNameAndDesc($type);
- $sheet->mergeCells("A$i:B$i");
- $sheet->setCellValueByColumnAndRow(0, $i, $namedesc[0]);
- $i++;
- $k = 1;
- foreach ($files1 as $file )
- {
- $x = pathinfo($file)['extension'];
- if($file === '.' || $file === '..') {continue;}
- if ($x == 'jpg') {
- $objDrawing = new PHPExcel_Worksheet_Drawing();
- $objDrawing->setName('test_img');
- $objDrawing->setDescription('test_img');
- //$objDrawing->setPath('ProSysNew/logo.png');$imgpath$file
- $objDrawing->setPath("$imgpath$file");
- if ($k%2 == 0) {
- $objDrawing->setCoordinates("B$i");
- $i++;
- }
- else {
- $sheet->getRowDimension($i)->setRowHeight(200);
- $objDrawing->setCoordinates("A$i");
- }
- //setOffsetX works properly
- $objDrawing->setOffsetX(5);
- $objDrawing->setOffsetY(5);
- //set width, height
- $objDrawing->setWidth(250);
- $objDrawing->setHeight(200);
- $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
- $k++;
- }
- }
- }
- }
- }
- $i+=4;
- $sheet->mergeCells("A$i:B$i");
- $sheet->getStyle("A$i")->getFont()->setSize(16);
- $sheet->getStyle("A$i")->getFont()->setBold(TRUE);
- $sheet->getStyle("A$i")->applyFromArray($styleCenter);
- $sheet->setCellValueByColumnAndRow(0, $i, 'Приемная комиссия');
- $i++;
- $sheet->getStyle("A$i:B".($i+5))->applyFromArray($styleBorder);
- $sheet->setCellValueByColumnAndRow(0, $i, 'ФИО');
- $sheet->setCellValueByColumnAndRow(1, $i, 'Подпись');
- $sheet->getStyle("A".$i)->getFont()->setBold(TRUE);
- $sheet->getStyle("B".$i)->getFont()->setBold(TRUE);
- $sheet->setCellValueByColumnAndRow(0, $i+1, $assignee_names);
- //$i+=2;
- //$sheet->getRowDimension($i)->setRowHeight(30);
- //$sheet->setCellValueByColumnAndRow(2, $i, 'Исполнитель: '.$assignee_names);
- $sheet->setCellValue('B9', $assignee_names);
- // Rename worksheet
- $sheet->setTitle('Report');
- // Set active sheet index to the first sheet, so Excel opens this as the first sheet
- $objPHPExcel->setActiveSheetIndex(0);
- $sheet->getColumnDimension('A')->setWidth(50);
- $sheet->getColumnDimension('B')->setWidth(50);
- $sheet->getColumnDimension('C')->setAutoSize(true);
- $sheet->getColumnDimension('D')->setAutoSize(true);
- $sheet->getColumnDimension('E')->setAutoSize(true);
- $sheet->getColumnDimension('F')->setAutoSize(true);
- $sheet->getColumnDimension('G')->setAutoSize(true);
- $sheet->getColumnDimension('H')->setAutoSize(true);
- $sheet->getColumnDimension('I')->setAutoSize(true);
- $sheet->getColumnDimension('J')->setAutoSize(true);
- $sheet->getColumnDimension('K')->setAutoSize(true);
- $sheet->getColumnDimension('L')->setAutoSize(true);
- $sheet->getColumnDimension('M')->setAutoSize(true);
- $styleBorder = array('font' => array('bold' => true));
- $sheet->getStyle('B1:F1')->applyFromArray($styleBorder);
- $sheet->getStyle('A1')->getFont()->setBold(TRUE);
- //$sheet->getStyle('B1')->getFont()->getColor()->setRGB('FFFFFF');
-
- // Redirect output to a client’s web browser (Excel5)
- header('Content-Type: application/vnd.ms-excel');
- $date1 = date('d.m.Y-H.i', strtotime($finished));
- header('Content-Disposition: attachment;filename="task-'.$activeid.'-defects.xls');
- header('Cache-Control: max-age=0');
- // If you're serving to IE 9, then the following may be needed
- header('Cache-Control: max-age=1');
-
- // If you're serving to IE over SSL, then the following may be needed
- 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, 'Excel5');
- //$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
- $objWriter->save('php://output');
- ?>
|