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

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