<?php
session_start();
error_reporting(E_ERROR | E_PARSE);


//if (isset($_SESSION['user'])&&!empty($_SESSION['user'])) {

/* http://programarenphp.wordpress.com */
/* incluimos primeramente el archivo que contiene la clase fpdf */
include '../conector.php';

$select_est="select estudiante_id,nombre,usuario,clave  from estudiante where curso_id=".$_POST['cur2']." and estado_est='A' order by nombre";
$res_select_est=mysql_query($select_est);
//echo $select_est;
include ('fpdf.php');

class PDF extends FPDF
{
function Header()
{
	

}
//Pie de pï¿½gina
function Footer()
{
$today_h = date('d-m-Y H:i:s');
$this->SetY(-2);
$this->SetFont('Arial','',8); 
									$this->SetFillColor(242,242,242);
    	$this->Cell(20.5,0.5,utf8_decode('Una educación sólida, con el prestigio y la experiencia de más de cien años.'),0,1,'C',true);
    	$this->Cell(20.5,0.5,utf8_decode('Dirección: Crespo, Cra. 2 Calle 63 N°2-04 - Teléfonos: +57 (605) 6516294 - Celular: 3126709145 - www.colegiolaesperanza.edu.co'),0,1,'C',true);
   	$this->Cell(20.5,0.5,'Cartagena de Indias, Colombia.',0,1,'C',true);    	
$this->SetFont('Arial','',6.5); 
	$this->Cell(4.5,0.5,'Fecha Generacion: '.$today_h,0,1,'L'); 

   }
  
}

/* tenemos que generar una instancia de la clase */
  $pdf=new PDF('P','cm','letter');

  	//	session_destroy();  
