<?php
require_once("../includes/bootstrap.php");
$sesion = new sesion();
$academia = bootstrap::initBd($sesion->get('anio'));
$tipo_usuario = $sesion->getVar('ac_tipo_user');
$numdocus = $sesion->getVar('ac_identidad');
$nomgrupo = $sesion->getVar('configuracion.nombres_grupos');
if (!headers_sent())
    ob_start("ob_gzhandler");
$sesion->set('permiso', permisos($_POST['privilegio']));
$permisos = str_split($sesion->get('permiso'));
cache();
if (!in_array("P", $permisos) || !in_array("M", $permisos) || !in_array("S", $permisos)) {
    echo '<div class="alert alert-block">
            <h4>Ups!!</h4>
            Usted no tiene permiso para acceder a este modulo...
    </div>';
    exit();
}

?>
<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <!-- CSS to style the file input field as button and adjust the Bootstrap progress bars -->
        <link rel="stylesheet" href="css/file_upload_ui/jquery.fileupload-ui.css">
        <!-- CSS adjustments for browsers with JavaScript disabled -->
        <noscript><link rel="stylesheet" href="css/file_upload_ui/jquery.fileupload-ui-noscript.css"></noscript>
        <!-- The jQuery UI widget factory, can be omitted if jQuery UI is already included -->
        <script type="text/javascript">
            $(function() {
                $("#help").window({
                    modal: true,
                    tittle: 'Ayuda',
                    minimizable: false,
                    maximizable: false,
                    collapsible: false,
                    closed: true,
                    modal:true,
                            resizable: false
                });
                $("#btnhelp").on("click", function() {
                    $("#help").window('open');
                });
                $(document).ready(function(e) {
                    $('div').delegate('.load-datas', 'click', function(e) {
                        e.preventDefault();
                        var cod = $(this).attr('data-cod');
                        var fil = $(this).attr('data-fil');
                        var dtslan_modulo = 'mod_imp_exp_xlsx';
                        jConfirm(dtsLang.mod_imp_exp_xlsx.msg_confirm_load, dtsLang.project.empresa, function(r) {
                            if (!r)
                                return false;
                            $.ajax({
                                url: 'mod_imp_planilla_docxmat/load_dts_xlsx.php',
                                data: {codigo: cod},
                                dataType: "json",
                                beforeSend: function() {
                                    jProgresbar('Guardando información en el sistema', dtsLang.globals.tit_msg_espere);
                                },
                                success: function(rta) {
                                    if (rta.error == 0) {
                                        jPbarClose();
                                        $("tr#fil" + fil).remove();
                                        notifica_ok("Se cargaron correctamente las notas del archivo al sistema", 4000)
                                    } else {
                                        if (dtsLang[dtslan_modulo][rta.error]) {
                                            jAlert(dtsLang[dtslan_modulo][rta.error], dtsLang.project.empresa, 'error');
                                            return false;
                                        } else {
                                            jAlert('Error desconocido', dtsLang.project.empresa, 'error');
                                            return false;
                                        }
                                    }
                                }
                            });

                        });
                        return false;
                    });
                });
            });
        </script>
        <script src="js/file_upload_ui/tmpl.min.js"></script>
        <!-- The Iframe Transport is required for browsers without support for XHR file uploads -->
        <script src="js/file_upload_ui/jquery.iframe-transport.js" type="text/javascript"></script>
        <!-- The basic File Upload plugin -->
        <script src="js/file_upload_ui/jquery.fileupload.js" type="text/javascript"></script>
        <!-- The File Upload processing plugin -->
        <script src="js/file_upload_ui/jquery.fileupload-process.js" type="text/javascript"></script>
        <!-- The File Upload validation plugin -->
        <script src="js/file_upload_ui/jquery.fileupload-validate.js" type="text/javascript"></script>
        <!-- The File Upload user interface plugin -->
        <script src="js/file_upload_ui/jquery.fileupload-ui.js" type="text/javascript"></script>
        <!-- The main application script -->
        <script src="mod_imp_planilla_docxmat/js/main.js" type="text/javascript"></script>

        <!-- The template to display files available for upload -->

        <script id="template-upload" type="text/x-tmpl">
            {% for (var i=0, file; file=o.files[i]; i++) { %}
            {%=file%}
            <tr class="template-upload fade">
            <td>
            <span><img src="css/icons/excel_grande.png"></span>
            </td>
            <td>
            <p class="name">{%=file.name%}</p>
            {% if (file.error) { %}
            <div><span class="label label-important">Error</span> {%=file.error%}</div>
            {% } %}
            </td>
            <td>
            <p class="size">{%=o.formatFileSize(file.size)%}</p>
            </td>
            <td>
            {% if (!o.files.error && !i && !o.options.autoUpload) { %}
            <button class="btn btn-primary start" >
            <i class="icon-upload icon-white"></i>
            <span>Iniciar</span>
            </button>
            {% } %}
            {% if (!i) { %}
            <button class="btn btn-warning cancel">
            <i class="ui-btn-cancel icon-white"></i>
            <span>Cancelar</span>
            </button>
            {% } %}
            </td>
            </tr>
            {% } %}
        </script>
        <!-- The template to display files available for download -->
        <script id="template-download" type="text/x-tmpl">
            {% var xyz=0; %}
            {% for (var i=0, file, xyz=0; file=o.files[i]; i++) { xyz++; %}
            <tr class="template-download fade" id="fil{%=xyz%}">
            <td>
            <span class="preview">
            {% if (!file.error && file.info.valid) { %}
            <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}"><img src="css/icons/excel_grande.png"></a>
            {% }else{ %}
            <img src="css/icons/excel_grande.png">
            {% } %}
            </span>
            </td>
            <td>
            {% if (file.info && file.info.valid){ %}
            <p class="name">
            <strong>Sede: </strong>{%=file.info.nomSede%} 
            <strong>Jornada: </strong>{%=file.info.nomJorn%}<br>
            <strong>Grupo: </strong>{%=file.info.nomGrup%} 
            <strong> Materia: </strong>{%=file.info.nomMate%}
            <strong> Periodo: </strong>{%=file.info.periodo%}<br>
            <strong> Docente: </strong>{%=file.info.doc%}<br>
            <strong> N° Estudiantes: </strong>{%=file.info.numEst%}
            <strong> N° Notas por estudiante: </strong>{%=file.info.numNot%}
            </p>
            {% }else{ %}
            <p class="">El documento no es un archivo de notas válido</p>
            {% } %}

            {% if (file.error) { %}
            <div><span class="label label-important">Error</span> {%=file.error%}</div>
            {% } %}
            </td>
            <td>
            <span class="size">{%=o.formatFileSize(file.size)%}</span>
            </td>
            <td>
            {% if (!file.error && file.info.valid) { %}
            <div class="btn btn-info load-datas" data-cod="{%=file.codigo%}" data-fil="{%=xyz%}">
            <i class="ui-btn-load-dts icon-white"></i>
            <span>Cargar datos</span>
            </div>
            <input type="checkbox" name="delete" value="1" class="toggle">
            {% } %}
            <button class="btn btn-danger delete" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}"{% if (file.delete_with_credentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>
            <i class="ui-btn-del icon-white"></i>
            <span>Eliminar</span>
            </button>
            </td> 
            </tr> 
            {% } %}
        </script>
    </head>
    <body>
        <div id="help" title="Ayuda">
            <ul type="circle">
                <li>Seleccione las planillas de notas en excel para cargar</li>
                <li>Suba los archivos haciendo click en el boton <strong>"Iniciar subida"</strong></li>
                <li>Una vez subido los archivos se le mostrará el listado de los mismos y sus características</li>
                <li>Para guardar en la Base de Datos las notas de las planillas haga click en el boton <strong>"Cargar datos"</strong></li>
            </ul>
        </div>
        <form id="fileupload" action="" method="POST" enctype="multipart/form-data">
            <!-- Redirect browsers with JavaScript disabled to the origin page -->
            <noscript><input type="hidden" name="redirect" value=""></noscript>
            <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
            <div class="row fileupload-buttonbar" style="text-align:center">
                <span class="btn btn-success fileinput-button">
                    <i class="ui-btn-new  icon-white"></i>
                    <span>Seleccionar archivos...</span>
                    <input name="files[]" multiple type="file">
                </span>

                <button type="submit" class="btn btn-primary start">
                    <i class="icon-upload icon-white"></i>
                    <span>Iniciar subida</span>
                </button>
                <button type="reset" class="btn btn-warning cancel">
                    <i class="ui-btn-cancel icon-white"></i>
                    <span>Cancelar carga</span>
                </button>
                <button type="button" class="btn btn-danger delete">
                    <i class="ui-btn-del icon-white"></i>
                    <span>Eliminar</span>
                </button>

                <input type="checkbox" class="toggle">
                <button type="button" id="btnhelp" class="btn btn-success">
                    <i class="ui-icon-help icon-white"></i>
                    <span></span>
                </button>
                <!-- The loading indicator is shown during file processing -->
                <span class="fileupload-loading"></span>
            </div>
            <!-- The global progress information -->
            <div class="span5 fileupload-progress fade">
                <!-- The extended global progress information -->
                <div class="progress-extended">&nbsp;</div>
            </div>
            <!-- The table listing the files available for upload/download -->
            <table role="presentation" class="table table-striped">
                <tbody class="files" data-toggle="modal-gallery" data-target="#modal-gallery"></tbody>
            </table>
        </form>
    </body>
</html>