<?php require_once('Connections/conn.php'); ?>
<?php
/* Permite modificar (rectificar) las calificaciones de un alumno seleccionado por el
   usuario */
 session_start();
 header("Content-Type:text/html; charset=utf-8");
	//Impide que la p�gina sea vista desde el navegador.
	if (!isset($_SESSION['MM_Username'])) {
      	header ("Location: modulos/inicio/index.php");
	  }
	$cedula=$_GET["cedula"];
	$carrera=$_GET["carrera"];
	
?>
<html>
<head>
<title>sadce -- rectificar calificaciones</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
  body {
    background-color: #FFFFFF;
    color: #0066CC;
    font-family: Arial;
    font-size: 12px;
  }
  .bd {
    background-color: #FFFFFF;
    color: #0066CC;
    font-family: Arial;
    font-size: 12px;
  }
  .tbl {
    background-color: #FFFFFF;
  }
  a:link { 
    color: #FF0000;
    font-family: Arial;
    font-size: 12px;
  }
  a:active { 
    color: #0000FF;
    font-family: Arial;
    font-size: 12px;
  }
  a:visited { 
    color: #800080;
    font-family: Arial;
    font-size: 12px;
  }
  .hr {
    background-color: #336699;
    color: #FFFFFF;
    font-family: Arial;
    font-size: 12px;
  }
  a.hr:link {
    color: #FFFFFF;
    font-family: Arial;
    font-size: 12px;
  }
  a.hr:active {
    color: #FFFFFF;
    font-family: Arial;
    font-size: 12px;
  }
  a.hr:visited {
    color: #FFFFFF;
    font-family: Arial;
    font-size: 12px;
  }
  .dr {
    background-color: #FFFFFF;
    color: #000000;
    font-family: Arial;
    font-size: 12px;
  }
  .sr {
    background-color: #FFFFCF;
    color: #000000;
    font-family: Arial;
    font-size: 12px;
  }
</style>
</head>
<body>
<table class="bd" width="100%"><tr><td class="hr"><h2>Rectificaci&oacute;n de Notas </h2></td></tr></table>
<?php
  if (!login($cedula, $carrera)) exit;
  	$conn=connect();
	
  	$query_carrera = "SELECT nombre_carrera FROM carreras WHERE id_carrera='$carrera'";
	$rs_carrera = mysql_query($query_carrera, $conn) or die(mysql_error());
	$row_carrera = mysql_fetch_assoc($rs_carrera);
	$totalRows_carrera = mysql_num_rows($rs_carrera);

	$query_rs_alumno = "SELECT id_alumno,cedula, apellidos, nombres FROM alumnos WHERE cedula='$cedula' or pasaporte='$cedula'";
	$rs_alumno = mysql_query($query_rs_alumno, $conn) or die(mysql_error());
	$row_alumno = mysql_fetch_assoc($rs_alumno);
	$totalRows_rs_alumno = mysql_num_rows($rs_alumno);
	$alumno=$row_alumno["id_alumno"];
?>
<div style="float: right"><a href="rectificar.php?a=logout">[ Logout ]</a></div>
  <table class="bd" border="0" cellspacing="1" cellpadding="2">
<tr>
   <td><b>PARTICIPANTE:</b></td>
   <td><?php echo $row_alumno['apellidos'].', '.$row_alumno['nombres']; ?></td>
</tr>
<tr>
   <td><b>CEDULA:</b></td>
   <td><?php echo $row_alumno['cedula']; ?></td>
</tr>
<tr>
   <td><b>MATRICULA:</b></td>
   <td><?php echo $alumno; ?></td>
</tr>

<tr>
   <td><b>PROGRAMA:</b></td>
   <td><?php echo $row_carrera['nombre_carrera']; ?></td>
</tr>
</table>

