source: schedule/Module/control.php@ 17489

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