Commit 23f4a7024eb970bba9acfaf77a4ecb4045e660a6

Authored by Lucas D'Avila
1 parent da41e2be
Exists in master

Melhorado / aplicado correções aos processos de matricula e enturmação

ieducar/intranet/educar_matricula_cad.php
... ... @@ -101,11 +101,11 @@ class indice extends clsCadastro
101 101 $obj_aluno = new clsPmieducarAluno($this->ref_cod_aluno);
102 102  
103 103 if (! $obj_aluno->existe()) {
104   - header('Location: educar_matricula_lst.php');
  104 + header('Location: educar_aluno_lst.php');
105 105 die;
106 106 }
107 107  
108   - $url = 'educar_matricula_lst.php?ref_cod_aluno=' . $this->ref_cod_aluno;
  108 + $url = 'educar_aluno_det.php?cod_aluno=' . $this->ref_cod_aluno;
109 109  
110 110 $obj_permissoes = new clsPermissoes();
111 111 $obj_permissoes->permissao_cadastra(578, $this->pessoa_logada, 7, $url);
... ... @@ -118,6 +118,7 @@ class indice extends clsCadastro
118 118  
119 119 $this->url_cancelar = $url;
120 120 $this->nome_url_cancelar = 'Cancelar';
  121 +
121 122 return $retorno;
122 123 }
123 124  
... ... @@ -152,17 +153,13 @@ class indice extends clsCadastro
152 153 'Caso seja transfência externa por favor marque esta opção.');
153 154 }
154 155  
155   - // foreign keys
156   - $instituicao_obrigatorio = TRUE;
157   - $curso_obrigatorio = TRUE;
158   - $escola_curso_obrigatorio = TRUE;
159   - $get_escola = TRUE;
160   - $get_curso = TRUE;
161   - $get_escola_curso_serie = TRUE;
162   - $get_matricula = TRUE;
163   - $sem_padrao = TRUE;
  156 + // inputs
  157 +
  158 + $anoLetivoHelperOptions = array('situacoes' => array('em_andamento', 'nao_iniciado'));
  159 +
  160 + $this->inputsHelper()->dynamic(array('instituicao', 'escola', 'curso', 'serie'));
  161 + $this->inputsHelper()->dynamic('anoLetivo', array('label' => 'Ano destino'), $anoLetivoHelperOptions);
164 162  
165   - include 'include/pmieducar/educar_campo_lista.php';
166 163  
167 164 if (is_numeric($this->ref_cod_curso)) {
168 165 $obj_curso = new clsPmieducarCurso($this->ref_cod_curso);
... ... @@ -174,34 +171,124 @@ class indice extends clsCadastro
174 171 }
175 172 }
176 173  
177   - if ($this->ref_cod_escola) {
178   - $this->ref_ref_cod_escola = $this->ref_cod_escola;
179   - }
  174 + $this->acao_enviar = 'formUtils.submit()';
  175 + }
180 176  
181   - $this->acao_enviar = 'valida()';
  177 + protected function getCurso($id) {
  178 + $curso = new clsPmieducarCurso($id);
  179 + return $curso->detalhe();
182 180 }
183 181  
184 182 function Novo()
185 183 {
  184 +
  185 + $this->url_cancelar = 'educar_aluno_det.php?cod_aluno=' . $this->ref_cod_aluno;
  186 + $this->nome_url_cancelar = 'Cancelar';
  187 +
186 188 @session_start();
187 189 $this->pessoa_logada = $_SESSION['id_pessoa'];
188 190 @session_write_close();
189 191  
190 192 $obj_permissoes = new clsPermissoes();
191 193 $obj_permissoes->permissao_cadastra(578, $this->pessoa_logada, 7,
192   - 'educar_matricula_lst.php?ref_cod_aluno=' . $this->ref_cod_aluno);
  194 + 'educar_aluno_det.php?cod_aluno=' . $this->ref_cod_aluno);
193 195  
194   - $obj_escola_ano_letivo = new clsPmieducarEscolaAnoLetivo();
195   - $lst_escola_ano_letivo = $obj_escola_ano_letivo->lista($this->ref_cod_escola,
196   - NULL, NULL, NULL,1, NULL, NULL, NULL, NULL, 1);
  196 + //novas regras matricula aluno
  197 + $this->ano = $_POST['ano'];
