source: schedule/Module/control.php@ 17493

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