<?php session_start();

?>

<html>
<head>
<title>siga_pregrado -- inscripciones</title>
<meta name="generator" http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
  body {
    background-color: #FFFFFF;
    color: #000000;
    font-family: Arial;
    font-size: 12px;
  }
  .bd {
    background-color: #FFFFFF;
    color: #000000;
    font-family: Arial;
    font-size: 12px;
  }
  .tbl {
    background-color: #FFFFFF;
  }
  a:link { 
    background-color: #FFFFFF01;
    color: #FF0000;
    font-family: Arial;
    font-size: 12px;
  }
  a:active { 
    background-color: #FFFFFF01;
    color: #0000FF;
    font-family: Arial;
    font-size: 12px;
  }
  a:visited { 
    background-color: #FFFFFF01;
    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>Gesti�n de Aulas</tr></table>
<?php
  $conn = connect();
  $showrecs = 20;
  $pagerange = 20;

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

  $sql = @$_POST["sql"];

  switch ($sql) {
    case "update":
      sql_update();
      break;
  }

  switch ($a) {
    case "edit":
      editrec($recid);
      break;
    default:
      select();
      break;
  }


  mysql_close($conn);
?>
<table class="bd" width="100%"><tr><td class="hr">!SIGA LA ENAHP!</td></tr></table>
</body>
</html>

<?php function select()
  {
  global $a;
  global $showrecs;
  global $page;

  $res = sql_select();
  $count = sql_getrecordcount();
  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);
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr><td>Tabla: inscripciones</td></tr>
<tr><td>Registros <?php echo $startrec + 1 ?> - <?php echo $reccount ?> de <?php echo $count ?></td></tr>
</table>
<hr size="1" noshade>
<?php showpagenav($page, $pagecount); ?>
<br>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="100%">
<tr>
<td class="hr">&nbsp;</td>
<td class="hr"><?php echo "id" ?></td>
<td class="hr"><?php echo "id_alumno" ?></td>
<td class="hr"><?php echo "sede" ?></td>
<td class="hr"><?php echo "id_seccion" ?></td>
<td class="hr"><?php echo "id_carrera" ?></td>
<td class="hr"><?php echo "pensum" ?></td>
<td class="hr"><?php echo "nivel" ?></td>
<td class="hr"><?php echo "mencion" ?></td>
<td class="hr"><?php echo "id_periodo" ?></td>
<td class="hr"><?php echo "semestre" ?></td>
<td class="hr"><?php echo "turno" ?></td>
<td class="hr"><?php echo "id_materia" ?></td>
<td class="hr"><?php echo "id_docente" ?></td>
<td class="hr"><?php echo "eval1" ?></td>
<td class="hr"><?php echo "eval2" ?></td>
<td class="hr"><?php echo "eval3" ?></td>
<td class="hr"><?php echo "recuperacion" ?></td>
<td class="hr"><?php echo "eval4" ?></td>
<td class="hr"><?php echo "corte_1" ?></td>
<td class="hr"><?php echo "eval5" ?></td>
<td class="hr"><?php echo "eval6" ?></td>
<td class="hr"><?php echo "eval7" ?></td>
<td class="hr"><?php echo "eval8" ?></td>
<td class="hr"><?php echo "corte_2" ?></td>
<td class="hr"><?php echo "eval9" ?></td>
<td class="hr"><?php echo "eval10" ?></td>
<td class="hr"><?php echo "eval11" ?></td>
<td class="hr"><?php echo "eval12" ?></td>
<td class="hr"><?php echo "corte_3" ?></td>
<td class="hr"><?php echo "eval13" ?></td>
<td class="hr"><?php echo "eval14" ?></td>
<td class="hr"><?php echo "eval15" ?></td>
<td class="hr"><?php echo "eval16" ?></td>
<td class="hr"><?php echo "corte_4" ?></td>
<td class="hr"><?php echo "acumulado" ?></td>
<td class="hr"><?php echo "nota" ?></td>
<td class="hr"><?php echo "fecha" ?></td>
<td class="hr"><?php echo "annio" ?></td>
<td class="hr"><?php echo "corte_sustituido" ?></td>
</tr>
<?php
  for ($i = $startrec; $i < $reccount; $i++)
  {
    $row = mysql_fetch_assoc($res);
    $style = "dr";
    if ($i % 2 != 0) {
      $style = "sr";
    }
?>
<tr>
<td class="<?php echo $style ?>"><a href="inscripciones_nv.php?a=edit&recid=<?php echo $i ?>">Editar</a></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["id"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["id_alumno"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["sede"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["id_seccion"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["id_carrera"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["pensum"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["nivel"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["mencion"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["id_periodo"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["semestre"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["turno"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["id_materia"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["id_docente"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["eval1"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["eval2"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["eval3"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["recuperacion"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["eval4"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["corte_1"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["eval5"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["eval6"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["eval7"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["eval8"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["corte_2"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["eval9"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["eval10"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["eval11"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["eval12"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["corte_3"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["eval13"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["eval14"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["eval15"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["eval16"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["corte_4"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["acumulado"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["nota"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["fecha"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["annio"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["corte_sustituido"]) ?></td>
</tr>
<?php
  }
  mysql_free_result($res);
?>
</table>
<br>
<?php } ?>

<?php function showroweditor($row, $iseditmode)
  {
  global $conn;
?>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="50%">
<tr>
<td class="hr"><?php echo htmlspecialchars("id")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="id" value="<?php echo str_replace('"', '&quot;', trim($row["id"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("id_alumno")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="id_alumno" value="<?php echo str_replace('"', '&quot;', trim($row["id_alumno"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("sede")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="sede" maxlength="7" value="<?php echo str_replace('"', '&quot;', trim($row["sede"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("id_seccion")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="id_seccion" maxlength="1" value="<?php echo str_replace('"', '&quot;', trim($row["id_seccion"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("id_carrera")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="id_carrera" maxlength="5" value="<?php echo str_replace('"', '&quot;', trim($row["id_carrera"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("pensum")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="pensum" maxlength="5" value="<?php echo str_replace('"', '&quot;', trim($row["pensum"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("nivel")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="nivel" maxlength="3" value="<?php echo str_replace('"', '&quot;', trim($row["nivel"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("mencion")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="mencion" maxlength="5" value="<?php echo str_replace('"', '&quot;', trim($row["mencion"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("id_periodo")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="id_periodo" value="<?php echo str_replace('"', '&quot;', trim($row["id_periodo"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("semestre")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="semestre" value="<?php echo str_replace('"', '&quot;', trim($row["semestre"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("turno")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="turno" maxlength="1" value="<?php echo str_replace('"', '&quot;', trim($row["turno"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("id_materia")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="id_materia" maxlength="15" value="<?php echo str_replace('"', '&quot;', trim($row["id_materia"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("id_docente")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="id_docente" value="<?php echo str_replace('"', '&quot;', trim($row["id_docente"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("eval1")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="eval1" value="<?php echo str_replace('"', '&quot;', trim($row["eval1"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("eval2")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="eval2" value="<?php echo str_replace('"', '&quot;', trim($row["eval2"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("eval3")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="eval3" value="<?php echo str_replace('"', '&quot;', trim($row["eval3"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("recuperacion")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="recuperacion" value="<?php echo str_replace('"', '&quot;', trim($row["recuperacion"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("eval4")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="eval4" value="<?php echo str_replace('"', '&quot;', trim($row["eval4"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("corte_1")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="corte_1" value="<?php echo str_replace('"', '&quot;', trim($row["corte_1"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("eval5")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="eval5" value="<?php echo str_replace('"', '&quot;', trim($row["eval5"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("eval6")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="eval6" value="<?php echo str_replace('"', '&quot;', trim($row["eval6"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("eval7")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="eval7" value="<?php echo str_replace('"', '&quot;', trim($row["eval7"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("eval8")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="eval8" value="<?php echo str_replace('"', '&quot;', trim($row["eval8"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("corte_2")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="corte_2" value="<?php echo str_replace('"', '&quot;', trim($row["corte_2"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("eval9")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="eval9" value="<?php echo str_replace('"', '&quot;', trim($row["eval9"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("eval10")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="eval10" value="<?php echo str_replace('"', '&quot;', trim($row["eval10"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("eval11")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="eval11" value="<?php echo str_replace('"', '&quot;', trim($row["eval11"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("eval12")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="eval12" value="<?php echo str_replace('"', '&quot;', trim($row["eval12"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("corte_3")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="corte_3" value="<?php echo str_replace('"', '&quot;', trim($row["corte_3"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("eval13")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="eval13" value="<?php echo str_replace('"', '&quot;', trim($row["eval13"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("eval14")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="eval14" value="<?php echo str_replace('"', '&quot;', trim($row["eval14"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("eval15")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="eval15" value="<?php echo str_replace('"', '&quot;', trim($row["eval15"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("eval16")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="eval16" value="<?php echo str_replace('"', '&quot;', trim($row["eval16"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("corte_4")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="corte_4" value="<?php echo str_replace('"', '&quot;', trim($row["corte_4"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("acumulado")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="acumulado" value="<?php echo str_replace('"', '&quot;', trim($row["acumulado"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("nota")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="nota" value="<?php echo str_replace('"', '&quot;', trim($row["nota"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("fecha")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="fecha" value="<?php echo str_replace('"', '&quot;', trim($row["fecha"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("annio")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="annio" value="<?php echo str_replace('"', '&quot;', trim($row["annio"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("corte_sustituido")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="corte_sustituido" value="<?php echo str_replace('"', '&quot;', trim($row["corte_sustituido"])) ?>"></td>
</tr>
</table>
<?php } ?>

<?php function showpagenav($page, $pagecount)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<?php if ($page > 1) { ?>
<td><a href="inscripciones_nv.php?page=<?php echo $page - 1 ?>">&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="inscripciones_nv.php?page=<?php echo $j ?>"><?php echo $j ?></a></td>
<?php } } } else { ?>
<td><a href="inscripciones_nv.php?page=<?php echo $startpage ?>"><?php echo $startpage ."..." .$count ?></a></td>
<?php } } } ?>
<?php if ($page < $pagecount) { ?>
<td>&nbsp;<a href="inscripciones_nv.php?page=<?php echo $page + 1 ?>">Siguiente&nbsp;&gt;&gt;</a>&nbsp;</td>
<?php } ?>
</tr>
</table>
<?php } ?>

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

<?php function editrec($recid)
{
  $res = sql_select();
  $count = sql_getrecordcount();
  mysql_data_seek($res, $recid);
  $row = mysql_fetch_assoc($res);
  showrecnav("edit", $recid, $count);
?>
<br>
<form enctype="multipart/form-data" action="cargar_corte1.php?periodo=<?php echo $periodo ?>&carrera=<?php echo $carrera ?>&materia=<?php echo $materia ?>&seccion=<?php echo $seccion ?>&sede=<?php echo $sede ?>&profesor=<?php echo $profesor ?>&turno=<?php echo $turno ?>" method="post">
<input type="hidden" name="sql" value="update">
<input type="hidden" name="xid" value="<?php echo $row["id"] ?>">
<?php showroweditor($row, true); ?>
<p><input type="submit" name="action" value="Guardar"></p>
</form>
<?php
  mysql_free_result($res);
} ?>

<?php function connect()
{
  $conn = mysql_connect("localhost", "siga_dbm", "2PN2QDmP6ZsHrcue");
  mysql_select_db("siga_pregrado");
  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()
{
  global $conn;
  $sql = "SELECT `id`, `id_alumno`, `sede`, `id_seccion`, `id_carrera`, `pensum`, `nivel`, `mencion`, `id_periodo`, `semestre`, `turno`, `id_materia`, `id_docente`, `eval1`, `eval2`, `eval3`, `recuperacion`, `eval4`, `corte_1`, `eval5`, `eval6`, `eval7`, `eval8`, `corte_2`, `eval9`, `eval10`, `eval11`, `eval12`, `corte_3`, `eval13`, `eval14`, `eval15`, `eval16`, `corte_4`, `acumulado`, `nota`, `fecha`, `annio`, `corte_sustituido` FROM `inscripciones`";
  $res = mysql_query($sql, $conn) or die(mysql_error());
  return $res;
}

function sql_getrecordcount()
{
  global $conn;
  $sql = "SELECT COUNT(*) FROM `inscripciones`";
  $res = mysql_query($sql, $conn) or die(mysql_error());
  $row = mysql_fetch_assoc($res);
  reset($row);
  return current($row);
}

function sql_update()
{
  global $conn;
  global $_POST;

  $sql = "update `inscripciones` set `id`=" .sqlvalue(@$_POST["id"], false).", `id_alumno`=" .sqlvalue(@$_POST["id_alumno"], false).", `sede`=" .sqlvalue(@$_POST["sede"], true).", `id_seccion`=" .sqlvalue(@$_POST["id_seccion"], true).", `id_carrera`=" .sqlvalue(@$_POST["id_carrera"], true).", `pensum`=" .sqlvalue(@$_POST["pensum"], true).", `nivel`=" .sqlvalue(@$_POST["nivel"], true).", `mencion`=" .sqlvalue(@$_POST["mencion"], true).", `id_periodo`=" .sqlvalue(@$_POST["id_periodo"], false).", `semestre`=" .sqlvalue(@$_POST["semestre"], false).", `turno`=" .sqlvalue(@$_POST["turno"], true).", `id_materia`=" .sqlvalue(@$_POST["id_materia"], true).", `id_docente`=" .sqlvalue(@$_POST["id_docente"], false).", `eval1`=" .sqlvalue(@$_POST["eval1"], false).", `eval2`=" .sqlvalue(@$_POST["eval2"], false).", `eval3`=" .sqlvalue(@$_POST["eval3"], false).", `recuperacion`=" .sqlvalue(@$_POST["recuperacion"], false).", `eval4`=" .sqlvalue(@$_POST["eval4"], false).", `corte_1`=" .sqlvalue(@$_POST["corte_1"], false).", `eval5`=" .sqlvalue(@$_POST["eval5"], false).", `eval6`=" .sqlvalue(@$_POST["eval6"], false).", `eval7`=" .sqlvalue(@$_POST["eval7"], false).", `eval8`=" .sqlvalue(@$_POST["eval8"], false).", `corte_2`=" .sqlvalue(@$_POST["corte_2"], false).", `eval9`=" .sqlvalue(@$_POST["eval9"], false).", `eval10`=" .sqlvalue(@$_POST["eval10"], false).", `eval11`=" .sqlvalue(@$_POST["eval11"], false).", `eval12`=" .sqlvalue(@$_POST["eval12"], false).", `corte_3`=" .sqlvalue(@$_POST["corte_3"], false).", `eval13`=" .sqlvalue(@$_POST["eval13"], false).", `eval14`=" .sqlvalue(@$_POST["eval14"], false).", `eval15`=" .sqlvalue(@$_POST["eval15"], false).", `eval16`=" .sqlvalue(@$_POST["eval16"], false).", `corte_4`=" .sqlvalue(@$_POST["corte_4"], false).", `acumulado`=" .sqlvalue(@$_POST["acumulado"], false).", `nota`=" .sqlvalue(@$_POST["nota"], false).", `fecha`=" .sqlvalue(@$_POST["fecha"], true).", `annio`=" .sqlvalue(@$_POST["annio"], true).", `corte_sustituido`=" .sqlvalue(@$_POST["corte_sustituido"], false) ." where " .primarykeycondition();
  mysql_query($sql, $conn) or die(mysql_error());

$query_acumulado = "SELECT acumulado FROM inscripciones where id_alumno='$id_alumno' AND id_periodo='$periodo' AND id_carrera='$carrera' AND id_materia='$materia' AND id_seccion='$seccion' AND sede='$sede' AND turno='$turno'";
	
$rst_acumulado = mysql_query($query_acumulado, $conn) or die(mysql_error());
$row_acumulado = mysql_fetch_assoc($rst_acumulado);
$corte1=$row_acumulado['corte_1'];
$acumulado=$row_acumulado['acumulado'];

 $acumulado1Dec=round($acumulado,1);
 $acumuladoInt=round($acumulado1Dec);
 $definitiva=1;
		if($acumuladoInt>=1 && $acumuladoInt<=5){
		   $definitiva=1;
		} elseif ($acumuladoInt>=6 && $acumuladoInt<=11){
		   $definitiva=2;
		} elseif ($acumuladoInt>=12 && $acumuladoInt<=17){
		   $definitiva=3;
		} elseif ($acumuladoInt>=18 && $acumuladoInt<=23){
		   $definitiva=4;
		} elseif ($acumuladoInt>=24 && $acumuladoInt<=29){
		   $definitiva=5;
		} elseif ($acumuladoInt>=30 && $acumuladoInt<=34){
		   $definitiva=6;
		} elseif ($acumuladoInt>=35 && $acumuladoInt<=39){
		   $definitiva=7;
		} elseif ($acumuladoInt>=40 && $acumuladoInt<=44){
		   $definitiva=8;
		} elseif ($acumuladoInt>=45 && $acumuladoInt<=49){
		   $definitiva=9;
		} elseif ($acumuladoInt>=50 && $acumuladoInt<=54){
		   $definitiva=10;
		} elseif ($acumuladoInt>=55 && $acumuladoInt<=59){
		   $definitiva=11;
		} elseif ($acumuladoInt>=60 && $acumuladoInt<=64){
		   $definitiva=12;
		} elseif ($acumuladoInt>=65 && $acumuladoInt<=69){
		   $definitiva=13;
		} elseif ($acumuladoInt>=70 && $acumuladoInt<=74){
		   $definitiva=14;
		} elseif ($acumuladoInt>=75 && $acumuladoInt<=79){
		   $definitiva=15;
		} elseif ($acumuladoInt>=80 && $acumuladoInt<=84){
		   $definitiva=16;
		} elseif ($acumuladoInt>=85 && $acumuladoInt<=88){
		   $definitiva=17;
		} elseif ($acumuladoInt>=89 && $acumuladoInt<=92){
		   $definitiva=18;
		} elseif ($acumuladoInt>=93 && $acumuladoInt<=96){
		   $definitiva=19;
		} elseif ($acumuladoInt>=97 && $acumuladoInt<=100){
		   $definitiva=20;
		}
 
 $sql = "update `inscripciones` set nota='$definitiva'  WHERE id_alumno='$id_alumno' AND id_periodo='$periodo' AND id_carrera='$carrera' AND id_materia='$materia' AND id_seccion='$seccion' AND sede='$sede' AND turno='$turno'";
   mysql_query($sql, $conn) or die(mysql_error());
}

function primarykeycondition()
{
  global $_POST;
  $pk = "";
  $pk .= "(`id`";
  if (@$_POST["xid"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xid"], false);
  };
  $pk .= ")";
  return $pk;
}
 ?>
