Index: schedule/Module/control.php
===================================================================
--- schedule/Module/control.php	(revision 17454)
+++ schedule/Module/control.php	(revision 17455)
@@ -306,23 +306,25 @@
 
 function addRowClone(nextrow){
-<?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))
+	<?php
+	$fetch = mysql_query("SELECT * FROM schedule WHERE date(fStart) = '$days' ORDER BY fStart ASC, fMeasurementID ASC") or die(mysql_error());
+	$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;
+	//$data  = array();
+	//$counter=0;
+	$prevtimestamp = 0;
+
+	while($times = mysql_fetch_array($observationsTime))
 	{
-		$scheduleId = $rows['fScheduleID'];
-		$timestamp=strtotime($rows['fStart']);
+		$timestamp=strtotime($times['fStart']);
 		$timestamp2 = date('Y-m-d',$timestamp);
-		$date_time = date('H:i:s',$timestamp);
+		$date_time = date('H:i:s',$timestamp);		
 		$prev_time[$cnt3]= $date_time;
-			?>
-			$('#save').attr('value','UPDATE');
+		$('#save').attr('value','UPDATE');
+		?>
 			var targetView = document.getElementById("Data");
 			// CREATE ELEMENT
@@ -330,8 +332,8 @@
 			var list     = $(".datalisting").length;
 			var newlist = list+1;
-			
+	
 			var cctr=$('.dataTable tr').length;
-				 ctr=cctr+1;
-				 
+			ctr=cctr+1;
+					 
 			var newdiv   = document.createElement("div");
 				newdiv.setAttribute("id","list_"+newlist);
@@ -345,5 +347,4 @@
 				newtable.setAttribute("cellspacing","0");
 				newtable.setAttribute("cellpadding","0");
-
 			
 			var newInnertable = document.createElement("table");
@@ -352,6 +353,6 @@
 				newInnertable.setAttribute("border","1");
 				
-				newInnertable.setAttribute("cellspacing","0");
-				newInnertable.setAttribute("cellpadding","0");
+			newInnertable.setAttribute("cellspacing","0");
+			newInnertable.setAttribute("cellpadding","0");
 			
 			var newtd_c1 = document.createElement("td");
@@ -372,144 +373,145 @@
 					input_data.onclick = function(){
 						addRowClone1("list_<?php echo $cnt+1; ?>");
+						}
+				);		
+			<?php
+
+			$observations = mysql_query("SELECT * FROM schedule WHERE fStart = '$timestamp'");
+
+			while($rows = mysql_fetch_array($observations))
+			{
+				$scheduleId = $rows['fScheduleID'];
+				?>
+					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.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
+			}
+			?>
+					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 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))
+	
+		<?php
+					$cnt++;
+					$prevtimestamp = $timestamp;
+		}
+		if(mysql_num_rows($fetch)<1)
 		{
 		?>
-					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"),
+			$('#save').attr('value','SAVE');
+			addRowClone1();
 		<?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; ?>);
-			
-			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; ?>);
-			}
-	<?php
-//$rows = mysql_fetch_array($fetch);	
-			
-		$cnt++;
-		$prevtimestamp = $timestamp;
-	}
-
-
-if(mysql_num_rows($fetch)<1)
-{
-?>
-	$('#save').attr('value','SAVE');
-	addRowClone1();
-<?php
-}
-
-?>
-
-			
+		}		
+		?>	
 }
  </script>
