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

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