197 198  
198   - if (is_array($lst_escola_ano_letivo)) {
199   - $det_escola_ano_letivo = array_shift($lst_escola_ano_letivo);
200   - $this->ano = $det_escola_ano_letivo['ano'];
  199 + $anoLetivoEmAndamentoEscola = new clsPmieducarEscolaAnoLetivo();
  200 + $anoLetivoEmAndamentoEscola = $anoLetivoEmAndamentoEscola->lista($this->ref_cod_escola,
  201 + $this->ano,
  202 + null,
  203 + null,
  204 + 2, /*adiciona where 0 ou 1*/
  205 + null,
  206 + null,
  207 + null,
  208 + null,
  209 + 1
  210 + );
  211 +
  212 + if(is_array($anoLetivoEmAndamentoEscola)) {
  213 + require_once 'include/pmieducar/clsPmieducarSerie.inc.php';
  214 + $db = new clsBanco();
  215 +
  216 + $db->Consulta("select ref_ref_cod_serie, ref_cod_curso from pmieducar.matricula where ativo = 1 and ref_ref_cod_escola = $this->ref_cod_escola and ref_cod_curso = $this->ref_cod_curso and ref_cod_aluno = $this->ref_cod_aluno and aprovado not in (1,2,4,5,6,7,8,9)");
  217 +
  218 + $db->ProximoRegistro();
  219 + $m = $db->Tupla();
  220 + if (is_array($m) && count($m)) {
  221 +
  222 + $curso = $this->getCurso($this->ref_cod_curso);
  223 +
  224 + if ($m['ref_ref_cod_serie'] == $this->ref_cod_serie) {
  225 + $this->mensagem .= "Este aluno já está matriculado nesta série e curso, não é possivel matricular um aluno mais de uma vez na mesma série.<br />";
  226 +
  227 + return false;
  228 + }
  229 +
  230 + elseif ($curso['multi_seriado'] != 1) {
  231 + $serie = new clsPmieducarSerie($m['ref_ref_cod_serie'], null, null, $m['ref_cod_curso']);
  232 + $serie = $serie->detalhe();
  233 +
  234 + if (is_array($serie) && count($serie))
  235 + $nomeSerie = $serie['nm_serie'];
  236 + else
  237 + $nomeSerie = '';
  238 +
  239 + $this->mensagem .= "Este aluno já está matriculado no(a) '$nomeSerie' deste curso e escola. Como este curso não é multi seriado, não é possivel manter mais de uma matricula em andamento para o mesmo curso.<br />";
  240 +
  241 + return false;
  242 + }
  243 + }
  244 +
  245 + else
  246 + {
  247 + $db->Consulta("select ref_ref_cod_escola, ref_cod_curso, ref_ref_cod_serie from pmieducar.matricula where ativo = 1 and ref_ref_cod_escola != $this->ref_cod_escola and ref_cod_aluno = $this->ref_cod_aluno and aprovado not in (1,2,4,5,6,7,8,9) and not exists (select 1 from pmieducar.transferencia_solicitacao as ts where ts.ativo = 1 and ts.ref_cod_matricula_saida = matricula.cod_matricula)");
  248 +
  249 + $db->ProximoRegistro();
  250 + $m = $db->Tupla();
  251 + if (is_array($m) && count($m)){
  252 + require_once 'include/pmieducar/clsPmieducarEscola.inc.php';
  253 + require_once 'include/pessoa/clsJuridica.inc.php';
  254 +
  255 + $serie = new clsPmieducarSerie($m['ref_ref_cod_serie'], null, null, $m['ref_cod_curso']);
  256 + $serie = $serie->detalhe();
  257 + if (is_array($serie) && count($serie))
  258 + $serie = $serie['nm_serie'];
  259 + else
  260 + $serie = '';
  261 +
  262 + $escola = new clsPmieducarEscola($m['ref_ref_cod_escola']);
  263 + $escola = $escola->detalhe();
  264 + if (is_array($escola) && count($escola))
  265 + {
  266 + $escola = new clsJuridica($escola['ref_idpes']);
  267 + $escola = $escola->detalhe();
  268 + if (is_array($escola) && count($escola))
  269 + $escola = $escola['fantasia'];
  270 + else
  271 + $escola = '';
  272 + }
  273 + else
  274 + $escola = '';
  275 +
  276 + $curso = new clsPmieducarCurso($m['ref_cod_curso']);
  277 + $curso = $curso->detalhe();
  278 + if (is_array($curso) && count($curso))
  279 + $curso = $curso['nm_curso'];
  280 + else
  281 + $curso = '';
  282 +
  283 + $this->mensagem .= "Este aluno já está matriculado no(a) '$serie' do curso '$curso' na escola '$escola', para matricular este aluno na sua escola solicite transferência ao secretário(a) da escola citada.<br />";
  284 +
  285 + return false;
  286 + }
  287 + }
201 288  
202 289 $obj_reserva_vaga = new clsPmieducarReservaVaga();
203 290 $lst_reserva_vaga = $obj_reserva_vaga->lista(NULL, $this->ref_cod_escola,
204   - $this->ref_ref_cod_serie, NULL, NULL,$this->ref_cod_aluno, NULL, NULL,
  291 + $this->ref_cod_serie, NULL, NULL,$this->ref_cod_aluno, NULL, NULL,
205 292 NULL, NULL, 1);
206 293  
207 294 // Verifica se existe reserva de vaga para o aluno
... ... @@ -223,7 +310,7 @@ class indice extends clsCadastro
223 310  
224 311 if (! $this->ref_cod_reserva_vaga) {
225 312 $obj_turmas = new clsPmieducarTurma();
226   - $lst_turmas = $obj_turmas->lista(NULL, NULL, NULL, $this->ref_ref_cod_serie,
  313 + $lst_turmas = $obj_turmas->lista(NULL, NULL, NULL, $this->ref_cod_serie,
227 314 $this->ref_cod_escola, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
228 315 NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
229 316 NULL, NULL, NULL, NULL, NULL, TRUE);
... ... @@ -235,13 +322,13 @@ class indice extends clsCadastro
235 322 }
236 323 }
237 324 else {
238   - $this->mensagem = 'Série não possui turmas cadastradas.<br />';
  325 + $this->mensagem = 'A série selecionada não possui turmas cadastradas.<br />';
239 326 return FALSE;
240 327 }
241 328  
242 329 $obj_matricula = new clsPmieducarMatricula();
243 330 $lst_matricula = $obj_matricula->lista(NULL, NULL, $this->ref_cod_escola,
244   - $this->ref_ref_cod_serie, NULL, NULL, NULL, 3, NULL, NULL, NULL, NULL, 1,
  331 + $this->ref_cod_serie, NULL, NULL, NULL, 3, NULL, NULL, NULL, NULL, 1,
245 332 $this->ano, $this->ref_cod_curso, $this->ref_cod_instituicao, 1);
246 333  
247 334 if (is_array($lst_matricula)) {
... ... @@ -250,7 +337,7 @@ class indice extends clsCadastro
250 337  
251 338 $obj_reserva_vaga = new clsPmieducarReservaVaga();
252 339 $lst_reserva_vaga = $obj_reserva_vaga->lista(NULL, $this->ref_cod_escola,
253   - $this->ref_ref_cod_serie, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1,
  340 + $this->ref_cod_serie, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1,
254 341 $this->ref_cod_instituicao, $this->ref_cod_curso);
255 342  
256 343 if (is_array($lst_reserva_vaga)) {
... ... @@ -271,7 +358,7 @@ class indice extends clsCadastro
271 358 msg += \'Deseja mesmo assim realizar a Matrícula?\';
272 359  
273 360 if (! confirm(msg)) {
274   - window.location = \'educar_matricula_lst.php?ref_cod_aluno=%d;
  361 + window.location = \'educar_aluno_det.php?cod_aluno=%d;
275 362 }
276 363 </script>',
277 364 $matriculados, $reservados, $total_vagas, $this->ref_cod_aluno
... ... @@ -295,21 +382,29 @@ class indice extends clsCadastro
295 382 $this->semestre = NULL;
296 383 }
297 384  
  385 + if (! $this->removerFlagUltimaMatricula($this->ref_cod_aluno)) {
  386 + return false;
  387 + }
  388 +
298 389 $obj = new clsPmieducarMatricula(NULL, $this->ref_cod_reserva_vaga,
299   - $this->ref_cod_escola, $this->ref_ref_cod_serie, NULL,
  390 + $this->ref_cod_escola, $this->ref_cod_serie, NULL,
300 391 $this->pessoa_logada, $this->ref_cod_aluno, 3, NULL, NULL, 1, $this->ano,
301 392 1, NULL, NULL, NULL, NULL, $this->ref_cod_curso,
302 393 $this->matricula_transferencia, $this->semestre);
303 394  
304 395 $cadastrou = $obj->cadastra();
305 396 if ($cadastrou) {
  397 +
306 398 $obj_transferencia = new clsPmieducarTransferenciaSolicitacao();
307   - $lst_transferencia = $obj_transferencia->lista(NULL, NULL, NULL, NULL,
  399 +
  400 +
  401 + #Se encontrar solicitações de transferencia externa (com data de transferencia sem codigo de matricula de entrada), inativa estas
  402 + /*$lst_transferencia = $obj_transferencia->lista(NULL, NULL, NULL, NULL,
308 403 NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL,
309 404 $this->ref_cod_aluno, FALSE, NULL, NULL, NULL, TRUE, FALSE);
310 405  
311   - // Verifica se existe solicitação de transferência de aluno
312 406 if (is_array($lst_transferencia)) {
  407 + echo 'Encontrou solicitações de transferencia externa (saida) com data de transferencia';
313 408 $det_transferencia = array_shift($lst_transferencia);
314 409  
315 410 $obj_transferencia = new clsPmieducarTransferenciaSolicitacao(
... ... @@ -334,14 +429,19 @@ class indice extends clsCadastro
334 429 return FALSE;
335 430 }
336 431 }
  432 + #senão pega as solicitacoes de transferencia internas (sem data de transferencia e sem codigo de matricula de entrada) e
  433 + #seta a data de transferencia e codigo de matricula de entrada, atualiza a situacao da matricula para transferido e inativa a matricula turma
337 434 else {
  435 + */
338 436 $obj_transferencia = new clsPmieducarTransferenciaSolicitacao();
339 437 $lst_transferencia = $obj_transferencia->lista(NULL, NULL, NULL, NULL,
340 438 NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL,
341 439 $this->ref_cod_aluno, FALSE, NULL, NULL, NULL, FALSE, FALSE);
342 440  
343   - // Verifica se existe solicitação de transferência do aluno
  441 + #TODO interna ?
  442 + // Verifica se existe solicitação de transferência (interna) do aluno
344 443 if (is_array($lst_transferencia)) {
  444 + #echo 'Encontrou solicitações de transferencia interna (saida) com data de transferencia';
345 445 // Verifica cada solicitação de transferência do aluno
346 446 foreach ($lst_transferencia as $transferencia) {
347 447 $obj_matricula = new clsPmieducarMatricula(
... ... @@ -351,14 +451,14 @@ class indice extends clsCadastro
351 451 $det_matricula = $obj_matricula->detalhe();
352 452  
353 453 // Caso a solicitação seja para uma mesma série
354   - if ($det_matricula['ref_ref_cod_serie'] == $this->ref_ref_cod_serie) {
  454 + if ($det_matricula['ref_ref_cod_serie'] == $this->ref_cod_serie) {
355 455 $ref_cod_transferencia = $transferencia['cod_transferencia_solicitacao'];
356 456 break;
357 457 }
358 458 // Caso a solicitação seja para a série da sequência
359 459 else {
360 460 $obj_sequencia = new clsPmieducarSequenciaSerie(
361   - $det_matricula['ref_ref_cod_serie'], $this->ref_ref_cod_serie,
  461 + $det_matricula['ref_ref_cod_serie'], $this->ref_cod_serie,
362 462 NULL, NULL, NULL, NULL, 1
363 463 );
364 464  
... ... @@ -397,31 +497,8 @@ class indice extends clsCadastro
397 497 NULL, NULL, NULL, NULL, 1, NULL, NULL, $det_matricula['modulo']
398 498 );
399 499  
400   - $editou_mat = $obj_matricula->edita();
401   -
402   - if ($editou_mat) {
403   - $obj_matricula_turma = new clsPmieducarMatriculaTurma();
404   - $lst_matricula_turma = $obj_matricula_turma->lista(
405   - $matricula_saida, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1
406   - );
407   -
408   - if (is_array($lst_matricula_turma)) {
409   - $det_matricula_turma = array_shift($lst_matricula_turma);
410   -
411   - $obj_matricula_turma = new clsPmieducarMatriculaTurma(
412   - $matricula_saida, $det_matricula_turma['ref_cod_turma'],
413   - $this->pessoa_logada, NULL, NULL, NULL, 0, NULL,
414   - $det_matricula_turma['sequencial']
415   - );
416   -
417   - $editou_mat_turma = $obj_matricula_turma->edita();
418   -
419   - if (! $editou_mat_turma) {
420   - $this->mensagem = 'Não foi possível editar a Matrícula Turma.<br />';
421   - return FALSE;
422   - }
423   - }
424   - }
  500 + if ($obj_matricula->edita() && ! $this->desativaEnturmacoesMatricula($matricula_saida))
  501 + return false;
425 502 }
426 503  
427 504 $obj = new clsPmieducarMatricula(
... ... @@ -442,22 +519,53 @@ class indice extends clsCadastro
442 519 }
443 520 }
444 521 }
445   - }
  522 + //}
446 523  
  524 + #TODO set in $_SESSION['flash'] 'Aluno matriculado com sucesso'
447 525 $this->mensagem .= 'Cadastro efetuado com sucesso.<br />';
448   - header('Location: educar_matricula_lst.php?ref_cod_aluno=' . $this->ref_cod_aluno);
449   - die();
  526 + header('Location: educar_aluno_det.php?cod_aluno=' . $this->ref_cod_aluno);
  527 + #die();
  528 + #return true;
450 529 }
451 530  
452 531 $this->mensagem = 'Cadastro não realizado.<br />';
453 532 return FALSE;
454 533 }
455 534 else {
456   - $this->mensagem = 'Não foi possível encontrar o "Ano Letivo" em andamento da Escola.<br />';
  535 + $this->mensagem = 'O ano (letivo) selecionado não esta em andamento na escola selecionada.<br />';
457 536 return FALSE;
458 537 }
459 538 }
460 539  
  540 +
  541 + function desativaEnturmacoesMatricula($matriculaId) {
  542 + $result = true;
  543 +
  544 + $enturmacoes = new clsPmieducarMatriculaTurma();
  545 + $enturmacoes = $enturmacoes->lista($matriculaId, NULL, NULL, NULL, NULL,
  546 + NULL, NULL, NULL, 1);
  547 +
  548 + if ($enturmacoes) {
  549 + foreach ($enturmacoes as $enturmacao) {
  550 + $enturmacao = new clsPmieducarMatriculaTurma($matriculaId,
  551 + $enturmacao['ref_cod_turma'],
  552 + $this->pessoa_logada, null,
  553 + null, null, 0, null,
  554 + $enturmacao['sequencial']);
  555 + if ($result && ! $enturmacao->edita())
  556 + $result = false;
  557 + }
  558 + }
  559 +
  560 + if(! $result) {
  561 + $this->mensagem = "N&atilde;o foi poss&iacute;vel desativar as " .
  562 + "enturma&ccedil;&otilde;es da matr&iacute;cula.";
  563 + }
  564 +
  565 + return $result;
  566 + }
  567 +
  568 +
461 569 function Excluir()
462 570 {
463 571 @session_start();
... ... @@ -466,28 +574,10 @@ class indice extends clsCadastro
466 574  
467 575 $obj_permissoes = new clsPermissoes();
468 576 $obj_permissoes->permissao_excluir(578, $this->pessoa_logada, 7,
469   - 'educar_matricula_lst.php?ref_cod_aluno=' . $this->ref_cod_aluno);
  577 + 'educar_aluno_det.php?cod_aluno=' . $this->ref_cod_aluno);
470 578  
471   - $obj_matricula_turma = new clsPmieducarMatriculaTurma();
472   - $lst_matricula_turma = $obj_matricula_turma->lista(
473   - $this->cod_matricula, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1
474   - );
475   -
476   - if (is_array($lst_matricula_turma)) {
477   - $det_matricula_turma = array_shift($lst_matricula_turma);
478   - $obj_matricula_turma = new clsPmieducarMatriculaTurma(
479   - $det_matricula_turma['ref_cod_matricula'],
480   - $det_matricula_turma['ref_cod_turma'], $this->pessoa_logada, NULL,
481   - NULL, NULL, 0, NULL, $det_matricula_turma['sequencial']
482   - );
483   -
484   - $editou = $obj_matricula_turma->edita();
485   -
486   - if (! $editou) {
487   - $this->mensagem = 'Edição não realizada.<br />';
488   - return FALSE;
489   - }
490   - }
  579 + if (! $this->desativaEnturmacoesMatricula($this->cod_matricula))
  580 + return false;
491 581  
492 582 $obj_matricula = new clsPmieducarMatricula( $this->cod_matricula );
493 583 $det_matricula = $obj_matricula->detalhe();
... ... @@ -536,13 +626,32 @@ class indice extends clsCadastro
536 626  
537 627 if ($excluiu) {
538 628 $this->mensagem .= 'Exclusão efetuada com sucesso.<br />';
539   - header('Location: educar_matricula_lst.php?ref_cod_aluno=' . $this->ref_cod_aluno);
  629 + header('Location: educar_aluno_det.php?cod_aluno=' . $this->ref_cod_aluno);
540 630 die();
541 631 }
542 632  
543 633 $this->mensagem = 'Exclusão não realizada.<br />';
544 634 return FALSE;
545 635 }
  636 +
  637 + protected function removerFlagUltimaMatricula($alunoId) {
  638 + $matriculas = new clsPmieducarMatricula();
  639 + $matriculas = $matriculas->lista(NULL, NULL, NULL, NULL, NULL, NULL, $this->ref_cod_aluno,
  640 + NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, 1);
  641 +
  642 +
  643 + foreach ($matriculas as $matricula) {
  644 + $matricula = new clsPmieducarMatricula($matricula['cod_matricula'], NULL, NULL, NULL,
  645 + $this->pessoa_logada, NULL, $alunoId, NULL, NULL,
  646 + NULL, 1, NULL, 0);
  647 + if (! $matricula->edita()) {
  648 + $this->mensagem = 'Erro ao remover flag ultima matricula das matriculas anteriores.';
  649 + return false;
  650 + }
  651 + }
  652 +
  653 + return true;
  654 + }
546 655 }
547 656  
548 657 // Instancia objeto de página
... ... @@ -557,122 +666,3 @@ $pagina-&gt;addForm($miolo);
557 666 // Gera o código HTML
558 667 $pagina->MakeAll();
559 668 ?>
560   -<script type="text/javascript">
561   -function getCursoMatricula()
562   -{
563   - var campoInstituicao = document.getElementById('ref_cod_instituicao').value;
564   - var cod_aluno = <?php print $_GET['ref_cod_aluno'] ?>;
565   - var campoCurso = document.getElementById('ref_cod_curso');
566   -
567   - campoCurso.length = 1;
568   - campoCurso.disabled = true;
569   - campoCurso.options[0].text = 'Carregando curso';
570   -
571   - var xml_curso_matricula = new ajax(atualizaCursoMatricula);
572   -
573   - var url = 'educar_curso_matricula_xml.php?ins=' + campoInstituicao + '&alu=' + cod_aluno;
574   - xml_curso_matricula.envia(url);
575   -}
576   -
577   -function atualizaCursoMatricula(xml_curso_matricula)
578   -{
579   - var campoCurso = document.getElementById('ref_cod_curso');
580   - var DOM_array = xml_curso_matricula.getElementsByTagName('curso');
581   -
582   - if (DOM_array.length) {
583   - campoCurso.length = 1;
584   - campoCurso.options[0].text = 'Selecione um curso';
585   - campoCurso.disabled = false;
586   -
587   - for (var i = 0; i < DOM_array.length; i++) {
588   - campoCurso.options[campoCurso.options.length] = new Option(
589   - DOM_array[i].firstChild.data, DOM_array[i].getAttribute('cod_curso'),
590   - false, false
591   - );
592   - }
593   - }
594   - else {
595   - campoCurso.options[0].text = 'A instituição não possui nenhum curso';
596   - }
597   -}
598   -
599   -function getSerieMatricula()
600   -{
601   - var campoInstituicao = document.getElementById('ref_cod_instituicao').value;
602   - var campoEscola = document.getElementById('ref_cod_escola').value;
603   - var campoCurso = document.getElementById('ref_cod_curso').value;
604   - var cod_aluno = <?php print $_GET['ref_cod_aluno'] ?>;
605   - var campoSerie = document.getElementById('ref_ref_cod_serie');
606   -
607   - campoSerie.length = 1;
608   - campoSerie.disabled = true;
609   - campoSerie.options[0].text = 'Carregando série';
610   -
611   - var xml_serie_matricula = new ajax(atualizaSerieMatricula);
612   -
613   - var url = 'educar_serie_matricula_xml.php?ins=' + campoInstituicao + '&cur=' + campoCurso
614   - + '&esc=' + campoEscola + '&alu=' + cod_aluno;
615   -
616   - xml_serie_matricula.envia(url);
617   -}
618   -
619   -function atualizaSerieMatricula(xml_serie_matricula)
620   -{
621   - var campoSerie = document.getElementById('ref_ref_cod_serie');
622   - var DOM_array = xml_serie_matricula.getElementsByTagName('serie');
623   -
624   - if (DOM_array.length) {
625   - campoSerie.length = 1;
626   - campoSerie.options[0].text = 'Selecione uma série';
627   - campoSerie.disabled = false;
628   -
629   - var series = new Array();
630   -
631   - for (var i = 0; i < DOM_array.length; i++) {
632   - if (! series[DOM_array[i].getAttribute('cod_serie') + '_']) {
633   - campoSerie.options[campoSerie.options.length] = new Option(
634   - DOM_array[i].firstChild.data, DOM_array[i].getAttribute('cod_serie'),
635   - false, false
636   - );
637   -
638   - series[DOM_array[i].getAttribute('cod_serie') + '_'] = true;
639   - }
640   - }
641   - }
642   - else {
643   - campoSerie.options[0].text = 'A escola/curso não possui nenhuma série';
644   - }
645   -}
646   -
647   -document.getElementById('ref_cod_escola').onchange = function()
648   -{
649   - if (document.getElementById('ref_cod_escola').value == '') {
650   - getCursoMatricula();
651   - }
652   - else {
653   - getEscolaCurso();
654   - }
655   -}
656   -
657   -document.getElementById('ref_cod_curso').onchange = function()
658   -{
659   - getSerieMatricula();
660   -}
661   -
662   -function valida()
663   -{
664   - if (document.getElementById('ref_cod_escola').value) {
665   - if (!document.getElementById('ref_ref_cod_serie').value) {
666   - alert('O campo "Série" deve ser preenchido corretamente!');
667   - document.getElementById('ref_ref_cod_serie').focus();
668   - return false;
669   - }
670   - }
671   -
672   - if (! acao()) {
673   - return false;
674   - }
675   -
676   - document.forms[0].submit();
677   -}
678   -</script>
679 669 \ No newline at end of file
... ...
ieducar/intranet/educar_matricula_det.php
... ... @@ -97,7 +97,7 @@ class indice extends clsDetalhe
97 97 }
98 98  
99 99 if (! $registro) {
100   - header("Location: educar_matricula_lst.php?ref_cod_aluno=" . $registro['ref_cod_aluno']);
  100 + header("Location: educar_aluno_det.php?cod_aluno=" . $registro['ref_cod_aluno']);
101 101 die();
102 102 }
103 103  
... ... @@ -131,18 +131,6 @@ class indice extends clsDetalhe
131 131 $nm_aluno = $det_aluno['nome_aluno'];
132 132 }
133 133  
134   - // Nome da turma
135   - $obj_mat_turma = new clsPmieducarMatriculaTurma();
136   - $det_mat_turma = $obj_mat_turma->lista($this->ref_cod_matricula, NULL, NULL,
137   - NULL, NULL, NULL, NULL, NULL, 1);
138   -
139   - if ($det_mat_turma){
140   - $det_mat_turma = array_shift($det_mat_turma);
141   - $obj_turma = new clsPmieducarTurma($det_mat_turma['ref_cod_turma']);
142   - $det_turma = $obj_turma->detalhe();
143   - $nm_turma = $det_turma['nm_turma'];
144   - }
145   -
146 134 if ($registro['cod_matricula']) {
147 135 $this->addDetalhe(array('Número Matrícula', $registro['cod_matricula']));
148 136 }
... ... @@ -167,9 +155,23 @@ class indice extends clsDetalhe
167 155 $this->addDetalhe(array('Série', $registro['ref_ref_cod_serie']));
168 156 }
169 157  
170   - if ($nm_turma) {
171   - $this->addDetalhe(array('Turma', $nm_turma));
  158 + // Nome da turma
  159 + $enturmacoes = new clsPmieducarMatriculaTurma();
  160 + $enturmacoes = $enturmacoes->lista($this->ref_cod_matricula, NULL, NULL,
  161 + NULL, NULL, NULL, NULL, NULL, 1);
  162 +
  163 + $nomesTurmas = array();
  164 + foreach ($enturmacoes as $enturmacao) {
  165 + $turma = new clsPmieducarTurma($enturmacao['ref_cod_turma']);
  166 + $turma = $turma->detalhe();
  167 + $nomesTurmas[] = $turma['nm_turma'];
172 168 }
  169 + $nomesTurmas = implode('<br />', $nomesTurmas);
  170 +
  171 + if ($nomesTurmas)
  172 + $this->addDetalhe(array('Turma', $nomesTurmas));
  173 + else
  174 + $this->addDetalhe(array('Turma', ''));
173 175  
174 176 if ($registro['ref_cod_reserva_vaga']) {
175 177 $this->addDetalhe(array('Número Reserva Vaga', $registro['ref_cod_reserva_vaga']));
... ... @@ -250,7 +252,7 @@ class indice extends clsDetalhe
250 252  
251 253 if ($registro['aprovado'] != 4 && $registro['aprovado'] != 6) {
252 254 if (is_array($lst_transferencia) && !isset($data_transferencia)) {
253   - $this->array_botao[] = 'Cancelar Solicitação Transferência';
  255 + $this->array_botao[] = 'Cancelar Solicitação Transferência (escola do sistema)';
254 256 $this->array_botao_url_script[] = "go(\"educar_transferencia_solicitacao_cad.php?ref_cod_matricula={$registro['cod_matricula']}&ref_cod_aluno={$registro['ref_cod_aluno']}&cancela=true\")";
255 257 }
256 258 else {
... ... @@ -274,15 +276,34 @@ class indice extends clsDetalhe
274 276 }
275 277 }
276 278  
  279 + if($registro['aprovado'] == 4 &&
  280 + $this->canCancelTransferenciaExterna($registro['cod_matricula'], $registro['ref_cod_aluno'])) {
  281 + $this->array_botao[] = 'Cancelar transferência (escola externa)';
  282 +
  283 +
  284 + # TODO ver se código, seta matricula como em andamento, ativa ultima matricula_turma for matricula, e desativa transferencia solicitacao
  285 + $this->array_botao_url_script[] = "go(\"educar_transferencia_solicitacao_cad.php?ref_cod_matricula={$registro['cod_matricula']}&ref_cod_aluno={$registro['ref_cod_aluno']}&cancela=true&reabrir_matricula=true\")";
  286 + }
  287 +
277 288 if ($registro['aprovado'] == 4 || $det_transferencia) {
278 289 $this->array_botao[] = 'Imprimir Atestado Frequência';
279 290 $this->array_botao_url_script[] = "showExpansivelImprimir(400, 200, \"educar_relatorio_atestado_frequencia.php?cod_matricula={$registro['cod_matricula']}\",[], \"Relatório Atestado de Freqüência\")";
280 291 }
281 292 }
282 293  
283   - $this->url_cancelar = 'educar_matricula_lst.php?ref_cod_aluno=' . $registro['ref_cod_aluno'];
  294 + $this->url_cancelar = 'educar_aluno_det.php?cod_aluno=' . $registro['ref_cod_aluno'];
284 295 $this->largura = '100%';
285 296 }
  297 +
  298 +
  299 + function canCancelTransferenciaExterna($matriculaId, $alunoId) {
  300 + $sql = "select 1 from pmieducar.matricula where ativo = 1 and cod_matricula > $matriculaId and ref_cod_aluno = $alunoId limit 1";
  301 +
  302 + $db = new clsBanco();
  303 + $existeNovaMatricula = $db->CampoUnico($sql) == '1';
  304 +
  305 + return ! $existeNovaMatricula;
  306 + }
