Advertisement
s00rk

Clase Contacto

Nov 23rd, 2011
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.85 KB | None | 0 0
  1. <?php
  2.  
  3. class Contacto
  4. {
  5.     var $Nombre;
  6.     var $Email;
  7.     var $Web;
  8.     var $Mensaje;
  9.     var $MiCorreo = array("andrew@mokomonster.com", "crymore3@gmail.com"); // Correos a quienes se les enviara
  10.     var $Opcion = array(0, 1, 2); // Las formas que deceemos que se guarden 0 = Archivo en el servidor, 1 = Por Correo, 2 = En una tabla de la BD
  11.     var $Exito;
  12.     var $BD = array("localhost", "root", "", "Contacto");
  13.    
  14.     public function SetDatos($nombre, $correo, $web, $mensaje)
  15.     {
  16.         $this->Nombre = limpiar($nombre);
  17.         $this->Email = limpiar($correo);
  18.         $this->Web = limpiar($web);
  19.         $this->Mensaje = limpiar($mensaje);
  20.     }
  21.    
  22.     public function Enviar()
  23.     {
  24.         if(!$this->ChecarDatos())
  25.         {
  26.             alerta("Alguno(s) de los campos estan vacios", "/");
  27.             die();
  28.         }
  29.         $this->Exito = false;
  30.         $Hoy = date("F j, Y, g:i a");
  31.         // Guardando en un Archivo
  32.         if(in_array(0, $this->Opcion))
  33.         {
  34.             $archivo = @fopen("Contacto.txt", "a+");
  35.             @fprintf($archivo, "Fecha[%s]: %s\n%s\n%s\n%s \n\n\n", $Hoy, $this->Mensaje,"By".$this->Nombre,$this->Email,$this->Web);
  36.             @fclose($archivo);
  37.             $this->Exito = true;
  38.         }
  39.         // Enviando un mail a todos los administradores
  40.         if(in_array(1, $this->Opcion))
  41.         {
  42.             foreach($this->MiCorreo as $corr)
  43.             {
  44.                 if(@mail($this->MiCorreo, "Contacto [".$this->Nombre."]", $this->Mensaje."<br />By".$this->Nombre."<br />".$this->Email."<br />".$this->Web))
  45.                 {
  46.                     $this->Exito = true;
  47.                 }
  48.             }
  49.         }
  50.         // Guardando la informacion en la BD
  51.         $link = @mysql_connect($this->BD[0], $this->BD[1], $this->BD[2]);
  52.         if($link)
  53.         {
  54.             if(@mysql_select_db($this->BD[3], $link))
  55.             {
  56.                 /*
  57.                 Tabla [Contacto]
  58.                 idContacto INT AutoIncrementable
  59.                 Nombre varchar(45) NOT NULL
  60.                 Email varchar(45) NOT NULL
  61.                 Web varchar(45) NULL
  62.                 Mensaje varchar(500) NOT NULL
  63.                 Fecha varchar(50) NOT NULL             
  64.                 */
  65.                 $sql = @mysql_query("INSERT INTO Contacto (Nombre, Email, Web, Mensaje, Fecha) VALUES ('".$this->Nombre."', '".$this->Email."', '".$this->Web."', '".$this->Mensaje."', '".$Hoy."')");
  66.                 if($sql)
  67.                 {
  68.                     $this->Exito = true;
  69.                 }
  70.             }
  71.         }
  72.         if($this->Exito)
  73.         {
  74.             alerta("Mensaje Enviado, Te responderemos lo mas pronto posible!", "/");
  75.             die();
  76.         }else{
  77.             alerta("Hubo un error al enviar el mensaje para contacto, intente de nuevo mas tarde porfavor!", "/");
  78.             die();
  79.         }
  80.     }
  81.    
  82.     private function ChecarDatos()
  83.     {
  84.         if(empty($this->Nombre) || empty($this->Email) || empty($this->Mensaje))
  85.         {
  86.             return false;
  87.         }
  88.         return true;           
  89.     }
  90.    
  91.     private function limpiar($valor)
  92.     {
  93.         $check = $valor;
  94.         $valor = mysql_real_escape_string(htmlspecialchars(strip_tags($valor)));
  95.         return ($check != $valor) ? "" : $valor;
  96.     }
  97.    
  98.     private function alerta($text, $url)
  99.     {
  100.         echo "<body  bgcolor='#000000'><script>alert('$text');document.location = '$url'</script></body>";
  101.         die("Javascript disabled");
  102.     }
  103.    
  104. }
  105.  
  106. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement