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

Last change on this file since 19598 was 13322, checked in by Daniela Dorner, 13 years ago
bugfix for date pulldowns
File size: 36.3 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, mode)
13{
14 xmlhttp.open("GET","get_progs.php?fProgram="+prog+"&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, mode)
29{
30 xmlhttp.open("GET","get_keys.php?fProgram="+prog+"&fKey="+key+"&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, "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 = 300;
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 = 200;
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 = 200;
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 = 200;
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 size='30' 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 size='40' align='right' id='newdescr"+index+"' value='"+olddescr+"'>";
476 if (oldtype=='int' || oldtype=='float')
477 {
478 document.getElementById('min'+index).innerHTML = "<input size='5' align='right' id='newmin"+index+"' value='"+oldmin+"'>";
479 document.getElementById('max'+index).innerHTML = "<input size='5' align='right' id='newmax"+index+"' value='"+oldmax+"'>";
480 }
481 /*
482 //set field for type
483 typeselecttext="<select id='newtype"+index+"' value='"+oldtype+"'>"+"<option>-</option>";
484 if (oldtype=='int')
485 typeselecttext=typeselecttext+"<option selected>int</option>";
486 else
487 typeselecttext=typeselecttext+"<option>int</option>";
488 if (oldtype=='float')
489 typeselecttext=typeselecttext+"<option selected>float</option>";
490 else
491 typeselecttext=typeselecttext+"<option>float</option>";
492 if (oldtype=='string')
493 typeselecttext=typeselecttext+"<option selected>string</option>";
494 else
495 typeselecttext=typeselecttext+"<option>string</option>";
496 if (oldtype=='bool')
497 typeselecttext=typeselecttext+"<option selected>bool</option>";
498 else
499 typeselecttext=typeselecttext+"<option>bool</option>";
500 typeselecttext=typeselecttext+"</select>";
501 document.getElementById('type'+index).innerHTML = typeselecttext;
502 */
503
504 //set field for action
505 actiontext="<input type='button' value='Update' onclick='UpdateRow(3,"+index+")'>";
506 notyetvalid=document.getElementById('notyetvalid'+index)
507 if (delcase!=6 || notyetvalid)
508 actiontext=actiontext+"<input type='button' value='Delete' onclick='UpdateRow("+delcase+","+index+")'>";
509 actiontext=actiontext+"<input type='button' value='Cancel' onclick='CancelUpdate()'>";
510 document.getElementById('action'+index).innerHTML =actiontext;
511}
512
513function UpdateRow(updcase,index)
514{
515 // five cases of update corresponds to
516 // 5: add new prog + key addcase 1
517 // 1: add new key addcase 2
518 // 2: add new val (for same key) addcase 3 -> same type,min,max
519 // 3: edit val -> same type,min,max
520 // 4: delete val (ie set to NULL) -> same type,min,max
521 // 6: delete new key (ie val still NULL) -> real delete
522 descr=document.getElementById('newdescr'+index).value;
523 origindex=0;
524 switch(updcase)
525 {
526 case 5:
527 prog=document.getElementById('prog'+index).value;
528 key1=document.getElementById('1key'+index).value;
529 key2=document.getElementById('2key'+index).value;
530 val=document.getElementById('newval'+index).innerHTML;
531 type=document.getElementById('newtype'+index).value;
532 min=document.getElementById('newmin'+index).value;
533 max=document.getElementById('newmax'+index).value;
534 break;
535 case 1:
536 //prog=document.getElementById('prog'+index).value;
537 prog=document.getElementById('prog'+index).innerHTML;
538 key1=document.getElementById('1key'+index).value;
539 key2=document.getElementById('2key'+index).value;
540 val=document.getElementById('newval'+index).innerHTML;
541 type=document.getElementById('newtype'+index).value;
542 min=document.getElementById('newmin'+index).value;
543 max=document.getElementById('newmax'+index).value;
544 break;
545 case 2:
546 //prog=document.getElementById('prog'+index).value;
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 type=document.getElementById('type'+index).innerHTML;
552 min=document.getElementById('min'+index).innerHTML;
553 max=document.getElementById('max'+index).innerHTML;
554 break;
555 case 3:
556 prog=document.getElementById('prog'+index).innerHTML;
557 key1=document.getElementById('1key'+index).innerHTML;
558 key2=document.getElementById('2key'+index).innerHTML;
559 type=document.getElementById('type'+index).innerHTML;
560 // changed to make min/max editable
561 if (type=='int' || type=='float')
562 {
563 min=document.getElementById('newmin'+index).value;
564 max=document.getElementById('newmax'+index).value;
565 }
566 else
567 {
568 min=document.getElementById('min'+index).innerHTML;
569 max=document.getElementById('max'+index).innerHTML;
570 }
571 val="hallo";
572 if (type=="bool")
573 {
574 radio=document.getElementsByName('boolbox');
575 for (i=0; i< radio.length; i++)
576 if (radio[i].checked)
577 val=radio[i].value;
578 }
579 else
580 val=document.getElementById('newval'+index).value;
581 origindex=document.getElementById('1origindex'+index).innerHTML;
582 break;
583 case 4:
584 case 6:
585 answer = confirm("Do you really want to delete the value?");
586 if (!answer)
587 return;
588 prog=document.getElementById('prog'+index).innerHTML;
589 key1=document.getElementById('1key'+index).innerHTML;
590 key2=document.getElementById('2key'+index).innerHTML;
591 val=document.getElementById('newval'+index).value;
592 if (!val)
593 val="NULL";
594 type=document.getElementById('type'+index).innerHTML;
595 min=document.getElementById('min'+index).innerHTML;
596 max=document.getElementById('max'+index).innerHTML;
597 origindex=document.getElementById('1origindex'+index).innerHTML;
598 break;
599 }
600 if (!descr)
601 alert("Please insert description!");
602 if (!key1)
603 alert("Please insert key1!");
604 if (!val)
605 alert("Please insert value!");
606 if (!val || !descr || !key1)
607 return;
608 if (index==0)
609 index=-1;
610 if (!type && (updcase==2 || updcase==3 || updcase==4))
611 {
612 alert("Please select type!");
613 return;
614 }
615
616 //check if value has correct type and is within ranges
617 // for string no check needed
618 if (updcase==3)
619 {
620 if (type=='int' && parseInt(val)!=val)
621 {
622 alert("Value is not a int.");
623 return;
624 }
625 if (type=='float' && parseFloat(val)!=val)
626 {
627 alert("Value is not a float.");
628 return;
629 }
630 if (type=='bool' && val!='yes' && val!='no')
631 {
632 alert("Value is neither 'yes' not 'no'.");
633 return;
634 }
635 // check ranges for int
636 if (max && type=='int' && parseInt(val)>parseInt(max))
637 {
638 alert("You cannot enter a value larger than "+max+".");
639 return;
640 }
641 if (min && type=='int' && parseInt(val)<parseInt(min))
642 {
643 alert("You cannot enter a value smaller than "+min+".");
644 return;
645 }
646 // check ranges for float
647 if (max && type=='float' && parseFloat(val)>parseFloat(max))
648 {
649 alert("You cannot enter a value larger than "+max+".");
650 return;
651 }
652 if (min && type=='float' && parseFloat(val)<parseFloat(min))
653 {
654 alert("You cannot enter a value smaller than "+min+".");
655 return;
656 }
657 }
658
659 /*
660 if (!min && (type=='int' || type=='float'))
661 {
662 alert("Please insert minimum!");
663 return;
664 }
665 if (!max && (type=='int' || type=='float'))
666 {
667 alert("Please insert maximum!");
668 return;
669 }
670 */
671 //check if min/max have correct type
672 // for string no check needed
673 if (updcase==1 || updcase==5)
674 {
675 if (min && type=='int' && parseInt(min)!=min)
676 {
677 alert("Minimum is not a int.");
678 return;
679 }
680 if (max && type=='int' && parseInt(max)!=max)
681 {
682 alert("Maximum is not a int.");
683 return;
684 }
685 if (min && type=='float' && parseFloat(min)!=min)
686 {
687 alert("Minimum is not a float.");
688 return;
689 }
690 if (max && type=='float' && parseFloat(max)!=max)
691 {
692 alert("Maximum is not a float.");
693 return;
694 }
695 if (min && max && type=='float' && parseFloat(max)<parseFloat(min))
696 {
697 alert("Maximum cannot be smaller than minimum.");
698 return;
699 }
700 if (min && max && type=='int' && parseInt(max)<parseInt(min))
701 {
702 alert("Maximum cannot be smaller than minimum.");
703 return;
704 }
705 }
706
707 phpcall="insert_po.php?fMode=edit&fUpdCase="+updcase+"&fIndex="+index+"&fOriginalIndex="+origindex
708 +"&fProgram="+prog+"&fKey1="+key1+"&fKey2="+key2+"&fValue="+val+"&fDescription="+descr
709 +"&fType="+type+"&fMin="+min+"&fMax="+max;
710 //alert(phpcall);
711
712 xmlhttp.open("GET", phpcall, false);
713 xmlhttp.send();
714
715 // get somehow return value of inser_po.php
716 // to catch cases where insert was rejected due to no update
717 if (xmlhttp.readyState==4 && xmlhttp.status==200)
718 {
719 if (xmlhttp.responseText=="no change")
720 {
721 alert("You didn't change anything.");
722 return;
723 }
724 if (xmlhttp.responseText=="key exists")
725 {
726 alert("This key already exists. You cannot insert it a second time.");
727 return;
728 }
729 if (xmlhttp.responseText=="prog exists")
730 {
731 alert("This program already exists. You cannot insert it a second time.");
732 return;
733 }
734 if (xmlhttp.responseText=="user empty")
735 {
736 alert("User name is missing. Please give a user name when logging in.");
737 return;
738 }
739 if (xmlhttp.responseText=="type empty")
740 {
741 alert("Type is missing. Please select a type.");
742 return;
743 }
744 alert(xmlhttp.responseText);
745 }
746 else
747 alert("Mist! "+xmlhttp.responseText);
748
749 //reload the content of the page
750 /*
751 progselect=document.getElementById("prog");
752 if (!progselect)
753 oldprog=prog;
754 else
755 if (progselect.selectedIndex>=0)
756 oldprog=progselect.options[progselect.selectedIndex].value;
757 else
758 oldprog=prog;
759 keyselect=document.getElementById("key");
760 if (!keyselect)
761 oldkey=key1+"."+key2;
762 else
763 if (keyselect.selectedIndex>=0)
764 oldkey=keyselect.options[keyselect.selectedIndex].value;
765 else
766 oldkey=key1+"."+key2;
767 */
768 //reload content of page for the values of prog and key1.key2
769 // which were just edited/added
770 oldprog=prog;
771 if (key2)
772 oldkey=key1+"."+key2;
773 else
774 oldkey=key1;
775 //reload progs and keys
776 get_progs(oldprog, "edit");
777 get_keys(oldprog, oldkey, "edit");
778 //reload values
779 xmlhttp.open("GET","get_values.php?fGetValCase=1&fKey="+oldkey+"&fProgram="+oldprog,false);
780 xmlhttp.send();
781 if (xmlhttp.readyState==4 && xmlhttp.status==200)
782 document.getElementById('valuefield1').innerHTML = xmlhttp.responseText;
783 else
784 document.getElementById('valuefield1').innerHTML = "argh";
785}
786
787function ShowCurrent()
788{
789 for (var i = 1 ; i <= document.getElementById('maxindex').innerHTML ; i++)
790 if(document.getElementById('old'+i))
791 document.getElementById('old'+i).style.display = "none";
792 document.getElementById('showcurrent').style.display = "none";
793 document.getElementById('showcurrent2').style.display = "none";
794 document.getElementById('showall').style.display = "";
795 document.getElementById('showall2').style.display = "";
796}
797
798function ShowAll()
799{
800 for (var i = 1 ; i <= document.getElementById('maxindex').innerHTML ; i++)
801 if(document.getElementById('old'+i))
802 {
803 document.getElementById('old'+i).style.display = "";
804 document.getElementById('old'+i).style.color = "grey";
805 }
806 document.getElementById('showcurrent').style.display = "";
807 document.getElementById('showcurrent2').style.display = "";
808 document.getElementById('showall').style.display = "none";
809 document.getElementById('showall2').style.display = "none";
810}
811
812function InsertRow(table, row)
813{
814 var x=document.getElementById('valtable'+table).insertRow(row);
815 y=x.insertCell(0);
816 y.colSpan='5';
817 y.innerHTML="&nbsp;";
818}
819
820function CompareValues()
821{
822 counter=0;
823 maxindex2=document.getElementById('maxindex').innerHTML;
824 maxindex3=document.getElementById('maxindex3').innerHTML;
825 if (parseInt(maxindex2)>parseInt(maxindex3))
826 maxindex=maxindex2;
827 else
828 maxindex=maxindex3;
829
830 for (var i = 1 ; i <= maxindex ; i++)
831 {
832 if (document.getElementById('2compare'+i))
833 {
834 counter++;
835 if (!document.getElementById('3compare'+i))
836 {
837 InsertRow(3,counter);
838 document.getElementById('2compare'+i).style.color='red';
839 }
840 else
841 {
842 val2=document.getElementById('2compare'+i).cells[5].innerHTML;
843 val3=document.getElementById('3compare'+i).cells[5].innerHTML;
844 if (val2!=val3)
845 {
846 document.getElementById('2compare'+i).style.color='blue';
847 document.getElementById('3compare'+i).style.color='blue';
848 }
849 }
850 }
851 else
852 if (document.getElementById('3compare'+i))
853 {
854 counter++;
855 InsertRow(2,counter);
856 document.getElementById('3compare'+i).style.color='green';
857 }
858 }
859 //document.getElementById('comparevals').style.display = "none";
860
861 //reload all setting for show-menu
862 ShowHide('indices', 'sh_indices', 2)
863 ShowHide('indices', 'sh_indices', 3)
864 ShowHide('description', 'sh_descr', 2)
865 ShowHide('description', 'sh_descr', 3)
866 ShowHide('validsince', 'sh_validsince', 2)
867 ShowHide('validsince', 'sh_validsince', 3)
868 ShowHide('minimum', 'sh_min', 2)
869 ShowHide('minimum', 'sh_min', 3)
870 ShowHide('maximum', 'sh_max', 2)
871 ShowHide('maximum', 'sh_max', 3)
872 ShowHide('user', 'sh_user', 2)
873 ShowHide('user', 'sh_user', 3)
874}
875
876function ShowHide(column, idname, getvalcase)
877{
878 box=document.getElementById(idname+getvalcase);
879 text=box.checked? '':'none';
880
881 for(var i=0;i<document.getElementsByTagName('*').length;i++)
882 if(document.getElementsByTagName('*')[i].className == column+getvalcase)
883 document.getElementsByTagName('*')[i].style.display = text;
884}
885
886function ShowDateInput(idx)
887{
888 document.getElementById('datepulldown'+idx).style.display = "none";
889 document.getElementById('dateinput'+idx).style.display = "inline";
890 set_statusdate(idx, get_statusdate(idx, 'pulldown'));
891}
892
893function ShowDatePulldown(idx)
894{
895 document.getElementById('datepulldown'+idx).style.display = "inline";
896 document.getElementById('dateinput'+idx).style.display = "none";
897 set_statusdate(idx, get_statusdate(idx, 'textinput'));
898}
899
900function reset_dates(datename, dateval, dateval2, idx)
901{
902 radio=document.getElementsByName('dateformat'+idx);
903 for (i=0; i< radio.length; i++)
904 if (radio[i].checked)
905 val=radio[i].value;
906 if (val=="pulldown")
907 {
908 /*
909 alert("reset:"+datename+"-"+dateval+"-"+dateval2+"-"+idx);
910 if (datename=="year")
911 {
912 get_dates("year", dateval, dateval2, idx);
913 get_dates("month", dateval, dateval2, idx);
914 }
915
916 if (datename=="year" || datename=="month")
917 if (datename=="month")
918 get_dates("day", dateval, dateval2, idx);
919 else
920 get_dates("day", "empty", "empty", idx);
921
922 if (datename=="year" || datename=="month" || datename=="day")
923 if (datename=="day")
924 get_dates("hour", dateval, dateval2, idx);
925 else
926 get_dates("hour", "empty", "empty", idx);
927
928 if (datename=="year" || datename=="month" || datename=="day" || datename=="hour")
929 if (datename=="hour")
930 get_dates("min", dateval, dateval2, idx);
931 else
932 get_dates("min", "empty", "empty", idx);
933
934 if (datename=="year" || datename=="month" || datename=="day" || datename=="hour" || datename=="min")
935 if (datename=="min")
936 get_dates("sec", dateval, dateval2, idx);
937 else
938 get_dates("sec", "empty", "empty", idx);
939 */
940
941 if (datename=="year")
942 {
943 get_dates("year", "empty", "empty", idx);
944 get_dates("month", "empty", "empty", idx);
945 }
946 if (datename=="year" || datename=="month")
947 get_dates("day", "empty", "empty", idx);
948 if (datename=="year" || datename=="month" || datename=="day")
949 get_dates("hour", "empty", "empty", idx);
950 if (datename=="year" || datename=="month" || datename=="day" || datename=="hour")
951 get_dates("min", "empty", "empty", idx);
952 if (datename=="year" || datename=="month" || datename=="day" || datename=="hour" || datename=="min")
953 get_dates("sec", "empty", "empty", idx);
954 }
955 if (val=="textinput")
956 document.getElementById('statusdate'+idx).value="";
957}
958
959function get_dates(datename, dateval, datevalprev, idx, reset)
960{
961 //alert(datename+"_"+dateval+"_"+datevalprev+"_"+idx);
962 statusdate=get_statusdate(idx);
963 //if (datename=="year")
964 // statusdate="";
965 //alert(datename+" === "+statusdate+" --- "+datevalprev);
966 phpcall="get_date.php?fDateValue="+dateval+"&fDateValuePrev="+datevalprev+"&fDateName="+datename+"&fIdx="+idx+"&fStatusDate="+statusdate;
967 //phpcall="get_date.php?fDateValue="+dateval+"&fDateValuePrev="+statusdate+"&fDateName="+datename+"&fIdx="+idx;
968 //alert(phpcall);
969 xmlhttp.open("GET",phpcall,false);
970 xmlhttp.send();
971 if (xmlhttp.readyState==4 && xmlhttp.status==200)
972 document.getElementById(datename+'select'+idx).innerHTML = xmlhttp.responseText;
973 else
974 document.getElementById(datename+'select'+idx).innerHTML = "argh";
975
976 //to be able to do no reset in case when the function is called from reset_dates()
977 if (reset)
978 reset_dates(datename, "empty", "empty", idx);
979}
980
981function set_statusdate(getvalcase, statusdate)
982{
983 //get info whether to get statusdate from pulldown or input
984 radio=document.getElementsByName('dateformat'+getvalcase);
985 for (i=0; i< radio.length; i++)
986 if (radio[i].checked)
987 val=radio[i].value;
988
989 if (val=="textinput")
990 {
991 document.getElementById('statusdate'+getvalcase).value=statusdate;
992 return
993 }
994
995 //val=="pulldown"
996 //reset date pulldowns
997 get_dates("year", "empty", "empty", getvalcase, "yes");
998
999 //whole string (YYYY-MM-DD hh:mm:ss)
1000 if (statusdate=="")
1001 return;
1002
1003 dates=statusdate.split("-",3);
1004 //years
1005 if (!dates[0])
1006 return;
1007 get_dates("year", dates[0], dates[0], getvalcase);
1008
1009 //months
1010 if (!dates[1])
1011 return;
1012 get_dates("month", dates[1], dates[0], getvalcase);
1013
1014 //rest of string (DD hh:mm:ss)
1015 if (!dates[2])
1016 return;
1017
1018 rests=dates[2].split(" ",2);
1019 //days
1020 if (!rests[0])
1021 return;
1022 get_dates("day", rests[0], dates[1], getvalcase);
1023
1024 //rest of string (hh:mm:ss)
1025 if (!rests[1])
1026 return;
1027
1028 times=rests[1].split(":",3);
1029 //hours
1030 if (!times[0])
1031 return;
1032 get_dates("hour", times[0], rests[0], getvalcase);
1033
1034 //minutes
1035 if (!times[1])
1036 return;
1037 get_dates("min", times[1], times[0], getvalcase);
1038
1039 //seconds
1040 if (!times[2])
1041 return;
1042 get_dates("sec", times[2], times[1], getvalcase);
1043}
1044
1045
1046function get_timestamp(getvalcase, direction)
1047{
1048 statusdate=get_statusdate(getvalcase);
1049
1050 // get next or previous timestamp
1051 xmlhttp.open("GET","get_timestamp.php?fStatusDate="+statusdate+"&fDirection="+direction,false);
1052 xmlhttp.send();
1053 if (xmlhttp.readyState==4 && xmlhttp.status==200)
1054 newstatusdate = xmlhttp.responseText;
1055 else
1056 newstatusdate = "argh";
1057
1058 set_statusdate(getvalcase, newstatusdate);
1059}
1060
1061function show_viewinfo()
1062{
1063 if (document.getElementById('showinfo').innerHTML=='Hide Info')
1064 {
1065 document.getElementById('viewinfo').style.display='none';
1066 document.getElementById('showinfo').innerHTML='Show Info';
1067 }
1068 else
1069 {
1070 document.getElementById('viewinfo').style.display='';
1071 document.getElementById('showinfo').innerHTML='Hide Info';
1072 }
1073
1074}
1075
Note: See TracBrowser for help on using the repository browser.