source: schedule/Module/control.php@ 17490

Last change on this file since 17490 was 17490, checked in by tose, 12 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 while($times = mysql_fetch_array($observationsTime))
331 {
332 $timestamp=strtotime($times['fStart']);
333 $actualtime = date('Y-m-d H:i:s', $timestamp);
334 $timestamp2 = date('Y-m-d',$timestamp);
335 $date_time = date('H:i:s',$timestamp);
336 $prev_time[$cnt3]= $date_time;
337 ?>
338 var targetView = document.getElementById("Data");
339 // CREATE ELEMENT
340 // COUNT LIST
341 var list = $(".datalisting").length;
342 var newlist = list+1;
343
344 var cctr=$('.dataTable tr').length;
345 ctr=cctr+1;
346
347 var newdiv = document.createElement("div");
348 newdiv.setAttribute("id","list_"+newlist);
349 newdiv.setAttribute("class","datalisting");
350 newdiv.setAttribute("style","margin:5px 0;");
351
352 var newtable = document.createElement("table");
353 newtable.setAttribute("class","dataTable");
354 newtable.setAttribute("width","100%");
355 newtable.setAttribute("border","1");
356 newtable.setAttribute("cellspacing","0");
357 newtable.setAttribute("cellpadding","0");
358
359 var newInnertable = document.createElement("table");
360 newInnertable.setAttribute("class","dataTable");
361 newInnertable.setAttribute("width","100%");
362 newInnertable.setAttribute("border","1");
363
364 newInnertable.setAttribute("cellspacing","0");
365 newInnertable.setAttribute("cellpadding","0");
366
367 var newtd_c1 = document.createElement("td");
368 newtd_c1.setAttribute("width","200");
369 newtd_c1.setAttribute("align","center");
370 newtd_c1.appendChild(
371 input_data = document.createElement("input"),
372 input_data.setAttribute("type","time"),
373 input_data.setAttribute("class","time"),
374 input_data.setAttribute("size","10"),
375 input_data.setAttribute("value","<?php echo $date_time; ?>"),
376 input_data.setAttribute("autofocus","true")
377 );
378 newtd_c1.appendChild(
379 input_data = document.createElement("input"),
380 input_data.setAttribute("type","button"),
381 input_data.setAttribute("value","+"),
382 input_data.onclick = function(){
383 addRowClone1("list_<?php echo $cnt+1; ?>");
384 }
385 );
386
387 <?php
388
389 $observations = mysql_query("SELECT * FROM schedule WHERE fStart = '$actualtime'");
390
391 while($rows = mysql_fetch_array($observations))
392 {
393 ?>
394 var newtr<?php echo $cnt; ?> = document.createElement("tr");
395 newtr<?php echo $cnt; ?>.setAttribute('class','tr');
396
397 var newtd_c2 = document.createElement("td");
398 newtd_c2.setAttribute("width","138");
399 newtd_c2.setAttribute("align","center");
400 newtd_c2.appendChild(
401 selection = document.createElement("select"),
402 <?php
403 $selectm = mysql_query("SELECT * FROM measurement");
404 while($rowmeasure = mysql_fetch_array($selectm))
405 {
406 ?>
407 selection.appendChild(
408 option = document.createElement("option"),
409 option.setAttribute("value","<?php echo $rowmeasure['fMeasurementKey']; ?>"),
410 <?php if($rows['fMeasurementTypeKey']==$rowmeasure['fMeasurementKey']){ echo "option.setAttribute('selected',true),";} ?>
411 option.appendChild(document.createTextNode("<?php echo $rowmeasure['fMeasurement']; ?>"))
412 ),
413 <?php
414 }
415 ?>
416 selection.setAttribute('id','measure'),
417 selection.setAttribute('class','measure')
418 );
419 newtd_c2.setAttribute("width","115");
420 newtd_c2.setAttribute("align","center");
421 newtd_c2.appendChild(
422 input_data = document.createElement("input"),
423 input_data.setAttribute("type","button"),
424 input_data.setAttribute("value","+"),
425 input_data.onclick = function(){
426 return addRow(newtr<?php echo $cnt; ?>);
427 ctr++;
428 });
429 var newtd_c3 = document.createElement("td");
430 newtd_c3.setAttribute("width","98");
431 newtd_c3.setAttribute("align","center");
432 newtd_c3.appendChild(
433 selection = document.createElement("select"),
434 <?php
435 $select = mysql_query("SELECT * FROM source");
436 while($rowsource = mysql_fetch_array($select))
437 {
438 ?>
439 selection.appendChild(
440 option = document.createElement("option"),
441 option.setAttribute('value','<?php echo $rowsource['fSourceKEY']; ?>'),
442 <?php if($rows['fSourceKey'] == $rowsource['fSourceKEY']){ echo "option.setAttribute('selected',true),"; } ?>
443 option.appendChild(document.createTextNode("<?php echo $rowsource['fSourceName']; ?>"))
444 ),
445 <?php
446 }
447 ?>
448
449 selection.setAttribute('id','source'), // End of retrieving
450 selection.setAttribute('class','source') // End of retrieving
451 );
452 var newtd_c4 = document.createElement("td");
453 newtd_c4.setAttribute("width","119");
454 newtd_c4.setAttribute("align","center");
455 newtd_c4.appendChild(
456 input_data = document.createElement("input"),
457 input_data.setAttribute("type","text"),
458 input_data.setAttribute("class","selected"),
459 input_data.setAttribute("size","12"),
460 input_data.setAttribute("value","<?php echo $rows['fData']; ?>"),
461 input_data.setAttribute("placeholder","Value")
462 );
463 var newtd_c5 = document.createElement("td");
464 newtd_c5.setAttribute("width","115");
465 newtd_c5.setAttribute("align","center");
466 newtd_c5.setAttribute("width","115");
467 newtd_c5.setAttribute("align","center");
468 newtd_c5.appendChild(
469 input_data = document.createElement("input"),
470 input_data.setAttribute("type","button"),
471 input_data.setAttribute("value","Delete"),
472 input_data.onclick = function(){ return clearNode(newtr<?php echo $cnt; ?>);
473 }
474 );
475
476 newtr<?php echo $cnt; ?>.appendChild(newtd_c2);
477 newtr<?php echo $cnt; ?>.appendChild(newtd_c3);
478 newtr<?php echo $cnt; ?>.appendChild(newtd_c4);
479 newtr<?php echo $cnt; ?>.appendChild(newtd_c5);
480 newInnertable.appendChild(newtr<?php echo $cnt; ?>);
481 <?php
482 $cnt++;
483 $prevtimestamp = $timestamp;
484 }
485 ?>
486 var newtd_c6 = document.createElement("td");
487 newtd_c6.appendChild(newInnertable);
488
489 var newtd_c7 = document.createElement("td");
490 newtd_c7.setAttribute("width","115");
491 newtd_c7.setAttribute("align","center");
492 newtd_c7.appendChild(
493 input_data = document.createElement("input"),
494 input_data.setAttribute("type","button"),
495 input_data.setAttribute("value","Delete Main"),
496 input_data.onclick = function(){ return clearNode(newdiv); }
497 );
498
499 var newOutertr = document.createElement("tr");
500
501 newtable.appendChild(newtd_c1);
502 newtable.appendChild(newtd_c6);
503 newtable.appendChild(newtd_c7);
504
505 newdiv.appendChild(newtable);
506
507 if(nextrow != null){
508 var doc = document.getElementById(nextrow);
509 $(doc).after(newdiv);
510 } else {
511 targetView.appendChild(newdiv);
512 }
513 <?php
514 }
515
516 if((mysql_num_rows($fetch)<1) || ($transaction == "save"))
517 {
518 $transaction = "save";
519 ?>
520 $('#save').attr('value','SAVE');
521 addRowClone1();
522 <?php
523 }
524 else {
525 ?>
526 $('#save').attr('value','UPDATE');
527 <?php
528 }
529 ?>
530}
531
532function loadPreviousData(){
533 <?php $previousData = "true"; ?>
534 addRowClone();
535}
536 </script>
537
Note: See TracBrowser for help on using the repository browser.