<?php

class Educador {

    private $db;
    public function __construct()
    {
        $this->db = new Database;
    }

    public function EducaById($id){
    //$this->db->startTransaction();
    $this->db->query('SELECT * FROM profesores WHERE email = :id');
    $this->db->bind(':id', $id);

    $row = $this->db->single();
    if($this->db->rowCount()==0){
    return false;
    }else{
    return $row;
    }
    }

    public function EducaPrg($curso){
    $this->db->query('SELECT cursos.codigo,cursos.programa, programas.descripcion FROM cursos INNER JOIN programas ON cursos.programa = programas.codigo
    WHERE cursos.codigo= :curso');
    $this->db->bind(':curso', $curso);
    $row = $this->db->single();
    return $row;
    }

    public function EducaCursos($ced){
//    $this->db->query('SELECT tecnicas.descripcion, tecnicas.horas, eval_mes.tecnica, eval_mes.horas_acu, eval_mes.id, eval_mes.codigo, eval_mes.estatus
//    FROM (eval_mes INNER JOIN tecnicas ON eval_mes.tecnica = tecnicas.id) INNER JOIN profesores ON eval_mes.cedula = profesores.cedula
//    WHERE eval_mes.cedula= :ced  ORDER BY tecnicas.descripcion');
    $this->db->query('SELECT tecnicas.descripcion, tecnicas.horas, eval_mes.tecnica, eval_mes.horas_acu, eval_mes.id, eval_mes.codigo, eval_mes.estatus
FROM ((eval_mes INNER JOIN tecnicas ON eval_mes.tecnica = tecnicas.id) INNER JOIN profesores ON eval_mes.cedula = profesores.cedula) INNER JOIN cursos ON eval_mes.codigo = cursos.codigo
WHERE (((eval_mes.cedula)=:ced)) ORDER BY tecnicas.descripcion');

    $this->db->bind(':ced', $ced);
    $result = $this->db->resultSet();
    return $result;
    }

    public function EducaEval($id){
    $this->db->query('SELECT * FROM eval_control WHERE id= :id order by ano,mes');
    $this->db->bind(':id', $id);
    $result = $this->db->resultSet();
    //$this->db->fintrans();
    return $result;
    }

    public function EducaTecnica($idtec){
    $this->db->query('SELECT * FROM tecnicas WHERE id= :id');
    $this->db->bind(':id', $idtec);
    $result = $this->db->single();
    return $result;
    }

    public function EducaMes($id){
    //$this->db->query('SELECT * FROM eval_mes WHERE id= :id');
    $this->db->query('SELECT eval_mes.*,tecnicas.descripcion
    FROM (eval_mes INNER JOIN tecnicas ON eval_mes.tecnica = tecnicas.id) WHERE eval_mes.id= :id');
    $this->db->bind(':id', $id);
    $result = $this->db->single();
    return $result;
    }

    public function EducatecMes($ced,$id){
    $this->db->query('SELECT eval_mes.*,tecnicas.descripcion
    FROM (eval_mes INNER JOIN tecnicas ON eval_mes.tecnica = tecnicas.id) WHERE eval_mes.cedula= :ced and eval_mes.id= :id');
    $this->db->bind(':id', $id);
    $this->db->bind(':ced', $ced);
    $result = $this->db->single();
    return $result;
    }

    public function EducaControl($id){
    $this->db->query('SELECT eval_control.id, eval_control.mes,eval_control.carga_mes,eval_control.horas_mes,eval_control.ano, eval_mes.codigo, eval_mes.tecnica, eval_control.idd,eval_mes.cedula
    FROM eval_control INNER JOIN eval_mes ON eval_control.id = eval_mes.id WHERE (((eval_control.idd)= :id))');
    $this->db->bind(':id', $id);
    $result = $this->db->single();
    return $result;
    }

    public function EducaAlum($curso){
//    $this->db->query('SELECT alumnos.cedula, alumnos.apellidos, alumnos.nombres,alumnos.tag1,alumnos.sexo
//    FROM alumnos WHERE alumnos.curso= :curso ORDER BY alumnos.apellidos, alumnos.nombres');

    $this->db->query('SELECT alumnos.cedula, alumnos.apellidos, alumnos.nombres, alumnos.sexo, alumnos.tag1, empresas.razon, alumnos.curso
    FROM alumnos INNER JOIN empresas ON alumnos.empresa = empresas.codigo
    WHERE alumnos.curso= :curso ORDER BY alumnos.apellidos, alumnos.nombres');
    $this->db->bind(':curso', $curso);
    $result = $this->db->resultSet();
    return $result;
    }

    public function EducaBusAsistencia($cur,$tec,$mes,$anho){
    $this->db->query('select * from asistencia where codigo= :cur and tecnica= :tec and mes= :mes and ano= :anho');
    $this->db->bind(':cur', $cur);
    $this->db->bind(':tec', $tec);
    $this->db->bind(':mes', $mes);
    $this->db->bind(':anho', $anho);
    $result = $this->db->resultSet();
    return $this->db->rowCount();
    }

    public function EducaEditAsistencia($cur,$tec,$mes,$anho){
    $this->db->query('SELECT alumnos.cedula, alumnos.apellidos, alumnos.nombres, alumnos.tag1, asistencia.*
    FROM asistencia INNER JOIN alumnos ON asistencia.cedula = alumnos.cedula
    WHERE (((asistencia.codigo)= :cur) AND ((asistencia.tecnica)= :tec) AND ((asistencia.mes)= :mes) AND ((asistencia.ano)= :anho))');
    $this->db->bind(':cur', $cur);
    $this->db->bind(':tec', $tec);
    $this->db->bind(':mes', $mes);
    $this->db->bind(':anho', $anho);
    $result = $this->db->resultSet();
    return $result;
    }
    public function EducaRec($tec,$mes,$anho){
    $this->db->query('select * from eval_nota_nt where tecnica= :tec and mes= :mes and ano= :anho order by cedula');
    $this->db->bind(':tec', $tec);
    $this->db->bind(':mes', $mes);
    $this->db->bind(':anho', $anho);
    $result = $this->db->resultSet();
    return $result;
    }

    public function EducaVerNotas($id){
    $eval_control = $this->EducaControl($id);
    $ceds=$eval_control->codigo;
    $tec=$eval_control->tecnica;
    $mes=$eval_control->mes;
    $anho=$eval_control->ano;
    $eval_alumnos = $this->EducaAlum($ceds);
    $eval_notas = $this->EducaRec($tec,$mes,$anho);

   // var_dump($eval_notas);
   // exit;
    $alum_nt=[];
    foreach ($eval_alumnos as $p){
        $sw=0;
        foreach ($eval_notas as $nt){
            if($p->cedula==$nt->cedula and $tec==$nt->tecnica and $mes==$nt->mes and $anho==$nt->ano){
            $alum_nt[] = array(
            'cedula' => $p->cedula,
            'apellidos' => $p->apellidos,
            'nombres' => $p->nombres,
            'tag1' => $p->tag1,
            'nt1' => $nt->nt1,
            'nt2' => $nt->nt2,
            'nt3' => $nt->nt3,
            'nt4' => $nt->nt4,
            'nt5' => $nt->nt5,
            'ntf' => $nt->ntf,
            );
            $sw=1;
            break;
            }
        }
            if($sw==0){
            $alum_nt[] = array(
            'cedula' => $p->cedula,
            'apellidos' => $p->apellidos,
            'nombres' => $p->nombres,
            'tag1' => $p->tag1,
            'nt1' => 0,
            'nt2' => 0,
            'nt3' => 0,
            'nt4' => 0,
            'nt5' => 0,
            'ntf' => 0,
            );
            }
    }

    return $alum_nt;
    } //


    public function EducaCountEval($id){
        $this->db->query('select * from eval_nota_ev where id_control= :id ');
        $this->db->bind(':id', $id);
        $result = $this->db->resultSet();
        //check the row

        return $this->db->rowCount();
    }

    public function EducaRegEval($id){
        $this->db->query('select * from eval_nota_ev where id_control= :id ');
        $this->db->bind(':id', $id);
        $result = $this->db->resultSet();
        return $result;
    }
    public function EducaConNt($cednt,$tecnt,$anont,$mesnt){
        $this->db->query('select * from eval_nota_nt where cedula= :cednt and tecnica= :tecnt and ano= :anont and mes= :mesnt');
        $this->db->bind(':cednt', $cednt);
        $this->db->bind(':tecnt', $tecnt);
        $this->db->bind(':anont', $anont);
        $this->db->bind(':mesnt', $mesnt);
        $result = $this->db->single();
        //check the row
        //return $this->db->rowCount();

        if(empty($result)){
        return false;
        }else{
        return $result;
        }
    }

    public function EducaActNt($cednt,$tecnt,$anont,$mesnt,$nttnt,$carnt,$curnt,$evalnt){
        if($evalnt==1){
        $this->db->query('update eval_nota_nt set nt1= :nttnt,codigo= :curnt,carga_mes= :carnt
         where cedula= :cednt and tecnica= :tecnt and ano= :anont and mes= :mesnt');
        }elseif($evalnt==2){
        $this->db->query('update eval_nota_nt set nt2= :nttnt,codigo= :curnt,carga_mes= :carnt
         where cedula= :cednt and tecnica= :tecnt and ano= :anont and mes= :mesnt');
        }elseif($evalnt==3){
        $this->db->query('update eval_nota_nt set nt3= :nttnt,codigo= :curnt,carga_mes= :carnt
         where cedula= :cednt and tecnica= :tecnt and ano= :anont and mes= :mesnt');
        }elseif($evalnt==4){
        $this->db->query('update eval_nota_nt set nt4= :nttnt,codigo= :curnt,carga_mes= :carnt
         where cedula= :cednt and tecnica= :tecnt and ano= :anont and mes= :mesnt');
        }elseif($evalnt==5){
        $this->db->query('update eval_nota_nt set nt5= :nttnt,codigo= :curnt,carga_mes= :carnt
         where cedula= :cednt and tecnica= :tecnt and ano= :anont and mes= :mesnt');
        }

        $this->db->bind(':cednt', $cednt);
        $this->db->bind(':tecnt', $tecnt);
        $this->db->bind(':anont', $anont);
        $this->db->bind(':mesnt', $mesnt);
        $this->db->bind(':nttnt', $nttnt);
        $this->db->bind(':carnt', $carnt);
        $this->db->bind(':curnt', $curnt);
        if($this->db->execute()){
        return true;
        }else{
        return false;
        }
    }

    public function EducaInsNt($cednt,$tecnt,$anont,$mesnt,$nttnt,$carnt,$curnt,$evalnt,$idnt){
        if($evalnt==1){
        $this->db->query('insert into eval_nota_nt(id_control,codigo,cedula,tecnica,ano,mes,carga_mes,nt1,ntf)
        values (:idnt, :curnt, :cednt, :tecnt, :anont, :mesnt, :carnt, :nttnt, :nttnt)');
        }elseif($evalnt==2){
        $this->db->query('insert into eval_nota_nt(id_control,codigo,cedula,tecnica,ano,mes,carga_mes,nt2,ntf)
        values (:idnt, :curnt, :cednt, :tecnt, :anont, :mesnt, :carnt, :nttnt, :nttnt)');
        }elseif($evalnt==3){
        $this->db->query('insert into eval_nota_nt(id_control,codigo,cedula,tecnica,ano,mes,carga_mes,nt3,ntf)
        values (:idnt, :curnt, :cednt, :tecnt, :anont, :mesnt, :carnt, :nttnt, :nttnt)');
        }elseif($evalnt==4){
        $this->db->query('insert into eval_nota_nt(id_control,codigo,cedula,tecnica,ano,mes,carga_mes,nt4,ntf)
        values (:idnt, :curnt, :cednt, :tecnt, :anont, :mesnt, :carnt, :nttnt, :nttnt)');
        }elseif($evalnt==5){
        $this->db->query('insert into eval_nota_nt(id_control,codigo,cedula,tecnica,ano,mes,carga_mes,nt5,ntf)
        values (:idnt, :curnt, :cednt, :tecnt, :anont, :mesnt, :carnt, :nttnt, :nttnt)');
        }
        $this->db->bind(':idnt', $idnt);
        $this->db->bind(':cednt', $cednt);
        $this->db->bind(':tecnt', $tecnt);
        $this->db->bind(':anont', $anont);
        $this->db->bind(':mesnt', $mesnt);
        $this->db->bind(':nttnt', $nttnt);
        $this->db->bind(':carnt', $carnt);
        $this->db->bind(':curnt', $curnt);
        $this->db->execute();
//        $this->db->debugDumpParams();
/*        if($this->db->execute()){
        return true;
        }else{
        return false;
        }*/

    }

    public function EducaProNt($cednt,$idnt,$evalnt){
        if($evalnt==1){
        $this->db->query('update eval_nota_nt set ntf=nt1,ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_control= :idnt and cedula= :cednt');
        }elseif($evalnt==2){
        $this->db->query('update eval_nota_nt set ntf=(nt1+nt2)/2,ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_control= :idnt and cedula= :cednt');
        }elseif($evalnt==3){
        $this->db->query('update eval_nota_nt set ntf=(nt1+nt2+nt3)/3,ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_control= :idnt and cedula= :cednt');
        }elseif($evalnt==4){
        $this->db->query('update eval_nota_nt set ntf=(nt1+nt2+nt3+nt4)/4,ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_control= :idnt and cedula= :cednt');
        }elseif($evalnt==5){
        $this->db->query('update eval_nota_nt set ntf=(nt1+nt2+nt3+nt4+nt5)/5,ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_control= :idnt and cedula= :cednt');
        }

        $this->db->bind(':cednt', $cednt);
        $this->db->bind(':idnt', $idnt);
        if($this->db->execute()){
        return true;
        }else{
        return false;
        }
    }

    public function EducaAntNt($cednt,$tecnt,$mesantes,$anoantes){
        $this->db->query('select cedula,ntantes,ntf from eval_nota_nt where cedula= :cednt and tecnica= :tecnt and mes= :mesantes and ano= :anoantes');
        $this->db->bind(':cednt', $cednt);
        $this->db->bind(':tecnt', $tecnt);
        $this->db->bind(':mesantes', $mesantes);
        $this->db->bind(':anoantes', $anoantes);
        $result = $this->db->single();
        return $result;
    }

    public function EducaAhoNt($cednt,$tecnt,$mesnt,$anont){
        $this->db->query('select cedula,ntantes,ntf,ntfact from eval_nota_nt where cedula= :cednt and tecnica= :tecnt and mes= :mesnt and ano= :anont');
        $this->db->bind(':cednt', $cednt);
        $this->db->bind(':tecnt', $tecnt);
        $this->db->bind(':anont', $anont);
        $this->db->bind(':mesnt', $mesnt);
        $result = $this->db->single();
        return $result;
    }

public function EducaActitudinalGuardar($data){
//[no_id] => 5862 [no_tec] => 92 [no_cur] => AEI1801 [carga] => Mensual [mes] => 05 [anho] => 2019
//$sqlx1="delete from asistencia where codigo='".$cod."' and tecnica=".$tec." and mes='".$mes."' and ano='".$ano."'";
//$this->db->beginTransaction();
//var_dump($data);
$cod=$data['no_cur'];
$tec=$data['no_tec'];
$mes=$data['mes'];
$ano=$data['anho'];

    $this->db->query('delete from actitudinales where codigo= :cod and tecnica= :tec and mes= :mes and ano= :ano');
    $this->db->bind(':cod', $cod);
    $this->db->bind(':tec', $tec);
    $this->db->bind(':mes', $mes);
    $this->db->bind(':ano', $ano);
    $this->db->execute();

$t_asis=0;
$t_inas=0;
$t_just=0;

$t_aste=$data['hrs'];

$this->db->query('insert into actitudinales(cedula,codigo,tecnica,mes,ano,d1,d2,d3,d4,d5,d6,d7,d8,d9)
 values (:ced, :cod, :tec, :mes, :ano, :d1, :d2, :d3, :d4, :d5, :d6, :d7, :d8, :d9)');

    foreach ($data['d1'] as $key =>$ced){
    //    var_dump($key);
    $cedx=$key;
    $var=[];
        for ($i = 0; $i <=8; $i++) {
        $dia=$data['d1'][$key][$i];
        $var[]= strtoupper($dia);
//                if($dia>=0 and $dia<=20){
//                }else{
//                $this->db->rollback();
//                return false;
//                }
        }
    $t_inas=$t_aste-$t_asis;
    $this->db->bind(':ced', $cedx);
    $this->db->bind(':cod', $cod);
    $this->db->bind(':tec', $tec);
    $this->db->bind(':mes', $mes);
    $this->db->bind(':ano', $ano);
    $this->db->bind(':d1', $var[0]);
    $this->db->bind(':d2', $var[1]);
    $this->db->bind(':d3', $var[2]);
    $this->db->bind(':d4', $var[3]);
    $this->db->bind(':d5', $var[4]);
    $this->db->bind(':d6', $var[5]);
    $this->db->bind(':d7', $var[6]);
    $this->db->bind(':d8', $var[7]);
    $this->db->bind(':d9', $var[8]);
    $this->db->execute();
    }
//$this->db->commit();
}

    public function EducaActitudinalEdit($cur,$tec,$mes,$anho){
    $this->db->query('SELECT alumnos.cedula, alumnos.apellidos, alumnos.nombres, alumnos.tag1, actitudinales.*
    FROM actitudinales INNER JOIN alumnos ON actitudinales.cedula = alumnos.cedula
    WHERE (((actitudinales.codigo)= :cur) AND ((actitudinales.tecnica)= :tec) AND ((actitudinales.mes)= :mes) AND ((actitudinales.ano)= :anho))');
    $this->db->bind(':cur', $cur);
    $this->db->bind(':tec', $tec);
    $this->db->bind(':mes', $mes);
    $this->db->bind(':anho', $anho);
    $result = $this->db->resultSet();
    return $result;
    }

    public function EducaActitudinalBus($cur,$tec,$mes,$anho){
    $this->db->query('select * from actitudinales where codigo= :cur and tecnica= :tec and mes= :mes and ano= :anho');
    $this->db->bind(':cur', $cur);
    $this->db->bind(':tec', $tec);
    $this->db->bind(':mes', $mes);
    $this->db->bind(':anho', $anho);
    $result = $this->db->resultSet();
    //return $result;
    return $this->db->rowCount();
    }

public function EducaGuardarAsist($data){
//[no_id] => 5862 [no_tec] => 92 [no_cur] => AEI1801 [carga] => Mensual [mes] => 05 [anho] => 2019
//$sqlx1="delete from asistencia where codigo='".$cod."' and tecnica=".$tec." and mes='".$mes."' and ano='".$ano."'";

$cod=$data['no_cur'];
$tec=$data['no_tec'];
$mes=$data['mes'];
$ano=$data['anho'];

    $this->db->query('delete from asistencia where codigo= :cod and tecnica= :tec and mes= :mes and ano= :ano');
    $this->db->bind(':cod', $cod);
    $this->db->bind(':tec', $tec);
    $this->db->bind(':mes', $mes);
    $this->db->bind(':ano', $ano);
    $this->db->execute();

$t_asis=0;
$t_inas=0;
$t_just=0;

$t_aste=$data['hrs'];

$this->db->query('insert into asistencia(cedula,codigo,tecnica,mes,ano,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14,d15,d16,d17,d18,d19,d20,d21,d22,d23,d24,d25,d26,d27,d28,d29,d30,d31,asistencia,inasistencia,justificada,asistencias)
values (:ced, :cod, :tec, :mes, :ano, :d1, :d2, :d3, :d4, :d5, :d6, :d7, :d8, :d9, :d10, :d11, :d12, :d13, :d14, :d15, :d16, :d17, :d18, :d19, :d20, :d21, :d22, :d23, :d24, :d25, :d26, :d27, :d28, :d29, :d30, :d31, :t_asis, :t_inas, :t_just, :t_aste)');

foreach ($data['d1'] as $key =>$ced){
    $cedx=$key;
    $var=[];
    for ($i = 0; $i <=30; $i++) {
    $jj=$i+1;
    $j=':d'.$jj;
    $dia=$data['d1'][$key][$i];

    $var[]= strtoupper($dia);

    //echo $j.'>>'.$dia;
        if(is_numeric($dia)){
        $t_asis=$t_asis+$dia;
        }
        //elseif($dia=="I"){
        //echo $leyenda[$t]." - ".$t;
        //$t_inas++;
        //}elseif($dia=="J"){
        //$t_just++;
        //$t_aste++;
        //}
    }
    $t_inas=$t_aste-$t_asis;
    $this->db->bind(':ced', $cedx);
    $this->db->bind(':cod', $cod);
    $this->db->bind(':tec', $tec);
    $this->db->bind(':mes', $mes);
    $this->db->bind(':ano', $ano);
    $this->db->bind(':d1', $var[0]);
    $this->db->bind(':d2', $var[1]);
    $this->db->bind(':d3', $var[2]);
    $this->db->bind(':d4', $var[3]);
    $this->db->bind(':d5', $var[4]);
    $this->db->bind(':d6', $var[5]);
    $this->db->bind(':d7', $var[6]);
    $this->db->bind(':d8', $var[7]);
    $this->db->bind(':d9', $var[8]);
    $this->db->bind(':d10', $var[9]);
    $this->db->bind(':d11', $var[10]);
    $this->db->bind(':d12', $var[11]);
    $this->db->bind(':d13', $var[12]);
    $this->db->bind(':d14', $var[13]);
    $this->db->bind(':d15', $var[14]);
    $this->db->bind(':d16', $var[15]);
    $this->db->bind(':d17', $var[16]);
    $this->db->bind(':d18', $var[17]);
    $this->db->bind(':d19', $var[18]);
    $this->db->bind(':d20', $var[19]);
    $this->db->bind(':d21', $var[20]);
    $this->db->bind(':d22', $var[21]);
    $this->db->bind(':d23', $var[22]);
    $this->db->bind(':d24', $var[23]);
    $this->db->bind(':d25', $var[24]);
    $this->db->bind(':d26', $var[25]);
    $this->db->bind(':d27', $var[26]);
    $this->db->bind(':d28', $var[27]);
    $this->db->bind(':d29', $var[28]);
    $this->db->bind(':d30', $var[29]);
    $this->db->bind(':d31', $var[30]);
    $this->db->bind(':t_asis', $t_asis);
    $this->db->bind(':t_inas', $t_inas);
    $this->db->bind(':t_just', $t_just);
    $this->db->bind(':t_aste', $t_aste);
    $this->db->execute();
}
}


public function EducaGuardarEval($data){

//var_dump($data);
//exit;
    //$this->db->beginTransaction0();

        $this->db->query('select * from eval_nota_ev where id_control= :id_control and nro= :nro');
        $this->db->bind(':id_control', $data['no_id']);
        $this->db->bind(':nro', $data['no_eval']);
        if($this->db->single()){
        $sw=1;
        }else{
        $sw=0;
        }

        if($sw==0){
        $this->db->query('INSERT INTO eval_nota_ev(id_control,nro,fecha,porcentaje,objetivo,objetivo2,estatus)
        VALUES (:id_control, :nro, :fecha, :porcentaje, :objetivo,:objetivo2, :estatus)');
        $this->db->bind(':id_control', $data['no_id']);
        $this->db->bind(':nro', $data['no_eval']);
        $this->db->bind(':fecha', $data['fecha']);
        $this->db->bind(':porcentaje', 0);
        $this->db->bind(':objetivo', $data['obj']);
        $this->db->bind(':objetivo2', $data['obj2']);
        $this->db->bind(':estatus', 'A');
        if($this->db->execute()){
        //return true;
        }else{
        //return false;
        }

        }else{
        $this->db->query('UPDATE eval_nota_ev SET fecha= :fecha,objetivo= :objetivo,objetivo2= :objetivo2 where id_control= :id_control and nro= :nro');
        $this->db->bind(':id_control', $data['no_id']);
        $this->db->bind(':nro', $data['no_eval']);
        $this->db->bind(':fecha', $data['fecha']);
        $this->db->bind(':objetivo', $data['obj']);
        $this->db->bind(':objetivo2', $data['obj2']);
        $this->db->execute();
        }


    $nt=$data['eval_ntt'];

    $car_nt =$data['carga'];
    $mes_nt =$data['mes'];
    $anho_nt=$data['anho'];

        if($mes_nt==1){
        $mes_antes=12;
        $ano_antes=$anho_nt-1;
        }else{
        $mes_antes=str_pad($mes_nt-1, 2, "0", STR_PAD_LEFT);
        $ano_antes=$anho_nt;
        }

    $id_nt=$data['no_id'];
    $tec_nt=$data['no_tec'];
    $eval_nt=$data['no_eval'];
    $cur_nt=$data['no_cur'];

    foreach ($data['eval_ced'] as $key =>$ced){
    $ced_nt=$ced;
    $ntt_nt=$nt[$key];
    if(trim($ntt_nt)==0){
    $ntt_nt=0;
    }else{
    $ntt_nt=$nt[$key];
    }

    $reg=$this->EducaConNt($ced_nt,$tec_nt,$anho_nt,$mes_nt);

        if($reg==false){
//        $this->EducaInsNt($ced_nt,$tec_nt,$anho_nt,$mes_nt,$ntt_nt,$car_nt,$cur_nt,$eval_nt,$id_nt);

        $datain[] = [
        'nt_ced' =>$ced_nt,
        'nt_tec' =>$tec_nt,
        'nt_ano' =>$anho_nt,
        'nt_mes' =>$mes_nt,
        'nt_car' =>$car_nt,
        'nt_cur' =>$cur_nt,
        'nt_ntt' =>$ntt_nt,
        'nt_idc' =>$id_nt,
        ];

        }else{

        $datant[] = [
        'nt_idd' =>$reg->id_nt,
        'nt_tec' =>$tec_nt,
        'nt_car' =>$car_nt,
        'nt_cur' =>$cur_nt,
        'nt_ntt' =>$ntt_nt,
        'nt_idc' =>$id_nt,
        ];
//        $this->EducaActNt($ced_nt,$tec_nt,$anho_nt,$mes_nt,$ntt_nt,$car_nt,$cur_nt,$eval_nt);
        }
//    $this->EducaProNt($ced_nt,$id_nt,$eval_nt);
    }

//var_dump($datant);
//exit;
if(!empty($datant)){
        if($eval_nt==1){
        $this->db->query('update eval_nota_nt set id_control= :idnt,nt1= :nttnt,codigo= :curnt,carga_mes= :carnt
         where id_nt= :iddnt');
        }elseif($eval_nt==2){
        $this->db->query('update eval_nota_nt set id_control= :idnt,nt2= :nttnt,codigo= :curnt,carga_mes= :carnt
         where id_nt= :iddnt');
        }elseif($eval_nt==3){
        $this->db->query('update eval_nota_nt set id_control= :idnt,nt3= :nttnt,codigo= :curnt,carga_mes= :carnt
         where id_nt= :iddnt');
        }elseif($eval_nt==4){
        $this->db->query('update eval_nota_nt set id_control= :idnt,nt4= :nttnt,codigo= :curnt,carga_mes= :carnt
         where id_nt= :iddnt');
        }elseif($eval_nt==5){
        $this->db->query('update eval_nota_nt set id_control= :idnt,nt5= :nttnt,codigo= :curnt,carga_mes= :carnt
         where id_nt= :iddnt');
        }
foreach($datant as $dato){
        $this->db->bind(':idnt', $dato['nt_idc']);
        $this->db->bind(':iddnt', $dato['nt_idd']);
        $this->db->bind(':nttnt', $dato['nt_ntt']);
        $this->db->bind(':carnt', $dato['nt_car']);
        $this->db->bind(':curnt', $dato['nt_cur']);
        $this->db->execute();
}
}

if(!empty($datain)){
        if($eval_nt==1){
        $this->db->query('insert into eval_nota_nt(id_control,codigo,cedula,tecnica,ano,mes,carga_mes,nt1,ntf)
        values (:idnt, :curnt, :cednt, :tecnt, :anont, :mesnt, :carnt, :nttnt, :nttnt)');
        }elseif($eval_nt==2){
        $this->db->query('insert into eval_nota_nt(id_control,codigo,cedula,tecnica,ano,mes,carga_mes,nt2,ntf)
        values (:idnt, :curnt, :cednt, :tecnt, :anont, :mesnt, :carnt, :nttnt, :nttnt)');
        }elseif($eval_nt==3){
        $this->db->query('insert into eval_nota_nt(id_control,codigo,cedula,tecnica,ano,mes,carga_mes,nt3,ntf)
        values (:idnt, :curnt, :cednt, :tecnt, :anont, :mesnt, :carnt, :nttnt, :nttnt)');
        }elseif($eval_nt==4){
        $this->db->query('insert into eval_nota_nt(id_control,codigo,cedula,tecnica,ano,mes,carga_mes,nt4,ntf)
        values (:idnt, :curnt, :cednt, :tecnt, :anont, :mesnt, :carnt, :nttnt, :nttnt)');
        }elseif($eval_nt==5){
        $this->db->query('insert into eval_nota_nt(id_control,codigo,cedula,tecnica,ano,mes,carga_mes,nt5,ntf)
        values (:idnt, :curnt, :cednt, :tecnt, :anont, :mesnt, :carnt, :nttnt, :nttnt)');
        }

foreach($datain as $dato){
        $this->db->bind(':idnt', $dato['nt_idc']);
        $this->db->bind(':cednt', $dato['nt_ced']);
        $this->db->bind(':tecnt', $dato['nt_tec']);
        $this->db->bind(':anont', $dato['nt_ano']);
        $this->db->bind(':mesnt', $dato['nt_mes']);
        $this->db->bind(':nttnt', $dato['nt_ntt']);
        $this->db->bind(':carnt', $dato['nt_car']);
        $this->db->bind(':curnt', $dato['nt_cur']);
        $this->db->execute();
}}



if(!empty($datant)){
//$this->db->query('update eval_nota_nt set ntf=round((nt1+nt2+nt3+nt4+nt5)),ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_nt= :iddnt');

        if($eval_nt==1){
        $this->db->query('update eval_nota_nt set ntf=nt1,ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_nt= :iddnt');
        }elseif($eval_nt==2){
        $this->db->query('update eval_nota_nt set ntf=round((nt1+nt2)/2),ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_nt= :iddnt');
        }elseif($eval_nt==3){
        $this->db->query('update eval_nota_nt set ntf=round((nt1+nt2+nt3)/3),ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_nt= :iddnt');
        }elseif($eval_nt==4){
        $this->db->query('update eval_nota_nt set ntf=round((nt1+nt2+nt3+nt4)/4),ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_nt= :iddnt');
        }elseif($eval_nt==5){
        $this->db->query('update eval_nota_nt set ntf=round((nt1+nt2+nt3+nt4+nt5)/5),ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_nt= :iddnt');
        }

foreach($datant as $dato){
    $this->db->bind(':iddnt', $dato['nt_idd']);
    $this->db->execute();
}
}

if(!empty($datain)){
//$this->db->query('update eval_nota_nt set ntf=round((nt1+nt2+nt3+nt4+nt5)),ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_control= :idnt and cedula= :cednt');

        if($eval_nt==1){
        $this->db->query('update eval_nota_nt set ntf=nt1,ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_control= :idnt and cedula= :cednt');
        }elseif($eval_nt==2){
        $this->db->query('update eval_nota_nt set ntf=round((nt1+nt2)/2),ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_control= :idnt and cedula= :cednt');
        }elseif($eval_nt==3){
        $this->db->query('update eval_nota_nt set ntf=round((nt1+nt2+nt3)/3),ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_control= :idnt and cedula= :cednt');
        }elseif($eval_nt==4){
        $this->db->query('update eval_nota_nt set ntf=round((nt1+nt2+nt3+nt4)/4),ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_control= :idnt and cedula= :cednt');
        }elseif($eval_nt==5){
        $this->db->query('update eval_nota_nt set ntf=round((nt1+nt2+nt3+nt4+nt5)/5),ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_control= :idnt and cedula= :cednt');
        }

foreach($datain as $dato){
    $this->db->bind(':idnt', $dato['nt_idc']);
    $this->db->bind(':cednt', $dato['nt_ced']);
    $this->db->execute();
}
}

$porc_ev=70;
$porc_ac=30;

    $nn=0;
    foreach ($data['eval_ced'] as $key =>$ced){
    $ced_nt=$ced;
    //echo $ced_nt.','.$tec_nt.','.$mes_antes.','.$ano_antes.'<br>';
    //$nn++;
    $QryAntes=$this->EducaAntNt($ced_nt,$tec_nt,$mes_antes,$ano_antes);
    if($QryAntes){
    $QryCed=$QryAntes->cedula;
    $QryNot=$QryAntes->ntantes;
    $sw_an="S";
    }else{
    $QryCed=$ced_nt;
    $QryNot=0;
    $sw_an="N";
    }
        $reg_antes[] = array(
        'ced_antes' => $QryCed,
        'not_antes' => $QryNot,
        'sw_an' => $sw_an,
        );
    }
    $ntfinal=0;$ntmes=0;

    foreach ($data['eval_ced'] as $key =>$ced){
    $ced_nt=$ced;
    $QryAhora=$this->EducaAhoNt($ced_nt,$tec_nt,$mes_nt,$anho_nt);
            if($QryAhora){
            $QryCedA=$QryAhora->cedula;
            $QryNotFin=$QryAhora->ntf;
            $QryNotAct=$QryAhora->ntfact;

                $nteval=$QryNotFin;
                $ntap1=$nteval*($porc_ev/100);
                $ntact=$QryNotAct;
                $ntap2=$ntact*($porc_ac/100);
                $ntmes=intval($ntap1+$ntap2);

            }else{
            $QryCedA=$ced_nt;
            $QryNotFin=0;
            $QryNotAct=0;
            $nteval=0;
            }

            $clave = array_search($ced_nt, $reg_antes);
            $ntms_an=$reg_antes[$clave]['not_antes'];
            $sw_an=  $reg_antes[$clave]['sw_an'];

            if($sw_an=="N"){
            $ntms_an=$nteval;
            }

            $ntfinal=intval((($ntmes+$ntms_an)/2)+.5);

        $this->db->query('update eval_nota_nt set ntpor1= :porc_ev,ntap1= :ntap1,ntpor2= :porc_ac,ntap2= :ntap2,ntmes= :ntmes,ntantes= :ntmes,ntfinal= :ntmes where cedula= :cednt and tecnica= :tec_nt and mes= :mes_nt and ano= :anho_nt');
        $this->db->bind(':porc_ev', $porc_ev);
        $this->db->bind(':ntap1', $ntap1);
        $this->db->bind(':porc_ac', $porc_ac);
        $this->db->bind(':ntap2', $ntap2);
        $this->db->bind(':ntmes', $ntmes);
        $this->db->bind(':cednt', $ced_nt);
        $this->db->bind(':tec_nt', $tec_nt);
        $this->db->bind(':mes_nt', $mes_nt);
        $this->db->bind(':anho_nt', $anho_nt);
        if($this->db->execute()){
        //return true;
        }else{
        //return false;
        }
    //$this->db->commit0();
    }
}

    public function EducaEditarEval($data){

    //$this->db->beginTransaction0();

        $this->db->query('UPDATE eval_nota_ev SET fecha= :fecha,objetivo= :objetivo where id_control= :id_control and nro= :nro');
        $this->db->bind(':id_control', $data['no_id']);
        $this->db->bind(':nro', $data['no_eval']);
        $this->db->bind(':fecha', $data['fecha']);
        $this->db->bind(':objetivo', $data['obj']);
//var_dump($this->db);
//exit;
        if($this->db->execute()){
        //return true;
        }else{
        //return false;
        }

    $nt=$data['eval_ntt'];

    $car_nt =$data['carga'];
    $mes_nt =$data['mes'];
    $anho_nt=$data['anho'];


if($mes_nt==1){
$mes_antes=12;
$ano_antes=$anho_nt-1;
}else{
$mes_antes=str_pad($mes_nt-1, 2, "0", STR_PAD_LEFT);
$ano_antes=$anho_nt;
}


    $id_nt=$data['no_id'];
    $tec_nt=$data['no_tec'];
    $eval_nt=$data['no_eval'];
    $cur_nt=$data['no_cur'];

    foreach ($data['eval_ced'] as $key =>$ced){
    $ced_nt=$ced;
    $ntt_nt=$nt[$key];

    $reg=$this->EducaConNt($ced_nt,$tec_nt,$anho_nt,$mes_nt);
    if($reg>0){
    $this->EducaActNt($ced_nt,$tec_nt,$anho_nt,$mes_nt,$ntt_nt,$car_nt,$cur_nt,$eval_nt);
    }else{
    $this->EducaInsNt($ced_nt,$tec_nt,$anho_nt,$mes_nt,$ntt_nt,$car_nt,$cur_nt,$eval_nt,$id_nt);
    }
    $this->EducaProNt($ced_nt,$id_nt,$eval_nt);
    }

$porc_ev=70;
$porc_ac=30;

    $nn=0;
    foreach ($data['eval_ced'] as $key =>$ced){
    $ced_nt=$ced;
    //echo $ced_nt.','.$tec_nt.','.$mes_antes.','.$ano_antes.'<br>';
    //$nn++;
    $QryAntes=$this->EducaAntNt($ced_nt,$tec_nt,$mes_antes,$ano_antes);
    if($QryAntes){
    $QryCed=$QryAntes->cedula;
    $QryNot=$QryAntes->ntantes;
    $sw_an="S";
    }else{
    $QryCed=$ced_nt;
    $QryNot=0;
    $sw_an="N";
    }
        $reg_antes[] = array(
        'ced_antes' => $QryCed,
        'not_antes' => $QryNot,
        'sw_an' => $sw_an,
        );
    }
    $ntfinal=0;$ntmes=0;

    foreach ($data['eval_ced'] as $key =>$ced){
    $ced_nt=$ced;
    $QryAhora=$this->EducaAhoNt($ced_nt,$tec_nt,$mes_nt,$anho_nt);
            if($QryAhora){
            $QryCedA=$QryAhora->cedula;
            $QryNotFin=$QryAhora->ntf;
            $QryNotAct=$QryAhora->ntfact;

                $nteval=$QryNotFin;
                $ntap1=$nteval*($porc_ev/100);
                $ntact=$QryNotAct;
                $ntap2=$ntact*($porc_ac/100);
                $ntmes=intval($ntap1+$ntap2);

            }else{
            $QryCedA=$ced_nt;
            $QryNotFin=0;
            $QryNotAct=0;
            $nteval=0;
            }

            $clave = array_search($ced_nt, $reg_antes);
            $ntms_an=$reg_antes[$clave]['not_antes'];
            $sw_an=  $reg_antes[$clave]['sw_an'];

            if($sw_an=="N"){
            $ntms_an=$nteval;
            }

            $ntfinal=intval((($ntmes+$ntms_an)/2)+.5);

        $this->db->query('update eval_nota_nt set ntpor1= :porc_ev,ntap1= :ntap1,ntpor2= :porc_ac,ntap2= :ntap2,ntmes= :ntmes,ntantes= :ntmes,ntfinal= :ntmes where cedula= :cednt and tecnica= :tec_nt and mes= :mes_nt and ano= :anho_nt');
        $this->db->bind(':porc_ev', $porc_ev);
        $this->db->bind(':ntap1', $ntap1);
        $this->db->bind(':porc_ac', $porc_ac);
        $this->db->bind(':ntap2', $ntap2);
        $this->db->bind(':ntmes', $ntmes);
        $this->db->bind(':cednt', $ced_nt);
        $this->db->bind(':tec_nt', $tec_nt);
        $this->db->bind(':mes_nt', $mes_nt);
        $this->db->bind(':anho_nt', $anho_nt);
        if($this->db->execute()){
        //return true;
        }else{
        //return false;
        }
    //$this->db->commit0();
    }
    }

    public function EducaTraerNotas($noeval,$noid,$nocur){
        if($noeval==1){
        $this->db->query('SELECT eval_nota_nt.id_control, eval_nota_nt.cedula, alumnos.apellidos, alumnos.nombres,alumnos.tag1, eval_nota_nt.nt1 as ntt
        FROM eval_nota_nt INNER JOIN alumnos ON eval_nota_nt.cedula = alumnos.cedula
        WHERE (((eval_nota_nt.id_control)= :noid)) ORDER BY alumnos.apellidos');
        }elseif($noeval==2){
        $this->db->query('SELECT eval_nota_nt.id_control, eval_nota_nt.cedula, alumnos.apellidos, alumnos.nombres,alumnos.tag1, eval_nota_nt.nt2 as ntt
        FROM eval_nota_nt INNER JOIN alumnos ON eval_nota_nt.cedula = alumnos.cedula
        WHERE (((eval_nota_nt.id_control)= :noid)) ORDER BY alumnos.apellidos');
        }elseif($noeval==3){
        $this->db->query('SELECT eval_nota_nt.id_control, eval_nota_nt.cedula, alumnos.apellidos, alumnos.nombres,alumnos.tag1, eval_nota_nt.nt3 as ntt
        FROM eval_nota_nt INNER JOIN alumnos ON eval_nota_nt.cedula = alumnos.cedula
        WHERE (((eval_nota_nt.id_control)= :noid)) ORDER BY alumnos.apellidos');
        }elseif($noeval==4){
        $this->db->query('SELECT eval_nota_nt.id_control, eval_nota_nt.cedula, alumnos.apellidos, alumnos.nombres,alumnos.tag1, eval_nota_nt.nt4 as ntt
        FROM eval_nota_nt INNER JOIN alumnos ON eval_nota_nt.cedula = alumnos.cedula
        WHERE (((eval_nota_nt.id_control)= :noid)) ORDER BY alumnos.apellidos');
        }elseif($noeval==5){
        $this->db->query('SELECT eval_nota_nt.id_control, eval_nota_nt.cedula, alumnos.apellidos, alumnos.nombres,alumnos.tag1, eval_nota_nt.nt5 as ntt
        FROM eval_nota_nt INNER JOIN alumnos ON eval_nota_nt.cedula = alumnos.cedula
        WHERE (((eval_nota_nt.id_control)= :noid)) ORDER BY alumnos.apellidos');
        }
        $this->db->bind(':noid', $noid);
        $result = $this->db->resultSet();
        return $result;
    }

    public function EducaDelNotas($noeval,$noid,$nocur){
        if($noeval==1){
        $this->db->query('UPDATE eval_nota_nt SET eval_nota_nt.nt1=0 WHERE eval_nota_nt.id_control= :noid');
        }elseif($noeval==2){
        $this->db->query('UPDATE eval_nota_nt SET eval_nota_nt.nt2=0 WHERE eval_nota_nt.id_control= :noid');
        }elseif($noeval==3){
        $this->db->query('UPDATE eval_nota_nt SET eval_nota_nt.nt3=0 WHERE eval_nota_nt.id_control= :noid');
        }elseif($noeval==4){
        $this->db->query('UPDATE eval_nota_nt SET eval_nota_nt.nt4=0 WHERE eval_nota_nt.id_control= :noid');
        }elseif($noeval==5){
        $this->db->query('UPDATE eval_nota_nt SET eval_nota_nt.nt5=0 WHERE eval_nota_nt.id_control= :noid');
        }
        $this->db->bind(':noid', $noid);
        $result = $this->db->execute();

        $this->db->query('DELETE FROM eval_nota_ev WHERE id_control= :noid and nro= :noeval');
        $this->db->bind(':noid', $noid);
        $this->db->bind(':noeval', $noeval);
        $this->db->execute();

                if($noeval-1==1){
        $this->db->query('update eval_nota_nt set ntf=nt1,ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_control= :idnt');
        }elseif($noeval-1==2){
        $this->db->query('update eval_nota_nt set ntf=(nt1+nt2)/2,ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_control= :idnt');
        }elseif($noeval-1==3){
        $this->db->query('update eval_nota_nt set ntf=(nt1+nt2+nt3)/3,ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_control= :idnt');
        }elseif($noeval-1==4){
        $this->db->query('update eval_nota_nt set ntf=(nt1+nt2+nt3+nt4)/4,ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_control= :idnt');
        }elseif($noeval-1==5){
        $this->db->query('update eval_nota_nt set ntf=(nt1+nt2+nt3+nt4+nt5)/5,ntpor1=ntf,ntap1=ntf,d1=ntf,d2=ntf,d3=ntf,d4=ntf,d5=ntf,d6=ntf,d7=ntf,d8=ntf,d9=ntf,d10=ntf,d11=ntf,d12=ntf,ntfact=ntf,ntpor2=ntf,ntap2=ntf,ntmes=ntf,ntantes=ntf,ntfinal=ntf where id_control= :idnt');
        }

        $this->db->bind(':idnt', $noid);
        if($this->db->execute()){
        return true;
        }else{
        return false;
        }


        return $result;
    }

}