Login   Register  
PHP Classes
elePHPant
Icontem

File: clasefilecounter.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of markitos  >  filecounter  >  clasefilecounter.php  >  Download  
File: clasefilecounter.php
Role: ???
Content type: text/plain
Description: filecounter base class
Class: filecounter
File counter class
Author: By
Last change:
Date: 12 years ago
Size: 2,799 bytes
 

Contents

Class file image Download
<?
class filecounter
{
var $_File;
var $_Tabla = "counter";
var $_Modo;
var $_ModosValidos = array ("open");

function filecounter ($Filename=0, $Modo="open")
{      
  if (!in_array ($Modo, $this->_ModosValidos)){ $Modo = "open"; }
  $this->_Modo = $Modo;
  
  $this->_File = $Filename;
  $this->_Set();  

  $this->Parsea();
    
  return $this;  
}

function DameHref()
{
  global $PHP_SELF,$HTTP_GET_VARS;

  $Retorno='';
  $Link = $PHP_SELF.'?';
  $HTTP_GET_VARS[fcaccion]= "upcounter";
  $HTTP_GET_VARS[fcfile]  = $this->_Encripta();
  foreach ($HTTP_GET_VARS as $Clave=>$Valor){ $Link.='&'.$Clave.'='.$Valor; }
  $Retorno = $Link;

  return $Retorno;  
}

function CambiaFile ($NuevoFile=0)
{
  $this->_File = $NuevoFile;
  $this->_Set();   
}

function DameDatos ($Datos="*")
{
  $Retorno=0;
  $Accesobd = new accesobd();
    $Sql = "SELECT ".$Datos." FROM ".$this->_Tabla." WHERE file='".$this->_File."'";  
    $Retorno = $Accesobd->QueryBDObjeto ($Sql);
  return $Retorno;
}

function Parsea()
{
  global $HTTP_GET_VARS;

  if ($HTTP_GET_VARS[fcaccion]!= "upcounter"){ return $Retorno; }
  $this->_File = $HTTP_GET_VARS[fcfile];  
  $this->_File = $this->_DesEncripta();

  $Accesobd = new accesobd();
    $Sql = "UPDATE ".$this->_Tabla." SET counter=counter+1 ";
    $Sql.= "WHERE file='".$this->_File."'";
    $Accesobd->InsertaBD ($Sql);
  
  $Retorno = $this->DameDatos ("counter");
  $Retorno = $Retorno->counter;  

  $CadenaEval = '$this->Modo'.strtolower (ucwords ($this->_Modo)).'();';
  eval ($CadenaEval);
       
  return $Retorno;  
}

function _Set()
{
  global $HTTP_GET_VARS;
  if (!$this->_File){ $this->_File=$HTTP_GET_VARS[fcfile]; }
  $this->_File = $this->_DesEncripta ();
  if (!$this->_Existe()){ $this->_InsertaNuevo(); }  
}

function _Existe()
{
  $Retorno=0;
    
  $Accesobd = new accesobd();  
    $Sql = "SELECT identificador FROM ".$this->_Tabla." WHERE file='".$this->_File."'";
    $Identificador = $Accesobd->QueryBDObjeto ($Sql);
    if ($Identificador->identificador){ $Retorno=1; }
  
  return $Retorno;
}

function _InsertaNuevo()
{
  $Retorno=0;  

  if (!$this->_File){ return $Retorno; }
 
  $Accesobd = new accesobd();  
    $Sql = "INSERT INTO ".$this->_Tabla."(identificador,file,counter) ";
    $Sql.= "VALUES ('', '".$this->_File."', '')";
    $Retorno = $Accesobd->InsertaBD ($Sql);
 
  return $Retorno;  
}

function ModoOpen()
{
  ?>
  <script language="Javascript">
    window.open ('<?=$this->_File?>');
  </script>
  <?  
}

function _Encripta()
{
  $Retorno = urlencode ($this->_File);
  return $Retorno;  
}

function _DesEncripta()
{    
  $Retorno = urldecode ($this->_File);  
  return $Retorno;
}

}
?>