/ch.pcilocarno.pbc.inventari.php/classes/class.05.ListaEvacuazione.php
PHP | 202 lines | 153 code | 26 blank | 23 comment | 10 complexity | 245cabfca9cce202373ace9ccb1c4682 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-2.0, GPL-3.0
- <?php
-
- require_once('class.Stampa.php');
- require_once('tcpdf_include.php');
- require_once('class.Tools.php');
-
- class ListaEvacuazione extends Stampa
- {
- public function createPDF($archid)
- {
- // file svg da elaborare e stampare
- $svgfilename = "svg/05_lista_evacuazione.svg";
- $svgfilename_tot = "svg/05_totale_evacuazione.svg";
- // connessione db
- mysql_connect(parent::$dbhost,parent::$dbuser,parent::$dbpass) or die("Unable to connect to MySQL");
- mysql_set_charset('utf8');
- @mysql_select_db(parent::$dbname) or die( "Unable to select database $database" );
- $query = "select *
- from OPERAARTE oa
- inner join PARTEARCHITETTONICA pa on pa.ID = oa.PARTEARCHITETTONICA_ID
- inner join ARCHITETTURA a on a.ID = pa.ARCHITETTURA_ID
- where oa.STATUS='A' and pa.STATUS='A' and oa.STATO='MOBILE' and a.ID='" . $archid . "'
- order by oa.NOPCI";
-
- mysql_query("SET NAMES 'utf8'");
- $result=mysql_query($query);
- $num=mysql_numrows($result);
-
-
- //
- $rndName = Tools::rndString(4);
- $outHomePath = "/tmp/";
- $outFilePath = $outHomePath . "PBC_" . $rndName . "/";
- mkdir($outFilePath);
-
- // gen pdf
- $pdf = new TCPDF('L', 'mm', 'A4', true, 'UTF-8', false, true);
- $pdf->SetPrintHeader(false);
- $pdf->SetPrintFooter(false);
- $pdf->SetMargins(0, 0, 0, true);
- $pdf->setPageOrientation('', false, 0);
- $pdf->SetFont('lato', '', 12);
-
- // calc tot pages
- $oapp = 15;
- $totpages = floor($num/$oapp)+1+($num%$oapp == 0 ?0:1);
-
- // var totali
- $tot_pezzi = 0;
- $tot_peso = 0;
- $tot_vol_cm = 0;
-
- // itera su OA
- $i=0;
- $page=1;
- $imgMaxSize=530;
- $lastpage=$page;
- $str=file_get_contents($svgfilename);
- $oapn=1;
-
- while ($i < $num) // $num
- {
- // carica dati da result set
- $oa_id = mysql_result($result,$i,"oa.ID");
- $a_denominazione = mysql_result($result,$i,"a.DENOMINAZIONE");
- $a_nopci = mysql_result($result,$i,"a.NOPCI");
- $a_comune = mysql_result($result,$i,"a.COMUNE");
- $a_cat = mysql_result($result,$i,"a.CATEGORIA");
- $a_indrifugio = mysql_result($result, $i, "a.INDICAZIONIRIFUGIO");
- $oa_denominazione = mysql_result($result,$i,"oa.DENOMINAZIONE");
- $oa_nopci = mysql_result($result,$i,"oa.NOPCI");
- $oa_genere = mysql_result($result,$i,"oa.GENERE");
- $oa_qta = mysql_result($result,$i,"oa.QUANTITA");
- $oa_peso = mysql_result($result,$i,"oa.MISPESO");
-
- $oa_alt = mysql_result($result,$i,"oa.MISALTEZZA");
- $oa_larg = mysql_result($result,$i,"oa.MISLARGHEZZA");
- $oa_prof = mysql_result($result,$i,"oa.MISPROFONDITA");
- $oa_vol_cm = $oa_alt * $oa_larg * $oa_prof;
-
- $oa_peso_cc = mysql_result($result,$i,"oa.MISCCPESO");
- $oa_alt_cc = mysql_result($result,$i,"oa.MISCCALTEZZA");
- $oa_larg_cc = mysql_result($result,$i,"oa.MISCCLARGHEZZA");
- $oa_prof_cc = mysql_result($result,$i,"oa.MISCCPROFONDITA");
- $oa_vol_cm_cc = $oa_alt_cc * $oa_larg_cc * $oa_prof_cc;
-
- if( $oa_genere == $oa_denominazione )
- $oa_denominazione = "";
- else
- $oa_denominazione = " - " . $oa_denominazione;
-
- // prendi misure con cornice o senza?
- if( !empty($oa_vol_cm_cc))
- {
- $oa_peso = $oa_peso_cc;
- $oa_alt = $oa_alt_cc;
- $oa_larg = $oa_larg_cc;
- $oa_prof = $oa_prof_cc;
- $oa_vol_cm = $oa_vol_cm_cc;
- }
-
- // aggiorna totali
- $tot_pezzi += $oa_qta;
- $tot_peso += ($oa_peso * $oa_qta);
- $tot_vol_cm += ($oa_vol_cm * $oa_qta);
-
- // dati OA elenco
- $oa_sub="_" . str_pad($oapn, 2, "0", STR_PAD_LEFT);
- $str=str_replace("?OA_NOPCI" . $oa_sub, Tools::cleanForSVG($oa_nopci), $str);
- $str=str_replace("?OA_DENOMINAZIONE" . $oa_sub, Tools::cleanForSVG($oa_genere . $oa_denominazione, 66), $str);
-
- $str=str_replace("?OA_QUANTITA" . $oa_sub, Tools::cleanForSVG($oa_qta), $str);
- $str=str_replace("?OA_MISALTEZZA" . $oa_sub, Tools::cleanForSVG($oa_alt), $str);
- $str=str_replace("?OA_MISLARGHEZZA" . $oa_sub, Tools::cleanForSVG($oa_larg), $str);
- $str=str_replace("?OA_MISPROFONDITA" . $oa_sub, Tools::cleanForSVG($oa_prof), $str);
- $str=str_replace("?OA_MISPESO" . $oa_sub, Tools::cleanForSVG($oa_peso), $str);
- $str=str_replace("?VOL" . $oa_sub, Tools::cleanForSVG(Tools::volCM3toM3($oa_vol_cm, 3)), $str);
-
- $page = floor(($i+1)/$oapp)+1;
- // new page?
- if( $page != $lastpage || $i == ($num-1))
- {
- // Ev. togli placeholder per posizioni non elaborate
- for( $j = $oapn; $j < ($oapp+1); $j++ )
- {
- $oa_sub="_" . str_pad($j, 2, "0", STR_PAD_LEFT);
- $str=str_replace("?OA_NOPCI" . $oa_sub, '', $str);
- $str=str_replace("?OA_DENOMINAZIONE" . $oa_sub, '', $str);
- $str=str_replace("?OA_QUANTITA" . $oa_sub, '', $str);
- $str=str_replace("?OA_MISALTEZZA" . $oa_sub, '', $str);
- $str=str_replace("?OA_MISLARGHEZZA" . $oa_sub, '', $str);
- $str=str_replace("?OA_MISPROFONDITA" . $oa_sub, '', $str);
- $str=str_replace("?OA_MISPESO" . $oa_sub, '', $str);
- $str=str_replace("?VOL" . $oa_sub, '', $str);
- }
- // dati testata
- $str=str_replace("?A_DENOMINAZIONE", Tools::cleanForSVG($a_denominazione), $str);
- $str=str_replace("?A_NOPCI", Tools::cleanForSVG($a_nopci), $str);
- $str=str_replace("?A_COMUNE", Tools::cleanForSVG($a_comune), $str);
- $str=str_replace("?A_CAT", Tools::cleanForSVG($a_cat), $str);
- $str=str_replace("?A_INDICAZIONIRIFUGIO", Tools::remNL(Tools::cleanForSVG($a_indrifugio)), $str);
- // dati footer
- $str=str_replace("?DATA", date("d.m.Y"), $str);
- $str=str_replace("?PAGINA", $lastpage, $str);
- $str=str_replace("?TOTPAGINA", $totpages, $str);
-
- // crea file temp SVG
- $outFileName = "PBC_ListaEvacuazione_" . str_pad($page, 4, "0", STR_PAD_LEFT);
- file_put_contents($outFilePath . $outFileName . ".svg", $str, LOCK_EX);
-
- // add a page
- $pdf->AddPage();
- $pdf->SetPrintHeader(false);
- $pdf->SetPrintFooter(false);
- $pdf->setMargins(0, 0, 0, true);
- $pdf->setPageOrientation('L', false, 0);
- $pdf->ImageSVG($file=$outFilePath . $outFileName . ".svg", $x=0, $y=0, $w=1052, $h=745, $link='', $align='T', $palign='L', $border=0, $fitonpage=true);
-
- // elimina SVG temp
- unlink($outFilePath . $outFileName . ".svg");
-
- // reload clean svg
- $str=file_get_contents($svgfilename);
- $lastpage=$page;
- $oapn=0;
- }
-
-
- $oapn++;
- $i++;
- }
-
- // aggiungi PDF totali
- $pdf->AddPage();
- $pdf->SetPrintHeader(false);
- $pdf->SetPrintFooter(false);
- $pdf->setMargins(0, 0, 0, true);
- $pdf->setPageOrientation('L', false, 0);
- $totstr = file_get_contents($svgfilename_tot);
- $totstr=str_replace("?A_DENOMINAZIONE", Tools::cleanForSVG($a_denominazione), $totstr);
- $totstr=str_replace("?A_NOPCI", Tools::cleanForSVG($a_nopci), $totstr);
- $totstr=str_replace("?A_COMUNE", Tools::cleanForSVG($a_comune), $totstr);
- $totstr=str_replace("?A_CAT", Tools::cleanForSVG($a_cat), $totstr);
- $totstr=str_replace("?A_INDICAZIONIRIFUGIO", Tools::remNL(Tools::cleanForSVG($a_indrifugio)), $totstr);
- $totstr = str_replace("?TOTALEPEZZI", $tot_pezzi, $totstr);
- $totstr = str_replace("?TOTALEPESO", $tot_peso, $totstr);
- $totstr = str_replace("?TOTALEVOLUME", Tools::cleanForSVG(Tools::volCM3toM3($tot_vol_cm)), $totstr);
- $totstr = str_replace("?DATA", date("d.m.Y"), $totstr);
- $totstr = str_replace("?PAGINA", $totpages, $totstr);
- $totstr = str_replace("?TOTPAGINA", $totpages, $totstr);
- file_put_contents($outFilePath . "PBC_ListaEvacuazione_TOT.svg", $totstr, LOCK_EX);
- $pdf->ImageSVG($file=$outFilePath . "PBC_ListaEvacuazione_TOT.svg", $x=0, $y=0, $w=1052, $h=745, $link='', $align='T', $palign='L', $border=0, $fitonpage=true);
- unlink($outFilePath . "PBC_ListaEvacuazione_TOT.svg");
- // chiudi PDF e scrivi
- $pdf->Output($outHomePath . "05_ListaEvacuazione" . "" . ".pdf", 'FD');
- // elimina cartella temp
- rmdir($outFilePath);
- // chiudi conn mysql
- mysql_close();
- }
-
- }