function getUsuarioRegistrado($post, $urlHome=NULL, $urlPerfil=NULL, $urlInvitado=NULL){
//echo "ACA";
$link=$this->conBD();
if (isset($_COOKIE['rem'])){
$dat=explode('|', $_COOKIE['rem']);
$query=sprintf("SELECT DECODE('%s','%s'), DECODE('%s','%s')", html_entity_decode($dat[0]), PHASE, html_entity_decode($dat[1]), PHASE);
try{
if (!$res=$this->db_exec($query))
throw new Exception ('<div class="alert warning">Error: Error en consulta BD, obteniendo data - '.__FUNCTION__.'</div>');
$row=mysql_fetch_array($res);
if (md5($dat[0].'|'.$dat[1].PHASE)==$dat[2]){
$query=sprintf("SELECT idcolaborador, nombre, apelpat, apelmat, idcargo FROM %s WHERE login='%s' AND pwd=ENCODE('%s','%s') AND estatus=1 ORDER BY idcolaborador ASC LIMIT 0, 1", COLAB, $row[0], $row[1], PHASE);
}
else{
$this->reloadLocation('/');
exit;
}
}
catch(Exception $e){
$err=$e->getMessage();
$this->logUsuario('Error (try)'.$err);
return $err;
}
}
else{
$query=sprintf("SELECT idcolaborador, nombre, apelpat, apelmat, idcargo FROM %s WHERE login='%s' AND pwd=ENCODE('%s','%s') AND estatus=1 ORDER BY idcolaborador ASC LIMIT 0, 1", COLAB, $this->InsMySQL($post['login']), $this->InsMySQL($post['pwd']), PHASE);
}
try{
if (!$res=$this->db_exec($query))
throw new Exception ('<div class="alert warning">Error: Error en consulta BD, obteniendo data - '.__FUNCTION__.'</div>');
//echo $query;
if (mysql_num_rows($res)>0){
$row=mysql_fetch_array($res);
session_start();
$_SESSION['adminCliente']=true;
$_SESSION['nombre']=$row['nombre'];
$_SESSION['cargo']=$row['idcargo'];
$_SESSION['apelPat']=$row['apelpat'];
$_SESSION['apelMat']=$row['apelmat'];
$_SESSION['idUser']=$row['idcolaborador'];
$_SESSION['ipUser']=$_SERVER['REMOTE_ADDR'];
$_SESSION['agentUser']=$_SERVER['HTTP_USER_AGENT'];
$_SESSION['inicioUser']=strftime("%Y-%m-%d %H:%M:%S");
$_SESSION['chkUser']=MD5(session_id().$_SESSION['idUser'].$_SESSION['inicioUser'].$_SESSION['ipUser']);
//echo "ACA1";
$query=sprintf("INSERT INTO %s (fecha, chk, idcolaborador) VALUES (NOW(), '%s', %d)", COLLO, $_SESSION['chkUser'], $_SESSION['idUser']);
//echo $query;
if (!$res=$this->db_exec($query))
throw new Exception ('<div class="alert warning">Error: Error en consulta BD, ingresando datos de Login - '.__FUNCTION__.'</div>');
else{
//echo "ACA3";
$_SESSION['idLogin']=mysql_insert_id();
if ($_POST['remember']==1){
$query=sprintf("SELECT ENCODE('%s', '%s'), ENCODE('%s', '%s')", $_POST['login'], PHASE, $_POST['pwd'], PHASE);
if (!$res=$this->db_exec($query))
throw new Exception ('<div class="alert warning">Error: Error en consulta BD, ingresando datos de Login - '.__FUNCTION__.'</div>');
else{
//echo "ACA4";
$row=mysql_fetch_array($res);
setcookie('remCubo3', htmlentities($row[0]).'|'.htmlentities($row[1]).'|'.md5(htmlentities($row[0]).'|'.htmlentities($row[1]).PHASE), time()+1296000, '/admin/', $_SERVER['SERVER_NAME']);
}
}
$this->logUsuario('Ingreso a sistema');
if ($_SESSION['cargo']==1)
$this->reloadLocation($urlHome);
elseif($_SESSION['cargo']==2)
$this->reloadLocation($urlPerfil);
else
$this->reloadLocation($urlInvitado);
exit;
}
//echo "ACA2";
}
else
throw new Exception ('<div class="content-box-content column-right" style="border=0px;"><div class="notification attention png_bg"><a href="#" class="close"><img src="/admin/resources/images/icons/cross_grey_small.png" title="Cerrar esta notificación" alt="cerrar" /></a><div>Problema: No se han encontrado resultados de Usuario<br></div></div></div>');
}
catch(Exception $e){
$err=$e->getMessage();
$this->logUsuario('Error (try)'.$err);
return $err;
}
}