286 307 }
287 308  
288 309 // Instancia objeto de página
... ... @@ -295,4 +316,4 @@ $miolo = new indice();
295 316 $pagina->addForm($miolo);
296 317  
297 318 // Gera o código HTML
298   -$pagina->MakeAll();
299 319 \ No newline at end of file
  320 +$pagina->MakeAll();
... ...
ieducar/intranet/educar_matricula_lst.php
... ... @@ -107,6 +107,10 @@ class indice extends clsListagem
107 107 $this->addBanner( "imagens/nvp_top_intranet.jpg", "imagens/nvp_vert_intranet.jpg", "Intranet" );
108 108  
109 109 $lista_busca = array(
  110 + "Ano",
  111 + "Matrícula",
  112 + "Situação",
  113 + "Turma",
110 114 "S&eacute;rie",
111 115 "Curso"
112 116 );
... ... @@ -139,7 +143,7 @@ class indice extends clsListagem
139 143 $this->offset = ( $_GET["pagina_{$this->nome}"] ) ? $_GET["pagina_{$this->nome}"]*$this->limite-$this->limite: 0;
140 144  
141 145 $obj_matricula = new clsPmieducarMatricula();
142   - $obj_matricula->setOrderby( "cod_matricula ASC" );
  146 + $obj_matricula->setOrderby('ano DESC, ref_ref_cod_serie DESC, aprovado, cod_matricula');
