00001
00002
00003
00004
00005 #ifndef W3_Intranet_h
00006 #define W3_Intranet_h
00007
00008
00009
00010
00011
00012
00013 #include "connectstring"
00014 #include "cgiClass.h"
00015 #include "page.hpp"
00016 #include "page_control.hpp"
00017 #include "page_enhancements.hpp"
00018 #include "forms.h"
00019 #include "ocTypes.h"
00020 #include "read_write_base.hpp"
00021 #include "superlist_base.hpp"
00022 #include "forms.h"
00023 #include "forms_base.hpp"
00024 #include "lookup.hpp"
00025 #include "InfoPoints.hpp"
00026
00027
00028
00029
00030 bool intraMain(page & pg ,cgiScript & script);
00031
00032 string flexButtons( long long key,
00033 string iLabel=" Insert ",
00034 string uLabel=" Update ",
00035 string dLabel=" Delete ",
00036 string rLabel=" New - Reset ",
00037 string nLabel=" New - Keep Data ",
00038 bool doInsert = true,
00039 bool doUpdate = true,
00040 bool doDelete = true,
00041 bool doReset = true,
00042 bool doKeepData = true )
00043 {
00044 string ret;
00045 if( key )
00046 {
00047 if( doUpdate )
00048 {
00049 ret += "<input class='submitButtons' type='button' onclick='doUpdate()' name='action' class='action' value='";
00050 ret += uLabel;
00051 ret += "'>";
00052 }
00053 if( doDelete )
00054 {
00055 ret += "<input class='submitButtons' type='button' onclick='doDelete()' name='action' class='action' value='";
00056 ret += dLabel;
00057 ret += "'>";
00058 }
00059 if( doReset )
00060 {
00061 ret += "<inputclass='submitButtons' type='button' onclick='doReset()' name='action' class='action' value='";
00062 ret += rLabel;
00063 ret += "'>";
00064 }
00065 if( doKeepData )
00066 {
00067 ret += "<input type='button' onclick='doNew()' name='action' class='action' value='";
00068 ret += nLabel;
00069 ret += "'>";
00070 }
00071 }
00072 else
00073 {
00074 if( doInsert )
00075 {
00076 ret += "<input type='button' onclick='doInsert()' name='action' class='action' value='";
00077 ret += iLabel;
00078 ret += "'>";
00079 }
00080 else
00081 {
00082 ret += "<input type='button' onclick='doInsert()' name='action' class='action' value='";
00083 ret += uLabel;
00084 ret += "'>";
00085 }
00086 }
00087 return ret;
00088 }
00089
00090 bool check(cgiScript & script)
00091 {
00092 bool isSignedOn = false;
00093
00094
00095 infoPoints iPoints;
00096 if( iPoints.idToken.length() )
00097 {
00098 oLogin.token = iPoints.idToken;
00099
00100 }
00101
00102
00103 if ( (script.ClientArguments().count("login")==1) &&
00104 (script.ClientArguments().count("password")==1) &&
00105 (script.ClientArguments().count("group_id")==0) )
00106 {
00107
00108 aString & asLogin = script.ClientArguments()["login"];
00109 aString & asPassword = script.ClientArguments()["password"];
00110
00111 isSignedOn = oLogin.checkUser( asLogin.str(), asPassword.str() );
00112 }
00113 else
00114 {
00115
00116
00117 if ( oLogin.testLoginStatus() )
00118 {
00119 if( script.ClientArguments().count("signoff") )
00120 {
00121 cgiCookie cookie;
00122 cookie.setTimeout( 1, 1, 1970, 0, 0 );
00123 cookie.setPath("/");
00124 cookie.set( oLogin.token.c_str(), "" );
00125 isSignedOn = false;
00126 }
00127 else
00128 {
00129 isSignedOn = true;
00130 }
00131 }
00132 }
00133 return isSignedOn;
00134 }
00135
00136 class servicelist_functor: public base_functor
00137 {
00138 cgiScript & script;
00139 bool isSignedOn;
00140
00141
00142 string path;
00143 public:
00144
00145 servicelist_functor(page & ipg,cgiScript & script, bool isSignedOn)
00146 :base_functor(ipg),script(script),isSignedOn(isSignedOn){;}
00147 virtual ~servicelist_functor(){;}
00148
00149 virtual bool operator()( xmlNode & node )
00150 {
00151 bool bRet = false;
00152 string item;
00153 if( isSignedOn )
00154 {
00155 bRet = true;
00156
00157 ocString catheadingTemplate = pg.paragraph_string( "catheading" );
00158 ocString catitemTemplate = pg.paragraph_string( "catitem" );
00159 string lastCat;
00160 if( oLogin.fetchServices() )
00161 {
00162 serviceVector & svcNames = oLogin.ServiceNames();
00163 serviceMap & svcs = oLogin.Services();
00164 for(int ix=0;ix<svcNames.size();++ix)
00165 {
00166 openService & service = svcs[svcNames[ix]];
00167 if( lastCat != service.cat_name )
00168 {
00169 lastCat = service.cat_name;
00170 script << catheadingTemplate.replace("$content",lastCat.c_str());
00171 }
00172 script << catitemTemplate.replace("$level",service.tree_depth.c_str())
00173 .replace("$location", fixURI(service.uri).c_str())
00174 .replace("$label",service.menu_name.c_str());
00175 }
00176 }
00177 string loggedIn = oLogin.FullName();
00178 script << catheadingTemplate.replace("$content",loggedIn.c_str());
00179 script << catitemTemplate.replace("$level","1")
00180 .replace("$location","?signoff=true")
00181 .replace("$label","Sign Off");
00182 }
00183 return bRet;
00184 }
00185 string fixURI( ocString uri )
00186 {
00187
00188 if( uri.regExMatch(":") ) return uri;
00189
00190
00191 string fixedURI = "http://";
00192
00193
00194 fixedURI += script.ServerName().c_str();
00195
00196
00197 if( path.length() == 0 )
00198 {
00199 ocString sql = "select url from metasite.sites where id = ";
00200 sql.append(pg.site_id());
00201 path = tableLookup( sql );
00202 }
00203
00204
00205 if( uri.regExMatch("/") == false )
00206 {
00207
00208 fixedURI += path;
00209 }
00210
00211 fixedURI += uri;
00212 return fixedURI;
00213 }
00214 };
00215
00216 class form_functor: public base_functor
00217 {
00218 cgiScript & script;
00219 bool isSignedOn;
00220
00221
00222 public:
00223
00224 form_functor(page & ipg
00225 ,cgiScript & script
00226 ,bool isSignedOn
00227
00228
00229 )
00230 :base_functor(ipg)
00231 ,script(script)
00232 ,isSignedOn(isSignedOn)
00233
00234 {;}
00235 virtual ~form_functor(){;}
00236
00237 virtual bool operator()( xmlNode & node )
00238 {
00239 bool bRet = false;
00240
00241 if( isSignedOn )
00242 {
00243 bRet = intraMain( pg , script);
00244 }
00245 else
00246 {
00247
00248 script << pg.paragraph_string( "sign_on_form" );
00249
00250 pg.get_page_paragraphs().clear();
00251 }
00252 return bRet;
00253 }
00254
00255 };
00256
00257
00258 #endif