Advertisement
Guest User

schedule

a guest
Apr 17th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Horario Profesor
  2. $(document).ready(function (){
  3.    
  4.    
  5.     var idenprof = metodosprof.setidprof();
  6.    
  7.     var iden = {
  8.         identificacion: idenprof  
  9.     };
  10.    
  11.     $.ajax({
  12.             type: 'GET',
  13.             url:  '/upcphp/horarioprof.php',
  14.             data: iden
  15.             //async: false
  16.  
  17.             }).done(function(msg) {
  18.                
  19.                 var str = $.trim(msg);
  20.                
  21.                     if(str !== "0"){
  22.                        
  23.                         console.log(str);
  24.                        
  25.                         var vector = (JSON.parse(str));
  26.                         var len = (vector.length);
  27.                         console.log(len);
  28.                        
  29.                        
  30.                           function ArregloHorario(arreglo, tamano){
  31.  
  32.                             var asignaturas = [];
  33.  
  34.                             for(var i = 0; i < tamano; i++){
  35.  
  36.                                 var asignatura = new Object();
  37.  
  38.                                 var asignatura = {
  39.                                     codigo: arreglo[i].CodiAsig,
  40.                                     grupo: arreglo[i].Grupo,
  41.                                     nombre: arreglo[i].NombAsig,
  42.                                     creditos: arreglo[i].Creditos,
  43.                                     dia: arreglo[i].DiaAsig,
  44.                                     hora: arreglo[i].HoraAsig,
  45.                                     lugar: arreglo[i].LugarAsig
  46.                                 };
  47.  
  48.                                 asignaturas.push(asignatura);
  49.  
  50.                             }
  51.  
  52.                             return asignaturas;
  53.  
  54.                         }
  55.  
  56.                         var Arregloh = ArregloHorario(vector, len);
  57.  
  58.                         //console.log(Arregloh);
  59.                        
  60.                         var base = metodos.getBD();
  61.                        
  62.                        
  63.                       //Crear tabla horario profesor  
  64.                       function CreateTableHoraProf(database){
  65.  
  66.                           database.transaction(function (tx){
  67.  
  68.                               var sql = 'CREATE TABLE IF NOT EXISTS HorarioP(codigo text primary key, grupo integer,\n\
  69.                                          nombre text, creditos integer, dia text, hora text, lugar text)';
  70.  
  71.                               tx.executeSql(sql);
  72.  
  73.                           });    
  74.  
  75.                        }
  76.  
  77.                        CreateTableHoraProf(base);
  78.                        
  79.                        
  80.                       /*Insertar Datos Horario Profesor con validacion*/
  81.                       function InsertDatosHoraProf(database, arreglo){
  82.  
  83.                            var prof = arreglo;
  84.                            var largo = prof.length;
  85.                            //console.log(largo);
  86.  
  87.                            database.transaction(function (tx) {
  88.  
  89.                                var consulta = 'SELECT * FROM HorarioP';
  90.  
  91.                                    tx.executeSql(consulta, [], function (tx, results){                                          
  92.  
  93.                                        var mostrar = results.rows.length;                
  94.                                        var sql = 'INSERT INTO HorarioP(codigo, grupo, nombre, creditos, dia, hora, lugar)\n\
  95.                                               VALUES(?,?,?,?,?,?,?)';
  96.                                        var sqldelete = 'DELETE FROM HorarioP';
  97.  
  98.                                        if (mostrar === 0){
  99.  
  100.                                            for(var i = 0; i < largo; i++){
  101.                                                 tx.executeSql(sql, [prof[i].codigo, prof[i].grupo, prof[i].nombre, prof[i].creditos,
  102.                                                                     prof[i].dia, prof[i].hora, prof[i].lugar]);
  103.                                            }
  104.  
  105.                                        }else{
  106.  
  107.                                            tx.executeSql(sqldelete);
  108.  
  109.                                            for(var i = 0; i < largo; i++){
  110.                                                 tx.executeSql(sql, [prof[i].codigo, prof[i].grupo, prof[i].nombre, prof[i].creditos,
  111.                                                                     prof[i].dia, prof[i].hora, prof[i].lugar]);
  112.                                            }
  113.  
  114.                                        }
  115.  
  116.                                    });
  117.                             });
  118.  
  119.                        }
  120.  
  121.                       InsertDatosHoraProf(base, Arregloh);
  122.                      
  123.                      
  124.                       //Consulta de datos horario y envio
  125.                       function ConsultaHoraProf(database){
  126.  
  127.                            database.transaction(function (tx) {
  128.  
  129.                                var sql = 'SELECT * FROM HorarioP';
  130.                                   tx.executeSql(sql,[],function (tx,results){
  131.  
  132.                                       var len = results.rows.length, i;
  133.                                       var asignaturas = [];
  134.  
  135.                                       for(i = 0; i < len; i++){
  136.                                           var row = results.rows.item(i);
  137.  
  138.                                           var asignatura = new Object();
  139.  
  140.                                             var asignatura = {
  141.                                                 codigo: row.codigo,
  142.                                                 grupo: row.grupo,
  143.                                                 nombre: row.nombre,
  144.                                                 creditos: row.creditos,
  145.                                                 dia: row.dia,
  146.                                                 hora: row.hora,
  147.                                                 lugar: row.lugar
  148.                                             };
  149.  
  150.                                             asignaturas.push(asignatura);
  151.  
  152.  
  153.                                       }
  154.                                       //console.log(asignaturas);
  155.                                       metodosprof.gethorarioprof(asignaturas);
  156.                                  });
  157.                            });
  158.  
  159.                       }
  160.  
  161.                       ConsultaHoraProf(base);
  162.                        
  163.                     }
  164.                
  165.             });
  166.    
  167. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement