<?php

require_once '../../../../app/model/db.class.php';

class Con4 extends database
{
    function proceso($doc)
    {
      $sql='';
        $this->conectar();
        $resul=$this->consulta("select * from curso_asignatura_profesor where profesor='".$doc."';");

       
	   if($this->numero_de_filas($resul))
            {
               
                while ( $tsArray = $this->fetch_assoc($resul) )
                        {
                        $data[] = $tsArray;

                        }



//                print_r($data);

                if(mysql_num_rows($resul))
                {
                $f=0;
                $arr='';
                  for($i=0;$i<count($data);$i++)
                    {
                      
                        $resul=$this->consulta("select * from logros where grado='".$data[$i]['grado']."' and curso='".$data[$i]['curso']."' and asignatura='".$data[$i]['asignatura']."' order by periodo asc ");

                        //echo ("select * from logros where grado='".$data[$i]['grado']."' and curso='".$data[$i]['curso']."' and asignatura='".$data[$i]['asignatura']."' order by periodo asc ");

                        
                        while($row=$this->fetch_assoc($resul))
                        {
                            $c=0;


                            $arr[$f][$c]= $row['grado'];
                            $arr[$f][$c+1]= $this->name('grados',$row['grado']);
                            $arr[$f][$c+2]= $row['curso'];
                            $arr[$f][$c+3]= $this->name('cursos',$row['curso']);
                            $arr[$f][$c+4]=$row['asignatura'];
                            $arr[$f][$c+5]=$this->asignatura('catalogo',$row['asignatura']);
                            $arr[$f][$c+6]=$row['periodo'];
                            $arr[$f][$c+7]=$this->name('periodos',$row['periodo']);
                            $arr[$f][$c+8]=$row['codigo'];
                            $arr[$f][$c+9]=$row['descripcion'];
                            $arr[$f][$c+10]=$row['orden'];
                            $arr[$f][$c+11]=$row['orden1'];
                            $f++;
                        }
                        

                    }

                    $profenombre=$this->namepro('profesores',$data[0]['profesor']);
//                    print_r($arr);
                    $resul=$this->consulta("truncate table temp_con_logros");



                   for($i=0;$i<count($arr);$i++)
                    {
                       $sql="insert into temp_con_logros (cod_grad,grado,cod_cur,curso,cod_as,asignatura,cod_per,periodo,codigo,descripcion,orden,orden1) values(";
                       $r=0;
                        for($r=0;$r<12;$r++)
                        {

                           $sql.="'".$arr[$i][$r]."'";

                           if($r<11){
                               $sql.=",";
                           }

                        }
                        $sql.=");";

//                        echo $sql."<br>";
                        $resul=$this->consulta($sql);


                    }

                        //---------------------------------

                        $resul=$this->consulta("select * from temp_con_logros order by cod_grad asc,cod_cur asc, cod_per asc, orden1 asc");

                        //echo ("select * from logros where grado='".$data[$i]['grado']."' and curso='".$data[$i]['curso']."' and asignatura='".$data[$i]['asignatura']."' order by periodo asc ");
                        $f=0;
                        $row='';
                        while($row=$this->fetch_assoc($resul))
                        {
                            $c=0;


                            $arrinfo[$f][$c+1]= $row['grado'];
                            $arrinfo[$f][$c+2]= $row['curso'];
                            $arrinfo[$f][$c+3]=$row['asignatura'];
                            $arrinfo[$f][$c+4]=$row['periodo'];
                            $arrinfo[$f][$c+5]=$row['codigo'];
                            $arrinfo[$f][$c+6]=$row['descripcion'];
                            $arrinfo[$f][$c+7]=$row['orden'];
                            $arrinfo[$f][$c+8]=$row['orden1'];
                            $f++;
                        }
                    $resul=$this->consulta("truncate table temp_con_logros");

                    $arrinfo[][0]=$profenombre;

                    if(count($arrinfo)>1){
                        return $arrinfo;
                    }else{
                        return 'no';
                    }

                }else{

                }
        }else{
            return 'no';
        }
	
    }
    
    function name($tabla,$cod){
         $result=$this->consulta("select * from ".$tabla." where codigo='".$cod."';");
         $rs=$this->fetch_assoc($result);
         return $rs['descripcion']; 
    }


    function namepro($tabla,$cod){
         $result=$this->consulta("select * from ".$tabla." where cedula='".$cod."';");
         $rs=$this->fetch_assoc($result);
         return $rs['nombres'];
    }

       function asignatura($tabla,$cod){
         $result=$this->consulta("select * from ".$tabla." where codigo='".$cod."';");
         $rs=$this->fetch_assoc($result);
         return $rs['nombrecorto'];
    }
}
/*
$ob=new Con4();
$arr=$obj->proceso($_REQUEST['docente']);
$obj->disconnect();


 for($i=0;$i<count($arr);$i++)
{
    for($c=0;$c<8;$c++)
    {
       echo $arr[$i][$c]." -- ";

    }
    echo "<br>";


}*/
?>