HEX
Server: Apache
System: Linux clpupre 5.4.0-90-generic #101-Ubuntu SMP Fri Oct 15 20:00:55 UTC 2021 x86_64
User: undanet (1000)
PHP: 7.4.3
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /home/undanet/www/PortalEmpleo/src/Views/GestionarCandidatos.php
<?php 

use PortalEmpleo\Entity\DboCandidato;
use PortalEmpleo\Entity\DboArea;
use PortalEmpleo\Entity\DboCandidatoidioma;
use PortalEmpleo\Entity\DboCandidatoperfil;
use PortalEmpleo\Entity\DboPerfil;
use PortalEmpleo\Entity\DboMateria;
use PortalEmpleo\Entity\DboTitulacion;
use PortalEmpleo\Entity\WpUsers;
use PortalEmpleo\Controller\CandidatoController;
use PortalEmpleo\Utils\Load;

require __DIR__ . '/../../vendor/autoload.php';

session_start();

$controllercandidato = new CandidatoController();

if( pll_current_language() == 'en')
    $lang = 'en_GB';
else 
    $lang = 'es_ES';

$root = get_site_url() . '/';
$rootwp = "";
$actual_link = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);


if($_SERVER['REQUEST_METHOD'] == "POST")
{
    /*foreach ($_POST as $key => $value) {
        echo $key . '->' . $value . ' ';
    }*/
    if(isset($_POST['accionCandidato']))
    {
        switch ($_POST['accionCandidato']) {
            case 'DetalleCandidato':
                if(isset($_POST['codigoUsuarioWP']))
                {
                    $idwp = $_POST['codigoUsuarioWP'];
                    call_user_func(array($controllercandidato, 'detalleCandidato'), $idwp, isset($lang) ? $lang : 'es_ES');
                }
                break;
            case 'Actualizar':
                $datosOK = "";
                $datosOK = validarCandidatoPerfil();
                
                echo $datosOK;
                if($datosOK == "")
                {
                    $candidat = construirCandidatoPerfil();
                    
                    if(isset($candidat))
                    {
                        call_user_func(array($controllercandidato, 'actualizarCandidatoPerfil'), $candidat, isset($lang) ? $lang : 'es_ES');
                    }
                } else {
                    
                    $actual_link .= "?e=" . $datosOK;
                    
                    header("LOCATION:$actual_link");                    
                    exit;
                }
                
                //redirigir al perfil o si viene de una convocatoria (tiene valor en $_GET['c']), redirigir a la convocatoria
                if(isset($_GET['c']) && is_numeric($_GET['c']))
                {
                    
                    $link_cvt = $root . $rootwp . __('en/call-details/?id=', 'panoramic_child'). $_GET['c'];
                    $_POST['accionConvocatoria'] = 'Register';
                    header("LOCATION:$link_cvt");

                }
                elseif( $_POST['txtExiste'] == 'no' )
                {
                    $actual_link .= "#frmCandidatoIdiomas";
                    header("LOCATION:$actual_link");
                    exit;
                }               
                else
                {
                    header("LOCATION:$actual_link");
                    exit;
                }
                break;
            case 'QuitarIdioma':
                if(isset($_POST['txtIdioma']))
                {
                    $idCandIdioma = $_POST['txtIdioma'];
                    $idwp = $_SESSION["codigoUsuarioWP"];
                    call_user_func(array($controllercandidato, 'quitarCandidatoIdioma'), $idCandIdioma, $idwp, isset($lang) ? $lang : 'es_ES');
                }
                break;
            case 'AddIdioma':
                $datosOK = "";
                $datosOK = validarCandidatoIdioma();

                if($datosOK == "")
                {
                    $candIdioma = construirCandidatoIdioma();

                    if(isset($candIdioma) && isset($_SESSION["codigoUsuarioWP"]))
                    {
                        $idwp = $_SESSION["codigoUsuarioWP"];
                        call_user_func(array($controllercandidato, 'addCandidatoIdioma'), $candIdioma, $idwp, isset($lang) ? $lang : 'es_ES');
                    }
                }
                else
                {
                   //redirigir al perfil
                    header("LOCATION:$actual_link");
                }

                break;
            case 'QuitarPerfil':
                if(isset($_POST['txtPerfil']))
                {
                    $idCandPerfil = $_POST['txtPerfil'];
                    $idwp = $_SESSION["codigoUsuarioWP"];
                    call_user_func(array($controllercandidato, 'quitarCandidatoPerfil'), $idCandPerfil, $idwp, isset($lang) ? $lang : 'es_ES');
                }
                break;
            case 'AddPerfil':
                $datosOK = "";
                $datosOK = validarPerfil();

                if($datosOK == "")
                {
                    $candPerfil = construirPerfil();

                    if(isset($candPerfil) && isset($_SESSION["codigoUsuarioWP"]))
                    {
                        $idwp = $_SESSION["codigoUsuarioWP"];
                        call_user_func(array($controllercandidato, 'addPerfil'), $candPerfil, $idwp, isset($lang) ? $lang : 'es_ES');
                    }
                }
                else
                {
                    //redirigir al perfil
                    header("LOCATION:$actual_link");
                }
                break;
            case 'VerFicha':
                if(isset($_POST['candidatoId']) && isset($_POST['convocatoriaId']) && isset($_POST['convocatoriaRef']))
                {
                    $idCandidato = $_POST['candidatoId'];
                    $idConvocatoria = $_POST['convocatoriaId'];
                    $refConvocatoria = $_POST['convocatoriaRef'];
                    call_user_func(array($controllercandidato, 'obtenerFichaCandidato'), $idCandidato, $idConvocatoria, $refConvocatoria, isset($lang) ? $lang : 'es_ES');
                }
                else
                {
                    if(isset($_POST['candidatoId']) && !isset($_POST['convocatoriaId']))
                    {
                        $idCandidato = $_POST['candidatoId'];
                        $idConvocatoria = null;
                        $refConvocatoria = null;
                        call_user_func(array($controllercandidato, 'obtenerFichaCandidato'), $idCandidato, $idConvocatoria, $refConvocatoria, isset($lang) ? $lang : 'es_ES');
                    }
                }
                break;
            case 'AdjuntarArchivos':
                    $lfiles = [];
                    foreach ($_FILES as $file) {
                        if (strlen(trim($file['name']))>0)
                        {
                            array_push($lfiles, $file);
                        }
                    }

                    if(count($lfiles) <= 0)
                    {
                        if($lang=='en' || $lang=='en_GB')
                        {
                            echo '<br><span class="large">There are no files to upload</span>';
                        }
                        else
                        {
                            echo '<br><span class="large">No se han adjuntado archivos para adjuntar</span>';
                        }   
                    }
                    else
                    {
                        if(count($lfiles) > 0 && is_numeric($_POST['codigoUsuarioWP']) && is_numeric($_POST['txtCvt']))
                        {
                            $result = uploadFiles($lfiles, $_POST['codigoUsuarioWP'], $_POST['txtCvt']);
                        }

                        if($result!= -1) //Si hay ficheros y no hay error en la subida
                        {
                            if($lang=='en' || $lang=='en_GB')
                            {
                                echo '<br><span class="large">Success uploading files</span>';
                            }
                            else
                            {
                                echo '<br><span class="large">Archivos subidos con &eacute;xito</span>';
                            }
                        }
                        else
                        {
                            if($lang=='en' || $lang=='en_GB')
                            {
                                echo '<br><span class="large">An error has occurred when processing your attached files. Please, check the size of the files (not up from 10MB) and check that all files extension are allowed</span>';
                            }
                            else
                            {
                                echo '<br><span class="large">Se ha producido un error al subir los ficheros adjuntos. Por favor, revise el tamaño de los archivos (no superior a 10MB) y la extensión de los mismos</span>';
                            }
                        }
                    }

                    //volver a la ficha de candidato
                    if(is_numeric($_POST['txtCdt']) && is_numeric($_POST['codigoUsuarioWP']) && is_numeric($_POST['txtCvt']))
                    {
						echo '<br><br><a href="' . $root .  __('en/candidate-tab/?id=', 'panoramic_child'). $_POST['txtCdt'] . '&cvt='. $_POST['txtCvt'] . '&ref=' . $_POST['txtReferencia'] . '" target="_self">Back to candidate\'s tab</a>';
                       /* if($lang=='en' || $lang=='en_GB')
                        {
                            echo '<br><br><a href="' . $root . 'en/candidate-tab/?id=' . $_POST['txtCdt'] . '&cvt='. $_POST['txtCvt'] . '&ref=' . $_POST['txtReferencia'] . '" target="_self">Back to candidate\'s tab</a>';
                        }
                        else
                        {
                            echo '<br><br><a href="' . $root . 'es/ficha-candidato/?id=' . $_POST['txtCdt'] . '&cvt='. $_POST['txtCvt'] . '&ref=' . $_POST['txtReferencia'] . '" target="_self">Volver a la ficha del candidato</a>';
                        }*/
                    }
                break;
            case 'BuscarCandidatos':
                    call_user_func(array($controllercandidato, 'buscadorCandidatos'), isset($lang) ? $lang : 'es_ES');
                break;
            default:
                //redirigir al perfil
                header("LOCATION:$actual_link");
                break;
        }
    }
    else
    {
        //redirigir al perfil
        header("LOCATION:$actual_link");
    }
}
else
{
    //redirigir al perfil
    header("LOCATION:$actual_link");
}

