<?php 		
	$academia->instruccion("SELECT ide_adtivo, LCASE(CONCAT_WS(' ', no1_adtivo, no2_adtivo,ape1_adtivo, ape2_adtivo)) nom_ape FROM adm_administrativos WHERE cod_cargo=1 or cod_cargo=2 order by cod_cargo");
	$regFirmantes=$academia->fetchAll();
	$nom_rector=$regFirmantes[0]['nom_ape'];
	$nom_cordin=$regFirmantes[1]['nom_ape'];
	
	$sql="call SP_SABANAS_GRUPO('$cod_estudiantes',$grupo,$periodon,'$iduser')"; 

	$academia->instruccion($sql); 
	echo '<div style="display:none">'.$sql.'</div>';
	unset($sql);
	$row=$academia->extraer_registro();
	$dtsColegio=$sesion->get('info_colegio');
	$encabezado=$dtsColegio['enca_dtos'];
	$observa="";

	$notest = str_replace("\n", "<br>", $row['notas']);
    $notest = str_replace("\t", " ", $notest);
    $notest = parseString($notest);

	//echo $row['notas'];
	$dtsEstNot=json_decode($notest,true);
	//echo '--->>'.jsonError();
	echo '<div id="pageSabana">';
	echo $encabezado;
	if($dtsEstNot===NULL){
				echo '<div class="alert">Error en la informacion</div>';
				exit;
	}
	$mayus_nom=$sesion->getVar('configuracion.format_nom');
	$mayus_mat=$sesion->getVar('configuracion.format_mat');
?>
<table width="100%" style="border:1px solid; margin-bottom:2px; font-size: 9pt;  font-family: Arial, Helvetica, sans-serif;  vertical-align:top;">
		<tr align="left">
			<td colspan="4" align="center"><strong>SABANA DE DESEMPEÑOS</strong></td>
		</tr>
		<tr align="left">
			<td> <strong>Sede:</strong>&nbsp;&nbsp;<?php echo $sede;   ?></td>
			<td> <strong>Jornada:</strong>&nbsp;&nbsp;<?php echo $jornada; ?></td>
			<td><strong>Grado:</strong> &nbsp;&nbsp;<?php echo $grado; ?></td>
			<td> <strong>Periodo:</strong>&nbsp;&nbsp;<?php echo $periodo; ?></td>
		</tr>
	</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td width="5%"></td>
		<td>&nbsp;</td>
		<td>&nbsp;</td> 
	</tr>
</table>

<table width="100%" border="0" cellspacing="0" cellpadding="0" class="sabana">
	<tr>
		<th width="5%">N°</th>
		<th width="27%">Estudiante</th> 
		<?php
			
			foreach($dtsEstNot['materias'] as $v){
				echo '<th width="15px"><div class="nommat">'.formatoPalabras($v['no_asi'],$mayus_mat).'</div></th>';
			}
		?>
		<th>Prom. Est.</th> 
		<th>Pto. Ets.</th> 
	</tr>

<?php
	$conEts=0;
	do{
        $notest = str_replace("\n", "<br>", $row['notas']);
        $notest = str_replace("\t", " ", $notest);
        $notest = parseString($notest);

		$dtsEstNot=json_decode($notest,true);



		if($dtsEstNot===NULL)
			continue;
		$msgPbar="id-".$notest[dc_est]."-pto-".$notest[pto_gru];
		$msgPbar.="-grado-".$grado."-per-".$periodon.'-val-si-anio'.$sesion->get('anio');
		$conEts++;
	?>
		<tr>
			<td><?php echo $conEts; ?></td>
			<td><?php echo formatoPalabras($dtsEstNot['no_est'],$mayus_nom) ?></td>
			<?php
				$promEst=0;$ax=0;
				$pto_gr=$dtsEstNot['pto_gru'];
				foreach($dtsEstNot['materias'] as $v){
					$promEst+=$v['nn'];
					$promMat[$ax]=(empty($promMat[$ax])) ? $v['nn'] : ($promMat[$ax]+$v['nn']);
					if($v['nn']<=$v['pierde']){
						echo '<td align="center"><strong>'.numberFormat($v['nn'],1,'.', '').'</strong></td>';
						$ax++; continue;
					}
					echo '<td align="center">'.numberFormat($v['nn'],1,'.', '').'</td>';
					$ax++;
				}
				$promMat[$ax]=(empty($promMat[$ax])) ? ($promEst/$ax) : ($promMat[$ax]+($promEst/$ax));
			?>	
			<td width="5%" align="center" style="font-size:10pt"><?php echo numberFormat(($promEst/$ax),1,'.', '') ?></td>
			<td width="5%" align="center" style="font-size:10pt"><?php echo $pto_gr ?></td>
		</tr>
	<?php
		}while($row=$academia->extraer_registro());
		$academia->liberar();
		echo '<tr><td></td><td>Promedio Materias</td>';
		foreach($promMat as $pm){
			echo '<td align="center" style="font-size:10pt">'.numberFormat((($pm/($conEts))),1,'.', '').'</td>';
		}
	?>
	
</table>
	<br><br>
	<table id="foot" width="100%" cellpadding="0" cellspacing="0">
		<tr>
				<td width="6%" rowspan="2" align="center" valign="middle">&nbsp;</td>
				<td align="center" valign="middle"><?php echo $sesion->getVar('info_colegio.pie_boletin') ?></td>
				<td width="6%" rowspan="2" align="right"><?php
					// user data
					$PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR;
					$PNG_WEB_DIR = 'temp/';
					//ofcourse we need rights to create temp dir
					if (!file_exists($PNG_TEMP_DIR))
						mkdir($PNG_TEMP_DIR);
						
					$errorCorrectionLevel = 'L';
					$matrixPointSize = 1;
					//echo $msgPbar;
					$filename = $PNG_TEMP_DIR.'Boletin'.$cod_est.'_'.$sesion->get('academia_succes')."-".md5($errorCorrectionLevel.'|'.$matrixPointSize.'').'.png';
					QRcode::png($msgPbar, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
					echo '<img src="'.$PNG_WEB_DIR.basename($filename).'" class="codbar" />';
				?></td>
			</tr>
			<tr>
				<td align="center"><span class="copy"><?php echo $dtsLang['project']['nom_soft'].' ' .$dtsLang['project']['ver_soft'].' '.$dtsLang['project']['footertext']." ".$dtsLang['project']['anio_ini'].' - '.date('Y') ?></span></td>
			</tr>
		</table>

<?php
	echo "</div>";//cirra la pagina
?>
