Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
857 righe
29 KiB
857 righe
29 KiB
<?php |
|
//exit(); |
|
|
|
switch ($_POST['action']) { |
|
case 'download': |
|
downloadFile(); |
|
break; |
|
case 'download_sconti': |
|
downloadSconti(); |
|
break; |
|
case 'download_estrazioni': |
|
downloadEstrazioni(); |
|
break; |
|
case 'download_mandati_xls': |
|
downloadMandatiXls(); |
|
break; |
|
case 'download_mandati_xml': |
|
downloadMandatiXml(); |
|
break; |
|
case 'download_mandati_pdf': |
|
downloadMandatoPdf(); |
|
break; |
|
case 'download_pagamenti_xls': |
|
downloadListaMandatiXls(); |
|
break; |
|
case 'downloadEstrazioneVistaXls'; |
|
downloadEstrazioneVistaXls(); |
|
break; |
|
case 'exportDecreti'; |
|
exportDecreti(); |
|
break; |
|
case 'exportAnagrafiche'; |
|
exportAnagrafiche(); |
|
break; |
|
case 'download_anagrafiche_xls': |
|
downloadAnagraficheXls(); |
|
} |
|
|
|
function downloadSconti() { |
|
global $LoggedAccount; |
|
//Utils::print_array($_POST);exit(); |
|
$id_sconto = intval($_POST['id']); |
|
if ($id_sconto > 0) { |
|
$sconto = new DomandaSconti($id_sconto); |
|
if (isset($_POST['type'])) { |
|
if ($_POST['type'] == 'biglietto') { |
|
$fileName = trim($sconto->FILEPATH_BIGLIETTO); |
|
} elseif ($_POST['type'] == 'imbarco') { |
|
$fileName = trim($sconto->FILEPATH_CARTAIMBARCO); |
|
} |
|
} |
|
//$istanza = Domanda::loadDomandaFromAccount(); |
|
$istanza = new Domanda($sconto->ID_DOMANDA); |
|
//$LoggedAccount->checkAuthShowDomandaPage($istanza->ID); |
|
$folder = $istanza->generateDirForUpload(ROOT_UPLOAD_PRESENTAZIONE, 'biglietti'); |
|
$filePath = $folder . '/' . $fileName; |
|
|
|
header('Content-Description: File Transfer'); |
|
header('Content-Type: application/octet-stream'); |
|
header('Content-Disposition: attachment; filename="' . $fileName . '"'); |
|
header('Content-Transfer-Encoding: binary'); |
|
header('Expires: 0'); |
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
header('Pragma: public'); |
|
header('Content-Length: ' . filesize($filePath)); |
|
ob_clean(); |
|
flush(); |
|
readfile($filePath); |
|
exit; |
|
} |
|
exit; |
|
} |
|
|
|
function downloadFile() { |
|
global $LoggedAccount; |
|
$id_allegato = intval($_POST['id']); |
|
if ($id_allegato > 0) { |
|
|
|
$allegato = new Allegati($id_allegato); |
|
if (isset($_POST['file'])) { |
|
$fileName = trim($_POST['file']); |
|
} else { |
|
$fileName = $allegato->FILEPATH; |
|
} |
|
$domanda = new Domanda($allegato->ID_DOMANDA); |
|
//$LoggedAccount->checkAuthShowDomandaPage($domanda->ID); |
|
|
|
$documenti_bando = new DocumentiBando($allegato->ID_DOCUMENTO); |
|
$pathInfo = $documenti_bando->getPathInfoDocumento(); |
|
$folder = $domanda->generateDirForUpload(ROOT_UPLOAD_PRESENTAZIONE, $pathInfo["PATH_DOCUMENTO"]); |
|
$filePath = $folder . '/' . $fileName; |
|
|
|
if (filesize($filePath)) { |
|
header('Content-Description: File Transfer'); |
|
header('Content-Type: application/octet-stream'); |
|
header('Content-Disposition: attachment; filename="' . $fileName . '"'); |
|
header('Content-Transfer-Encoding: binary'); |
|
header('Expires: 0'); |
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
header('Pragma: public'); |
|
header('Content-Length: ' . filesize($filePath)); |
|
ob_clean(); |
|
flush(); |
|
readfile($filePath); |
|
} else { |
|
echo "Il file non esiste!"; |
|
} |
|
exit; |
|
} |
|
exit; |
|
} |
|
|
|
function downloadIstanza() { |
|
global $LoggedAccount; |
|
$response = Utils::initDefaultResponse(); |
|
$id_domanda = intval($_POST['id']); |
|
if ($id_domanda > 0) { |
|
$domanda = new Domanda($id_domanda); |
|
} |
|
|
|
if ($domanda->STATO == PREPARATA) { |
|
|
|
$filePath = File::getFolderFromDomanda($domanda, ROOT_UPLOAD_PRESENTAZIONE); |
|
$filePath .= "/domanda_generata/" . $domanda->ALLEGATO_GENERATO; |
|
if (file_exists($filePath) && filesize($filePath) > 0) { |
|
header('Content-Description: File Transfer'); |
|
header('Content-Type: application/octet-stream'); |
|
header('Content-Disposition: attachment; filename=' . File::GetValidFilename($domanda->ALLEGATO_GENERATO)); |
|
header('Content-Transfer-Encoding: binary'); |
|
header('Expires: 0'); |
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
header('Pragma: public'); |
|
header('Content-Length: ' . filesize($filePath)); |
|
ob_clean(); |
|
flush(); |
|
readfile($filePath); |
|
exit; |
|
} else { |
|
echo "Si prega di procedere alla generazione del file."; |
|
} |
|
} else { |
|
$response['erroreDescrizione'] = 'Operazione non consentita in questa fase.'; |
|
exit; |
|
} |
|
exit; |
|
} |
|
|
|
function downloadProtocollo() { |
|
global $LoggedAccount; |
|
$response = Utils::initDefaultResponse(); |
|
$id_domanda = intval($_POST['id']); |
|
if ($id_domanda > 0) { |
|
$domanda = new Domanda($id_domanda); |
|
} |
|
|
|
if ($domanda->STATO == PREPARATA) { |
|
|
|
$filePath = File::getFolderFromDomanda($domanda, ROOT_UPLOAD_PRESENTAZIONE); |
|
$filePath .= "/domanda_protocollo/" . $domanda->FILEPATH_PROTOCOLLO; |
|
if (file_exists($filePath) && filesize($filePath) > 0) { |
|
header('Content-Description: File Transfer'); |
|
header('Content-Type: application/octet-stream'); |
|
header('Content-Disposition: attachment; filename=' . File::GetValidFilename($domanda->FILEPATH_PROTOCOLLO)); |
|
header('Content-Transfer-Encoding: binary'); |
|
header('Expires: 0'); |
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
header('Pragma: public'); |
|
header('Content-Length: ' . filesize($filePath)); |
|
ob_clean(); |
|
flush(); |
|
readfile($filePath); |
|
exit; |
|
} else { |
|
echo "Si prega di procedere alla generazione del file."; |
|
} |
|
} else { |
|
$response['erroreDescrizione'] = 'Operazione non consentita in questa fase.'; |
|
exit; |
|
} |
|
exit; |
|
} |
|
|
|
function printAllegato($allegato, $domanda) { |
|
global $LoggedAccount; |
|
if (!empty($allegato) && !empty($domanda)) { |
|
if ($allegato->FILEPATH != "") { |
|
$file = $allegato->FILEPATH; |
|
if ($LoggedAccount->checkIstitutoFromLoggedAccount($domanda->CODICE_ISTITUTO)) { // controllo proprietario domanda |
|
switch ($allegato->TIPO_DOCUMENTO) { |
|
case TIPO_UPLOAD_OBBLIGATORIO: |
|
$basePath = File::getFolderFromDomanda($domanda, ROOT_UPLOAD_PRESENTAZIONE); |
|
$basePath .= '/obbligatori/'; |
|
break; |
|
case TIPO_UPLOAD_OPZIONALE: |
|
$basePath = File::getFolderFromDomanda($domanda, ROOT_UPLOAD_PRESENTAZIONE); |
|
$basePath .= '/opzionali/'; |
|
break; |
|
case TIPO_UPLOAD_ISTANZA: |
|
$basePath = File::getFolderFromDomanda($domanda, ROOT_UPLOAD_PRESENTAZIONE); |
|
$basePath .= '/istanza/'; |
|
break; |
|
case TIPO_UPLOAD_CONTRIBUTO: |
|
$basePath = File::getFolderFromDomanda($domanda, ROOT_UPLOAD_EROGAZIONE); |
|
$basePath .= '/contributo/'; |
|
break; |
|
} |
|
$filePath = $basePath . $file; |
|
if (file_exists($filePath) && filesize($filePath) > 0) { |
|
header('Content-Description: File Transfer'); |
|
header('Content-Type: application/octet-stream'); |
|
header('Content-Disposition: attachment; filename=' . File::GetValidFilename($file)); |
|
header('Content-Transfer-Encoding: binary'); |
|
header('Expires: 0'); |
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
header('Pragma: public'); |
|
header('Content-Length: ' . filesize($filePath)); |
|
ob_clean(); |
|
flush(); |
|
readfile($filePath); |
|
exit; |
|
} else { |
|
$msg = "Non è possibile visualizzare il file richiesto, contattare il supporto tecnico (1316)."; |
|
} |
|
} else { |
|
$msg = "Accesso non autorizzato"; |
|
} |
|
} else { |
|
$msg = "Non è possibile visualizzare il file richiesto, contattare il supporto tecnico (1321)."; |
|
} |
|
} else { |
|
$msg = "Non è possibile visualizzare il file richiesto, contattare il supporto tecnico (1325)."; |
|
} |
|
|
|
echo $msg; |
|
} |
|
|
|
function downloadEstrazioni() { |
|
global $TIPO_RICHIESTA; |
|
$success = true; |
|
$result = Utils::initDefaultResponse(); |
|
$lotto = intval($_POST['lotto']); |
|
$stato = intval($_POST['stato']); |
|
|
|
$rec = DomandaSconti::listLottoFromExport($lotto, $stato); |
|
|
|
$estrazione = new Esportazioni($lotto); |
|
|
|
$dataArray = array(); |
|
$row = 0; |
|
$intestazione = true; |
|
foreach ($rec as $key => $value) { |
|
if ($key == 0 && $intestazione) { |
|
foreach ($value as $k => $v) { |
|
$dataArray[$row][] = $k; |
|
} |
|
} |
|
$row++; |
|
$dataArray[$row] = $value; |
|
} |
|
|
|
|
|
//Utils::print_array($dataArray);exit(); |
|
|
|
$prefile = 'estrazione'; |
|
|
|
$basepath = ROOT_EROGAZIONE . "ESTRAZIONI/"; |
|
if (!is_dir($basepath)) |
|
@mkdir($basepath, 0777, true); |
|
|
|
$file = $lotto . "_" . $stato . "_" . $prefile . "_" . $TIPO_RICHIESTA[$estrazione->TIPO] . "_" . time() . ".xlsx"; |
|
if (file_exists($basepath . $file)) |
|
@unlink($basepath . $file); |
|
|
|
$export = new SimpleXLSXGen(); |
|
|
|
$report = $basepath . $file; |
|
$export->fromArray($dataArray)->saveAs($report); |
|
ob_clean(); |
|
if (file_exists($report)) { |
|
$url = $report; |
|
header('Content-Description: File Transfer'); |
|
header('Content-Type: application/octet-stream'); |
|
header('Content-Disposition: attachment; filename=' . File::GetValidFilename($file)); |
|
header('Content-Transfer-Encoding: binary'); |
|
header('Expires: 0'); |
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
header('Pragma: public'); |
|
header('Content-Length: ' . filesize($url)); |
|
ob_clean(); |
|
flush(); |
|
readfile($url); |
|
exit; |
|
} else { |
|
echo "Il file non esiste!"; |
|
} |
|
exit; |
|
} |
|
|
|
function downloadMandatiXls() { |
|
global $TIPO_RICHIESTA; |
|
$success = true; |
|
$result = Utils::initDefaultResponse(); |
|
$lotto = intval($_POST['lotto']); |
|
$stato = intval($_POST['stato']); |
|
|
|
$rec = DomandaSconti::listLottoFromMandatiXls($lotto, $stato); |
|
$estrazione = new Esportazioni($lotto); |
|
|
|
$dataArray = array(); |
|
$row = 0; |
|
$intestazione = true; |
|
foreach ($rec as $key => $value) { |
|
if ($key == 0 && $intestazione) { |
|
foreach ($value as $k => $v) { |
|
$dataArray[$row][] = $k; |
|
} |
|
} |
|
$row++; |
|
$dataArray[$row] = $value; |
|
} |
|
|
|
|
|
//Utils::print_array($dataArray);exit(); |
|
|
|
$prefile = 'mandato'; |
|
|
|
$basepath = ROOT_EROGAZIONE . "MANDATI/"; |
|
if (!is_dir($basepath)) |
|
@mkdir($basepath, 0777, true); |
|
|
|
$file = $lotto . "_" . $stato . "_" . $prefile . "_" . $TIPO_RICHIESTA[$estrazione->TIPO] . "_" . time() . ".xlsx"; |
|
if (file_exists($basepath . $file)) |
|
@unlink($basepath . $file); |
|
|
|
$export = new SimpleXLSXGen(); |
|
|
|
$report = $basepath . $file; |
|
$export->fromArray($dataArray)->saveAs($report); |
|
ob_clean(); |
|
if (file_exists($report)) { |
|
$url = $report; |
|
header('Content-Description: File Transfer'); |
|
header('Content-Type: application/octet-stream'); |
|
header('Content-Disposition: attachment; filename=' . File::GetValidFilename($file)); |
|
header('Content-Transfer-Encoding: binary'); |
|
header('Expires: 0'); |
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
header('Pragma: public'); |
|
header('Content-Length: ' . filesize($url)); |
|
ob_clean(); |
|
flush(); |
|
readfile($url); |
|
exit; |
|
} else { |
|
echo "Il file non esiste!"; |
|
} |
|
exit; |
|
} |
|
|
|
function downloadMandatiXml() { |
|
$success = true; |
|
$result = Utils::initDefaultResponse(); |
|
$lotto = intval($_POST['lotto']); |
|
$stato = intval($_POST['stato']); |
|
|
|
$basepath = ROOT_EROGAZIONE . "MANDATI/"; |
|
if (!is_dir($basepath)) |
|
@mkdir($basepath, 0777, true); |
|
$nomeFile = time() . "_mandati.zip"; |
|
$destination = $basepath . $nomeFile; |
|
$zip = new ZipArchive(); |
|
|
|
$resZip = $zip->open($destination, ZIPARCHIVE::CREATE); |
|
//var_dump($resZip); |
|
if ($resZip !== TRUE) { |
|
|
|
$res['success'] = false; |
|
$res['descrizioneErrore'] = 'Errore: impossibile creare il file zip'; |
|
exit(json_encode($res)); |
|
} |
|
|
|
|
|
$record = DomandaSconti::listLottoFromMandatiXml($lotto, $stato); |
|
|
|
$blocchi = array_chunk($record, 100); |
|
$num = 0; |
|
foreach ($blocchi as $rec) { |
|
|
|
$xml_mandati = ""; |
|
$tot_Importo_Lordo = 0; |
|
foreach ($rec as $key => $value) { |
|
$xml_mandati .= "<Nazionalita_Italiana>"; |
|
foreach ($value as $k => $v) { |
|
$xml_mandati .= "<" . $k . ">" . $v . "</" . $k . ">"; |
|
if ($k == 'Importo_Lordo') { |
|
$tot_Importo_Lordo += $v; |
|
} |
|
} |
|
$xml_mandati .= "</Nazionalita_Italiana>"; |
|
} |
|
|
|
$tagXml_Id_mandato = TAGXML_ID_MANDATO; |
|
$tagXml_Capitolo = TAGXML_CAPITOLO; |
|
$tagXml_Anno_Provenienza = TAGXML_ANNO_PROVENIENZA; |
|
$tagXml_Impegno = TAGXML_IMPEGNO; |
|
$tagXml_Progressivo_DLQ = TAGXML_PROGRESSIVO_DLQ; |
|
$tagXml_Tipo_Mandato = TAGXML_TIPO_MANDATO; |
|
$tagXml_Collettivo = TAGXML_COLLETTIVO; |
|
$tagXml_Territorio = TAGXML_TERRITORIO; |
|
$tagXml_Importo_Lordo = number_format($tot_Importo_Lordo, 2, '.', ''); |
|
$tagXml_Importo_Netto = number_format($tot_Importo_Lordo, 2, '.', ''); |
|
$tagXml_Descrizione = TAGXML_DESCRIZIONE; |
|
$tagXml_Nr_Beneficiari = count($rec); |
|
$tagXml_Provincia = TAGXML_PROVINCIA; |
|
$tagXml_Comune = TAGXML_COMUNE; |
|
$tagXml_Modalita = TAGXML_MODALITA; |
|
$tagXml_Codice_SIOPE = TAGXML_CODICE_SIOPE; |
|
$tagXml_Impegno_Contestuale = TAGXML_IMPEGNO_CONTESTUALE; |
|
$tagXml_Data_Scadenza = TAGXML_DATA_SCADENZA; |
|
|
|
$string = "<?xml version='1.0' encoding=\"UTF-8\"?><Mandati xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><ImportMandato><Id_mandato>" . $tagXml_Id_mandato . "</Id_mandato><Dati_generali_mandato><Capitolo>" . $tagXml_Capitolo . "</Capitolo><Anno_Provenienza>" . $tagXml_Anno_Provenienza . "</Anno_Provenienza><Impegno>" . $tagXml_Impegno . "</Impegno><Progressivo_DLQ>" . $tagXml_Progressivo_DLQ . "</Progressivo_DLQ><Tipo_Mandato>" . $tagXml_Tipo_Mandato . "</Tipo_Mandato><Collettivo>" . $tagXml_Collettivo . "</Collettivo><Territorio>" . $tagXml_Territorio . "</Territorio><Importo_Lordo>" . $tagXml_Importo_Lordo . "</Importo_Lordo><Importo_Netto>" . $tagXml_Importo_Netto . "</Importo_Netto><Descrizione>" . $tagXml_Descrizione . "</Descrizione><Nr_Beneficiari>" . $tagXml_Nr_Beneficiari . "</Nr_Beneficiari><Provincia>" . $tagXml_Provincia . "</Provincia><Comune>" . $tagXml_Comune . "</Comune><Modalita>" . $tagXml_Modalita . "</Modalita><Codice_SIOPE>" . $tagXml_Codice_SIOPE . "</Codice_SIOPE><Impegno_Contestuale>" . $tagXml_Impegno_Contestuale . "</Impegno_Contestuale><Data_Scadenza>" . $tagXml_Data_Scadenza . "</Data_Scadenza></Dati_generali_mandato><Dati_beneficiari_mandato>" . $xml_mandati . "</Dati_beneficiari_mandato></ImportMandato></Mandati>"; |
|
|
|
$num++; |
|
$prefile = 'mandato-' . $num; |
|
|
|
$file = $lotto . "_" . $stato . "_" . $prefile . "_" . time() . ".xml"; |
|
if (file_exists($basepath . $file)) |
|
@unlink($basepath . $file); |
|
|
|
$report = $basepath . $file; |
|
|
|
$xml = simplexml_load_string($string); |
|
$xml->asXML($report); |
|
|
|
$zip->addFile($basepath . $file, $file); |
|
} |
|
|
|
$zip->close(); |
|
$report = $destination; |
|
|
|
//Utils::print_array($dataArray);exit(); |
|
|
|
|
|
ob_clean(); |
|
if (file_exists($report)) { |
|
$url = $report; |
|
header('Content-Description: File Transfer'); |
|
header('Content-Type: application/octet-stream'); |
|
header('Content-Disposition: attachment; filename=' . File::GetValidFilename($nomeFile)); |
|
header('Content-Transfer-Encoding: binary'); |
|
header('Expires: 0'); |
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
header('Pragma: public'); |
|
header('Content-Length: ' . filesize($url)); |
|
ob_clean(); |
|
flush(); |
|
readfile($url); |
|
exit; |
|
} else { |
|
echo "Il file non esiste!"; |
|
} |
|
exit; |
|
} |
|
|
|
function downloadListaMandatiXls() { |
|
$success = true; |
|
$result = Utils::initDefaultResponse(); |
|
$lotto = intval($_POST['lotto']); |
|
$stato = intval($_POST['stato']); |
|
|
|
$basepath = ROOT_EROGAZIONE . "MANDATI/"; |
|
if (!is_dir($basepath)) |
|
@mkdir($basepath, 0777, true); |
|
$nomeFile = $lotto . "_" . $stato . "_mandati_" . time() . ".zip"; |
|
$destination = $basepath . $nomeFile; |
|
$zip = new ZipArchive(); |
|
|
|
$resZip = $zip->open($destination, ZIPARCHIVE::CREATE); |
|
//var_dump($resZip); |
|
if ($resZip !== TRUE) { |
|
|
|
$res['success'] = false; |
|
$res['descrizioneErrore'] = 'Errore: impossibile creare il file zip'; |
|
exit(json_encode($res)); |
|
} |
|
|
|
|
|
$record = DomandaSconti::listLottoFromPagamentiXls($lotto, $stato); |
|
$blocchi = array_chunk($record, 500); |
|
$num = 0; |
|
foreach ($blocchi as $rec) { |
|
$dataArray = array(); |
|
$row = 0; |
|
foreach ($rec as $key => $value) { |
|
if ($key == 0) { |
|
foreach ($value as $k => $v) { |
|
$dataArray[$row][] = $k; |
|
} |
|
} |
|
$row++; |
|
$dataArray[$row] = $value; |
|
} |
|
|
|
$num++; |
|
$prefile = 'mandato-' . $num; |
|
|
|
$file = $lotto . "_" . $stato . "_" . $prefile . "_" . time() . ".xlsx"; |
|
if (file_exists($basepath . $file)) |
|
@unlink($basepath . $file); |
|
|
|
$export = new SimpleXLSXGen(); |
|
|
|
$reportXls = $basepath . $file; |
|
$export->fromArray($dataArray)->saveAs($reportXls); |
|
|
|
$zip->addFile($basepath . $file, $file); |
|
} |
|
|
|
$zip->close(); |
|
$report = $destination; |
|
|
|
//Utils::print_array($dataArray);exit(); |
|
|
|
|
|
ob_clean(); |
|
if (file_exists($report)) { |
|
$url = $report; |
|
header('Content-Description: File Transfer'); |
|
header('Content-Type: application/octet-stream'); |
|
header('Content-Disposition: attachment; filename=' . File::GetValidFilename($nomeFile)); |
|
header('Content-Transfer-Encoding: binary'); |
|
header('Expires: 0'); |
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
header('Pragma: public'); |
|
header('Content-Length: ' . filesize($url)); |
|
ob_clean(); |
|
flush(); |
|
readfile($url); |
|
exit; |
|
} else { |
|
echo "Il file non esiste!"; |
|
} |
|
exit; |
|
} |
|
|
|
function downloadMandatoPdf() { |
|
|
|
|
|
$nomeFile = $_POST['nomeFile']; |
|
|
|
$basepath = ROOT_EROGAZIONE . "MANDATI/"; |
|
if (!is_dir($basepath)) |
|
@mkdir($basepath, 0777, true); |
|
|
|
$report = $basepath . $nomeFile; |
|
|
|
ob_clean(); |
|
if (file_exists($report)) { |
|
$url = $report; |
|
header('Content-Description: File Transfer'); |
|
header('Content-Type: application/octet-stream'); |
|
header('Content-Disposition: attachment; filename=' . File::GetValidFilename($nomeFile)); |
|
header('Content-Transfer-Encoding: binary'); |
|
header('Expires: 0'); |
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
header('Pragma: public'); |
|
header('Content-Length: ' . filesize($url)); |
|
ob_clean(); |
|
flush(); |
|
readfile($url); |
|
exit; |
|
} else { |
|
echo "Il file non esiste!"; |
|
} |
|
exit; |
|
} |
|
|
|
function downloadEstrazioneVistaXls() { |
|
$success = true; |
|
$result = Utils::initDefaultResponse(); |
|
|
|
$rec = DomandaSconti::listEsportVista(); |
|
|
|
$dataArray = array(); |
|
$row = 0; |
|
$intestazione = true; |
|
foreach ($rec as $key => $value) { |
|
if ($key == 0 && $intestazione) { |
|
foreach ($value as $k => $v) { |
|
$dataArray[$row][] = $k; |
|
} |
|
$dataArray[$row][] = "STUDENTE"; |
|
$dataArray[$row][] = "DISABILE"; |
|
} |
|
$row++; |
|
|
|
foreach ($value as $k => $v) { |
|
if ($k == "FLAG") { |
|
$value['STUDENTE'] = Utils::isStudente($v) == 1 ? "SI" : "NO"; |
|
$value['DISABILE'] = Utils::isDisable($v) == 1 ? "SI" : "NO"; |
|
} |
|
} |
|
|
|
$dataArray[$row] = $value; |
|
} |
|
|
|
|
|
//Utils::print_array($dataArray);exit(); |
|
|
|
$prefile = 'estrazione'; |
|
|
|
$basepath = ROOT_EROGAZIONE . "ESTRAZIONI/"; |
|
if (!is_dir($basepath)) |
|
@mkdir($basepath, 0777, true); |
|
|
|
$file = "VISTA_ALL_" . $prefile . "_" . time() . ".xlsx"; |
|
if (file_exists($basepath . $file)) |
|
@unlink($basepath . $file); |
|
|
|
$export = new SimpleXLSXGen(); |
|
|
|
$report = $basepath . $file; |
|
$export->fromArray($dataArray)->saveAs($report); |
|
ob_clean(); |
|
if (file_exists($report)) { |
|
$url = $report; |
|
header('Content-Description: File Transfer'); |
|
header('Content-Type: application/octet-stream'); |
|
header('Content-Disposition: attachment; filename=' . File::GetValidFilename($file)); |
|
header('Content-Transfer-Encoding: binary'); |
|
header('Expires: 0'); |
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
header('Pragma: public'); |
|
header('Content-Length: ' . filesize($url)); |
|
ob_clean(); |
|
flush(); |
|
readfile($url); |
|
exit; |
|
} else { |
|
echo "Il file non esiste!"; |
|
} |
|
exit; |
|
} |
|
|
|
function exportDecreti() { |
|
$success = true; |
|
$result = Utils::initDefaultResponse(); |
|
$lotto = intval($_POST['lotto']); |
|
$stato = intval($_POST['stato']); |
|
$omissis = intval($_POST['omissis']); |
|
$priorita = intval($_POST['priorita']); |
|
$intestazione = array("ID Richiesta", "COGNOME", "NOME", "CODICE FISCALE", "DATA DI NASCITA", "Località", "Provincia", "Importo sconto", "IBAN"); |
|
|
|
$dataArray = DomandaSconti::exportDecreti($lotto, $stato, $omissis); |
|
array_unshift($dataArray, $intestazione); |
|
|
|
$stringaPre = ""; |
|
if ($priorita == 0) { |
|
$stringaPre = "_Residenti"; |
|
} else { |
|
$stringaPre = "_Prioritari_"; |
|
} |
|
$stringaOm = ""; |
|
if ($omissis == 1) { |
|
$stringaOm = "_OMISSIS_"; |
|
} |
|
// Utils::print_array($dataArray);exit(); |
|
$prefile = 'Decreti'; |
|
$basepath = ROOT_EROGAZIONE . "ESTRAZIONI/"; |
|
if (!is_dir($basepath)) |
|
@mkdir($basepath, 0777, true); |
|
|
|
$file = $prefile . $stringaPre . "_" . $lotto . "_" . $stringaOm . time() . ".xlsx"; |
|
if (file_exists($basepath . $file)) |
|
@unlink($basepath . $file); |
|
|
|
$export = new SimpleXLSXGen(); |
|
|
|
$report = $basepath . $file; |
|
$export->fromArray($dataArray)->saveAs($report); |
|
ob_clean(); |
|
if (file_exists($report)) { |
|
$url = $report; |
|
header('Content-Description: File Transfer'); |
|
header('Content-Type: application/octet-stream'); |
|
header('Content-Disposition: attachment; filename=' . File::GetValidFilename($file)); |
|
header('Content-Transfer-Encoding: binary'); |
|
header('Expires: 0'); |
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
header('Pragma: public'); |
|
header('Content-Length: ' . filesize($url)); |
|
ob_clean(); |
|
flush(); |
|
readfile($url); |
|
exit; |
|
} else { |
|
echo "Il file non esiste!"; |
|
} |
|
exit; |
|
} |
|
|
|
function exportAnagrafiche() { |
|
$success = true; |
|
$result = Utils::initDefaultResponse(); |
|
$lotto = intval($_POST['lotto']); |
|
$stato = intval($_POST['stato']); |
|
$priorita = intval($_POST['priorita']); |
|
|
|
$intestazione = array("COGNOME", "NOME", "CODICE FISCALE", "SESSO", "LUOGO DI NASCITA", "PROV", "DATA DI NASCITA", "INDIRIZZO", "CAP", "LOCALITA", "IBAN", "SCONTO_TOTALE"); |
|
|
|
$dataArray = DomandaSconti::exportAnagrafiche($lotto, $stato); |
|
$dataFormattata = array(); |
|
foreach ($dataArray as $row) { |
|
// Formatta la data nel formato corretto |
|
$row['DATA DI NASCITA'] = date('Y-m-d', strtotime($row['DATA DI NASCITA'])); |
|
$dataFormattata[] = $row; // Aggiungi la riga formattata a un nuovo array |
|
} |
|
|
|
array_unshift($dataFormattata, $intestazione); |
|
$stringaPre = ""; |
|
if ($priorita == 0) { |
|
$stringaPre = "_Residenti"; |
|
} else { |
|
$stringaPre = "_Prioritari_"; |
|
} |
|
// Utils::print_array($dataFormattata); |
|
// exit(); |
|
$prefile = 'Anagrafiche'; |
|
$basepath = ROOT_EROGAZIONE . "ESTRAZIONI/"; |
|
if (!is_dir($basepath)) |
|
@mkdir($basepath, 0777, true); |
|
|
|
$file = $prefile . $stringaPre . "_" . $lotto . "_" . time() . ".xlsx"; |
|
if (file_exists($basepath . $file)) |
|
@unlink($basepath . $file); |
|
|
|
$export = new SimpleXLSXGen(); |
|
|
|
$report = $basepath . $file; |
|
$export->fromArray($dataFormattata)->saveAs($report); |
|
ob_clean(); |
|
if (file_exists($report)) { |
|
$url = $report; |
|
header('Content-Description: File Transfer'); |
|
header('Content-Type: application/octet-stream'); |
|
header('Content-Disposition: attachment; filename=' . File::GetValidFilename($file)); |
|
header('Content-Transfer-Encoding: binary'); |
|
header('Expires: 0'); |
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
header('Pragma: public'); |
|
header('Content-Length: ' . filesize($url)); |
|
ob_clean(); |
|
flush(); |
|
readfile($url); |
|
exit; |
|
} else { |
|
echo "Il file non esiste!"; |
|
} |
|
exit; |
|
} |
|
|
|
function downloadAnagraficheXls() { |
|
$success = true; |
|
$result = Utils::initDefaultResponse(); |
|
$lotto = intval($_POST['lotto']); |
|
$stato = intval($_POST['stato']); |
|
|
|
$basepath = ROOT_EROGAZIONE . "ANAGRAFICHE/"; |
|
if (!is_dir($basepath)) { |
|
@mkdir($basepath, 0777, true); |
|
} |
|
|
|
$nomeFile = $lotto . "_" . $stato . "_anagrafiche_" . time() . ".zip"; |
|
$destination = $basepath . $nomeFile; |
|
$zip = new ZipArchive(); |
|
|
|
$resZip = $zip->open($destination, ZIPARCHIVE::CREATE); |
|
if ($resZip !== true) { |
|
$res['success'] = false; |
|
$res['descrizioneErrore'] = 'Errore: impossibile creare il file zip'; |
|
exit(json_encode($res)); |
|
} |
|
|
|
// Recupero dati e formattazione |
|
$dataArray = DomandaSconti::exportAnagrafiche($lotto, $stato); |
|
$dataFormattata = array_map(function ($row) { |
|
$row['DATA DI NASCITA'] = date('Y-m-d', strtotime($row['DATA DI NASCITA'])); |
|
return array_slice($row, 0, -2); // Rimuove le ultime 2 colonne |
|
}, $dataArray); |
|
|
|
// Divisione in blocchi da 500 |
|
$blocchi = array_chunk($dataFormattata, 500); |
|
$start = 1; |
|
$cartelleCreate = []; |
|
foreach ($blocchi as $index => $rec) { |
|
$end = $start + count($rec) - 1; |
|
$folderName = "Anagrafiche_{$start}-{$end}"; |
|
$folderPath = $basepath . $folderName . "/"; |
|
|
|
if (!is_dir($folderPath)) { |
|
@mkdir($folderPath, 0777, true); |
|
$cartelleCreate[] = $folderPath; |
|
} |
|
|
|
// Creazione file Excel |
|
$fileName = "TemplateImportAnagrafica.xlsx"; |
|
$filePath = $folderPath . $fileName; |
|
|
|
$dataArray = []; |
|
$row = 0; |
|
foreach ($rec as $key => $value) { |
|
if ($key == 0) { |
|
$dataArray[$row] = array_keys($value); |
|
$row++; |
|
} |
|
$dataArray[$row] = array_values($value); |
|
$row++; |
|
} |
|
|
|
$export = new SimpleXLSXGen(); |
|
$export->addSheet($dataArray, 'template')->saveAs($filePath); |
|
|
|
// Aggiunta file allo ZIP |
|
$zip->addFile($filePath, "$folderName/$fileName"); |
|
|
|
$start = $end + 1; |
|
} |
|
|
|
$zip->close(); |
|
$report = $destination; |
|
|
|
foreach ($cartelleCreate as $folder) { |
|
deleteFolder($folder); |
|
} |
|
//Utils::print_array($dataArray);exit(); |
|
|
|
|
|
ob_clean(); |
|
if (file_exists($report)) { |
|
$url = $report; |
|
header('Content-Description: File Transfer'); |
|
header('Content-Type: application/octet-stream'); |
|
header('Content-Disposition: attachment; filename=' . File::GetValidFilename($nomeFile)); |
|
header('Content-Transfer-Encoding: binary'); |
|
header('Expires: 0'); |
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
header('Pragma: public'); |
|
header('Content-Length: ' . filesize($url)); |
|
ob_clean(); |
|
flush(); |
|
readfile($url); |
|
exit; |
|
} else { |
|
echo "Il file non esiste!"; |
|
} |
|
exit; |
|
}
|
|
|