1er commit

This commit is contained in:
ines 2025-01-09 21:29:22 +01:00
commit 7ae77d8766
43 changed files with 3654 additions and 0 deletions

71
build.xml Normal file
View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="appli3" default="default" basedir=".">
<description>Builds, tests, and runs the project appli3.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-dist: called before archive building
-post-dist: called after archive building
-post-clean: called after cleaning build products
-pre-run-deploy: called before deploying
-post-run-deploy: called after deploying
Example of pluging an obfuscator after the compilation could look like
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Other way how to customize the build is by overriding existing main targets.
The target of interest are:
init-macrodef-javac: defines macro for javac compilation
init-macrodef-junit: defines macro for junit execution
init-macrodef-debug: defines macro for class debugging
do-dist: archive building
run: execution of project
javadoc-build: javadoc generation
Example of overriding the target for project execution could look like
<target name="run" depends="<PROJNAME>-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that overridden target depends on jar target and not only on
compile target as regular run target does. Again, for list of available
properties which you can use check the target you are overriding in
nbproject/build-impl.xml file.
-->
</project>

69
nbproject/ant-deploy.xml Normal file
View File

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project default="-deploy-ant" basedir=".">
<target name="-init" if="deploy.ant.enabled">
<property file="${deploy.ant.properties.file}"/>
<tempfile property="temp.module.folder" prefix="tomcat" destdir="${java.io.tmpdir}"/>
<unwar src="${deploy.ant.archive}" dest="${temp.module.folder}">
<patternset includes="META-INF/context.xml"/>
</unwar>
<xmlproperty file="${temp.module.folder}/META-INF/context.xml"/>
<delete dir="${temp.module.folder}"/>
</target>
<target name="-check-credentials" if="deploy.ant.enabled" depends="-init">
<fail message="Tomcat password has to be passed as tomcat.password property.">
<condition>
<not>
<isset property="tomcat.password"/>
</not>
</condition>
</fail>
</target>
<target name="-deploy-ant" if="deploy.ant.enabled" depends="-init,-check-credentials">
<echo message="Deploying ${deploy.ant.archive} to ${Context(path)}"/>
<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask">
<classpath>
<pathelement path="${tomcat.home}/lib/catalina-ant.jar"/>
<pathelement path="${tomcat.home}/lib/tomcat-coyote.jar"/>
<pathelement path="${tomcat.home}/lib/tomcat-util.jar"/>
<pathelement path="${tomcat.home}/bin/tomcat-juli.jar"/>
</classpath>
</taskdef>
<deploy url="${tomcat.url}/manager/text" username="${tomcat.username}"
password="${tomcat.password}" path="${Context(path)}"
war="${deploy.ant.archive}"/>
<property name="deploy.ant.client.url" value="${tomcat.url}${Context(path)}"/>
</target>
<target name="-undeploy-ant" if="deploy.ant.enabled" depends="-init,-check-credentials">
<echo message="Undeploying ${Context(path)}"/>
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask">
<classpath>
<pathelement path="${tomcat.home}/lib/catalina-ant.jar"/>
<pathelement path="${tomcat.home}/lib/tomcat-coyote.jar"/>
<pathelement path="${tomcat.home}/lib/tomcat-util.jar"/>
<pathelement path="${tomcat.home}/bin/tomcat-juli.jar"/>
</classpath>
</taskdef>
<undeploy url="${tomcat.url}/manager/text" username="${tomcat.username}"
password="${tomcat.password}" path="${Context(path)}"/>
</target>
</project>

1434
nbproject/build-impl.xml Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
build.xml.data.CRC32=9e76b6dd
build.xml.script.CRC32=5c202745
build.xml.stylesheet.CRC32=1707db4f@1.100.0.1
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=9e76b6dd
nbproject/build-impl.xml.script.CRC32=0271ca75
nbproject/build-impl.xml.stylesheet.CRC32=334708a0@1.100.0.1

View File