function listarConvocatoriasAdmin($controller, $lang)
{
    if(isset($_POST['codigoUsuarioWP']))
    {
        unset($_POST['codigoUsuarioWP']);
    }

	call_user_func(array($controller, 'listarConvocatoriasAdmin'), $lang);
}

function validarCandidatoPerfil()
{
	
	if( pll_current_language() == 'en')
    $lang1 = 'en_GB';
else 
    $lang1 = 'es_ES';
    /*
        *IdCandidato->
        *Nombre->$_POST['txtNombre']
        *Apellido1->$_POST['txtApellido1']
        Apellido2->$_POST['txtApellido2']
        *Documento->$_POST['txtDocumento']
        *FechaNacimiento->$_POST['dtFechaNacimiento']
        CodigoArea->$_POST['slctArea']
        *CodigoTitulacion->$_POST['slctTitulacion']
        CodigoMateria->$_POST['slctMateria']
        Puesto->$_POST['txtPuesto'] <--> DEPRECATED
        DescripcionMaster->$_POST['txtMaster']
        DescripcionEspecializacion->$_POST['txtEspecializacion']
        *RutaCV->$_FILES['flCV']
        RutaCP->$_FILES['flCartaPresentacion']
        Motivacion->$_POST['txtMotivacion']
        *HaParticipadoAnteriormente->$_POST['RdHasParticipado']
        ComoConocido->$_POST['RdHasConocido'] / $_POST['txtOtros']
        *CodigoUsuarioWP->
        *AceptaRGPD->
        *AceptaRecibirEmails->$_POST['chkRecibirEmails']
        *Baja->
    */

    $msgError = "";

    //Validar Nombre
	
 if($lang1=='en' || $lang1=='en_GB')
 {
                             
	
    if(!isset($_POST['txtNombre']))
    {
        $msgError = $msgError . "The Name field must be informed<BR>"; 
    }
    else if ($_POST['txtNombre']==null || strlen(trim($_POST['txtNombre']))<=0)
    {
		
        $msgError = $msgError . "The Name field must be informed or contain a valid value<BR>";       
	   
    }
 }
 else
 {
   if(!isset($_POST['txtNombre']))
    {
        $msgError = $msgError . "El campo Nombre debe estar informado<BR>"; 
    }
    else if ($_POST['txtNombre']==null || strlen(trim($_POST['txtNombre']))<=0)
    {
		
        $msgError = $msgError . "El campo Nombre debe estar informado o contener un valor válido <BR>";       
	   
    }
   
   
 } 
		
		

    //Validar Apellido1
  
if($lang1=='en' || $lang1=='en_GB')
 {
                             
	  if(!isset($_POST['txtApellido1']))
    {
        $msgError = $msgError . "The Surname 1 field must be informed<BR>"; 
    }
    else if ($_POST['txtApellido1']==null || strlen(trim($_POST['txtApellido1']))<=0)
    {
        $msgError = $msgError . "The Surname 1 field must be informed or contain a valid value<BR>"; 
    }
 }
 else
 {
    if(!isset($_POST['txtApellido1']))
    {
        $msgError = $msgError . "El campo Apellido 1 debe estar informado<BR>"; 
    }
    else if ($_POST['txtApellido1']==null || strlen(trim($_POST['txtApellido1']))<=0)
    {
        $msgError = $msgError . "El campo Apellido 1 debe estar informado o contener un valor válido<BR>"; 
    }
   
   
 } 


    //Validar Documento
    

if($lang1=='en' || $lang1=='en_GB')
 {
                             
	 if(!isset($_POST['txtDocumento']))
    {
        $msgError = $msgError . "The Document field must be informed<BR>"; 
    }
    else if ($_POST['txtDocumento']==null || strlen(trim($_POST['txtDocumento']))<=0)
    {
        $msgError = $msgError . "The Document field must be informed or contain a valid value<BR>"; 
    }
 }
 else
 {
    if(!isset($_POST['txtDocumento']))
    {
        $msgError = $msgError . "El campo Documento debe estar informado<BR>"; 
    }
    else if ($_POST['txtDocumento']==null || strlen(trim($_POST['txtDocumento']))<=0)
    {
        $msgError = $msgError . "El campo Documento debe estar informado o contener un valor válido<BR>"; 
    }
   
   
 } 



    //Validar FechaNacimiento
   
	
	if($lang1=='en' || $lang1=='en_GB')
 {
                             
	  if(!isset($_POST['dtFechaNacimiento']))
    {
        $msgError = $msgError . "
The Date of Birth field must be informed or contain a valid value<BR>"; 
    }
    else
    {
        if ($_POST['dtFechaNacimiento'] >= date("Y-m-d"))
        {
            $msgError = $msgError . "The Date of Birth field must be before the start date<BR>"; 
        }
    }
 }
 else
 {
    if(!isset($_POST['dtFechaNacimiento']))
    {
        $msgError = $msgError . "El campo Fecha de Nacimiento debe estar informado o contener un valor válido<BR>"; 
    }
    else
    {
        if ($_POST['dtFechaNacimiento'] >= date("Y-m-d"))
        {
            $msgError = $msgError . "El campo Fecha de Nacimiento debe ser anterior a la fecha de inicio<BR>"; 
        }
    }
   
 } 
	
	
	

    //Validar CodigoTitulacion
  
  
	
	if($lang1=='en' || $lang1=='en_GB')
 {
                             
	    if(!isset($_POST['slctTitulacion']))
    {
        $msgError = $msgError . "The Degree Code field must be informed<BR>"; 
    }
    else if ($_POST['slctTitulacion']==null || !is_numeric($_POST['slctTitulacion']))
    {
        $msgError = $msgError . "The Codigo Titulacion field must be informed or contain a valid value<BR>"; 
    }

 }
 else
 {
     if(!isset($_POST['slctTitulacion']))
    {
        $msgError = $msgError . "El campo Codigo Titulacion debe estar informado<BR>"; 
    }
    else if ($_POST['slctTitulacion']==null || !is_numeric($_POST['slctTitulacion']))
    {
        $msgError = $msgError . "El campo Codigo Titulacion debe estar informado o contener un valor válido<BR>"; 
    }

   
 } 
	

    //Validar RutaCV
  
		
	if($lang1=='en' || $lang1=='en_GB')
 {
        if(!isset($_FILES['flCV']) && !isset($_POST['txtflCV']))
    {
        $msgError = $msgError . "The CV route field must be informed<BR>"; 
    }
    else if (($_FILES['flCV']==null || strlen(trim($_FILES['flCV']['name']))<=0) && !isset($_POST['txtflCV']))
    {
        $msgError = $msgError . "The CV path field must be informed or contain a valid value<BR>"; 
    }
	
 }
 else
 {
      if(!isset($_FILES['flCV']) && !isset($_POST['txtflCV']))
    {
        $msgError = $msgError . "El campo ruta CV debe estar informado<BR>"; 
    }
    else if (($_FILES['flCV']==null || strlen(trim($_FILES['flCV']['name']))<=0) && !isset($_POST['txtflCV']))
    {
        $msgError = $msgError . "El campo ruta CV debe estar informado o contener un valor válido<BR>"; 
    }
	
   
 } 
	
	

    //Validar HaParticipadoAnteriormente
   
		
	if($lang1=='en' || $lang1=='en_GB')
 {
        if(!isset($_POST['RdHasParticipado']))
    {
        $msgError = $msgError . "El campo Ha Participado Anteriormente debe estar informado<BR>"; 
    }
	
 }
 else
 {
      if(!isset($_POST['RdHasParticipado']))
    {
        $msgError = $msgError . "El campo Ha Participado Anteriormente debe estar informado<BR>"; 
    }
	
   
 } 
	


    //Validar AceptaRecibirEmails  -- Si no se marca no existe la variable post al enviar
    /*if(!isset($_POST['chkRecibirEmails']))
    {
        $msgError = $msgError . "El campo Acepta Recibir Emails debe estar informado<BR>"; 
    }*/

    return $msgError;
}

