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

Last change on this file since 11600 was 11600, checked in by Daniela Dorner, 13 years ago
added user to displayed table
File size: 33.7 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 (!key2)
564 alert("Please insert key2!");
565 if (!val)
566 alert("Please insert value!");
567 if (!val || !descr || !key1 || !key2)
568 return;
569 if (index==0)
570 index=-1;
571 if (!type && (updcase==2 || updcase==3 || updcase==4))
572 {
573 alert("Please select type!");
574 return;
575 }
576
577 //check if value has correct type and is within ranges
578 // for string no check needed
579 if (updcase==3)
580 {
581 if (type=='int' && parseInt(val)!=val)
582 {
583 alert("Value is not a int.");
584 return;
585 }
586 if (type=='float' && parseFloat(val)!=val)
587 {
588 alert("Value is not a float.");
589 return;
590 }
591 if (type=='bool' && val!='yes' && val!='no')
592 {
593 alert("Value is neither 'yes' not 'no'.");
594 return;
595 }
596 // check ranges for int
597 if (type=='int' && parseInt(val)>parseInt(max))
598 {
599 alert("You cannot enter a value larger than "+max+".");
600 return;
601 }
602 if (type=='int' && parseInt(val)<parseInt(min))
603 {
604 alert("You cannot enter a value smaller than "+min+".");
605 return;
606 }
607 // check ranges for float
608 if (type=='float' && parseFloat(val)>parseFloat(max))
609 {
610 alert("You cannot enter a value larger than "+max+".");
611 return;
612 }
613 if (type=='float' && parseFloat(val)<parseFloat(min))
614 {
615 alert("You cannot enter a value smaller than "+min+".");
616 return;
617 }
618 }
619
620 if (!min && (type=='int' || type=='float'))
621 {
622 alert("Please insert minimum!");
623 return;
624 }
625 if (!max && (type=='int' || type=='float'))
626 {
627 alert("Please insert maximum!");
628 return;
629 }
630 //check if min/max have correct type
631 // for string no check needed
632 if (updcase==1 || updcase==5)
633 {
634 if (type=='int' && parseInt(min)!=min)
635 {
636 alert("Minimum is not a int.");
637 return;
638 }
639 if (type=='int' && parseInt(max)!=max)
640 {
641 alert("Maximum is not a int.");
642 return;
643 }
644 if (type=='float' && parseFloat(min)!=min)
645 {
646 alert("Minimum is not a float.");
647 return;
648 }
649 if (type=='float' && parseFloat(max)!=max)
650 {
651 alert("Maximum is not a float.");
652 return;
653 }
654 }
655
656 phpcall="insert_po.php?fUpdCase="+updcase+"&fIndex="+index+"&fOriginalIndex="+origindex
657 +"&fProgram="+prog+"&fKey1="+key1+"&fKey2="+key2+"&fValue="+val+"&fDescription="+descr
658 +"&fType="+type+"&fMin="+min+"&fMax="+max;
659 //alert(phpcall);
660
661 xmlhttp.open("GET", phpcall, false);
662 xmlhttp.send();
663
664 // get somehow return value of inser_po.php
665 // to catch cases where insert was rejected due to no update
666 if (xmlhttp.readyState==4 && xmlhttp.status==200)
667 {
668 if (xmlhttp.responseText=="no change")
669 {
670 alert("You didn't change anything.");
671 return;
672 }
673 if (xmlhttp.responseText=="key exists")
674 {
675 alert("This key already exists. You cannot insert it a second time.");
676 return;
677 }
678 if (xmlhttp.responseText=="prog exists")
679 {
680 alert("This program already exists. You cannot insert it a second time.");
681 return;
682 }
683 if (xmlhttp.responseText=="user empty")
684 {
685 alert("User name is missing. Please give a user name when logging in.");
686 return;
687 }
688 alert(xmlhttp.responseText);
689 }
690 else
691 alert("Mist! "+xmlhttp.responseText);
692
693 //reload the content of the page
694 progselect=document.getElementById("prog");
695 if (!progselect)
696 oldprog=prog;
697 else
698 if (progselect.options[progselect.selectedIndex])
699 oldprog=progselect.options[progselect.selectedIndex].value;
700 else
701 oldprog=prog;
702 keyselect=document.getElementById("key");
703 if (!keyselect)
704 oldkey=key1+"."+key2;
705 else
706 if (keyselect.options[keyselect.selectedIndex])
707 oldkey=keyselect.options[keyselect.selectedIndex].value;
708 else
709 oldkey=key1+"."+key2;
710 //reload progs and keys
711 get_progs(oldprog, "10", "edit");
712 get_keys(oldprog, oldkey, "10", "edit");
713 //reload values
714 xmlhttp.open("GET","get_values.php?fGetValCase=1&fKey="+oldkey+"&fProgram="+oldprog,false);
715 xmlhttp.send();
716 if (xmlhttp.readyState==4 && xmlhttp.status==200)
717 document.getElementById('valuefield1').innerHTML = xmlhttp.responseText;
718 else
719 document.getElementById('valuefield1').innerHTML = "argh";
720}
721
722function ShowCurrent()
723{
724 for (var i = 1 ; i <= document.getElementById('maxindex').innerHTML ; i++)
725 if(document.getElementById('old'+i))
726 document.getElementById('old'+i).style.display = "none";
727 document.getElementById('showcurrent').style.display = "none";
728 document.getElementById('showcurrent2').style.display = "none";
729 document.getElementById('showall').style.display = "";
730 document.getElementById('showall2').style.display = "";
731}
732
733function ShowAll()
734{
735 for (var i = 1 ; i <= document.getElementById('maxindex').innerHTML ; i++)
736 if(document.getElementById('old'+i))
737 {
738 document.getElementById('old'+i).style.display = "";
739 document.getElementById('old'+i).style.color = "grey";
740 }
741 document.getElementById('showcurrent').style.display = "";
742 document.getElementById('showcurrent2').style.display = "";
743 document.getElementById('showall').style.display = "none";
744 document.getElementById('showall2').style.display = "none";
745}
746
747function InsertRow(table, row)
748{
749 var x=document.getElementById('valtable'+table).insertRow(row);
750 y=x.insertCell(0);
751 y.colSpan='5';
752 y.innerHTML="&nbsp;";
753}
754
755function CompareValues()
756{
757 counter=0;
758 maxindex2=document.getElementById('maxindex').innerHTML;
759 maxindex3=document.getElementById('maxindex3').innerHTML;
760 if (parseInt(maxindex2)>parseInt(maxindex3))
761 maxindex=maxindex2;
762 else
763 maxindex=maxindex3;
764
765 for (var i = 1 ; i <= maxindex ; i++)
766 {
767 if (document.getElementById('2compare'+i))
768 {
769 counter++;
770 if (!document.getElementById('3compare'+i))
771 {
772 InsertRow(3,counter);
773 document.getElementById('2compare'+i).style.color='red';
774 }
775 else
776 {
777 val2=document.getElementById('2compare'+i).cells[5].innerHTML;
778 val3=document.getElementById('3compare'+i).cells[5].innerHTML;
779 if (val2!=val3)
780 {
781 document.getElementById('2compare'+i).style.color='blue';
782 document.getElementById('3compare'+i).style.color='blue';
783 }
784 }
785 }
786 else
787 if (document.getElementById('3compare'+i))
788 {
789 counter++;
790 InsertRow(2,counter);
791 document.getElementById('3compare'+i).style.color='green';
792 }
793 }
794 //document.getElementById('comparevals').style.display = "none";
795
796 //reload all setting for show-menu
797 ShowHide('indices', 'sh_indices', 2)
798 ShowHide('indices', 'sh_indices', 3)
799 ShowHide('description', 'sh_descr', 2)
800 ShowHide('description', 'sh_descr', 3)
801 ShowHide('validsince', 'sh_validsince', 2)
802 ShowHide('validsince', 'sh_validsince', 3)
803 ShowHide('minimum', 'sh_min', 2)
804 ShowHide('minimum', 'sh_min', 3)
805 ShowHide('maximum', 'sh_max', 2)
806 ShowHide('maximum', 'sh_max', 3)
807 ShowHide('user', 'sh_user', 2)
808 ShowHide('user', 'sh_user', 3)
809}
810
811function ShowHide(column, idname, getvalcase)
812{
813 box=document.getElementById(idname+getvalcase);
814 text=box.checked? '':'none';
815
816 for(var i=0;i<document.getElementsByTagName('*').length;i++)
817 if(document.getElementsByTagName('*')[i].className == column+getvalcase)
818 document.getElementsByTagName('*')[i].style.display = text;
819}
820
821function ShowDateInput(idx)
822{
823 document.getElementById('datepulldown'+idx).style.display = "none";
824 document.getElementById('dateinput'+idx).style.display = "";
825 set_statusdate(idx, get_statusdate(idx, 'pulldown'));
826}
827
828function ShowDatePulldown(idx)
829{
830 document.getElementById('datepulldown'+idx).style.display = "";
831 document.getElementById('dateinput'+idx).style.display = "none";
832 set_statusdate(idx, get_statusdate(idx, 'textinput'));
833}
834
835function reset_dates(datename, dateval, dateval2, idx)
836{
837 radio=document.getElementsByName('dateformat'+idx);
838 for (i=0; i< radio.length; i++)
839 if (radio[i].checked)
840 val=radio[i].value;
841 if (val=="pulldown")
842 {
843 //alert("reset:"+datename+"-"+dateval+"-"+dateval2+"-"+idx);
844 if (datename=="year")
845 {
846 get_dates("year", dateval, dateval2, idx);
847 get_dates("month", dateval, dateval2, idx);
848 }
849
850 if (datename=="year" || datename=="month")
851 if (datename=="month")
852 get_dates("day", dateval, dateval2, idx);
853 else
854 get_dates("day", "empty", "empty", idx);
855
856 if (datename=="year" || datename=="month" || datename=="day")
857 if (datename=="day")
858 get_dates("hour", dateval, dateval2, idx);
859 else
860 get_dates("hour", "empty", "empty", idx);
861
862 if (datename=="year" || datename=="month" || datename=="day" || datename=="hour")
863 if (datename=="hour")
864 get_dates("min", dateval, dateval2, idx);
865 else
866 get_dates("min", "empty", "empty", idx);
867
868 if (datename=="year" || datename=="month" || datename=="day" || datename=="hour" || datename=="min")
869 if (datename=="min")
870 get_dates("sec", dateval, dateval2, idx);
871 else
872 get_dates("sec", "empty", "empty", idx);
873 }
874 if (val=="textinput")
875 document.getElementById('statusdate'+idx).value="";
876}
877
878function get_dates(datename, dateval, datevalprev, idx, reset)
879{
880 //alert(datename+"_"+dateval+"_"+datevalprev+"_"+idx);
881 statusdate=get_statusdate(idx);
882 //if (datename=="year")
883 // statusdate="";
884 //alert(datename+" === "+statusdate+" --- "+datevalprev);
885 phpcall="get_date.php?fDateValue="+dateval+"&fDateValuePrev="+datevalprev+"&fDateName="+datename+"&fIdx="+idx+"&fStatusDate="+statusdate;
886 //phpcall="get_date.php?fDateValue="+dateval+"&fDateValuePrev="+statusdate+"&fDateName="+datename+"&fIdx="+idx;
887 //alert(phpcall);
888 xmlhttp.open("GET",phpcall,false);
889 xmlhttp.send();
890 if (xmlhttp.readyState==4 && xmlhttp.status==200)
891 document.getElementById(datename+'select'+idx).innerHTML = xmlhttp.responseText;
892 else
893 document.getElementById(datename+'select'+idx).innerHTML = "argh";
894
895 //to be able to do no reset in case when the function is called from reset_dates()
896 if (reset)
897 reset_dates(datename, "empty", "empty", idx);
898}
899
900function set_statusdate(getvalcase, statusdate)
901{
902 //get info whether to get statusdate from pulldown or input
903 radio=document.getElementsByName('dateformat'+getvalcase);
904 for (i=0; i< radio.length; i++)
905 if (radio[i].checked)
906 val=radio[i].value;
907
908 if (val=="textinput")
909 {
910 document.getElementById('statusdate'+getvalcase).value=statusdate;
911 return
912 }
913
914 //val=="pulldown"
915 //reset date pulldowns
916 get_dates("year", "empty", "empty", getvalcase, "yes");
917
918 //whole string (YYYY-MM-DD hh:mm:ss)
919 if (statusdate=="")
920 return;
921
922 dates=statusdate.split("-",3);
923 //years
924 if (!dates[0])
925 return;
926 get_dates("year", dates[0], dates[0], getvalcase);
927
928 //months
929 if (!dates[1])
930 return;
931 get_dates("month", dates[1], dates[0], getvalcase);
932
933 //rest of string (DD hh:mm:ss)
934 if (!dates[2])
935 return;
936
937 rests=dates[2].split(" ",2);
938 //days
939 if (!rests[0])
940 return;
941 get_dates("day", rests[0], dates[1], getvalcase);
942
943 //rest of string (hh:mm:ss)
944 if (!rests[1])
945 return;
946
947 times=rests[1].split(":",3);
948 //hours
949 if (!times[0])
950 return;
951 get_dates("hour", times[0], rests[0], getvalcase);
952
953 //minutes
954 if (!times[1])
955 return;
956 get_dates("min", times[1], times[0], getvalcase);
957
958 //seconds
959 if (!times[2])
960 return;
961 get_dates("sec", times[2], times[1], getvalcase);
962}
963
964
965function get_timestamp(getvalcase, direction)
966{
967 statusdate=get_statusdate(getvalcase);
968
969 // get next or previous timestamp
970 xmlhttp.open("GET","get_timestamp.php?fStatusDate="+statusdate+"&fDirection="+direction,false);
971 xmlhttp.send();
972 if (xmlhttp.readyState==4 && xmlhttp.status==200)
973 newstatusdate = xmlhttp.responseText;
974 else
975 newstatusdate = "argh";
976
977 set_statusdate(getvalcase, newstatusdate);
978}
979
980function show_viewinfo()
981{
982 if (document.getElementById('showinfo').innerHTML=='Hide Info')
983 {
984 document.getElementById('viewinfo').style.display='none';
985 document.getElementById('showinfo').innerHTML='Show Info';
986 }
987 else
988 {
989 document.getElementById('viewinfo').style.display='';
990 document.getElementById('showinfo').innerHTML='Hide Info';
991 }
992
993}
994
Note: See TracBrowser for help on using the repository browser.