00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <iostream>
00012 #include <iomanip>
00013 #include "cgiTemplates.h"
00014 #include "connectstring"
00015 #include "forms.h"
00016 #include "ocTypes.h"
00017 #include "ocString.h"
00018 #include "cgiTemplates.h"
00019
00020 #include "Category.hpp"
00021 #include "list_base.hpp"
00022 #include "forms_base.hpp"
00023
00024 #include "openLogin.h"
00025
00026 #include "richForm.hpp"
00027 using namespace std;
00028 openLogin oLogin;
00029
00030 class Category_List: public list_base
00031 {
00032 public:
00033 cgiTemplates movemap;
00034 string Id, Display_Order;
00035 long Display_Level;
00036
00037 Category_List(cgiScript&sc):list_base(sc)
00038 {
00039 movemap.load("Templates/map.htm");
00040 }
00041 ~Category_List(){;}
00042
00043 bool list_display( void )
00044 {
00045 bool breturn = true;
00046 editLink = "($ORDER$) <a target='_self' href='$prog$?Id=$key$'>$col$</a>";
00047 editLink = editLink.replace("$prog$","Category_ui.cgi");
00048 hotCol=3;
00049 ocString sql = "select Id, Display_Order, Display_Level, Name from Category ";
00050 sql += " order by Display_Order";
00051
00052 getData(sql);
00053 emitData();
00054 emitEnd();
00055 return breturn;
00056
00057 }
00058
00059 virtual void sendField( int iField, ocString & td )
00060 {
00061
00062 if(iField==0)
00063 {
00064 Id=rs.getField(iField).format();
00065 }
00066 if(iField==1)
00067 {
00068 Display_Order=rs.getField(iField).format();
00069 }
00070 if(iField==2)
00071 {
00072 Display_Level=atol(rs.getField(iField).format().c_str());
00073 }
00074 }
00075
00076
00077 virtual void sendHotField( int iField, ocString & td )
00078 {
00079 ocString moveMap = movemap.getParagraph("movemap");
00080 ocString level;
00081 level.append(Display_Level*30);
00082 webIO << moveMap.replaceAll("miid",Id.c_str())
00083 .replace( "$LEVEL$", level.c_str() )
00084 << td.replace( "$data$",
00085 editLink.replace("$ORDER$", Display_Order.c_str() )
00086 .replaceAll( "$key$", Id.c_str() )
00087 .replaceAll( "$col$", rs.getField(iField).format().c_str() ).c_str());
00088 }
00089 };
00090
00091 class Product_Categories_List: public list_base
00092 {
00093
00094 public:
00095 ocString Category_Id;
00096
00097 Product_Categories_List(cgiScript&sc):list_base(sc){;}
00098 ~Product_Categories_List(){;}
00099
00100 bool list_display( void )
00101 {
00102 bool breturn = true;
00103 string sql = "select pc.Id, p.Name as Product, pc.Leading_Text "
00104 "from Product_Categories pc inner join "
00105 "Product p on p.Id = pc.Product where pc.Category = " ;
00106 sql += Category_Id;
00107 sql += " order by Position";
00108 hotCol=-2;
00109 editLink = listTemplate.getParagraph("hotcolumn");
00110 editLink = editLink.replace("$prog$","Product_Categories_ui.cgi");
00111 string heading = "Id|Product|Leading_Text";
00112
00113 emitHeadings(heading);
00114
00115 getData( sql );
00116 emitData();
00117 ocString list_new = listTemplate.getParagraph("list_new");
00118 ocString url = "Product_Categories_ui.cgi?Category=";
00119 url += Category_Id;
00120 webIO << list_new.replace("$location",url.c_str()).replace("$item","Product Listing");
00121 emitEnd();
00122 return breturn;
00123 }
00124 };
00125
00126 class Category_form: public Category_Obj, public richForm
00127 {
00128 public:
00129 Category_form(cgiScript & script):Category_Obj(),richForm(script){setKey(*this);}
00130 virtual ~Category_form(){;}
00131
00132 void form_id_transfer( void )
00133 {
00134 llongFXfer( "Id", Id );
00135 }
00136 void form_data_transfer( void )
00137 {
00138
00139 stringFXfer( "Name", Name);
00140 intFXfer( "Display_Order", Display_Order);
00141 intFXfer( "Display_Level", Display_Level);
00142 stringFXfer( "Description", Description);
00143 stringFXfer( "Base_URL", Base_URL);
00144 }
00145
00146 bool dbf_action( string mode, changeMap & changes )
00147 {
00148
00149
00150 if( mode=="i" || mode=="u" )
00151 {
00152 Description=htmlDecode(Description);
00153 changes["Description"]="Description";
00154 }
00155 return db_action( mode, changes );
00156 }
00157
00158
00159 bool form_display( void )
00160 {
00161 bool breturn = true;
00162 ocString sql;
00163
00164 script << makeTop("Category_ui.cgi", "Category")
00165 << formTemplate.getParagraph("advanced_begin");
00166 script << makeStaticBox("Id", "Id", Id ,"8");
00167 script << "<br class='clearall'>" << endl;
00168
00169 script << "<br class='clearall'>" << endl;
00170
00171 script << makeTextBox("Display_Level", "Display_Level", Display_Level ,"8","8");
00172 script << "<br class='clearall'>" << endl;
00173 script << makeTextBox("Base URL", "Base_URL", Base_URL ,"125","35");
00174 script << "<br class='clearall'>" << endl;
00175 script << "<div style='font-size:7pt; color:#427; background: "
00176 "#fffff0; border:#427 solid 1px; margin:5 100px;'>"
00177 "The base url has the effect of <em>'mounting'</em> this node of "
00178 "the category list and this nodes children to the base url... "
00179 "The base url can be gotten from the URL field of the page editor.</div>" << endl;
00180 script << formTemplate.getParagraph("advanced_end");
00181
00182 script << makeTextBox("Name", "Name", Name ,"125", "25");
00183 script << "<br class='clearall'>" << endl;
00184 script << makeTextBox("Display Order", "Display_Order", Display_Order ,"8","8");
00185
00186
00187
00188 Description = htmlFixup( Description );
00189 string cedit = makeHiddenBox( "Description", Description );
00190 cedit += "<a href=\"javascript:jopen( 'richPopUpEditor.html?control=Description', 'scrollbars,resizable,width=730,height=510', 'rich' )\">";
00191 cedit += "Edit</a>";
00192 ocString ctrlGrp = formTemplate.getParagraph("control_group");
00193 script << ctrlGrp.replace("$label$","Description")
00194 .replace("$control$", cedit.c_str());
00195
00196
00197 script << "<br class='clearall'>" << endl;
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 script << makeButtons( key() );
00220 if( key() )
00221 {
00222 Product_Categories_List pcList(script);
00223 pcList.Category_Id.append(key());
00224 pcList.loadListTemplates("Templates/poplist.htmp");
00225 script << "<h5>Products attached to this category:</h5>" << endl;
00226 pcList.list_display();
00227
00228 }
00229 script << makeBottom( m_result ) << endl;
00230 return breturn;
00231 }
00232 };
00233
00234
00235 int main( int argcount, char ** args )
00236 {
00237 cgiScript script( "text/html", false );
00238 Category_form myFrm(script);
00239 Category_List mylist(script);
00240 if( oLogin.testLoginStatus() )
00241 {
00242 script.closeHeader();
00243 cgiTemplates pgTemplate;
00244 pgTemplate.load("Templates/adminPane.htmp");
00245 script << ocString(pgTemplate.getParagraph("top"))
00246 .replace( "// More Functions?",
00247 "</SCRIPT><SCRIPT type=\"text/javascript\" src=\"catalogmanip.js\"></SCRIPT>" );
00248
00249 myFrm.loadControlTemplates("Templates/divform.htmp");
00250 myFrm.form_action();
00251 myFrm.form_display();
00252
00253 mylist.loadListTemplates("Templates/divlist.htmp");
00254 mylist.list_display();
00255
00256 ocString end = pgTemplate.getParagraph("bottom");
00257 script << end;
00258 }
00259 else
00260 {
00261 script.Redirect("signIn.html");
00262 }
00263 }
00264
00265 #include "read_write_base.cpp"
00266 #include "forms_base.cpp"
00267