function construirCandidatoPerfil()
{
    try
    {
        /*
            *IdCandidato->
            *Nombre->$_POST['txtNombre']
            *Apellido1->$_POST['txtApellido1']
            Apellido2->$_POST['txtApellido2']
            *Documento->$_POST['txtDocumento']
            *FechaNacimiento->$_POST['dtFechaNacimiento']
            CodigoArea->$_POST['slctArea']
            *CodigoTitulacion->$_POST['slctTitulacion']
            CodigoMateria->$_POST['slctMateria']
            Puesto->$_POST['txtPuesto'] <--> DEPRECATED
            DescripcionMaster->$_POST['txtMaster']
            DescripcionEspecializacion->$_POST['txtEspecializacion']
            *RutaCV->$_FILES['flCV']
            RutaCP->$_FILES['flCartaPresentacion']
            Motivacion->$_POST['txtMotivacion']
            *HaParticipadoAnteriormente->$_POST['RdHasParticipado']
            ComoConocido->$_POST['RdHasConocido'] / $_POST['txtOtros']
            *CodigoUsuarioWP->
            *AceptaRGPD->
            *AceptaRecibirEmails->$_POST['chkRecibirEmails']
            *Baja->
        */
        $candidato = new DboCandidato();
        
        //Comprobamos si es una actualizacion o un alta, si es una actualizacion: 
        if(isset($_SESSION['data']) && is_numeric($_SESSION['data']->getIdcandidato()))
        {
            $candidato->setIdcandidato($_SESSION['data']->getIdcandidato());
            $candidato->setNombre(($_SESSION['data']->getNombre()!=$_POST['txtNombre']) ? $_POST['txtNombre'] : $_SESSION['data']->getNombre());
            $candidato->setApellido1(($_SESSION['data']->getApellido1()!=$_POST['txtApellido1']) ? $_POST['txtApellido1'] : $_SESSION['data']->getApellido1());
            $candidato->setApellido2(($_SESSION['data']->getApellido2()!=$_POST['txtApellido2']) ? $_POST['txtApellido2'] : $_SESSION['data']->getApellido2());
            $candidato->setDocumento(($_SESSION['data']->getDocumento()!=$_POST['txtDocumento']) ? $_POST['txtDocumento'] : $_SESSION['data']->getDocumento());
            $candidato->setFechanacimiento(($_SESSION['data']->getFechanacimiento()!=$_POST['dtFechaNacimiento']) ? DateTime::createFromFormat('Y-m-d', strval($_POST['dtFechaNacimiento'])) : $_SESSION['data']->getFechanacimiento());
            $candidato->setCodigoarea($_POST['slctArea']);
            $candidato->setCodigotitulacion($_POST['slctTitulacion']);
            $candidato->setCodigomateria($_POST['slctMateria']);
            $candidato->setPuesto(null);
            $candidato->setDescripcionmaster(($_SESSION['data']->getDescripcionmaster()!=$_POST['txtMaster']) ? $_POST['txtMaster'] : $_SESSION['data']->getDescripcionmaster());
            $candidato->setDescripcionespecializacion(($_SESSION['data']->getDescripcionespecializacion()!=$_POST['txtEspecializacion']) ? $_POST['txtEspecializacion'] : $_SESSION['data']->getDescripcionespecializacion());
            if(!isset($_FILES['flCV']) || strlen(trim($_FILES['flCV']['name']))<=0) //Cuando no ha modificado el CV que tenia
            {
                $candidato->setRutacv($_SESSION['data']->getRutacv());
            }
            elseif (isset($_FILES['flCV']) && strlen(trim($_FILES['flCV']['name']))>0) 
            {
                $load = new Load();
                if($load->loadEnv() == null || !isset($_ENV))
                {
                    throw $this->createNotFoundException(
                        'No se han podido cargar las variables de entorno.'
                    );
                }

                //subimos el fichero
                $_FILES['flCV']['name'] = clean($_FILES['flCV']['name']);    //limpiamos las rutas
                $candidato->setRutacv('//'.$_ENV['CANDIDATE_FILES_DIR']. '/' . $_SESSION["codigoUsuarioWP"]/*$candidato->getIdcandidato()*/.'//'.$_FILES['flCV']['name']);
                $fileOrigen = $_FILES['flCV'];
                $fileDestino = $_SERVER["DOCUMENT_ROOT"].$_ENV['FILES_DIR'].$candidato->getRutacv();
                include(__DIR__ . "/../Utils/file_uploader.php");

                if(isset($retorno) && $retorno==true)
                {
                    //Ha ido bien
                    //destruimos el retorno para otra subida
                    unset($retorno);
                }
                else
                {
                    echo $error;
                    //Algo ha ido mal
                    if(isset($retorno))
                    {
                        unset($retorno);
                        $candidato = null;
                        return $candidato;
                    }
                }
            }
            if(!isset($_FILES['flCartaPresentacion']) || strlen(trim($_FILES['flCartaPresentacion']['name']))<=0) //Cuando no ha modificado la CP que tenia
            {
                $candidato->setRutacp($_SESSION['data']->getRutacp());
            }
            elseif (isset($_FILES['flCartaPresentacion']) && strlen(trim($_FILES['flCartaPresentacion']['name']))>0) 
            {
                //$candidato->setRutacp($_FILES['flCartaPresentacion']);
                $load = new Load();
                if($load->loadEnv() == null || !isset($_ENV))
                {
                    throw $this->createNotFoundException(
                        'No se han podido cargar las variables de entorno.'
                    );
                }

                //subimos el fichero
                $_FILES['flCartaPresentacion']['name'] = clean($_FILES['flCartaPresentacion']['name']);    //limpiamos las rutas
                $candidato->setRutacp('//'.$_ENV['CANDIDATE_FILES_DIR']. '/' .$_SESSION["codigoUsuarioWP"]/*$candidato->getIdcandidato()*/.'//'.$_FILES['flCartaPresentacion']['name']);
                $fileOrigen = $_FILES['flCartaPresentacion'];
                $fileDestino = $_SERVER["DOCUMENT_ROOT"].$_ENV['FILES_DIR'].$candidato->getRutacp();
                include(__DIR__ . "/../Utils/file_uploader.php");

                if(!isset($retorno) || $retorno==false)
                {
                    echo $error;
                    //Algo ha ido mal
                    if(isset($retorno))
                    {
                        unset($retorno);
                        $candidato = null;
                        return $candidato;
                    }
                }
            }
            else
            {
                $candidato->setRutacp(null);
            }
            $candidato->setMotivacion(($_SESSION['data']->getMotivacion()!=$_POST['txtMotivacion']) ? $_POST['txtMotivacion'] : $_SESSION['data']->getMotivacion());
            $candidato->setHaparticipadoanteriormente($_POST['RdHasParticipado']==1 ? true : false);
            $candidato->setComoconocido($_POST['RdHasConocido']=='Otros' ? $_POST['txtOtros'] : $_POST['RdHasConocido']);
            $candidato->setCodigousuariowp($_SESSION["codigoUsuarioWP"]);
            $candidato->setAceptargpd($_SESSION['data']->getAceptargpd());
            $candidato->setAceptarecibiremails(isset($_POST['chkRecibirEmails']) ? true : false);
            $candidato->setBaja(false);
        }
        else //Si es un alta
        {
            $candidato->setNombre($_POST['txtNombre']);
            $candidato->setApellido1($_POST['txtApellido1']);
            $candidato->setApellido2($_POST['txtApellido2']);
            $candidato->setDocumento($_POST['txtDocumento']);
            $candidato->setFechanacimiento(DateTime::createFromFormat('Y-m-d', strval($_POST['dtFechaNacimiento'])));
            $candidato->setCodigoarea($_POST['slctArea']);
            $candidato->setCodigotitulacion($_POST['slctTitulacion']);
            $candidato->setCodigomateria($_POST['slctMateria']);
            $candidato->setPuesto(null);
            $candidato->setDescripcionmaster($_POST['txtMaster']);
            $candidato->setDescripcionespecializacion($_POST['txtEspecializacion']);
           
            if (isset($_FILES['flCV']) && strlen(trim($_FILES['flCV']['name']))>0) {

                $load = new Load();
                if($load->loadEnv() == null || !isset($_ENV))
                {
                    throw $this->createNotFoundException(
                        'No se han podido cargar las variables de entorno.'
                    );
                }

                //subimos el fichero
                $_FILES['flCV']['name'] = clean($_FILES['flCV']['name']);    //limpiamos las rutas
                $candidato->setRutacv('//'.$_ENV['CANDIDATE_FILES_DIR']. '/' . $_SESSION["codigoUsuarioWP"]/*$candidato->getIdcandidato()*/.'//'.$_FILES['flCV']['name']);
                $fileOrigen = $_FILES['flCV'];
                $fileDestino = $_SERVER["DOCUMENT_ROOT"].$_ENV['FILES_DIR'].$candidato->getRutacv();
                include(__DIR__ . "/../Utils/file_uploader.php");

                if(isset($retorno) && $retorno==true)
                {
                    //Ha ido bien
                    //destruimos el retorno para otra subida
                    unset($retorno);
                }
                else
                {
                    echo $error;
                    //Algo ha ido mal
                    if(isset($retorno))
                    {
                        unset($retorno);
                        $candidato = null;
                        return $candidato;
                    }
                }
            }
               
            if (isset($_FILES['flCartaPresentacion']) && strlen(trim($_FILES['flCartaPresentacion']['name']))>0) 
            {
                //$candidato->setRutacp($_FILES['flCartaPresentacion']);
                $load = new Load();
                if($load->loadEnv() == null || !isset($_ENV))
                {
                    throw $this->createNotFoundException(
                        'No se han podido cargar las variables de entorno.'
                    );
                }

                //subimos el fichero
                $_FILES['flCartaPresentacion']['name'] = clean($_FILES['flCartaPresentacion']['name']);    //limpiamos las rutas
                $candidato->setRutacp('//'.$_ENV['CANDIDATE_FILES_DIR']. '/' .$_SESSION["codigoUsuarioWP"]/*$candidato->getIdcandidato()*/.'//'.$_FILES['flCartaPresentacion']['name']);
                $fileOrigen = $_FILES['flCartaPresentacion'];
                $fileDestino = $_SERVER["DOCUMENT_ROOT"].$_ENV['FILES_DIR'].$candidato->getRutacp();
                include(__DIR__ . "/../Utils/file_uploader.php");

                if(!isset($retorno) || $retorno==false)
                {
                    echo $error;
                    //Algo ha ido mal
                    if(isset($retorno))
                    {
                        unset($retorno);
                        $candidato = null;
                        return $candidato;
                    }
                }
            }
            else
            {
                $candidato->setRutacp(null);
            }   
            
            $candidato->setRutacp($_FILES['flCartaPresentacion']['name']);
            $candidato->setMotivacion($_POST['txtMotivacion']);
            $candidato->setHaparticipadoanteriormente($_POST['RdHasParticipado']);
            $candidato->setComoconocido($_POST['RdHasConocido']=='Otros' ? $_POST['txtOtros'] : $_POST['RdHasConocido']);
            $candidato->setCodigousuariowp($_SESSION["codigoUsuarioWP"]);
            $candidato->setAceptargpd(true);
            $candidato->setAceptarecibiremails(isset($_POST['chkRecibirEmails']) ? true : false);
            $candidato->setBaja(false);
        }
    }
    catch (Exception $exception)
    {
        $candidato = null;
        echo "construirCandidatoPerfil(): " . $exception->getMessage();
    }
    finally
    {
        return $candidato;
    }
}

