00001
00002
00003
00004
00005
00006 #include "connectstring"
00007 #include "openLogin.h"
00008 #include "cgiTemplates.h"
00009 #include "openLogin.h"
00010 #include "ocFileSys.h"
00011
00012 #include "openLogger.h"
00013 #include "siteLimit.h"
00014 #include "ocXML.h"
00015
00016 using namespace std;
00017 openLogin oLogin;
00018 const string csPath="Templates";
00019 void templateList(cgiScript & script, openLogin & login)
00020 {
00021 string context;
00022 if( script.ClientArguments().count("context") ) context = script.ClientArguments()["context"].c_str();
00023 cgiTemplates htmlDoc;
00024 htmlDoc.load("Templates/listMetatags.htmp");
00025 char * Rows[2] = { "oddcell", "evencell" };
00026 script << ocString(htmlDoc.getParagraph("top"))
00027 .replaceAll( "$TITLE_GOES_HERE",
00028 "File Choices:" )
00029 << endl;
00030
00031 ocString link = "<a href='metatagPick.cgi?template_path=$path&site_id=$id&context=$context'>"
00032 "$path</a>";
00033
00034 ocString headitem = htmlDoc.getParagraph("headitem");
00035 string rowsep = htmlDoc.getParagraph("rowsep");
00036 script << headitem.replace("__hcell_label","Pick a file first:");
00037
00038 quickQuery qqry;
00039 openRS & rs = qqry.getRS();
00040
00041 string siteLimitation = siteFocus(login);
00042 string sql = "select path, site_id from metasite.templates";
00043 if( siteLimitation.length() )
00044 {
00045 sql += " where site_id ";
00046 sql += siteLimitation;
00047 }
00048 int iRow = 0;
00049 for( bool b = rs.open(sql);
00050 b;
00051 b= rs.next(), ++iRow )
00052 {
00053 ocString row = htmlDoc.getParagraph(Rows[ iRow % 2 ] );
00054 script << rowsep;
00055 script << row.replace( "$cell_data",
00056 link.replaceAll( "$path",
00057 rs.getField(0).format().c_str()
00058 )
00059 .replace( "$id",
00060 rs.getField(1).format().c_str() )
00061 .replace( "$context", context.c_str() ).c_str() );
00062 script << endl;
00063 }
00064 }
00065
00066
00067
00068
00069 string contextualFilter( ocString context, string controlXML )
00070 {
00071 string ret;
00072 writelog3("Entered contextualFilter( )", context, controlXML );
00073 if( context.length() && controlXML.length() )
00074 {
00075 xmlParser ctrlParse(controlXML);
00076 ctrlParse.parse();
00077 node_vector & node_vect = ctrlParse.nodeList();
00078
00079
00080
00081 string tk = context.parse(" ");
00082
00083 string attr = context.parse(" ");
00084 writelog2("Node Attribute: ", attr );
00085
00086 node_map::iterator node_pos = ctrlParse.states.nodemap.lower_bound(tk);
00087 if( node_pos != ctrlParse.states.nodemap.upper_bound(tk) ) ret = "(";
00088 for( ; node_pos != ctrlParse.states.nodemap.upper_bound(tk); ++ node_pos )
00089 {
00090 if( ret.length() > 1 ) ret += "|";
00091 xmlNode & node = node_vect[node_pos->second];
00092 if( attr.length() )
00093 {
00094 ocString filt = node.attr[attr];
00095 if( filt.length() )
00096 {
00097 ret += filt.replaceAll(",","|");
00098 }
00099 }
00100 }
00101 if( ret[0] == '(' ) ret += ")";
00102
00103 }
00104 writelog2("Exited contextualFilter( ) returning: ", ret );
00105 return ret;
00106 }
00107
00108 void tagList(cgiScript & script, string path, string site_id )
00109 {
00110 cgiTemplates htmlDoc, chosenTemplate;
00111 htmlDoc.load("Templates/listMetatags.htmp");
00112 script << ocString(htmlDoc.getParagraph("top"))
00113 .replaceAll( "$TITLE_GOES_HERE",
00114 "Tag Choices:" ) << endl;
00115
00116 string sql = "select path from metasite.sites where id = ";
00117 sql += site_id;
00118 quickQuery qqry;
00119 openRS & rs = qqry.getRS();
00120
00121 if( rs.open(sql) )
00122 {
00123 string iPath = rs.getField(0).format().c_str();
00124 iPath += "/";
00125 iPath += csPath;
00126 iPath += "/";
00127 iPath += path;
00128
00129 chosenTemplate.load(iPath.c_str());
00130
00131 char * Rows[2] = { "oddcell", "evencell" };
00132
00133 ocString headitem = htmlDoc.getParagraph("headitem");
00134 string rowsep = htmlDoc.getParagraph("rowsep");
00135
00136 writelog("Writing headers");
00137 script << headitem.replace("__hcell_label","Pick a tag:");
00138
00139 ocString link = "<a href='javascript:pickTag(\"$tag\")'>"
00140 "$tag</a>";
00141 paragraphMap::iterator pos;
00142 int iRow = 0;
00143 paragraphMap & pmap = const_cast<paragraphMap &>(chosenTemplate.getParagraphs());
00144
00145 string context;
00146 if( script.ClientArguments().count("context") ) context = script.ClientArguments()["context"].c_str();
00147 writelog2("Got context", context)
00148 string filt = contextualFilter( context, chosenTemplate.getParagraph("control") );
00149 for(pos = pmap.begin(); pos != pmap.end(); ++pos )
00150 {
00151 ocString test_it = pos->first;
00152
00153
00154 if( ( !filt.length() || test_it.regExMatch(filt.c_str()) ) &&
00155 pos->first != "edits" &&
00156 pos->first != "top" &&
00157 pos->first != "end" &&
00158 pos->first != "help" &&
00159 pos->first != "control" )
00160 {writelog3("Tags: ", pos->first, pos->second);
00161
00162 ocString row = htmlDoc.getParagraph(Rows[ iRow % 2 ] );
00163 ++iRow;
00164 script << rowsep <<
00165 row.replace( "$cell_data",
00166 link.replaceAll( "$tag",
00167 pos->first.c_str()
00168 ).c_str() ) << endl;
00169 }
00170 }
00171 }
00172 else
00173 {
00174 script << sql << endl;
00175 }
00176 script << htmlDoc.getParagraph("bottom") << endl;
00177 }
00178
00179 int main( int argcount, char ** args )
00180 {
00181
00182
00183
00184
00185 cgiScript script("text/html", false);
00186 writelog("OK - script made");
00187
00188 if ( oLogin.testLoginStatus() )
00189 {
00190 script.closeHeader();
00191 if( script.ClientArguments().count("template_path") )
00192 {
00193 tagList( script,
00194 script.ClientArguments()["template_path"].c_str(),
00195 currentSite( script.ClientArguments() ) );
00196 }
00197 else
00198 {
00199 templateList(script,oLogin);
00200 }
00201 writelog("Done");
00202 }
00203 else
00204 {
00205 script.Redirect("signIn.html");
00206 script.closeHeader();
00207 writelog("INVALID ACCESS ATTEMPT");
00208 }
00209 writelog("OK - All Done");
00210 return(0);
00211 }
00212 #include "read_write_base.cpp"
00213