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

EditMessageForm.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 "EditMessageForm.h" 00027 00028 /* 00029 #define DEB(x) { \ 00030 FILE *fil = fopen("/tmp/debug","at"); \ 00031 x; \ 00032 fclose(fil); \ 00033 } 00034 */ 00035 #define DEB(x) 00036 00037 00038 EditMessageForm::EditMessageForm(Web *w) : BaseForm(w, "EditMessageForm") 00039 { 00040 } 00041 00042 00043 EditMessageForm::~EditMessageForm() 00044 { 00045 } 00046 00047 00048 void EditMessageForm::Process() 00049 { 00050 IWeb *pWeb = static_cast<IWeb *>(GetWeb()); 00051 Database& db = pWeb -> GetDatabase(); 00052 char action[200]; 00053 00054 // <input type="submit" name="EditMessageForm" value="action" ... 00055 if (!GetForm() -> getvalue( (char *)GetFormName().c_str(), action, 200) || !*action) 00056 { 00057 return; 00058 } 00059 if (!strcmp(action," Update ")) 00060 { 00061 std::string title = GetForm() -> getvalue("title"); 00062 std::string message_body = GetForm() -> getvalue("message"); 00063 long image_num = 0; 00064 char fn[1000]; 00065 00066 GetForm() -> getvalue("the_file",fn,255); 00067 if (!strncmp(fn,"/tmp/",5) && strlen(fn) > 5) 00068 { 00069 image_num = AddImage(pWeb -> GetUsernum(), fn); 00070 } 00071 db::Forum forum(db,pWeb -> GetForum()); 00072 forum.updated = GetDate(); 00073 forum.updated_by = pWeb -> GetUsernum(); 00074 forum.save(); 00075 db::Thread thread(db,pWeb -> GetThread()); 00076 thread.updated = GetDate(); 00077 thread.updated_by = pWeb -> GetUsernum(); 00078 thread.save(); 00079 db::Message message(db, pWeb -> GetMessage()); 00080 message.title = title; 00081 message.body = message_body; 00082 message.version++; 00083 message.updated = GetDate(); 00084 if (message.posted_by == pWeb -> GetUsernum()) 00085 { 00086 char value[1000]; 00087 bool r = GetForm() -> getfirst(fn, 1000, value, 1000); 00088 message.save(); 00089 while (r) 00090 { 00091 DEB( fprintf(fil,"'%s' == '%s'\n",fn,value);) 00092 if (!strcmp(fn, "delete")) 00093 { 00094 long num = atol(value); 00095 db::Linkmessageimage x(db, num); 00096 if (x.message == message.num) 00097 { 00098 x.deleted = 1; 00099 x.save(); 00100 } 00101 } 00102 // 00103 r = GetForm() -> getnext(fn, 1000, value, 1000); 00104 } 00105 } 00106 if (image_num > 0) 00107 { 00108 db::Linkmessageimage x(&db); 00109 x.message = message.num; 00110 x.image = image_num; 00111 x.save(); 00112 } 00113 pWeb -> SetPage( 5 ); // View Thread 00114 } 00115 else 00116 if (!strcmp(action," Delete Message ")) 00117 { 00118 db::Message message(db, pWeb -> GetMessage()); 00119 if (message.posted_by == pWeb -> GetUsernum()) 00120 { 00121 message.deleted++; 00122 message.save(); 00123 } 00124 pWeb -> SetPage( 5 ); 00125 } 00126 } 00127 00128 00129 void EditMessageForm::Display(long) 00130 { 00131 IWeb *pWeb = static_cast<IWeb *>(GetWeb()); 00132 Database& db = pWeb -> GetDatabase(); 00133 Query q(db); 00134 db::Message message(db, pWeb -> GetMessage()); 00135 char sql[1000]; 00136 00137 // printf("<h3>Edit message</h3>"); 00138 Navigator(pWeb -> GetForum(),pWeb -> GetThread(),pWeb -> GetMessage()); 00139 printf("</td><td align=right>"); 00140 // printf("<div align=right>"); 00141 printf("[ <a href=\"%s?page=2\">settings</a> ",GetCgiName().c_str()); 00142 printf("| <a href=\"%s?logout=1\">logout</a> ",GetCgiName().c_str()); 00143 // printf("]</div>"); 00144 printf("]</td></tr></table>"); 00145 printf("</div>"); 00146 00147 printf("<form action=\"%s\" method=post enctype=\"multipart/form-data\">", 00148 GetCgiName().c_str()); 00149 printf("Add picture (optional)<br>"); 00150 printf("<input type=file name=the_file><br>"); 00151 printf("Title<br>"); 00152 printf("<input type=text name=title size=40 value=\"%s\"><br>", message.title.c_str()); 00153 printf("Message<br>"); 00154 printf("<textarea name=message rows=10 cols=80>"); 00155 viewtext(message.body, true); 00156 printf("</textarea><br>"); //, message.body.c_str() ); 00157 sprintf(sql,"select * from linkmessageimage where message=%ld and deleted=0",message.num); 00158 q.get_result(sql); 00159 printf("<table cellpadding=\"0\" cellspacing=\"0\" class=editmessage>"); 00160 printf("<tr><th>Delete</th><th>Image</th></tr>"); 00161 while (q.fetch_row()) 00162 { 00163 db::Linkmessageimage x(&db,&q); 00164 printf("<tr><td class=editmessage align=center><input type=checkbox name=delete value=%ld></td>",x.num); 00165 printf("<td class=editmessage>"); 00166 viewtn( x.image ); 00167 /* 00168 printf("<a href=\"%s?img=%ld\"><img border=\"0\" alt=\"Thumbnail\" src=\"%s?imgtn=%ld\"></a>", 00169 GetCgiName().c_str(),x.image, 00170 GetCgiName().c_str(),x.image); 00171 */ 00172 printf("</td></tr>"); 00173 } 00174 printf("</table>"); 00175 q.free_result(); 00176 printf("&nbsp;&nbsp;&nbsp;"); 00177 printf("<input type=submit name=\"%s\" value=\" Update \">",GetFormName().c_str()); 00178 printf("&nbsp;&nbsp;&nbsp;"); 00179 printf("<input type=submit name=\"%s\" value=\" Delete Message \">",GetFormName().c_str()); 00180 printf("</form>"); 00181 } 00182 00183

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