version 0.3.0
[fms.git] / src / http / pages / peertrustpage.cpp
index dc689bf..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
@@ -239,8 +256,9 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
        }\r
 \r
        content+="<h2>Peer Trust</h2>";\r
-       content+="Message Trust is how much you trust the identity to post good messages. Trust List Trust is how much weight you want the trust list of that identity to have when calculating the total. The local trust levels are set by you, and the peer trust levels are calculated by a weighted average using other identities' trust lists.  Trust is recalculated once an hour from received trust lists.  You must have at least 1 identity created and have received the SSK keypair for it from Freenet before setting trust.";\r
-       \r
+       content+="Message Trust is how much you trust the identity to post good messages. Trust List Trust is how much weight you want the trust list of that identity to have when calculating the total. The local trust levels are set by you, and the peer trust levels are calculated by a weighted average using other identities' trust lists.  Trust is recalculated once an hour from received trust lists.  You must have at least 1 identity created and have received the SSK keypair for it from Freenet before setting trust.<br>";\r
+       content+="* - This identity is not publishing a trust list<br>";\r
+\r
        // search drop down\r
        content+="<div style=\"text-align:center;margin-bottom:5px;\">";\r
        content+="<form name=\"frmsearch\" method=\"POST\" action=\"peertrust.htm?"+BuildQueryString(0,"","","",localidentityid)+"\">";\r
@@ -276,10 +294,9 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
        content+="<th><a href=\"peertrust.htm?"+BuildQueryString(startrow,namesearch,"MessageCount",ReverseSort("MessageCount",sortby,sortorder),localidentityid)+"\">Message Count</a></th>";\r
        content+="</tr>\r\n";\r
        \r
-//TODO - modify this query\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
@@ -296,9 +313,9 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
        st.ResultInt(0,identitycount);\r
        st.Finalize();\r
 \r
-       sql="SELECT tblIdentity.IdentityID,Name,tblIdentityTrust.LocalMessageTrust,PeerMessageTrust,tblIdentityTrust.LocalTrustListTrust,PeerTrustListTrust,PublicKey,tblIdentityTrust.MessageTrustComment,tblIdentityTrust.TrustListTrustComment,COUNT(MessageID) AS 'MessageCount' ";\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="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 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
@@ -339,6 +356,7 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
                std::string messagetrustcomment="";\r
                std::string trustlisttrustcomment="";\r
                std::string messagecountstr="";\r
+               std::string publishtrustlist="";\r
 \r
                StringFunctions::Convert(count,countstr);\r
 \r
@@ -352,6 +370,7 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
                st.ResultText(7,messagetrustcomment);\r
                st.ResultText(8,trustlisttrustcomment);\r
                st.ResultText(9,messagecountstr);\r
+               st.ResultText(10,publishtrustlist);\r
 \r
                content+="<tr>";\r
                content+="<td title=\""+publickey+"\">";\r
@@ -378,7 +397,12 @@ const std::string PeerTrustPage::GeneratePage(const std::string &method, const s
                content+=peermessagetrust+"</td>";\r
                content+="<td "+GetClassString(localtrustlisttrust)+">";\r
                content+="<input type=\"hidden\" name=\"oldlocaltrustlisttrust["+countstr+"]\" value=\""+localtrustlisttrust+"\">";\r
-               content+="<input type=\"text\" name=\"localtrustlisttrust["+countstr+"]\" value=\""+localtrustlisttrust+"\" size=\"2\" maxlength=\"3\" class=\"small90\"></td>";\r
+               content+="<input type=\"text\" name=\"localtrustlisttrust["+countstr+"]\" value=\""+localtrustlisttrust+"\" size=\"2\" maxlength=\"3\" class=\"small90\">";\r
+               if(publishtrustlist=="false")\r
+               {\r
+                       content+="*";\r
+               }\r
+               content+="</td>";\r
                content+="<td "+GetClassString(localtrustlisttrust)+">";\r
                content+="<input type=\"hidden\" name=\"oldtrustlisttrustcomment["+countstr+"]\" value=\""+SanitizeOutput(trustlisttrustcomment)+"\">";\r
                content+="<input type=\"text\" name=\"trustlisttrustcomment["+countstr+"]\" value=\""+SanitizeOutput(trustlisttrustcomment)+"\" maxlength=\"50\" class=\"small90\">";\r
@@ -419,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