<?    require_once('matricula_cabec.php');

  if ($_POST['PGTOCARTAO']) {
		if (trim($_POST['codigoBandeira']) == '') {
			$msg_erro = 'O campo "Bandeira do Cartão" deve ser informado !';
		}
		elseif (trim($_POST['cartaoNumero']) == '') {
			$msg_erro = 'O campo "Número do Cartão" deve ser informado !';
		}
		elseif (trim($_POST['MES_CARTAO']) == '') {
			$msg_erro = 'O campo "Mês de Validade" deve ser informado !';
		}
		elseif (trim($_POST['ANO_CARTAO']) == '') {
			$msg_erro = 'O campo "Ano de Validade" deve ser informado !';
		}
		elseif (trim($_POST['cartaoCodigoSeguranca']) == '') {
			$msg_erro = 'O campo "Código de Segurança" deve ser informado !';
		}
		elseif (trim($_POST['nome_portador']) == '') {
			$msg_erro = 'O campo "Nome do Portador" deve ser informado !';
		} else {
			$sqlestabpolo = "select coalesce(e.estab,r.estab) as estab from receb r
						  left join contrato co on r.contrato = co.contrato
						  left join cad_polo cpo on co.cad_polo = cpo.cad_polo
						  left join estab e on cpo.estab = e.estab
						  where receb = '{$_POST[ACORDO]}'";
			$query = @OCIParse($dbh, $sqlestabpolo);
			@ociexecute($query);
			@OCIFetchInto($query, $row_estabpolo, OCI_ASSOC);
			
			
			$_SESSION['ALUNO_CURSO'][$_SESSION['DADOS']['ALUNO_CURSO']]['DADOS']['ESTAB'] = $row_estabpolo['ESTAB'];
			
			/*revalidando saldo, para não ocorrer transação duas vezes*/
			$sqlreceb = "select f_receb_vlr_liquido({$_POST[ACORDO]}, null, null, null, 'S', 'S') as vlr from dual";
			$query = @OCIParse($dbh, $sqlreceb);
			@ociexecute($query);
			@OCIFetchInto($query, $row, OCI_ASSOC);
			$vlr = $row['VLR'];
			
			if ($vlr <= 0){
				echo '<tr>
						<td colspan="3" bgcolor="#F7F7F7" class="alerta_piscante centro"><br><br>Pagamento já efetuado.<br><br></td>
					  </tr>
					  <tr>
						<td colspan="3" bgcolor="#F7F7F7" class="centro">
							<form action="matricula_boleto.php" method="post" id="frm-cartao-credito" name="frm-cartao-credito">
								<input type="hidden" name="aluno" value="'.$RA_CRIPTO.'">
								<input type="hidden" name="ALUNO_CURSO" value="'.$aluno_curso.'">
								<br><br><input type="submit" value="Voltar para Tela Inicial" class="botao"><br><br>
							</form>
						</td>
					  </tr>';
				exit;
			} else{
			
				require_once('lib/loja/pages/carrinhoCartaoPagamento.php');
				
				if ($_SESSION['requisicao']['SITUACAO'] == 'APROVADO') {
					$finalizacao = true;
				} else {
					$finalizacao = false;
				}
				
				$receb = $_POST['ACORDO'];
				$autorizacao_cartao = $_SESSION['requisicao']['NUMAUTENT'];
				$transacao_cartao = $_SESSION['requisicao']['NUMCV'];
				$bandeira_cartao  = $_SESSION['requisicao']['BANDEIRA'];
				$ip_confirmacao = $_SERVER['REMOTE_ADDR'];
				$xmlRetorno = print_r($_SESSION['requisicao']['RETORNO_XML'], true);
				
				if ($finalizacao){
				
					$sqlfr = "select trim(fr.forma_recebimento) as nome_boleto, coalesce(er.isentar_multa, 'N') as isentar_multa,coalesce(er.isentar_juros, 'N') as isentar_juros
						    from curso cr
						    left join tipo_curso_estab tce on tce.tipo_curso = cr.tipo_curso and tce.estab = cr.estab
						    left join processo_rematricula pr on pr.estab = cr.estab     
						    left join estab_rematricula er on er.estab_rematricula = coalesce(tce.estab_rematricula, pr.estab_rematricula)
						    left join estab_rematricula_fr erf on erf.estab_rematricula = er.estab_rematricula
						    left join forma_recebimento fr on erf.forma_recebimento = fr.forma_recebimento
						   where cr.curso = '{$aluno['CURSO']}'
						     and fr.descr = trim('{$_POST['codigoBandeira']}')";
					$queryfr = @OCIParse($dbh, $sqlfr);
					$res = @OCIexecute($queryfr);
					@OCIFetchInto($queryfr, $rowfr, OCI_ASSOC);
					$forma_recebimento = trim($rowfr['NOME_BOLETO']);	
					$vlr = str_replace('.',',',$_POST['valorCartao']);
					
					$sp = "begin sp_gera_receb_bx_cartao(:receb,:forma_recebimento, :vlr, :retorno,:ip_confirmacao,:bandeira_cartao,:transacao_cartao,:autorizacao_cartao, :xml_retorno, :parcelas, :isentar_multa, :isentar_juros); end;";
					//echo  "begin sp_gera_receb_bx_cartao($receb,$forma_recebimento, $vlr, :retorno,$ip_confirmacao,$bandeira_cartao,$transacao_cartao,$autorizacao_cartao, $xmlRetorno); end;";
					$stmt = OCIParse($dbh, $sp);
					$retorno = OCI_new_cursor($dbh);
					OCIBindByName($stmt, ":retorno", $retorno, -1, OCI_B_CURSOR);
					OCIBindByName($stmt, "receb", $receb, -1, OCI_B_INT);
					OCIBindByName($stmt, "forma_recebimento", $forma_recebimento, 32, SQLT_CHR);
					OCIBindByName($stmt, "vlr", $vlr);
					OCIBindByName($stmt, "autorizacao_cartao", $autorizacao_cartao, 32, SQLT_CHR);
					OCIBindByName($stmt, "transacao_cartao", $transacao_cartao, 32, SQLT_CHR);
					OCIBindByName($stmt, "bandeira_cartao", $bandeira_cartao, 32, SQLT_CHR);
					OCIBindByName($stmt, "ip_confirmacao", $ip_confirmacao, 32, SQLT_CHR);
					OCIBindByName($stmt, "xml_retorno", $xmlRetorno, -1, SQLT_CHR);
					OCIBindByName($stmt, "parcelas", $formaPagamento, 32, SQLT_CHR);
					OCIBindByName($stmt, "isentar_multa", $rowfr['ISENTAR_MULTA'], 32, SQLT_CHR);
					OCIBindByName($stmt, "isentar_juros", $rowfr['ISENTAR_JUROS'], 32, SQLT_CHR);
					//OCIExecute($stmt);
					@oci_execute($stmt, OCI_DEFAULT);
					//OCIExecute($retorno);
					$erros = OCIError($stmt);
					//$row = oci_fetch_assoc($retorno);
				
					if (!$erros){
						$sql ="	select rb.receb_baixa, cad.e_mail as email, cad.cad, r.estab, r.contrato, ac.gc, ac.ra
								from receb r
								join receb_baixa rb on rb.receb= r.receb
								left join receb_bx_cartao rbx on rbx.receb_baixa = rb.receb_baixa 
								join cad on cad.cad = r.cad
								join cad_aluno ca on ca.cad =cad.cad
								join aluno_curso ac on ac.cad_aluno =ca.cad_aluno
								where rb.receb={$receb}";
							
						$sth 	= @db_query($dbh, $sql);
						$row 	= oci_fetch_assoc($sth[0]);
						$cad 	= $row['CAD'];
						$estab 	= $row['ESTAB'];
						$email 	= $row['EMAIL'];
						$CONTRATO 	= $row['CONTRATO'];
						$ra			= $row['RA'];
						$gc			= $row['GC'];
						
						$dir = 'tmp/';
							
						//******** Email Recibo *************
						$arquivo_email	=	'recibo_'.$receb.'.pdf';
						$arquivo 		= $dir.$arquivo_email;

						require_once "matricula_recibo_cartao.php";
						
						$th = db_start_t($dbh);
							
						$size	= filesize ($arquivo);
						$f 		= fopen($arquivo, 'r');
						$anexo 	= fread($f, $size);
						fclose($f);
						
						$sql = "insert into email_anexo (arquivo, nome) values (empty_blob(), '{$arquivo_email}') returning arquivo into :e";
						
						$e = OCINewDescriptor($th, OCI_D_LOB);
						$p = OCIParse($th, $sql);
						OCIBindByName($p, ":e", $e, -1, OCI_B_BLOB);
						OCIExecute($p, OCI_DEFAULT);

						$ok = $e->save($anexo);
						
						$sql_anexo 		= "select seq_email_anexo.currval as email_anexo from dual";
						$res_anexo 		= db_query($th, $sql_anexo);
						$email_anexo 	= db_fetch_row($res_anexo[0]);
						$key_anexo 		= $email_anexo['EMAIL_ANEXO'];
						
						$sql_email = "	insert into email (evento_email, e_mail, email_anexo,  assunto, texto, cad, estab, contrato) 
										values ('ENVIO_EMAIL_RECIBO_DE_CARTAO', '{$email}', '{$key_anexo}', 'Recibo de Pagamento', 'Recibo de Pagamento', '{$cad}', '{$estab}', '{$CONTRATO}')";
						$res_email = @OCIParse($th, $sql_email);
						@ociexecute($res_email);
						OCICommit($th);

						$h=opendir($dir);
		
						$path=$arquivo;
						@unlink($path);

						closedir($h);
						
						//******** Email Contrato *************
							
						$arquivo_contrato 	= 'contrato_'.$CONTRATO.'.pdf';
						$arquivo 			= $dir.'contrato_'.$CONTRATO.'.pdf';
						require_once "matricula_contrato.php";
						
						if($contrato_ok){
							
							$size	= filesize ($arquivo);
							$th 	= db_start_t($dbh);
							$f 		= fopen($arquivo, 'r');
							$anexo 	= fread($f, $size);
							fclose($f);
							
							$sql = "insert into email_anexo (arquivo, nome) values (empty_blob(), '{$arquivo_contrato}') returning arquivo into :e";
							
							$e = OCINewDescriptor($th, OCI_D_LOB);
							$p = OCIParse($th, $sql);
							OCIBindByName($p, ":e", $e, -1, OCI_B_BLOB);
							OCIExecute($p, OCI_DEFAULT);

							$ok = $e->save($anexo);
							
							$sql_anexo 		= "select seq_email_anexo.currval as email_anexo from dual";
							$res_anexo 		= db_query($th, $sql_anexo);
							$email_anexo 	= db_fetch_row($res_anexo[0]);
							$key_anexo 		= $email_anexo['EMAIL_ANEXO'];
							
							$sql_email = "	insert into email (evento_email, e_mail, email_anexo,  assunto, texto, cad, estab, contrato) 
											values ('ENVIO_EMAIL_RECIBO_DE_CARTAO', '{$email}', '{$key_anexo}', 'Contrato Prestação de Seviço', 'Contrato Prestação de Seviço', '{$cad}', '{$estab}', '{$CONTRATO}')";
							$res_email = @OCIParse($th, $sql_email);
							@ociexecute($res_email);
							OCICommit($th);
							
							$h=opendir($dir);
							
							$path=$arquivo_contrato;
							@unlink($path);
							
							closedir($h);
						}
						
							// *****************//
						
						
						echo '<tr>
								<td colspan="3" bgcolor="#F7F7F7" class="alerta_piscante centro">
									<br><br>Pagamento autorizado com sucesso.<br><br>
									<a href="matricula_recibo_cartao.php?RECEB_CARTAO='.$receb.'&aluno='.$RA_CRIPTO.'" alt="Clique aqui para imprimir seu recibo do Cartão !" title="Clique aqui para imprimir seu recibo do Cartão !" target="_blank">RECIBO DE PAGAMENTO</a>
									<br><br>
								</td>
							  </tr>
							  <tr>
								<td colspan="3" bgcolor="#F7F7F7" class="centro">
									<form action="matricula_boleto.php" method="post" id="frm-cartao-credito" name="frm-cartao-credito">
										<input type="hidden" name="aluno" value="'.$RA_CRIPTO.'">
										<input type="hidden" name="ALUNO_CURSO" value="'.$aluno_curso.'">
										<br><br><input type="submit" value="Voltar para Tela Inicial" class="botao"><br><br>
									</form>
								</td>
							  </tr>';
						exit;
					} else {
						echo '<tr>
								<td colspan="3" bgcolor="#F7F7F7" class="alerta_piscante centro"><br><br>Erro ao processar a matrícula, favor entrar em contato com a secretaria.'.$erros.'-'.$_POST['valorCartao'].'<br><br></td>
							  </tr>';
					}
								
				} else{
					$sql = "update receb set ip_confirmacao = '$ip_confirmacao', bandeira_cartao = '$bandeira_cartao', transacao_cartao = '$transacao_cartao', autorizacao_cartao = '$autorizacao_cartao', xml_retorno = '$xmlRetorno' where receb = $receb";
					$res = @OCIParse($dbh, $sql);
					@OCIExecute($res);
					@OCIFreeStatement($res);
					$msg_erro = 'Erro ao efetuar autorização do pagamento ! Tente novamente mais tarde.';
				}
			}
		}
  }

  //Validação de entrada na tela
  $sql = "begin SP_REMATRICULA_CONSISTENCIA({$aluno['ALUNO_CURSO']}, '$DT_VALIDO_DE_OLD', '$DT_VALIDO_ATE_OLD', '$DT_VALIDO_DE', '$DT_VALIDO_ATE', '$DT_BASE', :contrato, :retorno, :mensagem, :saldo_matricula); end;";
  $res = @OCIParse($dbh,$sql);
  @OCIBindByName($res,":contrato",&$CONTRATO, 32);
  @OCIBindByName($res,":retorno",&$RETORNO, 32);
  @OCIBindByName($res,":mensagem",&$MENSAGEM, 4000);
  @OCIBindByName($res,":saldo_matricula",&$SALDO_MATRICULA, 32);
  @ociexecute($res);
  @OCIFreeStatement($res);

	$sql = "select receb from receb where tp_origem = 2 and contrato = {$aluno['CONTRATO']}";
	
    $res = @OCIParse($dbh, $sql);
	@ociexecute($res);
	@OCIFetchInto($res, $dados, OCI_ASSOC);
	@ocifreestatement($res);  
	$RECEB = $dados['RECEB'];
  
 
  //$RETORNO = 1;
  if(($RETORNO != 1) && ($RETORNO != 2)) {
      $erro = 1;
  }

  if($erro){
      echo "<script>window.location = 'matricula_inicio.php?aluno=$RA_CRIPTO&ALUNO_CURSO=$aluno_curso';</script>";
	  exit;  	      	
  }

  $sql = "select count(*) as ja_aceito
            from aluno_curso_confirmacao
           where aluno_curso = {$aluno['ALUNO_CURSO']} and trunc(dt_valido_de) = '$DT_VALIDO_DE'";
  $res = @OCIParse($dbh, $sql);
  @ociexecute($res);
  @OCIFetchInto($res, $row, OCI_ASSOC);
  @ocifreestatement($res);        	  
  		
  if(!$row['JA_ACEITO']){
      $sql = "insert into aluno_curso_confirmacao (
  	   											   aluno_curso, 
  	  											   dt_valido_de,
												   dt_confirmacao
  	   											  ) values (
  	   											   {$aluno['ALUNO_CURSO']},
  	   											   '$DT_VALIDO_DE',
												   sysdate
  	   											  )";
      $res = @OCIParse($dbh, $sql);
  	  @ociexecute($res);
  	  @ocifreestatement($res);  		      
  }
 
  
  if (($SALDO_MATRICULA <= 0) and ($LIBERA_MATRICULA_ACADEMICA)) {
	  echo "<script>window.location = 'matricula_dados_cadastrais.php?aluno=$RA_CRIPTO&ALUNO_CURSO=$aluno_curso';</script>";
	  exit;
  }
