<?
include("../fnc.php");
enlinea_a();
$qinfo=mysql_query("select * from ec_evaluaciones
                    where id = '".dec($idev)."'");
$info=mysql_fetch_array($qinfo);



$id_ev=dec($idev);
$id_cat=dec($idcat);
$id_cur=dec($curso);

$qinfocat=mysql_query("select * from usuarios where usuario = '$id_cat'");
$infocat=mysql_fetch_array($qinfocat);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>e-Ducativo - Bienvenido</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../estilo1.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../jsincludes/overlib.js"></script>
<style type="text/css">
<!--
body {
	background-image: url(../images/tema/bg_pagina.png);
}
-->
</style></head>
<body>
<table width="750" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#333333">
  <tr>
    <td bgcolor="#FFFFCC">    <table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#E5E5E5">
      <tr bgcolor="#FFFFFF">
        <td width="40%"><img src="../images/logo_5.gif" width="300" height="50"></td>
        <td width="60%" background="../images/back_header.gif" bgcolor="#FFFFFF"><div align="right" class="usuario_nombre_enc"><strong><?echo "$unombre $uapellido";?><br>
          </strong>Tiene <?=mensajes($uuser);?> mensaje(s) sin leer</div></td>
      </tr>
      <tr bgcolor="#FFFFFF">
        <td height="15" colspan="2" background="../images/barra_encabezado.gif">&nbsp;</td>
        </tr>
    </table>
      <table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td width="20%" valign="top" background="../images/tema/bg_contenido.png" bgcolor="#FFFFCC"><?php include("menu.php"); ?>&nbsp;</td>
          <td width="80%" valign="top" background="../images/tema/bg_contenido.png"><table width="100%"  border="0" cellpadding="0" cellspacing="0" bgcolor="#333333">
            <tr align="center" valign="middle" bgcolor="#FFFFCC">
              <td height="20" class="titulo_pagina"><div align="center" class="titulo_pagina">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="65" background="../images/tema/bg_contenido.png">&nbsp;</td>
                    <td background="../images/tema/bg_contenido.png"><div align="center" class="titulo_pagina"><strong>RESULTADOS DE LA EVALUACION </strong></div></td>
                    <td width="65" background="../images/tema/bg_contenido.png"><div align="right"><a href="inicio.php" class="link_parrafo">Inicio<img src="../images/ic_home.png" width="21" height="21" border="0"></a></div></td>
                  </tr>
                </table>
              </div></td>
            </tr>
            <tr>
              <td align="left" valign="top" background="../images/tema/bg_contenido.png" bgcolor="#FFFFCC"><div align="left" class="parrafo">                  <table width="99%"  border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000099">
                      <tr>
                        <td bgcolor="#ECE9D8"><table width="100%"  border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
                            <tr bgcolor="#6699CC">
                              <td colspan="2" class="titulo_seccion"><div align="left" class="titulo_formulario">Informaci&oacute;n de la evaluaci&oacute;n </div></td>
                            </tr>
                            <tr>
                              <td width="14%" align="left" valign="middle" background="../images/tema/bg_frm_campos.png" bgcolor="#CFDFEF" class="lbl_campo"><div align="left">Nombre de la evaluaci&oacute;n: </div></td>
                              <td width="86%" background="../images/tema/bg_frm_campos.png" bgcolor="#ECF2F9"><div align="left">
                                <?=$info[nombre];?>
                              </div></td>
                            </tr>
                            <tr>
                              <td width="14%" align="left" valign="middle" background="../images/tema/bg_frm_campos.png" bgcolor="#CFDFEF" class="lbl_campo"><div align="left">Fechas de activaci&oacute;n: </div></td>
                              <td background="../images/tema/bg_frm_campos.png" bgcolor="#ECF2F9">
                                <div align="left">
                                  <?
                              echo "Del: ".fechalarga($info[fecha_inicio]);
                              echo "<br>Al: ".fechalarga($info[fecha_fin]);
                              ?>
                                </div></td>
                            </tr>
                            <tr bgcolor="#FFFFCC">
                              <td align="left" valign="middle" background="../images/tema/bg_frm_campos.png" class="lbl_campo">Grado:</td>
                              <td align="left" valign="middle" background="../images/tema/bg_frm_campos.png" class="lbl_campo"><?=substr(ggrado_completo($grado),7);?></td>
                            </tr>
                            <tr bgcolor="#FFFFCC">
                              <td align="left" valign="middle" background="../images/tema/bg_frm_campos.png" class="lbl_campo"><div align="left">Catedr&aacute;tico:</div></td>
                              <td align="left" valign="middle" background="../images/tema/bg_frm_campos.png" class="lbl_campo"><div align="left"><?=$infocat[apellido]." ".$infocat[nombre];?></div></td>
                            </tr>
                            <tr bgcolor="#FFFFCC">
                              <td align="left" valign="middle" background="../images/tema/bg_frm_campos.png" class="lbl_campo"><div align="left">Curso:</div></td>
                              <td align="left" valign="middle" background="../images/tema/bg_frm_campos.png" class="lbl_campo"><div align="left">Todos</div></td>
                            </tr>
                            <tr bgcolor="#FFFFCC">
                              <td colspan="2" align="left" valign="middle" background="../images/tema/bg_contenido.png" class="lbl_campo">&nbsp;</td>
                            </tr>
                            <tr bgcolor="#CFDFEF">
                              <td colspan="2" align="left" valign="middle" background="../images/tema/bg_frm_campos.png" class="lbl_campo">
                              <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                              <?
                              // inicio ciclo de preguntas
                              $nota_total=0;
                              
                              $qpr=mysql_query("select * from ec_preguntas where evaluacion = '$id_ev' order by id");
                              while($ipr=mysql_fetch_array($qpr)){
                              $qcantre=mysql_query("select count(distinct alumno) as cant
                                                    from ec_respuestas
                                                    where evaluacion = '$id_ev'
                                                    and pregunta = {$ipr[id]}
                                                    and catedratico = '$id_cat'");
                              $icantre=mysql_fetch_array($qcantre);
                              $cnt_usuarios=$icantre[cant];
                              
                              
                              $qcantre=mysql_query("select count(*) as cant
                                                    from ec_respuestas
                                                    where evaluacion = '$id_ev'
                                                    and pregunta = {$ipr[id]}
                                                    and catedratico = '$id_cat'");
                              $icantre=mysql_fetch_array($qcantre);
                              $total_re=$icantre[cant];
                              ?>
                                <tr>
                                  <td background="../images/tema/bg_frm_campos.png">Pregunta: <span class="lbl_formulario"><?=$ipr[pregunta];?></span> </td>
                                </tr>
                                <tr>
                                  <td>
                                  <table width="100%"  border="0" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
                                  <?
                                  // opciones y promedio de opciones
                                  $qop=mysql_query("select * from ec_opciones where evaluacion = '$id_ev' and pregunta = '{$ipr[id]}' order by id");
                                  while($iop=mysql_fetch_array($qop)){
                                    $qprom=mysql_query("select avg(valor*{$ipr[puntos]}/100) as promedio
                                                        from ec_respuestas
                                                        where evaluacion = '$id_ev'
                                                        and pregunta='{$ipr[id]}'
                                                        and catedratico = '$id_cat'
                                                        having promedio <> 'NULL'");
                                    if(mysql_num_rows($qprom)==0){
                                     $prom_pr=0;
                                    }else{
                                     $iprom=mysql_fetch_array($qprom);
                                     $prom_pr=$iprom[promedio];
                                    }
                                    $prom_pr=round($prom_pr,0);
                                    $qpromop=mysql_query("select count(*) as cant
                                                          from ec_respuestas
                                                          where evaluacion = '$id_ev'
                                                          and pregunta='{$ipr[id]}'
                                                          and respuesta = '{$iop[id]}'
                                                          and catedratico = '$id_cat'");
                                    if(mysql_num_rows($qpromop)==0){
                                     $prom_op=0;
                                    }else{
                                     $ipromop=mysql_fetch_array($qpromop);
                                     $prom_op=$ipromop[cant];
                                    }
                                    $prom_op=round($prom_op/$total_re*100,0);
                                  ?>
                                    <tr bgcolor="#ECF2F9">
                                      <td width="48%" height="20" align="left" valign="middle" class="parrafo"><?=$iop[opcion];?></td>
                                      <td width="41%" height="20" align="left" valign="middle"><img src="../images/barra_enc_centro.gif" width="<?=$prom_op*2;?>" height="15"><img src="../images/barra_enc_d.gif" width="10" height="15"></td>
                                      <td width="11%" height="20" align="left" valign="middle"><div align="left"><?=$prom_op;?>%</div></td>
                                    </tr>
                                  <?
                                  }// fin de opciones
                                  $nota_total+=$prom_pr;
                                  ?>
                                    <tr bgcolor="#ECF2F9">
                                      <td>Cantidad de usuarios que respondieron: <?=$cnt_usuarios;?> </td>
                                      <td>Valor promedio: <span class="lbl_formulario"><?=$prom_pr;?></span> </td>
                                      <td>&nbsp;</td>
                                    </tr>
                                  </table>
                                  <hr size="1"></td>
                                </tr>
                                <?
                                }// fin ciclo preguntas
                                ?>
                              </table>
                              <br>
                              VALOR FINAL: <span class="titulo_pagina"><?=$nota_total;?></span> </td>
                            </tr>
                        </table></td>
                      </tr>
                    </table>
                    <br>
                    <a href="rpt_ec_resultadosxgrado.php?<?="idev=$idev&nivel=$nivel&grado=$grado";?>"><img src="../images/regresar_c.png" width="32" height="32" border="0"></a><br>
                <strong>Salir</strong> </div></td>
              </tr>
          </table></td>
        </tr>
    </table>    </td>
  </tr>
</table>
</body>
</html>
