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

ViewThreadForm.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 #include <map> 00025 00026 #include "IWeb.h" 00027 #include <libibank.h> 00028 #include "ViewThreadForm.h" 00029 00030 00031 00032 00033 ViewThreadForm::ViewThreadForm(Web *w) : BaseForm(w, "ViewThreadForm") 00034 { 00035 } 00036 00037 00038 ViewThreadForm::~ViewThreadForm() 00039 { 00040 } 00041 00042 00043 void ViewThreadForm::Process() 00044 { 00045 IWeb *pWeb = static_cast<IWeb *>(GetWeb()); 00046 Database& db = pWeb -> GetDatabase(); 00047 char action[200]; 00048 00049 // <input type="submit" name="ViewThreadForm" value="action" ... 00050 if (!GetForm() -> getvalue( (char *)GetFormName().c_str(), action, 200) || !*action) 00051 { 00052 return; 00053 } 00054 if (!strcmp(action,"edit")) 00055 { 00056 std::string message = GetForm() -> getvalue("message"); 00057 long num = atol(message.c_str()); 00058 pWeb -> SetMessage(num); 00059 pWeb -> SetPage( 8 ); 00060 } 00061 else 00062 if (!strcmp(action,"delete")) 00063 { 00064 db::Thread thread(db, pWeb -> GetThread()); 00065 if (thread.started_by == pWeb -> GetUsernum()) 00066 { 00067 thread.deleted++; 00068 thread.save(); 00069 } 00070 pWeb -> SetPage( 4 ); 00071 } 00072 } 00073 00074 00075 void ViewThreadForm::Display(long) 00076 { 00077 IWeb *pWeb = static_cast<IWeb *>(GetWeb()); 00078 Database& db = pWeb -> GetDatabase(); 00079 Query q(db); 00080 Query q2(db); 00081 char sql[1000]; 00082 std::map<long,long> mmap; 00083 db::Thread thread(db, pWeb -> GetThread()); 00084 00085 // printf("<h3>View thread</h3>"); 00086 Navigator(pWeb -> GetForum(),pWeb -> GetThread()); 00087 printf("</td><td align=center>"); 00088 printf("[ <a href=\"%s?page=7\">post message</a> ",GetCgiName().c_str()); 00089 if (thread.started_by == pWeb -> GetUsernum()) 00090 { 00091 printf("| <a href=\"%s?ViewThreadForm=delete\">remove topic</a> ",GetCgiName().c_str()); 00092 } 00093 printf("]</td><td align=right>"); 00094 // printf("<div align=right>"); 00095 printf("[ <a href=\"%s?page=2\">settings</a> ",GetCgiName().c_str()); 00096 printf("| <a href=\"%s?logout=1\">logout</a> ",GetCgiName().c_str()); 00097 // printf("]</div>"); 00098 printf("]</td></tr></table>"); 00099 printf("</div>"); 00100 00101 00102 sprintf(sql,"select num,version from message where thread=%ld",pWeb -> GetThread()); 00103 q.get_result(sql); 00104 while (q.fetch_row()) 00105 { 00106 long num = q.getval(); 00107 long version = q.getval(); 00108 mmap[num] = (version > mmap[num]) ? version : mmap[num]; 00109 } 00110 q.free_result(); 00111 00112 sprintf(sql,"select * from message where thread=%ld and deleted=0 order by posted",pWeb -> GetThread()); 00113 q.get_result(sql); 00114 printf("<table cellpadding=\"0\" cellspacing=\"0\" class=viewthread width=\"100%%\">"); 00115 while (q.fetch_row()) 00116 { 00117 db::Message message(&db,&q); 00118 if (message.version == mmap[message.num]) 00119 { 00120 db::Account account(db,message.posted_by); 00121 printf("<tr>"); 00122 printf("<th class=viewthread width=\"1%%\" align=left>"); 00123 printf("%s<br>",GetAccountName(account).c_str()); 00124 nbprintf("%s",message.posted.c_str()); 00125 if (message.version > 1) 00126 { 00127 printf("<br><span class=updated>Version: %d<br>",message.version); 00128 nbprintf("%s</span>",message.updated.c_str()); 00129 } 00130 printf("</th>"); 00131 printf("<td class=viewthread><b>%s</b>",message.title.c_str()); 00132 if (message.posted_by == pWeb -> GetUsernum()) 00133 { 00134 printf(" [ <a href=\"%s?ViewThreadForm=edit&message=%ld\">edit message</a> ]",GetCgiName().c_str(),message.num); 00135 } 00136 printf("<br>"); 00137 viewtext(message.body); 00138 sprintf(sql,"select * from linkmessageimage where message=%ld and deleted=0",message.num); 00139 q2.get_result(sql); 00140 if (q2.num_rows() > 0) 00141 { 00142 printf("<hr>"); 00143 } 00144 while (q2.fetch_row()) 00145 { 00146 db::Linkmessageimage x(&db,&q2); 00147 printf("&nbsp;&nbsp;"); 00148 viewtn( x.image ); 00149 // printf("<a href=\"%s?img=%ld\">",GetCgiName().c_str(),x.image); 00150 // printf("<img alt=\"Thumbnail\" border=\"0\" src=\"%s?imgtn=%ld\"></a> ",GetCgiName().c_str(),x.image); 00151 } 00152 q2.free_result(); 00153 printf("</tr>"); 00154 } 00155 } 00156 printf("</table>"); 00157 q.free_result(); 00158 } 00159 00160

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