2011-01-05 22:24:11 +01:00
|
|
|
/*
|
|
|
|
* This file is a part of Winix
|
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010, Tomasz Sowa
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
2011-01-20 19:37:51 +01:00
|
|
|
|
|
|
|
#include <algorithm>
|
2011-01-05 22:24:11 +01:00
|
|
|
#include "showthreads.h"
|
|
|
|
#include "functions.h"
|
|
|
|
|
|
|
|
|
2011-01-20 19:37:51 +01:00
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
namespace Thread
|
|
|
|
{
|
|
|
|
|
2011-01-20 19:37:51 +01:00
|
|
|
ShowThreads::ShowThreads()
|
|
|
|
{
|
|
|
|
fun.url = L"showthreads";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ShowThreads::SetTDb(TDb * ptdb)
|
|
|
|
{
|
|
|
|
tdb = ptdb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ShowThreads::SetThreadInfo(ThreadInfo * pthread_info)
|
|
|
|
{
|
|
|
|
thread_info = pthread_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ShowThreads::HasAccess()
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->is_item )
|
2011-01-20 19:37:51 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if( system->mounts.pmount->type != thread_info->mount_type_thread )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ShowThreads::Sort::operator()(const Item * item1, const Item * item2)
|
|
|
|
{
|
|
|
|
if( sort_type == 0 )
|
|
|
|
{
|
|
|
|
// sorting by url
|
|
|
|
return item1->url < item2->url;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// sorting by date
|
|
|
|
tm tm1 = item1->date_creation;
|
|
|
|
tm tm2 = item2->date_creation;
|
|
|
|
|
|
|
|
time_t time1 = Time(tm1);
|
|
|
|
time_t time2 = Time(tm2);
|
|
|
|
|
|
|
|
return time1 > time2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ShowThreads::ReadFiles()
|
|
|
|
{
|
|
|
|
// reading files
|
|
|
|
DbItemQuery iq;
|
|
|
|
iq.SetAll(false, false);
|
|
|
|
iq.sel_url = true;
|
|
|
|
iq.sel_subject = true;
|
|
|
|
iq.sel_date = true;
|
|
|
|
iq.sel_user_id = true;
|
|
|
|
iq.sel_group_id = true;
|
|
|
|
iq.sel_guest_name = true;
|
|
|
|
iq.sel_privileges = true;
|
|
|
|
iq.sel_date = true;
|
2011-01-23 15:15:30 +01:00
|
|
|
iq.WhereParentId(cur->request->dir_tab.back()->id);
|
2011-01-20 19:37:51 +01:00
|
|
|
iq.WhereType(Item::file);
|
|
|
|
iq.WhereFileType(WINIX_ITEM_FILETYPE_NONE);
|
|
|
|
|
|
|
|
db->GetItems(thread_info->item_tab, iq);
|
|
|
|
system->CheckAccessToItems(thread_info->item_tab);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ShowThreads::ReadThreads()
|
|
|
|
{
|
|
|
|
// reading threads for the files
|
|
|
|
file_id_tab.resize(thread_info->item_sort_tab.size());
|
|
|
|
|
|
|
|
for(size_t i=0 ; i<thread_info->item_sort_tab.size() ; ++i)
|
|
|
|
file_id_tab[i] = thread_info->item_sort_tab[i]->id;
|
|
|
|
|
|
|
|
tdb->GetThreads(file_id_tab, thread_info->thread_tab);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ShowThreads::CreatePointers()
|
|
|
|
{
|
|
|
|
// creating a pointers table
|
|
|
|
thread_info->item_sort_tab.resize(thread_info->item_tab.size());
|
|
|
|
|
|
|
|
for(size_t i=0 ; i<thread_info->item_tab.size() ; ++i)
|
|
|
|
thread_info->item_sort_tab[i] = &thread_info->item_tab[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ShowThreads::SortPointers()
|
|
|
|
{
|
|
|
|
int sort_type = 1;
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->ParamValue(L"sort") == L"url" )
|
2011-01-20 19:37:51 +01:00
|
|
|
sort_type = 0;
|
|
|
|
|
|
|
|
std::vector<Item*> & table = thread_info->item_sort_tab;
|
|
|
|
std::sort(table.begin(), table.end(), Sort(this, sort_type));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ShowThreads::MakeGet()
|
|
|
|
{
|
|
|
|
thread_info->Clear();
|
2011-01-05 22:24:11 +01:00
|
|
|
|
2011-01-20 19:37:51 +01:00
|
|
|
ReadFiles();
|
|
|
|
CreatePointers();
|
|
|
|
SortPointers();
|
|
|
|
ReadThreads();
|
|
|
|
}
|
2011-01-05 22:24:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|