<?php require_once('Connections/cn.php'); ?>
<?php session_start();
  if (!isset($_SESSION['MM_Username'])) {
      header ("Location: modulos/inicio/index.php");
	  }
	  
// Captura la datos del usuario que se logueó (Cédula, Tipo de Usuario y Username).
$cedula_usuario=$_SESSION['CEDULA_USUARIO'];
$username=$_SESSION['MM_Username'];
$tipo_usuario=$_SESSION['PRIVILEGIO']; 

// Captura la cédula del docente a quien se le cargará la información.
$cedula_docente=$_GET["cedula_docente"];
if(empty($cedula_docente)){
   $cedula_docente=$cedula_usuario;
}   

mysql_select_db($database_cn, $cn);
mysql_query ("SET NAMES 'utf8'");

//para tomar el id del alumno
$sqlx = "SELECT id_docente,cedula,apellidos, nombres FROM docentes where cedula='$cedula_docente'";
$rsx = mysql_query($sqlx, $cn) or die(mysql_error());
$rowx = mysql_fetch_assoc($rsx);
$id_docente= $rowx['id_docente'];
$cedula= $rowx['cedula'];
$apellidos= $rowx['apellidos'];
$nombres= $rowx['nombres'];

  if (isset($_GET["order"])) $order = @$_GET["order"];
  if (isset($_GET["type"])) $ordtype = @$_GET["type"];

  if (!isset($order) && isset($_SESSION["order"])) $order = $_SESSION["order"];
  if (!isset($ordtype) && isset($_SESSION["type"])) $ordtype = $_SESSION["type"];

?>

<html>
<head>
<title>enaph_siace -- experiencia_docente</title>
<meta 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;
  }
   .bd1 {
    background-color: #FFFFFF;
    color: #004080;
    font-family: Arial;
    font-size: 14px;
  }
  .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>Experiencia Docente</h2></tr></table>
<table  class="bd" width="100%"><tr><td>(Experiencia como docente que ha tenido)</td></tr></table>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr><td class="bd1"><b>DOCENTE:</b>&nbsp;&nbsp;<?php echo $apellidos ?>,&nbsp;<?php echo $nombres ?></td></tr>
</table>
<?php
  require_once('Connections/conn.php');
  mysql_select_db("siga_pregrado");
  mysql_query ("SET NAMES 'utf8'");
  
  $showrecs = 100;
  $pagerange = 100;

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

  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;
  global $order;
  global $ordtype;
  global $cedula_docente;
  global $conn;


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

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