if($_POST['val2']==1){

while($rs_sest=mysql_fetch_array($res_select_est))
{$aux=1;
$seleccion_pen=" select distinct pensum.subject_id
            from estudiante,pensum,curso,planilla_detalle,asignatura 
				             where pensum.class_id=".$_POST['cur2']." 
				            and estudiante.estudiante_id=".$rs_sest[0]." 
				            and planilla_detalle.planilla=".$_POST['per2']." 
				            and pensum.class_id=curso.curso_id 
				            and estudiante.curso_id=pensum.class_id 
				            and pensum.estado='A' 
				            and planilla_detalle.codigo_pensum=pensum.subject_id 
				            and planilla_detalle.codigo_est=estudiante.estudiante_id 
				            and asignatura.subject_id=pensum.asignatura_id  order by pensum.nombre";
				            

//echo $rs_sest[0]."<br>";
$pdf->AddPage();

$select_obs_dir_prm="		select observacion.tipo,round(AVG(observacion_dirgrupo.nota )),observacion.descripcion
					from observacion_dirgrupo,observacion 
					where observacion_dirgrupo.estado='A' 
					and observacion_dirgrupo.id_observacion=observacion.Id 
					and observacion_dirgrupo.id_planilla=".$_POST['per2']." 
					and observacion_dirgrupo.id_curso=".$_POST['cur2']." 
					and observacion_dirgrupo.id__estudiante=".$rs_sest[0]." 
					group by observacion.tipo";
					$res_select_obs_dir_prm=mysql_query($select_obs_dir_prm);
					$filas3 = mysql_num_rows($res_select_obs_dir_prm);





//if (isset($_SESSION['planilla'])){$planilla=$_SESSION['planilla'];} 

$today_h = date('d-m-Y');	

$sel_estudiante="select estu.nombre,estu.usuario,estu.clave,u.nombre_archivo as foto from"
        . " estudiante estu"
        ." left join upload u ON (u.codigo = estu.estudiante_id and u.clase='F')"
        . "where estu.estudiante_id=".$rs_sest[0]." ";
$res_sel_estudiante=mysql_query($sel_estudiante);
$estudiante=mysql_fetch_array($res_sel_estudiante);

$sel_curso="select codigo,nombre from curso where curso_id=".$_POST['cur2']." ";
$res_sel_curso=mysql_query($sel_curso);
$curso=mysql_fetch_array($res_sel_curso);

$sel_planilla="select anno,periodo from planilla where id=".$_POST['per2']." ";
$res_sel_planilla=mysql_query($sel_planilla);
$planilla=mysql_fetch_array($res_sel_planilla);

    if($aux==1){   
	$pdf->Ln(0.2);
	$pdf->SetFillColor(212,212,212);
	$pdf->SetFont('Arial','B',15); 
        $pdf->Cell(8,1,'COLEGIO DE LA ESPERANZA',0,0,'C',TRUE); 
        $pdf->Cell(0.1,1,' ',0,0,'C');
        $pdf->Cell(12.4,1,' INFORME ACADEMICO',0,1,'C',TRUE);

	$pdf->Ln(0.1);
	$pdf->Cell(8.1,1,' ',0,0,'C');
	$pdf->SetFont('Arial','b',8); 
        $pdf->Cell(12.4,0.5,'NOMBRE DEL ALUMNO',0,1,'C',TRUE);

	$pdf->Ln(0.1);
	$pdf->Cell(8.1,1,' ',0,0,'C');
	$pdf->SetFont('Arial','',8); 
        $pdf->Cell(12.4,2.5,''.utf8_decode($estudiante[0]),0,1,'C',false);
        $imagen_nueva_v = '../img/foto/'.$estudiante[3];
        
        if (file_exists($imagen_nueva_v) && $estudiante[3] != "") {
            $pdf->Image($imagen_nueva_v,8.7,2.3,2.8);
        } else {
            $pdf->Image('../img/foto/estudiante.jpg',8.7,2.3,2.8);
        }
        $pdf->Ln(0.1);
        
	$pdf->Ln(0.1);
	$pdf->Cell(8.1,1,' ',0,0,'C');
	$pdf->SetFont('Arial','b',8); 
        $pdf->Cell(3,0.5,'CODIGO',0,0,'C',true);
        $pdf->Cell(0.1,1,' ',0,0,'C');        
        $pdf->Cell(2,0.5,'CURSO',0,0,'C',true);
        $pdf->Cell(0.1,1,' ',0,0,'C');        
        $pdf->Cell(2,0.5,'FECHA',0,0,'C',true);
        $pdf->Cell(0.1,1,' ',0,0,'C');        
        $pdf->Cell(2,0.5,'PERIODO',0,0,'C',true);
        $pdf->Cell(0.1,1,' ',0,0,'C');        
        $pdf->Cell(3,0.5,'AÑO ESCOLAR',0,1,'C',true);        

	$pdf->Cell(8.1,1,' ',0,0,'C');
	$pdf->SetFont('Arial','',8); 
        $pdf->Cell(3,0.5,''.$rs_sest[0],0,0,'C',false);
        $pdf->Cell(0.1,1,' ',0,0,'C');        
        $pdf->Cell(2,0.5,''.$curso[0].' - '.$curso[1],0,0,'C',false);
        $pdf->Cell(0.1,1,' ',0,0,'C');        
        $pdf->Cell(2,0.5,''.$today_h,0,0,'C',false);
        $pdf->Cell(0.1,1,' ',0,0,'C');        
        $pdf->Cell(2,0.5,''.$planilla[1],0,0,'C',false);
        $pdf->Cell(0.1,1,' ',0,0,'C');        
        $pdf->Cell(3,0.5,''.$planilla[0],0,1,'C',false);        

	$pdf->Ln(0.1);
	$pdf->Cell(8.1,0.5,' ',0,0,'C');
	$pdf->SetFont('Arial','b',8); 
        $pdf->Cell(12.4,0.5,'OBSERVACIONES DISCIPLINARIAS',0,1,'C',true);
if($filas3==0){
		$pdf->Ln(0.1);
		$pdf->Cell(8.1,0.3,' ',0,0,'C');
		$pdf->SetFont('Arial','b',8); 
	        
		$pdf->Cell(12.4,3.6,'   ',0,1,'L');


}
if($filas3>0){
	while($enc=mysql_fetch_array($res_select_obs_dir_prm)){

	if($enc[1]>=0 && $enc[1]<=69){$concepto=' BAJO';}
	if($enc[1]>=70 && $enc[1]<=79){$concepto=' BASICO';}
	if($enc[1]>=80 && $enc[1]<=94){$concepto=' ALTO';}
	if($enc[1]>=95 && $enc[1]<=100){$concepto=' SUPERIOR';}		
		$pdf->Ln(0.1);
		$pdf->Cell(8.1,0.3,' ',0,0,'C');
		$pdf->SetFont('Arial','b',8); 
	        $pdf->Cell(12.4,0.3,$enc[2].': '.$enc[1].' '.$concepto,0,1,'L');
	
		$select_obs_dir="
						select observacion.id,
							observacion.tipo,
							observacion.descripcion,
							observacion_dirgrupo.id,
							observacion_dirgrupo.nota
						from observacion_dirgrupo,observacion 
							where observacion_dirgrupo.estado='A' 
							and observacion_dirgrupo.id_observacion=observacion.Id
							and observacion_dirgrupo.id_planilla=".$_POST['per2']." 
							and observacion_dirgrupo.id_curso=".$_POST['cur2']." 
							and observacion_dirgrupo.id__estudiante=".$rs_sest[0]." 
							and observacion.tipo='".$enc[0]."'
							order by observacion_dirgrupo.id_observacion  ";
						$res_select_obs_dir=mysql_query($select_obs_dir);
						$filas2 = mysql_num_rows($res_select_obs_dir);
		if($filas2>0){
			while($det=mysql_fetch_array($res_select_obs_dir)){
				$pdf->Ln(0.1);
				$pdf->Cell(8.1,0.3,' ',0,0,'C');
				$pdf->SetFont('Arial','',7); 
			        
			        if($det[4]<100){
			        $pdf->Cell(12.4,0.3,'   '.$det[4].' '.$det[2],0,1,'L');}
			        else{
			        $pdf->Cell(12.4,0.3,' '.$det[4].' '.$det[2],0,1,'L');}
			        
			}
		}	
	
	}
}
        


	$pdf->Ln(0.2);
	$pdf->SetFillColor(255,255,255);
	$pdf->Cell(8.1,0.9,' ',0,0,'C');
	$pdf->SetFont('Arial','b',8); 
        $pdf->Cell(4.1,0.7,'',0,0,'C',true);
        $pdf->Cell(4.1,0.7,'',0,0,'C',true);
        $pdf->Cell(4.1,0.7,'',0,1,'C',true);

	$pdf->Cell(8.1,2,' ',0,0,'C');
	$pdf->SetFont('Arial','b',8); 
        $pdf->Cell(4.1,0.5,' ',0,0,'C',true);
        $pdf->Cell(4.1,0.5,' ',0,0,'C',true);
        $pdf->Cell(4.1,0.5,'_________________',0,1,'C',true);

$pdf->Cell(8.1,2,' ',0,0,'C');
	$pdf->SetFont('Arial','b',7); 
        $pdf->Cell(4.1,0.3,'JORGE PEREZ VASQUEZ',0,0,'C',true);
        $pdf->Cell(4.1,0.3,'EVELYN TORRES HERAZO',0,0,'C',true);
        $pdf->Cell(4.1,0.3,'DIRECTOR DE GRUPO',0,1,'C',true);
        

	$pdf->SetFont('Arial','',8); 
      	$pdf->Cell(8.1,0.3,'PLATAFORMA USUARIO: '.strtoupper($estudiante[1]).'  CLAVE: '.$estudiante[2],0,0,'L');
	$pdf->SetFont('Arial','b',6); 
        $pdf->Cell(4.1,0.3,'RECTOR',0,0,'C',true);
        $pdf->Image('../img/firma_rector.jpg',9.6,11.1,0);
        $pdf->Cell(4.1,0.3,'SECRETARIA ACADEMICA',0,0,'C',true);
        $pdf->Image('../img/firma_secretaria.jpg',13.2,11.1,0);
        $pdf->Cell(4.1,0.3,' ',0,1,'C',true);

	$pdf->Image('../img/banner_periodo.jpg',0.5,1.8,0);
        $pdf->Ln(0.1);
	}

	//$pdf->AddPage();

	$res_seleccion_pen=mysql_query($seleccion_pen);
	$num_filas_pen = mysql_num_rows($res_seleccion_pen);	

	if($num_filas_pen>0){
//	$pdf->Ln(2);	
$color=242;$c=0;
		while($rs_sel_pen=mysql_fetch_array($res_seleccion_pen)){
                                /**************************   FALTAS  *****************************/
				$sel_faltas="select * from asistencia a,asistencia_det b
						where b.asistencia_id=a.id
						and a.periodo=".$_POST['per2']."
						and a.pensum=".$rs_sel_pen[0]."
						and b.estudiante=".$rs_sest[0]."
						and asiste=0";
				$num_faltas=0;
		            	$res_sel_faltas=mysql_query($sel_faltas);
			    	$num_faltas = mysql_num_rows($res_sel_faltas);	
		 	
				/**************************  FIN FALTAS  *****************************/	
			$c++;
			 	$select_curso_nota="select asignatura.nombre,planilla_consulta.pensum,
				IFNULL(planilla_consulta.D,0),
				IFNULL(planilla_consulta.I,0),
				IFNULL(planilla_consulta.F,0),
				IFNULL(planilla_consulta.IP,0),
				IFNULL(planilla_consulta.FP,0),
				IFNULL(planilla_consulta.C1,0),
				IFNULL(planilla_consulta.C2,0),
				IFNULL(planilla_consulta.CG,0)	
					,pensum.intensidad
				            from estudiante,pensum,curso,planilla_consulta,asignatura 
				            where pensum.class_id=".$_POST['cur2']." 
				            and estudiante.estudiante_id=".$rs_sest[0]." 
				            and planilla_consulta.periodo=".$_POST['per2']." 
				            and pensum.class_id=curso.curso_id 
				            and estudiante.curso_id=pensum.class_id 
				            and pensum.estado='A' 
				            and pensum.subject_id=".$rs_sel_pen[0]."
				            and planilla_consulta.pensum=pensum.subject_id 
				            and planilla_consulta.estudiante=estudiante.estudiante_id 
				            and asignatura.subject_id=pensum.asignatura_id 
				            order by  pensum.nombre";	
				            
				            $num_filas_not=0;
				            if($res_select_curso_nota=mysql_query($select_curso_nota)){
					    $num_filas_not = mysql_num_rows($res_select_curso_nota);	}
					    
					    				    	/*********nota final otros periodos*****/
		     	
				     	/*******11-04-2014****QUERY PARA RECORRER PERIODOS PARA LAS DEF*/ 
					$select_periodos="select a.anno,b.periodo,b.id,a.periodo
								from planilla a,planilla b 
								where a.id='".$_POST['per2']."' 
								and a.anno=b.anno
								and b.periodo<a.periodo
								order by b.periodo
								";
					 $res_select_periodos=mysql_query($select_periodos);
					$num_periodos = mysql_num_rows($res_select_periodos);				
					
					
								
					/****************************************************************/
				     	$actual=1;
				     	$acum_nota_final_per=0;
				     	$nota_p1=0;
					    $nota_p2=0;
					    $nota_p3=0;
					    //$nota_p4=0;
				     	
				     	if($num_periodos>0){
		
						while($periodos=mysql_fetch_array($res_select_periodos)){
							
							$actual=$periodos[3];
						//	echo $periodos[2]." id plan - per actual ".$periodos[3]."<br>";
							
							$select_curso_nota_per=" select asignatura.nombre,planilla_consulta.pensum,
								IFNULL(planilla_consulta.D,0),
								IFNULL(planilla_consulta.I,0),
								IFNULL(planilla_consulta.F,0),
								IFNULL(planilla_consulta.IP,0),
								IFNULL(planilla_consulta.FP,0),
								IFNULL(planilla_consulta.C1,0),
								IFNULL(planilla_consulta.C2,0),
								IFNULL(planilla_consulta.CG,0)	

						            from estudiante,pensum,curso,planilla_consulta,asignatura 
						            where pensum.class_id=".$_POST['cur2']." 
						            and estudiante.estudiante_id=".$rs_sest[0]." 
						            and planilla_consulta.periodo=".$periodos[2]." 
						            and pensum.class_id=curso.curso_id 
						            and estudiante.curso_id=pensum.class_id 
						            and pensum.estado='A' 
						            and pensum.subject_id=".$rs_sel_pen[0]."
						            and planilla_consulta.pensum=pensum.subject_id 
						            and planilla_consulta.estudiante=estudiante.estudiante_id 
						            and asignatura.subject_id=pensum.asignatura_id 
						             order by pensum.nombre
						            ";
							
							
							//echo $select_curso_nota_per."<br>";
							
							    $num_filas_not_per=0;
						            if( $res_select_curso_nota_per=mysql_query($select_curso_nota_per)){
							    $num_filas_not_per = mysql_num_rows($res_select_curso_nota_per);	
							    }
					      
							    	if($num_filas_not_per>0){			
									$materia_pensum_p='';
									$diario_p=0;
									$inter_p=0;
									$final_p=0;
									$int_prof_p=0;
									$fin_prof_p=0;
									$credito1_p=0;
									$credito2_p=0;	
									$total_60_p=0;
									$cuarenta_intermedio_p=0;
									$sesenta_global_p=0;
									$cuarenta_global_p=0;
									
									
									
									while($rs_not_per=mysql_fetch_array($res_select_curso_nota_per)){
									$materia_pensum_p=$rs_not_per[0];
									$diario_p+=$rs_not_per[2];
									$inter_p+=$rs_not_per[3];
									$final_p+=$rs_not_per[4];
									$int_prof_p+=$rs_not_per[5];
									$fin_prof_p+=$rs_not_per[6];
									$credito1_p+=$rs_not_per[7];
									$credito2_p+=$rs_not_per[8];

									}
									if($credito1_p>=0 && $credito1_p<=59)  {$bono1_p=0;}
									if($credito1_p>=60 && $credito1_p<=64) {$bono1_p=3;}
									if($credito1_p>=65 && $credito1_p<=69) {$bono1_p=5;}
									if($credito1_p>=70 && $credito1_p<=74) {$bono1_p=8;}
									if($credito1_p>=75 && $credito1_p<=79) {$bono1_p=10;}
									if($credito1_p>=80 && $credito1_p<=84) {$bono1_p=13;}
									if($credito1_p>=85 && $credito1_p<=89) {$bono1_p=15;}
									if($credito1_p>=90 && $credito1_p<=94) {$bono1_p=18;}
									if($credito1_p>=95 && $credito1_p<=100){$bono1_p=20;}
									
									if($credito2_p>=0 && $credito2_p<=59)  {$bono2_p=0;}
									if($credito2_p>=60 && $credito2_p<=64) {$bono2_p=3;}
									if($credito2_p>=65 && $credito2_p<=69) {$bono2_p=5;}
									if($credito2_p>=70 && $credito2_p<=74) {$bono2_p=8;}
									if($credito2_p>=75 && $credito2_p<=79) {$bono2_p=10;}
									if($credito2_p>=80 && $credito2_p<=84) {$bono2_p=13;}
									if($credito2_p>=85 && $credito2_p<=89) {$bono2_p=15;}
									if($credito2_p>=90 && $credito2_p<=94) {$bono2_p=18;}
									if($credito2_p>=95 && $credito2_p<=100){$bono2_p=20;}
																		
									$cuarenta_intermedio_p=round(($int_prof_p+$inter_p)/2)*0.4;
									$sesenta_parcial_p=round(($cuarenta_intermedio_p+round($diario_p*0.6)));									
									$sesenta_global_p=round(($cuarenta_intermedio_p+round($diario_p*0.6))+round($bono2_p)+round($bono1_p));
									$cuarenta_global_p=round(($final_p+$fin_prof_p)/2)*0.4;
									$total_60_p=round($sesenta_parcial_p)+round($bono2_p)+round($bono1_p);
									if($total_60_p>100){$total_60_p=100;}


//									$nota_final_per=$total_60_p+$cuarenta_global_p;
									$nota_final_per=round($total_60_p*0.6)+$cuarenta_global_p;
									
									if($nota_final_per>100){$nota_final_per=100;}
									
									//echo "nota final periodo".$periodos[1]." <b>".$nota_final_per." </b>";
									

								if($periodos[1]==1){$nota_p1=$nota_final_per;$acum_nota_final_per+=$nota_final_per ;}
								if($periodos[1]==2){$nota_p2=$nota_final_per;$acum_nota_final_per+=$nota_final_per ;}
								if($periodos[1]==3){$nota_p3=$nota_final_per;$acum_nota_final_per+=$nota_final_per ;}
								/*if($periodos[1]==4){$nota_p4=$nota_final_per;$acum_nota_final_per+=$nota_final_per ;}*/
								}
						}
					}		

					     	/**************************************/
					    	if($num_filas_not>0){	
					    	
					    			$materia_pensum='';
									$diario=0;
									$inter=0;
									$final=0;
									$int_prof=0;
									$fin_prof=0;
									
									$credito1=0;
									$credito2=0;	
									$creditog11=0;
									$total_60=0;
									$creditog11=0;
									$nota_final_p=0;
									
									$cuarenta_intermedio=0;
									$sesenta_parcial=0;
									$sesenta_global=0;
									$cuarenta_global=0;
									$nota_min=0;
									$acum_gral=0;

									
									
									while($rs_curso_nota=mysql_fetch_array($res_select_curso_nota)){
									$materia_pensum=utf8_decode($rs_curso_nota[0]);
									$diario+=$rs_curso_nota[2];
									$inter+=$rs_curso_nota[3];
									$final+=$rs_curso_nota[4];
									$int_prof+=$rs_curso_nota[5];
									$fin_prof+=$rs_curso_nota[6];
									$credito1+=$rs_curso_nota[7];
									$credito2+=$rs_curso_nota[8];
									$creditog11+=$rs_curso_nota[9];
									$intensidad=$rs_curso_nota[10];
									
									
																		
									}
									
									$bono1=0;$bono2=0;$bono3=0;
									if($credito1>=0 && $credito1<=59)  {$bono1=0;}
									if($credito1>=60 && $credito1<=64) {$bono1=3;}
									if($credito1>=65 && $credito1<=69) {$bono1=5;}
									if($credito1>=70 && $credito1<=74) {$bono1=8;}
									if($credito1>=75 && $credito1<=79) {$bono1=10;}
									if($credito1>=80 && $credito1<=84) {$bono1=13;}
									if($credito1>=85 && $credito1<=89) {$bono1=15;}
									if($credito1>=90 && $credito1<=94) {$bono1=18;}
									if($credito1>=95 && $credito1<=100){$bono1=20;}
									
									if($credito2>=0 && $credito2<=59)  {$bono2=0;}
									if($credito2>=60 && $credito2<=64) {$bono2=3;}
									if($credito2>=65 && $credito2<=69) {$bono2=5;}
									if($credito2>=70 && $credito2<=74) {$bono2=8;}
									if($credito2>=75 && $credito2<=79) {$bono2=10;}
									if($credito2>=80 && $credito2<=84) {$bono2=13;}
									if($credito2>=85 && $credito2<=89) {$bono2=15;}
									if($credito2>=90 && $credito2<=94) {$bono2=18;}
									if($credito2>=95 && $credito2<=100){$bono2=20;}
									
									if($creditog11>=0 && $creditog11<=59)  {$bono3=0;}
									if($creditog11>=60 && $creditog11<=64) {$bono3=3;}
									if($creditog11>=65 && $creditog11<=69) {$bono3=5;}
									if($creditog11>=70 && $creditog11<=74) {$bono3=8;}
									if($creditog11>=75 && $creditog11<=79) {$bono3=10;}
									if($creditog11>=80 && $creditog11<=84) {$bono3=13;}
									if($creditog11>=85 && $creditog11<=89) {$bono3=15;}
									if($creditog11>=90 && $creditog11<=94) {$bono3=18;}
									if($creditog11>=95 && $creditog11<=100){$bono3=20;}
									
									//$cuarenta_intermedio=round(($int_prof+$inter)/2)*0.4;
									
									//$sesenta_global=round(($cuarenta_intermedio+round($diario*0.6)+$bono2+$bono1));
									//$cuarenta_global=round(($final+$fin_prof)/2)*0.4;
									//$nota_final_p=round($sesenta_global*0.6 + $cuarenta_global*0.4);

									$cuarenta_intermedio=round(($int_prof+$inter)/2)*0.4;
									$sesenta_parcial=round(($cuarenta_intermedio+round($diario*0.6))*0.6);
									$sesenta_global=round((($cuarenta_intermedio+round($diario*0.6))));
									//$sesenta_global=round(($cuarenta_intermedio+round($diario*0.6)+$bono2+$bono1)*0.6);
									$cuarenta_global=round(($final+$fin_prof)/2)*0.4;

									
									
									
									if($sesenta_global>100){$sesenta_global=100;}
									$total_60=round($sesenta_global)+round($bono2)+round($bono1);
									if($total_60>100){$total_60=100;}
									$nota_final_p=round(($total_60*0.6)+$cuarenta_global);
									//$nota_final_p=($sesenta_global)+$cuarenta_global;									
									if($nota_final_p>100){$nota_final_p=100;}
																			
																		
									if($nota_final_p>=0 && $nota_final_p<=69){$concepto_p='BAJO';} 
									if($nota_final_p>=70 && $nota_final_p<=79){$concepto_p='BASICO';}
									if($nota_final_p>=80 && $nota_final_p<=94){$concepto_p='ALTO';}
									if($nota_final_p>=95 && $nota_final_p<=100){$concepto_p='SUPERIOR';}
									
									if($actual==1){$nota_p1=$nota_final_p;$acum_nota_final_per+=$nota_final_p ;$nota_min=140-$acum_nota_final_per;}
									if($actual==2){$nota_p2=$nota_final_p;$acum_nota_final_per+=$nota_final_p ;$nota_min=210-$acum_nota_final_per;}
									if($actual==3){$nota_p3=$nota_final_p;$acum_nota_final_per+=$nota_final_p ;}
									
									

									if((round($acum_nota_final_per*0.3333)+$bono3)>100){$acum_gral=100;}
									else{$acum_gral=(round($acum_nota_final_per*0.3333)+$bono3);}
									if(round(round($acum_nota_final_per*0.3333)+round($bono3))>100){$nota_final=100;}
									else{$nota_final=round(round($acum_nota_final_per*0.3333)+round($bono3));}


									if($c==5||$c==13){$pdf->AddPage();}	

									$pdf->SetFont('Arial','b',7);
									//$pdf->SetDrawColor(212,86,86);
									
									$pdf->SetFillColor(212,212,212);
									$pdf->Cell(8,0.5,"ASIGNATURA",0,0,'C',true);
									$pdf->Cell(0.1,0.5,"",0,0,'C',FALSE);									
									$pdf->Cell(12.4,0.5,"CONCEPTOS",0,1,'C',true);									
									$pdf->Cell(20.5,0.1,"",0,1,'C',FALSE);
									
									$pdf->SetFont('Arial','b',9);
									$pdf->SetFillColor(242,242,242);
									$pdf->Cell(8,0.5," ".strtoupper($materia_pensum),0,0,'L',true);	
									$pdf->SetFont('Arial','b',7);
									$pdf->Cell(0.1,0.5,"",0,0,'C',FALSE);								
									$pdf->Cell(1.4,0.5," I.H. :",0,0,'R',true);$pdf->Cell(0.6,0.5,"".$intensidad,1,0,'C',FALSE);
									$pdf->Cell(1.5,0.5," AUS :",0,0,'R',true);$pdf->Cell(0.6,0.5,"".$num_faltas,1,0,'C',FALSE);									
									$pdf->Cell(3.5,0.5," NOTA FINAL P1:",0,0,'L',true);$pdf->Cell(0.6,0.5,"".round($nota_p1),1,0,'R',false);
									$pdf->Cell(3,0.5," INDICADOR:",0,0,'L',true);$pdf->Cell(1.2,0.5,"".$concepto_p,0,1,'R',TRUE);
				
									$pdf->Cell(3,0.5," PROM. NOTAS 60%",0,0,'L',true);$pdf->Cell(1,0.5,"  ".round($diario),0,0,'R',false);
									$pdf->Cell(3,0.5," CREDITO 1 Y 2",0,0,'L',true);$pdf->Cell(1,0.5,"".$credito1." - ".$credito2,1,0,'R',false);
									$pdf->Cell(0.1,0.5,"",0,0,'C',FALSE);								
									$pdf->Cell(3.5,0.5," FINAL 60%:",0,0,'L',true);$pdf->Cell(0.6,0.5,"".round($total_60*0.6),1,0,'R',false);
									$pdf->Cell(3.5,0.5," NOTA FINAL P2:",0,0,'L',true);$pdf->Cell(0.6,0.5,"".round($nota_p2),1,0,'R',false);
									$pdf->Cell(3.5,0.5," ACUMULADO GENERAL",0,0,'L',true);$pdf->Cell(0.7,0.5,"".round($acum_nota_final_per*0.3333),1,1,'R',false);

									$pdf->Cell(3,0.5," PROC-INTERMEDIOS",0,0,'L',true);$pdf->Cell(1,0.5,"".round($inter),0,0,'R',false);
									$pdf->Cell(3,0.5," EXA. FINAL",0,0,'L',true);$pdf->Cell(1,0.5,"".round($final),1,0,'R',false);
									$pdf->Cell(0.1,0.5,"",0,0,'C',FALSE);								
									$pdf->Cell(3.5,0.5," FINAL 40%:",0,0,'L',true);$pdf->Cell(0.6,0.5,"".round($cuarenta_global),1,0,'R',false);
									$pdf->Cell(3.5,0.5," NOTA FINAL P3:",0,0,'L',true);$pdf->Cell(0.6,0.5,"".round($nota_p3),1,0,'R',false);
									$pdf->Cell(3.5,0.5," N.M.PROX. PERIODO",0,0,'L',true);$pdf->Cell(0.7,0.5,"".round($nota_min),1,1,'R',false);

									$pdf->Cell(3,0.5," REC. o PROF.",0,0,'L',true);$pdf->Cell(1,0.5,"".round($int_prof),0,0,'R',false);
									$pdf->Cell(3,0.5," REC. o PROF.",0,0,'L',true);$pdf->Cell(1,0.5,"".round($fin_prof),1,0,'R',false);
									$pdf->Cell(0.1,0.5,"",0,0,'C',FALSE);								
									$pdf->Cell(3.5,0.5," CREDITO G11:",0,0,'L',true);$pdf->Cell(0.6,0.5,"".$creditog11,1,0,'R',false);
									/*$pdf->Cell(3.5,0.5," NOTA FINAL P4:",0,0,'L',true);$pdf->Cell(0.6,0.5,"".round($nota_p4),1,0,'R',false);*/
									$pdf->Cell(3.5,0.5," FINAL:",0,0,'L',true);$pdf->Cell(0.7,0.5,"".$nota_final,1,1,'R',false);

									
									$pdf->Cell(20.5,0.1,"",0,1,'C',true);									
									$pdf->Ln(0.3);

								}
		}
	
	}
	
$sel_estudiante="select nombre,usuario,clave from estudiante where estudiante_id=".$rs_sest[0]." ";
$res_sel_estudiante=mysql_query($sel_estudiante);
$estudiante=mysql_fetch_array($res_sel_estudiante);



}
$pdf->Output("Informe_Periodo.pdf",'I');
}
if($_POST['val2']==2){
  //$pdf=new PDF('P','cm','letter');
//$pdf->AddPage();
while($rs_sest=mysql_fetch_array($res_select_est))
{$aux=1;
$pdf->AddPage();
$seleccion_pen=" select distinct pensum.subject_id
            from estudiante,pensum,curso,planilla_detalle,asignatura 
				             where pensum.class_id=".$_POST['cur2']." 
				            and estudiante.estudiante_id=".$rs_sest[0]." 
				            and planilla_detalle.planilla=".$_POST['per2']." 
				            and pensum.class_id=curso.curso_id 
				            and estudiante.curso_id=pensum.class_id 
				            and pensum.estado='A' 
				            and planilla_detalle.codigo_pensum=pensum.subject_id 
				            and planilla_detalle.codigo_est=estudiante.estudiante_id 
				            and asignatura.subject_id=pensum.asignatura_id  order by pensum.nombre";

//echo $rs_sest[0]."<br>";
$select_obs_dir_prm="		select observacion.tipo,round(AVG(observacion_dirgrupo.nota )),observacion.descripcion
					from observacion_dirgrupo,observacion 
					where observacion_dirgrupo.estado='A' 
					and observacion_dirgrupo.id_observacion=observacion.Id 
					and observacion_dirgrupo.id_planilla=".$_POST['per2']." 
					and observacion_dirgrupo.id_curso=".$_POST['cur2']." 
					and observacion_dirgrupo.id__estudiante=".$rs_sest[0]." 
					group by observacion.tipo";
					$res_select_obs_dir_prm=mysql_query($select_obs_dir_prm);
					$filas3 = mysql_num_rows($res_select_obs_dir_prm);





//if (isset($_SESSION['planilla'])){$planilla=$_SESSION['planilla'];} 

$today_h = date('d-m-Y');	




$sel_estudiante="select estu.nombre,estu.usuario,estu.clave,u.nombre_archivo as foto from"
        . " estudiante estu"
        ." left join upload u ON (u.codigo = estu.estudiante_id and u.clase='F')"
        . "where estu.estudiante_id=".$rs_sest[0]." ";
$res_sel_estudiante=mysql_query($sel_estudiante);
$estudiante=mysql_fetch_array($res_sel_estudiante);

$sel_curso="select codigo,nombre from curso where curso_id=".$_POST['cur2']." ";
$res_sel_curso=mysql_query($sel_curso);
$curso=mysql_fetch_array($res_sel_curso);

$sel_planilla="select anno,periodo from planilla where id=".$_POST['per2']." ";
$res_sel_planilla=mysql_query($sel_planilla);
$planilla=mysql_fetch_array($res_sel_planilla);

    if($aux==1){   
	$pdf->Ln(0.2);
	$pdf->SetFillColor(212,212,212);
	$pdf->SetFont('Arial','B',15); 
        $pdf->Cell(8,1,'COLEGIO DE LA ESPERANZA',0,0,'C',TRUE); 
        $pdf->Cell(0.1,1,' ',0,0,'C');
        $pdf->Cell(12.4,1,' INFORME ACADEMICO',0,1,'C',TRUE);

	$pdf->Ln(0.1);
	$pdf->Cell(8.1,1,' ',0,0,'C');
	$pdf->SetFont('Arial','b',8); 
        $pdf->Cell(12.4,0.5,'NOMBRE DEL ALUMNO',0,1,'C',TRUE);

	$pdf->Ln(0.1);
	$pdf->Cell(8.1,1,' ',0,0,'C');
	$pdf->SetFont('Arial','',8); 
        $pdf->Cell(12.4,2.5,''.utf8_decode($estudiante[0]),0,1,'C',false);
        $imagen_nueva_v = '../img/foto/'.$estudiante[3];
        if (file_exists($imagen_nueva_v) && $estudiante[3] != "") {
            $pdf->Image($imagen_nueva_v,8.7,2.3,2.8);
        } else {
            $pdf->Image('../img/foto/estudiante.jpg',8.7,2.3,2.8);
        }
        $pdf->Ln(0.1);
	$pdf->Ln(0.1);
	$pdf->Cell(8.1,1,' ',0,0,'C');
	$pdf->SetFont('Arial','b',8); 
        $pdf->Cell(3,0.5,'CODIGO',0,0,'C',true);
        $pdf->Cell(0.1,1,' ',0,0,'C');        
        $pdf->Cell(2,0.5,'CURSO',0,0,'C',true);
        $pdf->Cell(0.1,1,' ',0,0,'C');        
        $pdf->Cell(2,0.5,'FECHA',0,0,'C',true);
        $pdf->Cell(0.1,1,' ',0,0,'C');        
        $pdf->Cell(2,0.5,'PERIODO',0,0,'C',true);
        $pdf->Cell(0.1,1,' ',0,0,'C');        
        $pdf->Cell(3,0.5,'AÑO ESCOLAR',0,1,'C',true);        

	$pdf->Cell(8.1,1,' ',0,0,'C');
	$pdf->SetFont('Arial','',8); 
        $pdf->Cell(3,0.5,''.$rs_sest[0],0,0,'C',false);
        $pdf->Cell(0.1,1,' ',0,0,'C');        
        $pdf->Cell(2,0.5,''.$curso[0].' - '.$curso[1],0,0,'C',false);
        $pdf->Cell(0.1,1,' ',0,0,'C');        
        $pdf->Cell(2,0.5,''.$today_h,0,0,'C',false);
        $pdf->Cell(0.1,1,' ',0,0,'C');        
        $pdf->Cell(2,0.5,''.$planilla[1],0,0,'C',false);
        $pdf->Cell(0.1,1,' ',0,0,'C');        
        $pdf->Cell(3,0.5,''.$planilla[0],0,1,'C',false);        

	$pdf->Ln(0.1);
	$pdf->Cell(8.1,0.5,' ',0,0,'C');
	$pdf->SetFont('Arial','b',8); 
        $pdf->Cell(12.4,0.5,'OBSERVACIONES DISCIPLINARIAS',0,1,'C',true);
if($filas3==0){
		$pdf->Ln(0.1);
		$pdf->Cell(8.1,0.3,' ',0,0,'C');
		$pdf->SetFont('Arial','b',8); 
	        
		$pdf->Cell(12.4,3.6,'   ',0,1,'L');


}
if($filas3>0){
	while($enc=mysql_fetch_array($res_select_obs_dir_prm)){

	if($enc[1]>=0 && $enc[1]<=69){$concepto=' BAJO';}
	if($enc[1]>=70 && $enc[1]<=79){$concepto=' BASICO';}
	if($enc[1]>=80 && $enc[1]<=94){$concepto=' ALTO';}
	if($enc[1]>=95 && $enc[1]<=100){$concepto=' SUPERIOR';}		
		$pdf->Ln(0.1);
		$pdf->Cell(8.1,0.3,' ',0,0,'C');
		$pdf->SetFont('Arial','b',8); 
	        $pdf->Cell(12.4,0.3,$enc[2].': '.$enc[1].' '.$concepto,0,1,'L');
	
		$select_obs_dir="
						select observacion.id,
							observacion.tipo,
							observacion.descripcion,
							observacion_dirgrupo.id,
							observacion_dirgrupo.nota
						from observacion_dirgrupo,observacion 
							where observacion_dirgrupo.estado='A' 
							and observacion_dirgrupo.id_observacion=observacion.Id
							and observacion_dirgrupo.id_planilla=".$_POST['per2']." 
							and observacion_dirgrupo.id_curso=".$_POST['cur2']." 
							and observacion_dirgrupo.id__estudiante=".$rs_sest[0]." 
							and observacion.tipo='".$enc[0]."'
							order by observacion_dirgrupo.id_observacion  ";
						$res_select_obs_dir=mysql_query($select_obs_dir);
						$filas2 = mysql_num_rows($res_select_obs_dir);
		if($filas2>0){
			while($det=mysql_fetch_array($res_select_obs_dir)){
				$pdf->Ln(0.1);
				$pdf->Cell(8.1,0.3,' ',0,0,'C');
				$pdf->SetFont('Arial','',7); 
			        
			        if($det[4]<100){
			        $pdf->Cell(12.4,0.3,'   '.$det[4].' '.$det[2],0,1,'L');}
			        else{
			        $pdf->Cell(12.4,0.3,' '.$det[4].' '.$det[2],0,1,'L');}
			        
			}
		}	
	
	}
}
        


	$pdf->Ln(0.2);
	$pdf->SetFillColor(255,255,255);
	$pdf->Cell(8.1,0.9,' ',0,0,'C');
	$pdf->SetFont('Arial','b',8); 
        $pdf->Cell(4.1,0.7,'',0,0,'C',true);
        $pdf->Cell(4.1,0.7,'',0,0,'C',true);
        $pdf->Cell(4.1,0.7,'',0,1,'C',true);

	$pdf->Cell(8.1,2,' ',0,0,'C');
	$pdf->SetFont('Arial','b',8); 
        $pdf->Cell(4.1,0.5,' ',0,0,'C',true);
        $pdf->Cell(4.1,0.5,' ',0,0,'C',true);
        $pdf->Cell(4.1,0.5,'_________________',0,1,'C',true);

$pdf->Cell(8.1,2,' ',0,0,'C');
	$pdf->SetFont('Arial','b',7); 
        $pdf->Cell(4.1,0.3,'JORGE PEREZ VASQUEZ',0,0,'C',true);
        $pdf->Cell(4.1,0.3,'EVELYN TORRES HERAZO',0,0,'C',true);
        $pdf->Cell(4.1,0.3,'DIRECTOR DE GRUPO',0,1,'C',true);
        

	$pdf->SetFont('Arial','',8); 
      	$pdf->Cell(8.1,0.3,'PLATAFORMA USUARIO: '.strtoupper($estudiante[1]).'  CLAVE: '.$estudiante[2],0,0,'L');
	$pdf->SetFont('Arial','b',6); 
        $pdf->Cell(4.1,0.3,'RECTOR',0,0,'C',true);
        $pdf->Image('../img/firma_rector.jpg',9.6,11.1,0);
        $pdf->Cell(4.1,0.3,'SECRETARIA ACADEMICA',0,0,'C',true);
        $pdf->Image('../img/firma_secretaria.jpg',13.2,11.1,0);
        $pdf->Cell(4.1,0.3,' ',0,1,'C',true);

	$pdf->Image('../img/banner_periodo.jpg',0.5,1.8,0);
        $pdf->Ln(0.1);
	}
	


  	//	session_destroy();  


	$res_seleccion_pen=mysql_query($seleccion_pen);
	$num_filas_pen = mysql_num_rows($res_seleccion_pen);	

	if($num_filas_pen>0){
//	$pdf->Ln(2);	
$color=242;$c=0;
		while($rs_sel_pen=mysql_fetch_array($res_seleccion_pen)){
                               /**************************   FALTAS  *****************************/
				$sel_faltas="select * from asistencia a,asistencia_det b
						where b.asistencia_id=a.id
						and a.periodo=".$_POST['per2']."
						and a.pensum=".$rs_sel_pen[0]."
						and b.estudiante=".$rs_sest[0]."
						and asiste=0";
				$num_faltas=0;
		            	$res_sel_faltas=mysql_query($sel_faltas);
			    	$num_faltas = mysql_num_rows($res_sel_faltas);	
		 	
				/**************************  FIN FALTAS  *****************************/	
			$c++;
			 	$select_curso_nota="select asignatura.nombre,planilla_consulta.pensum,
				IFNULL(planilla_consulta.D,0),
				IFNULL(planilla_consulta.I,0),
				IFNULL(planilla_consulta.F,0),
				IFNULL(planilla_consulta.IP,0),
				IFNULL(planilla_consulta.FP,0),
				IFNULL(planilla_consulta.C1,0),
				IFNULL(planilla_consulta.C2,0),
				IFNULL(planilla_consulta.CG,0)	
					,pensum.intensidad
				            from estudiante,pensum,curso,planilla_consulta,asignatura 
				            where pensum.class_id=".$_POST['cur2']." 
				            and estudiante.estudiante_id=".$rs_sest[0]." 
				            and planilla_consulta.periodo=".$_POST['per2']." 
				            and pensum.class_id=curso.curso_id 
				            and estudiante.curso_id=pensum.class_id 
				            and pensum.estado='A' 
				            and pensum.subject_id=".$rs_sel_pen[0]."
				            and planilla_consulta.pensum=pensum.subject_id 
				            and planilla_consulta.estudiante=estudiante.estudiante_id 
				            and asignatura.subject_id=pensum.asignatura_id 
				            order by  pensum.nombre";	
			 	
				            
				            $num_filas_not=0;
				            if($res_select_curso_nota=mysql_query($select_curso_nota)){
					    $num_filas_not = mysql_num_rows($res_select_curso_nota);	}
					    
					    				    	/*********nota final otros periodos*****/
		     	
				     	/*******11-04-2014****QUERY PARA RECORRER PERIODOS PARA LAS DEF*/ 
					$select_periodos="select a.anno,b.periodo,b.id,a.periodo
								from planilla a,planilla b 
								where a.id='".$_POST['per2']."' 
								and a.anno=b.anno
								and b.periodo<a.periodo
								order by b.periodo
								";
					 $res_select_periodos=mysql_query($select_periodos);
					$num_periodos = mysql_num_rows($res_select_periodos);				
					
					
								
					/****************************************************************/
				     	$actual=1;
				     	$acum_nota_final_per=0;
                        $nota_p1=0;
					    $nota_p2=0;
					    $nota_p3=0;
					    /*$nota_p4=0;*/
				     	
				     	if($num_periodos>0){
		
						while($periodos=mysql_fetch_array($res_select_periodos)){
							
							$actual=$periodos[3];
						//	echo $periodos[2]." id plan - per actual ".$periodos[3]."<br>";
							
							$select_curso_nota_per=" select asignatura.nombre,planilla_consulta.pensum,
								IFNULL(planilla_consulta.D,0),
								IFNULL(planilla_consulta.I,0),
								IFNULL(planilla_consulta.F,0),
								IFNULL(planilla_consulta.IP,0),
								IFNULL(planilla_consulta.FP,0),
                                IFNULL(planilla_consulta.C1,0),
								IFNULL(planilla_consulta.C2,0),
								IFNULL(planilla_consulta.CG,0)
						            from estudiante,pensum,curso,planilla_consulta,asignatura 
						            where pensum.class_id=".$_POST['cur2']." 
						            and estudiante.estudiante_id=".$rs_sest[0]." 
						            and planilla_consulta.periodo=".$periodos[2]." 
						            and pensum.class_id=curso.curso_id 
						            and estudiante.curso_id=pensum.class_id 
						            and pensum.estado='A' 
						            and pensum.subject_id=".$rs_sel_pen[0]."
						            and planilla_consulta.pensum=pensum.subject_id 
						            and planilla_consulta.estudiante=estudiante.estudiante_id 
						            and asignatura.subject_id=pensum.asignatura_id  order by pensum.nombre";
							
							
							//echo $select_curso_nota_per."<br>";
							$num_filas_not_per=0;
							   if($res_select_curso_nota_per=mysql_query($select_curso_nota_per)){
							    $num_filas_not_per = mysql_num_rows($res_select_curso_nota_per);	}
							    
							    	if($num_filas_not_per>0){			
									
											$materia_pensum_p='';
											$diario_p=0;
											$inter_p=0;
											$final_p=0;
											$int_prof_p=0;
											$fin_prof_p=0;
                                            $credito1_p=0;
											$credito2_p=0;	

											$total_60_p=0;
											$cuarenta_intermedio_p=0;
											$sesenta_global_p=0;
											$cuarenta_global_p=0;
											while($rs_not_per=mysql_fetch_array($res_select_curso_nota_per)){
											$materia_pensum_p=$rs_not_per[0];
											$diario_p+=$rs_not_per[2];
											$inter_p+=$rs_not_per[3];
											$final_p+=$rs_not_per[4];
											$int_prof_p+=$rs_not_per[5];
											$fin_prof_p+=$rs_not_per[6];
                                            $credito1_p+=$rs_not_per[7];
											$credito2_p+=$rs_not_per[8];	

                                                                                        }
											$bono1_p=0;$bono2_p=0;$bono3_p=0;
											if($credito1_p>=0 && $credito1_p<=59)  {$bono1_p=0;}
											if($credito1_p>=60 && $credito1_p<=64) {$bono1_p=3;}
											if($credito1_p>=65 && $credito1_p<=69) {$bono1_p=5;}
											if($credito1_p>=70 && $credito1_p<=74) {$bono1_p=8;}
											if($credito1_p>=75 && $credito1_p<=79) {$bono1_p=10;}
											if($credito1_p>=80 && $credito1_p<=84) {$bono1_p=13;}
											if($credito1_p>=85 && $credito1_p<=89) {$bono1_p=15;}
											if($credito1_p>=90 && $credito1_p<=94) {$bono1_p=18;}
											if($credito1_p>=95 && $credito1_p<=100){$bono1_p=20;}
											
											if($credito2_p>=0 && $credito2_p<=59)  {$bono2_p=0;}
											if($credito2_p>=60 && $credito2_p<=64) {$bono2_p=3;}
											if($credito2_p>=65 && $credito2_p<=69) {$bono2_p=5;}
											if($credito2_p>=70 && $credito2_p<=74) {$bono2_p=8;}
											if($credito2_p>=75 && $credito2_p<=79) {$bono2_p=10;}
											if($credito2_p>=80 && $credito2_p<=84) {$bono2_p=13;}
											if($credito2_p>=85 && $credito2_p<=89) {$bono2_p=15;}
											if($credito2_p>=90 && $credito2_p<=94) {$bono2_p=18;}
											if($credito2_p>=95 && $credito2_p<=100){$bono2_p=20;}





											/*$cuarenta_intermedio_p=round(($int_prof_p+$inter_p)/2)*0.4;
											$sesenta_global_p=round(($cuarenta_intermedio_p+round($diario_p*0.6)+$bono2_p+$bono1_p)*0.6);
											$cuarenta_global_p=round(($final_p+$fin_prof_p)/2)*0.4;
											$nota_final_per=$sesenta_global_p+$cuarenta_global_p;*/
											
											$cuarenta_intermedio_p=round(($int_prof_p+$inter_p)/2)*0.4;
											$sesenta_parcial_p=round(($cuarenta_intermedio_p+round($diario_p*0.6)));									
											$sesenta_global_p=round(($cuarenta_intermedio_p+round($diario_p*0.6))+round($bono2_p)+round($bono1_p));
											$cuarenta_global_p=round(($final_p+$fin_prof_p)/2)*0.4;
											$total_60_p=round($sesenta_parcial_p)+round($bono2_p)+round($bono1_p);
											if($total_60_p>100){$total_60_p=100;}


//									$nota_final_per=$total_60_p+$cuarenta_global_p;
									$nota_final_per=round($total_60_p*0.6)+$cuarenta_global_p;
									
									if($nota_final_per>100){$nota_final_per=100;}
											
											//echo "nota final periodo".$periodos[1]." <b>".$nota_final_per." </b>";
											
		
										if($periodos[1]==1){$nota_p1=$nota_final_per;$acum_nota_final_per+=$nota_final_per ;}
										if($periodos[1]==2){$nota_p2=$nota_final_per;$acum_nota_final_per+=$nota_final_per ;}
										if($periodos[1]==3){$nota_p3=$nota_final_per;$acum_nota_final_per+=$nota_final_per ;}
										/*if($periodos[1]==4){$nota_p4=$nota_final_per;$acum_nota_final_per+=$nota_final_per ;}*/

								}
							
					
								
								
						}
			
			
					}		
					     	
					     	/**************************************/
					    
					    
					    
					    
					    	if($num_filas_not>0){	
					    	
					    			$materia_pensum='';
									$diario=0;
									$inter=0;
									$final=0;
									$int_prof=0;
									$fin_prof=0;
                                    $credito1=0;
									$credito2=0;	
									$creditog11=0;	
									$total_60=0;
									$cuarenta_intermedio=0;
									$sesenta_global=0;
									$cuarenta_global=0;
									while($rs_curso_nota=mysql_fetch_array($res_select_curso_nota)){
									$materia_pensum=utf8_decode($rs_curso_nota[0]);
									$diario+=$rs_curso_nota[2];
									$inter+=$rs_curso_nota[3];
									$final+=$rs_curso_nota[4];
									$int_prof+=$rs_curso_nota[5];
									$fin_prof+=$rs_curso_nota[6];
                                    $credito1+=$rs_curso_nota[7];
									$credito2+=$rs_curso_nota[8];
									$creditog11+=$rs_curso_nota[9];
									$intensidad=$rs_curso_nota[10];
									
									}

									$bono1=0;$bono2=0;$bono3=0;
									if($credito1>=0 && $credito1<=59)  {$bono1=0;}
									if($credito1>=60 && $credito1<=64) {$bono1=3;}
									if($credito1>=65 && $credito1<=69) {$bono1=5;}
									if($credito1>=70 && $credito1<=74) {$bono1=8;}
									if($credito1>=75 && $credito1<=79) {$bono1=10;}
									if($credito1>=80 && $credito1<=84) {$bono1=13;}
									if($credito1>=85 && $credito1<=89) {$bono1=15;}
									if($credito1>=90 && $credito1<=94) {$bono1=18;}
									if($credito1>=95 && $credito1<=100){$bono1=20;}
									
									if($credito2>=0 && $credito2<=59)  {$bono2=0;}
									if($credito2>=60 && $credito2<=64) {$bono2=3;}
									if($credito2>=65 && $credito2<=69) {$bono2=5;}
									if($credito2>=70 && $credito2<=74) {$bono2=8;}
									if($credito2>=75 && $credito2<=79) {$bono2=10;}
									if($credito2>=80 && $credito2<=84) {$bono2=13;}
									if($credito2>=85 && $credito2<=89) {$bono2=15;}
									if($credito2>=90 && $credito2<=94) {$bono2=18;}
									if($credito2>=95 && $credito2<=100){$bono2=20;}
									
									if($creditog11>=0 && $creditog11<=59)  {$bono3=0;}
									if($creditog11>=60 && $creditog11<=64) {$bono3=3;}
									if($creditog11>=65 && $creditog11<=69) {$bono3=5;}
									if($creditog11>=70 && $creditog11<=74) {$bono3=8;}
									if($creditog11>=75 && $creditog11<=79) {$bono3=10;}
									if($creditog11>=80 && $creditog11<=84) {$bono3=13;}
									if($creditog11>=85 && $creditog11<=89) {$bono3=15;}
									if($creditog11>=90 && $creditog11<=94) {$bono3=18;}
									if($creditog11>=95 && $creditog11<=100){$bono3=20;}

                                    $cuarenta_intermedio=round(($int_prof+$inter)/2)*0.4;
									$sesenta_parcial=round(($cuarenta_intermedio+round($diario*0.6))*0.6);
									$sesenta_global=round((($cuarenta_intermedio+round($diario*0.6))));
									//$sesenta_global=round(($cuarenta_intermedio+round($diario*0.6)+$bono2+$bono1)*0.6);
									$cuarenta_global=round(($final+$fin_prof)/2)*0.4;

									
									
									
									if($sesenta_global>100){$sesenta_global=100;}
									$total_60=round($sesenta_global)+round($bono2)+round($bono1);
									if($total_60>100){$total_60=100;}
									$nota_final_p=round(($total_60*0.6)+$cuarenta_global);
//$nota_final_p=($sesenta_global)+$cuarenta_global;									
                                                                       if($nota_final_p>100){$nota_final_p=100;}

/*
$cuarenta_intermedio=round(($int_prof+$inter)/2)*0.4;
									$sesenta_global=round(($cuarenta_intermedio+round($diario*0.6)+$bono2+$bono1)*0.6);
									$cuarenta_global=round(($final+$fin_prof)/2)*0.4;
									//$nota_final_p=($sesenta_global)+$cuarenta_global;
									
                                                                       if($sesenta_global>100){$sesenta_global=100;}
									$total_60=round($sesenta_global)+round($bono2)+round($bono1);
									if($total_60>100){$total_60=100;}
									$nota_final_p=round(($total_60*0.6)+$cuarenta_global);*/


									if($nota_final_p>=0 && $nota_final_p<=69){$concepto_p='BAJO';} 
									if($nota_final_p>=70 && $nota_final_p<=79){$concepto_p='BASICO';}
									if($nota_final_p>=80 && $nota_final_p<=94){$concepto_p='ALTO';}
									if($nota_final_p>=95 && $nota_final_p<=100){$concepto_p='SUPERIOR';}
									
									if($actual==1){$nota_p1=$nota_final_p;$acum_nota_final_per+=$nota_final_p ;$nota_min=140-$acum_nota_final_per;}
									if($actual==2){$nota_p2=$nota_final_p;$acum_nota_final_per+=$nota_final_p ;$nota_min=210-$acum_nota_final_per;}
									if($actual==3){$nota_p3=$nota_final_p;$acum_nota_final_per+=$nota_final_p ;}
									/*if($actual==4){$nota_p4=$nota_final_p;$acum_nota_final_per+=$nota_final_p ;}*/
									
 
//									if($cont==1){$color=212;$cont=2;}
//									elseif($cont==2){$color=242;$cont=1;}
									$cuarenta_intermedio=round(($int_prof+$inter)/2)*0.4;
									$sesenta_global=round(($cuarenta_intermedio+round($diario*0.6))*0.6);
									$cuarenta_global=round(round(($final+$fin_prof)/2)*0.4);

									if((round($acum_nota_final_per*0.3333)+$bono3)>100){$acum_gral=100;}
									else{$acum_gral=(round($acum_nota_final_per*0.3333)+$bono3);}
									if(round(round($acum_nota_final_per*0.3333)+round($bono3))>100){$nota_final=100;}
									else{$nota_final=round(round($acum_nota_final_per*0.3333)+round($bono3));}


									if($c==3||$c==6){$pdf->AddPage();}	

									$pdf->SetFont('Arial','b',7);
									//$pdf->SetDrawColor(212,86,86);
									
									$pdf->SetFillColor(212,212,212);
									$pdf->Cell(8,0.5,"ASIGNATURA",0,0,'C',true);
									$pdf->Cell(0.1,0.5,"",0,0,'C',FALSE);									
									$pdf->Cell(12.4,0.5,"CONCEPTOS",0,1,'C',true);									
									$pdf->Cell(20.5,0.1,"",0,1,'C',FALSE);
									
									$pdf->SetFont('Arial','b',9);
									$pdf->SetFillColor(242,242,242);
									$pdf->Cell(8,0.5," ".strtoupper($materia_pensum),0,0,'L',true);	
									$pdf->SetFont('Arial','b',7);
									$pdf->Cell(0.1,0.5,"",0,0,'C',FALSE);								
									$pdf->Cell(1.4,0.5," I.H. :",0,0,'R',true);$pdf->Cell(0.6,0.5,"".$intensidad,1,0,'C',FALSE);
									$pdf->Cell(1.5,0.5," AUS :",0,0,'R',true);$pdf->Cell(0.6,0.5,"".$num_faltas,1,0,'C',FALSE);																		
									$pdf->Cell(3.5,0.5," NOTA FINAL P1:",0,0,'L',true);$pdf->Cell(0.6,0.5,"".round($nota_p1),1,0,'R',false);
									$pdf->Cell(3,0.5," INDICADOR:",0,0,'L',true);$pdf->Cell(1.2,0.5,"".$concepto_p,0,1,'R',TRUE);
				
									$pdf->Cell(3,0.5," PROM. NOTAS 60%",0,0,'L',true);$pdf->Cell(1,0.5,"  ".round($diario),0,0,'R',false);
									$pdf->Cell(3,0.5," CREDITO 1 Y 2",0,0,'L',true);$pdf->Cell(1,0.5,"".$credito1." - ".$credito2."",1,0,'R',false);
									$pdf->Cell(0.1,0.5,"",0,0,'C',FALSE);								
//									$pdf->Cell(3.5,0.5," FINAL 60%:",0,0,'L',true);$pdf->Cell(0.6,0.5,"".round($sesenta_global),1,0,'R',false);
									$pdf->Cell(3.5,0.5," FINAL 60%:",0,0,'L',true);$pdf->Cell(0.6,0.5,"".round($total_60*0.6),1,0,'R',false);
									$pdf->Cell(3.5,0.5," NOTA FINAL P2:",0,0,'L',true);$pdf->Cell(0.6,0.5,"".round($nota_p2),1,0,'R',false);
									$pdf->Cell(3.5,0.5," ACUMULADO GRAL.",0,0,'L',true);$pdf->Cell(0.7,0.5,"".round($acum_nota_final_per*0.3333),1,1,'R',false);

									$pdf->Cell(3,0.5," PROC-INTERMEDIOS",0,0,'L',true);$pdf->Cell(1,0.5,"".round($inter),0,0,'R',false);
									$pdf->Cell(3,0.5," EXA. FINAL",0,0,'L',true);$pdf->Cell(1,0.5,"".round($final),1,0,'R',false);
									$pdf->Cell(0.1,0.5,"",0,0,'C',FALSE);								
									$pdf->Cell(3.5,0.5," FINAL 40%:",0,0,'L',true);$pdf->Cell(0.6,0.5,"".round($cuarenta_global),1,0,'R',false);
									$pdf->Cell(3.5,0.5," CREDITO G11:",0,0,'L',true);$pdf->Cell(0.6,0.5,"".$creditog11,1,0,'R',false);
									$pdf->Cell(3.5,0.5," NOTA FINAL P3:",0,0,'L',true);$pdf->Cell(0.6,0.5,"".round($nota_p3),1,0,'R',false);
									/*$pdf->Cell(3.5,0.5," N.M.PROX. PERIODO",0,0,'L',true);$pdf->Cell(0.7,0.5,"".round($nota_min),1,1,'R',false);*/
									$pdf->Cell(3.5,0.5," FINAL:",0,0,'L',true);$pdf->Cell(0.7,0.5,"".$nota_final,1,1,'R',false);

									$pdf->Cell(3,0.5," REC. o PROF.",0,0,'L',true);$pdf->Cell(1,0.5,"".round($int_prof),0,0,'R',false);
									$pdf->Cell(3,0.5," REC. o PROF.",0,0,'L',true);$pdf->Cell(1,0.5,"".round($fin_prof),1,0,'R',false);
									$pdf->Cell(0.1,0.5,"",0,0,'C',FALSE);								
									//$pdf->Cell(3.5,0.5," CREDITO G11:",0,0,'L',true);$pdf->Cell(0.6,0.5,"".$creditog11,1,0,'R',false);
									/*$pdf->Cell(3.5,0.5," NOTA FINAL P4:",0,0,'L',true);$pdf->Cell(0.6,0.5,"".round($nota_p4),1,0,'R',false);*/
									//$pdf->Cell(3.5,0.5," FINAL:",0,0,'L',true);$pdf->Cell(0.7,0.5,"".$nota_final,1,1,'R',false);

									
									//$pdf->Cell(20.5,0.1,"",0,1,'C',true);									
									//$pdf->Ln(0.3);

						/**************************************/
								$select_logro="
									select logros.descripcion 
									from logros,logros_estudiante 
									where logros.id=logros_estudiante.id_logro
									and logros_estudiante.id_estudiante=".$rs_sest[0]." 
									and logros.planilla=".$_POST['per2']." 
									and logros.pensum=".$rs_sel_pen[0]."
									order by logros.descripcion ";
									$res_select_logro=mysql_query($select_logro);
									$num_filas_log = mysql_num_rows($res_select_logro);	
									if($num_filas_log>0){	
										$pdf->Cell(9,0.5,"  LOGROS:",0,1,'L',false);
										while($rs_logro=mysql_fetch_array($res_select_logro)){
										
										$pdf->Cell(9,0.4,"  *  ".strtoupper(utf8_decode($rs_logro[0])),0,1,'L',false);
										
										}
										$pdf->Cell(9,0.2,"  ",0,1,'L',false);
									}
									
									$select_rec="select id,descripcion 
											from recomendacion 
											where pensum=".$rs_sel_pen[0]." 
											and id_estudiante='".$rs_sest[0]."' 
											and planilla='".$_POST['per2']."' ";
											
									$res_select_rec=mysql_query($select_rec);
									$filas=mysql_num_rows($res_select_rec);
									
									if($filas>0){
									$res=mysql_fetch_array($res_select_rec);
									$pdf->SetFillColor(255,255,255);
								        $pdf->Ln(0.1);
									$pdf->Cell(3,0.5,"  RECOMENDACIONES:  ",0,0,'L',false);
									$pdf->MultiCell(17.5,0.5," ".strtoupper(utf8_decode($res[1])),1,1,'L',false);	
									$pdf->Ln(0.1);
									
									
									}
						/**************************************/

								
								
								
								}
		}
	
	}	
	
$sel_estudiante="select nombre,usuario,clave from estudiante where estudiante_id=".$rs_sest[0]." ";

//echo $sel_estudiante."<br>";
$res_sel_estudiante=mysql_query($sel_estudiante);
$estudiante=mysql_fetch_array($res_sel_estudiante);


}
$pdf->Output("Informe_Periodo_Logros.pdf",'D');
}




	?>	