Advertisement
Guest User

erro dados booleanos

a guest
Dec 12th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.90 KB | None | 0 0
  1. <?php
  2.  
  3.         class Cadastro extends DB{
  4.        
  5.                 public $erro;
  6.                 private $dados;
  7.                 private $_tabela;
  8.                 /*Extende a classe*/   
  9.                 function __construct(array $dados, $table='usuarios'){
  10.                        
  11.                         $this->_tabela = $table;
  12.                         $this->dados = $dados;
  13.                        
  14.                         $this->register();
  15.                        
  16.                 }
  17.                
  18.                 private function crip($senha){
  19.                         return sha1($senha);
  20.                 }
  21.                
  22.                 private function check($email){
  23.                         $check = self::getConn()->prepare('SELECT `id` FROM `'.$this->_tabela.'` WHERE `email`=? LIMIT 1');
  24.                         $check->execute(array($email));
  25.                         return $check->rowCount()==0 ? true : false;
  26.                 }
  27.                /*Checa se o email é valido "Se já esta cadastrado"*/
  28.                 private function validar(){
  29.                session_start();
  30.                        if(strtolower($this->dados['captcha'])<>strtolower($_SESSION['securimage_code_value'])){
  31.                                 $this->erro[] = 'O captcha não confere com a imagem!';
  32.                         }
  33.                      
  34.                         foreach($this->dados as $colunm=>$value){
  35.                                
  36.                                 if($colunm == 'senha'){
  37.                                         $this->dados[$colunm] = $this->crip($value);
  38.                                 }
  39.                                
  40.                                 if($value==''){
  41.                                         $this->erro[] = 'O campo <strong>'.$colunm.'</strong> é obrigat&oacute;rio!';
  42.                                 }
  43.                         }
  44.                        
  45.                         if($colunm=='email' AND !preg_match("/^[a-z0-9_\.\-]+@[a-z0-9_\.\-]*[a-z0-9_\-]+\.[a-z]{2,4}$/i",$value)){
  46.                                 $this->erro[] = 'O email digitado n&atilde;o &eacute; v&aacute;lido!';
  47.                         }
  48.                        
  49.                        
  50.                 }
  51.                
  52.         /*Valida se todos os campos foram preenchidos*/
  53.                 private function setCampos(){
  54.                         return '`'.implode('`=?, `',array_keys($this->dados)).'`=?';
  55.                 }
  56.                
  57.                 private function register(){
  58.                        
  59.                         $this->validar();
  60.                        
  61.                         if($this->check($this->dados['email'])){
  62.                        
  63.                                 if(empty($this->erro)){
  64.                                        
  65.                                         unset($this->dados['captcha']);
  66.                                        
  67.                                         $inserir = self::getConn()->prepare('INSERT INTO '.$this->_tabela.' SET '.$this->setCampos().', `cadastro`=NOW()');
  68.                                         if($inserir->execute(array_values($this->dados))){
  69.                                                 header('Location: ./');
  70.                                                 exit();
  71.                                         }else{
  72.                                                 $this->erro[] = 'Não foi possivel fazer seus cadastro agora! Tente mais tarde!';
  73.                                         }
  74.                                        
  75.                                 }
  76.                        
  77.                         }else{
  78.                                 $this->erro[] = 'O email digitado ja est&aacute; cadastrado!';
  79.                         }
  80.                 }
  81.                
  82.                 function getErros(){
  83.                         return implode('<br />', $this->erro);
  84.                 }
  85.                
  86.         }
  87.  
  88.         ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement