Google
Web alhem.net
Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

NewThreadForm.cpp

Go to the documentation of this file.
00001 00006 /* 00007 Copyright (C) 2004 Anders Hedstrom 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License 00011 as published by the Free Software Foundation; either version 2 00012 of the License, or (at your option) any later version. 00013 00014 This program is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with this program; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 */ 00023 //#include <stdio.h> 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 // <input type="submit" name="NewThreadForm" value="action" ... 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 ); // View Thread 00096 } 00097 } 00098 00099 00100 void NewThreadForm::Display(long) 00101 { 00102 IWeb *pWeb = static_cast<IWeb *>(GetWeb()); 00103 00104 // printf("<h3>New thread</h3>"); 00105 Navigator(pWeb -> GetForum(),-1); 00106 printf("</td><td align=right>"); 00107 // printf("<div align=right>"); 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 // printf("]</div>"); 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

Generated on Sat Feb 12 00:14:57 2005 for IBank by doxygen 1.3.7