staffPDF.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /*
  3. An Example PDF Report Using FPDF
  4. by Matt Doyle
  5. From "Create Nice-Looking PDFs with PHP and FPDF"
  6. http://www.elated.com/articles/create-nice-looking-pdfs-php-fpdf/
  7. */
  8. session_start();
  9. define('FPDF_FONTPATH',"fpdf/font/");
  10. require_once( "fpdf/fpdf.php" );
  11. class myPDF extends FPDF {
  12. function myCell($w,$h,$x,$t){
  13. $height=$h/3;
  14. $first=$height+2;
  15. $second=$height+$height+$height+3;
  16. $third=$height+$height+$height+$height+20;
  17. $len=strlen($t);
  18. if($len>15){
  19. //$txt=str_split($t,55);
  20. $txt = explode('?', $t);
  21. $this->SetX($x);
  22. $this->Cell($w,$first,$txt[0],'','','');
  23. $this->SetX($x);
  24. $this->Cell($w,$second,$txt[1],'','','');
  25. $this->SetX($x);
  26. $this->Cell($w,$third,$txt[2],'','','');
  27. $this->SetX($x);
  28. $this->Cell($w,$h,'','LTRB',0,'L',0);
  29. }
  30. else{
  31. $this->SetX($x);
  32. $this->Cell($w,$h,$t,'LTRB',0,'L',0);
  33. }
  34. }
  35. }
  36. $textColour = array( 0, 0, 0 );
  37. $tableHeaderTopTextColour = array( 255, 255, 255 );
  38. $tableHeaderTopFillColour = array( 125, 152, 179 );
  39. $tableHeaderTopProductTextColour = array( 0, 0, 0 );
  40. $tableHeaderTopProductFillColour = array( 143, 173, 204 );
  41. $tableHeaderLeftTextColour = array( 99, 42, 57 );
  42. $tableHeaderLeftFillColour = array( 184, 207, 229 );
  43. $tableBorderColour = array( 50, 50, 50 );
  44. $tableRowFillColour = array( 213, 170, 170 );
  45. $logoXPos = 20;
  46. $logoYPos = 40;
  47. $logoWidth = 40;
  48. $columnLabels = array( "QRкод" , "Инфо" );//, "Имя", "Логин", "Пароль"
  49. $arrNames = array( '0' =>"qr" , '1' =>"name", '2' =>"login", '3' =>"password" );
  50. $countListItem = 5;
  51. $mainArray = [];
  52. $tempArray = [];
  53. $halfArray = [];
  54. $i = 1;
  55. $textQR = "QRкод";
  56. $pdf = new myPDF( 'P', 'mm', 'A4' );
  57. $myArray = $_SESSION['staffQRList'];
  58. foreach( $myArray as $item) {
  59. $tempArray[] = $item;
  60. if ($i == $countListItem){
  61. $mainArray[] = $tempArray;
  62. $tempArray = [];
  63. $countListItem += 5;
  64. $halfArray = [];
  65. } else {
  66. $halfArray[] = $item;
  67. }
  68. $i++;
  69. }
  70. if ( !empty($halfArray)) {
  71. $mainArray[] = $halfArray;
  72. }
  73. $myArray = $mainArray;
  74. $countListItem = 5;
  75. $countPage = ceil(count($_SESSION['staffQRList'])/$countListItem);
  76. $ii = 0;
  77. $textQR = iconv('UTF-8', 'windows-1251', $textQR);
  78. $w=65;
  79. $h=41;
  80. while ( $ii < $countPage ) {
  81. $logoYPos = 40;
  82. $pdf->AddPage();
  83. $pdf->AddFont('Arial','','arial.php');
  84. $pdf->SetFont('Arial');
  85. // Логотип
  86. $pdf->SetDrawColor( $tableBorderColour[0], $tableBorderColour[1], $tableBorderColour[2] );
  87. $pdf->Ln( 15 );
  88. $pdf->SetTextColor( $tableHeaderTopProductTextColour[0], $tableHeaderTopProductTextColour[1], $tableHeaderTopProductTextColour[2] );
  89. $pdf->SetFillColor( $tableHeaderTopProductFillColour[0], $tableHeaderTopProductFillColour[1], $tableHeaderTopProductFillColour[2] );
  90. // Остальные ячейки заголовков
  91. $pdf->SetTextColor( $tableHeaderTopTextColour[0], $tableHeaderTopTextColour[1], $tableHeaderTopTextColour[2] );
  92. $pdf->SetFillColor( $tableHeaderTopFillColour[0], $tableHeaderTopFillColour[1], $tableHeaderTopFillColour[2] );
  93. $pdf->Cell( 60, 12, iconv('UTF-8', 'windows-1251', $columnLabels[0]), 1, 0, 'C', true );
  94. $pdf->Cell( 120, 12, iconv('UTF-8', 'windows-1251', $columnLabels[1]), 1, 0, 'C', true );
  95. $pdf->Ln( 12 );
  96. $fill = false;
  97. $row = 0;
  98. for( $r = 0 ; $r < $countListItem; $r++) {
  99. if(null == $myArray[$ii][$r]['password']){
  100. continue;
  101. }
  102. $pdf->SetTextColor( $tableHeaderLeftTextColour[0], $tableHeaderLeftTextColour[1], $tableHeaderLeftTextColour[2] );
  103. $pdf->SetFillColor( $tableHeaderLeftFillColour[0], $tableHeaderLeftFillColour[1], $tableHeaderLeftFillColour[2] );
  104. $pdf->SetTextColor( $textColour[0], $textColour[1], $textColour[2] );
  105. $pdf->SetFillColor( $tableRowFillColour[0], $tableRowFillColour[1], $tableRowFillColour[2] );
  106. $pdf->SetFont( 'Arial', '', 15 );
  107. $textInfo = "Имя: ".$myArray[$ii][$r]['name']."?Логин: ".$myArray[$ii][$r]['login']."?Пароль: " .$myArray[$ii][$r]['password'] ;
  108. $textInfo = iconv('UTF-8', 'windows-1251', $textInfo);
  109. $x = $pdf->getx();
  110. $rty = $pdf->Image( $myArray[$ii][$r]['qr'], $logoXPos, $logoYPos, $logoWidth );
  111. $pdf->myCell(60,$h,$x,$rty);
  112. $x=$pdf->getx();
  113. $pdf->myCell(120,$h,$x,$textInfo);
  114. $pdf->Ln();
  115. $row++;
  116. $fill = !$fill;
  117. $pdf->Ln( 0 );
  118. $logoYPos += 40;
  119. }
  120. $ii++;
  121. }
  122. $pdf->Output( "report.pdf", "I" );
  123. ?>