1 #include "../../../include/http/pages/boardspage.h"
\r
2 #include "../../../include/stringfunctions.h"
\r
3 #include "../../../include/datetime.h"
\r
9 const std::string BoardsPage::BuildQueryString(const long startrow, const std::string &boardsearch)
\r
11 std::string returnval="";
\r
12 std::string tempval="";
\r
16 StringFunctions::Convert(startrow,tempval);
\r
17 returnval+="startrow="+tempval;
\r
26 returnval+="boardsearch="+boardsearch;
\r
33 const std::string BoardsPage::GeneratePage(const std::string &method, const std::map<std::string,std::string> &queryvars)
\r
36 std::string content="";
\r
39 std::string rowsperpagestr="25";
\r
41 std::string startrowstr="0";
\r
42 std::string boardsearch="";
\r
47 if(queryvars.find("formaction")!=queryvars.end())
\r
49 if((*queryvars.find("formaction")).second=="addboard" && queryvars.find("boardname")!=queryvars.end() && queryvars.find("boarddescription")!=queryvars.end())
\r
51 std::string boardname="";
\r
52 std::string boarddescription="";
\r
54 boardname=(*queryvars.find("boardname")).second;
\r
55 StringFunctions::LowerCase(boardname,boardname);
\r
56 boarddescription=(*queryvars.find("boarddescription")).second;
\r
58 SQLite3DB::Statement addst=m_db->Prepare("INSERT INTO tblBoard(BoardName,BoardDescription,DateAdded) VALUES(?,?,?);");
\r
59 addst.Bind(0,boardname);
\r
60 addst.Bind(1,boarddescription);
\r
61 addst.Bind(2,now.Format("%Y-%m-%d %H:%M:%S"));
\r
64 if((*queryvars.find("formaction")).second=="update")
\r
67 std::vector<std::string> boardids;
\r
68 std::vector<std::string> olddescriptions;
\r
69 std::vector<std::string> descriptions;
\r
70 std::vector<std::string> oldsavemessages;
\r
71 std::vector<std::string> savemessages;
\r
73 CreateArgArray(queryvars,"boardid",boardids);
\r
74 CreateArgArray(queryvars,"oldboarddescription",olddescriptions);
\r
75 CreateArgArray(queryvars,"boarddescription",descriptions);
\r
76 CreateArgArray(queryvars,"oldsavereceivedmessages",oldsavemessages);
\r
77 CreateArgArray(queryvars,"savereceivedmessages",savemessages);
\r
79 olddescriptions.resize(boardids.size(),"");
\r
80 descriptions.resize(boardids.size(),"");
\r
81 oldsavemessages.resize(boardids.size(),"");
\r
82 savemessages.resize(boardids.size(),"");
\r
84 SQLite3DB::Statement updatest=m_db->Prepare("UPDATE tblBoard SET BoardDescription=?, SaveReceivedMessages=? WHERE BoardID=?;");
\r
86 for(int i=0; i<boardids.size(); i++)
\r
88 if(olddescriptions[i]!=descriptions[i] || oldsavemessages[i]!=savemessages[i])
\r
90 updatest.Bind(0,descriptions[i]);
\r
91 if(savemessages[i]!="true")
\r
93 updatest.Bind(1,"false");
\r
97 updatest.Bind(1,"true");
\r
100 StringFunctions::Convert(boardids[i],boardid);
\r
101 updatest.Bind(2,boardid);
\r
110 // if startrow is specified
\r
111 if(queryvars.find("startrow")!=queryvars.end())
\r
113 startrowstr=(*queryvars.find("startrow")).second;
\r
114 // convert back and forth, just in case a number wasn't passed in startrow
\r
115 StringFunctions::Convert(startrowstr,startrow);
\r
120 StringFunctions::Convert(startrow,startrowstr);
\r
123 // if we are searching by name
\r
124 if(queryvars.find("boardsearch")!=queryvars.end())
\r
126 boardsearch=(*queryvars.find("boardsearch")).second;
\r
129 content+="<h2>Boards</h2>";
\r
131 sql="SELECT COUNT(*) FROM tblBoard WHERE BoardID NOT IN (SELECT BoardID FROM tblAdministrationBoard)";
\r
132 if(boardsearch!="")
\r
134 sql+=" AND (BoardName LIKE '%' || ? || '%' OR BoardDescription LIKE '%' || ? || '%')";
\r
137 SQLite3DB::Statement st=m_db->Prepare(sql);
\r
138 if(boardsearch!="")
\r
140 st.Bind(0,boardsearch);
\r
141 st.Bind(1,boardsearch);
\r
144 if(st.RowReturned())
\r
146 st.ResultInt(0,boardcount);
\r
151 sql="SELECT BoardID,BoardName,BoardDescription,SaveReceivedMessages FROM tblBoard WHERE BoardID NOT IN (SELECT BoardID FROM tblAdministrationBoard)";
\r
152 if(boardsearch!="")
\r
154 sql+=" AND (BoardName LIKE '%' || ? || '%' OR BoardDescription LIKE '%' || ? || '%')";
\r
156 sql+=" ORDER BY BoardName COLLATE NOCASE";
\r
157 sql+=" LIMIT "+startrowstr+","+rowsperpagestr+";";
\r
159 st=m_db->Prepare(sql);
\r
160 if(boardsearch!="")
\r
162 st.Bind(0,boardsearch);
\r
163 st.Bind(1,boardsearch);
\r
167 content+="<table>";
\r
170 content+="<td colspan=\"3\"><center>";
\r
171 content+="<form name=\"frmboardsearch\" action=\"boards.htm\" method=\"POST\"><input type=\"text\" name=\"boardsearch\" value=\""+SanitizeOutput(boardsearch)+"\"><input type=\"submit\" value=\"Search\"></form>";
\r
172 content+="</center></td>";
\r
176 content+="<td><form name=\"frmaddboard\" method=\"POST\"><input type=\"hidden\" name=\"formaction\" value=\"addboard\"><input type=\"text\" name=\"boardname\"></td><td><input type=\"text\" name=\"boarddescription\" size=\"40\" maxlength=\"50\"></td><td><input type=\"submit\" value=\"Add Board\"></form></td>";
\r
179 content+="<tr><td colspan=\"3\"><hr><form name=\"frmboards\" method=\"POST\"><input type=\"hidden\" name=\"formaction\" value=\"update\"></td></tr>";
\r
181 content+="<th>Name</th><th>Description</th><th>Save Received Messages *</th>";
\r
183 while(st.RowReturned() && rownum<rowsperpage)
\r
185 std::string rownumstr="";
\r
186 std::string boardidstr="";
\r
187 std::string boardname="";
\r
188 std::string boarddescription="";
\r
189 std::string savereceivedmessages="";
\r
191 st.ResultText(0,boardidstr);
\r
192 st.ResultText(1,boardname);
\r
193 st.ResultText(2,boarddescription);
\r
194 st.ResultText(3,savereceivedmessages);
\r
196 StringFunctions::Convert(rownum,rownumstr);
\r
199 content+="<td>"+SanitizeOutput(boardname)+"</td>";
\r
200 content+="<td><input type=\"hidden\" name=\"boardid["+rownumstr+"]\" value=\""+boardidstr+"\">";
\r
201 content+="<input type=\"hidden\" name=\"oldboarddescription["+rownumstr+"]\" value=\""+StringFunctions::Replace(SanitizeOutput(boarddescription)," "," ")+"\">";
\r
202 content+="<input type=\"text\" name=\"boarddescription["+rownumstr+"]\" value=\""+SanitizeOutput(boarddescription)+"\" size=\"40\" maxlength=\"50\"></td>";
\r
204 content+="<input type=\"hidden\" name=\"oldsavereceivedmessages["+rownumstr+"]\" value=\""+savereceivedmessages+"\">";
\r
205 content+="<input type=\"checkbox\" name=\"savereceivedmessages["+rownumstr+"]\" value=\"true\"";
\r
206 if(savereceivedmessages=="true")
\r
208 content+=" CHECKED";
\r
212 content+="</tr>\r\n";
\r
217 if(startrow>0 || startrow+rowsperpage<boardcount)
\r
219 std::string tempstr;
\r
225 StringFunctions::Convert(startrow-rowsperpage,tempstr);
\r
226 content+="<td colspan=\"1\" align=\"left\"><a href=\"boards.htm?"+BuildQueryString(startrow-rowsperpage,boardsearch)+"\"><-- Previous Page</a></td>";
\r
229 if(startrow+rowsperpage<boardcount)
\r
233 content+="<td></td>";
\r
236 content+="<td colspan=\"1\" align=\"right\"><a href=\"boards.htm?"+BuildQueryString(startrow+rowsperpage,boardsearch)+"\">Next Page --></a></td>";
\r
242 content+="<td colspan=\"3\"><center><input type=\"submit\" value=\"Update\"></center></form></td>";
\r
244 content+="</table>";
\r
245 content+="<p class=\"paragraph\">";
\r
246 content+="* If you uncheck this box, any new messages you download that are posted to this board will be discarded.";
\r
249 return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content);
\r
252 const bool BoardsPage::WillHandleURI(const std::string &uri)
\r
254 if(uri.find("boards.")!=std::string::npos)
\r