<?php require_once('Connections/conn.php'); ?><?php session_start();
  if (!isset($_SESSION['MM_Username'])) {
      header ("Location: modulos/inicio/index.php");
	  }
  if (isset($_GET["order"])) $order = @$_GET["order"];
  if (isset($_GET["type"])) $ordtype = @$_GET["type"];

  if (isset($_POST["filter"])) $filter = @$_POST["filter"];
  if (isset($_POST["filter_field"])) $filterfield = @$_POST["filter_field"];
  $wholeonly = false;
  if (isset($_POST["wholeonly"])) $wholeonly = @$_POST["wholeonly"];

  if (!isset($order) && isset($_SESSION["order"])) $order = $_SESSION["order"];
  if (!isset($ordtype) && isset($_SESSION["type"])) $ordtype = $_SESSION["type"];
  if (!isset($filter) && isset($_SESSION["filter"])) $filter = $_SESSION["filter"];
  if (!isset($filterfield) && isset($_SESSION["filter_field"])) $filterfield = $_SESSION["filter_field"];
 
?>

<html>
<head>
<title>sadce -- inscripciones</title>
<meta name="generator" http-equiv="content-type" content="text/html">
<style type="text/css">
  body {
    background-color: #FFFFFF;
    color: #004080;
    font-family: Arial;
    font-size: 12px;
  }
  .bd {
    background-color: #FFFFFF;
    color: #004080;
    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>Inscripci&oacute;n de Participantes </h2></td></tr></table>
<?php
  $conn = connect();
  $showrecs = 20;
  $pagerange = 10;

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

  $sql = @$_POST["sql"];
  // Captura las variables que vienen de cargar1.php.
 
  $periodo=$_GET["periodo"];
  $seccion=$_GET["seccion"];
  $sede=$_GET["sede"];
  $materia=$_GET["materia"];
  $carrera=$_GET["carrera"];
 
  switch ($sql) {
    
    case "update":
      sql_update();
      break;
	  
	case "insert":
      sql_insert();
      break;  
   
	  }

  switch ($a) {
    case "add":
      addrec( $periodo, $seccion, $sede, $materia, $carrera);
      break;
    case "view":
      viewrec($recid,  $periodo, $seccion, $sede, $materia, $carrera);
      break;
	 case "edit":
      viewrec($recid,  $periodo, $seccion, $sede, $materia, $carrera);
      break; 
    default:
      select( $periodo, $seccion, $sede, $materia, $carrera);
      break;
  }

  if (isset($order)) $_SESSION["order"] = $order;
  if (isset($ordtype)) $_SESSION["type"] = $ordtype;
  if (isset($filter)) $_SESSION["filter"] = $filter;
  if (isset($filterfield)) $_SESSION["filter_field"] = $filterfield;
  if (isset($wholeonly)) $_SESSION["wholeonly"] = $wholeonly;

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

<?php



 function select($periodo, $seccion, $sede, $materia, $carrera)
  {
  
  global $conn;
  global $a;
  global $showrecs;
  global $page;
  global $filter;
  global $filterfield;
  global $wholeonly;
  global $order;
  global $ordtype;

  //Busco el nombre de la materia
$conn=connect();

mysql_select_db($database_conn, $conn);
$query_rs_materias = "SELECT materias.nombre_materia FROM materias WHERE id_materia='$materia'";
$rs_materias = mysql_query($query_rs_materias, $conn) or die(mysql_error());
$row_rs_materias = mysql_fetch_assoc($rs_materias);
$totalRows_rs_materias = mysql_num_rows($rs_materias);

$query_sede = "SELECT nombre_sede FROM sedes WHERE codigo='$sede'";
$rs_sede = mysql_query($query_sede, $conn) or die(mysql_error());
$row_sede = mysql_fetch_assoc($rs_sede);
$totalRows_sede = mysql_num_rows($rs_sede);

$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);


 
  if ($a == "reset") {
    $filter = "";
    $filterfield = "";
    $wholeonly = "";
    $order = "";
    $ordtype = "";
  }

  $checkstr = "";
  if ($wholeonly) $checkstr = " checked";
  if ($ordtype == "asc") { $ordtypestr = "desc"; } else { $ordtypestr = "asc"; }
  $res = sql_select($periodo, $seccion, $sede, $materia, $carrera);
  $count = sql_getrecordcount($periodo, $seccion, $sede, $materia, $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);
?>
<table class="bd" border="0" cellspacing="1" cellpadding="2">
<tr>
   <td><b>CARRERA:</b></td>
   <td><?php echo $row_carrera['nombre_carrera']; ?></td>
</tr>

<tr>
   <td><b>MATERIA:</b></td>
   <td><?php echo $row_rs_materias['nombre_materia']; ?></td>
</tr>
<tr>
<td colspan="2"><b>SECCION:</b> <?php echo $seccion; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>PERIODO:</b> <?php echo $periodo; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>SEDE:</b> <?php echo $row_sede['nombre_sede']; ?></td>
</tr>
<tr>
<td colspan="2"><b>FACILITADOR:</b> <?php echo $row_rs_docentes['apellidos'].' '.$row_rs_docentes['nombres']?></td>
</tr>
<tr>
<td align="right" colspan="2">N&uacute;mero de Inscritos: <?php echo $count ?></td>
</tr>
</table>
<hr size="1" noshade>
<?php showpagenav($page, $pagecount, $periodo,$seccion,$sede,$materia,$carrera); ?>

<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="100%">
<tr>
<td align="center" class="hr">Modificar</td>
<td align="center" class="hr"><a class="hr" href="cargar_historico.php?order=<?php echo "id_alumno" ?>&type=<?php echo $ordtypestr ?>&periodo=<?php echo $periodo ?>&seccion=<?php echo $seccion ?>&sede=<?php echo $sede ?>&materia=<?php echo $materia ?>&carrera=<?php echo $carrera ?>"><?php echo htmlspecialchars("Matr�cula") ?></a></td>
<td align="center" class="hr"><a class="hr" href="cargar_historico.php?order=<?php echo "cedula" ?>&type=<?php echo $ordtypestr ?>&periodo=<?php echo $periodo ?>&seccion=<?php echo $seccion ?>&sede=<?php echo $sede ?>&materia=<?php echo $materia ?>&carrera=<?php echo $carrera ?>"><?php echo htmlspecialchars("Documento Id") ?></a></td>
<td align="center" class="hr"><a class="hr" href="cargar_historico.php?order=<?php echo "apellidos" ?>&type=<?php echo $ordtypestr ?>&periodo=<?php echo $periodo ?>&seccion=<?php echo $seccion ?>&sede=<?php echo $sede ?>&materia=<?php echo $materia ?>&carrera=<?php echo $carrera ?>"><?php echo htmlspecialchars("Apellidos") ?></a></td>
<td align="center" class="hr"><a class="hr" href="cargar_historico.php?order=<?php echo "nombres" ?>&type=<?php echo $ordtypestr ?>&periodo=<?php echo $periodo ?>&seccion=<?php echo $seccion ?>&sede=<?php echo $sede ?>&materia=<?php echo $materia ?>&carrera=<?php echo $carrera ?>"><?php echo htmlspecialchars("Nombres") ?></a></td>
<td align="center" class="hr"><a class="hr" href="cargar_historico.php?order=<?php echo "nota" ?>&type=<?php echo $ordtypestr ?>&periodo=<?php echo $periodo ?>&seccion=<?php echo $seccion ?>&sede=<?php echo $sede ?>&materia=<?php echo $materia ?>&carrera=<?php echo $carrera ?>"><?php echo htmlspecialchars("Nota") ?></a></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="cargar_historico.php?a=view&recid=<?php echo $i ?>&periodo=<?php echo $periodo ?>&seccion=<?php echo $seccion ?>&sede=<?php echo $sede ?>&materia=<?php echo $materia ?>&carrera=<?php echo $carrera ?>"><img src="imagenes/edit.gif" border="0" ></a></td>

<td align="center" class="<?php echo $style ?>"><?php echo htmlspecialchars($row["id_alumno"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["cedula"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["apellidos"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["nombres"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["nota"]) ?></td>
</tr>
<?php
  }
  mysql_free_result($res);
?>
</table>
<br>
<?php showpagenav($page, $pagecount,$periodo,$seccion,$sede,$materia,$carrera); ?>
<?php } ?>

<?php function showrow($row, $recid)
  {
?>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="50%">
<tr>
<td class="hr"><?php echo htmlspecialchars("Matr�cula")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["id_alumno"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Documento Id")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["cedula"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Apellidos")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["apellidos"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Nombres")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["nombres"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Per�odo")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["periodo"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Carrera")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["id_carrera"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Materia")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["id_materia"]) ?></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("Calificaci�n")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["nota"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Sede")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["sede"]) ?></td>
</tr>

</table>
<?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("Matr�cula")."&nbsp;" ?></td>
<td class="dr"><input readonly="true" type="text" name="id_alumno" value="<?php echo str_replace('"', '&quot;', trim($row["id_alumno"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Documento Id")."&nbsp;" ?></td>
<td class="dr"><input readonly="true"  type="text" name="docid" maxlength="10" value="<?php echo str_replace('"', '&quot;', trim($row["cedula"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Apellidos")."&nbsp;" ?></td>
<td class="dr"><input readonly="true"  type="text" name="apellidos" maxlength="10" value="<?php echo str_replace('"', '&quot;', trim($row["apellidos"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Nombres")."&nbsp;" ?></td>
<td class="dr"><input readonly="true"  type="text" name="nombres" maxlength="10" value="<?php echo str_replace('"', '&quot;', trim($row["nombres"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Per�odo")."&nbsp;" ?></td>
<td class="dr"><input readonly="true" type="text" name="periodo" maxlength="10" value="<?php echo str_replace('"', '&quot;', trim($row["periodo"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Carrera")."&nbsp;" ?></td>
<td class="dr"><input readonly="true" 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("Materia")."&nbsp;" ?></td>
<td class="dr"><input readonly="true" 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("Secci�n")."&nbsp;" ?></td>
<td class="dr"><input readonly="true" type="text" name="seccion" maxlength="10" value="<?php echo str_replace('"', '&quot;', trim($row["seccion"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Sede")."&nbsp;" ?></td>
<td class="dr"><input readonly="true" type="text" name="sede" maxlength="2" value="<?php echo str_replace('"', '&quot;', trim($row["sede"])) ?>"></td>
</tr>

<tr>
<td class="hr"><?php echo htmlspecialchars("Calificaci�n")."&nbsp;" ?></td>
<td class="dr">
<input name="nota" type="text" value="<?php echo str_replace('"', '&quot;', trim($row["nota"])) ?>" onKeyUp="mascara(this,'.',patron1,true)" maxlength="4" size="4" >
</td>
</tr>
</table>
<?php } ?>

<?php function showrowadd($row, $iseditmode)
  {
  global $conn;
  $conn=connect();
  
  
$id_carrera=$row['id_carrera'];
mysql_select_db($database_conn, $conn);
$query_rstAlumnos = "Select
carreras_alumno.id_alumno,
alumnos.apellidos,
alumnos.nombres
From
carreras_alumno
Inner Join alumnos ON alumnos.id_alumno = carreras_alumno.id_alumno
Where
carreras_alumno.cod_carrera = '$id_carrera' ORDER BY apellidos,nombres";
//SELECT alumnos.apellidos, alumnos.nombres, alumnos.id_alumno FROM alumnos ORDER BY apellidos,nombres";
$rstAlumnos = mysql_query($query_rstAlumnos, $conn) or die(mysql_error());
$row_rstAlumnos = mysql_fetch_assoc($rstAlumnos);
$totalRows_rstAlumnos = mysql_num_rows($rstAlumnos);
onLoad="document.getElementById('id_alumno').focus()";
?>

<table class="tbl" border="0" cellspacing="1" cellpadding="5" width="50%">
<tr>
<td class="hr"><?php echo htmlspecialchars("Alumno")."&nbsp;" ?></td>
<td class="dr">

<select tabindex="1" id="id_alumno" name="id_alumno" onBlur="verificar_historico(this.value, document.addNota.id_carrera.value, document.addNota.id_materia.value,document.addNota.periodo.value)">
   <option value="0">Seleccione...</option>
  <?php
do {  
?>
  <option  value="<?php echo $row_rstAlumnos['id_alumno']?>"><?php echo $row_rstAlumnos['apellidos']?>, <?php echo $row_rstAlumnos['nombres']?></option>
  <?php
} while ($row_rstAlumnos = mysql_fetch_assoc($rstAlumnos));
  $rows = mysql_num_rows($rstAlumnos);
  if($rows > 0) {
      mysql_data_seek($rstAlumnos, 0);
	  $row_rstAlumnos = mysql_fetch_assoc($rstAlumnos);
  }
?></select>
<iframe name="frameHistorico" id="frameHistorico" with="0" height="0" frameborder="0" ></iframe>
</td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Calificaci�n")."&nbsp;" ?></td>
<td class="dr">
<input  tabindex="2" name="nota" type="text" 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("Docente")."&nbsp;" ?></td>
<td class="dr"><input disabled="disabled" type="text" name="id_docente" maxlength="10" value="<?php echo str_replace('"', '&quot;', trim($row["id_docente"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Per�odo")."&nbsp;" ?></td>
<td class="dr"><input disabled="disabled" type="text" name="periodo" maxlength="10" value="<?php echo str_replace('"', '&quot;', trim($row["periodo"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Secci�n")."&nbsp;" ?></td>
<td class="dr"><input disabled="disabled" type="text" name="seccion" maxlength="10" value="<?php echo str_replace('"', '&quot;', trim($row["seccion"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Sede")."&nbsp;" ?></td>
<td class="dr"><input disabled="disabled" type="text" name="sede" maxlength="2" value="<?php echo str_replace('"', '&quot;', trim($row["sede"])) ?>"></td>
</tr>

<tr>
<td class="hr"><?php echo htmlspecialchars("Carrera")."&nbsp;" ?></td>
<td class="dr"><input disabled="disabled" 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("Materia")."&nbsp;" ?></td>
<td class="dr"><input disabled="disabled" type="text" name="id_materia" maxlength="15" value="<?php echo str_replace('"', '&quot;', trim($row["id_materia"])) ?>"></td>
</tr>

</table>
<?php
mysql_free_result($rstAlumnos);
 } ?>



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

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


<?php function addrec($periodo,$seccion,$sede,$materia,$carrera)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="cargar_historico.php?periodo=<?php echo $periodo ?>&seccion=<?php echo $seccion ?>&sede=<?php echo $sede ?>&materia=<?php echo $materia ?>&carrera=<?php echo $carrera ?>">Regresar</a></td>
</tr>
</table>
<hr size="1" noshade>
<form name="addNota" id="addNota" enctype="multipart/form-data" action="cargar_historico.php?periodo=<?php echo $periodo ?>&seccion=<?php echo $seccion ?>&sede=<?php echo $sede ?>&materia=<?php echo $materia ?>&carrera=<?php echo $carrera ?>" method="post" onSubmit="return validar_datos1()">
<p><input type="hidden" name="sql" value="insert"></p>
<p><input type="hidden" name="yid_carrera" value="<?php echo $carrera ?>"></p>
<p><input type="hidden" name="yid_materia" value="<?php echo $materia ?>"></p>
<p><input type="hidden" name="yid_sede" value="<?php echo $sede ?>"></p>
<p><input type="hidden" name="yid_seccion" value="<?php echo $seccion ?>"></p>
<p><input type="hidden" name="yid_periodo" value="<?php echo $periodo ?>"></p>
<?php
$row = array(
  "id_alumno" => "",
  "id_carrera" => "$carrera",
  "id_materia" => "$materia",
  "nota" => "",
  "id_seccion" => "$seccion",
  "id_periodo" => "$periodo",
  "sede" => "$sede");
showrowadd($row, false);
?>
<p><input type="submit" name="action" value="Guardar"></p>
</form>
<?php } ?>



<?php function viewrec($recid, $periodo, $seccion, $sede, $materia, $carrera)
{
   
  $res = sql_select($periodo, $seccion, $sede, $materia, $carrera);
  $count = sql_getrecordcount($periodo, $seccion, $sede, $materia, $carrera);
  mysql_data_seek($res, $recid);
  $row = mysql_fetch_assoc($res);
  showrecnav("edit", $recid, $count, $periodo, $seccion, $sede, $materia, $carrera);
?>
<br>
<form name="editarNota" id="editarNota" enctype="multipart/form-data" action="cargar_historico.php?periodo=<?php echo $periodo ?>&seccion=<?php echo $seccion ?>&sede=<?php echo $sede ?>&materia=<?php echo $materia ?>&carrera=<?php echo $carrera ?>" method="post" onSubmit="return validar_datos()">
<input type="hidden" name="sql" value="update">
<input type="hidden" name="xid_alumno" value="<?php echo $row["id_alumno"] ?>">
<input type="hidden" name="xperiodo" value="<?php echo $row["periodo"] ?>">
<input type="hidden" name="xseccion" value="<?php echo $row["seccion"] ?>">
<?php showroweditor($row, true); ?>
<p><input type="submit" name="action" value="Modificar Nota"></p>
</form>
<?php
  mysql_free_result($res);
} ?>

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


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

function sql_select($periodo, $seccion, $sede, $materia, $carrera)
{
  global $conn;
  global $order;
  global $ordtype;
  global $filter;
  global $filterfield;
  global $wholeonly;
  
  $filterstr = sqlstr($filter);
  if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
  $sql = "SELECT * FROM (Select inscripciones.id_alumno, alumnos.cedula, alumnos.apellidos, alumnos.nombres, inscripciones.id_periodo, inscripciones.id_carrera, inscripciones.id_materia, inscripciones.id_seccion, inscripciones.nota, inscripciones.sede, inscripciones.id_docente From alumnos Inner Join inscripciones ON alumnos.id_alumno = inscripciones.id_alumno) subq WHERE  id_periodo='$periodo' and id_seccion='$seccion' and sede='$sede' and id_materia='$materia' and id_carrera='$carrera' ORDER BY apellidos,nombres";
  $res = mysql_query($sql, $conn) or die(mysql_error());
  return $res;
}

function sql_getrecordcount($periodo, $seccion, $sede, $materia, $carrera)
{
  global $conn;
  global $order;
  global $ordtype;
  global $filter;
  global $filterfield;
  global $wholeonly;
  $filterstr = sqlstr($filter);
  if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
  $sql = "SELECT COUNT(*) FROM (Select inscripciones.id_alumno, alumnos.cedula, alumnos.apellidos, alumnos.nombres, inscripciones.id_periodo, inscripciones.id_carrera, inscripciones.id_materia, inscripciones.id_seccion, inscripciones.nota, inscripciones.sede,  inscripciones.id_docente From alumnos Inner Join inscripciones ON alumnos.id_alumno = inscripciones.id_alumno) subq WHERE id_periodo='$periodo' and id_seccion='$seccion' and sede='$sede' and id_materia='$materia' and id_carrera='$carrera' ORDER BY apellidos,nombres";
  $res = mysql_query($sql, $conn) or die(mysql_error());
  $row = mysql_fetch_assoc($res);
  reset($row);
  return current($row);
} ?>

<?php
function sql_update()
{
  global $conn;
  global $_POST;

  $sql = "update `inscripciones` set `nota`=" .sqlvalue(@$_POST["nota"], false) ." where " .primarykeycondition();
  mysql_query($sql, $conn) or die(mysql_error());
}

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

  $sql = "insert into `inscripciones` (`id_alumno`, `id_carrera`, `id_materia`, `id_docente`, `nota`, `seccion`, `periodo`, `sede`, `annio`) values (" .sqlvalue(@$_POST["id_alumno"], false).", " .sqlvalue(@$_POST["yid_carrera"], true).", " .sqlvalue(@$_POST["yid_materia"], true).", " .sqlvalue(@$_POST["yid_docente"], false).", " .sqlvalue(@$_POST["nota"], false).", " .sqlvalue(@$_POST["yid_seccion"], true).", " .sqlvalue(@$_POST["yid_periodo"], true).", " .sqlvalue(@$_POST["yid_sede"], true).", " .sqlvalue(@$_POST["annio"], true).")";
  mysql_query($sql, $conn) or die(mysql_error());
}


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

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 .= "(`periodo`";
  if (@$_POST["xperiodo"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xperiodo"], true);
  };
  $pk .= ") and ";
  $pk .= "(`seccion`";
  if (@$_POST["xseccion"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xseccion"], 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_datos()
{
  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>

<script type="text/javascript">

function validar_datos1()
{

  if(document.addNota.id_alumno.value==0){
	alert("El campo <<Alumno>> es obligatorio");
	document.addNota.id_alumno.focus();
	return false;
	}

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

</script>

<script type="text/javascript">
function verificar_historico(alumno,carrera,materia,periodo)
{
 	if (alumno!="")
	 {
	 url="validar_historico.php?id_alumno="+alumno+"&id_carrera="+carrera+"&id_materia="+materia+"&periodo="+periodo;
	 frameHistorico.location=url;
	 }
}
</script>
