source: trunk/www/db_po/po.js@ 11976

Last change on this file since 11976 was 11976, checked in by Daniela Dorner, 13 years ago
bugfix for 'Add Prg/Key' button
File size: 33.9 KB
Line 
1var xmlhttp;
2if (window.XMLHttpRequest)
3{// code for IE7+, Firefox, Chrome, Opera, Safari
4 xmlhttp=new XMLHttpRequest();
5}
6else
7{// code for IE6, IE5
8 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
9}
10
11//function to get programs from the db
12function get_progs(prog, selectsize, mode)
13{
14 xmlhttp.open("GET","get_progs.php?fProgram="+prog+"&fSelectSize="+selectsize+"&fMode="+mode,false);
15 xmlhttp.send();
16 if (xmlhttp.readyState==4 && xmlhttp.status==200)
17 {
18 document.getElementById('progfield').innerHTML = xmlhttp.responseText;
19 document.getElementById('keyfield').innerHTML = "";
20 if (document.getElementById('valuefield1'))
21 document.getElementById('valuefield1').innerHTML = "";
22 }
23 else
24 document.getElementById('progfield').innerHTML = "argh";
25}
26
27//function to get keys from the db
28function get_keys(prog, key, selectsize, mode)
29{
30 xmlhttp.open("GET","get_keys.php?fProgram="+prog+"&fKey="+key+"&fSelectSize="+selectsize+"&fMode="+mode,false);
31 xmlhttp.send();
32 if (xmlhttp.readyState==4 && xmlhttp.status==200)
33 {
34 document.getElementById('keyfield').innerHTML = xmlhttp.responseText;
35 if (document.getElementById('valuefield1'))
36 document.getElementById('valuefield1').innerHTML = "";
37 }
38 else
39 document.getElementById('keyfield').innerHTML = "argh";
40
41 if(document.getElementById('addrowprog'))
42 document.getElementById('addrowprog').style.display = "";
43}
44
45function get_statusdate(getvalcase, val)
46{
47 if (!val)
48 {
49 radio=document.getElementsByName('dateformat'+getvalcase);
50 for (i=0; i< radio.length; i++)
51 if (radio[i].checked)
52 val=radio[i].value;
53 }
54 if (val=="pulldown")
55 {
56 year=document.getElementById('year'+getvalcase).value;
57 month=document.getElementById('month'+getvalcase).value;
58 day=document.getElementById('day'+getvalcase).value;
59 hour=document.getElementById('hour'+getvalcase).value;
60 min=document.getElementById('min'+getvalcase).value;
61 sec=document.getElementById('sec'+getvalcase).value;
62
63 statusdate=(year =='empty'? '':year);
64 statusdate=statusdate+(month=='empty'? '':'-'+month);
65 statusdate=statusdate+(day =='empty'? '':'-'+day);
66 statusdate=statusdate+(hour =='empty'? '':' '+hour);
67 statusdate=statusdate+(min =='empty'? '':':'+min);
68 statusdate=statusdate+(sec =='empty'? '':':'+sec);
69 }
70 if (val=="textinput")
71 statusdate=document.getElementById('statusdate'+getvalcase).value;
72 return statusdate;
73}
74
75//function to get values from the db
76function get_values(getvalcase, prog, key, mode)
77{
78 //in this case the given 'prog' and 'key' are ignored
79 if (parseInt(getvalcase)>1)
80 {
81 //get prog and key
82 progselect=document.getElementById("prog");
83 if (!progselect)
84 prog="all";
85 else
86 if (progselect.options[progselect.selectedIndex])
87 prog=progselect.options[progselect.selectedIndex].value;
88 else
89 prog="all";
90 keyselect=document.getElementById("key");
91 if (!keyselect)
92 key="all";
93 else
94 if (keyselect.options[keyselect.selectedIndex])
95 key=keyselect.options[keyselect.selectedIndex].value;
96 else
97 key="all";
98 }
99 //if (mode=="view" && getvalcase==1)
100 // return;
101
102 if ((getvalcase==2 || getvalcase==3) && document.getElementById('statusdate'+getvalcase))
103 {
104 statusdate=get_statusdate(getvalcase);
105 phpcall="get_values.php?fStatusDate="+statusdate+"&fGetValCase="+getvalcase+"&fKey="+key+"&fProgram="+prog;
106 }
107 else
108 phpcall="get_values.php?fGetValCase="+getvalcase+"&fKey="+key+"&fProgram="+prog;
109
110 xmlhttp.open("GET",phpcall,false);
111 xmlhttp.send();
112 if (xmlhttp.readyState==4 && xmlhttp.status==200)
113 document.getElementById('valuefield'+getvalcase).innerHTML = xmlhttp.responseText;
114 else
115 document.getElementById('valuefield'+getvalcase).innerHTML = "argh";
116
117 if(document.getElementById('addrowkey'))
118 document.getElementById('addrowkey').style.display = "";
119}
120
121function addRow(addcase, prog, key, key1, key2, type, min, max)
122{
123 if (!prog)
124 {
125 progselect=document.getElementById("prog");
126 if (progselect.selectedIndex>=0)
127 prog=progselect.options[progselect.selectedIndex].value;
128 else
129 prog='all';
130 }
131 if (!key)
132 {
133 keyselect=document.getElementById("key");
134 if (!keyselect)
135 key='all';
136 else
137 if (keyselect.selectedIndex>=0)
138 key=keyselect.options[keyselect.selectedIndex].value;
139 else
140 key='all';
141 }
142
143 switch(addcase)
144 {
145 case 1:
146 get_keys(prog, key, "10", "edit");
147 case 2:
148 get_values(1, prog, key, "edit");
149 }
150
151 if (prog=='all' && (addcase==3 || addcase==2))
152 addcase=1;
153 if (key=='all' && addcase==3)
154 addcase=2;
155
156
157 for (var i = 1 ; i <= document.getElementById('maxindex').innerHTML ; i++)
158 if(document.getElementById('action'+i))
159 //document.getElementById('action'+i).innerHTML = "";
160 document.getElementById('action'+i).style.display = "none";
161
162 tabBody=document.getElementById("valtable1");
163 row=document.createElement("TR");
164 row.id='val0';
165 row.bgColor='#C8C8C8';
166 cell0 = document.createElement("TD");
167 cell1 = document.createElement("TD");
168 cell2 = document.createElement("TD");
169 cell3 = document.createElement("TD");
170 cell4 = document.createElement("TD");
171 cell5 = document.createElement("TD");
172 cell6 = document.createElement("TD");
173 cell7 = document.createElement("TD");
174 cell8 = document.createElement("TD");
175 cell9 = document.createElement("TD");
176 cell10 = document.createElement("TD");
177 var updcase;
178
179 // addcase: three cases
180 // 1: add new prog+key, val=NULL
181 // 2: add new key, val=NULL, prog=selected
182 // 3: add new val, prog=selected, key=selected, type/min/max fixed
183 switch(addcase)
184 {
185 case 1:
186 updcase=5;
187 //field for prog
188 input1 = document.createElement("INPUT");
189 input1.style.width = 80;
190 input1.id = 'prog0';
191 cell1.appendChild(input1);
192 //fields for keys
193 input2 = document.createElement("INPUT");
194 input2.style.width = 100;
195 input2.id = '1key0';
196 cell2.appendChild(input2);
197 input10 = document.createElement("INPUT");
198 input10.id = '2key0';
199 input10.style.width = 100;
200 cell10.appendChild(input10);
201 //field for val
202 cell3.id = 'newval0';
203 textnode3=document.createTextNode("NULL");
204 cell3.appendChild(textnode3);
205 //field type
206 select7 = document.createElement("select");
207 select7.id = 'newtype0';
208 select7.option = 'string';
209 option7a = document.createElement("option");
210 option7a.text = '-';
211 option7a.value = '';
212 select7.appendChild(option7a);
213 option7b = document.createElement("option");
214 option7b.id = 'int';
215 option7b.text = 'int';
216 option7b.value = 'int';
217 select7.appendChild(option7b);
218 option7c = document.createElement("option");
219 option7c.id = 'float';
220 option7c.text = 'float';
221 option7c.value = 'float';
222 select7.appendChild(option7c);
223 option7d = document.createElement("option");
224 option7d.id = 'string';
225 option7d.text = 'string';
226 option7d.value = 'string';
227 select7.appendChild(option7d);
228 option7e = document.createElement("option");
229 option7e.id = 'bool';
230 option7e.text = 'bool';
231 option7e.value = 'bool';
232 select7.appendChild(option7e);
233 cell7.appendChild(select7);
234 //field for min
235 input8 = document.createElement("INPUT");
236 input8.id = 'newmin0';
237 input8.style.width = 50;
238 cell8.appendChild(input8);
239 //field for max
240 input9 = document.createElement("INPUT");
241 input9.id = 'newmax0';
242 input9.style.width = 50;
243 cell9.appendChild(input9);
244 break;
245 case 2:
246 updcase=1;
247 //field for prog
248 cell1.id = 'prog0';
249 textnode1=document.createTextNode(prog);
250 cell1.appendChild(textnode1);
251 //field for key
252 input2 = document.createElement("INPUT");
253 input2.id = '1key0';
254 input2.style.width = 100;
255 cell2.appendChild(input2);
256 input10 = document.createElement("INPUT");
257 input10.id = '2key0';
258 input10.style.width = 100;
259 cell10.appendChild(input10);
260 //field for val
261 cell3.id = 'newval0';
262 textnode3=document.createTextNode("NULL");
263 cell3.appendChild(textnode3);
264 //field type
265 select7 = document.createElement("select");
266 select7.id = 'newtype0';
267 select7.option = 'string';
268 option7a = document.createElement("option");
269 option7a.text = '-';
270 option7a.value = '';
271 select7.appendChild(option7a);
272 option7b = document.createElement("option");
273 option7b.id = 'int';
274 option7b.text = 'int';
275 option7b.value = 'int';
276 select7.appendChild(option7b);
277 option7c = document.createElement("option");
278 option7c.id = 'float';
279 option7c.text = 'float';
280 option7c.value = 'float';
281 select7.appendChild(option7c);
282 option7d = document.createElement("option");
283 option7d.id = 'string';
284 option7d.text = 'string';
285 option7d.value = 'string';
286 select7.appendChild(option7d);
287 option7e = document.createElement("option");
288 option7e.id = 'bool';
289 option7e.text = 'bool';
290 option7e.value = 'bool';
291 select7.appendChild(option7e);
292 cell7.appendChild(select7);
293 //field for min
294 input8 = document.createElement("INPUT");
295 input8.id = 'newmin0';
296 input8.style.width = 50;
297 cell8.appendChild(input8);
298 //field for max
299 input9 = document.createElement("INPUT");
300 input9.id = 'newmax0';
301 input9.style.width = 50;
302 cell9.appendChild(input9);
303 break;
304 case 3:
305 updcase=2;
306 //field for prog
307 cell1.id = 'prog0';
308 textnode1=document.createTextNode(prog);
309 cell1.appendChild(textnode1);
310 //field for key
311 cell2.id = '1key0';
312 textnode2=document.createTextNode(key1);
313 cell2.appendChild(textnode2);
314 cell10.id = '2key0';
315 textnode10=document.createTextNode(key2);
316 cell10.appendChild(textnode10);
317 //field for val
318 input3 = document.createElement("INPUT");
319 input3.style.width = 100;
320 input3.id = 'newval0';
321 cell3.appendChild(input3);
322 //field type
323 cell7.id = 'type0';
324 textnode7 = document.createTextNode(type);
325 cell7.appendChild(textnode7);
326 //field min
327 cell8.id = 'min0';
328 textnode8 = document.createTextNode(min);
329 cell8.appendChild(textnode8);
330 //field max
331 cell9.id = 'max0';
332 textnode9 = document.createTextNode(max);
333 cell9.appendChild(textnode9);
334 break;
335 default:
336 break;
337 }
338
339 //field descr
340 input4 = document.createElement("INPUT");
341 input4.style.width = 200;
342 input4.id = 'newdescr0';
343 cell4.appendChild(input4);
344 //field action
345 input5a = document.createElement("input");
346 input5a.value = 'Add';
347 input5a.type = "button";
348 input5a.onclick = function () { UpdateRow(updcase, 0); onclick() }
349 cell5.appendChild(input5a);
350 input5b = document.createElement("input");
351 input5b.value = 'Cancel';
352 input5b.type = "button";
353 input5b.onclick = function () { CancelAddRow(prog, key); onclick() }
354 cell5.appendChild(input5b);
355
356 row.appendChild(cell0);//index, counter
357 row.appendChild(cell6);//valid from
358 row.appendChild(cell1);//prog
359 row.appendChild(cell2);//key1
360 row.appendChild(cell10);//key2
361 row.appendChild(cell3);//value
362 row.appendChild(cell7);//type
363 row.appendChild(cell8);//min
364 row.appendChild(cell9);//max
365 row.appendChild(cell4);//descr
366 row.appendChild(cell5);//action
367 tabBody.appendChild(row);
368
369 //disabeling all other edit/add buttons
370 // (to be removed later when solution for adding multiple new rows is found)
371 document.getElementById('addrowvals').style.display = "none";
372 document.getElementById('addrowvals2').style.display = "none";
373 document.getElementById('addrowkey').style.display = "none";
374 document.getElementById('addrowprog').style.display = "none";
375}
376
377function CancelAddRow(prog, key)
378{
379 //get select program and key
380 if (!prog)
381 {
382 progselect=document.getElementById("prog");
383 prog=progselect.options[progselect.selectedIndex].value;
384 }
385 if (!key)
386 {
387 keyselect=document.getElementById("key");
388 key=keyselect.options[keyselect.selectedIndex].value;
389 }
390 //reload the original content in case of cancel
391 get_values(1, prog, key, "edit");
392
393 //disabeling all other edit/add buttons
394 // (to be removed later when solution for adding multiple new rows is found)
395 document.getElementById('addrowvals').style.display = "";
396 document.getElementById('addrowvals2').style.display = "";
397 document.getElementById('addrowkey').style.display = "";
398 document.getElementById('addrowprog').style.display = "";
399}
400
401function CancelUpdate()
402{
403 //get select program and key
404 document.getElementById('addrowprog').style.display = "";
405 progselect=document.getElementById("prog");
406 prog=progselect.options[progselect.selectedIndex].value;
407 keyselect=document.getElementById("key");
408 key=keyselect.options[keyselect.selectedIndex].value;
409 //reload the original table in case of cancel
410 get_values(1, prog, key, "edit");
411}
412
413function EditRow(index)
414{
415 //disabeling all other edit/add buttons
416 // (to be removed later when solution for adding multiple new rows is found)
417 for (var i = 1 ; i <= document.getElementById('maxindex').innerHTML ; i++)
418 if(document.getElementById('action'+i) && i!=index)
419 document.getElementById('action'+i).style.display = "none";
420 document.getElementById('addrowvals').style.display = "none";
421 document.getElementById('addrowvals2').style.display = "none";
422 document.getElementById('addrowkey').style.display = "none";
423 document.getElementById('addrowprog').style.display = "none";
424
425 //get current values
426 oldval=document.getElementById('val'+index).innerHTML;
427 olddescr=document.getElementById('descr'+index).innerHTML;
428 oldtype=document.getElementById('type'+index).innerHTML;
429 if (!oldval)
430 delcase=6;
431 else
432 delcase=4;
433 //set field for value
434 if (oldtype=='bool')
435 {
436 if (oldval=='yes')
437 textval="<input name='boolbox' type='radio' id='newval"+index+"' value='yes' checked> yes";
438 else
439 textval="<input name='boolbox' type='radio' id='newval"+index+"' value='yes'> yes";
440 if (oldval=='no')
441 textval=textval+"<input name='boolbox' type='radio' id='newval"+index+"' value='no' checked> no"
442 else
443 textval=textval+"<input name='boolbox' type='radio' id='newval"+index+"' value='no'> no"
444 }
445 else
446 textval="<input align='right' id='newval"+index+"' value='"+oldval+"'>";
447 document.getElementById('val'+index).innerHTML = textval;
448 //set field for description
449 document.getElementById('descr'+index).innerHTML = "<input align='right' id='newdescr"+index+"' value='"+olddescr+"'>";
450 /*
451 //set field for type
452 typeselecttext="<select id='newtype"+index+"' value='"+oldtype+"'>"+"<option>-</option>";
453 if (oldtype=='int')
454 typeselecttext=typeselecttext+"<option selected>int</option>";
455 else
456 typeselecttext=typeselecttext+"<option>int</option>";
457 if (oldtype=='float')
458 typeselecttext=typeselecttext+"<option selected>float</option>";
459 else
460 typeselecttext=typeselecttext+"<option>float</option>";
461 if (oldtype=='string')
462 typeselecttext=typeselecttext+"<option selected>string</option>";
463 else
464 typeselecttext=typeselecttext+"<option>string</option>";
465 if (oldtype=='bool')
466 typeselecttext=typeselecttext+"<option selected>bool</option>";
467 else
468 typeselecttext=typeselecttext+"<option>bool</option>";
469 typeselecttext=typeselecttext+"</select>";
470 document.getElementById('type'+index).innerHTML = typeselecttext;
471 */
472
473 //set field for action
474 actiontext="<input type='button' value='Update' onclick='UpdateRow(3,"+index+")'>";
475 notyetvalid=document.getElementById('notyetvalid'+index)
476 if (delcase!=6 || notyetvalid)
477 actiontext=actiontext+"<input type='button' value='Delete' onclick='UpdateRow("+delcase+","+index+")'>";
478 actiontext=actiontext+"<input type='button' value='Cancel' onclick='CancelUpdate()'>";
479 document.getElementById('action'+index).innerHTML =actiontext;
480}
481
482function UpdateRow(updcase,index)
483{
484 // five cases of update corresponds to
485 // 5: add new prog + key addcase 1
486 // 1: add new key addcase 2
487 // 2: add new val (for same key) addcase 3 -> same type,min,max
488 // 3: edit val -> same type,min,max
489 // 4: delete val (ie set to NULL) -> same type,min,max
490 // 6: delete new key (ie val still NULL) -> real delete
491 descr=document.getElementById('newdescr'+index).value;
492 origindex=0;
493 switch(updcase)
494 {
495 case 5:
496 prog=document.getElementById('prog'+index).value;
497 key1=document.getElementById('1key'+index).value;
498 key2=document.getElementById('2key'+index).value;
499 val=document.getElementById('newval'+index).innerHTML;
500 type=document.getElementById('newtype'+index).value;
501 min=document.getElementById('newmin'+index).value;
502 max=document.getElementById('newmax'+index).value;
503 break;
504 case 1:
505 //prog=document.getElementById('prog'+index).value;
506 prog=document.getElementById('prog'+index).innerHTML;
507 key1=document.getElementById('1key'+index).value;
508 key2=document.getElementById('2key'+index).value;
509 val=document.getElementById('newval'+index).innerHTML;
510 type=document.getElementById('newtype'+index).value;
511 min=document.getElementById('newmin'+index).value;
512 max=document.getElementById('newmax'+index).value;
513 break;
514 case 2:
515 //prog=document.getElementById('prog'+index).value;
516 prog=document.getElementById('prog'+index).innerHTML;
517 key1=document.getElementById('1key'+index).innerHTML;
518 key2=document.getElementById('2key'+index).innerHTML;
519 val=document.getElementById('newval'+index).value;
520 type=document.getElementById('type'+index).innerHTML;
521 min=document.getElementById('min'+index).innerHTML;
522 max=document.getElementById('max'+index).innerHTML;
523 break;
524 case 3:
525 prog=document.getElementById('prog'+index).innerHTML;
526 key1=document.getElementById('1key'+index).innerHTML;
527 key2=document.getElementById('2key'+index).innerHTML;
528 type=document.getElementById('type'+index).innerHTML;
529 min=document.getElementById('min'+index).innerHTML;
530 max=document.getElementById('max'+index).innerHTML;
531 val="hallo";
532 if (type=="bool")
533 {
534 radio=document.getElementsByName('boolbox');
535 for (i=0; i< radio.length; i++)
536 if (radio[i].checked)
537 val=radio[i].value;
538 }
539 else
540 val=document.getElementById('newval'+index).value;
541 origindex=document.getElementById('1origindex'+index).innerHTML;
542 break;
543 case 4:
544 case 6:
545 answer = confirm("Do you really want to delete the value?");
546 if (!answer)
547 return;
548 prog=document.getElementById('prog'+index).innerHTML;
549 key1=document.getElementById('1key'+index).innerHTML;
550 key2=document.getElementById('2key'+index).innerHTML;
551 val=document.getElementById('newval'+index).value;
552 if (!val)
553 val="NULL";
554 type=document.getElementById('type'+index).innerHTML;
555 min=document.getElementById('min'+index).innerHTML;
556 max=document.getElementById('max'+index).innerHTML;
557 origindex=document.getElementById('1origindex'+index).innerHTML;
558 break;
559 }
560 if (!descr)
561 alert("Please insert description!");
562 if (!key1)
563 alert("Please insert key1!");
564 if (!val)
565 alert("Please insert value!");
566 if (!val || !descr || !key1)
567 return;
568 if (index==0)
569 index=-1;
570 if (!type && (updcase==2 || updcase==3 || updcase==4))
571 {
572 alert("Please select type!");
573 return;
574 }
575
576 //check if value has correct type and is within ranges
577 // for string no check needed
578 if (updcase==3)
579 {
580 if (type=='int' && parseInt(val)!=val)
581 {
582 alert("Value is not a int.");
583 return;
584 }
585 if (type=='float' && parseFloat(val)!=val)
586 {
587 alert("Value is not a float.");
588 return;
589 }
590 if (type=='bool' && val!='yes' && val!='no')
591 {
592 alert("Value is neither 'yes' not 'no'.");
593 return;
594 }
595 // check ranges for int
596 if (type=='int' && parseInt(val)>parseInt(max))
597 {
598 alert("You cannot enter a value larger than "+max+".");
599 return;
600 }
601 if (type=='int' && parseInt(val)<parseInt(min))
602 {
603 alert("You cannot enter a value smaller than "+min+".");
604 return;
605 }
606 // check ranges for float
607 if (type=='float' && parseFloat(val)>parseFloat(max))
608 {
609 alert("You cannot enter a value larger than "+max+".");
610 return;
611 }
612 if (type=='float' && parseFloat(val)<parseFloat(min))
613 {
614 alert("You cannot enter a value smaller than "+min+".");
615 return;
616 }
617 }
618
619 if (!min && (type=='int' || type=='float'))
620 {
621 alert("Please insert minimum!");
622 return;
623 }
624 if (!max && (type=='int' || type=='float'))
625 {
626 alert("Please insert maximum!");
627 return;
628 }
629 //check if min/max have correct type
630 // for string no check needed
631 if (updcase==1 || updcase==5)
632 {
633 if (type=='int' && parseInt(min)!=min)
634 {
635 alert("Minimum is not a int.");
636 return;
637 }
638 if (type=='int' && parseInt(max)!=max)
639 {
640 alert("Maximum is not a int.");
641 return;
642 }
643 if (type=='float' && parseFloat(min)!=min)
644 {
645 alert("Minimum is not a float.");
646 return;
647 }
648 if (type=='float' && parseFloat(max)!=max)
649 {
650 alert("Maximum is not a float.");
651 return;
652 }
653 if (type=='float' && parseFloat(max)<parseFloat(min))
654 {
655 alert("Maximum cannot be smaller than minimum.");
656 return;
657 }
658 if (type=='int' && parseInt(max)<parseInt(min))
659 {
660 alert("Maximum cannot be smaller than minimum.");
661 return;
662 }
663 }
664
665 phpcall="insert_po.php?fUpdCase="+updcase+"&fIndex="+index+"&fOriginalIndex="+origindex
666 +"&fProgram="+prog+"&fKey1="+key1+"&fKey2="+key2+"&fValue="+val+"&fDescription="+descr
667 +"&fType="+type+"&fMin="+min+"&fMax="+max;
668 //alert(phpcall);
669
670 xmlhttp.open("GET", phpcall, false);
671 xmlhttp.send();
672
673 // get somehow return value of inser_po.php
674 // to catch cases where insert was rejected due to no update
675 if (xmlhttp.readyState==4 && xmlhttp.status==200)
676 {
677 if (xmlhttp.responseText=="no change")
678 {
679 alert("You didn't change anything.");
680 return;
681 }
682 if (xmlhttp.responseText=="key exists")
683 {
684 alert("This key already exists. You cannot insert it a second time.");
685 return;
686 }
687 if (xmlhttp.responseText=="prog exists")
688 {
689 alert("This program already exists. You cannot insert it a second time.");
690 return;
691 }
692 if (xmlhttp.responseText=="user empty")
693 {
694 alert("User name is missing. Please give a user name when logging in.");
695 return;
696 }
697 alert(xmlhttp.responseText);
698 }
699 else
700 alert("Mist! "+xmlhttp.responseText);
701
702 //reload the content of the page
703 progselect=document.getElementById("prog");
704 if (!progselect)
705 oldprog=prog;
706 else
707 if (progselect.options[progselect.selectedIndex])
708 oldprog=progselect.options[progselect.selectedIndex].value;
709 else
710 oldprog=prog;
711 keyselect=document.getElementById("key");
712 if (!keyselect)
713 oldkey=key1+"."+key2;
714 else
715 if (keyselect.options[keyselect.selectedIndex])
716 oldkey=keyselect.options[keyselect.selectedIndex].value;
717 else
718 oldkey=key1+"."+key2;
719 //reload progs and keys
720 get_progs(oldprog, "10", "edit");
721 get_keys(oldprog, oldkey, "10", "edit");
722 //reload values
723 xmlhttp.open("GET","get_values.php?fGetValCase=1&fKey="+oldkey+"&fProgram="+oldprog,false);
724 xmlhttp.send();
725 if (xmlhttp.readyState==4 && xmlhttp.status==200)
726 document.getElementById('valuefield1').innerHTML = xmlhttp.responseText;
727 else
728 document.getElementById('valuefield1').innerHTML = "argh";
729}
730
731function ShowCurrent()
732{
733 for (var i = 1 ; i <= document.getElementById('maxindex').innerHTML ; i++)
734 if(document.getElementById('old'+i))
735 document.getElementById('old'+i).style.display = "none";
736 document.getElementById('showcurrent').style.display = "none";
737 document.getElementById('showcurrent2').style.display = "none";
738 document.getElementById('showall').style.display = "";
739 document.getElementById('showall2').style.display = "";
740}
741
742function ShowAll()
743{
744 for (var i = 1 ; i <= document.getElementById('maxindex').innerHTML ; i++)
745 if(document.getElementById('old'+i))
746 {
747 document.getElementById('old'+i).style.display = "";
748 document.getElementById('old'+i).style.color = "grey";
749 }
750 document.getElementById('showcurrent').style.display = "";
751 document.getElementById('showcurrent2').style.display = "";
752 document.getElementById('showall').style.display = "none";
753 document.getElementById('showall2').style.display = "none";
754}
755
756function InsertRow(table, row)
757{
758 var x=document.getElementById('valtable'+table).insertRow(row);
759 y=x.insertCell(0);
760 y.colSpan='5';
761 y.innerHTML="&nbsp;";
762}
763
764function CompareValues()
765{
766 counter=0;
767 maxindex2=document.getElementById('maxindex').innerHTML;
768 maxindex3=document.getElementById('maxindex3').innerHTML;
769 if (parseInt(maxindex2)>parseInt(maxindex3))
770 maxindex=maxindex2;
771 else
772 maxindex=maxindex3;
773
774 for (var i = 1 ; i <= maxindex ; i++)
775 {
776 if (document.getElementById('2compare'+i))
777 {
778 counter++;
779 if (!document.getElementById('3compare'+i))
780 {
781 InsertRow(3,counter);
782 document.getElementById('2compare'+i).style.color='red';
783 }
784 else
785 {
786 val2=document.getElementById('2compare'+i).cells[5].innerHTML;
787 val3=document.getElementById('3compare'+i).cells[5].innerHTML;
788 if (val2!=val3)
789 {
790 document.getElementById('2compare'+i).style.color='blue';
791 document.getElementById('3compare'+i).style.color='blue';
792 }
793 }
794 }
795 else
796 if (document.getElementById('3compare'+i))
797 {
798 counter++;
799 InsertRow(2,counter);
800 document.getElementById('3compare'+i).style.color='green';
801 }
802 }
803 //document.getElementById('comparevals').style.display = "none";
804
805 //reload all setting for show-menu
806 ShowHide('indices', 'sh_indices', 2)
807 ShowHide('indices', 'sh_indices', 3)
808 ShowHide('description', 'sh_descr', 2)
809 ShowHide('description', 'sh_descr', 3)
810 ShowHide('validsince', 'sh_validsince', 2)
811 ShowHide('validsince', 'sh_validsince', 3)
812 ShowHide('minimum', 'sh_min', 2)
813 ShowHide('minimum', 'sh_min', 3)
814 ShowHide('maximum', 'sh_max', 2)
815 ShowHide('maximum', 'sh_max', 3)
816 ShowHide('user', 'sh_user', 2)
817 ShowHide('user', 'sh_user', 3)
818}
819
820function ShowHide(column, idname, getvalcase)
821{
822 box=document.getElementById(idname+getvalcase);
823 text=box.checked? '':'none';
824
825 for(var i=0;i<document.getElementsByTagName('*').length;i++)
826 if(document.getElementsByTagName('*')[i].className == column+getvalcase)
827 document.getElementsByTagName('*')[i].style.display = text;
828}
829
830function ShowDateInput(idx)
831{
832 document.getElementById('datepulldown'+idx).style.display = "none";
833 document.getElementById('dateinput'+idx).style.display = "inline";
834 set_statusdate(idx, get_statusdate(idx, 'pulldown'));
835}
836
837function ShowDatePulldown(idx)
838{
839 document.getElementById('datepulldown'+idx).style.display = "inline";
840 document.getElementById('dateinput'+idx).style.display = "none";
841 set_statusdate(idx, get_statusdate(idx, 'textinput'));
842}
843
844function reset_dates(datename, dateval, dateval2, idx)
845{
846 radio=document.getElementsByName('dateformat'+idx);
847 for (i=0; i< radio.length; i++)
848 if (radio[i].checked)
849 val=radio[i].value;
850 if (val=="pulldown")
851 {
852 //alert("reset:"+datename+"-"+dateval+"-"+dateval2+"-"+idx);
853 if (datename=="year")
854 {
855 get_dates("year", dateval, dateval2, idx);
856 get_dates("month", dateval, dateval2, idx);
857 }
858
859 if (datename=="year" || datename=="month")
860 if (datename=="month")
861 get_dates("day", dateval, dateval2, idx);
862 else
863 get_dates("day", "empty", "empty", idx);
864
865 if (datename=="year" || datename=="month" || datename=="day")
866 if (datename=="day")
867 get_dates("hour", dateval, dateval2, idx);
868 else
869 get_dates("hour", "empty", "empty", idx);
870
871 if (datename=="year" || datename=="month" || datename=="day" || datename=="hour")
872 if (datename=="hour")
873 get_dates("min", dateval, dateval2, idx);
874 else
875 get_dates("min", "empty", "empty", idx);
876
877 if (datename=="year" || datename=="month" || datename=="day" || datename=="hour" || datename=="min")
878 if (datename=="min")
879 get_dates("sec", dateval, dateval2, idx);
880 else
881 get_dates("sec", "empty", "empty", idx);
882 }
883 if (val=="textinput")
884 document.getElementById('statusdate'+idx).value="";
885}
886
887function get_dates(datename, dateval, datevalprev, idx, reset)
888{
889 //alert(datename+"_"+dateval+"_"+datevalprev+"_"+idx);
890 statusdate=get_statusdate(idx);
891 //if (datename=="year")
892 // statusdate="";
893 //alert(datename+" === "+statusdate+" --- "+datevalprev);
894 phpcall="get_date.php?fDateValue="+dateval+"&fDateValuePrev="+datevalprev+"&fDateName="+datename+"&fIdx="+idx+"&fStatusDate="+statusdate;
895 //phpcall="get_date.php?fDateValue="+dateval+"&fDateValuePrev="+statusdate+"&fDateName="+datename+"&fIdx="+idx;
896 //alert(phpcall);
897 xmlhttp.open("GET",phpcall,false);
898 xmlhttp.send();
899 if (xmlhttp.readyState==4 && xmlhttp.status==200)
900 document.getElementById(datename+'select'+idx).innerHTML = xmlhttp.responseText;
901 else
902 document.getElementById(datename+'select'+idx).innerHTML = "argh";
903
904 //to be able to do no reset in case when the function is called from reset_dates()
905 if (reset)
906 reset_dates(datename, "empty", "empty", idx);
907}
908
909function set_statusdate(getvalcase, statusdate)
910{
911 //get info whether to get statusdate from pulldown or input
912 radio=document.getElementsByName('dateformat'+getvalcase);
913 for (i=0; i< radio.length; i++)
914 if (radio[i].checked)
915 val=radio[i].value;
916
917 if (val=="textinput")
918 {
919 document.getElementById('statusdate'+getvalcase).value=statusdate;
920 return
921 }
922
923 //val=="pulldown"
924 //reset date pulldowns
925 get_dates("year", "empty", "empty", getvalcase, "yes");
926
927 //whole string (YYYY-MM-DD hh:mm:ss)
928 if (statusdate=="")
929 return;
930
931 dates=statusdate.split("-",3);
932 //years
933 if (!dates[0])
934 return;
935 get_dates("year", dates[0], dates[0], getvalcase);
936
937 //months
938 if (!dates[1])
939 return;
940 get_dates("month", dates[1], dates[0], getvalcase);
941
942 //rest of string (DD hh:mm:ss)
943 if (!dates[2])
944 return;
945
946 rests=dates[2].split(" ",2);
947 //days
948 if (!rests[0])
949 return;
950 get_dates("day", rests[0], dates[1], getvalcase);
951
952 //rest of string (hh:mm:ss)
953 if (!rests[1])
954 return;
955
956 times=rests[1].split(":",3);
957 //hours
958 if (!times[0])
959 return;
960 get_dates("hour", times[0], rests[0], getvalcase);
961
962 //minutes
963 if (!times[1])
964 return;
965 get_dates("min", times[1], times[0], getvalcase);
966
967 //seconds
968 if (!times[2])
969 return;
970 get_dates("sec", times[2], times[1], getvalcase);
971}
972
973
974function get_timestamp(getvalcase, direction)
975{
976 statusdate=get_statusdate(getvalcase);
977
978 // get next or previous timestamp
979 xmlhttp.open("GET","get_timestamp.php?fStatusDate="+statusdate+"&fDirection="+direction,false);
980 xmlhttp.send();
981 if (xmlhttp.readyState==4 && xmlhttp.status==200)
982 newstatusdate = xmlhttp.responseText;
983 else
984 newstatusdate = "argh";
985
986 set_statusdate(getvalcase, newstatusdate);
987}
988
989function show_viewinfo()
990{
991 if (document.getElementById('showinfo').innerHTML=='Hide Info')
992 {
993 document.getElementById('viewinfo').style.display='none';
994 document.getElementById('showinfo').innerHTML='Show Info';
995 }
996 else
997 {
998 document.getElementById('viewinfo').style.display='';
999 document.getElementById('showinfo').innerHTML='Hide Info';
1000 }
1001
1002}
1003
Note: See TracBrowser for help on using the repository browser.