00001 #ifndef OPEN_CORE_FORMS_H
00002 #define OPEN_CORE_FORMS_H 123456
00003 #include "ocControls.h"
00004 #include "read_base.hpp"
00005
00006 #ifdef WEB_USER_RESTRICTED
00007
00008 string formButtons( long long key,
00009 string, string, string )
00010 {
00011 string ret;
00012 if( key )
00013 {
00014 ret += "<input type='button' onclick='doUpdate()' name='action' class='action' value=' Update '>";
00015 }
00016 else
00017 {
00018 ret += "<input type='button' onclick='doInsert()' name='action' class='action' value=' Continue '>";
00019 }
00020 return ret;
00021 }
00022 #else
00023
00024 string formButtons( string iLabel=" Insert ",
00025 string uLabel=" Update ",
00026 string dLabel=" Delete ")
00027 {
00028 string ret;
00029 #ifndef NO_INSERT_BUTTON
00030 ret += "<input type='button' onclick='doInsert()' name='action' class='action' value='";
00031 ret += iLabel;
00032 ret += "'> ";
00033 #endif
00034 #ifndef NO_UPDATE_BUTTON
00035
00036 ret += "<input type='button' onclick='doUpdate()' name='action' class='action' value='";
00037 ret += uLabel;
00038 ret += "'> ";
00039 #endif
00040 #ifndef NO_DELETE_BUTTON
00041 ret += "<input type='button' onclick='doDelete()' name='action' class='action' class='action' value='";
00042 ret += dLabel;
00043 ret += "'>";
00044 #endif
00045 return ret;
00046 }
00047 string formButtons( long long key,
00048 string iLabel=" Insert ",
00049 string uLabel=" Update ",
00050 string dLabel=" Delete " )
00051 {
00052 string ret;
00053 if( key )
00054 {
00055 #ifndef NO_UPDATE_BUTTON
00056 ret += "<input type='button' onclick='doUpdate()' name='action' class='action' value='";
00057 ret += uLabel;
00058 ret += "'> ";
00059 #endif
00060 #ifndef NO_DELETE_BUTTON
00061 ret += "<input type='button' onclick='doDelete()' name='action' class='action' value='";
00062 ret += dLabel;
00063 ret += "'> \n";
00064 #endif
00065 #ifndef NO_INSERT_BUTTON
00066 ret += "<input type='button' onclick='doReset()' name='action' class='action' value=' New - Reset Form '>";
00067 ret += " ";
00068 ret += "<input type='button' onclick='doNew()' name='action' class='action' value=' New - Keep Data '>";
00069 #endif
00070 }
00071 else
00072 {
00073 #ifndef NO_INSERT_BUTTON
00074 ret += "<input type='button' onclick='doInsert()' name='action' class='action' value='";
00075 ret += iLabel;
00076 ret += "'>";
00077 #else // hide the fact you inserting, make it look like an update, you will never get here unless this is the intent
00078 ret += "<input type='button' onclick='doInsert()' name='action' class='action' value='";
00079 ret += uLabel;
00080 ret += "'>";
00081 #endif
00082 }
00083 return ret;
00084 }
00085 #endif
00086
00087
00088
00089
00090
00091 ocTextbox * textEntry( string name, string size, string length = "", string attr = "onChange='ctrlChanged(this)'" )
00092 {
00093 attr += " id='";
00094 attr += name;
00095 attr += "''";
00096 string len = length.length()?length:size;
00097 ocTextbox * box = new ocTextbox( name, len, size, attr );
00098 return box;
00099 }
00100 ocFilebox * fileEntry( string name, string size, string length = "", string xtra_attr = "" )
00101 {
00102 string attr = "onChange='ctrlChanged(this)' id='";
00103 attr += name;
00104 attr += "'";
00105 if(xtra_attr.length())
00106 {
00107 attr += " ";
00108 attr += xtra_attr;
00109 }
00110 string len = length.length()?length:size;
00111 ocFilebox * box = new ocFilebox( name, len, size, attr );
00112 return box;
00113 }
00114
00115
00116 ocTextbox * staticEntry( string name, string size, string length = "" )
00117 {
00118 string attr = "readonly class='static' id='";
00119 attr += name;
00120 attr += "'";
00121 string len = length.length()?length:size;
00122 ocTextbox * box = new ocTextbox( name, len, size, attr );
00123 return box;
00124 }
00125 ocHidden * hiddenEntry( string name )
00126 {
00127 ocHidden * box = new ocHidden( name );
00128 return box;
00129 }
00130 ocTextbox * dateEntry( string name, string size )
00131 {
00132 string attr = "onChange='validDate(this,true)' id='";
00133 attr += name;
00134 attr += "'";
00135 ocTextbox * box = new ocTextbox( name, size, size, attr );
00136 return box;
00137 }
00138 ocTextbox * timeEntry( string name, string size )
00139 {
00140 string attr = "onChange='validTime(this,true)' id='";
00141 attr += name;
00142 attr += "'";
00143 ocTextbox * box = new ocTextbox( name, size, size, attr );
00144 return box;
00145 }
00146 ocTextbox * emailEntry( string name, string size, string length = "" )
00147 {
00148 string attr = "onChange='isEmail(this,true)' id='";
00149 attr += name;
00150 attr += "'";
00151 string len = length.length()?length:size;
00152 ocTextbox * box = new ocTextbox( name, len, size, attr );
00153 return box;
00154 }
00155 ocTextbox * ssnEntry( string name, string size )
00156 {
00157 string attr = "onChange='validSSN(this,true)' id='";
00158 attr += name;
00159 attr += "'";
00160 ocTextbox * box = new ocTextbox( name, size, size, attr );
00161 return box;
00162 }
00163 ocTextbox * zipEntry( string name, string size )
00164 {
00165 string attr = "onChange='isZip(this,true)' id='";
00166 attr += name;
00167 attr += "'";
00168 ocTextbox * box = new ocTextbox( name, size, size, attr );
00169 return box;
00170 }
00171 ocTextbox * phoneEntry( string name, string size )
00172 {
00173 string attr = "onChange='isPhoneNumber(this,true)' id='";
00174 attr += name;
00175 attr += "'";
00176 ocTextbox * box = new ocTextbox( name, size, size, attr );
00177 return box;
00178 }
00179 ocTextbox * longNumberEntry( string name, string size )
00180 {
00181 string attr = "onChange='hasFormattedNumericData(this,true)' id='";
00182 attr += name;
00183 attr += "'";
00184 ocTextbox * box = new ocTextbox( name, size, size, attr );
00185 return box;
00186 }
00187 ocTextbox * shortNumberEntry( string name, string size )
00188 {
00189 string attr = "onChange='hasNumericData(this,true)' id='";
00190 attr += name;
00191 attr += "'";
00192 ocTextbox * box = new ocTextbox( name, size, size, attr );
00193 return box;
00194 }
00195 ocPassword * pswdEntry( string name, string size )
00196 {
00197 string attr = "onChange='ctrlChanged(this)' id='";
00198 attr += name;
00199 attr += "'";
00200 ocPassword * box = new ocPassword( name, size, size, attr );
00201 return box;
00202 }
00203
00204
00205 ocSelect * cmboEntry( string name, string sql,
00206 ocString defaulted = "",
00207 string multiple = "" )
00208 {
00209
00210 string attributes = " name='";
00211 attributes += name;
00212 attributes += "' id='";
00213 attributes += name;
00214 attributes += "'";
00215 attributes += " onChange='ctrlChanged(this)' ";
00216 attributes += multiple;
00217 ocSelect * combo = new ocSelect(attributes);
00218
00219 if( defaulted.length() > 0 )
00220 {
00221 if(defaulted.find("=") == string::npos)
00222 {
00223 combo->addOption( defaulted, "-1" );
00224 }
00225 else
00226 {
00227 string lbl = defaulted.parse("=");
00228 string vlu = defaulted.parse("=");
00229 combo->addOption( lbl, vlu );
00230 }
00231 }
00232 if( sql.length() )
00233 {
00234 quickQuery qq;
00235 openRS & rs = qq.getData(sql);
00236 for( bool result=qq.opened; result; result=rs.next() )
00237 {
00238 string label = "";
00239 for( int lx=1; lx<rs.getFieldCount(); lx++ )
00240 {
00241 if( label.length() && rs.getField(lx).format().length() ) label += " - ";
00242 label += rs.getField(lx).format();
00243 }
00244 combo->addOption( label, rs.getField(0).format() );
00245 }
00246 }
00247 return combo;
00248 }
00249
00250
00251
00252
00253
00254
00255
00256
00257 ocSelect * cmboManualEntry( string name,
00258 ocString keyVals = "",
00259 string defaulted = "",
00260 string multiple = "" )
00261 {
00262
00263 string attributes = " name='";
00264 attributes += name;
00265 attributes += "' id='";
00266 attributes += name;
00267 attributes += "'";
00268 attributes += " onChange='ctrlChanged(this)' ";
00269 attributes += multiple;
00270 ocSelect * combo = new ocSelect(attributes);
00271
00272 if( defaulted.length() > 0 )
00273 {
00274 combo->addOption( defaulted, "-1" );
00275 }
00276 if( keyVals.length() )
00277 {
00278 while( keyVals.endOfParse() == false )
00279 {
00280 ocString pair = keyVals.parse(",");
00281 string val = pair.parse("=");
00282 string label = pair.parse("=");
00283 combo->addOption( val, label );
00284 }
00285 }
00286 return combo;
00287 }
00288
00289
00290
00291
00292
00293
00294
00295 ocCheckBoxes * checksEntry( string name,
00296 ocString keyVals = "",
00297 string defaulted = "",
00298 string moreattributes = "" )
00299 {
00300
00301 string attributes = " name='";
00302 attributes += name;
00303 attributes += "' id='";
00304 attributes += name;
00305 attributes += "' ";
00306 attributes += moreattributes;
00307 ocCheckBoxes * chks = new ocCheckBoxes(name, attributes);
00308
00309 if( defaulted.length() > 0 )
00310 {
00311 chks->addOption( defaulted, "-1" );
00312 }
00313 if( keyVals.length() )
00314 {
00315 while( keyVals.endOfParse() == false )
00316 {
00317 ocString pair = keyVals.parse(",");
00318 string val = pair.parse("=");
00319 string label = pair.parse("=");
00320 chks->addOption( val, label, " onChange='ctrlChanged(this)' " );
00321 }
00322 }
00323 return chks;
00324 }
00325 ocRadio * radioEntry( string name,
00326 ocString keyVals = "",
00327 string defaulted = "",
00328 string moreattributes = "" )
00329 {
00330
00331 string attributes = " name='";
00332 attributes += name;
00333 attributes += "' id='";
00334 attributes += name;
00335 attributes += "' ";
00336 attributes += moreattributes;
00337 ocRadio * rads = new ocRadio(name, attributes);
00338
00339 if( defaulted.length() > 0 )
00340 {
00341 rads->addOption( defaulted, "-1" );
00342 }
00343 if( keyVals.length() )
00344 {
00345 while( keyVals.endOfParse() == false )
00346 {
00347 ocString pair = keyVals.parse(",");
00348 string val = pair.parse("=");
00349 string label = pair.parse("=");
00350 rads->addOption( val, label," onChange='ctrlChanged(this)' " );
00351 }
00352 }
00353 return rads;
00354 }
00355
00356
00357
00358 ocHidden * ctrlDateGroup( string name,
00359 int yearStart = 2003,
00360 int yearEnd = 2015
00361 )
00362 {
00363
00364 string mattributes = " name='m_" + name + "' id='m_" + name + "' onChange='m_Changed(this)' ";
00365 string dattributes = " name='d_" + name + "' id='d_" + name + "' onChange='d_Changed(this)' ";
00366 string yattributes = " name='y_" + name + "' id='y_" + name + "' onChange='y_Changed(this)' ";
00367
00368 ocHidden * box = new ocHidden( name );
00369 ocSelect * mcombo = new ocSelect(mattributes);
00370 ocSelect * dcombo = new ocSelect(dattributes);
00371 ocSelect * ycombo = new ocSelect(yattributes);
00372 if( box && mcombo && dcombo && ycombo )
00373 {
00374
00375 box->addNext(mcombo);
00376 mcombo->addNext(dcombo);
00377 dcombo->addNext(ycombo);
00378
00379
00380 int idt;
00381 ycombo->addOption("YYYY","YYYY");
00382 for( idt=yearStart; idt <=yearEnd; idt++ )
00383 {
00384 ocString year;
00385 year.append(idt);
00386 ycombo->addOption( year, year );
00387 }
00388 mcombo->addOption("MM","MM");
00389 for( idt=1; idt<=12; idt++ )
00390 {
00391 ocString month;
00392 if( idt < 10 ) month="0";
00393 month.append(idt);
00394 mcombo->addOption( month, month );
00395 }
00396 dcombo->addOption("DD","DD");
00397 for( idt=1; idt <=31; idt++ )
00398 {
00399 ocString day;
00400 if( idt < 10 ) day = "0";
00401 day.append(idt);
00402 dcombo->addOption( day, day );
00403 }
00404 }
00405 return box;
00406 }
00407
00408 ocTextarea * areaEntry( string name, string rows="12", string cols="80" )
00409 {
00410 string attr = " name='";
00411 attr += name;
00412 attr += "' id='";
00413 attr += name;
00414 attr += "' rows='";
00415 attr += rows;
00416 attr += "' cols='";
00417 attr += cols;
00418 attr += "'";
00419 attr += " onChange='ctrlChanged(this)'";
00420 ocTextarea * ta = new ocTextarea(attr);
00421 return ta;
00422 }
00423
00424 ocBoolbox * boolBox( string name, string id )
00425 {
00426 string attr = "class='checkbox' onChange='ctrlChanged(this)' id='";
00427 attr += id;
00428 attr += "'";
00429 ocBoolbox * bbox = new ocBoolbox( name , attr, "1", "1" );
00430 return bbox;
00431 }
00432
00433 #endif
00434