00001
00002
00003
00004
00005
00006
00007 #ifndef SUBsublist_base_HPP
00008 #define SUBsublist_base_HPP
00009
00010 #include <iostream>
00011 #include <iomanip>
00012 #include "ocTypes.h"
00013 #include "ocString.h"
00014 #include "read_base.hpp"
00015 #include "cgiClass.h"
00016 #include "cgiTemplates.h"
00017
00018 #define DEBUGOUT
00019
00020
00021 class sublist_base: public read_base
00022 {
00023 protected:
00024 cgiTemplates listTemplate;
00025 ostream & webIO;
00026 ocString td;
00027
00028 public:
00029 bool opened;
00031 ocString editLink;
00033 int hotCol;
00034 int skipCol;
00035 string addedCriteria;
00036
00037
00038
00039 string cookiePrefix;
00040 int recCount, colCount;
00041
00042
00043
00044
00045
00046
00047 sublist_base(ostream&sc):read_base(),webIO(sc),opened(false),hotCol(0),skipCol(-1)
00048 ,recCount(0), colCount(0)
00049 {
00050
00051 }
00052
00053 virtual ~sublist_base()
00054 {
00055 }
00056
00057
00058 bool loadListTemplates( string path )
00059 {
00060 return listTemplate.load(path.c_str());
00061 }
00062
00063 sublist_base & copyListTemplates( const cgiTemplates & in )
00064 {
00065 listTemplate = in;
00066 return * this;
00067 }
00068
00069 bool getData( string sql )
00070 {
00071 opened = rs.open(sql);
00072 if( opened ) recCount = rs.getRecordCount();
00073 return opened;
00074 }
00075
00076
00077 sublist_base & emitHeadings( string pipedelimited )
00078 {
00079 ocString headings(pipedelimited);
00080 string list_begin = listTemplate.getParagraph("list_begin");
00081 string tr = listTemplate.getParagraph("tr");
00082 ocString th = listTemplate.getParagraph("th");
00083 string end_tr = listTemplate.getParagraph("end_tr");
00084 webIO << list_begin << tr;
00085 while( ! headings.endOfParse() )
00086 {
00087 colCount++;
00088 string heading = headings.parse("|");
00089 webIO << th.replace( "$data$", heading.c_str() );
00090 }
00091 webIO << end_tr;
00092 return * this;
00093 }
00094
00095 sublist_base & emitEnd( void )
00096 {
00097 ocString list_end = listTemplate.getParagraph("list_end");
00098 webIO << list_end;
00099 return * this;
00100 }
00101
00102 void setColFormat( string fmt, int pos )
00103 {
00104 if( pos < rs.getFieldCount() )
00105 {
00106 rs.getField(pos).setFormatMask(fmt);
00107 }
00108 }
00109
00110 sublist_base & emitData( void )
00111 {
00112 bool more_data = opened;
00113 string tr = listTemplate.getParagraph("tr");
00114 td = listTemplate.getParagraph("td");
00115 string end_tr = listTemplate.getParagraph("end_tr");
00116 int fieldCount;
00117 if( opened ) fieldCount = rs.getFieldCount();
00118 derived_commence_event();
00119 while( more_data )
00120 {
00121 if(derived_predata_event())
00122 {
00123 webIO << tr;
00124 for( int i=0; i < fieldCount; ++i )
00125 {
00126 if( i != skipCol && (i == hotCol || hotCol == -2) )
00127 {
00128 sendHotField(i, td );
00129 }
00130 else if( i != skipCol )
00131 {
00132 sendField(i, td );
00133 }
00134 }
00135 webIO << end_tr;
00136 }
00137 derived_data_event();
00138 more_data = rs.next();
00139 }
00140 derived_complete_event();
00141 return * this;
00142 }
00143
00144
00145 virtual void sendField( int iField, ocString & td )
00146 {
00147 webIO << td.replace( "$data$", rs.getField(iField).format().c_str() );
00148 }
00149
00150
00151 virtual void sendHotField( int iField, ocString & td )
00152 {
00153 webIO << td.replace( "$data$",
00154 editLink.replaceAll( "$key$",rs.getField(0).format().c_str())
00155 .replaceAll( "$col$",rs.getField(iField).format().c_str()).c_str());
00156 }
00157
00158
00159 virtual void derived_commence_event( void ){;}
00160 virtual bool derived_predata_event( void ){return true; }
00161 virtual void derived_data_event( void ){;}
00162 virtual void derived_complete_event( void ){;}
00163 };
00164
00165 #endif