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 "ZoneForm.h"
00033
00034
00035 namespace cgi
00036 {
00037
00038
00039 ZoneForm::ZoneForm(Web *web)
00040 :BaseForm(web, "zoneform")
00041 ,m_edit(0)
00042 ,m_error(false)
00043 ,m_editm(0)
00044 ,m_edito(0)
00045 ,m_editg(0)
00046 {
00047 Query q(GetDatabase());
00048 q.get_result("select * from zone_reset");
00049 while (q.fetch_row())
00050 {
00051 db::Zone_reset *tmp = new db::Zone_reset(GetDatabase(),&q);
00052 m_reset[tmp -> num] = tmp;
00053 }
00054 q.free_result();
00055 }
00056
00057
00058 ZoneForm::~ZoneForm()
00059 {
00060 for (resets_t::iterator it = m_reset.begin(); it != m_reset.end(); it++)
00061 {
00062 delete (*it).second;
00063 }
00064 }
00065
00066
00067 void ZoneForm::Process()
00068 {
00069 char action[200];
00070
00071 if (GetForm() -> getvalue("zoneform",action,200))
00072 {
00073 char slask[200];
00074 if (GetForm() -> getvalue("editg",slask,100))
00075 {
00076 m_editg = atol(slask);
00077 }
00078 if (GetForm() -> getvalue("editm",slask,100))
00079 {
00080 m_editm = atol(slask);
00081 }
00082 if (GetForm() -> getvalue("edito",slask,100))
00083 {
00084 m_edito = atol(slask);
00085 }
00086 if (!strcmp(action,"edit"))
00087 {
00088 GetForm() -> getvalue("edit",slask,100);
00089 m_edit = atol(slask);
00090 }
00091 else
00092 if (!strcmp(action," Save "))
00093 {
00094 GetForm() -> getvalue("num",slask,100);
00095 long num = atol(slask);
00096 GetForm() -> getvalue("onum",slask,100);
00097 long onum = atol(slask);
00098 db::Zone zone(GetDatabase(),num);
00099
00100 if (num != onum && zone.num)
00101 {
00102 m_error = true;
00103 }
00104 else
00105 {
00106 GetForm() -> EnableRaw( true );
00107 zone.num = num;
00108 GetForm() -> getvalue("name",zone.name,255);
00109 GetForm() -> getvalue("lifespan",slask,100);
00110 zone.lifespan = atol(slask);
00111 GetForm() -> getvalue("resetmode",slask,100);
00112 zone.resetmode = atol(slask);
00113 GetForm() -> getvalue("size",slask,100);
00114 zone.size = atol(slask);
00115 zone.save();
00116 m_edit = num;
00117 }
00118 }
00119 else
00120 if (!strcmp(action," Delete Mob "))
00121 {
00122 Query q(GetDatabase());
00123 char sql[200];
00124 GetForm() -> getvalue("num",slask,100);
00125 long num = atol(slask);
00126 GetForm() -> getvalue("zonenum",slask,100);
00127 long zonenum = atol(slask);
00128 sprintf(sql,"delete from zone_m where num=%ld and zone=%ld",num,zonenum);
00129 q.execute(sql);
00130 m_edit = zonenum;
00131 }
00132 else
00133 if (!strcmp(action," Add Mob ") ||
00134 !strcmp(action," Save Mob ") )
00135 {
00136 GetForm() -> getvalue("num",slask,100);
00137 long num = atol(slask);
00138 db::Zone_m zm(GetDatabase(),num);
00139 bool ok = true;
00140 zm.num = num;
00141 GetForm() -> getvalue("zonenum",slask,100);
00142 zm.zone = atol(slask);
00143 GetForm() -> getvalue("mobnum",slask,100);
00144 zm.mobvnum = atol(slask);
00145 GetForm() -> getvalue("max",slask,100);
00146 zm.max = atol(slask);
00147 GetForm() -> getvalue("roomnum",slask,100);
00148 zm.roomvnum = atol(slask);
00149 {
00150 db::Mob mob(GetDatabase(),zm.mobvnum);
00151 db::Room room(GetDatabase(),zm.roomvnum);
00152 if (!mob.num || !room.num)
00153 {
00154 ok = false;
00155 }
00156 }
00157 if (ok)
00158 {
00159 zm.save();
00160 }
00161 m_edit = zm.zone;
00162 }
00163 else
00164 if (!strcmp(action," Delete Obj "))
00165 {
00166 Query q(GetDatabase());
00167 char sql[200];
00168 GetForm() -> getvalue("num",slask,100);
00169 long num = atol(slask);
00170 GetForm() -> getvalue("zonenum",slask,100);
00171 long zonenum = atol(slask);
00172 sprintf(sql,"delete from zone_o where num=%ld and zone=%ld",num,zonenum);
00173 q.execute(sql);
00174 m_edit = zonenum;
00175 }
00176 else
00177 if (!strcmp(action," Add Obj ") ||
00178 !strcmp(action," Save Obj ") )
00179 {
00180 GetForm() -> getvalue("num",slask,100);
00181 long num = atol(slask);
00182 db::Zone_o zo(GetDatabase(),num);
00183 bool ok = true;
00184 zo.num = num;
00185 GetForm() -> getvalue("zonenum",slask,100);
00186 zo.zone = atol(slask);
00187 GetForm() -> getvalue("objnum",slask,100);
00188 zo.objvnum = atol(slask);
00189 GetForm() -> getvalue("max",slask,100);
00190 zo.max = atol(slask);
00191 GetForm() -> getvalue("roomnum",slask,100);
00192 zo.roomvnum = atol(slask);
00193 {
00194 db::Obj obj(GetDatabase(),zo.objvnum);
00195 db::Room room(GetDatabase(),zo.roomvnum);
00196 if (!obj.num || !room.num)
00197 {
00198 ok = false;
00199 }
00200 }
00201 if (ok)
00202 {
00203 zo.save();
00204 }
00205 m_edit = zo.zone;
00206 }
00207 else
00208 if (!strcmp(action," Delete Eq "))
00209 {
00210 char sql[200];
00211 GetForm() -> getvalue("num",slask,100);
00212 long num = atol(slask);
00213 GetForm() -> getvalue("mnum",slask,100);
00214 long mnum = atol(slask);
00215 sprintf(sql,"select * from zone_g where num=%ld and zone_m=%ld",num,mnum);
00216 db::Zone_g zg(GetDatabase(),sql);
00217 zg.erase();
00218 GetForm() -> getvalue("zonenum",slask,100);
00219 m_edit = atol(slask);
00220 m_editm = mnum;
00221 }
00222 else
00223 if (!strcmp(action," Add Eq ") ||
00224 !strcmp(action," Save Eq "))
00225 {
00226 GetForm() -> getvalue("num",slask,100);
00227 long num = atol(slask);
00228 GetForm() -> getvalue("mnum",slask,100);
00229 long mnum = atol(slask);
00230 db::Zone_g zg(GetDatabase(),num);
00231 zg.zone_m = mnum;
00232 GetForm() -> getvalue("objnum",slask,100);
00233 zg.objvnum = atol(slask);
00234 GetForm() -> getvalue("eqpos",slask,100);
00235 zg.eqpos = atol(slask);
00236 zg.save();
00237 GetForm() -> getvalue("zonenum",slask,100);
00238 m_edit = atol(slask);
00239 m_editm = mnum;
00240 }
00241 }
00242 }
00243
00244
00245 void ZoneForm::Select(const string &)
00246 {
00247 }
00248
00249
00250 void ZoneForm::List()
00251 {
00252 }
00253
00254
00255 void ZoneForm::Display(long)
00256 {
00257 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00258 Database *db = GetDatabase();
00259 Query q(db);
00260 Query q2(db);
00261 char sql[200];
00262
00263 if (!m_edit)
00264 web -> DisplayStartAntalForm();
00265
00266 if (m_error)
00267 {
00268 printf("<h3>New Zone# is already taken</h3>");
00269 }
00270
00271 {
00272 if (m_edit)
00273 sprintf(sql,"select * from zone where num=%ld",m_edit);
00274 else
00275 sprintf(sql,"select * from zone where num>=%ld order by num limit %ld",GetStart(),GetAntal());
00276 q.get_result(sql);
00277 char header[100];
00278
00279 if (m_edit)
00280 sprintf(header," Editing Zone#%ld",m_edit);
00281 else
00282 sprintf(header," Zones (%ld zones displayed)",q.num_rows());
00283 Table tbl("#000000", 3, header);
00284 printf("<tr bgcolor=#ffffff>");
00285 printf("<th align=left> Zone | Vnum</th>");
00286 printf("<th align=left> LifeSpan</th>");
00287 printf("<th align=left> ResetMode</th>");
00288 printf("<th align=left> Size</th>");
00289 printf("</tr>");
00290
00291 while (q.fetch_row())
00292 {
00293 db::Zone zone(db,&q);
00294
00295 printf("<tr bgcolor=#c0c0c0>");
00296 printf("<td bgcolor=#808080>");
00297 ShowZone(zone,true);
00298 printf("</td>");
00299 printf("<td align=right> %ld mins </td>",zone.lifespan);
00300 printf("<td> %s </td>",m_reset[zone.resetmode] -> name);
00301 printf("<td align=right> %ld </td>",zone.size);
00302 printf("</tr>");
00303 }
00304 q.free_result();
00305 }
00306 printf("<br>");
00307
00308 if (m_editg)
00309 {
00310 db::Zone_g zg(db,m_editg);
00311 {
00312 Table tbl("#000000", 3);
00313
00314 printf("<form action=%s method=post>",GetCgiName().c_str());
00315 printf("<input type=hidden name=num value=%ld>",zg.num);
00316 printf("<input type=hidden name=zonenum value=%ld>",m_edit);
00317 printf("<input type=hidden name=mnum value=%ld>",zg.zone_m);
00318
00319 inputnum("Obj Vnum","objnum",zg.objvnum,VALUE_IS_OBJ);
00320 inputnum("EqPos","eqpos",zg.eqpos);
00321 inputsubmit(" Save Eq ");
00322 inputsubmit(" Delete Eq ");
00323
00324 printf("</form>");
00325 }
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337 }
00338 else
00339 if (m_editm)
00340 {
00341 db::Zone_m zm(db,m_editm);
00342 {
00343 Table tbl("#000000", 3);
00344
00345 printf("<form action=%s method=post>",GetCgiName().c_str());
00346 printf("<input type=hidden name=num value=%ld>",zm.num);
00347 printf("<input type=hidden name=zonenum value=%ld>",m_edit);
00348
00349 inputnum("Mob Vnum","mobnum",zm.mobvnum,VALUE_IS_MOB);
00350 inputnum("Max","max",zm.max);
00351 inputnum("Room Vnum","roomnum",zm.roomvnum,VALUE_IS_ROOM);
00352 inputsubmit(" Save Mob ");
00353 inputsubmit(" Delete Mob ");
00354
00355 printf("</form>");
00356 }
00357 printf("<br>");
00358 {
00359 Table tbl("#000000", 3, " Equipment");
00360
00361 sprintf(sql,"select * from zone_g where zone_m=%ld",zm.num);
00362 q2.get_result(sql);
00363 if (q2.num_rows())
00364 {
00365 printf("<tr bgcolor=#ffffff>");
00366 printf("<td colspan=3>");
00367 {
00368 Table tbl("#000000",3);
00369 printf("<tr bgcolor=#ffffff>");
00370 printf("<th align=left>Item | Vnum</th>");
00371 printf("<th align=left>EqPos</th>");
00372 printf("<th></th>");
00373 printf("</tr>");
00374 while (q2.fetch_row())
00375 {
00376 db::Zone_g zg(db,&q2);
00377 db::Obj obj(db,zg.objvnum);
00378 printf("<tr bgcolor=#808080>");
00379 ShowObj(obj,true,true);
00380 printf("<td bgcolor=#c0c0c0>");
00381 printf("eqpos %ld",zg.eqpos);
00382 printf("</td>");
00383 printf("<td align=middle> ");
00384 printf("<a href=%s?%s=edit&edit=%ld&editg=%ld>edit</a>",
00385 GetCgiName().c_str(),
00386 GetFormName().c_str(),
00387 m_edit,zg.num);
00388 printf(" </td>");
00389 printf("</tr>");
00390 }
00391 }
00392 printf("</td>");
00393 printf("</tr>");
00394 }
00395 q2.free_result();
00396 }
00397 printf("<br>");
00398
00399 {
00400 Table tbl("#000000", 3);
00401
00402 printf("<form action=%s method=post>",GetCgiName().c_str());
00403 printf("<input type=hidden name=num value=%d>",0);
00404 printf("<input type=hidden name=zonenum value=%ld>",m_edit);
00405 printf("<input type=hidden name=mnum value=%ld>",zm.num);
00406
00407 inputnum("Obj Vnum","objnum",-1);
00408 inputnum("EqPos","eqpos",0);
00409 inputsubmit(" Add Eq ");
00410
00411 printf("</form>");
00412 }
00413 printf("<br>");
00414 }
00415 else
00416 if (m_edito)
00417 {
00418 db::Zone_o zo(db,m_edito);
00419 {
00420 Table tbl("#000000", 3);
00421
00422 printf("<form action=%s method=post>",GetCgiName().c_str());
00423 printf("<input type=hidden name=num value=%ld>",zo.num);
00424 printf("<input type=hidden name=zonenum value=%ld>",m_edit);
00425
00426 inputnum("Obj Vnum","objnum",zo.objvnum,VALUE_IS_OBJ);
00427 inputnum("Max","max",zo.max);
00428 inputnum("Room Vnum","roomnum",zo.roomvnum,VALUE_IS_ROOM);
00429 inputsubmit(" Save Obj ");
00430 inputsubmit(" Delete Obj ");
00431
00432 printf("</form>");
00433 }
00434 printf("<br>");
00435 }
00436 else
00437 if (m_edit)
00438 {
00439 db::Zone zone(db,m_edit);
00440 {
00441 Table tbl("#000000", 3);
00442
00443 printf("<form action=%s method=post>",GetCgiName().c_str());
00444 printf("<input type=hidden name=onum value=%ld>",zone.num);
00445
00446 inputnum("Vnum","num",zone.num);
00447 inputstr("Name","name",60,zone.name,true);
00448 inputnum("LifeSpan","lifespan",zone.lifespan);
00449 inputselect(q,"ResetMode","resetmode","select num,name from zone_reset order by num",zone.resetmode);
00450 inputnum("Size","size",zone.size);
00451 inputsubmit(" Save ");
00452
00453 printf("</form>");
00454 }
00455 printf("<br>");
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480 sprintf(sql,"select * from zone_m where zone=%ld order by mobvnum,roomvnum",zone.num);
00481 q.get_result(sql);
00482 if (q.num_rows())
00483 {
00484 Table tbl("#000000", 3);
00485 printf("<tr bgcolor=#ffffff>");
00486 printf("<th>Mob</th>");
00487 printf("<th>Max</th>");
00488 printf("<th>Room</th>");
00489 printf("<th>Equipment</th>");
00490 printf("<th></th>");
00491 printf("</tr>");
00492 while (q.fetch_row())
00493 {
00494 db::Zone_m x(db,&q);
00495 db::Mob mob(db,x.mobvnum);
00496 db::Room room(db,x.roomvnum);
00497 printf("<tr bgcolor=#808080>");
00498 ShowMob(mob,true,true);
00499 printf("<td bgcolor=#c0c0c0 align=right> %ld </td>",x.max);
00500 ShowRoom(room,true,true);
00501 sprintf(sql,"select count(*) from zone_g where zone_m=%ld",x.num);
00502 printf("<td bgcolor=#c0c0c0 align=right> %ld </td>",q2.get_count(sql));
00503 printf("<td bgcolor=#c0c0c0 align=middle> [ ");
00504 printf("<a href=%s?zoneform=edit&edit=%ld&editm=%ld>edit</a>",
00505 GetCgiName().c_str(),m_edit,x.num);
00506 printf(" ] </td>");
00507 printf("</tr>");
00508 }
00509 }
00510 if (q.num_rows())
00511 {
00512 printf("<br>");
00513 }
00514 q.free_result();
00515
00516
00517 {
00518 Table tbl("#000000", 3);
00519
00520 SetColor("#c0ffff");
00521 printf("<form action=%s method=post>",GetCgiName().c_str());
00522 printf("<input type=hidden name=num value=%d>",0);
00523 printf("<input type=hidden name=zonenum value=%ld>",zone.num);
00524
00525 inputnum("Mob Vnum","mobnum",-1);
00526 inputnum("Max","max",-1);
00527 inputnum("Room Vnum","roomnum",-1);
00528
00529 inputsubmit(" Add Mob ");
00530
00531 printf("</form>");
00532 SetColor("#ffffc0");
00533 }
00534 printf("<br>");
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549 sprintf(sql,"select * from zone_o where zone=%ld order by objvnum,roomvnum",zone.num);
00550 q.get_result(sql);
00551 if (q.num_rows())
00552 {
00553 Table tbl("#000000", 3);
00554 printf("<tr bgcolor=#ffffff>");
00555 printf("<th>Obj</th>");
00556 printf("<th>Max</th>");
00557 printf("<th>Room</th>");
00558 printf("<th></th>");
00559 printf("</tr>");
00560 while (q.fetch_row())
00561 {
00562 db::Zone_o x(db,&q);
00563 db::Obj obj(db,x.objvnum);
00564 db::Room room(db,x.roomvnum);
00565 printf("<tr bgcolor=#808080>");
00566 ShowObj(obj,true,true);
00567 printf("<td bgcolor=#c0c0c0 align=right> %ld </td>",x.max);
00568 ShowRoom(room,true,true);
00569 printf("<td bgcolor=#c0c0c0 align=middle> [ ");
00570 printf("<a href=%s?zoneform=edit&edit=%ld&edito=%ld>edit</a>",
00571 GetCgiName().c_str(),m_edit,x.num);
00572 printf(" ] </td>");
00573 printf("</tr>");
00574 }
00575 }
00576 if (q.num_rows())
00577 {
00578 printf("<br>");
00579 }
00580 q.free_result();
00581
00582
00583
00584 {
00585 Table tbl("#000000", 3);
00586
00587 SetColor("#c0ffff");
00588 printf("<form action=%s method=post>",GetCgiName().c_str());
00589 printf("<input type=hidden name=num value=%d>",0);
00590 printf("<input type=hidden name=zonenum value=%ld>",zone.num);
00591
00592 inputnum("Obj Vnum","objnum",-1);
00593 inputnum("Max","max",-1);
00594 inputnum("Room Vnum","roomnum",-1);
00595
00596 inputsubmit(" Add Obj ");
00597
00598 printf("</form>");
00599 SetColor("#ffffc0");
00600 }
00601 printf("<br>");
00602
00603 }
00604 }
00605
00606
00607 }
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651