@ -0,0 +1,88 @@
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=true
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
build.classes.dir=${build.web.dir}/WEB-INF/classes
build.classes.excludes=**/*.java,**/*.form
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
build.web.dir=${build.dir}/web
build.web.excludes=${build.classes.excludes}
client.urlPart=
compile.jsps=false
conf.dir=${source.root}/conf
debug.classpath=${build.classes.dir}:${javac.classpath}
debug.test.classpath=\
${run.test.classpath}
display.browser=true
# Files to be excluded from distribution war
dist.archive.excludes=
dist.dir=dist
dist.ear.war=${dist.dir}/${war.ear.name}
dist.javadoc.dir=${dist.dir}/javadoc
dist.war=${dist.dir}/${war.name}
excludes=
file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar=C:\\Users\\noobm\\Downloads\\drive-download-20250105T160443Z-001\\jakarta.servlet.jsp.jstl-2.0.0.jar
file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar=C:\\Users\\noobm\\Downloads\\drive-download-20250105T160443Z-001\\jakarta.servlet.jsp.jstl-api-2.0.0.jar
file.reference.mysql-connector-java-8.0.23.jar=C:\\Users\\noobm\\Downloads\\drive-download-20250105T160443Z-001\\mysql-connector-java-8.0.23.jar
includes=**
j2ee.compile.on.save=true
j2ee.copy.static.files.on.save=true
j2ee.deploy.on.save=true
j2ee.platform=10-web
j2ee.platform.classpath=${j2ee.server.home}/bin/tomcat-juli.jar:${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-ssi.jar:${j2ee.server.home}/lib/catalina-storeconfig.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.27.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jakartaee-migration-1.0.8-shaded.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jaspic-api.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote-ffm.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-cs.jar:${j2ee.server.home}/lib/tomcat-i18n-de.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-i18n-ko.jar:${j2ee.server.home}/lib/tomcat-i18n-pt-BR.jar:${j2ee.server.home}/lib/tomcat-i18n-ru.jar:${j2ee.server.home}/lib/tomcat-i18n-zh-CN.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-jni.jar:${j2ee.server.home}/lib/tomcat-util-scan.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-websocket.jar:${j2ee.server.home}/lib/websocket-api.jar:${j2ee.server.home}/lib/websocket-client-api.jar
j2ee.server.type=Tomcat
jar.compress=false
javac.classpath=\
${file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar}:\
${file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar}:\
${file.reference.mysql-connector-java-8.0.23.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.debug=true
javac.deprecation=false
javac.processorpath=\
${javac.classpath}
javac.source=17
javac.target=17
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.preview=true
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
lib.dir=${web.docbase.dir}/WEB-INF/lib
no.dependencies=false
persistence.xml.dir=${conf.dir}
platform.active=default_platform
resource.dir=setup
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
# Space-separated list of JVM arguments used when running a class with a main method or a unit test
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value):
runmain.jvmargs=
source.encoding=UTF-8
source.root=src
src.dir=${source.root}/java
test.src.dir=test
war.content.additional=
war.ear.name=${war.name}
war.name=appli3.war
web.docbase.dir=web
webinf.dir=web/WEB-INF

31
nbproject/project.xml Normal file
View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.web.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/web-project/3">
<name>appli3</name>
<minimum-ant-version>1.6.5</minimum-ant-version>
<web-module-libraries>
<library dirs="200">
<file>${file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library dirs="200">
<file>${file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library dirs="200">
<file>${file.reference.mysql-connector-java-8.0.23.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
</web-module-libraries>
<web-module-additional-libraries/>
<source-roots>
<root id="src.dir" name="Source Packages"/>
</source-roots>
<test-roots>
<root id="test.src.dir" name="Test Packages"/>
</test-roots>
</data>
</configuration>
</project>

2
src/conf/MANIFEST.MF Normal file
View File

@ -0,0 +1,2 @@
Manifest-Version: 1.0

View File

@ -0,0 +1,116 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Servlet.java to edit this template
*/
package Servlet;
import beans.Pompier;
import form.AuthentifForm;
import java.io.IOException;
import java.io.PrintWriter;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
/**
*
* @author noobm
*/
public class AuthentificationServlet extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet authentificationServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet authentificationServlet at " + request.getContextPath() + "</h1>");
out.println("</body>");
out.println("</html>");
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession Session = request.getSession();
Session.removeAttribute("lePompierConnecte");
Session.removeAttribute("lesPompiers");
Session.removeAttribute("lePompier");
request.getRequestDispatcher("/WEB-INF/views/AuthentificationJSP.jsp").forward(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Pompier lePompier = null;
AuthentifForm authentif = new AuthentifForm(request);
if (authentif.ctrlAuthentif() && authentif.ctrlBDD()) {
HttpSession maSession = request.getSession();
lePompier = (Pompier) maSession.getAttribute("lePompierConnecte");
if (lePompier != null) {
if (lePompier.getStatut() == 1) {
getServletContext().getRequestDispatcher("/WEB-INF/views/AccueilPompierJSP.jsp").forward(request, response);
} else if (lePompier.getStatut() == 2) {
getServletContext().getRequestDispatcher("/WEB-INF/views/AccueilResponsableJSP.jsp").forward(request, response);
} else {
request.setAttribute("message", "Statut non reconnu.");
getServletContext().getRequestDispatcher("/WEB-INF/views/AuthentificationJSP.jsp").forward(request, response);
}
} else {
request.setAttribute("message", "Erreur interne : utilisateur non trouvé.");
getServletContext().getRequestDispatcher("/WEB-INF/views/AuthentificationJSP.jsp").forward(request, response);
}
} else {
getServletContext().getRequestDispatcher("/WEB-INF/views/AuthentificationJSP.jsp").forward(request, response);
}
}
/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}

View File

@ -0,0 +1,118 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Servlet.java to edit this template
*/
package Servlet;
import beans.Pompier;
import form.EditionForm;
import java.io.IOException;
import java.io.PrintWriter;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
/**
*
* @author noobm
*/
public class EditionProfilServlet extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet EditionPompierServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet EditionPompierServlet at " + request.getContextPath() + "</h1>");
out.println("</body>");
out.println("</html>");
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Pompier lePompier = null;
HttpSession maSession = request.getSession();
lePompier = (Pompier) maSession.getAttribute("lePompierConnecte");
if (lePompier != null) {
request.setAttribute("pompier", lePompier);
request.getRequestDispatcher("/WEB-INF/views/EditionPompierJSP.jsp").forward(request, response);
} else {
response.sendRedirect("/WEB-INF/views/AuthentificationJSP.jsp");
}
}
/**
* Handles the HTTP <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
EditionForm edition = new EditionForm(request);
Pompier lePompier = null;
HttpSession maSession = request.getSession();
lePompier = (Pompier) maSession.getAttribute("lePompierConnecte");
if (edition.ctrlEdition() && lePompier != null){
lePompier.setNom(request.getParameter("nom"));
lePompier.setPrenom(request.getParameter("prenom"));
lePompier.setLogin(request.getParameter("login"));
lePompier.setMail(request.getParameter("mail"));
lePompier.setAdresse(request.getParameter("adresse"));
lePompier.setCp(request.getParameter("cp"));
lePompier.setVille(request.getParameter("ville"));
lePompier.setBip(request.getParameter("bip"));
lePompier.setGrade(Integer.parseInt(request.getParameter("grade")));
lePompier.setCommentaire(request.getParameter("commentaire"));
request.getSession().setAttribute("lePompierConnecte", lePompier);
response.sendRedirect("/WEB-INF/views/ProfilJSP.jsp");}
else {
response.sendRedirect("/WEB-INF/views/AuthentificationJSP.jsp"); // Rediriger si pas de pompier connecté
}
}
/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}

View File

@ -0,0 +1,93 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Servlet.java to edit this template
*/
package Servlet;
import beans.Pompier;
import java.io.IOException;
import java.io.PrintWriter;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
/**
*
* @author noobm
*/
public class ProfilPompierServlet extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet AccueilPompierServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet AccueilPompierServlet at " + request.getContextPath() + "</h1>");
out.println("</body>");
out.println("</html>");
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession maSession = request.getSession();
Pompier lePompier = (Pompier) maSession.getAttribute("lePompierConnecte");
if (lePompier != null) {
request.setAttribute("pompier", lePompier);
request.getRequestDispatcher("/WEB-INF/views/ProfilJSP.jsp").forward(request, response);
} else {
// Rediriger vers la page de connexion si aucun pompier n'est connecté
response.sendRedirect("login");
}
}
/**
* Handles the HTTP <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}

View File

@ -0,0 +1,37 @@
/*
* bddd/CaserneMySQL.java
*/
package bdd;
import beans.Caserne;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class CaserneMySQL {
private final Connection laConnection = Connexion.getConnect("172.20.10.5",
"sdis29",
"adminBDsdis",
"mdpBDsdis");
public Caserne read(int id) {
Caserne laCaserne = null;
try {
PreparedStatement prepStmt = null;
String sql = "SELECT * FROM caserne WHERE id=?";
prepStmt = laConnection.prepareStatement(sql);
prepStmt.setInt(1, id);
ResultSet result = prepStmt.executeQuery();
if (result.next()) {
laCaserne = new Caserne(result.getInt(1), result.getString(2),result.getString(3),
result.getString(4), result.getString(5),result.getString(6));
}
prepStmt.close();
} catch (SQLException ex) {
System.out.println("SQLExeption : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
return laCaserne;
}
}

View File

@ -0,0 +1,61 @@
package bdd;
/*
Connexion.java
Classe permettant d'établir une connexion avec une base de données mySQL
*/
import java.sql.Connection;
import java.sql.DriverManager;
public class Connexion {
private static Connection connect; // Variable de connexion
/**
* Constructeur
* @param serveur nom du serveur, localhost si local
* @param bdd nom de la base de données
* @param nomUtil nom utilisateur
* @param mdp mot de passe lié à l'utilisateur
*/
private Connexion(String serveur, String bdd, String nomUtil, String mdp) {
try {
// 1. Chargement du driver
//Class.forName("com.mysql.jdbc.Driver");
Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println("Driver accessible");
// 2. Initialisation des paramètres de connexion
String host = serveur; // Serveur de bd
String dbname = bdd; // Nom bd
String url = "jdbc:mysql://" + host + "/" + dbname; // url de connexion
url += "?autoReconnect=true"; // Ajout 26/09/2021
System.out.println("url : "+url);
String user = nomUtil; // nom du user
System.out.println("nomUtil : "+nomUtil);
String passwd = mdp; // mot de passe
System.out.println("mdp : "+mdp);
// 3. Connexion
connect = (Connection) DriverManager.getConnection(url, user, passwd);
System.out.println("Connexion réussie !");
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Retourne la connection établie (Création d'une connection si elle n'existe pas)
* @param serveur nom du serveur, localhost si local
* @param bdd nom de la base de données
* @param nomUtil nom utilisateur
* @param mdp mot de passe lié à l'utilisateur
* @return connection établie
*/
public static Connection getConnect(String serveur, String bdd, String nomUtil, String mdp) {
//System.out.println("getConnect");
if (connect == null) {
new Connexion(serveur, bdd, nomUtil, mdp);
}
return connect;
}
}

View File

@ -0,0 +1,62 @@
package bdd;
import beans.Grade;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
/**
*
* @author noobm
*/
public class GradeMySQL {
private final Connection laConnection = Connexion.getConnect("172.20.10.5",
"sdis29",
"adminBDsdis",
"mdpBDsdis");
public Grade read(int id) {
Grade leGrade = null;
try {
PreparedStatement prepStmt = null;
String sql = "SELECT * FROM grade WHERE idGrade=?";
prepStmt = laConnection.prepareStatement(sql);
prepStmt.setInt(1, id);
ResultSet result = prepStmt.executeQuery();
if (result.next()) {
leGrade = new Grade(result.getInt(1), result.getString(2));
}
prepStmt.close();
} catch (SQLException ex) {
System.out.println("SQLExeption : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
return leGrade;
}
// Lecture de tous les grades dans la base de données
public ArrayList<Grade> readGrades() {
ArrayList<Grade> lesGrades = new ArrayList<>();
try {
PreparedStatement prepStmt = null;
String sql = "SELECT * FROM grade";
prepStmt = laConnection.prepareStatement(sql);
ResultSet result = prepStmt.executeQuery();
while (result.next()) {
Grade grade = new Grade(result.getInt(1), result.getString(2));
lesGrades.add(grade);
}
prepStmt.close();
} catch (SQLException ex) {
System.out.println("SQLExeption : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
return lesGrades;
}
}

View File

@ -0,0 +1,217 @@
/*
* bdd/PompierMysql.java
*/
package bdd;
import beans.Caserne;
import beans.Pompier;
import beans.Statut;
import beans.TypePers;
import beans.Grade;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
public class PompierMySQL {
private final Connection theConnection = Connexion.getConnect("172.20.10.5",
"sdis29",
"adminBDsdis",
"mdpBDsdis");
// Tableau des attributs mis à jour
// 1ère dimension : noms des attributs en bdd
// 2ème dimension : noms des champs transmis
// 3ème dimension : type de données, i pour Integet, s pour String
private String[][] lesAttributs = {
{"id", "idCaserne", "nom", "prenom", "statut", "typePers", "mail", "login", "mdp", "adresse", "cp", "ville", "bip", "grade", "commentaire"},
{"idPompier", "idCaserne", "nom", "prenom", "statut", "type", "mail", "login", "mdp", "adresse", "cp", "ville", "bip", "grade", "obs"},
{"i", "i", "s", "s", "i", "i", "s", "s", "s", "s", "s", "s", "s", "i", "s"}
};
/**
* Recherche du pompier ayant le login et le mdp passé en paramètres
*
* @param login
* @param mdp
* @return Pompier correspondant ou null si non trouvé
*/
public Pompier readAuthentif(String login, String mdp) {
Pompier lePompier = null;
try {
PreparedStatement prepStmt;
String sql = "SELECT * FROM pompier WHERE login=? AND mdp=? ";
prepStmt = theConnection.prepareStatement(sql);
prepStmt.setString(1, login);
prepStmt.setString(2, mdp);
ResultSet result = prepStmt.executeQuery();
if (result.next()) {
CaserneMySQL laCaserneMySQL = new CaserneMySQL();
Caserne laCaserne = laCaserneMySQL.read(result.getInt(2));
lePompier = constituerLePompier(result, laCaserne);
}
prepStmt.close();
} catch (SQLException ex) {
System.out.println("SQLExeption : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
return lePompier;
}
/**
* Recherche les pompiers volontaires de la caserne
*
* @param idCaserne
* @return collection des pompiers concernés
*/
public ArrayList<Pompier> readLesPompiersCaserne(int idCaserne) {
ArrayList<Pompier> lesPompiers = new ArrayList();
try {
PreparedStatement prepStmt;
String sql = "SELECT * FROM pompier WHERE idCaserne=? AND statut=1 AND typePers=2 ORDER BY nom, prenom";
prepStmt = theConnection.prepareStatement(sql);
prepStmt.setInt(1, idCaserne);
ResultSet result = prepStmt.executeQuery();
CaserneMySQL laCaserneMySQL = new CaserneMySQL();
Caserne laCaserne = laCaserneMySQL.read(idCaserne);
while (result.next()) {
Pompier unPompier = constituerLePompier(result, laCaserne);
lesPompiers.add(unPompier);
}
prepStmt.close();
} catch (SQLException ex) {
System.out.println("SQLExeption : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
return lesPompiers;
}
public Pompier constituerLePompier(ResultSet result, Caserne laCaserne) {
Pompier lePompier = null;
StatutMySQL leStatutMySQL = new StatutMySQL();
GradeMySQL leGradeMySQL = new GradeMySQL();
TypePersoMySQL leTypePersoMySQL = new TypePersoMySQL();
try {
Statut leStatut = leStatutMySQL.read(result.getInt("statut"));
TypePers leTypePers = leTypePersoMySQL.read(result.getInt("typePers"));
Grade leGrade = leGradeMySQL.read(result.getInt("grade"));
lePompier = new Pompier(
result.getInt(1),
laCaserne.getId(),
result.getString(3),
result.getString(4),
leStatut.getIdStatut(),
leTypePers.getIdTypePers(),
result.getString(7),
result.getString(8),
result.getString(9),
result.getString(10),
result.getString(11),
result.getString(12),
result.getString(13),
leGrade.getIdGrade(),
result.getString(16));
//System.out.println("lePompier " + lePompier);
} catch (SQLException ex) {
Logger.getLogger(PompierMySQL.class.getName()).log(Level.SEVERE, null, ex);
}
return lePompier;
}
public Pompier create(HashMap<String, Object> lesParametres) {
Pompier lePompierCree = null;
String valeurs [] = new String[lesAttributs[1].length];
String sql = "INSERT INTO pompier (";
int nbAttributsMaj = 0;
String virgule = "";
for (HashMap.Entry unParam : lesParametres.entrySet()) {
int i = 0;
while (i < lesAttributs[1].length && !(lesAttributs[1][i].equals(unParam.getKey()))) {
i++;
}
if (i < lesAttributs[0].length) {
sql += virgule + lesAttributs[0][i];
valeurs[nbAttributsMaj] = "("+lesAttributs[2][i]+")" + unParam.getValue();
nbAttributsMaj++;
virgule = ", ";
}
}
sql += ", dateEnreg) values (?";
for (int i=0; i<nbAttributsMaj; i++ ) {
sql+= ", ?";
}
sql += ");";
// Alimentation des valeurs de la requête
PreparedStatement prepStmt;
try {
prepStmt = theConnection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
for (int i=0; i<nbAttributsMaj; i++) {
if (valeurs[i].substring(0, 3).equals("(s)")) {
prepStmt.setString(i+1, valeurs[i].substring(3));
} else {
prepStmt.setInt(i+1, Integer.parseInt(valeurs[i].substring(3)));
}
}
prepStmt.setTimestamp(nbAttributsMaj+1, new Timestamp(Calendar.getInstance().getTimeInMillis()));
System.out.println("sql "+prepStmt);
int nbLigne = prepStmt.executeUpdate();
//Recherche du no du pompier créé
if (nbLigne > 0) {
ResultSet result = prepStmt.getGeneratedKeys();
if (result.first()) {
int id = result.getInt(1);
lePompierCree = read(id);
System.out.println("lePompierCree : "+ lePompierCree);
}
}
prepStmt.close();
} catch (SQLException ex) {
System.out.println("SQLExeption : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
return lePompierCree;
}
public Pompier read(int idP) {
Pompier unPompier = null;
try {
PreparedStatement prepStmt;
String sql = "SELECT * FROM pompier WHERE idPompier=? ";
prepStmt = theConnection.prepareStatement(sql);
prepStmt.setInt(1, idP);
ResultSet result = prepStmt.executeQuery();
if (result.next()) {
CaserneMySQL laCaserneMySQL = new CaserneMySQL();
Caserne laCaserne = laCaserneMySQL.read(result.getInt(2));
unPompier = constituerLePompier(result, laCaserne);
}
prepStmt.close();
} catch (SQLException ex) {
System.out.println("SQLExeption : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
return unPompier;
}
}

View File

@ -0,0 +1,59 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package bdd;
import beans.Statut;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class StatutMySQL {
private final Connection laConnection = Connexion.getConnect("172.20.10.5",
"sdis29",
"adminBDsdis",
"mdpBDsdis");
public Statut read(int id) {
Statut leStatut = null;
try {
PreparedStatement prepStmt = null;
String sql = "SELECT * FROM statut WHERE idStatut=?";
prepStmt = laConnection.prepareStatement(sql);
prepStmt.setInt(1, id);
ResultSet result = prepStmt.executeQuery();
if (result.next()) {
leStatut = new Statut(result.getInt(1), result.getString(2));
}
prepStmt.close();
} catch (SQLException ex) {
System.out.println("SQLExeption : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
return leStatut;
}
// Lecture de tous les grades dans la base de données
public ArrayList<Statut> readStatuts() {
ArrayList<Statut> lesStatuts = new ArrayList<>();
try {
PreparedStatement prepStmt = null;
String sql = "SELECT * FROM statut";
prepStmt = laConnection.prepareStatement(sql);
ResultSet result = prepStmt.executeQuery();
while (result.next()) {
Statut leStatut = new Statut(result.getInt(1), result.getString(2));
lesStatuts.add(leStatut);
}
prepStmt.close();
} catch (SQLException ex) {
System.out.println("SQLExeption : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
return lesStatuts;
}
}

View File

@ -0,0 +1,65 @@
package bdd;
import beans.Tranche;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
/**
*
* @author noobm
*/
public class TrancheMySQL {
private final Connection laConnection = Connexion.getConnect("172.20.10.5",
"sdis29",
"adminBDsdis",
"mdpBDsdis");
public Tranche read(int id) {
Tranche laTranche = null;
try {
PreparedStatement prepStmt = null;
String sql = "SELECT * FROM tranche WHERE idTranche=?";
prepStmt = laConnection.prepareStatement(sql);
prepStmt.setInt(1, id);
ResultSet result = prepStmt.executeQuery();
if (result.next()) {
laTranche = new Tranche(result.getInt(1), result.getString(2));
}
prepStmt.close();
} catch (SQLException ex) {
System.out.println("SQLExeption : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
return laTranche;
}
// Lecture de tous les grades dans la base de données
public ArrayList<Tranche> readTranches() {
ArrayList<Tranche> lesTranches = new ArrayList<>();
try {
PreparedStatement prepStmt = null;
String sql = "SELECT * FROM tranche";
prepStmt = laConnection.prepareStatement(sql);
ResultSet result = prepStmt.executeQuery();
while (result.next()) {
Tranche laTranche = new Tranche(result.getInt(1), result.getString(2));
lesTranches.add(laTranche);
}
prepStmt.close();
} catch (SQLException ex) {
System.out.println("SQLExeption : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
return lesTranches;
}
}

View File

@ -0,0 +1,65 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package bdd;
import beans.TypePers;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
public class TypePersoMySQL {
private final Connection laConnection = Connexion.getConnect("172.20.10.5",
"sdis29",
"adminBDsdis",
"mdpBDsdis");
public TypePers read(int id) {
TypePers leTypePerso = null;
try {
PreparedStatement prepStmt = null;
String sql = "SELECT * FROM typePers WHERE idTypePers=?";
prepStmt = laConnection.prepareStatement(sql);
prepStmt.setInt(1, id);
ResultSet result = prepStmt.executeQuery();
if (result.next()) {
leTypePerso = new TypePers(result.getInt(1), result.getString(2));
}
prepStmt.close();
} catch (SQLException ex) {
System.out.println("SQLExeption : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
return leTypePerso;
}
// Lecture de tous les grades dans la base de données
public ArrayList<TypePers> readStatuts() {
ArrayList<TypePers> lesTypePers = new ArrayList<>();
try {
PreparedStatement prepStmt = null;
String sql = "SELECT * FROM typePers";
prepStmt = laConnection.prepareStatement(sql);
ResultSet result = prepStmt.executeQuery();
while (result.next()) {
TypePers leTypePers = new TypePers(result.getInt(1), result.getString(2));
lesTypePers.add(leTypePers);
}
prepStmt.close();
} catch (SQLException ex) {
System.out.println("SQLExeption : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
return lesTypePers;
}
}

View File

@ -0,0 +1,84 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package beans;
public class Caserne {
private int id;
private String nom;
private String adresse;
private String tel;
private String groupement;
private String codePostal;
public Caserne(int id, String nom, String adresse, String tel, String groupement, String codePostal) {
this.id = id;
this.nom = nom;
this.adresse = adresse;
this.tel = tel;
this.groupement = groupement;
this.codePostal = codePostal;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getAdresse() {
return adresse;
}
public void setAdresse(String adresse) {
this.adresse = adresse;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getGroupement() {
return groupement;
}
public void setGroupement(String groupement) {
this.groupement = groupement;
}
public String getCodePostal() {
return codePostal;
}
public void setCodePostal(String codePostal) {
this.codePostal = codePostal;
}
@Override
public String toString() {
return "Caserne{" +
"id=" + id +
", nom='" + nom + '\'' +
", adresse='" + adresse + '\'' +
", tel='" + tel + '\'' +
", groupement='" + groupement + '\'' +
", codePostal='" + codePostal + '\'' +
'}';
}
}

View File

@ -0,0 +1,41 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package beans;
public class Disponibilite {
private int idDispo;
private String libelle;
public Disponibilite() {}
public Disponibilite(int idDispo, String libelle) {
this.idDispo = idDispo;
this.libelle = libelle;
}
public int getIdDispo() {
return idDispo;
}
public void setIdDispo(int idDispo) {
this.idDispo = idDispo;
}
public String getLibelle() {
return libelle;
}
public void setLibelle(String libelle) {
this.libelle = libelle;
}
@Override
public String toString() {
return "Disponibilite{" +
"idDispo=" + idDispo +
", libelle='" + libelle + '\'' +
'}';
}
}

41
src/java/beans/Grade.java Normal file
View File

@ -0,0 +1,41 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package beans;
public class Grade {
private int idGrade;
private String libelle;
public Grade() {}
public Grade(int idGrade, String libelle) {
this.idGrade = idGrade;
this.libelle = libelle;
}
public int getIdGrade() {
return idGrade;
}
public void setIdGrade(int idGrade) {
this.idGrade = idGrade;
}
public String getLibelle() {
return libelle;
}
public void setLibelle(String libelle) {
this.libelle = libelle;
}
@Override
public String toString() {
return "Grade{" +
"idGrade=" + idGrade +
", libelle='" + libelle + '\'' +
'}';
}
}

202
src/java/beans/Pompier.java Normal file
View File

@ -0,0 +1,202 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package beans;
public class Pompier {
private int idPompier;
private int idCaserne;
private String nom;
private String prenom;
private int statut;
private int typePers;
private String mail;
private String login;
private String mdp;
private String adresse;
private String cp;
private String ville;
private String bip;
private int grade;
private String commentaire;
public Pompier(
int idPompier,
int idCaserne,
String nom,
String prenom,
int statut,
int typePers,
String mail,
String login,
String mdp,
String adresse,
String cp,
String ville,
String bip,
int grade,
String commentaire) {
this.idPompier = idPompier;
this.idCaserne = idCaserne;
this.nom = nom;
this.prenom = prenom;
this.statut = statut;
this.typePers = typePers;
this.mail = mail;
this.login = login;
this.mdp = mdp;
this.adresse = adresse;
this.cp = cp;
this.ville = ville;
this.bip = bip;
this.grade = grade;
this.commentaire = commentaire;
}
public int getIdPompier() {
return idPompier;
}
public void setIdPompier(int idPompier) {
this.idPompier = idPompier;
}
public int getIdCaserne() {
return idCaserne;
}
public void setIdCaserne(int idCaserne) {
this.idCaserne = idCaserne;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
public int getStatut() {
return statut;
}
public void setStatut(int statut) {
this.statut = statut;
}
public int getTypePers() {
return typePers;
}
public void setTypePers(int typePers) {
this.typePers = typePers;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getMdp() {
return mdp;
}
public void setMdp(String mdp) {
this.mdp = mdp;
}
public String getAdresse() {
return adresse;
}
public void setAdresse(String adresse) {
this.adresse = adresse;
}
public String getCp() {
return cp;
}
public void setCp(String cp) {
this.cp = cp;
}
public String getVille() {
return ville;
}
public void setVille(String ville) {
this.ville = ville;
}
public String getBip() {
return bip;
}
public void setBip(String bip) {
this.bip = bip;
}
public int getGrade() {
return grade;
}
public void setGrade(int grade) {
this.grade = grade;
}
public String getCommentaire() {
return commentaire;
}
public void setCommentaire(String commentaire) {
this.commentaire = commentaire;
}
@Override
public String toString() {
return "Pompier{" +
"idPompier=" + idPompier +
", idCaserne=" + idCaserne +
", nom='" + nom + '\'' +
", prenom='" + prenom + '\'' +
", statut=" + statut +
", typePers=" + typePers +
", mail='" + mail + '\'' +
", login='" + login + '\'' +
", mdp='" + mdp + '\'' +
", adresse='" + adresse + '\'' +
", cp='" + cp + '\'' +
", ville='" + ville + '\'' +
", bip='" + bip + '\'' +
", grade=" + grade +
", commentaire='" + commentaire + '\'' +
'}';
}
}

View File

@ -0,0 +1,63 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package beans;
public class PompierDispo {
private int idJour;
private int idPompier;
private int idTranche;
private Integer idDisponibilite;
public PompierDispo() {}
public PompierDispo(int idJour, int idPompier, int idTranche, Integer idDisponibilite) {
this.idJour = idJour;
this.idPompier = idPompier;
this.idTranche = idTranche;
this.idDisponibilite = idDisponibilite;
}
public int getIdJour() {
return idJour;
}
public void setIdJour(int idJour) {
this.idJour = idJour;
}
public int getIdPompier() {
return idPompier;
}
public void setIdPompier(int idPompier) {
this.idPompier = idPompier;
}
public int getIdTranche() {
return idTranche;
}
public void setIdTranche(int idTranche) {
this.idTranche = idTranche;
}
public Integer getIdDisponibilite() {
return idDisponibilite;
}
public void setIdDisponibilite(Integer idDisponibilite) {
this.idDisponibilite = idDisponibilite;
}
@Override
public String toString() {
return "PompierDispo{" +
"idJour=" + idJour +
", idPompier=" + idPompier +
", idTranche=" + idTranche +
", idDisponibilite=" + idDisponibilite +
'}';
}
}

View File

@ -0,0 +1,41 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package beans;
public class Statut {
private int idStatut;
private String libelle;
public Statut() {}
public Statut(int idStatut, String libelle) {
this.idStatut = idStatut;
this.libelle = libelle;
}
public int getIdStatut() {
return idStatut;
}
public void setIdStatut(int idStatut) {
this.idStatut = idStatut;
}
public String getLibelle() {
return libelle;
}
public void setLibelle(String libelle) {
this.libelle = libelle;
}
@Override
public String toString() {
return "Statut{" +
"idStatut=" + idStatut +
", libelle='" + libelle + '\'' +
'}';
}
}

View File

@ -0,0 +1,42 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package beans;
public class Tranche {
private int idTranche;
private String libelle;
public Tranche() {}
public Tranche(int idTranche, String libelle) {
this.idTranche = idTranche;
this.libelle = libelle;
}
public int getIdTranche() {
return idTranche;
}
public void setIdTranche(int idTranche) {
this.idTranche = idTranche;
}
public String getLibelle() {
return libelle;
}
public void setLibelle(String libelle) {
this.libelle = libelle;
}
@Override
public String toString() {
return "Tranche{" +
"idTranche=" + idTranche +
", libelle='" + libelle + '\'' +
'}';
}
}

View File

@ -0,0 +1,41 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package beans;
public class TypePers {
private int idTypePers;
private String libelle;
public TypePers() {}
public TypePers(int idTypePers, String libelle) {
this.idTypePers = idTypePers;
this.libelle = libelle;
}
public int getIdTypePers() {
return idTypePers;
}
public void setIdTypePers(int idTypePers) {
this.idTypePers = idTypePers;
}
public String getLibelle() {
return libelle;
}
public void setLibelle(String libelle) {
this.libelle = libelle;
}
@Override
public String toString() {
return "TypePers{" +
"idTypePers=" + idTypePers +
", libelle='" + libelle + '\'' +
'}';
}
}

View File

@ -0,0 +1,86 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package form;
import bdd.GradeMySQL;
import bdd.PompierMySQL;
import bdd.StatutMySQL;
import bdd.TypePersoMySQL;
import bdd.TrancheMySQL;
import beans.Pompier;
import beans.Statut;
import beans.TypePers;
import beans.Grade;
import beans.Tranche;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import java.util.ArrayList;
import util.CtrlSaisie;
import util.MD5;
public class AuthentifForm {
String message;
HttpServletRequest request;
public AuthentifForm(HttpServletRequest request) {
this.request = request;
}
public boolean ctrlAuthentif() {
request.removeAttribute("message");
String[] champsObligatoires = {"username", "password"};
if (!CtrlSaisie.CtrlChampsObligatoires(request, champsObligatoires)) {
return false;
}
// Vérification absence de chevron
if (!CtrlSaisie.CtrlChevron(request)) {
return false;
}
return true;
}
public boolean ctrlBDD() {
boolean trouve = false;
String login = request.getParameter("username");
String mdp = MD5.encode(request.getParameter("password"));
PompierMySQL pompierMySQL = new PompierMySQL();
Pompier lePompier = pompierMySQL.readAuthentif(login, mdp);
if (lePompier!= null) {
trouve = true;
HttpSession maSession = request.getSession();
maSession.setAttribute("lePompierConnecte", lePompier);
StatutMySQL leStatutMySQL = new StatutMySQL();
GradeMySQL leGradeMySQL = new GradeMySQL();
TrancheMySQL lesTranchesMySQL = new TrancheMySQL();
TypePersoMySQL leTypePersoMySQL = new TypePersoMySQL();
ArrayList<Grade> lesGrades = leGradeMySQL.readGrades();
maSession.setAttribute("les grades", lesGrades);
ArrayList<Tranche> lesTranches = lesTranchesMySQL.readTranches();
maSession.setAttribute("les tranches", lesTranches);
ArrayList<Statut> lesStatuts = leStatutMySQL.readStatuts();
maSession.setAttribute("les statuts", lesStatuts);
ArrayList<TypePers> lesTypes = leTypePersoMySQL.readStatuts();
maSession.setAttribute("lesTypes", lesTypes);
if (lePompier.getStatut()== 2) {
ArrayList <Pompier> lesPompiers = pompierMySQL.readLesPompiersCaserne(lePompier.getIdCaserne());
maSession.setAttribute("lesPompiers", lesPompiers);
}
} else {
request.setAttribute("message", "Login ou mot de passe erroné");
}
return trouve;
}
}

View File

@ -0,0 +1,45 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package form;
import bdd.GradeMySQL;
import bdd.PompierMySQL;
import bdd.StatutMySQL;
import bdd.TypePersoMySQL;
import bdd.TrancheMySQL;
import beans.Pompier;
import beans.Statut;
import beans.TypePers;
import beans.Grade;
import beans.Tranche;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import java.util.ArrayList;
import util.CtrlSaisie;
/**
*
* @author noobm
*/
public class EditionForm {
String message;
HttpServletRequest request;
public EditionForm(HttpServletRequest request) {
this.request = request;
}
public boolean ctrlEdition() {
request.removeAttribute("message");
String[] champsObligatoires = {"username", "password",};
if (!CtrlSaisie.CtrlChampsObligatoires(request, champsObligatoires)) {
return false;
}
// Vérification absence de chevron
if (!CtrlSaisie.CtrlChevron(request)) {
return false;
}
return true;
}
}

View File

@ -0,0 +1,64 @@
/*
* util/CtrlSaisie.java
*/
package util;
import jakarta.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Enumeration;
/**
*
* @author domin
*/
public abstract class CtrlSaisie {
/**
* Vérifie la présence des champs obligatoires dans les paramètres transmis
* @param request
* @param champsObligatoires : tableau de chaine de caractères, avec le nom des champs obligatoires
* @return booléen
*/
public static boolean CtrlChampsObligatoires(HttpServletRequest request, String[] champsObligatoires) {
ArrayList <String> champsPresents = new ArrayList<>(request.getParameterMap().keySet());
int i = 0;
int nbChampsO = champsObligatoires.length;
boolean erreur = false;
while (erreur == false && i < nbChampsO && champsPresents.contains(champsObligatoires[i])){
String value=request.getParameter(champsObligatoires[i]);
if (value.trim().length() > 0) {
i++;
} else {
erreur = true;
}
}
if (i < nbChampsO) {
request.setAttribute("message", "Veuillez renseigner toutes les zones obligatoires ("+i+')');
}
return (i>=nbChampsO);
}
/**
* Contrôle si un champ de saisie contient un chevron
* @param request
* @return 0 sinon, -1 si oui
*/
public static boolean CtrlChevron(HttpServletRequest request) {
// Contrôle car "<" dans les zones de texte
Enumeration lesNoms = request.getParameterNames();
int erreur = 0;
//ArrayList <String> parameterNames = new ArrayList<String>(request.getParameterMap().keySet());
while (erreur == 0 && lesNoms.hasMoreElements()) {
Object paramObjet=lesNoms.nextElement();
String param=(String) paramObjet;
String value=request.getParameter(param);
if (value.contains("<") || value.contains("<")) {
String message = "Veuillez recommencer votre saisie, une anomalie sur une zone de saisie a été détectée ";
request.setAttribute("message", message);
erreur=1;
}
}
return (erreur > 0) ? false : true;
}
}

36
src/java/util/MD5.java Normal file
View File

@ -0,0 +1,36 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package util;
/**
*
* @author sio
*/
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;
public abstract class MD5 {
public static String encode(String uneChaine){
MessageDigest md = null;
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException ex) {
throw new IllegalArgumentException(ex);
}
md.update(uneChaine.getBytes());
byte[] digest = md.digest();
//myHash = DatatypeConverter.printHexBinary(digest).toLowerCase();
StringBuilder sb = new StringBuilder();
for (byte b : digest) {
sb.append(String.format("%02x", b));
}
return sb.toString();
}
}

2
web/META-INF/context.xml Normal file
View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/appli3"/>

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SDIS29</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

View File

@ -0,0 +1,3 @@
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</body>
</html>

View File

@ -0,0 +1,19 @@
<body class="bg-light">
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="AccueilPompier">SDIS29</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="Profil">Consulter le Profil</a>
</li>
<li class="nav-item">
<a class="nav-link" href="EditionProfil">Éditer le Profil</a>
</li>
</ul>
</div>
</div>
</nav>

View File

@ -0,0 +1,38 @@
<jsp:include page="../shared/EnteteJSP.jsp" />
<jsp:include page="../shared/NavigationJSP.jsp"/>
<div class="container mt-5">
<div class="row">
<div class="col-md-4">
<div class="card mb-4">
<img src="https://via.placeholder.com/150" class="card-img-top">
<div class="card-body">
<h5 class="card-title">Card 1</h5>
<p class="card-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero.</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card mb-4">
<img src="https://via.placeholder.com/150" class="card-img-top" >
<div class="card-body">
<h5 class="card-title">Card 2</h5>
<p class="card-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero.</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card mb-4">
<img src="https://via.placeholder.com/150" class="card-img-top" >
<div class="card-body">
<h5 class="card-title">Card 3</h5>
<p class="card-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero.</p>
</div>
</div>
</div>
</div>
</div>
</body>
<jsp:include page="../shared/FooterJSP.jsp" />

View File

@ -0,0 +1,12 @@
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>

View File

@ -0,0 +1,25 @@
<jsp:include page="../shared/EnteteJSP.jsp" />
<body class="p-3 mb-2 bg-light.bg-gradient text-dark" style="background: linear-gradient(135deg, #ffffff, #b0b0b0); min-height: 100vh; display: flex; justify-content: center; align-items: center; margin: 0;">
<div class="card p-4" style="max-width: 400px; width: 100%; border-radius: 10px;">
<h2 class="text-center mb-4">Connexion</h2>
<form action="authentification" method="post">
<div class="mb-3">
<label for="username" class="form-label">Nom d'utilisateur</label>
<input type="text" class="form-control" id="username" name="username" placeholder="Entrez votre nom d'utilisateur" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Mot de passe</label>
<input type="password" class="form-control" id="password" name="password" placeholder="Entrez votre mot de passe" required>
</div>
<c:if test="${not empty message}">
<div class="message">
${message}
</div>
</c:if>
<button class="btn btn-outline-secondary w-100" type="submit">Se connecter</button>
</form>
</div>
<jsp:include page="../shared/FooterJSP.jsp" />
</html>

View File

@ -0,0 +1,50 @@
<jsp:include page="../shared/EnteteJSP.jsp" />
<jsp:include page="../shared/NavigationJSP.jsp"/>
<body class="bg-light">
<div class="container mt-5">
<h1 class="text-center">Modifier le profil</h1>
<form action="EditionProfil" method="Post">
<div class="mb-3">
<label for="nom" class="form-label">Nom</label>
<input type="text" class="form-control" id="nom" name="nom" placeholder="${pompier.nom}" value="${pompier.nom}" required>
</div>
<div class="mb-3">
<label for="prenom" class="form-label">Prénom</label>
<input type="text" class="form-control" id="prenom" name="prenom" placeholder="${pompier.prenom}" value="${pompier.prenom}" required>
</div>
<div class="mb-3">
<label for="login" class="form-label">Login</label>
<input type="text" class="form-control" id="login" name="login" placeholder="${pompier.login}" value="${pompier.login}" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" name="mail" placeholder="${pompier.mail}" value="${pompier.mail}" required>
</div>
<div class="mb-3">
<label for="adresse" class="form-label">Adresse</label>
<input type="text" class="form-control" id="adresse" name="adresse" placeholder="${pompier.adresse}" value="${pompier.adresse}" required>
</div>
<div class="mb-3">
<label for="cp" class="form-label">Code Postal</label>
<input type="text" class="form-control" id="cp" name="cp" placeholder="${pompier.cp}" value="${pompier.cp}" required>
</div>
<div class="mb-3">
<label for="ville" class="form-label">Ville</label>
<input type="text" class="form-control" id="ville" name="ville" placeholder="${pompier.ville}" value="${pompier.ville}" required>
</div>
<div class="mb-3">
<label for="bip" class="form-label">BIP</label>
<input type="text" class="form-control" id="bip" name="bip" placeholder="${pompier.bip}" value="${pompier.bip}" required>
</div>
<div class="mb-3">
<label for="grade" class="form-label">Grade</label>
<input type="number" class="form-control" id="grade" name="grade" placeholder="${pompier.grade}" value="${pompier.grade}" required>
</div>
<button type="submit" class="btn btn-primary">Enregistrer les modifications</button>
</form>
</div>
</body>
<jsp:include page="../shared/FooterJSP.jsp" />

View File

@ -0,0 +1,29 @@
<jsp:include page="../shared/EnteteJSP.jsp" />
<jsp:include page="../shared/NavigationJSP.jsp"/>
<div class="container mt-5">
<h1 class="text-center">Informations du Pompier</h1>
<table class="table table-bordered table-striped">
<tr>
<th>ID</th>
<td>${pompier.idPompier}</td>
</tr>
<tr>
<th>Nom</th>
<td>${pompier.nom}</td>
</tr>
<tr>
<th>Prénom</th>
<td>${pompier.prenom}</td>
</tr>
<tr>
<th>Login</th>
<td>${pompier.login}</td>
</tr>
<tr>
<th>Adresse</th>
<td>${pompier.adresse}, ${pompier.ville}, ${pompier.cp} </td>
</tr>
</table>
</div>
<jsp:include page="../shared/FooterJSP.jsp" />

27
web/WEB-INF/web.xml Normal file
View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="6.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd">
<servlet>
<servlet-name>AuthentificationServlet</servlet-name>
<servlet-class>Servlet.AuthentificationServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>ProfilPompierServlet</servlet-name>
<servlet-class>Servlet.ProfilPompierServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>EditionProfilServlet</servlet-name>
<servlet-class>Servlet.EditionProfilServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AuthentificationServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ProfilPompierServlet</servlet-name>
<url-pattern>/Profil</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>EditionProfilServlet</servlet-name>
<url-pattern>/EditionProfil</url-pattern>
</servlet-mapping>
</web-app>

BIN
web/img/logo-sdis.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
web/img/pompier.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

15
web/index.html Normal file
View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<!--
Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Html.html to edit this template
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>TODO write content</div>
</body>
</html>

39
web/ressources/mycss.css Normal file
View File

@ -0,0 +1,39 @@
body {
background: linear-gradient(135deg, #667eea, #764ba2);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
margin: 0;
}
.auth-form {
background: #fff;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
padding: 30px;
max-width: 400px;
width: 100%;
}
.auth-form h2 {
text-align: center;
margin-bottom: 20px;
color: #333;
}
.auth-form .btn-primary {
background: #667eea;
border-color: #667eea;
}
.auth-form .btn-primary:hover {
background: #5a67d8;
}
.form-footer {
text-align: center;
margin-top: 15px;
}
.form-footer a {
text-decoration: none;
color: #667eea;
}
.form-footer a:hover {
text-decoration: underline;
}