Compare commits

...

2 Commits

Author SHA1 Message Date
thomas.millot
2c1ac0fa50 Merge origin/master 2021-12-14 09:14:14 +01:00
thomas.millot
eae43733b0 Merge origin/master
Conflicts:
	src/java/bdd/PompierMysql.java
	web/WEB-INF/ProfilJSP.jsp
2021-12-14 08:44:24 +01:00
45 changed files with 5162 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="sdis29M1" default="default" basedir=".">
<description>Builds, tests, and runs the project sdis29M1.</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>

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

@ -0,0 +1,57 @@
<?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="${tomcat.home}/server/lib/catalina-ant.jar"/>
<deploy url="${tomcat.url}/manager" 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="${tomcat.home}/server/lib/catalina-ant.jar"/>
<undeploy url="${tomcat.url}/manager" 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=b54f128f
build.xml.script.CRC32=111e10f7
build.xml.stylesheet.CRC32=1707db4f@1.86.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=b54f128f
nbproject/build-impl.xml.script.CRC32=bc2b5756
nbproject/build-impl.xml.stylesheet.CRC32=334708a0@1.86.0.1

View File

@ -0,0 +1,89 @@
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=authentification
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}
endorsed.classpath=\
${libs.javaee-endorsed-api-7.0.classpath}
excludes=
file.reference.jakarta.servlet.jsp.jstl-2.0.0.jar=C:\\Users\\domin\\Downloads\\lib\\jakarta.servlet.jsp.jstl-2.0.0.jar
file.reference.jakarta.servlet.jsp.jstl-api-2.0.0.jar=C:\\Users\\domin\\Downloads\\lib\\jakarta.servlet.jsp.jstl-api-2.0.0.jar
file.reference.mysql-connector-java-8.0.26.jar=C:\\Users\\domin\\Downloads\\lib\\mysql-connector-java-8.0.26.jar
includes=**
j2ee.compile.on.save=true
j2ee.copy.static.files.on.save=true
j2ee.deploy.on.save=true
j2ee.platform=1.7-web
j2ee.platform.classpath=${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.20.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jakartaee-migration-1.0.0-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.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.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.26.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.debug=true
javac.deprecation=false
javac.processorpath=\
${javac.classpath}
javac.source=1.7
javac.target=1.7
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
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=sdis29M1.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>sdis29M1</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.26.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"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</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,41 @@
/*
* bddd/CaserneMySQL.java
*/
package bdd;
import bean.Caserne;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
*
* @author Dominique_2
*/
public class CaserneMySQL {
private final Connection laConnection = Connexion.getConnect("Localhost",
"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));
}
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,80 @@
/*
* bdd/ParamMySQL.java
*/
package bdd;
import bean.Parametre;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
/**
*
* @author Dominique_2
*/
public class ParamMySQL {
private final Connection laConnection = Connexion.getConnect("Localhost",
"sdis29",
"adminBDsdis",
"mdpBDsdis");
/**
* Recherche du paramètre correspondant au type et à l'indice passé en paramètres
* @param typeParam
* @param ind
* @return Parametre concerné ou null si non trouvé
*/
public Parametre read(String typeParam, int ind) {
Parametre leParam = null;
try {
PreparedStatement prepStmt = null;
String sql = "SELECT * FROM parametre WHERE idType=? AND indice=?";
prepStmt = laConnection.prepareStatement(sql);
prepStmt.setString(1, typeParam);
prepStmt.setInt(2, ind);
ResultSet result = prepStmt.executeQuery();
if (result.next()) {
leParam = new Parametre(result.getString(1), result.getInt(2),
result.getString(3));
}
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 leParam;
}
/**
* Recherche de tous les paramètres du type passé en paramètre
* @param unType
* @return collection de Parametre correspondant au type
*/
public ArrayList<Parametre> readType(String unType) {
ArrayList<Parametre> lesParam = new ArrayList();
try {
PreparedStatement prepStmt = null;
String sql = "SELECT * FROM parametre WHERE idType=? ";
prepStmt = laConnection.prepareStatement(sql);
prepStmt.setString(1, unType);
ResultSet result = prepStmt.executeQuery();
Parametre leParam;
while (result.next()) {
leParam = new Parametre(result.getString(1), result.getInt(2),
result.getString(3));
lesParam.add(leParam);
}
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 lesParam;
}
}

View File

@ -0,0 +1,338 @@
/*
* bdd/PompierMysql.java
*/
package bdd;
import bean.Caserne;
import bean.Parametre;
import bean.Pompier;
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;
/**
*
* @author Dominique_2
*/
public class PompierMySQL {
private final Connection theConnection = Connexion.getConnect("localhost",
"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"},
{"idP", "idC", "ztNom", "ztPrenom", "ldrStatut", "ldrType", "ztMail", "ztLogin", "ztMdp", "ztAdresse", "ztCP", "zlVille", "ztBip", "ldrGrade", "ztObs"},
{"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 des 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;
ParamMySQL leParamMySQL = new ParamMySQL();
try {
Parametre leStatut = leParamMySQL.read("statAgt", result.getInt(5));
Parametre leType = leParamMySQL.read("typePer", result.getInt(6));
Parametre leGrade = leParamMySQL.read("grade", result.getInt(15));
lePompier = new Pompier(laCaserne, result.getInt(1),
result.getString(3), result.getString(4),
leStatut, leType,
result.getString(7), result.getString(8),
result.getString(9), result.getString(10),
result.getString(11), result.getString(12),
result.getString(13), leGrade, result.getString(16));
//System.out.println("lePompier " + lePompier);
} catch (SQLException ex) {
Logger.getLogger(PompierMySQL.class.getName()).log(Level.SEVERE, null, ex);
}
return lePompier;
}
/**
* Recherche du dernier no de pompier utilisé pour une caserne
*
* @param idC : caserne concernée
* @return dernier no de pompier utilisé dansla caserne
*/
public int getIdMax(int idC) {
int max = 0;
try {
PreparedStatement prepStmt;
String sql = "SELECT max(pId) FROM pompier WHERE pCis = ?";
prepStmt = theConnection.prepareStatement(sql);
prepStmt.setInt(1, idC);
ResultSet result = prepStmt.executeQuery();
if (result.first()) {
max = result.getInt(1);
}
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 max;
}
public Pompier update(HashMap<String, Object> lesParametres, int idP) {
// Date dateJ = new Date();
// DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
// String dateDuJour = dateFormat.format(dateJ);
Pompier lePompierMaj = null;
// Constitution de la requête en fonction des données transmises
String valeurs [] = new String[lesAttributs[1].length];
String sql = "UPDATE pompier SET ";
int nbAttributsMaj = 0;
String virgule = "";
for (HashMap.Entry unParam : lesParametres.entrySet()) {
// Recherche attribut correspondant au champ trnasmis
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 += ", dateModif = ? WHERE id = ?;";
// Alimentation des valeurs de la requête
PreparedStatement prepStmt;
try {
prepStmt = theConnection.prepareStatement(sql);
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()));
prepStmt.setInt(nbAttributsMaj+2, idP);
System.out.println("sql "+prepStmt);
int nbLigne = prepStmt.executeUpdate();
//Recherche du no du pompier créé
if (nbLigne > 0) {
System.out.println("nbLigne " + nbLigne);
lePompierMaj = read(idP);
System.out.println("lePompierMaj : "+ lePompierMaj);
}
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 lePompierMaj;
// String sql = "UPDATE pompier "
// + "SET pNom = ?, pPrenom = ?, pMail = ?, "
// + "pLogin = ?, pMdp = ?, pAdresse = ?, pCp = ?, pVille = ?, "
// + "pBip = ?, pGrade = ?, pCommentaire = ?, pDateModif = ? "
// + "WHERE pCis=? AND pId=?; ";
// return requeteMaj(sql, lesParametres);
}
public Pompier create(HashMap<String, Object> lesParametres) {
Pompier lePompierCree = null;
// Constitution de la requête en fonction des données transmises
String valeurs [] = new String[lesAttributs[1].length];
String sql = "INSERT INTO pompier (";
int nbAttributsMaj = 0;
String virgule = "";
for (HashMap.Entry unParam : lesParametres.entrySet()) {
// Recherche attribut correspondant au champ trnasmis
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;
}
private Pompier requeteMaj(String sql, HashMap<String, Object> lesParametres) {
int nbLigne = 0;
try {
PreparedStatement prepStmt;
prepStmt = theConnection.prepareStatement(sql);
prepStmt.setString(1, (String) lesParametres.get("ztNom"));
prepStmt.setString(2, (String) lesParametres.get("ztPrenom"));
prepStmt.setString(3, (String) lesParametres.get("ztMail"));
prepStmt.setString(4, (String) lesParametres.get("ztLogin"));
prepStmt.setString(5, (String) lesParametres.get("ztMdp"));
prepStmt.setString(6, (String) lesParametres.get("ztAdresse"));
prepStmt.setString(7, (String) lesParametres.get("ztCP"));
prepStmt.setString(8, (String) lesParametres.get("ztVille"));
prepStmt.setString(9, (String) lesParametres.get("ztBip"));
prepStmt.setInt(10, (Integer) lesParametres.get("ldrGrade"));
prepStmt.setString(11, (String) lesParametres.get("taObs"));
//prepStmt.setDate(12, java.sql.Date.valueOf(java.time.LocalDate.now()));
prepStmt.setTimestamp(12, new Timestamp(Calendar.getInstance().getTimeInMillis()));
prepStmt.setInt(13, (Integer) lesParametres.get("idC"));
prepStmt.setInt(14, (Integer) lesParametres.get("zhIdP"));
if (sql.substring(0, 6).equals("INSERT")) {
prepStmt.setInt(15, (Integer) lesParametres.get("idStatut"));
prepStmt.setInt(16, (Integer) lesParametres.get("idType"));
}
System.out.println(prepStmt);
nbLigne = prepStmt.executeUpdate();
prepStmt.close();
} catch (SQLException ex) {
System.out.println("SQLExeption : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
Pompier lePompierMaj = null;
if (nbLigne > 0) {
//lePompierMaj = read((Integer) lesParametres.get("idC"), (Integer) lesParametres.get("zhIdP"));
}
return lePompierMaj;
}
public Pompier read(int idP) {
Pompier unPompier = null;
try {
PreparedStatement prepStmt;
String sql = "SELECT * FROM pompier WHERE id=? ";
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,194 @@
/*
* 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 bdd;
import bean.Parametre;
import bean.Pompier;
import bean.Ventil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import util.TrmtDate;
/**
*
* @author sio
*/
public class VentilMysql {
private final Connection theConnection = Connexion.getConnect("localhost",
"sdis29",
"adminBDsdis",
"mdpBDsdis");
public ArrayList<Ventil> getLesVentil(Calendar[] lesDates, String[] lesPeriodes, HttpServletRequest request) {
ArrayList<Ventil> lesVentil = new ArrayList<>();
Ventil uneVentil;
/* a. Initialisation de la collection lesVentil pour la période,
création d'une ventil par pompier, par date et période
*/
int indiceDateFin = lesDates.length - 1;
Pompier lePompier;
PompierMySQL pm = new PompierMySQL();
HttpSession maSession = request.getSession();
ArrayList<Pompier> lesPompiers = (ArrayList<Pompier>) maSession.getAttribute("lesPompiers");
for (Pompier unPompier : lesPompiers) {
for (Calendar uneDate : lesDates) {
for (String unePeriode : lesPeriodes) {
uneVentil = new Ventil(uneDate, unePeriode, unPompier);
lesVentil.add(uneVentil);
}
}
}
/* b) Maj de la collection lesVentil
*/
readAll(lesVentil, lesDates[0], lesDates[indiceDateFin]);
//System.out.println("lesVentil : " + lesVentil);
return lesVentil;
}
public void readAll(ArrayList<Ventil> lesVentil, Calendar d1, Calendar d2) {
Pompier lePompier;
Ventil uneVentil;
Ventil laVentilTrouvee;
ParamMySQL leParamMySQL = new ParamMySQL();
String sql = "SELECT * FROM ventilation "
+ "INNER JOIN pompier on idPompier = id "
+ "WHERE jourVentil BETWEEN ? and ?;";
try {
PreparedStatement prepStmt = theConnection.prepareStatement(sql);
prepStmt.setDate(1, TrmtDate.getSQLDate(d1));
prepStmt.setDate(2, TrmtDate.getSQLDate(d2));
ResultSet resultat = prepStmt.executeQuery();
while (resultat.next()) {
Parametre leStatut = leParamMySQL.read("statAgt", resultat.getInt(5));
lePompier = new Pompier(resultat.getInt("id"),
resultat.getString("nom"),
resultat.getString("prenom"),
leStatut);
uneVentil = new Ventil(TrmtDate.getCalDate(resultat.getDate("jourVentil")),
resultat.getString("periode"),
lePompier);
// Recherche si uneVentil existe dans les Ventil
int indice = lesVentil.indexOf(uneVentil);
if (indice > -1) {
laVentilTrouvee = lesVentil.get(indice);
laVentilTrouvee.setActivite(resultat.getInt("ventil"));
laVentilTrouvee.setIsInBD(true);
}
}
prepStmt.close();
resultat.close();
} catch (SQLException ex) {
System.out.println("SQLExeption : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
}
/**
* Suppression de la ventilation passée en paramètre
*
* @param v : ventilation à supprimer
* @return : nb lignes supprimées ou -1 si erreur
*/
public int delete(Ventil v) {
int nbMAJ = -1;
String sql = "DELETE FROM ventilation "
+ "WHERE idPompier = ? "
+ "AND periode = ? "
+ "AND jourVentil = ?;";
try {
PreparedStatement prepStmt = theConnection.prepareStatement(sql);
prepStmt.setInt(1, v.getPompier().getId());
prepStmt.setString(2, v.getPeriode());
prepStmt.setDate(3, TrmtDate.getSQLDate(v.getJourVentil()));
nbMAJ = prepStmt.executeUpdate();
} catch (SQLException ex) {
System.out.println("SQLExeption : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
return nbMAJ;
}
/**
* Création de la ventilation passée en paramètre
*
* @param v : ventilation à créer
* @return : identifiant de la ventilation créé, ou -1 si erreur
*/
public int create(Ventil v) {
int idCree = -1;
String sql = "INSERT into ventilation "
+ "(jourVentil, periode, idPompier, ventil) "
+ "VALUES (?, ?, ?, ?)";
try {
PreparedStatement prepStmt = null;
prepStmt = theConnection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
prepStmt.setDate(1, TrmtDate.getSQLDate(v.getJourVentil()));
prepStmt.setString(2, v.getPeriode());
prepStmt.setInt(3, v.getPompier().getId());
prepStmt.setInt(4, v.getActivite());
System.out.println("create : "+ prepStmt);
int nbLigne = prepStmt.executeUpdate();
// Recherche du no de la ventilation créée
if (nbLigne > 0) {
ResultSet result = prepStmt.getGeneratedKeys();
if (result.next()) {
idCree = result.getInt(1);
}
}
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 idCree;
}
/**
* Mise à jour de la ventilation passée en paramètre
* @param v : ventilation à mettre à jour
* @return : nb lignes mises à jour, -1 si erreur
*/
public int update(Ventil v) {
int nbMAJ = -1;
String sql = "UPDATE ventilation "
+ "SET ventil = ? "
+ "WHERE idPompier = ? "
+ "AND jourVentil = ? "
+ "AND periode = ?";
try {
PreparedStatement prepStmt = theConnection.prepareStatement(sql);
prepStmt.setInt(1, v.getActivite());
prepStmt.setInt(2, v.getPompier().getId());
prepStmt.setDate(3, TrmtDate.getSQLDate(v.getJourVentil()));
prepStmt.setString(4, v.getPeriode());
System.out.println("update : " + prepStmt);
nbMAJ = prepStmt.executeUpdate();
} catch (SQLException ex) {
Logger.getLogger(VentilMysql.class.getName()).log(Level.SEVERE, null, ex);
}
return nbMAJ;
}
}

101
src/java/bean/Caserne.java Normal file
View File

@ -0,0 +1,101 @@
/*
* bean/Caserne.java
*/
package bean;
import java.util.Objects;
/**
*
* @author Dominique_2
*/
public class Caserne {
private int id;
private String nom;
private String adresse;
private String tel;
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 Caserne(int cId, String cNom, String cAdresse, String cTel) {
this.id = cId;
this.nom = cNom;
this.adresse = cAdresse;
this.tel = cTel;
}
@Override
public int hashCode() {
int hash = 5;
hash = 17 * hash + this.id;
hash = 17 * hash + Objects.hashCode(this.nom);
hash = 17 * hash + Objects.hashCode(this.adresse);
hash = 17 * hash + Objects.hashCode(this.tel);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Caserne other = (Caserne) obj;
if (this.id != other.id) {
return false;
}
if (!Objects.equals(this.nom, other.nom)) {
return false;
}
if (!Objects.equals(this.adresse, other.adresse)) {
return false;
}
if (!Objects.equals(this.tel, other.tel)) {
return false;
}
return true;
}
@Override
public String toString() {
return "Caserne{" + "id=" + id + ", nom=" + nom + ", adresse=" + adresse + ", tel=" + tel + '}';
}
}

View File

@ -0,0 +1,71 @@
/*
* bean/Parametre.java
*/
package bean;
/**
*
* @author Dominique_2
*/
public class Parametre {
private String typParam;
private int code;
private String valeur;
/**
* @return the code
*/
public int getCode() {
return code;
}
/**
* @param code the code to set
*/
public void setCode(int code) {
this.code = code;
}
/**
* @return the valeur
*/
public String getValeur() {
return valeur;
}
/**
* @param valeur the valeur to set
*/
public void setValeur(String valeur) {
this.valeur = valeur;
}
public Parametre(String typParam, int code, String valeur) {
this.typParam = typParam;
this.code = code;
this.valeur = valeur;
}
/**
* @return the typParam
*/
public String getTypParam() {
return typParam;
}
/**
* @param typParam the typParam to set
*/
public void setTypParam(String typParam) {
this.typParam = typParam;
}
@Override
public String toString() {
return "Parametre{" + "typParam=" + typParam + ", code=" + code + ", valeur=" + valeur + '}';
}
}

227
src/java/bean/Pompier.java Normal file
View File

@ -0,0 +1,227 @@
/*
* bean/Pompier.java
*/
package bean;
import java.util.Objects;
/**
*
* @author Dominique_2
*/
public class Pompier {
private Caserne laCaserne;
private int id;
private String nom;
private String prenom;
private Parametre leStatut;
private Parametre leType;
private String mail;
private String login;
private String mdp;
private String adresse;
private String cp;
private String ville;
private String bip;
private Parametre leGrade;
private String commentaire;
public Caserne getLaCaserne() {
return laCaserne;
}
public void setLaCaserne(Caserne laCaserne) {
this.laCaserne = laCaserne;
}
public Pompier(Caserne laCaserne, int id, String nom, String prenom, Parametre leStatut, Parametre leType, String mail, String login, String mdp, String adresse, String cp, String ville, String bip, Parametre leGrade, String commentaire) {
// this.laCaserne = laCaserne;
// this.pId = pId;
// this.pNom = pNom;
// this.pPrenom = pPrenom;
this(laCaserne, id, nom, prenom);
this.leStatut = leStatut;
this.leType = leType;
this.mail = mail;
this.login = login;
this.mdp = mdp;
this.adresse = adresse;
this.cp = cp;
this.ville = ville;
this.bip = bip;
this.leGrade = leGrade;
this.commentaire = commentaire;
}
public Pompier(int id, String nom, String prenom, Parametre leStatut) {
this.id = id;
this.nom = nom;
this.prenom = prenom;
this.leStatut = leStatut;
}
public Pompier(Caserne laCaserne, int id, String nom, String prenom) {
this.laCaserne = laCaserne;
this.id = id;
this.nom = nom;
this.prenom = prenom;
}
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 getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
public Parametre getLeStatut() {
return leStatut;
}
public void setLeStatut(Parametre leStatut) {
this.leStatut = leStatut;
}
public Parametre getLeType() {
return leType;
}
public void setLeType(Parametre leType) {
this.leType = leType;
}
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 Parametre getLeGrade() {
return leGrade;
}
public void setLeGrade(Parametre leGrade) {
this.leGrade = leGrade;
}
public String getCommentaire() {
return commentaire;
}
public void setCommentaire(String commentaire) {
this.commentaire = commentaire;
}
@Override
public int hashCode() {
int hash = 5;
hash = 67 * hash + Objects.hashCode(this.laCaserne);
hash = 67 * hash + this.id;
hash = 67 * hash + Objects.hashCode(this.nom);
hash = 67 * hash + Objects.hashCode(this.prenom);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Pompier other = (Pompier) obj;
if (this.id != other.id) {
return false;
}
return true;
}
@Override
public String toString() {
return "Pompier{" + "laCaserne=" + laCaserne + ", id=" + id + ", nom=" + nom + ", prenom=" + prenom + ", leStatut=" + leStatut + ", leType=" + leType + ", mail=" + mail + ", login=" + login + ", mdp=" + mdp + ", adresse=" + adresse + ", cp=" + cp + ", ville=" + ville + ", bip=" + bip + ", grade=" + leGrade + ", commentaire=" + commentaire + '}';
}
}

116
src/java/bean/Ventil.java Normal file
View File

@ -0,0 +1,116 @@
/*
* 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 bean;
import java.util.Calendar;
import java.util.Objects;
/**
*
* @author sio
*/
public class Ventil {
Calendar JourVentil;
String periode;
Pompier pompier;
int activite;
boolean isInBD;
public Calendar getJourVentil() {
return JourVentil;
}
public void setJourVentil(Calendar JourVentil) {
this.JourVentil = JourVentil;
}
public String getPeriode() {
return periode;
}
public void setPeriode(String periode) {
this.periode = periode;
}
public Pompier getPompier() {
return pompier;
}
public void setPompier(Pompier pompier) {
this.pompier = pompier;
}
public int getActivite() {
return activite;
}
public void setActivite(int activite) {
this.activite = activite;
}
public boolean isIsInBD() {
return isInBD;
}
public void setIsInBD(boolean isInBD) {
this.isInBD = isInBD;
}
public Ventil(Calendar JourVentil, String periode, Pompier pompier, int activite, boolean isInBD) {
this.JourVentil = JourVentil;
this.periode = periode;
this.pompier = pompier;
this.activite = activite;
this.isInBD = isInBD;
}
public Ventil(Calendar JourVentil, String periode, Pompier pompier) {
this.JourVentil = JourVentil;
this.periode = periode;
this.pompier = pompier;
}
@Override
public int hashCode() {
int hash = 7;
hash = 71 * hash + Objects.hashCode(this.JourVentil);
hash = 71 * hash + Objects.hashCode(this.periode);
hash = 71 * hash + Objects.hashCode(this.pompier);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Ventil other = (Ventil) obj;
if (!Objects.equals(this.periode, other.periode)) {
return false;
}
if (!Objects.equals(this.JourVentil, other.JourVentil)) {
return false;
}
if (!Objects.equals(this.pompier, other.pompier)) {
return false;
}
return true;
}
@Override
public String toString() {
return "Ventil{" + "JourVentil=" + JourVentil.getTime() + ", periode=" + periode + ", pompier=" + pompier + ", activite=" + activite + ", isInBD=" + isInBD + '}';
}
}

15
src/java/doc/readMe Normal file
View File

@ -0,0 +1,15 @@
Variables de session :
Variables mises en session après authentification (AuthentifForm.java)
lePompierConnecte : pompier authentifié
lePompier : pompier à afficher dans pompierJSP
lesGrades : collection des grades possibles (
lesPeriodes : collections des périodes d'affectation possibles (nuit, matin, ...)
lesStatuts : collection des statuts (pompier, chef de centre, resp. alertes)
lesTypes : collection des types (pompier volontaires, perso médical, perso adm.)
lesPompiers : collection des pompiers de la caserne, reseignée uniquement si le pompier connecté est un chef de centre
Variables mises en session dans PompierServlet.java)
lePompier : pompier à afficher dans pompierJSP
Attributs utilisés entre la servet PompierServlet.java et pompierJSP :
page : 2 --> affichage des données du pompier connecté
3 --> affichage des données d'un pompier de la caserne pour le chef de centre

View File

@ -0,0 +1,229 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Filter.java to edit this template
*/
package filter;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.FilterConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
/**
*
* @author domin
*/
public class authentifFilter implements Filter {
private static final boolean debug = true;
// The filter configuration object we are associated with. If
// this value is null, this filter instance is not currently
// configured.
private FilterConfig filterConfig = null;
public authentifFilter() {
}
private void doBeforeProcessing(ServletRequest request, ServletResponse response)
throws IOException, ServletException {
if (debug) {
log("authentifFilter:DoBeforeProcessing");
}
// Write code here to process the request and/or response before
// the rest of the filter chain is invoked.
// For example, a logging filter might log items on the request object,
// such as the parameters.
/*
for (Enumeration en = request.getParameterNames(); en.hasMoreElements(); ) {
String name = (String)en.nextElement();
String values[] = request.getParameterValues(name);
int n = values.length;
StringBuffer buf = new StringBuffer();
buf.append(name);
buf.append("=");
for(int i=0; i < n; i++) {
buf.append(values[i]);
if (i < n-1)
buf.append(",");
}
log(buf.toString());
}
*/
}
private void doAfterProcessing(ServletRequest request, ServletResponse response)
throws IOException, ServletException {
if (debug) {
log("authentifFilter:DoAfterProcessing");
}
// Write code here to process the request and/or response after
// the rest of the filter chain is invoked.
// For example, a logging filter might log the attributes on the
// request object after the request has been processed.
/*
for (Enumeration en = request.getAttributeNames(); en.hasMoreElements(); ) {
String name = (String)en.nextElement();
Object value = request.getAttribute(name);
log("attribute: " + name + "=" + value.toString());
}
*/
// For example, a filter might append something to the response.
/*
PrintWriter respOut = new PrintWriter(response.getWriter());
respOut.println("<P><B>This has been appended by an intrusive filter.</B>");
*/
}
/**
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
* @param chain The filter chain we are processing
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet error occurs
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
if (debug) {
log("authentifFilter:doFilter()");
}
// Cast de l'objet request
HttpServletRequest requete = (HttpServletRequest) request;
// Pas de filtrage des css, des images, des js
String chemin = requete.getRequestURI().substring(requete.getContextPath().length());
//System.out.println("Chemin : " + chemin);
if (chemin.startsWith("/css") || chemin.startsWith("/images") || chemin.startsWith("/js")) {
//System.out.println(" - passage ok");
chain.doFilter(request, response);
return;
}
// Récupération de la session
HttpSession maSession = requete.getSession();
// Récupération du booléen d'authentification
boolean authentificationOK = false;
if (maSession.getAttribute("lePompierConnecte") != null) {
authentificationOK = true;
}
//System.out.println("authentificationOK : "+ authentificationOK);
if (authentificationOK) {
// Poursuite sans problème
chain.doFilter(request, response);
} else {
// retour vers la page d'authentification
request.getRequestDispatcher("authentification").forward(request, response);
}
}
/**
* Return the filter configuration object for this filter.
*/
public FilterConfig getFilterConfig() {
return (this.filterConfig);
}
/**
* Set the filter configuration object for this filter.
*
* @param filterConfig The filter configuration object
*/
public void setFilterConfig(FilterConfig filterConfig) {
this.filterConfig = filterConfig;
}
/**
* Destroy method for this filter
*/
public void destroy() {
}
/**
* Init method for this filter
*/
public void init(FilterConfig filterConfig) {
this.filterConfig = filterConfig;
if (filterConfig != null) {
if (debug) {
log("authentifFilter:Initializing filter");
}
}
}
/**
* Return a String representation of this object.
*/
@Override
public String toString() {
if (filterConfig == null) {
return ("authentifFilter()");
}
StringBuffer sb = new StringBuffer("authentifFilter(");
sb.append(filterConfig);
sb.append(")");
return (sb.toString());
}
private void sendProcessingError(Throwable t, ServletResponse response) {
String stackTrace = getStackTrace(t);
if (stackTrace != null && !stackTrace.equals("")) {
try {
response.setContentType("text/html");
PrintStream ps = new PrintStream(response.getOutputStream());
PrintWriter pw = new PrintWriter(ps);
pw.print("<html>\n<head>\n<title>Error</title>\n</head>\n<body>\n"); //NOI18N
// PENDING! Localize this for next official release
pw.print("<h1>The resource did not process correctly</h1>\n<pre>\n");
pw.print(stackTrace);
pw.print("</pre></body>\n</html>"); //NOI18N
pw.close();
ps.close();
response.getOutputStream().close();
} catch (Exception ex) {
}
} else {
try {
PrintStream ps = new PrintStream(response.getOutputStream());
t.printStackTrace(ps);
ps.close();
response.getOutputStream().close();
} catch (Exception ex) {
}
}
}
public static String getStackTrace(Throwable t) {
String stackTrace = null;
try {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
pw.close();
sw.close();
stackTrace = sw.getBuffer().toString();
} catch (Exception ex) {
}
return stackTrace;
}
public void log(String msg) {
filterConfig.getServletContext().log(msg);
}
}

View File

@ -0,0 +1,75 @@
/*
* form/authentifForm.java
* Controle des données saisie dans le formulaire d'authentification
*/
package form;
import bdd.ParamMySQL;
import bdd.PompierMySQL;
import bean.Parametre;
import bean.Pompier;
import com.sun.net.httpserver.HttpServer;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import java.util.ArrayList;
import util.CtrlSaisie;
import util.MD5;
/**
*
* @author domin
*/
public class AuthentifForm {
String message;
HttpServletRequest request;
public AuthentifForm(HttpServletRequest request) {
this.request = request;
}
public boolean ctrlAuthentif() {
request.removeAttribute("message");
// Vérification de la présence des zones obligatoires
String[] champsObligatoires = {"ztLogin", "ztMDP"};
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("ztLogin");
String mdp = MD5.encode(request.getParameter("ztMDP"));
PompierMySQL pompierMySQL = new PompierMySQL();
Pompier lePompier = pompierMySQL.readAuthentif(login, mdp);
if (lePompier!= null) {
trouve = true;
HttpSession maSession = request.getSession();
maSession.setAttribute("lePompierConnecte", lePompier);
ParamMySQL paramMySQL = new ParamMySQL();
ArrayList <Parametre> lesGrades = paramMySQL.readType("grade");
maSession.setAttribute("lesGrades", lesGrades);
ArrayList <Parametre> lesPeriodes = paramMySQL.readType("tranche");
maSession.setAttribute("lesPeriodes", lesPeriodes);
ArrayList <Parametre> lesStatuts = paramMySQL.readType("statAgt");
maSession.setAttribute("lesStatuts", lesStatuts);
ArrayList <Parametre> lesTypes = paramMySQL.readType("typePer");
maSession.setAttribute("lesTypes", lesTypes);
if (lePompier.getLeStatut().getCode()==2) {
// Recherche des pompiers de la caserne
ArrayList <Pompier> lesPompiers = pompierMySQL.readLesPompiersCaserne(lePompier.getLaCaserne().getId());
maSession.setAttribute("lesPompiers", lesPompiers);
}
} else {
request.setAttribute("message", "Login ou mot de passe erroné");
}
return trouve;
}
}

View File

@ -0,0 +1,169 @@
/*
* form/PompierForm.java
* Contrôle des données saisies dans le formulaire pompier et maj bdd
*/
package form;
import bdd.ParamMySQL;
import bdd.PompierMySQL;
import bean.Parametre;
import bean.Pompier;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashMap;
import util.CtrlSaisie;
import util.MD5;
/**
*
* @author domin
*/
public class PompierForm {
String message;
HttpServletRequest request;
public PompierForm(HttpServletRequest request) {
this.request = request;
}
public boolean ctrlPompier() {
request.removeAttribute("message");
// Vérification de la présence des zones obligatoires
String[] champsObligatoires = {"ztNom", "ztPrenom", "ztAdresse", "ztCP",
"zlVille", "ztMail", "ztLogin", "ztMdp", "ztBip", "ldrGrade", "ldrStatut", "ldrType"};
if (!CtrlSaisie.CtrlChampsObligatoires(request, champsObligatoires)) {
return false;
}
// Contrôle caractères indésirables
if (!CtrlSaisie.CtrlChevron(request)) {
return false;
}
// Contrôle des zones grade, statut et typerPers
HttpSession maSession = request.getSession();
Pompier lePompierConnecte = (Pompier) maSession.getAttribute("lePompierConnecte");
boolean chef = lePompierConnecte.getLeStatut().getCode() == 2;
ParamMySQL pm = new ParamMySQL();
if (chef) { // contrôle uniquement pour les chefs de centre
int statut, type, grade = -1;
try {
statut = Integer.parseInt(request.getParameter("ldrStatut"));
type = Integer.parseInt(request.getParameter("ldrType"));
grade = Integer.parseInt(request.getParameter("ldrGrade"));
} catch (Exception e) {
System.out.println("Statut, type ou grade transmis non numérique - " + e.getMessage());
request.setAttribute("message", "Erreur au niveau de la saisie du statut, du grade ou du type");
return false;
}
Parametre leStatut = pm.read("statAgt", statut);
Parametre leType = pm.read("typePer", type);
Parametre leGrade = pm.read("grade", grade);
if (leStatut == null || leType == null || leGrade == null) {
System.out.println("Statut, type ou grade transmis inexistant dans la table paramètre - "
+ "Statut:" + statut + " - Type:" + type + " - Grade:" + grade);
request.setAttribute("message", "Erreur au niveau de la saisie du statut, du grade ou du type");
return false;
}
}
return true;
}
// Mise à jour de la fiche du pompier
public Pompier majBDD() {
HttpSession maSession = request.getSession();
Pompier lePompierConnecte = (Pompier) maSession.getAttribute("lePompierConnecte");
boolean chef = lePompierConnecte.getLeStatut().getCode() == 2;
Pompier lepompierAffiche = (Pompier) maSession.getAttribute("lePompier");
// Recherche du type de mise à jour à effectuer
int typMaj = -1;
if (chef && maSession.getAttribute("lePompier") == null) {
System.out.println("Creation d'un nouveau pompier");
typMaj = 1;
} else {
if (chef && lepompierAffiche.getId() != lePompierConnecte.getId()) {
System.out.println("Maj d'un pompier par le chef de centre");
typMaj = 2;
} else {
System.out.println("Maj du pompier connecté par lui-même");
typMaj = 3;
}
}
ArrayList<String> nonModifParPompier = new ArrayList<>();
nonModifParPompier.add("ldrGrade");
nonModifParPompier.add("ldrStatut");
nonModifParPompier.add("ldrType");
nonModifParPompier.add("ztBip");
// Zones saisies
HashMap<String, Object> lesParametres = new HashMap();
Enumeration<String> names = request.getParameterNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
// Exclusion des zones non modifiables pour les pompiers
if (typMaj == 1 || typMaj == 2 || !nonModifParPompier.contains(name)) {
Object value = request.getParameter(name);
lesParametres.put(name, value);
}
}
// Zones implicites
if (typMaj == 1) {
int idC = lePompierConnecte.getLaCaserne().getId();
lesParametres.put("idC", idC); // Caserne
}
// if (typMaj == 2 || typMaj == 3) {
// int idP = lepompierAffiche.getId();
// lesParametres.put("idP", idP); // id du pompier
// }
// Cas particulier du mot de passe, actuellement non modifiable
String ztMdp = MD5.encode((String) lesParametres.get("ztLogin"));
lesParametres.put("ztMdp", ztMdp); // Mot de passe défini à partir du login
/* Pb pour les zones numériques :
elles doivent être mémorisées dans le dictionnaire en entier, pour
une lecture par la suite */
Pompier lePompierMaj = null;
PompierMySQL pompierMySQL = new PompierMySQL();
if (typMaj == 1) {
lePompierMaj = pompierMySQL.create(lesParametres);
} else {
lePompierMaj = pompierMySQL.update(lesParametres, lepompierAffiche.getId());
}
if (lePompierMaj != null) {
request.setAttribute("message", "Le pompier no " + lePompierMaj.getId() + " a été mis à jour");
} else {
request.setAttribute("message", "Erreur lors de la mise à jour du pompier");
}
// Mise à jour de la collection les Pompiers, si le pompier mis à jour est volontaire
if (chef && lePompierMaj != null) {
// ArrayList<Pompier> lesPompiers = (ArrayList<Pompier>) maSession.getAttribute("lesPompiers");
// if (lesPompiers.contains(lePompierMaj)) {
// lesPompiers.remove(lePompierMaj);
// }
// if (lePompierConnecte.getId() != lePompierMaj.getId()) {
// lesPompiers.add(lePompierMaj);
// }
ArrayList<Pompier> lesPompiers = pompierMySQL.readLesPompiersCaserne(lePompierConnecte.getLaCaserne().getId());
maSession.setAttribute("lesPompiers", lesPompiers);
maSession.setAttribute("lePompier", lesPompiers.get(0));
}
if (typMaj==3) {
maSession.setAttribute("lePompierConnecte", lePompierMaj);
maSession.setAttribute("lePompier", lePompierMaj);
}
return lePompierMaj;
}
}

View File

@ -0,0 +1,58 @@
/*
* 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 form;
import bdd.VentilMysql;
import bean.Ventil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Map;
/**
*
* @author thomas.millot
*/
public class VentilForm {
public void verifVentil(HttpServletRequest request) {
//a.récupération de la collection des ventilation
HttpSession maSession = request.getSession();
ArrayList<Ventil> lesVentil
= (ArrayList<Ventil>) maSession.getAttribute("lesVentilInit");
//b.Créer un objet de type VentilMysql
VentilMysql vm = new VentilMysql();
//c.Récupérer les données du formulaire
Map<String, String[]> map = request.getParameterMap();
String[] lesNvVentil = map.get("lesActivites");
//d. Initialiser du compteur de boucle
int i = 0;
//e.Mise a jour des activité des salariés
for (Ventil uneVentil : lesVentil) {
int oldAct = uneVentil.getActivite();
int newAct = Integer.parseInt(lesNvVentil[i]);
if (oldAct != newAct) {
if (uneVentil.isIsInBD()) {
if(newAct == 0){
vm.delete(uneVentil);
} else {
uneVentil.setActivite(newAct);
vm.update(uneVentil);
}
} else {
uneVentil.setActivite(newAct);
vm.create(uneVentil);
}
}
i++;
}
}
}

View File

@ -0,0 +1,115 @@
/*
* 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 bean.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;
import java.util.ArrayList;
/**
*
* @author domin
*/
public class AuthentifServlet 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 AuthentifServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet AuthentifServlet 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 {
//processRequest(request, response);
// Suppression des variables de session
System.out.println("doGet AuthentifServlet");
HttpSession maSession = request.getSession();
maSession.removeAttribute("lePompierConnecte");
maSession.removeAttribute("lesPompiers");
maSession.removeAttribute("lePompier");
getServletContext().getRequestDispatcher("/WEB-INF/authentifJSP.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 {
//processRequest(request, response);
Pompier lePompier = null;
int page = 2;
AuthentifForm af = new AuthentifForm(request);
if (af.ctrlAuthentif() && af.ctrlBDD()) { // Contrôle des zones saisies et contrôle en base de données
HttpSession maSession = request.getSession();
lePompier = (Pompier) maSession.getAttribute("lePompierConnecte");
if (lePompier.getLeStatut().getCode()==2) { // Chef de centre
ArrayList <Pompier> lesPompiers = (ArrayList <Pompier>) maSession.getAttribute("lesPompiers");
if (lesPompiers.size() > 0) {
lePompier = lesPompiers.get(0);
page = 3;
}
}
request.setAttribute("page", page);
//request.setAttribute("lePompier", lePompier);
maSession.setAttribute("lePompier", lePompier);
getServletContext().getRequestDispatcher("/WEB-INF/pompierJSP.jsp").forward(request, response);
} else { // Une erreur a été détectée
getServletContext().getRequestDispatcher("/WEB-INF/authentifJSP.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,180 @@
/*
* 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 servlet;
import bdd.VentilMysql;
import bean.Pompier;
import bean.Ventil;
import com.mysql.cj.util.StringUtils;
import form.VentilForm;
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;
import java.util.ArrayList;
import java.util.Calendar;
import util.TrmtDate;
/**
*
* @author thomas.millot
*/
public class LesDispoServlet 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 LesDispoServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet LesDispoServlet 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 {
// processRequest(request, response);
//Méthode accédée uniquement depuis la barre du menu
int pageDemandee = 0;
int page = 5;
String jsp = "lesDispoJSP.jsp";
boolean erreur = false;
if (request.getParameter("pageDemandee") != null) {
String pageEnString = request.getParameter("pageDemandee");
boolean isNumeric = StringUtils.isStrictlyNumeric(pageEnString);
if (isNumeric) {
pageDemandee = Integer.parseInt(pageEnString);
if (pageDemandee != 5) { // erreur
erreur = true;
}
} else {
erreur = true;
}
} else {
erreur = true;
}
HttpSession maSession = request.getSession();
Pompier lePompier = null;
if (maSession.getAttribute("lesVentilInit") == null) {
/* Initialisations des dates de la semaine */
Calendar[] lesDates = new Calendar[7];
String[] lesDatesEnString = new String[7];
lesDates[0] = TrmtDate.getDateDebutSemaine();
lesDatesEnString[0] = TrmtDate.getDateAAfficher(lesDates[0]);
for (int i = 1; i < lesDates.length; i++) {
lesDates[i] = TrmtDate.addDays(lesDates[0], i);
lesDatesEnString[i] = TrmtDate.getDateAAfficher(lesDates[i]);
}
maSession.setAttribute("lesDates", lesDates);
maSession.setAttribute("lesDatesEnString", lesDatesEnString);
//System.out.println("lesDates "+ lesDates[4].getTime());
/* Initialisation des périodes */
String[] lesPeriodes = {"1", "2", "3", "4"};
maSession.setAttribute("lesPeriodes", lesPeriodes);
/* Recherche des ventilations */
VentilMysql vm = new VentilMysql();
ArrayList<Ventil> lesVentilInit = vm.getLesVentil(lesDates, lesPeriodes, request);
//System.out.println("lesVentilInit : " + lesVentilInit);
maSession.setAttribute("lesVentilInit", lesVentilInit);
/* Initialisation des couleurs */
String[] lesCouleurs = {"vert", "orange", "rouge"};
maSession.setAttribute("lesCouleurs", lesCouleurs);
}
if (erreur == false) {
lePompier = (Pompier) maSession.getAttribute("lePompierConnecte");
if (pageDemandee == 5 && lePompier.getLeStatut().getCode() != 2) { // erreur
erreur = true;
}
}
if (erreur == false && pageDemandee == 5) { // Chef de centre
ArrayList<Pompier> lesPompiers = (ArrayList<Pompier>) maSession.getAttribute("lesPompiers");
//System.out.println("lesPompiers de la caserne " + lesPompiers);
if (lesPompiers.size() > 0) {
lePompier = lesPompiers.get(0);
page = 5;
}
}
if (erreur) {
request.getRequestDispatcher("/authentification").forward(request, response); // redirection servlet
} else {
request.setAttribute("page", page);
maSession.setAttribute("lePompier", lePompier);
getServletContext().getRequestDispatcher("/WEB-INF/" + 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 {
//processRequest(request, response);
//a.créer un objet de type ventilForm
VentilForm vf = new VentilForm();
//b.Appeler verifVentil
vf.verifVentil(request);
//c.Afficher le menu
getServletContext().getRequestDispatcher("/WEB-INF/pompierJSP.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,173 @@
/*
* 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 servlet;
import bdd.VentilMysql;
import bean.Pompier;
import bean.Ventil;
import com.mysql.cj.util.StringUtils;
import form.VentilForm;
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;
import java.util.ArrayList;
import java.util.Calendar;
import util.TrmtDate;
/**
*
* @author thomas.millot
*/
public class MesDispoServlet 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 MesDispoServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet MesDispoServlet 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 {
//processRequest(request, response);
//Méthode accédée uniquement depuis la barre du menu
System.out.println("doGet mesDispo");
int pageDemandee = 0;
int page = 6;
String jsp = "mesDispoJSP.jsp";
boolean erreur = false;
if (request.getParameter("pageDemandee") != null) {
String pageEnString = request.getParameter("pageDemandee");
boolean isNumeric = StringUtils.isStrictlyNumeric(pageEnString);
if (isNumeric) {
pageDemandee = Integer.parseInt(pageEnString);
if (pageDemandee != 6) { // erreur
erreur = true;
}
} else {
erreur = true;
}
} else {
erreur = true;
}
HttpSession maSession = request.getSession();
Pompier lePompier = null;
if (maSession.getAttribute("lesVentilInit") == null) {
/* Initialisations des dates de la semaine */
Calendar[] lesDates = new Calendar[7];
String[] lesDatesEnString = new String[7];
lesDates[0] = TrmtDate.getDateDebutSemaine();
lesDatesEnString[0] = TrmtDate.getDateAAfficher(lesDates[0]);
for (int i = 1; i < lesDates.length; i++) {
lesDates[i] = TrmtDate.addDays(lesDates[0], i);
lesDatesEnString[i] = TrmtDate.getDateAAfficher(lesDates[i]);
}
maSession.setAttribute("lesDates", lesDates);
maSession.setAttribute("lesDatesEnString", lesDatesEnString);
//System.out.println("lesDates "+ lesDates[4].getTime());
/* Initialisation des périodes */
String[] lesPeriodes = {"1", "2", "3", "4"};
maSession.setAttribute("lesPeriodes", lesPeriodes);
/* Recherche des ventilations */
VentilMysql vm = new VentilMysql();
ArrayList<Ventil> lesVentilInit = vm.getLesVentil(lesDates, lesPeriodes, request);
//System.out.println("lesVentilInit : " + lesVentilInit);
maSession.setAttribute("lesVentilInit", lesVentilInit);
/* Initialisation des couleurs */
String[] lesCouleurs = {"vert", "orange", "rouge"};
maSession.setAttribute("lesCouleurs", lesCouleurs);
}
if (erreur == false) {
lePompier = (Pompier) maSession.getAttribute("lePompierConnecte");
if (pageDemandee == 6 && lePompier.getLeStatut().getCode() != 1) { // erreur
erreur = true;
}
}
System.out.println("erreur : "+ erreur);
if (erreur) {
request.getRequestDispatcher("/authentification").forward(request, response); // redirection servlet
} else {
request.setAttribute("page", page);
maSession.setAttribute("lePompier", lePompier);
getServletContext().getRequestDispatcher("/WEB-INF/" + 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 {
//processRequest(request, response);
//a.créer un objet de type ventilForm
VentilForm vf = new VentilForm();
//b.Appeler verifVentil
vf.verifVentil(request);
//c.Afficher le menu
getServletContext().getRequestDispatcher("/WEB-INF/pompierJSP.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,194 @@
/*
* 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 bean.Pompier;
import com.mysql.cj.util.StringUtils;
import form.PompierForm;
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;
import java.util.ArrayList;
/**
*
* @author domin
*/
public class PompierServlet 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 PompierServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet PompierServlet 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 {
//processRequest(request, response);
//Méthode accédée uniquement depuis la barre du menu
int pageDemandee = 0;
int page = 2;
String jsp = "pompierJSP.jsp";
boolean erreur = false;
if (request.getParameter("pageDemandee") != null) {
String pageEnString = request.getParameter("pageDemandee");
boolean isNumeric = StringUtils.isStrictlyNumeric(pageEnString);
if (isNumeric) {
pageDemandee = Integer.parseInt(pageEnString);
if (pageDemandee != 2 && pageDemandee != 3) { // erreur
erreur = true;
}
} else {
erreur = true;
}
} else {
erreur = true;
}
HttpSession maSession = request.getSession();
Pompier lePompier = null;
if (erreur == false) {
lePompier = (Pompier) maSession.getAttribute("lePompierConnecte");
if (pageDemandee == 3 && lePompier.getLeStatut().getCode() != 2) { // erreur
erreur = true;
}
}
if (erreur == false && pageDemandee == 3) { // Chef de centre
ArrayList<Pompier> lesPompiers = (ArrayList<Pompier>) maSession.getAttribute("lesPompiers");
//System.out.println("lesPompiers de la caserne " + lesPompiers);
if (lesPompiers.size() > 0) {
lePompier = lesPompiers.get(0);
page = 3;
}
}
if (erreur) {
request.getRequestDispatcher("/authentification").forward(request, response); // redirection servlet
} else {
request.setAttribute("page", page);
maSession.setAttribute("lePompier", lePompier);
getServletContext().getRequestDispatcher("/WEB-INF/" + 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 {
//processRequest(request, response);
/* Méthode accédée
depuis la validation du formulaire de choix du pompier à afficher (btAfficherPompier = "Afficher")
depuis le bouton Ajouter du formulaire du choix du pompier (btAfficherPompier = "Ajouter")
depuis le bouton de validation de mise à jour d'un pompier (btAfficherPompier = "ValiderMaj")
*/
int erreur = 0;
String btValue = null;
ArrayList<String> valeursBt = new ArrayList<String>() ;
valeursBt.add("Afficher") ;
valeursBt.add("Ajouter") ;
valeursBt.add("ValiderMaj") ;
// Test du bouton btAfficherPompier
if (request.getParameter("btAfficherPompier")==null) {
erreur = 1;
} else {
btValue = request.getParameter("btAfficherPompier");
if (!valeursBt.contains(btValue)) {
erreur = 2;
}
}
if (erreur > 0) {
request.getRequestDispatcher("/authentification").forward(request, response); // redirection servlet
//response.sendRedirect("/sdis29M1/authentification");
return;
}
HttpSession maSession = request.getSession();
ArrayList<Pompier> lesPompiers = (ArrayList<Pompier>) maSession.getAttribute("lesPompiers");
if (request.getParameter("btAfficherPompier").equals("Afficher")
&& Integer.parseInt(request.getParameter("ldrPompier")) < lesPompiers.size()) {
int noPompier = Integer.parseInt(request.getParameter("ldrPompier"));
//request.setAttribute("lePompier", lesPompiers.get(noPompier));
maSession.setAttribute("lePompier", lesPompiers.get(noPompier));
request.setAttribute("page", 3);
}
if (request.getParameter("btAfficherPompier").equals("Ajouter")) {
maSession.removeAttribute("lePompier");
}
if (request.getParameter("btAfficherPompier").equals("ValiderMaj")) {
PompierForm pf = new PompierForm(request);
boolean valid = pf.ctrlPompier();
// if (maSession.getAttribute("lePompier")==null) {
// System.out.println("Creation d'un nouveau pompier");
// } else {
// Pompier lePompier = (Pompier) maSession.getAttribute("lePompier");
// Pompier lePompierConnecte = (Pompier) maSession.getAttribute("lePompierConnecte");
// if (lePompier.getId() != lePompierConnecte.getId()) {
// System.out.println("Maj d'un pompier par le chef de centre");
// } else {
// System.out.println("Maj du pompier connecté par lui-même");
// }
// }
pf.majBDD();
}
getServletContext().getRequestDispatcher("/WEB-INF/pompierJSP.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,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();
}
}

129
src/java/util/TrmtDate.java Normal file
View File

@ -0,0 +1,129 @@
package util;
/*
* Classe abstraite facilitant le traitement des dates
* Toutes les méthodes sont statiques, appel : TrmtDate.nomMéthode
*/
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
/**
*
* @author Dominique_2
*/
public abstract class TrmtDate {
static Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("Europe/Paris"));
/**
* Recherche de la date du début de la semaine courante
* @return date du lundi de la semaine, format Calendar
*/
public static Calendar getDateDebutSemaine() {
return getDateDebutSemaine(getDateDuJour());
}
/**
* Recherche de la date du début de semaine à partir de la date passée en paramètre
* @param c Calendar, date de recherche
* @return Calendar, début semaine à partir de c
*/
public static Calendar getDateDebutSemaine(Calendar c) {
Calendar leCal = getClone(c);
leCal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
//System.out.println("Date du lundi correspondant : " + nvCal.getTime());
return leCal;
}
/**
* Retourne la date passée en paramètre sous la forme : lun.05/10 par exemple
* @param d date à transformer
* @return chaine de car., forme lun.05/10 par exemple
*/
public static String getDateAAfficher(Calendar d) {
Locale locale = Locale.getDefault();
String dateAAfficher = d.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, locale);
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM");
String jrMois = sdf.format(d.getTime());
dateAAfficher += jrMois;
return dateAAfficher;
}
/**
* Retourne une date égale à la date passée en paramètre plus le nb jours indiqués
* @param dateInit date initiale, format Calendar
* @param days nb jours à ajouter
* @return dateInit + days, format Calendar
*/
public static Calendar addDays(Calendar dateInit, int days) {
Calendar leCal = getClone(dateInit);
leCal.setTime(dateInit.getTime());
leCal.add(Calendar.DAY_OF_MONTH, days);
return leCal;
}
/**
* Retourne une instance de Calendar correspondant à la date au format SQl
* passée en paramètre
* @param sqlDate : date au format java.sql.Date
* @return instance de Calendar
*/
public static Calendar getCalDate(java.sql.Date sqlDate) {
cal.setTime(new java.util.Date(sqlDate.getTime()));
return cal;
}
/**
* Retourne une date sql à partir d'une instance de Calendar
* @param unCal
* @return date sql
*/
public static java.sql.Date getSQLDate(Calendar unCal) {
return new java.sql.Date(unCal.getTimeInMillis());
}
/**
* Retourne une instance de Calendar correspondant à la date
* passée en paramètre
* @param utilDate : date au format java.util.Date
* @return instance de Calendar
*/
public static Calendar getCalDate(java.util.Date utilDate) {
cal.setTime(utilDate);
return cal;
}
/**
* Retourne la date du jour au format SQL
* @return Date au format sql
*/
public static java.sql.Date getSQLDateDuJour() {
return java.sql.Date.valueOf(java.time.LocalDate.now());
}
/**
* Retourne la date du jour au format Calendar
* @return Calendar
*/
public static Calendar getDateDuJour() {
Calendar nvCal = new GregorianCalendar(TimeZone.getTimeZone("Europe/Paris"));
nvCal.set(Calendar.HOUR_OF_DAY, 0);
nvCal.set(Calendar.MINUTE, 0);
nvCal.set(Calendar.SECOND, 0);
nvCal.set(Calendar.MILLISECOND, 0);
//System.out.println("Date du jour : " + nvCal.getTime());
return nvCal;
}
/**
* Permet d'obtenir une autre instance de Calendar identique à celle passée en paramètre
* @param c Calendar à cloner
* @return nouvelle instance de Calendar
*/
public static Calendar getClone(Calendar c) {
Calendar leCal = Calendar.getInstance();
leCal.setTime(c.getTime());
return leCal;
}
}

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

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

View File

@ -0,0 +1,41 @@
<%--
Document : authentifJSP
Created on : 23 oct. 2021, 10:02:18
Author : domin
--%>
<%@include file= "jspf/debutJSP.jspf" %>
<body>
<c:set var="page" value="1" scope="request" />
<%@include file= "jspf/header.jspf" %>
<div class="container">
<section id="contenuAffiche">
<fieldset id="authentif">
<legend>
Authentification
</legend>
<form id="fAuthentif" method="POST" action="authentification">
<div class="mb-3 mt-3">
<label for="ztLogin"> Login * </label>
<input type="text" placeholder="login" id="ztLogin"
autocomplete="username" name="ztLogin" class="form-control" required />
</div>
<div class="mb-3">
<label for="ztMDP"> Mot de passe * </label>
<input type="password" placeholder="mdp" id="ztMDP"
name="ztMDP" class="form-control" required />
</div>
<div class="text-center">
<button type="submit" value="Valider" class="btn btn-danger"><i class="bi bi-check2"></i> Valider</button>
</div>
</form>
${message}
</fieldset>
</section> <!-- /section id contenuAffiche -->
<%@include file= "jspf/footer.jspf" %>
</div> <!-- /div class container -->
<!-- Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</body>
</html>

View File

@ -0,0 +1,16 @@
<%-- jspf/debutJSP.jsp --%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.6.1/font/bootstrap-icons.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link href="css/mycss.css" rel="stylesheet" />
<link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico" />
<title>SDIS29</title>
</head>

View File

@ -0,0 +1,5 @@
<%-- jspf/footer.jspf --%>
<%@ page pageEncoding="UTF-8" %>
<footer>
<p>SDIS 29 - 58, avenue de Keradennec - 29337 QUIMPER CEDEX - 02 98 10 31 50</p>
</footer>

View File

@ -0,0 +1,30 @@
<%-- any content can be specified here e.g.: --%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page pageEncoding="UTF-8" %>
<form action="pompier" method="POST" id="fChoixPompier" name="fChoixPompier">
<div class="row">
<div class="col-md-9">
<label for="ldrPompier">Choix du pompier</label>
<select class="form-control" id="ldrPompier" name="ldrPompier">
<optgroup label="les pompiers volontaires" />
<c:forEach items="${sessionScope.lesPompiers}" var="unPompier" varStatus="status">
<c:set var="select" value="" scope="page" />
<c:if test="${lePompier.getId() eq unPompier.getId()}" var="testSelect" scope="page">
<c:set var="select" value="selected" scope="page" />
</c:if>
<option ${select} value="${status.index}">${unPompier.getLeGrade().getValeur()} ${unPompier.getNom()} ${unPompier.getPrenom()}</option>
</c:forEach>
</select>
</div>
<div class="col-md-3" id="btAfficherPompier" name="btAfficherPompier">
<!--<input class="btn btn-danger" name="btAfficherPompier" type="submit" value="Afficher" /> -->
<button class="btn btn-danger" name="btAfficherPompier" value="Afficher" type="submit"><i class="bi bi-eye-fill"></i> Afficher</button>
<button class="btn btn-danger ms-5" name="btAfficherPompier" value="Ajouter" type="submit"> <i class="bi bi-plus-lg"></i> Ajouter</button>
</div>
</div>
</form>

View File

@ -0,0 +1,144 @@
<%@ page pageEncoding="UTF-8" %>
<form action="pompier" method="POST" class="formPompier"> <!-- enctype="multipart/form-data" -->
<div class="row">
<aside class="col-md-3 text-center">
<img src="images/pompier.png" alt="portrait">
</aside>
<section class="col-md-8">
<div class="row">
<div class="col-md-6">
<label for="ztNom">Nom *</label>
<input type="text" class="form-control" id="ztNom" name="ztNom"
placeholder="Nom" value="${lePompier.getNom()}" required />
</div>
<div class="col-md-6">
<label for="ztPrenom">Prenom *</label>
<input type="text" class="form-control" id="ztPrenom" name="ztPrenom"
placeholder="Prénom" value="${lePompier.getPrenom()}" required />
</div>
</div><!-- fin ligne nom prenom -->
<div class="row mt-3">
<div class="col-md-6">
<label for="ztRue">Adresse *</label>
<input type="text" class="form-control" id="ztRue" name="ztAdresse"
placeholder="Adresse" value="${lePompier.getAdresse()}" required="" />
</div>
<div class="col-md-2">
<label for="ztCP">Code postal *</label>
<input type="text" class="form-control" id="ztCP" name="ztCP" pattern="^(([0-8][0-9])|(9[0-5])|(2[ab]))[0-9]{3}$"
placeholder="Code postal" value="${lePompier.getCp()}" required />
</div>
<div class="col-md-4">
<label for="zlVille">Ville *</label>
<!-- <input type="text" class="form-control" id="zlVille" name = "zlVille"
placeholder="Ville" value="${lePompier.getVille()}" required /> comment -->
<select class="form-select" aria-label="Default select example" id="zlVille" name = "zlVille" required>
<option value="${lePompier.getVille()}">${lePompier.getVille()}</option>
</select>
</div>
</div><!-- fin ligne adresse -->
<div class="row mt-3">
<div class="col-md-6">
<label for="ztMail">Adresse électronique *</label>
<input type="email" class="form-control" id="ztMail" name="ztMail"
placeholder="Email" value="${lePompier.getMail()}" required />
</div>
<div class="text-danger col-md-6" id="msgCP" ></div>
</div><!-- fin ligne mail -->
<div class="row mt-3">
<div class="col-md-6">
<label for="ztLogin">Login *</label>
<input type="text" class="form-control" id="ztLogin" name="ztLogin"
placeholder="Login" value="${lePompier.getLogin()}" required />
</div>
<div class="col-md-6">
<label for="ztMdp">Mot de passe *</label>
<input type="password" class="form-control" id="ztMdp" name="ztMdp" value="12345"
placeholder="Mot de passe" required />
</div>
</div><!-- fin ligne login mot de passe -->
<div class="row refPhoto mt-3">
<div class="col-md-12">
<label for="photo" class="custom-file">Changer la photo</label>
<input type="file" class="form-control" id="photo" name="photo" accept=".png, .jpg, .jpeg" />
</div>
</div> <!-- fin ligne photo -->
<div class="row mt-3">
<div class="col-md-2">
<c:set var="readO" value="" scope="page" />
<c:if test="${sessionScope.lePompierConnecte.getLeStatut().getCode() ne 2 ||
sessionScope.lePompierConnecte.getId() == lePompier.getId()}" var="testChef" scope="page">
<c:set var="readO" value="readonly" scope="page" />
</c:if>
<label for="ztBip">No bip *</label>
<input type="number" ${readO} class="form-control" id="ztBip"
name="ztBip" placeholder="No bip" value="${lePompier.getBip()}" required min="1" />
</div>
<div class="col-md-4">
<label for="ldrGrade">Grade *</label>
<select ${readO} class="form-control" id="ldrGrade" name="ldrGrade">
<c:forEach items="${sessionScope.lesGrades}" var="unGrade" >
<c:set var="select" value="" scope="page" />
<c:if test="${lePompier.getLeGrade().getCode() eq unGrade.getCode()}" var="testGrade" scope="page">
<c:set var="select" value="selected" scope="page" />
</c:if>
<option ${select} value="${unGrade.getCode()}">${unGrade.getValeur()}</option>;
</c:forEach>
</select>
</div>
<div class="col-md-3">
<label for="ldrStatut">Statut *</label>
<select ${readO} class="form-control" id="ldrStatut" name="ldrStatut">
<c:forEach items="${sessionScope.lesStatuts}" var="unStatut" >
<c:set var="select" value="" scope="page" />
<c:if test="${lePompier.getLeStatut().getCode() eq unStatut.getCode()}" var="testStatut" scope="page">
<c:set var="select" value="selected" scope="page" />
</c:if>
<option ${select} value="${unStatut.getCode()}">${unStatut.getValeur()}</option>;
</c:forEach>
</select>
</div>
<div class="col-md-3">
<label for="ldrType">Type personnel *</label>
<select ${readO} class="form-control" id="ldrType" name="ldrType">
<c:forEach items="${sessionScope.lesTypes}" var="unType" >
<c:set var="select" value="" scope="page" />
<c:if test="${lePompier.getLeType().getCode() eq unType.getCode()}" var="testStatut" scope="page">
<c:set var="select" value="selected" scope="page" />
</c:if>
<option ${select} value="${unType.getCode()}">${unType.getValeur()}</option>;
</c:forEach>
</select>
</div>
</div><!-- fin ligne bip grade statut type-->
<div class="row mt-3">
<div class="col-md-12">
<label for="ztObs">Observations</label>
<input type="text" class="form-control" id="ztObs" name="ztObs"
value="${lePompier.getCommentaire()}" />
</div><!-- fin ligne observation -->
</div> <!-- fin observation -->
<div class="danger mt-3">${message} </div>
<div class="text-center mt-3">
<button type="submit" name="btAfficherPompier" value="ValiderMaj" class="btn btn-danger">
<i class="bi bi-check2"></i> Valider
</button>
</div>
<p><em>* zone obligatoire</em></p>
</section>
</div> <!-- fin div contenant aside et section -->
</form>

View File

@ -0,0 +1,126 @@
<%-- jspf/header.jspf --%>
<%@ page pageEncoding="UTF-8" %>
<c:set var="blancs8" value=" " scope="page" />
<header>
<div class="container" id="entete">
<img id="logo" src="images/logo-sdis.png" alt='logo sdis29' />
<div id="identite">
<div id="login">
<c:choose>
<c:when test="${empty sessionScope.lePompierConnecte}">
<h4>Bienvenue</h4>
</c:when>
<c:otherwise>
<h4>Bienvenue ${sessionScope.lePompierConnecte.getPrenom()}
${sessionScope.lePompierConnecte.getNom()} (
${sessionScope.lePompierConnecte.getLeStatut().getValeur()})
</h4>
<button type="button" class="btn btn-warning fs-4" title="Déconnexion">
<a href="authentification">
<i class="bi bi-box-arrow-right heading" width="32" height="32" fill="currentColor"></i> Déconnexion
</a>
</button>
</c:otherwise>
</c:choose>
</div>
<h4>Service Départemental d'Incendie et de Secours du Finistère</h4>
<div id="caserne" title="Adresse caserne">
${sessionScope.lePompierConnecte.getLaCaserne().getNom()}
${sessionScope.lePompierConnecte.getLaCaserne().getAdresse()}<br />
${sessionScope.lePompierConnecte.getLaCaserne().getTel()}<br />
</div>
<nav class="navbar navbar-expand-sm bg-danger navbar-dark">
<div class="container-fluid">
<ul class="navbar-nav">
<li class="nav-item">
<span class="nav-link"><pre>${blancs8}</pre> </span>
</li>
<li class="nav-item">
<c:choose>
<c:when test="${page eq 1}">
<a class="nav-link active" href="authentification">Authentification</a>
</c:when>
<c:otherwise>
<a class="nav-link" href="authentification">Authentification</a>
</c:otherwise>
</c:choose>
</li>
<li class="nav-item">
<c:choose>
<c:when test="${page eq 2}">
<a class="nav-link active" href="pompier?pageDemandee=2">Mes Données</a>
</c:when>
<c:when test="${empty lePompierConnecte}">
<a class="nav-link disabled" href="#">Mes Données</a>
</c:when>
<c:otherwise>
<a class="nav-link" href="pompier?pageDemandee=2">Mes Données</a>
</c:otherwise>
</c:choose>
</li>
<li class="nav-item">
<c:choose>
<c:when test="${page eq 3}">
<a class="nav-link active" href="pompier?pageDemandee=3">Les Pompiers</a>
</c:when>
<c:when test="${sessionScope.lePompierConnecte.getLeStatut().getCode() eq 2}">
<a class="nav-link" href="pompier?pageDemandee=3">Les pompiers</a>
</c:when>
<c:otherwise>
</c:otherwise>
</c:choose>
</li>
<li class="nav-item">
<c:choose>
<c:when test="${page eq 4}">
<a class="nav-link active" href="#">Les Paramètres</a>
</c:when>
<c:when test="${sessionScope.lePompierConnecte.getLeStatut().getCode() eq 2}">
<a class="nav-link" href="#">Les paramètres</a>
</c:when>
<c:otherwise>
</c:otherwise>
</c:choose>
</li>
<li class="nav-item">
<c:choose>
<c:when test="${page eq 5}">
<a class="nav-link active" href="affectation?pageDemandee=5">Les Disponibilités</a>
</c:when>
<c:when test="${sessionScope.lePompierConnecte.getLeStatut().getCode() eq 2}">
<a class="nav-link" href="affectation?pageDemandee=5">Les Disponibilités</a>
</c:when>
<c:otherwise>
</c:otherwise>
</c:choose>
</li>
<li class="nav-item">
<c:choose>
<c:when test="${page eq 6}">
<a class="nav-link active" href="MesDisponibilites?pageDemandee=6">Mes Disponibilités</a>
</c:when>
<c:when test="${sessionScope.lePompierConnecte.getLeStatut().getCode() eq 1}">
<a class="nav-link" href="MesDisponibilites?pageDemandee=6">Mes Disponibilités</a>
</c:when>
<c:otherwise>
</c:otherwise>
</c:choose>
</li>
</ul>
</div>
</nav>
</div> <!-- fin id=identie -->
</div> <!-- fin class=container -->
</header>

View File

@ -0,0 +1,86 @@
<%--
Document : LesDispoJSP
Created on : 6 déc. 2021, 15:15:56
Author : thomas.millot
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file= "jspf/debutJSP.jspf" %>
<body>
<%@include file= "jspf/header.jspf" %>
<div class="container">
<section id="contenuAffiche" class="row">
<legend>
Les disponibilités
</legend>
<form action="affectation" method="POST">
<table class="table">
<thead>
<tr>
<th rowspan="2"> Id</th>
<th rowspan="2"> Nom prénom</th>
<c:forEach items="${sessionScope.lesDatesEnString}"
var= "uneDate" varStatus="status">
<th colspan="4" class= "text-center" >${uneDate}</th>
</c:forEach>
</tr>
<tr>
<c:forEach var="i" begin ="0" end="6" step="1">
<c:forEach items="${sessionScope.lesPeriodes}"
var= "unePeriode" varStatus="status">
<th class= "text-center" >${unePeriode}</th>
</c:forEach>
</c:forEach>
</tr>
</thead>
<tbody>
<c:set var="oldId" value="-1" scope="page"/>
<c:forEach items="${sessionScope.lesVentilInit}"
var="uneVentil" varStatus="status">
<c:set var="newId" value="${uneVentil.getPompier().getId()}" scope="page"/>
<c:if test="${oldId != newId}" var="test" scope="page">
<tr></tr>
<td>${uneVentil.getPompier().getId()}</td>
<td>${uneVentil.getPompier().getNom()}
${uneVentil.getPompier().getPrenom()}</td>
<c:set var="oldId" value="${newId}" scope="page"/>
</c:if>
<c:set var="activite" value="${uneVentil.getActivite()}" scope="page"/>
<td>
<input type ="text" value="${activite}" name="lesActivites" class="ztVentil ${sessionScope.lesCouleurs[activite]}"/>
</td>
</c:forEach>
</tbody>
</table>
<div class="text-center">
<button type="submit" value="Valider" class="btn btn-danger"><i class="bi bi-check2"></i> Valider</button>
</div>
</form>
<div id="legendCouleurs">
<span class="${sessionScope.lesCouleurs[0]}">Disponible</span>
<span class="${sessionScope.lesCouleurs[1]}">Au travail</span>
<span class="${sessionScope.lesCouleurs[2]}">Indisponible</span>
</div>
</section> <!-- /section id contenuAffiche -->
</div>
<script>
var lesCouleurs = ["vert", "orange", "rouge"];
var lesActivites = document.getElementsByClassName("ztVentil");
for (var uneActivite of lesActivites) {
uneActivite.onclick = function () {
var act = this.value;
var newAct = (act + 1) % 3;
var couleur = lesCouleurs[newAct];
this.classList.remove(lesCouleurs[act]);
this.classList.add(couleur);
this.value = newAct;
//alert("Click ok, Nouvelle Couleur : "+ act);
}
}
</script>
</body>

View File

@ -0,0 +1,86 @@
<%--
Document : LesDispoJSP
Created on : 6 déc. 2021, 15:15:56
Author : thomas.millot
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file= "jspf/debutJSP.jspf" %>
<body>
<%@include file= "jspf/header.jspf" %>
<div class="container">
<section id="contenuAffiche" class="row">
<legend>
Les disponibilités
</legend>
<form action="affectation" method="POST">
<table class="table">
<thead>
<tr>
<th rowspan="2"> Id</th>
<th rowspan="2"> Nom prénom</th>
<c:forEach items="${sessionScope.lesDatesEnString}"
var= "uneDate" varStatus="status">
<th colspan="4" class= "text-center" >${uneDate}</th>
</c:forEach>
</tr>
<tr>
<c:forEach var="i" begin ="0" end="6" step="1">
<c:forEach items="${sessionScope.lesPeriodes}"
var= "unePeriode" varStatus="status">
<th class= "text-center" >${unePeriode}</th>
</c:forEach>
</c:forEach>
</tr>
</thead>
<tbody>
<c:set var="oldId" value="-1" scope="page"/>
<c:forEach items="${sessionScope.lesVentilInit}"
var="uneVentil" varStatus="status">
<c:set var="newId" value="${uneVentil.getPompier().getId()}" scope="page"/>
<c:if test="${oldId != newId}" var="test" scope="page">
<tr></tr>
<td>${uneVentil.getPompier().getId()}</td>
<td>${uneVentil.getPompier().getNom()}
${uneVentil.getPompier().getPrenom()}</td>
<c:set var="oldId" value="${newId}" scope="page"/>
</c:if>
<c:set var="activite" value="${uneVentil.getActivite()}" scope="page"/>
<td>
<input type ="text" value="${activite}" name="lesActivites" class="ztVentil ${sessionScope.lesCouleurs[activite]}"/>
</td>
</c:forEach>
</tbody>
</table>
<div class="text-center">
<button type="submit" value="Valider" class="btn btn-danger"><i class="bi bi-check2"></i> Valider</button>
</div>
</form>
<div id="legendCouleurs">
<span class="${sessionScope.lesCouleurs[0]}">Disponible</span>
<span class="${sessionScope.lesCouleurs[1]}">Au travail</span>
<span class="${sessionScope.lesCouleurs[2]}">Indisponible</span>
</div>
</section> <!-- /section id contenuAffiche -->
</div>
<script>
var lesCouleurs = ["vert", "orange", "rouge"];
var lesActivites = document.getElementsByClassName("ztVentil");
for (var uneActivite of lesActivites) {
uneActivite.onclick = function () {
var act = this.value;
var newAct = (act + 1) % 3;
var couleur = lesCouleurs[newAct];
this.classList.remove(lesCouleurs[act]);
this.classList.add(couleur);
this.value = newAct;
//alert("Click ok, Nouvelle Couleur : "+ act);
}
}
</script>
</body>

View File

@ -0,0 +1,50 @@
<%--
pompierJSP.jsp
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file= "jspf/debutJSP.jspf" %>
<body>
<%@include file= "jspf/header.jspf" %>
<div class="container">
<section id="contenuAffiche" class="row">
<c:set var="legend" value="Mes données" scope="page" />
<c:if test="${sessionScope.lePompierConnecte.getLeStatut().getCode() eq 2}" var="testChef" scope="page">
<c:if test="${sessionScope.lePompierConnecte.getId() ne lePompier.getId()}" var="testAffich" scope="page">
<c:set var="legend" scope="page">
Données du pompier ${lePompier.getNom()} ${lePompier.getPrenom()}
</c:set>
<c:if test="${sessionScope.lePompier==null}" var="testCreation" scope="page">
<c:set var="legend" scope="page">
Données du pompier à créer
</c:set>
</c:if>
<fieldset class="row mb-10 text-center">
<%@include file= "jspf/formChoixPompier.jspf" %>
</fieldset>
</c:if>
</c:if>
<fieldset class="row mt-1 mb-10">
<legend>
${legend}
</legend>
<%@include file= "jspf/formulairePompier.jspf" %>
</fieldset>
</section>
<%@include file= "jspf/footer.jspf" %>
</div> <!-- /div class container -->
<!-- Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<!-- Code postaux -->
<script src="js/ctrlCodePostal.js"></script>
</body>
</html>

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

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<servlet>
<servlet-name>AuthentifServlet</servlet-name>
<servlet-class>servlet.AuthentifServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>ModifServlet</servlet-name>
<servlet-class>servlet.ModifServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>ProfilServlet</servlet-name>
<servlet-class>servlet.ProfilServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>LesDispoServlet</servlet-name>
<servlet-class>servlet.LesDispoServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>MesDispoServlet</servlet-name>
<servlet-class>servlet.MesDispoServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>VentilServlet</servlet-name>
<servlet-class>servlet.VentilServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>PompierServlet</servlet-name>
<servlet-class>servlet.PompierServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AuthentifServlet</servlet-name>
<url-pattern>/authentification</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ModifServlet</servlet-name>
<url-pattern>/Modif</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>LesDispoServlet</servlet-name>
<url-pattern>/affectation</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>MesDispoServlet</servlet-name>
<url-pattern>/MesDisponibilites</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>PompierServlet</servlet-name>
<url-pattern>/pompier</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>

119
web/css/mycss.css Normal file
View File

@ -0,0 +1,119 @@
/*
css/mycss.css
*/
body {
background-color: #ECECEC;
}
#contenuAffiche {
display: flex;
justify-content:center;
padding-top: 10px;
padding-bottom: 10px;
background-color: #ffffff;
border-radius: 5px;
}
#authentif {
width : 50%;
}
fieldset {
border-radius: 5px;
padding: 5px;
border: 1px solid #DB0005;
width: 100%;
}
legend {
margin-bottom:0px;
padding-bottom: 0px;
}
footer {
margin-top: 10px;
background-color: #EDEDED;
text-align: center;
font-size: smaller;
padding: 10px;
/*border-bottom: 3px solid #DB0005; */
}
header {
background-color: #333333;
color: #EDEDED;
padding: 10px;
}
#entete {
display: flex;
/* align-items: center; */
align-items: flex-end ;
}
li {
text-align: center;
}
li:not(:first-child) {
border-left: 2px solid #EDEDED;
}
#identite {
width : 100%;
}
.navbar {
padding: 0 0 0 0;
border-radius: 5px;
margin-left: -8%;
}
#logo {
z-index:1; /* arriere plan */
}
#login {
background-color: #EDEDED;
color: #333333;
display: flex;
justify-content:space-around;
align-items: center;
margin-left: -8%;
}
button a {
text-decoration:none;
color: #333333;
}
aside, #btAfficherPompier {
justify-content: center;
display: flex;
align-items: center;
}
select[readonly] {
pointer-events: none;
}
#legendCouleurs span{
color: black;
}
.vert {
background-color: green;
color: green;
border-color : green;
}
.rouge {
background-color: red;
color: red;
border-color: red;
}
.orange {
background-color: orange;
color: orange;
border-color: orange;
}
.ztVentil {
width : 20px;
height: 20px;
border: 3px solid;
}
.ztVentil:hover {
border-color: grey;
}

BIN
web/images/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
web/images/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>

28
web/js/ctrlCodePostal.js Normal file
View File

@ -0,0 +1,28 @@
// Recherche de la ou des villes correspondantes au code postal saisi (exemple 54490 --> 7 villes)
ztCP.onchange = function () {
//alert("ztCP a changé");
msgCP.textContent = "";
zlVille.length = 0;
const XHTTP = new XMLHttpRequest();
XHTTP.onload = function () {
if (this.status != 200) {
msgCP.textContent = "Code postal erroné";
} else {
var lesVilles = JSON.parse(this.responseText);
var info = "";
if (lesVilles.length > 1) {
info += "<optgroup label='Les villes du code postal' />";
}
for (var i = 0; i < lesVilles.length; i++) {
var uneVille = lesVilles[i];
info += "<option value='" + uneVille.libelleAcheminement + "'>";
info += uneVille.libelleAcheminement + '</option>';
}
zlVille.innerHTML = info;
}
}
var cp = ztCP.value;
XHTTP.open("GET", "https://apicarto.ign.fr/api/codes-postaux/communes/" + cp);
XHTTP.send();
}