version 0.2.22
[fms.git] / src / http / pages / optionspage.cpp
index 7743738..ff58489 100644 (file)
@@ -5,6 +5,35 @@
        #include <xmem.h>\r
 #endif\r
 \r
+const std::string OptionsPage::CreateDropDown(const std::string &name, const std::vector<std::string> &items, const std::string &selecteditem)\r
+{\r
+       std::string rval="";\r
+\r
+       rval+="<select name=\""+name+"\">";\r
+\r
+       std::vector<std::string>::const_iterator i=items.begin();\r
+       while(i!=items.end())\r
+       {\r
+               rval+="<option value=\""+(*i)+"\"";\r
+               if((*i)==selecteditem)\r
+               {\r
+                       rval+=" SELECTED";\r
+               }\r
+               rval+=">";\r
+               i++;\r
+               if(i!=items.end())\r
+               {\r
+                       rval+=(*i);\r
+                       i++;\r
+               }\r
+               rval+="</option>";\r
+       }\r
+\r
+       rval+="</select>";\r
+\r
+       return rval;\r
+}\r
+\r
 const std::string OptionsPage::GeneratePage(const std::string &method, const std::map<std::string,std::string> &queryvars)\r
 {\r
        std::string content="<h2 style=\"text-align:center;\">Options</h2>\r\n";\r
@@ -33,27 +62,49 @@ const std::string OptionsPage::GeneratePage(const std::string &method, const std
                }\r
        }\r
 \r
-       SQLite3DB::Statement st=m_db->Prepare("SELECT Option,OptionValue,OptionDescription FROM tblOption;");\r
+       SQLite3DB::Statement st=m_db->Prepare("SELECT Option,OptionValue,OptionDescription,Section,ValidValues FROM tblOption ORDER BY SortOrder;");\r
        st.Step();\r
 \r
        int count=0;\r
        std::string countstr;\r
+       std::string lastsection="";\r
        while(st.RowReturned())\r
        {\r
                std::string option;\r
                std::string value;\r
                std::string description;\r
+               std::string section;\r
+               std::string validvalues;\r
+               std::vector<std::string> validvaluevec;\r
 \r
                st.ResultText(0,option);\r
                st.ResultText(1,value);\r
                st.ResultText(2,description);\r
+               st.ResultText(3,section);\r
+               if(st.ResultNull(4)==false)\r
+               {\r
+                       st.ResultText(4,validvalues);\r
+                       StringFunctions::Split(validvalues,"|",validvaluevec);\r
+               }\r
+\r
+               if(section!=lastsection)\r
+               {\r
+                       content+="<tr>";\r
+                       content+="<td colspan=\"3\"><h3>"+section+"</h3></td>";\r
+                       content+="</tr>";\r
+                       lastsection=section;\r
+               }\r
 \r
                StringFunctions::Convert(count,countstr);\r
                content+="<tr>";\r
                content+="<td valign=\"top\"><input type=\"hidden\" name=\"option["+countstr+"]\" value=\""+option+"\">"+option+"</td>";\r
                content+="<td valign=\"top\"><input type=\"hidden\" name=\"oldvalue["+countstr+"]\" value=\""+value+"\">";\r
 \r
-               if(value!="true" && value!="false")\r
+               if(validvaluevec.size()>0)\r
+               {\r
+                       content+=CreateDropDown("value["+countstr+"]",validvaluevec,value);\r
+               }\r
+               else if(value!="true" && value!="false")\r
                {\r
                        content+="<input type=\"text\" name=\"value["+countstr+"]\" value=\""+value+"\"></td>";\r
                }\r