/**
  * listar_candidato
  * Lista candidatos
  *
  * @author joao paulo bastos <jpbl.bastos at gmail dot com>
  * @param  string $tipo     [p = presidentes / g = governadores]
  * @param  string $uf       [se informado tipo = g, deve se informar a uf para buscar os governadores]
  * @return string           [html preparado]
  */
 public function listar_candidato($tipo = '', $uf = '')
 {
     /* inicializa variavel erro_msg */
     $this->erro_msg = '';
     /* inicializa */
     $data = '';
     $this->html = '';
     /* inicializa sql */
     $this->sql = '';
     /* prepara sql */
     if ($tipo === "p") {
         $tipo = 1;
     } elseif ($tipo === "g") {
         $tipo = 2;
     } else {
         $this->erro_msg = "OPS, erro em setar o tipo de consulta !";
         return false;
     }
     if (!empty($uf)) {
         $this->sql = "SELECT candidato.idcandidato, candidato.nome, candidato.sobrenome, candidato.face, candidato.idade, candidato.url_foto, cidade.nome, estado.uf, partido.sigla\n                            FROM (((eleicao.candidato INNER JOIN eleicao.cidade ON eleicao.candidato.idcidade_cidade = eleicao.cidade.idcidade)\n                            INNER JOIN eleicao.estado ON eleicao.cidade.idestado_estado = eleicao.estado.idestado)\n                            INNER JOIN eleicao.partido ON eleicao.candidato.idpartido_partido =  eleicao.partido.idpartido)\n                            WHERE candidato.idtipo_tipo = " . $tipo . " AND eleicao.estado.uf = '" . uf . "'' ;";
     } else {
         $this->sql = "SELECT candidato.idcandidato, candidato.nome, candidato.sobrenome, candidato.face, candidato.idade, candidato.url_foto, cidade.nome, estado.uf, partido.sigla\n                            FROM (((eleicao.candidato INNER JOIN eleicao.cidade ON eleicao.candidato.idcidade_cidade = eleicao.cidade.idcidade)\n                            INNER JOIN eleicao.estado ON eleicao.cidade.idestado_estado = eleicao.estado.idestado)\n                            INNER JOIN eleicao.partido ON eleicao.candidato.idpartido_partido =  eleicao.partido.idpartido)\n                            WHERE candidato.idtipo_tipo = " . $tipo . " ;";
     }
     /* Trabalhando com a base de dados */
     if (!$this->db->open()) {
         $this->erro_msg = $this->db->erroMsg;
         return false;
     }
     if (!$this->db->query($this->sql)) {
         $this->erro_msg = $this->db->erroMsg;
         return false;
     }
     /* percorre consulta realizada e gera html */
     $this->html .= "<div class='lista-candidato'>";
     $this->html .= "<div class='col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 lista'>";
     $this->html .= "   <h3 class='text-muted'>Candidatos a Presidência <i class='fa fa-star fa-fw'></i></h3>";
     $this->html .= "   <div class='row placeholders'>";
     while ($data = $this->db->fetch()) {
         $this->html .= "<div class='col-xs-6 col-sm-3 placeholder'>";
         $this->html .= "   <img src='" . $data['url_foto'] . "' class='img-responsive' alt='" . utf8_encode($data['nome']) . " " . utf8_encode($data['sobrenome']) . "'>";
         $this->html .= "   <h4>" . utf8_encode($data[1]) . " " . utf8_encode($data[2]) . "</h4>";
         $this->html .= "  <h4>" . $data['sigla'] . "</h4>";
         $this->html .= "   <div class='caption'>";
         $this->html .= "      <br />";
         $this->html .= "      <p><a href='#' class='btn btn-primary' role='button' onclick='votar(" . $data['idcandidato'] . ");'>Votar <i class='fa fa-paper-plane fa-fw'></i></a> <a href='" . $data['face'] . "' target='_blank' class='btn btn-default' role='button'>Mais <i class='fa fa-tags fa-fw'></i></a></p>";
         $this->html .= "  </div>";
         $this->html .= "</div>";
     }
     $this->html .= "   </div>";
     $this->html .= "</div>";
     $this->html .= "</div>";
     $this->db->close();
     /* Finalizando com o banco */
     return $this->html;
 }
 /**
  * estatistica_voto
  * Lista candidatos
  *
  * @author joao paulo bastos <jpbl.bastos at gmail dot com>
  * @param  string $tipo     [p = presidentes / g = governadores]
  * @param  string $uf       [se informado tipo = g, deve se informar a uf para buscar os governadores]
  * @return string $html     [html preparado]
  */
 public function estatistica_voto()
 {
     /* inicializa variavel erro_msg */
     $this->erro_msg = '';
     /* inicializa */
     $data = '';
     $this->html = '';
     /* inicializa sql */
     $this->sql = '';
     $this->sql = "SELECT COUNT(*), candidato.nome, candidato.sobrenome, candidato.url_foto, partido.sigla, parametro.status\n                         FROM (((eleicao.votacao INNER JOIN  eleicao.candidato ON votacao.idcandidato_candidato = candidato.idcandidato)\n                         INNER JOIN eleicao.partido ON candidato.idpartido_partido =  partido.idpartido)\n                         INNER JOIN eleicao.parametro ON votacao.idparametro_parametro = parametro.idparametro)\n                         WHERE parametro.idtipo_tipo = 1\n                         GROUP BY candidato.nome;";
     /* Trabalhando com a base de dados */
     if (!$this->db->open()) {
         $this->erro_msg = $this->db->erroMsg;
         return false;
     }
     if (!$this->db->query($this->sql)) {
         $this->erro_msg = $this->db->erroMsg;
         return false;
     }
     /* percorre consulta realizada e gera html */
     $this->html .= "<div class='lista-candidato'>";
     $this->html .= "<div class='col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 lista'>";
     $this->html .= "   <h3 class='text-muted'>Corrida a Presidência <i class='fa fa-rocket fa-fw'></i></h3>";
     $this->html .= "   <div class='row placeholders'>";
     while ($data = $this->db->fetch()) {
         $this->html .= "<div class='col-xs-6 col-sm-3 placeholder'>";
         $this->html .= "   <img src='" . $data['url_foto'] . "' class='img-responsive' alt='" . utf8_encode($data['nome']) . " " . utf8_encode($data['sobrenome']) . "'>";
         $this->html .= "   <h4>" . utf8_encode($data[1]) . " " . utf8_encode($data[2]) . "</h4>";
         $this->html .= "  <h4>" . $data['sigla'] . "</h4>";
         $this->html .= "   <div class='caption'>";
         $this->html .= "      <h4>" . $data[0] . " Votos</h4>";
         $this->html .= "  </div>";
         $this->html .= "</div>";
     }
     $this->html .= "   </div>";
     $this->html .= "</div>";
     $this->html .= "</div>";
     $this->db->close();
     /* Finalizando com o banco */
     return $this->html;
 }
 /**
  * votar
  * Faz a votação
  *
  * @author  joao paulo bastos <jpbl.bastos at gmail dot com>
  * @param  int $ideleitor   - defin o eleitor 
  * @param  int $idcandidato - define o candidato escolhido
  * @return boolean
  */
 public function votar($ideleitor = null, $idcandidato = null)
 {
     /* inicializa variavel */
     $this->erro_msg = '';
     $this->html = '';
     /* inicializa sql */
     $this->sql = '';
     /* Trabalhando com a base de dados */
     if (!$this->db->open()) {
         $this->erro_msg = $this->db->erroMsg;
         return false;
     }
     if (!$this->verifica_se_pode($ideleitor)) {
         $this->sql = "INSERT INTO eleicao.votacao(ideleitor_eleitor, idparametro_parametro,idcandidato_candidato) \n                               VALUES (" . $ideleitor . "," . $this->idparametro . "," . $idcandidato . ");";
         if ($this->db->query($this->sql)) {
             $this->html .= "<div class='jumbotron' id='box'>";
             $this->html .= "<form class='form-signin' role='form' >";
             $this->html .= "   <h3 class='text-muted'> Obrigado seu voto foi registrado :)</h3>";
             $this->html .= "<br/>";
             $this->html .= "<a class='btn btn-lg btn-primary' href='../pesquisa/' role='button'>Veja á Corrida <i class='fa fa-rocket fa-fw'></i></a>";
             $this->html .= "</form>";
             $this->html .= "</div> <!-- /jumbotron -->";
             return true;
         } else {
             $this->erro_msg = $this->db->erroMsg;
             return false;
         }
     } else {
         $this->html .= "<div class='jumbotron' id='box'>";
         $this->html .= "<form class='form-signin' role='form' >";
         $this->html .= "   <h3 class='text-muted'> Desculpe mas você ja deixou seu voto nessa pesquisa :(</h3>";
         $this->html .= "   <h3 class='text-muted'> Entre na próxima !</h3>";
         $this->html .= "<br/>";
         $this->html .= "<a class='btn btn-lg btn-primary' href='../pesquisa/' role='button'>Veja á Corrida <i class='fa fa-rocket fa-fw'></i></a>";
         $this->html .= "</form>";
         $this->html .= "</div> <!-- /jumbotron -->";
         return false;
     }
     $this->db->close();
     /* Finalizando com o banco */
 }
 /**
  * consulta_eleitor
  * Consulta todos dados eleitor 
  *
  * @author João Paulo Bastos <jpbl.bastos at gmail dot com>
  * @return boolean     [status da consulta]
  */
 private function consulta_eleitor()
 {
     /* inicializa sql */
     $this->sql = '';
     $colun = '';
     /* Contém o nome da coluna */
     $data = '';
     /* Armazena a linha consultada */
     /* prepara sql */
     $this->sql = "SELECT nome, sobrenome, email, idade, idcidade_cidade FROM eleicao.eleitor WHERE eleitor.ideleitor = '" . $this->get_dado('ideleitor') . "';";
     /* Trabalhando com a base de dados */
     if (!$this->db->open()) {
         $this->erro_msg = $this->db->erroMsg;
         return false;
     }
     if (!$this->db->query($this->sql)) {
         $this->erro_msg = $this->db->erroMsg;
         return false;
     }
     /* Recebe matriz de dados e percorre preenchendo os atributos da classe */
     $data = $this->db->fetch();
     $i = 0;
     while ($i < $this->db->num_fields()) {
         $colun = $this->db->fetch_field($i);
         $this->set_dado($colun->name, $data[$colun->name]);
         $i++;
     }
     $this->db->close();
     /* Finalizando com o banco */
     return true;
 }