00001 <?php
00002
00035 include_once LIBRARY_PATH.'fpdf/fpdf.php';
00036
00037 class PDF extends FPDF
00038 {
00039
00040 function Header()
00041 {
00042 $this->Ln(10);
00043 }
00044
00045
00046 function Footer()
00047 {
00048
00049 $config = Config::read("config.ini");
00050 $active_app = Router::get_application();
00051
00052 $this->SetY(-21);
00053
00054 $this->SetFont('Arial', '', 7);
00055
00056
00057 $this->SetY(-18);
00058
00059 $this->SetFont('Arial','',7);
00060
00061 $this->Cell(0,10, $config->$active_app->name,0,0,'C');
00062
00063
00064 $this->SetY(-10);
00065
00066 $this->SetFont('Arial','',8);
00067
00068 $this->Cell(0,10,'-- '.$this->PageNo().' --',0,0,'C');
00069
00070 }
00071
00072 }
00073
00083 function pdf($result, $sumArray, $title, $weightArray, $headerArray){
00084
00085 $config = Config::read("config.ini");
00086 $active_app = Router::get_application();
00087
00088
00089 if($sumArray>200) {
00090 $orientation = 'L';
00091 } else {
00092 $orientation = 'P';
00093 }
00094
00095 $numRows = 140;
00096
00097 if($sumArray>250) {
00098 $paper = 'legal';
00099 } else {
00100 $paper = 'letter';
00101 }
00102
00103 if($paper=='letter'&&$orientation=='P'){
00104 $widthPage = 220;
00105 $numRows = 42;
00106 }
00107
00108 if($paper=='legal'&&$orientation=='L'){
00109 $widthPage = 355;
00110 $numRows = 30;
00111 }
00112
00113 if($paper=='letter'&&$orientation=='L'){
00114 $widthPage = 270;
00115 $numRows = 30;
00116 }
00117
00118
00119 $pdf = new PDF($orientation, 'mm', $paper);
00120
00121 $pdf->Open();
00122 $pdf->AddPage();
00123
00124
00125 $pdf->SetFillColor(255, 255, 255);
00126 $pdf->AddFont('Verdana','','verdana.php');
00127 $pdf->SetFont('Verdana','', 14);
00128 $pdf->SetY(20);
00129 $pdf->SetX(0);
00130
00131
00132 $pdf->Ln();
00133
00134 if($config->$active_app->name){
00135 $pdf->MultiCell(0, 6, strtoupper($config->$active_app->name), 0, "C", 0);
00136 }
00137 $pdf->MultiCell(0, 6, "REPORTE DE ".strtoupper($title), 0, "C", 0);
00138 $pdf->SetFont('Verdana','', 12);
00139 if(isset($_SESSION['fecsis'])){
00140 $pdf->MultiCell(0, 6, "FECHA ".date("Y-m-d"), 0, "C", 0);
00141 }
00142 $pdf->Ln();
00143
00144
00145 $pdf->SetFillColor(0xF2,0xF2, 0xF2);
00146 $pdf->SetTextColor(0);
00147 $pdf->SetDrawColor(0,0,0);
00148 $pdf->SetLineWidth(.2);
00149 $pdf->SetFont('Arial', 'B', 10);
00150
00151 if($weightArray[0]<11){
00152 $weightArray[0] = 11;
00153 }
00154
00155
00156 $pos = floor(($widthPage/2)-($sumArray/2));
00157 $pdf->SetX($pos);
00158 for($i=0;$i<=count($headerArray)-1;$i++){
00159 $pdf->Cell($weightArray[$i],7,$headerArray[$i], 1, 0, 'C', 1);
00160 }
00161 $pdf->Ln();
00162
00163
00164 $pdf->SetFillColor(224, 235, 255);
00165 $pdf->SetTextColor(0);
00166 $pdf->SetFont('Arial','B', 7);
00167
00168
00169
00170
00171 $n = 1;
00172 $p = 1;
00173 $t = 0;
00174 foreach($result as $row){
00175
00176 if($n>$numRows||($p==1&&($n>$numRows-3))){
00177 $pdf->AddPage($orientation);
00178 $pdf->SetY(30);
00179 $pdf->SetX($pos);
00180 $pdf->SetFillColor(0xF2,0xF2, 0xF2);
00181 $pdf->SetTextColor(0);
00182 $pdf->SetDrawColor(0,0,0);
00183 $pdf->SetLineWidth(.2);
00184 $pdf->SetFont('Arial', 'B', 10);
00185 for($i=0;$i<count($headerArray);$i++){
00186 $pdf->Cell($weightArray[$i], 7, $headerArray[$i], 1, 0, 'C', 1);
00187 }
00188 $pdf->Ln();
00189 $pdf->SetFillColor(224, 235, 255);
00190 $pdf->SetTextColor(0);
00191 $pdf->SetFont('Arial', 'B', 7);
00192 $n = 1;
00193 $p++;
00194 }
00195 $pdf->SetX($pos);
00196 for($i=0;$i<=count($row)-1;$i++){
00197 if(is_numeric($row[$i])){
00198 $pdf->Cell($weightArray[$i], 5, trim($row[$i]),'LRTB', 0, 'C');
00199 } else {
00200 $pdf->Cell($weightArray[$i], 5, trim($row[$i]),'LRTB', 0, 'L');
00201 }
00202 }
00203 $n++;
00204 $t++;
00205 $pdf->Ln();
00206
00207 }
00208
00209 $pdf->SetX($pos);
00210 $pdf->SetFont('Arial', 'B', 7);
00211 $pdf->SetFillColor(0xF2,0xF2, 0xF2);
00212 $pdf->Cell($weightArray[0], 5, "TOTAL",'LRTB', 0, 'R');
00213 $pdf->Cell($weightArray[1], 5, $t,'LRTB', 0, 'L');
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 $file = md5(uniqid());
00224 $pdf->Output(CORE_PATH.'public/temp/'.$file .".pdf", 'F');
00225 if(isset($raw_output)){
00226 print "<script type='text/javascript'> window.open('".KUMBIA_PATH."temp/".$file.".pdf', null); </script>";
00227 } else {
00228 Generator::forms_print("<script type='text/javascript'> window.open('".KUMBIA_PATH."temp/".$file.".pdf', null); </script>");
00229 }
00230
00231 }
00232 ?>