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

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