<?php
  $conn = connect();
  $showrecs = 10;
  $pagerange = 10;

  $a = @$_GET["a"];
  $recid = @$_GET["recid"];
  $page = @$_GET["page"];
  if (!isset($page)) $page = 1;

  $sql = @$_POST["sql"];
  
  $cedula=$_GET["cedula"];
  $carrera=$_GET["carrera"];

  switch ($sql) {
    case "update":
      sql_update($alumno, $carrera);
      break;
    case "delete":
      sql_delete($alumno, $carrera);
      break;
  }

  switch ($a) {
    case "edit":
      editrec($recid, $alumno, $carrera);
      break;
    case "del":
      deleterec($recid, $alumno, $carrera);
      break;
    default:
      select($alumno, $carrera);
      break;
  }
  mysql_close($conn);
?>
<table class="bd" width="100%"><tr><td class="hr"></td></tr></table>
</body>
</html>

<?php

 function select($alumno, $carrera)
  {
  global $a;
  global $showrecs;
  global $page;
  global $cedula;
    
	
  $res = sql_select($alumno, $carrera);
  $count = sql_getrecordcount($alumno, $carrera);
  if ($count % $showrecs != 0) {
    $pagecount = intval($count / $showrecs) + 1;
  }
  else {
    $pagecount = intval($count / $showrecs);
  }
  $startrec = $showrecs * ($page - 1);
  if ($startrec < $count) {mysql_data_seek($res, $startrec);}
  $reccount = min($showrecs * $page, $count);
?>

<hr size="1" noshade>
<?php showpagenav($page, $pagecount, $alumno, $carrera); ?>
<br>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="100%">
<tr>
<td class="hr">Rectificar</td>
<td class="hr">Borrar</td>
<td class="hr"><?php echo "Código" ?></td>
<td class="hr"><?php echo "Unidad Curricular" ?></td>
<td class="hr"><?php echo "Nota" ?></td>
<td class="hr"><?php echo "Sección" ?></td>
<td class="hr"><?php echo "Periodo" ?></td>
<td class="hr"><?php echo "Sede" ?></td>
</tr>
<?php
  for ($i = $startrec; $i < $reccount; $i++)
  {
    $row = mysql_fetch_assoc($res);
    $style = "dr";
    if ($i % 2 != 0) {
      $style = "sr";
    }
?>
<tr>
<td align="center" class="<?php echo $style ?>"><a href="rectificar_historico.php?a=edit&recid=<?php echo $i ?>&cedula=<?php echo $cedula ?>&carrera=<?php echo $carrera ?>"><img src="imagenes/edit.gif" border="0" ></a></td>
<td align="center" class="<?php echo $style ?>"><a href="rectificar_historico.php?a=del&recid=<?php echo $i ?>&cedula=<?php echo $cedula ?>&carrera=<?php echo $carrera ?>"><img src="imagenes/delete.png" border="0" ></a></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["id_materia"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["nombre_materia"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["nota"]) ?></td>
<td class="<?php echo $style ?>" align="center"><?php echo htmlspecialchars($row["seccion"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["periodo"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["sede"]) ?></td>
</tr>
<?php
  }
  mysql_free_result($res);
?>
</table>
<br>
<?php } ?>

<?php function login($cedula, $carrera)
{
  global $_POST;
  global $_SESSION;

  global $_GET;
  if (isset($_GET["a"]) && ($_GET["a"] == 'logout')) $_SESSION["logged_in"] = false;
  if (!isset($_SESSION["logged_in"])) $_SESSION["logged_in"] = false;
  if (!$_SESSION["logged_in"]) {
    $login = "";
    $password = "";
    if (isset($_POST["login"])) $login = @$_POST["login"];
    if (isset($_POST["password"])) $password = @$_POST["password"];

    if (($login != "") && ($password != "")) {
	
	   $conn = mysql_connect("localhost", "ceula_sadce_admi", "j7BnJdCGzyQBGcud");
       mysql_select_db("ceulac_sadce"); 
       mysql_query ("SET NAMES 'utf8'");
	   
      $sql = "select `psw_rectificar` from `usuarios` where `username` = '" .$login ."'";
      $res = mysql_query($sql, $conn) or die(mysql_error());
      $row = mysql_fetch_assoc($res) or $row = array(0 => "");;
      if (isset($row)) reset($row);

      if (isset($password) && ($password == trim(current($row)))) {
        $_SESSION["logged_in"] = true;
    }
    else {
?>
<p><b><font color="-1">El Usuario/Contraseña es inválido</font></b></p>
<?php } } }if (isset($_SESSION["logged_in"]) && (!$_SESSION["logged_in"])) { ?>
<form action="rectificar_historico.php?cedula=<?php echo $cedula ?>&carrera=<?php echo $carrera ?>" method="post"> 
<table width="40%" border="0" align="center" cellpadding="0" cellspacing="0" class="bd" id="tablaLogin">
  <tr><td colspan="2" align="center" valign="middle" class="hr1">Autenticación de Usuario</td>
  </tr>
  <tr>
    <td width="39%">&nbsp;</td>
    <td width="61%">&nbsp;</td>
  </tr>
  <tr>
    <td><div align="right" class="style5">
      Usuario:&nbsp; 
    </div></td>
    <td class="style1"><input type="text" name="login" value="<?php echo $login ?>"></td>
  </tr>
  <tr>
    <td align="right"><div align="right" class="style5">
      Contraseña:&nbsp; 
    </div></td>
    <td class="style1"><input type="password" name="password" value="<?php echo $password ?>"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2"><div align="center">
	  <input type="submit" name="action" value="Acceder">
    </div></td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
  </tr>
</table>
</form>
<?php
  }
  if (!isset($_SESSION["logged_in"])) $_SESSION["logged_in"] = false;
  return $_SESSION["logged_in"];
} ?>

<?php function showrow($row, $recid)
  {
    global $conn;  
    $materia=$row['id_materia'];
	mysql_select_db($database_conn, $conn);
	mysql_query ("SET NAMES 'utf8'");
	$query_rstMaterias = "SELECT materias.nombre_materia FROM materias WHERE id_materia='$materia'";
	$rstMaterias = mysql_query($query_rstMaterias, $conn) or die(mysql_error());
	$row_rstMaterias = mysql_fetch_assoc($rstMaterias);
	$totalRows_rstMaterias = mysql_num_rows($rstMaterias);
    $nombre_materia=$row_rstMaterias['nombre_materia'];  
  
  
?>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="100%">
<tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Código Unidad Curricular")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($materia) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Nombre Unidad Curricular")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($nombre_materia) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Calificación")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["nota"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Sección")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["seccion"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Periodo")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["periodo"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Sede")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["sede"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Año")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["annio"]) ?></td>
</tr>
</table>
<?php } ?>

<?php function showroweditor($row, $iseditmode)
  {
  global $conn;
  
    $materia=$row['id_materia'];
	mysql_select_db($database_conn, $conn);
	mysql_query ("SET NAMES 'utf8'");
	$query_rstMaterias = "SELECT materias.nombre_materia FROM materias WHERE id_materia='$materia'";
	$rstMaterias = mysql_query($query_rstMaterias, $conn) or die(mysql_error());
	$row_rstMaterias = mysql_fetch_assoc($rstMaterias);
	$totalRows_rstMaterias = mysql_num_rows($rstMaterias);
    $nombre_materia=$row_rstMaterias['nombre_materia'];  
		
	
	$query_rstSecciones = "SELECT DISTINCT secciones.id_seccion FROM secciones";
	$rstSecciones = mysql_query($query_rstSecciones, $conn) or die(mysql_error());
	$row_rstSecciones = mysql_fetch_assoc($rstSecciones);
	$totalRows_rstSecciones = mysql_num_rows($rstSecciones);

   
	$query_rstPeriodos = "SELECT periodos.codigo FROM periodos";
	$rstPeriodos = mysql_query($query_rstPeriodos, $conn) or die(mysql_error());
	$row_rstPeriodos = mysql_fetch_assoc($rstPeriodos);
	$totalRows_rstPeriodos = mysql_num_rows($rstPeriodos);
	
	$sede=$row['sede'];
	$query_rstSedes = "SELECT nombre_sede FROM sedes where codigo='$sede'";
	$rstSedes = mysql_query($query_rstSedes, $conn) or die(mysql_error());
	$row_rstSedes = mysql_fetch_assoc($rstSedes);
	$totalRows_rstSedes = mysql_num_rows($rstSedes);
	
	
	$query_rstSedes1 = "SELECT codigo,nombre_sede FROM sedes";
	$rstSedes1 = mysql_query($query_rstSedes1, $conn) or die(mysql_error());
	$row_rstSedes1 = mysql_fetch_assoc($rstSedes1);
	$totalRows_rstSedes1 = mysql_num_rows($rstSedes1);
  
?>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="90%">

<tr>
<td class="hr"><?php echo htmlspecialchars("Unidad Curricular")."&nbsp;" ?></td>
<td class="dr"><textarea disabled="disabled" cols="50" rows="2" name="nombre_materia" maxlength="255"><?php echo $nombre_materia ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Calificación")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="nota" value="<?php echo str_replace('"', '&quot;', trim($row["nota"])) ?>" onKeyUp="mascara(this,'.',patron1,true)" maxlength="4" size="4"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Modalidad de Curso")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="aprobacion" value="<?php echo str_replace('"', '&quot;', trim($row["aprobacion"])) ?>" onKeyUp="mascara(this,'.',patron1,true)" maxlength="12" size="12"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Sección")."&nbsp;" ?></td>
<td class="dr">
<select name="seccion">
<option value="<?php echo $row['seccion']?>"><?php echo $row['seccion']?></option>
  <?php
do {  
?>
  <option value="<?php echo $row_rstSecciones['id_seccion']?>"><?php echo $row_rstSecciones['id_seccion']?></option>
  <?php
} while ($row_rstSecciones = mysql_fetch_assoc($rstSecciones));
  $rows = mysql_num_rows($rstSecciones);
  if($rows > 0) {
      mysql_data_seek($rstSecciones, 0);
	  $row_rstSecciones = mysql_fetch_assoc($rstSecciones);
  }
?></select>
</td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Periodo")."&nbsp;" ?></td>
<td class="dr">
<select name="periodo">
  <option value="<?php echo $row['periodo']?>"><?php echo $row['periodo']?></option>
  <?php
do {  
?>
  <option value="<?php echo $row_rstPeriodos['codigo']?>"><?php echo $row_rstPeriodos['codigo']?></option>
  <?php
} while ($row_rstPeriodos = mysql_fetch_assoc($rstPeriodos));
  $rows = mysql_num_rows($rstPeriodos);
  if($rows > 0) {
      mysql_data_seek($rstPeriodos, 0);
	  $row_rstPeriodos = mysql_fetch_assoc($rstPeriodos);
  }
?></select>
</td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Sede")."&nbsp;" ?></td>
<td class="dr"><select name="sede">
  <option value="<?php echo $row['sede']?>"><?php echo $row_rstSedes['nombre_sede']?></option>
  <?php
do {  
?>
  <option value="<?php echo $row_rstSedes1['codigo']?>"><?php echo $row_rstSedes1['nombre_sede']?></option>
  <?php
} while ($row_rstSedes1 = mysql_fetch_assoc($rstSedes1));
  $rows = mysql_num_rows($rstSedes1);
  if($rows > 0) {
      mysql_data_seek($rstSedes1, 0);
	  $row_rstSedes1 = mysql_fetch_assoc($rstSedes1);
  }
?></select>
</td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Año")."&nbsp;" ?></td>
<td class="dr"><input name="annio" type="text" value="<?php echo str_replace('"', '&quot;', trim($row["annio"])) ?>" size="2" maxlength="4"></td>
</tr>
</table>
<?php
mysql_free_result($rstMaterias);

mysql_free_result($rstSecciones);

mysql_free_result($rstPeriodos);
 } ?>


<?php function showrowadd($row, $iseditmode)
  {
  global $conn;
  
    $materia=$row['id_materia'];
	mysql_select_db($database_conn, $conn);
	mysql_query ("SET NAMES 'utf8'");
	$query_rstMaterias = "SELECT materias.nombre_materia FROM materias WHERE id_materia='$materia'";
	$rstMaterias = mysql_query($query_rstMaterias, $conn) or die(mysql_error());
	$row_rstMaterias = mysql_fetch_assoc($rstMaterias);
	$totalRows_rstMaterias = mysql_num_rows($rstMaterias);
    $nombre_materia=$row_rstMaterias['nombre_materia'];  
		
	
	$query_rstSecciones = "SELECT DISTINCT secciones.id_seccion FROM secciones";
	$rstSecciones = mysql_query($query_rstSecciones, $conn) or die(mysql_error());
	$row_rstSecciones = mysql_fetch_assoc($rstSecciones);
	$totalRows_rstSecciones = mysql_num_rows($rstSecciones);


	$query_rstPeriodos = "SELECT periodos.codigo FROM periodos";
	$rstPeriodos = mysql_query($query_rstPeriodos, $conn) or die(mysql_error());
	$row_rstPeriodos = mysql_fetch_assoc($rstPeriodos);
	$totalRows_rstPeriodos = mysql_num_rows($rstPeriodos);
     
	
  
?>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="50%">

<tr>
<td class="hr"><?php echo htmlspecialchars("Unidad Curricular")."&nbsp;" ?></td>
<td class="dr"><textarea disabled="disabled" cols="40" rows="3" name="nombre_materia" maxlength="255"><?php echo $nombre_materia ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Calificación")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="nota" value="<?php echo str_replace('"', '&quot;', trim($row["nota"])) ?>" onKeyUp="mascara(this,'.',patron1,true)" maxlength="4" size="4"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Sección")."&nbsp;" ?></td>
<td class="dr">
<select name="seccion">
<option value="<?php echo $row['seccion']?>"><?php echo $row['seccion']?></option>
  <?php
do {  
?>
  <option value="<?php echo $row_rstSecciones['id_seccion']?>"><?php echo $row_rstSecciones['id_seccion']?></option>
  <?php
} while ($row_rstSecciones = mysql_fetch_assoc($rstSecciones));
  $rows = mysql_num_rows($rstSecciones);
  if($rows > 0) {
      mysql_data_seek($rstSecciones, 0);
	  $row_rstSecciones = mysql_fetch_assoc($rstSecciones);
  }
?></select>
</td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Periodo")."&nbsp;" ?></td>
<td class="dr">
<select name="periodo">
  <option value="<?php echo $row['periodo']?>"><?php echo $row['periodo']?></option>
  <?php
do {  
?>
  <option value="<?php echo $row_rstPeriodos['codigo']?>"><?php echo $row_rstPeriodos['codigo']?></option>
  <?php
} while ($row_rstPeriodos = mysql_fetch_assoc($rstPeriodos));
  $rows = mysql_num_rows($rstPeriodos);
  if($rows > 0) {
      mysql_data_seek($rstPeriodos, 0);
	  $row_rstPeriodos = mysql_fetch_assoc($rstPeriodos);
  }
?></select>
</td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Sede")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="sede" maxlength="2" value="<?php echo str_replace('"', '&quot;', trim($row["sede"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Año")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="annio" value="<?php echo str_replace('"', '&quot;', trim($row["annio"])) ?>"></td>
</tr>
</table>
<?php
mysql_free_result($rstMaterias);

mysql_free_result($rstSecciones);

mysql_free_result($rstPeriodos);
 } ?>


<?php function showpagenav($page, $pagecount, $alumno, $carrera)
{
global $cedula;
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<?php if ($page > 1) { ?>
<td><a href="rectificar_historico.php?page=<?php echo $page - 1 ?>&cedula=<?php echo $cedula ?>&carrera=<?php echo $carrera ?>">&lt;&lt;&nbsp;Anterior</a>&nbsp;</td>
<?php } ?>
<?php
  global $pagerange;

  if ($pagecount > 1) {

  if ($pagecount % $pagerange != 0) {
    $rangecount = intval($pagecount / $pagerange) + 1;
  }
  else {
    $rangecount = intval($pagecount / $pagerange);
  }
  for ($i = 1; $i < $rangecount + 1; $i++) {
    $startpage = (($i - 1) * $pagerange) + 1;
    $count = min($i * $pagerange, $pagecount);

    if ((($page >= $startpage) && ($page <= ($i * $pagerange)))) {
      for ($j = $startpage; $j < $count + 1; $j++) {
        if ($j == $page) {
?>
<td><b><?php echo $j ?></b></td>
<?php } else { ?>
<td><a href="rectificar_historico.php?page=<?php echo $j ?>&cedula=<?php echo $cedula ?>&carrera=<?php echo $carrera ?>"><?php echo $j ?></a></td>
<?php } } } else { ?>
<td><a href="rectificar_historico.php?page=<?php echo $startpage ?>&cedula=<?php echo $cedula ?>&carrera=<?php echo $carrera ?>"><?php echo $startpage ."..." .$count ?></a></td>
<?php } } } ?>
<?php if ($page < $pagecount) { ?>
<td>&nbsp;<a href="rectificar_historico.php?page=<?php echo $page + 1 ?>&cedula=<?php echo $cedula ?>&carrera=<?php echo $carrera ?>">Siguiente&nbsp;&gt;&gt;</a>&nbsp; </td>
<?php } ?>
</tr>
</table>
<?php } ?>

<?php function showrecnav($a, $recid, $count, $alumno, $carrera)
{
global $cedula;
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="rectificar_historico.php?cedula=<?php echo $cedula ?>&carrera=<?php echo $carrera ?>">Regresar</a></td>
<?php if ($recid > 0) { ?>
<td><a href="rectificar_historico.php?a=<?php echo $a ?>&recid=<?php echo $recid - 1 ?>&cedula=<?php echo $cedula ?>&carrera=<?php echo $carrera ?>">Siguiente</a></td>
<?php } if ($recid < $count - 1) { ?>
<td><a href="rectificar_historico.php?a=<?php echo $a ?>&recid=<?php echo $recid + 1 ?>&cedula=<?php echo $cedula ?>&carrera=<?php echo $carrera ?>">Anterior</a></td>
<?php } ?>
</tr>
</table>
<hr size="1" noshade>
<?php } ?>

<?php function editrec($recid, $alumno, $carrera)
{
 global $cedula;
  $res = sql_select($alumno, $carrera);
  $count = sql_getrecordcount($alumno, $carrera);
  mysql_data_seek($res, $recid);
  $row = mysql_fetch_assoc($res);
  showrecnav("edit", $recid, $count, $alumno, $carrera);
?>
<br>
<form name="editarNota" id="editarNota" enctype="multipart/form-data" action="rectificar_historico.php?cedula=<?php echo $cedula ?>&carrera=<?php echo $carrera ?>" method="post" onSubmit="return validar_nota()">
<input type="hidden" name="sql" value="update">
<input type="hidden" name="xid_alumno" value="<?php echo $row["id_alumno"] ?>">
<input type="hidden" name="xcedula" value="<?php echo $row["cedula"] ?>">
<input type="hidden" name="xid_carrera" value="<?php echo $row["id_carrera"] ?>">
<input type="hidden" name="xid_materia" value="<?php echo $row["id_materia"] ?>">
<input type="hidden" name="xid_docente" value="<?php echo $row["id_docente"] ?>">
<input type="hidden" name="xnota" value="<?php echo $row["nota"] ?>">
<input type="hidden" name="xseccion" value="<?php echo $row["seccion"] ?>">
<input type="hidden" name="xperiodo" value="<?php echo $row["periodo"] ?>">
<input type="hidden" name="xsede" value="<?php echo $row["sede"] ?>">
<input type="hidden" name="xannio" value="<?php echo $row["annio"] ?>">
<?php showroweditor($row, true); ?>
<p><input type="submit" name="action" value="Guardar"></p>
</form>
<?php
  mysql_free_result($res);
} ?>

<?php function deleterec($recid, $alumno, $carrera)
{
global $cedula;
  $res = sql_select($alumno, $carrera);
  $count = sql_getrecordcount($alumno, $carrera);
  mysql_data_seek($res, $recid);
  $row = mysql_fetch_assoc($res);
  showrecnav("del", $recid, $count, $alumno, $carrera);
?>
<br>
<form action="rectificar_historico.php?cedula=<?php echo $cedula ?>&carrera=<?php echo $carrera ?>" method="post">
<input type="hidden" name="sql" value="delete">
<input type="hidden" name="xid_alumno" value="<?php echo $row["id_alumno"] ?>">
<input type="hidden" name="xcedula" value="<?php echo $row["cedula"] ?>">
<input type="hidden" name="xid_carrera" value="<?php echo $row["id_carrera"] ?>">
<input type="hidden" name="xid_materia" value="<?php echo $row["id_materia"] ?>">
<input type="hidden" name="xid_docente" value="<?php echo $row["id_docente"] ?>">
<input type="hidden" name="xnota" value="<?php echo $row["nota"] ?>">
<input type="hidden" name="xseccion" value="<?php echo $row["seccion"] ?>">
<input type="hidden" name="xperiodo" value="<?php echo $row["periodo"] ?>">
<input type="hidden" name="xsede" value="<?php echo $row["sede"] ?>">
<input type="hidden" name="xannio" value="<?php echo $row["annio"] ?>">
<?php showrow($row, $recid) ?>
<p><input type="submit" name="action" value="Confirmar"></p>
</form>
<?php
  mysql_free_result($res);
} ?>

<?php function connect()
{
  $conn = mysql_connect("localhost", "ceula_sadce_admi", "j7BnJdCGzyQBGcud");
  mysql_select_db("ceulac_sadce");
  mysql_query ("SET NAMES 'utf8'");
  
  return $conn;
}


function sqlvalue($val, $quote)
{
  if ($quote)
    $tmp = sqlstr($val);
  else
    $tmp = $val;
  if ($tmp == "")
    $tmp = "NULL";
  elseif ($quote)
    $tmp = "'".$tmp."'";
  return $tmp;
}

function sqlstr($val)
{
  return str_replace("'", "''", $val);
}

function sql_select($alumno, $carrera)
{
  global $conn;
  $sql = "Select
historico_notas.id_alumno,
historico_notas.id_carrera,
historico_notas.id_materia,
historico_notas.id_docente,
historico_notas.nota,
historico_notas.seccion,
historico_notas.periodo,
historico_notas.sede,
historico_notas.annio,
materias.nombre_materia
From
historico_notas
Inner Join materias ON historico_notas.id_materia = materias.id_materia
Where
historico_notas.id_alumno = '$alumno' AND
historico_notas.id_carrera = '$carrera' ";
  $res = mysql_query($sql, $conn) or die(mysql_error());
  return $res;
}

function sql_getrecordcount($alumno, $carrera)
{
  global $conn;
  $sql = "SELECT COUNT(*) FROM `historico_notas` WHERE id_alumno='$alumno' AND id_carrera='$carrera'";
  $res = mysql_query($sql, $conn) or die(mysql_error());
  $row = mysql_fetch_assoc($res);
  reset($row);
  return current($row);
}

function sql_update($alumno, $carrera)
{
  global $conn;
  global $_POST;
  
  $materia=@$_POST["xid_materia"];

  $sql = "update `historico_notas` set `nota`=" .sqlvalue(@$_POST["nota"], false).", `seccion`=" .sqlvalue(@$_POST["seccion"], true).", `periodo`=" .sqlvalue(@$_POST["periodo"], true) ." where id_alumno='$alumno' AND  id_materia='$materia' AND id_carrera='$carrera'" ;
  mysql_query($sql, $conn) or die(mysql_error());
}

function sql_delete($alumno, $carrera)
{
  global $conn;
  
  $materia=@$_POST["xid_materia"];
  $sql = "delete from `historico_notas` where id_alumno='$alumno' AND  id_materia='$materia' AND id_carrera='$carrera'";
  mysql_query($sql, $conn) or die(mysql_error());
}

function primarykeycondition()
{
  global $_POST;
  $pk = "";
  $pk .= "(`id_alumno`";
  if (@$_POST["xid_alumno"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xid_alumno"], false);
  };
  $pk .= ") and ";
  $pk .= "(`cedula`";
  if (@$_POST["xcedula"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xcedula"], true);
  };
  $pk .= ") and ";
  $pk .= "(`id_carrera`";
  if (@$_POST["xid_carrera"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xid_carrera"], true);
  };
  $pk .= ") and ";
  $pk .= "(`id_materia`";
  if (@$_POST["xid_materia"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xid_materia"], true);
  };
  $pk .= ") and ";
  $pk .= "(`id_docente`";
  if (@$_POST["xid_docente"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xid_docente"], false);
  };
  $pk .= ") and ";
  $pk .= "(`nota`";
  if (@$_POST["xnota"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xnota"], false);
  };
  $pk .= ") and ";
  $pk .= "(`seccion`";
  if (@$_POST["xseccion"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xseccion"], true);
  };
  $pk .= ") and ";
  $pk .= "(`periodo`";
  if (@$_POST["xperiodo"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xperiodo"], true);
  };
  $pk .= ") and ";
  $pk .= "(`sede`";
  if (@$_POST["xsede"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xsede"], true);
  };
  $pk .= ") and ";
  $pk .= "(`annio`";
  if (@$_POST["xannio"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xannio"], true);
  };
  $pk .= ")";
  return $pk;
}
 ?>

<script type="text/javascript">
var patron = new Array(2,2,4)
var patron1= new Array(1,2)
var patron2 = new Array(1,3,3,3,3)
function mascara(d,sep,pat,nums){
if(d.valant != d.value){
	val = d.value
	largo = val.length
	val = val.split(sep)
	val2 = ''
	for(r=0;r<val.length;r++){
		val2 += val[r]	
	}
	if(nums){
		for(z=0;z<val2.length;z++){
			if(isNaN(val2.charAt(z))){
				letra = new RegExp(val2.charAt(z),"g")
				val2 = val2.replace(letra,"")
			}
		}
	}
	val = ''
	val3 = new Array()
	for(s=0; s<pat.length; s++){
		val3[s] = val2.substring(0,pat[s])
		val2 = val2.substr(pat[s])
	}
	for(q=0;q<val3.length; q++){
		if(q ==0){
			val = val3[q]
		}
		else{
			if(val3[q] != ""){
				val += sep + val3[q]
				}
		}
	}
	d.value = val
	d.valant = val
	}
}
</script>



<script type="text/javascript">

function validar_nota()
{
  if(document.editarNota.nota.value==""){
	alert("El campo <<Calificación>> es obligatorio");
	document.editarNota.nota.focus();
	return false;
	}
	
  if((document.editarNota.nota.value<1) || (document.editarNota.nota.value>5)){
	alert("Calificación <<"+document.editarNota.nota.value+">> fuera de rango. \n El rango válido es [1..5]");
	document.editarNota.nota.focus();
	document.editarNota.nota.value="";
	return false;
	} 
	
return true;
}

</script>