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
00028 #include "BaseForm.h"
00029 #include "WolfshadeWeb.h"
00030
00031
00032 #include "ObjectForm.h"
00033
00034
00035 namespace cgi
00036 {
00037
00038
00039 ObjectForm::ObjectForm(Web *web)
00040 :BaseForm(web, "objectform")
00041 ,m_edit(0)
00042 ,m_error(false)
00043 ,m_edita(0)
00044 ,m_editx(0)
00045 ,m_editr(0)
00046 {
00047 Query q(GetDatabase());
00048
00049 q.get_result("select * from obj_type");
00050 while (q.fetch_row())
00051 {
00052 db::Obj_type *tmp = new db::Obj_type(GetDatabase(),&q);
00053 m_objtype[tmp -> num] = tmp;
00054 }
00055 q.free_result();
00056
00057 q.get_result("select * from obj_material");
00058 while (q.fetch_row())
00059 {
00060 db::Obj_material *tmp = new db::Obj_material(GetDatabase(),&q);
00061 m_material[tmp -> num] = tmp;
00062 }
00063 q.free_result();
00064 }
00065
00066
00067 ObjectForm::~ObjectForm()
00068 {
00069 for (objtypes_t::iterator it = m_objtype.begin(); it != m_objtype.end(); it++)
00070 {
00071 delete (*it).second;
00072 }
00073 for (materials_t::iterator it = m_material.begin(); it != m_material.end(); it++)
00074 {
00075 delete (*it).second;
00076 }
00077 }
00078
00079
00080 void ObjectForm::Process()
00081 {
00082 WolfshadeWeb *pclWeb = static_cast<WolfshadeWeb *>(GetWeb());
00083 char action[200];
00084
00085 if (GetForm() -> getvalue("objectform",action,200))
00086 {
00087 char slask[100];
00088 if (GetForm() -> getvalue("edita",slask,100))
00089 {
00090 m_edita = atol(slask);
00091 }
00092 if (GetForm() -> getvalue("editx",slask,100))
00093 {
00094 m_editx = atol(slask);
00095 }
00096 if (GetForm() -> getvalue("editr",slask,100))
00097 {
00098 m_editr = atol(slask);
00099 }
00100 if (!strcmp(action,"edit"))
00101 {
00102 GetForm() -> getvalue("edit",slask,100);
00103 m_edit = atol(slask);
00104 }
00105 else
00106 if (!strcmp(action," Save "))
00107 {
00108 GetForm() -> getvalue("num",slask,100);
00109 long num = atol(slask);
00110 GetForm() -> getvalue("onum",slask,100);
00111 long onum = atol(slask);
00112 db::Obj obj(GetDatabase(),num);
00113
00114 if (num != onum && obj.num)
00115 {
00116 m_error = true;
00117 }
00118 else
00119 {
00120 long affbit = 0;
00121 long wearbit = 0;
00122 char value[256];
00123 GetForm() -> getfirst(slask,100,value,256);
00124 while (*slask)
00125 {
00126 if (!strcmp(slask,"affbit"))
00127 affbit |= atol(value);
00128 if (!strcmp(slask,"wearbit"))
00129 wearbit |= atol(value);
00130 GetForm() -> getnext(slask,100,value,256);
00131 }
00132
00133 GetForm() -> EnableRaw( true );
00134 obj.num = num;
00135 GetForm() -> getvalue("alias",obj.alias,255);
00136 GetForm() -> getvalue("name",obj.name,255);
00137 GetForm() -> getvalue("descr",obj.description,255);
00138 GetForm() -> getvalue("sdescr",obj.sitting_description,255);
00139 GetForm() -> getvalue("type",slask,100);
00140 obj.object_type = atol(slask);
00141 sprintf(obj.affbit,"%ld",affbit);
00142 sprintf(obj.wearbit,"%ld",wearbit);
00143 GetForm() -> getvalue("val0",slask,100);
00144 obj.val0 = atol(slask);
00145 GetForm() -> getvalue("val1",slask,100);
00146 obj.val1 = atol(slask);
00147 GetForm() -> getvalue("val2",slask,100);
00148 obj.val2 = atol(slask);
00149 GetForm() -> getvalue("val3",slask,100);
00150 obj.val3 = atol(slask);
00151 GetForm() -> getvalue("val4",slask,100);
00152 obj.val4 = atol(slask);
00153 GetForm() -> getvalue("weight",slask,100);
00154 obj.weight = atol(slask);
00155 GetForm() -> getvalue("cost",slask,100);
00156 obj.cost = atol(slask);
00157 GetForm() -> getvalue("material",slask,100);
00158 obj.material = atol(slask);
00159
00160 obj.save();
00161 m_edit = num;
00162 }
00163 }
00164 else
00165 if (!strcmp(action," Delete Affect "))
00166 {
00167 GetForm() -> getvalue("num",slask,100);
00168 long num = atol(slask);
00169 db::Obj_affect x(GetDatabase(),num);
00170 x.erase();
00171 GetForm() -> getvalue("objnum",slask,100);
00172 m_edit = atol(slask);
00173 }
00174 else
00175 if (!strcmp(action," Save Affect ") ||
00176 !strcmp(action," Add Affect ") )
00177 {
00178 GetForm() -> getvalue("num",slask,100);
00179 long num = atol(slask);
00180 db::Obj_affect x(GetDatabase(),num);
00181 GetForm() -> getvalue("objnum",slask,100);
00182 long objnum = atol(slask);
00183
00184 x.obj = objnum;
00185 GetForm() -> getvalue("location",slask,100);
00186 x.location = atol(slask);
00187 GetForm() -> getvalue("affect",slask,100);
00188 x.affect = atol(slask);
00189 if (x.location)
00190 x.save();
00191
00192 m_edit = objnum;
00193 }
00194 else
00195 if (!strcmp(action," Save Extra ") ||
00196 !strcmp(action," Add Extra ") )
00197 {
00198 GetForm() -> getvalue("num",slask,100);
00199 long num = atol(slask);
00200 db::Obj_extra x(GetDatabase(),num);
00201 GetForm() -> getvalue("objnum",slask,100);
00202 long objnum = atol(slask);
00203
00204 GetForm() -> EnableRaw(true);
00205 x.obj = objnum;
00206 GetForm() -> getvalue("keyword",x.keyword,255);
00207 GetForm() -> getvalue("descr",x.description,255);
00208 x.save();
00209
00210 m_edit = objnum;
00211 }
00212 else
00213 if (!strcmp(action," Delete Resource "))
00214 {
00215 GetForm() -> getvalue("num",slask,100);
00216 long num = atol(slask);
00217 db::Obj_resource x(GetDatabase(),num);
00218 x.erase();
00219 GetForm() -> getvalue("objnum",slask,100);
00220 m_edit = atol(slask);
00221 }
00222 else
00223 if (!strcmp(action," Save Resource ") ||
00224 !strcmp(action," Add Resource "))
00225 {
00226 GetForm() -> getvalue("num",slask,100);
00227 long num = atol(slask);
00228 db::Obj_resource x(GetDatabase(),num);
00229 GetForm() -> getvalue("objnum",slask,100);
00230 long objnum = atol(slask);
00231
00232 x.obj = objnum;
00233 GetForm() -> getvalue("resource",slask,100);
00234 x.resource = atol(slask);
00235 GetForm() -> getvalue("amount",slask,100);
00236 x.amount = atol(slask);
00237 if (x.resource)
00238 x.save();
00239
00240 m_edit = objnum;
00241 }
00242 else
00243 if (!strcmp(action," Post Picture "))
00244 {
00245 char fn[256];
00246 GetForm() -> getvalue("objnum",slask,100);
00247 long objnum = atol(slask);
00248 GetForm() -> getvalue("the_file",fn,255);
00249 if (!strncmp(fn,"/tmp/",5) && strlen(fn) > 5)
00250 {
00251 db::Obj obj(GetDatabase(),objnum);
00252 obj.pic = AddPic(obj.pic,fn);
00253 obj.save();
00254 }
00255
00256 m_edit = objnum;
00257 }
00258 else
00259 if (!strcmp(action,"pic"))
00260 {
00261 GetForm() -> getvalue("obj",slask,100);
00262 long objnum = atol(slask);
00263 GetForm() -> getvalue("pic",slask,100);
00264 long picnum = atol(slask);
00265 db::Obj obj(GetDatabase(),objnum);
00266 if (obj.pic == picnum)
00267 {
00268 db::Pic x(GetDatabase(),obj.pic);
00269 pclWeb -> SetPic(x.pic,x.ext);
00270 }
00271 }
00272 }
00273 }
00274
00275
00276 void ObjectForm::Select(const string &)
00277 {
00278 }
00279
00280
00281 void ObjectForm::List()
00282 {
00283 }
00284
00285
00286 void ObjectForm::Display(long)
00287 {
00288 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00289 Database *db = GetDatabase();
00290 Query q(db);
00291 Query q2(db);
00292 long zonesize = 0;
00293 char sql[200];
00294
00295 zonesize = EditingZone();
00296
00297 if (!m_edit)
00298 web -> DisplayStartAntalForm();
00299
00300 if (m_error)
00301 {
00302 printf("<h3>New Object# is already taken</h3>");
00303 }
00304
00305 {
00306 if (m_edit)
00307 sprintf(sql,"select * from obj where num=%ld",m_edit);
00308 else
00309 {
00310 if (GetObjtype() || GetMaterial())
00311 {
00312 char slask[100];
00313
00314 strcpy(sql,"select * from obj");
00315 strcpy(slask," where");
00316 if (GetObjtype())
00317 {
00318 sprintf(sql + strlen(sql),"%s object_type=%ld",slask,GetObjtype());
00319 strcpy(slask," and");
00320 }
00321 if (GetMaterial())
00322 {
00323 sprintf(sql + strlen(sql),"%s material=%ld",slask,GetMaterial());
00324 strcpy(slask," and");
00325 }
00326 if (GetZone())
00327 {
00328 sprintf(sql + strlen(sql),"%s num>=%ld and num<%ld",
00329 slask,
00330 GetZone() * 100,GetZone() * 100 + zonesize);
00331 }
00332 strcat(sql," order by num");
00333 }
00334 else
00335 if (GetZone())
00336 {
00337 sprintf(sql,"select * from obj where num>=%ld and num<%ld order by num",
00338 GetZone() * 100,GetZone() * 100 + zonesize);
00339 }
00340 else
00341 {
00342 sprintf(sql,"select * from obj where num>=%ld order by num limit %ld",GetStart(),GetAntal());
00343 }
00344 }
00345 q.get_result(sql);
00346 char header[100];
00347
00348 if (m_edit)
00349 sprintf(header," Editing Item#%ld",m_edit);
00350 else
00351 sprintf(header," Items (%ld items displayed)",q.num_rows());
00352 Table tbl("#000000", 3, header);
00353 printf("<tr bgcolor=#ffffff>");
00354 printf("<th align=left> Pic</th>");
00355 printf("<th align=left> Obj | Vnum</th>");
00356 printf("<th align=left> Type</th>");
00357 printf("<th align=left> Material</th>");
00358 printf("<th>Cost</th>");
00359 printf("</tr>");
00360
00361 while (q.fetch_row())
00362 {
00363 db::Obj obj(db,&q);
00364 db::Obj_type *tmp = m_objtype[obj.object_type];
00365 db::Obj_material *pm = m_material[obj.material];
00366
00367 printf("<tr bgcolor=#c0c0c0>");
00368 printf("<td bgcolor=#000000 align=middle>");
00369 if (obj.pic)
00370 {
00371 Table tbl("#ffffff", 0);
00372 printf("<tr><td bgcolor=#000000>");
00373 printf("<img src=%s?%s=pic&obj=%ld&pic=%ld>",
00374 GetCgiName().c_str(),
00375 GetFormName().c_str(),obj.num,obj.pic);
00376 printf("</td></tr>");
00377 }
00378 printf("</td>");
00379 printf("<td bgcolor=#808080 valign=middle>");
00380 ShowObj(obj,true);
00381 printf("</td>");
00382 printf("<td bgcolor=#c0c0c0>");
00383 if (tmp)
00384 printf(" %s ",tmp -> name);
00385 printf("</td>");
00386 printf("<td bgcolor=#c0c0c0>");
00387 if (pm)
00388 printf(" %s ",pm -> name);
00389 printf("</td>");
00390 printf("<td align=right> %ld copper </td>",obj.cost);
00391 printf("</tr>");
00392 }
00393 q.free_result();
00394 }
00395 printf("<br>");
00396
00397 if (m_edit)
00398 {
00399 db::Obj obj(db,m_edit);
00400
00401
00402 {
00403 Table tbl("#000000", 3, " Picture");
00404 printf("<form action=%s method=post enctype=\"multipart/form-data\">",
00405 GetCgiName().c_str());
00406 printf("<input type=hidden name=objnum value=%ld>",obj.num);
00407 if (obj.pic)
00408 {
00409 printf("<tr bgcolor=#ffffff><td colspan=2 align=middle>");
00410 printf("<img src=%s?%s=pic&obj=%ld&pic=%ld>",
00411 GetCgiName().c_str(),
00412 GetFormName().c_str(),obj.num,obj.pic);
00413 printf("</td></tr>");
00414 }
00415 printf("<tr bgcolor=#ffffff><td colspan=2> ");
00416 printf("<input type=file name=the_file>");
00417 printf(" </td></tr>");
00418 inputsubmit(" Post Picture ");
00419 printf("</form>");
00420 }
00421 printf("<br>");
00422
00423 if (m_editr)
00424 {
00425 db::Obj_resource x(db,m_editr);
00426 {
00427 Table tbl("#000000", 3);
00428
00429 printf("<form action=%s method=post>",GetCgiName().c_str());
00430 printf("<input type=hidden name=num value=%ld>",x.num);
00431 printf("<input type=hidden name=objnum value=%ld>",obj.num);
00432
00433 inputselect(q2,"Resource","resource","select num,alias from resource order by alias",x.resource,true);
00434 inputnum("Amount","amount",x.amount);
00435 inputsubmit(" Save Resource ");
00436 inputsubmit(" Delete Resource ");
00437
00438 printf("</form>");
00439 }
00440 printf("<br>");
00441 }
00442 else
00443 if (m_edita)
00444 {
00445 db::Obj_affect x(db,m_edita);
00446 {
00447 Table tbl("#000000", 3);
00448
00449 printf("<form action=%s method=post>",GetCgiName().c_str());
00450 printf("<input type=hidden name=num value=%ld>",x.num);
00451 printf("<input type=hidden name=objnum value=%ld>",obj.num);
00452
00453 inputselect(q2,"Location","location","select num,name from obj_affectnames",x.location);
00454 inputnum("Affect","affect",x.affect);
00455 inputsubmit(" Save Affect ");
00456 inputsubmit(" Delete Affect ");
00457
00458 printf("</form>");
00459 }
00460 printf("<br>");
00461 }
00462 else
00463 if (m_editx)
00464 {
00465 }
00466 else
00467 {
00468 Table tbl("#000000", 3);
00469 long affbit = asciiconvert(obj.affbit);
00470 long wearbit = asciiconvert(obj.wearbit);
00471
00472 printf("<form action=%s method=post>",GetCgiName().c_str());
00473 printf("<input type=hidden name=onum value=%ld>",obj.num);
00474
00475 inputnum("Vnum", "num", obj.num);
00476 inputstr("Alias","alias",40,obj.alias);
00477 inputstr("Name","name",60,obj.name,true);
00478 textarea("Description","descr",obj.description,true);
00479 textarea("Sitting Description","sdescr",obj.sitting_description,true);
00480 inputselect(q,"Type","type","select num,name from obj_type order by name",obj.object_type);
00481
00482 inputbit(q,"Extra Bits","affbit","select num,name from obj_affbit order by name",affbit,3);
00483
00484 inputbit(q,"Wear Bits","wearbit","select num,name from obj_wearbit order by name",wearbit,3);
00485
00486
00487 switch (obj.object_type)
00488 {
00489 case 6:
00490 inputnum("AC", "val0", obj.val0);
00491 printf("<input type=hidden name=val1 value=%ld>",obj.val1);
00492 printf("<input type=hidden name=val2 value=%ld>",obj.val2);
00493 printf("<input type=hidden name=val3 value=%ld>",obj.val3);
00494 printf("<input type=hidden name=val4 value=%ld>",obj.val4);
00495 break;
00496 case 12:
00497 inputnum("ToRoom", "val0", obj.val0);
00498 inputnum("TimeToLive (minutes)", "val1", obj.val1);
00499 printf("<input type=hidden name=val2 value=%ld>",obj.val2);
00500 printf("<input type=hidden name=val3 value=%ld>",obj.val3);
00501 printf("<input type=hidden name=val4 value=%ld>",obj.val4);
00502 break;
00503 case 2:
00504 inputnum("LightPower (1-6)", "val0", obj.val0);
00505 inputnum("Capacity (hours)", "val1", obj.val1);
00506 printf("<input type=hidden name=val2 value=%ld>",obj.val2);
00507 printf("<input type=hidden name=val3 value=%ld>",obj.val3);
00508 printf("<input type=hidden name=val4 value=%ld>",obj.val4);
00509 break;
00510 case 3:
00511 inputnum("SpellLevel", "val0", obj.val0);
00512 inputnum("Spell#1", "val1", obj.val1);
00513 inputnum("Spell#2", "val2", obj.val2);
00514 inputnum("Spell#3", "val3", obj.val3);
00515 inputnum("Spell#4", "val4", obj.val4);
00516 break;
00517 case 11:
00518 case 10:
00519 case 5:
00520 case 14:
00521 inputnum("Val0", "val0", obj.val0);
00522 inputnum("Val1", "val1", obj.val1);
00523 inputnum("Val2", "val2", obj.val2);
00524 inputnum("Val3", "val3", obj.val3);
00525 inputnum("Val4", "val4", obj.val4);
00526 break;
00527 case 8:
00528 case 9:
00529 inputnum("Val0", "val0", obj.val0);
00530 inputnum("Val1", "val1", obj.val1);
00531 inputnum("Val2", "val2", obj.val2);
00532 printf("<input type=hidden name=val3 value=%ld>",obj.val3);
00533 printf("<input type=hidden name=val4 value=%ld>",obj.val4);
00534 break;
00535 }
00536
00537 inputnum("Weight","weight",obj.weight);
00538 inputnum("Cost","cost",obj.cost);
00539 inputselect(q,"Material","material","select num,name from obj_material order by name",obj.material);
00540
00541
00542 inputsubmit(" Save ");
00543
00544 printf("</form>");
00545 }
00546 printf("<br>");
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558 sprintf(sql,"select * from obj_affect where obj=%ld",obj.num);
00559 q.get_result(sql);
00560 if (q.num_rows())
00561 {
00562 Table tbl("#000000", 3, " Affects");
00563 printf("<tr bgcolor=#ffffff>");
00564 printf("<th>Location</th>");
00565 printf("<th>Affect</th>");
00566 printf("<th></th>");
00567 printf("</tr>");
00568 while (q.fetch_row())
00569 {
00570 db::Obj_affect x(db,&q);
00571 db::Obj_affectnames loc(db,x.location);
00572 printf("<tr bgcolor=#ffffff>");
00573 printf("<td> %s </td>",loc.name);
00574 printf("<td align=right> %ld </td>",x.affect);
00575 printf("<td> [ ");
00576 printf("<a href=%s?objectform=edit&edit=%ld&edita=%ld>edit</a>",
00577 GetCgiName().c_str(),obj.num,x.num);
00578 printf(" ] </td>");
00579 printf("</tr>");
00580 }
00581 }
00582 if (q.num_rows())
00583 {
00584 printf("<br>");
00585 }
00586 q.free_result();
00587
00588
00589 {
00590 Table tbl("#000000", 3);
00591
00592 SetColor("#c0ffff");
00593 printf("<form action=%s method=post>",GetCgiName().c_str());
00594 printf("<input type=hidden name=num value=%d>",0);
00595 printf("<input type=hidden name=objnum value=%ld>",obj.num);
00596
00597 inputselect(q2,"Location","location","select num,name from obj_affectnames",-1);
00598 inputnum("Affect","affect",0);
00599 inputsubmit(" Add Affect ");
00600
00601 printf("</form>");
00602 SetColor("#ffffc0");
00603 }
00604 printf("<br>");
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616 sprintf(sql,"select * from obj_extra where obj=%ld",obj.num);
00617 q.get_result(sql);
00618 while (q.fetch_row())
00619 {
00620 db::Obj_extra x(db,&q);
00621 {
00622 Table tbl("#000000", 3);
00623
00624 printf("<form action=%s method=post>",GetCgiName().c_str());
00625 printf("<input type=hidden name=num value=%ld>",x.num);
00626 printf("<input type=hidden name=objnum value=%ld>",obj.num);
00627
00628 inputstr("Keyword","keyword",60,x.keyword);
00629 textarea("Description","descr",x.description,true);
00630 inputsubmit(" Save Extra ");
00631
00632 printf("</form>");
00633 }
00634 printf("<br>");
00635 }
00636 q.free_result();
00637
00638
00639 {
00640 Table tbl("#000000", 3);
00641
00642 SetColor("#c0ffff");
00643 printf("<form action=%s method=post>",GetCgiName().c_str());
00644 printf("<input type=hidden name=num value=%d>",0);
00645 printf("<input type=hidden name=objnum value=%ld>",obj.num);
00646
00647 inputstr("Keyword","keyword",60,"");
00648 textarea("Description","descr","");
00649 inputsubmit(" Add Extra ");
00650
00651 printf("</form>");
00652 SetColor("#ffffc0");
00653 }
00654 printf("<br>");
00655
00656
00657 sprintf(sql,"select * from obj_resource where obj=%ld",obj.num);
00658 q.get_result(sql);
00659 if (q.num_rows())
00660 {
00661 Table tbl("#000000", 3, " Resources");
00662 printf("<tr bgcolor=#ffffff>");
00663 printf("<th>Resource</th>");
00664 printf("<th>Amount</th>");
00665 printf("<th></th>");
00666 printf("</tr>");
00667 while (q.fetch_row())
00668 {
00669 db::Obj_resource x(db,&q);
00670 db::Resource loc(db,x.resource);
00671 printf("<tr bgcolor=#808080>");
00672 printf("<td> %s </td>",htmlcolor(loc.name));
00673 printf("<td align=right> %ld </td>",x.amount);
00674 printf("<td> [ ");
00675 printf("<a href=%s?objectform=edit&edit=%ld&editr=%ld>edit</a>",
00676 GetCgiName().c_str(),obj.num,x.num);
00677 printf(" ] </td>");
00678 printf("</tr>");
00679 }
00680 }
00681 if (q.num_rows())
00682 {
00683 printf("<br>");
00684 }
00685 q.free_result();
00686
00687
00688 {
00689 Table tbl("#000000", 3);
00690
00691 SetColor("#c0ffff");
00692 printf("<form action=%s method=post>",GetCgiName().c_str());
00693 printf("<input type=hidden name=num value=%d>",0);
00694 printf("<input type=hidden name=objnum value=%ld>",obj.num);
00695
00696 inputselect(q2,"Resource","resource","select num,alias from resource order by alias",-1);
00697 inputnum("Amount","amount",0);
00698 inputsubmit(" Add Resource ");
00699
00700 printf("</form>");
00701 SetColor("#ffffc0");
00702 }
00703 printf("<br>");
00704
00705 }
00706 }
00707
00708
00709 }
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734