version 0.3.13
[fms.git] / src / http / pages / recentlyaddedpage.cpp
diff --git a/src/http/pages/recentlyaddedpage.cpp b/src/http/pages/recentlyaddedpage.cpp
new file mode 100644 (file)
index 0000000..2b09ce8
--- /dev/null
@@ -0,0 +1,95 @@
+#include "../../../include/http/pages/recentlyaddedpage.h"\r
+#include "../../../include/global.h"\r
+#include "../../../include/stringfunctions.h"\r
+\r
+#include <Poco/DateTime.h>\r
+#include <Poco/DateTimeFormatter.h>\r
+#include <Poco/Timespan.h>\r
+\r
+const std::string RecentlyAddedPage::GeneratePage(const std::string &method, const std::map<std::string,std::string> &queryvars)\r
+{\r
+       std::string content="";\r
+       Poco::DateTime date;\r
+       int count=0;\r
+       std::string countstr="0";\r
+\r
+       if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="delete" && ValidateFormPassword(queryvars))\r
+       {\r
+               std::vector<std::string> identityids;\r
+               CreateArgArray(queryvars,"chkdel",identityids);\r
+\r
+               SQLite3DB::Statement del=m_db->Prepare("DELETE FROM tblIdentity WHERE IdentityID=?;");\r
+\r
+               for(std::vector<std::string>::iterator i=identityids.begin(); i!=identityids.end(); i++)\r
+               {\r
+                       if((*i)!="")\r
+                       {\r
+                               del.Bind(0,(*i));\r
+                               del.Step();\r
+                               del.Reset();\r
+                       }\r
+               }\r
+\r
+       }\r
+\r
+       content="<h2>Recently Added Peers</h2>";\r
+\r
+       SQLite3DB::Statement st=m_db->Prepare("SELECT IdentityID, PublicKey, Name, DateAdded, AddedMethod FROM tblIdentity WHERE DateAdded>=? ORDER BY DateAdded DESC;");\r
+       date-=Poco::Timespan(5,0,0,0,0);\r
+       st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
+       st.Step();\r
+\r
+       content+="<form name=\"frmdel\" method=\"post\">";\r
+       content+=CreateFormPassword();\r
+       content+="<input type=\"hidden\" name=\"formaction\" value=\"delete\">";\r
+       content+="<table class=\"small90\">";\r
+       content+="<tr><th>Name</th><th>Date Added</th><th>Added Method</th></tr>";\r
+\r
+       while(st.RowReturned())\r
+       {\r
+               std::string identityidstr="";\r
+               std::string publickey="";\r
+               std::string name="";\r
+               std::string dateadded="";\r
+               std::string addedmethod="";\r
+\r
+               st.ResultText(0,identityidstr);\r
+               st.ResultText(1,publickey);\r
+               st.ResultText(2,name);\r
+               st.ResultText(3,dateadded);\r
+               st.ResultText(4,addedmethod);\r
+\r
+               StringFunctions::Convert(count,countstr);\r
+\r
+               content+="<tr>";\r
+               content+="<td title=\""+publickey+"\">";\r
+               content+="<a href=\"peerdetails.htm?identityid="+identityidstr+"\">";\r
+               content+=SanitizeOutput(CreateShortIdentityName(name,publickey));\r
+               content+="</a>";\r
+               content+="</td>";\r
+               content+="<td>"+dateadded+"</td>";\r
+               content+="<td>"+SanitizeOutput(addedmethod)+"</td>";\r
+               content+="<td><input type=\"checkbox\" name=\"chkdel["+countstr+"]\" value=\""+identityidstr+"\"></td>";\r
+               content+="</tr>";\r
+\r
+               count++;\r
+\r
+               st.Step();\r
+       }\r
+       content+="<tr><td colspan=\"4\"><center><input type=\"submit\" value=\"Delete Selected\"></center></td></tr>";\r
+       content+="</table>";\r
+\r
+       return StringFunctions::Replace(m_template,"[CONTENT]",content);\r
+}\r
+\r
+const bool RecentlyAddedPage::WillHandleURI(const std::string &uri)\r
+{\r
+       if(uri.find("recentlyadded.")!=std::string::npos)\r
+       {\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               return false;\r
+       }\r
+}\r