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 "NewMessageForm.h"
00027
00028
00029
00030
00031 NewMessageForm::NewMessageForm(Web *w) :
BaseForm(w, "
NewMessageForm")
00032 {
00033 }
00034
00035
00036 NewMessageForm::~NewMessageForm()
00037 {
00038 }
00039
00040
00041 void NewMessageForm::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 std::string title = GetForm() -> getvalue(
"title");
00051 std::string message_body = GetForm() -> getvalue(
"message");
00052
long image_num = 0;
00053
char fn[1000];
00054
00055 GetForm() -> getvalue(
"the_file",fn,255);
00056
if (!strncmp(fn,
"/tmp/",5) && strlen(fn) > 5)
00057 {
00058 image_num = AddImage(pWeb -> GetUsernum(), fn);
00059 }
00060 db::Forum forum(db,pWeb -> GetForum());
00061 forum.updated = GetDate();
00062 forum.updated_by = pWeb -> GetUsernum();
00063 forum.save();
00064 db::Thread thread(db,pWeb -> GetThread());
00065 thread.updated = GetDate();
00066 thread.updated_by = pWeb -> GetUsernum();
00067 thread.save();
00068 db::Message message(&db);
00069 message.thread = pWeb -> GetThread();
00070 message.posted_by = pWeb -> GetUsernum();
00071 message.posted = GetDate();
00072 message.title = title;
00073 message.body = message_body;
00074 message.version = 1;
00075 message.updated = GetDate();
00076 message.save();
00077
if (image_num > 0)
00078 {
00079 db::Linkmessageimage x(&db);
00080 x.message = message.num;
00081 x.image = image_num;
00082 x.save();
00083 }
00084 pWeb -> SetPage( 5 );
00085 }
00086 }
00087
00088
00089 void NewMessageForm::Display(
long)
00090 {
00091
IWeb *pWeb = static_cast<IWeb *>(GetWeb());
00092
00093
00094 Navigator(pWeb -> GetForum(),pWeb -> GetThread(),-1);
00095 printf(
"</td><td align=right>");
00096
00097 printf(
"[ <a href=\"%s?page=2\">settings</a> ",GetCgiName().c_str());
00098 printf(
"| <a href=\"%s?logout=1\">logout</a> ",GetCgiName().c_str());
00099
00100 printf(
"]</td></tr></table>");
00101 printf(
"</div>");
00102
00103 printf(
"<form action=\"%s\" method=post enctype=\"multipart/form-data\">",
00104 GetCgiName().c_str());
00105 printf(
"Picture (optional)<br>");
00106 printf(
"<input type=file name=the_file><br>");
00107 printf(
"Title<br>");
00108 printf(
"<input type=text name=title size=40><br>");
00109 printf(
"Message<br>");
00110 printf(
"<textarea name=message rows=10 cols=80></textarea><br>");
00111 printf(
"<input type=submit name=\"%s\" value=\" Post \">",GetFormName().c_str());
00112 printf(
"</form>");
00113 }
00114
00115