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