00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <iostream>
00015 #include <iomanip>
00016 #include "cgiTemplates.h"
00017 #include "connectstring"
00018 #include "forms.h"
00019 #include "ocTypes.h"
00020 #include "ocString.h"
00021 #include "cgiTemplates.h"
00022
00023 #include "read_write_base.hpp"
00024 #include "list_base.hpp"
00025 #include "forms_base.hpp"
00026 #include "richForm.hpp"
00027 #include "Product.hpp"
00028 #include "openLogin.h"
00029 #include "sublist_base.hpp"
00030
00031 using namespace std;
00032 openLogin oLogin;
00033 class Style_List: public sublist_base
00034 {
00035
00036 public:
00037 ocString Parent_Id;
00038
00039 Style_List(cgiScript&sc):sublist_base(sc){;}
00040 ~Style_List(){;}
00041
00042 bool list_display( void )
00043 {
00044 bool breturn = true;
00045 string sql = "select Id, "
00046 "Name, "
00047 "Image, "
00048 "Manufacturer_Design_No "
00049 "from Style where Product = " ;
00050 sql += Parent_Id;
00051 hotCol=-2;
00052
00053 editLink = "<a href=\"javascript:jopen('$prog$?Id=$key$')\">$col$</a>";
00054
00055 editLink = editLink.replace("$prog$","Style_ui.cgi");
00056 string heading = "Id|"
00057 "Name|"
00058 "Image|"
00059 "Manufacturer_Design_No";
00060 emitHeadings(heading);
00061 getData( sql );
00062 emitData();
00063 ocString list_new = listTemplate.getParagraph("list_new");
00064 ocString url = "Style_ui.cgi?Product=";
00065 url += Parent_Id;
00066 webIO << list_new.replace("$location",url.c_str()).replace("$cols","5");
00067 emitEnd();
00068 return breturn;
00069 }
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 };
00087
00088 class Product_List: public list_base
00089 {
00090
00091 public:
00092
00093 Product_List(cgiScript&sc):list_base(sc)
00094 {
00095 itemsPerPg=50;
00096 }
00097 ~Product_List(){;}
00098
00099 bool list_display( void )
00100 {
00101 bool breturn = true;
00102
00103 hotCol=-2;
00104 editLink = listTemplate.getParagraph("hotcolumn");
00105 editLink = editLink.replace("$prog$","Product_ui.cgi");
00106 emitFilter( "Product_ui.cgi",
00107 " <B>FILTER (by Name)</B>" );
00108 string heading =
00109 "<a class='sortcol' href='Product_ui.cgi?sort=Id'>p.Id</a>|"
00110 "<a class='sortcol' href='Product_ui.cgi?sort=pl.Name'>Product Line</a>|"
00111 "<a class='sortcol' href='Product_ui.cgi?sort=p.Name'>Name</a>|"
00112 "<a class='sortcol' href='Product_ui.cgi?sort=p.Lines_Custom_Text'>Lines Custom Text</a>|"
00113 "<a class='sortcol' href='Product_ui.cgi?sort=p.SKU'>SKU</a>"
00114 ;
00115 emitHeadings(heading);
00116 getFilteredData( "p.Id, "
00117 "pl.Name, "
00118 "p.Name, "
00119 "p.Lines_Custom_Text, "
00120 "p.SKU "
00121 ,"Product p inner join Product_Line pl on p.Product_Line = pl.Id",
00122 "p.Name like '$filter$%'" );
00123 emitData();
00124 emitNavigation("Product_ui.cgi");
00125 emitEnd();
00126 return breturn;
00127 }
00128
00129 };
00130
00131
00132
00133
00134
00135
00136 class Product_form: public Product_Obj, public richForm
00137 {
00138 private:
00139
00140 bool setAttributes( string Table, string LeftId, string RightId, ocString values )
00141 {
00142 bool bRet = false;
00143
00144 if( values.length() )
00145 {
00146 ocString sql;
00147 ocString sqlStart = "insert into " + Table + " (" +LeftId+ ", " +RightId+ " ) values (";
00148 sqlStart.append(Id);
00149 sqlStart += ",";
00150 values.parseInit();
00151 while( !values.endOfParse() )
00152 {
00153 sql = sqlStart;
00154 sql += values.parse("|");
00155 sql += ")";
00156
00157 bRet = cmd.execute(sql);
00158 if(!bRet) break;
00159 }
00160 bRet = true;
00161 }
00162 return bRet;
00163 }
00164
00165
00166 bool deleteAttributes( string Table, string LeftId )
00167 {
00168 bool bRet = false;
00169 ocString sql = "delete from " +Table+ " where " +LeftId+ " = ";
00170 sql.append(Id);
00171 bRet = cmd.execute(sql);
00172 return bRet;
00173 }
00174
00175
00176 bool retrieveAttributes( string Table, string LeftId, string RightId, string & values )
00177 {
00178 bool bRet = false;
00179 values = "";
00180 ocString sql = "select " +RightId+ " from " +Table+ " where " +LeftId+ " = ";
00181 sql.append(Id);
00182 if( rs.open(sql) )
00183 {
00184 bRet = true;
00185 bool moreData = true;
00186 do
00187 {
00188 values += rs.getField(0).format();
00189 moreData = rs.next();
00190 if( moreData ) values += "|";
00191 }
00192 while( moreData );
00193 }
00194 return bRet;
00195 }
00196 protected:
00197
00198
00199 string sizes, fonts, colors, backgrounds;
00200
00201
00202 public:
00203 bool isupplemental( void )
00204 {
00205 bool bRet = true;
00206 bRet = setAttributes("Product_Sizes", "Product", "Size", sizes);
00207
00208 return bRet;
00209 }
00210
00211 bool usupplemental( changeMap & changes )
00212 {
00213 bool bRet=true;
00214 if( changes.count("Product_Sizes") > 0 )
00215 {
00216 if( deleteAttributes("Product_Sizes", "Product") )
00217 bRet &= setAttributes("Product_Sizes", "Product", "Size", sizes);
00218 }
00219 if( changes.count("Product_Fonts") > 0 )
00220 {
00221 if( deleteAttributes("Product_Fonts", "Product") )
00222 bRet &= setAttributes("Product_Fonts", "Product", "Font", fonts);
00223 }
00224 if( changes.count("Product_Colors") > 0 )
00225 {
00226 if( deleteAttributes("Product_Colors", "Product") )
00227 bRet &= setAttributes("Product_Colors", "Product", "Color", colors);
00228 }
00229 if( changes.count("Product_Backgrounds") > 0 )
00230 {
00231 if( deleteAttributes("Product_Backgrounds", "Product") );
00232 bRet &= setAttributes("Product_Backgrounds", "Product", "Color", backgrounds);
00233 }
00234 return bRet;
00235 }
00236 bool ssupplemental( void )
00237 {
00238 bool bret = true;
00239 retrieveAttributes("Product_Sizes", "Product", "Size", sizes);
00240 retrieveAttributes("Product_Fonts", "Product", "Font", fonts);
00241 retrieveAttributes("Product_Colors", "Product", "Color", colors);
00242 retrieveAttributes("Product_Backgrounds", "Product", "Color", backgrounds);
00243 return bret;
00244 }
00245 Product_form(cgiScript & script):Product_Obj(),richForm(script){setKey(*this);}
00246 virtual ~Product_form(){;}
00247
00248 void form_id_transfer( void )
00249 {
00250 llongFXfer( "Id", Id );
00251 }
00252 void form_data_transfer( void )
00253 {
00254 llongFXfer( "Product_Line", Product_Line);
00255 stringFXfer( "Name", Name);
00256 stringFXfer( "Product_Sizes", sizes);
00257
00258 stringFXfer( "Product_Fonts", fonts);
00259 stringFXfer( "Product_Colors",colors );
00260 stringFXfer( "Product_Backgrounds", backgrounds);
00261
00262 stringFXfer( "Description", Description);
00263 intFXfer( "Lines_Custom_Text", Lines_Custom_Text);
00264 stringFXfer( "SKU", SKU);
00265 boolFXfer( "Designer", Designer);
00266 llongFXfer( "Manufacturer", Manufacturer);
00267 }
00268
00269 bool dbf_action( string mode, changeMap & changes )
00270 {
00271 if( mode=="i" || mode=="u" )
00272 { Description=htmlDecode(Description);
00273 changes["Description"]="Description";
00274 }
00275 return db_action( mode, changes );
00276 }
00277
00278
00279 bool form_display( void )
00280 {
00281 bool breturn = true;
00282 ocString sql;
00283
00284 script << makeTop("Product_ui.cgi", "Product")
00285 << formTemplate.getParagraph("advanced_begin");
00286 script << makeStaticBox("Id", "Id", Id ,"8");
00287 script << "<br class='clearall'>" << endl;
00288 script << formTemplate.getParagraph("advanced_end");
00289
00290 sql = "Select Id, Name from Product_Line";
00291 script << makeComboBox("Product Line", "Product_Line", Product_Line ,sql);
00292 script << "<br class='clearall'>" << endl;
00293
00294
00295
00296
00297
00298 if( key() )
00299 {
00300 Style_List cList(script);
00301 cList.Parent_Id.append(key());
00302 cList.loadListTemplates("Templates/spawninglist.htmp");
00303 script << "<h5>Styles:</h5>" << endl;
00304 cList.list_display();
00305 }
00306
00307
00308 script << "<br class='clearall'>" << endl;
00309 script << makeTextBox("Name", "Name", Name ,"125","35");
00310 script << "<br class='clearall'>" << endl;
00311
00312
00313 Description = htmlFixup( Description );
00314 string cedit = makeHiddenBox( "Description", Description );
00315 cedit += "<a href=\"javascript:jopen( 'richPopUpEditor.html?control=Description', 'scrollbars,resizable,width=730,height=510', 'rich' )\">";
00316 cedit += "Edit</a>";
00317
00318 ocString ctrlGrp = formTemplate.getParagraph("control_group");
00319
00320 script << ctrlGrp.replace("$label$","Description")
00321 .replace("$control$", cedit.c_str());
00322
00323 script << makeComboBox( "Sizes","Product_Sizes",sizes,
00324 "select s.Id, concat(s.X, 'x', s.Y, u.Abbreviation, ' ', pl.Name ) from "
00325 "Size_Price s inner join Unit u on s.Units = u.Id "
00326 " inner join Product_Line pl on s.Product_Line = pl.Id",
00327 "", " multiple='multiple' size='6'" );
00328
00329
00330 script << "<br class='clearall'>" << endl;
00331 script << makeTextBox("Lines Custom Text", "Lines_Custom_Text", Lines_Custom_Text ,"8","8");
00332 script << "<br class='clearall'>" << endl;
00333 script << makeTextBox("SKU", "SKU", SKU ,"125","35");
00334 script << "<br class='clearall'>" << endl;
00335
00336 sql = "Select Id, Name from Manufacturer";
00337 script << makeComboBox("Manufacturer", "Manufacturer", Manufacturer ,sql);
00338 script << "<br class='clearall'>" << endl;
00339
00340
00341 ocString DesignerProg = "Designer_ui.cgi?Product_Id=";
00342 DesignerProg.append(Id);
00343 script << makeBoolBox("Designer", "Designer", Designer );
00344 if(Designer)
00345 {
00346 script << " <a href=\"javascript:addChild('"+DesignerProg+"','', '' )\">Designer Form</a>";
00347 script << "<br class='clearall'>" << endl;
00348 script << "<br class='clearall'>" << endl;
00349 script << makeComboBox( "Fonts","Product_Fonts",fonts,
00350 "select Id, Name from Font",
00351 "", " multiple='multiple' size='6'" );
00352
00353 script << makeComboBox( "Colors","Product_Colors",colors,
00354 "select Id, Name from Color" ,
00355 "", " multiple='multiple' size='6'" );
00356
00357 script << makeComboBox( "Backgrounds","Product_Backgrounds",backgrounds,
00358 "select Id, Name from Color",
00359 "", " multiple='multiple' size='6'" );
00360 }
00361 script << "<br class='clearall'>" << endl;
00362
00363
00364
00365 script << makeButtons( key() );
00366 script << makeBottom( m_result ) << endl;
00367 return breturn;
00368 }
00369 };
00370
00371
00372 int main( int argcount, char ** args )
00373 {
00374 cgiScript script( "text/html", false );
00375 Product_form myFrm(script);
00376 Product_List mylist(script);
00377 if( oLogin.testLoginStatus() )
00378 {
00379 script.closeHeader();
00380 cgiTemplates pgTemplate;
00381 pgTemplate.load("Templates/adminPane.htmp");
00382
00383 script << ocString(pgTemplate.getParagraph("top"))
00384 .replaceAll("$heading$","Product");
00385
00386 myFrm.loadControlTemplates("Templates/divform.htmp");
00387 myFrm.form_action();
00388 myFrm.form_display();
00389
00390 mylist.loadListTemplates("Templates/list.htmp");
00391 mylist.list_display();
00392
00393 ocString end = pgTemplate.getParagraph("bottom");
00394 script << end;
00395 }
00396 else
00397 {
00398 script.Redirect("signIn.html");
00399 }
00400 }
00401
00402 #include "read_write_base.cpp"
00403 #include "forms_base.cpp"
00404