function validarCandidatoIdioma()
{
    /*
        *IdCandidatoIdioma->
        *CodigoCandidato->$_POST['txtCdtIdioma']
        *CodigoIdiomas->$_POST['slctIdiomas']
        OtroIdioma->$_POST['txtOtroIdioma']
        *CodigoNivelIdioma->$_POST['slctNivelIdioma']
        *Baja->
    */

if( pll_current_language() == 'en')
    $lang1 = 'en_GB';
else 
    $lang1 = 'es_ES';
   



    $msgError = "";

    //Validar CodigoCandidato
   

if($lang1=='en' || $lang1=='en_GB')
 {
                             
	 if(!isset($_POST['txtCdtIdioma']))
    {
        $msgError = $msgError . "The IdCandidato field must be informed<BR>"; 
    }
    else if ($_POST['txtCdtIdioma']==null || !is_numeric(trim($_POST['txtCdtIdioma'])))
    {
        $msgError = $msgError . "The IdCandidato field must be informed or contain a valid value<BR>"; 
    }
 }
 else
 {
   if(!isset($_POST['txtCdtIdioma']))
    {
        $msgError = $msgError . "El campo IdCandidato debe estar informado<BR>"; 
    }
    else if ($_POST['txtCdtIdioma']==null || !is_numeric(trim($_POST['txtCdtIdioma'])))
    {
        $msgError = $msgError . "El campo IdCandidato debe estar informado o contener un valor válido<BR>"; 
    }
   
   
 } 


    //Validar CodigoIdiomas
   
	
	
	if($lang1=='en' || $lang1=='en_GB')
 {
     if(!isset($_POST['slctIdiomas']))
    {
        $msgError = $msgError . "The CodigoLidiomas field must be informed<BR>"; 
    }
    else if ($_POST['slctIdiomas']==null || !is_numeric($_POST['slctIdiomas']))
    {
        $msgError = $msgError . "The CodigoIdiomas field must be informed or contain a valid value<BR>"; 
    }
 }
 else
 {
    if(!isset($_POST['slctIdiomas']))
    {
        $msgError = $msgError . "El campo CodigoIdiomas debe estar informado<BR>"; 
    }
    else if ($_POST['slctIdiomas']==null || !is_numeric($_POST['slctIdiomas']))
    {
        $msgError = $msgError . "El campo CodigoIdiomas debe estar informado o contener un valor válido<BR>"; 
    }
   
 } 
	
	
	
	

    //Validar CodigoNivelIdioma
   
		if($lang1=='en' || $lang1=='en_GB')
 {
      if(!isset($_POST['slctNivelIdioma']))
    {
        $msgError = $msgError . "The CodigoNivelLidioma field must be informed<BR>"; 
    }
    else if ($_POST['slctNivelIdioma']==null || !is_numeric($_POST['slctNivelIdioma']))
    {
        $msgError = $msgError . "The CodigoNivelLidioma field must be informed or contain a valid value
<BR>"; 
    }
	
 }
 else
 {
    if(!isset($_POST['slctNivelIdioma']))
    {
        $msgError = $msgError . "El campo CodigoNivelIdioma debe estar informado<BR>"; 
    }
    else if ($_POST['slctNivelIdioma']==null || !is_numeric($_POST['slctNivelIdioma']))
    {
        $msgError = $msgError . "El campo CodigoNivelIdioma debe estar informado o contener un valor válido<BR>"; 
    }
	
   
 } 
	
	

    return $msgError;
}

