Index: schedule/Module/control.php
===================================================================
--- schedule/Module/control.php	(revision 17497)
+++ schedule/Module/control.php	(revision 17501)
@@ -1,3 +1,4 @@
 <script language="javascript">
+
 	var ctr;
 	
@@ -34,5 +35,5 @@
 				select = document.createElement("select"),
 				select.setAttribute("class","measure"),
-				$.ajax({	//Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
+				$.ajax({																	//Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
 				type:"post",
 				url:"Transaction/measurement.php",
@@ -47,5 +48,5 @@
 					})
 				}
-				})	// End of retrieving
+				})																				// End of retrieving
 			);
 			newtd_c2.setAttribute("width","115");
@@ -65,5 +66,5 @@
 					selection = document.createElement("select"),
 					selection.setAttribute("class","source"),
-					$.ajax({	//Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
+					$.ajax({																	//Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
 						type:"post",
 						url:"Transaction/source.php",
@@ -79,5 +80,5 @@
 							});
 						}
-					})	// End of retrieving		
+					})																			// End of retrieving		
 			);
 		var newtd_c4 = document.createElement("td");
@@ -145,7 +146,4 @@
 $days = Date('Y-m-d',strtotime($day));	
 $prev_time = array();
-$previousData = "false";
-$transaction = "save";
-
 ?>
 function addRowClone1(nextrow){
@@ -202,5 +200,5 @@
 			select = document.createElement("select"),
 			select.setAttribute("class","measure"),
-			$.ajax({	//Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
+			$.ajax({																	//Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
 			type:"post",
 			url:"Transaction/measurement.php",
@@ -214,6 +212,8 @@
 				)
 				})
+			
 			}
-			}) // End of retrieving
+			})																			// End of retrieving
+			
 		);
 		newtd_c2.setAttribute("width","115");
@@ -233,5 +233,5 @@
 			selection = document.createElement("select"),
 			selection.setAttribute("class","source"),
-			$.ajax({	//Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
+			$.ajax({																	//Retrieving Measurement name and id in Database september 13,2013 modify by Jaypee Tanio
 				type:"post",
 				url:"Transaction/source.php",
@@ -247,5 +247,5 @@
 					});
 				}
-			})	// End of retrieving
+			})																			// End of retrieving
 		);
 	var newtd_c4 = document.createElement("td");
@@ -296,4 +296,5 @@
 
 	newdiv.appendChild(newtable);
