1 #include "../../../include/http/pages/announceidentitypage.h"
\r
2 #include "../../../include/stringfunctions.h"
\r
3 #include "../../../include/datetime.h"
\r
9 const std::string AnnounceIdentityPage::CreateLocalIdentityDropDown(const std::string &name, const std::string &selected)
\r
11 std::string rval="";
\r
12 SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID, Name, PublicKey FROM tblLocalIdentity ORDER BY Name;");
\r
15 rval+="<select name=\""+name+"\">";
\r
16 while(st.RowReturned())
\r
22 st.ResultText(0,id);
\r
23 st.ResultText(1,name);
\r
24 st.ResultText(2,pubkey);
\r
26 rval+="<option value=\""+id+"\" title=\""+pubkey+"\">"+name+"</option>";
\r
33 const std::string AnnounceIdentityPage::GeneratePage(const std::string &method, const std::map<std::string,std::string> &queryvars)
\r
36 std::string content;
\r
38 std::string countstr="";
\r
40 std::string lastid="";
\r
41 std::string thisid="";
\r
44 if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="announce")
\r
46 SQLite3DB::Statement insert=m_db->Prepare("INSERT INTO tblIdentityIntroductionInserts(LocalIdentityID,Day,UUID,Solution) VALUES(?,?,?,?);");
\r
47 std::string localidentityidstr="";
\r
48 int localidentityid=0;
\r
49 std::vector<std::string> uuids;
\r
50 std::vector<std::string> days;
\r
51 std::vector<std::string> solutions;
\r
53 if(queryvars.find("localidentityid")!=queryvars.end())
\r
55 localidentityidstr=(*queryvars.find("localidentityid")).second;
\r
56 StringFunctions::Convert(localidentityidstr,localidentityid);
\r
58 CreateArgArray(queryvars,"uuid",uuids);
\r
59 CreateArgArray(queryvars,"day",days);
\r
60 CreateArgArray(queryvars,"solution",solutions);
\r
62 for(int i=0; i<solutions.size(); i++)
\r
64 if(solutions[i]!="")
\r
66 insert.Bind(0,localidentityid);
\r
67 insert.Bind(1,days[i]);
\r
68 insert.Bind(2,uuids[i]);
\r
69 insert.Bind(3,solutions[i]);
\r
77 content+="<h2>Announce Identity</h2>";
\r
78 content+="<form name=\"frmannounce\" method=\"POST\">";
\r
79 content+="<input type=\"hidden\" name=\"formaction\" value=\"announce\">";
\r
81 content+="<tr><td colspan=\"4\"><center>Select Identity : ";
\r
82 content+=CreateLocalIdentityDropDown("localidentityid","");
\r
83 content+="</td></tr>";
\r
84 content+="<tr><td colspan=\"4\"><center>Type the answers of a few puzzles</td></tr>";
\r
89 SQLite3DB::Statement st=m_db->Prepare("SELECT UUID,Day,IdentityID FROM tblIntroductionPuzzleRequests WHERE UUID NOT IN (SELECT UUID FROM tblIdentityIntroductionInserts) AND UUID NOT IN (SELECT UUID FROM tblIntroductionPuzzleInserts) AND Day>='"+date.Format("%Y-%m-%d")+"' AND Found='true' ORDER BY IdentityID, Day DESC, RequestIndex DESC;");
\r
92 if(st.RowReturned()==false)
\r
94 content+="<td colspan=\"4\"><center>You must wait for some puzzles to be downloaded. Check back later.</td>";
\r
97 while(st.RowReturned() && shown<20)
\r
99 st.ResultText(0,uuid);
\r
100 st.ResultText(1,day);
\r
101 st.ResultText(2,thisid);
\r
105 StringFunctions::Convert(shown,countstr);
\r
106 if(shown>0 && shown%4==0)
\r
108 content+="</tr>\r\n<tr>";
\r
111 content+="<img src=\"showcaptcha.htm?UUID="+uuid+"\"><br>";
\r
112 content+="<input type=\"hidden\" name=\"uuid["+countstr+"]\" value=\""+uuid+"\">";
\r
113 content+="<input type=\"hidden\" name=\"day["+countstr+"]\" value=\""+day+"\">";
\r
114 content+="<input type=\"text\" name=\"solution["+countstr+"]\">";
\r
115 content+="</td>\r\n";
\r
123 content+="</tr><td colspan=\"4\"><center><input type=\"submit\" value=\"Announce\"></td></tr>";
\r
124 content+="</table>";
\r
125 content+="</form>";
\r
127 return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content);
\r
130 const bool AnnounceIdentityPage::WillHandleURI(const std::string &uri)
\r
132 if(uri.find("announceidentity.")!=std::string::npos)
\r