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 <libibank.h>
00027
#include "NewThreadForm.h"
00028
00029
00030
00031
00032 NewThreadForm::NewThreadForm(Web *w) :
BaseForm(w, "
NewThreadForm")
00033 ,m_bImageMissing(false)
00034 {
00035 }
00036
00037
00038 NewThreadForm::~NewThreadForm()
00039 {
00040 }
00041
00042
00043 void NewThreadForm::Process()
00044 {
00045
IWeb *pWeb = static_cast<IWeb *>(GetWeb());
00046 Database& db = pWeb -> GetDatabase();
00047
char action[200];
00048
00049
00050
if (GetForm() -> getvalue( (
char *)GetFormName().c_str(), action, 200) && *action)
00051 {
00052
m_title = GetForm() -> getvalue(
"title");
00053
m_body = GetForm() -> getvalue(
"message");
00054
long image_num = 0;
00055
char fn[1000];
00056
00057 GetForm() -> getvalue(
"the_file",fn,255);
00058
m_filename = fn;
00059
if (!strncmp(fn,
"/tmp/",5) && strlen(fn) > 5)
00060 {
00061 image_num = AddImage(pWeb -> GetUsernum(), fn);
00062 }
00063
if (!image_num)
00064 {
00065
m_bImageMissing =
true;
00066
return;
00067 }
00068 db::Forum forum(db,pWeb -> GetForum());
00069 forum.updated = GetDate();
00070 forum.updated_by = pWeb -> GetUsernum();
00071 forum.save();
00072 db::Thread thread(&db);
00073 thread.started_by = pWeb -> GetUsernum();
00074 thread.started = GetDate();
00075 thread.image = image_num;
00076 thread.forum = pWeb -> GetForum();
00077 thread.title =
m_title;
00078 thread.updated = GetDate();
00079 thread.updated_by = pWeb -> GetUsernum();
00080 thread.save();
00081 db::Message message(&db);
00082 message.thread = thread.num;
00083 message.posted_by = pWeb -> GetUsernum();
00084 message.posted = GetDate();
00085 message.title =
m_title;
00086 message.body =
m_body;
00087 message.version = 1;
00088 message.updated = GetDate();
00089 message.save();
00090 db::Linkmessageimage x(&db);
00091 x.message = message.num;
00092 x.image = image_num;
00093 x.save();
00094 pWeb -> SetThread( thread.num );
00095 pWeb -> SetPage( 5 );
00096 }
00097 }
00098
00099
00100 void NewThreadForm::Display(
long)
00101 {
00102
IWeb *pWeb = static_cast<IWeb *>(GetWeb());
00103
00104
00105 Navigator(pWeb -> GetForum(),-1);
00106 printf(
"</td><td align=right>");
00107
00108 printf(
"[ <a href=\"%s?page=2\">settings</a> ",GetCgiName().c_str());
00109 printf(
"| <a href=\"%s?logout=1\">logout</a> ",GetCgiName().c_str());
00110
00111 printf(
"]</td></tr></table>");
00112 printf(
"</div>");
00113
00114
if (
m_bImageMissing)
00115 {
00116
if (
m_filename.size())
00117 printf(
"<font class=error size=\"+2\">Image upload failed</font><br>");
00118
else
00119 printf(
"<font class=error size=\"+2\">Image missing</font><br>");
00120 }
00121 printf(
"<form action=\"%s\" method=post enctype=\"multipart/form-data\">",
00122 GetCgiName().c_str());
00123 printf(
"Picture<br>");
00124 printf(
"<input type=file name=the_file><br>");
00125 printf(
"Title<br>");
00126 printf(
"<input type=text name=title size=40 value=\"%s\"><br>",
m_title.c_str());
00127 printf(
"Message<br>");
00128 printf(
"<textarea name=message rows=10 cols=80>%s</textarea><br>",
m_body.c_str());
00129 printf(
"<input type=submit name=\"%s\" value=\" Create topic \">",GetFormName().c_str());
00130 printf(
"</form>");
00131 }
00132
00133