<?php
// FORMATO DE IMPRESION PARA RECIBO CONTINUO POR OTROS INGRESOS

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);
        $this->Ln();
}

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

include("../fnc.php");
//enlinea_c();
/*$uuser="misanchez";
$unombre="efren";
$uapellido="monterroso - PRUEBA";
*/
if(!$ide){
  alert("Parámetros incorrectos","$goback");
  exit();
}

$id_e=dec($ide);

$qev=runsql("select * from evaluaciones where id = '$id_e'");
$info=registro($qev);
$qgr=runsql("select g.*
             from grados g inner join unidades_grados ug ON ug.grado = g.id
             where
             ug.id = '{$info[unidad]}'");
$igr=registro($qgr);             

$pdf=new PDF('P','mm','Letter');
$pdf->SetMargins(20,10,20);
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->Image('../logo_colegio.png',20,10,20);
//$pdf->Encabezado("","CORTE DE CAJA");
$pdf->SetFillColor(255,255,255);
$pdf->SetFont('Arial','',16);
$pdf->cell(50,0,"");
$pdf->setstyle("B",true);
$pdf->multicell(0,5,get_nombre_institucion(),0,"R");
$pdf->setstyle("B",false);
//$pdf->ln(5);
$pdf->SetFont('Arial','',14);
$pdf->cell(50,0,"");
$pdf->multicell(0,5,"Grado: ".$igr[grado].", Sección: ".$info[seccion],0,"R");
$pdf->cell(50,0,"");
$pdf->multicell(0,5,"Curso: ".gcurso(enc($info[curso])),0,"R");
$pdf->cell(50,0,"");
$pdf->multicell(0,5,$unombre." ".$uapellido,0,"R");
$pdf->SetFont('Arial','',12);

$pdf->Ln(15);
$pdf->cell(0,5,"No. Carné: ____________ Nombre Completo: _____________________________________",0,1);
$pdf->Ln(4);
$pdf->setstyle("B",true);
$pdf->multicell(0,4,"INSTRUCCIONES: ".$info[instrucciones],0,"J");
$pdf->setstyle("B",false);
$pdf->Ln(4);

$preguntas=Array();
$respuestas=Array();
$puntos=Array();

$cnt=0;
$qpr=runsql("select * from ev_m_preguntas where evaluacion ='$id_e'");
while($ipr=registro($qpr)){
  if($pdf->GetY()>240){
    $pdf->AddPage();
  }
  $cnt++;
  $pdf->cell(10,5,$cnt.".");
  $pdf->multicell(0,5,$ipr[pregunta]);
  $qre=runsql("select * from ev_m_opciones where pregunta = '{$ipr[id]}'");
  while($ire=registro($qre)){
    $pdf->image("../images/exa_circulo.png",35,$pdf->GetY(),4);
    $pdf->cell(20,5,"");
    $pdf->multicell(0,5,$ire[opcion],0,"L");
  }
  $pdf->Ln(3);
}


//$cnt=0;
$qpr=runsql("select * from ev_d_preguntas where evaluacion ='$id_e'");
while($ipr=registro($qpr)){
  if($pdf->GetY()>240){
    $pdf->AddPage();
  }
  $cnt++;
  $pdf->cell(10,5,$cnt.".");
  $pdf->multicell(0,5,$ipr[pregunta]);
  //$qre=runsql("select * from ev_d_opciones where pregunta = '{$ipr[id]}'");
  //while($ire=registro($qre)){
    $pdf->cell(10,6,"");
    $pdf->multicell(0,10,"_______________________________________________________",0,"L");
  //}
  $pdf->Ln(5);
}

//$pdf->Output("examen.pdf","I");
$pdf->Output();
exit();
?>
