예제 #1
0
 public function baixar_prematriculados()
 {
     $msg = null;
     $data = $this->getParametroVisao();
     $data['page'] = 'home';
     $data['tema'] != '' ? $this->load->setTheme($data['tema']) : '';
     $data['msg'] = $msg;
     $data['abaAtiva'] = 26;
     $data['abaPage'] = 'baixar_prematriculados';
     $data['alias'] = 'baixar_prematriculados';
     if ($_SERVER['REQUEST_METHOD'] == "POST") {
         try {
             // View::validarFormAntInjection('contrato');
             $data_matricula = View::converteDataEUA($this->input->post('data_evento'));
             $sqlMatricula = new SqlMatricula();
             $result = $sqlMatricula->get_dados($data_matricula, $this->input->post('pk_unidade'));
             $corpo = '';
             foreach ($result as $row) {
                 $alu_resp = str_pad($row['alu_resp'], 50);
                 $alu_resnaci = str_pad($row['alu_resnaci'], 2);
                 $alu_resestciv = str_pad($row['alu_resestciv'], 10);
                 $alu_resprof = str_pad($row['alu_resprof'], 20);
                 $alu_cpfres = str_pad($row['alu_cpfres'], 14);
                 $alu_resident = str_pad($row['alu_resident'], 15);
                 $alu_resorgao = str_pad($row['alu_resorgao'], 8);
                 $alu_resend = str_pad($row['alu_resend'], 40);
                 $alu_resbai = str_pad($row['alu_resbai'], 12);
                 $alu_resnum = str_pad($row['alu_resnum'], 8);
                 $alu_rescom = str_pad($row['alu_rescom'], 8);
                 $alu_rescid = str_pad($row['alu_rescid'], 15);
                 $alu_resuf = str_pad($row['alu_resuf'], 2);
                 $alu_rescep = str_pad($row['alu_rescep'], 9);
                 $alu_resfone = str_pad($row['alu_resfone'], 25);
                 $alu_rescel = str_pad($row['alu_rescel'], 13);
                 $alu_resemail = str_pad($row['alu_resemail'], 30);
                 $alu_nom = str_pad($row['alu_nom'], 50);
                 $alu_sexo = str_pad($row['alu_sexo'], 1);
                 $alu_nasc = str_pad($row['alu_nasc'], 10);
                 $alu_pai = str_pad($row['alu_pai'], 50);
                 $alu_mae = str_pad($row['alu_mae'], 50);
                 $alu_fone = str_pad($row['alu_fone'], 25);
                 $alu_cel = str_pad($row['alu_cel'], 13);
                 $alu_naci = str_pad($row['alu_naci'], 10);
                 $alu_end = str_pad($row['alu_end'], 50);
                 $alu_num = str_pad($row['alu_num'], 8);
                 $alu_compl = str_pad($row['alu_compl'], 10);
                 $alu_bai = str_pad($row['alu_bai'], 12);
                 $alu_cid = str_pad($row['alu_cid'], 15);
                 $alu_uf = str_pad($row['alu_uf'], 2);
                 $alu_cep = str_pad($row['alu_cep'], 9);
                 $escola_origem = str_pad($row['escola_origem'], 30);
                 $corpo .= $alu_resp . "#" . $alu_resnaci . "#" . $alu_resestciv . "#" . $alu_resprof . "#" . $alu_cpfres . "#" . $alu_resident . "#" . $alu_resorgao . "#" . $alu_resend . "#" . $alu_resbai . "#" . $alu_resnum . "#" . $alu_rescom . "#" . $alu_rescid . "#" . $alu_resuf . "#" . $alu_rescep . "#" . $alu_resfone . "#" . $alu_rescel . "#" . $alu_resemail . "#" . $alu_nom . "#" . $alu_sexo . "#" . $alu_nasc . "#" . $alu_pai . "#" . $alu_mae . "#" . $alu_fone . "#" . $alu_cel . "#" . $alu_naci . "#" . $alu_end . "#" . $alu_num . "#" . $alu_compl . "#" . $alu_bai . "#" . $alu_cid . "#" . $alu_uf . "#" . $alu_cep . "#" . $escola_origem . " \r\n";
             }
             $nome_arquivo = $this->input->post('pk_unidade') . '_' . $data_matricula;
             $arquivo = "uploadArquivos/matricula/" . $nome_arquivo . ".txt";
             unlink($arquivo);
             // Abre ou cria o arquivo bloco1.txt
             // "a" representa que o arquivo é aberto para ser escrito
             $fp = fopen($arquivo, "a");
             // Escreve "exemplo de escrita" no bloco1.txt
             $escreve = fwrite($fp, $corpo);
             // Fecha o arquivo
             fclose($fp);
             $tipo = "application/txt";
             header("Content-Type: " . $tipo);
             // informa o tipo do arquivo ao navegador
             header("Content-Length: " . filesize($arquivo));
             // informa o tamanho do arquivo ao navegador
             header("Content-Disposition: attachment; filename=" . basename($arquivo));
             // informa ao navegador que é tipo anexo e faz abrir a janela de download, tambem informa o nome do arquivo
             readfile($arquivo);
             // lê o arquivo
             exit;
             // aborta pós-ações
         } catch (Exception $e) {
             $msg = '<p class="alert erro">' . $e->getMessage() . '</p>';
         }
     }
     if (!empty($data['unidades'])) {
         if (count($data['unidades']) == 1) {
             $pk_unidade = $data['unidades'][0];
             $data['atendente_unidade'] = 1;
         } else {
             $pk_unidade = isset($_GET['pk_unidade']) && $_GET['pk_unidade'] != '' ? $_GET['pk_unidade'] : 0;
             $data['atendente_unidade'] = 0;
         }
     } else {
         $pk_unidade = isset($_GET['pk_unidade']) && $_GET['pk_unidade'] != '' ? $_GET['pk_unidade'] : 0;
         $data['atendente_unidade'] = 0;
     }
     $data['pk_unidade'] = $pk_unidade;
     $config['base_url'] = base_url() . $this->uri->segment(1) . '/' . $this->uri->segment(2) . '/' . $this->uri->segment(3) . '/';
     // Select filtro de unidade
     $sqlUsuario = new SqlUsuario();
     $data['unidade'] = $sqlUsuario->unidade();
     $unidade = explode("&pk_unidade=", $_SERVER['QUERY_STRING']);
     $data['unidade_url'] = $config['base_url'] . $this->uri->segment(4) . '?' . $unidade[0];
     $this->load->view($this->load->getUrlTema(), $data);
 }