00001 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
#include "IWeb.h"
00026 
#include "SettingsForm.h"
00027 
00028 
00029 
00030 
00031 SettingsForm::SettingsForm(Web *w) : 
BaseForm(w, "
SettingsForm")
00032 {
00033 }
00034 
00035 
00036 SettingsForm::~SettingsForm()
00037 {
00038 }
00039 
00040 
00041 void SettingsForm::Process()
00042 {
00043         
IWeb *pWeb = static_cast<IWeb *>(GetWeb());
00044         Database& db = pWeb -> GetDatabase();
00045         
char action[200];
00046 
00047         
00048         
if (!GetForm() -> getvalue( (
char *)GetFormName().c_str(), action, 200) || !*action)
00049         {
00050                 
return;
00051         }
00052         
if (!strcmp(action,
" Save changes "))
00053         {
00054                 db::Account account(db, pWeb -> GetUsernum());
00055                 account.show_email = atoi(GetForm() -> getvalue(
"show_email").c_str());
00056                 std::string old = GetForm() -> getvalue(
"old");
00057                 std::string new_password = GetForm() -> getvalue(
"new_password");
00058                 std::string new_password2 = GetForm() -> getvalue(
"new_password2");
00059                 
if (!strcmp(old.c_str(),account.secret.c_str()))
00060                 {
00061                         
if (new_password.size() >= 4 && !strcmp(new_password.c_str(),new_password2.c_str()))
00062                         {
00063                                 account.secret = new_password;
00064                         }
00065                 }
00066                 account.save();
00067         }
00068         
if (!strcmp(action,
" Return to forums "))
00069         {
00070                 pWeb -> SetPage( 3 );
00071         }
00072 }
00073 
00074 
00075 void SettingsForm::Display(
long)
00076 {
00077         
IWeb *pWeb = static_cast<IWeb *>(GetWeb());
00078         Database& db = pWeb -> GetDatabase();
00079         db::Account account(db, pWeb -> GetUsernum());
00080 
00081 
00082         printf(
"<div class=navigator>");
00083         printf(
"<table cellpadding=0 cellspacing=0 width=\"100%%\"><tr><td>");
00084         printf(
"<b>Settings</b>");
00085         printf(
"</td><td align=right>");
00086 
00087         printf(
"[ <a href=\"%s?page=3\">forums</a> ",GetCgiName().c_str());
00088         printf(
"| <a href=\"%s?logout=1\">logout</a> ",GetCgiName().c_str());
00089 
00090         printf(
"]</td></tr></table>");
00091         printf(
"</div>");
00092 
00093         printf(
"<form action=\"%s\" method=post>",GetCgiName().c_str());
00094 
00095         printf(
"<p><b>Email</b>: %s</p>",account.email.c_str());
00096         printf(
"<p><b>Name</b>: %s</p>",account.name.c_str());
00097         printf(
"<p>");
00098         printf(
"<input type=checkbox name=show_email value=1%s> Show email when posting<br>",
00099                 account.show_email ? 
" CHECKED" : 
"");
00100         printf(
"</p><p>");
00101         printf(
"Enter old password to change<br>");
00102         printf(
"<input type=password name=old><br>");
00103         printf(
"</p><p>");
00104         printf(
"Enter new password<br>");
00105         printf(
"<input type=new_password><br>");
00106         printf(
"</p><p>");
00107         printf(
"Repeat new password<br>");
00108         printf(
"<input type=new_password2><br>");
00109         printf(
"</p>");
00110         printf(
"    ");
00111         printf(
"<input type=submit name=\"%s\" value=\" Save changes \">",GetFormName().c_str());
00112         printf(
"    ");
00113         printf(
"<input type=submit name=\"%s\" value=\" Return to forums \">",GetFormName().c_str());
00114         printf(
"</form>");
00115 }
00116 
00117