<%-- 
    Document   : exportarTodoUsuDocente
    Created on : 05/12/2014, 10:07:05 AM
    Author     : sistem16user
--%>


<%@page import="pe.siso.horario.Beans.Docente"%>
<%@page import="pe.siso.horario.Services.DocenteServices"%>
<%@page import="pe.siso.horario.Services.CursoServices"%>
<%@page import="pe.siso.horario.Beans.Horario"%>
<%@page import="java.util.ArrayList"%>
<%@page import="pe.siso.horario.Services.HorarioServices"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%

    String codDocente = request.getParameter("codDocente");
    

    HorarioServices servicios = new HorarioServices();
    DocenteServices serviciosDoc = new DocenteServices();
    Docente docente= new Docente();
    Docente docenteDatos= new Docente();
    ArrayList<Horario>lista = new ArrayList<Horario>();
    lista=servicios.horarioDocente(codDocente);
    CursoServices servicios2 = new CursoServices();
    
    docente=serviciosDoc.NombreDocente(codDocente);
    String nombreDocente = docente.ape_pro+", "+docente.nom_pro;
    
    docenteDatos = serviciosDoc.datosDocente(codDocente);
    String telefono = docenteDatos.getTelefono();
    String correo = docenteDatos.getCorreo();
    String zona = docenteDatos.getNombreDDis();
    String direccion=docenteDatos.getDireccion();
    String celular=docenteDatos.getCell();
    String provincia=docenteDatos.getNombrePro();
    String departamento=docenteDatos.getNombreDep();
    
    if(telefono==null || correo==null || zona==null || direccion == null || celular == null || provincia==null || departamento == null){
        telefono = "";
        correo = "";
        zona = "";
        direccion = "";
        celular = "";
        provincia="";
        departamento="";
    }
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
         <%
            response.setContentType("application/vnd.ms-excel; ");
            response.setHeader("Content-Disposition","attachment; filename=UsuarioDocente.xls");
            
            String border="style='border:solid 0.5pt #000000;vertical-align:middle;'";
            String borderT="style='border:solid 0.5pt #000000;vertical-align:middle; background-color:#D9D9D9;' ";
            String centrado="style='vertical-align:middle;' ";
            String borderColor="style='border:solid 0.5pt #000000; vertical-align:middle; background-color:#B5E0F5;'";
            String borderColorTitulo="style='border:solid 0.5pt #000000; vertical-align:middle; background-color:#006699; color:#FFFFFF;'";
            String estilo = "";
        %>
        
        
        
            
           
        <table width='100%' cellpadding='0' cellspacing='0'> 
            <tr> 
                <td colspan="7" height='10'> </td>
            </tr> 
            <tr>
                <td colspan="2" <%=borderT%> ><b>DOCENTE:</b></td>
                <td colspan="2" <%=border%> ><%=nombreDocente%></td>
                <td colspan="1" <%=borderT%> ><b>CORREO:</b></td>
                <td colspan="2" <%=border%> ><%=correo%></td>
                <td colspan="3" ></td>
            </tr> 
            <tr>
                <td colspan="2" <%=borderT%> ><b>TELÉFONO:</b></td>
                <td colspan="2" <%=border%> align='left'> <%=telefono%></td>
                <td colspan="1" <%=borderT%> ><b>CELULAR:</b></td>
                <td colspan="2" <%=border%> align='left'> <%=celular%></td>
                <td colspan="2" ></td>
            </tr> 
            <tr>
                <td colspan="2" <%=borderT%> ><b>PROVINCIA:</b></td>
                <td colspan="2" <%=border%> ><%=provincia%></td>
                <td colspan="1" <%=borderT%> ><b>DEPARTAMENTO:</b></td>
                <td colspan="2" <%=border%> ><%=departamento%></td>
                <td colspan="3" ></td>
            </tr> 
            <tr>
                <td colspan="2" <%=borderT%> ><b>DISTRITO:</b></td>
                <td colspan="2" <%=border%> ><%=zona%></td>
                <td colspan="1" <%=borderT%> ><b>DIRECCIÓN:</b></td>
                <td colspan="2" <%=border%> ><%=direccion%></td>
                <td colspan="3" ></td>
            </tr> 
            <tr> 
                <td height='10'  colspan="7" ></td>
            </tr> 
            <tr>
                <th <%=borderT%> >N°</th> 
                <th <%=borderT%> >LUNES</th> 
                <th <%=borderT%> >MARTES</th> 
                <th <%=borderT%> >MIERCOLES</th> 
                <th <%=borderT%> >JUEVES</th> 
                <th <%=borderT%> >VIERNES</th> 
                <th <%=borderT%> >SÁBADO</th> 
            </tr> 
            
    <%        
    int blo=1;
    int cont=1;
    int cantMayor=0;
    String dia="";
    String cadenaLun = "";
    String cadenaMar = "";
    String cadenaMier = "";
    String cadenaJue = "";
    String cadenaVier = "";
    String cadenaSab = "";
   
         for(int i=0;i<lista.size(); i++){
            dia =lista.get(i).getDia_HorarioCursoDoc();
            String[] arrayIni=lista.get(i).getHini_HorarioCursoDoc().split(":");
            String[] arrayFin=lista.get(i).getHfin_HorarioCursoDoc().split(":");
            
            String Hora=arrayIni[0]+":"+arrayIni[1]+" a "+arrayFin[0]+":"+arrayFin[1];
            
            
            if(dia.equals("1")){
                if(cadenaLun.equals("")){
                    cadenaLun += "<b>"+lista.get(i).getNombreCurso()+"</b><br><font color='black'><b>Sede:</b>"+lista.get(i).getNombreSede()+"<br> <b>Hora:</b>"+Hora+"</font>";
                }else{
                    cadenaLun += "#<b>"+lista.get(i).getNombreCurso()+"</b><br><font color='black'><b>Sede:</b>"+lista.get(i).getNombreSede()+"<br> <b>Hora:</b>"+Hora+"</font>";
                }
            }else if(dia.equals("2")){
                if(cadenaMar.equals("")){
                    cadenaMar += "<b>"+lista.get(i).getNombreCurso()+"</b><br><font color='black'><b>Sede:</b>"+lista.get(i).getNombreSede()+"<br> <b>Hora:</b>"+Hora+"</font>";;
                }else{
                    cadenaMar += "#<b>"+lista.get(i).getNombreCurso()+"</b><br><font color='black'><b>Sede:</b>"+lista.get(i).getNombreSede()+"<br> <b>Hora:</b>"+Hora+"</font>";;
                }
            }else if(dia.equals("3")){
                if(cadenaMier.equals("")){
                    cadenaMier += "<b>"+lista.get(i).getNombreCurso()+"</b><br><font color='black'><b>Sede:</b>"+lista.get(i).getNombreSede()+"<br> <b>Hora:</b>"+Hora+"</font>";;
                }else{
                    cadenaMier += "#"+lista.get(i).getNombreCurso()+"</b><br><font color='black'><b>Sede:</b>"+lista.get(i).getNombreSede()+"<br> <b>Hora:</b>"+Hora+"</font>";;
                }
            }else if(dia.equals("4")){
                if(cadenaJue.equals("")){
                    cadenaJue += "<b>"+lista.get(i).getNombreCurso()+"</b><br><font color='black'><b>Sede:</b>"+lista.get(i).getNombreSede()+"<br> <b>Hora:</b>"+Hora+"</font>";;
                }else{
                    cadenaJue += "#<b>"+lista.get(i).getNombreCurso()+"</b><br><font color='black'><b>Sede:</b>"+lista.get(i).getNombreSede()+"<br> <b>Hora:</b>"+Hora+"</font>";;
                }
            }else if(dia.equals("5")){
                if(cadenaVier.equals("")){
                    cadenaVier += "<b>"+lista.get(i).getNombreCurso()+"</b><br><font color='black'><b>Sede:</b>"+lista.get(i).getNombreSede()+"<br> <b>Hora:</b>"+Hora+"</font>";;
                }else{
                    cadenaVier += "#<b>"+lista.get(i).getNombreCurso()+"</b><br><font color='black'><b>Sede:</b>"+lista.get(i).getNombreSede()+"<br> <b>Hora:</b>"+Hora+"</font>";;
                }
            }else if(dia.equals("6")){
                if(cadenaSab.equals("")){
                    cadenaSab += "<b>"+lista.get(i).getNombreCurso()+"</b><br><font color='black'><b>Sede:</b>"+lista.get(i).getNombreSede()+"<br> <b>Hora:</b>"+Hora+"</font>";;
                }else{
                    cadenaSab += "#<b>"+lista.get(i).getNombreCurso()+"</b><br><font color='black'><b>Sede:</b>"+lista.get(i).getNombreSede()+"<br> <b>Hora:</b>"+Hora+"</font>";;
                }
            }
         }
         
         //ARRAY
         
         String[] arrayLun = cadenaLun.split("#");
         String[] arrayMar = cadenaMar.split("#");
         String[] arrayMier = cadenaMier.split("#");
         String[] arrayJue = cadenaJue.split("#");
         String[] arrayVier = cadenaVier.split("#");
         String[] arraySab = cadenaSab.split("#");
         
         
         
         int[] cantDias = {arrayLun.length,arrayMar.length,arrayMier.length,arrayJue.length,arrayVier.length,arraySab.length};
         for(int i=0; i<cantDias.length; i++){
             if(cantDias[i]>cantMayor){
                 cantMayor = cantDias[i];
             }
         }
         
        for(int i=0; i<cantMayor; i++){
        %>
            <tr>
                <td height='40' width='20' align='center' <%=border%> ><%=cont%>°</td>
        <%
                for(int d=1;d<=6;d++){
                if(d==1){
                    if(!cadenaLun.equals("")){
                        if(arrayLun.length>=cont){
        %>
                            <td height='100' width='140' align='center' <%=border%> ><%=arrayLun[i]%></td>
        <%
                        }else{
        %>
                           <td height='100' width='140' align='center' <%=border%> ><font size="9"><b>X</b></font></td>
        <%
                        }
                    }else{
        %>
                                <td height='100' width='140' align='center' <%=border%> ><font size="9"><b>X</b></font></td>
        <%
                        }
                }else if(d==2){
                    if(!cadenaMar.equals("")){
                        if(arrayMar.length>=cont){
        %>
                            <td height='100' width='140' align='center' <%=border%> ><%=arrayMar[i]%></td>
        <%
                        }else{
        %>
                            <td height='100' width='140' align='center' <%=border%> ><font size="9"><b>X</b></font></td>
        <%
                        }
                    }else{
        %>
                                <td height='100' width='140' align='center' <%=border%> ><font size="9"><b>X</b></font></td>
        <%
                        }
                }else if(d==3){
                    if(!cadenaMier.equals("")){
                        if(arrayMier.length>=cont){
        %>
                            <td height='100' width='140' align='center' <%=border%> ><%=arrayMier[i]%></td>
        <%
                        }else{
        %>
                            <td height='100' width='140' align='center' <%=border%> ><font size="9"><b>X</b></font></td>
        <%
                        }
                    }else{
        %>
                                <td height='100' width='140' align='center' <%=border%> ><font size="9"><b>X</b></font></td>
        <%
                        }
                }else if(d==4){
                    if(!cadenaJue.equals("")){
                        if(arrayJue.length>=cont){
        %>
                            <td height='100' width='140' align='center' <%=border%> ><%=arrayJue[i]%></td>
        <%
                        }else{
        %>
                            <td height='100' width='140' align='center' <%=border%> ><font size="9"><b>X</b></font></td>
        <%
                        } 
                    }else{
        %>
                                <td height='100' width='140' align='center' <%=border%> ><font size="9"><b>X</b></font></td>
        <%
                        }
                }else if(d==5){
                    if(!cadenaVier.equals("")){
                        if(arrayVier.length>=cont){
        %>
                            <td height='100' width='140' align='center' <%=border%> ><%=arrayVier[i]%></td>
        <%
                        }else{
        %>
                            <td height='100' width='140' align='center' <%=border%> ><font size="9"><b>X</b></font></td>
        <%
                        } 
                    }else{
        %>
                                <td height='100' width='140' align='center' <%=border%> ><font size="9"><b>X</b></font></td>
        <%
                        }
                }else if(d==6){
                    //if(!cadenaLun.equals("")){
                    if(!cadenaSab.equals("")){
                        if(arraySab.length>=cont){
        %>
                            <td height='100' width='140' align='center' <%=border%> ><%=arraySab[i]%></td>
        <%
                        }else{
        %>
                            <td height='100' width='140' align='center' <%=border%> ><font size="9"><b>X</b></font></td>
        <%
                        }
                    }else{
        %>
                        <td height='100' width='140' align='center' <%=border%> ><font size="9"><b>X</b></font></td>
        <%
                    }  
                }
            }
            cont++;
        %>
            </tr>
        <%
        }
        %>
           </table>
        
        
        
        
    </body>
</html>