%@page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*"%> <%@ include file="Connections/library.jsp" %> <%--Copyright (C) 2002 Tony Grant This file is part of lmstoolkit lmstoolkit is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. lmstoolkit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with lmstoolkit; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA--%> <% // *** 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; %> <% // *** Update Record: set variables if (request.getParameter("MM_update") != null && request.getParameter("MM_recordId") != null) { MM_editDriver = MM_library_DRIVER; MM_editConnection = MM_library_STRING; MM_editUserName = MM_library_USERNAME; MM_editPassword = MM_library_PASSWORD; MM_editTable = "books"; MM_editColumn = "book_id"; MM_recordId = "" + request.getParameter("MM_recordId") + ""; MM_editRedirectUrl = "docindex.jsp"; String MM_fieldsStr = "noinventaire|value|namebreexemplaires|value|noisbn|value|typedocument|value|titre|value|titreexposition|value|lieupublication|value|datepublication|value|nbpages|value|nbpagesillustr|value|nbpagesnb|value|nbpagescoul|value|pagesfrac|value|modeacquisition|value|thematique|value|resume|value|date_modification_fiche|value||value"; String MM_columnsStr = "noinventaire|',none,''|namebreexemplaires|none,none,NULL|noisbn|',none,''|typedocument|',none,''|titre|',none,''|titreexposition|',none,''|lieupublication|',none,''|datepublication|none,none,NULL|nbpages|none,none,NULL|nbpagesillustr|none,none,NULL|nbpagesnb|none,none,NULL|nbpagescoul|none,none,NULL|pagesfrac|',none,''|modeacquisition|',none,''|thematique|',none,''|resume|',none,''|date_modification_fiche|',none,''||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(); } } %> <% // *** Update Record: construct a sql update statement and execute it if (request.getParameter("MM_update") != null && request.getParameter("MM_recordId") != null) { // create the update sql statement MM_editQuery = new StringBuffer("update ").append(MM_editTable).append(" set "); 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_editQuery.append((i!=0)?",":"").append(MM_columns[i]).append(" = ").append(formVal); } MM_editQuery.append(" where ").append(MM_editColumn).append(" = ").append(MM_recordId); 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)); } } } %> <% Driver Driverbooks = (Driver)Class.forName(MM_library_DRIVER).newInstance(); Connection Connbooks = DriverManager.getConnection(MM_library_STRING,MM_library_USERNAME,MM_library_PASSWORD); PreparedStatement Statementbooks = Connbooks.prepareStatement("SELECT * FROM books"); ResultSet books = Statementbooks.executeQuery(); boolean books_isEmpty = !books.next(); boolean books_hasData = !books_isEmpty; Object books_data; int books_numRows = 0; %> <% String editor__varDoc = "1"; if (request.getParameter("book_id") !=null) {editor__varDoc = (String)request.getParameter("book_id");} %> <% Driver Drivereditor = (Driver)Class.forName(MM_library_DRIVER).newInstance(); Connection Conneditor = DriverManager.getConnection(MM_library_STRING,MM_library_USERNAME,MM_library_PASSWORD); PreparedStatement Statementeditor = Conneditor.prepareStatement("SELECT name_editor, editor.editor_id, books.book_id, a_publie.book_id FROM editor, a_publie, books WHERE a_publie.editor_id = editor.editor_id AND a_publie.book_id = books.book_id AND books.book_id = '" + editor__varDoc + "'"); ResultSet editor = Statementeditor.executeQuery(); boolean editor_isEmpty = !editor.next(); boolean editor_hasData = !editor_isEmpty; Object editor_data; int editor_numRows = 0; %> <% String artist__varDoc = "1"; if (request.getParameter("book_id") !=null) {artist__varDoc = (String)request.getParameter("book_id");} %> <% Driver Driverartist = (Driver)Class.forName(MM_library_DRIVER).newInstance(); Connection Connartist = DriverManager.getConnection(MM_library_STRING,MM_library_USERNAME,MM_library_PASSWORD); PreparedStatement Statementartist = Connartist.prepareStatement("SELECT artist.artist_id, name, first_name, refers_to.artist_id, refers_to.book_id, books.book_id FROM artist, refers_to, books WHERE books.book_id = refers_to.book_id and refers_to.artist_id = artist.artist_id AND books.book_id = '" + artist__varDoc + "' ORDER BY name"); ResultSet artist = Statementartist.executeQuery(); boolean artist_isEmpty = !artist.next(); boolean artist_hasData = !artist_isEmpty; Object artist_data; int artist_numRows = 0; %> <% String auteur__varDoc = "1"; if (request.getParameter("book_id") !=null) {auteur__varDoc = (String)request.getParameter("book_id") ;} %> <% Driver Driverauteur = (Driver)Class.forName(MM_library_DRIVER).newInstance(); Connection Connauteur = DriverManager.getConnection(MM_library_STRING,MM_library_USERNAME,MM_library_PASSWORD); PreparedStatement Statementauteur = Connauteur.prepareStatement("SELECT name, first_name, auteur.auteur_id, auteur_de.book_id, books.book_id FROM auteur, auteur_de, books WHERE books.book_id = auteur_de.book_id and auteur_de.auteur_id = auteur.auteur_id and books.book_id = ('" + auteur__varDoc + "') ORDER BY name"); ResultSet auteur = Statementauteur.executeQuery(); boolean auteur_isEmpty = !auteur.next(); boolean auteur_hasData = !auteur_isEmpty; Object auteur_data; int auteur_numRows = 0; %> <% int Repeat1__numRows = -1; int Repeat1__index = 0; artist_numRows += Repeat1__numRows; %> <% int Repeat2__numRows = -1; int Repeat2__index = 0; auteur_numRows += Repeat2__numRows; %> <% // *** Recordset Stats, Move To Record, and Go To Record: declare stats variables int books_first = 1; int books_last = 1; int books_total = -1; if (books_isEmpty) { books_total = books_first = books_last = 0; } //set the number of rows displayed on this page if (books_numRows == 0) { books_numRows = 1; } %> <% String MM_paramName = ""; %> <% // *** Move To Record and Go To Record: declare variables ResultSet MM_rs = books; int MM_rsCount = books_total; int MM_size = books_numRows; String MM_uniqueCol = "book_id"; MM_paramName = "book_id"; int MM_offset = 0; boolean MM_atTotal = false; boolean MM_paramIsDefined = (MM_paramName.length() != 0 && request.getParameter(MM_paramName) != null); %> <% // *** Move To Specific Record: handle detail parameter if (MM_paramIsDefined && MM_rsCount != 0) { // get the value of the parameter String param = request.getParameter(MM_paramName); // find the record with the unique column value equal to the parameter value String colVal; while (books_hasData) { colVal = ((MM_rs.getObject(MM_uniqueCol)!=null)?MM_rs.getObject(MM_uniqueCol).toString():""); if (colVal.equals(param)) break; books_hasData = MM_rs.next(); MM_offset++; } // if not found, set the number of records and reset the cursor if (!books_hasData) { if (MM_rsCount < 0) MM_rsCount = MM_offset; if (MM_size < 0 || MM_size > MM_rsCount) MM_size = MM_rsCount; MM_offset = 0; // reset the cursor to the beginning books.close(); books = Statementbooks.executeQuery(); books_hasData = books.next(); MM_rs = books; } } %> <% // *** Move To Record: if we dont know the record count, check the display range if (MM_rsCount == -1) { // walk to the end of the display range for this page int i; for (i=MM_offset; books_hasData && (MM_size < 0 || i < MM_offset + MM_size); i++) { books_hasData = MM_rs.next(); } // if we walked off the end of the recordset, set MM_rsCount and MM_size if (!books_hasData) { MM_rsCount = i; if (MM_size < 0 || MM_size > MM_rsCount) MM_size = MM_rsCount; } // if we walked off the end, set the offset based on page size if (!books_hasData && !MM_paramIsDefined) { if (MM_offset > MM_rsCount - MM_size || MM_offset == -1) { //check if past end or last if (MM_rsCount % MM_size != 0) //last page has less records than MM_size MM_offset = MM_rsCount - MM_rsCount % MM_size; else MM_offset = MM_rsCount - MM_size; } } // reset the cursor to the beginning books.close(); books = Statementbooks.executeQuery(); books_hasData = books.next(); MM_rs = books; // move the cursor to the selected record for (i=0; books_hasData && i < MM_offset; i++) { books_hasData = MM_rs.next(); } } %> <% // *** Move To Record: update recordset stats // set the first and last displayed record books_first = MM_offset + 1; books_last = MM_offset + MM_size; if (MM_rsCount != -1) { books_first = Math.min(books_first, MM_rsCount); books_last = Math.min(books_last, MM_rsCount); } // set the boolean used by hide region to check if we are on the last record MM_atTotal = (MM_rsCount != -1 && MM_offset + MM_size >= MM_rsCount); %>
Update file |
© Tony Grant/tgds.net 2002 |