143 147 $obj_matricula->setLimite( $this->limite, $this->offset );
144 148  
145 149 $lista = $obj_matricula->lista(
... ... @@ -214,8 +218,43 @@ class indice extends clsListagem
214 218 echo "<!--\nErro\nClasse n&atilde;o existente: clsPmieducarEscola\n-->";
215 219 }
216 220  
  221 + $enturmacoes = new clsPmieducarMatriculaTurma();
  222 + $enturmacoes = $enturmacoes->lista($registro['cod_matricula'], NULL, NULL,
  223 + NULL, NULL, NULL, NULL, NULL, 1);
  224 + $nomesTurmas = array();
  225 + foreach ($enturmacoes as $enturmacao) {
  226 + $turma = new clsPmieducarTurma($enturmacao['ref_cod_turma']);
  227 + $turma = $turma->detalhe();
  228 + $nomesTurmas[] = $turma['nm_turma'];
  229 + }
  230 + $nomesTurmas = implode('<br />', $nomesTurmas);
  231 +
  232 + $situacao = $registro['aprovado'];
  233 + if ($situacao == 1)
  234 + $situacao = 'Aprovado';
  235 + elseif ($situacao == 2)
  236 + $situacao = 'Reprovado';
  237 + elseif ($situacao == 3)
  238 + $situacao = 'Em Andamento';
  239 + elseif ($situacao == 4)
  240 + $situacao = 'Transferido';
  241 + elseif ($situacao == 5)
  242 + $situacao = 'Reclassificado';
  243 + elseif ($situacao == 6)
  244 + $situacao = 'Abandono';
  245 +
