148 lines
2.8 KiB
C++
Executable File
148 lines
2.8 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 "createticket.h"
|
|
#include "functions/functions.h"
|
|
|
|
|
|
namespace Ticket
|
|
{
|
|
|
|
|
|
CreateTicket::CreateTicket()
|
|
{
|
|
fun.url = "createticket";
|
|
}
|
|
|
|
|
|
void CreateTicket::SetTDb(TDb * ptdb)
|
|
{
|
|
tdb = ptdb;
|
|
}
|
|
|
|
|
|
void CreateTicket::SetTicketInfo(TicketInfo * pinfo)
|
|
{
|
|
ticket_info = pinfo;
|
|
}
|
|
|
|
|
|
|
|
|
|
void CreateTicket::Clear()
|
|
{
|
|
ticket_info->Clear();
|
|
}
|
|
|
|
|
|
// returning true if we can create a ticket in the current directory
|
|
bool CreateTicket::HasAccess(bool check_root)
|
|
{
|
|
if( request->dir_tab.empty() )
|
|
return false;
|
|
|
|
if( request->is_item )
|
|
return false;
|
|
|
|
if( !system->HasWriteAccess(*request->dir_tab.back()) )
|
|
return false;
|
|
|
|
if( !system->mounts.pmount || system->mounts.pmount->type != ticket_info->mount_type_ticket )
|
|
return false;
|
|
|
|
|
|
// checking for par_createticket_on mount option
|
|
|
|
if( !check_root && request->session && request->session->puser && request->session->puser->super_user )
|
|
// super can create tickets regardless of the createticket_on option
|
|
return true;
|
|
|
|
if( !system->mounts.pmount->IsPar(ticket_info->mount_par_createticket_on) )
|
|
return true;
|
|
|
|
if( system->mounts.pmount->IsArg(ticket_info->mount_par_createticket_on, request->dir_tab.size()) )
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
bool CreateTicket::HasAccess()
|
|
{
|
|
return HasAccess(false);
|
|
}
|
|
|
|
|
|
|
|
void CreateTicket::AddTicket()
|
|
{
|
|
// a new directory created by system->AddDir()
|
|
ticket_info->ticket.dir_id = request->dir_tab.back()->id;
|
|
request->status = tdb->AddTicket(ticket_info->ticket);
|
|
}
|
|
|
|
|
|
void CreateTicket::LogAndRedirect()
|
|
{
|
|
if( request->status == WINIX_ERR_OK )
|
|
{
|
|
log << log2 << "CreateTicket: added a new ticket" << logend;
|
|
system->RedirectToLastDir();
|
|
}
|
|
else
|
|
{
|
|
log << log1 << "CreateTicket: problem with adding a new ticket, error code: "
|
|
<< request->status << logend;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void CreateTicket::MakePost()
|
|
{
|
|
ticket_info->FindCurrentConf();
|
|
functions->ReadItem(ticket_info->item, Item::file);
|
|
functions->SetUser(ticket_info->item);
|
|
ticket_info->item.privileges = request->dir_tab.back()->privileges; // !! tymczasowo takie same jak z katalogu nadrzednego
|
|
|
|
ticket_info->ReadTicketParams();
|
|
|
|
if( functions->CheckAbuse() )
|
|
return;
|
|
|
|
ticket_info->item.type = Item::dir;
|
|
request->status = system->dirs.AddDirectory(ticket_info->item, true);
|
|
|
|
if( request->status == WINIX_ERR_OK )
|
|
{
|
|
ticket_info->item.type = Item::file;
|
|
ticket_info->item.privileges = 0644; // !! tymczasowo
|
|
ticket_info->item.parent_id = request->dir_tab.back()->id;
|
|
|
|
// adding without notificating
|
|
request->status = system->AddFile(ticket_info->item, false);
|
|
|
|
if( request->status == WINIX_ERR_OK )
|
|
AddTicket();
|
|
}
|
|
|
|
LogAndRedirect();
|
|
}
|
|
|
|
|
|
void CreateTicket::MakeGet()
|
|
{
|
|
ticket_info->FindCurrentConf();
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|