function construirCandidatoIdioma()
{
    try
    {
        /*
            *IdCandidatoIdioma->
            *CodigoCandidato->$_POST['txtCdtIdioma']
            *CodigoIdiomas->$_POST['slctIdiomas']
            OtroIdioma->$_POST['txtOtroIdioma']
            *CodigoNivelIdioma->$_POST['slctNivelIdioma']
            *Baja->
        */
        $cdtIdioma = new DboCandidatoidioma();
        
        $cdtIdioma->setCodigocandidato($_POST['txtCdtIdioma']);
        $cdtIdioma->setCodigoidiomas($_POST['slctIdiomas']);
        if( isset($_POST['txtOtroIdioma']) )
            $cdtIdioma->setOtroidioma(trim($_POST['txtOtroIdioma']));
        $cdtIdioma->setCodigonivelidioma($_POST['slctNivelIdioma']);
        $cdtIdioma->setBaja(false);
    }
    catch (Exception $exception)
    {
        $cdtIdioma = null;
        echo "construirCandidatoIdioma(): " . $exception->getMessage();
    }
    finally
    {
        return $cdtIdioma;
    }
}

function validarPerfil()
{
    /*
        *IdCandidaPerfil->
        *CodigoCandidato->$_POST['txtCdtPerfil']
        *CodigoPerfil->$_POST['slctPerfil']
        *CodigoRangoExperiencia->$_POST['slctRangoExperiencia']
        *Baja->
    */
	if( pll_current_language() == 'en')
    $lang1 = 'en_GB';
    else 
    $lang1 = 'es_ES';
   

    $msgError = "";

    //Validar CodigoCandidato
    
	
if($lang1=='en' || $lang1=='en_GB')
{
                             
   if(!isset($_POST['txtCdtPerfil']))
    {
        $msgError = $msgError . "The CodigoCandidato field must be informed<BR>"; 
    }
    else if ($_POST['txtCdtPerfil']==null || !is_numeric(trim($_POST['txtCdtPerfil'])))
    {
        $msgError = $msgError . "The CodigoCandidato field must be informed or contain a valid value<BR>"; 
    }
 }
 else
 {
   if(!isset($_POST['txtCdtPerfil']))
    {
        $msgError = $msgError . "El campo CodigoCandidato debe estar informado<BR>"; 
    }
    else if ($_POST['txtCdtPerfil']==null || !is_numeric(trim($_POST['txtCdtPerfil'])))
    {
        $msgError = $msgError . "El campo CodigoCandidato debe estar informado o contener un valor válido<BR>"; 
    }
   
 } 

    //Validar CodigoPerfil
  	
	if($lang1=='en' || $lang1=='en_GB')
{
                             
     if(!isset($_POST['slctPerfil']))
    {
        $msgError = $msgError . "The CodigoPerfil field must be informed<BR>"; 
    }
    else if ($_POST['slctPerfil']==null || !is_numeric($_POST['slctPerfil']))
    {
        $msgError = $msgError . "The CodigoPerfil field must be informed or contain a valid value<BR>"; 
    }
 }
 else
 {
     if(!isset($_POST['slctPerfil']))
    {
        $msgError = $msgError . "El campo CodigoPerfil debe estar informado<BR>"; 
    }
    else if ($_POST['slctPerfil']==null || !is_numeric($_POST['slctPerfil']))
    {
        $msgError = $msgError . "El campo CodigoPerfil debe estar informado o contener un valor válido<BR>"; 
    }
   
 } 
	
	

    //Validar CodigoRangoExperiencia
   

if($lang1=='en' || $lang1=='en_GB')
{
                             
      if(!isset($_POST['slctRangoExperiencia']))
    {
        $msgError = $msgError . "The CodigoRangoExperiencia field must be informed<BR>"; 
    }
    else if ($_POST['slctRangoExperiencia']==null || !is_numeric($_POST['slctRangoExperiencia']))
    {
        $msgError = $msgError . "The CodigoRangoExperiencia field must be informed or contain a valid value<BR>"; 
    }

 }
 else
 {
     if(!isset($_POST['slctRangoExperiencia']))
    {
        $msgError = $msgError . "El campo CodigoRangoExperiencia debe estar informado<BR>"; 
    }
    else if ($_POST['slctRangoExperiencia']==null || !is_numeric($_POST['slctRangoExperiencia']))
    {
        $msgError = $msgError . "El campo CodigoRangoExperiencia debe estar informado o contener un valor válido<BR>"; 
    }

   
 } 



    return $msgError;
}

