00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021 #include <mysql/mysql.h>
00022 #include <libsql++.h>
00023 #include <string>
00024 using std::string;
00025 #include <libcgi++.h>
00026 #include <libwolfshade.h>
00027 #include <ctype.h>
00028
00029 #include "WolfshadeWeb.h"
00030 #include "BaseForm.h"
00031
00032
00033 namespace cgi
00034 {
00035
00036
00037 BaseForm::BaseForm(Web *web,const string &name)
00038 :WebForm(web,name)
00039 ,m_strColor("#ffffc0")
00040 {
00041 }
00042
00043
00044 BaseForm::~BaseForm()
00045 {
00046 }
00047
00048
00049 Database *BaseForm::GetDatabase()
00050 {
00051 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00052 return web -> GetDatabase();
00053 }
00054
00055
00056 long BaseForm::GetStart()
00057 {
00058 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00059 return web -> GetStart();
00060 }
00061
00062
00063 long BaseForm::GetAntal()
00064 {
00065 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00066 return web -> GetAntal();
00067 }
00068
00069
00070 long BaseForm::GetZone()
00071 {
00072 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00073 return web -> GetZone();
00074 }
00075
00076
00077 long BaseForm::GetRace()
00078 {
00079 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00080 return web -> GetRace();
00081 }
00082
00083
00084 long BaseForm::GetClass()
00085 {
00086 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00087 return web -> GetClass();
00088 }
00089
00090
00091 long BaseForm::GetObjtype()
00092 {
00093 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00094 return web -> GetObjtype();
00095 }
00096
00097
00098 long BaseForm::GetMaterial()
00099 {
00100 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00101 return web -> GetMaterial();
00102 }
00103
00104
00105 char *BaseForm::htmlcolor(const string &x)
00106 {
00107 string s;
00108 int fgcolor = -1;
00109 int bgcolor = -1;
00110 bool bold = false;
00111 bool ul = false;
00112 bool fl = false;
00113 bool infont = false;
00114 static char slask[2000];
00115
00116 for (size_t i = 0; i < x.size(); i++)
00117 {
00118 if (x[i] == 13)
00119 {
00120 s += "<br>";
00121 }
00122 else
00123 if (x[i] == ' ')
00124 {
00125 s += " ";
00126 }
00127 else
00128 if (x[i] == '&')
00129 {
00130
00131
00132
00133 bool ulo = ul;
00134 bool flo = fl;
00135 bool normal = false;
00136
00137 i++;
00138 switch (x[i])
00139 {
00140 case 'n':
00141 fgcolor = -1;
00142 bgcolor = -1;
00143 bold = false;
00144 ul = false;
00145 fl = false;
00146 normal = true;
00147 break;
00148
00149 case 'r':
00150 fgcolor = 1;
00151 bold = false;
00152 break;
00153 case 'g':
00154 fgcolor = 2;
00155 bold = false;
00156 break;
00157 case 'y':
00158 fgcolor = 3;
00159 bold = false;
00160 break;
00161 case 'b':
00162 fgcolor = 4;
00163 bold = false;
00164 break;
00165 case 'm':
00166 fgcolor = 5;
00167 bold = false;
00168 break;
00169 case 'c':
00170 fgcolor = 6;
00171 bold = false;
00172 break;
00173 case 'w':
00174 fgcolor = 7;
00175 bold = false;
00176 break;
00177 case 'l':
00178 fgcolor = 0;
00179 bold = false;
00180 break;
00181
00182 case 'R':
00183 fgcolor = 1;
00184 bold = true;
00185 break;
00186 case 'G':
00187 fgcolor = 2;
00188 bold = true;
00189 break;
00190 case 'Y':
00191 fgcolor = 3;
00192 bold = true;
00193 break;
00194 case 'B':
00195 fgcolor = 4;
00196 bold = true;
00197 break;
00198 case 'M':
00199 fgcolor = 5;
00200 bold = true;
00201 break;
00202 case 'C':
00203 fgcolor = 6;
00204 bold = true;
00205 break;
00206 case 'W':
00207 fgcolor = 7;
00208 bold = true;
00209 break;
00210 case 'L':
00211 fgcolor = 0;
00212 bold = true;
00213 break;
00214
00215 case 'e':
00216 bgcolor = 1;
00217 break;
00218 case 'k':
00219 bgcolor = 2;
00220 break;
00221 case 'p':
00222 bgcolor = 3;
00223 break;
00224 case 'u':
00225 bgcolor = 4;
00226 break;
00227 case 'a':
00228 bgcolor = 5;
00229 break;
00230 case 'f':
00231 bgcolor = 6;
00232 break;
00233 case 'h':
00234 bgcolor = 7;
00235 break;
00236 case 'i':
00237 bgcolor = 0;
00238 break;
00239 case 'U':
00240 ul = true;
00241 break;
00242 case 'F':
00243 fl = true;
00244 break;
00245 }
00246 if (flo)
00247 {
00248 s += "</blink>";
00249 }
00250 if (ulo)
00251 {
00252 s += "</u>";
00253 }
00254 if (infont)
00255 {
00256 s += "</font>";
00257 }
00258 infont = false;
00259 if (!normal)
00260 {
00261 s += "<font style=\"";
00262 if (fgcolor > -1)
00263 {
00264 s += "color: #";
00265 s += (fgcolor & 1) ? "FF" : "00";
00266 s += (fgcolor & 2) ? "FF" : "00";
00267 s += (fgcolor & 4) ? "FF" : "00";
00268 s += ";";
00269 }
00270 if (bgcolor > -1)
00271 {
00272 s += "background-color: #";
00273 s += (bgcolor & 1) ? "FF" : "00";
00274 s += (bgcolor & 2) ? "FF" : "00";
00275 s += (bgcolor & 4) ? "FF" : "00";
00276 s += ";";
00277 }
00278 if (bold)
00279 {
00280 s += "font-weight: bold";
00281 }
00282 s += "\">";
00283 infont = true;
00284 if (ul)
00285 {
00286 s += "<u>";
00287 }
00288 if (fl)
00289 {
00290 s += "<blink>";
00291 }
00292 }
00293 }
00294 else
00295 {
00296 s += x[i];
00297 }
00298 }
00299 if (infont)
00300 {
00301 s += "</font>";
00302 }
00303 strcpy(slask, s.c_str());
00304 return slask;
00305 }
00306
00307
00308 char *BaseForm::nocolor(const string &str)
00309 {
00310 string s;
00311 static char slask[1000];
00312
00313 for (size_t i = 0; i < str.size(); i++)
00314 {
00315 if (str[i] == '&')
00316 i++;
00317 else
00318 s += str[i];
00319 }
00320 strcpy(slask, s.c_str());
00321 return slask;
00322 }
00323
00324
00325 void BaseForm::textarea(const string &txt,const string &name,const string &str,bool bPreview )
00326 {
00327 int qrows = 1;
00328 for (size_t i = 0; i < str.size(); i++)
00329 {
00330 if (str[i] == '\n')
00331 qrows++;
00332 }
00333 printf("<tr bgcolor=%s>",m_strColor.c_str());
00334 printf("<td>%s</td>",txt.c_str());
00335 printf("<td>");
00336 printf("<textarea name=\"%s\" rows=%d cols=81>",name.c_str(),qrows);
00337 printf("%s",str.c_str());
00338 printf("</textarea>");
00339 if (bPreview)
00340 {
00341 printf("<br><div style=\"background-color: #808080\">%s</div>",htmlcolor(str.c_str()));
00342 }
00343 printf("</td>");
00344 printf("</tr>");
00345 }
00346
00347
00348 long BaseForm::asciiconvert(const string &str)
00349 {
00350 long flags = 0;
00351 bool is_number = true;
00352
00353 for (size_t i = 0; i < str.size(); i++)
00354 {
00355 if (islower(str[i]))
00356 flags |= 1 << (str[i] - 'a');
00357 else
00358 if (isupper(str[i]))
00359 flags |= 1 << (25 + (str[i] - 'A'));
00360 if (!isdigit(str[i]))
00361 is_number = false;
00362 }
00363
00364 if (is_number)
00365 flags = atol(str.c_str());
00366
00367 return flags;
00368 }
00369
00370
00371 void BaseForm::inputnum(const string &title,const string &name,long value,int vad)
00372 {
00373 printf("<tr bgcolor=%s>",m_strColor.c_str());
00374 nbprintf("<td> %s </td>",title.c_str() );
00375 printf("<td><input type=text size=8 name=%s value=%ld>",name.c_str(),value);
00376 if (vad != VALUE_WHATEVER && value > 0)
00377 {
00378 printf("<div style=\"background-color: #808080\">");
00379 }
00380 switch (vad)
00381 {
00382 case VALUE_WHATEVER:
00383 break;
00384 case VALUE_IS_MOB:
00385 if (value > 0)
00386 {
00387 db::Mob mob(GetDatabase(),value);
00388 ShowMob(mob,true);
00389 }
00390 break;
00391 case VALUE_IS_OBJ:
00392 if (value > 0)
00393 {
00394 db::Obj obj(GetDatabase(),value);
00395 ShowObj(obj,true);
00396 }
00397 break;
00398 case VALUE_IS_ROOM:
00399 if (value > 0)
00400 {
00401 db::Room room(GetDatabase(),value);
00402 ShowRoom(room,true);
00403 }
00404 break;
00405 case VALUE_IS_ZONE:
00406 if (value > 0)
00407 {
00408 db::Zone zone(GetDatabase(),value);
00409 ShowZone(zone,true);
00410 }
00411 break;
00412 }
00413 if (vad != VALUE_WHATEVER && value > 0)
00414 {
00415 printf("</div>");
00416 }
00417 printf("</td>");
00418 printf("</tr>");
00419 }
00420
00421
00422 void BaseForm::inputcheck(const string &title,const string &name,bool checked)
00423 {
00424 printf("<tr bgcolor=%s>",m_strColor.c_str());
00425 nbprintf("<td> %s </td>",title.c_str() );
00426 printf("<td><input type=checkbox name=%s value=1%s>",name.c_str(),checked ? " CHECKED" : "");
00427 printf("</td>");
00428 printf("</tr>");
00429 }
00430
00431
00432 void BaseForm::inputselect(Query &q,const string &title,const string &name,const string &query,long value,bool bNocolor)
00433 {
00434 printf("<tr bgcolor=%s>",m_strColor.c_str());
00435 nbprintf("<td> %s </td>",title.c_str());
00436 printf("<td>");
00437 printf("<select name=%s>",name.c_str());
00438 printf("<option value=0>");
00439 q.get_result( (char *)query.c_str());
00440 while (q.fetch_row())
00441 {
00442 long num = q.getval();
00443 printf("<option value=%ld%s>%s",
00444 num,
00445 (num == value) ? " SELECTED" : "",
00446 bNocolor ? nocolor(q.getstr()) : q.getstr());
00447 }
00448 q.free_result();
00449 printf("</select>");
00450 printf("</td>");
00451 printf("</tr>");
00452 }
00453
00454
00455 void BaseForm::inputstr(const string &title,const string &name,int size,const string &value,bool bPreview )
00456 {
00457 printf("<tr bgcolor=%s>",m_strColor.c_str());
00458 nbprintf("<td> %s </td>",title.c_str());
00459 printf("<td><input type=text size=%d name=%s value=\"%s\">",size,name.c_str(),value.c_str());
00460 if (bPreview)
00461 {
00462 printf("<br><div style=\"background-color: #808080\">%s</div>",htmlcolor(value.c_str()));
00463 }
00464 printf("</td>");
00465 printf("</tr>");
00466 }
00467
00468
00469 void BaseForm::inputsubmit(const string &title)
00470 {
00471 printf("<tr bgcolor=%s>",m_strColor.c_str());
00472 printf("<td align=middle colspan=2>");
00473 printf(" <input type=submit name=%s value=\"%s\"> ",GetFormName().c_str(),title.c_str());
00474 printf("</td>");
00475 printf("</tr>");
00476 }
00477
00478
00479 void BaseForm::inputbit(Query &q,const string &title,const string &name,const string &query,long flags,int brk,bool bRadio )
00480 {
00481 int i = 1;
00482
00483 printf("<tr bgcolor=%s>",m_strColor.c_str());
00484 nbprintf("<td> %s </td>",title.c_str());
00485 printf("<td>");
00486 q.get_result( (char *)query.c_str());
00487 while (q.fetch_row())
00488 {
00489 long num = q.getval();
00490 long bit = 1 << num;
00491 printf(" <input type=%s name=%s value=%ld%s>%s ",
00492 bRadio ? "radio" : "checkbox",
00493 name.c_str(),
00494 bit,(flags & bit) ? " CHECKED" : "",q.getstr());
00495 if (i && i % brk == 0)
00496 {
00497 printf("<br>");
00498 }
00499 i++;
00500 }
00501 q.free_result();
00502 printf("</td>");
00503 printf("</tr>");
00504 }
00505
00506
00507 void BaseForm::ShowMob(db::Mob &x,bool bLink,bool bTd)
00508 {
00509 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00510
00511 if (bTd)
00512 printf("<td>");
00513
00514 if (bLink)
00515 printf("<a class=edit href=%s?page=%ld&mobform=edit&edit=%ld>",
00516 GetCgiName().c_str(),web -> GetMenuMob(),x.num);
00517 printf(" %s ",htmlcolor(x.name));
00518 if (bLink)
00519 printf("</a>");
00520 printf(" | <font color=#ffffff>%ld</font> ",x.num);
00521 if (bTd)
00522 printf("</td>");
00523 }
00524
00525
00526 void BaseForm::ShowObj(db::Obj &x,bool bLink,bool bTd)
00527 {
00528 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00529
00530 if (bTd)
00531 printf("<td>");
00532 if (bLink)
00533 printf("<a class=edit href=%s?page=%ld&objectform=edit&edit=%ld>",
00534 GetCgiName().c_str(),web -> GetMenuObj(),x.num);
00535 printf(" %s ",htmlcolor(x.name));
00536 if (bLink)
00537 printf("</a>");
00538 printf(" | <font color=#ffffff>%ld</font> ",x.num);
00539 if (bTd)
00540 printf("</td>");
00541 }
00542
00543
00544 void BaseForm::ShowRoom(db::Room &x,bool bLink,bool bTd,bool bNonum)
00545 {
00546 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00547
00548 if (bTd)
00549 printf("<td>");
00550 if (bLink)
00551 printf("<a class=edit href=%s?page=%ld&roomform=edit&edit=%ld>",
00552 GetCgiName().c_str(),web -> GetMenuRoom(),x.num);
00553 printf(" %s ",htmlcolor(x.name));
00554 if (bLink)
00555 printf("</a>");
00556 if (!bNonum)
00557 printf("| <font color=#ffffff>%ld</font> ",x.num);
00558 if (x.virtual_room)
00559 {
00560 printf("| <font color=#ffffff>virtual</font> ");
00561 printf("| <font face=courier>%s</font> ",htmlcolor(x.virtual_char));
00562 printf("| <font color=#ffffff>%c</font> ",*x.design_char);
00563 }
00564 if (bTd)
00565 printf("</td>");
00566 }
00567
00568
00569 void BaseForm::ShowZone(db::Zone &x,bool bLink,bool bTd)
00570 {
00571 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00572
00573 if (bTd)
00574 printf("<td>");
00575 if (bLink)
00576 printf("<a class=edit href=%s?page=%ld&zoneform=edit&edit=%ld&xzonex=%ld>",
00577 GetCgiName().c_str(),web -> GetMenuZone(),x.num,x.num);
00578 printf(" %s ",htmlcolor(x.name));
00579 if (bLink)
00580 printf("</a>");
00581 printf(" | <font color=#ffffff>%ld</font> ",x.num);
00582 if (bTd)
00583 printf("</td>");
00584 }
00585
00586
00587 void BaseForm::ShowVirtual(db::Vzone &x,bool bLink,bool bTd,bool bNonum)
00588 {
00589 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00590
00591 if (bTd)
00592 printf("<td>");
00593 if (bLink)
00594 printf("<a class=edit href=%s?page=%ld&virtualform=edit&edit=%ld>",
00595 GetCgiName().c_str(),web -> GetMenuVirtual(),x.num);
00596 printf(" %s ",htmlcolor(x.name));
00597 if (bLink)
00598 printf("</a>");
00599 if (!bNonum)
00600 printf(" | <font color=#ffffff>%ld</font> ",x.num);
00601 if (bTd)
00602 printf("</td>");
00603 }
00604
00605
00606 long BaseForm::EditingZone()
00607 {
00608 long zonesize = 0;
00609
00610 if (GetZone())
00611 {
00612 db::Zone zone(GetDatabase(),GetZone());
00613 printf("<table><tr>");
00614 printf("<td>Editing Zone</td>");
00615 printf("<td><div style=\"background-color: #808080\">");
00616 ShowZone(zone,true);
00617 printf("</div></td>");
00618 printf("<td>[ <a href=%s?xzonex=0>End Edit</a> ]</td>",GetCgiName().c_str());
00619 printf("</tr></table>");
00620 printf("<br>");
00621 zonesize = zone.size;
00622 }
00623 return zonesize;
00624 }
00625
00626
00627 void BaseForm::ShowRace(db::Race &x,bool bLink,bool bTd)
00628 {
00629 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00630
00631 if (bTd)
00632 printf("<td>");
00633 if (bLink)
00634 printf("<a class=edit href=%s?page=%ld&raceform=edit&edit=%ld>",
00635 GetCgiName().c_str(),web -> GetMenuRace(),x.num);
00636 printf(" %s ",htmlcolor(x.name));
00637 if (bLink)
00638 printf("</a>");
00639 printf(" | <font color=#ffffff>%ld</font> ",x.num);
00640 if (bTd)
00641 printf("</td>");
00642 }
00643
00644
00645 void BaseForm::ShowWeapon(db::Weapon &x,bool bLink,bool bTd)
00646 {
00647 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00648
00649 if (bTd)
00650 printf("<td>");
00651 if (bLink)
00652 printf("<a class=edit href=%s?page=%ld&weaponform=edit&edit=%ld>",
00653 GetCgiName().c_str(),web -> GetMenuWeapon(),x.num);
00654 printf(" %s ",htmlcolor(x.name));
00655 if (bLink)
00656 printf("</a>");
00657 printf(" | <font color=#ffffff>%ld</font> ",x.num);
00658 if (bTd)
00659 printf("</td>");
00660 }
00661
00662
00663 void BaseForm::inputdie(const string &title,const string &name,long val1,long val2)
00664 {
00665 printf("<tr bgcolor=%s>",m_strColor.c_str());
00666 nbprintf("<td> %s </td>",title.c_str() );
00667 printf("<td><input type=text size=8 name=%s1 value=%ld>",name.c_str(),val1);
00668 printf(" D ");
00669 printf("<input type=text size=8 name=%s2 value=%ld>",name.c_str(),val2);
00670 printf("</td>");
00671 printf("</tr>");
00672 }
00673
00674
00675 void BaseForm::ShowSkill(db::Skill &x,bool bLink,bool bTd)
00676 {
00677 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00678
00679 if (bTd)
00680 printf("<td>");
00681 if (bLink)
00682 printf("<a class=edit href=%s?page=%ld&skillform=edit&edit=%ld>",
00683 GetCgiName().c_str(),web -> GetMenuSkill(),x.num);
00684 printf(" %s ",htmlcolor(x.name));
00685 if (bLink)
00686 printf("</a>");
00687 printf(" | <font color=#ffffff>%ld</font> ",x.num);
00688 if (bTd)
00689 printf("</td>");
00690 }
00691
00692
00693 void BaseForm::ShowResource(db::Resource &x,bool bLink,bool bTd)
00694 {
00695 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00696
00697 if (bTd)
00698 printf("<td>");
00699 if (bLink)
00700 printf("<a class=edit href=%s?page=%ld&resourceform=edit&edit=%ld>",
00701 GetCgiName().c_str(),web -> GetMenuResource(),x.num);
00702 printf(" %s ",htmlcolor(x.name));
00703 if (bLink)
00704 printf("</a>");
00705 printf(" | <font color=#ffffff>%ld</font> ",x.num);
00706 if (bTd)
00707 printf("</td>");
00708 }
00709
00710
00711 long BaseForm::AddPic(long num,const string &filename)
00712 {
00713 db::Pic pic(GetDatabase(),num);
00714 size_t x = 0;
00715 for (size_t i = 0; i < filename.size(); i++)
00716 if (filename[i] == '.')
00717 x = i + 1;
00718 strcpy(pic.ext,filename.c_str() + x);
00719 pic.save();
00720 {
00721 Query q(GetDatabase());
00722 vector<string> sv;
00723 string query;
00724 Base64 bomb;
00725 char slask[100];
00726 bomb.encode_from_file( (char *)filename.c_str(),sv);
00727 query = "update pic set pic='";
00728 for (vector<string>::iterator it = sv.begin(); it != sv.end(); it++)
00729 {
00730 query += *it;
00731 query += '\n';
00732 }
00733 sprintf(slask,"' where num=%ld",pic.num);
00734 query += slask;
00735 q.execute( (char *)query.c_str());
00736 }
00737 return pic.num;
00738 }
00739
00740
00741 }
00742
00743