<?php session_start();
  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>rediteg -- recursos</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>Personal Administrativo y Obrero</h2></td></tr></table>
<?php
  $conn = connect();
  $showrecs = 30;
  $pagerange = 30;

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

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

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

  switch ($a) {
    case "add":
      addrec();
      break;
    case "view":
      viewrec($recid);
      break;
    case "edit":
      editrec($recid);
      break;
    case "del":
      deleterec($recid);
      break;
    default:
      select();
      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()
  {
  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();
  $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: recursos</td></tr>
<tr><td>Registros <?php echo $startrec + 1 ?> - <?php echo $reccount ?> de <?php echo $count ?></td></tr>
</table>
<hr size="1" noshade>
<form action="recursos.php" 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("titulo") ?></option>
<option value="<?php echo "idioma" ?>"<?php if ($filterfield == "idioma") { echo "selected"; } ?>><?php echo htmlspecialchars("idioma") ?></option>
<option value="<?php echo "autor" ?>"<?php if ($filterfield == "autor") { echo "selected"; } ?>><?php echo htmlspecialchars("autor") ?></option>
<option value="<?php echo "autor_secundario" ?>"<?php if ($filterfield == "autor_secundario") { echo "selected"; } ?>><?php echo htmlspecialchars("autor_secundario") ?></option>
<option value="<?php echo "fecha_publicacion" ?>"<?php if ($filterfield == "fecha_publicacion") { echo "selected"; } ?>><?php echo htmlspecialchars("fecha_publicacion") ?></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="recursos.php?a=reset">Quitar Filtro</a></td>
</tr>
</table>
</form>
<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">&nbsp;</td>
<td class="hr">&nbsp;</td>
<td class="hr"><a class="hr" href="recursos.php?order=<?php echo "titulo" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("titulo") ?></a></td>
<td class="hr"><a class="hr" href="recursos.php?order=<?php echo "idioma" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("idioma") ?></a></td>
<td class="hr"><a class="hr" href="recursos.php?order=<?php echo "autor" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("autor") ?></a></td>
<td class="hr"><a class="hr" href="recursos.php?order=<?php echo "autor_secundario" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("autor_secundario") ?></a></td>
<td class="hr"><a class="hr" href="recursos.php?order=<?php echo "fecha_publicacion" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("fecha_publicacion") ?></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 ?>"><a href="recursos.php?a=view&recid=<?php echo $i ?>">Ver</a></td>
<td class="<?php echo $style ?>"><a href="recursos.php?a=edit&recid=<?php echo $i ?>">Editar</a></td>
<td class="<?php echo $style ?>"><a href="recursos.php?a=del&recid=<?php echo $i ?>">Borrar</a></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["titulo"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["idioma"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["autor"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["autor_secundario"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["fecha_publicacion"]) ?></td>
</tr>
<?php
  }
  mysql_free_result($res);
?>
</table>
<br>
<?php } ?>

<?php function showrow($row, $recid)
  {
?>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="50%">
<tr>
<td class="hr"><?php echo htmlspecialchars("titulo")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["titulo"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("idioma")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["idioma"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("autor")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["autor"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("autor_secundario")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["autor_secundario"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("fecha_publicacion")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["fecha_publicacion"]) ?></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("titulo")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="titulo" maxlength="120"><?php echo str_replace('"', '&quot;', trim($row["titulo"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("palabras_claves")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="palabras_claves" maxlength="120"><?php echo str_replace('"', '&quot;', trim($row["palabras_claves"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("resumen")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="resumen" maxlength="250"><?php echo str_replace('"', '&quot;', trim($row["resumen"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("referencia")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="referencia" maxlength="120"><?php echo str_replace('"', '&quot;', trim($row["referencia"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("idioma")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="idioma" maxlength="20" value="<?php echo str_replace('"', '&quot;', trim($row["idioma"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("relacion")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="relacion" maxlength="120"><?php echo str_replace('"', '&quot;', trim($row["relacion"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("descriptores")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="descriptores" maxlength="120"><?php echo str_replace('"', '&quot;', trim($row["descriptores"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("autor")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="autor" maxlength="120"><?php echo str_replace('"', '&quot;', trim($row["autor"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("nota_edicion")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="nota_edicion" maxlength="120"><?php echo str_replace('"', '&quot;', trim($row["nota_edicion"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("autor_secundario")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="autor_secundario" maxlength="120"><?php echo str_replace('"', '&quot;', trim($row["autor_secundario"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("propiedad_intelectual")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="propiedad_intelectual" maxlength="120"><?php echo str_replace('"', '&quot;', trim($row["propiedad_intelectual"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("fecha_publicacion")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="fecha_publicacion" maxlength="120"><?php echo str_replace('"', '&quot;', trim($row["fecha_publicacion"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("tipo_recurso")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="tipo_recurso" maxlength="120"><?php echo str_replace('"', '&quot;', trim($row["tipo_recurso"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("formato")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="formato" maxlength="120"><?php echo str_replace('"', '&quot;', trim($row["formato"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("area_conocimiento")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="area_conocimiento" maxlength="120"><?php echo str_replace('"', '&quot;', trim($row["area_conocimiento"])) ?></textarea></td>
</tr>
</table>
<?php } ?>

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

<?php function addrec()
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="recursos.php">Regresar</a></td>
</tr>
</table>
<hr size="1" noshade>
<form enctype="multipart/form-data" action="recursos.php" method="post">
<p><input type="hidden" name="sql" value="insert"></p>
<?php
$row = array(
  "titulo" => "",
  "palabras_claves" => "",
  "resumen" => "",
  "referencia" => "",
  "idioma" => "",
  "relacion" => "",
  "descriptores" => "",
  "autor" => "",
  "nota_edicion" => "",
  "autor_secundario" => "",
  "propiedad_intelectual" => "",
  "fecha_publicacion" => "",
  "tipo_recurso" => "",
  "formato" => "",
  "area_conocimiento" => "");
showroweditor($row, false);
?>
<p><input type="submit" name="action" value="Guardar"></p>
</form>
<?php } ?>

<?php function viewrec($recid)
{
  $res = sql_select();
  $count = sql_getrecordcount();
  mysql_data_seek($res, $recid);
  $row = mysql_fetch_assoc($res);
  showrecnav("view", $recid, $count);
?>
<br>
<?php showrow($row, $recid) ?>
<br>
<hr size="1" noshade>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="recursos.php?a=add">Agregar </a></td>
<td><a href="recursos.php?a=edit&recid=<?php echo $recid ?>">Editar </a></td>
<td><a href="recursos.php?a=del&recid=<?php echo $recid ?>">Borrar </a></td>
</tr>
</table>
<?php
  mysql_free_result($res);
} ?>

<?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="recursos.php" method="post">
<input type="hidden" name="sql" value="update">
<input type="hidden" name="xidioma" value="<?php echo $row["idioma"] ?>">
<?php showroweditor($row, true); ?>
<p><input type="submit" name="action" value="Guardar"></p>
</form>
<?php
  mysql_free_result($res);
} ?>

<?php function deleterec($recid)
{
  $res = sql_select();
  $count = sql_getrecordcount();
  mysql_data_seek($res, $recid);
  $row = mysql_fetch_assoc($res);
  showrecnav("del", $recid, $count);
?>
<br>
<form action="recursos.php" method="post">
<input type="hidden" name="sql" value="delete">
<input type="hidden" name="xidioma" value="<?php echo $row["idioma"] ?>">
<?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", "rediteg_admin", "rediteg5176");
  mysql_select_db("rediteg");
  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;
  global $order;
  global $ordtype;
  global $filter;
  global $filterfield;
  global $wholeonly;

  $filterstr = sqlstr($filter);
  if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
  $sql = "SELECT `titulo`, `palabras_claves`, `resumen`, `referencia`, `idioma`, `relacion`, `descriptores`, `autor`, `nota_edicion`, `autor_secundario`, `propiedad_intelectual`, `fecha_publicacion`, `tipo_recurso`, `formato`, `area_conocimiento` FROM `recursos`";
  if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
    $sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
  } elseif (isset($filterstr) && $filterstr!='') {
    $sql .= " where (`titulo` like '" .$filterstr ."') or (`idioma` like '" .$filterstr ."') or (`autor` like '" .$filterstr ."') or (`autor_secundario` like '" .$filterstr ."') or (`fecha_publicacion` 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()
{
  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 `recursos`";
  if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
    $sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
  } elseif (isset($filterstr) && $filterstr!='') {
    $sql .= " where (`titulo` like '" .$filterstr ."') or (`idioma` like '" .$filterstr ."') or (`autor` like '" .$filterstr ."') or (`autor_secundario` like '" .$filterstr ."') or (`fecha_publicacion` like '" .$filterstr ."')";
  }
  $res = mysql_query($sql, $conn) or die(mysql_error());
  $row = mysql_fetch_assoc($res);
  reset($row);
  return current($row);
}

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

  $sql = "insert into `recursos` (`titulo`, `palabras_claves`, `resumen`, `referencia`, `idioma`, `relacion`, `descriptores`, `autor`, `nota_edicion`, `autor_secundario`, `propiedad_intelectual`, `fecha_publicacion`, `tipo_recurso`, `formato`, `area_conocimiento`) values (" .sqlvalue(@$_POST["titulo"], true).", " .sqlvalue(@$_POST["palabras_claves"], true).", " .sqlvalue(@$_POST["resumen"], true).", " .sqlvalue(@$_POST["referencia"], true).", " .sqlvalue(@$_POST["idioma"], true).", " .sqlvalue(@$_POST["relacion"], true).", " .sqlvalue(@$_POST["descriptores"], true).", " .sqlvalue(@$_POST["autor"], true).", " .sqlvalue(@$_POST["nota_edicion"], true).", " .sqlvalue(@$_POST["autor_secundario"], true).", " .sqlvalue(@$_POST["propiedad_intelectual"], true).", " .sqlvalue(@$_POST["fecha_publicacion"], true).", " .sqlvalue(@$_POST["tipo_recurso"], true).", " .sqlvalue(@$_POST["formato"], true).", " .sqlvalue(@$_POST["area_conocimiento"], true).")";
  mysql_query($sql, $conn) or die(mysql_error());
}

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

  $sql = "update `recursos` set `titulo`=" .sqlvalue(@$_POST["titulo"], true).", `palabras_claves`=" .sqlvalue(@$_POST["palabras_claves"], true).", `resumen`=" .sqlvalue(@$_POST["resumen"], true).", `referencia`=" .sqlvalue(@$_POST["referencia"], true).", `idioma`=" .sqlvalue(@$_POST["idioma"], true).", `relacion`=" .sqlvalue(@$_POST["relacion"], true).", `descriptores`=" .sqlvalue(@$_POST["descriptores"], true).", `autor`=" .sqlvalue(@$_POST["autor"], true).", `nota_edicion`=" .sqlvalue(@$_POST["nota_edicion"], true).", `autor_secundario`=" .sqlvalue(@$_POST["autor_secundario"], true).", `propiedad_intelectual`=" .sqlvalue(@$_POST["propiedad_intelectual"], true).", `fecha_publicacion`=" .sqlvalue(@$_POST["fecha_publicacion"], true).", `tipo_recurso`=" .sqlvalue(@$_POST["tipo_recurso"], true).", `formato`=" .sqlvalue(@$_POST["formato"], true).", `area_conocimiento`=" .sqlvalue(@$_POST["area_conocimiento"], true) ." where " .primarykeycondition();
  mysql_query($sql, $conn) or die(mysql_error());
}

function sql_delete()
{
  global $conn;

  $sql = "delete from `recursos` where " .primarykeycondition();
  mysql_query($sql, $conn) or die(mysql_error());
}
function primarykeycondition()
{
  global $_POST;
  $pk = "";
  $pk .= "(`idioma`";
  if (@$_POST["xidioma"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xidioma"], true);
  };
  $pk .= ")";
  return $pk;
}
 ?>
