source: schedule/Module/control.php@ 17511

Last change on this file since 17511 was 17511, checked in by tose, 11 years ago
Fixed the deletion of observation and task in an observation
File size: 18.6 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.setAttribute("valign", "top");
189 newtd_c1.appendChild(
190 input_data = document.createElement("input"),
191 input_data.setAttribute("type","time"),
192 input_data.setAttribute("class","time"),
193 input_data.setAttribute("size","10"),
194 input_data.setAttribute("autofocus","true")
195 );
196 newtd_c1.appendChild(
197 input_data = document.createElement("input"),
198 input_data.setAttribute("type","button"),
199 input_data.setAttribute("value","+"),
200 input_data.onclick = function(){
201 addRowCloneNew("list_"+newlist);
202 }
203 );
204 var newtd_c2 = document.createElement("td");
205
206 newtd_c2.setAttribute("width","138");
207 newtd_c2.setAttribute("align","center");
208 newtd_c2.appendChild(
209 select = document.createElement("select"),
210 select.setAttribute("class","measure"),
211 $.ajax({ //Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
212 type:"post",
213 url:"Transaction/measurement.php",
214 success:function(data){
215 var obj=$.parseJSON(data);
216 $.each(obj,function(){
217 select.appendChild(
218 option = document.createElement("option"),
219 option.setAttribute('value',this['fMeasurementKey']),
220 option.appendChild(document.createTextNode(this['fMeasurement']))
221 )
222 })
223
224 }
225 }) // End of retrieving
226
227 );
228 newtd_c2.setAttribute("width","115");
229 newtd_c2.setAttribute("align","center");
230 newtd_c2.appendChild(
231 input_data = document.createElement("input"),
232 input_data.setAttribute("type","button"),
233 input_data.setAttribute("value","+"),
234 input_data.onclick = function(){
235 return addRow(newtr);
236 ctr++;
237 });
238 var newtd_c3 = document.createElement("td");
239 newtd_c3.setAttribute("width","98");
240 newtd_c3.setAttribute("align","center");
241 newtd_c3.appendChild(
242 selection = document.createElement("select"),
243 selection.setAttribute("class","source"),
244 $.ajax({ //Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
245 type:"post",
246 url:"Transaction/source.php",
247 success:function(data)
248 {
249 var obj = $.parseJSON(data);
250 $.each(obj,function(){
251 selection.appendChild(
252 option=document.createElement('option'),
253 option.setAttribute('value',this['fSourceKEY']),
254 option.appendChild(document.createTextNode(this['fSourceName']))
255 )
256 });
257 }
258 }) // End of retrieving
259 );
260 var newtd_c4 = document.createElement("td");
261 newtd_c4.setAttribute("width","119");
262 newtd_c4.setAttribute("align","center");
263 newtd_c4.appendChild(
264 input_data = document.createElement("input"),
265 input_data.setAttribute("type","text"),
266 input_data.setAttribute("class","selected"),
267 input_data.setAttribute("size","12"),
268 input_data.setAttribute("placeholder","Value")
269 );
270 var newtd_c5 = document.createElement("td");
271 newtd_c5.setAttribute("width","115");
272 newtd_c5.setAttribute("align","center");
273 newtd_c5.setAttribute("width","115");
274 newtd_c5.setAttribute("align","center");
275 newtd_c5.appendChild(
276 input_data = document.createElement("input"),
277 input_data.setAttribute("type","button"),
278 input_data.setAttribute("value","Delete"),
279 input_data.onclick = function(){ return clearNode(newtr);
280 }
281 );
282 newtr.appendChild(newtd_c2);
283 newtr.appendChild(newtd_c3);
284 newtr.appendChild(newtd_c4);
285 newtr.appendChild(newtd_c5);
286 newInnertable.appendChild(newtr);
287 var newtd_c6 = document.createElement("td");
288 newtd_c6.appendChild(newInnertable);
289
290 var newtd_c7 = document.createElement("td");
291 newtd_c7.setAttribute("width","115");
292 newtd_c7.setAttribute("align","center");
293 newtd_c7.setAttribute("valign", "top");
294 newtd_c7.appendChild(
295 input_data = document.createElement("input"),
296 input_data.setAttribute("type","button"),
297 input_data.setAttribute("value","Delete Main"),
298 input_data.onclick = function(){ return clearNode(newdiv); }
299 );
300
301 var newOutertr = document.createElement("tr");
302
303 newtable.appendChild(newtd_c1);
304 newtable.appendChild(newtd_c6);
305 newtable.appendChild(newtd_c7);
306
307 newdiv.appendChild(newtable);
308 if(nextrow != null){
309 var doc = document.getElementById(nextrow);
310 $(doc).after(newdiv);
311 }else{
312 targetView.appendChild(newdiv);
313 }
314}
315
316function addRowClone(nextrow){
317 <?php
318 $fetch = mysql_query("SELECT * FROM schedule WHERE date(fStart) = '$day' ORDER BY fScheduleID ASC, fMeasurementID ASC") or die(mysql_error());
319$observationsTime = mysql_query("SELECT DISTINCT fStart FROM schedule WHERE date(fStart) = '$day'");
320$cnt3=0;
321$cnt2=0;
322$cnt4 = 0;
323$cnt5 = 0;
324$cnt = 0;
325$cntrow = 0;
326//$data = array();
327//$counter=0;
328 while($times = mysql_fetch_array($observationsTime))
329 {
330 $timestamp=strtotime($times['fStart']);
331 $actualtime = date('Y-m-d H:i:s', $timestamp);
332 $timestamp2 = date('Y-m-d',$timestamp);
333 $date_time = date('H:i',$timestamp);
334 $prev_time[$cnt3]= $date_time;
335 ?>
336 $('#save').attr('value','UPDATE');
337 var targetView = document.getElementById("Data");
338 // CREATE ELEMENT
339 // COUNT LIST
340 var list = $(".datalisting").length;
341 var newlist = list+1;
342 <?php $cnt++;?>
343
344 var cctr=$('.dataTable tr').length;
345 ctr=cctr+1;
346 var input_data;
347 var select;
348 var option;
349 var selection;
350
351 var newdiv<?php echo $cnt; ?> = document.createElement("div");
352 newdiv<?php echo $cnt; ?>.setAttribute("id", "list_<?php echo $cnt; ?>");
353 newdiv<?php echo $cnt; ?>.setAttribute("class","datalisting");
354 newdiv<?php echo $cnt; ?>.setAttribute("style","margin:5px 0;");
355
356 var newtable = document.createElement("table");
357 newtable.setAttribute("class","dataTable");
358 newtable.setAttribute("width","100%");
359 newtable.setAttribute("border","1");
360 newtable.setAttribute("cellspacing","0");
361 newtable.setAttribute("cellpadding","0");
362
363
364 var newInnertable = document.createElement("table");
365 newInnertable.setAttribute("class","dataTable");
366 newInnertable.setAttribute("width","100%");
367 newInnertable.setAttribute("border","1");
368
369 newInnertable.setAttribute("cellspacing","0");
370 newInnertable.setAttribute("cellpadding","0");
371
372 var newtd_c1 = document.createElement("td");
373 newtd_c1.setAttribute("width","200");
374 newtd_c1.setAttribute("align","center");
375 newtd_c1.setAttribute("valign", "top");
376 newtd_c1.appendChild(
377 input_data = document.createElement("input"),
378 input_data.setAttribute("type","time"),
379 input_data.setAttribute("class","time"),
380 input_data.setAttribute("size","10"),
381 input_data.setAttribute("value","<?php echo $date_time; ?>"),
382 input_data.setAttribute("autofocus","true")
383 );
384 newtd_c1.appendChild(
385 input_data = document.createElement("input"),
386 input_data.setAttribute("type","button"),
387 input_data.setAttribute("value","+"),
388 input_data.onclick = function(){
389 addRowCloneNew("list_<?php echo $cnt; ?>");
390 }
391 );
392
393 <?php
394 $observations = mysql_query("SELECT * FROM schedule WHERE fStart = '$actualtime'");
395
396 while($rows = mysql_fetch_array($observations))
397 {
398 $cntrow++;
399 ?>
400
401 var newtr<?php echo $cntrow; ?> = document.createElement("tr");
402 newtr<?php echo $cntrow; ?>.setAttribute('class','tr');
403
404 var newtd_c2 = document.createElement("td");
405 newtd_c2.setAttribute("width","138");
406 newtd_c2.setAttribute("align","center");
407 newtd_c2.appendChild(
408 selection = document.createElement("select"),
409 <?php
410 $selectm = mysql_query("SELECT * FROM measurement");
411 while($rowmeasure = mysql_fetch_array($selectm))
412 {
413 ?>
414 selection.appendChild(
415 option = document.createElement("option"),
416 option.setAttribute("value","<?php echo $rowmeasure['fMeasurementKey']; ?>"),
417 <?php if($rows['fMeasurementTypeKey']==$rowmeasure['fMeasurementKey']){ echo "option.setAttribute('selected',true),";} ?>
418 option.appendChild(document.createTextNode("<?php echo $rowmeasure['fMeasurement']; ?>"))
419 ),
420 <?php
421 }
422 ?>
423
424
425 selection.setAttribute('id','measure'),
426 selection.setAttribute('class','measure')
427 );
428 newtd_c2.setAttribute("width","115");
429 newtd_c2.setAttribute("align","center");
430 newtd_c2.appendChild(
431 input_data = document.createElement("input"),
432 input_data.setAttribute("type","button"),
433 input_data.setAttribute("value","+"),
434 input_data.onclick = function(){
435 return addRow(newtr<?php echo $cntrow; ?>);
436 ctr++;
437 });
438 var newtd_c3 = document.createElement("td");
439 newtd_c3.setAttribute("width","98");
440 newtd_c3.setAttribute("align","center");
441 newtd_c3.appendChild(
442 selection = document.createElement("select"),
443 <?php
444 $select = mysql_query("SELECT * FROM source");
445 while($rowsource = mysql_fetch_array($select))
446 {
447 ?>
448 selection.appendChild(
449 option = document.createElement("option"),
450 option.setAttribute('value','<?php echo $rowsource['fSourceKEY']; ?>'),
451 <?php if($rows['fSourceKey'] == $rowsource['fSourceKEY']){ echo "option.setAttribute('selected',true),"; } ?>
452 option.appendChild(document.createTextNode("<?php echo $rowsource['fSourceName']; ?>"))
453 ),
454 <?php
455 }
456 ?>
457
458 selection.setAttribute('id','source'), // End of retrieving
459 selection.setAttribute('class','source') // End of retrieving
460 );
461 var newtd_c4 = document.createElement("td");
462 newtd_c4.setAttribute("width","119");
463 newtd_c4.setAttribute("align","center");
464 newtd_c4.appendChild(
465 input_data = document.createElement("input"),
466 input_data.setAttribute("type","text"),
467 input_data.setAttribute("class","selected"),
468 input_data.setAttribute("size","12"),
469 input_data.setAttribute("value","<?php echo $rows['fData']; ?>"),
470 input_data.setAttribute("placeholder","Value")
471 );
472 var newtd_c5 = document.createElement("td");
473 newtd_c5.setAttribute("width","115");
474 newtd_c5.setAttribute("align","center");
475 newtd_c5.setAttribute("width","115");
476 newtd_c5.setAttribute("align","center");
477 newtd_c5.appendChild(
478 input_data = document.createElement("input"),
479 input_data.setAttribute("type","button"),
480 input_data.setAttribute("value","Delete"),
481 input_data.onclick = function(){ return clearNode(newtr<?php echo $cntrow; ?>);
482
483 }
484 );
485 newtr<?php echo $cntrow; ?>.appendChild(newtd_c2);
486 newtr<?php echo $cntrow; ?>.appendChild(newtd_c3);
487 newtr<?php echo $cntrow; ?>.appendChild(newtd_c4);
488 newtr<?php echo $cntrow; ?>.appendChild(newtd_c5);
489 newInnertable.appendChild(newtr<?php echo $cntrow; ?>);
490
491 <?php
492
493 $prevtimestamp = $timestamp;
494 }
495 ?>
496
497 var newtd_c6 = document.createElement("td");
498 newtd_c6.appendChild(newInnertable);
499
500 var newtd_c7 = document.createElement("td");
501 newtd_c7.setAttribute("width","115");
502 newtd_c7.setAttribute("align","center");
503 newtd_c7.setAttribute("valign", "top");
504 newtd_c7.appendChild(
505 input_data = document.createElement("input"),
506 input_data.setAttribute("type","button"),
507 input_data.setAttribute("value","Delete Main"),
508 input_data.onclick = function(){ return clearNode(newdiv<?php echo $cnt; ?>); }
509 );
510
511 var newOutertr = document.createElement("tr");
512
513 newtable.appendChild(newtd_c1);
514 newtable.appendChild(newtd_c6);
515 newtable.appendChild(newtd_c7);
516
517 newdiv<?php echo $cnt; ?>.appendChild(newtable);
518 if(nextrow != null){
519 var doc = document.getElementById(nextrow);
520 $(doc).after(newdiv<?php echo $cnt;?>);
521 }else{
522 targetView.appendChild(newdiv<?php echo $cnt;?>);
523 //$(targetView).after(newtr<?php echo $cnt; ?>);
524 }
525 <?php
526}
527if(mysql_num_rows($fetch)<1)
528{
529?>
530 $('#save').attr('value','SAVE');
531 addRowCloneNew();
532<?php
533}
534
535?>
536
537
538}
539 </script>
540
Note: See TracBrowser for help on using the repository browser.