PARTE II
Código PHP:
String.prototype.trim = function() { return this.replace(/^s+|s+$/g, ""); };
function crearFilas() {
var reporte = document.getElementById("reporte");
reporte.innerHTML = "";
var grups = document.getElementById("grupos").value;
str = grups.trim();
var grups = parseInt(str);
var cols = document.getElementById("cols").value;
str = cols.trim();
var cols = parseInt(str);
if (cols > 1)
largo = ((152*cols+1)+(4*cols));
else
largo = 152*cols+1;
tbl = document.createElement("table");
tbl.setAttribute("cellspacing", "0");
tbl.setAttribute("cellpadding", "0");
tbl.setAttribute("border", "1");
tbl.setAttribute("background-color", "white");
i = 0;
k = 1;
//TITULOS
totlar = ((largo*grups)+(1*cols))+152;
colsxlin = (cols*grups)+1;
for (i=0;i<2;i++) {
tr = document.createElement("tr");
idtit="tit"+i;
nuevoTDt = document.createElement("td");
nuevoTDt.setAttribute("colspan", colsxlin);
nuevoTDt.setAttribute("align", "center");
input = document.createElement("input");
input.setAttribute("type", "text");
input.setAttribute("id", idtit);
input.setAttribute("name", idtit);
if (i==0)
input.setAttribute("value", "Titulo Reporte");
else
input.setAttribute("value", "Subtitulo Reporte");
input.setAttribute("class", "claseinput");
estilo = "text-align:center; color:blue; width:"+totlar+"px";
input.setAttribute("style", estilo);
nuevoTDt.appendChild(input);
tr.appendChild(nuevoTDt);
tbl.appendChild(tr);
}
tr = document.createElement("tr");
//GRUPOS
nuevoTDz = document.createElement("td");
nuevoTDz.setAttribute("class", "clasetd");
tr.appendChild(nuevoTDz);
for (i=0;i<grups;i++) {
idnameg="grp"+k+"_0";
nuevoTDg = document.createElement("td");
nuevoTDg.setAttribute("colspan", cols);
nuevoTDg.setAttribute("align", "center");
input = document.createElement("input");
input.setAttribute("type", "text");
input.setAttribute("id", idnameg);
input.setAttribute("name", idnameg);
input.setAttribute("value", "Titulo Grupo "+k);
input.setAttribute("class", "claseinput");
estilo = "text-align:center; color:blue; width:"+largo+"px";
input.setAttribute("style", estilo);
input.setAttribute("onChange", "verificaInput('"+idnameg+"');");
nuevoTDg.appendChild(input);
tr.appendChild(nuevoTDg);
tbl.appendChild(tr);
k++;
}
//COLUMNAS
tr = document.createElement("tr");
idtit="c0_0";
nuevoTDx = document.createElement("td");
nuevoTDx.setAttribute("colspan", "1");
nuevoTDx.setAttribute("align", "center");
input = document.createElement("input");
input.setAttribute("type", "text");
input.setAttribute("id", idtit);
input.setAttribute("name", idtit);
input.setAttribute("value", "Id");
estilo = "text-align:center; color:red; width:152px";
input.setAttribute("style", estilo);
input.setAttribute("class", "claseinput");
input.setAttribute("onChange", "verificaInput('"+idtit+"');");
nuevoTDx.appendChild(input);
tr.appendChild(nuevoTDx);
k = 1;
g = 1;
col_orig = cols;
cols = grups*cols;
for (j=0;j<cols;j++) {
idnamec = "c"+k+"_"+g;
nuevoTDt = document.createElement("td");
nuevoTDt.setAttribute("colspan", "1");
input = document.createElement("input");
input.setAttribute("type", "text");
input.setAttribute("id", idnamec);
input.setAttribute("name", idnamec);
input.setAttribute("value", "Titulo Columna "+k);
input.setAttribute("class", "claseinput");
estilo = "text-align:center; color:red; width:152px;";
input.setAttribute("style", estilo);
input.setAttribute("onChange", "verificaInput('"+idnamec+"');");
nuevoTDt.appendChild(input);
tr.appendChild(nuevoTDt);
k = k+1;
if (k>col_orig) {
g = g+1;
k=1;
}
}
tbl.appendChild(tr);
//SELECTS
tr = document.createElement("tr");
k = 1;
g = 1;
for (j=0;j<cols;j++) {
idnames = "s"+k+"_"+g;
if (j == 0) {
nuevoTDs = document.createElement("td");
nuevoTDs.setAttribute("colspan", "1");
nuevoSelect = document.createElement("select");
nuevoSelect.setAttribute("id", "s0_0");
nuevoSelect.setAttribute("name", "s0_0");
//nuevoSelect.setAttribute("style", "width:152px; background-color:#B0E0E6;");
nuevoSelect.setAttribute("style", "width:152px; background-color:transparent; font-size=12px; border:solid #B0E0E6;");
nuevoSelect.setAttribute("onChange", "muestra_textArea(0,0);");
opt = document.createElement("Option");
opt.setAttribute("value", "I");
opt.innerHTML="Seleccione Filtro";
opt.setAttribute("selected","0");
opt.setAttribute("style", "background-color:#00FFFF;");
nuevoSelect.appendChild(opt);
opt = document.createElement("Option");
opt.setAttribute("style", "background-color:#00FFFF;");
opt.setAttribute("value", "Q");
opt.innerHTML="Query";
nuevoSelect.appendChild(opt);
nuevoTDs.appendChild(nuevoSelect);
tr.appendChild(nuevoTDs);
}
nuevoTDs = document.createElement("td");
nuevoTDs.setAttribute("colspan", "1");
nuevoSelect = document.createElement("select");
nuevoSelect.setAttribute("id", idnames);
nuevoSelect.setAttribute("name", idnames);
//nuevoSelect.setAttribute("style", "width:152px; background-color:#B0E0E6;");
nuevoSelect.setAttribute("style", "width:152px; background-color:transparent; font-size=12px; border:solid #B0E0E6;");
nuevoSelect.setAttribute("onChange", "muestra_textArea("+k+", "+g+");");
opt = document.createElement("Option");
opt.setAttribute("value", "0");
opt.innerHTML="Seleccione Filtro";
opt.setAttribute("selected","0");
opt.setAttribute("style", "background-color:#00FFFF;");
nuevoSelect.appendChild(opt);
opt = document.createElement("Option");
opt.setAttribute("style", "background-color:#00FFFF;");
opt.setAttribute("value", "Q");
opt.innerHTML="Query";
nuevoSelect.appendChild(opt);
opt = document.createElement("Option");
opt.setAttribute("style", "background-color:#00FFFF;");
opt.setAttribute("value", "F");
opt.innerHTML="Formula";
nuevoSelect.appendChild(opt);
opt = document.createElement("Option");
opt.setAttribute("style", "background-color:#00FFFF;");
opt.setAttribute("value", "C");
opt.innerHTML="Copiar Desde Columna";
nuevoSelect.appendChild(opt);
nuevoTDs.appendChild(nuevoSelect);
tr.appendChild(nuevoTDs);
k=k+1;
if (k>col_orig) {
g = g+1;
k=1;
}
}
tbl.appendChild(tr);
//TEXTAREA
tr = document.createElement("tr");
k = 1;
g = 1;
cols = cols+1;
for (j=0;j<cols;j++) {
if (j==0) {
idnamet = "t0_0";
k = 0;
}
else
idnamet = "t"+k+"_"+g;
nuevoTDa = document.createElement("td");
nuevoTDa.setAttribute("colspan", "1");
textarea = document.createElement("textarea");
textarea.setAttribute("id", idnamet);
textarea.setAttribute("name", idnamet);
textarea.setAttribute("rows", "30");
textarea.setAttribute("cols", "87");
textarea.setAttribute("onChange", "verificaInput('"+idnamet+"');");
fun = "oculta_textArea('"+idnamet+"');";
textarea.setAttribute("style", "display : none");
textarea.setAttribute("onBlur", fun);
nuevoTDa.appendChild(textarea);
tr.appendChild(nuevoTDa);
k = k+1;
if (k>col_orig) {
g = g+1;
k=1;
}
}
tbl.appendChild(tr);
// BOTONES
tr = document.createElement("tr");
nuevoTDb = document.createElement("td");
nuevoTDb.setAttribute("align", "center");
nuevoTDb.setAttribute("colspan", largo);
nuevoBoton = document.createElement("input");
nuevoBoton.setAttribute("type", "button");
nuevoBoton.setAttribute("id", "graba");
nuevoBoton.setAttribute("accion", "graba");
nuevoBoton.setAttribute("value", "Grabar");
nuevoBoton.setAttribute("onClick", "fDatos('reporte','grabar');");
nuevoBoton.setAttribute("style", "background-color:#738EB5; height:18px; font-size:8pt; font-weight:bold; color:#FFFFFF; border-style:solid; border-width:1px;");
nuevoTDb.appendChild(nuevoBoton);
tr.appendChild(nuevoTDb);
tbl.appendChild(tr);
reporte.appendChild(tbl);
/*
var ss = document.getElementById('reporte').innerHTML;
ss = ss.replace(/>/g, ">");
ss = ss.replace(/</g, "<");
document.write(ss);
*/
ds = document.getElementById("reporte");
ds.style.display = "block";
reporte.style.display = "block";
}
function verificaInput(par) {
//alert(document.getElementById(par).offsetWidth);
//alert(document.getElementById(par).value);
}