<?php
//FORMATO DE IMPRESION RECIBO DE CAJA
include("../fnc.php");
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)
{
        if(!$text){$texto="COLEGIO COACTEMALAN";}
        //Logo
        $this->Image('../logo_colegio.png',10,12,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(0,7,$texto,0,1,'C');
        $this->SetFont('Arial','B',12);
        $this->Cell(0,5,"REPORTE DE ALUMNOS POR RUTA DE BUS",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');
}
}

function gplan_pago($id){
$q=mysql_query("select * from cp_planesdepagos where id = '$id'");
$i=mysql_fetch_array($q);
return $i[plan];
}

$pdf=new PDF('L','mm','Legal');
$pdf->SetMargins(10,10.00,0.00);
$pdf->AliasNbPages();
$qg=mysql_query("select * from cp_tipos_cargos where id like 'TRES%'");

$columna=Array();
$columna[0]=22;
$columna[1]=90;
$columna[2]=30;
$columna[3]=30;
$columna[4]=40;
$columna[5]=30;
$columna[6]=30;

while($ig=mysql_fetch_array($qg)){
  $pdf->AddPage();
  $pdf->Encabezado($nombre_colegio,"ALUMNOS POR RUTA DE BUS");
  $pdf->SetFont('Arial','',12);
  $pdf->SetStyle("B",true);
  $pdf->cell(0,6,"RUTA: {$ig[descripcion]}",0,1,"L");
  $pdf->SetStyle("B",false);
  $pdf->SetFont('Arial','',12);

  $qalmn=mysql_query("select distinct alumnos.*
                      from alumnos inner join cp_cargos ON cp_cargos.carnet = alumnos.carnet
                      where tipo='{$ig[id]}'
                      and (cp_cargos.year = '".get_ciclo_inscripcion()."' or cp_cargos.year = '".get_ciclo_activo()."')
                      and alumnos.year_estudio = '$df_year_actual' 
                      order by apellido");

  $pdf->SetStyle("B",true);
  $pdf->cell($columna[0],5,"CARNET",1,0,"C");
  $pdf->cell($columna[1],5,"NOMBRE DEL ALUMNO",1,0,"C");
  $pdf->cell($columna[2],5,"TEL. CASA",1,0,"C");
  $pdf->cell($columna[3],5,"CELULAR",1,0,"C");
  $pdf->cell($columna[4],5,"TEL. ENCARGADO",1,0,"C");
  $pdf->cell($columna[5],5,"TEL. PADRE",1,0,"C");
  $pdf->cell($columna[6],5,"TEL. MADRE",1,0,"C");
//  $pdf->cell($columna[7],5,"PLAN DE PAGO",1,0,"C");
  $pdf->SetStyle("B",false);
  $pdf->ln();
  $total_almn=0;
  while($ial=mysql_fetch_array($qalmn)){
  $total_almn++;
   $pdf->cell($columna[0],5,$ial[carnet],1,0);
   $pdf->cell($columna[1],5,$ial[apellido].", ".$ial[nombre],1,0);
   $pdf->cell($columna[2],5,$ial[tel_casa],1,0);
   $pdf->cell($columna[3],5,$ial[tel_movil],1,0);
   $pdf->cell($columna[4],5,$ial[enc_telefono],1,0);
   $pdf->cell($columna[5],5,$ial[padre_telefono],1,0);
   $pdf->cell($columna[6],5,$ial[madre_telefono],1,1);
   $pdf->cell(suma_columnas($columna),6,"DIRECCION: ".get_direccionalumno($ial[carnet],"alumnos"),1,1);
  }
  $pdf->SetStyle("B",true);
  $pdf->cell(0,6,"TOTAL: $total_almn alumno(s)",0,1,"L");
  $pdf->SetStyle("B",false);
}
$pdf->Output();
exit();
?>
