public function import_alunos($pk_unidade, $ano_letivo) { try { $this->getDb()->beginTransaction(); $sql = "DELETE FROM mestre.ggeint_alunos WHERE unidade = " . $pk_unidade; $prepare = $this->getDb()->prepare($sql); $prepare->execute(); require_once 'php/conexao_mysql.php'; $query_Recordset1 = "SELECT * FROM Alunos"; mysql_select_db($database_principal, $principal); $Recordset1 = mysql_query($query_Recordset1, $principal) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $total = mysql_num_rows($Recordset1); do { $alu_nom = Mestre::trata_campos($row_Recordset1['ALU_NOM']); $alu_pai = Mestre::trata_campos($row_Recordset1['ALU_PAI']); $alu_mae = Mestre::trata_campos($row_Recordset1['ALU_MAE']); $alu_resp = Mestre::trata_campos($row_Recordset1['ALU_RESP']); $alu_dtnasc = $row_Recordset1['ALU_DTNASC']; $alu_end = Mestre::trata_campos($row_Recordset1['ALU_END']); $alu_num = Mestre::trata_campos($row_Recordset1['ALU_NUM']); $alu_compl = Mestre::trata_campos($row_Recordset1['ALU_COMPL']); $alu_bai = Mestre::trata_campos($row_Recordset1['ALU_BAI']); $alu_cid = Mestre::trata_campos($row_Recordset1['ALU_CID']); $alu_cep = Mestre::trata_campos($row_Recordset1['ALU_CEP']); $alu_uf = Mestre::trata_campos($row_Recordset1['ALU_UF']); $alu_cpf = Mestre::trata_campos($row_Recordset1['ALU_CPF']); $alu_ident = substr(Mestre::trata_campos($row_Recordset1['ALU_IDENT']), 0, 10); $alu_sexo = Mestre::trata_campos($row_Recordset1['ALU_SEXO']); $sql = "INSERT INTO mestre.ggeint_alunos (alu_mat, alu_nom, alu_pai, alu_mae, alu_resp, alu_dtnasc, unidade, alu_end, alu_num, alu_compl, alu_bai, alu_cid, alu_cep, alu_uf, alu_cpf, alu_ident, alu_sexo) \n VALUES ('" . utf8_encode($row_Recordset1['ALU_MAT']) . "', '" . $alu_nom . "', '" . $alu_pai . "', '" . $alu_mae . "', '" . $alu_resp . "', '" . $alu_dtnasc . "', " . $pk_unidade . ", '" . $alu_end . "', '" . $alu_num . "', '" . $alu_compl . "', '" . $alu_bai . "', '" . $alu_cid . "', '" . $alu_cep . "', '" . $alu_uf . "', '" . $alu_cpf . "', '" . $alu_ident . "', '" . $alu_sexo . "')"; $prepare = $this->getDb()->prepare($sql); $prepare->execute(); } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); $sql = "SELECT COUNT(*) FROM mestre.ggeint_alunos WHERE unidade = " . $pk_unidade; $prepare = $this->getDb()->prepare($sql); $prepare->execute(); $totalInserido = $prepare->fetchAll(); $this->getDb()->commit(); return array('total_origem' => $total, 'total_inserido' => $totalInserido[0]['count']); } catch (Exception $e) { $this->getDb()->rollBack(); throw new Exception($e->getMessage()); } }
public function checa_anteriores() { $data = $this->getParametroVisao(); $data['page'] = 'home'; $data['tema'] != '' ? $this->load->setTheme($data['tema']) : ''; $data['msg'] = $this->getMsg(); $data['abaAtiva'] = 3; $data['abaPage'] = 'checa_anteriores'; // vefifica se é a primeira vez que será feita a importação da unidade $sqlAtualizacao = new SqlAtualizacao(); $total = $sqlAtualizacao->get_alunos_otimize($this->uri->segment(4), $data['ano_letivo']); // seta a sessão unidade $this->session->set_userdata('unidade', $this->uri->segment(4)); // se não tiver dados, é a primeira vez if ($total > 0) { require_once 'php/conexao_mysql.php'; $query_Recordset1 = "SELECT a.ALU_MAT, a.ALU_NOM,\n b.VIN_ANO, b.VIN_OCOCOD\n FROM Alunos a\n JOIN Vinculos b ON a.ALU_MAT = b.VIN_ALUMAT\n WHERE b.VIN_OCOCOD = 'MT'\n GROUP BY a.ALU_MAT"; mysql_select_db($database_principal, $principal); $Recordset1 = mysql_query($query_Recordset1, $principal) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $total = mysql_num_rows($Recordset1); $count = 0; do { // echo $row_Recordset1['ALU_NOM'].'<br />'; $sqlAtualizacao = new SqlAtualizacao(); $result = $sqlAtualizacao->listar_alunos_atuais($this->session->userdata('unidade'), Mestre::trata_campos($row_Recordset1['ALU_NOM'])); if ($result > 0) { $count++; } } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); $percent = $count / $total * 100; if ($percent > 80) { redirect(base_url() . $this->uri->segment(1) . '/' . $this->uri->segment(2) . '/mestre1_vinculos'); } else { $data['msg'] = '<div class="alert atencao">Apenas ' . number_format($percent, 1) . '% dos alunos da base selecionada constam na versão anterior. Você tem certeza que selecionou a unidade correta?<br/><a class="submit" href="' . base_url() . $this->uri->segment(1) . '/' . $this->uri->segment(2) . '/mestre1_vinculos">Sim</a><a class="submit" href="' . base_url() . $this->uri->segment(1) . '/' . $this->uri->segment(2) . '">Não</a></div>'; } $this->load->view($this->load->getUrlTema(), $data); } else { redirect(base_url() . $this->uri->segment(1) . '/' . $this->uri->segment(2) . '/mestre1_vinculos'); } }