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 "ResourceForm.h"
00033
00034
00035 namespace cgi
00036 {
00037
00038
00039 ResourceForm::ResourceForm(Web *web)
00040 :BaseForm(web, "resourceform")
00041 ,m_edit(0)
00042 ,m_error(false)
00043 {
00044 Query q(GetDatabase());
00045
00046 q.get_result("select * from skill");
00047 while (q.fetch_row())
00048 {
00049 db::Skill *tmp = new db::Skill(GetDatabase(),&q);
00050 m_skill[tmp -> num] = tmp;
00051 }
00052 q.free_result();
00053 }
00054
00055
00056 ResourceForm::~ResourceForm()
00057 {
00058 for (skills_t::iterator it = m_skill.begin(); it != m_skill.end(); it++)
00059 {
00060 delete (*it).second;
00061 }
00062 }
00063
00064
00065 void ResourceForm::Process()
00066 {
00067 char action[200];
00068
00069 if (GetForm() -> getvalue("resourceform",action,200))
00070 {
00071 if (!strcmp(action,"edit"))
00072 {
00073 char slask[100];
00074 GetForm() -> getvalue("edit",slask,100);
00075 m_edit = atol(slask);
00076 }
00077 else
00078 if (!strcmp(action," Save "))
00079 {
00080 char slask[100];
00081 GetForm() -> getvalue("num",slask,100);
00082 long num = atol(slask);
00083 GetForm() -> getvalue("onum",slask,100);
00084 long onum = atol(slask);
00085 db::Resource resource(GetDatabase(),num);
00086
00087 if (num != onum && resource.num)
00088 {
00089 m_error = true;
00090 }
00091 else
00092 {
00093
00094 GetForm() -> EnableRaw( true );
00095 resource.num = num;
00096 GetForm() -> getvalue("name",resource.name,255);
00097 GetForm() -> getvalue("skill",slask,100);
00098 resource.skill = atol(slask);
00099 GetForm() -> getvalue("alias",resource.alias,255);
00100 GetForm() -> getvalue("low_price",slask,100);
00101 resource.low_price = atol(slask);
00102 GetForm() -> getvalue("high_price",slask,100);
00103 resource.high_price = atol(slask);
00104 GetForm() -> getvalue("low_count",slask,100);
00105 resource.low_count = atol(slask);
00106 GetForm() -> getvalue("high_count",slask,100);
00107 resource.high_count = atol(slask);
00108 GetForm() -> getvalue("base_resource",slask,100);
00109 resource.base_resource = atol(slask);
00110
00111 resource.save();
00112
00113 }
00114 }
00115 }
00116 }
00117
00118
00119 void ResourceForm::Select(const string &)
00120 {
00121 }
00122
00123
00124 void ResourceForm::List()
00125 {
00126 }
00127
00128
00129 void ResourceForm::Display(long)
00130 {
00131 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00132 Database *db = GetDatabase();
00133 Query q(db);
00134 long zonesize = 0;
00135 char sql[200];
00136
00137 zonesize = EditingZone();
00138
00139 if (!m_edit)
00140 web -> DisplayStartAntalForm();
00141
00142 if (m_error)
00143 {
00144 printf("<h3>New Resource# is already taken</h3>");
00145 }
00146
00147 {
00148 if (m_edit)
00149 sprintf(sql,"select * from resource where num=%ld",m_edit);
00150 else
00151 {
00152 sprintf(sql,"select * from resource where num>=%ld order by num limit %ld",GetStart(),GetAntal());
00153 }
00154 q.get_result(sql);
00155 char header[100];
00156
00157 if (m_edit)
00158 sprintf(header," Editing Resource#%ld",m_edit);
00159 else
00160 sprintf(header," Resources (%ld resources displayed)",q.num_rows());
00161 Table tbl("#000000", 3, header);
00162 printf("<tr bgcolor=#ffffff>");
00163 printf("<th align=left> Resource | Vnum</th>");
00164 printf("<th align=left> Skill</th>");
00165 printf("<th align=left> Base resource</th>");
00166 printf("<th align=left> Low price/count</th>");
00167 printf("<th align=left> High price/count</th>");
00168 printf("</tr>");
00169
00170 while (q.fetch_row())
00171 {
00172 db::Resource resource(db,&q);
00173 db::Skill *tmp = m_skill[resource.skill];
00174 db::Resource base(db,resource.base_resource);
00175
00176 printf("<tr bgcolor=#808080>");
00177 ShowResource(resource,true,true);
00178 if (tmp)
00179 ShowSkill(*tmp,true,true);
00180 else
00181 printf("<td align=middle>-</td>");
00182 if (base.num)
00183 ShowResource(base,true,true);
00184 else
00185 printf("<td align=middle>-</td>");
00186 printf("<td align=middle> %ld/%ld </td>",
00187 resource.low_price,resource.high_count);
00188 printf("<td align=middle> %ld/%ld </td>",
00189 resource.high_price,resource.low_count);
00190 printf("</tr>");
00191 }
00192 q.free_result();
00193 }
00194 printf("<br>");
00195
00196 if (m_edit)
00197 {
00198 db::Resource resource(db,m_edit);
00199
00200
00201 {
00202 }
00203
00204
00205 {
00206 Table tbl("#000000", 3);
00207
00208 printf("<form action=%s method=post>",GetCgiName().c_str());
00209 printf("<input type=hidden name=onum value=%ld>",resource.num);
00210
00211 inputnum("Vnum", "num", resource.num);
00212 inputstr("ResourceAlias","alias",60,resource.alias);
00213 inputstr("ResourceName","name",60,resource.name,true);
00214 inputselect(q,"Skill","skill","select num,name from skill order by name",resource.skill);
00215 inputselect(q,"Base Resource","base_resource","select num,alias from resource order by alias",resource.base_resource);
00216 inputnum("Low Price","low_price",resource.low_price);
00217 inputnum("High Price","high_price",resource.high_price);
00218 inputnum("Low Count","low_count",resource.low_count);
00219 inputnum("High Count","high_count",resource.high_count);
00220
00221 inputsubmit(" Save ");
00222
00223 printf("</form>");
00224 }
00225 printf("<br>");
00226 }
00227 }
00228
00229
00230 }
00231
00232
00233