<%@page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*"%> <%@ include file="Connections/library.jsp" %> <% // *** Edit Operations: declare variables // set the form action variable String MM_editAction = request.getRequestURI(); if (request.getQueryString() != null && request.getQueryString().length() > 0) { MM_editAction += "?" + request.getQueryString(); } // connection information String MM_editDriver = null, MM_editConnection = null, MM_editUserName = null, MM_editPassword = null; // redirect information String MM_editRedirectUrl = null; // query string to execute StringBuffer MM_editQuery = null; // boolean to abort record edit boolean MM_abortEdit = false; // table information String MM_editTable = null, MM_editColumn = null, MM_recordId = null; // form field information String[] MM_fields = null, MM_columns = null; %> <% // *** Insert Record: set variables if (request.getParameter("MM_insert") != null) { session.setAttribute("emprunt_id",request.getParameter("emprunt_id")); MM_editDriver = MM_library_DRIVER; MM_editConnection = MM_library_STRING; MM_editUserName = MM_library_USERNAME; MM_editPassword = MM_library_PASSWORD; MM_editTable = "emprunt"; MM_editRedirectUrl = "valid_emprunt.jsp"; String MM_fieldsStr = "emprunt_id|value|datesortie|value|dateretour|value|individu_id|value"; String MM_columnsStr = "emprunt_id|none,none,NULL|datesortie|',none,NULL|dateretour|',none,NULL|emprunteur_id|none,none,NULL"; // create the MM_fields and MM_columns arrays java.util.StringTokenizer tokens = new java.util.StringTokenizer(MM_fieldsStr,"|"); MM_fields = new String[tokens.countTokens()]; for (int i=0; tokens.hasMoreTokens(); i++) MM_fields[i] = tokens.nextToken(); tokens = new java.util.StringTokenizer(MM_columnsStr,"|"); MM_columns = new String[tokens.countTokens()]; for (int i=0; tokens.hasMoreTokens(); i++) MM_columns[i] = tokens.nextToken(); // set the form values for (int i=0; i+1 < MM_fields.length; i+=2) { MM_fields[i+1] = ((request.getParameter(MM_fields[i])!=null)?(String)request.getParameter(MM_fields[i]):""); } // append the query string to the redirect URL if (MM_editRedirectUrl.length() != 0 && request.getQueryString() != null) { MM_editRedirectUrl += ((MM_editRedirectUrl.indexOf('?') == -1)?"?":"&") + request.getQueryString(); } } %> <% // *** Insert Record: construct a sql insert statement and execute it if (request.getParameter("MM_insert") != null) { // create the insert sql statement StringBuffer MM_tableValues = new StringBuffer(), MM_dbValues = new StringBuffer(); for (int i=0; i+1 < MM_fields.length; i+=2) { String formVal = MM_fields[i+1]; String elem; java.util.StringTokenizer tokens = new java.util.StringTokenizer(MM_columns[i+1],","); String delim = ((elem = (String)tokens.nextToken()) != null && elem.compareTo("none")!=0)?elem:""; String altVal = ((elem = (String)tokens.nextToken()) != null && elem.compareTo("none")!=0)?elem:""; String emptyVal = ((elem = (String)tokens.nextToken()) != null && elem.compareTo("none")!=0)?elem:""; if (formVal.length() == 0) { formVal = emptyVal; } else { if (altVal.length() != 0) { formVal = altVal; } else if (delim.compareTo("'") == 0) { // escape quotes StringBuffer escQuotes = new StringBuffer(formVal); for (int j=0; j < escQuotes.length(); j++) if (escQuotes.charAt(j) == '\'') escQuotes.insert(j++,'\''); formVal = "'" + escQuotes + "'"; } else { formVal = delim + formVal + delim; } } MM_tableValues.append((i!=0)?",":"").append(MM_columns[i]); MM_dbValues.append((i!=0)?",":"").append(formVal); } MM_editQuery = new StringBuffer("insert into " + MM_editTable); MM_editQuery.append(" (").append(MM_tableValues.toString()).append(") values ("); MM_editQuery.append(MM_dbValues.toString()).append(")"); if (!MM_abortEdit) { // finish the sql and execute it Driver MM_driver = (Driver)Class.forName(MM_editDriver).newInstance(); Connection MM_connection = DriverManager.getConnection(MM_editConnection,MM_editUserName,MM_editPassword); PreparedStatement MM_editStatement = MM_connection.prepareStatement(MM_editQuery.toString()); MM_editStatement.executeUpdate(); MM_connection.close(); // redirect with URL parameters if (MM_editRedirectUrl.length() != 0) { response.sendRedirect(response.encodeRedirectURL(MM_editRedirectUrl)); } } } %> <% String emprunteur__varInd = "1"; if (request.getParameter("individu_id") !=null) {emprunteur__varInd = (String)request.getParameter("individu_id");} %> <% Driver Driveremprunteur = (Driver)Class.forName(MM_library_DRIVER).newInstance(); Connection Connemprunteur = DriverManager.getConnection(MM_library_STRING,MM_library_USERNAME,MM_library_PASSWORD); PreparedStatement Statementemprunteur = Connemprunteur.prepareStatement("SELECT emprunteur_id, nom, prenom, tel, email FROM emprunteur WHERE emprunteur_id = '" + emprunteur__varInd + "'"); ResultSet emprunteur = Statementemprunteur.executeQuery(); boolean emprunteur_isEmpty = !emprunteur.next(); boolean emprunteur_hasData = !emprunteur_isEmpty; Object emprunteur_data; int emprunteur_numRows = 0; %> <% Driver Driverdate_today = (Driver)Class.forName(MM_library_DRIVER).newInstance(); Connection Conndate_today = DriverManager.getConnection(MM_library_STRING,MM_library_USERNAME,MM_library_PASSWORD); PreparedStatement Statementdate_today = Conndate_today.prepareStatement("SELECT to_char(current_date, 'DD-MM-YYYY') "); ResultSet date_today = Statementdate_today.executeQuery(); boolean date_today_isEmpty = !date_today.next(); boolean date_today_hasData = !date_today_isEmpty; Object date_today_data; int date_today_numRows = 0; %> <% Driver Driverdate_retour = (Driver)Class.forName(MM_library_DRIVER).newInstance(); Connection Conndate_retour = DriverManager.getConnection(MM_library_STRING,MM_library_USERNAME,MM_library_PASSWORD); PreparedStatement Statementdate_retour = Conndate_retour.prepareStatement("SELECT to_char(current_date + interval '21 days','DD-MM-YYYY') "); ResultSet date_retour = Statementdate_retour.executeQuery(); boolean date_retour_isEmpty = !date_retour.next(); boolean date_retour_hasData = !date_retour_isEmpty; Object date_retour_data; int date_retour_numRows = 0; %> <% Driver Drivernumero = (Driver)Class.forName(MM_library_DRIVER).newInstance(); Connection Connnumero = DriverManager.getConnection(MM_library_STRING,MM_library_USERNAME,MM_library_PASSWORD); PreparedStatement Statementnumero = Connnumero.prepareStatement("SELECT nextval('emprunt_serial') "); ResultSet numero = Statementnumero.executeQuery(); boolean numero_isEmpty = !numero.next(); boolean numero_hasData = !numero_isEmpty; Object numero_data; int numero_numRows = 0; %> <% Driver Drivertoday = (Driver)Class.forName(MM_library_DRIVER).newInstance(); Connection Conntoday = DriverManager.getConnection(MM_library_STRING,MM_library_USERNAME,MM_library_PASSWORD); PreparedStatement Statementtoday = Conntoday.prepareStatement("SELECT current_date "); ResultSet today = Statementtoday.executeQuery(); boolean today_isEmpty = !today.next(); boolean today_hasData = !today_isEmpty; Object today_data; int today_numRows = 0; %> <% Driver Driverretour = (Driver)Class.forName(MM_library_DRIVER).newInstance(); Connection Connretour = DriverManager.getConnection(MM_library_STRING,MM_library_USERNAME,MM_library_PASSWORD); PreparedStatement Statementretour = Connretour.prepareStatement("SELECT (current_date + interval '21 days') AS retour "); ResultSet retour = Statementretour.executeQuery(); boolean retour_isEmpty = !retour.next(); boolean retour_hasData = !retour_isEmpty; Object retour_data; int retour_numRows = 0; %> <% String MM_paramName = ""; %> <% // *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters String MM_keepBoth,MM_keepURL="",MM_keepForm="",MM_keepNone=""; String[] MM_removeList = { "index", MM_paramName }; // create the MM_keepURL string if (request.getQueryString() != null) { MM_keepURL = '&' + request.getQueryString(); for (int i=0; i < MM_removeList.length && MM_removeList[i].length() != 0; i++) { int start = MM_keepURL.indexOf(MM_removeList[i]) - 1; if (start >= 0 && MM_keepURL.charAt(start) == '&' && MM_keepURL.charAt(start + MM_removeList[i].length() + 1) == '=') { int stop = MM_keepURL.indexOf('&', start + 1); if (stop == -1) stop = MM_keepURL.length(); MM_keepURL = MM_keepURL.substring(0,start) + MM_keepURL.substring(stop); } } } // add the Form variables to the MM_keepForm string if (request.getParameterNames().hasMoreElements()) { java.util.Enumeration items = request.getParameterNames(); while (items.hasMoreElements()) { String nextItem = (String)items.nextElement(); boolean found = false; for (int i=0; !found && i < MM_removeList.length; i++) { if (MM_removeList[i].equals(nextItem)) found = true; } if (!found && MM_keepURL.indexOf('&' + nextItem + '=') == -1) { MM_keepForm = MM_keepForm + '&' + nextItem + '=' + java.net.URLEncoder.encode(request.getParameter(nextItem)); } } } // create the Form + URL string and remove the intial '&' from each of the strings MM_keepBoth = MM_keepURL + MM_keepForm; if (MM_keepBoth.length() > 0) MM_keepBoth = MM_keepBoth.substring(1); if (MM_keepURL.length() > 0) MM_keepURL = MM_keepURL.substring(1); if (MM_keepForm.length() > 0) MM_keepForm = MM_keepForm.substring(1); %> Emprunteur

Emrunt : ">
Date emprunt : "> ">
Date retour : "> ">
No d'emprunteur :
 
 
<% emprunteur.close(); Connemprunteur.close(); %> <% date_today.close(); Conndate_today.close(); %> <% date_retour.close(); Conndate_retour.close(); %> <% numero.close(); Connnumero.close(); %> <% today.close(); Statementtoday.close(); Conntoday.close(); %> <% retour.close(); Statementretour.close(); Connretour.close(); %>