Esempio n. 1
0
 public static function inscricao()
 {
     header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
     header('Cache-Control: no-store, no-cache, must-revalidate');
     header('Cache-Control: pre-check=0, post-check=0, max-age=0');
     header('Pragma: no-cache');
     if (!empty($_POST)) {
         $participante = new Participante();
         if (empty($_POST['nome'])) {
             $erro .= 'nr|';
         }
         if (empty($_POST['email'])) {
             $erro .= 'er|';
         }
         if (!preg_match('/^[a-zA-Z0-9][a-zA-Z0-9\\._-]+@([a-zA-Z0-9\\._-]+\\.)[a-zA-Z-0-9]{2}/', $_POST['email']) && !empty($_POST['email'])) {
             $erro .= 'ei|';
         }
         if ($participante->count('email = \'' . $_POST['email'] . '\'') > 0 && !empty($_POST['email'])) {
             $erro .= 'ee|';
         }
         if (empty($_POST['telefone'])) {
             $erro .= 'tr|';
         }
         if (empty($_POST['data_nascimento'])) {
             $erro .= 'dnr|';
         }
         if (!empty($_POST['data_nascimento'])) {
             $data_nascimento = explode("/", $_POST['data_nascimento']);
             if ($data_nascimento[1] == 2 && $data_nascimento[0] > 29 || in_array($data_nascimento[1], array(4, 6, 9, 11)) && $data_nascimento[0] > 30 || $data_nascimento[0] > 31 || $data_nascimento[1] > 12 || $data_nascimento[2] . $data_nascimento[1] . $data_nascimento > date('Ymd')) {
                 $erro .= 'dni|';
             }
         }
         if (empty($_POST['sexo'])) {
             $erro .= 'sr|';
         }
         if (empty($_POST['cpf'])) {
             $erro .= 'cr|';
         }
         if (!preg_match('/\\d{3}[\\.]\\d{3}[\\.]\\d{3}[\\-]\\d{2}/', $_POST['cpf']) && !empty($_POST['cpf'])) {
             $erro .= 'ci|';
         }
         if ($participante->count('cpf = \'' . $_POST['cpf'] . '\'') > 0 && !empty($_POST['cpf'])) {
             $erro .= 'ce|';
         }
         if (!empty($_POST['cep']) && !preg_match('/\\d{5}[\\-]\\d{3}/', $_POST['cep'])) {
             $erro .= 'cei|';
         }
         if (!isset($_POST['estado']) || empty($_POST['estado'])) {
             $erro .= 'esr|';
         }
         if (!isset($_POST['cidade']) || empty($_POST['cidade'])) {
             $erro .= 'cir|';
         }
         if (!isset($_POST['bairro']) || empty($_POST['bairro'])) {
             $erro .= 'br|';
         }
         if (!isset($_POST['logradouro']) || empty($_POST['logradouro'])) {
             $erro .= 'lr|';
         }
         if (!isset($_POST['numero']) || empty($_POST['numero'])) {
             $erro .= 'nr|';
         }
         if (!empty($_POST['numero']) && !preg_match('/\\d+/', $_POST['numero'])) {
             $erro .= 'ni|';
         }
         if (!isset($_POST['instituicao']) || empty($_POST['instituicao'])) {
             $erro .= 'ir|';
         }
         if (!isset($_POST['area_atuacao']) || empty($_POST['area_atuacao'])) {
             $erro .= 'ar|';
         }
         if (!isset($_POST['profissao']) || empty($_POST['profissao'])) {
             $erro .= 'pr|';
         }
         if ($_POST['profissao'] == 770 && (!isset($_POST['outra_profissao']) || empty($_POST['outra_profissao']))) {
             $erro .= 'opr|';
         }
         if (!isset($_POST['grau_instrucao']) || empty($_POST['grau_instrucao'])) {
             $erro .= 'gir|';
         }
         if (!isset($_POST['tamanho_camisa']) || empty($_POST['tamanho_camisa'])) {
             $erro .= 'tcr|';
         }
         if (isset($_POST['voucher']) && !empty($_POST['voucher'])) {
             //TODO Voucher
             $voucher = new Voucher();
             $listaDeVouchers = $voucher->listar("hash LIKE '" . trim($_POST['voucher']) . "'");
             if (count($listaDeVouchers) <= 0) {
                 $erro .= 'vch|';
             }
             //Testa se ja foi usado
             $voucher2 = new Voucher();
             $listaDeVouchers2 = $voucher2->listar("hash LIKE '" . trim($_POST['voucher']) . "' AND usado = 0 ");
             if (count($listaDeVouchers2) <= 0) {
                 $erro .= 'vch2|';
             }
         }
         if (!empty($erro)) {
             $_SESSION['dados'] = $_POST;
             if (strpos($_SERVER['HTTP_REFERER'], '?') !== false) {
                 $caminho = explode("?", $_SERVER['HTTP_REFERER']);
                 $caminho = $caminho[0];
             } else {
                 $caminho = $_SERVER['HTTP_REFERER'];
             }
             header('Location: ' . Configuracao::$baseUrl . 'inscricao' . Configuracao::$extensaoPadrao . '?e=' . $erro);
             exit;
         }
         $participante->nome = trim($_POST['nome']);
         $participante->funcao = trim($_POST['funcao']);
         $participante->email = trim($_POST['email']);
         $participante->sexo = trim($_POST['sexo']);
         $participante->data_nascimento = trim($_POST['data_nascimento']);
         $participante->cpf = trim($_POST['cpf']);
         $participante->rg = trim($_POST['rg']);
         $participante->orgao_emissor = trim($_POST['orgao_emissor']);
         $participante->cep = trim($_POST['cep']);
         $participante->telefone = trim($_POST['telefone']);
         $participante->estado = $_POST['estado'];
         $participante->cidade = $_POST['cidade'];
         $participante->bairro = trim($_POST['bairro']);
         $participante->logradouro = trim($_POST['logradouro']);
         $participante->numero = trim($_POST['numero']);
         $participante->profissao = trim($_POST['profissao']);
         $participante->outra_profissao = trim($_POST['outra_profissao']);
         $participante->grau_instrucao = trim($_POST['grau_instrucao']);
         $participante->instituicao = trim($_POST['instituicao']);
         $participante->area_atuacao = trim($_POST['area_atuacao']);
         $participante->tamanho_camisa = trim($_POST['tamanho_camisa']);
         if (isset($_POST['voucher']) && !empty($_POST['voucher'])) {
             $participante->voucher = $_POST['voucher'];
         }
         /*
         TODO BOLETO POR WEBSERVICE
         */
         if ($participante->funcao == 'participante') {
             $cURL = curl_init('url do ws');
             curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
             $post = array('post' => array('nome' => $participante->nome, 'cpf' => $participante->cpf, 'cep' => $participante->cep, 'logradouro' => $participante->logradouro, 'num' => $participante->numero, 'bairro' => $participante->bairro, 'cidade' => $participante->getCidade()->nome, 'estado' => $participante->getEstado()->nome, 'complemento' => $participante->complemento, 'voucher' => @$listaDeVouchers[0]->desconto, 'email' => $participante->email), 1 => 1);
             curl_setopt($cURL, CURLOPT_POST, true);
             curl_setopt($cURL, CURLOPT_POSTFIELDS, http_build_query($post));
             $resposta = curl_exec($cURL);
             curl_close($cURL);
             $resposta = json_decode($resposta);
             $participante->nossonumero = $resposta->nossonumero;
         }
         if ($participante->salvar() && $participante->funcao == 'participante') {
             if (isset($_POST['voucher']) && !empty($_POST['voucher'])) {
                 $voucher3 = new Voucher();
                 $voucher3->selecionarPorId(@$listaDeVouchers[0]->id);
                 $voucher3->usado = 1;
                 $voucher3->salvar();
             }
             echo '<meta charset="UTF-8">';
             echo "<script>alert('Você cadastrou-se com sucesso!'); document.location.href='" . Configuracao::$baseUrl . 'confirmacaoCadastro' . Configuracao::$extensaoPadrao . '?nn=' . $participante->nossonumero . "';</script>";
             exit;
         } else {
             echo '<meta charset="UTF-8">';
             echo "<script>alert('Você cadastrou-se com sucesso!'); document.location.href='" . Configuracao::$baseUrl . 'confirmacaoCadastro' . Configuracao::$extensaoPadrao . "';</script>";
             exit;
         }
     }
     $listaFuncoes = Listas::getFuncao();
     $listaSexos = Listas::getSexo();
     $listaAreasAtuacao = Listas::getAreaAtuacao();
     $listaGrausIntrucao = Listas::getGrauInstrucao();
     $listaTamanhosCamisa = Listas::getTamanhoCamisa();
     $profissao = new Profissao();
     $listaProfissoes = $profissao->listar(null, 'nome');
     $estado = new Estado();
     $listaEstados = $estado->listar(null, 'nome');
     $texto = new Texto();
     $texto->selecionarPorId(10);
     self::$corpo = "inscricao";
     self::$variaveis = array('texto' => $texto, 'listaFuncoes' => $listaFuncoes, 'listaSexos' => $listaSexos, 'listaAreasAtuacao' => $listaAreasAtuacao, 'listaGrausInstrucao' => $listaGrausIntrucao, 'listaTamanhosCamisa' => $listaTamanhosCamisa, 'listaProfissoes' => $listaProfissoes, 'listaEstados' => $listaEstados);
     self::renderizar(self::$viewController);
 }
 public static function listarGrid()
 {
     $page = $_GET['page'];
     // get the requested page
     $limit = $_GET['rows'];
     // get how many rows we want to have into the grid
     $sidx = $_GET['sidx'];
     // get index row - i.e. user click to sort
     $sord = $_GET['sord'];
     // get the direction
     if (!$sidx) {
         $sidx = 1;
     }
     // connect to the database
     if ($_GET['_search'] === 'true') {
         switch ($_GET['searchOper']) {
             case 'eq':
                 $condicao = $_GET['searchField'] . " = " . $_GET['searchString'];
                 break;
             case 'ne':
                 $condicao = $_GET['searchField'] . " <> " . $_GET['searchString'];
                 break;
             case 'bw':
                 $condicao = $_GET['searchField'] . " LIKE '" . $_GET['searchString'] . "%'";
                 break;
             case 'bn':
                 $condicao = $_GET['searchField'] . " NOT LIKE '" . $_GET['searchString'] . "%'";
                 break;
             case 'ew':
                 $condicao = $_GET['searchField'] . " LIKE '%" . $_GET['searchString'] . "'";
                 break;
             case 'en':
                 $condicao = $_GET['searchField'] . " NOT LIKE '%" . $_GET['searchString'] . "'";
                 break;
             case 'cn':
                 $condicao = $_GET['searchField'] . " LIKE '%" . $_GET['searchString'] . "%'";
                 break;
             case 'nc':
                 $condicao = $_GET['searchField'] . " NOT LIKE '%" . $_GET['searchString'] . "%'";
                 break;
             case 'nu':
                 $condicao = $_GET['searchField'] . " IS NULL";
                 break;
             case 'nn':
                 $condicao = $_GET['searchField'] . " IS NOT NULL";
                 break;
             case 'in':
                 $condicao = $_GET['searchField'] . " IN (" . $_GET['searchString'] . ")";
                 break;
             case 'ni':
                 $condicao = $_GET['searchField'] . " NOT IN (" . $_GET['searchString'] . ")";
                 break;
         }
     } else {
         $condicao = null;
     }
     $participante = new Participante();
     $count = $participante->count($condicao);
     //$count = 10000000;
     if ($count > 0) {
         $total_pages = ceil($count / $limit);
     } else {
         $total_pages = 0;
         $limit = 0;
     }
     if ($page > $total_pages) {
         $page = $total_pages;
     }
     $start = $limit * $page - $limit;
     if ($sidx == "acoes") {
         $order = "pago ASC, nossonumero ASC";
     } else {
         if ($sidx == 'idade') {
             $sidx = 'data_nascimento';
         }
         $order = $sidx . " " . $sord;
     }
     $listaDeParticipantes = $participante->listar($condicao, $order, $start . "," . $limit);
     $responce = new stdClass();
     $responce->page = $page;
     $responce->total = $total_pages;
     $responce->records = $count;
     foreach ($listaDeParticipantes as $indice => $participante) {
         if ($participante->funcao == 'participante') {
             if ($participante->pago) {
                 $botao = '<a id="participante-' . $participante->id . '" title="Desaprovar o pagamento do participante" href="javascript:void(0);" class="btn btn-small btn-success btn-pagar" style="width:35%; margin-right:2%; color:white;">Pago</a>';
             } else {
                 $botao = '<a title="enviar boleto ao participante por email" href="javascript:void(0);" id="enviar_' . $participante->id . '" class="btn btn-small" ><i class="btn-icon-only icon-envelope"> enviar boleto</i></a> <a id="participante-' . $participante->id . '" title="Aprovar o pagamento do participante" href="javascript:void(0);" class="btn btn-small btn-danger btn-pagar" style="width:35%; margin-right:2%; color:white;">Não Pago</a>';
             }
             //Com voucher
             if ($participante->voucher) {
                 $botao = '<a title="Voucher: ' . $participante->voucher . '" href="javascript:void(0);" class="btn btn-small btn-info btn-pagar" style="width:35%; margin-right:2%; color:white;" >Voucher</a>';
             }
         } else {
             $botao = '<a id="isento-' . $participante->id . '" title="Participante isento de pagamento" href="javascript:void(0);" class="btn btn-small btn-primary" style="width:35%; margin-right:2%; color:white;">Isento</a>';
         }
         //TODO IDADE
         $idadeParticipante = Funcao::calculaIdade($participante->data_nascimento);
         $responce->rows[$indice]['id'] = $participante->id;
         $responce->rows[$indice]['cell'] = @array($participante->id, $participante->nome, $participante->funcao, $idadeParticipante, $participante->email, $participante->estado ? $participante->getEstado()->nome : '---', $participante->cidade ? $participante->getCidade()->nome : '---', $botao);
     }
     echo json_encode($responce);
 }