package util;
import java.util.ArrayList;
import dao.Dao;
import modele.Ressource;
import modele.RessourceUser;
import modele.Role;
import modele.User;
public class UsageForm {
public static String roleForm() {
String body = "";
String head = "";
String foot = "";
head = "<form id='roleList'><table><caption class='titre'>Roles disponibles</caption><thead><TR align='center'><TH>Description</TH><TH>Action</TH></TR></thead><tbody>";
ArrayList<Role> roles = Dao.allRoles();
Role r = null;
if (roles.size() > 0) {
for (int i = 0; i < roles.size(); i++) {
r = roles.get(i);
body = body
+ "<tr><td>"
+ r.getRoleDescription()
+ "</td><td><input type='button'value='Supprimer' class='slick-black' id=roleDel"
+ i + " onclick = 'deleteRole(" + r.getRoleId()
+ ")'></td></tr>";
foot = "</tbody></table></form>";
}
}
return head + body + foot;
}
public static String userForm() {
String body = "";
String head = "";
String foot = "";
ArrayList<User> users = Dao.allUsers();
User us = null;
head = "<fieldset>"
+ "<form id='userList'>"
+ "<p><p>"
+ "<article>"
+ "<TABLE>"
+ "<thead> <TR align='center'><TH>Description</TH><TH>Courriel</TH><TH>Role</TH><TH>Statut</TH></TR></thead>"
+ "<tbody>";
if (users.size() > 0) {
for (int i = 0; i < users.size(); i++) {
us = users.get(i);
body = body
+ "<tr><td>"
+ us.getUserDescription()
+ "<td>"
+ us.getUserCode()
+ "<input type='hidden' id='uc"
+ i
+ "' value='"
+ us.getUserCode()
+ "'></td><td>"
+ us.getRole().getRoleDescription()
+ "</td><td>"
+ us.activeToString()
+ "</td><td><input type='button' value='Supprimer' class='slick-black' id=userDelete"
+ i + " onclick = 'deleteUser(" + i + ")'></td></tr>";
}
}
foot = "</tbody></TABLE></form><p></fieldset>";
return head + body + foot;
}
public static String ressourceForm() {
String body = "";
String head = "";
String foot = "";
head = "<form id='ressourceList'><table><caption class='titre'>Resssources disponibles</caption><thead><TR align='center'>"
+ "<TH>Description</TH><TH>Page</TH><TH>Action</TH></TR></thead><tbody>";
ArrayList<Ressource> ressources = Dao.allRessources();
Ressource rs = null;
if (ressources.size() > 0) {
for (int i = 0; i < ressources.size(); i++) {
rs = ressources.get(i);
body = body
+ "<tr><td>"
+ rs.getRessourceDescription()
+ "</td><td>"
+ rs.getRessourcePage()
+ "<td><input type='button'value='Supprimer' class='slick-black' id=ressourceDelete"
+ i + " onclick = 'deleteRessource("
+ rs.getRessourceId() + ")'></td></tr>";
}
}
foot = "</tbody></table></form>";
return head + body + foot;
}
public static String ruForm() {
String body = "";
String head = "";
String foot = "";
head = "<form id='ressourceuserList'><table><caption class='titre'>Ressources par utilisateur</caption><thead><TR align='center'><TH>Ressource</TH><TH>Utilisateur</TH><TH>Action</TH></TR></thead><tbody>";
ArrayList<RessourceUser> rusers = Dao.allRessourceUser();
RessourceUser ru = null;
if (rusers.size() > 0) {
for (int i = 0; i < rusers.size(); i++) {
ru = rusers.get(i);
body = body
+ "<tr><td>"
+ Dao.getRessource(ru.getRessourceId())
.getRessourceDescription()
+ "<input type='hidden' id=ucru"
+ i
+ " value="
+ ru.getUserCode()
+ ">"
+ "<input type='hidden' id=rru"
+ i
+ " value="
+ ru.getRessourceId()
+ ">"
+ "</td><td>"
+ Dao.getUser(ru.getUserCode()).getUserDescription()
+ "<td><input type='button'value='Supprimer' class='slick-black' id=ressourceuserDel"
+ i + " onclick = 'deleteRessourceuser(" + i
+ ")'></td></tr>";
}
}
foot = "</tbody></table></form>";
return head + body + foot;
}
public static String activForm() {
String body = "";
String head = "";
String foot = "";
head = "<form id='fact'><table><fieldset class='titre'>Liste des utilisateurs bloqu�s</fieldset><thead><th>Utilisateur</th><th>Etat</th></thead><tbody>";
ArrayList<User> lusers = Dao.lockedUsers();
User lu = null;
if (lusers.size() > 0) {
for (int i = 0; i < lusers.size(); i++) {
lu = lusers.get(i);
body = body
+ "<tr><td>"
+ lu.getUserDescription()
+ "<input type='hidden' value="
+ lu.getUserCode()
+ " id='ba"
+ i
+ "'>"
+ "</td><td>"
+ lu.activeToString()
+ "<td><input type='button'value='Débloquer' id=userUnlock"
+ i + " onclick = 'unlock(" + i + ")'></td></tr>";
}
}
foot = "</tbody></table></form>";
return head + body + foot;
}
}