<?php
//ini_set("error_reporting",E_ALL);
require('../fpdf.php');

class PDF extends FPDF
{
var $B;
var $I;
var $U;
var $HREF;


function WriteHTML($html)
{
        //HTML parser
        $html=str_replace("\n",' ',$html);
        $a=preg_split('/<(.*)>/U',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
        foreach($a as $i=>$e)
        {
                if($i%2==0)
                {
                        //Text
                        if($this->HREF)
                                $this->PutLink($this->HREF,$e);
                        else
                                $this->Write(5,$e);
//                              $this->Cell(180,5,$e,1,2,'J');
                }
                else
                {
                        //Tag
                        if($e{0}=='/')
                                $this->CloseTag(strtoupper(substr($e,1)));
                        else
                        {
                                //Extract attributes
                                $a2=explode(' ',$e);
                                $tag=strtoupper(array_shift($a2));
                                $attr=array();
                                foreach($a2 as $v)
                                        if(ereg('^([^=]*)=["\']?([^"\']*)["\']?$',$v,$a3))
                                                $attr[strtoupper($a3[1])]=$a3[2];
                                $this->OpenTag($tag,$attr);
                        }
                }
        }
}

function OpenTag($tag,$attr)
{
        //Opening tag
        if($tag=='B' or $tag=='I' or $tag=='U')
                $this->SetStyle($tag,true);
        if($tag=='A')
                $this->HREF=$attr['HREF'];
        if($tag=='BR')
                $this->Ln(5);
}

function CloseTag($tag)
{
        //Closing tag
        if($tag=='B' or $tag=='I' or $tag=='U')
                $this->SetStyle($tag,false);
        if($tag=='A')
                $this->HREF='';
}

function SetStyle($tag,$enable)
{
        //Modify style and select corresponding font
        $this->$tag+=($enable ? 1 : -1);
        $style='';
        foreach(array('B','I','U') as $s)
                if($this->$s>0)
                        $style.=$s;
        $this->SetFont('',$style);
}

function PutLink($URL,$txt)
{
        //Put a hyperlink
        $this->SetTextColor(0,0,255);
        $this->SetStyle('U',true);
        $this->Write(5,$txt,$URL);
        $this->SetStyle('U',false);
        $this->SetTextColor(0);
}
//Page header
function Header2($texto)
{
        //Logo
        $this->Image('../logo_colegio.png',10,8,20);
        $this->Image('../logo_colegio2.png',180,8,18);
        //Arial bold 15
        $this->SetFont('Arial','B',15);
        //Move to the right
        $this->Cell(80);
        //Title
        $this->Cell(30,10,$texto,0,0,'C');
        //Line break
        $this->Ln(20);
}

//Page footer
function Footer2()
{
        //Position at 1.5 cm from bottom
        $this->SetY(-15);
        //Arial italic 8
        $this->SetFont('Arial','I',8);
        //Page number
//        $this->Cell(0,10,'Pagina '.$this->PageNo().'/{nb}',0,0,'C');
}
}

include("../fnc.php");

$pdf=new PDF('P','mm','Letter');
$pdf->SetMargins(10,10,0.00);
$agregar_pagina=true;

$pdf->SetFont('Arial','',10);

$q=mysql_query("select alumnos from alumnos where grado_estudio = '$idgrado'");
$fechacorte=fechabd($fechacorte);
$n=0;
$izq=0;
while($ialumno=mysql_fetch_array($q)){
$n++;
echo $n;
/*
if($n%2==0){
  $izq=100;
}else{
  $izq=0;
}
*/
 // columna 2
 //$ialumno=mysql_fetch_array($q);
 
 $sql="select sum(saldo) as tsaldo 
       from cp_cargos 
       where fecha_cargo <= '$fechacorte 23:59:00'
       and carnet='{$ialumno[carnet]}'
       having tsaldo";
 
 /*
 echo $sql."<br>";
 continue;
 */
 
 $qsaldo=mysql_query($sql);
 
 $msg="";
 if(mysql_num_rows($qsaldo)==0){
   $msg="SOLVENTE";
 }else{
   $isaldo=mysql_fetch_array($qsaldo);
   if($isaldo[tsaldo]>0){
     $msg="PROVISIONAL";
   }else{
     $msg="SOLVENTE";
   }
 }
 
 
 if(!$txtsolventes){
   if($msg=="SOLVENTE"){
     if($izq==100){$izq=0;}else{$izq=100;}
     continue;
   }
 }
 
 if(!$txtnosolventes){
   if($msg=="PROVISIONAL"){
   if($izq==100){$izq=0;}else{$izq=100;}
     continue;
   }
 }
 
 
 if($n>1 && $izq==100){
  $pdf->Ln(-60);
 }
 
 $pdf->cell($izq,5,"",0,0);
 $pdf->cell(95,55,"",1,1);
 $pdf->ln(-55);
 $pdf->cell($izq,5,"",0,0);
 
 /*
 $pdf->SetFont('Arial','',14);
 $pdf->SetStyle("B",true);
 $pdf->cell(95,5,$nombre_colegio,0,1,"C");
 $pdf->SetStyle("B",false);
 */
 
 $tmpx=$pdf->GetX();
 $tmpy=$pdf->GetY();
 $pdf->Image('../slogan_colegio.png',$tmpx+22,$tmpy+1,50);
 $pdf->setXY($tmpx,$tmpy+5);
 
 $pdf->cell($izq,5,"",0,0);
 
 $pdf->SetFont('Arial','',10);
 $pdf->cell(95,5,"",0,1,"C");
 $pdf->Ln();
 
 $pdf->cell($izq,5,"",0,0);
 $pdf->cell(20,5,"Carnet: ",0,0);
 $pdf->cell(75,5,$ialumno[carnet],0,1);
 
 $pdf->cell($izq,5,"",0,0);
 
 $pdf->SetStyle("B",true);
 $pdf->cell(20,5,"Nombre: ",0,0);
 $pdf->cell(75,5,$ialumno[apellido].", ".$ialumno[nombre],0,1);
 $pdf->SetStyle("B",false);
 
 $pdf->cell($izq,5,"",0,0);
 
 $pdf->cell(20,5,"Grado: ",0,0);
 $pdf->cell(75,5,ggrado(enc($ialumno[grado_estudio])),0,1);
 
 $pdf->cell($izq,5,"",0,0);
 
 $pdf->cell(20,5,"Carrera: ",0,0);
 $pdf->cell(75,5,gnivel(enc($ialumno[nivel_estudio])),0,1);
 $pdf->SetFont('Arial','',18);
 $pdf->Ln(10);
 
 $pdf->cell($izq,5,"",0,0);
 
 $pdf->SetStyle("B",true);
 $pdf->cell(75,6,"$msg",0,1);
 $pdf->SetStyle("B",false);
 
 $pdf->cell($izq,5,"",0,0);
 
 $pdf->SetFont('Arial','',6);
 $pdf->cell(75,4,fecha($fecha),0,1);
 $pdf->SetFont('Arial','',10);
 $pdf->Ln(-10);
 $pdf->cell($izq,5,"",0,0);
 $pdf->SetFont('Arial','',10);
 $pdf->cell(90,5,"Maury Iboy",0,1,"R");
 $pdf->cell($izq,5,"",0,0);
 $pdf->cell(90,5,"Control de Pagos",0,1,"R");
 $pdf->Ln(5); 
 if($izq==100){$izq=0;}else{$izq=100;}
}

$pdf->Output();
exit();
?>
