<?php
require_once 'bs_con2.php';
require_once '../../../../app/model/bs_info_col.php';
require_once('../../../../app/model/FPDF/fpdf.php');

class GenerarPdf extends FPDF
{
    function Header()
    {
        $ob=new InfoCol();
        $arr=$obj->proceso();
        
        
	$this->Ln(9);
        $this->Image("../../views/default/images/".$arr[1],10,12,20);
        $this->SetFont("Times","B",16);
        $this->Cell(24);
        $this->SetTextColor(0,0,0);
        $this->SetFillColor(248,248,255);
        $this->Cell(155,9,$arr[0],1,0,'C',false);
                
                
                
        $this->Ln(13);
        //$this->Image("",10,10,30);
        $this->SetFont("Times","B",12);
        $this->Cell(70);
        $this->SetTextColor(0,0,0);
        $this->SetFillColor(240,230,140);
        $this->Cell(50,6,"Logros",1,0,'C',true);
        $this->Ln(12);
        
    }
 
    


    function datos_Tbla($cabeceraT){
        
        $obj=new Con2();
        $arr=$obj->proceso($_REQUEST['grado'],$_REQUEST['curso'],$_REQUEST['asig']);
        $obj->disconnect();

        $orden='';
        if($arr=='no')
         {
            //$this->SetFont("Helvetica","B",9);
            $this->Cell(65);
            $this->SetFillColor(248,248,255);
            $this->Cell(60,9,"No hay Logros Registrados",1,0,'C',true);
         }else{
       
        
            $this->Ln(5);
            $this->Cell(1);
            $this->SetFont("Times","B",12);
            $this->SetTextColor(0,0,0);
            $this->SetFillColor(248,248,255);
            $this->Cell(110,6,"Curso : ".$arr[0][1],1,0,'C',true);
            $this->Ln(10);
            $this->SetFont("Helvetica","B",7);
            $this->Cell(21);

            $orden;

            for($c=0;$c<count($arr);$c++)
            {

               if($c>0){

                    if($arr[$c][2]==$arr[$c-1][2]){

                            if($arr[$c][4]==$arr[$c-1][4])
                             {

                                    $this->SetFont("Helvetica","I",7);
                            //              $this->Cell(10);
                                    $this->Cell(30);
                                    $this->Cell(25,5,$arr[$c][6],1,0,'C');				
                                    $this->Cell(25,5,$arr[$c][7],1,0,'C');											
                                    //$orden=$this->VariasLineas($arr[$c][7],90,105,65,$orden['y'],$align="");



                               $this->ln(5);

                            }else{


                                    $this->Ln(5);
                                    $this->Cell(1);
                                    $this->SetFont("Times","B",12);
                                    $this->SetTextColor(0,0,0);
                                    $this->SetFillColor(255,248,220);
                                    $this->Cell(20);
                                    $this->Cell(50,6,"Periodo : ".$arr[$c][5],1,0,'C',true);
                                    $this->Ln(10);
                                    $this->SetFont("Helvetica","B",7);

                                    $this->Cell(30);

                                    $this->SetFillColor(248,248,255);
                                    for($i=0;$i<count($cabeceraT);$i++)
                                    {
                                            if($i==1)
                                            {
                                               $this->Cell(105,5,($cabeceraT[$i]),1,0,'C',true);

                                            }else{
                                            $this->Cell(25,5,($cabeceraT[$i]),1,0,'C',true);}


                                    }
                                    $this->ln(5);


                                    $this->SetFont("Helvetica","I",7);
                                    $this->Cell(30);


                                    $this->Cell(25,5,$arr[$c][6],1,0,'C');
                                    $this->Cell(25,5,$arr[$c][7],1,0,'C');
                                    //$orden=$this->VariasLineas($arr[$c][7],90,105,65,$orden['y'],$align="");
                                    //print_r($orden);

                                       $this->ln(5);



                              }	

                    }else{

                       $this->Ln(5);
                       $this->Cell(1);
                       $this->SetFont("Times","B",12);
                       $this->SetTextColor(0,0,0);
                       $this->SetFillColor(255,248,220);
                       $this->Cell(10);
                       $this->Cell(50,6,"Asignatura : ".$arr[$c][3],1,0,'C',true);
                       $this->Ln(10);
                       $this->SetFont("Helvetica","B",7);


                       $this->Ln(5);
                       $this->Cell(1);
                       $this->SetFont("Times","B",12);
                       $this->SetTextColor(0,0,0);
                       $this->SetFillColor(255,248,220);
                       $this->Cell(20);
                       $this->Cell(50,6,"Periodo : ".$arr[$c][5],1,0,'C',true);
                       $this->Ln(10);
                       $this->SetFont("Helvetica","B",7);

                       $this->Cell(30);

                            $this->SetFillColor(248,248,255);
                       for($i=0;$i<count($cabeceraT);$i++)
                            {
                               if($i==1)
                               {
                                       $this->Cell(105,5,($cabeceraT[$i]),1,0,'C',true);

                               }else{
                               $this->Cell(25,5,($cabeceraT[$i]),1,0,'C',true);}


                             }
                            $this->ln(5);


                            $this->SetFont("Helvetica","I",7);
                            $this->Cell(30);


                      $this->Cell(25,5,$arr[$c][6],1,0,'C');
                      $orden=$this->VariasLineas($arr[$c][7],90,105,65,94,$align="");

                    }
			   }else {
				
			   $this->Ln(5);
			   $this->Cell(1);
			   $this->SetFont("Times","B",12);
			   $this->SetTextColor(0,0,0);
			   $this->SetFillColor(255,248,220);
			   $this->Cell(10);
			   $this->Cell(50,6,"Asignatura : ".$arr[$c][3],1,0,'C',true);
			   $this->Ln(10);
			   $this->SetFont("Helvetica","B",7);


			   $this->Ln(5);
			   $this->Cell(1);
			   $this->SetFont("Times","B",12);
			   $this->SetTextColor(0,0,0);
			   $this->SetFillColor(255,248,220);
			   $this->Cell(20);
			   $this->Cell(50,6,"Periodo : ".$arr[$c][5],1,0,'C',true);
			   $this->Ln(10);
			   $this->SetFont("Helvetica","B",7);

			   $this->Cell(30);

				$this->SetFillColor(248,248,255);
			   for($i=0;$i<count($cabeceraT);$i++)
				{
				   if($i==1)
				   {
					   $this->Cell(105,5,($cabeceraT[$i]),1,0,'C',true);

				   }else{
				   $this->Cell(25,5,($cabeceraT[$i]),1,0,'C',true);}


				 }
				$this->ln(5);


				$this->SetFont("Helvetica","I",7);
				$this->Cell(30);


			  $this->Cell(25,5,$arr[$c][6],1,0,'C');
			  $orden=$this->VariasLineas($arr[$c][7],90,105,65,94,$align="");



		//                   $this->ln(5);
		//                $this->Cell(30);

			   }

               }
         }
        
       
        
    }

function VariasLineas($cadena, $cantidad,$largo,$x,$y,$align="")
{
$numLin=0;
while (!(strlen($cadena)==''))
{
    $numLin++;

    $subcadena = substr($cadena, 0, $cantidad);
    $this->SetXY($x,$y);
    $this->Cell($largo,5,$subcadena,'1',"",$align);
    $y+=5;
    $cadena= substr($cadena,$cantidad);

    $this->Ln();
}
$array['numLin']=$numLin;
$array['y']=$y;
    return $array;
}



function Footer()
    {
        $this->SetY(-20);
        $this->Cell(20);
        $this->Cell(120,10,"Pagina No.".$this->PageNo()."",1,0);
        $this->Cell(200);
    }
}

$cabeceraT=array("Codigo","Descripcion");


$pdf=new GenerarPdf();
$pdf->AddPage();

$pdf->datos_Tbla($cabeceraT);
$pdf->Output();

?>
