Index: SysLogController.groovy
===================================================================
--- SysLogController.groovy	(revision 41)
+++ SysLogController.groovy	(revision 42)
@@ -40,7 +40,43 @@
 		
 		flash['warnings'] = null
 		
-		def entries = LoggedData.list()
+		List devicesForCheckBox = new ArrayList()
+		DeviceInfo.findAllByInputDeviceOrOutputDevice(true,true).each {
+			devicesForCheckBox << it
+		}
+		
+		def entries = new ArrayList()
+		
+		List checkedDevices = new ArrayList()
+		devicesForCheckBox.each {
+			if(params['cb_' + it.deviceId]) {
+				checkedDevices << it.deviceId
+			}
+		}
+		
+		if(params['fromDate'] && params['tillDate']) {
+			if(params['all_cb']) {
+				def c = LoggedData.createCriteria()
+				entries = c {
+					and {
+						between("dateRecieved",params['fromDate'],params['tillDate'])
+					}
+					order("dateRecieved","asc")
+				}
+			} else {
+				if(checkedDevices.size > 0) {
+					def c = LoggedData.createCriteria()
+					entries = c {
+						and {
+							between("dateRecieved",params['fromDate'],params['tillDate'])
+							'in'("deviceId",checkedDevices)
+						}
+						order("dateRecieved","asc")
+					}
+				}
+			}
+		}
+
 		Map devices = new HashMap()
 		Map icons   = new HashMap()
 		List unknownDevices = new ArrayList()
@@ -62,7 +98,7 @@
 			flash['warnings'] += "<p>There was found at least one log entry for a device with id <b>${it}</b>, which is <b>unknown</b> to HCI. You should <b>add this device</b> by <b>" + g.link(controller: 'config', action: 'addDevice', params: ['deviceId' : it], "clicking here") + "</b>.</p>"
 		}
 		
-		[data: entries, devices: devices, icons: icons]
+		[data: entries, devices: devices, icons: icons, devicesForCheckBox:devicesForCheckBox]
 		
 	}
 	
@@ -122,5 +158,147 @@
 		[data: data, devices: devices, params:params]
 		
 	}
+	
+	def export = {
+		
+		List devicesForCheckBox = new ArrayList()
+		DeviceInfo.findAllByInputDeviceOrOutputDevice(true,true).each {
+			devicesForCheckBox << it
+		}
+		
+		[devicesForCheckBox: devicesForCheckBox]
+		
+	}
+	
+	def exportDo = {
+		
+		List devicesForCheckBox = new ArrayList()
+		DeviceInfo.findAllByInputDeviceOrOutputDevice(true,true).each {
+			devicesForCheckBox << it
+		}
+		
+		List checkedDevices = new ArrayList()
+		devicesForCheckBox.each {
+			if(params['cb_' + it.deviceId]) {
+				checkedDevices << it.deviceId
+			}
+		}
+		
+		List entries = new ArrayList()
+		def cont = ""
+		
+		if(params['all_cb']) {
+			def c = LoggedData.createCriteria()
+			entries = c {
+				and {
+					between("dateRecieved",params['fromDate'],params['tillDate'])
+				}
+				order("dateRecieved","asc")
+			}
+		} else {
+			if(checkedDevices.size > 0) {
+				def c = LoggedData.createCriteria()
+				entries = c {
+					and {
+						between("dateRecieved",params['fromDate'],params['tillDate'])
+						'in'("deviceId",checkedDevices)
+					}
+					order("dateRecieved","asc")
+				}
+			}
+		}
+		
+		if(entries.size == 0) {
+			flash['errors'] = "<p>Nothing to export!</p><p>There are no log entries for selected devices in the time interval specified.</p>"
+			redirect(action:'export')
+		}
+		else if(params['format'] == "Plain text (.txt)") {
+			entries.each {
+				cont += it.dateRecieved.toString() + " " + it.deviceId + " " + it.reportedData + "\n"
+			}
+			render(text: cont,contentType:"text/plain",encoding:"UTF-8")
+		} else if(params['format'] == "PostgreSQL script (.sql)") {
+			entries.each {
+				cont += "INSERT INTO logged_data(id, \"version\", date_recieved, device_id, reported_data) VALUES (nextval('hibernate_sequence'), 0, '" + it.dateRecieved.toString() + "', '" + it.deviceId + "', '" + it.reportedData + "');\n";
+			}
+			render(text: cont,contentType:"text/plain",encoding:"UTF-8")
+		} else {
+			cont += "<log>\n"
+			entries.each {
+				cont += "\t<entry>\n"
+				cont += "\t\t<device>" + it.deviceId + "</device>\n"
+				cont += "\t\t<time>" + it.dateRecieved.toString() + "</time>\n"
+				cont += "\t\t<data>\n"
+				cont += "\t\t\t" + it.reportedData + "\n"
+				cont += "\t\t</data>\n"
+				cont += "\t</entry>\n"
+			}
+			cont += "</log>"
+			render(text: cont,contentType:"text/xml",encoding:"UTF-8")
+		}
+	}
+	
+	def clear = {
+		
+		List devicesForCheckBox = new ArrayList()
+		DeviceInfo.findAllByInputDeviceOrOutputDevice(true,true).each {
+			devicesForCheckBox << it
+		}
+		
+		[devicesForCheckBox: devicesForCheckBox]
+		
+	}
+	
+	def clearDo = {
+		
+		List devicesForCheckBox = new ArrayList()
+		DeviceInfo.findAllByInputDeviceOrOutputDevice(true,true).each {
+			devicesForCheckBox << it
+		}
+		
+		List checkedDevices = new ArrayList()
+		devicesForCheckBox.each {
+			if(params['cb_' + it.deviceId]) {
+				checkedDevices << it.deviceId
+			}
+		}
+		
+		List entries = new ArrayList()
+		def cont = ""
+		
+		if(params['all_cb']) {
+			def c = LoggedData.createCriteria()
+			entries = c {
+				and {
+					between("dateRecieved",params['fromDate'],params['tillDate'])
+				}
+				order("dateRecieved","asc")
+			}
+		} else {
+			if(checkedDevices.size > 0) {
+				def c = LoggedData.createCriteria()
+				entries = c {
+					and {
+						between("dateRecieved",params['fromDate'],params['tillDate'])
+						'in'("deviceId",checkedDevices)
+					}
+					order("dateRecieved","asc")
+				}
+			}
+		}
+		
+		if(entries.size == 0) {
+			flash['errors'] = "<p>Nothing to clear!</p><p>There are no log entries for selected devices in the time interval specified.</p>"
+		} else {
+			def entCleared = 0
+			entries.each {
+				it.delete()
+				entCleared++
+			}
+			flash['confirms'] = "<p>" + entCleared + " log entries succesfully cleared!</p>"
+		}
+		redirect(action:'clear')
+		
+	}
 	
 }