217 246 $lista_busca = array();
218 247  
  248 + $lista_busca[] = "<a href=\"educar_matricula_det.php?cod_matricula={$registro["cod_matricula"]}\">{$registro["ano"]}</a>";
  249 + $lista_busca[] = "<a href=\"educar_matricula_det.php?cod_matricula={$registro["cod_matricula"]}\">{$registro["cod_matricula"]}</a>";
  250 + $lista_busca[] = "<a href=\"educar_matricula_det.php?cod_matricula={$registro["cod_matricula"]}\">$situacao</a>";
  251 +
  252 + if ($nomesTurmas) {
  253 + $lista_busca[] = "<a href=\"educar_matricula_det.php?cod_matricula={$registro["cod_matricula"]}\">$nomesTurmas</a>";
  254 + }
  255 + else
  256 + $lista_busca[] = "";
  257 +
219 258 if ($registro["ref_ref_cod_serie"])
220 259 $lista_busca[] = "<a href=\"educar_matricula_det.php?cod_matricula={$registro["cod_matricula"]}\">{$registro["ref_ref_cod_serie"]}</a>";
221 260 else
... ... @@ -246,6 +285,11 @@ class indice extends clsListagem
246 285 $this->addLinhas($lista_busca);
247 286 }
248 287 }
  288 + else
  289 + {
  290 + $this->addLinhas(array('Aluno sem matrículas em andamento na sua escola.'));
  291 + }
  292 +