?>
<tr>
    <td colspan="3" bgcolor="#000000" align="center" class="texto3">Orientações Gerais</td>
</tr>
<tr>
    <td colspan="3" bgcolor="#F7F7F7">&nbsp;</td>
</tr>
<?
      $sql = "select coalesce(txt.texto, etr.texto) as texto from aluno_curso ac
				join gc on gc.gc = ac.gc
				join curso c on c.curso = gc.curso
				join estab e on e.estab = c.estab
				join estab_texto_rematricula etr on etr.estab = e.estab and etr.nr_texto = 11
				join tipo_curso tc on tc.tipo_curso = c.tipo_curso
				left join tipo_curso_estab tce on tce.tipo_curso = tc.tipo_curso and tce.estab = c.estab
				left join tipo_curso_estab_texto_rematr txt on txt.tipo_curso_estab = tce.tipo_curso_estab and txt.nr_texto = 11
				where ac.aluno_curso = {$aluno['ALUNO_CURSO']}"; 					
	  $res = @OCIParse($dbh, $sql);				
	  @ociexecute($res);
	  @OCIFetchInto($res, $row, OCI_ASSOC);
	  @ocifreestatement($res);	  
?>
	  <tr>
	      <td colspan="3" bgcolor="#F7F7F7"><?=$row['TEXTO']->load()?></td>
	  </tr>