function construirPerfil()
{
    try
    {
        /*
            *IdCandidatoPerfil->
            *CodigoCandidato->$_POST['txtCdtPerfil']
            *CodigoPerfil->$_POST['slctPerfil']
            *CodigoRangoExperiencia->$_POST['slctRangoExperiencia']
            *Baja->
        */
        $cdtPerfil = new DboCandidatoperfil();

        $cdtPerfil->setCodigocandidato($_POST['txtCdtPerfil']);
        $cdtPerfil->setCodigoperfil($_POST['slctPerfil']);
        $cdtPerfil->setCodigorangoexperiencia($_POST['slctRangoExperiencia']);
        $cdtPerfil->setBaja(false);
    }
    catch (Exception $exception)
    {
        $cdtPerfil = null;
        echo "construirPerfil(): " . $exception->getMessage();
    }
    finally
    {
        return $cdtPerfil;
    }
}

function uploadFiles($lfiles, $idCandidatoWP, $idConvocatoria) 
{
    $load = new Load();
    if($load->loadEnv() == null || !isset($_ENV))
    {
        throw $this->createNotFoundException(
            'No se han podido cargar las variables de entorno.'
        );
    }

    foreach ($lfiles as $fil) {
        $fil['name'] = clean($fil['name']); //limpiamos las rutas
        $ruta = '//' . $_ENV['CANDIDATE_FILES_DIR']. '/' . $idCandidatoWP . '//C'. $idConvocatoria .'//'.$fil['name'];
        $fileOrigen = $fil;
        $fileDestino = $_SERVER["DOCUMENT_ROOT"].$_ENV['FILES_DIR'].$ruta;
        $permiteImagenes = true;
        if(isset($retorno))
        {
            unset($retorno);
        }
        include(__DIR__ . "/../Utils/file_uploader.php");
        unset($permiteImagenes);

        if(!isset($retorno) || $retorno==false)
        {
            //move_uploaded_file() del file_uploader devuelve false pero el archivo se sube con éxito. Se da por bueno
            if($retorno==false && !file_exists($fileDestino))
            {
                echo $error;
                //Algo ha ido mal
                if(isset($retorno))
                {
                    unset($retorno);
                    return -1;
                }
            }
        }
    }
}

function clean($string) 
{
    $string = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $string);

    $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
    $string = preg_replace('/[^A-Za-z0-9\-\_\.]/', '', $string); // Removes special chars.
    $string = preg_replace('/_+/', '_', $string); // Replaces multiple slack down with single one

    return preg_replace('/-+/', '-', $string); // Replaces multiple hyphens with single one
}
?>