249 293 $this->addPaginador2( "educar_matricula_lst.php", $total, $_GET, $this->nome, $this->limite );
250 294 if( $obj_permissoes->permissao_cadastra( 578, $this->pessoa_logada, 7 ) )
251 295 {
... ... @@ -279,4 +323,4 @@ document.getElementById(&#39;ref_cod_curso&#39;).onchange = function()
279 323 getEscolaCursoSerie();
280 324 }
281 325  
282   -</script>
283 326 \ No newline at end of file
  327 +</script>
... ...
ieducar/intranet/educar_matricula_turma_cad.php
... ... @@ -32,6 +32,7 @@ require_once &#39;include/clsBase.inc.php&#39;;
32 32 require_once 'include/clsCadastro.inc.php';
33 33 require_once 'include/clsBanco.inc.php';
34 34 require_once 'include/pmieducar/geral.inc.php';
  35 +require_once 'include/pmieducar/clsPmieducarMatricula.inc.php';
35 36  
36 37 /**
37 38 * clsIndexBase class.
... ... @@ -87,7 +88,7 @@ class indice extends clsCadastro
87 88 $this->pessoa_logada = $_SESSION['id_pessoa'];
88 89 @session_write_close();
89 90  
90   - if (!$_POST) {
  91 + if (! $_POST) {
91 92 header('Location: educar_matricula_lst.php');
92 93 die;
93 94 }
... ... @@ -99,59 +100,92 @@ class indice extends clsCadastro
99 100 $obj_permissoes = new clsPermissoes();
100 101 $obj_permissoes->permissao_cadastra(578, $this->pessoa_logada, 7, 'educar_matricula_lst.php');
101 102  
  103 + //nova lógica
102 104 if (is_numeric($this->ref_cod_matricula)) {
103   - if (is_numeric($this->ref_cod_turma_origem)) {
104   - $obj_matricula_turma = new clsPmieducarMatriculaTurma();
105   - $lst_matricula_turma = $obj_matricula_turma->lista($this->ref_cod_matricula,
106   - NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1);
107   -
108   - if ($lst_matricula_turma) {
109   - foreach ($lst_matricula_turma as $matricula) {
110   - $obj = new clsPmieducarMatriculaTurma($this->ref_cod_matricula,
111   - $matricula['ref_cod_turma'], $this->pessoa_logada, NULL, NULL,
112   - NULL, 0, NULL, $matricula['sequencial']);
113   -
114   - $registro = $obj->detalhe();
115   - if ($registro) {
116   - if (!$obj->edita()) {
117   - echo "erro ao cadastrar";
118   - die;
119   - }
120   - }
121   - }
122   - }
123   -
124   - $obj = new clsPmieducarMatriculaTurma($this->ref_cod_matricula,
125   - $this->ref_cod_turma_destino, $this->pessoa_logada, $this->pessoa_logada,
126   - NULL, NULL, 1);
127   -
128   - $cadastrou = $obj->cadastra();
129   -
130   - if ($cadastrou) {
131   - $this->mensagem .= 'Cadastro efetuado com sucesso.<br>';
132   - header('Location: educar_matricula_det.php?cod_matricula=' . $this->ref_cod_matricula);
133   - die();
134   - }
135   - }
  105 +
  106 + if ($this->ref_cod_turma_origem == 'remover-enturmacao-destino')
  107 + $this->removerEnturmacao($this->ref_cod_matricula, $this->ref_cod_turma_destino);
  108 + elseif (! is_numeric($this->ref_cod_turma_origem))
  109 + $this->novaEnturmacao($this->ref_cod_matricula, $this->ref_cod_turma_destino);
136 110 else {
137   - $obj = new clsPmieducarMatriculaTurma($this->ref_cod_matricula,
138   - $this->ref_cod_turma_destino, $this->pessoa_logada, $this->pessoa_logada,
139   - NULL, NULL, 1);
  111 + $this->transferirEnturmacao($this->ref_cod_matricula,
  112 + $this->ref_cod_turma_origem,
  113 + $this->ref_cod_turma_destino);
  114 + }
140 115  
141   - $cadastrou = $obj->cadastra();
  116 + header('Location: educar_matricula_det.php?cod_matricula=' . $this->ref_cod_matricula);
  117 + die();
  118 + }
  119 + else {
  120 + header('Location: /intranet/educar_aluno_lst.php');
  121 + die();
  122 + }
  123 + }
142 124  
143   - if ($cadastrou) {
144   - $this->mensagem .= 'Cadastro efetuado com sucesso.<br>';
145   - header('Location: educar_matricula_det.php?cod_matricula=' . $this->ref_cod_matricula);
146   - die();
147   - }
148   - }
  125 + function novaEnturmacao($matriculaId, $turmaDestinoId) {
  126 +
  127 + $enturmacaoExists = new clsPmieducarMatriculaTurma();
  128 + $enturmacaoExists = $enturmacaoExists->lista($matriculaId,
  129 + $turmaDestinoId,
  130 + NULL,
  131 + NULL,
  132 + NULL,
  133 + NULL,
  134 + NULL,
  135 + NULL,
  136 + 1);
  137 +
  138 + $enturmacaoExists = is_array($enturmacaoExists) && count($enturmacaoExists) > 0;
  139 + if (! $enturmacaoExists) {
  140 + $enturmacao = new clsPmieducarMatriculaTurma($matriculaId,
  141 + $turmaDestinoId,
  142 + $this->pessoa_logada,
  143 + $this->pessoa_logada,
  144 + NULL,
  145 + NULL,
  146 + 1);
  147 + return $enturmacao->cadastra();
149 148 }
  149 + return false;
  150 + }
150 151  
151   - header('Location: educar_matricula_lst.php');
152   - die;
  152 +
  153 + function transferirEnturmacao($matriculaId, $turmaOrigemId, $turmaDestinoId) {
  154 + if($this->removerEnturmacao($matriculaId, $turmaOrigemId))
  155 + return $this->novaEnturmacao($matriculaId, $turmaDestinoId);
  156 + return false;
153 157 }
154 158  
  159 +
  160 + function removerEnturmacao($matriculaId, $turmaId) {
  161 + $sequencialEnturmacao = $this->getSequencialEnturmacaoByTurmaId($matriculaId, $turmaId);
  162 + $enturmacao = new clsPmieducarMatriculaTurma($matriculaId,
  163 + $turmaId,
  164 + $this->pessoa_logada,
  165 + NULL,
  166 + NULL,
  167 + NULL,
  168 + 0,
  169 + NULL,
  170 + $sequencialEnturmacao);
  171 +
  172 + return $enturmacao->edita();
  173 + }
  174 +
  175 +
  176 + function getSequencialEnturmacaoByTurmaId($matriculaId, $turmaId) {
  177 + $db = new clsBanco();
  178 + $sql = 'select coalesce(max(sequencial), 1) from pmieducar.matricula_turma where ativo = 1 and ref_cod_matricula = $1 and ref_cod_turma = $2';
  179 +
  180 + if ($db->execPreparedQuery($sql, array($matriculaId, $turmaId)) != false) {
  181 + $db->ProximoRegistro();
  182 + $sequencial = $db->Tupla();
  183 + return $sequencial[0];
  184 + }
  185 + return 1;
  186 + }
  187 +
  188 +
155 189 function Gerar()
156 190 {
157 191 die;
... ... @@ -180,4 +214,4 @@ $miolo = new indice();
180 214 $pagina->addForm($miolo);
181 215  
182 216 // Gera o código HTML
183   -$pagina->MakeAll();
184 217 \ No newline at end of file
  218 +$pagina->MakeAll();
... ...
ieducar/intranet/educar_matricula_turma_det.php
... ... @@ -94,6 +94,11 @@ class indice extends clsDetalhe
94 94 $this->$key = $value;
95 95 }
96 96  
  97 + if (! $this->ref_cod_matricula) {
  98 + header('Location: educar_matricula_lst.php');
  99 + die();
  100 + }
  101 +
97 102 $obj_mat_turma = new clsPmieducarMatriculaTurma();
98 103 $det_mat_turma = $obj_mat_turma->lista($this->ref_cod_matricula, NULL, NULL,
99 104 NULL, NULL, NULL, NULL, NULL, 1);
... ... @@ -108,19 +113,27 @@ class indice extends clsDetalhe
108 113 $this->sequencial = $det_mat_turma['sequencial'];
109 114 }
110 115  
111   - $tmp_obj = new clsPmieducarMatriculaTurma( );
112   - $lista = $tmp_obj->lista(NULL, $this->ref_cod_turma, NULL, NULL, NULL, NULL,
113   - NULL, NULL, 1);
  116 + // #TODO adicionar ano da matricula atual
  117 + #$tmp_obj = new clsPmieducarMatriculaTurma( );
  118 + #$lista = $tmp_obj->lista(NULL, $this->ref_cod_turma, NULL, NULL, NULL, NULL,
  119 + # NULL, NULL, 1);
114 120  
115   - $total_alunos = 0;
116   - if ($lista) {
117   - $total_alunos = count($lista);
118   - }
  121 + #$total_alunos = 0;
  122 + #if ($lista) {
  123 + # $total_alunos = count($lista);
  124 + #}
119 125  
120 126 $tmp_obj = new clsPmieducarTurma();
121 127 $lst_obj = $tmp_obj->lista($this->ref_cod_turma);
122 128 $registro = array_shift($lst_obj);
123 129  
  130 + $db = new clsBanco();
  131 +
  132 + $ano = $db->CampoUnico("select ano from pmieducar.matricula where cod_matricula = $this->ref_cod_matricula");
  133 + $sql = "select count(cod_matricula) as qtd_matriculas from pmieducar.matricula, pmieducar.matricula_turma, pmieducar.aluno where aluno.cod_aluno = matricula.ref_cod_aluno and ano = {$ano} and aluno.ativo = 1 and matricula.ativo = 1 and matricula_turma.ativo = matricula.ativo and cod_matricula = ref_cod_matricula and ref_cod_turma = $this->ref_cod_turma";
  134 +
  135 + $total_alunos = $db->CampoUnico($sql);
  136 +
124 137 $this->ref_cod_curso = $registro['ref_cod_curso'];
125 138  
126 139 if (!$registro || !$_POST) {
... ... @@ -183,7 +196,42 @@ class indice extends clsDetalhe
183 196 $this->addDetalhe(array('S&eacute;rie', $registro['ref_ref_cod_serie']));
184 197 }
185 198  
186   - $this->addDetalhe(array('Turma atual', $this->nm_turma));
  199 + //(enturmações) turma atual
  200 + $enturmacoes = new clsPmieducarMatriculaTurma();
  201 + $enturmacoes = $enturmacoes->lista($this->ref_cod_matricula, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1);
  202 +
  203 + $this->possuiEnturmacao = ! empty($enturmacoes);
  204 + $this->possuiEnturmacaoTurmaDestino = false;
  205 + $this->turmaOrigemMesmaDestino = false;
  206 +
  207 + if ($this->possuiEnturmacao) {
  208 + //se possui uma enturmacao mostra o nome, se mais de uma mostra select para selecionar
  209 + if (count($enturmacoes) > 1) {
  210 + $selectEnturmacoes = "<select id='ref_cod_turma_origem' class='obrigatorio'>";
  211 + $selectEnturmacoes .= "<option value=''>Selecione</option>";
  212 +
  213 + foreach ($enturmacoes as $enturmacao) {
  214 + if($enturmacao['ref_cod_turma'] != $this->ref_cod_turma)
  215 + $selectEnturmacoes .= "<option value='{$enturmacao['ref_cod_turma']}'>{$enturmacao['nm_turma']}</option>";
  216 + elseif (! $this->possuiEnturmacaoTurmaDestino)
  217 + $this->possuiEnturmacaoTurmaDestino = true;
  218 + }
  219 + $selectEnturmacoes .= "</select>";
  220 + }
  221 + else {
  222 + if ($enturmacoes[0]['ref_cod_turma'] == $this->ref_cod_turma) {
  223 + $this->possuiEnturmacaoTurmaDestino = true;
  224 + $this->turmaOrigemMesmaDestino = true;
  225 + }
  226 +
  227 + $selectEnturmacoes = "<input id='ref_cod_turma_origem' type='hidden' value = '{$enturmacoes[0]['ref_cod_turma']}'/>{$enturmacoes[0]['nm_turma']}";
  228 + }
  229 +
  230 + $this->addDetalhe(array('Turma atual (origem)', $selectEnturmacoes));
  231 + }
  232 + else
  233 + $this->addDetalhe(array('Turma atual (origem)', 'Sem enturmações'));
  234 +
187 235  
188 236 if ($registro['nm_turma']) {
189 237 $this->addDetalhe(array('Turma destino' , $registro['nm_turma']));
... ... @@ -213,30 +261,76 @@ class indice extends clsDetalhe
213 261 ));
214 262  
215 263 if ($registro['max_aluno'] - $total_alunos <= 0) {
216   - $msg = sprintf('Atenção! Turma sem vagas! Deseja continuar com a enturmação mesmo assim?');
217   - $valida = sprintf('if (!confirm("%s")) return false;', $msg);
218   - }
219   - else {
220   - $valida = 'if (!confirm("Confirmar a enturmação?")) return false;';
  264 +
  265 + $escolaSerie = $this->getEscolaSerie($det_ref_cod_escola['cod_escola'], $det_ser['cod_serie']);
  266 +
  267 + if($escolaSerie['bloquear_enturmacao_sem_vagas'] != 1) {
  268 + $msg = sprintf('Atenção! Turma sem vagas! Deseja continuar com a enturmação mesmo assim?');
  269 + $jsEnturmacao = sprintf('if (!confirm("%s")) return false;', $msg);
  270 + }
  271 + else {
  272 + $msg = sprintf('Enturmação não pode ser realizada,\n\no limite de vagas da turma já foi atingido e para esta série e escola foi definido bloqueio de enturmação após atingir tal limite.');
  273 + $jsEnturmacao = sprintf('alert("%s"); return false;', $msg);
  274 + }
221 275 }
  276 + else
  277 + $jsEnturmacao = 'if (!confirm("Confirma a enturmação?")) return false;';
222 278  
223 279 $script = sprintf('
224 280 <script type="text/javascript">
225   - function enturmar(ref_cod_matricula, ref_cod_turma_destino){
  281 +
  282 + function enturmar(ref_cod_matricula, ref_cod_turma_destino, tipo){
  283 + document.formcadastro.ref_cod_turma_origem.value = "";
  284 +
  285 + if(tipo == "transferir") {
  286 + var turmaOrigemId = document.getElementById("ref_cod_turma_origem");
  287 + if (turmaOrigemId && turmaOrigemId.value)
  288 + document.formcadastro.ref_cod_turma_origem.value = turmaOrigemId.value;
  289 + else {
  290 + alert("Por favor selecione a turma atual (que será transferida).");
  291 + return false;
  292 + }
  293 + }
  294 +
226 295 %s
  296 +
  297 + document.formcadastro.ref_cod_matricula.value = ref_cod_matricula;
  298 + document.formcadastro.ref_cod_turma_destino.value = ref_cod_turma_destino;
  299 + document.formcadastro.submit();
  300 + }
  301 +
  302 + function removerEnturmacao(ref_cod_matricula, ref_cod_turma_destino) {
  303 +
  304 + if (! confirm("Tem certeza que deseja remover a enturmação (da turma destino)?"))
  305 + return false;
  306 +
  307 + document.formcadastro.ref_cod_turma_origem.value = "remover-enturmacao-destino";
227 308 document.formcadastro.ref_cod_matricula.value = ref_cod_matricula;
228 309 document.formcadastro.ref_cod_turma_destino.value = ref_cod_turma_destino;
229 310 document.formcadastro.submit();
230 311 }
231   - </script>', $valida);
  312 +
  313 + </script>', $jsEnturmacao);
232 314  
233 315 print $script;
234 316  
235 317 $obj_permissoes = new clsPermissoes();
236   - if ($obj_permissoes->permissao_cadastra(578, $this->pessoa_logada, 7)) {
237   - $script = "enturmar({$this->ref_cod_matricula},{$this->ref_cod_turma})";
238   - $this->array_botao = array('Transferir Aluno');
239   - $this->array_botao_url_script = array($script);
  318 + if (! $this->turmaOrigemMesmaDestino && $obj_permissoes->permissao_cadastra(578, $this->pessoa_logada, 7)) {
  319 +
  320 + if ($this->possuiEnturmacao) {
  321 + //mover enturmação
  322 + $this->array_botao = array('Transferir (turma atual) para turma destino');
  323 + $this->array_botao_url_script = array("enturmar({$this->ref_cod_matricula}, {$this->ref_cod_turma}, \"transferir\")");
  324 + }
  325 +
  326 + //nova enturmação
  327 + $this->array_botao[] = 'Nova enturmação (na turma destino)';
  328 + $this->array_botao_url_script[] = "enturmar({$this->ref_cod_matricula}, {$this->ref_cod_turma}, \"nova\")";
  329 +
  330 + if ($this->possuiEnturmacaoTurmaDestino){
  331 + $this->array_botao[] = 'Remover enturmação (turma destino)';
  332 + $this->array_botao_url_script[] = "removerEnturmacao({$this->ref_cod_matricula}, {$this->ref_cod_turma})";
  333 + }
240 334 }
241 335  
242 336 $this->array_botao[] = 'Voltar';
... ... @@ -244,6 +338,15 @@ class indice extends clsDetalhe
244 338  
245 339 $this->largura = '100%';
246 340 }
  341 +
  342 + protected function getEscolaSerie($escolaId, $serieId) {
  343 + $escolaSerie = new clsPmieducarEscolaSerie();
  344 + $escolaSerie->ref_cod_escola = $escolaId;
  345 + $escolaSerie->ref_cod_serie = $serieId;
  346 +
  347 + return $escolaSerie->detalhe();
  348 + }
  349 +
247 350 }
248 351  
249 352 // Instancia objeto de página
... ... @@ -256,4 +359,4 @@ $miolo = new indice();
256 359 $pagina->addForm($miolo);
257 360  
258 361 // Gera o código HTML
259   -$pagina->MakeAll();
260 362 \ No newline at end of file
  363 +$pagina->MakeAll();
... ...
ieducar/intranet/educar_matricula_turma_lst.php
... ... @@ -91,7 +91,7 @@ class indice extends clsListagem
91 91 $this->pessoa_logada = $_SESSION['id_pessoa'];
92 92 session_write_close();
93 93  
94   - $this->titulo = 'Listagem - Selecione a turma para realizar a transferência';
  94 + $this->titulo = 'Selecione uma turma para enturmar ou remover a enturmação';
95 95  
96 96 $this->ref_cod_matricula = $_GET['ref_cod_matricula'];
97 97  
... ... @@ -111,7 +111,8 @@ class indice extends clsListagem
111 111 $this->addBanner('imagens/nvp_top_intranet.jpg', 'imagens/nvp_vert_intranet.jpg', 'Intranet');
112 112  
113 113 $this->addCabecalhos(array(
114   - 'Turma'
  114 + 'Turma',
  115 + 'Enturmado'
115 116 ));
116 117  
117 118 // Busca dados da matricula
... ... @@ -146,9 +147,12 @@ class indice extends clsListagem
146 147 foreach ($lista as $registro) {
147 148 $opcoes[$registro['cod_turma']] = $registro['nm_turma'];
148 149 }
  150 +
  151 + $this->exibirBotaoSubmit = false;
  152 +
149 153 }
150 154  
151   - $this->campoLista('ref_cod_turma_', 'Turma', $opcoes, $this->ref_cod_turma);
  155 + #$this->campoLista('ref_cod_turma_', 'Turma', $opcoes, $this->ref_cod_turma);
152 156  
153 157 // outros filtros
154 158 $this->campoOculto('ref_cod_matricula', $this->ref_cod_matricula);
... ... @@ -211,27 +215,30 @@ WHERE
211 215 $total = $obj_matricula_turma->_total;
212 216 }
213 217  
214   - $tmp_obj = new clsPmieducarMatriculaTurma();
215   - $det_obj = $tmp_obj->lista($this->ref_cod_matricula, NULL, NULL, NULL, NULL,
216   - NULL, NULL, NULL, 1);
  218 + $enturmacoesMatricula = new clsPmieducarMatriculaTurma();
  219 + $enturmacoesMatricula = $enturmacoesMatricula->lista($this->ref_cod_matricula, NULL, NULL,
  220 + NULL, NULL, NULL, NULL, NULL, 1);
217 221  
218   - if ($det_obj) {
219   - $det_obj = array_shift($det_obj);
220   - }
  222 + $turmasThisSerie = $lista;
  223 + // lista turmas disponiveis para enturmacao, somente lista as turmas sem enturmacao
  224 + foreach ($turmasThisSerie as $turma) {
221 225  
222   - // Monta a lista
223   - if (is_array($lista) && count($lista)) {
224   - foreach ($lista as $registro) {
225   - if($registro['cod_turma'] != $det_obj['ref_cod_turma']) {
226   - $script = sprintf('onclick="enturmar(\'%s\',\'%s\',\'%s\',\'%s\');"',
227   - $this->ref_cod_escola, $registro['ref_ref_cod_serie'],
228   - $this->ref_cod_matricula, $registro['cod_turma']);
229   -
230   - $this->addLinhas(array(
231   - sprintf('<a href="#" %s>%s</a>', $script, $registro['nm_turma'])
232   - ));
233   - }
  226 + $turmaHasEnturmacao = false;
  227 + foreach ($enturmacoesMatricula as $enturmacao) {
  228 + if(! $turmaHasEnturmacao && $turma['cod_turma'] == $enturmacao['ref_cod_turma'])
  229 + $turmaHasEnturmacao = true;
234 230 }
  231 +
  232 + if($turmaHasEnturmacao)
  233 + $enturmado = "Sim";
  234 + else
  235 + $enturmado = "Não";
  236 +
  237 + $script = sprintf('onclick="enturmar(\'%s\',\'%s\',\'%s\',\'%s\');"',
  238 + $this->ref_cod_escola, $turma['ref_ref_cod_serie'],
  239 + $this->ref_cod_matricula, $turma['cod_turma']);
  240 +
  241 + $this->addLinhas(array(sprintf('<a href="#" %s>%s</a>', $script, $turma['nm_turma']), $enturmado));
235 242 }
236 243  
237 244 $this->addPaginador2("educar_matricula_turma_lst.php", $total, $_GET,
... ... @@ -272,4 +279,4 @@ function enturmar(ref_cod_escola, ref_cod_serie, ref_cod_matricula, ref_cod_turm
272 279  
273 280 document.formcadastro.submit();
274 281 }
275   -</script>
276 282 \ No newline at end of file
  283 +</script>
... ...