function __construct() { //session_start(); //require('app/Modelo/singleton.php'); $this->instancia = Conexion::getInstance(); $this->instancia->__construct(); $this->mysql = $this->instancia->getConnection(); $this->header = file_get_contents('Vistas/header.html'); $this->header = $this->headerSesion($this->header); }
function __construct() { //session_start(); require 'Controladores/generalCtl.php'; $this->instancia = Conexion::getInstance(); $this->instancia->__construct(); $this->mysql = $this->instancia->getConnection(); $this->generalctl = new General(); $this->header = file_get_contents("Vistas/header.html"); $this->header = $this->generalctl->headerSesion($this->header); $this->head = file_get_contents('Vistas/head.html'); $this->footer = file_get_contents('Vistas/footer.html'); }
function __construct() { //require('app/Modelo/singleton.php'); require 'app/Controladores/generalCtl.php'; $this->instancia = Conexion::getInstance(); $this->instancia->__construct(); $this->mysql = $this->instancia->getConnection(); $this->generalctl = new General(); $this->headerOriginal = file_get_contents("app/Vistas/header.html"); $this->header = $this->generalctl->headerSesion($this->headerOriginal); $this->footer = file_get_contents("app/Vistas/footer.html"); $this->head = file_get_contents("app/Vistas/head.html"); }
public static function nuevoCliente($nom_empresa, $nombre, $apellido, $email, $telefono) { require_once 'Trabajador.php'; $retVal = 1; //0->KO / 1->OK / 2->Existe el cliente /3-> Cliente insertado correo KO Utils::escribeLog("Inicio nuevoUsuario", "debug"); $bd = Conexion::getInstance()->getDb(); try { //Antes de insertar comprobar que no exista el mismo nombre de empresa $sql = "SELECT Cliente_Id FROM Clientes WHERE Nombre=:nom_emp"; $comando = $bd->prepare($sql); $comando->execute(array(":nom_emp" => $nom_empresa)); } catch (PDOException $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Línea: " . $e->getLine() . " [Usuario o email existentes]", "debug"); $retVal = 0; return $retVal; } $cuenta = $comando->rowCount(); if ($cuenta != 0) { Utils::escribeLog("nom_empresa y/o correo existentes en la BBDD -> KO", "debug"); $retVal = 2; return $retVal; } try { $bd->beginTransaction(); //insertar cliente $sql = "INSERT INTO Clientes(Nombre,Nombre_contacto,Apellido_contacto,Correo_contacto,Tel_contacto)VALUES\n\t\t\t(:nom_empresa,:nombre,:ape,:email,:tel)"; $comando = null; $comando = $bd->prepare($sql); $comando->execute(array(":nom_empresa" => $nom_empresa, ":nombre" => $nombre, ":ape" => $apellido, ":email" => $email, ":tel" => $telefono)); $bd->commit(); $idCli = $bd->lastInsertId(); } catch (PDOException $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Línea: " . $e->getLine() . " [Error al insertar usuario]", "debug"); $retVal = 0; $bd->rollback(); return $retVal; } try { $key = Utils::random_string(50); Trabajador::nuevoTrabajador($nombre, $apellido, $key, $idCli, $email); } catch (PDOException $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Línea: " . $e->getLine() . " [Error al insertar usuario]", "debug"); $retVal = 0; return $retVal; } return $retVal; //si todo va OK deveria devolver 1 }
public static function getLecturasByDisp($id) { $result = array(); try { $sql = "SELECT Dis_datos_Id,Dispositivo_Id,Volumen,Fuego,Fecha,Bateria FROM Dis_datos WHERE Dispositivo_Id=:id"; $comando = Conexion::getInstance()->getDb()->prepare($sql); $comando->execute(array(":id" => $id)); } catch (PDOException $e) { //Utils::escribeLog("Error: ".$e->getMessage()." | Fichero: ".$e->getFile()." | Línea: ".$e->getLine()." [Usuario o email existentes]","debug"); $result = null; return $result; } $cuenta = $comando->rowCount(); if ($cuenta == 0) { $result = null; return $result; } $result = $comando->fetchAll(PDO::FETCH_ASSOC); return $result; }
public static function nuevoTrabajador($nombre, $apellido, $key, $idCliente, $email) { $retVal = 1; $bd = Conexion::getInstance()->getDb(); try { $sql = "INSERT INTO Trabajadores(Nombre,Apellido,User_key,Cliente_Id,Email) VALUES(:nom,:ape,:key,:cliId,:email)"; $consulta = $bd->prepare($sql); $consulta->execute(array(":nom" => $nombre, ":ape" => $apellido, ":key" => $key, ":cliId" => $idCliente, ":email" => $email)); } catch (PDOException $e) { $retVal = 0; return $retVal; } $cuenta = $comando->rowCount(); if ($cuenta != 0) { //Utils::escribeLog("nom_empresa y/o correo existentes en la BBDD -> KO","debug"); $retVal = 2; return $retVal; } $correouser = new CorreoUser(); $correouser->enviarCorreoRegistro($idUsuario, $Nombre, $ape1, $correo, $key); }
public static function changeTrabajador($nom, $apel, $tel, $ema, $trabId) { $bd = Conexion::getInstance()->getDb(); $retVal = 1; try { //$sql="UPDATE Trabajadores SET Activo='1' WHERE Trabajador_Id LIKE :id"; // $comando=$db->prepare($sql); //$comando->execute(array(':id'=>$TrabId)); //SET `Dispositivo_Id`=[value-1],`Cliente_Id`=[value-2],`Latitud`=[value-3],`Longitud`=[value-4],`Activo`=[value-5],`Barrio`=[value-6],`Tipo`=[value-7] $sql = "UPDATE Trabajadores SET Nombre=:no, Apellido=:ape, Telefono=:te,Email=:em WHERE Trabajador_Id=:traId"; $comando = $bd->prepare($sql); $comando->execute(array(":no" => $nom, ":ape" => $apel, ":te" => $tel, ":em" => $ema, ":traId" => $trabId)); } catch (PDOException $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Linea: " . $e->getLine() . " []", "debug"); $retVal = 0; return retVal; } if ($comando->rowCount() == 0) { Utils::escribeLog("Error al validar", "debug"); $retVal = 0; return $retVal; } return $retVal; }
public static function getAllDisp($id) { $posiciones = array(); try { //Obtener los datos de los dispositivos $sql = "SELECT dis.Dispositivo_Id,dis.Cliente_Id,dis.Latitud,dis.Longitud,dis.Barrio,dis.Tipo,L.Volumen,L.Fuego,L.Bateria,L.Fecha \n\t\t\t\t\t FROM Dispositivos as dis, Dis_datos as L LEFT JOIN Dis_datos as R\t\t\t \n\t\t\t\t\t ON L.Dispositivo_Id=R.Dispositivo_Id AND L.Fecha<R.Fecha\n\t\t\t\t\t WHERE isnull(R.Dispositivo_Id)AND dis.Dispositivo_Id=L.Dispositivo_Id \n\t\t\t\t\t AND Cliente_Id IN(SELECT trab.Cliente_Id\n\t\t\t\t\t\t\t\t\t\tFROM Usuarios as usu JOIN Trabajadores as trab\n\t\t\t\t\t\t\t\t\t\tON usu.Trabajador_Id=trab.Trabajador_Id\n\t\t\t\t\t\t\t\t\t\tWHERE usu.Usuario_Id=:id)\n\t\t\t\t\t ORDER BY dis.Tipo"; $comando = Conexion::getInstance()->getDb()->prepare($sql); $comando->execute(array(':id' => $id)); } catch (PDOException $e) { //Utils::escribeLog("Error: ".$e->getMessage()." | Fichero: ".$e->getFile()." | Línea: ".$e->getLine()." [Error al insertar posicion]","debug"); $posiciones['estado'] = 0; $posiciones['resultado'] = $e->getMessage(); return $posiciones; } $cuenta = $comando->rowCount(); if ($cuenta == 0) { $posiciones['estado'] = 0; $posiciones['resultado'] = "No hay dispositivos disponibles."; return $posiciones; } $posiciones['estado'] = 1; $posiciones['resultado'] = $comando->fetchAll(PDO::FETCH_ASSOC); return $posiciones; }
public static function getUsrData($idUsu) { $bd = Conexion::getInstance()->getDb(); $res = array(); try { $sql = "SELECT trab.Nombre, trab.Apellido,trab.Profile_ImageURL\n\t\t\t\t FROM Usuarios AS usu JOIN Trabajadores AS trab \n\t\t\t\t ON usu.Trabajador_Id = trab.Trabajador_Id\n\t\t\t\t WHERE usu.Usuario_Id LIKE :id"; $comando = $bd->prepare($sql); $comando->execute(array(":id" => $idUsu)); } catch (PDOException $e) { //Utils::escribeLog("Error: ".$e->getMessage()." | Fichero: ".$e->getFile()." | Línea: ".$e->getLine()." ","debug"); $res['estado'] = 0; $res['resultado'] = $e->getMessage(); return $res; } $cuenta = $comando->rowCount(); if ($cuenta == 0) { $res['estado'] = 0; $res['resultado'] = "Noo hay resultados de usuario"; return $res; } else { $res['estado'] = 1; $res['resultado'] = $comando->fetch(PDO::FETCH_ASSOC); return $res; } }
public static function comprobarUsuario($idUsuario, $pass) { $retVal = 1; Utils::escribeLog('inicio comprobar usuario', 'debug'); //comprobar en bd try { $sql = "SELECT id_usuario,nombre,apellido1,validado FROM usuario WHERE id_usuario LIKE :id AND pass LIKE :pass"; $comando = Conexion::getInstance()->getDb()->prepare($sql); $comando->execute(array(":id" => $idUsuario, ":pass" => md5($pass))); } catch (PDOException $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Línea: " . $e->getLine() . " ", "debug"); $retval = 0; return $retVal; } $cuenta = $comando->rowCount(); if ($cuenta == 0) { $retVal = 0; return $retVal; } $datos = $comando->fetch(PDO::FETCH_ASSOC); if ($datos['validado'] == 0) { $retVal = 2; return $retVal; } else { $_SESSION['id_usuario'] = $datos['id_usuario']; $_SESSION['nombre'] = $datos['nombre']; $_SESSION['apellido'] = $datos['apellido1']; return $retVal; } }
public static function modTrabajador($nom, $apel, $tel, $ema, $idUsu, $imgURL = null) { $bd = Conexion::getInstance()->getDb(); $retVal = 1; if (is_null($imgURL)) { $sql = "UPDATE Trabajadores SET Nombre=:no, Apellido=:ape, Telefono=:te,Email=:em \n\t\t\t WHERE Trabajador_Id IN(SELECT Trabajador_Id\n\t\t\t\t\t\t\t\t\tFROM Usuarios\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tWHERE Usuario_Id=:id)"; $variables = array(":no" => $nom, ":ape" => $apel, ":te" => $tel, ":em" => $ema, ":id" => $idUsu); } else { $sql = "UPDATE Trabajadores SET Nombre=:no, Apellido=:ape, Telefono=:te,Email=:em, Profile_ImageURL=:img \n\t\t\t\t WHERE Trabajador_Id IN(SELECT Trabajador_Id\n\t\t\t\t\t\t\t\t\t\tFROM Usuarios\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\tWHERE Usuario_Id=:id)"; $variables = array(":no" => $nom, ":ape" => $apel, ":te" => $tel, ":em" => $ema, "img" => $imgURL, ":id" => $idUsu); } try { $comando = $bd->prepare($sql); $comando->execute($variables); } catch (PDOException $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Linea: " . $e->getLine() . " []", "debug"); $retVal = 0; return $retVal; } if ($comando->rowCount() == 0) { Utils::escribeLog("Error al validar", "debug"); $retVal = 0; return $retVal; } return $retVal; }
public static function ModDispositivo($dis, $cli, $latit, $longit, $act, $tip) { $bd = Conexion::getInstance()->getDb(); $retVal = 1; try { //comprobar si hay valores distintos $sql = "UPDATE Dispositivos SET Latitud=:lat,Longitud=:long,Tipo=:tip,Activo=:act WHERE Dispositivo_Id=:dis"; $comando = $bd->prepare($sql); $comando->execute(array(":lat" => $latit, ":long" => $longit, ":tip" => $tip, ":act" => $act, ":dis" => $dis)); } catch (PDOException $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Linea: " . $e->getLine() . " []", "debug"); $retVal = 0; return $retVal; } if ($comando->rowCount() == 0) { Utils::escribeLog("Error al validar", "debug"); $retVal = 0; return $retVal; } return $retVal; }
public static function comprobarUsuario($idUsuario, $pass) { $retVal = 1; //Utils::escribeLog('inicio comprobar usuario','debug'); //comprobar en bd try { $sql = "SELECT usu.Usuario_Id, trab.Nombre, trab.Apellido\n\t\t\t\t FROM Usuarios AS usu\n\t\t\t\t JOIN Trabajadores AS trab ON usu.Trabajador_Id = trab.Trabajador_Id\n\t\t\t\t WHERE usu.Nombre_Usuario LIKE :id\n\t\t\t\t AND usu.Password LIKE :pass"; $comando = Conexion::getInstance()->getDb()->prepare($sql); $comando->execute(array(":id" => $idUsuario, ":pass" => md5($pass))); } catch (PDOException $e) { //Utils::escribeLog("Error: ".$e->getMessage()." | Fichero: ".$e->getFile()." | Línea: ".$e->getLine()." ","debug"); $retVal = 0; return $retVal; } $cuenta = $comando->rowCount(); if ($cuenta == 0) { $retVal = 0; return $retVal; } $datos = $comando->fetch(PDO::FETCH_ASSOC); $_SESSION['id_usuario'] = $datos['Usuario_Id']; $_SESSION['nombre'] = $datos['Nombre']; $_SESSION['apellido'] = $datos['Apellido']; return $retVal; }
public function __construct() { $this->conexion = Conexion::getInstance(); }
function __construct() { $this->pdo = Conexion::getInstance(); $this->log = LoggingHelper::getLogger(); }
public static function changeCliente($nom_empresa, $coment, $nif, $nombre, $apellido, $correo, $telefono, $cliente, $compra) { $retVal = 1; $bd = Conexion::getInstance()->getDb(); try { $sql = "UPDATE Clientes SET Nombre=:nomempr,Comprado=:compra,Comentarios=:com,NIF=:nif,Nombre_contacto=:nom,Apellido_contacto=:apell,Correo_contacto=:cor,Tel_contacto=:tel WHERE Cliente_Id=:cli"; $comando = $bd->prepare($sql); $comando->execute(array(":nomempr" => $nom_empresa, ":compra" => $compra, ":com" => $coment, ":nif" => $nif, ":nom" => $nombre, ":apell" => $apellido, ":cor" => $correo, ":tel" => $telefono, ":cli" => $cliente)); } catch (PDOException $e) { Utils::escribeLog("Error: " . $e->getMessage() . " | Fichero: " . $e->getFile() . " | Línea: " . $e->getLine() . " [Usuario o email existentes]", "debug"); $retVal = 0; return $retVal; } if ($comando->rowCount() == 0) { Utils::escribeLog("Error al validar", "debug"); $retVal = 0; return $retVal; } return $retVal; }
public static function getAllDispMod($id) { $posiciones = array(); $bd = Conexion::getInstance()->getDb(); try { $sql = "SELECT dis.Dispositivo_Id,dis.Cliente_Id,dis.Latitud,dis.Longitud,dis.Barrio,dis.Tipo,dis.Activo\n\t\t\t \t\t FROM Dispositivos as dis\n\t\t\t \t\t WHERE Cliente_Id IN(SELECT trab.Cliente_Id\n\t\t\t\t\t\t\t\t \t\t FROM Usuarios as usu JOIN Trabajadores as trab\n\t\t\t\t\t\t\t\t\t\t ON usu.Trabajador_Id=trab.Trabajador_Id\n\t\t\t\t\t\t\t\t\t\t WHERE usu.Usuario_Id=:id)\n\t\t\t ORDER BY dis.Dispositivo_Id,dis.Tipo"; $comando = $bd->prepare($sql); $comando->execute(array(':id' => $id)); } catch (PDOException $e) { //Utils::escribeLog("Error: ".$e->getMessage()." | Fichero: ".$e->getFile()." | Línea: ".$e->getLine()." [Error al insertar posicion]","debug"); $posiciones['estado'] = 0; $posiciones['resultado'] = $e->getMessage(); return $posiciones; } $cuenta = $comando->rowCount(); if ($cuenta == 0) { $posiciones['estado'] = 0; $posiciones['resultado'] = "No hay dispositivos disponibles."; return $posiciones; } $posiciones['estado'] = 1; $posiciones['resultado'] = $comando->fetchAll(PDO::FETCH_ASSOC); return $posiciones; }
public static function getPosicionesByUsuario() { $posiciones = array(); try { //si la cuenta da 0 insertar $sql = "SELECT `Latitude`,`Longitude`,`Bario` FROM Dispositivos"; $comando = Conexion::getInstance()->getDb()->prepare($sql); $comando->execute(); } catch (PDOException $e) { //Utils::escribeLog("Error: ".$e->getMessage()." | Fichero: ".$e->getFile()." | Línea: ".$e->getLine()." [Error al insertar posicion]","debug"); $posiciones = null; return $posiciones; } $cuenta = $comando->rowCount(); if ($cuenta == 0) { $posiciones = null; return $posiciones; } $posiciones = $comando->fetchAll(PDO::FETCH_ASSOC); return $posiciones; }
function modificarContrasenia($dni, $contrasenia, $nuevacontrasenia) { $consulta = "UPDATE empleado set CONTRASENIA=? WHERE DNI_EMPLEADO=? AND CONTRASENIA = ?"; $preparando = Conexion::getInstance()->prepare($consulta); $preparando->bind_param("sss", $nuevacontrasenia, $dni, $contrasenia); //configuramos la consulta if ($preparando->execute()) { return true; } else { return false; } }