00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef Page_Enhancements_Hpp
00011 #define Page_Enhancements_Hpp
00012 #include <sstream>
00013 #include "ocString.h"
00014 #include "ocXML.h"
00015
00016
00017
00018
00019
00020
00021 class qrystr_content_functor: public base_functor
00022 {
00023 protected:
00024 cgiScript & script;
00025 public:
00026 qrystr_content_functor(page & ipg,cgiScript & in):base_functor(ipg),script(in){;}
00027 virtual ~qrystr_content_functor(){;}
00028
00029 virtual bool operator()( xmlNode & node )
00030 {
00031 bool bRet = true;
00032 string items, replace_tag;
00033 node_attr::iterator x = node.attr.find("items");
00034 if( x!=node.attr.end() )
00035 {
00036 items=x->second;
00037 x = node.attr.find("replace-tag");
00038 if( x==node.attr.end())
00039 {
00040 x = node.attr.find("replace_tag");
00041 }
00042 if( x!=node.attr.end())
00043 {
00044 replace_tag=x->second;
00045 paragraphMap & paras = pg.get_template().getParagraphs();
00046 emit( paras, items, replace_tag );
00047 }
00048 else
00049 {
00050 cout << "no content replace tag" << endl;
00051 }
00052 }
00053 else
00054 {
00055 cout << "no content items" << endl;
00056 }
00057 return bRet;
00058 }
00059
00060 void emit( paragraphMap & paras, ocString templateTags, string replace_tag )
00061 {
00062 page_paragraphs & pgcontent = pg.get_page_paragraphs();
00063 paragraph_vector::iterator pos;
00064 for( pos=pgcontent.begin(); pos!=pgcontent.end(); ++pos )
00065 {
00066 ocString tags = "," + templateTags + ",";
00067 string testTag = "," + pos->template_tag() + ",";
00068
00069 string pName = pos->name();
00070 ocString pQ = script.QueryString().c_str();
00071
00072 if( tags.regExMatch( testTag.c_str() ) && pQ.regExMatch(pName.c_str()) )
00073 {
00074 pos->emit(paras,script,replace_tag);
00075 }
00076 }
00077 }
00078 };
00079
00080 #ifdef OPEN_LOGIN_H
00081
00082
00083
00084
00085
00086 class role_content_functor: public base_functor
00087 {
00088 protected:
00089 cgiScript & script;
00090 string roles;
00091 public:
00092
00093 role_content_functor(page & ipg,cgiScript & in):base_functor(ipg),script(in)
00094 {
00095 roles="[";
00096 string sql = "select role_id from user_roles where user_id = ";
00097 sql += oLogin.Id();
00098 quickQuery qq;
00099 openRS & rs = qq.getRS();
00100 for( bool isOpen = rs.open(sql); isOpen; )
00101 {
00102 roles+=rs.getField(0).format();
00103 isOpen = rs.next();
00104 if( isOpen ) roles+=",";
00105 }
00106 roles+="]";
00107 }
00108 virtual ~role_content_functor(){;}
00109
00110 virtual bool operator()( xmlNode & node )
00111 {
00112 bool bRet = true;
00113 string items, replace_tag;
00114 node_attr::iterator x = node.attr.find("items");
00115 if( x!=node.attr.end() )
00116 {
00117 items=x->second;
00118 x = node.attr.find("replace-tag");
00119 if( x==node.attr.end())
00120 {
00121 x = node.attr.find("replace_tag");
00122 }
00123 if( x!=node.attr.end())
00124 {
00125 replace_tag=x->second;
00126 paragraphMap & paras = pg.get_template().getParagraphs();
00127 emit( paras, items, replace_tag );
00128 }
00129 else
00130 {
00131 cout << "no content replace tag" << endl;
00132 }
00133 }
00134 else
00135 {
00136 cout << "no content items" << endl;
00137 }
00138 return bRet;
00139 }
00140
00141 void emit( paragraphMap & paras, ocString templateTags, string replace_tag )
00142 {
00143 stringstream s;
00144 page_paragraphs & pgcontent = pg.get_page_paragraphs();
00145 paragraph_vector::iterator pos;
00146 for( pos=pgcontent.begin(); pos!=pgcontent.end(); ++pos )
00147 {
00148 ocString tags = "," + templateTags + ",";
00149 string testTag = "," + pos->template_tag() + ",";
00150
00151 ocString pName = pos->name();
00152
00153 if( tags.regExMatch( testTag.c_str() ) && pName.regExMatch(roles.c_str()) )
00154 {
00155 pos->emit(paras,s,replace_tag);
00156 ocString content = s.str();
00157 script << content.replaceAll("{{name}}",oLogin.FullName())
00158 .replaceAll("{{last}}",oLogin.Last())
00159 .replaceAll("{{first}}",oLogin.Last())
00160 .replaceAll("{{Id}}",oLogin.Id())
00161 .replaceAll("{{email}}",oLogin.Email())
00162 .replaceAll("{{phone}}",oLogin.PhoneNumber());
00163 }
00164 }
00165 }
00166 };
00167 #endif
00168
00169 #endif