winix/plugins/thread/createthread.cpp

110 lines
2.1 KiB
C++
Executable File

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "createthread.h"
#include "functions.h"
#include "functions/functions.h"
namespace Thread
{
CreateThread::CreateThread()
{
fun.url = L"createthread";
}
void CreateThread::SetTDb(TDb * ptdb)
{
tdb = ptdb;
}
void CreateThread::SetThreadInfo(ThreadInfo * pthread_info)
{
thread_info = pthread_info;
}
// returning true if we can create a thread in the current directory
bool CreateThread::HasAccess()
{
if( cur->request->is_item || !system->HasWriteAccess(*cur->request->dir_tab.back()) )
return false;
if( system->mounts.pmount->type != thread_info->mount_type_thread )
return false;
return true;
}
void CreateThread::SendNotify(const Item & item)
{
// sending notification
notify_msg.code = WINIX_NOTIFY_CODE_ADD;
notify_msg.template_index = thread_info->template_index;
notify_msg.dir_link = config->url_proto;
notify_msg.dir_link += config->base_url;
system->dirs.MakePath(item.parent_id, notify_msg.dir_link, false);
notify_msg.item_link = notify_msg.dir_link;
notify_msg.item_link += item.url;
system->notify.ItemChanged(notify_msg);
}
void CreateThread::MakePost()
{
cur->request->item.Clear();
functions->ReadItem(cur->request->item, Item::file);
functions->SetUser(cur->request->item);
functions->PrepareUrl(cur->request->item);
cur->request->item.parent_id = cur->request->dir_tab.back()->id;
cur->request->item.privileges = 0644; // !! tymczasowo
if( functions->CheckAbuse() )
return;
cur->request->status = system->AddFile(cur->request->item);
if( cur->request->status == WINIX_ERR_OK )
{
thread.Clear();
thread.file_id = cur->request->item.id;
cur->request->status = tdb->AddThread(thread);
}
if( cur->request->status == WINIX_ERR_OK )
{
log << log2 << "CreateThread: added a new thread" << logend;
system->RedirectTo(cur->request->item);
SendNotify(cur->request->item);
}
else
{
log << log1 << "CreateThread: problem with adding a new thread, error code: "
<< cur->request->status << logend;
}
}
} // namespace