<hr size="1" noshade>
<?php showpagenav($page, $pagecount); ?>
<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">Editar</td>
<td class="hr" align="center">Borrar</td>
<td class="hr" align="center"><a class="hr" href="experiencia_docente.php?order=<?php echo "institucion" ?>&type=<?php echo $ordtypestr ?>&cedula_docente=<?php echo $cedula_docente; ?>"><?php echo htmlspecialchars("Institución") ?></a></td>
<td class="hr" align="center"><a class="hr" href="experiencia_docente.php?order=<?php echo "nivel" ?>&type=<?php echo $ordtypestr ?>&cedula_docente=<?php echo $cedula_docente; ?>"><?php echo htmlspecialchars("Nivel") ?></a></td>
<td class="hr" align="center"><a class="hr" href="experiencia_docente.php?order=<?php echo "categoria" ?>&type=<?php echo $ordtypestr ?>&cedula_docente=<?php echo $cedula_docente; ?>"><?php echo htmlspecialchars("Categoria") ?></a></td>
<td class="hr" align="center"><a class="hr" href="experiencia_docente.php?order=<?php echo "area" ?>&type=<?php echo $ordtypestr ?>&cedula_docente=<?php echo $cedula_docente; ?>"><?php echo htmlspecialchars("Area de Conocimiento") ?></a></td>
<td class="hr" align="center"><a class="hr" href="experiencia_docente.php?order=<?php echo "desde" ?>&type=<?php echo $ordtypestr ?>&cedula_docente=<?php echo $cedula_docente; ?>"><?php echo htmlspecialchars("Desde") ?></a></td>
<td class="hr" align="center"><a class="hr" href="experiencia_docente.php?order=<?php echo "hasta" ?>&type=<?php echo $ordtypestr ?>&cedula_docente=<?php echo $cedula_docente; ?>"><?php echo htmlspecialchars("Hasta") ?></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="experiencia_docente.php?a=view&recid=<?php echo $i ?>&cedula_docente=<?php echo $cedula_docente; ?>"><img src="imagenes/search.gif" border="0"> </a></td>
<td class="<?php echo $style ?>" align="center"><a href="experiencia_docente.php?a=edit&recid=<?php echo $i ?>&cedula_docente=<?php echo $cedula_docente; ?>"><img src="imagenes/edit.gif" border="0" ></a></td>
<td class="<?php echo $style ?>" align="center"><a href="experiencia_docente.php?a=del&recid=<?php echo $i ?>&cedula_docente=<?php echo $cedula_docente; ?>"><img src="imagenes/delete.png" border="0" ></a></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["institucion"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["nivel"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["categoria"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["area"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["desde"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["hasta"]) ?></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="80%">
<tr>
<td class="hr"><?php echo htmlspecialchars("Institución")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["institucion"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Nivel")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["nivel"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Categoría")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["categoria"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Area de Conocimiento")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["area"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Desde")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["desde"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Hasta")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["hasta"]) ?></td>
</tr>
</table>
<?php } ?>

<?php function showroweditor($row, $iseditmode)
  {
  global $conn;
  
  $categoria = str_replace('"', '&quot;', trim($row["categoria"]));
  $query_rstCat1 = "SELECT * FROM categoria WHERE categoria.codigo='$categoria'";
  $rstCat1 = mysql_query($query_rstCat1, $conn) or die(mysql_error());
  $row_rstCat1 = mysql_fetch_assoc($rstCat1);
  $totalRows_rstCat1 = mysql_num_rows($rstCat1);
 
  $query_rstCat = "SELECT * FROM categoria";
  $rstCat = mysql_query($query_rstCat, $conn) or die(mysql_error());
  $row_rstCat= mysql_fetch_assoc($rstCat);
  $totalRows_rstCat = mysql_num_rows($rstCat);
  
?>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="50%">
<tr>
<td class="hr"><?php echo htmlspecialchars("Institución")."&nbsp;" ?></td>
<td class="dr"><input onKeyUp="this.value=this.value.toUpperCase();" name="institucion" type="text" value="<?php echo str_replace('"', '&quot;', trim($row["institucion"])) ?>" size="50" maxlength="50"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Nivel")."&nbsp;" ?></td>
<td class="dr">
<select name="nivel"  id="nivel">
    <option value="<?php echo $row["nivel"] ?>"><?php echo $row["nivel"] ?></option>
	<option value="PRE-GRADO">PRE-GRADO</option>
	<option value="POST-GRADO">POST-GRADO</option>	
</select>
</td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Categoria")."&nbsp;" ?></td>
<td class="dr">
<select name="categoria">
  <?php
do {  
?>
  <option value="<?php echo $row_rstCat['categoria']?>"><?php echo $row_rstCat['categoria']?></option>
  <?php
} while ($row_rstCat = mysql_fetch_assoc($rstCat));
  $rows = mysql_num_rows($rstCat);
  if($rows > 0) {
      mysql_data_seek($rstCat, 0);
	  $row_rstCat = mysql_fetch_assoc($rstCat);
  }
?>
</select>
</td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Area de Conocimiento")."&nbsp;" ?></td>
<td class="dr"><input onKeyUp="this.value=this.value.toUpperCase();" name="area" type="text" value="<?php echo str_replace('"', '&quot;', trim($row["area"])) ?>" size="30" maxlength="30"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Desde")."&nbsp;" ?></td>
<td class="dr"><input name="desde" type="text" onKeyUp="mascara(this,'-',patron3,true)" value="<?php echo str_replace('"', '&quot;', trim($row["desde"])) ?>" size="5" maxlength="7" >(mm-aaaa)</td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Hasta")."&nbsp;" ?></td>
<td class="dr"><input name="hasta" type="text" onKeyUp="mascara(this,'-',patron3,true)" value="<?php echo str_replace('"', '&quot;', trim($row["hasta"])) ?>" size="5" maxlength="7" >(mm-aaaa)</td>
</tr>
</table>
<?php } ?>

<?php function showpagenav($page, $pagecount)
{
global $cedula_docente;

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

<?php function showrecnav($a, $recid, $count)
{
global $cedula_docente;

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

<?php function addrec()
{
global $cedula_docente;

?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="experiencia_docente.php?cedula_docente=<?php echo $cedula_docente; ?>">Regresar</a></td>
</tr>
</table>
<hr size="1" noshade>
<form enctype="multipart/form-data" action="experiencia_docente.php?cedula_docente=<?php echo $cedula_docente; ?>" method="post">
<p><input type="hidden" name="sql" value="insert"></p>
<?php
$row = array(
  "id_docente" => "",
  "institucion" => "",
  "nivel" => "",
  "categoria" => "",
  "area" => "",
  "desde" => "",
  "hasta" => "");
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>

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

<?php function editrec($recid)
{
global $cedula_docente;

  $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="experiencia_docente.php?cedula_docente=<?php echo $cedula_docente; ?>" method="post">
<input type="hidden" name="sql" value="update">
<input type="hidden" name="xid_docente" value="<?php echo $row["id_docente"] ?>">
<input type="hidden" name="xinstitucion" value="<?php echo $row["institucion"] ?>">
<input type="hidden" name="xnivel" value="<?php echo $row["nivel"] ?>">
<input type="hidden" name="xcategoria" value="<?php echo $row["categoria"] ?>">
<input type="hidden" name="xarea" value="<?php echo $row["area"] ?>">
<input type="hidden" name="xdesde" value="<?php echo $row["desde"] ?>">
<input type="hidden" name="xhasta" value="<?php echo $row["hasta"] ?>">
<?php showroweditor($row, true); ?>
<p><input type="submit" name="action" value="Guardar"></p>
</form>
<?php
  mysql_free_result($res);
} ?>

<?php function deleterec($recid)
{
global $cedula_docente;

  $res = sql_select();
  $count = sql_getrecordcount();
  mysql_data_seek($res, $recid);
  $row = mysql_fetch_assoc($res);
  showrecnav("del", $recid, $count);
?>
<br>
<form action="experiencia_docente.php?cedula_docente=<?php echo $cedula_docente; ?>" method="post">
<input type="hidden" name="sql" value="delete">
<input type="hidden" name="xid_docente" value="<?php echo $row["id_docente"] ?>">
<input type="hidden" name="xinstitucion" value="<?php echo $row["institucion"] ?>">
<input type="hidden" name="xnivel" value="<?php echo $row["nivel"] ?>">
<input type="hidden" name="xcategoria" value="<?php echo $row["categoria"] ?>">
<input type="hidden" name="xarea" value="<?php echo $row["area"] ?>">
<input type="hidden" name="xdesde" value="<?php echo $row["desde"] ?>">
<input type="hidden" name="xhasta" value="<?php echo $row["hasta"] ?>">
<?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", "siace_admin", "j7BnJdCGzyQBGcud");
  mysql_select_db("enaph_siace");
  mysql_query ("SET NAMES 'utf8'");
  return $conn;
}

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

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

function sql_select()
{
  global $conn;
  global $order;
  global $ordtype;
  global $id_docente;
  
  $sql = "SELECT `id_docente`, `institucion`, `nivel`, `categoria`, `area`, `desde`, `hasta` FROM `experiencia_docente` where id_docente='$id_docente'";
  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 $id_docente;
  
  $sql = "SELECT COUNT(*) FROM `experiencia_docente` where id_docente='$id_docente'";
  $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;
  global $id_docente;
  global $cedula_usuario;
  global $username;
  global $tipo_usuario;
  
  $sql = "insert into `experiencia_docente` (`id_docente`, `institucion`, `nivel`, `categoria`, `area`, `desde`, `hasta`) values ('$id_docente', " .sqlvalue(@$_POST["institucion"], true).", " .sqlvalue(@$_POST["nivel"], true).", " .sqlvalue(@$_POST["categoria"], true).", " .sqlvalue(@$_POST["area"], true).", " .sqlvalue(@$_POST["desde"], true).", " .sqlvalue(@$_POST["hasta"], true).")";
  mysql_query($sql, $conn) or die(mysql_error());
  
  // Guarda el Registro de Auditoría
  $consulta=addslashes($sql);
  $fecha=date("Y-m-d G:i:A");
  $accion="Agregar Experiencia Docente";
  $script="experiencia_docente.php";
  $ip=obtener_ip();
  $sql1 = "insert into `auditoria` (`username`, `tipo_usuario`,`cedula`, `ip`, `fecha`, `accion`, `script`, `query`) values ('$username', '$tipo_usuario', '$cedula_usuario', '$ip', '$fecha', '$accion', '$script', '$consulta')";
  mysql_query($sql1, $conn) or die(mysql_error()); 
}

function sql_update()
{
  global $conn;
  global $_POST;
  global $cedula_usuario;
  global $username;
  global $tipo_usuario;

  $sql = "update `experiencia_docente` set `institucion`=" .sqlvalue(@$_POST["institucion"], true).", `nivel`=" .sqlvalue(@$_POST["nivel"], true).", `categoria`=" .sqlvalue(@$_POST["categoria"], true).", `area`=" .sqlvalue(@$_POST["area"], true).", `desde`=" .sqlvalue(@$_POST["desde"], true).", `hasta`=" .sqlvalue(@$_POST["hasta"], true) ." where " .primarykeycondition();
  mysql_query($sql, $conn) or die(mysql_error());

// Guarda el Registro de Auditoría
  $consulta=addslashes($sql);
  $fecha=date("Y-m-d G:i:A");
  $accion="Modificar Experiencia Docente";
  $script="experiencia_docente.php";
  $ip=obtener_ip();
  $sql1 = "insert into `auditoria` (`username`, `tipo_usuario`,`cedula`, `ip`, `fecha`, `accion`, `script`, `query`) values ('$username', '$tipo_usuario', '$cedula_usuario', '$ip', '$fecha', '$accion', '$script', '$consulta')";
  mysql_query($sql1, $conn) or die(mysql_error());
}

function sql_delete()
{
  global $conn;
  global $cedula_usuario;
  global $username;
  global $tipo_usuario;
  
  $sql = "delete from `experiencia_docente` where " .primarykeycondition();
  mysql_query($sql, $conn) or die(mysql_error());
  
   // Guarda el Registro de Auditoría
  $consulta=addslashes($sql);
  $fecha=date("Y-m-d G:i:A");
  $accion="Eliminar Experiencia Docente";
  $script="experiencia_docente.php";
  $ip=obtener_ip();
  $sql1 = "insert into `auditoria` (`username`, `tipo_usuario`,`cedula`, `ip`, `fecha`, `accion`, `script`, `query`) values ('$username', '$tipo_usuario', '$cedula_usuario', '$ip', '$fecha', '$accion', '$script', '$consulta')";
  mysql_query($sql1, $conn) or die(mysql_error());
}

function primarykeycondition()
{
  global $_POST;
  $pk = "";
  $pk .= "(`id_docente`";
  if (@$_POST["xid_docente"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xid_docente"], false);
  };
  $pk .= ") and ";
  $pk .= "(`institucion`";
  if (@$_POST["xinstitucion"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xinstitucion"], true);
  };
  $pk .= ") and ";
  $pk .= "(`nivel`";
  if (@$_POST["xnivel"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xnivel"], true);
  };
  $pk .= ") and ";
  $pk .= "(`categoria`";
  if (@$_POST["xcategoria"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xcategoria"], true);
  };
  $pk .= ") and ";
  $pk .= "(`area`";
  if (@$_POST["xarea"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xarea"], true);
  };
  $pk .= ") and ";
  $pk .= "(`desde`";
  if (@$_POST["xdesde"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xdesde"], true);
  };
  $pk .= ") and ";
  $pk .= "(`hasta`";
  if (@$_POST["xhasta"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xhasta"], true);
  };
  $pk .= ")";
  return $pk;
}

function obtener_ip()
  {
 if ($_SERVER) {  
    if ( $_SERVER[HTTP_X_FORWARDED_FOR] ) {  
    $realip = $_SERVER["HTTP_X_FORWARDED_FOR"];  
   } elseif ( $_SERVER["HTTP_CLIENT_IP"] ) {  
$realip = $_SERVER["HTTP_CLIENT_IP"];  
} else  {  
$realip = $_SERVER["REMOTE_ADDR"];  
}  
} else {  
if ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) {  
$realip = getenv( 'HTTP_X_FORWARDED_FOR' );  
} elseif ( getenv( 'HTTP_CLIENT_IP' ) ) {  
$realip = getenv( 'HTTP_CLIENT_IP' );  
} else {  
$realip = getenv( 'REMOTE_ADDR' );  
}  
}  
return $realip;  
  }
 ?>
 
 <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)
var patron3= new Array(2,4)

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>

