source: schedule/Module/control.php@ 17508

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