<?php session_start();
if (!isset($_SESSION['MM_Username'])) {
      header ("Location: modulos/inicio/index.php");
	  }
  $nombre=$_GET["nombre"];
  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 -- titulos_alumno</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>T&iacute;tulos del Participante </h2></td>
</tr>
<tr><td><?php echo $nombre ?></td></tr>
</table>
<hr size="1" noshade>

<?php
  $conn = connect();
  $showrecs = 10;
  $pagerange = 10;
  
  $id_alumno=$_GET['id_alumno'];
  $alumVolver=$_GET["alumVolver"];
  $nombre=$_GET["nombre"];

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

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

  switch ($sql) {
    case "insert":
      sql_insert($id_alumno);
      break;
    case "update":
      sql_update($id_alumno);
      break;
    case "delete":
      sql_delete($id_alumno);
      break;
  }

  switch ($a) {
    case "add":
      addrec($alumVolver, $id_alumno, $nombre);
      break;
    case "view":
      viewrec($recid, $id_alumno, $alumVolver, $nombre);
      break;
    case "edit":
      editrec($recid, $id_alumno,$alumVolver,$nombre);
      break;
    case "del":
      deleterec($recid, $id_alumno,$alumVolver,$nombre);
      break;
    default:
      select($id_alumno, $alumVolver, $nombre);
      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);
?>
</td></tr></table>
<table class="bd" width="100%"><tr><td class="hr"></td></tr></table>
</body>
</html>

<?php function select($id_alumno,$alumVolver,$nombre)
  {
  global $a;
  global $showrecs;
  global $page;
  global $filter;
  global $filterfield;
  global $wholeonly;
  global $order;
  global $ordtype;


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

  $checkstr = "";
  if ($wholeonly) $checkstr = " checked";
  if ($ordtype == "asc") { $ordtypestr = "desc"; } else { $ordtypestr = "asc"; }
  $res = sql_select($id_alumno);
  $count = sql_getrecordcount($id_alumno);
  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);
?>

<?php $alumVolver=$_GET["alumVolver"];?>
<?php $nombre=$_GET["nombre"];?>


<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr><td>N&uacute;mero de T&iacute;tulos: <?php echo $startrec + 1 ?> - <?php echo $reccount ?> de <?php echo $count ?></td></tr>
</table>
<hr size="1" noshade>
<form action="titulos_alumno_3.php?nombre=<?php echo $nombre ?>&id_alumno=<?php echo $id_alumno ?>&alumVolver=<?php echo $alumVolver ?>" method="post">
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><b>Filtrar por</b>&nbsp;</td>
<td><input type="text" name="filter" value="<?php echo $filter ?>"></td>
<td><select name="filter_field">
<option value="">Todos los campos</option>
<option value="<?php echo "titulo" ?>"<?php if ($filterfield == "titulo") { echo "selected"; } ?>><?php echo htmlspecialchars("Título") ?></option>
<option value="<?php echo "institucion" ?>"<?php if ($filterfield == "institucion") { echo "selected"; } ?>><?php echo htmlspecialchars("Institución") ?></option>
<option value="<?php echo "annio_egreso" ?>"<?php if ($filterfield == "annio_egreso") { echo "selected"; } ?>><?php echo htmlspecialchars("Año de Egreso") ?></option>
<option value="<?php echo "nivel" ?>"<?php if ($filterfield == "nivel") { echo "selected"; } ?>><?php echo htmlspecialchars("Nivel") ?></option>
</select></td>
<td><input type="checkbox" name="wholeonly"<?php echo $checkstr ?>>Palabra completa</td>
</td></tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="action" value="Aplicar Filtro"></td>
<td><a href="titulos_alumno_3.php?a=reset&nombre=<?php echo $nombre ?>">Quitar Filtro</a></td>
</tr>
</table>
</form>
<hr size="1" noshade>
<?php showpagenav($page, $pagecount, $id_alumno, $alumVolver, $nombre); ?>
<br>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="100%">
<tr>
<td class="hr" align="center">Ver</td>
<td class="hr" align="center"><a class="hr" href="titulos_alumno_3.php?order=<?php echo "id_alumno" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Matrícula") ?></a></td>
<td class="hr" align="center"><a class="hr" href="titulos_alumno_3.php?order=<?php echo "titulo" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Título Obtenido") ?></a></td>
<td class="hr" align="center"><a class="hr" href="titulos_alumno_3.php?order=<?php echo "institucion" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Institución") ?></a></td>
<td class="hr" align="center"><a class="hr" href="titulos_alumno_3.php?order=<?php echo "annio_egreso" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Año de Egreso") ?></a></td>
<td class="hr" align="center"><a class="hr" href="titulos_alumno_3.php?order=<?php echo "nivel" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Nivel") ?></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 class="<?php echo $style ?>" align="center"><a href="titulos_alumno_3.php?a=view&recid=<?php echo $i ?>&alumVolver=<?php echo $alumVolver ?>&id_alumno=<?php echo htmlspecialchars($row["id_alumno"]) ?>&nombre=<?php echo $nombre ?>"><img src="imagenes/search.gif" border="0"</a></td>

