19 Commits

Author SHA1 Message Date
7207f39892 Version 0.3.1-Beta 2020-01-23 18:06:03 +01:00
a9cf947670 log improvements 2020-01-23 17:33:40 +01:00
664ba5e28b multiple replies on device request with more than one city provided 2020-01-23 17:33:00 +01:00
d34b43f61a enable multiple cities per device
applied db entries on add btn click
2020-01-23 17:10:22 +01:00
c590b612b5 some name and warning fixings 2020-01-20 18:20:37 +01:00
81e79c1e67 adding info to db 2020-01-18 11:02:00 +01:00
7f62fc9bec add button for adding new zone infos to device 2020-01-18 10:17:33 +01:00
fa16d1206b waste zone/type/city info on device page 2020-01-18 08:42:08 +01:00
ce44ee5d17 version 0.3.0-Beta 2020-01-16 21:24:21 +01:00
23f75cae4f correctly configure new devices
edit data in db correctly
response correctly to requests
2020-01-16 21:12:05 +01:00
b9ba0dbcef load devices in table
configure popup for devices
2020-01-16 17:27:16 +01:00
92ef4cc0c6 * added table to device page
* request devices from js from db
2020-01-13 21:00:33 +01:00
ac02e4bd62 * added some todos 2020-01-12 14:05:28 +01:00
c3fb92d6eb * changed city zone handling to server instead of pcb 2020-01-12 13:22:31 +01:00
05b15a1ea2 * style improvements in mqtt 2020-01-12 11:32:33 +01:00
86dc38a8da * Waste logo on every page
* username displayed right on every page
2020-01-12 11:23:47 +01:00
7c8a0d3018 * mqtt service cleanup
* removed unused methods
2020-01-12 11:23:05 +01:00
4b96ad576d cleanup in mqtt methods
deleted unneccessary classes
2020-01-10 18:45:32 +01:00
f7383474ac * fixed multiple username bug
* added table to devices page
2020-01-10 18:18:06 +01:00
27 changed files with 854 additions and 561 deletions

2
.idea/misc.xml generated
View File

@ -4,7 +4,7 @@
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_13" default="true" project-jdk-name="13" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -5,7 +5,7 @@ plugins {
}
group 'com.wasteinformationserver'
version '0.2.1-Beta'
version '0.3.1-Beta'
sourceCompatibility = 1.8
@ -32,7 +32,7 @@ dependencies {
task run (type: JavaExec){
description = "Secure algorythm testing"
main = 'com.wasteinformationserver.main'
main = 'com.wasteinformationserver.Main'
classpath = sourceSets.main.runtimeClasspath
}

View File

@ -1,3 +1,6 @@
/**
* dead code...
*/
package com.wasteinformationserver;
import com.wasteinformationserver.basicutils.Log;

View File

@ -2,20 +2,19 @@ package com.wasteinformationserver;
import com.wasteinformationserver.basicutils.Info;
import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.JDCB;
import com.wasteinformationserver.mqtt.mqtt;
import com.wasteinformationserver.db.JDBC;
import com.wasteinformationserver.mqtt.MqttService;
import com.wasteinformationserver.website.Webserver;
import java.io.IOException;
public class main {
public class Main {
public static void main(String[] args) {
Log.setLevel(Log.DEBUG);
Info.init();
Log.setLevel(Log.INFO);
Log.info("startup of WasteInformationServer");
Log.info("mem: "+Runtime.getRuntime().totalMemory());
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
Thread.sleep(200);
@ -27,21 +26,18 @@ public class main {
}
}));
Info.init();
Log.info("Server version: " + Info.getVersion());
Log.debug("Build date: " + Info.getBuilddate());
//initial connect to db
Log.message("initial login to db");
new Thread(() -> {
try {
//JDCB.init("users", "admin0", "wasteinformation", "192.168.65.15", 1883);
JDCB.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306);
} catch (IOException e) {
//e.printStackTrace();
Log.error("no connection to db");
}
}).start();
try {
JDBC.init("ingproject", "Kb9Dxklumt76ieq6", "ingproject", "db.power4future.at", 3306);
//JDBC.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306);
} catch (IOException e) {
//e.printStackTrace();
Log.error("no connection to db");
}
//startup web server
@ -52,12 +48,10 @@ public class main {
//startup mqtt service
Log.message("starting mqtt service");
try {
mqtt m = new mqtt();
m.notifymessage();
MqttService m = new MqttService("mqtt.heili.eu", "1883");
m.startupService();
} catch (Exception e) {
Log.error("An error occured in the class mqtt");
}
Log.info("mem: "+Runtime.getRuntime().totalMemory());
}
}

View File