+
 	if(nextrow != null){	
 		var doc = document.getElementById(nextrow);
@@ -305,232 +306,211 @@
 
 function addRowClone(nextrow){
-	<?php
-	/*if($previousData == "true") {
-		$fetch = mysql_query("SELECT * FROM schedule WHERE date(fStart) < '$days' ORDER BY date(fStart) DESC, fScheduleID ASC, fMeasurementID ASC") or die(mysql_error());	
-		$firstRecord = mysql_fetch_array($fetch);
-		if($firstRecord != null) {
-			$firstRecordDate = strtotime($firstRecord['fStart']);
-			$days = date('Y-m-d', $firstRecordDate);
-		}
-		$previousData = "false";
-	}
-	else {
-		$fetch = mysql_query("SELECT * FROM schedule WHERE date(fStart) = '$days' ORDER BY fScheduleID ASC, fMeasurementID ASC") or die(mysql_error());
-		$transaction = "update";
-	}*/
-
-		$fetch = mysql_query("SELECT * FROM schedule WHERE date(fStart) = '$days' ORDER BY fScheduleID ASC, fMeasurementID ASC") or die(mysql_error());
-		$transaction = "update";
-
-	$observationsCount = mysql_query("SELECT COUNT(DISTINCT fStart) FROM schedule WHERE date(fStart) = '$days'");
-	$observationsTime = mysql_query("SELECT DISTINCT fStart FROM schedule WHERE date(fStart) = '$days'");
-
-	$cnt3=0;
-	$cnt2=0;
-	$cnt4 = 0;
-	$cnt5 = 0;
-	$prevtimestamp = 0;
-
-	while($times = mysql_fetch_array($observationsTime))
+<?php
+$fetch = mysql_query("SELECT * FROM schedule WHERE date(fStart) = '$days' ORDER BY fScheduleID ASC, fMeasurementID ASC") or die(mysql_error());
+$cnt3=0;
+$cnt2=0;
+$cnt4 = 0;
+$cnt5 = 0;
+//$data  = array();
+//$counter=0;
+$prevtimestamp = 0;
+
+	while($rows = mysql_fetch_array($fetch))
 	{
-			?> alert("Fetching data"); <?php
-			$timestamp=strtotime($times['fStart']);
-			$actualtime = date('Y-m-d H:i:s', $timestamp);
-			$timestamp2 = date('Y-m-d',$timestamp);
-			$date_time = date('H:i:s',$timestamp);
-			$prev_time[$cnt3]= $date_time;
-	?>
-				var targetView = document.getElementById("Data");
-				// CREATE ELEMENT
-				// COUNT LIST
-				var list     = $(".datalisting").length;
-				var newlist = list+1;
-			
-				var cctr=$('.dataTable tr').length;
-					 ctr=cctr+1;
-					 
-				var newdiv   = document.createElement("div");
-					newdiv.setAttribute("id","list_"+newlist);
-					newdiv.setAttribute("class","datalisting");
-					newdiv.setAttribute("style","margin:5px 0;");
-			
-				var newtable = document.createElement("table");
-					newtable.setAttribute("class","dataTable");
-					newtable.setAttribute("width","100%");
-					newtable.setAttribute("border","1");
-					newtable.setAttribute("cellspacing","0");
-					newtable.setAttribute("cellpadding","0");
-			
-				var newInnertable = document.createElement("table");
-					newInnertable.setAttribute("class","dataTable");
-					newInnertable.setAttribute("width","100%");
-					newInnertable.setAttribute("border","1");
+		$scheduleId = $rows['fScheduleID'];
+		$timestamp=strtotime($rows['fStart']);
+		$timestamp2 = date('Y-m-d',$timestamp);
+		$date_time = date('H:i:s',$timestamp);
+		$prev_time[$cnt3]= $date_time;
+			?>
+			$('#save').attr('value','UPDATE');
+			var targetView = document.getElementById("Data");
+			// CREATE ELEMENT
+			// COUNT LIST
+			var list     = $(".datalisting").length;
+			var newlist = list+1;
+			
+			var cctr=$('.dataTable tr').length;
+				 ctr=cctr+1;
+				 
+			var newdiv   = document.createElement("div");
+				newdiv.setAttribute("id","list_"+newlist);
+				newdiv.setAttribute("class","datalisting");
+				newdiv.setAttribute("style","margin:5px 0;");
+			
+			var newtable = document.createElement("table");
+				newtable.setAttribute("class","dataTable");
+				newtable.setAttribute("width","100%");
+				newtable.setAttribute("border","1");
+				newtable.setAttribute("cellspacing","0");
+				newtable.setAttribute("cellpadding","0");
+
+			
+			var newInnertable = document.createElement("table");
+				newInnertable.setAttribute("class","dataTable");
+				newInnertable.setAttribute("width","100%");
+				newInnertable.setAttribute("border","1");
 				
-					newInnertable.setAttribute("cellspacing","0");
-					newInnertable.setAttribute("cellpadding","0");
-			
-				var newtd_c1 = document.createElement("td");
-					newtd_c1.setAttribute("width","200");
-					newtd_c1.setAttribute("align","center");
-					newtd_c1.appendChild(
-						input_data = document.createElement("input"),
-						input_data.setAttribute("type","time"),
-						input_data.setAttribute("class","time"),
-						input_data.setAttribute("size","10"),
-						input_data.setAttribute("value","<?php echo $date_time; ?>"),
-						input_data.setAttribute("autofocus","true")
-					);
-					newtd_c1.appendChild(
-						input_data = document.createElement("input"),
-						input_data.setAttribute("type","button"),
-						input_data.setAttribute("value","+"),
-						input_data.onclick = function(){
-							addRowClone1("list_<?php echo $cnt+1; ?>");
-						}
-					);
-			
-		<?php
-	
-		$observations = mysql_query("SELECT * FROM schedule WHERE fStart = '$actualtime'");
-
-		while($rows = mysql_fetch_array($observations))
+				newInnertable.setAttribute("cellspacing","0");
+				newInnertable.setAttribute("cellpadding","0");
+			
+			var newtd_c1 = document.createElement("td");
+				newtd_c1.setAttribute("width","200");
+				newtd_c1.setAttribute("align","center");
+				newtd_c1.appendChild(
+					input_data = document.createElement("input"),
+					input_data.setAttribute("type","time"),
+					input_data.setAttribute("class","time"),
+					input_data.setAttribute("size","10"),
+					input_data.setAttribute("value","<?php echo $date_time; ?>"),
+					input_data.setAttribute("autofocus","true")
+				);
+				newtd_c1.appendChild(
+					input_data = document.createElement("input"),
+					input_data.setAttribute("type","button"),
+					input_data.setAttribute("value","+"),
+					input_data.onclick = function(){
+						addRowClone1("list_<?php echo $cnt+1; ?>");
+					}
+				);
+			
+			var newtr<?php echo $cnt; ?> = document.createElement("tr");
+				newtr<?php echo $cnt; ?>.setAttribute('class','tr');
+			
+			var newtd_c2 = document.createElement("td");
+				newtd_c2.setAttribute("width","138");
+				newtd_c2.setAttribute("align","center");
+				newtd_c2.appendChild(
+					selection = document.createElement("select"),
+		<?php   
+		$selectm = mysql_query("SELECT * FROM measurement");
+		while($rowmeasure = mysql_fetch_array($selectm))
 		{
 		?>
-				var newtr<?php echo $cnt; ?> = document.createElement("tr");
-					newtr<?php echo $cnt; ?>.setAttribute('class','tr');
-
-				var newtd_c2 = document.createElement("td");
-					newtd_c2.setAttribute("width","138");
-					newtd_c2.setAttribute("align","center");
-					newtd_c2.appendChild(
-						selection = document.createElement("select"),
-				<?php   
-				$selectm = mysql_query("SELECT * FROM measurement");
-				while($rowmeasure = mysql_fetch_array($selectm))
-				{
-				?>
-							selection.appendChild(
-							option = document.createElement("option"),
-							option.setAttribute("value","<?php echo $rowmeasure['fMeasurementKey']; ?>"),
-							<?php  if($rows['fMeasurementTypeKey']==$rowmeasure['fMeasurementKey']){ echo "option.setAttribute('selected',true),";}   ?>
-							option.appendChild(document.createTextNode("<?php echo $rowmeasure['fMeasurement']; ?>"))
-							),
-				<?php 
-				} 
-				?>
-							selection.setAttribute('id','measure'),
-							selection.setAttribute('class','measure')
-						);
-						newtd_c2.setAttribute("width","115");
-						newtd_c2.setAttribute("align","center");
-						newtd_c2.appendChild(
-							input_data = document.createElement("input"),
-							input_data.setAttribute("type","button"),
-							input_data.setAttribute("value","+"),
-							input_data.onclick = function(){ 
-							return addRow(newtr<?php echo $cnt; ?>);
-								ctr++;
-							});
-					var newtd_c3 = document.createElement("td");
-						newtd_c3.setAttribute("width","98");
-						newtd_c3.setAttribute("align","center");
-						newtd_c3.appendChild(
-							selection = document.createElement("select"),
-				<?php
-				$select = mysql_query("SELECT * FROM source");
-				while($rowsource = mysql_fetch_array($select))
-				{
-				?>
-								selection.appendChild(
-								option = document.createElement("option"),
-								option.setAttribute('value','<?php echo $rowsource['fSourceKEY']; ?>'),
-								<?php if($rows['fSourceKey'] == $rowsource['fSourceKEY']){ echo "option.setAttribute('selected',true),"; } ?>
-								option.appendChild(document.createTextNode("<?php echo $rowsource['fSourceName']; ?>"))
-								),
-				<?php
-				} 
-				?>
+					selection.appendChild(
+					option = document.createElement("option"),
+					option.setAttribute("value","<?php echo $rowmeasure['fMeasurementKey']; ?>"),
+					<?php  if($rows['fMeasurementTypeKey']==$rowmeasure['fMeasurementKey']){ echo "option.setAttribute('selected',true),";}   ?>
+					option.appendChild(document.createTextNode("<?php echo $rowmeasure['fMeasurement']; ?>"))
+					),
+		<?php 
+		} 
+		?>
+						
+						
+					selection.setAttribute('id','measure'),
+					selection.setAttribute('class','measure')
+				);
+				newtd_c2.setAttribute("width","115");
+				newtd_c2.setAttribute("align","center");
+				newtd_c2.appendChild(
+					input_data = document.createElement("input"),
+					input_data.setAttribute("type","button"),
+					input_data.setAttribute("value","+"),
+					input_data.onclick = function(){ 
+					return addRow(newtr<?php echo $cnt; ?>);
+						ctr++;
+					});
+			var newtd_c3 = document.createElement("td");
+				newtd_c3.setAttribute("width","98");
+				newtd_c3.setAttribute("align","center");
+				newtd_c3.appendChild(
+					selection = document.createElement("select"),
+		<?php
+		$select = mysql_query("SELECT * FROM source");
+		while($rowsource = mysql_fetch_array($select))
+		{
+		?>
+						selection.appendChild(
+						option = document.createElement("option"),
+						option.setAttribute('value','<?php echo $rowsource['fSourceKEY']; ?>'),
+						<?php if($rows['fSourceKey'] == $rowsource['fSourceKEY']){ echo "option.setAttribute('selected',true),"; } ?>
+						option.appendChild(document.createTextNode("<?php echo $rowsource['fSourceName']; ?>"))
+						),
+		<?php
+		} 
+		?>
 					
-							selection.setAttribute('id','source'),	// End of retrieving
-							selection.setAttribute('class','source')	// End of retrieving
-						);
-					var newtd_c4 = document.createElement("td");
-						newtd_c4.setAttribute("width","119");
-						newtd_c4.setAttribute("align","center");
-						newtd_c4.appendChild(
-							input_data = document.createElement("input"),
-							input_data.setAttribute("type","text"),
-							input_data.setAttribute("class","selected"),
-							input_data.setAttribute("size","12"),
-							input_data.setAttribute("value","<?php echo $rows['fData']; ?>"),
-							input_data.setAttribute("placeholder","Value")
-						);
-					var newtd_c5 = document.createElement("td");
-						newtd_c5.setAttribute("width","115");
-						newtd_c5.setAttribute("align","center");
-						newtd_c5.setAttribute("width","115");
-						newtd_c5.setAttribute("align","center");
-						newtd_c5.appendChild(
-							input_data = document.createElement("input"),
-							input_data.setAttribute("type","button"),
-							input_data.setAttribute("value","Delete"),
-							input_data.onclick = function(){ return clearNode(newtr<?php echo $cnt; ?>);
-							}
-						);
-			
-					newtr<?php echo $cnt; ?>.appendChild(newtd_c2);
-					newtr<?php echo $cnt; ?>.appendChild(newtd_c3);
-					newtr<?php echo $cnt; ?>.appendChild(newtd_c4);
-					newtr<?php echo $cnt; ?>.appendChild(newtd_c5);
-					newInnertable.appendChild(newtr<?php echo $cnt; ?>);
-			<?php		
-				$cnt++;
-				$prevtimestamp = $timestamp;
+					selection.setAttribute('id','source'),																			// End of retrieving
+					selection.setAttribute('class','source')																			// End of retrieving
+				);
+			var newtd_c4 = document.createElement("td");
+				newtd_c4.setAttribute("width","119");
+				newtd_c4.setAttribute("align","center");
+				newtd_c4.appendChild(
+					input_data = document.createElement("input"),
+					input_data.setAttribute("type","text"),
+					input_data.setAttribute("class","selected"),
+					input_data.setAttribute("size","12"),
+					input_data.setAttribute("value","<?php echo $rows['fData']; ?>"),
+					input_data.setAttribute("placeholder","Value")
+				);
+			var newtd_c5 = document.createElement("td");
+				newtd_c5.setAttribute("width","115");
+				newtd_c5.setAttribute("align","center");
+				newtd_c5.setAttribute("width","115");
+				newtd_c5.setAttribute("align","center");
+				newtd_c5.appendChild(
+					input_data = document.createElement("input"),
+					input_data.setAttribute("type","button"),
+					input_data.setAttribute("value","Delete"),
+					input_data.onclick = function(){ return clearNode(newtr<?php echo $cnt; ?>);
+					}
+				);
+			
+			newtr<?php echo $cnt; ?>.appendChild(newtd_c2);
+			newtr<?php echo $cnt; ?>.appendChild(newtd_c3);
+			newtr<?php echo $cnt; ?>.appendChild(newtd_c4);
+			newtr<?php echo $cnt; ?>.appendChild(newtd_c5);
+			newInnertable.appendChild(newtr<?php echo $cnt; ?>);
+			
+			var newtd_c6 = document.createElement("td");
+				newtd_c6.appendChild(newInnertable);
+
+			var newtd_c7 = document.createElement("td");
+				newtd_c7.setAttribute("width","115");
+				newtd_c7.setAttribute("align","center");
+				newtd_c7.appendChild(
+					input_data = document.createElement("input"),
+					input_data.setAttribute("type","button"),
+					input_data.setAttribute("value","Delete Main"),
+					input_data.onclick = function(){ return clearNode(newdiv); }
+				);
+
+			var newOutertr = document.createElement("tr");
+
+			newtable.appendChild(newtd_c1);
+			newtable.appendChild(newtd_c6);
+			newtable.appendChild(newtd_c7);
+
+			newdiv.appendChild(newtable);
+
+			if(nextrow != null){	
+				var doc = document.getElementById(nextrow);
+				$(doc).after(newdiv);
+			} else {
+				targetView.appendChild(newdiv);
+				//$(targetView).after(newtr<?php echo $cnt; ?>);
 			}
-			?>
-				var newtd_c6 = document.createElement("td");
-					newtd_c6.appendChild(newInnertable);
-
-				var newtd_c7 = document.createElement("td");
-					newtd_c7.setAttribute("width","115");
-					newtd_c7.setAttribute("align","center");
-					newtd_c7.appendChild(
-						input_data = document.createElement("input"),
-						input_data.setAttribute("type","button"),
-						input_data.setAttribute("value","Delete Main"),
-						input_data.onclick = function(){ return clearNode(newdiv); }
-					);
-
-				var newOutertr = document.createElement("tr");
-
-				newtable.appendChild(newtd_c1);
-				newtable.appendChild(newtd_c6);
-				newtable.appendChild(newtd_c7);
-
-				newdiv.appendChild(newtable);
-
-				if(nextrow != null){	
-					var doc = document.getElementById(nextrow);
-					$(doc).after(newdiv);
-				} else {
-					targetView.appendChild(newdiv);
-				}	
-		<?php
+	<?php
+//$rows = mysql_fetch_array($fetch);	
+			
+		$cnt++;
+		$prevtimestamp = $timestamp;
 	}
 
-	if(mysql_num_rows($fetch)<1)
-	{
-	?>
-		$('#save').attr('value','SAVE');
-		addRowClone1();
-	<?php
-	}
-	?>
+
+if(mysql_num_rows($fetch)<1)
+{
+?>
+	$('#save').attr('value','SAVE');
+	addRowClone1();
+<?php
 }
 
-/*function loadPreviousData(){
-	<?php $previousData = "true"; ?>
-	addRowClone();
-}*/
+?>
+
+			
+}
  </script>
 	