<td class="<?php echo $style ?>" align="center"><?php echo htmlspecialchars($row["id_alumno"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["titulo"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["institucion"]) ?></td>
<td class="<?php echo $style ?>" align="center"><?php echo htmlspecialchars($row["annio_egreso"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["nivel"]) ?></td>
</tr>
<?php
  }
  mysql_free_result($res);
?>
</table>
<br>
<?php showpagenav($page, $pagecount, $id_alumno, $alumVolver, $nombre); ?>
<?php } ?>

<?php function showrow($row, $recid, $nombre)
  {
?>
<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("T�tulo Obtenido")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["titulo"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Institucion")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["institucion"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("A�o de Egreso")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["annio_egreso"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Nivel")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["nivel"]) ?></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 disabled="disabled" name="id_alumno" type="text" value="<?php echo str_replace('"', '&quot;', trim($row["id_alumno"])) ?>" size="5" maxlength="5"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("T�tulo Obtenido")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="2" name="titulo"><?php echo str_replace('"', '&quot;', trim($row["titulo"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Institucion")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="2" name="institucion"><?php echo str_replace('"', '&quot;', trim($row["institucion"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("A�o de Egreso")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="annio_egreso" value="<?php echo str_replace('"', '&quot;', trim($row["annio_egreso"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Nivel")."&nbsp;" ?></td>
<td class="dr">
<select name="nivel">
   <option value="<?php echo str_replace('"', '&quot;', trim($row["nivel"])) ?>"><?php echo str_replace('"', '&quot;', trim($row["nivel"])) ?></option>
  <option value="PRE-GRADO">PRE-GRADO</option>
  <option value="POST-GRADO">POST-GRADO</option>
</select>
</td>
</tr>
</table>
<?php } ?>

<?php function showrowadd($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 disabled="disabled" name="id_alumno1" type="text" value="<?php echo str_replace('"', '&quot;', trim($row["id_alumno"])) ?>" size="5" maxlength="5"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("T�tulo Obtenido")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="2" name="titulo" maxlength="90"><?php echo str_replace('"', '&quot;', trim($row["titulo"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Institucion")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="2" name="institucion"><?php echo str_replace('"', '&quot;', trim($row["institucion"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("A�o de Egreso")."&nbsp;" ?></td>
<td class="dr"><input name="annio_egreso" type="text" value="<?php echo str_replace('"', '&quot;', trim($row["annio_egreso"])) ?>" size="4" maxlength="4"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Nivel")."&nbsp;" ?></td>
<td class="dr">
<select name="nivel">
  <option value="PRE-GRADO">PRE-GRADO</option>
  <option value="POST-GRADO">POST-GRADO</option>
</select>

</tr>
</table>
<?php } ?>


<?php function showpagenav($page, $pagecount, $id_alumno,$alumVolver, $nombre)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="alumnos_3.php?a=retorno&recid=<?php echo $alumVolver ?>&id_alumno=<?php echo $id_alumno ?>&nombre=<?php echo $nombre ?>">Regresar</a>&nbsp;</td>

<?php if ($page > 1) { ?>
<td><a href="titulos_alumno_3.php?page=<?php echo $page - 1 ?>&id_alumno=<?php echo $id_alumno ?>">&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="titulos_alumno_3.php?page=<?php echo $j ?>&id_alumno=<?php echo $id_alumno ?>"><?php echo $j ?></a></td>
<?php } } } else { ?>
<td><a href="titulos_alumno_3.php?page=<?php echo $startpage ?>&id_alumno=<?php echo $id_alumno ?>"><?php echo $startpage ."..." .$count ?></a></td>
<?php } } } ?>
<?php if ($page < $pagecount) { ?>
<td>&nbsp;<a href="titulos_alumno_3.php?page=<?php echo $page + 1 ?>&id_alumno=<?php echo $id_alumno ?>">Siguiente&nbsp;&gt;&gt;</a>&nbsp;</td>
<?php } ?>
</tr>
</table>
<?php } ?>

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

