version 0.1.7
[fms.git] / src / http / pages / localidentitiespage.cpp
diff --git a/src/http/pages/localidentitiespage.cpp b/src/http/pages/localidentitiespage.cpp
new file mode 100644 (file)
index 0000000..821339d
--- /dev/null
@@ -0,0 +1,139 @@
+#include "../../../include/http/pages/localidentitiespage.h"\r
+#include "../../../include/stringfunctions.h"\r
+\r
+#ifdef XMEM\r
+       #include <xmem.h>\r
+#endif\r
+\r
+const std::string LocalIdentitiesPage::CreateTrueFalseDropDown(const std::string &name, const std::string &selected)\r
+{\r
+       std::string rval="";\r
+\r
+       rval+="<select name=\""+name+"\">";\r
+       rval+="<option value=\"true\"";\r
+       if(selected=="true")\r
+       {\r
+               rval+=" SELECTED";\r
+       }\r
+       rval+=">true</option>";\r
+       rval+="<option value=\"false\"";\r
+       if(selected=="false")\r
+       {\r
+               rval+=" SELECTED";\r
+       }\r
+       rval+=">false</option>";\r
+       rval+="</select>";\r
+\r
+       return rval;\r
+}\r
+\r
+const std::string LocalIdentitiesPage::GeneratePage(const std::string &method, const std::map<std::string,std::string> &queryvars)\r
+{\r
+       int count;\r
+       std::string countstr;\r
+       std::string content="";\r
+\r
+\r
+       if(queryvars.find("formaction")!=queryvars.end())\r
+       {\r
+               int id;\r
+               std::vector<std::string> ids;\r
+               std::vector<std::string> singleuse;\r
+               std::vector<std::string> publishtrustlist;\r
+\r
+               CreateArgArray(queryvars,"chkidentityid",ids);\r
+               CreateArgArray(queryvars,"singleuse",singleuse);\r
+               CreateArgArray(queryvars,"publishtrustlist",publishtrustlist);\r
+\r
+               if((*queryvars.find("formaction")).second=="update")\r
+               {\r
+                       SQLite3DB::Statement update=m_db->Prepare("UPDATE tblLocalIdentity SET SingleUse=?, PublishTrustList=? WHERE LocalIdentityID=?;");\r
+                       for(int i=0; i<ids.size(); i++)\r
+                       {\r
+                               if(ids[i]!="")\r
+                               {\r
+                                       StringFunctions::Convert(ids[i],id);\r
+                                       update.Bind(0,singleuse[i]);\r
+                                       update.Bind(1,publishtrustlist[i]);\r
+                                       update.Bind(2,id);\r
+                                       update.Step();\r
+                                       update.Reset();\r
+                               }\r
+                       }\r
+               }\r
+               if((*queryvars.find("formaction")).second=="delete")\r
+               {\r
+                       SQLite3DB::Statement del=m_db->Prepare("DELETE FROM tblLocalIdentity WHERE LocalIdentityID=?;");\r
+                       for(int i=0; i<ids.size(); i++)\r
+                       {\r
+                               if(ids[i]!="")\r
+                               {\r
+                                       StringFunctions::Convert(ids[i],id);\r
+                                       del.Bind(0,id);\r
+                                       del.Step();\r
+                                       del.Reset();\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       content+="<h2>Local Identities</h2>";\r
+       content+="<form name=\"frmlocalidentity\" method=\"POST\">";\r
+       content+="<input type=\"hidden\" name=\"formaction\" value=\"update\">";\r
+       content+="<table><tr><td></td><th>Name</th><th>Single Use</th><th>Publish Trust List</th><th>Announced? *</th></tr>";\r
+\r
+       SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID,tblLocalIdentity.Name,tblLocalIdentity.PublicKey,tbLLocalIdentity.PublishTrustList,tblLocalIdentity.SingleUse,tblLocalIdentity.PublishBoardList,tblIdentity.IdentityID FROM tblLocalIdentity LEFT JOIN tblIdentity ON tblLocalIdentity.PublicKey=tblIdentity.PublicKey ORDER BY tblLocalIdentity.Name;");\r
+       st.Step();\r
+\r
+       count=0;\r
+       while(st.RowReturned())\r
+       {\r
+               StringFunctions::Convert(count,countstr);\r
+               std::string id;\r
+               std::string name;\r
+               std::string publickey;\r
+               std::string publishtrustlist;\r
+               std::string singleuse;\r
+\r
+               st.ResultText(0,id);\r
+               st.ResultText(1,name);\r
+               st.ResultText(2,publickey);\r
+               st.ResultText(3,publishtrustlist);\r
+               st.ResultText(4,singleuse);\r
+\r
+               content+="<tr>";\r
+               content+="<td><input type=\"checkbox\" name=\"chkidentityid["+countstr+"]\" value=\""+id+"\"></td>";\r
+               content+="<td title=\""+publickey+"\">"+name+"</td>";\r
+               content+="<td>"+CreateTrueFalseDropDown("singleuse["+countstr+"]",singleuse)+"</td>";\r
+               content+="<td>"+CreateTrueFalseDropDown("publishtrustlist["+countstr+"]",publishtrustlist)+"</td>";\r
+               if(st.ResultNull(6))\r
+               {\r
+                       content+="<td>No</td>";\r
+               }\r
+               else\r
+               {\r
+                       content+="<td>Yes</td>";\r
+               }\r
+               content+="</tr>";\r
+               st.Step();\r
+               count++;\r
+       }\r
+\r
+       content+="<tr><td colspan=\"4\"><center><input type=\"submit\" value=\"Update Selected\"> <input type=\"submit\" value=\"Delete Selected\" onClick=\"if(confirm('Delete Selected Identities?')){frmlocalidentity.formaction.value='delete';}else{return false;}\"></td></tr>";\r
+       content+="</table>";\r
+       content+="<p class=\"paragraph=\">* An identity is considered successfully announced when you have downloaded a trust list from someone that contains the identity.</p>";\r
+\r
+       return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content);\r
+}\r
+\r
+const bool LocalIdentitiesPage::WillHandleURI(const std::string &uri)\r
+{\r
+       if(uri.find("localidentities.")!=std::string::npos)\r
+       {\r
+               return true;\r
+       }\r
+       else\r
+       {\r
+               return false;\r
+       }\r
+}\r