00001
00002
00003
00004
00005 #ifndef PROOFS_HPP
00006 #define PROOFS_HPP
00007 #include "read_base.hpp"
00008
00009 typedef vector<string> lines;
00010
00011
00012
00013
00014 #include "../admin/Product.hpp"
00015 #include "../admin/Ordered_Item.hpp"
00016 #include "../admin/Size_Price.hpp"
00017 #include "../admin/Style.hpp"
00018 #include "../admin/ItemDetail.hpp"
00019 class proofs : public read_base
00020 {
00021 protected:
00022 ocString sql;
00023 cgiTemplates tmplt;
00024 public:
00025 ocString o, oi, m;
00026 bool isTemplateLoaded;
00027
00028 proofs():read_base(),isTemplateLoaded(false)
00029 {
00030 isTemplateLoaded = tmplt.load("Templates/order.html");
00031 }
00032
00033 ~proofs()
00034 {
00035 ;
00036 }
00037
00038 void setArgs( cgiScript & script )
00039 {
00040 cgiInput & inputArgs = script.ClientArguments();
00041 if( inputArgs.count("o") )
00042 {
00043 o = inputArgs["o"].c_str();
00044 }
00045 if( inputArgs.count("oi") )
00046 {
00047 oi = inputArgs["oi"].c_str();
00048 }
00049 if( inputArgs.count("m") )
00050 {
00051 m = inputArgs["m"].c_str();
00052 }
00053 }
00054
00055 void emit( cgiScript & script )
00056 {
00057 if( oi.length() )
00058 {
00059
00060 showOrderedItem( script );
00061 }
00062 else if( o.length() )
00063 {
00064
00065 showOrderedItems( script );
00066 }
00067 else
00068 {
00069 script << "<h1><br>I don't know what you want!<br></h1>";
00070 }
00071
00072 }
00073
00074 void showDesign( ostream & ostrm )
00075 {
00076 if(isTemplateLoaded)
00077 {
00078 Ordered_Item_Obj oio;
00079 oio.key( atoll(oi.c_str()) );
00080 bool opened = oio.get_data();
00081
00082 if( opened )
00083 {
00084 ItemDetail detail;
00085 detail = oio;
00086
00087 ocString Real_Height, Real_Width, Design_No;
00088
00089 Real_Width.append( atof(detail.Width().replaceAll("'","").c_str()) * 12 );
00090 Real_Height.append( atof(detail.Height().replaceAll("'","").c_str()) * 12 );
00091
00092 ocString Id;
00093 Id.append(detail.Design());
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 sql = "select Id , Pixel_Height , Pixel_Width , "
00107 "Text_Top_Left_X , Text_Top_Left_Y , Text_Bot_Right_X , Text_Bot_Right_Y , "
00108 "Pattern_Image from Designer where Product_Id = ";
00109
00110 sql.append(detail.Product());
00111 sql += " and Size = ";
00112 sql.append(detail.Size());
00113 sql += " and Style = ";
00114 sql.append(detail.Style());
00115 sql += " and Orientation = '";
00116 sql.append(detail.Orientation());
00117 sql += "'";
00118
00119 opened = rs.open(sql);
00120
00121 if( opened )
00122 {
00123 string Design = rs.getField("Id").format();
00124 ocString form = tmplt.getParagraph("proofmid");
00125 ostrm << tmplt.getParagraph("prooftop");
00126 ostrm << "myDesigner = new designer(" << detail.LinesCustomText() << ");" << endl;
00127
00128
00129 ostrm << "myDesigner.addDesign('" <<
00130 Design << "', '" <<
00131 detail.Design_No() << "','" <<
00132 rs.getField("Pattern_Image").format() << "'," <<
00133 Real_Width << "," <<
00134 Real_Height << "," <<
00135 rs.getField("Pixel_Width").format() << "," <<
00136 rs.getField("Pixel_Height").format() << "," <<
00137 rs.getField("Text_Top_Left_X").format() << "," <<
00138 rs.getField("Text_Top_Left_Y").format() << "," <<
00139 rs.getField("Text_Bot_Right_X").format() << "," <<
00140 rs.getField("Text_Bot_Right_Y").format() << ");" << endl;
00141
00142 rs.close();
00143
00144
00145 sql = "select Name, External_Id from Font where Name = '";
00146 sql += detail.Font();
00147 sql +="'";
00148
00149 if(rs.open(sql))
00150 {
00151
00152 ostrm << "myDesigner.addFont('"
00153 << rs.getField("Name").format() << "','"
00154 << rs.getField("External_Id").format() << "');" << endl;
00155 rs.close();
00156 }
00157
00158 sql = "select Name, RGB, Image "
00159 "from Color where Name = '";
00160 sql += detail.Background();
00161 sql +="'";
00162
00163 opened = rs.open(sql);
00164
00165 if(opened)
00166 {
00167 ostrm << "myDesigner.addBackground('"
00168 << rs.getField("RGB").format()
00169 << "','"
00170 << rs.getField("Image").format()
00171 << "','"
00172 << rs.getField("Name").format()
00173 << "');" << endl;
00174
00175 rs.close();
00176 }
00177
00178 sql = "select Name,RGB,Image "
00179 "from Color where Name = '";
00180 sql += detail.Textcolor();
00181 sql +="'";
00182 opened = rs.open(sql);
00183
00184 if(opened)
00185 {
00186 ostrm << "myDesigner.addColor('" << rs.getField("RGB").format() << "','"
00187 << rs.getField("Image").format() << "','"
00188 << rs.getField("Name").format() << "');" << endl;
00189 rs.close();
00190 }
00191
00192 ostrm << "myDesigner.addFontSize( myDesigner.designs['"<<Design<<"'].pointsToPixels("
00193 << detail.FontSize() << "), " << detail.FontSize() << " );" << endl;
00194 ostrm << "myDesigner.setProof();";
00195 ostrm << form.replaceAll("$id$",Id).replace("$label",detail.ProductName().c_str());
00196
00197 ostrm << detail.CustomText().replaceAll("\n","<br>\n") << endl;
00198
00199 ostrm << tmplt.getParagraph("proofend");
00200 }
00201 }
00202 }
00203 else
00204 {
00205 ostrm << "<h1>TEMPLATE NOT LOADED</h1>" << endl;
00206 }
00207
00208 }
00209
00210 void showOrderedItem( ostream & ostrm )
00211 {
00212 ocString prodTemplate = tmplt.getParagraph("order_detail");
00213 Ordered_Item_Obj oio;
00214 oio.key( atoll(oi.c_str()) );
00215 bool opened = oio.get_data();
00216
00217 if( opened )
00218 {
00219 ItemDetail dtl;
00220 dtl = oio;
00221
00222 bool isDesignerMode = dtl.IsDesigner();
00223
00224 if( isDesignerMode )
00225 {
00226 showDesign(ostrm);
00227 }
00228 else
00229 {
00230 ocString linked = "Order: ";
00231 linked.append(oio.Order_Id);
00232 linked += " : ";
00233 if( m.length() )
00234 {
00235 linked.append( dtl.Design_No() );
00236 linked += " : ";
00237 }
00238 linked += dtl.ProductName();
00239 ocString textual = dtl.CustomText();
00240 textual = textual.replaceAll("\n","<br>\n");
00241
00242 ocString count; count.append(dtl.Count());
00243 ostrm << prodTemplate.replaceAll("$title$",linked.c_str())
00244 .replaceAll("$image$",dtl.StyleImage())
00245 .replaceAll("$style$",dtl.StyleName())
00246 .replace("$width$",dtl.Width())
00247 .replace("$height$",dtl.Height())
00248 .replace("$orientation$",dtl.Orientation())
00249 .replace("$text$",textual)
00250 .replace("$count$",count)
00251 ;
00252
00253
00254 }
00255 rs.close();
00256 }
00257
00258 }
00259
00260 void showOrderedItems( ostream & ostrm, llong mfrId = 0 )
00261 {
00262 ocString topTemplate = tmplt.getParagraph("order_top");
00263 ocString linkTemplate = tmplt.getParagraph("proof_link");
00264
00265 sql = "select Order_Date from Ordered where Id = ";
00266 sql += o;
00267 bool opened = rs.open(sql);
00268 if( opened )
00269 {
00270 ostrm << topTemplate.replace("$order$",o.c_str()).replace("$date$",rs.getField(0).format());
00271 rs.close();
00272
00273 Ordered_Item_Obj oitem;
00274 ocString clause = " Order_Id = " + o;
00275
00276 opened = oitem.get_data(clause);
00277 if( opened )
00278 {
00279
00280 string prepend = (m.length()>0)?"manufacturer":"consumer";
00281 ostrm << tmplt.getParagraph((prepend+"_list_head").c_str());
00282 ocString dtaTemplate = tmplt.getParagraph(prepend+"_list_data");
00283
00284 do
00285 {
00286 ItemDetail detail;
00287 detail = oitem;
00288
00289 if( mfrId == 0 || mfrId == detail.Manufacturer() )
00290 {
00291 ocString oid; oid.append(oitem.Id);
00292 ocString textual = detail.CustomText();
00293 textual = textual.replaceAll("\n","<br>\n");
00294 string linked = linkTemplate.replace("$oi",oid)
00295 .replace("$name",(m.length()>0)?
00296 detail.Design_No():detail.ProductName());
00297
00298 ocString count; count.append(detail.Count());
00299 ostrm << dtaTemplate
00300 .replace("Design",linked.c_str())
00301 .replace("Count",count)
00302 .replace("Width",detail.Width())
00303 .replace("Height",detail.Height())
00304 .replace("Orientation",detail.Orientation())
00305 .replace("Font",detail.Font())
00306 .replace("Background",detail.Background())
00307 .replace("TextColor",detail.Textcolor())
00308 .replace("PointSize",detail.FontSize())
00309 .replace("CustomText",textual);
00310 }
00311 } while( oitem.next() );
00312
00313 ostrm << tmplt.getParagraph("list_end");
00314
00315 }
00316 else
00317 {
00318 ostrm << sql;
00319 }
00320
00321 }
00322 }
00323
00324 };
00325
00326 #endif