source: schedule/function/SplitDelete.php@ 16918

Last change on this file since 16918 was 16918, checked in by tanio, 11 years ago
File size: 29.6 KB
Line 
1<script type="text/javascript">
2 $(document).ready(function(){
3 var name;
4var value;
5 var timeValue;
6var meas;
7var meas2;
8var x=0;
9var measurement=0;
10var getTableId;
11var is=0;
12 window.cnt=0;
13 var x = 0;
14 <?php
15 include '../include/factdb.php';
16 if(isset($_GET['days']))
17 {
18 $day = $_GET['days'];
19 }
20 else
21 {
22 $day =date("Y-m-d");
23 }
24 $days = Date('Y-m-d',strtotime($day));
25 $fetch = mysql_query("SELECT * FROM schedule ORDER BY fScheduleID ASC") or die(mysql_error());
26 while($rows = mysql_fetch_array($fetch))
27 {
28 $timestamp=strtotime($rows['fStart']);
29 $timestamp2 = date('Y-m-d',$timestamp);
30 $date_time = date('H:i',$timestamp);
31
32 if($days == $timestamp2)
33 {
34 ?>
35 cnt++;
36
37 $('#save').attr('value','UPDATE');
38
39
40 var div= document.createElement("div");
41 div.setAttribute('id','TableHolder');
42 var table = document.createElement("table");
43 table.setAttribute('id',"table"+cnt);
44 table.setAttribute('width','100%');
45 var tr = document.createElement('tr');
46 var td3=document.createElement('td');
47 td3.setAttribute('style','border:1px solid white; color:#37DFB1; font-size:14px; text-align:center;');
48 td3.appendChild(
49 input = document.createElement("input"),
50 input.setAttribute("type","time"),
51 input.setAttribute("id","Time"),
52 input.setAttribute("max","24"),
53 input.setAttribute("min","1"),
54 input.setAttribute("required",true),
55 input.setAttribute("value",'<?php echo $date_time; ?>')
56
57 );
58 td3.appendChild(
59 button=document.createElement('input'),
60 button.setAttribute('type','button'),
61 button.setAttribute('value','[+]'),
62 button.setAttribute('id','btnAddTime'),
63 button.setAttribute('name','#table'+cnt),
64 button.onclick=function(){
65
66
67
68 if($('#Time').val() != ""){ var splitting = $('#Time').val().split(':'); var add = 01;
69
70 timeValue = pad((Number(splitting[0]) + Number(add)),2)+':'+splitting[1];
71
72 function pad(number, length) {
73
74 var str = '' + number;
75 while (str.length < length) {
76 str = '0' + str;
77 }
78
79 return str;
80
81 }
82 var s = 0; var get;
83 var nn;
84 nn = $(this).attr('name');
85 $("table").each(function() {
86 if($(this).attr("name")==nn){
87
88 get = "#"+$(this).attr("id");
89 //get = $(this).attr("name");
90 s =1;
91 }else{
92 if(s==0){
93 get = '#table'+cnt;
94 }
95 }
96 });
97
98
99
100 getTableId =get;
101
102
103 name="name"; value=""; meas = "name"; meas2 = "time"; //getTableId = $(this).attr('name');
104 split1(); }else{ alert("please enter value for time to add measurement"); }
105
106
107 }
108 );
109 var td=document.createElement('td');
110 td.setAttribute("style","border:1px solid white; color:#37DFB1; font-size:14px;text-align:center;");
111 td.appendChild(
112 sourcecbo= document.createElement('select'),
113 sourcecbo.setAttribute('id','source'),
114 <?php
115 $source=mysql_query("SELECT*FROM source");
116 while($rowsource=mysql_fetch_array($source))
117 {
118 ?>
119 sourcecbo.appendChild(
120 option=document.createElement('option'),
121
122 option.setAttribute('value','<?php echo $rowsource['fSourceKEY']; ?>'),
123 <?php if($rows['fSourceKey'] == $rowsource['fSourceKEY']){ echo"option.setAttribute('selected',true),"; } ?>
124
125
126 option.appendChild(document.createTextNode("<?php echo $rowsource['fSourceName']; ?>"))
127
128
129 ),
130 <?php
131 }
132 ?>
133 sourcecbo.setAttribute('id','source')
134
135 );
136 var td1=document.createElement('td');
137 td1.setAttribute("style","border:1px solid white; color:#37DFB1; font-size:14px;text-align:center;");
138 td1.appendChild(
139 measurementcbo= document.createElement('select'),
140 measurementcbo.setAttribute('id','measurement'),
141 <?php
142 $measure=mysql_query("SELECT*FROM measurement");
143 while($rowmeasure=mysql_fetch_array($measure))
144 {
145 ?>
146 measurementcbo.appendChild(
147 option=document.createElement('option'),
148 option.setAttribute('value','<?php echo $rowmeasure['fMeasurementKey']; ?>'),
149
150 <?php if($rows['fMeasurementTypeKey']==$rowmeasure['fMeasurementKey']){ echo "option.setAttribute('selected',true),";} ?>
151
152 option.appendChild(document.createTextNode("<?php echo $rowmeasure['fMeasurement']; ?>"))
153 ),
154 <?php
155 }
156 ?>
157 measurementcbo.setAttribute('id','measurement')
158 );
159 td1.appendChild(
160 button=document.createElement('input'),
161 button.setAttribute('type','button'),
162 button.setAttribute('value','[+]'),
163 button.setAttribute('id','btnAddTime'),
164 button.setAttribute('name','#table'+cnt),
165 button.onclick=function(){
166 if($('#Time').val() != ""){ timeValue = $('#Time').val(); name="name"; value=$(this).attr('name'); meas = "hidden"; meas2 = true; is=1; getTableId = $(this).attr('name'); split1(); }else{ alert("please enter value for time to add measurement"); }
167
168
169 }
170 );
171 var td2=document.createElement('td');
172 td2.setAttribute("style","border:1px solid white; color:#37DFB1; font-size:14px; text-align:center;");
173 td2.appendChild(
174 input = document.createElement('input'),
175 input.setAttribute('type','text'),
176 input.setAttribute('id','txtData'),
177 input.setAttribute('value','<?php echo $rows['fData']; ?>')
178
179
180 );
181 var td4=document.createElement('td');
182 td4.setAttribute("style","border:1px solid white; color:#37DFB1; font-size:14px; text-align:center;");
183 td4.appendChild(
184 button=document.createElement('input'),
185 button.setAttribute('type','button'),
186 button.setAttribute('value','Delete'),
187 button.setAttribute('id','btnDelete'),
188 button.onclick=function(){
189 $('#table'+cnt).remove();
190 }
191 );
192
193 tr.appendChild(td3);
194 tr.appendChild(td1);
195 tr.appendChild(td);
196
197 tr.appendChild(td2);
198 tr.appendChild(td4);
199 table.appendChild(tr);
200 div.appendChild(table);
201 $('#TableH1').append(div);
202
203 <?php
204 }
205 }
206 ?>
207
208 if(cnt==0)
209 {
210 $('#save').attr('value','SAVE');
211 var div= document.createElement("div");
212 div.setAttribute('id','TableHolder');
213 var table = document.createElement("table");
214 table.setAttribute('id',"table2");
215 table.setAttribute('width','100%');
216 table.setAttribute('name','#table2');
217 var tr = document.createElement('tr');
218 tr.setAttribute('id','');
219 tr.setAttribute('class','');
220 var td3=document.createElement('td');
221 td3.setAttribute('style','border:1px solid white; color:#37DFB1; font-size:14px; text-align:center;');
222 td3.appendChild(
223 input = document.createElement("input"),
224 input.setAttribute("type","time"),
225 input.setAttribute("id","Time"),
226 input.setAttribute("max","24"),
227 input.setAttribute("min","1"),
228 input.setAttribute("required",true),
229 input.onkeyup = function(){
230
231
232
233
234 if($('div#TableHolder #table2 #Time').val() <= 0 || $('div#TableHolder #table1 #Time').val() <=0){
235
236
237 }else{
238 if($('div#TableHolder #table1 #Time').val() <= $('div#TableHolder #table2 #Time').val()){
239 alert('2nd row must be greater than 1st');
240 }
241 }
242
243
244
245
246
247
248 }
249
250
251 );
252 td3.appendChild(
253 button=document.createElement('input'),
254 button.setAttribute('type','button'),
255 button.setAttribute('value','[+]'),
256 button.setAttribute('id','btnAddTime'),
257 button.setAttribute('name','#table2'),
258 button.onclick=function(){
259 var aa;
260 $('div#TableHolder #table2 #Time').each(function(){
261 aa = $(this).val();
262 });
263
264 if(aa != ""){ var splitting =aa.split(':'); var add = 01;
265
266 timeValue = pad((Number(splitting[0]) + Number(add)),2)+':'+splitting[1];
267
268 function pad(number, length) {
269
270 var str = '' + number;
271 while (str.length < length) {
272 str = '0' + str;
273 }
274
275 return str;
276
277 };
278
279 var s = 0; var get;
280
281 $("table").each(function() { if($(this).attr("name")=='#table2'){ get = "#"+$(this).attr("id"); s =1; }else{ if(s==0){ get = '#table'+cnt; }
282 }
283 });
284getTableId =get;
285name="name"; value = '#table2';
286measurement = 0;
287 meas = "class"; meas2 = "time"; //getTableId = $(this).attr('name');
288 split2(); }else{ alert("please enter value for time to add measurement"); }
289
290
291 }
292 );
293 var td=document.createElement('td');
294 td.setAttribute("style","border:1px solid white; color:#37DFB1; font-size:14px;text-align:center;");
295 td.appendChild(
296 sourcecbo= document.createElement('select'),
297 sourcecbo.setAttribute('id','source'),
298<?php
299 $source=mysql_query("SELECT*FROM source");
300 while($rowsource=mysql_fetch_array($source))
301 {
302?>
303 sourcecbo.appendChild(
304 option=document.createElement('option'),
305 option.setAttribute('value','<?php echo $rowsource['fSourceKEY']; ?>'),
306 option.setAttribute('selected',true),
307 option.appendChild(document.createTextNode("<?php echo $rowsource['fSourceName']; ?>"))
308
309 ),
310<?php
311 }
312 ?>
313 sourcecbo.setAttribute('id','source')
314
315 );
316 var td1=document.createElement('td');
317 td1.setAttribute("style","border:1px solid white; color:#37DFB1; font-size:14px;text-align:center;");
318 td1.appendChild(
319 measurementcbo= document.createElement('select'),
320 measurementcbo.setAttribute('id','measurement'),
321<?php
322 $measure=mysql_query("SELECT*FROM measurement");
323 while($rowmeasure=mysql_fetch_array($measure))
324 {
325?>
326 measurementcbo.appendChild(
327 option=document.createElement('option'),
328 option.setAttribute('value','<?php echo $rowmeasure['fMeasurementKey']; ?>'),
329 option.setAttribute('selected',true),
330 option.appendChild(document.createTextNode("<?php echo $rowmeasure['fMeasurement']; ?>"))
331 ),
332<?php
333 }
334?>
335 measurementcbo.setAttribute('id','measurement')
336 );
337 td1.appendChild(
338 button=document.createElement('input'),
339 button.setAttribute('type','button'),
340 button.setAttribute('value','[+]'),
341 button.setAttribute('id','btnAddTime'),
342 button.setAttribute('name','#table2'),
343 button.onclick=function(){
344 var aa;
345 $('div#TableHolder #table2 #Time').each(function(){
346 aa = $(this).val();
347 });
348 if(aa != ""){ timeValue =aa; name="name"; value=$(this).attr('name'); measurement = 1; meas = "hidden"; meas2 = true; getTableId = $(this).attr('name'); split2(); }else{ alert("please enter value for time to add measurement"); }
349
350
351 }
352 );
353 var td2=document.createElement('td');
354 td2.setAttribute("style","border:1px solid white; color:#37DFB1; font-size:14px; text-align:center;");
355 td2.appendChild(
356 input = document.createElement('input'),
357 input.setAttribute('type','text'),
358 input.setAttribute('id','txtData')
359
360 );
361 var td4=document.createElement('td');
362 td4.setAttribute("style","border:1px solid white; color:#37DFB1; font-size:14px; text-align:center;");
363
364 td4.appendChild(
365 button=document.createElement('input'),
366 button.setAttribute('type','button'),
367 button.setAttribute('value','Delete'),
368 button.setAttribute('id','btnDelete'),
369 button.onclick=function(){
370 $('#table2').remove();
371
372 }
373 );
374
375 tr.appendChild(td3);
376 tr.appendChild(td1);
377 tr.appendChild(td);
378
379 tr.appendChild(td2);
380 tr.appendChild(td4);
381 table.appendChild(tr);
382 div.appendChild(table);
383 $('#TableH1').append(div);
384
385 var div= document.createElement("div");
386 div.setAttribute('id','TableHolder');
387 var table = document.createElement("table");
388 table.setAttribute('id',"table1");
389 table.setAttribute('width','100%');
390 var tr = document.createElement('tr');
391 tr.setAttribute('id','');
392 tr.setAttribute('class','');
393 var td3=document.createElement('td');
394 td3.setAttribute('style','border:1px solid white; color:#37DFB1; font-size:14px; text-align:center;');
395 td3.appendChild(
396 input = document.createElement("input"),
397 input.setAttribute("type","time"),
398 input.setAttribute("id","Time"),
399 input.setAttribute("max","24"),
400 input.setAttribute("min","1"),
401 input.setAttribute("required",true),
402 input.onkeyup = function(){
403
404
405
406
407
408 if($('div#TableHolder #table2 #Time').val() <= 0 || $('div#TableHolder #table1 #Time').val() <=0){
409
410
411 }else{
412 if($('div#TableHolder #table1 #Time').val() <= $('div#TableHolder #table2 #Time').val()){
413 alert(' row must be greater than previous');
414 return false;
415 }
416 }
417
418
419
420
421
422
423 }
424 );
425 td3.appendChild(
426 button=document.createElement('input'),
427 button.setAttribute('type','button'),
428 button.setAttribute('value','[+]'),
429 button.setAttribute('id','btnAddTime'),
430 button.setAttribute('name','#table1'),
431 button.onclick=function(){
432 var aa;
433 $('div#TableHolder #table1 #Time').each(function(){
434 aa = $(this).val();
435 });
436 if(aa !='') { var splitting =aa.split(':'); var add = 01;
437
438 timeValue = pad((Number(splitting[0]) + Number(add)),2)+':'+splitting[1];
439
440 function pad(number, length) {
441
442 var str = '' + number;
443 while (str.length < length) {
444 str = '0' + str;
445 }
446
447 return str;
448
449 };
450
451
452 var s = 0; var get;
453
454$("table").each(function() {
455 if($(this).attr("name")=='#table1'){
456 get = "#"+$(this).attr("id");
457
458 s =1;
459 }else{
460 if(s==0){
461 get = '#table1';
462 }
463 }
464 });
465getTableId =get;
466name="name"; value = '#table1';
467 measurement = 0;
468 meas = "class"; meas2 = "time"; //getTableId = $(this).attr('name');
469split2(); }else{ alert("please enter value for time to add measurement"); }
470
471
472 }
473 );
474 var td=document.createElement('td');
475 td.setAttribute("style","border:1px solid white; color:#37DFB1; font-size:14px;text-align:center;");
476 td.appendChild(
477 sourcecbo= document.createElement('select'),
478 sourcecbo.setAttribute('id','source'),
479<?php
480 $source=mysql_query("SELECT*FROM source");
481 while($rowsource=mysql_fetch_array($source))
482 {
483?>
484 sourcecbo.appendChild(
485 option=document.createElement('option'),
486 option.setAttribute('value','<?php echo $rowsource['fSourceKEY']; ?>'),
487 option.setAttribute('selected',true),
488 option.appendChild(document.createTextNode("<?php echo $rowsource['fSourceName']; ?>"))
489
490 ),
491<?php
492 }
493 ?>
494 sourcecbo.setAttribute('id','source')
495
496 );
497 var td1=document.createElement('td');
498 td1.setAttribute("style","border:1px solid white; color:#37DFB1; font-size:14px;text-align:center;");
499 td1.appendChild(
500 measurementcbo= document.createElement('select'),
501 measurementcbo.setAttribute('id','measurement'),
502<?php
503 $measure=mysql_query("SELECT*FROM measurement");
504 while($rowmeasure=mysql_fetch_array($measure))
505 {
506?>
507 measurementcbo.appendChild(
508 option=document.createElement('option'),
509 option.setAttribute('value','<?php echo $rowmeasure['fMeasurementKey']; ?>'),
510 option.setAttribute('selected',true),
511 option.appendChild(document.createTextNode("<?php echo $rowmeasure['fMeasurement']; ?>"))
512 ),
513<?php
514 }
515?>
516 measurementcbo.setAttribute('id','measurement')
517 );
518 td1.appendChild(
519 button=document.createElement('input'),
520 button.setAttribute('type','button'),
521 button.setAttribute('value','[+]'),
522 button.setAttribute('id','btnAddTime'),
523 button.setAttribute('name','#table1'),
524 button.onclick=function(){
525 var aa;
526 $('div#TableHolder #table1 #Time').each(function(){
527 aa = $(this).val();
528 });
529
530 if(aa != ""){ timeValue = aa; name="name"; value="#table1"; measurement=1; meas = "hidden"; meas2 = true; getTableId = $(this).attr('name'); split2(); }else{ alert("please enter value for time to add measurement"); }
531
532
533 }
534 );
535 var td2=document.createElement('td');
536 td2.setAttribute("style","border:1px solid white; color:#37DFB1; font-size:14px; text-align:center;");
537 td2.appendChild(
538 input = document.createElement('input'),
539 input.setAttribute('type','text'),
540 input.setAttribute('id','txtData')
541
542 );
543 var td4=document.createElement('td');
544 td4.setAttribute("style","border:1px solid white; color:#37DFB1; font-size:14px; text-align:center;");
545
546 td4.appendChild(
547 button=document.createElement('input'),
548 button.setAttribute('type','button'),
549 button.setAttribute('value','Delete'),
550 button.setAttribute('id','btnDelete'),
551 button.onclick=function(){
552 $('#table1').remove();
553
554 }
555 );
556
557 tr.appendChild(td3);
558 tr.appendChild(td1);
559 tr.appendChild(td);
560
561 tr.appendChild(td2);
562 tr.appendChild(td4);
563 table.appendChild(tr);
564 div.appendChild(table);
565 $('#TableH1').append(div);
566
567
568 }
569 var meas;
570 var timeValue;
571 var pad;
572 if(cnt==0){ cnt=2; }
573 function split2()
574 {
575
576 cnt++;
577 var div= document.createElement("div");
578 div.setAttribute('id','TableHolder');
579 var table = document.createElement("table");
580 table.setAttribute('id',"table"+cnt);
581 table.setAttribute('width','100%');
582 if(measurement==1){ table.setAttribute(name,value); }
583 var tr = document.createElement('tr');
584 tr.setAttribute('id','');
585 tr.setAttribute('class','');
586
587 var td3=document.createElement('td');
588 td3.setAttribute('style','border:1px solid white; color:#37DFB1; font-size:14px; text-align:center;');
589 td3.setAttribute('class','first');
590
591 td3.appendChild(
592 input = document.createElement("input"),
593 input.setAttribute("type","time"),
594 input.setAttribute("id","Time"),
595 input.setAttribute("max","24"),
596 input.setAttribute("min",'1'),
597 input.setAttribute("required",true),
598 input.setAttribute(meas,meas2),
599 input.setAttribute("value",timeValue)
600
601
602 );
603 td3.appendChild(
604 button=document.createElement('input'),
605 button.setAttribute('type','button'),
606 button.setAttribute('value','[+]'),
607 button.setAttribute('id','btnAddTime'),
608 button.setAttribute(meas,meas2),
609 button.setAttribute('name','table'+cnt),
610
611 button.onclick=function(){
612 var aa;
613 $('div#TableHolder #table'+cnt+' #Time').each(function(){
614 aa = $(this).val();
615 });
616
617 if(value == 'undefined'){ bb = $(this).closest('table').attr('name'); }else{
618 bb = value; }
619 if(aa != ""){var splitting = aa.split(':'); var add = 01;
620
621
622 timeValue = pad((Number(splitting[0]) + Number(add)),2)+':'+splitting[1];
623
624 function pad(number, length) {
625
626 var str = '' + number;
627 while (str.length < length) {
628 str = '0' + str;
629 }
630
631 return str;
632
633 }
634
635 var s = 0; var get;
636 var nn;
637 nn = '#'+$(this).attr("name");
638 $("table").each(function() {
639 if($(this).attr("name")==nn){
640
641 get = "#"+$(this).attr("id");
642 //get = $(this).attr("name");
643 s =1;
644 }else{
645 if(s==0){
646 get = '#table'+cnt;
647 }
648 }
649 });
650
651name="name"; value = bb;
652meas = "class"; meas2 = "time"; getTableId = get; measurement =0; split1(); }else{ alert("please enter value for time to add measurement"); }
653
654
655 }
656 );
657
658 var td=document.createElement('td');
659 td.setAttribute("style","border:1px solid white; color:#37DFB1; font-size:14px;text-align:center;");
660 td.appendChild(
661 sourcecbo= document.createElement('select'),
662 sourcecbo.setAttribute('id','source'),
663<?php
664 $source=mysql_query("SELECT*FROM source");
665 while($rowsource=mysql_fetch_array($source))
666 {
667?>
668 sourcecbo.appendChild(
669 option=document.createElement('option'),
670 option.setAttribute('value','<?php echo $rowsource['fSourceKEY']; ?>'),
671 option.setAttribute('selected',true),
672 option.appendChild(document.createTextNode("<?php echo $rowsource['fSourceName']; ?>"))
673
674 ),
675<?php
676 }
677 ?>
678 sourcecbo.setAttribute('id','source')
679
680 );
681var td1=document.createElement('td');
682td1.setAttribute("style","border:1px solid white; color:#37DFB1; font-size:14px;text-align:center;");
683td1.appendChild(
684measurementcbo= document.createElement('select'),
685measurementcbo.setAttribute('id','measurement'),
686<?php
687 $measure=mysql_query("SELECT*FROM measurement");
688 while($rowmeasure=mysql_fetch_array($measure))
689 {
690?>
691measurementcbo.appendChild(
692option=document.createElement('option'),
693option.setAttribute('value','<?php echo $rowmeasure['fMeasurementKey']; ?>'),
694option.setAttribute('selected',true),
695option.appendChild(document.createTextNode("<?php echo $rowmeasure['fMeasurement']; ?>"))
696 ),
697<?php
698 }
699?>
700 measurementcbo.setAttribute('id','measurement')
701 );
702 td1.appendChild(
703 button=document.createElement('input'),
704 button.setAttribute('type','button'),
705 button.setAttribute('value','[+]'),
706 button.setAttribute('id','btnAddTime'),
707 button.setAttribute('name','#table'+cnt),
708 button.onclick=function(){
709 var aa,cc=0;
710 var bb,dd;
711 $('div#TableHolder #table'+cnt+' #Time').each(function(){
712 aa = $(this).val();
713
714
715
716 });
717 dd= $(this).attr('name');
718 //alert(dd);
719 if($('div#TableHolder '+dd+' #Time').is(':visible')){
720 cc=0;
721 //alert(cc);
722 }else{
723 cc=1;
724 }
725 //alert(value);
726 x = 1;
727 if(meas2 == 'time' && measurement == 0 && cc != 1){ bb = '#'+$(this).closest('table').attr('id'); }else{
728 bb = value; }
729 if(aa != "")
730 {
731 name = "name";
732 value = bb;
733 // alert('2'+bb);
734 timeValue = aa;
735 meas = "hidden";
736 meas2 = true;
737 getTableId = $(this).attr('name');
738 //alert(getTableId);
739 measurement = 1;
740 split1();
741 }
742 else
743 {
744 alert("please enter value for time to add measurement");
745 }
746
747
748 }
749 );
750
751 var td2=document.createElement('td');
752 td2.setAttribute("style","border:1px solid white; color:#37DFB1; font-size:14px; text-align:center;");
753 td2.appendChild(
754 input = document.createElement('input'),
755 input.setAttribute('type','text'),
756 input.setAttribute('id','txtData')
757
758 );
759 var td4=document.createElement('td');
760 td4.setAttribute("style","border:1px solid white; color:#37DFB1; font-size:14px; text-align:center;");
761
762 td4.appendChild(
763 button=document.createElement('input'),
764 button.setAttribute('type','button'),
765 button.setAttribute('value','Delete'),
766 button.setAttribute('id','btnDelete'),
767 button.onclick=function(){
768 $('#table'+cnt).remove();
769 cnt--;
770 }
771 );
772
773 tr.appendChild(td3);
774 tr.appendChild(td1);
775 tr.appendChild(td);
776
777 tr.appendChild(td2);
778 tr.appendChild(td4);
779 table.appendChild(tr);
780 div.appendChild(table);
781 $(div).insertAfter($(getTableId));
782
783
784
785 }
786 function split1()
787 {
788
789 cnt++;
790 var div= document.createElement("div");
791 div.setAttribute('id','TableHolder');
792 var table = document.createElement("table");
793 table.setAttribute('id',"table"+cnt);
794 table.setAttribute('width','100%');
795 if(measurement==1){ table.setAttribute(name,value); }
796 var tr = document.createElement('tr');
797 tr.setAttribute('id','');
798 tr.setAttribute('class','');
799
800 var td3=document.createElement('td');
801 td3.setAttribute('style','border:1px solid white; color:#37DFB1; font-size:14px; text-align:center;');
802 td3.setAttribute('class','first');
803 td3.appendChild(
804 input = document.createElement("input"),
805 input.setAttribute("type","time"),
806 input.setAttribute("id","Time"),
807 input.setAttribute("max","24"),
808 input.setAttribute("min",'1'),
809 input.setAttribute("required",true),
810 input.setAttribute(meas,meas2),
811 input.setAttribute("value",timeValue)
812
813 );
814 td3.appendChild(
815 button=document.createElement('input'),
816 button.setAttribute('type','button'),
817 button.setAttribute('value','[+]'),
818 button.setAttribute('id','btnAddTime'),
819 button.setAttribute(meas,meas2),
820 button.setAttribute('name','table'+cnt),
821
822 button.onclick=function(){
823 var aa;
824 $('div#TableHolder #table'+cnt+' #Time').each(function(){
825 aa = $(this).val();
826 });
827 if(value == 'undefined'){ bb = $(this).closest('table').attr('name'); }else{
828 bb = value; }
829 if(aa != ""){ var splitting = aa.split(':'); var add = 01;
830
831 timeValue = pad((Number(splitting[0]) + Number(add)),2)+':'+splitting[1];
832
833 function pad(number, length) {
834
835 var str = '' + number;
836 while (str.length < length) {
837 str = '0' + str;
838 }
839
840 return str;
841
842 }
843 var s = 0; var get;
844 var nn;
845 nn = bb;
846 $("table").each(function() {
847 if($(this).attr("name")==nn){
848
849 get = "#"+$(this).attr("id");
850 //get = $(this).attr("name");
851 s =1;
852 }else{
853 if(s==0){
854 get = '#table'+cnt;
855 }
856 }
857 });
858
859 name="name"; value=bb; measurement=0; meas = "class"; meas2 = "time"; getTableId = get; split1(); }else{ alert("please enter value for time to add measurement"); }
860
861
862 }
863 );
864
865 var td=document.createElement('td');
866 td.setAttribute("style","border:1px solid white; color:#37DFB1; font-size:14px;text-align:center;");
867 td.appendChild(
868 sourcecbo= document.createElement('select'),
869 sourcecbo.setAttribute('id','source'),
870<?php
871 $source=mysql_query("SELECT*FROM source");
872 while($rowsource=mysql_fetch_array($source))
873 {
874?>
875 sourcecbo.appendChild(
876 option=document.createElement('option'),
877 option.setAttribute('value','<?php echo $rowsource['fSourceKEY']; ?>'),
878 option.setAttribute('selected',true),
879 option.appendChild(document.createTextNode("<?php echo $rowsource['fSourceName']; ?>"))
880
881 ),
882<?php
883 }
884 ?>
885 sourcecbo.setAttribute('id','source')
886
887 );
888 var td1=document.createElement('td');
889 td1.setAttribute("style","border:1px solid white; color:#37DFB1; font-size:14px;text-align:center;");
890
891 td1.appendChild(
892 measurementcbo= document.createElement('select'),
893 measurementcbo.setAttribute('id','measurement'),
894<?php
895 $measure=mysql_query("SELECT*FROM measurement");
896 while($rowmeasure=mysql_fetch_array($measure))
897 {
898?>
899 measurementcbo.appendChild(
900 option=document.createElement('option'),
901 option.setAttribute('value','<?php echo $rowmeasure['fMeasurementKey']; ?>'),
902 option.setAttribute('selected',true),
903 option.appendChild(document.createTextNode("<?php echo $rowmeasure['fMeasurement']; ?>"))
904 ),
905<?php
906 }
907?>
908 measurementcbo.setAttribute('id','measurement')
909 );
910 td1.appendChild(
911 button=document.createElement('input'),
912 button.setAttribute('type','button'),
913 button.setAttribute('value','[+]'),
914 button.setAttribute('id','btnAddTimes'),
915 button.setAttribute('name','#table'+cnt),
916 button.onclick=function(){
917
918 var aa,cc=0;
919 var bb,dd;
920 $('div#TableHolder #table'+cnt+' #Time').each(function(){
921 aa = $(this).val();
922
923 });
924 dd= $(this).attr('name');
925 if($('div#TableHolder '+dd+' #Time').is(':visible')){
926 cc=0;
927 //alert(cc);
928 }else{
929 cc=1;
930 }
931 x=1;
932 if(meas2 == 'time' && measurement == 0 && cc!=1){ bb = '#'+$(this).closest('table').attr('id'); }else{
933 bb = value; }
934
935 if(aa != "")
936 {
937 name = "name";
938 value = bb;
939 //alert(value);
940 timeValue = aa;
941 meas = "hidden";
942 meas2 = true;
943 getTableId = $(this).attr('name');
944 measurement =1;
945 split1();
946 }
947 else
948 {
949 alert("please enter value for time to add measurement");
950 }
951 }
952 );
953
954 var td2=document.createElement('td');
955 td2.setAttribute("style","border:1px solid white; color:#37DFB1; font-size:14px; text-align:center;");
956 td2.appendChild(
957 input = document.createElement('input'),
958 input.setAttribute('type','text'),
959 input.setAttribute('id','txtData')
960
961 );
962 var td4=document.createElement('td');
963 td4.setAttribute("style","border:1px solid white; color:#37DFB1; font-size:14px; text-align:center;");
964
965 td4.appendChild(
966 button=document.createElement('input'),
967 button.setAttribute('type','button'),
968 button.setAttribute('value','Delete'),
969 button.setAttribute('id','btnDelete'),
970 button.onclick=function(){
971 $('#table'+cnt).remove();
972 cnt--;
973 });
974
975 tr.appendChild(td3);
976 tr.appendChild(td1);
977 tr.appendChild(td);
978
979 tr.appendChild(td2);
980 tr.appendChild(td4);
981 table.appendChild(tr);
982 div.appendChild(table);
983 $(div).insertAfter($(getTableId));
984 }
985
986 //$('div#TableHolder #table'+cnt+' #Time')
987
988
989 // $('div#TableHolder table #Time').keyup(function(){
990
991 // if($('div#TableHolder #table2 #Time').val() <= 0 || $('div#TableHolder #table1 #Time').val() <=0){
992
993
994 // }else{
995 // if($('div#TableHolder #table1 #Time').val() <= $('div#TableHolder #table2 #Time').val()){
996 // alert(cnt);
997 // }
998 // }
999 // });
1000
1001
1002
1003
1004
1005 });
1006 </script>
Note: See TracBrowser for help on using the repository browser.