version 0.3.0
[fms.git] / src / http / pages / peertrustpage.cpp
index ac6b053..92f804c 100644 (file)
@@ -119,16 +119,33 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
        {\r
                localidentityidstr=(*queryvars.find("localidentityid")).second;\r
                StringFunctions::Convert(localidentityidstr,localidentityid);\r
+               // insert the ID into the temporary table so we remember the identity if we load the page later\r
+               m_db->Execute("DELETE FROM tmpLocalIdentityPeerTrustPage;");\r
+               SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tmpLocalIdentityPeerTrustPage(LocalIdentityID) VALUES(?);");\r
+               st.Bind(0,localidentityid);\r
+               st.Step();\r
        }\r
        else\r
        {\r
-               SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID FROM tblLocalIdentity;");\r
+               // try to get the localidentityid if it exists in the temp table, otherwise load the first identity in the database\r
+               SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID FROM tmpLocalIdentityPeerTrustPage;");\r
                st.Step();\r
                if(st.RowReturned())\r
                {\r
                        st.ResultInt(0,localidentityid);\r
                        StringFunctions::Convert(localidentityid,localidentityidstr);\r
                }\r
+               else\r
+               {\r
+                       st=m_db->Prepare("SELECT LocalIdentityID FROM tblLocalIdentity;");\r
+                       st.Step();\r
+                       if(st.RowReturned())\r
+                       {\r
+                               st.ResultInt(0,localidentityid);\r
+                               StringFunctions::Convert(localidentityid,localidentityidstr);\r
+                       }\r
+                       st.Finalize();\r
+               }\r
        }\r
 \r
        if(localidentityid!=-1 && queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="update")\r
@@ -278,8 +295,8 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
        content+="</tr>\r\n";\r
        \r
        // get count of identities we are showing\r
-       sql="SELECT COUNT(*) FROM tblIdentity LEFT JOIN (SELECT IdentityID FROM tblIdentityTrust WHERE LocalIdentityID=?) AS 'tblIdentityTrust' ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID ";\r
-       sql+="WHERE tblIdentity.Hidden='false'";\r
+       sql="SELECT COUNT(*) FROM tblIdentity LEFT JOIN tblIdentityTrust ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID ";\r
+       sql+="WHERE tblIdentity.Hidden='false' AND tblIdentityTrust.LocalIdentityID=?";\r
        if(namesearch!="")\r
        {\r
                sql+=" AND (Name LIKE '%' || ? || '%' OR PublicKey LIKE '%' || ? || '%')";\r
@@ -297,8 +314,8 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
        st.Finalize();\r
 \r
        sql="SELECT tblIdentity.IdentityID,Name,tblIdentityTrust.LocalMessageTrust,PeerMessageTrust,tblIdentityTrust.LocalTrustListTrust,PeerTrustListTrust,PublicKey,tblIdentityTrust.MessageTrustComment,tblIdentityTrust.TrustListTrustComment,COUNT(MessageID) AS 'MessageCount',tblIdentity.PublishTrustList ";\r
-       sql+="FROM tblIdentity LEFT JOIN (SELECT LocalIdentityID,IdentityID,LocalMessageTrust,LocalTrustListTrust,MessageTrustComment,TrustListTrustComment FROM tblIdentityTrust WHERE LocalIdentityID=?) AS tblIdentityTrust ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID ";\r
-       sql+="WHERE tblIdentity.Hidden='false'";\r
+       sql+="FROM tblIdentity LEFT JOIN tblIdentityTrust ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID ";\r
+       sql+="WHERE tblIdentity.Hidden='false' AND tblIdentityTrust.LocalIdentityID=?";\r
        if(namesearch!="")\r
        {\r
                sql+=" AND (Name LIKE  '%' || ? || '%' OR PublicKey LIKE '%' || ? || '%')";\r
@@ -426,7 +443,7 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
        content+="</table>";\r
        content+="</form>";\r
 \r
-       return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content);\r
+       return StringFunctions::Replace(m_template,"[CONTENT]",content);\r
 }\r
 \r
 const std::string PeerTrustPage::GetClassString(const std::string &trustlevel)\r