source: schedule/Module/control.php@ 17510

Last change on this file since 17510 was 17510, checked in by tose, 11 years ago
Fixed inserting new observations on update schedule
File size: 17.8 KB
Line 
1<script>
2'use strict';
3 var ctr;
4
5 function clearNode(node){
6 var child = node.childNodes[0];
7 while(child != null)
8 {
9 node.removeChild(child);
10 child = node.childNodes[0];
11 }
12 }
13
14 function addRow(table){
15 var targetView = table;
16 var cctr=$('.dataTable tr').length;
17 ctr=cctr+1;
18 var input_data;
19 var select;
20 var option;
21 var selection;
22 // CREATE ELEMENT
23 var newtr = document.createElement("tr");
24 newtr.setAttribute("class","tr");
25 var newtd_c1 = document.createElement("td");
26 newtd_c1.setAttribute("width","147");
27 newtd_c1.setAttribute("align","center");
28 newtd_c1.appendChild(
29 input_data = document.createElement("input"),
30 input_data.setAttribute("type","time"),
31 input_data.setAttribute("size","10"),
32 input_data.setAttribute("autofocus","true"),
33 input_data.setAttribute("hidden","true")
34 );
35 var newtd_c2 = document.createElement("td");
36 newtd_c2.setAttribute("width","138");
37 newtd_c2.setAttribute("align","center");
38 newtd_c2.appendChild(
39 select = document.createElement("select"),
40 select.setAttribute("class","measure"),
41 $.ajax({ //Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
42 type:"post",
43 url:"Transaction/measurement.php",
44 success:function(data){
45 var obj=$.parseJSON(data);
46 $.each(obj,function(){
47 select.appendChild(
48 option = document.createElement("option"),
49 option.setAttribute('value',this['fMeasurementKey']),
50 option.appendChild(document.createTextNode(this['fMeasurement']))
51 )
52 })
53 }
54 }) // End of retrieving
55 );
56 newtd_c2.setAttribute("width","115");
57 newtd_c2.setAttribute("align","center");
58 newtd_c2.appendChild(
59 input_data = document.createElement("input"),
60 input_data.setAttribute("type","button"),
61 input_data.setAttribute("value","+"),
62 input_data.onclick = function(){ return addRow(newtr);
63 ctr++;
64 }
65 );
66 var newtd_c3 = document.createElement("td");
67 newtd_c3.setAttribute("width","98");
68 newtd_c3.setAttribute("align","center");
69 newtd_c3.appendChild(
70 selection = document.createElement("select"),
71 selection.setAttribute("class","source"),
72 $.ajax({ //Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
73 type:"post",
74 url:"Transaction/source.php",
75 success:function(data)
76 {
77 var obj = $.parseJSON(data);
78 $.each(obj,function(){
79 selection.appendChild(
80 option=document.createElement('option'),
81 option.setAttribute('value',this['fSourceKEY']),
82 option.appendChild(document.createTextNode(this['fSourceName']))
83 )
84 });
85 }
86 }) // End of retrieving
87 );
88 var newtd_c4 = document.createElement("td");
89 newtd_c4.setAttribute("width","119");
90 newtd_c4.setAttribute("align","center");
91 newtd_c4.appendChild(
92 input_data = document.createElement("input"),
93 input_data.setAttribute("type","text"),
94 input_data.setAttribute("class","selected"),
95 input_data.setAttribute("size","12"),
96 input_data.setAttribute("placeholder","Value")
97 );
98 var newtd_c5 = document.createElement("td");
99 newtd_c5.setAttribute("width","115");
100 newtd_c5.setAttribute("align","center");
101 newtd_c5.appendChild(
102 input_data = document.createElement("input"),
103 input_data.setAttribute("type","button"),
104 input_data.setAttribute("value","Delete"),
105 input_data.onclick = function(){ return clearNode(newtr); }
106 );
107
108 newtr.appendChild(newtd_c2);
109 newtr.appendChild(newtd_c3);
110 newtr.appendChild(newtd_c4);
111 newtr.appendChild(newtd_c5);
112
113 $(targetView).after(newtr);
114 }
115function deleteRow(tableID){
116 try{
117 var table = document.getElementById(tableID);
118 var rowCount = table.rows.length;
119
120 for(var i = 0; i < rowCount; i++){
121 var row = table.rows[i];
122 var chkbox = row.cells[0].childNodes[0];
123 if(null != chkbox && true == chkbox.checked){
124 if(rowCount <= 1){
125 alert("Cannot delete all the rows.");
126 break;
127 }
128 table.deleteRow(i);
129 rowCount--;
130 i--;
131 }
132 }
133 }catch(e){
134 alert(e);
135 }
136 }
137
138<?php
139$cnt=0;
140$day=0;
141if(isset($_GET['days']))
142{
143 $day = $_GET['days'];
144?> addRowClone(); <?php
145}
146else
147{
148 $day =date("Y-m-d");
149}
150$prev_time = array();
151?>
152
153function addRowCloneNew(nextrow){
154 var targetView = document.getElementById("Data");
155 // CREATE ELEMENT
156 // COUNT LIST
157 var list = $(".datalisting").length;
158 var newlist = list+1;
159 var cctr=$('.dataTable tr').length;
160 ctr=cctr+1;
161 var input_data;
162 var select;
163 var option;
164 var selection;
165 var newdiv = document.createElement("div");
166 newdiv.setAttribute("id","list_"+newlist);
167 newdiv.setAttribute("class","datalisting");
168 newdiv.setAttribute("style","margin:5px 0;");
169 var newtable = document.createElement("table");
170 newtable.setAttribute("class","dataTable");
171 newtable.setAttribute("width","100%");
172 newtable.setAttribute("border","1");
173 newtable.setAttribute("cellspacing","0");
174 newtable.setAttribute("cellpadding","0");
175 var newInnertable = document.createElement("table");
176 newInnertable.setAttribute("class","dataTable");
177 newInnertable.setAttribute("width","100%");
178 newInnertable.setAttribute("border","1");
179
180 newInnertable.setAttribute("cellspacing","0");
181 newInnertable.setAttribute("cellpadding","0");
182
183 var newtr = document.createElement("tr");
184 newtr.setAttribute('class','tr');
185 var newtd_c1 = document.createElement("td");
186 newtd_c1.setAttribute("width","200");
187 newtd_c1.setAttribute("align","center");
188 newtd_c1.appendChild(
189 input_data = document.createElement("input"),
190 input_data.setAttribute("type","time"),
191 input_data.setAttribute("class","time"),
192 input_data.setAttribute("size","10"),
193 input_data.setAttribute("autofocus","true")
194 );
195 newtd_c1.appendChild(
196 input_data = document.createElement("input"),
197 input_data.setAttribute("type","button"),
198 input_data.setAttribute("value","+"),
199 input_data.onclick = function(){
200 addRowCloneNew("list_"+newlist);
201 }
202 );
203 var newtd_c2 = document.createElement("td");
204
205 newtd_c2.setAttribute("width","138");
206 newtd_c2.setAttribute("align","center");
207 newtd_c2.appendChild(
208 select = document.createElement("select"),
209 select.setAttribute("class","measure"),
210 $.ajax({ //Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
211 type:"post",
212 url:"Transaction/measurement.php",
213 success:function(data){
214 var obj=$.parseJSON(data);
215 $.each(obj,function(){
216 select.appendChild(
217 option = document.createElement("option"),
218 option.setAttribute('value',this['fMeasurementKey']),
219 option.appendChild(document.createTextNode(this['fMeasurement']))
220 )
221 })
222
223 }
224 }) // End of retrieving
225
226 );
227 newtd_c2.setAttribute("width","115");
228 newtd_c2.setAttribute("align","center");
229 newtd_c2.appendChild(
230 input_data = document.createElement("input"),
231 input_data.setAttribute("type","button"),
232 input_data.setAttribute("value","+"),
233 input_data.onclick = function(){
234 return addRow(newtr);
235 ctr++;
236 });
237 var newtd_c3 = document.createElement("td");
238 newtd_c3.setAttribute("width","98");
239 newtd_c3.setAttribute("align","center");
240 newtd_c3.appendChild(
241 selection = document.createElement("select"),
242 selection.setAttribute("class","source"),
243 $.ajax({ //Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
244 type:"post",
245 url:"Transaction/source.php",
246 success:function(data)
247 {
248 var obj = $.parseJSON(data);
249 $.each(obj,function(){
250 selection.appendChild(
251 option=document.createElement('option'),
252 option.setAttribute('value',this['fSourceKEY']),
253 option.appendChild(document.createTextNode(this['fSourceName']))
254 )
255 });
256 }
257 }) // End of retrieving
258 );
259 var newtd_c4 = document.createElement("td");
260 newtd_c4.setAttribute("width","119");
261 newtd_c4.setAttribute("align","center");
262 newtd_c4.appendChild(
263 input_data = document.createElement("input"),
264 input_data.setAttribute("type","text"),
265 input_data.setAttribute("class","selected"),
266 input_data.setAttribute("size","12"),
267 input_data.setAttribute("placeholder","Value")
268 );
269 var newtd_c5 = document.createElement("td");
270 newtd_c5.setAttribute("width","115");
271 newtd_c5.setAttribute("align","center");
272 newtd_c5.setAttribute("width","115");
273 newtd_c5.setAttribute("align","center");
274 newtd_c5.appendChild(
275 input_data = document.createElement("input"),
276 input_data.setAttribute("type","button"),
277 input_data.setAttribute("value","Delete"),
278 input_data.onclick = function(){ return clearNode(newtr);
279 }
280 );
281 newtr.appendChild(newtd_c2);
282 newtr.appendChild(newtd_c3);
283 newtr.appendChild(newtd_c4);
284 newtr.appendChild(newtd_c5);
285 newInnertable.appendChild(newtr);
286 var newtd_c6 = document.createElement("td");
287 newtd_c6.appendChild(newInnertable);
288
289 var newtd_c7 = document.createElement("td");
290 newtd_c7.setAttribute("width","115");
291 newtd_c7.setAttribute("align","center");
292 newtd_c7.appendChild(
293 input_data = document.createElement("input"),
294 input_data.setAttribute("type","button"),
295 input_data.setAttribute("value","Delete Main"),
296 input_data.onclick = function(){ return clearNode(newdiv); }
297 );
298
299 var newOutertr = document.createElement("tr");
300
301 newtable.appendChild(newtd_c1);
302 newtable.appendChild(newtd_c6);
303 newtable.appendChild(newtd_c7);
304
305 newdiv.appendChild(newtable);
306 if(nextrow != null){
307 var doc = document.getElementById(nextrow);
308 $(doc).after(newdiv);
309 }else{
310 targetView.appendChild(newdiv);
311 }
312}
313
314function addRowClone(nextrow){
315 <?php
316 $fetch = mysql_query("SELECT * FROM schedule WHERE date(fStart) = '$day' ORDER BY fScheduleID ASC, fMeasurementID ASC") or die(mysql_error());
317$observationsTime = mysql_query("SELECT DISTINCT fStart FROM schedule WHERE date(fStart) = '$day'");
318$cnt3=0;
319$cnt2=0;
320$cnt4 = 0;
321$cnt5 = 0;
322$cnt = 0;
323//$data = array();
324//$counter=0;
325 while($times = mysql_fetch_array($observationsTime))
326 {
327 $timestamp=strtotime($times['fStart']);
328 $actualtime = date('Y-m-d H:i:s', $timestamp);
329 $timestamp2 = date('Y-m-d',$timestamp);
330 $date_time = date('H:i',$timestamp);
331 $prev_time[$cnt3]= $date_time;
332 ?>
333 $('#save').attr('value','UPDATE');
334 var targetView = document.getElementById("Data");
335 // CREATE ELEMENT
336 // COUNT LIST
337 var list = $(".datalisting").length;
338 var newlist = list+1;
339 <?php $cnt++ ?>;
340
341 var cctr=$('.dataTable tr').length;
342 ctr=cctr+1;
343 var input_data;
344 var select;
345 var option;
346 var selection;
347
348 var newdiv = document.createElement("div");
349 newdiv.setAttribute("id", "list_<?php echo $cnt; ?>");
350 newdiv.setAttribute("class","datalisting");
351 newdiv.setAttribute("style","margin:5px 0;");
352
353 var newtable = document.createElement("table");
354 newtable.setAttribute("class","dataTable");
355 newtable.setAttribute("width","100%");
356 newtable.setAttribute("border","1");
357 newtable.setAttribute("cellspacing","0");
358 newtable.setAttribute("cellpadding","0");
359
360
361 var newInnertable = document.createElement("table");
362 newInnertable.setAttribute("class","dataTable");
363 newInnertable.setAttribute("width","100%");
364 newInnertable.setAttribute("border","1");
365
366 newInnertable.setAttribute("cellspacing","0");
367 newInnertable.setAttribute("cellpadding","0");
368
369 var newtd_c1 = document.createElement("td");
370 newtd_c1.setAttribute("width","200");
371 newtd_c1.setAttribute("align","center");
372 newtd_c1.appendChild(
373 input_data = document.createElement("input"),
374 input_data.setAttribute("type","time"),
375 input_data.setAttribute("class","time"),
376 input_data.setAttribute("size","10"),
377 input_data.setAttribute("value","<?php echo $date_time; ?>"),
378 input_data.setAttribute("autofocus","true")
379 );
380 newtd_c1.appendChild(
381 input_data = document.createElement("input"),
382 input_data.setAttribute("type","button"),
383 input_data.setAttribute("value","+"),
384 input_data.onclick = function(){
385 addRowCloneNew("list_<?php echo $cnt; ?>");
386 }
387 );
388
389 <?php
390 $observations = mysql_query("SELECT * FROM schedule WHERE fStart = '$actualtime'");
391
392 while($rows = mysql_fetch_array($observations))
393 {
394 ?>
395
396 var newtr<?php echo $cnt; ?> = document.createElement("tr");
397 newtr<?php echo $cnt; ?>.setAttribute('class','tr');
398
399 var newtd_c2 = document.createElement("td");
400 newtd_c2.setAttribute("width","138");
401 newtd_c2.setAttribute("align","center");
402 newtd_c2.appendChild(
403 selection = document.createElement("select"),
404 <?php
405 $selectm = mysql_query("SELECT * FROM measurement");
406 while($rowmeasure = mysql_fetch_array($selectm))
407 {
408 ?>
409 selection.appendChild(
410 option = document.createElement("option"),
411 option.setAttribute("value","<?php echo $rowmeasure['fMeasurementKey']; ?>"),
412 <?php if($rows['fMeasurementTypeKey']==$rowmeasure['fMeasurementKey']){ echo "option.setAttribute('selected',true),";} ?>
413 option.appendChild(document.createTextNode("<?php echo $rowmeasure['fMeasurement']; ?>"))
414 ),
415 <?php
416 }
417 ?>
418
419
420 selection.setAttribute('id','measure'),
421 selection.setAttribute('class','measure')
422 );
423 newtd_c2.setAttribute("width","115");
424 newtd_c2.setAttribute("align","center");
425 newtd_c2.appendChild(
426 input_data = document.createElement("input"),
427 input_data.setAttribute("type","button"),
428 input_data.setAttribute("value","+"),
429 input_data.onclick = function(){
430 return addRow(newtr<?php echo $cnt; ?>);
431 ctr++;
432 });
433 var newtd_c3 = document.createElement("td");
434 newtd_c3.setAttribute("width","98");
435 newtd_c3.setAttribute("align","center");
436 newtd_c3.appendChild(
437 selection = document.createElement("select"),
438 <?php
439 $select = mysql_query("SELECT * FROM source");
440 while($rowsource = mysql_fetch_array($select))
441 {
442 ?>
443 selection.appendChild(
444 option = document.createElement("option"),
445 option.setAttribute('value','<?php echo $rowsource['fSourceKEY']; ?>'),
446 <?php if($rows['fSourceKey'] == $rowsource['fSourceKEY']){ echo "option.setAttribute('selected',true),"; } ?>
447 option.appendChild(document.createTextNode("<?php echo $rowsource['fSourceName']; ?>"))
448 ),
449 <?php
450 }
451 ?>
452
453 selection.setAttribute('id','source'), // End of retrieving
454 selection.setAttribute('class','source') // End of retrieving
455 );
456 var newtd_c4 = document.createElement("td");
457 newtd_c4.setAttribute("width","119");
458 newtd_c4.setAttribute("align","center");
459 newtd_c4.appendChild(
460 input_data = document.createElement("input"),
461 input_data.setAttribute("type","text"),
462 input_data.setAttribute("class","selected"),
463 input_data.setAttribute("size","12"),
464 input_data.setAttribute("value","<?php echo $rows['fData']; ?>"),
465 input_data.setAttribute("placeholder","Value")
466 );
467 var newtd_c5 = document.createElement("td");
468 newtd_c5.setAttribute("width","115");
469 newtd_c5.setAttribute("align","center");
470 newtd_c5.setAttribute("width","115");
471 newtd_c5.setAttribute("align","center");
472 newtd_c5.appendChild(
473 input_data = document.createElement("input"),
474 input_data.setAttribute("type","button"),
475 input_data.setAttribute("value","Delete"),
476 input_data.onclick = function(){ return clearNode(newtr<?php echo $cnt; ?>);
477 }
478 );
479 newtr<?php echo $cnt; ?>.appendChild(newtd_c2);
480 newtr<?php echo $cnt; ?>.appendChild(newtd_c3);
481 newtr<?php echo $cnt; ?>.appendChild(newtd_c4);
482 newtr<?php echo $cnt; ?>.appendChild(newtd_c5);
483 newInnertable.appendChild(newtr<?php echo $cnt; ?>);
484
485 <?php
486
487 $prevtimestamp = $timestamp;
488 }
489 ?>
490
491 var newtd_c6 = document.createElement("td");
492 newtd_c6.appendChild(newInnertable);
493
494 var newtd_c7 = document.createElement("td");
495 newtd_c7.setAttribute("width","115");
496 newtd_c7.setAttribute("align","center");
497 newtd_c7.appendChild(
498 input_data = document.createElement("input"),
499 input_data.setAttribute("type","button"),
500 input_data.setAttribute("value","Delete Main"),
501 input_data.onclick = function(){ return clearNode(newdiv); }
502 );
503
504 var newOutertr = document.createElement("tr");
505
506 newtable.appendChild(newtd_c1);
507 newtable.appendChild(newtd_c6);
508 newtable.appendChild(newtd_c7);
509
510 newdiv.appendChild(newtable);
511 if(nextrow != null){
512 var doc = document.getElementById(nextrow);
513 $(doc).after(newdiv);
514 }else{
515 targetView.appendChild(newdiv);
516 //$(targetView).after(newtr<?php echo $cnt; ?>);
517 }
518 <?php
519}
520if(mysql_num_rows($fetch)<1)
521{
522?>
523 $('#save').attr('value','SAVE');
524 addRowCloneNew();
525<?php
526}
527
528?>
529
530
531}
532 </script>
533
Note: See TracBrowser for help on using the repository browser.