PageRenderTime 134ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/ch.pcilocarno.pbc.inventari.php/classes/class.05.ListaEvacuazione.php

https://bitbucket.org/elvisd/pci-pbc-inventari
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
  1. <?php
  2. require_once('class.Stampa.php');
  3. require_once('tcpdf_include.php');
  4. require_once('class.Tools.php');
  5. class ListaEvacuazione extends Stampa
  6. {
  7. public function createPDF($archid)
  8. {
  9. // file svg da elaborare e stampare
  10. $svgfilename = "svg/05_lista_evacuazione.svg";
  11. $svgfilename_tot = "svg/05_totale_evacuazione.svg";
  12. // connessione db
  13. mysql_connect(parent::$dbhost,parent::$dbuser,parent::$dbpass) or die("Unable to connect to MySQL");
  14. mysql_set_charset('utf8');
  15. @mysql_select_db(parent::$dbname) or die( "Unable to select database $database" );
  16. $query = "select *
  17. from OPERAARTE oa
  18. inner join PARTEARCHITETTONICA pa on pa.ID = oa.PARTEARCHITETTONICA_ID
  19. inner join ARCHITETTURA a on a.ID = pa.ARCHITETTURA_ID
  20. where oa.STATUS='A' and pa.STATUS='A' and oa.STATO='MOBILE' and a.ID='" . $archid . "'
  21. order by oa.NOPCI";
  22. mysql_query("SET NAMES 'utf8'");
  23. $result=mysql_query($query);
  24. $num=mysql_numrows($result);
  25. //
  26. $rndName = Tools::rndString(4);
  27. $outHomePath = "/tmp/";
  28. $outFilePath = $outHomePath . "PBC_" . $rndName . "/";
  29. mkdir($outFilePath);
  30. // gen pdf
  31. $pdf = new TCPDF('L', 'mm', 'A4', true, 'UTF-8', false, true);
  32. $pdf->SetPrintHeader(false);
  33. $pdf->SetPrintFooter(false);
  34. $pdf->SetMargins(0, 0, 0, true);
  35. $pdf->setPageOrientation('', false, 0);
  36. $pdf->SetFont('lato', '', 12);
  37. // calc tot pages
  38. $oapp = 15;
  39. $totpages = floor($num/$oapp)+1+($num%$oapp == 0 ?0:1);
  40. // var totali
  41. $tot_pezzi = 0;
  42. $tot_peso = 0;
  43. $tot_vol_cm = 0;
  44. // itera su OA
  45. $i=0;
  46. $page=1;
  47. $imgMaxSize=530;
  48. $lastpage=$page;
  49. $str=file_get_contents($svgfilename);
  50. $oapn=1;
  51. while ($i < $num) // $num
  52. {
  53. // carica dati da result set
  54. $oa_id = mysql_result($result,$i,"oa.ID");
  55. $a_denominazione = mysql_result($result,$i,"a.DENOMINAZIONE");
  56. $a_nopci = mysql_result($result,$i,"a.NOPCI");
  57. $a_comune = mysql_result($result,$i,"a.COMUNE");
  58. $a_cat = mysql_result($result,$i,"a.CATEGORIA");
  59. $a_indrifugio = mysql_result($result, $i, "a.INDICAZIONIRIFUGIO");
  60. $oa_denominazione = mysql_result($result,$i,"oa.DENOMINAZIONE");
  61. $oa_nopci = mysql_result($result,$i,"oa.NOPCI");
  62. $oa_genere = mysql_result($result,$i,"oa.GENERE");
  63. $oa_qta = mysql_result($result,$i,"oa.QUANTITA");
  64. $oa_peso = mysql_result($result,$i,"oa.MISPESO");
  65. $oa_alt = mysql_result($result,$i,"oa.MISALTEZZA");
  66. $oa_larg = mysql_result($result,$i,"oa.MISLARGHEZZA");
  67. $oa_prof = mysql_result($result,$i,"oa.MISPROFONDITA");
  68. $oa_vol_cm = $oa_alt * $oa_larg * $oa_prof;
  69. $oa_peso_cc = mysql_result($result,$i,"oa.MISCCPESO");
  70. $oa_alt_cc = mysql_result($result,$i,"oa.MISCCALTEZZA");
  71. $oa_larg_cc = mysql_result($result,$i,"oa.MISCCLARGHEZZA");
  72. $oa_prof_cc = mysql_result($result,$i,"oa.MISCCPROFONDITA");
  73. $oa_vol_cm_cc = $oa_alt_cc * $oa_larg_cc * $oa_prof_cc;
  74. if( $oa_genere == $oa_denominazione )
  75. $oa_denominazione = "";
  76. else
  77. $oa_denominazione = " - " . $oa_denominazione;
  78. // prendi misure con cornice o senza?
  79. if( !empty($oa_vol_cm_cc))
  80. {
  81. $oa_peso = $oa_peso_cc;
  82. $oa_alt = $oa_alt_cc;
  83. $oa_larg = $oa_larg_cc;
  84. $oa_prof = $oa_prof_cc;
  85. $oa_vol_cm = $oa_vol_cm_cc;
  86. }
  87. // aggiorna totali
  88. $tot_pezzi += $oa_qta;
  89. $tot_peso += ($oa_peso * $oa_qta);
  90. $tot_vol_cm += ($oa_vol_cm * $oa_qta);
  91. // dati OA elenco
  92. $oa_sub="_" . str_pad($oapn, 2, "0", STR_PAD_LEFT);
  93. $str=str_replace("?OA_NOPCI" . $oa_sub, Tools::cleanForSVG($oa_nopci), $str);
  94. $str=str_replace("?OA_DENOMINAZIONE" . $oa_sub, Tools::cleanForSVG($oa_genere . $oa_denominazione, 66), $str);
  95. $str=str_replace("?OA_QUANTITA" . $oa_sub, Tools::cleanForSVG($oa_qta), $str);
  96. $str=str_replace("?OA_MISALTEZZA" . $oa_sub, Tools::cleanForSVG($oa_alt), $str);
  97. $str=str_replace("?OA_MISLARGHEZZA" . $oa_sub, Tools::cleanForSVG($oa_larg), $str);
  98. $str=str_replace("?OA_MISPROFONDITA" . $oa_sub, Tools::cleanForSVG($oa_prof), $str);
  99. $str=str_replace("?OA_MISPESO" . $oa_sub, Tools::cleanForSVG($oa_peso), $str);
  100. $str=str_replace("?VOL" . $oa_sub, Tools::cleanForSVG(Tools::volCM3toM3($oa_vol_cm, 3)), $str);
  101. $page = floor(($i+1)/$oapp)+1;
  102. // new page?
  103. if( $page != $lastpage || $i == ($num-1))
  104. {
  105. // Ev. togli placeholder per posizioni non elaborate
  106. for( $j = $oapn; $j < ($oapp+1); $j++ )
  107. {
  108. $oa_sub="_" . str_pad($j, 2, "0", STR_PAD_LEFT);
  109. $str=str_replace("?OA_NOPCI" . $oa_sub, '', $str);
  110. $str=str_replace("?OA_DENOMINAZIONE" . $oa_sub, '', $str);
  111. $str=str_replace("?OA_QUANTITA" . $oa_sub, '', $str);
  112. $str=str_replace("?OA_MISALTEZZA" . $oa_sub, '', $str);
  113. $str=str_replace("?OA_MISLARGHEZZA" . $oa_sub, '', $str);
  114. $str=str_replace("?OA_MISPROFONDITA" . $oa_sub, '', $str);
  115. $str=str_replace("?OA_MISPESO" . $oa_sub, '', $str);
  116. $str=str_replace("?VOL" . $oa_sub, '', $str);
  117. }
  118. // dati testata
  119. $str=str_replace("?A_DENOMINAZIONE", Tools::cleanForSVG($a_denominazione), $str);
  120. $str=str_replace("?A_NOPCI", Tools::cleanForSVG($a_nopci), $str);
  121. $str=str_replace("?A_COMUNE", Tools::cleanForSVG($a_comune), $str);
  122. $str=str_replace("?A_CAT", Tools::cleanForSVG($a_cat), $str);
  123. $str=str_replace("?A_INDICAZIONIRIFUGIO", Tools::remNL(Tools::cleanForSVG($a_indrifugio)), $str);
  124. // dati footer
  125. $str=str_replace("?DATA", date("d.m.Y"), $str);
  126. $str=str_replace("?PAGINA", $lastpage, $str);
  127. $str=str_replace("?TOTPAGINA", $totpages, $str);
  128. // crea file temp SVG
  129. $outFileName = "PBC_ListaEvacuazione_" . str_pad($page, 4, "0", STR_PAD_LEFT);
  130. file_put_contents($outFilePath . $outFileName . ".svg", $str, LOCK_EX);
  131. // add a page
  132. $pdf->AddPage();
  133. $pdf->SetPrintHeader(false);
  134. $pdf->SetPrintFooter(false);
  135. $pdf->setMargins(0, 0, 0, true);
  136. $pdf->setPageOrientation('L', false, 0);
  137. $pdf->ImageSVG($file=$outFilePath . $outFileName . ".svg", $x=0, $y=0, $w=1052, $h=745, $link='', $align='T', $palign='L', $border=0, $fitonpage=true);
  138. // elimina SVG temp
  139. unlink($outFilePath . $outFileName . ".svg");
  140. // reload clean svg
  141. $str=file_get_contents($svgfilename);
  142. $lastpage=$page;
  143. $oapn=0;
  144. }
  145. $oapn++;
  146. $i++;
  147. }
  148. // aggiungi PDF totali
  149. $pdf->AddPage();
  150. $pdf->SetPrintHeader(false);
  151. $pdf->SetPrintFooter(false);
  152. $pdf->setMargins(0, 0, 0, true);
  153. $pdf->setPageOrientation('L', false, 0);
  154. $totstr = file_get_contents($svgfilename_tot);
  155. $totstr=str_replace("?A_DENOMINAZIONE", Tools::cleanForSVG($a_denominazione), $totstr);
  156. $totstr=str_replace("?A_NOPCI", Tools::cleanForSVG($a_nopci), $totstr);
  157. $totstr=str_replace("?A_COMUNE", Tools::cleanForSVG($a_comune), $totstr);
  158. $totstr=str_replace("?A_CAT", Tools::cleanForSVG($a_cat), $totstr);
  159. $totstr=str_replace("?A_INDICAZIONIRIFUGIO", Tools::remNL(Tools::cleanForSVG($a_indrifugio)), $totstr);
  160. $totstr = str_replace("?TOTALEPEZZI", $tot_pezzi, $totstr);
  161. $totstr = str_replace("?TOTALEPESO", $tot_peso, $totstr);
  162. $totstr = str_replace("?TOTALEVOLUME", Tools::cleanForSVG(Tools::volCM3toM3($tot_vol_cm)), $totstr);
  163. $totstr = str_replace("?DATA", date("d.m.Y"), $totstr);
  164. $totstr = str_replace("?PAGINA", $totpages, $totstr);
  165. $totstr = str_replace("?TOTPAGINA", $totpages, $totstr);
  166. file_put_contents($outFilePath . "PBC_ListaEvacuazione_TOT.svg", $totstr, LOCK_EX);
  167. $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);
  168. unlink($outFilePath . "PBC_ListaEvacuazione_TOT.svg");
  169. // chiudi PDF e scrivi
  170. $pdf->Output($outHomePath . "05_ListaEvacuazione" . "" . ".pdf", 'FD');
  171. // elimina cartella temp
  172. rmdir($outFilePath);
  173. // chiudi conn mysql
  174. mysql_close();
  175. }
  176. }