00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "shoppingCart.hpp"
00014 #include "cgiTemplates.h"
00015
00016 int main( int iCount, char ** pchArgs )
00017 {
00018
00019 cgiScript script( "text/html", false);
00020 cgiTemplates htemplate;
00021 htemplate.load("Templates/ShoppingCart.html");
00022
00023
00024 uiShoppingCart cart( script );
00025 script.closeHeader();
00026
00027
00028 cgiInput & args = script.ClientArguments ();
00029
00030
00031
00032 if( args.count("action") )
00033 {
00034 string productId;
00035 if(args.count("p"))
00036 productId=args["p"].c_str();
00037
00038 string count;
00039 if(args.count("qty"))
00040 count=args["qty"].c_str();
00041 if(args.count("count"))
00042 count=args["count"].c_str();
00043
00044 if( args["action"] == "add" )
00045 {
00046 string options;
00047
00048 if(args.count("style"))
00049 options+=string("style=")+args["style"].c_str()+";";
00050 if(args.count("size"))
00051 options+=string("size=")+args["size"].c_str()+";";
00052 if(args.count("orientation"))
00053 options+=string("orientation=")+args["orientation"].c_str()+";";
00054 if(args.count("font"))
00055 options+=string("font=")+args["font"].c_str()+";";
00056 if(args.count("fontsize"))
00057 options+=string("fontsize=")+args["fontsize"].c_str()+";";
00058 if(args.count("background"))
00059 options+=string("background=")+args["background"].c_str()+";";
00060 if(args.count("textcolor"))
00061 options+=string("textcolor=")+args["textcolor"].c_str();
00062
00063
00064 string keyBase="line";
00065 ocString key = "line1";
00066 string lines;
00067 int linNo=1;
00068
00069
00070 while( args.count(key.c_str()) )
00071 {
00072 lines += args[key.c_str()].c_str();
00073 lines += "\n";
00074 key=keyBase;
00075 key.append(++linNo);
00076 }
00077
00078 cart.AlwaysAddProduct( productId, count,
00079 options,
00080 lines,
00081 120 );
00082
00083
00084 script << "<script type='text/javascript'>"
00085 "var loco='" << script.HttpReferer() << "&p="
00086 << productId << "&crtid="
00087 << cart.Id << "';"
00088 "location.href = loco"
00089 "</script>";
00090
00091 }
00092 else if( args["action"] == "update" )
00093 {
00094
00095 if( args.count("p") && args.count("seq"))
00096 {
00097 string productId = args["p"].c_str();
00098 string count = "0";
00099 if( args.count("qty") )
00100 {
00101 count=args["qty"].c_str();
00102 if( atol( count.c_str()) < 0 )
00103 {
00104 count = "0";
00105 }
00106 }
00107 int node=atol(args["seq"].c_str());
00108
00109 script << "cart.UpdateProduct(" << productId <<", " << count << ", " << node << ")" << endl;
00110 cart.UpdateProduct( productId, count,
00111 "",
00112 "",
00113 node );
00114
00115 script << "<script type='text/javascript'>"
00116 "var loco='" << script.HttpReferer() << "';"
00117 "location.href = loco"
00118 "</script>";
00119 }
00120 }
00121 }
00122
00123
00124 cart.stats();
00125 string checkoutMsg = "Check Out";
00126 ocString itemCount;
00127 itemCount.append(cart.items);
00128 if( cart.items == 0 )
00129 {
00130 checkoutMsg = "";
00131 }
00132 ocString qs = "?crtid=";
00133 qs.append(cart.Id);
00134 ocString content = htemplate. getUnparsedHtml();
00135 script << content. replace("$cnt", itemCount.c_str())
00136 . replace("$CheckOut", checkoutMsg.c_str())
00137 . replace("$url",CHECKOUT)
00138 . replace("?qs",qs.c_str() );
00139 return 0;
00140 }
00141
00142
00143 #include "read_write_base.cpp"