<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%-- Travail pratique 3, IFT1149 (Technologie JSP) --%>
<%-- (C) 2008 - 2009 Oldrin Bărbulescu --%>
<%@ page pageEncoding = "UTF-8" %>
<%@ page contentType = "text/html; charset = UTF-8" %>
<%@ page errorPage = "error.jsp" %>
<%@ include file="WEB-INF/jspf/initBeans.jspf" %>
<%@ page import = "java.sql.SQLException" %>
<jsp:setProperty name = "db" property = "driver" value = "<%= application.getInitParameter(\"jdbc.driver\") %>" />
<jsp:setProperty name = "db" property = "url" value = "<%= application.getInitParameter(\"jdbc.url\") %>" />
<jsp:setProperty name = "db" property = "username" value = "<%= application.getInitParameter(\"jdbc.username\") %>" />
<jsp:setProperty name = "db" property = "password" value = "<%= application.getInitParameter(\"jdbc.password\") %>" />
<%-- On efface les erreurs de la page "login.jsp",
si on sorte en appuyant le bouton "RECHERCHE". --%>
<% form.clearErrors(); %>
<% String id = request.getParameter("item");
String film = request.getParameter("film");
String error = "";
// Si on n'utilise pas le bouton "Ajouter au panier".
if (id == null) {
if (film != null)
dbfilms.setSearchField (film);
else dbfilms.setSearchField ("");
try {
dbfilms.setConnection(db.getConnection());
dbfilms.setTitleQuery(film);
dbfilms.closeConnection();
} catch (SQLException e){
error = "Desolé, une erreur s´est produite"
+ " lors de l´exécution de cette page.";
}
}
// Si un des boutons "Ajouter au panier" a été appuyé,
// on ajoute le film qui corresponde avec le bouton dans le panier.
else {
dbfilms.setIndex(id);
String title = dbfilms.getTitle();
Double price = dbfilms.getPrice();
if (cart.isItemAlreadyInCart(id))
cart.addItem(id);
else
cart.addNewItem(id,title,price);
}
%>
<html xmlns = "http://www.w3.org/1999/xhtml">
<%@ include file="WEB-INF/jspf/header.jspf" %>
<body>
<table class = "page">
<tr>
<td colspan ="3"><h1><%=dbfilms.getPageTitle()%></h1></td>
</tr>
<%-- Rechercher des films. --%>
<tr>
<td colspan ="3" class ="center">
<form action = "index.jsp" method = "post" id ="recherche">
<p>Recherche du film: </p>
<p><input type = "text" name = "film" size = "25" class ="blue"
value ="<%=dbfilms.getSearchField()%>" /> </p>
<p><input type = "submit" value = "Soumettre" /></p>
</form>
<p>Tapez un nom de film ou laisser ce champ vide pour voir tout les films.</p>
</td>
</tr>
<%-- Afficher les films. --%>
<tr>
<td colspan ="3" class="center">
<% dbfilms.first();
if (!error.equals("")) { %>
<p class ="red"><br/><br/><%=error%></p>
<%} else if (dbfilms.next()){%>
<div id ="films">
<table>
<tr>
<td class = "title"><b>Titre</b></td>
<td><b>Type</b></td>
<td class = "currency"><b>Prix</b></td>
<td> </td>
</tr>
<% dbfilms.first();
while (dbfilms.next()){ %>
<tr>
<td class = "title"><%= dbfilms.getTitle()%></td>
<td><%= dbfilms.getType()%></td>
<td class = "currency"><%= dbfilms.getPrice()%></td>
<td>
<form action = "index.jsp" method = "post">
<p><input type = "hidden" name = "item"
value = "<%= dbfilms.getId()%>" /></p>
<p><input type = "image" src = "images/movie_store/addtocart.gif" alt="Ajouter au panier"/></p>
</form>
</td>
</tr>
<%}%>
</table>
</div>
<%} else if (!dbfilms.getSearchField().equals("")) {%>
<p class ="red"><br /><br />Aucun résultat ne corresponde à votre recherche.</p>
<%}%>
<br /><br />
</td>
</tr>
<tr>
<%-- Afficher le panier. --%>
<td class ="panier_left">
<img src = "images/movie_store/panier.gif" alt = "Votre panier: " width ="146" height ="23"/>
</td>
<td>
<table id = "panier">
<tr>
<td><b>Nobre d´items</b></td>
<td><b>Total d´achats</b></td>
</tr>
<tr>
<td><%= cart.getTotalItems() %></td>
<td><%= cart.getTotalPrice() %></td>
</tr>
</table>
</td>
<%-- Afficher les bouttons. --%>
<td id = "buttons">
<% if (cart.getCartSize() > 0){ %>
<ul>
<li><a href="purchaseCart.jsp">VOIR PANIER</a></li>
<li><a href="order.jsp">COMMANDER</a></li>
</ul>
<%}%>
</td>
</tr>
</table>
<%@include file="WEB-INF/jspf/footer.jspf" %>
</body>
</html>