<?php
//FORMATO DE IMPRESION RECIBO DE CAJA
include("../fnc.php");
require('../fpdf.php');
include("../n2l_notas.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(0,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,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(0,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');
}
}

$pdf=new PDF('P','mm','Legal');
$pdf->SetMargins(10,10,10);
$pdf->AliasNbPages();

$id_grado=$txtgrado;
$qalumnosg=mysql_query("select carnet from alumnos where grado_estudio = '$id_grado' and year_estudio = ".get_ciclo_activo());
while($ialumnosg=mysql_fetch_array($qalumnosg)){
$idalumno=$ialumnosg[carnet];

$qinfo=mysql_query("select * from alumnos where carnet = '$idalumno'");
$info=mysql_fetch_array($qinfo);


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

$tmp_nivel=explode(" ",gnivel(enc($info[nivel_estudio])));
$carrera=strtolower($tmp_nivel[0]);
$carrera2=$carrera;
switch($carrera){
  case "bachillerato": $numero_acuerdo="876";
                       $fecha_acuerdo="15/10/1981";
                       $num_grados_carrera=2;
                       $carrera="BACHILLER EN TURISMO";
  break;
  case "perito":       $numero_acuerdo="326-92-EP";
                       $fecha_acuerdo="12/11/1992";
                       $num_grados_carrera=3;
                       $carrera="PERITO EN ADMINISTRACION TURISTICA Y HOTELERA";
  break;
  case "secretariado": $numero_acuerdo="876";
                       $fecha_acuerdo="15/10/1981";
                       $num_grados_carrera=2;
                       $carrear="SECRETARIA BILINGUE CON ESPECIALIZACION EN TURISMO Y HOTELERIA";
  break;
}

$num_grados_basico = 3;
$inicio=$pdf->GetY();

$texto="El(la)  infrascrito(a)  secretario(a)  del  \"$nombre_colegio\",  con   acuerdo   Ministerial  número  $numero_acuerdo";
$texto.=" de fecha $fecha_acuerdo CERTIFICA: Que el(la) alumno(a)";
$texto.=" {$info[nombre]} {$info[apellido]}";
$texto.=" cursó las asignaturas correspondientes a los $num_grados_basico";
$texto.=" grados de Educación Básica o de Cultura General y $num_grados_carrera de la carrera de $carrera";
$texto.=" habiendo obtenido las calificaciones siguientes:";

$pdf->multicell(195,7,$texto,1,'J');

$fin=$pdf->GetY();

$lineas=(($fin-$inicio)/7);
$pdf->Ln($lineas*-7);
for($i=1;$i<=$lineas;$i++){
 $pdf->cell(195,7,"",1,1);
}

$qmt=mysql_query("select * 
                  from exp_matriculas 
                  where 
                  carnet = '$idalumno'
                  and nivel = 'BASICOS'
                  and grado = 1");
$imt=mysql_fetch_array($qmt);

$pdf->setstyle("B",true);
$pdf->cell(195,7,"PRIMER GRADO DE EDUCACION BASICA O DE CULTURA GENERAL",1,1,"C");
$pdf->setstyle("B",false);
$pdf->cell(30,7,"Cursado en:",1,0);
$pdf->cell(165,7,$imt[cursado_en],1,1);
$pdf->cell(30,7,"Matrícula No.:",1,0);
$pdf->cell(30,7,$imt[matricula],1,0);
$pdf->cell(30,7,"De fecha:",1,0);
$pdf->cell(105,7,fecha($imt[matricula_fecha]),1,1);
$pdf->cell(30,7,"Extendida en:",1,0);
$pdf->cell(165,7,$imt[matricula_extendidaen],1,1);

$qcursos=mysql_query("select * 
                      from exp_cursos 
                      where 
                      alumno='$idalumno'
                      and nivel='BASICOS'
                      and grado = 1");
$n=0;                      
while($icurso=mysql_fetch_array($qcursos)){
  $n++;
  $pdf->cell(10,7,"$n",1,0,"C");
  $pdf->cell(89,7,$icurso[curso],1,0,"L");
  $pdf->cell(10,7,$icurso[nota],1,0,"C");
  $pdf->cell(45,7,inicial_mayuscula(enletras($icurso[nota])),1,0,"L");
  if($icurso[nota]>=60){
  $pdf->cell(20,7,"Aprobado",1,0,"C");
  }else{
  $pdf->cell(20,7,"Reprobado",1,0,"C");
  }
  
  $pdf->cell(21,7,fecha($icurso[fecha]),1,1,"C");
  
}



$qmt=mysql_query("select * 
                  from exp_matriculas 
                  where 
                  carnet = '$idalumno'
                  and nivel = 'BASICOS'
                  and grado = 2");
$imt=mysql_fetch_array($qmt);

$pdf->setstyle("B",true);
$pdf->cell(195,7,"SEGUNDO GRADO DE EDUCACION BASICA O DE CULTURA GENERAL",1,1,"C");
$pdf->setstyle("B",false);
$pdf->cell(30,7,"Cursado en:",1,0);
$pdf->cell(165,7,$imt[cursado_en],1,1);
$pdf->cell(30,7,"Matrícula No.:",1,0);
$pdf->cell(30,7,$imt[matricula],1,0);
$pdf->cell(30,7,"De fecha:",1,0);
$pdf->cell(105,7,fecha($imt[matricula_fecha]),1,1);
$pdf->cell(30,7,"Extendida en:",1,0);
$pdf->cell(165,7,$imt[matricula_extendidaen],1,1);

$qcursos=mysql_query("select * 
                      from exp_cursos 
                      where 
                      alumno='$idalumno'
                      and nivel='BASICOS'
                      and grado = 2");
$n=0;                      
while($icurso=mysql_fetch_array($qcursos)){
  $n++;
  $pdf->cell(10,7,"$n",1,0,"C");
  $pdf->cell(89,7,$icurso[curso],1,0,"L");
  $pdf->cell(10,7,$icurso[nota],1,0,"C");
  $pdf->cell(45,7,inicial_mayuscula(enletras($icurso[nota])),1,0,"L");
  if($icurso[nota]>=60){
  $pdf->cell(20,7,"Aprobado",1,0,"C");
  }else{
  $pdf->cell(20,7,"Reprobado",1,0,"C");
  }
  
  $pdf->cell(21,7,fecha($icurso[fecha]),1,1,"C");
  
}

$qmt=mysql_query("select * 
                  from exp_matriculas 
                  where 
                  carnet = '$idalumno'
                  and nivel = 'BASICOS'
                  and grado = 3");
$imt=mysql_fetch_array($qmt);

$pdf->setstyle("B",true);
$pdf->cell(195,7,"TERCER GRADO DE EDUCACION BASICA O DE CULTURA GENERAL",1,1,"C");
$pdf->setstyle("B",false);
$pdf->cell(30,7,"Cursado en:",1,0);
$pdf->cell(165,7,$imt[cursado_en],1,1);
$pdf->cell(30,7,"Matrícula No.:",1,0);
$pdf->cell(30,7,$imt[matricula],1,0);
$pdf->cell(30,7,"De fecha:",1,0);
$pdf->cell(105,7,fecha($imt[matricula_fecha]),1,1);
$pdf->cell(30,7,"Extendida en:",1,0);
$pdf->cell(165,7,$imt[matricula_extendidaen],1,1);

$qcursos=mysql_query("select * 
                      from exp_cursos 
                      where 
                      alumno='$idalumno'
                      and nivel='BASICOS'
                      and grado = 3");
$n=0;                      
while($icurso=mysql_fetch_array($qcursos)){
  $n++;
  $pdf->cell(10,7,"$n",1,0,"C");
  $pdf->cell(89,7,$icurso[curso],1,0,"L");
  $pdf->cell(10,7,$icurso[nota],1,0,"C");
  $pdf->cell(45,7,inicial_mayuscula(enletras($icurso[nota])),1,0,"L");
  if($icurso[nota]>=60){
  $pdf->cell(20,7,"Aprobado",1,0,"C");
  }else{
  $pdf->cell(20,7,"Reprobado",1,0,"C");
  }
  
  $pdf->cell(21,7,fecha($icurso[fecha]),1,1,"C");
  
}

//HOJA # 2
$pdf->AddPage();
$pdf->SetFont('Arial','',10);
$pdf->cell(195,7,"HOJA # DOS, CERTIFICACION:",1,1,"L");

$pdf->setstyle("B",true);
$pdf->cell(195,7,"CICLO DIVERSIFICADO",1,1,"C");
$pdf->setstyle("B",false);


$qmt=mysql_query("select * 
                  from exp_matriculas 
                  where 
                  carnet = '$idalumno'
                  and nivel = 'DIVERSIFIC'
                  and grado = 4");
$imt=mysql_fetch_array($qmt);

$pdf->setstyle("B",true);
$pdf->cell(195,7,"CUARTO GRADO DE ".strtoupper($carrera),1,1,"C");
$pdf->setstyle("B",false);
$pdf->cell(30,7,"Cursado en:",1,0);
$pdf->cell(165,7,$imt[cursado_en],1,1);
$pdf->cell(30,7,"Matrícula No.:",1,0);
$pdf->cell(30,7,$imt[matricula],1,0);
$pdf->cell(30,7,"De fecha:",1,0);
$pdf->cell(105,7,fecha($imt[matricula_fecha]),1,1);
$pdf->cell(30,7,"Extendida en:",1,0);
$pdf->cell(165,7,$imt[matricula_extendidaen],1,1);

$qcursos=mysql_query("select * 
                      from exp_cursos 
                      where 
                      alumno='$idalumno'
                      and nivel='DIVERSIFIC'
                      and grado = 4");
$n=0;                      
while($icurso=mysql_fetch_array($qcursos)){
  $n++;
  $pdf->cell(10,7,"$n",1,0,"C");
  $pdf->cell(89,7,$icurso[curso],1,0,"L");
  $pdf->cell(10,7,$icurso[nota],1,0,"C");
  $pdf->cell(45,7,inicial_mayuscula(enletras($icurso[nota])),1,0,"L");
  if($icurso[nota]>=60){
  $pdf->cell(20,7,"Aprobado",1,0,"C");
  }else{
  $pdf->cell(20,7,"Reprobado",1,0,"C");
  }
  
  $pdf->cell(21,7,fecha($icurso[fecha]),1,1,"C");
  
}




$qmt=mysql_query("select * 
                  from exp_matriculas 
                  where 
                  carnet = '$idalumno'
                  and nivel = 'DIVERSIFIC'
                  and grado = 5");
$imt=mysql_fetch_array($qmt);

$pdf->setstyle("B",true);
$pdf->cell(195,7,"QUINTO GRADO DE ".strtoupper($carrera),1,1,"C");
$pdf->setstyle("B",false);
$pdf->cell(30,7,"Cursado en:",1,0);
$pdf->cell(165,7,$imt[cursado_en],1,1);
$pdf->cell(30,7,"Matrícula No.:",1,0);
$pdf->cell(30,7,$imt[matricula],1,0);
$pdf->cell(30,7,"De fecha:",1,0);
$pdf->cell(105,7,fecha($imt[matricula_fecha]),1,1);
$pdf->cell(30,7,"Extendida en:",1,0);
$pdf->cell(165,7,$imt[matricula_extendidaen],1,1);

$qcursos=mysql_query("select * 
                      from exp_cursos 
                      where 
                      alumno='$idalumno'
                      and nivel='DIVERSIFIC'
                      and grado = 5");
$n=0;                      
while($icurso=mysql_fetch_array($qcursos)){
  $n++;
  $pdf->cell(10,7,"$n",1,0,"C");
  $pdf->cell(89,7,$icurso[curso],1,0,"L");
  $pdf->cell(10,7,$icurso[nota],1,0,"C");
  $pdf->cell(45,7,inicial_mayuscula(enletras($icurso[nota])),1,0,"L");
  if($icurso[nota]>=60){
  $pdf->cell(20,7,"Aprobado",1,0,"C");
  }else{
  $pdf->cell(20,7,"Reprobado",1,0,"C");
  }
  
  $pdf->cell(21,7,fecha($icurso[fecha]),1,1,"C");
  
}

if($carrera2 != "bachillerato"){
/// SEXTO
$qmt=mysql_query("select * 
                  from exp_matriculas 
                  where 
                  carnet = '$idalumno'
                  and nivel = 'DIVERSIFIC'
                  and grado = 6");
$imt=mysql_fetch_array($qmt);

$pdf->setstyle("B",true);
$pdf->cell(195,7,"SEXTO GRADO DE ".strtoupper($carrera),1,1,"C");
$pdf->setstyle("B",false);
$pdf->cell(30,7,"Cursado en:",1,0);
$pdf->cell(165,7,$imt[cursado_en],1,1);
$pdf->cell(30,7,"Matrícula No.:",1,0);
$pdf->cell(30,7,$imt[matricula],1,0);
$pdf->cell(30,7,"De fecha:",1,0);
$pdf->cell(105,7,fecha($imt[matricula_fecha]),1,1);
$pdf->cell(30,7,"Extendida en:",1,0);
$pdf->cell(165,7,$imt[matricula_extendidaen],1,1);

$qcursos=mysql_query("select * 
                      from exp_cursos 
                      where 
                      alumno='$idalumno'
                      and nivel='DIVERSIFIC'
                      and grado = 6");
$n=0;                      
while($icurso=mysql_fetch_array($qcursos)){
  $n++;
  $pdf->cell(10,7,"$n",1,0,"C");
  $pdf->cell(89,7,$icurso[curso],1,0,"L");
  $pdf->cell(10,7,$icurso[nota],1,0,"C");
  $pdf->cell(45,7,inicial_mayuscula(enletras($icurso[nota])),1,0,"L");
  if($icurso[nota]>=60){
  $pdf->cell(20,7,"Aprobado",1,0,"C");
  }else{
  $pdf->cell(20,7,"Reprobado",1,0,"C");
  }
  
  $pdf->cell(21,7,fecha($icurso[fecha]),1,1,"C");
  
}
} // fin si no es bachillerato

$fecha_certificado=enletras(date("d"))." día(s) del mes de ".mes_letras(date("m"))." del ".enletras(date("Y"));

$pdf->cell(195,7,"Y para los usos que al (la) interesado(a) convengan, se extiende la presente en DOS hojas de papel bond,",1,1);
$pdf->cell(195,7,"en la ciudad de Guatemala a los ".$fecha_certificado.".",1,1);
$pdf->setstyle("B",true);

$pdf->cell(195,7,"",1,1);
$pdf->cell(195,7,"",1,1);
$pdf->cell(195,7,"",1,1);

$pdf->cell(195,7,"",1,1);
$pdf->cell(195,7,"",1,1);
$pdf->cell(195,7,"",1,1);
$pdf->cell(195,7,"",1,1);
$pdf->cell(195,7,"",1,1);
$pdf->cell(195,7,"",1,1);
$pdf->ln(-7*6);
$pdf->cell(110,7,"",0,0);
$pdf->cell(40,7,"Profa. Gloria Xicará de Sabán",0,1,"C");
$pdf->cell(110,7,"",0,0);
$pdf->cell(40,7,"SECRETARIO(A)",0,1,"C");

$pdf->cell(195,7,"",1,1);
$pdf->cell(195,7,"",1,1);
$pdf->cell(195,7,"",1,1);
$pdf->ln(-7*3);

$pdf->cell(10,7,"Vo.Bo.",0,1);
$pdf->cell(60,7,"Licda. Carmen de Pardo",0,1,"C");
$pdf->cell(60,7,"DIRECTORA GENERAL",0,1,"C");

$pdf->setstyle("B",false);

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