<?php function addrec($alumVolver, $id_alumno, $nombre)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="titulos_alumno_3.php?alumVolver=<?php echo $alumVolver ?>&id_alumno=<?php echo $id_alumno ?>&nombre=<?php echo $nombre ?>">Regresar</a></td>
</tr>
</table>
<hr size="1" noshade>
<form enctype="multipart/form-data" action="titulos_alumno_3.php?recid=<?php echo $alumVolver ?>&id_alumno=<?php echo $id_alumno ?>&nombre=<?php echo $nombre ?>" method="post">
<p><input type="hidden" name="sql" value="insert"></p>
<?php
$row = array(
  "id_alumno" => "$id_alumno",
  "titulo" => "",
  "institucion" => "",
  "annio_egreso" => "",
  "nivel" => "");
showrowadd($row, false);
?>
<p><input type="submit" name="action" value="Guardar"></p>
</form>
<?php } ?>

<?php function viewrec($recid, $id_alumno, $alumVolver, $nombre)
{
  $res = sql_select($id_alumno);
  $count = sql_getrecordcount($id_alumno);
  mysql_data_seek($res, $recid);
  $row = mysql_fetch_assoc($res);
  showrecnav("view", $recid, $count, $id_alumno, $alumVolver, $nombre);
?>
<br>
<?php showrow($row, $recid, $nombre) ?>
<br>
<hr size="1" noshade>

<?php
  mysql_free_result($res);
} ?>

<?php function editrec($recid, $id_alumno, $alumVolver, $nombre)
{
  $res = sql_select($id_alumno);
  $count = sql_getrecordcount($id_alumno);
  mysql_data_seek($res, $recid);
  $row = mysql_fetch_assoc($res);
  showrecnav("edit", $recid, $count, $id_alumno, $alumVolver,$nombre);
?>
<br>
<form enctype="multipart/form-data" action="titulos_alumno_3.php?recid=<?php echo $recid ?>&alumVolver=<?php echo $alumVolver ?>&id_alumno=<?php echo $id_alumno ?>" method="post">
<input type="hidden" name="sql" value="update">
<input type="hidden" name="xid_alumno" value="<?php echo $row["id_alumno"] ?>">
<input type="hidden" name="xannio_egreso" value="<?php echo $row["annio_egreso"] ?>">
<input type="hidden" name="xnivel" value="<?php echo $row["nivel"] ?>">
<?php showroweditor($row, true); ?>
<p><input type="submit" name="action" value="Guardar Cambios"></p>
</form>
<?php
  mysql_free_result($res);
} ?>

