00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "openLogger.h"
00025 #include "cgiClass.h"
00026 #include"oc_Mail.h"
00027 #include "connectstring"
00028
00029 #include "w3intranet.h"
00030 #include "page.hpp"
00031 #include "page_control.hpp"
00032 using namespace std;
00033
00034
00035 class mail_functor: public base_functor
00036 {
00037 public:
00038 cgiScript & script;
00039 page & pg;
00040 ocSendMail sendMail;
00041
00042 string bodyStart;
00043 string itemTemplate;
00044 string bodyEnd;
00045 string formName;
00046 string thankYou;
00047
00048
00049 string sendTo;
00050
00051 string mailBody;
00052 string dataSent;
00053
00054 mail_functor(page & ipg,cgiScript & scriptIn):base_functor(ipg)
00055 ,script(scriptIn),pg(ipg),sendMail("127.0.0.1"){;}
00056 virtual ~mail_functor(){;}
00057
00058 virtual bool operator()( xmlNode & node )
00059 {
00060 bool bRet = true;
00061
00062 node_attr::iterator x = node.attr.find("items");
00063 if( x!=node.attr.end() )
00064 {
00065 formName=x->second;
00066 }
00067 x = node.attr.find("mailbodystart");
00068 if( x!=node.attr.end())
00069 {
00070 bodyStart=x->second;
00071 }
00072 x = node.attr.find("mailbodyitem");
00073 if( x!=node.attr.end())
00074 {
00075 itemTemplate=x->second;
00076 }
00077 x = node.attr.find("mailbodyend");
00078 if( x!=node.attr.end())
00079 {
00080 bodyEnd=x->second;
00081 }
00082 x = node.attr.find("thankyou");
00083 if( x!=node.attr.end())
00084 {
00085 thankYou=x->second;
00086 }
00087 x = node.attr.find("sendto");
00088 if( x!=node.attr.end())
00089 {
00090 sendTo=x->second;
00091 }
00092
00093 if( script.RequestMethod().upper() == "GET" )
00094 {
00095
00096
00097 showForm();
00098 }
00099 else
00100 {
00101
00102
00103
00104
00105 doMail();
00106 }
00107 return bRet;
00108 }
00109
00110 void showForm( void )
00111 {
00112 script << "<!-- form name = '" << formName << "' -->" << endl;
00113 pg.emitContent( formName, "$content" );
00114 }
00115
00116 void doMail( void )
00117 {
00118 dataSent = "";
00119 mailBody = pg.paragraph_string(bodyStart);
00120 queryStringMap::iterator pos;
00121 cgiInput & args = script.ClientArguments();
00122 string from = sendTo.c_str();
00123 string to = sendTo.c_str();
00124 ocString testForEmail;
00125 for(pos=args.TheMap().begin(); pos!=args.TheMap().end(); ++pos)
00126 {
00127 testForEmail = pos->first;
00128 if( testForEmail.regExMatch( "[eE][mM][aA][iI][lL]" ) && pos->second.length() )
00129 {
00130 from = pos->second.c_str();
00131 }
00132 dataItem( pos->first, pos->second );
00133 }
00134 mailBody += pg.paragraph_string(bodyEnd);
00135 sendMail.openRoute( from.c_str(), to.c_str(), "Customer Request" );
00136 sendMail.setMimeType("text/html");
00137 sendMail.write( mailBody.c_str() );
00138 sendMail.send();
00139 script << thanksMsg()<< endl;
00140 }
00141 ocString find( page_paragraphs & paras, string name )
00142 {
00143 ocString output;
00144
00145 for( int pos = 0; pos < paras.size(); ++pos )
00146 {
00147
00148 if( paras[pos].name() == name )
00149 {
00150 output = paras[pos].content();
00151 break;
00152 }
00153 }
00154
00155 return output;
00156 }
00157 string thanksMsg( void )
00158 {
00159 string message = find( pg.get_page_paragraphs(), thankYou);
00160 ocString thanksMsg = pg.paragraph_string(thankYou);
00161 return thanksMsg.replace("$data",dataSent.c_str()).replace("$message",message.c_str());
00162 }
00163
00164 void dataItem( ocString name,
00165 aString value )
00166 {
00167
00168 if( name.substr(0,2)=="mi")
00169 {
00170 name.parse("_");
00171 ocString datum = pg.paragraph_string(itemTemplate);
00172 string formatted = datum.replace("$label",name.remainder().c_str()).replace("$data",value.c_str());
00173 mailBody += formatted;
00174 dataSent += formatted;
00175 }
00176 }
00177 };
00178
00179
00180
00181 int main(int argc, char ** argv)
00182 {
00183 baseUrl = "contactus.meta";
00184 cgiScript script("text/html",false);
00185 isSignedOn = check(script);
00186 script.closeHeader();
00187
00188 page pg(script);
00189
00190 if( pg.load() )
00191 {
00192 page_control ctrl(pg);
00193 ctrl.addOp ( "contactus", new mail_functor(pg,script) );
00194
00195 ctrl.emit();
00196 }
00197 else
00198 {
00199 script << "<html><head><title>Page Unavailable</title></head>" << endl
00200 << "<body><h1>Sorry</h1>" << endl
00201 << "<p>The page you requested is not available</p></body></html>";
00202 }
00203 return 0;
00204 }
00205 #include "read_write_base.cpp"