00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef Web_Page_Paragraph_Hpp
00010 #define Web_Page_Paragraph_Hpp
00011
00012
00013 #include "cgiTemplates.h"
00014 #include "read_base.hpp"
00015 #include "ocTypes.h"
00016 #include <vector>
00017
00018
00019 #include "openLogger.h"
00020 #include "openLogin.h"
00021 using namespace std;
00022 typedef long long identifier;
00023 typedef long long llong;
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 class page_paragraph
00125 {
00126 protected:
00127
00128 identifier m_id;
00129 llong m_site_id;
00130 llong m_page_id;
00131 int m_place_order;
00132 string m_template_tag;
00133 string m_replace_tag;
00134 string m_name;
00135 string m_content;
00136
00137
00138 llong m_author;
00139 time_date m_time_authored;
00140 time_date m_time_start;
00141 time_date m_time_end;
00142 bool m_approved;
00143 string m_section;
00144
00145 public:
00146 string editIcon;
00147
00148
00149 page_paragraph():
00150 m_id(0LL),
00151 m_site_id(0LL),
00152 m_page_id(0LL),
00153 m_place_order(0),
00154 m_template_tag(""),
00155 m_replace_tag("$content$"),
00156 m_name(""),
00157 m_content(""),
00158 m_author(0LL),
00159 m_time_authored( ),
00160 m_time_start( ),
00161 m_time_end( ),
00162 m_approved(false),
00163 m_section("")
00164 {
00165 ;
00166 }
00167
00168 virtual ~page_paragraph(){;}
00169
00170 page_paragraph( const page_paragraph & in):
00171 m_id(in.m_id),
00172 m_site_id(in.m_site_id),
00173 m_page_id(in.m_page_id),
00174 m_place_order(in.m_place_order),
00175 m_template_tag(in.m_template_tag),
00176 m_replace_tag(in.m_replace_tag),
00177 m_name(in.m_name),
00178 m_content(in.m_content),
00179 m_author(in.m_author),
00180 m_time_authored(in.m_time_authored),
00181 m_time_start(in.m_time_start),
00182 m_time_end(in.m_time_end),
00183 m_approved(in.m_approved),
00184 m_section(in.m_section)
00185 {
00186 ;
00187 }
00188
00189 page_paragraph & operator = ( const page_paragraph & in )
00190 {
00191 m_id = in.m_id;
00192 m_site_id = in.m_site_id;
00193 m_page_id = in.m_page_id;
00194 m_place_order = in.m_place_order;
00195 m_template_tag = in.m_template_tag;
00196 m_replace_tag = in.m_replace_tag;
00197 m_name = in.m_name;
00198 m_content = in.m_content;
00199 m_author = in.m_author;
00200 m_time_authored = in.m_time_authored;
00201 m_time_start = in.m_time_start;
00202 m_time_end = in.m_time_end;
00203 m_approved = in.m_approved;
00204 m_section = in.m_section;
00205 return *this;
00206 }
00207
00208 void propset( openRS & rs )
00209 {
00210 id(atoll(rs.getField(0).format().c_str()));
00211 site_id(atoll(rs.getField(1).format().c_str()));
00212 page_id(atoll(rs.getField(2).format().c_str()));
00213 place_order(atol(rs.getField(3).format().c_str()));
00214 template_tag(rs.getField(4).format());
00215 replace_tag(rs.getField(5).format());
00216 name(rs.getField(6).format());
00217 content(rs.getField(7).format());
00218 author(atoll(rs.getField(8).format().c_str()));
00219 time_authored(dynamic_cast<dateTimeField&>(rs.getField(9)).get());
00220 time_start(dynamic_cast<dateTimeField&>(rs.getField(10)).get());
00221 time_end(dynamic_cast<dateTimeField&>(rs.getField(11)).get());
00222 approved(rs.getField(12).isNull()||dynamic_cast<longField&>(rs.getField(12)).get()!=0);
00223 section(rs.getField(13).format());
00224 }
00225
00226 string userName( void )
00227 {
00228 string name = "";
00229 if( author() > 0 )
00230 {
00231 openLogin tmpLogin;
00232 ocString ID;
00233 ID.append(author());
00234 if( tmpLogin.getUser(ID) )
00235 {
00236 name = tmpLogin.FullName();
00237 }
00238 }
00239 return name;
00240 }
00241
00242 void emit( paragraphMap & paras, ostream & toBrowser, string replace_tag )
00243 {
00244
00245 paragraphMap::iterator pos;
00246 pos = paras.find(template_tag());
00247 if( pos != paras.end() && approved() )
00248 {
00249 ocString uniqueId = "paragraph_";
00250 uniqueId.append(place_order());
00251 ocString output = pos->second;
00252 toBrowser <<
00253 output.replace( "$id",uniqueId.c_str() )
00254 .replace( replace_tag.c_str(), content().c_str() )
00255
00256 .replace( "$time_authored$", time_authored().format("%b %d %Y %I:%M %p") )
00257 .replace( "$author$", userName() )
00258 ;
00259 }
00260
00261 }
00262
00263
00264
00265 identifier id( void ) { return m_id; }
00266
00267 void id( const identifier in ) { m_id = in; }
00268
00269
00270 llong site_id( void ) { return m_site_id; }
00271
00272 void site_id( const llong in ) { m_site_id = in; }
00273
00274
00275 llong page_id( void ) { return m_page_id; }
00276
00277 void page_id( const llong in ) { m_page_id = in; }
00278
00279
00280 int place_order( void ) { return m_place_order; }
00281
00282 void place_order( const int in ) { m_place_order = in; }
00283
00284
00285 string & template_tag( void ) { return m_template_tag; }
00286
00287 void template_tag( const string & in ) { m_template_tag = in; }
00288
00289
00290 string & replace_tag( void ) { return m_replace_tag; }
00291
00292 void replace_tag( const string & in ) { m_replace_tag = in; }
00293
00294
00295 string & name( void ) { return m_name; }
00296
00297 void name( const string & in ) { m_name = in; }
00298
00299
00300 string & content( void ) { return m_content; }
00301
00302 void content( const string & in ) { m_content = in; }
00303
00304
00305 llong author( void ) { return m_author; }
00306
00307 void author( const llong in ) { m_author = in; }
00308
00309
00310 time_date & time_authored( void ) { return m_time_authored; }
00311
00312 void time_authored( const time_date & in ) { m_time_authored = in; }
00313
00314
00315 time_date & time_start( void ) { return m_time_start; }
00316
00317 void time_start( const time_date & in ) { m_time_start = in; }
00318
00319
00320 time_date & time_end( void ) { return m_time_end; }
00321
00322 void time_end( const time_date & in ) { m_time_end = in; }
00323
00324
00325 bool approved( void ) { return m_approved; }
00326
00327 void approved( const bool in ) { m_approved = in; }
00328
00329
00330 string & section( void ) { return m_section; }
00331
00332 void section( const string & in ) { m_section = in; }
00333
00334
00335 };
00336
00337
00338
00339 typedef vector<page_paragraph> paragraph_vector;
00340
00341 class page_paragraphs : protected ref_base, public paragraph_vector
00342 {
00343 public:
00344 string editIcon;
00345
00346 page_paragraphs(openDB & dbIn):ref_base(dbIn),paragraph_vector()
00347 {
00348 ;
00349 }
00350 ~page_paragraphs()
00351 {
00352 ;
00353 }
00354 string getSQL( long long pgid )
00355 {
00356
00357 ocString sql = "select id,site_id,page_id,place_order,"
00358 "template_tag,replace_tag,name,content,author,time_authored,"
00359 "time_start,time_end,approved,section "
00360 "from metasite.paragraphs where page_id = ";
00361 sql.append( pgid );
00362 sql += " order by section, place_order";
00363 writelog( sql );
00364 return sql;
00365 }
00366
00367 bool load( long long pgid )
00368 {
00369 bool breturn=false;
00370 bool bData;
00371 for( bData=rs.open(getSQL(pgid));bData;bData=rs.next() )
00372 {
00373 page_paragraph pp;
00374 pp.propset(rs);
00375 push_back(pp);
00376 }
00377 rs.close();
00378 return breturn;
00379 }
00380
00381 void emit( paragraphMap & paras, ostream & toBrowser,
00382 ocString templateTags, string replace_tag, string section = "" )
00383 {
00384 paragraph_vector::iterator pos;
00385 for( pos=begin(); pos!=end(); ++pos )
00386 {
00387 if( section.length() )
00388 {
00389 if( section == pos->section() )
00390 {
00391 pos->emit(paras,toBrowser,replace_tag);
00392 }
00393 }
00394 else
00395 {
00396 ocString tags = "," + templateTags + ",";
00397 string testTag = "," + pos->template_tag() + ",";
00398 if( tags.regExMatch( testTag.c_str() ) )
00399 {
00400 pos->emit(paras,toBrowser,replace_tag);
00401 }
00402 }
00403 }
00404 }
00405 };
00406
00407 #endif