Mister Spy Say ="Hello Kids ... :D"
___ ____ _ _____
| \/ (_) | | / ___|
| . . |_ ___| |_ ___ _ __ \ `--. _ __ _ _
| |\/| | / __| __/ _ \ '__| `--. \ '_ \| | | |
| | | | \__ \ || __/ | /\__/ / |_) | |_| |
\_| |_/_|___/\__\___|_| \____/| .__/ \__, |
| | __/ |
|_| |___/
Bot Mister Spy V3
Mister Spy
Mister Spy
<?php
require_once('class.excelhelper.php');
require_once('class.catalogos.php');
require_once('class.eventos.php');
require_once('class.eventosmorfologicosautoridades.php');
require_once('class.jurados.php');
require_once('class.premiosmorfologicos.php');
require_once('class.premiotipos.php');
require_once('class.misc.php');
require_once('class.rechazotipos.php');
require_once('class.rechazocondiciones.php');
require_once('class.sexos.php');
class ExcelTipoAptitudHelper extends ExcelHelper {
protected $categoriaActual = null;
protected $categoriaPrev = null;
protected $idSexo;
protected $categoriesRange = array();
public function __construct($idEvento, $boxPerPage = 19, $idSexo) {
parent::__construct($idEvento, $boxPerPage);
$this->templatePath = 'templates/tipo_aptitud.xlsx';
$this->filename = $this->evento->Denominacion . ' - Planilla Tipo y Aptitud - ' . Sexos::GetById($idSexo) . '.xlsx';
$this->infoCells = 'A11:AB26';
$this->idSexo = $idSexo;
}
protected function getAnimales() {
$oCatalogos = new Catalogos();
if (!$this->animales) {
$this->animales = $oCatalogos->GetAllCatalogoMorfologico(array('IdEvento' => $this->evento->IdEvento, 'TipoAptitud' => '1', 'IdSexo' => $this->idSexo));
}
return $this->animales;
}
protected function getCategoriaMorfologica() {
if (!$this->categoria) {
$oEventosMorfologicosAutoridades = new EventosMorfologicosAutoridades();
$oEventosMorfologicosAutoridad = $oEventosMorfologicosAutoridades->GetByIdEvento($this->evento->IdEvento);
$this->categoria = $oEventosMorfologicosAutoridad->Categoria;
}
return $this->categoria;
}
public function getJurado() {
if (!$this->jurado) {
$oEventosMorfologicosAutoridades = new EventosMorfologicosAutoridades();
$oJurados = new Jurados();
$oEventosMorfologicosAutoridad = $oEventosMorfologicosAutoridades->GetByIdEvento($this->evento->IdEvento);
$this->jurado = $oJurados->GetById($oEventosMorfologicosAutoridad->JAVE1);
}
return $this->jurado;
}
public function validate() {
return !!$this->getAnimales();
}
protected function getStyles() {
$headerStyle = array(
'font' => array(
'bold' => true,
'size' => 11
),
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
),
'borders' => array(
'outline' => array(
'style' => PHPExcel_Style_Border::BORDER_MEDIUM,
),
)
);
$headerStyle2 = array(
'font' => array(
'bold' => true,
'size' => 9
),
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
),
'borders' => array(
'outline' => array(
'style' => PHPExcel_Style_Border::BORDER_MEDIUM,
),
)
);
$headerStyleFill = array(
'font' => array(
'bold' => true,
'size' => 11
),
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
),
'borders' => array(
'outline' => array(
'style' => PHPExcel_Style_Border::BORDER_MEDIUM,
),
),
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('argb' => 'FFC0C0C0'), // Gris claro
),
);
$footerStyle = array(
'font' => array(
'bold' => false,
'size' => 11
),
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
),
'borders' => array(
'outline' => array(
'style' => PHPExcel_Style_Border::BORDER_MEDIUM,
),
),
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('argb' => 'FFFFFFFF'), // Gris claro
),
);
$animalStyle = array(
'font' => array(
'bold' => false,
'size' => 11
),
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
),
'borders' => array(
'outline' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN,
),
),
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('argb' => 'FFFFFFFF'), // Gris claro
),
);
$styles = array(
'B3' => array(
'font' => array(
'bold' => true,
'name' => 'Baskerville Old Face',
'size' => 22,
'underline' => PHPExcel_Style_Font::UNDERLINE_SINGLE, // Subrayado
),
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
)
),
'B5' => array(
'font' => array(
'size' => 18
),
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
)
),
'K6' => array(
'font' => array(
'bold' => true,
'size' => 12
)
),
'L6' => array(
'font' => array(
'bold' => true,
'size' => 12
)
),
'K7' => array(
'font' => array(
'bold' => true,
'size' => 12
)
),
'L7' => array(
'font' => array(
'bold' => true,
'size' => 12
)
),
'B7' => array(
'font' => array(
'bold' => true,
'size' => 12
)
),
'C7' => array(
'font' => array(
'bold' => true,
'size' => 12
)
),
'A9' => $headerStyle,
'A9' => $headerStyle,
'B9' => $headerStyleFill,
'C9' => $headerStyle,
'D9' => $headerStyle,
'E9' => $headerStyle,
'F9' => $headerStyle,
'G9' => $headerStyle,
'H9' => $headerStyle,
'I9' => $headerStyle,
'J9' => $headerStyle,
'K9' => $headerStyle,
'L9' => $headerStyle,
'M9' => $headerStyle,
// 'N9' => $headerStyle,
// 'O9' => $headerStyle,
'P9' => $headerStyle,
'Q9' => $headerStyle,
'R9' => $headerStyle,
'S9' => $headerStyle,
'T9' => $headerStyle,
'U9' => $headerStyle,
'V9' => $headerStyle,
// 'W9' => $headerStyle,
// 'X9' => $headerStyle,
// 'Y9' => $headerStyle,
// 'Z9' => $headerStyle,
// 'AA9' => $headerStyle,
// 'AB9' => $headerStyle,
'A10' => $headerStyle2,
'A10' => $headerStyle2,
'B10' => $headerStyle2,
'C10' => $headerStyle2,
'D10' => $headerStyle2,
'E10' => $headerStyle2,
'F10' => $headerStyle2,
'G10' => $headerStyle2,
'H10' => $headerStyle2,
'I10' => $headerStyle2,
'J10' => $headerStyle2,
'K10' => $headerStyle2,
'L10' => $headerStyle2,
'M10' => $headerStyle2,
'N10' => $headerStyle2,
'O10' => $headerStyleFill,
'P10' => $headerStyle2,
'Q10' => $headerStyle2,
'R10' => $headerStyle2,
'S10' => $headerStyle2,
'T10' => $headerStyle2,
'U10' => $headerStyle2,
'V10' => $headerStyle2,
'W10' => $headerStyleFill,
'X10' => $headerStyle2,
'Y10' => $headerStyle2,
'Z10' => $headerStyle2,
'AA10' => $headerStyle2,
'AB10' => $headerStyle2,
'C28' => $footerStyle,
'D28' => $footerStyle,
'E28' => $footerStyle,
'F28' => $footerStyle,
'B29' => $footerStyle,
'B30' => $footerStyle,
'B31' => $footerStyle,
'C29' => $footerStyle,
'C30' => $footerStyle,
'C31' => $footerStyle,
'D29' => $footerStyle,
'D30' => $footerStyle,
'D31' => $footerStyle,
'E29' => $footerStyle,
'E30' => $footerStyle,
'E31' => $footerStyle,
'F29' => $footerStyle,
'F30' => $footerStyle,
'F31' => $footerStyle,
'O29' => array(
'font' => array(
'bold' => true,
'size' => 11
)
),
'O31' => array(
'font' => array(
'bold' => true,
'size' => 11
)
),
'O33' => array(
'font' => array(
'bold' => true,
'size' => 11
)
),
'W30' => array(
'font' => array(
'bold' => true,
'size' => 11
)
),
);
for ($i = 11; $i < 27; $i++) {
$styles['A' . $i] = $animalStyle;
$styles['B' . $i] = $animalStyle;
$styles['C' . $i] = $animalStyle;
$styles['D' . $i] = $animalStyle;
$styles['E' . $i] = $animalStyle;
$styles['F' . $i] = $animalStyle;
$styles['G' . $i] = $animalStyle;
$styles['H' . $i] = $animalStyle;
$styles['I' . $i] = $animalStyle;
$styles['J' . $i] = $animalStyle;
$styles['K' . $i] = $animalStyle;
$styles['L' . $i] = $animalStyle;
$styles['M' . $i] = $animalStyle;
$styles['N' . $i] = $animalStyle;
$styles['O' . $i] = $animalStyle;
$styles['P' . $i] = $animalStyle;
$styles['Q' . $i] = $animalStyle;
$styles['R' . $i] = $animalStyle;
$styles['S' . $i] = $animalStyle;
$styles['T' . $i] = $animalStyle;
$styles['U' . $i] = $animalStyle;
$styles['V' . $i] = $animalStyle;
$styles['W' . $i] = $animalStyle;
$styles['X' . $i] = $animalStyle;
$styles['Y' . $i] = $animalStyle;
$styles['Z' . $i] = $animalStyle;
$styles['AA' . $i] = $animalStyle;
$styles['AB' . $i] = $animalStyle;
}
return $styles;
}
protected function setSheetHeader($activeSheet) {
$activeSheet->setCellValue('A2', 'Hoja NÂș ' . ($sheetIndex + 1));
$activeSheet->setCellValue('C7', $this->evento->Denominacion);
$activeSheet->setCellValue('L6', str_replace('-', '/', CambiarFecha($this->evento->EventoDesdeFecha)));
$activeSheet->setCellValue('L7', $this->getJurado()->Nombre . ' ' . $this->getJurado()->Apellido);
}
protected function setSheetStyles($activeSheet) {
foreach ($this->getStyles() as $key => $style) {
$activeSheet->getStyle($key)->applyFromArray($style);
}
}
private function optionNumbers($start = 1, $finish = 10, $step = 0.25) {
$options = array();
for ($i = $start; $i <= $finish; $i+= $step) {
$options[] = number_format($i, 2);
}
return $options;
}
protected function configureCell($activeSheet, $column, $cellIndex, $value, $protection = null, $options = null) {
if ($value) {
$value = str_replace('%index%', $cellIndex, $value);
$activeSheet->setCellValue($column . $cellIndex, $value);
} else {
$this->setSelectCell($activeSheet->getCell($column . $cellIndex), $options);
}
if ($protection) {
$activeSheet->getStyle($column . $cellIndex)->getProtection()->setLocked($protection);
}
}
protected function getOpcionesPremios($idTipo) {
$oPremiosMorfologicos = new PremiosMorfologicos();
$premios = $oPremiosMorfologicos->GetAll(array('IdTipo' => $idTipo));
$premios2 = null;
if ($idTipo == PremioTipos::Premios) {
$premios2 = $oPremiosMorfologicos->GetAll(array('IdTipo' => PremioTipos::Menciones));
}
$premiosSinPremio = $oPremiosMorfologicos->GetAll(array('IdTipo' => PremioTipos::SinPremio));
$arr = array();
foreach ($premios as $premio) {
$arr[] = utf8_encode($premio->Nombre);
}
if ($premios2) {
foreach ($premios2 as $premio) {
$arr[] = utf8_encode($premio->Nombre);
}
}
foreach ($premiosSinPremio as $premio) {
$arr[] = utf8_encode($premio->Nombre);
}
return $arr;
}
protected function setSheetValues($activeSheet, $cellIndex, $oAnimal, $count) {
$this->configureCell($activeSheet, 'A', $cellIndex, $oAnimal->Box);
$this->configureCell($activeSheet, 'B', $cellIndex, $oAnimal->MorfologiaCategoriaTA);
$this->configureCell($activeSheet, 'C', $cellIndex, $oAnimal->RP);
$this->configureCell($activeSheet, 'D', $cellIndex, $oAnimal->SBA);
$this->configureCell($activeSheet, 'H', $cellIndex, null, PHPExcel_Style_Protection::PROTECTION_UNPROTECTED, $this->optionNumbers(2));
$this->configureCell($activeSheet, 'I', $cellIndex, '=IF(H%index% <> "", SUBSTITUTE(H%index%, ".", ",", 1)*4, "")', PHPExcel_Style_Protection::PROTECTION_PROTECTED);
$this->configureCell($activeSheet, 'J', $cellIndex, null, PHPExcel_Style_Protection::PROTECTION_UNPROTECTED, $this->optionNumbers());
$this->configureCell($activeSheet, 'K', $cellIndex, '=IF(J%index% <> "", SUBSTITUTE(J%index%, ".", ",", 1)*2, "")', PHPExcel_Style_Protection::PROTECTION_PROTECTED);
$this->configureCell($activeSheet, 'L', $cellIndex, null, PHPExcel_Style_Protection::PROTECTION_UNPROTECTED, $this->optionNumbers());
$this->configureCell($activeSheet, 'M', $cellIndex, '=IF(L%index% <> "", SUBSTITUTE(L%index%, ".", ",", 1)*4, "")', PHPExcel_Style_Protection::PROTECTION_PROTECTED);
$this->configureCell($activeSheet, 'N', $cellIndex, '=IF(AND(I%index% <> "", K%index% <> "", M%index% <> ""), I%index%+K%index%+M%index%, "")', PHPExcel_Style_Protection::PROTECTION_PROTECTED);
$this->setSelectCell($activeSheet->getCell('O' . $cellIndex), $this->getOpcionesPremios(PremioTipos::Premios));
$this->configureCell($activeSheet, 'P', $cellIndex, '=IF(H%index% <> "", H%index%, "")', PHPExcel_Style_Protection::PROTECTION_PROTECTED);
$this->configureCell($activeSheet, 'Q', $cellIndex, '=IF(I%index% <> "", I%index%, "")', PHPExcel_Style_Protection::PROTECTION_PROTECTED);
$this->configureCell($activeSheet, 'R', $cellIndex, '=IF(J%index% <> "", J%index%, "")', PHPExcel_Style_Protection::PROTECTION_PROTECTED);
$this->configureCell($activeSheet, 'S', $cellIndex, '=IF(K%index% <> "", K%index%, "")', PHPExcel_Style_Protection::PROTECTION_PROTECTED);
$this->configureCell($activeSheet, 'T', $cellIndex, null, PHPExcel_Style_Protection::PROTECTION_UNPROTECTED, $this->optionNumbers());
$this->configureCell($activeSheet, 'U', $cellIndex, '=IF(T%index% <> "", SUBSTITUTE(T%index%, ".", ",", 1)*4, "")', PHPExcel_Style_Protection::PROTECTION_PROTECTED);
$this->configureCell($activeSheet, 'V', $cellIndex, '=IF(AND(Q%index% <> "", S%index% <> "", U%index% <> ""), Q%index%+S%index%+U%index%, "")', PHPExcel_Style_Protection::PROTECTION_PROTECTED);
$this->setSelectCell($activeSheet->getCell('W' . $cellIndex), $this->getOpcionesPremios(PremioTipos::Campeonato));
$this->setSelectCell($activeSheet->getCell('X' . $cellIndex), array('Asistio', 'Ausente'));
$this->setSelectCell($activeSheet->getCell('Y' . $cellIndex), array('Aceptado', 'Rechazado'));
$this->setSelectCell($activeSheet->getCell('Z' . $cellIndex), array_map(function($tipo) { return $tipo['Descripcion']; }, RechazoTipos::GetAll()));
$this->setSelectCell($activeSheet->getCell('AA' . $cellIndex), array_map(function($condicion) { return $condicion['Descripcion']; }, RechazoCondiciones::GetAll()));
}
protected function setCategoria($activeSheet, $oAnimal) {
if ($this->categoriaActual != $oAnimal->MorfologiaCategoriaTA) {
$this->categoriaPrev = $this->categoriaActual;
$this->categoriaActual = $oAnimal->MorfologiaCategoriaTA;
}
$activeSheet->setCellValue('A1', explode(' - ', $this->categoriaActual)[0]);
}
protected function setHeader($activeSheet, $idx) {
for ($col = 'A'; $col <= 'Q'; $col++) {
$originalCell = $activeSheet->getCell($col . '1');
$targetCell = $activeSheet->getCell($col . $idx);
$targetCell->setValue($originalCell->getValue());
$activeSheet->duplicateStyle($activeSheet->getStyle($col . '1'), $col . $idx);
$originalCell = $activeSheet->getCell($col . '2');
$targetCell = $activeSheet->getCell($col . ($idx + 1));
$targetCell->setValue($originalCell->getValue());
$activeSheet->duplicateStyle($activeSheet->getStyle($col . '2'), $col . ($idx + 1));
}
$activeSheet->mergeCells('B' . $idx . ':C' . $idx);
$activeSheet->mergeCells('D' . $idx . ':E' . $idx);
$activeSheet->mergeCells('F' . $idx . ':G' . $idx);
$activeSheet->mergeCells('H' . $idx . ':I' . $idx);
$activeSheet->mergeCells('J' . $idx . ':K' . $idx);
$activeSheet->mergeCells('L' . $idx . ':M' . $idx);
$activeSheet->mergeCells('N' . $idx . ':O' . $idx);
$activeSheet->mergeCells('P' . $idx . ':Q' . $idx);
$activeSheet->setCellValue('A' . $idx, explode(' - ', $this->categoriaActual)[0]);
}
// protected function configurePrizes($objPHPExcel) {
// $hiddenSheet = $objPHPExcel->createSheet(2)->setTitle('Datos Combinados');
// // $hiddenSheet->setSheetState(PHPExcel_Worksheet::SHEETSTATE_HIDDEN);
// $count = 0;
// foreach ($this->categoriesRange as $key => $range) {
// $items = 1;
// foreach ($range as $page => $indexes) {
// $sheet = $objPHPExcel->getSheetByName($page);
// $start = $indexes['startIdx'];
// $end = array_key_exists('endIdx', $indexes) ? $indexes['endIdx'] : 21;
// for ($i = $start; $i <= $end; $i++) {
// $cell = $this->columnIndexToLetter($count) . $items;
// $hiddenSheet->setCellValue($cell, "='$page'!H$i");
// $items++;
// }
// }
// foreach ($range as $page => $indexes) {
// $sheet = $objPHPExcel->getSheetByName($page);
// $start = $indexes['startIdx'];
// $end = array_key_exists('endIdx', $indexes) ? $indexes['endIdx'] : 21;
// for ($i = $start; $i <= $end; $i++) {
// $col = $this->columnIndexToLetter($count);
// $colStart = $col . '1';
// $colEnd = $col . $items;
// $sheet->setCellValue("I$i", "=IF(H$i <> \"\", RANK(H$i, 'Datos Combinados'!$colStart:$colEnd, 0), \"\")");
// }
// }
// $count++;
// }
// }
public function generateExcel() {
$this->loadTemplate();
$objPHPExcel = new PHPExcel();
$objPHPExcel->removeSheetByIndex(0);
$sheet = $this->template->getSheet(0);
$sheet->rebindParent($objPHPExcel);
$count = 0;
$sheetIndex = 0;
if ($this->validate()) {
$activeSheet = null;
foreach ($this->animales as $oAnimal) {
if ($count % $this->boxPerPage == 0) {
$objPHPExcel->addSheet($sheet->copy());
$objPHPExcel->setActiveSheetIndex($sheetIndex);
$activeSheet = $objPHPExcel->getActiveSheet();
$this->setSheetHeader($activeSheet);
$limit = ($sheetIndex * $this->boxPerPage + $this->boxPerPage);
if ($limit > count($this->animales)) {
$limit = count($this->animales);
}
$activeSheet->setTitle('Box ' . ($sheetIndex * $this->boxPerPage + 1) . ' - ' . $limit);
$this->setSheetStyles($activeSheet);
$sheetIndex++;
}
$cellIndex = ($count % $this->boxPerPage) + 11;
$this->setSheetValues($activeSheet, $cellIndex, $oAnimal, $count);
$count++;
}
}
$objPHPExcel->setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $this->filename . '"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
}
public function parseInfo($value, $reference) {
if (!$reference) {
return utf8_decode($value);
}
if ($value === '') {
return '';
}
if ($value == $reference) {
return '1';
}
return '0';
}
public function parsePremio($value, $idTipo) {
$oPremiosMorfologicos = new PremiosMorfologicos();
$premios = $oPremiosMorfologicos->GetAll(array('IdTipo' => $idTipo));
$premiosSinPremio = $oPremiosMorfologicos->GetAll(array('IdTipo' => PremioTipos::SinPremio));
foreach ($premios as $premio) {
if ($premio->Nombre == $value) {
return $premio;
}
}
foreach ($premiosSinPremio as $premio) {
if ($premio->Nombre == $value) {
return $premio;
}
}
return null;
}
public function parseRechazoTipo($value) {
foreach (RechazoTipos::GetAll() as $tipo) {
if ($tipo['Descripcion'] == $value) {
return $tipo['IdTipo'];
}
}
return null;
}
public function parseRechazoCondicion($value) {
foreach (RechazoCondiciones::GetAll() as $condicion) {
if ($condicion['Descripcion'] == $value) {
return $condicion['IdCondicion'];
}
}
return null;
}
}
?>
Mr. DellatioNx196 GaLers xh3LL Backd00r 1.0, Coded By Mr. DellatioNx196 - Bogor BlackHat