<?php
require_once("../includes/bootstrap2.php");
	$sesion=new sesion(); // inicio la sesion
	if(!comprobar_sesion()){
		$ar=array();
		$ar['error']='session';
		echo json_encode($ar);
		exit;
	}
	$academia = bootstrap::initBd($sesion->get('anio'));
	if($_SERVER['REQUEST_METHOD']=='POST'){
		$oper=$academia->escapar($_POST['oper']);
		$arr=array('new','edit','del');
		if(in_array($oper,$arr)){
			
			$codest=$academia->escapar($_POST['idest']);
			$nnum=$academia->escapar($_POST['nt_num']);
                        $nnum=(empty($nnum) ? NULL :  $nnum);
			$per=$academia->escapar($_POST['per']); 
			$obs=str_replace('\n','<br>',$academia->escapar($_POST['obs']));
			$nlet=$academia->escapar($_POST['nlet']);
			switch($oper){
				case 'del':
					$sql="delete from aca_observaxest where  periodo='$per' and cod_estudiantes_grupos='$codest' ";
				break;
				case 'edit':
                                case 'new': 
                                    if(!empty($nnum))
					$sql="INSERT INTO aca_observaxest ( cod_estudiantes_grupos, periodo, nonu_per_dis, nole_per_dis, observacion) VALUES ('$codest', '$per', '$nnum', '$nlet', '$obs') ON DUPLICATE KEY UPDATE cod_estudiantes_grupos='$codest', periodo='$per', nonu_per_dis='$nnum', nole_per_dis='$nlet',observacion='$obs';";
                                    else
                                        $sql="INSERT INTO aca_observaxest ( cod_estudiantes_grupos, periodo, nole_per_dis, observacion) VALUES ('$codest', '$per',  '$nlet', '$obs') ON DUPLICATE KEY UPDATE cod_estudiantes_grupos='$codest', periodo='$per', nonu_per_dis='$nnum', nole_per_dis='$nlet',observacion='$obs';";    
				break;
				default:
					$sql="";
			}
			if($sql!=''){
				$academia->instruccion($sql);
				$rta=array('error'=>$academia->extraer_error());
				echo json_encode($rta);		
			}	
		}
	}
	$academia->cerrar();
?>