Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Horario Profesor
- $(document).ready(function (){
- var idenprof = metodosprof.setidprof();
- var iden = {
- identificacion: idenprof
- };
- $.ajax({
- type: 'GET',
- url: '/upcphp/horarioprof.php',
- data: iden
- //async: false
- }).done(function(msg) {
- var str = $.trim(msg);
- if(str !== "0"){
- console.log(str);
- var vector = (JSON.parse(str));
- var len = (vector.length);
- console.log(len);
- function ArregloHorario(arreglo, tamano){
- var asignaturas = [];
- for(var i = 0; i < tamano; i++){
- var asignatura = new Object();
- var asignatura = {
- codigo: arreglo[i].CodiAsig,
- grupo: arreglo[i].Grupo,
- nombre: arreglo[i].NombAsig,
- creditos: arreglo[i].Creditos,
- dia: arreglo[i].DiaAsig,
- hora: arreglo[i].HoraAsig,
- lugar: arreglo[i].LugarAsig
- };
- asignaturas.push(asignatura);
- }
- return asignaturas;
- }
- var Arregloh = ArregloHorario(vector, len);
- //console.log(Arregloh);
- var base = metodos.getBD();
- //Crear tabla horario profesor
- function CreateTableHoraProf(database){
- database.transaction(function (tx){
- var sql = 'CREATE TABLE IF NOT EXISTS HorarioP(codigo text primary key, grupo integer,\n\
- nombre text, creditos integer, dia text, hora text, lugar text)';
- tx.executeSql(sql);
- });
- }
- CreateTableHoraProf(base);
- /*Insertar Datos Horario Profesor con validacion*/
- function InsertDatosHoraProf(database, arreglo){
- var prof = arreglo;
- var largo = prof.length;
- //console.log(largo);
- database.transaction(function (tx) {
- var consulta = 'SELECT * FROM HorarioP';
- tx.executeSql(consulta, [], function (tx, results){
- var mostrar = results.rows.length;
- var sql = 'INSERT INTO HorarioP(codigo, grupo, nombre, creditos, dia, hora, lugar)\n\
- VALUES(?,?,?,?,?,?,?)';
- var sqldelete = 'DELETE FROM HorarioP';
- if (mostrar === 0){
- for(var i = 0; i < largo; i++){
- tx.executeSql(sql, [prof[i].codigo, prof[i].grupo, prof[i].nombre, prof[i].creditos,
- prof[i].dia, prof[i].hora, prof[i].lugar]);
- }
- }else{
- tx.executeSql(sqldelete);
- for(var i = 0; i < largo; i++){
- tx.executeSql(sql, [prof[i].codigo, prof[i].grupo, prof[i].nombre, prof[i].creditos,
- prof[i].dia, prof[i].hora, prof[i].lugar]);
- }
- }
- });
- });
- }
- InsertDatosHoraProf(base, Arregloh);
- //Consulta de datos horario y envio
- function ConsultaHoraProf(database){
- database.transaction(function (tx) {
- var sql = 'SELECT * FROM HorarioP';
- tx.executeSql(sql,[],function (tx,results){
- var len = results.rows.length, i;
- var asignaturas = [];
- for(i = 0; i < len; i++){
- var row = results.rows.item(i);
- var asignatura = new Object();
- var asignatura = {
- codigo: row.codigo,
- grupo: row.grupo,
- nombre: row.nombre,
- creditos: row.creditos,
- dia: row.dia,
- hora: row.hora,
- lugar: row.lugar
- };
- asignaturas.push(asignatura);
- }
- //console.log(asignaturas);
- metodosprof.gethorarioprof(asignaturas);
- });
- });
- }
- ConsultaHoraProf(base);
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement