var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } //function to get programs from the db function get_progs(prog, selectsize, mode) { xmlhttp.open("GET","get_progs.php?fProgram="+prog+"&fSelectSize="+selectsize+"&fMode="+mode,false); xmlhttp.send(); if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById('progfield').innerHTML = xmlhttp.responseText; document.getElementById('keyfield').innerHTML = ""; if (document.getElementById('valuefield1')) document.getElementById('valuefield1').innerHTML = ""; } else document.getElementById('progfield').innerHTML = "argh"; } //function to get keys from the db function get_keys(prog, key, selectsize, mode) { xmlhttp.open("GET","get_keys.php?fProgram="+prog+"&fKey="+key+"&fSelectSize="+selectsize+"&fMode="+mode,false); xmlhttp.send(); if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById('keyfield').innerHTML = xmlhttp.responseText; if (document.getElementById('valuefield1')) document.getElementById('valuefield1').innerHTML = ""; } else document.getElementById('keyfield').innerHTML = "argh"; if(document.getElementById('addrowprog')) document.getElementById('addrowprog').style.display = ""; } function get_statusdate(getvalcase, val) { if (!val) { radio=document.getElementsByName('dateformat'+getvalcase); for (i=0; i< radio.length; i++) if (radio[i].checked) val=radio[i].value; } if (val=="pulldown") { year=document.getElementById('year'+getvalcase).value; month=document.getElementById('month'+getvalcase).value; day=document.getElementById('day'+getvalcase).value; hour=document.getElementById('hour'+getvalcase).value; min=document.getElementById('min'+getvalcase).value; sec=document.getElementById('sec'+getvalcase).value; if (year=="empty") statusdate=""; else { statusdate=year; if (month!="empty") { statusdate=statusdate+"-"+month; if (day!="empty") { statusdate=statusdate+"-"+day; if (hour!="empty") { statusdate=statusdate+" "+hour; if (min!="empty") { statusdate=statusdate+":"+min; if (sec!="empty") statusdate=statusdate+":"+sec; } } } } } } if (val=="textinput") statusdate=document.getElementById('statusdate'+getvalcase).value; return statusdate; } //function to get values from the db function get_values(getvalcase, prog, key, mode) { if (parseInt(getvalcase)>1) { //get prog and key progselect=document.getElementById("prog"); if (!progselect) prog="all"; else if (progselect.options[progselect.selectedIndex]) prog=progselect.options[progselect.selectedIndex].value; else prog="all"; keyselect=document.getElementById("key"); if (!keyselect) key="all"; else if (keyselect.options[keyselect.selectedIndex]) key=keyselect.options[keyselect.selectedIndex].value; else key="all"; } if (mode=="view" && getvalcase==1) return; //if (getvalcase==3) // document.getElementById('comparevals').style.display = ""; if ((getvalcase==2 || getvalcase==3) && document.getElementById('statusdate'+getvalcase)) { statusdate=get_statusdate(getvalcase); //alert(statusdate); phpcall="get_values.php?fStatusDate="+statusdate+"&fGetValCase="+getvalcase+"&fKey="+key+"&fProgram="+prog; } else phpcall="get_values.php?fGetValCase="+getvalcase+"&fKey="+key+"&fProgram="+prog; xmlhttp.open("GET",phpcall,false); xmlhttp.send(); if (xmlhttp.readyState==4 && xmlhttp.status==200) document.getElementById('valuefield'+getvalcase).innerHTML = xmlhttp.responseText; else document.getElementById('valuefield'+getvalcase).innerHTML = "argh"; if(document.getElementById('addrowkey')) document.getElementById('addrowkey').style.display = ""; } function addRow(addcase, prog, key, key1, key2, type) { if (!prog) { progselect=document.getElementById("prog"); if (progselect.options[progselect.selectedIndex]) prog=progselect.options[progselect.selectedIndex].value; else prog='all'; } if (!key) { keyselect=document.getElementById("key"); if (!keyselect) key='all'; else if (keyselect.options[keyselect.selectedIndex]) key=keyselect.options[keyselect.selectedIndex].value; else key='all'; } switch(addcase) { case 1: get_keys(prog,key,"10", "edit"); case 2: get_values(1, prog, key); } if (prog=='all' && (addcase==3 || addcase==2)) addcase=1; if (key=='all' && addcase==3) addcase=2; for (var i = 1 ; i <= document.getElementById('maxindex').innerHTML ; i++) if(document.getElementById('action'+i)) //document.getElementById('action'+i).innerHTML = ""; document.getElementById('action'+i).style.display = "none"; tabBody=document.getElementById("valtable1"); row=document.createElement("TR"); row.id='val0'; cell0 = document.createElement("TD"); cell1 = document.createElement("TD"); cell2 = document.createElement("TD"); cell3 = document.createElement("TD"); cell4 = document.createElement("TD"); cell5 = document.createElement("TD"); cell6 = document.createElement("TD"); cell7 = document.createElement("TD"); cell8 = document.createElement("TD"); cell9 = document.createElement("TD"); cell10 = document.createElement("TD"); var updcase; // addcase: three cases // 1: add new prog+key, val=NULL // 2: add new key, val=NULL, prog=selected // 3: add new val, prog=selected, key=selected, type fixed switch(addcase) { case 1: //field for prog input1 = document.createElement("INPUT"); input1.id = 'prog0'; cell1.appendChild(input1); //fields for keys input2 = document.createElement("INPUT"); input2.id = '1key0'; cell2.appendChild(input2); input10 = document.createElement("INPUT"); input10.id = '2key0'; cell10.appendChild(input10); //field for val cell3.id = 'newval0'; textnode3=document.createTextNode("NULL"); cell3.appendChild(textnode3); updcase=5; //field type select7 = document.createElement("select"); select7.id = 'newtype0'; select7.option = 'string'; option7a = document.createElement("option"); option7a.text = '-'; option7a.value = ''; select7.appendChild(option7a); option7b = document.createElement("option"); option7b.id = 'int'; option7b.text = 'int'; option7b.value = 'int'; select7.appendChild(option7b); option7c = document.createElement("option"); option7c.id = 'float'; option7c.text = 'float'; option7c.value = 'float'; select7.appendChild(option7c); option7d = document.createElement("option"); option7d.id = 'string'; option7d.text = 'string'; option7d.value = 'string'; select7.appendChild(option7d); option7e = document.createElement("option"); option7e.id = 'bool'; option7e.text = 'bool'; option7e.value = 'bool'; select7.appendChild(option7e); cell7.appendChild(select7); break; case 2: //field for prog cell1.id = 'prog0'; textnode1=document.createTextNode(prog); cell1.appendChild(textnode1); //field for key input2 = document.createElement("INPUT"); input2.id = '1key0'; cell2.appendChild(input2); input10 = document.createElement("INPUT"); input10.id = '2key0'; cell10.appendChild(input10); //field for val cell3.id = 'newval0'; textnode3=document.createTextNode("NULL"); cell3.appendChild(textnode3); updcase=1; //field type select7 = document.createElement("select"); select7.id = 'newtype0'; select7.option = 'string'; option7a = document.createElement("option"); option7a.text = '-'; option7a.value = ''; select7.appendChild(option7a); option7b = document.createElement("option"); option7b.id = 'int'; option7b.text = 'int'; option7b.value = 'int'; select7.appendChild(option7b); option7c = document.createElement("option"); option7c.id = 'float'; option7c.text = 'float'; option7c.value = 'float'; select7.appendChild(option7c); option7d = document.createElement("option"); option7d.id = 'string'; option7d.text = 'string'; option7d.value = 'string'; select7.appendChild(option7d); option7e = document.createElement("option"); option7e.id = 'bool'; option7e.text = 'bool'; option7e.value = 'bool'; select7.appendChild(option7e); cell7.appendChild(select7); break; case 3: //field for prog cell1.id = 'prog0'; textnode1=document.createTextNode(prog); cell1.appendChild(textnode1); //field for key cell2.id = '1key0'; textnode2=document.createTextNode(key1); cell2.appendChild(textnode2); cell10.id = '2key0'; textnode10=document.createTextNode(key2); cell10.appendChild(textnode10); //field for val input3 = document.createElement("INPUT"); input3.id = 'newval0'; cell3.appendChild(input3); updcase=2; //field type cell7.id = 'type0'; textnode7 = document.createTextNode(type); cell7.appendChild(textnode7); break; default: break; } //field descr input4 = document.createElement("INPUT"); input4.id = 'newdescr0'; cell4.appendChild(input4); //field action input5a = document.createElement("input"); input5a.value = 'Add'; input5a.type = "button"; input5a.onclick = function () { UpdateRow(updcase, 0); onclick() } cell5.appendChild(input5a); input5b = document.createElement("input"); input5b.value = 'Cancel'; input5b.type = "button"; input5b.onclick = function () { CancelAddRow(prog, key); onclick() } cell5.appendChild(input5b); row.appendChild(cell0);//index, counter row.appendChild(cell6);//valid from row.appendChild(cell1);//prog row.appendChild(cell2);//key1 row.appendChild(cell10);//key2 row.appendChild(cell3);//value row.appendChild(cell7);//type row.appendChild(cell4);//descr row.appendChild(cell5);//action row.appendChild(cell8);//min row.appendChild(cell9);//max tabBody.appendChild(row); // to be removed later when solution for adding multiple new rows is found document.getElementById('addrowvals').style.display = "none"; document.getElementById('addrowvals2').style.display = "none"; document.getElementById('addrowkey').style.display = "none"; document.getElementById('addrowprog').style.display = "none"; } function CancelAddRow(prog, key) { //get select program and key if (!prog) { progselect=document.getElementById("prog"); prog=progselect.options[progselect.selectedIndex].value; } if (!key) { keyselect=document.getElementById("key"); key=keyselect.options[keyselect.selectedIndex].value; } //reload the original content in case of cancel get_values(1, prog, key); // to be removed later when solution for adding multiple new rows is found document.getElementById('addrowvals').style.display = ""; document.getElementById('addrowvals2').style.display = ""; document.getElementById('addrowkey').style.display = ""; document.getElementById('addrowprog').style.display = ""; } function CancelUpdate() { //get select program and key progselect=document.getElementById("prog"); prog=progselect.options[progselect.selectedIndex].value; keyselect=document.getElementById("key"); key=keyselect.options[keyselect.selectedIndex].value; //reload the original table in case of cancel get_values(1, prog, key); } function EditRow(index) { for (var i = 1 ; i <= document.getElementById('maxindex').innerHTML ; i++) if(document.getElementById('action'+i) && i!=index) //document.getElementById('action'+i).innerHTML = ""; document.getElementById('action'+i).style.display = "none"; //get current values oldval=document.getElementById('val'+index).innerHTML; olddescr=document.getElementById('descr'+index).innerHTML; oldtype=document.getElementById('type'+index).innerHTML; if (!oldval) delcase=6; else delcase=4; //set field for value if (oldtype=='bool') { if (oldval=='yes') textval=" yes"; else textval=" yes"; if (oldval=='no') textval=textval+" no" else textval=textval+" no" } else textval=""; document.getElementById('val'+index).innerHTML = textval; //set field for description document.getElementById('descr'+index).innerHTML = ""; /* //set field for type typeselecttext=""; document.getElementById('type'+index).innerHTML = typeselecttext; */ //set field for action actiontext=""; notyetvalid=document.getElementById('notyetvalid'+index) if (delcase!=6 || notyetvalid) actiontext=actiontext+""; actiontext=actiontext+""; document.getElementById('action'+index).innerHTML =actiontext; } function UpdateRow(updcase,index) { // five cases of update corresponds to // 5: add new prog + key addcase 1 // 1: add new key addcase 2 // 2: add new val (for same key) addcase 3 -> same type // 3: edit val -> same type // 4: delete val (ie set to NULL) -> same type // 6: delete new key (ie val still NULL) -> real delete descr=document.getElementById('newdescr'+index).value; origindex=0; switch(updcase) { case 5: prog=document.getElementById('prog'+index).value; key1=document.getElementById('1key'+index).value; key2=document.getElementById('2key'+index).value; val=document.getElementById('newval'+index).innerHTML; type=document.getElementById('newtype'+index).value; break; case 1: //prog=document.getElementById('prog'+index).value; prog=document.getElementById('prog'+index).innerHTML; key1=document.getElementById('1key'+index).value; key2=document.getElementById('2key'+index).value; val=document.getElementById('newval'+index).innerHTML; type=document.getElementById('newtype'+index).value; break; case 2: //prog=document.getElementById('prog'+index).value; prog=document.getElementById('prog'+index).innerHTML; key1=document.getElementById('1key'+index).innerHTML; key2=document.getElementById('2key'+index).innerHTML; val=document.getElementById('newval'+index).value; type=document.getElementById('type'+index).innerHTML; break; case 3: prog=document.getElementById('prog'+index).innerHTML; key1=document.getElementById('1key'+index).innerHTML; key2=document.getElementById('2key'+index).innerHTML; type=document.getElementById('type'+index).innerHTML; val="hallo"; if (type=="bool") { radio=document.getElementsByName('boolbox'); for (i=0; i< radio.length; i++) if (radio[i].checked) val=radio[i].value; } else val=document.getElementById('newval'+index).value; origindex=document.getElementById('1origindex'+index).innerHTML; break; case 4: case 6: answer = confirm("Do you really want to delete the value?"); if (!answer) return; prog=document.getElementById('prog'+index).innerHTML; key1=document.getElementById('1key'+index).innerHTML; key2=document.getElementById('2key'+index).innerHTML; val=document.getElementById('newval'+index).value; if (!val) val="NULL"; type=document.getElementById('type'+index).innerHTML; origindex=document.getElementById('1origindex'+index).innerHTML; break; } if (!descr) alert("Please insert description!"); if (!key1) alert("Please insert key1!"); if (!key2) alert("Please insert key2!"); if (!val) alert("Please insert value!"); if (!val || !descr || !key1 || !key2) return; if (index==0) index=-1; //check if value has correct type // for string no check needed if (updcase==3) { if (type=='int' && parseInt(val)!=val) { alert("Value is not a int."); return; } if (type=='float' && parseFloat(val)!=val) { alert("Value is not a float."); return; } if (type=='bool' && val!='yes' && val!='no') { alert("Value is neither 'yes' not 'no'."); return; } } if (!type && (updcase==2 || updcase==3 || updcase==4)) { alert("Please select type!"); return; } phpcall="insert_po.php?fUpdCase="+updcase+"&fIndex="+index+"&fOriginalIndex="+origindex+"&fProgram="+prog +"&fKey1="+key1+"&fKey2="+key2+"&fValue="+val+"&fDescription="+descr+"&fType="+type; //alert(phpcall); xmlhttp.open("GET", phpcall, false); xmlhttp.send(); // get somehow return value of inser_po.php // to catch cases where insert was rejected due to no update if (xmlhttp.readyState==4 && xmlhttp.status==200) { if (xmlhttp.responseText=="no change") { alert("You didn't change anything."); return; } if (xmlhttp.responseText=="key exists") { alert("This key already exists. You cannot insert it a second time."); return; } if (xmlhttp.responseText=="prog exists") { alert("This program already exists. You cannot insert it a second time."); return; } alert(xmlhttp.responseText); } else alert("Mist! "+xmlhttp.responseText); //reload the content of the page progselect=document.getElementById("prog"); if (!progselect) oldprog=prog; else if (progselect.options[progselect.selectedIndex]) oldprog=progselect.options[progselect.selectedIndex].value; else oldprog=prog; keyselect=document.getElementById("key"); if (!keyselect) oldkey=key1+"."+key2; else if (keyselect.options[keyselect.selectedIndex]) oldkey=keyselect.options[keyselect.selectedIndex].value; else oldkey=key1+"."+key2; //reload progs and keys get_progs(oldprog, "10", "edit"); get_keys(oldprog, oldkey, "10", "edit"); //reload values xmlhttp.open("GET","get_values.php?fGetValCase=1&fKey="+oldkey+"&fProgram="+oldprog,false); xmlhttp.send(); if (xmlhttp.readyState==4 && xmlhttp.status==200) document.getElementById('valuefield1').innerHTML = xmlhttp.responseText; else document.getElementById('valuefield1').innerHTML = "argh"; } function ShowCurrent() { for (var i = 1 ; i <= document.getElementById('maxindex').innerHTML ; i++) if(document.getElementById('old'+i)) document.getElementById('old'+i).style.display = "none"; document.getElementById('showcurrent').style.display = "none"; document.getElementById('showcurrent2').style.display = "none"; document.getElementById('showall').style.display = ""; document.getElementById('showall2').style.display = ""; } function ShowAll() { for (var i = 1 ; i <= document.getElementById('maxindex').innerHTML ; i++) if(document.getElementById('old'+i)) { document.getElementById('old'+i).style.display = ""; document.getElementById('old'+i).style.color = "grey"; } document.getElementById('showcurrent').style.display = ""; document.getElementById('showcurrent2').style.display = ""; document.getElementById('showall').style.display = "none"; document.getElementById('showall2').style.display = "none"; } function InsertRow(table, row) { var x=document.getElementById('valtable'+table).insertRow(row); for (var i = 0 ; i < 9 ; i++) { y=x.insertCell(i); y.innerHTML=" "; } } function CompareValues() { counter=0; maxindex2=document.getElementById('maxindex').innerHTML; maxindex3=document.getElementById('maxindex3').innerHTML; //alert(maxindex2); //alert(maxindex3); if (parseInt(maxindex2)>parseInt(maxindex3)) maxindex=maxindex2; else maxindex=maxindex3; for (var i = 1 ; i <= maxindex ; i++) { if (document.getElementById('2compare'+i)) { counter++; if (!document.getElementById('3compare'+i)) { InsertRow(3,counter); document.getElementById('2compare'+i).style.color='red'; } else { val2=document.getElementById('2compare'+i).cells[5].innerHTML; val3=document.getElementById('3compare'+i).cells[5].innerHTML; if (val2!=val3) { document.getElementById('2compare'+i).style.color='blue'; document.getElementById('3compare'+i).style.color='blue'; } } } else if (document.getElementById('3compare'+i)) { counter++; InsertRow(2,counter); document.getElementById('3compare'+i).style.color='green'; } } //document.getElementById('comparevals').style.display = "none"; } function HideDescription(getvalcase) { for(var i=0;i