@ -5,10 +5,10 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class JDCB {
public class JDBC {
static Connection conn;
static JDCB jdcb;
static JDBC JDBC;
static boolean loggedin = false;
static String usernamec;
@ -21,19 +21,19 @@ public class JDCB {
usernamec = username;
passwordc = password;
dbnamec = dbname;
jdcb = new JDCB(username, password, dbname, ip, port);
JDBC = new JDBC(username, password, dbname, ip, port);
}
private JDCB(String username, String password, String dbname, String ip, int port) throws IOException {
private JDBC(String username, String password, String dbname, String ip, int port) throws IOException {
logintodb(username, password, dbname, ip, port);
}
public static JDCB getInstance() throws IOException {
public static JDBC getInstance() throws IOException {
if (loggedin) {
return jdcb;
return JDBC;
} else {
logintodb(usernamec, passwordc, dbnamec, ipc, portc);
return jdcb;
return JDBC;
}
}

View File

@ -19,7 +19,7 @@ public class MySQLConnector extends Database {
}
public Connection getConnection() throws SQLException {
DriverManager.setLoginTimeout(1); // TODO: 30.11.19 set higher maybe
DriverManager.setLoginTimeout(1);
return DriverManager.getConnection(
"jdbc:mysql://" + host + ":" + port + "/" + dbName + "?useSSL=false",
user,

View File

@ -1,37 +0,0 @@
package com.wasteinformationserver.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class PostgreSQLConnector extends Database {
static {
try {
Class.forName("org.postgresql.Driver").newInstance();
} catch (Exception e) {
e.printStackTrace();
}
}
public PostgreSQLConnector(String user, String password, String host, int port, String dbName) {
super(user, password, host, port, dbName);
}
@Override
public Connection getConnection() {
Connection con = null;
try {
con = DriverManager.getConnection(
"jdbc:postgresql://" + host + ":" + port + "/" + dbName,
user,
password);
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
}

View File

@ -0,0 +1,184 @@
package com.wasteinformationserver.mqtt;
import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.JDBC;
import org.eclipse.paho.client.mqttv3.*;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class MqttService {
private MqttClient client = null;
private String serveruri;
JDBC db;
public MqttService(String serverurl, String port) {
serveruri = "tcp://" + serverurl + ":" + port;
try {
db = JDBC.getInstance();
} catch (IOException e) {
Log.error("no connetion to db");
}
}
public void startupService() {
try {
client = new MqttClient(serveruri, "JavaSample42");
MqttConnectOptions connOpts = new MqttConnectOptions();
connOpts.setCleanSession(true);
client.connect(connOpts);
client.setCallback(new MqttCallback() {
@Override
public void connectionLost(Throwable throwable) {
Log.error("connection lost");
// TODO: 12.01.20 reconnect
}
@Override
public void messageArrived(String s, MqttMessage mqttMessage) {
String deviceid = new String(mqttMessage.getPayload());
Log.message("received Request from PCB");
ResultSet res = db.executeQuery("SELECT * from devices WHERE DeviceID=" + deviceid);
try {
res.last();
if (res.getRow() != 0) {
//existing device
res.first();
ResultSet devicecities = db.executeQuery("SELECT * from device_city WHERE DeviceID='" + deviceid + "'");
devicecities.last();
if (devicecities.getRow() == 0) {
//not configured
tramsmitMessage(deviceid + ",-1");
} else {
devicecities.first();
devicecities.previous();
// TODO: 23.01.20 Test this stuff
while (devicecities.next()) {
int cityid = devicecities.getInt("CityID");
checkDatabase(cityid, Integer.parseInt(deviceid));
}
}
} else {
//new device
db.executeUpdate("INSERT INTO devices (DeviceID) VALUES (" + deviceid + ")");
Log.info("new device registered to server");
tramsmitMessage(deviceid + ",-1");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
}
});
client.subscribe("TopicIn");
} catch (MqttException e) {
Log.error("Connection to the Broker failed");
}
}
public void checkDatabase(int citywastezoneid, int deviceid) {
int wastetype = -1;
ResultSet set2 = db.executeQuery("SELECT * FROM cities WHERE `id`='" + citywastezoneid + "'");
try {
set2.last();
if (set2.getRow() != 1) {
//error
} else {
String typ = set2.getString("wastetype");
wastetype = getIntTyp(typ);
}
} catch (SQLException e) {
e.printStackTrace();
}
ResultSet result = db.executeQuery("SELECT pickupdates.pickupdate FROM pickupdates WHERE pickupdates.citywastezoneid=" + citywastezoneid);
try {
result.last();
if (result.getRow() == 0) {
//if not found in db --> send zero
Log.debug("not found in db");
tramsmitMessage(deviceid + "," + wastetype + "," + 0);
} else {
Log.debug(result.getString("pickupdate"));
result.first();
do {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
long timestamp = formatter.parse(result.getString("pickupdate")).getTime();
long timestampnow = formatter.parse(formatter.format(new Date())).getTime();
Log.debug("timestamp is :" + timestamp);
if (timestamp == timestampnow || timestamp == timestampnow + 86400000) { // 86400000 == one day
// valid time
tramsmitMessage(deviceid + "," + wastetype + "," + 1);
Log.debug("valid time");
return;
}
} while (result.next());
tramsmitMessage(deviceid + "," + wastetype + "," + 0); //transmit zero if not returned before
}
} catch (SQLException | ParseException e) {
e.printStackTrace();
}
}
private void tramsmitMessage(String temp) {
Log.debug("sending message >>>" + temp);
MqttMessage message = new MqttMessage(temp.getBytes());
message.setQos(2);
try {
client.publish("TopicOut", message);
} catch (MqttException e) {
e.printStackTrace();
}
}
private String getTyp(int number) {
if (number == 1) {
return "Plastic";
} else if (number == 2) {
return "Metal";
} else if (number == 3) {
return "Residual waste";
} else if (number == 4) {
return "Biowaste";
}
return null;
}
private int getIntTyp(String temp) {
int number = 0;
switch (temp) {
case "Plastic":
number = 1;
break;
case "Metal":
number = 2;
break;
case "Residual waste":
number = 3;
break;
case "Biowaste":
number = 4;
break;
}
return number;
}
}

View File

@ -1,154 +0,0 @@
package com.wasteinformationserver.mqtt;
import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.JDCB;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class mqtt {
MqttClient client = null;
public mqtt() {
}
public void notifymessage() {
try {
client = new MqttClient("tcp://192.168.65.15:1883", "JavaSample42");
MqttConnectOptions connOpts = new MqttConnectOptions();
connOpts.setCleanSession(true);
client.connect(connOpts);
} catch (MqttException e) {
Log.error("Connection to the ESB was failed");
}
mqttreceiver mr = new mqttreceiver(client);
mr.addMessageReceivedListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Log.debug("received message");
String[] split = e.getActionCommand().split(",");
String wastetyp = getTyp(Integer.parseInt(split[2]));
getDatabasedata("SELECT pickupdates.pickupdate FROM pickupdates WHERE pickupdates.citywastezoneid=(SELECT cities.zone FROM cities WHERE cities.name='" + split[1] + "' AND cities.wastetype='" + wastetyp + "' AND cities.zone=" + split[3] + ")", wastetyp, Integer.parseInt(split[0]));
}
});
mr.getmessage();
}
public void getDatabasedata(String message, String wastetyp, int clientidentify) {
Log.debug(message);
Log.debug(wastetyp);
Log.debug(clientidentify);
JDCB Database = null;
try {
Database = JDCB.getInstance();
} catch (IOException e) {
Log.error("No Connection to the databank");
}
int wastenumber = getIntTyp(wastetyp);
ResultSet result = Database.executeQuery(message);
try {
result.last();
if (result.getFetchSize() == 0){
//if not found in db --> send zero
transmitmessageAbfallart(clientidentify + "," + wastenumber + "," + 0);
}
result.first();
while (result.next()) {
String newDate = getDateDatabase(String.valueOf(result.getString("pickupdate")));
String currentDate = getcurrentDate();
String Datetomorrow = nexDayDate();
if (currentDate.equals(newDate) || currentDate.equals(Datetomorrow)) {
transmitmessageAbfallart(clientidentify + "," + wastenumber + "," + 1);
} else {
transmitmessageAbfallart(clientidentify + "," + wastenumber + "," + 0);
}
}
} catch (SQLException e) {
Log.error("No data from database");
}
}
private void transmitmessageAbfallart(String temp) {
Log.debug("sending message >>>"+temp);
mqtttransmitter mt = new mqtttransmitter(client);
Log.debug(temp);
mt.sendmessage(temp);
}
private String nexDayDate() {
final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date currentDate = new Date();
Calendar c = Calendar.getInstance();
c.setTime(currentDate);
c.add(Calendar.DATE, 1);
Date currentDatePlusOne = c.getTime();
String temp = dateFormat.format(currentDatePlusOne);
String split[] = temp.split("/");
return split[2] + "." + split[1] + "." + split[0];
}
private String getTyp(int number) {
if (number == 1) {
return "Plastic";
} else if (number == 2) {
return "Metal";
} else if (number == 3) {
return "Residual waste";
} else if (number == 4) {
return "Biowaste";
}
return null;
}
private int getIntTyp(String temp) {
int number = 0;
if (temp.equals("Plastic")) {
number = 1;
} else if (temp.equals("Metal")) {
number = 2;
} else if (temp.equals("Residual waste")) {
number = 3;
} else if (temp.equals("Biowaste")) {
number = 4;
}
return number;
}
private String getDateDatabase(String temptime) {
String[] parts = temptime.split("-");
String tempyear = parts[0];
String[] yearsplit = tempyear.split("0");
String tempyearnew = yearsplit[1];
return parts[2] + "." + parts[1] + "." + tempyearnew;
}
private String getcurrentDate() {
GregorianCalendar now = new GregorianCalendar();
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG);
String date = df.format(now.getTime());
String[] partstwo = date.split(",");
return partstwo[0];
}
}

View File

@ -1,62 +0,0 @@
package com.wasteinformationserver.mqtt;
import com.wasteinformationserver.basicutils.Log;
import org.eclipse.paho.client.mqttv3.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
public class mqttreceiver {
private MqttClient client;
public ArrayList<ActionListener> mylisteners = new ArrayList<>();
public String message;
public mqttreceiver(MqttClient mqtt) {
this.client = mqtt;
}
public String getmessage() {
try {
client.setCallback(new MqttCallback() {
@Override
public void connectionLost(Throwable throwable) {
Log.error("connection lost");
}
@Override
public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
message = new String(mqttMessage.getPayload());
Log.info("received Request from PCB");
notifylisteners(message);
}
@Override
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
}
});
client.subscribe("TopicIn");
Log.debug("subscribed topic");
} catch (MqttException e) {
Log.error("Connection to the ESB failed");
}
return message;
}
private void notifylisteners(String message) {
for (ActionListener ac : mylisteners) {
ac.actionPerformed(new ActionEvent(this, 0, message));
}
}
public void addMessageReceivedListener(ActionListener l) {
mylisteners.add(l);
}
}

View File

@ -1,40 +0,0 @@
package com.wasteinformationserver.mqtt;
import com.wasteinformationserver.basicutils.Log;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
public class mqtttransmitter {
MqttClient client;
public mqtttransmitter(MqttClient client) {
this.client = client;
}
public void sendmessage(String temp) {
String topic = "TopicOut";
String content = temp;
int qos = 2;
MemoryPersistence persistence = new MemoryPersistence();
try {
Log.debug("Connected");
Log.debug("Publishing message: " + content);
MqttMessage message = new MqttMessage(content.getBytes());
message.setQos(qos);
client.publish(topic, message);
Log.debug("Message published");
} catch (MqttException me) {
Log.debug("reason " + me.getReasonCode());
Log.debug("msg " + me.getMessage());
Log.debug("loc " + me.getLocalizedMessage());
Log.debug("cause " + me.getCause());
Log.debug("excep " + me);
}
}
}

View File

@ -53,12 +53,13 @@ public class MainPage implements HttpHandler {
Log.warning("wrong page sending 404");
sendPage("/404Error.html", t);
} else if (fs == null) {
Log.warning("requested resource doesnt exist");
Log.warning("requested resource doesnt exist --> "+path);
} else {
// Object exists and is a file: accept with response code 200.
String mime = "text/html";
if (path.substring(path.length() - 3).equals(".js")) mime = "application/javascript";
if (path.substring(path.length() - 3).equals("css")) mime = "text/css";
final String s = path.substring(path.length() - 3);
if (s.equals(".js")) mime = "application/javascript";
if (s.equals("css")) mime = "text/css";
Headers h = t.getResponseHeaders();
h.set("Content-Type", mime);

View File

@ -2,10 +2,7 @@ package com.wasteinformationserver.website;
import com.sun.net.httpserver.HttpServer;
import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.website.datarequests.AdminRequests;
import com.wasteinformationserver.website.datarequests.DataRequest;
import com.wasteinformationserver.website.datarequests.NewDateRequest;
import com.wasteinformationserver.website.datarequests.RegisterRequest;
import com.wasteinformationserver.website.datarequests.*;
import com.wasteinformationserver.website.datarequests.login.CheckLoginState;
import com.wasteinformationserver.website.datarequests.login.LoginRequest;
@ -29,6 +26,7 @@ public class Webserver {
server.createContext("/senddata/wastedata", new DataRequest());
server.createContext("/senddata/admindata", new AdminRequests());
server.createContext("/senddata/newdate", new NewDateRequest());
server.createContext("/senddata/Devicedata", new DeviceRequest());
server.setExecutor(null); // creates a default executor
server.start();

View File

@ -2,7 +2,7 @@ package com.wasteinformationserver.website.datarequests;
import com.wasteinformationserver.basicutils.Info;
import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.JDCB;
import com.wasteinformationserver.db.JDBC;
import com.wasteinformationserver.website.basicrequest.PostRequest;
import java.io.IOException;
@ -20,9 +20,9 @@ public class DataRequest extends PostRequest {
ResultSet set = null;
int status = -1;
JDCB jdcb;
JDBC jdbc;
try {
jdcb = JDCB.getInstance();
jdbc = JDBC.getInstance();
} catch (IOException e) {
Log.error("no connection to db");
return "{\"query\" : \"nodbconn\"}";
@ -35,7 +35,7 @@ public class DataRequest extends PostRequest {
// check if wastezone and wasteregion already exists
Log.debug(params.get("cityname") + params.get("wastetype") + params.get("wastezone"));
set = jdcb.executeQuery("select * from `cities` where `name`='" + params.get("cityname") + "' AND `wastetype`='" + params.get("wastetype") + "' AND `zone`='" + params.get("wastezone") + "'");
set = jdbc.executeQuery("select * from `cities` where `name`='" + params.get("cityname") + "' AND `wastetype`='" + params.get("wastetype") + "' AND `zone`='" + params.get("wastezone") + "'");
int size = 0;
try {
if (set != null) {
@ -48,7 +48,7 @@ public class DataRequest extends PostRequest {
if (size == 0) {
//doesnt exist
try {
status = jdcb.executeUpdate("INSERT INTO `cities`(`userid`, `name`, `wastetype`, `zone`) VALUES ('0','" + params.get("cityname") + "','" + params.get("wastetype") + "','" + params.get("wastezone") + "');");
status = jdbc.executeUpdate("INSERT INTO `cities`(`userid`, `name`, `wastetype`, `zone`) VALUES ('0','" + params.get("cityname") + "','" + params.get("wastetype") + "','" + params.get("wastezone") + "');");
} catch (SQLException e) {
e.printStackTrace();
}
@ -71,7 +71,7 @@ public class DataRequest extends PostRequest {
sb.append("}");
break;
case "getAllCities":
set = jdcb.executeQuery("select * from cities");
set = jdbc.executeQuery("select * from cities");
Log.debug(set.toString());
sb.append("{\"data\":[");
try {
@ -95,7 +95,7 @@ public class DataRequest extends PostRequest {
//DELETE FROM `cities` WHERE `id`=0
sb.append("{");
try {
status = jdcb.executeUpdate("DELETE FROM `cities` WHERE `id`='" + params.get("id") + "'");
status = jdbc.executeUpdate("DELETE FROM `cities` WHERE `id`='" + params.get("id") + "'");
if (status == 1) {
//success
sb.append("\"status\" : \"success\"");
@ -117,7 +117,7 @@ public class DataRequest extends PostRequest {
break;
case "getAllDates":
set = jdcb.executeQuery("SELECT pickupdates.id,pickupdates.pickupdate,cities.userid,cities.name,cities.wastetype,cities.zone " +
set = jdbc.executeQuery("SELECT pickupdates.id,pickupdates.pickupdate,cities.userid,cities.name,cities.wastetype,cities.zone " +
"FROM `pickupdates` INNER JOIN `cities` ON pickupdates.citywastezoneid = cities.id");
sb.append("{\"data\":[");
try {
@ -141,7 +141,7 @@ public class DataRequest extends PostRequest {
case "deletedate":
sb.append("{");
try {
status = jdcb.executeUpdate("DELETE FROM `pickupdates` WHERE `id`='" + params.get("id") + "'");
status = jdbc.executeUpdate("DELETE FROM `pickupdates` WHERE `id`='" + params.get("id") + "'");
if (status == 1) {
//success
sb.append("\"status\" : \"success\"");
@ -176,7 +176,7 @@ public class DataRequest extends PostRequest {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
String time = sdf.format(date);
set = jdcb.executeQuery("SELECT * FROM `pickupdates` WHERE `pickupdate` BETWEEN '0000-12-27' AND '"+time+"'");
set = jdbc.executeQuery("SELECT * FROM `pickupdates` WHERE `pickupdate` BETWEEN '0000-12-27' AND '"+time+"'");
set.last();
sb.append("\"finshedcollections\":\"" + set.getRow() + "\"");
@ -185,15 +185,15 @@ public class DataRequest extends PostRequest {
date = new Date(date.getTime()+1 * 24 * 60 * 60 * 1000);
time = sdf.format(date);
set = jdcb.executeQuery("SELECT * FROM `pickupdates` WHERE `pickupdate` BETWEEN '"+time+"' AND '2222-12-27'");
set = jdbc.executeQuery("SELECT * FROM `pickupdates` WHERE `pickupdate` BETWEEN '"+time+"' AND '2222-12-27'");
set.last();
sb.append(",\"futurecollections\":\"" + set.getRow() + "\"");
set = jdcb.executeQuery("select * from pickupdates");
set = jdbc.executeQuery("select * from pickupdates");
set.last();
sb.append(",\"collectionnumber\":\"" + set.getRow() + "\"");
set = jdcb.executeQuery("select * from `cities`");
set = jdbc.executeQuery("select * from `cities`");
set.last();
sb.append(",\"citynumber\":\"" + set.getRow() + "\"");
} catch (SQLException e) {

View File

@ -0,0 +1,181 @@
package com.wasteinformationserver.website.datarequests;
import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.JDBC;
import com.wasteinformationserver.website.basicrequest.PostRequest;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
public class DeviceRequest extends PostRequest {
@Override
public String request(HashMap<String, String> params) {
JDBC jdbc = null;
try {
jdbc = JDBC.getInstance();
} catch (IOException e) {
e.printStackTrace();
}
StringBuilder sb = new StringBuilder();
switch (params.get("action")) {
case "getdevices":
ResultSet deviceset = jdbc.executeQuery("SELECT * FROM `devices");
sb.append("{\"data\":[");
try {
while (deviceset.next()) {
int deviceid = deviceset.getInt("DeviceID");
int cityid = deviceset.getInt("CityID");
if (cityid == -1) {
sb.append("{\"deviceid\":\"").append(deviceid).append("\",\"cityid\":\"").append(cityid).append("\"}");
} else {
String devicename = deviceset.getString("DeviceName");
String devicelocation = deviceset.getString("DeviceLocation");
sb.append("{\"deviceid\":\"").append(deviceid).append("\",\"devicename\":\"").append(devicename).append("\",\"devicelocation\":\"").append(devicelocation).append("\",\"devices\":[");
ResultSet devicecities = jdbc.executeQuery("SELECT * FROM `device_city` INNER JOIN `cities` ON device_city.CityID=cities.id WHERE `DeviceID`='" + deviceid + "'");
while (devicecities.next()) {
int cityidd = devicecities.getInt("id");
String cityname = devicecities.getString("name");
String wastetype = devicecities.getString("wastetype");
String zone = devicecities.getString("zone");
sb.append("{\"cityid\":\"").append(cityidd).append("\",\"cityname\":\"").append(cityname).append("\",\"wastetype\":\"").append(wastetype).append("\",\"zone\":\"").append(zone).append("\"}");
if (!(devicecities.isLast())) {
sb.append(",");
}
}
sb.append("]}");
}
if (!(deviceset.isLast())) {
sb.append(",");
}
}
sb.append("]}");
} catch (SQLException e) {
e.printStackTrace();
}
break;
case "getCitynames":
deviceset = jdbc.executeQuery("select * from cities");
Log.debug(deviceset.toString());
sb.append("{");
try {
String prev = "";
while (deviceset.next()) {
if (!prev.equals(deviceset.getString("name"))) {
if (!deviceset.isFirst()) {
sb.append(",");
}
sb.append("\"").append(deviceset.getString("name")).append("\":\"").append(deviceset.getString("name")).append("\"");
}
prev = deviceset.getString("name");
}
} catch (SQLException e) {
e.printStackTrace();
}
sb.append("}");
Log.debug(sb.toString());
break;
case "getzones":
deviceset = jdbc.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' ORDER BY zone ASC");
Log.debug(deviceset.toString());
sb.append("{");
try {
int prev = 42;
while (deviceset.next()) {
if (prev != deviceset.getInt("zone")) {
sb.append("\"").append(deviceset.getInt("zone")).append("\":\"").append(deviceset.getInt("zone")).append("\"");
if (!deviceset.isLast()) {
sb.append(",");
}
}
prev = deviceset.getInt("zone");
}
} catch (SQLException e) {
e.printStackTrace();
}
sb.append("}");
break;
case "gettypes":
deviceset = jdbc.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='" + params.get("zonename") + "' ORDER BY zone ASC");
Log.debug(deviceset.toString());
sb.append("{");
try {
String prev = "42";
while (deviceset.next()) {
if (!prev.equals(deviceset.getString("wastetype"))) {
sb.append("\"" + deviceset.getString("wastetype") + "\":\"" + deviceset.getString("wastetype") + "\"");
if (!deviceset.isLast()) {
sb.append(",");
}
}
prev = deviceset.getString("wastetype");
}
} catch (SQLException e) {
e.printStackTrace();
}
sb.append("}");
break;
case "savetodb":
try {
ResultSet cityset = jdbc.executeQuery("SELECT id from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='" + params.get("zonename") + "' AND `wastetype`='" + params.get("wastetype") + "'");
cityset.last();
if (cityset.getRow() != 1) {
// TODO: 17.01.20 error handling
} else {
int cityid = cityset.getInt("id");
jdbc.executeUpdate("INSERT INTO `device_city` (`DeviceID`, `CityID`) VALUES ('" + params.get("deviceid") + "', '" + cityid + "');");
jdbc.executeUpdate("UPDATE devices SET `CityID`='0',`DeviceName`='" + params.get("devicename") + "',`DeviceLocation`='" + params.get("devicelocation") + "' WHERE `DeviceID`='" + params.get("deviceid") + "'");
sb.append("{\"success\":\"true\"}");
}
} catch (SQLException e) {
e.printStackTrace();
}
break;
case "deleteDevice":
try {
jdbc.executeUpdate("DELETE FROM devices WHERE `DeviceID`='" + params.get("id") + "'");
jdbc.executeUpdate("DELETE FROM device_city WHERE `DeviceID`='" + params.get("id") + "'");
} catch (SQLException e) {
e.printStackTrace();
}
sb.append("{\"status\":\"success\"}");
break;
case "getDeviceNumber":
try {
ResultSet numberset = jdbc.executeQuery("SELECT * FROM devices");
numberset.last();
int devicenr = numberset.getRow();
sb.append("{\"devicenr\":\"" + devicenr + "\"}");
} catch (SQLException e) {
e.printStackTrace();
}
break;
case "addtodb":
int cityid = -1;
try {
ResultSet device = jdbc.executeQuery("SELECT * FROM cities WHERE name='" + params.get("cityname") + "' AND wastetype='" + params.get("wastetype") + "' AND zone='" + params.get("zonename") + "'");
device.first();
cityid = device.getInt("id");
jdbc.executeUpdate("INSERT INTO `device_city` (`DeviceID`, `CityID`) VALUES ('" + params.get("deviceid") + "', '" + cityid + "');");
} catch (SQLException e) {
e.printStackTrace();
}
sb.append("{\"success\":true}");
break;
}
return sb.toString();
}
}

View File

@ -1,7 +1,7 @@
package com.wasteinformationserver.website.datarequests;
import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.JDCB;
import com.wasteinformationserver.db.JDBC;
import com.wasteinformationserver.website.basicrequest.PostRequest;
import java.io.IOException;
@ -13,17 +13,17 @@ public class NewDateRequest extends PostRequest {
@Override
public String request(HashMap<String, String> params) {
StringBuilder sb = new StringBuilder();
JDCB jdcb;
JDBC jdbc;
ResultSet set;
try {
jdcb = JDCB.getInstance();
jdbc = JDBC.getInstance();
} catch (IOException e) {
Log.error("no connection to db");
return "{\"query\" : \"nodbconn\"}";
}
switch (params.get("action")) {
case "getCitynames":
set = jdcb.executeQuery("select * from cities");
set = jdbc.executeQuery("select * from cities");
Log.debug(set.toString());
sb.append("{\"data\":[");
try {
@ -48,7 +48,7 @@ public class NewDateRequest extends PostRequest {
Log.debug(sb.toString());
break;
case "getzones":
set = jdcb.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' ORDER BY zone ASC");
set = jdbc.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' ORDER BY zone ASC");
Log.debug(set.toString());
sb.append("{\"data\":[");
try {
@ -72,7 +72,7 @@ public class NewDateRequest extends PostRequest {
sb.append("}");
break;
case "gettypes":
set = jdcb.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='"+params.get("zonename")+"' ORDER BY zone ASC");
set = jdbc.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='"+params.get("zonename")+"' ORDER BY zone ASC");
Log.debug(set.toString());
sb.append("{\"data\":[");
try {
@ -98,13 +98,13 @@ public class NewDateRequest extends PostRequest {
case "newdate":
sb.append("{");
Log.debug(params);
set = jdcb.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='" + params.get("zone") + "' AND `wastetype`='" + params.get("wastetype") + "'");
set = jdbc.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='" + params.get("zone") + "' AND `wastetype`='" + params.get("wastetype") + "'");
try {
set.last();
if (set.getRow() == 1) {
Log.debug(set.getInt("id"));
int status = jdcb.executeUpdate("INSERT INTO `pickupdates`(`citywastezoneid`, `pickupdate`) VALUES ('" + set.getInt("id") + "','" + params.get("date") + "')");
int status = jdbc.executeUpdate("INSERT INTO `pickupdates`(`citywastezoneid`, `pickupdate`) VALUES ('" + set.getInt("id") + "','" + params.get("date") + "')");
if (status == 1) {
sb.append("\"status\" : \"success\"");
} else {

View File

@ -1,7 +1,7 @@
package com.wasteinformationserver.website.datarequests;
import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.JDCB;
import com.wasteinformationserver.db.JDBC;
import com.wasteinformationserver.website.HttpTools;
import com.wasteinformationserver.website.basicrequest.PostRequest;
@ -16,15 +16,15 @@ public class RegisterRequest extends PostRequest {
String passhash = HttpTools.StringToMD5(params.get("password"));
JDCB myjd = null;
JDBC myjd = null;
try {
myjd = JDCB.getInstance();
myjd = JDBC.getInstance();
} catch (IOException e) {
e.printStackTrace();
}
//new JDCB("users", "kOpaIJUjkgb9ur6S", "wasteinformation");
try {
int s = myjd.executeUpdate("INSERT INTO `user` (`username`, `firstName`, `secondName`, `password`, `email`, `logindate`) VALUES ('" + params.get("username") + "', '" + params.get("firstname") + "', '" + params.get("lastname") + "', '" + passhash + "', '" + params.get("email") + "', current_timestamp());");
myjd.executeUpdate("INSERT INTO `user` (`username`, `firstName`, `secondName`, `password`, `email`, `logindate`) VALUES ('" + params.get("username") + "', '" + params.get("firstname") + "', '" + params.get("lastname") + "', '" + passhash + "', '" + params.get("email") + "', current_timestamp());");
} catch (SQLException e) {
e.printStackTrace();
}

View File

@ -1,7 +1,7 @@
package com.wasteinformationserver.website.datarequests.login;
import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.JDCB;
import com.wasteinformationserver.db.JDBC;
import com.wasteinformationserver.website.HttpTools;
import com.wasteinformationserver.website.basicrequest.PostRequest;
@ -19,16 +19,16 @@ public class LoginRequest extends PostRequest {
String password = params.get("password");
String username = params.get("username");
JDCB jdcb;
JDBC jdbc;
try {
jdcb = JDCB.getInstance();
jdbc = JDBC.getInstance();
} catch (IOException e) {
Log.error("no connection to db");
return "{\"status\" : \"nodbconn\"}";
}
ResultSet s = jdcb.executeQuery("select * from user where username ='" + username + "'");
;
ResultSet s = jdbc.executeQuery("select * from user where username ='" + username + "'");
//new JDCB("users", "kOpaIJUjkgb9ur6S", "wasteinformation").executeQuery("select * from user where username ='" + username + "'");
Log.debug("successfully logged in to db");
String response = "{\"accept\": false}";

View File

@ -23,7 +23,7 @@
<aside class="main-sidebar sidebar-dark-primary elevation-4">
<!-- Brand Logo -->
<a href="dashboard.html" class="brand-link">
<img src="lib/AdminLTE/dist/img/AdminLTELogo.png"
<img src="/favicon.png"
alt="AdminLTE Logo"
class="brand-image img-circle elevation-3"
style="opacity: .8">

View File

@ -45,7 +45,7 @@
<aside class="main-sidebar sidebar-dark-primary elevation-4">
<!-- Brand Logo -->
<a href="dashboard.html" class="brand-link">
<img src="lib/AdminLTE/dist/img/AdminLTELogo.png" alt="AdminLTE Logo"
<img src="/favicon.png" alt="AdminLTE Logo"
class="brand-image img-circle elevation-3"
style="opacity: .8">
<span class="brand-text font-weight-light">Waste Control</span>
@ -271,5 +271,7 @@
<script src="lib/AdminLTE/plugins/sweetalert2/sweetalert2.all.js"></script>
<script src="js/userManager.js"></script>
</body>
</html>

View File

@ -47,7 +47,7 @@
<aside class="main-sidebar sidebar-dark-primary elevation-4">
<!-- Brand Logo -->
<a href="dashboard.html" class="brand-link">
<img src="lib/AdminLTE/dist/img/AdminLTELogo.png" alt="AdminLTE Logo"
<img src="/favicon.png" alt="AdminLTE Logo"
class="brand-image img-circle elevation-3"
style="opacity: .8">
<span class="brand-text font-weight-light">Waste Control</span>
@ -210,7 +210,7 @@
<div class="card-header">
<h3 class="card-title">
<i class="fas fa-chart-pie mr-1"></i>
Alle abholdaten
All pickupdats
</h3>
</div><!-- /.card-header -->
<div class="card-body">
@ -440,12 +440,16 @@
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
<script type="text/javascript" src="js/dashboard.js"></script>
<!-- DataTables -->
<script src="lib/AdminLTE/plugins/datatables/jquery.dataTables.js"></script>
<script src="lib/AdminLTE/plugins/datatables-bs4/js/dataTables.bootstrap4.js"></script>
<script src="lib/AdminLTE/plugins/sweetalert2/sweetalert2.all.js"></script>
<!-- OWN -->
<script type="text/javascript" src="js/dashboard.js"></script>
<script src="js/userManager.js"></script>
</body>
</html>

View File

@ -45,7 +45,7 @@
<aside class="main-sidebar sidebar-dark-primary elevation-4">
<!-- Brand Logo -->
<a href="dashboard.html" class="brand-link">
<img src="lib/AdminLTE/dist/img/AdminLTELogo.png" alt="AdminLTE Logo"
<img src="/favicon.png" alt="AdminLTE Logo"
class="brand-image img-circle elevation-3"
style="opacity: .8">
<span class="brand-text font-weight-light">Waste Control</span>
@ -65,64 +65,50 @@
</div>
</div>
<!-- Sidebar -->
<div class="sidebar">
<!-- Sidebar user panel (optional) -->
<div class="user-panel mt-3 pb-3 mb-3 d-flex">
<div class="image">
<!-- <img src="lib/AdminLTE/dist/img/user2-160x160.jpg" class="img-circle elevation-2" alt="User Image"> -->
<i class="nav-icon fas fa-user img-circle elevation-2" style="color:white"></i>
</div>
<!-- <i class="nav-icon fas fa-tachometer-alt"></i> -->
<div class="info">
<a href="user.html" class="d-block" id="userlabel">Username to set!</a>
</div>
</div>
<!-- Sidebar Menu -->
<nav class="mt-2">
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu"
data-accordion="false">
<!-- Sidebar Menu -->
<nav class="mt-2">
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu"
data-accordion="false">
<li class="nav-item">
<a href="#todo" class="nav-link">
<i class="nav-icon fas fa-cog"></i>
<p>
Settings
</p>
</a>
</li>
<li class="nav-item">
<a href="#todo" class="nav-link">
<i class="nav-icon fas fa-cog"></i>
<p>
Settings
</p>
</a>
</li>
<li class="nav-item">
<a href="index.html" class="nav-link" id="logoutbtn">
<i class="nav-icon fas fa-sign-out-alt"></i>
<p>
Logout
</p>
</a>
</li>
<li class="nav-item">
<a href="index.html" class="nav-link" id="logoutbtn">
<i class="nav-icon fas fa-sign-out-alt"></i>
<p>
Logout
</p>
</a>
</li>
<li id="adminpanel" class="nav-item hideit">
<a href="adminpanel.html" class="nav-link">
<i class="nav-icon fas fa-plus-circle"></i>
<p>
Admin panel
</p>
</a>
</li>
<li id="adminpanel" class="nav-item hideit">
<a href="adminpanel.html" class="nav-link">
<i class="nav-icon fas fa-plus-circle"></i>
<p>
Admin panel
</p>
</a>
</li>
<li id="devicepanel" class="nav-item">
<a href="device.html" class="nav-link">
<i class="nav-icon fas fa-plus-circle"></i>
<p>
Devices
</p>
</a>
</li>
</ul>
</nav>
<!-- /.sidebar-menu -->
</div>
<li id="devicepanel" class="nav-item">
<a href="device.html" class="nav-link">
<i class="nav-icon fas fa-plus-circle"></i>
<p>
Devices
</p>
</a>
</li>
</ul>
</nav>
<!-- /.sidebar-menu -->
</div>
<!-- /.sidebar -->
</aside>
@ -155,7 +141,7 @@
<!-- small box -->
<div class="small-box bg-info">
<div class="inner">
<h3>150</h3>
<h3>TODO</h3>
<p>Todo</p>
</div>
@ -170,7 +156,7 @@
<!-- small box -->
<div class="small-box bg-success">
<div class="inner">
<h3>42</h3>
<h3>TODO</h3>
<p>Devices</p>
</div>
@ -193,42 +179,32 @@
<div class="card-header">
<h3 class="card-title">
<i class="fas fa-chart-pie mr-1"></i>
User Data
All Devices
</h3>
<button id="btn-newdevice" type="button" class="btn btn-success"
style="float:right;">Save
</button>
</div><!-- /.card-header -->
<div class="card-body">
<div class="form-group" style="margin-top: 15px; width: 10cm;">
<!-- todo todo -->
<label for="new_city_cityname">City/Village name</label>
<input type="email" class="form-control" id="new_city_cityname"
aria-describedby="emailHelp" placeholder="Enter city name here">
<small class="form-text text-muted">Please try to use no special
characters</small>
</div>
<div class="form-group" style="width: 10cm;">
<label for="new_city_zonename">Zone Name</label>
<input type="email" class="form-control" id="new_city_zonename"
aria-describedby="emailHelp" placeholder="Enter Zone name here">
<small class="form-text text-muted">Please try to use no special
characters</small>
</div>
<div class="input-group-prepend">
<button id="dropdown-wastetype" type="button"
class="btn btn-outline-dark dropdown-toggle"
data-toggle="dropdown">
Select waste type
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Plastic</a>
<a class="dropdown-item" href="#">Metal</a>
<a class="dropdown-item" href="#">Residual waste</a>
<a class="dropdown-item" href="#">Biowaste</a>
</div>
</div>
<table id="table-devices" class="table table-bordered table-hover">
<thead>
<tr>
<th>Device ID</th>
<th>Devicename</th>
<th>Devicelocation</th>
<th>WasteType</th>
<th>Action</th>
</tr>
</thead>
<tbody id="devices-tablebody">
</tbody>
<tfoot>
<tr>
<th>Device ID</th>
<th>Devicename</th>
<th>Devicelocation</th>
<th>WasteType</th>
<th>Action</th>
</tr>
</tfoot>
</table>
</div><!-- /.card-body -->
</div>
@ -312,6 +288,7 @@
<script src="lib/AdminLTE/plugins/sweetalert2/sweetalert2.all.js"></script>
<script src="js/userManager.js"></script>
<script src="js/device.js"></script>
</body>
</html>

View File

@ -1,74 +1,77 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<head>
<meta charset="utf-8">
<title>Login Page</title>
<!--Made with love by Mutiullah Samim -->
<title>Login Page</title>
<!--Made with love by Mutiullah Samim -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="lib/bootstrap.min.css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="lib/bootstrap.min.css">
<!-- jQuery library -->
<script src="lib/jquery.min.js"></script>
<!-- jQuery library -->
<script src="lib/jquery.min.js"></script>
<!-- Popper JS -->
<script src="lib/popper.min.js"></script>
<!-- Popper JS -->
<script src="lib/popper.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="lib/bootstrap.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="lib/bootstrap.min.js"></script>
<!--Fontawesome CDN-->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<!--Fontawesome CDN-->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css"
integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<!--Custom styles-->
<link rel="stylesheet" type="text/css" href="css/index.css">
<!--Custom styles-->
<link rel="stylesheet" type="text/css" href="css/index.css">
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script src="lib/AdminLTE/plugins/sweetalert2/sweetalert2.all.js"></script>
<script src="lib/AdminLTE/plugins/sweetalert2/sweetalert2.all.js"></script>
<link rel="manifest" href="/manifest.json">
<link rel="manifest" href="/manifest.json">
<link rel="icon" type="image/png" href="/favicon.png">
</head>
<body>
<div class="container">
<div class="d-flex justify-content-center h-100">
<div class="card">
<div class="card-header">
<h3>Sign In</h3>
</div>
<div class="card-body">
<form>
<div class="input-group form-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-user"></i></span>
</div>
<input type="text" class="form-control" placeholder="username" id="userfield">
<div class="d-flex justify-content-center h-100">
<div class="card">
<div class="card-header">
<h3>Sign In</h3>
</div>
<div class="card-body">
<form>
<div class="input-group form-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-user"></i></span>
</div>
<input type="text" class="form-control" placeholder="username" id="userfield">
</div>
<div class="input-group form-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-key"></i></span>
</div>
<input type="password" class="form-control" placeholder="password" id="passfield">
</div>
<div class="row align-items-center remember">
<input type="checkbox">Remember Me
</div>
<div class="form-group">
<input type="submit" value="Login" class="btn float-right login_btn" id="loginbtn">
</div>
</form>
</div>
<div class="card-footer">
<div class="d-flex justify-content-center links">
Don't have an account?<a href="register.html">Sign Up</a>
</div>
<div class="d-flex justify-content-center">
<a href="#">Forgot your password?</a>
</div>
</div>
</div>
</div>
</div>
<div class="input-group form-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-key"></i></span>
</div>
<input type="password" class="form-control" placeholder="password" id="passfield">
</div>
<div class="row align-items-center remember">
<input type="checkbox">Remember Me
</div>
<div class="form-group">
<input type="submit" value="Login" class="btn float-right login_btn" id="loginbtn">
</div>
</form>
</div>
<div class="card-footer">
<div class="d-flex justify-content-center links">
Don't have an account?<a href="register.html">Sign Up</a>
</div>
<div class="d-flex justify-content-center">
<a href="#">Forgot your password?</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

View File

@ -1,17 +1,4 @@
$(document).ready(function () {
console.log("page loaded");
$.post('/senddata/checkloginstate', 'action=getloginstate', function (data) {
console.log(data);
if (data.loggedin == true) {
$("#userlabel").html(" " + data.username);
if (data.permission > 0) {
$("#adminpanel").show();
}
} else {
$("#userlabel").html(" not logged in!!");
}
}, 'json');
//load total collections
$.post('/senddata/wastedata', 'action=getStartHeaderData', function (data) {
console.log(data);
@ -27,7 +14,7 @@ $(document).ready(function () {
//load version footer
//
$.post('/senddata/wastedata', 'action=getversionandbuildtime', function (data) {
$("#version-footer-label").html("<b>Version</b> "+data.version+" <b>Build</b> "+data.buildtime);
$("#version-footer-label").html("<b>Version</b> " + data.version + " <b>Build</b> " + data.buildtime);
}, 'json');
@ -112,7 +99,7 @@ $(document).ready(function () {
if (data.query == "ok") {
$('#picupdates-tablebody').html("");
$(".delbtndate").off();
$(".delbtndate").off();
for (var i = 0; i < data.data.length; i++) {
$('#picupdates-tablebody').append("<tr>" +
@ -156,11 +143,11 @@ $(document).ready(function () {
});
}
datetable = $("#table-pickupdates").DataTable({
"order": [[ 3, "asc" ]]
} );
"order": [[3, "asc"]]
});
//todo picupdates-tablebody
},"json");
}, "json");
}
reloadtable();
@ -274,7 +261,7 @@ $(document).ready(function () {
dropdata.html("");
console.log("clickeeeed");
$.post('/senddata/newdate', 'action=gettypes&cityname=' + $("#dropdown-city").html()+'&zonename='+$("#dropdown-zone").html(), function (data) {
$.post('/senddata/newdate', 'action=gettypes&cityname=' + $("#dropdown-city").html() + '&zonename=' + $("#dropdown-zone").html(), function (data) {
console.log(data);
if (data.query == "ok") {
for (var i = 0; i < data.data.length; i++) {
@ -291,7 +278,6 @@ $(document).ready(function () {
});
});

View File

@ -1,37 +1,274 @@
$(document).ready(function () {
$('#btn-newdevice').click(function (e) {
e.preventDefault();
Swal.showLoading({
title: 'No connection to Database',
html: 'Setup DB here --> <a href="index.html">click<a/>.',
var devicetable = null;
reloadDevices();
function reloadDevices() {
$.post('/senddata/Devicedata', 'action=getdevices', function (data) {
if (devicetable != null) {
devicetable.destroy();
}
console.log(data);
$('#devices-tablebody').html("");
$(".delbtn").off();
for (var i = 0; i < data.data.length; i++) {
var id = data.data[i].deviceid;
var cityid = data.data[i].cityid;
if (cityid == -1) {
$("#devices-tablebody").append("<tr><td>" + id + "</td><td>new Device</td><td><button deviceid=\"" + id + "\"type=\"button\" class=\"btn btn-primary configuredevicebutton\">Configure</button></td><td></td><td><button dataid='" + id + "' type='button' class='delbtn btn btn-danger'>X</button></td></tr>");
} else {
var devicename = data.data[i].devicename;
var devicelocation = data.data[i].devicelocation;
var row = "<tr><td>" + id + "</td><td>" + devicename + "</td><td>" + devicelocation + "</td><td>";
for (var n = 0; n < data.data[i].devices.length; n++) {
var cityname = data.data[i].devices[n].cityname;
var cityzone = data.data[i].devices[n].zone;
var wastetype = data.data[i].devices[n].wastetype;
row += cityname + "/" + wastetype + "/" + cityzone + " </br>";
}
row += "</td><td><button dataid='" + id + "' type='button' class='delbtn btn btn-danger'>X</button><button dataid='" + id + "' type='button' class='addbtn btn btn-success'>ADD</button></td></tr>";
$("#devices-tablebody").append(row);
}
}
addDeleteButton();
addAddButton();
addConfigDialog();
devicetable = $('#table-devices').DataTable();
}, 'json');
}
function addAddButton() {
$('.addbtn').click(function (event) {
var id = event.target.getAttribute("dataid");
var cityname;
var zone;
var wastetype;
var devicename;
var devicelocation;
$.post('/senddata/Devicedata', 'action=getCitynames', function (data) {
Swal.mixin({
input: 'text',
confirmButtonText: 'Next &rarr;',
showCancelButton: true,
progressSteps: ['1']
}).queue([{
title: 'City',
text: 'Select your City',
input: 'select',
inputOptions: data
}
]).then((result) => {
if (result.value) {
console.log(result.value);
const answers = JSON.stringify(result.value);
cityname = result.value[0];
console.log("cityname=" + cityname);
$.post('/senddata/Devicedata', 'action=getzones&cityname=' + cityname, function (data) {
Swal.mixin({
input: 'text',
confirmButtonText: 'Next &rarr;',
showCancelButton: true,
progressSteps: ['1']
}).queue([
{
title: 'City',
text: 'Select your City',
input: 'select',
inputOptions: data
}
]).then((result) => {
if (result.value) {
console.log(result.value);
zone = result.value[0];
$.post('/senddata/Devicedata', 'action=gettypes&cityname=' + cityname + '&zonename=' + zone, function (data) {
Swal.mixin({
input: 'text',
confirmButtonText: 'Next &rarr;',
showCancelButton: true,
progressSteps: ['1']
}).queue([
{
title: 'City',
text: 'Select your City',
input: 'select',
inputOptions: data
}
]).then((result) => {
if (result.value) {
console.log(result.value);
wastetype = result.value[0];
//todo add to db
$.post('/senddata/Devicedata', 'action=addtodb&deviceid=' + id + '&cityname=' + cityname + '&zonename=' + zone + '&wastetype=' + wastetype, function (data) {
if (data.success) {
Swal.fire({
type: "success",
title: 'Successfully configured!',
html: 'This alert closes added.',
timer: 1000,
}).then((result) => {
console.log('Popup closed. ');
reloadDevices();
});
}
});
}
});
});
}
});
});
}
});
});
});
}
function addDeleteButton() {
$(".delbtn").click(function (event) {
var id = event.target.getAttribute("dataid");
console.log("clicked btn data " + id);
$.post('/senddata/Devicedata', 'action=deleteDevice&id=' + id, function (data) {
console.log(data);
if (data.status == "success") {
Swal.fire({
type: "success",
title: 'Successfully deleted city!',
html: 'This alert closes automatically.',
timer: 1000,
}).then((result) => {
console.log('Popup closed. ')
});
reloadDevices();
} else if (data.status == "dependenciesnotdeleted") {
Swal.fire({
type: "warning",
title: 'This city is a dependency of a date',
html: 'Do you want do delete it anyway with all dependencies?',
}).then((result) => {
console.log('Popup closed. ')
});
//todo set yes no button here
}
}, "json");
});
}
function addConfigDialog() {
$(".configuredevicebutton").click(function (event) {
var id = event.target.getAttribute("deviceid");
var cityname;
var zone;
var wastetype;
var devicename;
var devicelocation;
$.post('/senddata/Devicedata', 'action=getCitynames', function (data) {
Swal.mixin({
input: 'text',
confirmButtonText: 'Next &rarr;',
showCancelButton: true,
progressSteps: ['1', '2', '3']
}).queue([
{
title: 'Name of device',
text: 'Please define a device name'
}, {
title: 'Location of device',
text: 'Please define a device location'
}, {
title: 'City',
text: 'Select your City',
input: 'select',
inputOptions: data
}
]).then((result) => {
if (result.value) {
console.log(result.value);
const answers = JSON.stringify(result.value);
cityname = result.value[2];
devicename = result.value[0];
devicelocation = result.value[1];
console.log("cityname=" + cityname);
$.post('/senddata/Devicedata', 'action=getzones&cityname=' + cityname, function (data) {
Swal.mixin({
input: 'text',
confirmButtonText: 'Next &rarr;',
showCancelButton: true,
progressSteps: ['1']
}).queue([
{
title: 'City',
text: 'Select your City',
input: 'select',
inputOptions: data
}
]).then((result) => {
if (result.value) {
console.log(result.value);
zone = result.value[0];
$.post('/senddata/Devicedata', 'action=gettypes&cityname=' + cityname + '&zonename=' + zone, function (data) {
Swal.mixin({
input: 'text',
confirmButtonText: 'Next &rarr;',
showCancelButton: true,
progressSteps: ['1']
}).queue([
{
title: 'City',
text: 'Select your City',
input: 'select',
inputOptions: data
}
]).then((result) => {
if (result.value) {
console.log(result.value);
wastetype = result.value[0];
$.post('/senddata/Devicedata', 'action=savetodb&deviceid=' + id + '&cityname=' + cityname + '&zonename=' + zone + '&wastetype=' + wastetype + '&devicename=' + devicename + '&devicelocation=' + devicelocation, function (data) {
if (data.success) {
Swal.fire({
type: "success",
title: 'Successfully configured!',
html: 'This alert closes automatically.',
timer: 1000,
}).then((result) => {
console.log('Popup closed. ');
reloadDevices();
});
}
});
}
});
});
}
});
});
}
});
});
// Swal.fire({
// type: "error",
// title: 'No connection to Database',
// html: 'Setup DB here --> <a href="index.html">click<a/>.',
// onBeforeOpen: () => {
// Swal.showLoading()
// },
// }).then((result) => {
// console.log('Popup closed. ')
//
// });
console.log("click..." + id);
});
}
// $.post('/senddata/loginget', 'username=' + username + '&password=' + password, function (data) {
//
// console.log(data);
// if (data.status == "nodbconn"){
//
// }
// if (data.accept == true) {
// console.log("successfully logged in!");
// document.cookie = "username=" + username;
// window.location = 'dashboard.html';
// }
// }, 'json');
});
});

View File

@ -0,0 +1,14 @@
$(document).ready(function () {
console.log("page loaded");
$.post('/senddata/checkloginstate', 'action=getloginstate', function (data) {
console.log(data);
if (data.loggedin == true) {
$("#userlabel").html(" " + data.username);
if (data.permission > 0) {
$("#adminpanel").show();
}
} else {
$("#userlabel").html(" not logged in!!");
}
}, 'json');
});

View File

@ -45,7 +45,7 @@
<aside class="main-sidebar sidebar-dark-primary elevation-4">
<!-- Brand Logo -->
<a href="dashboard.html" class="brand-link">
<img src="lib/AdminLTE/dist/img/AdminLTELogo.png" alt="AdminLTE Logo"
<img src="/favicon.png" alt="AdminLTE Logo"
class="brand-image img-circle elevation-3"
style="opacity: .8">
<span class="brand-text font-weight-light">Waste Control</span>
@ -289,5 +289,7 @@
<script src="lib/AdminLTE/plugins/sweetalert2/sweetalert2.all.js"></script>
<script src="js/userManager.js"></script>
</body>
</html>