00001
00002
00003
00004
00005
00006
00007 #include "forms_base.hpp"
00008 #include "ocXML.h"
00009
00010 forms_base::forms_base(cgiScript & in):script(in)
00011 {
00012 m_warn = "<br>";
00013 getInstructions();
00014 }
00015
00016 forms_base::~forms_base()
00017 {
00018 ;
00019 }
00020
00021 bool forms_base::getInstructions( void )
00022 {
00023 bool breturn = false;
00024
00025 if( script.ClientArguments().count("xmldirections") )
00026 {
00027 string xml = script.ClientArguments()["xmldirections"].c_str();
00028 xmlParser parser(xml);
00029 parser.parse();
00030 node_vector & xnodes = parser.nodeList();
00031 int i;
00032 for(i=0;i<xnodes.size();i++)
00033 {
00034 xmlNode & node = xnodes[i];
00035 if( node.name == "change" )
00036 {
00037 changes[node.data]=node.data;
00038 }
00039 else if( node.name == "mode" )
00040 {
00041
00042 mode = node.data;
00043 breturn = true;
00044 }
00045 }
00046 }
00047
00048
00049
00050 cgiCookie cookie;
00051 string cookie_mode = cookie.get("mode");
00052 if( mode != cookie_mode )
00053 {
00054 mode = "s";
00055 }
00056 return breturn;
00057 }
00058
00059
00060 bool forms_base::form_action( void )
00061 {
00062
00063 if( mode != "r" && mode != "n" )
00064 {
00065 form_id_transfer();
00066 }
00067
00068 if( mode != "r" )
00069 {
00070 form_data_transfer();
00071 }
00072 return dbf_action( mode, changes );
00073 }
00074
00075
00076 bool forms_base::loadControlTemplates( string path )
00077 {
00078 return formTemplate.load(path.c_str());
00079 }
00080 string forms_base::makeButtons( long long key,
00081 string iLabel,
00082 string uLabel,
00083 string dLabel )
00084 {
00085 ocString ret = formTemplate.getParagraph("button_group");
00086 return ret.replace("$buttons$",formButtons( key,iLabel,uLabel,dLabel ).c_str());
00087 }
00088 string forms_base::makeTop(string uri, string name )
00089 {
00090 ocString ret = formTemplate.getParagraph("form_begin");
00091 return ret.replace("$action$",uri.c_str()).replace("$name$",name.c_str());
00092 }
00093 string forms_base::makeBottom( string status )
00094 {
00095 ocString ret = formTemplate.getParagraph("form_end");
00096 if( m_warn != "<br>" ) status += m_warn;
00097 return ret.replace("$status$",status.c_str());
00098 }
00099
00100
00101 void forms_base::stringFXfer( string in, string & out )
00102 {
00103 if( script.ClientArguments().count(in.c_str()) )
00104 {
00105 out=script.ClientArguments()[in.c_str()].c_str();
00106 }
00107 }
00108 void forms_base::llongFXfer( string in, long long & out )
00109 {
00110 if( script.ClientArguments().count(in.c_str()) )
00111 {
00112 out=atoll(script.ClientArguments()[in.c_str()].c_str());
00113 }
00114 }
00115 void forms_base::longFXfer( string in, long & out )
00116 {
00117 if( script.ClientArguments().count(in.c_str()) )
00118 {
00119 out=atol(script.ClientArguments()[in.c_str()].c_str());
00120 }
00121 }
00122 void forms_base::unfmtLongFXfer( string in, long & out )
00123 {
00124 if( script.ClientArguments().count(in.c_str()) )
00125 {
00126 ocString fixUp = script.ClientArguments()[in.c_str()].c_str();
00127 out=atol(fixUp.replaceAll(",","").c_str());
00128 }
00129 }
00130 void forms_base::intFXfer( string in, int & out )
00131 {
00132 if( script.ClientArguments().count(in.c_str()) )
00133 {
00134 out=atoi(script.ClientArguments()[in.c_str()].c_str());
00135 }
00136 }
00137 void forms_base::shortFXfer( string in, short & out )
00138 {
00139 if( script.ClientArguments().count(in.c_str()) )
00140 {
00141 out=atoi(script.ClientArguments()[in.c_str()].c_str());
00142 }
00143 }
00144 void forms_base::doubleFXfer( string in, double & out )
00145 {
00146 if( script.ClientArguments().count(in.c_str()) )
00147 {
00148 out=atof( script.ClientArguments()[in.c_str()].c_str());
00149 }
00150 }
00151 void forms_base::moneyFXfer( string in, money & out )
00152 {
00153 if( script.ClientArguments().count(in.c_str()) )
00154 {
00155 ocString tmpVal = script.ClientArguments()[in.c_str()].c_str();
00156 double val = atof( tmpVal.replaceAll("$","").replaceAll(",","").c_str() );
00157 out=val;
00158 }
00159 }
00160 void forms_base::boolFXfer( string in, bool & out )
00161 {
00162 out = false;
00163 if( script.ClientArguments().count(in.c_str()) )
00164 {
00165 out=true;
00166 }
00167 }
00168
00169 void forms_base::dateFXfer( string in, oc_date & out )
00170 {
00171 if( script.ClientArguments().count(in.c_str())&& script.ClientArguments()[in.c_str()].length() )
00172 out.parse( script.ClientArguments()[in.c_str()].c_str() );
00173 }
00174
00175 void forms_base::dateFXfer( string in, time_date & out )
00176 {
00177 if( script.ClientArguments().count(in.c_str()) && script.ClientArguments()[in.c_str()].length())
00178 {
00179 out.parse( script.ClientArguments()[in.c_str()].c_str() ,"%m/%d/%Y %H:%M" );
00180 }
00181 }
00182
00183 void forms_base::timeFXfer( string in, oc_time & out )
00184 {
00185 if( script.ClientArguments().count(in.c_str()) && script.ClientArguments()[in.c_str()].length() )
00186 {
00187 out.setFormat("%I:%M %p");
00188 out.parse( script.ClientArguments()[in.c_str()].c_str() );
00189 }
00190 }
00191
00192 string forms_base::makeEmailBox( string label, string name, string value,
00193 string size, string length)
00194 {
00195 ocString ret = formTemplate.getParagraph("control_group");
00196 ocTextbox * pText = emailEntry( name, size, length );
00197 if( pText )
00198 {
00199 pText->setContent(value);
00200 ret = ret.replace("$label$",label.c_str()).replace("$name$",name.c_str())
00201 .replace("$control$", pText->getHtml().c_str());
00202 delete pText;
00203 }
00204 return ret;
00205 }
00206
00207
00208 string forms_base::makePasswordBox( string label, string name,
00209 string value, string size)
00210 {
00211 ocString ret = formTemplate.getParagraph("control_group");
00212 ocPassword * pText = pswdEntry( name, size );
00213 if( pText )
00214 {
00215 pText->setContent(value);
00216 ret = ret.replace("$label$",label.c_str()).replace("$name$",name.c_str())
00217 .replace("$control$", pText->getHtml().c_str());
00218 delete pText;
00219 }
00220 return ret;
00221 }
00222
00223 string forms_base::makeZipBox( string label, string name,
00224 string value, string size)
00225 {
00226 ocString ret = formTemplate.getParagraph("control_group");
00227 ocTextbox * pText = zipEntry( name, size );
00228 if( pText )
00229 {
00230 pText->setContent(value);
00231 ret = ret.replace("$label$",label.c_str()).replace("$name$",name.c_str())
00232 .replace("$control$", pText->getHtml().c_str());
00233 delete pText;
00234 }
00235 return ret;
00236 }
00237 string forms_base::makePhoneBox( string label, string name, string value, string size)
00238 {
00239 ocString ret = formTemplate.getParagraph("control_group");
00240 ocTextbox * pText = phoneEntry( name, size );
00241 if( pText )
00242 {
00243 pText->setContent(value);
00244 ret = ret.replace("$label$",label.c_str()).replace("$name$",name.c_str())
00245 .replace("$control$", pText->getHtml().c_str());
00246 delete pText;
00247 }
00248 return ret;
00249 }
00250
00251
00252 string forms_base::makeFileBox( string label, string name, string value, string size)
00253 {
00254 ocString ret = formTemplate.getParagraph("file_group");
00255 ocTextbox * pText = textEntry( name, size, size );
00256 if( pText )
00257 {
00258 pText->setContent(value);
00259 ret = ret.replace("$label$",label.c_str()).replace("$name$",name.c_str())
00260 .replace("$control$", pText->getHtml().c_str())
00261 .replace("$id$",name.c_str());
00262 delete pText;
00263 }
00264 return ret;
00265 }
00266
00267
00268 string forms_base::makeFileBox( string label, string name, string value, string size, string maxlen, string attr)
00269 {
00270 ocString ret = formTemplate.getParagraph("control_group");
00271 string allAttr = " onChange='ctrlChanged(this)' ";
00272 allAttr += attr;
00273 ocFilebox * pText = new ocFilebox( name, size, maxlen, allAttr );
00274 if( pText )
00275 {
00276 string ctrlText = pText->getHtml();
00277 ctrlText += " : ";
00278 ctrlText += value;
00279 ret = ret.replace("$label$",label.c_str()).replace("$name$",name.c_str())
00280 .replace("$control$", ctrlText.c_str())
00281 .replace("$id$",name.c_str());
00282 delete pText;
00283 }
00284 return ret;
00285 }
00286
00287 string forms_base::makeMetaBox( string label, string name,
00288 string value, string size,
00289 string metaFile,
00290 string context )
00291 {
00292 ocString ret = formTemplate.getParagraph("meta_group");
00293 ocTextbox * pText = textEntry( name, size, size );
00294 ocString jopen_url="metatagPick.cgi";
00295 if( metaFile.length() )
00296 {
00297 jopen_url += "?template_path=";
00298 jopen_url += metaFile;
00299 if( context.length() )
00300 {
00301 jopen_url += "&context=";
00302 jopen_url += context;
00303 }
00304 }
00305 else if(context.length() )
00306 {
00307 jopen_url += "?context=";
00308 jopen_url += context;
00309 }
00310 if( pText )
00311 {
00312 pText->setContent(value);
00313 ret = ret.replace("$label$",label.c_str()).replace("$name$",name.c_str())
00314 .replace("$control$", pText->getHtml().c_str())
00315 .replace("$id$",name.c_str())
00316 .replace("metatagPick.cgi",jopen_url.c_str());
00317 delete pText;
00318 }
00319 return ret;
00320 }
00321 string forms_base::makeImageBox( string label, string name,
00322 string value, string size)
00323 {
00324 ocString ret = formTemplate.getParagraph("image_group");
00325 ocTextbox * pText = textEntry( name, "125", size );
00326 if( pText )
00327 {
00328 pText->setContent(value);
00329 ret = ret.replace("$label$",label.c_str()).replace("$name$",name.c_str())
00330 .replace("$control$", pText->getHtml().c_str())
00331 .replace("$id$",name.c_str());
00332 delete pText;
00333 }
00334 return ret;
00335 }
00336 string forms_base::makeTextArea( string label, string name,
00337 string value, string rows, string cols)
00338 {
00339 ocString ret = formTemplate.getParagraph("wide_group");
00340 ocTextarea * pText = areaEntry( name, rows, cols );
00341 if( pText )
00342 {
00343 pText->setContent(value);
00344 ret = ret.replace("$label$",label.c_str()).replace("$name$",name.c_str())
00345 .replace("$control$", pText->getHtml().c_str());
00346 delete pText;
00347 }
00348 return ret;
00349 }
00350 string forms_base::makeStateBox( string label, string name, string value)
00351 {
00352 ocString ret = formTemplate.getParagraph("control_group");
00353 ocSelect * pCombo = cmboManualEntry( name,
00354 "Alabama=AL,Alaska=AK,Arizona=AZ,Arkansas=AR,California=CA,Colorado=CO,Connecticut=CT,Washington DC=DC,"
00355 "Delaware=DE,Florida=FL,Georgia=GA,Hawaii=HI,Idaho=ID,Illinois=IL,Indiana=IN,Iowa=IA,Kansas=KS,Kentucky=KY,"
00356 "Louisiana=LA,Maine=ME,Maryland=MD,Massachusetts=MA,Michigan=MI,Minnesota=MN,Mississippi=MS,Missouri=MO,"
00357 "Montana=MT,Nebraska=NE,Nevada=NV,New Hampshire=NH,New Jersey=NJ,New Mexico=NM,New York=NY,North Carolina=NC,"
00358 "North Dakota=ND,Ohio=OH,Oklahoma=OK,Oregon=OR,Pennsylvania=PA,Puerto Rico=PR,Rhode Island=RI,South Carolina=SC,"
00359 "South Dakota=SD,Tennessee=TN,Texas=TX,Utah=UT,Vermont=VT,Virginia=VA,Washington=WA,West Virginia=WV,Wisconsin=WI,"
00360 "Wyoming=WY","",value);
00361 if( pCombo )
00362 {
00363 pCombo->setContent(value);
00364 ret = ret.replace("$label$",label.c_str()).replace("$name$",name.c_str())
00365 .replace("$control$", pCombo->getHtml().c_str());
00366 delete pCombo;
00367 }
00368 return ret;
00369 }
00370
00371 string forms_base::makeBoolBox( string label, string name, bool value )
00372 {
00373 ocString ret = formTemplate.getParagraph("control_group");
00374 ocBoolbox * pbBox = boolBox( name, name );
00375 if( pbBox )
00376 {
00377 string strValue = value?"1":"0";
00378 pbBox->setContent(strValue);
00379 ret = ret.replace("$label$",label.c_str()).replace("$name$",name.c_str())
00380 .replace("$control$", pbBox->getHtml().c_str());
00381 }
00382 return ret;
00383 }
00384
00385 string forms_base::makeDateGroup( string label, string name,
00386 time_date & value, int yearStart, int yearEnd )
00387 {
00388 ocString ret = formTemplate.getParagraph("control_group");
00389 ocString val; val.append(value);
00390 ocHidden * pText = ctrlDateGroup( name, yearStart, yearEnd );
00391 string month = value.format("%m");
00392 string day = value.format("%d");
00393 string year= value.format("%Y");
00394
00395
00396 if( pText )
00397 {
00398 pText->setContent(val);
00399
00400 string groupText = pText->getHtml() + "\n ";
00401
00402 ocSelect * pCombo = dynamic_cast<ocSelect*>(pText->getNext());
00403 if( pCombo )
00404 {
00405 pCombo->setContent( month );
00406 groupText += pCombo->getHtml() + "\n / ";
00407 }
00408 else
00409 {
00410 return ret.replace("$label$",label.c_str()).replace("$name$",name.c_str())
00411 .replace("$control$", groupText.c_str());
00412 }
00413
00414 pCombo = dynamic_cast<ocSelect*>(pCombo->getNext());
00415 if( pCombo )
00416 {
00417 pCombo->setContent( day );
00418 groupText += pCombo->getHtml() + "\n / ";
00419 }
00420 else
00421 {
00422 return ret.replace("$label$",label.c_str()).replace("$name$",name.c_str())
00423 .replace("$control$", groupText.c_str());
00424 }
00425
00426 pCombo = dynamic_cast<ocSelect*>(pCombo->getNext());
00427 if( pCombo )
00428 {
00429 pCombo->setContent( year );
00430 groupText += pCombo->getHtml();
00431 }
00432 ret = ret.replace("$label$",label.c_str()).replace("$name$",name.c_str())
00433 .replace("$control$", groupText.c_str());
00434 delete pText;
00435 }
00436 return ret;
00437 }