Incam_Intranet/src/buscar_candidato.php

200 lines
6.4 KiB
PHP

<?php
include("seguridad.php");
include("functions.php");
// Sólo los administradores y rrhh pueden buscar
if(!$usuario->tieneRol("1")
&& !$usuario->tieneRol("4")){
header("Location: aplicacion.php?e=permiso");
exit;
}
include_once("html/cabecera.php");
include_once("Objects/HTML.php");
$html=new HTML($locale);
echo $html->menuCandidatos();
$errores = "";
include_once("Objects/ListaCandidatos.php");
$listaCandidatos=new ListaCandidatos($usuario,"","","10");
//CAMPOS EN LOS QUE BUSCAR LA PALABRA
$resultado=$listaCandidatos->getCamposBusqueda();
$camposPermitidos = array("nombre", "apellidos", "observaciones");
////////////////////////////
// Proceso del Formulario
///////////////////////////
if (isset($_GET['pagLista'])) {
if ((isset($_SESSION['palabra'])) && ($_SESSION['palabra'] != ""))
$_POST['palabra'] = $_SESSION['palabra'];
if ((isset($_SESSION['campos'])) && ($_SESSION['campos'] != ""))
$_POST['campo'] = $_SESSION['campos'];
if ((isset($_SESSION['perfiles_tecnicos'])) && ($_SESSION['perfiles_tecnicos'] != ""))
$_POST['id_perfil_tecnico'] = $_SESSION['perfiles_tecnicos'];
if ((isset($_SESSION['perfiles_funcionales'])) && ($_SESSION['perfiles_funcionales'] != ""))
$_POST['id_perfil_funcional'] = $_SESSION['perfiles_funcionales'];
if ((isset($_SESSION['tecnologias'])) && ($_SESSION['tecnologias'] != ""))
$_POST['tecnologias'] = $_SESSION['tecnologias'];
}
if ((isset($_POST['buscar'])) || (isset($_GET['pagLista']))) {
$palabra=$_POST['palabra'];
$campos=$_POST['campo'];
$whereCampos="";
$tablas = "usuarios";
foreach($campos as $campo)
if ($campo != "") {
if ($whereCampos != "") {
$whereCampos = $whereCampos . " or ";
}
$whereCampos = $whereCampos . "usuarios.". $campo ." like '%". $palabra ."%'";
}
if (($palabra != "") && ($whereCampos == "")) {
$errores = $locale['01903'];
}
$SemaforoPerfilTec = false;
$perfiles_tec = $_POST["id_perfil_tecnico"];
$wherePerfilesTec="";
foreach($perfiles_tec as $perfil)
if ($perfil != "") {
if(!$SemaforoPerfilTec)
$tablas .= ", capacidades capacidades1";
$SemaforoPerfilTec = true;
if ($wherePerfilesTec != "") {
$wherePerfilesTec = $wherePerfilesTec . " or ";
}
$wherePerfilesTec = $wherePerfilesTec . "(capacidades1.id_perfil_tecnico = ". $perfil ." and capacidades1.id_usuario = usuarios.oid)";
}
$SemaforoPerfilFun = false;
$perfiles_fun = $_POST["id_perfil_funcional"];
$wherePerfilesFun="";
foreach($perfiles_fun as $perfil)
if ($perfil != "") {
if(!$SemaforoPerfilFun)
$tablas .= ", capacidades capacidades2";
$SemaforoPerfilFun = true;
if ($wherePerfilesFun != "") {
$wherePerfilesFun = $wherePerfilesFun . " or ";
}
$wherePerfilesFun = $wherePerfilesFun . "(capacidades2.id_perfil_funcional = ". $perfil ." and capacidades2.id_usuario = usuarios.oid)";
}
$SemaforoTecnologias = false;
$tecnologias = $_POST["tecnologias"];
$whereTecnologias="";
foreach($tecnologias as $tecnologia)
if ($tecnologia != "") {
if(!$SemaforoTecnologias)
$tablas .= ", capacidades capacidades3, capacidades_perfil_tecnologias";
$SemaforoTecnologias = true;
if ($whereTecnologias != "") {
$whereTecnologias = $whereTecnologias . " or ";
}
$whereTecnologias = $whereTecnologias . "(capacidades_perfil_tecnologias.id_tecnologia = ". $tecnologia ." and capacidades_perfil_tecnologias.id_capacidad = capacidades3.id and capacidades3.id_usuario = usuarios.oid)";
}
//Vamos a meter los parametros de busqueda en session para que en la paginación no se pierdan
$_SESSION['palabra']=$palabra;
$_SESSION['campos']=$campos;
$_SESSION['perfiles_tecnicos']=$perfiles_tec;
$_SESSION['perfiles_funcionales']=$perfiles_fun;
$_SESSION['tecnologias']=$tecnologias;
if ($errores == "") {
$query = "SELECT distinct usuarios.* from ". $tablas ." where (usuarios.tipo = 'candidato')";
if ($whereCampos != "")
$query = $query . " and (". $whereCampos .")";
if ($wherePerfilesTec != "")
$query = $query . " and (". $wherePerfilesTec .")";
if ($wherePerfilesFun != "")
$query = $query . " and (". $wherePerfilesFun .")";
if ($whereTecnologias != "")
$query = $query . " and (". $whereTecnologias .")";
//echo $query;
$listaCandidatos=new ListaCandidatos($usuario,"",$query,"");
}
}
?>
<form name="buscador" method="post" action="buscar_candidato.php"><br>
<h2><?php echo $locale['820']; ?></h2>
<?php
if($errores!=""){
// Mostramos el mensaje
echo "<div class=\"aviso error\">".$errores."</div>";
}
?>
<div class="encabezado"><?php echo $locale['Candidato007']; ?></div>
<table align="center" width="100%" border="0">
<tr>
<td width="10%">
<?php echo $locale['01901'] .'<br><input type="text" name="palabra" value="'. $_POST['palabra'] .'"></td>';
echo '<td width="90%"';
if ($errores != "") echo " class=\"errorcampo\"";
echo '>'. $locale['01902'];
?>
<br><select multiple name="campo[]" id="campo" size="10">
<?php
while($row = mysql_fetch_row($resultado)) {
if (in_array($row[0], $camposPermitidos)){
if (in_array($row[0], $_POST['campo']))
echo '<option selected ';
else
echo '<option ';
echo 'value="'. $row[0] .'">'. $row[0] .'</option>';
}
}
?>
</select>
</td>
</tr></table>
<input type="submit" value="Buscar" name="buscar">
<br>
<div class="encabezado"><?php echo $locale['Capacidades004']; ?></div>
<table align="center" width="100%" border="0">
<tr>
<td width="20%">
<?php
echo $locale['202']. "<br>";
echo $html->listaSelect("perfil","oid","id","id_perfil_tecnico",array("",$locale['ns']),$_POST['id_perfil_tecnico'],true,true,"15");
?>
</td>
<td width="20%">
<?php
echo $locale['203'].'<br>';
echo $html->listaSelect("tecnologia","oid","id","tecnologias",array("",$locale['ns']),$_POST['tecnologias'],true,true,"15");
?>
</td>
<td width="60%">
<?php
echo $locale['202_2'].'<br>';
echo $html->listaSelect("perfil_funcional","oid","id","id_perfil_funcional",array("",$locale['ns']),$_POST['id_perfil_funcional'],true,true,"15");
?>
</td>
</tr>
</table>
<input type="submit" value="Buscar" name="buscar">
</form>
<?php
include_once("ver_lista_candidatos.php");
include_once("html/pie.php");
?>