head 1.29;
access;
symbols
ChronicleBooks-TomcatApacheRelease:1.4;
locks; strict;
comment @# @;
1.29
date 2003.05.13.03.42.46; author erik; state Exp;
branches;
next 1.28;
1.28
date 2003.05.09.20.35.11; author erik; state Exp;
branches;
next 1.27;
1.27
date 2003.02.03.20.01.48; author erik; state Exp;
branches;
next 1.26;
1.26
date 2002.10.31.17.59.15; author erik; state Exp;
branches;
next 1.25;
1.25
date 2002.09.18.17.48.53; author mike; state Exp;
branches;
next 1.24;
1.24
date 2002.09.16.22.58.42; author mike; state Exp;
branches;
next 1.23;
1.23
date 2002.05.02.20.42.49; author mike; state Exp;
branches;
next 1.22;
1.22
date 2002.05.02.18.00.02; author mike; state Exp;
branches;
next 1.21;
1.21
date 2002.05.02.00.27.54; author mike; state Exp;
branches;
next 1.20;
1.20
date 2002.04.09.20.30.34; author mike; state Exp;
branches;
next 1.19;
1.19
date 2002.04.04.22.30.26; author mike; state Exp;
branches;
next 1.18;
1.18
date 2002.02.12.20.23.24; author mike; state Exp;
branches;
next 1.17;
1.17
date 2002.02.12.01.38.28; author mike; state Exp;
branches;
next 1.16;
1.16
date 2002.02.01.20.39.28; author mike; state Exp;
branches;
next 1.15;
1.15
date 2002.02.01.20.00.21; author mike; state Exp;
branches;
next 1.14;
1.14
date 2001.12.20.02.05.24; author mike; state Exp;
branches;
next 1.13;
1.13
date 2001.12.18.19.17.32; author mike; state Exp;
branches;
next 1.12;
1.12
date 2001.12.18.01.25.11; author mike; state Exp;
branches;
next 1.11;
1.11
date 2001.12.13.20.58.56; author alon; state Exp;
branches;
next 1.10;
1.10
date 2001.12.13.20.30.49; author alon; state Exp;
branches;
next 1.9;
1.9
date 2001.12.05.23.35.15; author mike; state Exp;
branches;
next 1.8;
1.8
date 2001.12.05.21.00.25; author mike; state Exp;
branches;
next 1.7;
1.7
date 2001.12.05.02.40.48; author mike; state Exp;
branches;
next 1.6;
1.6
date 2001.12.05.00.29.13; author mike; state Exp;
branches;
next 1.5;
1.5
date 2001.12.04.01.32.32; author alon; state Exp;
branches;
next 1.4;
1.4
date 2001.11.13.00.18.44; author sara; state Exp;
branches;
next 1.3;
1.3
date 2001.11.08.23.48.05; author alon; state Exp;
branches;
next 1.2;
1.2
date 2001.10.30.22.05.51; author alon; state Exp;
branches;
next 1.1;
1.1
date 2001.10.23.23.32.17; author sara; state Exp;
branches;
next ;
desc
@@
1.29
log
@*** empty log message ***
@
text
@import java.io.*;
import java.util.*;
import java.text.SimpleDateFormat;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.mail.internet.*;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.xml.parsers.*;
import org.apache.xalan.xslt.*;
import org.w3c.dom.*;
import com.posttool.hierarchy.*;
import com.posttool.Chronicle.*;
import com.posttool.util.XSL.*;
import com.posttool.dbManager.DataClass;
import com.posttool.util.DataClassFactory;
import com.chronicle.util.Sequence;
import com.chronicle.xsl.*;
/**
* this is pretty much all of the form processing for Chronicle.
* Creation date: (1/11/2001 8:58:52 PM)
* Modified regularly until (4/24/2001 9:34:33 AM)
* @@author:
*/
public class processForm extends javax.servlet.http.HttpServlet
{
private static org.apache.log4j.Category log =
org.apache.log4j.Category.getInstance(processForm.class.getName());
int count, postcardCount;
private static ResourceBundle labels = null;
private final static String locBundle = "com.posttool.Chronicle.LocalStrings",
resBundle = "com.posttool.Chronicle.taskManager";
private static Locale currentLocale = Locale.getDefault();
private static ResourceBundle appContext = null;
private static ResourceBundle messages = null;
private static String baseURL = "/Chronicle/servlet/at/";
static
{
Locale currentlocale = Locale.getDefault();
labels = ResourceBundle.getBundle("com.posttool.Chronicle.LocalStrings", currentlocale);
messages = ResourceBundle.getBundle("Messages", currentlocale);
}
/**
* Insert the method's description here.
* Creation date: (1/12/2001 9:55:44 AM)
* @@param table java.lang.String
*/
public boolean addFavorite(HttpServletRequest request, HttpServletResponse response)
{
// unfortunately, this is how i make a global variable for processform
// it must be synced at the end of the method for the next method...
HttpSession session = request.getSession();
ActionInfo actionInfo = (ActionInfo) session.getAttribute("ActionInfo");
RegUsers user = (RegUsers) session.getAttribute("RegUsers");
if (user == null)
{
// this is a problem, i think. perhaps the session timed out?
log.warn("Trying to add a favorite with no user logged in");
actionInfo.message = "I could not add the item to your favorites "
+ "because you do not appear to be logged in.";
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
return false;
}
Favorites fav = new Favorites();
fav.makeFromRequest(request, false);
fav.Email = user.Email;
boolean success = fav.DBInsert();
actionInfo.message = "The item was added to your list of favorites.";
//
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
//synchronized (session.getId().intern()) { session.setAttribute("RegUsers", user); }
//
return success;
}
/**
* Insert the method's description here.
* Creation date: (1/12/2001 9:55:44 AM)
* @@param table java.lang.String
*/
public void addressDelete(HttpServletRequest request, HttpServletResponse response)
{
// unfortunately, this is how i make a global variable for processform
// it must be synced at the end of the method for the next method...
HttpSession session = request.getSession();
ActionInfo actionInfo = (ActionInfo)session.getAttribute("ActionInfo");
RegUsers user = (RegUsers) session.getAttribute("RegUsers");
//
AddressBook addressBook = new AddressBook();
String key1 = (String) request.getParameter("k1");
String key2 = (String) request.getParameter("k2");
addressBook.DBDelete("Email = \""+user.Email+"\" and "+
"EntryFirst = \""+key1+"\" and "+
"EntryLast = \""+key2+"\"");
actionInfo.message = "";
//
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
//synchronized (session.getId().intern()) { session.setAttribute("RegUsers", user); }
//
}
/**
* Insert the method's description here.
* Creation date: (1/12/2001 9:55:44 AM)
* @@param table java.lang.String
*/
public void addressInsert(HttpServletRequest request, HttpServletResponse response)
{
// unfortunately, this is how i make a global variable for processform
// it must be synced at the end of the method for the next method...
HttpSession session = request.getSession();
ActionInfo actionInfo = (ActionInfo)session.getAttribute("ActionInfo");
RegUsers user = (RegUsers) session.getAttribute("RegUsers");
//
AddressBook addressBook = new AddressBook();
addressBook.makeFromRequest(request,false);
addressBook.Email = user.Email;
addressBook.DBInsert();
actionInfo.message = "";
//
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
//synchronized (session.getId().intern()) { session.setAttribute("RegUsers", user); }
//
}
/**
* Hello.
*/
public void addressItem(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
//
String addressId = (String) request.getParameter("address");
Point p = new Point();
DataAssociation da = new DataAssociation();
Vector v = new Vector();
v.add(da);
p.dataAssociation = v;
p.id = "address_book";
p.displayName = "Address Book";
p.masterPage = "blankMasterPage";
p.subStructure = "blankSubStructure";
da.table = "AddressBook";
da.tableTemplate = "Address";
da.whereClause = "select * from AddressBook where EntryName = \""+addressId+"\"";
da.orderBy = "EntryName";
da.direction = "";
da.subStructureBucket = "report";
da.perPage = "1";
//
HttpSession session = request.getSession(true);
String[] address = { "address", addressId };
synchronized (session.getId().intern()) { session.setAttribute("address", address); }
//
ClientInfo clientInfo = new ClientInfo();
clientInfo.addPointToSession("pop",p, session);
}
/**
* Hello.
*/
public void addressReport(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
// unfortunately, this is how i make a global variable for processform
// it must be synced at the end of the method for the next method...
HttpSession session = request.getSession();
ActionInfo actionInfo = (ActionInfo)session.getAttribute("ActionInfo");
RegUsers user = (RegUsers) session.getAttribute("RegUsers");
// //
String letter = (String) request.getParameter("letter");
Point p = new Point();
DataAssociation da = new DataAssociation();
DataAssociation pi = new DataAssociation();
DataAssociation pc = new DataAssociation();
Vector v = new Vector();
v.add(da);
v.add(pi);
v.add(pc);
p.dataAssociation = v;
p.id = "address_book";
p.displayName = "Address Book";
p.masterPage = "blankMasterPage";
p.subStructure = "blankSubStructure";
da.table = "AddressBook";
da.tableTemplate = "Address";
da.whereClause = "select * from AddressBook where "
+"Email = \"" + user.Email +"\" AND "
+"EntryLast like \""+letter+"%\"";
da.orderBy = "EntryLast, EntryFirst";
da.direction = "";
da.subStructureBucket = "report";
da.perPage = "33";
//
pi.name = "personalImage";
pi.table = "PersonalImage";
pi.whereClause = "( ( Email eq \"_session.Email\" ) and ( ImageType is \"Address\" ) )";
pi.orderBy = "PersonalImage.Email";
pi.tableTemplate="none";
pi.subStructureBucket="report";
//
pc.table ="Postcard";
pc.whereClause="( ( ISBN eq \"_personalImage.ISBN\" ) )";
pc.orderBy="Postcard.ISBN";
pc.tableTemplate="blankPC";
pc.subStructureBucket="report";
String[] address = { "letter", letter };
synchronized (session.getId().intern()) { session.setAttribute("address", address); }
//
ClientInfo clientInfo = new ClientInfo();
clientInfo.addPointToSession("pop",p, session);
//
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
//synchronized (session.getId().intern()) { session.setAttribute("RegUsers", user); }
//
}
/**
* Hello.
*/
public void addressSearch(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
// unfortunately, this is how i make a global variable for processform
// it must be synced at the end of the method for the next method...
HttpSession session = request.getSession();
ActionInfo actionInfo = (ActionInfo)session.getAttribute("ActionInfo");
RegUsers user = (RegUsers) session.getAttribute("RegUsers");
// //
String searchField = (String) request.getParameter("searchField");
String search = "%" + searchField.replace(' ', '%') + "%";
Point p = new Point();
DataAssociation da = new DataAssociation();
DataAssociation pi = new DataAssociation();
DataAssociation pc = new DataAssociation();
Vector v = new Vector();
v.add(da);
v.add(pi);
v.add(pc);
p.dataAssociation = v;
p.id = "address_book";
p.displayName = "Address Book";
p.masterPage = "blankMasterPage";
p.subStructure = "blankSubStructure";
//
da.table = "AddressBook";
da.tableTemplate = "Address";
da.whereClause =
"select * from AddressBook where "
+ "Email = \"" + user.Email +"\" AND ("
+ "EntryFirst like \"" + search+ "\" or "
+ "EntryLast like \"" + search + "\" or "
+ "Address1 like \"" + search + "\" or "
+ "Address2 like \"" + search + "\" or "
+ "City like \"" + search + "\" or "
+ "State like \"" + search + "\" or "
+ "ZipCode like \"" + search + "\" or "
+ "EntryEmail like \"" + search + "\" or "
+ "HomePhone like \"" + search + "\" or "
+ "WorkPhone like \"" + search + "\" )";
da.orderBy = "EntryLast, EntryFirst";
da.direction = "";
da.subStructureBucket = "report";
da.perPage = "33";
//
pi.name = "personalImage";
pi.table = "PersonalImage";
pi.whereClause = "( ( Email eq \"_session.Email\" ) and ( ImageType is \"Address\" ) )";
pi.orderBy = "PersonalImage.Email";
pi.tableTemplate="none";
pi.subStructureBucket="report";
//
pc.table ="Postcard";
pc.whereClause="( ( ISBN eq \"_personalImage.ISBN\" ) )";
pc.orderBy="Postcard.ISBN";
pc.tableTemplate="blankPC";
pc.subStructureBucket="report";
//
String[] address = { "search", searchField };
synchronized (session.getId().intern()) { session.setAttribute("address", address); }
//
ClientInfo clientInfo = new ClientInfo();
clientInfo.addPointToSession("pop",p, session);
//
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
//synchronized (session.getId().intern()) { session.setAttribute("RegUsers", user); }
//
}
/**
* Insert the method's description here.
* Creation date: (1/12/2001 9:55:44 AM)
* @@param table java.lang.String
*/
public void addressUpdate(HttpServletRequest request, HttpServletResponse response) {
// unfortunately, this is how i make a global variable for processform
// it must be synced at the end of the method for the next method...
HttpSession session = request.getSession();
ActionInfo actionInfo = (ActionInfo)session.getAttribute("ActionInfo");
RegUsers user = (RegUsers) session.getAttribute("RegUsers");
// '
AddressBook addressBook = new AddressBook();
String key1 = (String) request.getParameter("k1");
String key2 = (String) request.getParameter("k2");
Hashtable originalKeys = new Hashtable();
originalKeys.put("Email",user.Email);
originalKeys.put("EntryFirst",key1);
originalKeys.put("EntryLast",key2);
addressBook.makeFromRequest(request,false);
addressBook.Email = user.Email;
addressBook.DBUpdate(originalKeys);
actionInfo.message = "";
//
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
//synchronized (session.getId().intern()) { session.setAttribute("RegUsers", user); }
//
}
/**
* Insert the method's description here.
* Creation date: (1/12/2001 9:55:44 AM)
* @@param table java.lang.String
*/
public Orders cart_AccountToOrder(RegUserAccount acct, Orders order) {
order.Email = acct.Email;
order.ShipName = acct.ShipName;
order.ShipAddress1 = acct.ShipAddress1;
order.ShipAddress2 = acct.ShipAddress2;
order.ShipCity = acct.ShipCity;
order.ShipState = acct.ShipState;
order.ShipZipCode = acct.ShipZipCode;
order.ShipCountry = acct.ShipCountry;
order.ShipTelephone = acct.ShipTelephone;
order.ShipMethod = acct.ShipMethod;
order.BillName = acct.BillName;
order.BillAddress1 = acct.BillAddress1;
order.BillAddress2 = acct.BillAddress2;
order.BillCity = acct.BillCity;
order.BillState = acct.BillState;
order.BillZipCode = acct.BillZipCode;
order.BillCountry = acct.BillCountry;
order.BillTelephone = acct.BillTelephone;
order.CardHolder = acct.CardHolder;
order.CardNumber = acct.CardNumber;
order.CardType = acct.CardType;
order.ExpDateMM = acct.ExpDateMM;
order.ExpDateYY = acct.ExpDateYY;
return order;
}
/**
* Insert the method's description here.
* Creation date: (1/12/2001 9:55:44 AM)
* @@param table java.lang.String
*/
public AddressBook cart_OrderToAddress(Orders order, AddressBook address, RegUsers user) {
//
address.Email = user.Email;
int space = order.ShipName.indexOf(" ");
if (space != -1) {
address.EntryFirst = order.ShipName.substring(0, space).trim();
address.EntryLast = order.ShipName.substring(space).trim();
} else {
address.EntryLast = order.ShipName;
}
address.Address1 = order.ShipAddress1;
address.Address2 = order.ShipAddress2;
address.City = order.ShipCity;
address.State = order.ShipState;
address.Country = order.ShipCountry;
address.ZipCode = order.ShipZipCode;
address.HomePhone = order.ShipTelephone;
return address;
}
/**
* Insert the method's description here.
* Creation date: (1/12/2001 9:55:44 AM)
* @@param table java.lang.String
*/
public RegUserAccount cart_OrderToRegUserAccount(Orders order, RegUserAccount acct, RegUsers user) {
acct.Email = user.Email;
//
acct.ShipName = order.ShipName;
acct.ShipAddress1 = order.ShipAddress1;
acct.ShipAddress2 = order.ShipAddress2;
acct.ShipCity = order.ShipCity;
acct.ShipState = order.ShipState;
acct.ShipCountry = order.ShipCountry;
acct.ShipZipCode = order.ShipZipCode;
acct.ShipTelephone = order.ShipTelephone;
//
acct.BillName = order.BillName;
acct.BillAddress1 = order.BillAddress1;
acct.BillAddress2 = order.BillAddress2;
acct.BillCity = order.BillCity;
acct.BillState = order.BillState;
acct.BillCountry = order.BillCountry;
acct.BillZipCode = order.BillZipCode;
acct.BillTelephone = order.BillTelephone;
//
acct.CardHolder = order.CardHolder;
acct.CardNumber = order.CardNumber;
acct.CardType = order.CardType;
acct.ExpDateMM = order.ExpDateMM;
acct.ExpDateYY = order.ExpDateYY;
return acct;
}
/**
* Insert the method's description here.
* Creation date: (1/12/2001 9:55:44 AM)
* @@param table java.lang.String
*/
public void cartAdd(HttpServletRequest request, HttpServletResponse response)
{
// unfortunately, this is how i make a global variable for processform
// it must be synced at the end of the method for the next method...
HttpSession session = request.getSession();
ActionInfo actionInfo = (ActionInfo) session.getAttribute("ActionInfo");
RegUsers user = (RegUsers) session.getAttribute("RegUsers");
String client = (String) session.getAttribute("client");
Cart cart = new Cart();
cart.makeFromRequest(request, false);
boolean isOk = cart.DBInsert();
if (isOk)
{
//actionInfo.redirect = "";
actionInfo.message += "Item added to cart. ";
}
else
{
// back to the page you were on
//actionInfo.redirect = "";
String sclink = "shopping cart";
if ("HTML".equals(client))
{
sclink = "" + sclink + "";
}
actionInfo.message += "You already have that in your cart. To purchase additional "
+ "copies, go to your " + sclink + ", change quantity and click \"update\".";
if ("HTML".equals(client))
{
actionInfo.message = "" + actionInfo.message + "";
}
}
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
//synchronized (session.getId().intern()) { session.setAttribute("RegUsers", user); }
}
/**
* Insert the method's description here.
* Creation date: (1/12/2001 9:55:44 AM)
* @@param table java.lang.String
*/
public boolean cartCheckout(HttpServletRequest request, HttpServletResponse response)
{
log.debug("In processForm.cartCheckout");
// unfortunately, this is how i make a global variable for processform
// it must be synced at the end of the method for the next method...
HttpSession session = request.getSession();
ActionInfo actionInfo = (ActionInfo) session.getAttribute("ActionInfo");
RegUsers user = (RegUsers) session.getAttribute("RegUsers");
String status = "";
// this will capture the form at hand
// or pickup a registered user's account preferences
Orders order = (Orders) session.getAttribute("Orders");
if (order == null) order = new Orders();
order.makeFromRequest(request, false);
synchronized (session.getId().intern()) { session.setAttribute("Orders", order); }
if (actionInfo.redirect.indexOf("shipping") > -1
&& request.getParameter("ShipName") != null)
{
log.debug("Redirect has 'shipping' and ShipName is not null");
actionInfo.redirect = "history(u);billing";
}
if (actionInfo.redirect.indexOf("billing") > -1
&& request.getParameter("ExpDateMM") != null)
{
log.debug("Redirect has 'billing' and ExpDateMM is not null");
actionInfo.redirect = "history(u);confirm";
}
/* registered users can save the shipping address to their personal
* address book. new users (who register from checkout) cannot save the
* the first address because it will be used as the reg user address.
*/
String saveAddress = (String) request.getParameter("saveAddress");
if (saveAddress != null && saveAddress.equals("checked")) {
AddressBook address = new AddressBook();
address = cart_OrderToAddress(order, address, user);
boolean inserted = address.DBInsert();
if (!inserted)
status += "Chckout Error. Cannot transfer shipping address to personal address book. ";
}
/* */
if (status.equals(""))
status = "Your order information has been updated. ";
actionInfo.message += status;
//
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
//synchronized (session.getId().intern()) { session.setAttribute("RegUsers", user); }
//
return true;
}
/**
* Transfer cart contents to order contents.
* Return true if no error occurs, false otherwise.
*/
public boolean cartOrder(HttpServletRequest request, HttpServletResponse response)
throws ServletException
{
// the order, the user info and the card information
HttpSession session = request.getSession();
ActionInfo actionInfo = (ActionInfo) session.getAttribute("ActionInfo");
RegUsers user = (RegUsers) session.getAttribute("RegUsers");
String client = (String) session.getAttribute("client");
Orders order = (Orders) session.getAttribute("Orders");
RegUserAccount account = (RegUserAccount) session.getAttribute("RegUserAccount");
// is anything null?
if (user == null || account == null || order == null)
{
actionInfo.redirect = "history(u);login";
actionInfo.message = "Order Error: Please log in.";
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
log.warn("Something is null. User must log in again.");
return false;
}
// connect the order to this user
if (order.CardHolder == null || order.CardHolder.equals("CardHolder"))
{
log.debug("Set order card holder to order ship name");
order.CardHolder = order.ShipName;
}
// Get next order id
// this is in place of the old post tool solution where
// id's were maintained in a file by this code
int id;
try
{
id = Sequence.nextOrderId();
}
catch (java.sql.SQLException e)
{
log.error("error getting next order id", e);
throw new ServletException(e);
}
log.debug("Set order id and email");
order.OrderID = id;
order.Email = user.Email;
synchronized (session.getId().intern()) { session.setAttribute("Orders", order); }
// and insert
log.debug("Insert order in to database");
boolean inserted = order.DBInsert();
if (! inserted)
{
log.error("Could not insert order: " + order.OrderID);
actionInfo.message += "Order Error: Invalid invoice number for order. ";
}
// copy from the cart to orderItems
Cart cart = new Cart();
log.debug("Select items from cart");
int cartItems = cart.DBSelect("Email = \"" + user.Email + "\"");
OrderItems orderItem = new OrderItems();
log.debug("There are " + cartItems + " in the cart");
for (int i = 0; i < cartItems; i++)
{
log.debug("Select row from cart table");
cart.DBSelectRow(i);
orderItem.OrderID = order.OrderID;
orderItem.ISBN = cart.ISBN;
orderItem.Quantity = toInt(cart.Quantity);
log.debug("Insert into order table (" + orderItem.ISBN + ", " + orderItem.Quantity + ")");
inserted = orderItem.DBInsert();
if (! inserted)
{
log.error("Count not insert order item: " + orderItem.ISBN);
actionInfo.message += "Order Error: Cannot transfer from cart to orderItems. ";
}
}
// delete the cart
log.debug("Delete cart");
cart.DBDelete("Email = \"" + user.Email + "\"");
// transfer the order info is the savePrefs is checked
String savePrefs = (String) request.getParameter("savePrefs");
if (savePrefs != null)
{
log.debug("Update user account information");
account = cart_OrderToRegUserAccount(order, account, user);
account.DBUpdate();
}
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
return (actionInfo.message.equals(""));
}
/**
* This method DOESN'T DO ANYTHING!!
*/
public void cartOrderEmail(HttpServletRequest request,
RegUsers user,
Orders order)
{
log.warn("This method doesn't do anything! Nobody should be calling me!");
String m = "";
m += "Dear " + order.BillName + ",\n\n";
m += "Thank you for ordering from chroniclebooks.com!\n";
m += "In accordance with your order (Order #"
+ order.OrderID
+ "), we have shipped\n";
m += "Quantity ISBN Title\n";
m += "--------------------------------------------------------------------\n";
//5 . . . 0811831434 . . . . Paper Palm
int total = 0;
// loop through items
// didn't do this yet, i just noticed that this was already being done....
//
// total += qty * unitPrice;
//
if (! order.ShipAddress1.equals(""))
{
m += "to " + order.ShipName + "\n";
m += "" + order.ShipAddress1 + "\n";
if (! order.ShipAddress2.equals("")) m += "" + order.ShipAddress2 + "\n";
m += "" + order.ShipState + " " + order.ShipZipCode + "\n";
}
else
{
m += "to " + order.BillName + "\n";
m += "" + order.BillAddress1 + "\n";
if (! order.BillAddress2.equals("")) m += "" + order.BillAddress2 + "\n";
m += "" + order.BillState + " " + order.BillZipCode + "\n";
}
String last4digits = order.CardNumber.substring(order.CardNumber.length() - 4);
m += "and have charged credit card number XXXX-XXXX-XXXX-" + last4digits + "\n";
m += "[note-only last four digits printed for your security] ";
m += "in the amount of $" + total + ".\n";
m += "Should you wish to check the status of this order, please visit";
m += "Order Status.\n";
m += "If you have questions about your order, ";
m += "contact order_inquiries@@chroniclebooks.com\n\n";
m += "Your order should arrive in 10-12 business days.\n";
m += "Thanks again for your order, and be sure to visit www.chroniclebooks.com";
m += "again soon!\n";
m += "Chronicle Books Customer Service.\n";
m += "800-722-6657\n";
m += "order_inquiries@@chroniclebooks.com\n\n";
}
/**
* Handles placing an order
*/
public boolean cartOrderResponse(HttpServletRequest request,
HttpServletResponse response)
{
// unfortunately, this is how i make a global variable for processform
// it must be synced at the end of the method for the next method...
HttpSession session = request.getSession();
ActionInfo actionInfo = (ActionInfo) session.getAttribute("ActionInfo");
RegUsers user = (RegUsers) session.getAttribute("RegUsers");
Orders order = (Orders) session.getAttribute("Orders");
// delete the user if no password was ever specified-
// a new user with this email has no history (see userInserNew)
String client = (String) session.getAttribute("client");
if (actionInfo.message.equals(""))
{
actionInfo.message = "Your order has been submitted with an Order Id of " + order.OrderID + ". ";
// Hack additional parameter for fl.pl to switch on.
actionInfo.fh = "home";
// cartOrderEmail doesn't do anything, so we won't call it -mike
// cartOrderEmail(request, user, order);
String ccs = "contact customer service";
// Flash checkout uses HTML confirmation page, too
if (client.equals("HTML") || client.equals("Flash"))
{
ccs = "" + ccs + "";
}
if (user.CatSection.equals("Temp"))
{
// temp user goes byebye
actionInfo.message
+= "Your order should arrive 7-10 days after it is processed. If you have any questions, " + ccs + ".";
user.DBDelete("Email = \"" + user.Email + "\"");
synchronized (session.getId().intern()) { session.removeAttribute("RegUsers"); }
synchronized (session.getId().intern()) { session.removeAttribute("RegUserAccount"); }
synchronized (session.getId().intern()) { session.removeAttribute("Orders"); }
synchronized (session.getId().intern()) { session.removeAttribute("secure"); }
actionInfo.redirect = "history(u);message";
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
sendJSResponse(request, response, client, true, false, false, false);
// update parent, close window, no cookie.
return true;
}
else
{
String yourcb = "Your Chronicle Books";
// Flash checkout uses HTML confirmation page, too
if (client.equals("HTML"))
{
yourcb = "" + yourcb + "";
}
else if (client.equals("Flash"))
{
yourcb = "" + yourcb + "";
}
actionInfo.message
+= "You may cancel this order from account maintenance anytime before it is shipped or "
+ "view the status of this order using " + yourcb + ". Your order should arrive "
+ "7-10 days after it is processed. If you have any questions, " + ccs + ".";
synchronized (session.getId().intern()) { session.setAttribute("whichTree", "adults"); }
if (client.equals("HTML") || client.equals("Flash"))
{
actionInfo.message = "" + actionInfo.message + "";
}
if (user != null)
actionInfo.redirect = "history(u);your";
else
actionInfo.redirect = "history(u);message";
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
// synchronized (session.getId().intern()) { session.setAttribute("RegUsers", user); }
sendJSResponse(request, response, client, true, false, false, true);
// switch parent window to adults
return true;
}
}
else
{
// copy from the cart to orderItems
OrderItems oi = new OrderItems();
int oiCount = oi.DBSelect("OrderID = \"" + order.OrderID + "\"");
Cart cart = new Cart();
for (int i = 0; i < oiCount; i++)
{
oi.DBSelectRow(i);
cart.ISBN = oi.ISBN;
cart.Quantity = oi.Quantity + "";
cart.Email = user.Email;
boolean inserted = cart.DBInsert();
if (! inserted) actionInfo.message += "Order Error: Cannot transfer cart. ";
}
oi.DBDelete("OrderID = \"" + order.OrderID + "\"");
// remove the order
int ordersDeleted = order.DBDelete();
actionInfo.message = "There were problems placing the order (id: "
+ order.OrderID
+ "). "
+ actionInfo.message;
actionInfo.redirect = "history(u);message";
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
return false;
}
}
/**
* Insert the method's description here.
* Creation date: (1/12/2001 9:55:44 AM)
* @@param table java.lang.String
*/
public void cartUpdate(HttpServletRequest request, HttpServletResponse response)
{
// unfortunately, this is how i make a global variable for processform
// it must be synced at the end of the method for the next method...
HttpSession session = request.getSession();
ActionInfo actionInfo = (ActionInfo) session.getAttribute("ActionInfo");
RegUsers user = (RegUsers) session.getAttribute("RegUsers");
boolean isOk = true;
Cart cart = new Cart();
Vector rows = requestAsRows(request, cart);
if (rows.isEmpty())
{
log.warn("Nothing to update the cart with in the request");
}
else
{
log.debug("Updating the cart with " + rows.size() + " rows");
Hashtable newRow = (Hashtable) rows.elementAt(0); // get one row in order to get the email address
Hashtable oldRow = null;
String newISBN = null;
log.debug("Reading cart in from database");
cart.DBSelect( "ISBN", "Catalog", "Email = \"" + newRow.get("Email") + "\" " + " ORDER BY Catalog.Title");
for (int i = 0; i < rows.size(); i++)
{
log.debug("Getting item from request: " + i);
newRow = (Hashtable) rows.elementAt(i);
newISBN = (String) newRow.get("ISBN");
log.debug("Reading cart item in from database: " + newISBN);
boolean couldFind = cart.DBSelectRow(newISBN);
if (! couldFind)
{
log.error("Could not find item in cart: " + newISBN);
isOk = false;
break;
}
oldRow = cart.toHash();
log.debug("old row: " + oldRow);
log.debug("new row: " + newRow);
if (toInt((String) newRow.get("Quantity")) == 0)
{
log.debug("Quantity is zero, deleting item from cart: " + newISBN);
int rowsGone = cart.DBDelete();
if (rowsGone > 1)
{
log.error(rowsGone + " rows were deleted from the cart (should be 1) for item: " + newISBN);
isOk = false;
break;
}
}
else if (toInt((String) newRow.get("Quantity")) == toInt((String) oldRow.get("Quantity")))
{
log.debug("Nothing has changed for item: " + newRow.get("ISBN"));
}
else
{
log.debug("Updating cart for item: " + newRow.get("ISBN"));
isOk = cart.DBUpdate(oldRow, newRow);
if (! isOk)
{
log.error("Unable to update cart with item: " + newRow.get("ISBN"));
break;
}
}
}
}
if (isOk)
{
// forward
log.debug("Shopping cart successfully updated.");
if (actionInfo.redirect == null) actionInfo.redirect = "";
actionInfo.message = "Your shopping cart has been updated.";
}
else
{
// back to the page you were on (with some message)
log.debug("Error updating cart. Redirecting user back to same page.");
actionInfo.redirect = "";
actionInfo.message = "There was a problem updating your shopping cart.";
}
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
// synchronized (session.getId().intern()) { session.setAttribute("RegUsers", user); }
}
/**
* Insert the method's description here.
* Creation date: (1/12/2001 9:55:44 AM)
* @@param table java.lang.String
*/
public boolean cartUserUpdate(String userEmail, String id, HttpServletRequest request) {
Cart cart = new Cart();
int itemsInCart = cart.DBSelect("Email = \"" + id + "\"");
for (int i = 0; i < itemsInCart; i++) {
cart.DBSelectRow(i);
Hashtable row = cart.toHash();
cart.Email = userEmail;
boolean isOk = cart.DBUpdate(row);
if (!isOk)
return false;
}
return true;
}
/**
* Insert the method's description here.
* Creation date: (1/12/2001 9:55:44 AM)
* @@param table java.lang.String
*/
public boolean cartUserUpdate(String userEmail, HttpServletRequest request) {
String id = (String) request.getParameter("cartConnect");
return cartUserUpdate(userEmail, id, request);
}
/**
* Verify credit card -mike
*/
public boolean cartVerifyCC(HttpServletRequest request, HttpServletResponse response)
{
boolean isOk = true;
// the order, the user info and the card information
HttpSession session = request.getSession();
ActionInfo actionInfo = (ActionInfo) session.getAttribute("ActionInfo");
RegUsers user = (RegUsers) session.getAttribute("RegUsers");
Orders order = (Orders) session.getAttribute("Orders");
RegUserAccount account = (RegUserAccount) session.getAttribute("RegUserAccount");
taskCheckCredit tcc = new taskCheckCredit();
String result = tcc.check(order.OrderID);
if (result.equals("OK"))
{
isOk = true;
}
else if (result.equals("NoCredit"))
{
actionInfo.message =
"The credit card you submitted has been declined by VeriSign, our "
+ "online credit card verification service. Please try another card if you "
+ "wish, and contact your credit card company if you feel there is an error "
+ "with your card. To place your order by phone, call our Customer Service "
+ "Department at: 800-722-6657, and to report ordering problems, email us."
+ "
"
+ "Click here to adjust your entry or try another card.
"
+ actionInfo.message;
isOk = false;
}
else if (result.equals("Failure"))
{
actionInfo.message =
"We could not get authorization for the credit card number you submitted. "
+ "Please check to make sure you have entered the card number and expiration "
+ "date correctly or try another credit card. To place your order by phone, "
+ "call our Customer Service Department at: 800-722-6657, and to report "
+ "ordering problems, email us."
+ "
"
+ "Click here to adjust your entry or try another card.
"
+ actionInfo.message;
isOk = false;
}
else
{
// NOTE: this message is the same as Failure above, but only because I didn't have anything
// else to put here. We should probably come up with a more robust error reporting scheme.
// -mike
log.error("Got an unknown response from taskCheckCredit.check(). Sending failure message.");
actionInfo.message =
"We could not get authorization for the credit card number you submitted. "
+ "Please check to make sure you have entered the card number and expiration "
+ "date correctly or try another credit card. To place your order by phone, "
+ "call our Customer Service Department at: 800-722-6657, and to report "
+ "ordering problems, email us."
+ "
"
+ "Click here to adjust your entry or try another card.
"
+ actionInfo.message;
isOk = false;
}
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
return isOk;
}
/**
* Insert the method's description here.
* Creation date: (1/12/2001 9:55:44 AM)
* @@param table java.lang.String
*/
public void dateChange(HttpServletRequest request, HttpServletResponse response) {
// unfortunately, this is how i make a global variable for processform
// it must be synced at the end of the method for the next method...
HttpSession session = request.getSession();
ActionInfo actionInfo = (ActionInfo) session.getAttribute("ActionInfo");
RegUsers user = (RegUsers) session.getAttribute("RegUsers");
//
actionInfo.redirect = (String) request.getParameter("redirect");
if (actionInfo.redirect == null) actionInfo.redirect = "day;history(pop);";
String dateChange = (String) request.getParameter("date");
Date date = (Date) session.getAttribute("Date");
if (date == null) {
date = new Date();
}
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
if (dateChange.length() == 10) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
try {
date = dateFormat.parse(dateChange);
synchronized (session.getId().intern()) { session.setAttribute("Date", date); }
cal.setTime(date);
} catch (Exception e) {
}
} else if (dateChange.indexOf("30") == -1) {
int d = toInt(dateChange);
int m = cal.get(java.util.Calendar.DAY_OF_YEAR);
int y = cal.get(java.util.Calendar.YEAR);
if (m + d < 0) {
cal.set(java.util.Calendar.YEAR, y - 1);
cal.set(java.util.Calendar.DAY_OF_YEAR, 365 + (m + d));
} else if (m + d > 365) {
cal.set(java.util.Calendar.YEAR, y + 1);
cal.set(java.util.Calendar.DAY_OF_YEAR, (m + d) - 366);
} else {
cal.set(java.util.Calendar.DAY_OF_YEAR, m + d);
}
if (d == 7 || d == -7)
actionInfo.redirect = "week";
} else {
int d = 1;
if (dateChange.indexOf("-") > -1)
d = -1;
int m = cal.get(java.util.Calendar.MONTH);
int y = cal.get(java.util.Calendar.YEAR);
if (m == 0 && d == -1) {
cal.set(java.util.Calendar.YEAR, y - 1);
cal.set(java.util.Calendar.MONTH, 11);
} else if (m == 11 && d == 1) {
cal.set(java.util.Calendar.YEAR, y + 1);
cal.set(java.util.Calendar.MONTH, 0);
} else {
cal.set(java.util.Calendar.MONTH, m + d);
}
actionInfo.redirect = "month";
}
date = cal.getTime();
synchronized (session.getId().intern()) { session.setAttribute("Date", date); }
actionInfo.message = "";
//
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
//synchronized (session.getId().intern()) { session.setAttribute("RegUsers", user); }
//
}
/**
* Insert the method's description here.
* Creation date: (1/12/2001 9:55:44 AM)
* @@param table java.lang.String
*/
public void dateDelete(HttpServletRequest request, HttpServletResponse response) {
// unfortunately, this is how i make a global variable for processform
// it must be synced at the end of the method for the next method...
HttpSession session = request.getSession();
ActionInfo actionInfo = (ActionInfo) session.getAttribute("ActionInfo");
RegUsers user = (RegUsers) session.getAttribute("RegUsers");
//
boolean isOk = true;
PersonalCalendar cal = new PersonalCalendar();
cal.makeFromRequest(request,false);
cal.Email = user.Email;
int d = cal.DBDelete();
if (d==1){
// forward
actionInfo.redirect ="day;history(pop);";
actionInfo.message = "";
} else {
// back to the page you were on (with some message)
actionInfo.redirect = "";
actionInfo.message = "There are "+d+" event(s) at that time.";
}
//
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
//synchronized (session.getId().intern()) { session.setAttribute("RegUsers", user); }
//
}
/**
* Insert the method's description here.
* Creation date: (1/12/2001 9:55:44 AM)
* @@param table java.lang.String
*/
public void dateInsert(HttpServletRequest request, HttpServletResponse response) {
// unfortunately, this is how i make a global variable for processform
// it must be synced at the end of the method for the next method...
HttpSession session = request.getSession();
ActionInfo actionInfo = (ActionInfo) session.getAttribute("ActionInfo");
RegUsers user = (RegUsers) session.getAttribute("RegUsers");
//
Date date = (Date) session.getAttribute("Date");
if (date == null) {
date = new Date();
}
String hour = (String) request.getParameter("hour");
String newEvent = (String) request.getParameter("new");
// adjust date
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
cal.set(java.util.Calendar.HOUR_OF_DAY, toInt(hour));
date = cal.getTime();
synchronized (session.getId().intern()) { session.setAttribute("Date", date); }
// write record
if (newEvent != null) {
PersonalCalendar dcal = new PersonalCalendar();
dcal.Email = user.Email;
dcal.Date = dateFormat.format(date);
dcal.Time = hour;
dcal.EventDescription = "A new event.";
dcal.DBInsert();
// when does "A new event." get cleaned up?
}
actionInfo.redirect = "go(edit_cal," + hour + ");history(pop);";
actionInfo.message = "";
//
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
//synchronized (session.getId().intern()) { session.setAttribute("RegUsers", user); }
//
}
/**
* Insert the method's description here.
* Creation date: (1/12/2001 9:55:44 AM)
* @@param table java.lang.String
*/
public void dateUpdate(HttpServletRequest request, HttpServletResponse response) {
// unfortunately, this is how i make a global variable for processform
// it must be synced at the end of the method for the next method...
HttpSession session = request.getSession();
ActionInfo actionInfo = (ActionInfo) session.getAttribute("ActionInfo");
RegUsers user = (RegUsers) session.getAttribute("RegUsers");
//
Date date = (Date) session.getAttribute("Date");
if (date == null) {
date = new Date();
}
// adjust date
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
GregorianCalendar gcal = new GregorianCalendar();
gcal.setTime(date);
int hour = gcal.get(java.util.Calendar.HOUR_OF_DAY);
String CalendarHour = hour+"";
if (hour <10) CalendarHour = "0"+CalendarHour;
//
PersonalCalendar pcal = new PersonalCalendar();
pcal.Email = user.Email;
pcal.DBSelect(
"Email = \""
+user.Email
+ "\" AND Date = \""
+ dateFormat.format(date)
+ "\" AND Time = \""
+ CalendarHour
+ "\"");
Hashtable row = pcal.toHash();
pcal.makeFromRequest(request,false);
pcal.Email = user.Email;
pcal.DBUpdate(row);
//
try {
date =dateFormat.parse(pcal.Date);
} catch (Exception e) {
}
if (date != null) {
// forward
synchronized (session.getId().intern()) { session.setAttribute("Date", date); }
actionInfo.redirect = "day;history(pop)";
actionInfo.message = "";
} else {
// back to the page you were on (with some message)
actionInfo.redirect = "";
actionInfo.message = "There was a problem updating your calendar.";
}
//
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
//synchronized (session.getId().intern()) { session.setAttribute("RegUsers", user); }
//
}
/**
* Process incoming HTTP GET requests
*
* @@param request Object that encapsulates the request to the servlet
* @@param response Object that encapsulates the response from the servlet
*/
public void doGet(
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException, java.io.IOException {
// unfortunately, this is how i make a global variable for processform
// it must be synced at the end of the method for the next method...
HttpSession session = request.getSession(true);
ActionInfo actionInfo = new ActionInfo();
RegUsers user = (RegUsers) session.getAttribute("RegUsers");
//
actionInfo.message = "";
actionInfo.table = (String) request.getParameter("table");
actionInfo.action = (String) request.getParameter("action");
actionInfo.redirect = (String) request.getParameter("redirect");
if (actionInfo.table == null) {
actionInfo.table = "";
}
if (actionInfo.action == null) {
actionInfo.action = "";
}
if (actionInfo.redirect == null) {
actionInfo.redirect = "";
}
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
//
if (actionInfo.table.equals("PostcardSent")) {
sendPostcard(request, response);
}
// date changes
if (request.getParameter("date") != null) {
dateChange(request, response);
}
if (request.getParameter("hour") != null) {
dateInsert(request, response);
}
if (request.getParameter("letter") != null) {
addressReport(request, response);
actionInfo.redirect = "history(pop);" + actionInfo.redirect;
}
if (request.getParameter("searchField") != null) {
addressSearch(request, response);
actionInfo.redirect = "history(pop);" + actionInfo.redirect;
}
if (request.getParameter("address") != null) {
addressItem(request, response);
actionInfo.redirect = "history(pop);" + actionInfo.redirect;
}
String excerpt = (String) request.getParameter("excerpt");
if (excerpt != null)
{
//System.err.println("Excerpt is: " + excerpt + ".");
//System.err.println("Excerpt's length is: " + excerpt.length());
response.sendRedirect(
getString("apacheHttp") + "Chronicle/excerpt/" + excerpt + "-e0.html");
return;
}
//
if (request.getParameter("logout") != null) {
logout(request,response);
} else {
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
}
//synchronized (session.getId().intern()) { session.setAttribute("RegUsers", user); }
//
if (!response.isCommitted()) {
sendRedirect(response, this.baseURL + actionInfo.redirect, actionInfo.message);
}
}
/**
* Process incoming HTTP POST requests
*
* @@param request Object that encapsulates the request to the servlet
* @@param response Object that encapsulates the response from the servlet
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws javax.servlet.ServletException,
java.io.IOException
{
// unfortunately, this is how i make a global variable for processform
// it must be synced at the end of the method for the next method...
HttpSession session = request.getSession(true);
ActionInfo actionInfo = (ActionInfo) session.getAttribute("ActionInfo");
if (actionInfo == null)
{
actionInfo = new ActionInfo();
}
RegUsers user = (RegUsers) session.getAttribute("RegUsers");
// init
actionInfo.message = "";
actionInfo.table = (String) request.getParameter("table");
actionInfo.action = (String) request.getParameter("action");
actionInfo.redirect = (String) request.getParameter("redirect");
log.debug("actionInfo = " + actionInfo);
synchronized (session.getId().intern()) { session.setAttribute("ActionInfo", actionInfo); }
//synchronized (session.getId().intern()) { session.setAttribute("RegUsers", user); }
try
{
interpretCommand(request, response);
}
catch (Exception e)
{
log.error("Exception while intrepreting some POST command", e);
sendRedirect(response, this.baseURL + "login", "Please log in.");
}
}
/**
* ResourceBundle boilerplate -
* variety two, with application context
*/
protected static String getAppContext(String theKey, String theBundle) {
String returnValue = "";
if ((appContext = ResourceBundle.getBundle(theBundle, currentLocale)) != null) {
try {
returnValue = appContext.getString(theKey);
} catch (MissingResourceException MRExcp) {
/* just leave it alone if not found */
}
}
return returnValue;
}
/**
* Reads checkbox values and inserts or deletes them from the table based on your id.
* Creation date: (2/16/2001 11:31:57 AM)
*/
public String[] getCheckboxes(HttpServletRequest request) {
String[] checkboxValues = null;
List l = new LinkedList();
Enumeration e = request.getParameterNames();
while (e.hasMoreElements()) {
String a = (String) e.nextElement();
if (a.startsWith("checkbox")) {
l.add(request.getParameter(a));
}
}
checkboxValues = new String[ l.size() ];
for (int i=0; i< l.size(); i++) {
checkboxValues[i] = (String) l.get(i);
//System.out.println(l.get(i));
}
return checkboxValues;
}
/**
* Returns the servlet info string.
*/
public String getSecurePath(HttpServletRequest request) {
// unfortunately, this is how i make a global variable for processform
// it must be synced at the end of the method for the next method...
HttpSession session = request.getSession();
ActionInfo actionInfo = (ActionInfo) session.getAttribute("ActionInfo");
//
return getString("tomcatHttps") +this.baseURL.substring(1)+"secure(1);"+ actionInfo.redirect;
}
/**
* Returns the servlet info string.
*/
public String getServletInfo() {
return super.getServletInfo();
}
/*
Louisburg College
501 North Main Street
Louisburg, NC 27549
*/
private static String getString(String key) {
return labels.getString(key);
}
/**
* do we use it?
* Creation date: (2/16/2001 11:31:57 AM)
*/
public void giftFinder(HttpServletRequest request, HttpServletResponse response) {
at pageGen = new at();
}
/**
* Interpret POST command (from doPOST).
* This method handles EVERY post command there is (i think).
* -mike wynholds
*/
public void interpretCommand( HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
// unfortunately, this is how i make a global variable for processform
// it must be synced at the end of the method for the next method...
HttpSession session = request.getSession();
ActionInfo actionInfo = (ActionInfo) session.getAttribute("ActionInfo");
RegUsers user = (RegUsers) session.getAttribute("RegUsers");
if (actionInfo.table != null && actionInfo.action != null)
{
boolean secure = false;
// User Registration
if (actionInfo.table.equals("RegUsers"))
{
if (actionInfo.action.equals("Insert"))
{
// does its own response
switchToSecure(request);
secure = userInsertNew(request, response);
}
if (actionInfo.action.equals("Validate"))
{
// does its own response
switchToSecure(request);
userValidate(request, response);
}
if (actionInfo.action.equals("Update"))
{
secure = userUpdate(request, response);
}
}
// Password table
if (actionInfo.table.equals("Password"))
{
if (actionInfo.action.equals("Update"))
{
secure = userPasswordPrefs(request, response);
}
}
// Shipping table
if (actionInfo.table.equals("Shipping"))
{
if (actionInfo.action.equals("Update"))
{
secure = userShippingPrefs(request, response);
}
}
// Billing table
if (actionInfo.table.equals("Billing"))
{
if (actionInfo.action.equals("Update"))
{
secure = userBillingPrefs(request, response);
}
}
// Checkout Shipping
if (actionInfo.table.equals("Orders"))
{
if (actionInfo.action.equals("toSession"))
{
secure = cartCheckout(request, response);
}
if (actionInfo.action.equals("placeOrder"))
{
// returns whether an error happened or not
secure = cartOrder(request, response);
if (secure)
{
secure = cartVerifyCC(request, response);
cartOrderResponse(request, response);
}
}
if (actionInfo.action.equals("Delete"))
{
secure = orderDelete(request, response);
}
}
// Your stuff
if (actionInfo.table.equals("Subscriptions"))
{
secure = yourSubscription(request, response);
}
if (actionInfo.table.equals("Reminders"))
{
secure = yourReminders(request, response);
}
if (actionInfo.table.equals("HomePage"))
{
secure = yourFavorites(request, response);
}
// Calendar add/update event
if (actionInfo.table.equals("PersonalCalendar"))
{
if (actionInfo.action.equals("Update"))
{
dateUpdate(request, response);
}
}
if (actionInfo.table.equals("PersonalCalendar"))
{
if (actionInfo.action.equals("Delete"))
{
dateDelete(request, response);
}
}
// Cart Maintenance
if (actionInfo.table.equals("Cart"))
{
// Special Case insert from custom JSPs
if (actionInfo.action.equals("InsertHTML"))
{
synchronized (session.getId().intern()) {
session.setAttribute("client", "HTML");
}
cartAdd(request, response);
}
if (actionInfo.action.equals("Insert"))
{
cartAdd(request, response);
}
if (actionInfo.action.equals("Update"))
{
cartUpdate(request, response);
}
}
// Gift Finder
if (actionInfo.table.equals("Gift"))
{
giftFinder(request, response);
}
// Address Book
if (actionInfo.table.equals("AddressBook"))
{
if (actionInfo.action.equals("Insert"))
{
addressInsert(request, response);
}
if (actionInfo.action.equals("Update"))
{
addressUpdate(request, response);
}
if (actionInfo.action.equals("Delete"))
{
addressDelete(request, response);
}
}
// Favorites
if (actionInfo.table.equals("Favorites"))
{
addFavorite(request, response);
// secure = true;
}
// Personal image (for calendar or address book)
if (actionInfo.table.equals("PersonalImage"))
{
setImage(request, response);
secure = true;
}
// Send and preview postcard
if (actionInfo.table.equals("PostcardSent"))
{
sendPostcard(request, response);
}
// Send non-postcard emails:
// - order inquiries
// - permission inquiries
// - other
if (actionInfo.table.equals("SendMail"))
{
sendMail(request);
}
boolean secureProtocol = request.getPathInfo().indexOf("secure") > -1;
// really should be
// boolean correctProtocol = request.getProtocol().startsWith("HTTPS");
if (secure && secureProtocol)
{
log.debug("Secure redirect to " + getSecurePath(request));
sendRedirect(response, getSecurePath(request), actionInfo.message);
}
else if (secure && !secureProtocol)
{
// should we be redirecting them to the current server or just "chronbooks"?
log.debug("Redirect to http://www.chronbooks.com (hard-coded)");
sendRedirect(response, "http://www.chronbooks.com", "");
}
else
{
log.debug("Redirect to " + this.baseURL + actionInfo.redirect);
sendRedirect(response, this.baseURL + actionInfo.redirect, actionInfo.message);
}
}
else
{
sendRedirect(response, "/Chronicle/servlet/at/", "");
}
}
public void killCookie(
HttpServletRequest request,
HttpServletResponse response) {
Cookie c = new Cookie("RegUser", "");
c.setMaxAge(0); //
c.setPath("/Chronicle");
response.addCookie(c);
}
public void logout(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) {
// invalidate session
HttpSession session = request.getSession(true);
String whichtree = (String) session.getAttribute("whichTree");
String client = (String) session.getAttribute("client");
Vector history = (Vector) session.getAttribute("history");
Vector command = (Vector) session.getAttribute("command");
//
session.invalidate();
killCookie(request,response);
//
session = request.getSession(true);
synchronized (session.getId().intern()) { session.setAttribute("whichTree",whichtree); }
synchronized (session.getId().intern()) { session.setAttribute("historyLevel",""); }
synchronized (session.getId().intern()) { session.setAttribute("history", history); }
synchronized (session.getId().intern()) { session.setAttribute("command", command); }
synchronized (session.getId().intern()) { session.setAttribute("client", client); }
}
/**
* deletes orders from the table based on id.
* Creation date: (2/16/2001 11:31:57 AM)
*/
public boolean orderDelete(HttpServletRequest request, HttpServletResponse response) {
String[] checkboxValues = getCheckboxes(request);
Orders order = new Orders();
OrderItems items = new OrderItems();
taskCheckCredit tcc = new taskCheckCredit();
for (int i = 0; i < checkboxValues.length; i++) {
//
order.OrderID = toInt(checkboxValues[i]);
items.OrderID = order.OrderID;
tcc.voidOrder(order.OrderID);
// tcc should kill the order, but in case it don't...
order.DBDelete();
items.DBDelete();
}
//this.message = "";
return true;
}
/**
* Insert the method's description here.
* Creation date: (1/12/2001 9:55:44 AM)
* @@param table java.lang.String
*/
public Vector requestAsRows(HttpServletRequest request, DataClass dC) {
String[] key = dC.getColumns();
Vector rows = new Vector();
boolean stillReading = true;
while (stillReading) {
Hashtable row = new Hashtable();
for (int i = 0; i < key.length; i++) {
String value = request.getParameter(key[i]+(rows.size()+1)); // column1, column2, column...
if (value == null) {
if (dC.isPrimaryKey(key[i])) {
stillReading = false;
}
} else {
row.put(key[i], value);
}
}
if (!row.isEmpty()) rows.add(row);
}
return rows;
}
/**
* called by userInsert & userValidate & cartOrder
* Creation date: (1/12/2001 9:55:44 AM)
* @@param table java.lang.String
*/
public void sendJSResponse(
HttpServletRequest request,
HttpServletResponse response,
String client,
boolean refreshParent,
boolean closeWindow,
boolean setCookie,
boolean switchParentToAdults) {
// unfortunately, this is how i make a global variable for processform
// it must be synced at the end of the method for the next method...
HttpSession session = request.getSession();
ActionInfo actionInfo = (ActionInfo) session.getAttribute("ActionInfo");
RegUsers user = (RegUsers) session.getAttribute("RegUsers");
Orders order = (Orders) session.getAttribute("Orders");
// '
try {
// cannot just redirect, cause we want to set the cookie in the response
//
if (client == null)
client = "HTML";
if (!response.isCommitted()) {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("");
out.close();
//
//System.out.println(user.Email + "\n" + user.FirstName + "\n" + user.Access + "\n" + user.CatSection);
}
} catch (Exception e) {
System.out.println("Redirection error in processForm.sendRedirect.");
//e.printStackTrace();
}
}
// updated 2001.04.26 18:35:06
// add new text
// new postcard URL with part of recipient's address embedded
// wrap URL in
public void sendMail(PostcardSent pc)
throws Exception
{
MimeMessage pcMessage; // postcardsent as a message
javax.mail.Session mailSess = null;
String SMTPHost = this.getAppContext("taskSendNews.SMTPHost", resBundle);
String SMTPUser = this.getAppContext("taskSendNews.SMTPUser", resBundle);
Properties theProps = System.getProperties();
theProps.put("mail.smtp.host", SMTPHost);
theProps.put("mail.smtp.user", SMTPUser);
log.info("Sending postcard email to " + pc.SentTo);
try
{
// fill in headers
mailSess = Session.getDefaultInstance(theProps, null);
pcMessage = new MimeMessage(mailSess);
pcMessage.setRecipients(
Message.RecipientType.TO,
InternetAddress.parse(pc.SentTo, false));
pcMessage.setFrom(
new InternetAddress(
"frontdesk@@chroniclebooks.com",
"Chronicle Book Postcards"));
pcMessage.setSubject(pc.Subject);
pcMessage.setSentDate(new Date());
pcMessage.setReplyTo(
new InternetAddress[] { new InternetAddress(pc.SentBy, pc.FromName) });
// What is a better way to get this name?
String stylesheetName = "PostcardEmailHTML.xsl";
StylesheetRoot style = StylesheetManager.getStylesheet(stylesheetName);
// Now create the DOM element (this is kinda hard-coded at this point)
// Looks like this:
/*