Updated init script.
[dtbartle/bnbt.git] / tracker_index.cpp
1 /***\r
2 *\r
3 * BNBT Beta 8.0 - A C++ BitTorrent Tracker\r
4 * Copyright (C) 2003-2004 Trevor Hogan\r
5 *\r
6 * CBTT variations (C) 2003-2005 Harold Feit\r
7 *\r
8 * This library is free software; you can redistribute it and/or\r
9 * modify it under the terms of the GNU Lesser General Public\r
10 * License as published by the Free Software Foundation; either\r
11 * version 2.1 of the License, or (at your option) any later version.\r
12 *\r
13 * This library is distributed in the hope that it will be useful,\r
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
16 * Lesser General Public License for more details.\r
17 *\r
18 * You should have received a copy of the GNU Lesser General Public\r
19 * License along with this library; if not, write to the Free Software\r
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
21 *\r
22 ***/\r
23 \r
24 #include "bnbt.h"\r
25 #include "atom.h"\r
26 #include "sort.h"\r
27 #include "tracker.h"\r
28 #include "util.h"\r
29 \r
30 void CTracker :: serverResponseIndex( struct request_t *pRequest, struct response_t *pResponse, user_t user )\r
31 {\r
32         struct bnbttv btv = UTIL_CurrentTime( );\r
33 \r
34         pResponse->strCode = "200 OK";\r
35 \r
36         pResponse->mapHeaders.insert( pair<string, string>( "Content-Type", string( "text/html; charset=" ) + gstrCharSet ) );\r
37 \r
38         pResponse->strContent += "<html>\n";\r
39         pResponse->strContent += "<head>\n";\r
40         if ( !gstrTrackerTitle.empty( ) )\r
41                 pResponse->strContent += "<title>" + gstrTrackerTitle + " - Tracker Info</title>\n";\r
42         else\r
43                 pResponse->strContent += "<title>BNBT Tracker Info</title>\n";\r
44 \r
45         if( !gstrStyle.empty( ) )\r
46                 pResponse->strContent += "<link rel=stylesheet type=\"text/css\" href=\"" + gstrStyle + "\">\n";\r
47         //addition by labarks\r
48         if( !m_strDumpRSSFile.empty( ) )\r
49         {\r
50                 pResponse->strContent += "<!-- Filename: " + m_strDumpRSSFile + " -->";\r
51                 string :: size_type iExt2 = m_strDumpRSSFile.rfind( "\\" );\r
52                 string :: size_type iExt = m_strDumpRSSFile.rfind( "/" );\r
53 \r
54                 string strPath;\r
55                 \r
56                 if( iExt != string :: npos )\r
57                         strPath = m_strDumpRSSFile.substr( iExt );\r
58                 if( iExt2 != string :: npos )\r
59                         strPath = m_strDumpRSSFile.substr( iExt2 );\r
60                 string m_strDumpRSSFileNameToUse = m_strDumpRSSFile.substr( m_strDumpRSSFile.length() - strPath.length() + 1, strPath.length() );\r
61 \r
62                 if( (m_iDumpRSSFileMode == 0 || m_iDumpRSSFileMode == 2) && !m_strDumpRSSFileURL.empty() )\r
63                         pResponse->strContent += "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"" + m_strDumpRSSFileURL + m_strDumpRSSFileNameToUse + "\">\n";\r
64                 // There's a bug here Harold, Remove this comment when fixed\r
65         }\r
66         //end addition\r
67 \r
68         pResponse->strContent += "</head>\n";\r
69         pResponse->strContent += "<body>\n";\r
70 \r
71         if( !m_bDisableLogon )\r
72         {\r
73                 if( user.strLogin.empty( ) )\r
74                         pResponse->strContent += "<p class=\"login1_index\">You are not logged in. Click <a href=\"/login.html\">here</a> to login.</p>\n";\r
75                 else\r
76                         pResponse->strContent += "<p class=\"login2_index\">You are logged in as <span class=\"username\">" + UTIL_RemoveHTML( user.strLogin ) + "</span>. Click <a href=\"/login.html?logout=1\">here</a> to logout.</p>\n";\r
77         }\r
78 \r
79         if( user.iAccess & ACCESS_VIEW )\r
80         {\r
81                 //\r
82                 // delete torrent\r
83                 //\r
84 \r
85                 if( user.iAccess & ACCESS_EDIT )\r
86                 {\r
87                         if( pRequest->mapParams.find( "del" ) != pRequest->mapParams.end( ) )\r
88                         {\r
89                                 string strDelHashString = pRequest->mapParams["del"];\r
90                                 string strDelHash = UTIL_StringToHash( strDelHashString );\r
91                                 string strOK = pRequest->mapParams["ok"];\r
92 \r
93                                 if( strDelHash.empty( ) )\r
94                                 {\r
95                                         pResponse->strContent += "<p>Unable to delete torrent " + strDelHashString + ". The info hash is invalid. Click <a href=\"/index.html\">here</a> to return to the tracker.</p>\n";\r
96 \r
97                                         if( m_bGen )\r
98                                                 pResponse->strContent += "<p class=\"gen\">Generated in " + UTIL_ElapsedTimeStr( btv, UTIL_CurrentTime( ) ) + " seconds.</p>\n";\r
99 \r
100                                         pResponse->strContent += "</body>\n";\r
101                                         pResponse->strContent += "</html>\n";\r
102 \r
103                                         return;\r
104                                 }\r
105                                 else\r
106                                 {\r
107                                         if( strOK == "1" )\r
108                                         {\r
109                                                 if( m_pAllowed )\r
110                                                 {\r
111                                                         // delete from disk\r
112 \r
113                                                         CAtom *pList = m_pAllowed->getItem( strDelHash );\r
114 \r
115                                                         if( pList && pList->isList( ) )\r
116                                                         {\r
117                                                                 vector<CAtom *> vecTorrent = ( (CAtomList *)pList )->getValue( );\r
118 \r
119                                                                 if( vecTorrent.size( ) == 6 )\r
120                                                                 {\r
121                                                                         CAtom *pFileName = vecTorrent[0];\r
122 \r
123                                                                         if( pFileName )\r
124                                                                         {\r
125                                                                                 if( m_strArchiveDir.empty( ) )\r
126                                                                                         UTIL_DeleteFile( ( m_strAllowedDir + pFileName->toString( ) ).c_str( ) );\r
127                                                                                 else\r
128                                                                                         UTIL_MoveFile( ( m_strAllowedDir + pFileName->toString( ) ).c_str( ), ( m_strArchiveDir + pFileName->toString( ) ).c_str( ) );\r
129                                                                         }\r
130                                                                 }\r
131                                                         }\r
132 \r
133                                                         m_pAllowed->delItem( strDelHash );\r
134                                                         m_pDFile->delItem( strDelHash );\r
135                                                         deleteTag( strDelHash );\r
136 \r
137                                                         pResponse->strContent += "<p>Deleted torrent " + strDelHashString + ". Click <a href=\"/index.html\">here</a> to return to the tracker.</p>\n";\r
138 \r
139                                                         if( m_bGen )\r
140                                                                 pResponse->strContent += "<p class=\"gen\">Generated in " + UTIL_ElapsedTimeStr( btv, UTIL_CurrentTime( ) ) + " seconds.</p>\n";\r
141 \r
142                                                         pResponse->strContent += "</body>\n";\r
143                                                         pResponse->strContent += "</html>\n";\r
144 \r
145                                                         return;\r
146                                                 }\r
147                                         }\r
148                                         else\r
149                                         {\r
150                                                 pResponse->strContent += "<p>Are you sure you want to delete the torrent " + strDelHashString + "?</p>\n";\r
151                                                 // The Trinity Edition - Modification Begins\r
152                                                 // The following replaces the OK response with a YES | NO option\r
153                                                 // when DELETING A TORRENT\r
154 \r
155                                                 pResponse->strContent += "<p><a href=\"/index.html?del=" + strDelHashString + "&ok=1\">YES</a>\n";\r
156                                                 pResponse->strContent += " | <a href=\"javascript:history.back()\">NO</a></p>\n";\r
157 \r
158                                                 /* Original Source Code:\r
159                                                 pResponse->strContent += "<p><a href=\"/index.html?del=" + pDel->toString( ) + "&ok=1\">OK</a></p>\n";\r
160                                                 */\r
161 \r
162                                                 // ------------------------------------------------- End of Modification\r
163                                                 pResponse->strContent += "</body>\n";\r
164                                                 pResponse->strContent += "</html>\n";\r
165 \r
166                                                 return;\r
167                                         }\r
168                                 }\r
169                         }\r
170                 }\r
171 \r
172                 pResponse->strContent += m_strStaticHeader;\r
173 \r
174                 if( m_pDFile )\r
175                 {\r
176                         if( m_pDFile->isEmpty( ) )\r
177                         {\r
178                                 pResponse->strContent += "<p>Not tracking any files yet!</p>\n";\r
179 \r
180                                 pResponse->strContent += m_strStaticFooter;\r
181 \r
182                                 if( m_bGen )\r
183                                         pResponse->strContent += "<p class=\"gen\">Generated in " + UTIL_ElapsedTimeStr( btv, UTIL_CurrentTime( ) ) + " seconds.</p>\n";\r
184 \r
185                                 pResponse->strContent += "</body>\n";\r
186                                 pResponse->strContent += "</html>\n";\r
187 \r
188                                 return;\r
189                         }\r
190 \r
191                         map<string, CAtom *> *pmapDicti = m_pDFile->getValuePtr( );\r
192 \r
193                         unsigned long iKeySize = pmapDicti->size( );\r
194 \r
195                         // add the torrents into this structure one by one and sort it afterwards\r
196 \r
197                         struct torrent_t *pTorrents = new struct torrent_t[iKeySize];\r
198 \r
199                         unsigned long i = 0;\r
200 \r
201                         for( map<string, CAtom *> :: iterator it = pmapDicti->begin( ); it != pmapDicti->end( ); it++ )\r
202                         {\r
203                                 pTorrents[i].strInfoHash = (*it).first;\r
204                                 pTorrents[i].strName = "unknown";\r
205                                 pTorrents[i].strLowerName = "unknown";\r
206                                 pTorrents[i].iComplete = 0;\r
207                                 pTorrents[i].iDL = 0;\r
208                                 pTorrents[i].iSize = 0;\r
209                                 pTorrents[i].iFiles = 0;\r
210                                 pTorrents[i].iComments = 0;\r
211                                 pTorrents[i].iAverageLeft = 0;\r
212                                 pTorrents[i].iAverageLeftPercent = 0;\r
213                                 pTorrents[i].iMinLeft = 0;\r
214                                 pTorrents[i].iMaxiLeft = 0;\r
215                                 pTorrents[i].iCompleted = 0;\r
216                                 pTorrents[i].iTransferred = 0;\r
217 \r
218                                 if( (*it).second->isDicti( ) )\r
219                                 {\r
220                                         map<string, CAtom *> *pmapPeersDicti = ( (CAtomDicti *)(*it).second )->getValuePtr( );\r
221 \r
222                                         bool bFirst = true;\r
223 \r
224                                         for( map<string, CAtom *> :: iterator j = pmapPeersDicti->begin( ); j != pmapPeersDicti->end( ); j++ )\r
225                                         {\r
226                                                 if( (*j).second->isDicti( ) )\r
227                                                 {\r
228                                                         CAtom *pLeft = ( (CAtomDicti *)(*j).second )->getItem( "left" );\r
229 \r
230                                                         if( pLeft && pLeft->isLong( ) )\r
231                                                         {\r
232                                                                 int64 iLeft = ( (CAtomLong *)pLeft )->getValue( );\r
233 \r
234                                                                 if( iLeft == 0 )\r
235                                                                         pTorrents[i].iComplete++;\r
236                                                                 else\r
237                                                                 {\r
238                                                                         pTorrents[i].iDL++;\r
239 \r
240                                                                         // only calculate average / min / max on leechers\r
241 \r
242                                                                         pTorrents[i].iAverageLeft += iLeft;\r
243 \r
244                                                                         if( bFirst || iLeft < pTorrents[i].iMinLeft )\r
245                                                                                 pTorrents[i].iMinLeft = iLeft;\r
246 \r
247                                                                         if( bFirst || iLeft > pTorrents[i].iMaxiLeft )\r
248                                                                                 pTorrents[i].iMaxiLeft = iLeft;\r
249 \r
250                                                                         bFirst = false;\r
251                                                                 }\r
252                                                         }\r
253                                                 }\r
254                                         }\r
255 \r
256                                         if( m_pAllowed )\r
257                                         {\r
258                                                 CAtom *pList = m_pAllowed->getItem( pTorrents[i].strInfoHash );\r
259 \r
260                                                 if( pList && pList->isList( ) )\r
261                                                 {\r
262                                                         vector<CAtom *> vecTorrent = ( (CAtomList *)pList )->getValue( );\r
263 \r
264                                                         if( vecTorrent.size( ) == 6 )\r
265                                                         {\r
266                                                                 CAtom *pFileName = vecTorrent[0];\r
267                                                                 CAtom *pName = vecTorrent[1];\r
268                                                                 CAtom *pAdded = vecTorrent[2];\r
269                                                                 CAtom *pSize = vecTorrent[3];\r
270                                                                 CAtom *pFiles = vecTorrent[4];\r
271 \r
272                                                                 if( pFileName )\r
273                                                                         pTorrents[i].strFileName = pFileName->toString( );\r
274 \r
275                                                                 if( pName )\r
276                                                                 {\r
277                                                                         // stick a lower case version in strNameLower for non case sensitive searching and sorting\r
278 \r
279                                                                         pTorrents[i].strName = pName->toString( );\r
280                                                                         pTorrents[i].strLowerName = UTIL_ToLower( pTorrents[i].strName );\r
281                                                                 }\r
282 \r
283                                                                 if( pAdded )\r
284                                                                         pTorrents[i].strAdded = pAdded->toString( );\r
285 \r
286                                                                 if( pSize && dynamic_cast<CAtomLong *>( pSize ) )\r
287                                                                         pTorrents[i].iSize = dynamic_cast<CAtomLong *>( pSize )->getValue( );\r
288 \r
289                                                                 if( pFiles && dynamic_cast<CAtomInt *>( pFiles ) )\r
290                                                                         pTorrents[i].iFiles = dynamic_cast<CAtomInt *>( pFiles )->getValue( );\r
291                                                         }\r
292                                                 }\r
293 \r
294                                                 if( m_bAllowComments )\r
295                                                 {\r
296                                                         if( m_pComments )\r
297                                                         {\r
298                                                                 CAtom *pCommentList = m_pComments->getItem( pTorrents[i].strInfoHash );\r
299 \r
300                                                                 if( pCommentList && pCommentList->isList( ) )\r
301                                                                         pTorrents[i].iComments = ( (CAtomList *)pCommentList )->getValuePtr( )->size( );\r
302                                                         }\r
303                                                 }\r
304                                         }\r
305 \r
306                                         if( m_pCompleted )\r
307                                         {\r
308                                                 CAtom *pCompleted = m_pCompleted->getItem( pTorrents[i].strInfoHash );\r
309 \r
310                                                 if( pCompleted && pCompleted->isLong( ) )\r
311                                                 {\r
312                                                         pTorrents[i].iCompleted = (int)( (CAtomLong *)pCompleted )->getValue( );\r
313 \r
314                                                         // size has already been found, calculate transferred\r
315 \r
316                                                         if( m_pAllowed && m_bShowTransferred )\r
317                                                                 pTorrents[i].iTransferred = pTorrents[i].iCompleted * pTorrents[i].iSize;\r
318                                                 }\r
319                                         }\r
320 \r
321                                         if( m_pTags )\r
322                                         {\r
323                                                 CAtom *pDicti = m_pTags->getItem( pTorrents[i].strInfoHash );\r
324 \r
325                                                 if( pDicti && pDicti->isDicti( ) )\r
326                                                 {\r
327                                                         CAtom *pTag = ( (CAtomDicti *)pDicti )->getItem( "tag" );\r
328                                                         CAtom *pName = ( (CAtomDicti *)pDicti )->getItem( "name" );\r
329                                                         CAtom *pUploader = ( (CAtomDicti *)pDicti )->getItem( "uploader" );\r
330                                                         CAtom *pInfoLink = ( (CAtomDicti *)pDicti )->getItem( "infolink" );\r
331 \r
332                                                         if( pTag )\r
333                                                                 pTorrents[i].strTag = pTag->toString( );\r
334 \r
335                                                         if( pName )\r
336                                                         {\r
337                                                                 // this will overwrite the previous name, i.e. the filename\r
338 \r
339                                                                 pTorrents[i].strName = pName->toString( );\r
340                                                                 pTorrents[i].strLowerName = UTIL_ToLower( pTorrents[i].strName );\r
341                                                         }\r
342 \r
343                                                         if( pUploader )\r
344                                                                 pTorrents[i].strUploader = pUploader->toString( );\r
345 \r
346                                                         if( pInfoLink )\r
347                                                                 pTorrents[i].strInfoLink = pInfoLink->toString( );\r
348                                                 }\r
349                                         }\r
350 \r
351                                         if( m_bShowAverageLeft )\r
352                                         {\r
353                                                 // iAverageLeft actually contains the total left at this point, so find the average\r
354 \r
355                                                 if( pTorrents[i].iDL > 0 )\r
356                                                         pTorrents[i].iAverageLeft /= pTorrents[i].iDL;\r
357 \r
358                                                 if( pTorrents[i].iSize > 0 )\r
359                                                         pTorrents[i].iAverageLeftPercent = (int)( ( (float)pTorrents[i].iAverageLeft / pTorrents[i].iSize ) * 100 );\r
360                                         }\r
361                                 }\r
362 \r
363                                 i++;\r
364                         }\r
365 \r
366                         string strSort = pRequest->mapParams["sort"];\r
367 \r
368                         if( m_bSort )\r
369                         {\r
370                                 if( !strSort.empty( ) )\r
371                                 {\r
372                                         int iSort = atoi( strSort.c_str( ) );\r
373 \r
374                                         if( iSort == SORT_ANAME )\r
375                                         {\r
376                                                 if( m_pAllowed && m_bShowNames )\r
377                                                         qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), asortByName );\r
378                                         }\r
379                                         else if( iSort == SORT_ACOMPLETE )\r
380                                                 qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), asortByComplete );\r
381                                         else if( iSort == SORT_AINCOMPLETE )\r
382                                                 qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), asortByDL );\r
383                                         else if( iSort == SORT_AADDED )\r
384                                         {\r
385                                                 if( m_pAllowed && m_bShowAdded )\r
386                                                         qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), asortByAdded );\r
387                                         }\r
388                                         else if( iSort == SORT_ASIZE )\r
389                                         {\r
390                                                 if( m_pAllowed && m_bShowSize )\r
391                                                         qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), asortBySize );\r
392                                         }\r
393                                         else if( iSort == SORT_AFILES )\r
394                                         {\r
395                                                 if( m_pAllowed && m_bShowNumFiles )\r
396                                                         qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), asortByFiles );\r
397                                         }\r
398                                         else if( iSort == SORT_ACOMMENTS )\r
399                                         {\r
400                                                 if( m_pAllowed && m_bAllowComments )\r
401                                                         qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), asortByComments );\r
402                                         }\r
403                                         else if( iSort == SORT_AAVGLEFT )\r
404                                         {\r
405                                                 if( m_bShowAverageLeft )\r
406                                                 {\r
407                                                         if( m_pAllowed )\r
408                                                         {\r
409                                                                 if( m_bShowLeftAsProgress )\r
410                                                                         qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), dsortByAvgLeftPercent );\r
411                                                                 else\r
412                                                                         qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), asortByAvgLeftPercent );\r
413                                                         }\r
414                                                         else\r
415                                                                 qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), asortByAvgLeft );\r
416                                                 }\r
417                                         }\r
418                                         else if( iSort == SORT_ACOMPLETED )\r
419                                         {\r
420                                                 if( m_bShowCompleted )\r
421                                                         qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), asortByCompleted );\r
422                                         }\r
423                                         else if( iSort == SORT_ATRANSFERRED )\r
424                                         {\r
425                                                 if( m_pAllowed && m_bShowTransferred )\r
426                                                         qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), asortByTransferred );\r
427                                         }\r
428                                         else if( iSort == SORT_DNAME )\r
429                                         {\r
430                                                 if( m_pAllowed && m_bShowNames )\r
431                                                         qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), dsortByName );\r
432                                         }\r
433                                         else if( iSort == SORT_DCOMPLETE )\r
434                                                 qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), dsortByComplete );\r
435                                         else if( iSort == SORT_DINCOMPLETE )\r
436                                                 qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), dsortByDL );\r
437                                         else if( iSort == SORT_DADDED )\r
438                                         {\r
439                                                 if( m_pAllowed && m_bShowAdded )\r
440                                                         qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), dsortByAdded );\r
441                                         }\r
442                                         else if( iSort == SORT_DSIZE )\r
443                                         {\r
444                                                 if( m_pAllowed && m_bShowSize )\r
445                                                         qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), dsortBySize );\r
446                                         }\r
447                                         else if( iSort == SORT_DFILES )\r
448                                         {\r
449                                                 if( m_pAllowed && m_bShowNumFiles )\r
450                                                         qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), dsortByFiles );\r
451                                         }\r
452                                         else if( iSort == SORT_DCOMMENTS )\r
453                                         {\r
454                                                 if( m_pAllowed && m_bAllowComments )\r
455                                                         qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), dsortByComments );\r
456                                         }\r
457                                         else if( iSort == SORT_DAVGLEFT )\r
458                                         {\r
459                                                 if( m_bShowAverageLeft )\r
460                                                 {\r
461                                                         if( m_pAllowed )\r
462                                                         {\r
463                                                                 if( m_bShowLeftAsProgress )\r
464                                                                         qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), asortByAvgLeftPercent );\r
465                                                                 else\r
466                                                                         qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), dsortByAvgLeftPercent );\r
467                                                         }\r
468                                                         else\r
469                                                                 qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), dsortByAvgLeft );\r
470                                                 }\r
471                                         }\r
472                                         else if( iSort == SORT_DCOMPLETED )\r
473                                         {\r
474                                                 if( m_bShowCompleted )\r
475                                                         qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), dsortByCompleted );\r
476                                         }\r
477                                         else if( iSort == SORT_DTRANSFERRED )\r
478                                         {\r
479                                                 if( m_pAllowed && m_bShowTransferred )\r
480                                                         qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), dsortByTransferred );\r
481                                         }\r
482                                         else\r
483                                         {\r
484                                                 // default action is to sort by added if we can\r
485 \r
486                                                 if( m_pAllowed && m_bShowAdded )\r
487                                                         qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), dsortByAdded );\r
488                                         }\r
489                                 }\r
490                                 else\r
491                                 {\r
492                                         // default action is to sort by added if we can\r
493 \r
494                                         if( m_pAllowed && m_bShowAdded )\r
495                                                 qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), dsortByAdded );\r
496                                 }\r
497                         }\r
498                         else\r
499                         {\r
500                                 // sort is disabled, but default action is to sort by added if we can\r
501 \r
502                                 if( m_pAllowed && m_bShowAdded )\r
503                                         qsort( pTorrents, iKeySize, sizeof( struct torrent_t ), dsortByAdded );\r
504                         }\r
505 \r
506                         // some preliminary search crap\r
507 \r
508                         string strSearch = pRequest->mapParams["search"];\r
509                         string strLowerSearch = UTIL_ToLower( strSearch );\r
510                         string strSearchResp = UTIL_StringToEscaped( strSearch );\r
511 \r
512                         if( !strSearch.empty( ) && m_pAllowed && m_bShowNames && m_bSearch )\r
513                                 pResponse->strContent += "<p class=\"search_results\">Search results for \"" + UTIL_RemoveHTML( strSearch ) + "\".</p>\n";\r
514 \r
515                         // filters\r
516 \r
517                         string strFilter = pRequest->mapParams["filter"];\r
518 \r
519                         if( !m_vecTags.empty( ) )\r
520                         {\r
521                                 pResponse->strContent += "<p align=\"center\">";\r
522 \r
523                                 bool bFound = false;\r
524 \r
525                                 for( vector< pair<string, string> > :: iterator i = m_vecTags.begin( ); i != m_vecTags.end( ); i++ )\r
526                                 {\r
527                                         if( !bFound )\r
528                                                 // The Trinity Edition - Modification Begins\r
529                                                 // The following changes the CLEAR FILTER link to read\r
530                                                 // CLEAR FILTER AND SEARCH RESULTS which appears before the\r
531                                                 // Table of Torrents\r
532 \r
533                                                 // It also sets a CSS class "clearfilter" which can be used\r
534                                                 // to HIDE this link using the following CSS command \r
535                                                 // .clearfilter{display:none}\r
536 \r
537                                                 pResponse->strContent += "<p class=\"clearfilter\"><a href=\"/index.html\">Clear Filter and Search Results</a></p>\n";\r
538 \r
539                                                 /* Original Source Code:\r
540                                                 pResponse->strContent += "<a href=\"/index.html\">Clear Filter</a><br><br>\n";\r
541                                                 */\r
542 \r
543                                                 // ------------------------------------------------- End of Modification\r
544 \r
545                                         //addition by labarks\r
546                                         pResponse->strContent += "<a title=\"" + (*i).first + "\" href=\"/index.html?filter=" + UTIL_StringToEscaped( (*i).first );\r
547                                         /* Original Source Code:\r
548                                         pResponse->strContent += "<a href=\"/index.html?filter=" + UTIL_StringToEscaped( (*i).first );\r
549                                         */\r
550                                         //end addition\r
551 \r
552                                         if( !strSort.empty( ) )\r
553                                                 pResponse->strContent += "&sort=" + strSort;\r
554 \r
555                                         if( !strSearch.empty( ) )\r
556                                                 pResponse->strContent += "&search=" + strSearchResp;\r
557 \r
558                                         pResponse->strContent += "\">";\r
559 \r
560                                         if( !(*i).second.empty( ) )\r
561                                                 pResponse->strContent += "<img class=\"tag\" src=\"" + (*i).second + "\" border=\"0\">";\r
562                                         else\r
563                                                 pResponse->strContent += UTIL_RemoveHTML( (*i).first );\r
564 \r
565                                         pResponse->strContent += "</a>";\r
566 \r
567                                         //RSS Support - Code by labarks\r
568                                         if( ( m_iDumpRSSFileMode == 1 || m_iDumpRSSFileMode == 2 ) && m_strDumpRSSFileDir != "" )\r
569                                         {\r
570                                                 string :: size_type iExt = m_strDumpRSSFile.rfind( "." );\r
571 \r
572                                                 string strExt;\r
573 \r
574                                                 if( iExt != string :: npos )\r
575                                                         strExt = m_strDumpRSSFile.substr( iExt );\r
576                                                 string strRSSFile = UTIL_StripPath( m_strDumpRSSFile );\r
577                                                 strRSSFile = m_strDumpRSSFileDir + strRSSFile.substr( 0, strRSSFile.length() - strExt.length() ) + "-" + (*i).first + strExt;\r
578 \r
579                                                 pResponse->strContent += "<span class=\"dash\">&nbsp;-&nbsp;</span><a class=\"rss\" href=\"" + strRSSFile + "\">RSS</a>";\r
580                                         }\r
581                                         //end addition\r
582 \r
583                                         if( i + 1 != m_vecTags.end( ) )\r
584                                                 pResponse->strContent += " <span class=\"pipe\">|</span> ";\r
585 \r
586                                         bFound = true;\r
587                                 }\r
588 \r
589                                 pResponse->strContent += "</p>\n";\r
590                         }\r
591 \r
592                         // which page are we viewing\r
593 \r
594                         unsigned int iStart = 0;\r
595                         unsigned int m_override_iPerPage;\r
596                         string strPerPage = pRequest->mapParams["per_page"];\r
597                         if ( strPerPage.empty() )\r
598                                 m_override_iPerPage = m_iPerPage;\r
599                         else\r
600                                 m_override_iPerPage = atoi(strPerPage.c_str() );\r
601 \r
602 \r
603                         if( m_override_iPerPage > 0 )\r
604                         {\r
605                                 string strPage = pRequest->mapParams["page"];\r
606 \r
607                                 if( !strPage.empty( ) )\r
608                                         iStart = atoi( strPage.c_str( ) ) * m_override_iPerPage;\r
609 \r
610                                 // The Trinity Edition - Modification Begins\r
611                                 // The following code changes "Page" to "You are viewing page" which appears before the current page number\r
612 \r
613                                 // It also creates an internal document link, called "Jump to Page Navigation and Torrent Search" that will\r
614                                 // bring the user to the bottom of the Table of Torrents\r
615 \r
616                                 // Sets a CSS class "pagenavjumplink" which can be used to HIDE this link\r
617                                 // using the following CSS command: .pagenavjumplink{display:none}\r
618                                 \r
619                 pResponse->strContent += "<p class=\"pagenum_top\">You are viewing page " + CAtomInt( ( iStart / m_override_iPerPage ) + 1 ).toString( ) + "\n";\r
620                 pResponse->strContent += "<span class=\"pagenavjumplink\">| <a href=\"#search\">Jump to Page Navigation and Torrent Search</a></span></p>\n";\r
621 \r
622                                 /* Original Source Code:\r
623                                 pResponse->strContent += "<p class=\"pagenum_top\">Page " + CAtomInt( ( iStart / m_override_iPerPage ) + 1 ).toString( ) + "</p>\n";\r
624                                 */\r
625 \r
626                                 // ------------------------------------------------- End of Modification\r
627                         }\r
628 \r
629                         bool bFound = false;\r
630 \r
631                         int iAdded = 0;\r
632                         int iSkipped = 0;\r
633 \r
634                         // for correct page numbers after searching\r
635 \r
636                         int iFound = 0;\r
637 \r
638                         for( unsigned long i = 0; i < iKeySize; i++ )\r
639                         {\r
640                                 if( !strFilter.empty( ) )\r
641                                 {\r
642                                         // only display entries that match the filter\r
643 \r
644                                         if( pTorrents[i].strTag != strFilter )\r
645                                                 continue;\r
646                                 }\r
647 \r
648                                 if( !strSearch.empty( ) )\r
649                                 {\r
650                                         // only display entries that match the search\r
651 \r
652                                         if( pTorrents[i].strLowerName.find( strLowerSearch ) == string :: npos )\r
653                                                 continue;\r
654                                 }\r
655 \r
656                                 iFound++;\r
657 \r
658                                 if( m_override_iPerPage == 0 || iAdded < m_override_iPerPage )\r
659                                 {\r
660                                         if( !bFound )\r
661                                         {\r
662                                                 // output table headers\r
663 \r
664                                                 pResponse->strContent += "<table summary=\"files\">\n";\r
665                                                 pResponse->strContent += "<tr>";\r
666 \r
667                                                 // <th> tag\r
668 \r
669                                                 if( !m_vecTags.empty( ) )\r
670                                                         pResponse->strContent += "<th>Tag</th>";\r
671 \r
672                                                 // <th> info hash\r
673 \r
674                                                 if( m_bShowInfoHash )\r
675                                                         pResponse->strContent += "<th class=\"hash\">Info Hash</th>";\r
676 \r
677                                                 // <th> name\r
678 \r
679                                                 if( m_pAllowed && m_bShowNames )\r
680                                                 {\r
681                                                         pResponse->strContent += "<th class=\"name\">Name";\r
682 \r
683                                                         if( m_bSort )\r
684                                                         {\r
685                                                                 pResponse->strContent += "<br><a class=\"sort\" href=\"/index.html?sort=" + SORTSTR_ANAME;\r
686 \r
687                                                                 if( !strSearch.empty( ) )\r
688                                                                         pResponse->strContent += "&search=" + strSearchResp;\r
689 \r
690                                                                 if( !strFilter.empty( ) )\r
691                                                                         pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
692 \r
693                                                                 if( !strPerPage.empty( ) )\r
694                                                                         pResponse->strContent += "&per_page=" + strPerPage;\r
695 \r
696                                                                 pResponse->strContent += "\">A</a> <a class=\"sort\" href=\"/index.html?sort=" + SORTSTR_DNAME;\r
697 \r
698                                                                 if( !strSearch.empty( ) )\r
699                                                                         pResponse->strContent += "&search=" + strSearchResp;\r
700 \r
701                                                                 if( !strFilter.empty( ) )\r
702                                                                         pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
703 \r
704                                                                 if( !strPerPage.empty( ) )\r
705                                                                         pResponse->strContent += "&per_page=" + strPerPage;\r
706 \r
707                                                                 pResponse->strContent += "\">Z</a>";\r
708                                                         }\r
709 \r
710                                                         pResponse->strContent += "</th>";\r
711                                                 }\r
712 \r
713                                                 // <th> torrent\r
714 \r
715                                                 if( m_pAllowed && m_bAllowTorrentDownloads && ( user.iAccess & ACCESS_DL ) && !m_bSwapTorrentLink )\r
716                                                         pResponse->strContent += "<th class=\"download\">Torrent</th>\n";\r
717 \r
718                                                 // <th> Stats\r
719 \r
720                                                 if( m_pAllowed && m_bShowStats && ( user.iAccess & ACCESS_DL ) && m_bSwapTorrentLink )\r
721                                                         pResponse->strContent += "<th class=\"download\">Stats</th>\n";\r
722 \r
723 \r
724                                                 // <th> comments\r
725 \r
726                                                 if( m_pAllowed && m_bAllowComments )\r
727                                                 {\r
728                                                         if( m_pComments )\r
729                                                         {\r
730                                                                 pResponse->strContent += "<th class=\"number\">Comments";\r
731 \r
732                                                                 if( m_bSort )\r
733                                                                 {\r
734                                                                         pResponse->strContent += "<br><a class=\"sort\" href=\"/index.html?sort=" + SORTSTR_ACOMMENTS;\r
735 \r
736                                                                         if( !strSearch.empty( ) )\r
737                                                                                 pResponse->strContent += "&search=" + strSearchResp;\r
738 \r
739                                                                         if( !strFilter.empty( ) )\r
740                                                                                 pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
741 \r
742                                                                         if( !strPerPage.empty( ) )\r
743                                                                                 pResponse->strContent += "&per_page=" + strPerPage;\r
744 \r
745 \r
746                                                                         pResponse->strContent += "\">A</a> <a class=\"sort\" href=\"/index.html?sort=" + SORTSTR_DCOMMENTS;\r
747 \r
748                                                                         if( !strSearch.empty( ) )\r
749                                                                                 pResponse->strContent += "&search=" + strSearchResp;\r
750 \r
751                                                                         if( !strFilter.empty( ) )\r
752                                                                                 pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
753 \r
754                                                                         if( !strPerPage.empty( ) )\r
755                                                                                 pResponse->strContent += "&per_page=" + strPerPage;\r
756 \r
757                                                                         pResponse->strContent += "\">Z</a>";\r
758                                                                 }\r
759 \r
760                                                                 pResponse->strContent += "</th>";\r
761                                                         }\r
762                                                 }\r
763 \r
764                                                 // <th> added\r
765 \r
766                                                 if( m_pAllowed && m_bShowAdded )\r
767                                                 {\r
768                                                         pResponse->strContent += "<th class=\"date\">Added";\r
769                                                         \r
770                                                         if( m_bSort )\r
771                                                         {\r
772                                                                 pResponse->strContent += "<br><a class=\"sort\" href=\"/index.html?sort=" + SORTSTR_AADDED;\r
773 \r
774                                                                 if( !strSearch.empty( ) )\r
775                                                                         pResponse->strContent += "&search=" + strSearchResp;\r
776 \r
777                                                                 if( !strFilter.empty( ) )\r
778                                                                         pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
779 \r
780                                                                 if( !strPerPage.empty( ) )\r
781                                                                         pResponse->strContent += "&per_page=" + strPerPage;\r
782 \r
783                                                                 pResponse->strContent += "\">A</a> <a class=\"sort\" href=\"/index.html?sort=" + SORTSTR_DADDED;\r
784 \r
785                                                                 if( !strSearch.empty( ) )\r
786                                                                         pResponse->strContent += "&search=" + strSearchResp;\r
787 \r
788                                                                 if( !strFilter.empty( ) )\r
789                                                                         pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
790 \r
791                                                                 if( !strPerPage.empty( ) )\r
792                                                                         pResponse->strContent += "&per_page=" + strPerPage;\r
793 \r
794                                                                 pResponse->strContent += "\">Z</a>";\r
795                                                         }\r
796 \r
797                                                         pResponse->strContent += "</th>";\r
798                                                 }\r
799 \r
800                                                 // <th> size\r
801 \r
802                                                 if( m_pAllowed && m_bShowSize )\r
803                                                 {\r
804                                                         pResponse->strContent += "<th class=\"bytes\">Size";\r
805 \r
806                                                         if( m_bSort )\r
807                                                         {\r
808                                                                 pResponse->strContent += "<br><a class=\"sort\" href=\"/index.html?sort=" + SORTSTR_ASIZE;\r
809 \r
810                                                                 if( !strSearch.empty( ) )\r
811                                                                         pResponse->strContent += "&search=" + strSearchResp;\r
812 \r
813                                                                 if( !strFilter.empty( ) )\r
814                                                                         pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
815 \r
816                                                                 if( !strPerPage.empty( ) )\r
817                                                                         pResponse->strContent += "&per_page=" + strPerPage;\r
818 \r
819                                                                 pResponse->strContent += "\">A</a> <a class=\"sort\" href=\"/index.html?sort=" + SORTSTR_DSIZE;\r
820 \r
821                                                                 if( !strSearch.empty( ) )\r
822                                                                         pResponse->strContent += "&search=" + strSearchResp;\r
823 \r
824                                                                 if( !strFilter.empty( ) )\r
825                                                                         pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
826 \r
827                                                                 if( !strPerPage.empty( ) )\r
828                                                                         pResponse->strContent += "&per_page=" + strPerPage;\r
829 \r
830                                                                 pResponse->strContent += "\">Z</a>";\r
831                                                         }\r
832 \r
833                                                         pResponse->strContent += "</th>";\r
834                                                 }\r
835 \r
836                                                 // <th> files\r
837 \r
838                                                 if( m_pAllowed && m_bShowNumFiles )\r
839                                                 {\r
840                                                         pResponse->strContent += "<th class=\"number\">Files";\r
841 \r
842                                                         if( m_bSort )\r
843                                                         {\r
844                                                                 pResponse->strContent += "<br><a class=\"sort\" href=\"/index.html?sort=" + SORTSTR_AFILES;\r
845 \r
846                                                                 if( !strSearch.empty( ) )\r
847                                                                         pResponse->strContent += "&search=" + strSearchResp;\r
848 \r
849                                                                 if( !strFilter.empty( ) )\r
850                                                                         pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
851 \r
852                                                                 if( !strPerPage.empty( ) )\r
853                                                                         pResponse->strContent += "&per_page=" + strPerPage;\r
854 \r
855                                                                 pResponse->strContent += "\">A</a> <a class=\"sort\" href=\"/index.html?sort=" + SORTSTR_DFILES;\r
856 \r
857                                                                 if( !strSearch.empty( ) )\r
858                                                                         pResponse->strContent += "&search=" + strSearchResp;\r
859 \r
860                                                                 if( !strFilter.empty( ) )\r
861                                                                         pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
862 \r
863                                                                 if( !strPerPage.empty( ) )\r
864                                                                         pResponse->strContent += "&per_page=" + strPerPage;\r
865 \r
866                                                                 pResponse->strContent += "\">Z</a>";\r
867                                                         }\r
868 \r
869                                                         pResponse->strContent += "</th>";\r
870                                                 }\r
871 \r
872                                                 // <th> seeders\r
873 \r
874                                                 pResponse->strContent += "<th class=\"number\">SDs";\r
875                                                 \r
876                                                 if( m_bSort )\r
877                                                 {\r
878                                                         pResponse->strContent += "<br><a class=\"sort\" href=\"/index.html?sort=" + SORTSTR_ACOMPLETE;\r
879 \r
880                                                         if( !strSearch.empty( ) )\r
881                                                                 pResponse->strContent += "&search=" + strSearchResp;\r
882 \r
883                                                         if( !strFilter.empty( ) )\r
884                                                                 pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
885 \r
886                                                         if( !strPerPage.empty( ) )\r
887                                                                 pResponse->strContent += "&per_page=" + strPerPage;\r
888 \r
889                                                         pResponse->strContent += "\">A</a> <a class=\"sort\" href=\"/index.html?sort=" + SORTSTR_DCOMPLETE;\r
890 \r
891                                                         if( !strSearch.empty( ) )\r
892                                                                 pResponse->strContent += "&search=" + strSearchResp;\r
893 \r
894                                                         if( !strFilter.empty( ) )\r
895                                                                 pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
896 \r
897                                                         if( !strPerPage.empty( ) )\r
898                                                                 pResponse->strContent += "&per_page=" + strPerPage;\r
899 \r
900                                                         pResponse->strContent += "\">Z</a>";\r
901                                                 }\r
902 \r
903                                                 pResponse->strContent += "</th>";\r
904 \r
905                                                 // <th> leechers\r
906                                                 \r
907                                                 pResponse->strContent += "<th class=\"number\">DLs";\r
908                                                 \r
909                                                 if( m_bSort )\r
910                                                 {\r
911                                                         pResponse->strContent += "<br><a class=\"sort\" href=\"/index.html?sort=" + SORTSTR_AINCOMPLETE;\r
912 \r
913                                                         if( !strSearch.empty( ) )\r
914                                                                 pResponse->strContent += "&search=" + strSearchResp;\r
915 \r
916                                                         if( !strFilter.empty( ) )\r
917                                                                 pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
918 \r
919                                                         if( !strPerPage.empty( ) )\r
920                                                                 pResponse->strContent += "&per_page=" + strPerPage;\r
921 \r
922                                                         pResponse->strContent += "\">A</a> <a class=\"sort\" href=\"/index.html?sort=" + SORTSTR_DINCOMPLETE;\r
923 \r
924                                                         if( !strSearch.empty( ) )\r
925                                                                 pResponse->strContent += "&search=" + strSearchResp;\r
926 \r
927                                                         if( !strFilter.empty( ) )\r
928                                                                 pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
929 \r
930                                                         if( !strPerPage.empty( ) )\r
931                                                                 pResponse->strContent += "&per_page=" + strPerPage;\r
932 \r
933                                                         pResponse->strContent += "\">Z</a>";\r
934                                                 }\r
935 \r
936                                                 pResponse->strContent += "</th>";\r
937 \r
938                                                 // <th> completed\r
939 \r
940                                                 if( m_bShowCompleted )\r
941                                                 {\r
942                                                         pResponse->strContent += "<th class=\"number\">Completed";\r
943 \r
944                                                         if( m_bSort )\r
945                                                         {\r
946                                                                 pResponse->strContent += "<br><a class=\"sort\" href=\"/index.html?sort=" + SORTSTR_ACOMPLETED;\r
947 \r
948                                                                 if( !strSearch.empty( ) )\r
949                                                                         pResponse->strContent += "&search=" + strSearchResp;\r
950 \r
951                                                                 if( !strFilter.empty( ) )\r
952                                                                         pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
953 \r
954                                                                 if( !strPerPage.empty( ) )\r
955                                                                         pResponse->strContent += "&per_page=" + strPerPage;\r
956 \r
957                                                                 pResponse->strContent += "\">A</a> <a class=\"sort\" href=\"/index.html?sort=" + SORTSTR_DCOMPLETED;\r
958 \r
959                                                                 if( !strSearch.empty( ) )\r
960                                                                         pResponse->strContent += "&search=" + strSearchResp;\r
961 \r
962                                                                 if( !strFilter.empty( ) )\r
963                                                                         pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
964 \r
965                                                                 if( !strPerPage.empty( ) )\r
966                                                                         pResponse->strContent += "&per_page=" + strPerPage;\r
967 \r
968                                                                 pResponse->strContent += "\">Z</a>";\r
969                                                         }\r
970 \r
971                                                         pResponse->strContent += "</th>";\r
972                                                 }\r
973 \r
974                                                 // <th> transferred\r
975 \r
976                                                 if( m_pAllowed && m_bShowTransferred )\r
977                                                 {\r
978                                                         pResponse->strContent += "<th class=\"bytes\">Transferred";\r
979 \r
980                                                         if( m_bSort )\r
981                                                         {\r
982                                                                 pResponse->strContent += "<br><a class=\"sort\" href=\"/index.html?sort=" + SORTSTR_ATRANSFERRED;\r
983 \r
984                                                                 if( !strSearch.empty( ) )\r
985                                                                         pResponse->strContent += "&search=" + strSearchResp;\r
986 \r
987                                                                 if( !strFilter.empty( ) )\r
988                                                                         pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
989 \r
990                                                                 if( !strPerPage.empty( ) )\r
991                                                                         pResponse->strContent += "&per_page=" + strPerPage;\r
992 \r
993                                                                 pResponse->strContent += "\">A</a> <a class=\"sort\" href=\"/index.html?sort=" + SORTSTR_DTRANSFERRED;\r
994 \r
995                                                                 if( !strSearch.empty( ) )\r
996                                                                         pResponse->strContent += "&search=" + strSearchResp;\r
997 \r
998                                                                 if( !strFilter.empty( ) )\r
999                                                                         pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
1000 \r
1001                                                                 if( !strPerPage.empty( ) )\r
1002                                                                         pResponse->strContent += "&per_page=" + strPerPage;\r
1003 \r
1004                                                                 pResponse->strContent += "\">Z</a>";\r
1005                                                         }\r
1006 \r
1007                                                         pResponse->strContent += "</th>";\r
1008                                                 }\r
1009 \r
1010                                                 // <th> min left\r
1011 \r
1012                                                 if( m_bShowMinLeft )\r
1013                                                 {\r
1014                                                         if( m_pAllowed && m_bShowLeftAsProgress )\r
1015                                                                 pResponse->strContent += "<th class=\"percent\">Min Progress</th>";\r
1016                                                         else\r
1017                                                                 pResponse->strContent += "<th class=\"percent\">Min Left</th>";\r
1018                                                 }\r
1019 \r
1020                                                 // <th> average left\r
1021 \r
1022                                                 if( m_bShowAverageLeft )\r
1023                                                 {\r
1024                                                         if( m_pAllowed && m_bShowLeftAsProgress )\r
1025                                                                 pResponse->strContent += "<th class=\"percent\">Average Progress";\r
1026                                                         else\r
1027                                                                 pResponse->strContent += "<th class=\"percent\">Average Left";\r
1028 \r
1029                                                         if( m_bSort )\r
1030                                                         {\r
1031                                                                 pResponse->strContent += "<br><a class=\"sort\" href=\"/index.html?sort=" + SORTSTR_AAVGLEFT;\r
1032 \r
1033                                                                 if( !strSearch.empty( ) )\r
1034                                                                         pResponse->strContent += "&search=" + strSearchResp;\r
1035 \r
1036                                                                 if( !strFilter.empty( ) )\r
1037                                                                         pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
1038 \r
1039                                                                 if( !strPerPage.empty( ) )\r
1040                                                                         pResponse->strContent += "&per_page=" + strPerPage;\r
1041 \r
1042                                                                 pResponse->strContent += "\">A</a> <a class=\"sort\" href=\"/index.html?sort=" + SORTSTR_DAVGLEFT;\r
1043 \r
1044                                                                 if( !strSearch.empty( ) )\r
1045                                                                         pResponse->strContent += "&search=" + strSearchResp;\r
1046 \r
1047                                                                 if( !strFilter.empty( ) )\r
1048                                                                         pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
1049 \r
1050                                                                 if( !strPerPage.empty( ) )\r
1051                                                                         pResponse->strContent += "&per_page=" + strPerPage;\r
1052 \r
1053                                                                 pResponse->strContent += "\">Z</a>";\r
1054                                                         }\r
1055 \r
1056                                                         pResponse->strContent += "</th>";\r
1057                                                 }\r
1058 \r
1059                                                 // <th> maxi left\r
1060 \r
1061                                                 if( m_bShowMaxiLeft )\r
1062                                                 {\r
1063                                                         if( m_pAllowed && m_bShowLeftAsProgress )\r
1064                                                                 pResponse->strContent += "<th class=\"percent\">Max Progress</th>";\r
1065                                                         else\r
1066                                                                 pResponse->strContent += "<th class=\"percent\">Max Left</th>";\r
1067                                                 }\r
1068 \r
1069                                                 // <th> uploader\r
1070 \r
1071                                                 if( m_bShowUploader )\r
1072                                                         pResponse->strContent += "<th class=\"name\">Uploader</th>";\r
1073 \r
1074                                                 // <th> info link\r
1075 \r
1076                                                 if( m_bAllowInfoLink )\r
1077                                                         pResponse->strContent += "<th class=\"infolink\">Info Link</th>";\r
1078 \r
1079                                                 // <th> admin\r
1080 \r
1081                                                 if( user.iAccess & ACCESS_EDIT )\r
1082                                                 {\r
1083                                                         if( m_pAllowed )\r
1084                                                                 pResponse->strContent += "<th>Admin</th>";\r
1085                                                 }\r
1086 \r
1087                                                 pResponse->strContent += "</tr>\n";\r
1088 \r
1089                                                 bFound = true;\r
1090                                         }\r
1091 \r
1092                                         if( iSkipped == (int)iStart )\r
1093                                         {\r
1094                                                 // output table rows\r
1095 \r
1096                                                 if( iAdded % 2 )\r
1097                                                         pResponse->strContent += "<tr class=\"even\">";\r
1098                                                 else\r
1099                                                         pResponse->strContent += "<tr class=\"odd\">";\r
1100 \r
1101                                                 // <td> tag\r
1102 \r
1103                                                 if( !m_vecTags.empty( ) )\r
1104                                                 {\r
1105                                                         string strTemp = pTorrents[i].strTag;\r
1106 \r
1107                                                         for( vector< pair<string, string> > :: iterator j = m_vecTags.begin( ); j != m_vecTags.end( ); j++ )\r
1108                                                         {\r
1109                                                                 if( (*j).first == pTorrents[i].strTag && !(*j).second.empty( ) ){\r
1110                                                                         //addition by labarks\r
1111                                                                         pTorrents[i].strTag = "<img src=\"" + (*j).second + "\" border=\"0\"/>";\r
1112                                                                         /* Original source code:\r
1113                                                                         pTorrents[i].strTag = "<img src=\"" + (*j).second + "\">";\r
1114                                                                         */\r
1115                                                                 }\r
1116                                                         }\r
1117 \r
1118                                                         if( pTorrents[i].strTag == strTemp )\r
1119                                                                 pTorrents[i].strTag = UTIL_RemoveHTML( pTorrents[i].strTag );\r
1120 \r
1121                                                         pResponse->strContent += "<td class=\"tag\">";\r
1122 \r
1123                                                         // Link code for tag Filters\r
1124                                                         pResponse->strContent += "<a title=\"" + strTemp + "\" href=\"/index.html?filter=" + UTIL_StringToEscaped( strTemp );\r
1125 \r
1126                                                         if( !strSort.empty( ) )\r
1127                                                                 pResponse->strContent += "&sort=" + strSort;\r
1128 \r
1129                                                         if( !strSearch.empty( ) )\r
1130                                                                 pResponse->strContent += "&search=" + strSearchResp;\r
1131 \r
1132                                                         pResponse->strContent += "\">";\r
1133                                                         // End link code for tag Filters\r
1134                                                         pResponse->strContent += pTorrents[i].strTag;\r
1135                                                         pResponse->strContent += "</a>";\r
1136                                                         pResponse->strContent += "</td>";\r
1137                                                 }\r
1138 \r
1139                                                 // <td> info hash\r
1140 \r
1141                                                 if( m_bShowInfoHash )\r
1142                                                 {\r
1143                                                         pResponse->strContent += "<td class=\"hash\">";\r
1144 \r
1145                                                         if( m_bShowStats && !m_bSwapTorrentLink )\r
1146                                                                 pResponse->strContent += "<a class=\"stats\" href=\"/stats.html?info_hash=" + UTIL_HashToString( pTorrents[i].strInfoHash ) + "\">";\r
1147                                                         if( m_bSwapTorrentLink && m_pAllowed && m_bAllowTorrentDownloads && ( user.iAccess & ACCESS_DL ) )\r
1148                                                         {\r
1149                                                                 pResponse->strContent += "<a class=\"download\" href=\"";\r
1150                                                                 if( m_strExternalTorrentDir.empty( ) )\r
1151                                                                         pResponse->strContent += "/torrents/" + UTIL_StringToEscapedStrict( pTorrents[i].strFileName ) + "?info_hash=" + UTIL_HashToString( pTorrents[i].strInfoHash );\r
1152                                                                 else\r
1153                                                                         pResponse->strContent += m_strExternalTorrentDir + UTIL_StringToEscapedStrict( pTorrents[i].strFileName );\r
1154                                 pResponse->strContent += "\">";\r
1155                                                         }\r
1156 \r
1157                                                         pResponse->strContent += UTIL_HashToString( pTorrents[i].strInfoHash );\r
1158 \r
1159                                                         if( m_bShowStats || ( m_bSwapTorrentLink && m_pAllowed && m_bAllowTorrentDownloads && ( user.iAccess & ACCESS_DL ) ) )\r
1160                                                                 pResponse->strContent += "</a>";\r
1161 \r
1162                                                         pResponse->strContent += "</td>";\r
1163                                                 }\r
1164 \r
1165                                                 // <td> name\r
1166 \r
1167                                                 if( m_pAllowed && m_bShowNames )\r
1168                                                 {\r
1169                                                         pResponse->strContent += "<td class=\"name\">";\r
1170 \r
1171                                                         if( m_bShowStats && !m_bSwapTorrentLink )\r
1172                                                         {\r
1173                                                                 pResponse->strContent += "<a class=\"stats\" href=\"/stats.html?info_hash=" + UTIL_HashToString( pTorrents[i].strInfoHash ) + "\">";\r
1174                                                                 if( m_strStatsLinkImage != "" )\r
1175                                                                         pResponse->strContent += "<img src=\"" + m_strStatsLinkImage + "\" border=0 alt=\"Statistics\">";\r
1176                                                         }\r
1177 \r
1178                                                         if( m_bSwapTorrentLink && m_pAllowed && m_bAllowTorrentDownloads && ( user.iAccess & ACCESS_DL ) )\r
1179                                                         {\r
1180                                                                 pResponse->strContent += "<a class=\"download\" href=\"";\r
1181                                                                 if( m_strExternalTorrentDir.empty( ) )\r
1182                                                                         pResponse->strContent += "/torrents/" + UTIL_StringToEscapedStrict( pTorrents[i].strFileName ) + "?info_hash=" + UTIL_HashToString( pTorrents[i].strInfoHash );\r
1183                                                                 else\r
1184                                                                         pResponse->strContent += m_strExternalTorrentDir + UTIL_StringToEscapedStrict( pTorrents[i].strFileName );\r
1185                                                                 pResponse->strContent += "\">";\r
1186 \r
1187                                                                 if( m_strDownloadLinkImage != "" )\r
1188                                                                         pResponse->strContent += "<img src=\"" + m_strDownloadLinkImage + "\" border=0 alt=\"Download Torrent\">";\r
1189                                                         }\r
1190 \r
1191                                                         pResponse->strContent += UTIL_RemoveHTML( pTorrents[i].strName );\r
1192 \r
1193                                                         if( m_bShowStats || ( m_bSwapTorrentLink && m_pAllowed && m_bAllowTorrentDownloads && ( user.iAccess & ACCESS_DL ) ) )\r
1194                                                                 pResponse->strContent += "</a>";\r
1195 \r
1196                                                         pResponse->strContent += "</td>";\r
1197                                                 }\r
1198 \r
1199                                                 // <td> torrent\r
1200 \r
1201                                                 if( m_pAllowed && m_bAllowTorrentDownloads && ( user.iAccess & ACCESS_DL ) && !m_bSwapTorrentLink )\r
1202                                                 {\r
1203                                                         pResponse->strContent += "<td class=\"download\"><a class=\"download\" href=\"";\r
1204 \r
1205                                                         // Removed previous code for clarity, /torrent.html support is present for legacy link support ONLY. all links are generated with /torrents/<torrentname>?info_hash=<hash> for clarity\r
1206                                                         if( m_strExternalTorrentDir.empty( ) )\r
1207                                                                 pResponse->strContent += "/torrents/" + UTIL_StringToEscapedStrict( pTorrents[i].strFileName ) + "?info_hash=" + UTIL_HashToString( pTorrents[i].strInfoHash );\r
1208                                                         else\r
1209                                                                 pResponse->strContent += m_strExternalTorrentDir + UTIL_StringToEscapedStrict( pTorrents[i].strFileName );\r
1210 \r
1211                                                         if( m_strDownloadLinkImage == "" )\r
1212                                                                 pResponse->strContent += "\">DL</a></td>";\r
1213                                                         else\r
1214                                                                 pResponse->strContent += "\"><img src=\"" + m_strDownloadLinkImage + "\" border=0 alt=\"Download Torrent\"></a></td>";\r
1215                                                 }\r
1216 \r
1217                                                 // <td> Torrent Info\r
1218                                                 if( m_bShowStats && m_bSwapTorrentLink )\r
1219                                                 {\r
1220                             pResponse->strContent += "<td class=\"download\">";\r
1221                                                         if( m_strStatsLinkImage == "" )\r
1222                                                                 pResponse->strContent += "<a class=\"stats\" href=\"/stats.html?info_hash=" + UTIL_HashToString( pTorrents[i].strInfoHash ) + "\">Stats</a></td>";\r
1223                                                         else\r
1224                                                                 pResponse->strContent += "<a class=\"stats\" href=\"/stats.html?info_hash=" + UTIL_HashToString( pTorrents[i].strInfoHash ) + "\"><img src=\"" + m_strStatsLinkImage + "\" border=0 alt=\"Stats\"></a></td>";\r
1225                                                 }\r
1226 \r
1227                                                 // <td> comments\r
1228 \r
1229                                                 if( m_pAllowed && m_bAllowComments )\r
1230                                                 {\r
1231                                                         if( m_pComments )\r
1232                                                                 pResponse->strContent += "<td class=\"number\"><a href=\"/comments.html?info_hash=" + UTIL_HashToString( pTorrents[i].strInfoHash ) + "\">" + CAtomInt( pTorrents[i].iComments ).toString( ) + "</a></td>";\r
1233                                                 }\r
1234 \r
1235                                                 // <td> added\r
1236 \r
1237                                                 if( m_pAllowed && m_bShowAdded )\r
1238                                                 {\r
1239                                                         pResponse->strContent += "<td class=\"date\">";\r
1240 \r
1241                                                         if( !pTorrents[i].strAdded.empty( ) )\r
1242                                                         {\r
1243                                                                 // strip year and seconds from time\r
1244 \r
1245                                                                 pResponse->strContent += pTorrents[i].strAdded.substr( 5, pTorrents[i].strAdded.size( ) - 8 );\r
1246                                                         }\r
1247 \r
1248                                                         pResponse->strContent += "</td>";\r
1249                                                 }\r
1250 \r
1251                                                 // <td> size\r
1252 \r
1253                                                 if( m_pAllowed && m_bShowSize )\r
1254                                                         pResponse->strContent += "<td class=\"bytes\">" + UTIL_BytesToString( pTorrents[i].iSize ) + "</td>";\r
1255 \r
1256                                                 // <td> files\r
1257 \r
1258                                                 if( m_pAllowed && m_bShowNumFiles )\r
1259                                                         pResponse->strContent += "<td class=\"number\">" + CAtomInt( pTorrents[i].iFiles ).toString( ) + "</td>";\r
1260 \r
1261                                                 // <td> seeders\r
1262 \r
1263                                                 pResponse->strContent += "<td class=\"number_";\r
1264 \r
1265                                                 if( pTorrents[i].iComplete == 0 )\r
1266                                                         pResponse->strContent += "red\">";\r
1267                                                 else if( pTorrents[i].iComplete < 5 )\r
1268                                                         pResponse->strContent += "yellow\">";\r
1269                                                 else\r
1270                                                         pResponse->strContent += "green\">";\r
1271 \r
1272                                                 pResponse->strContent += CAtomInt( pTorrents[i].iComplete ).toString( ) + "</td>";\r
1273 \r
1274                                                 // <td> leechers\r
1275 \r
1276                                                 pResponse->strContent += "<td class=\"number_";\r
1277 \r
1278                                                 if( pTorrents[i].iDL == 0 )\r
1279                                                         pResponse->strContent += "red\">";\r
1280                                                 else if( pTorrents[i].iDL < 5 )\r
1281                                                         pResponse->strContent += "yellow\">";\r
1282                                                 else\r
1283                                                         pResponse->strContent += "green\">";\r
1284 \r
1285                                                 pResponse->strContent += CAtomInt( pTorrents[i].iDL ).toString( ) + "</td>";\r
1286 \r
1287                                                 // <td> completed\r
1288 \r
1289                                                 if( m_bShowCompleted )\r
1290                                                         pResponse->strContent += "<td class=\"number\">" + CAtomInt( pTorrents[i].iCompleted ).toString( ) + "</td>";\r
1291 \r
1292                                                 // <td> transferred\r
1293 \r
1294                                                 if( m_pAllowed && m_bShowTransferred )\r
1295                                                         pResponse->strContent += "<td class=\"bytes\">" + UTIL_BytesToString( pTorrents[i].iTransferred ) + "</td>";\r
1296 \r
1297                                                 // <td> min left\r
1298 \r
1299                                                 if( m_bShowMinLeft )\r
1300                                                 {\r
1301                                                         pResponse->strContent += "<td class=\"percent\">";\r
1302 \r
1303                                                         if( pTorrents[i].iDL == 0 )\r
1304                                                                 pResponse->strContent += "N/A";\r
1305                                                         else\r
1306                                                         {\r
1307                                                                 if( m_pAllowed )\r
1308                                                                 {\r
1309                                                                         int iPercent = 0;\r
1310 \r
1311                                                                         if( pTorrents[i].iSize > 0 )\r
1312                                                                         {\r
1313                                                                                 if( m_bShowLeftAsProgress )\r
1314                                                                                         iPercent = 100 - (int)( ( (float)pTorrents[i].iMaxiLeft / pTorrents[i].iSize ) * 100 );\r
1315                                                                                 else\r
1316                                                                                         iPercent = (int)( ( (float)pTorrents[i].iMinLeft / pTorrents[i].iSize ) * 100 );\r
1317                                                                         }\r
1318 \r
1319                                                                         pResponse->strContent += CAtomInt( iPercent ).toString( ) + "%</td>";\r
1320                                                                 }\r
1321                                                                 else\r
1322                                                                         pResponse->strContent += UTIL_BytesToString( pTorrents[i].iMinLeft );\r
1323                                                         }\r
1324                                                 }\r
1325 \r
1326                                                 // <td> average left\r
1327 \r
1328                                                 if( m_bShowAverageLeft )\r
1329                                                 {\r
1330                                                         pResponse->strContent += "<td class=\"percent\">";\r
1331 \r
1332                                                         if( pTorrents[i].iDL == 0 )\r
1333                                                                 pResponse->strContent += "N/A";\r
1334                                                         else\r
1335                                                         {\r
1336                                                                 if( m_pAllowed )\r
1337                                                                 {\r
1338                                                                         int iPercent;\r
1339 \r
1340                                                                         if( m_bShowLeftAsProgress )\r
1341                                                                                 iPercent = 100 - pTorrents[i].iAverageLeftPercent;\r
1342                                                                         else\r
1343                                                                                 iPercent = pTorrents[i].iAverageLeftPercent;\r
1344 \r
1345                                                                         pResponse->strContent += CAtomInt( iPercent ).toString( ) + "%";\r
1346 \r
1347                                                                         if( !m_strImageBarFill.empty( ) && !m_strImageBarTrans.empty( ) )\r
1348                                                                         {\r
1349                                                                                 pResponse->strContent += "<br>";\r
1350 \r
1351                                                                                 if( iPercent < 0 )\r
1352                                                                                         iPercent = 0;\r
1353                                                                                 if( iPercent > 100 )\r
1354                                                                                         iPercent = 100;\r
1355 \r
1356                                                                                 if( iPercent > 0 )\r
1357                                                                                         pResponse->strContent += "<img src=\"" + m_strImageBarFill + "\" width=" + CAtomInt( iPercent ).toString( ) + " height=8>";\r
1358 \r
1359                                                                                 if( iPercent < 100 )\r
1360                                                                                         pResponse->strContent += "<img src=\"" + m_strImageBarTrans + "\" width=" + CAtomInt( 100 - iPercent ).toString( ) + " height=8>";\r
1361                                                                         }\r
1362                                                                 }\r
1363                                                                 else\r
1364                                                                         pResponse->strContent += UTIL_BytesToString( pTorrents[i].iAverageLeft );\r
1365 \r
1366                                                                 pResponse->strContent += "</td>";\r
1367                                                         }\r
1368                                                 }\r
1369 \r
1370                                                 // <td> maxi left\r
1371 \r
1372                                                 if( m_bShowMaxiLeft )\r
1373                                                 {\r
1374                                                         pResponse->strContent += "<td class=\"percent\">";\r
1375 \r
1376                                                         if( pTorrents[i].iDL == 0 )\r
1377                                                                 pResponse->strContent += "N/A";\r
1378                                                         else\r
1379                                                         {\r
1380                                                                 if( m_pAllowed )\r
1381                                                                 {\r
1382                                                                         int iPercent = 0;\r
1383 \r
1384                                                                         if( pTorrents[i].iSize > 0 )\r
1385                                                                         {\r
1386                                                                                 if( m_bShowLeftAsProgress )\r
1387                                                                                         iPercent = 100 - (int)( ( (float)pTorrents[i].iMinLeft / pTorrents[i].iSize ) * 100 );\r
1388                                                                                 else\r
1389                                                                                         iPercent = (int)( ( (float)pTorrents[i].iMaxiLeft / pTorrents[i].iSize ) * 100 );\r
1390                                                                         }\r
1391 \r
1392                                                                         pResponse->strContent += CAtomInt( iPercent ).toString( ) + "%</td>";\r
1393                                                                 }\r
1394                                                                 else\r
1395                                                                         pResponse->strContent += UTIL_BytesToString( pTorrents[i].iMaxiLeft );\r
1396                                                         }\r
1397                                                 }\r
1398 \r
1399                                                 // <td> uploader\r
1400 \r
1401                                                 if( m_bShowUploader )\r
1402                                                         pResponse->strContent += "<td class=\"name\">" + UTIL_RemoveHTML( pTorrents[i].strUploader ) + "</td>";\r
1403 \r
1404                                                 // <td> info link\r
1405 \r
1406                                                 if( m_bAllowInfoLink )\r
1407                                                 {\r
1408                                                         pResponse->strContent += "<td class=\"infolink\">";\r
1409 \r
1410                                                         if( !pTorrents[i].strInfoLink.empty( ) )\r
1411                                                                 pResponse->strContent += "<a href=\"" + UTIL_RemoveHTML( pTorrents[i].strInfoLink ) + "\">Link</a>";\r
1412 \r
1413                                                         pResponse->strContent += "</td>";\r
1414                                                 }\r
1415 \r
1416                                                 // <td> admin\r
1417 \r
1418                                                 if( user.iAccess & ACCESS_EDIT )\r
1419                                                 {\r
1420                                                         if( m_pAllowed )\r
1421                                                                 pResponse->strContent += "<td>[<a href=\"/index.html?del=" + UTIL_HashToString( pTorrents[i].strInfoHash ) + "\">Delete</a>]</td>";\r
1422                                                 }\r
1423 \r
1424                                                 pResponse->strContent += "</tr>\n";\r
1425 \r
1426                                                 iAdded++;\r
1427                                         }\r
1428                                         else\r
1429                                                 iSkipped++;\r
1430                                 }\r
1431                         }\r
1432 \r
1433                         delete [] pTorrents;\r
1434 \r
1435                         // some finishing touches\r
1436 \r
1437                         if( bFound )\r
1438                                 pResponse->strContent += "</table>\n";\r
1439 \r
1440                         if( m_pAllowed && m_bShowNames && m_bSearch )\r
1441                         {\r
1442                                 pResponse->strContent += "<span class=\"search_index\"><form method=\"get\" action=\"/index.html\">\n";\r
1443 \r
1444                                 if( !strSort.empty( ) )\r
1445                                         pResponse->strContent += "<input name=\"sort\" type=hidden value=\"" + strSort + "\">\n";\r
1446 \r
1447                                 if( !strFilter.empty( ) )\r
1448                                         pResponse->strContent += "<input name=\"filter\" type=hidden value=\"" + strFilter + "\">\n";\r
1449 \r
1450                                 pResponse->strContent += "Search <input name=\"search\" type=text size=40> <a href=\"/index.html\">Clear Search</a>\n";\r
1451                                 pResponse->strContent += "</form></span>\n";\r
1452                         }\r
1453 \r
1454                         // page numbers\r
1455 \r
1456                         // Number of items to show left/right of the current page:\r
1457                         unsigned int pageRange = 3;\r
1458                         \r
1459                         if( m_override_iPerPage > 0 )\r
1460                         {\r
1461                                 pResponse->strContent += "<table class=\"pagenumbers\"><tr><td width=\"39%\"><p align=\"right\" class=\"pagenum_bottom\">";\r
1462 \r
1463                                 // iStart holds the start number of items.  Ie, 45 means hold from 45 to 45+m_override_iPerPage\r
1464                                 // m_override_iPerPage holds the number of items on a page.\r
1465 \r
1466 \r
1467 /*                              // Lets just temporarily store this stuff, so we're not constantly regenerating it...\r
1468                                 string tmpHTML;\r
1469 \r
1470                                 if( !strSort.empty( ) )\r
1471                                         tmpHTML += "&sort=" + strSort;\r
1472 \r
1473                                 if( !strSearch.empty( ) )\r
1474                                         tmpHTML += "&search=" + strSearchResp;\r
1475 \r
1476                                 if( !strFilter.empty( ) )\r
1477                                         tmpHTML += "&filter=" + UTIL_StringToEscaped( strFilter );\r
1478 */                              \r
1479                                 \r
1480                                 // Add a "go to start" link if the current page is more than pageRange pages away...\r
1481                                 if( iStart > m_override_iPerPage * m_iPageRange) {\r
1482                                         pResponse->strContent += "<span class=\"pages\"><a href=\"/index.html?page=0";\r
1483                                         \r
1484                                         if( !strSort.empty( ) )\r
1485                                                 pResponse->strContent += "&sort=" + strSort;\r
1486 \r
1487                                         if( !strSearch.empty( ) )\r
1488                                                 pResponse->strContent += "&search=" + strSearchResp;\r
1489 \r
1490                                         if( !strFilter.empty( ) )\r
1491                                                 pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
1492 \r
1493                                         if( !strPerPage.empty( ) )\r
1494                                                 pResponse->strContent += "&per_page=" + strPerPage;\r
1495 \r
1496                                         pResponse->strContent += "\" title=\"Go to first page\">&laquo;</a></span>&nbsp;";\r
1497                                 }\r
1498                                 \r
1499                                 // Adds a previous link iff we are not at the beginning\r
1500                                 if( iStart != 0 )\r
1501                                 {\r
1502                                         pResponse->strContent += "<span class=\"pages\"><a href=\"/index.html?page=" + CAtomInt( (iStart / m_override_iPerPage) - 1 ).toString( );\r
1503                                         \r
1504                                         if( !strSort.empty( ) )\r
1505                                                 pResponse->strContent += "&sort=" + strSort;\r
1506 \r
1507                                         if( !strSearch.empty( ) )\r
1508                                                 pResponse->strContent += "&search=" + strSearchResp;\r
1509 \r
1510                                         if( !strFilter.empty( ) )\r
1511                                                 pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
1512 \r
1513                                         if( !strPerPage.empty( ) )\r
1514                                                 pResponse->strContent += "&per_page=" + strPerPage;\r
1515 \r
1516                                         pResponse->strContent += "\" title=\"Previous page\">&lt;</a></span>&nbsp;";\r
1517                                 }\r
1518                                 \r
1519                                 for( unsigned int i = ( (int) iStart - (int) (m_iPageRange*m_override_iPerPage) < 0 ? 0 : iStart - (m_iPageRange*m_override_iPerPage)); i < iStart; i += m_override_iPerPage )\r
1520                                 {\r
1521                                         pResponse->strContent += "<span class=\"pages\"><a href=\"/index.html?page=" + CAtomInt( i / m_override_iPerPage ).toString( );\r
1522 \r
1523                                         if( !strSort.empty( ) )\r
1524                                                 pResponse->strContent += "&sort=" + strSort;\r
1525 \r
1526                                         if( !strSearch.empty( ) )\r
1527                                                 pResponse->strContent += "&search=" + strSearchResp;\r
1528 \r
1529                                         if( !strFilter.empty( ) )\r
1530                                                 pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
1531 \r
1532                                         if( !strPerPage.empty( ) )\r
1533                                                 pResponse->strContent += "&per_page=" + strPerPage;\r
1534 \r
1535                                         pResponse->strContent += "\">";\r
1536                                         \r
1537                                         pResponse->strContent += CAtomInt( ( i / m_override_iPerPage ) + 1 ).toString( );\r
1538 \r
1539                                         pResponse->strContent += "</a></span>&nbsp;";\r
1540                                 }\r
1541                                 \r
1542                                 // Print out the current page, without linkage of any kind...\r
1543                                 pResponse->strContent += "<span class=\"pagecurrent\">";\r
1544                                 pResponse->strContent += CAtomInt( ( iStart / m_override_iPerPage ) + 1 ).toString( );\r
1545                                 pResponse->strContent += "</span>&nbsp;";\r
1546 \r
1547                                 if( iStart != iFound )\r
1548                                 {\r
1549                                         for( unsigned int i = iStart + m_override_iPerPage ; i < (iStart + ( m_override_iPerPage * (m_iPageRange+1) ) > iFound ? iFound : iStart + ( m_override_iPerPage * (m_iPageRange+1) ) ); i += m_override_iPerPage )\r
1550                                         {\r
1551                                                 pResponse->strContent += "<span class=\"pages\"><a href=\"/index.html?page=" + CAtomInt( i / m_override_iPerPage ).toString( );\r
1552         \r
1553                                                 if( !strSort.empty( ) )\r
1554                                                         pResponse->strContent += "&sort=" + strSort;\r
1555         \r
1556                                                 if( !strSearch.empty( ) )\r
1557                                                         pResponse->strContent += "&search=" + strSearchResp;\r
1558         \r
1559                                                 if( !strFilter.empty( ) )\r
1560                                                         pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
1561         \r
1562                                                 if( !strPerPage.empty( ) )\r
1563                                                         pResponse->strContent += "&per_page=" + strPerPage;\r
1564         \r
1565                                                 pResponse->strContent += "\">";\r
1566                                                 \r
1567                                                 pResponse->strContent += CAtomInt( ( i / m_override_iPerPage ) + 1 ).toString( );\r
1568         \r
1569                                                 pResponse->strContent += "</a></span>&nbsp;";\r
1570                                         }\r
1571                                 }\r
1572                                 \r
1573                                 // Adds a next link iff we are not at the beginning\r
1574                                 if( iStart + m_override_iPerPage < iFound )\r
1575                                 {\r
1576                                         pResponse->strContent += "<span class=\"pages\"><a href=\"/index.html?page=" + CAtomInt( (iStart / m_override_iPerPage) + 1 ).toString( );\r
1577                                         \r
1578                                         if( !strSort.empty( ) )\r
1579                                                 pResponse->strContent += "&sort=" + strSort;\r
1580 \r
1581                                         if( !strSearch.empty( ) )\r
1582                                                 pResponse->strContent += "&search=" + strSearchResp;\r
1583 \r
1584                                         if( !strFilter.empty( ) )\r
1585                                                 pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
1586 \r
1587                                         if( !strPerPage.empty( ) )\r
1588                                                 pResponse->strContent += "&per_page=" + strPerPage;\r
1589 \r
1590 \r
1591                                         pResponse->strContent += "\" title=\"Next page\">&gt;</a></span>&nbsp;";\r
1592                                 }\r
1593                                 \r
1594                                 // Add a "go to end" link if the current page is more than pageRange pages away...\r
1595                                 if( iStart + ( m_override_iPerPage * (m_iPageRange+1) ) < iFound ) {\r
1596                                         pResponse->strContent += "<span class=\"pages\"><a href=\"/index.html?page=" + CAtomInt( (iFound / m_override_iPerPage) ).toString( );\r
1597                                         \r
1598                                         if( !strSort.empty( ) )\r
1599                                                 pResponse->strContent += "&sort=" + strSort;\r
1600 \r
1601                                         if( !strSearch.empty( ) )\r
1602                                                 pResponse->strContent += "&search=" + strSearchResp;\r
1603 \r
1604                                         if( !strFilter.empty( ) )\r
1605                                                 pResponse->strContent += "&filter=" + UTIL_StringToEscaped( strFilter );\r
1606 \r
1607                                         if( !strPerPage.empty( ) )\r
1608                                                 pResponse->strContent += "&per_page=" + strPerPage;\r
1609 \r
1610                                         pResponse->strContent += "\" title=\"Go to last page\">&raquo;</a></span>";\r
1611                                 }\r
1612 \r
1613                                 pResponse->strContent += "</p></td>\n";\r
1614                                 pResponse->strContent += "</tr></table>";\r
1615                         }\r
1616                 }\r
1617 \r
1618                 pResponse->strContent += m_strStaticFooter;\r
1619 \r
1620                 // don't even think about removing this :)\r
1621 \r
1622                 pResponse->strContent += "<p align=\"center\">POWERED BY " + string( BNBT_VER ) + "</p>\n";\r
1623         }\r
1624         else\r
1625         {\r
1626                 pResponse->strContent += "<p class=\"denied\">You are not authorized to view this page.";\r
1627 \r
1628                 if( user.iAccess & ACCESS_SIGNUP )\r
1629                         pResponse->strContent += " Click <a href=\"/signup.html\">here</a> to sign up for an account!";\r
1630 \r
1631                 pResponse->strContent += "</p>\n";\r
1632         }\r
1633 \r
1634         if( m_bGen )\r
1635                 pResponse->strContent += "<p class=\"gen\">Generated in " + UTIL_ElapsedTimeStr( btv, UTIL_CurrentTime( ) ) + " seconds.</p>\n";\r
1636 \r
1637         pResponse->strContent += "</body>\n";\r
1638         pResponse->strContent += "</html>\n";\r
1639 }\r