my code stock.com

este archivo es una clase y debe estar dentro de una carpeta de nombre "class" dentro del mismo directorio "system" en que se encuentra el archivo "wellart.php"

Snippet options

Download: Download snippet as datauserphp.php.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

<?php

class dataUser extends cnx{
	function __construct($username = null,$id = null){
		parent::__construct();
		if($username != null){
			$this->select($username);
		}elseif($id != null){
			$this->selectById($id);
		}
	}

	var $nombre;
	var $apellido_p;
	var $apellido_m;
	var $email;
	var $id;
	var $username;
	var $password;
	private $old_pass;
	var $status;
	var $tipo;
	var $result;

	function selectById($id){
		$id = $this->escapar($id);
		$cmd = $this->cnx->query("SELECT * FROM usuarios WHERE id = '".$id."'");
		if($cmd){
			$a = $cmd->fetch_assoc();
			$nombre = explode("|",$a["nombre"]);
			$this->nombre = $nombre[0];
			$this->apellido_p = $nombre[1];
			$this->apellido_m = $nombre[2];
			$this->email = $a["email"];
			$this->username = $a["username"];
			$this->password = $a["password"];
			$this->old_pass = $a["password"];
			$this->status = $a["status"];
			$this->tipo = $a["tipo"];
			$this->id = $a["id"];
		}
	}

	function select($username){
		$username = $this->escapar($username);
		$cmd = $this->cnx->query("SELECT * FROM usuarios WHERE username = '".$username."'");
		if($cmd){
			$a = $cmd->fetch_assoc();
			$nombre = explode("|",$a["nombre"]);
			$this->nombre = $nombre[0];
			$this->apellido_p = $nombre[1];
			$this->apellido_m = $nombre[2];
			$this->email = $a["email"];
			$this->username = $a["username"];
			$this->password = $a["password"];
			$this->old_pass = $a["password"];
			$this->status = $a["status"];
			$this->tipo = $a["tipo"];
			$this->id = $a["id"];
		}
	}

	function insert(){
		if($this->hasVal_all()) {
			$this->escapar_all();
			$cmd = "INSERT INTO usuarios VALUES(NULL,"
				."'".$this->username."',"
				."PASSWORD('".$this->password."'),"
				."'".$this->nombre."|".$this->apellido_p."|".$this->apellido_m."',"
				."'".$this->email."',"
				."'0',"
				."'".$this->tipo."');";
			if($this->cnx->query($cmd)){
				$this->id = $this->cnx->insert_id;
				$this->result = "INSERT Realizado correctamente.";
				return true;
			}
		}
		return false;
	}

	function update(){
		if($this->hasVal_all()){
			$this->escapar_all();
			$cmd = "UPDATE usuarios SET "
				."password = PASSWORD('".$this->password."'), "
				."nombre = '".$this->nombre."|".$this->apellido_p."|".$this->apellido_m."', "
				."email = '".$this->email."'"
				."WHERE id = '".$this->id."';";
			if($this->cnx->query($cmd)){
				$this->result = "UPDATE Realizado correctamente";
				return true;
			}
		}
		return false;
	}

	function delete(){
		if(!is_null($this->id) && isset($this->id)){
			$cmd = $this->cnx->query("UPDATE usuarios SET status = 1 WHERE id = '".$this->id."';");
			if($cmd){
				$this->result = "Usuario eliminado correctamente";
				return true;
			}
		}
		return false;
	}

	function hasVal_all(){
		if(!$this->hasVal($this->nombre)){ return false; }
		if(!$this->hasVal($this->apellido_p)){ return false; }	
		if(!$this->hasVal($this->apellido_m)){ return false; }
		if(!$this->hasVal($this->email)){ return false; }
		if(!$this->hasVal($this->username)){ return false; }
		if(!$this->hasVal($this->password)){ return false; }
		return true;
	}

	function escapar_all(){
		$this->nombre = $this->escapar($this->nombre);
		$this->apellido_p = $this->escapar($this->apellido_p);
		$this->apellido_m = $this->escapar($this->apellido_m);
		$this->email = $this->escapar($this->email);
		$this->email = filter_var($this->email,FILTER_SANITIZE_FULL_EMAIL);
		$this->username = $this->escapar($this->username);
		$this->password = $this->escapar($this->password);
		return true;
	}
}
?>

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.