<?php function deleterec($recid,$id_alumno,$alumVolver, $nombre)
{
  $res = sql_select($id_alumno);
  $count = sql_getrecordcount($id_alumno);
  mysql_data_seek($res, $recid);
  $row = mysql_fetch_assoc($res);
  showrecnav("del", $recid, $count, $id_alumno, $alumVolver, $nombre);
?>
<br>
<form action="titulos_alumno_3.php?recid=<?php echo $recid ?>&alumVolver=<?php echo $alumVolver ?>&id_alumno=<?php echo $id_alumno ?>&nombre=<?php echo $nombre ?>" 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="xannio_egreso" value="<?php echo $row["annio_egreso"] ?>">
<input type="hidden" name="xnivel" value="<?php echo $row["nivel"] ?>">
<?php showrow($row, $recid, $nombre) ?>
<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");
  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($id_alumno)
{
  global $conn;
  global $order;
  global $ordtype;
  global $filter;
  global $filterfield;
  global $wholeonly;

  $filterstr = sqlstr($filter);
  mysql_query ("SET NAMES 'utf8'");
  if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
  $sql = "SELECT `id_alumno`, `titulo`, `institucion`, `annio_egreso`, `nivel` FROM `titulos_alumno` WHERE `id_alumno`='$id_alumno' ";
  if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
    $sql .= "  and  " .sqlstr($filterfield) ." like '" .$filterstr ."'";
  } elseif (isset($filterstr) && $filterstr!='') {
    $sql .= " and ((`titulo` like '" .$filterstr ."') or (`institucion` like '" .$filterstr ."') or (`annio_egreso` like '" .$filterstr ."') or (`nivel` like '" .$filterstr ."'))";
  }
  if (isset($order) && $order!='') $sql .= " order by `" .sqlstr($order) ."`";
  if (isset($ordtype) && $ordtype!='') $sql .= " " .sqlstr($ordtype);
  $res = mysql_query($sql, $conn) or die(mysql_error());
  return $res;
}

function sql_getrecordcount($id_alumno)
{
  global $conn;
  global $order;
  global $ordtype;
  global $filter;
  global $filterfield;
  global $wholeonly;

  $filterstr = sqlstr($filter);
   mysql_query ("SET NAMES 'utf8'");
  if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
  $sql = "SELECT COUNT(*) FROM `titulos_alumno` WHERE `id_alumno`='$id_alumno'";
  if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
    $sql .= " and " .sqlstr($filterfield) ." like '" .$filterstr ."'";
  } elseif (isset($filterstr) && $filterstr!='') {
    $sql .= " and (`id_alumno` like '" .$filterstr ."') or (`titulo` like '" .$filterstr ."') or (`institucion` like '" .$filterstr ."') or (`annio_egreso` like '" .$filterstr ."') or (`nivel` like '" .$filterstr ."')";
  }
  $res = mysql_query($sql, $conn) or die(mysql_error());
  $row = mysql_fetch_assoc($res);
  reset($row);
  return current($row);
}

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

  $sql = "insert into `titulos_alumno` (`id_alumno`, `titulo`, `institucion`, `annio_egreso`, `nivel`) values (" .sqlvalue($id_alumno, false).", " .sqlvalue(@$_POST["titulo"], true).", " .sqlvalue(@$_POST["institucion"], true).", " .sqlvalue(@$_POST["annio_egreso"], true).", " .sqlvalue(@$_POST["nivel"], true).")";
  mysql_query($sql, $conn) or die(mysql_error());
}

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

  $sql = "update `titulos_alumno` set `titulo`=" .sqlvalue(@$_POST["titulo"], true).", `institucion`=" .sqlvalue(@$_POST["institucion"], true).", `annio_egreso`=" .sqlvalue(@$_POST["annio_egreso"], true).", `nivel`=" .sqlvalue(@$_POST["nivel"], true) ." where " .primarykeycondition();
  mysql_query($sql, $conn) or die(mysql_error());
}

function sql_delete()
{
  global $conn;

  $sql = "delete from `titulos_alumno` where " .primarykeycondition();
  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 .= "(`annio_egreso`";
  if (@$_POST["xannio_egreso"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xannio_egreso"], true);
  };
  $pk .= ") and ";
  $pk .= "(`nivel`";
  if (@$_POST["xnivel"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xnivel"], true);
  };
  $pk .= ")";
  return $pk;
}
 ?>
