[#] hm X_Shell Backd00r [#]

Current Path : /var/www/clients/client35/web46/web/buen-fin/app/model/
Upload File :
Current File : /var/www/clients/client35/web46/web/buen-fin/app/model/CcontadorVisitas.class.php

<?php



require_once "conexion.class.php";

class ContadorVisitas{
	
	public $ip;
	public $promo;

	function __construct(){
		$this->conex = Conexion::singleton_conexion();
		$this->ip = $_SERVER['REMOTE_ADDR'];
	}

	public function contador(){
		try{
			
			$sql="SELECT ip, TIMEDIFF(NOW(), fecha), fecha, num_visitas FROM contador WHERE ip=:ip";
			$query = $this->conex->prepare($sql);
			$query->execute(array(":ip"=>$this->ip));
			$fila = $query->fetch(PDO::FETCH_ASSOC);
			$tiempo=$fila["TIMEDIFF(NOW(), fecha)"]; //Diferencia entre fecha guardada y fecha actual
			$num_visitas=$fila["num_visitas"]; //Número de visitas
			$horas_t=substr($tiempo,0,2); //Número de horas transcurridas
			$tiemRes = 5; //Varible de tiempo en horas para restringir la visita	
			
			if($query->rowCount() == 0){
				
				$sql="INSERT INTO contador(ip, num_visitas, fecha) VALUES(:ip, 1, NOW())";
				$query = $this->conex->prepare($sql);
				$query->execute(array(":ip"=>$this->ip));

			}
			
			if($query->rowCount() >= 1  && $horas_t > $tiemRes){
				
				$sql="UPDATE contador SET fecha=NOW(), num_visitas='$num_visitas'+1 WHERE ip=:ip";
				$query = $this->conex->prepare($sql);
				$query->execute(array(":ip"=>$this->ip));
			}
							
		}catch(PDOExeption $e){
			print "Error!: ".$e->getMessage();
		}
	}


	public function totalvisitas(){
		try{
			$sql="SELECT SUM(num_visitas) AS total FROM contador"; //Obtenemos la suma de todas las visitas
			$query = $this->conex->prepare($sql);
			$query->execute();
			$fila = $query->fetch(PDO::FETCH_ASSOC);
			if($query->rowCount() > 0):
				return $fila['total'];
			else:
				return false;
			endif;
			
		}catch(PDOExeption $e){
			print "Error!: ".$e->getMessage();
		}
	}

	public function contadorpromo(){
		try{
			$sql="SELECT * FROM contadorpromo WHERE ip = :ip AND promo = :promo ";
			$query = $this->conex->prepare($sql);
			$query->execute(array(":promo"=>$this->promo,":ip"=>$this->ip));
			if($query->rowCount() == 0):
				$sql="INSERT INTO contadorpromo(promo, ip) VALUES(:promo, :ip)";
				$query = $this->conex->prepare($sql);
				$query->execute(array(":promo"=>$this->promo,":ip"=>$this->ip));
				if($query->rowCount() > 0):
					return true;
				else:
					return false;
				endif;
			else:
				return false;
			endif;

		}catch(PDOExeption $e){
			print "Error!: ".$e->getMessage();
		}	
	}

	public function totalvisitaspromociones(){
		try{
			$sql="SELECT COUNT(ip) AS total FROM contadorpromo WHERE promo = :promo"; //Obtenemos la suma de todas las visitas
			$query = $this->conex->prepare($sql);
			$query->execute(array(":promo"=>$this->promo));
			$res = $query->fetch(PDO::FETCH_ASSOC);
			if($query->rowCount() > 0):
				return $res['total'];
			else:
				return false;
			endif;
			
		}catch(PDOExeption $e){
			print "Error!: ".$e->getMessage();
		}
	}

	public function totalregistradospromos(){
		try{
			$sql="SELECT COUNT(ip) AS total FROM registro WHERE promocion = :promo"; //Obtenemos la suma de todas las visitas
			$query = $this->conex->prepare($sql);
			$query->execute(array(":promo"=>$this->promo));
			$res = $query->fetch(PDO::FETCH_ASSOC);
			if($query->rowCount() > 0):
				return $res['total'];
			else:
				return false;
			endif;
			
		}catch(PDOExeption $e){
			print "Error!: ".$e->getMessage();
		}
	}

}





?>

Mr.hm X_Shell Backd00r 1.0, Coded By Mr.hm X_Shell Backd00r