00001
00002
00003
00004
00005
00006
00007 #include <iostream>
00008 #include <iomanip>
00009 #include "cgiTemplates.h"
00010 #include "connectstring"
00011 #include "forms.h"
00012 #include "ocTypes.h"
00013 #include "ocString.h"
00014 #include "read_write_base.hpp"
00015 #include "page.hpp"
00016 #include "forms_base.hpp"
00017 #include "list_base.hpp"
00018 #include "openLogin.h"
00019 #include "siteLimit.h"
00020 #include "ocXML.h"
00021 #include "openLogger.h"
00022 using namespace std;
00023 openLogin oLogin;
00024
00025
00026 class page_item_List: public list_base
00027 {
00028 public:
00029 long long id;
00030 long long site_id;
00031 ocString defaultElement;
00032
00033 page_item_List(cgiScript&sc, long long id, long long site_id, string & defElement)
00034 :list_base(sc),id(id),site_id(site_id),defaultElement(defElement)
00035 {
00036 ;
00037 }
00038 ~page_item_List(){;}
00039
00040 bool list_display( void )
00041 {
00042 bool breturn = true;
00043 editLink = listTemplate.getParagraph("hotcolumn");
00044 editLink = editLink.replace("$prog$","paragraph_ui.cgi");
00045 hotCol=-2; skipCol=0;
00046 ocString sql = "select id ,name, content, template_tag, place_order "
00047 "from metasite.paragraphs "
00048 "where page_id = ";
00049 sql.append(id);
00050 sql += " and template_tag in ('";
00051 sql += defaultElement.replaceAll(",","','");
00052 sql += "') order by place_order";
00053 webIO << "<!-- " << sql << "-->" << endl;
00054
00055 emitHeadings("Name|Content|Style|Order");
00056 getData(sql);
00057 emitData();
00058 emitEnd();
00059 return breturn;
00060 }
00061 void derived_complete_event( void )
00062 {
00063 if(id)
00064 {
00065 ocString DefaultElement = defaultElement.parse(",");
00066 webIO << "<tr><td colspan='3' style='text-align:right; width: 500px;'>" << endl;
00067 webIO << " New Item by Style: " << endl;
00068 while( DefaultElement.length() )
00069 {
00070 ocString loco = "paragraph_ui.cgi?page_id=";
00071 loco.append(id);
00072 loco += "&site_id=";
00073 loco.append(site_id);
00074 loco += "§ion=";
00075 loco += defaultElement;
00076 loco += "&template_tag=";
00077 loco += DefaultElement;
00078 webIO << "<a href=\"javascript:jopen('" << loco
00079 << "')\">" << DefaultElement
00080 << "</a> " << endl;
00081 DefaultElement = defaultElement.parse(",");
00082 }
00083 webIO << "</td></tr>" << endl;
00084 }
00085 }
00086
00087
00088 virtual void sendHotField( int iField, ocString & td )
00089 {
00090 ocString linkId = rs.getField(0).format();
00091 if(id)
00092 {
00093 linkId += "&page_id=";
00094 linkId.append(id);
00095 }
00096
00097 string data;
00098 if( iField == 0 )
00099 {
00100
00101 }
00102 else if(iField == 2 )
00103 {
00104 ocString Parse(rs.getField(iField).format());
00105
00106 while( Parse.endOfParse() == false )
00107 {
00108 data += Parse.parse( "<" );
00109 data += " ";
00110 Parse.parse( ">" );
00111 }
00112 }
00113 else
00114 {
00115 data = rs.getField(iField).format();
00116 }
00117 if( data.length() )
00118 {
00119 webIO << td.replace( "$data$",
00120 editLink.replaceAll( "$key$", linkId.c_str() )
00121 .replaceAll( "$col$", data.c_str() ).c_str());
00122 }
00123 }
00124
00125 };
00126
00127 struct page_menu
00128 {
00129 string id;
00130 string name;
00131 page_menu(const string & iid, const string & iname)
00132 {
00133 id=iid;
00134 name=iname;
00135 }
00136 ~page_menu(){;}
00137 page_menu & operator = ( const page_menu & in )
00138 {
00139 id=in.id;
00140 name=in.name;
00141 return *this;
00142 }
00143 };
00144 typedef vector<page_menu> page_menus;
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 class controlLayout
00155 {
00156 public:
00157
00158 string csPath;
00159 cgiCookie cookie;
00160 node_vector nodes;
00161 page_menus menus;
00162 long long page_id;
00163 long long site_id;
00164 controlLayout( long long template_id, long long page_id, long long site_id )
00165 :csPath("Templates"),page_id(page_id),site_id(site_id)
00166 {
00167 cgiTemplates chosenTemplate;
00168
00169 cookie.setPath("/");
00170
00171 string strSite_id = cookie.get("site_id");
00172 string iPath;
00173 ocString sql = "select path from metasite.sites where id = ";
00174 sql += strSite_id;
00175 quickQuery qqry;
00176 openRS & rs = qqry.getRS();
00177
00178 if( rs.open(sql) )
00179 {
00180 string iPath = rs.getField(0).format().c_str();
00181 rs.close();
00182 sql = "select path from metasite.templates where id = ";
00183 sql.append(template_id);
00184 if( rs.open(sql) )
00185 {
00186 string tmplt = rs.getField(0).format().c_str();
00187 rs.close();
00188 iPath += "/";
00189 iPath += csPath;
00190 iPath += "/";
00191 iPath += tmplt;
00192
00193 chosenTemplate.load(iPath.c_str());
00194
00195 string controlXML = chosenTemplate.getParagraph("control");
00196 if( controlXML.length() )
00197 {
00198 xmlParser ctrlParse(controlXML);
00199 ctrlParse.parse();
00200 nodes = ctrlParse.nodeList();
00201 }
00202 }
00203 }
00204 }
00205 void getMenus( long long page_id )
00206 {
00207 ocString sql = "select pm.id, m.name "
00208 "from metasite.page_menus pm inner join metasite.menus m on pm.menu_id = m.id "
00209 "where pm.page_id = ";
00210 sql.append(page_id);
00211 sql += " order by pm.place_order ";
00212 quickQuery qqry;
00213 openRS & rs = qqry.getRS();
00214 if( rs.open(sql) )
00215 {
00216 do
00217 menus.push_back(page_menu(rs.getField(0).format(),rs.getField(1).format()));
00218 while( rs.next() );
00219 }
00220
00221 }
00222 void emit( cgiScript & script )
00223 {
00224 ocString elList;
00225 string defaultElement;
00226 int contents=0, menus=0;
00227 getMenus(page_id);
00228 if(nodes.size())
00229 {
00230 script << "<div class='extra'>" << endl;
00231 script << "<h4>Page Layout</h4>" << endl;
00232 for( int i = 0; i < nodes.size(); ++ i )
00233 {
00234 string & name = nodes[i].name;
00235 if( name == "menu" )
00236 {
00237 node_attr::iterator pos = nodes[i].attr.find("items");
00238 if( pos != nodes[i].attr.end() )
00239 {
00240 elList = pos->second;
00241 defaultElement = elList.parse(",");
00242 script << "<div class='label'>Menu " << menus+1 << ":</div>";
00243 if( menus < this->menus.size() )
00244 {
00245 script << "<a href=\"javascript:jopen('page_menu_ui.cgi?Id=";
00246 script << this->menus[menus].id;
00247 script << "&page_id=";
00248 script << page_id;
00249 script << "')\">";
00250 script << this->menus[menus].name;
00251 script << "</a>";
00252 }
00253 else
00254 {
00255 script << "<a href=\"javascript:jopen('page_menu_ui.cgi?page_id=";
00256 script << page_id;
00257 script << "')\">NEEDS TO BE ASSIGNED</a>";
00258 }
00259
00260 script << "<br class='clearall'>" << endl;
00261 menus++;
00262 }
00263 }
00264 else if( name != "xml" && name != "top" && name != "end"&& name != "spacer")
00265 {
00266 node_attr::iterator pos = nodes[i].attr.find("items");
00267 if( pos != nodes[i].attr.end() )
00268 {
00269 script << "<div class='label'>Content:</div>";
00270 elList = pos->second;
00271 page_item_List list(script,page_id,site_id,elList);
00272 list.loadListTemplates("Templates/poplist.htmp");
00273 list.list_display();
00274 script << "<br class='clearall'>" << endl;
00275 contents ++;
00276 }
00277 }
00278 }
00279 }
00280 }
00281 };
00282
00283 class page_form: public page, public forms_base
00284 {
00285 public:
00286 page_form(cgiScript & script):page(),forms_base(script){setKey(*this);}
00287 virtual ~page_form(){;}
00288
00289 void form_id_transfer( void )
00290 {
00291 llongFXfer( "id", id );
00292 }
00293 void form_data_transfer( void )
00294 {
00295
00296 llongFXfer( "site_id", site_id );
00297 llongFXfer( "template_id", template_id );
00298 stringFXfer( "name", name );
00299 stringFXfer( "url", url );
00300 stringFXfer( "meta_description", meta_description );
00301 }
00302
00303 bool dbf_action( string mode, changeMap & changes )
00304 {
00305 return db_action( mode, changes );
00306 }
00307
00308
00309 bool form_display( void )
00310 {
00311 bool breturn = true;
00312 string siteLimitation = siteFocus(oLogin);
00313 ocString sql = "select id, name from metasite.sites";
00314 if( siteLimitation.length() != 0 )
00315 {
00316 sql += " where id ";
00317 sql += siteLimitation;
00318 }
00319
00320 script << makeTop("page_ui.cgi", "Page Editor")
00321 << formTemplate.getParagraph("advanced_begin")
00322 << makeStaticBox("Id", "id", id, "12")
00323 << makeComboBox( "Site", "site_id", site_id,
00324 sql );
00325 script << "<br class='clearall'>" << endl
00326 << makeTextBox("SEO Key Phrases","meta_description",meta_description, "355", "50")
00327 << "<br class='clearall'>" << endl
00328 << formTemplate.getParagraph("advanced_end");
00329
00330 sql = "select id, name from metasite.templates";
00331 if( siteLimitation.length() )
00332 {
00333 sql += " where site_id ";
00334 sql += siteLimitation;
00335 }
00336 script << makeComboBox( "Template", "template_id", template_id,
00337 sql );
00338 script << "<br class='clearall'>" << endl;
00339 script << makeTextBox("Title","name",name,"50", "25")
00340 << "<br class='clearall'>" << endl
00341 << makeTextBox("URL","url",url,"255", "25")
00342 << "  <a href=\"javascript:jcontrol('url','urlpick.cgi')\">Create</a>";
00343 script << "<br class='clearall'>" << endl;
00344
00345
00346 script << makeButtons( key() );
00347
00348 if ( id != 0 )
00349 {
00350 script << "<a style='float:right; color:green;' target='view' href='../"
00351 << url
00352 << "'>View Page</a>" << endl;
00353 controlLayout layout( template_id, id, site_id );
00354 layout.emit(script);
00355
00356
00357 }
00358 script << makeBottom( m_result ) << endl;
00359 return breturn;
00360 }
00361 };
00362
00363
00364 int main( int argcount, char ** args )
00365 {
00366 cgiScript script( "text/html", false );
00367 page_form myFrm(script);
00368
00369 if( oLogin.testLoginStatus() )
00370 {
00371 script.closeHeader();
00372 cgiTemplates pgoo;
00373 pgoo.load("Templates/adminPane.htmp");
00374
00375 script << ocString(pgoo.getParagraph("top"))
00376 .replaceAll("$heading$","SITES");
00377
00378 myFrm.loadControlTemplates("Templates/divform.htmp");
00379 myFrm.form_action();
00380 myFrm.form_display();
00381
00382 ocString end = pgoo.getParagraph("bottom");
00383
00384 if( myFrm.getMode() != "s" )
00385 {
00386 script << end.replace("/*_extra_js_*/"," remenu();");
00387 }
00388 else
00389 {
00390 script << end;
00391 }
00392 }
00393 else
00394 {
00395 script.Redirect("signIn.html");
00396 }
00397 }
00398
00399
00400 #include "read_write_base.cpp"
00401 #include "forms_base.cpp"