<?
	if($SALDO_MATRICULA <= 0){
?>
      <tr>
    	  <td colspan="3" bgcolor="#F7F7F7"class=" texto4"><br><br>Boleto<?=($TIPO_CURSO != 15 ? ' de matrícula ' : ' ')?>quitado. Aguarde o período de rematrícula acadêmica.<br><br></td>
      </tr>
<?
	} else {
	$sqlreceb = "select receb, (select case when trunc(sysdate) <= trunc(coalesce(tce.dt_limite_impressao_boleto, er.dt_limite_impressao_boleto)) then 1 else 0 end 
								  from curso cr1
							 left join tipo_curso_estab tce on tce.tipo_curso = cr1.tipo_curso and tce.estab = cr1.estab
							 left join processo_rematricula pr on pr.estab = cr1.estab     
							 left join estab_rematricula er on er.estab_rematricula = coalesce(tce.estab_rematricula, pr.estab_rematricula)
						 		 where cr1.curso = cr.curso) as libera_impressao,
							   /*(select coalesce(er.permite_rematricula_via_cartao, 'N')
								  from curso cr1
							 left join tipo_curso_estab tce on tce.tipo_curso = cr1.tipo_curso and tce.estab = cr1.estab
							 left join processo_rematricula pr on pr.estab = cr1.estab     
							 left join estab_rematricula er on er.estab_rematricula = coalesce(tce.estab_rematricula, pr.estab_rematricula)
								 where cr1.curso = cr.curso) as permite_cartao,*/
								 
								 coalesce(er.permite_rematricula_via_cartao, 'N') as permite_cartao,
								 coalesce(er.cartao_nr_maximo_parcelas, 1) as cartao_nr_maximo_parcelas,
								 coalesce(er.cartao_vlr_minimo_parcelas, 0) as cartao_vlr_minimo_parcelas,
								 coalesce(er.isentar_multa, 'N') as isentar_multa,
								 coalesce(er.isentar_juros, 'N') as isentar_juros,
								 f_receb_vlr_liquido(r.receb, null, null, null, coalesce(er.isentar_multa, 'N'),coalesce(er.isentar_juros, 'N')) as vlr,
								 coalesce((select sum(vlr_baixa)*-1 from receb_baixa where receb = r.receb and id_arq_migracao_saldo is not null),0) as vlr_outros_debitos
				   from receb r 
				   join contrato c on c.contrato = r.contrato
				   join aluno_curso ac on ac.aluno_curso = c.aluno_curso
				   join gc on gc.gc = ac.gc
				   join curso cr on cr.curso = gc.curso
				   
				   left join tipo_curso_estab tce on tce.tipo_curso = cr.tipo_curso and tce.estab = cr.estab
				   left join processo_rematricula pr on pr.estab = cr.estab     
                   left join estab_rematricula er on er.estab_rematricula = coalesce(tce.estab_rematricula, pr.estab_rematricula)
		   
				  where r.contrato = $CONTRATO 
					and r.tp_origem = 2";
	$query = @OCIParse($dbh, $sqlreceb);
	@ociexecute($query);
	@OCIFetchInto($query, $row, OCI_ASSOC);
	$RECEB = $row['RECEB'];
	$LIBERA_IMPRESSAO = $row['LIBERA_IMPRESSAO'];
	$PERMITE_CARTAO = $row['PERMITE_CARTAO'];
	$cartao_nr_maximo_parcelas = $row['CARTAO_NR_MAXIMO_PARCELAS'];
	$cartao_vlr_minimo_parcelas = $row['CARTAO_VLR_MINIMO_PARCELAS'];
	//$VLR = $row['VLR'];
	$VLR = str_replace(',','.',$row['VLR']);
	$VLR_MT = str_replace(',','.',$row['VLR']-$row['VLR_OUTROS_DEBITOS']);
	$VLR_OD = str_replace(',','.',$row['VLR_OUTROS_DEBITOS']);
	
	@ocifreestatement($query);  
	if ($LIBERA_IMPRESSAO == 1) {
		
		echo "<td><br></td></tr>
			  <tr>
				<td align='center' colspan='3' class='texto8' height='30px'>Valores</td>
			  </tr>
			  <tr>
				<td>
					<br>&nbsp;&nbsp;<b>Matrícula:</b> R$ ".number_format($VLR_MT,2,',','.');
		if ($VLR_OD > 0){
			echo "<br>&nbsp;&nbsp;<b>Outros Débitos:</b> R$ ".number_format($VLR_OD,2,',','.')."
				  <br>&nbsp;&nbsp;<b>Total a Pagar :</b> R$ ".number_format($VLR,2,',','.')
				  ."</td>";
		}
		
		echo "</td></tr><tr><td><br></td></tr>";	
		
		if ($PERMITE_CARTAO == 'S' && $VLR > 0){			
			$mesesc = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
			for($yy=(date('y')/*-1*/), $i= 0; $i <= 20; $i++){
				$anosc[] = ($yy + $i);
			}
			echo "<tr>
						<td align='center' colspan='3' class='texto8' height='30px'>
							<input type='radio' name='FORMA_PGTO' id='FORMA_PGTOB' value='B' onclick=\"$('.hide1').css( 'display', 'table-row' );$('.hide2').hide();\" > Pagar com Boleto &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<input type='radio' name='FORMA_PGTO' id='FORMA_PGTOC' value='C' onclick=\"$('.hide2').css( 'display', 'table-row' );$('.hide1').hide();\" ".($_POST['PGTOCARTAO'] ? 'checked' : '')."> Pagar com Cartão de Crédito
						</td>
				   </tr>";	

		   if ($msg_erro) {
				echo '<tr>
						<td colspan="3" bgcolor="#F7F7F7" class="alerta_piscante centro"><br><br>'.$msg_erro.'<br><br></td>
					  </tr>';
			}
?>
      <tr class='hide2' <?=($_POST['PGTOCARTAO'] ? 'style="display: block !important;"' : '')?>>
    	  <td colspan="3" bgcolor="#F7F7F7" class=" texto4">
			  	<form action="matricula_boleto.php" method="post" id="frm-cartao-credito" name="frm-cartao-credito">
						<input type="hidden" name="aluno" value="<?=$RA_CRIPTO?>">
						<input type="hidden" name="ALUNO_CURSO" value="<?=$aluno_curso?>">
						<input type="hidden" name="ACORDO" value="<?=$RECEB?>">
						<input type="hidden" name="valorCartao" maxlength="20" value="<?=$VLR?>"/>
						<!--input type="hidden" name="formaPagamento" maxlength="20" value="1"/-->
						<table width="55%" align="center" cellspacing="1" cellpadding="5" class="grade">
						<tr>
							<td class="texto10">Selecione a Bandeira do Cartão</td>
						</tr>
						<tr>
							<td class="texto4">
								<select name="codigoBandeira" id="codigoBandeira"/>
									<option value=""></option>
		<?
									$sqlc = "select fr.descr as nome_boleto
											   from curso cr
  										  left join tipo_curso_estab tce on tce.tipo_curso = cr.tipo_curso and tce.estab = cr.estab
										  left join processo_rematricula pr on pr.estab = cr.estab     
										  left join estab_rematricula er on er.estab_rematricula = coalesce(tce.estab_rematricula, pr.estab_rematricula)
										  left join estab_rematricula_fr erf on erf.estab_rematricula = er.estab_rematricula
										  left join forma_recebimento fr on erf.forma_recebimento = fr.forma_recebimento
									          where cr.curso = '{$aluno['CURSO']}'
											    and fr.descr is not null";

									$queryc = OCIParse($dbh, $sqlc);
									ociexecute($queryc);
									
									while (OCIFetchInto($queryc, $row, OCI_ASSOC)) {
		?>
										<option value="<?=$row['NOME_BOLETO']?>" <?=($_POST['codigoBandeira'] == $row['NOME_BOLETO'] ? 'selected' : '')?>><?=$row['NOME_BOLETO']?></option>
		<?
									}
		?>
								</select>
							</td>
						</tr>
						<tr>
							<td class="texto10">Número do cartão</td>
						</tr>
						<tr>
							<td class="texto4"><input type="text" name="cartaoNumero" id="cartaoNumero" maxlength="20" value="<?PHP echo $_POST['cartaoNumero']; ?>"/></td>
						</tr>
					   <tr>
							<td class="texto10">Nome do titular <i style="font-size:80%;">(como gravado no cartão)</i></td>
					   </tr>
					   <tr>
							<td class="texto4"><input type="text" name="nome_portador" id="nome_portador" maxlength="100" value="<?PHP echo $_POST['nome_portador']; ?>" onblur="javascript: this.value = this.value.toUpperCase();"/></td>
					   </tr>
					   <tr>
							<td class="texto10">Data de validade</td>
					   </tr>
					   <tr>
							<td class="texto4"><nobr>
									<select name="MES_CARTAO" id="MES_CARTAO">
										<option value="">Mês</option> <?
										foreach ($mesesc as $mes){
											$selected = $_POST['MES_CARTAO'] == $mes ? "selected='selected'" : ''; ?>
											<option value="<?=$mes?>" <?=$selected?>><?=$mes?></option> <?
										} ?>
									</select>
									<select name="ANO_CARTAO" id="ANO_CARTAO">
										<option value="">Ano</option> <?
										foreach ($anosc as $ano){
											$selected = $_POST['ANO_CARTAO'] == $ano ? "selected='selected'" : ''; ?>
											<option value="<?=$ano?>" <?=$selected?>><?=$ano?></option> <?
										} ?>
									</select>
								</nobr>
							</td>
					   </tr>
					   <tr>
							<td class="texto10">Código de Segurança</td>
					   </tr>
					   <tr>
							<td class="texto4"><input type="text" name="cartaoCodigoSeguranca" id="cartaoCodigoSeguranca" value="" style="max-width:100px" maxlength="4" /></td>
					   </tr>
					   <tr>
							<td class="texto10">Valores<td>
					   </tr>
						<tr>
							<td class="texto4">Matrícula: R$ <?=number_format($VLR_MT,2,',','.')?></td>
						</tr>
						
					    <? if ($VLR_OD > 0){ ?>
						<tr>
							<td class="texto4">Outros Débitos: R$ <?=number_format($VLR_OD,2,',','.')?></td>
						</tr>
						<tr>
							<td class="texto4">Total a Pagar : R$ <?=number_format($VLR,2,',','.')?></td>
					   </tr>
						<? }?>
					   <tr>
							<td class="texto10">Forma de Pagamento </td>
							</tr>
						<tr>
							<td class="texto4">
							<select name="formaPagamento" id="formaPagamento">
							<? for ($i = 1; $i <= $cartao_nr_maximo_parcelas; $i++){
								 $vlr_parcela = round($VLR/$i,2);
								 if (($VLR/$i) >= $cartao_vlr_minimo_parcelas){
									echo "<option value='{$i}'>{$i} parcela".($i>1?'s':'')." de ".number_format($vlr_parcela,2,',','.')."</option>";
								 }
							}
							?>
							</select>
							</td>
					   </tr>
					   <tr><td class="centro">
							<br><br><input type="submit" name="PGTOCARTAO" value="Pagar com Cartão" class="botao"><br><br>
					   </td></tr>
					   </table>
					</form>
		  </td>
      </tr>
	  <tr class='hide1' <?=($_POST['PGTOCARTAO'] ? 'style="display: none !important;"' : '')?>>
			  <td align='center' colspan="3" bgcolor="#F7F7F7" class=" texto10" width="55%"><br><br>Clique <a href="receb.2avia.pdf.php?RECEB=<?=$RECEB?>&aluno=<?=$RA_CRIPTO?>&ALUNO_CURSO=<?= $aluno_curso; ?>" target="_blank">aqui</a> para imprimir seu boleto<?=($TIPO_CURSO != 15 ? 'de matrícula' : '')?>.<br><br></td>
	  </tr>
<?	  
		} 
		else {
?>
		  <tr>
			  <td align='center' colspan="3" bgcolor="#F7F7F7" class=" texto4"><br><br>Clique <a href="receb.2avia.pdf.php?RECEB=<?=$RECEB?>&aluno=<?=$RA_CRIPTO?>&ALUNO_CURSO=<?= $aluno_curso; ?>" target="_blank">aqui</a> para imprimir seu boleto<?=($TIPO_CURSO != 15 ? 'de matrícula' : '')?>.<br><br></td>
		  </tr>
<?
		}
	}else{
	
			$sql = "select coalesce(txt.texto, etr.texto) as texto from aluno_curso ac
				join gc on gc.gc = ac.gc
				join curso c on c.curso = gc.curso
				join estab e on e.estab = c.estab
				join estab_texto_rematricula etr on etr.estab = e.estab and etr.nr_texto = 12
				join tipo_curso tc on tc.tipo_curso = c.tipo_curso
				join tipo_curso_estab tce on tce.tipo_curso = tc.tipo_curso and tce.estab = c.estab
				join tipo_curso_estab_texto_rematr txt on txt.tipo_curso_estab = tce.tipo_curso_estab and txt.nr_texto = 12
				where ac.aluno_curso = {$aluno['ALUNO_CURSO']}";
        	$res = @OCIParse($dbh, $sql);
        	@ociexecute($res);
        	@OCIFetchInto($res, $row, OCI_ASSOC);
        	@ocifreestatement($res);
?>
       <tr>
	       <td colspan="3" bgcolor="#F7F7F7"><?=($row['TEXTO'] ? $row['TEXTO']->load() : '')?></td>
       </tr>
<?
	}
  }
?>
<tr>
	<td colspan="3" bgcolor="#F7F7F7">&nbsp;</td>
</tr>
</table>

</body>
		
</html>
