00001
00002
00003
00004
00005
00006
00007 #include "connectstring"
00008 #include "openLogin.h"
00009 #include "cgiTemplates.h"
00010 #include "cgiExtend.h"
00011 #include "siteLimit.h"
00012
00013
00014 extern "C"
00015 {
00016 int ordinal( void );
00017 string label( void );
00018 void presentation( ostream & client );
00019 }
00020 using namespace std;
00021
00022 int ordinal( void )
00023 {
00024 return 2;
00025 }
00026
00027 string label( void )
00028 {
00029 return "Meta-Site-Admin";
00030 }
00031
00032 void showSites( ostream & client, cgiTemplates & tmplts, openLogin & login )
00033 {
00034 quickQuery QQ;
00035 openRS & rs = QQ.getRS();
00036 string siteLimitation = siteLimits(login);
00037 string sql = "select id, name from metasite.sites";
00038 if( siteLimitation.length() )
00039 {
00040 sql += " where id ";
00041 sql += siteLimitation;
00042 }
00043 sql += " order by name";
00044 client << "<!--To get sites: " << sql << "-->" << endl;
00045 for( bool b = rs.open(sql);
00046 b;
00047 b= rs.next() )
00048 {
00049 ocString loco = "site_ui.cgi?id=";
00050 loco += rs.getField(0).format();
00051 client << ocString(tmplts.getParagraph("listitem"))
00052 .replace( "$location", loco.c_str())
00053 .replace( "$label", rs.getField(1).format().c_str() ) << endl;
00054 }
00055 }
00056
00057 void showTemplates( ostream & client, cgiTemplates & tmplts, openLogin & login )
00058 {
00059 quickQuery QQ;
00060 openRS & rs = QQ.getRS();
00061 string siteLimitation = siteFocus(login);
00062 string sql = "select id, name from metasite.templates";
00063 if( siteLimitation.length() )
00064 {
00065 sql += " where site_id ";
00066 sql += siteLimitation;
00067 }
00068 sql += " order by name";
00069 client << "<!--To get templates: " << sql << "-->" << endl;
00070 for( bool b = rs.open(sql);
00071 b;
00072 b= rs.next() )
00073 {
00074 ocString loco = "template_ui.cgi?id=";
00075 loco += rs.getField(0).format();
00076 client << ocString(tmplts.getParagraph("listitem"))
00077 .replace( "$location", loco.c_str())
00078 .replace( "$label", rs.getField(1).format().c_str() ) << endl;
00079 }
00080 }
00081 void showMenus( ostream & client, cgiTemplates & tmplts, openLogin & login )
00082 {
00083 quickQuery QQ;
00084 openRS & rs = QQ.getRS();
00085 string siteLimitation = siteFocus(login);
00086 string sql = "select id, name from metasite.menus";
00087 if( siteLimitation.length() )
00088 {
00089 sql += " where site_id ";
00090 sql += siteLimitation;
00091 }
00092 sql += " order by name";
00093 client << "<!--To get menus: " << sql << "-->" << endl;
00094 for( bool b = rs.open(sql);
00095 b;
00096 b= rs.next() )
00097 {
00098 ocString loco = "menu_ui.cgi?id=";
00099 loco += rs.getField(0).format();
00100 client << ocString(tmplts.getParagraph("listitem"))
00101 .replace( "$location", loco.c_str())
00102 .replace( "$label", rs.getField(1).format().c_str() ) << endl;
00103 }
00104 }
00105 void showPages( ostream & client, cgiTemplates & tmplts, openLogin & login )
00106 {
00107 quickQuery QQ;
00108 openRS & rs = QQ.getRS();
00109 string siteLimitation = siteFocus(login);
00110 string sql = "select id, name from metasite.pages";
00111 if( siteLimitation.length() )
00112 {
00113 sql += " where site_id ";
00114 sql += siteLimitation;
00115 }
00116 sql += " order by name";
00117 client << "<!--To get pages: " << sql << "-->" << endl;
00118 for( bool b = rs.open(sql);
00119 b;
00120 b= rs.next() )
00121 {
00122 ocString loco = "page_ui.cgi?id=";
00123 loco += rs.getField(0).format();
00124 client << ocString(tmplts.getParagraph("listitem"))
00125 .replace( "$location", loco.c_str())
00126 .replace( "$label", rs.getField(1).format().c_str() ) << endl;
00127 }
00128 }
00129 void runService( ostream & client, string serviceName, cgiTemplates & tmplts, openLogin & login )
00130 {
00131
00132 if( serviceName == "Meta-Site Sites" )
00133 {
00134 showSites( client, tmplts, login );
00135 }
00136 else if ( serviceName == "Meta-Site Templates" )
00137 {
00138 showTemplates( client, tmplts, login );
00139 }
00140 else if ( serviceName == "Meta-Site Menus" )
00141 {
00142 showMenus( client, tmplts, login );
00143 }
00144
00145 else if ( serviceName == "Meta-Site Pages" )
00146 {
00147 showPages( client, tmplts, login );
00148 }
00149 }
00150
00151 void presentation( ostream & client )
00152 {
00153 cgiEnvironment envir;
00154 cgiTemplates tmplts;
00155 tmplts.load("./Templates/menu.htmp");
00156 openLogin login(false);
00157
00158 ocString expanded = tmplts.getParagraph("expanded");
00159 ocString collapsed = tmplts.getParagraph("collapsed");
00160 ocString subitem = tmplts.getParagraph("subitem");
00161
00162
00163
00164 ocString thisOrdinal;
00165 string expandedOrdinal;
00166 string link="menu.cgi";
00167 thisOrdinal.append(ordinal());
00168
00169 cgiInput & clientSent = envir.ClientArguments();
00170
00171 if( clientSent.count("module") )
00172 {
00173 expandedOrdinal = clientSent["module"].c_str();
00174 }
00175
00176 if( thisOrdinal == expandedOrdinal )
00177 {
00178
00179 client << expanded.replace( "$location", link.c_str() )
00180 .replace( "$label", label().c_str() ) << endl;
00181 if( login.testLoginStatus() &&
00182 login.fetchServices( " s.tree_depth >= 2 && s.xml_params like '<actor>site author</actor>%'" ) )
00183 {
00184
00185
00186 serviceMap & services = login.Services();
00187 serviceVector & names = login.ServiceNames();
00188 serviceMap::iterator pos;
00189 int st;
00190 for(st=0; st<names.size();++st )
00191 {
00192 pos = services.find(names[st]);
00193 if(pos!=services.end())
00194 {
00195
00196 openService & service = pos->second;
00197 client << subitem
00198 .replace("$location",service.uri.c_str())
00199 .replace("$label",service.menu_name.c_str()) << endl;
00200 runService( client, service.service_name, tmplts, login );
00201 }
00202 }
00203 }
00204 else
00205 {
00206 client << login.getLastError() << endl;
00207 }
00208 }
00209 else
00210 {
00211 link+="?module=";
00212 link+=thisOrdinal;
00213 client << collapsed.replace( "$location", link.c_str() )
00214 .replace( "$label", label().c_str() ) << endl;
00215 }
00216 }
00217 #include "read_write_base.cpp"
00218