211 lines
3.7 KiB
C++
Executable File
211 lines
3.7 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 "editticket.h"
|
|
#include "functions/functions.h"
|
|
|
|
|
|
|
|
|
|
namespace Ticket
|
|
{
|
|
|
|
EditTicket::EditTicket()
|
|
{
|
|
fun.url = "editticket";
|
|
}
|
|
|
|
|
|
void EditTicket::SetTDb(TDb * ptdb)
|
|
{
|
|
tdb = ptdb;
|
|
}
|
|
|
|
|
|
void EditTicket::SetTicketInfo(TicketInfo * pinfo)
|
|
{
|
|
ticket_info = pinfo;
|
|
}
|
|
|
|
|
|
void EditTicket::Clear()
|
|
{
|
|
ticket_info->Clear();
|
|
}
|
|
|
|
|
|
bool EditTicket::HasAccess()
|
|
{
|
|
// not logged users cannot edit tickets
|
|
if( !request->session->puser )
|
|
return false;
|
|
|
|
if( request->dir_tab.empty() )
|
|
return false;
|
|
|
|
ticket_info->ReadTicket(request->dir_tab.back()->id);
|
|
|
|
if( request->is_item || !ticket_info->is_ticket )
|
|
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;
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EditTicket::GetFirstItem(Item & item)
|
|
{
|
|
if( request->status != WINIX_ERR_OK )
|
|
return;
|
|
|
|
DbItemQuery iq;
|
|
iq.Limit(1);
|
|
iq.WhereParentId(request->dir_tab.back()->id);
|
|
db->GetItems(item_tab, iq); // !! chwilowo GetItems() nie zwraca zadnych kodow bledow
|
|
|
|
if( request->status != WINIX_ERR_OK )
|
|
return;
|
|
|
|
if( item_tab.empty() )
|
|
{
|
|
// creating a new item (the item was deleted by a user)
|
|
|
|
item.parent_id = request->dir_tab.back()->id;
|
|
item.subject = request->dir_tab.back()->subject;
|
|
item.type = Item::file;
|
|
item.privileges = 0644; // !! tymczasowo
|
|
functions->SetUser(item);
|
|
functions->PrepareUrl(item);
|
|
|
|
request->status = system->AddFile(item);
|
|
|
|
if( request->status == WINIX_ERR_OK )
|
|
log << log2 << "EditTicket: added the first item with content for the ticket, item.id: "
|
|
<< item.id << logend;
|
|
}
|
|
else
|
|
{
|
|
item = item_tab[0];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void EditTicket::ModifyTicket()
|
|
{
|
|
if( request->status != WINIX_ERR_OK )
|
|
return;
|
|
|
|
ticket_info->ReadTicketParams();
|
|
request->status = tdb->RemoveAddTicket(ticket_info->ticket);
|
|
}
|
|
|
|
|
|
|
|
void EditTicket::ModifyLastDir()
|
|
{
|
|
if( request->status != WINIX_ERR_OK )
|
|
return;
|
|
|
|
// we don't modify the url
|
|
Item & dir = *request->dir_tab.back();
|
|
|
|
if( dir.subject != ticket_info->item.subject )
|
|
{
|
|
dir.subject = ticket_info->item.subject;
|
|
request->status = db->EditItemById(dir, false);
|
|
}
|
|
}
|
|
|
|
|
|
void EditTicket::ModifyFirstItem()
|
|
{
|
|
if( request->status != WINIX_ERR_OK )
|
|
return;
|
|
|
|
// we don't modify the url and don't use notifications
|
|
system->EditFile(ticket_info->item, false, false);
|
|
}
|
|
|
|
|
|
|
|
void EditTicket::LogAndRedirect()
|
|
{
|
|
if( request->status == WINIX_ERR_OK )
|
|
{
|
|
log << log2 << "EditTicket: edited a ticket" << logend;
|
|
system->RedirectToLastDir();
|
|
}
|
|
else
|
|
{
|
|
log << log1 << "EditTicket: problem with editing a ticket, error code: "
|
|
<< request->status << logend;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void EditTicket::MakePost()
|
|
{
|
|
ticket_info->FindCurrentConf();
|
|
|
|
// reading the first item from the db or creating it if not exists
|
|
GetFirstItem(ticket_info->item);
|
|
|
|
// reading information from POST
|
|
functions->ReadItem(ticket_info->item, Item::file);
|
|
|
|
if( functions->CheckAbuse() )
|
|
return;
|
|
|
|
if( tdb->GetTicket(request->dir_tab.back()->id, ticket_info->ticket) != WINIX_ERR_OK )
|
|
{
|
|
request->status = WINIX_ERR_PERMISSION_DENIED;
|
|
return;
|
|
}
|
|
|
|
ModifyTicket();
|
|
ModifyLastDir();
|
|
ModifyFirstItem();
|
|
LogAndRedirect();
|
|
}
|
|
|
|
|
|
|
|
void EditTicket::MakeGet()
|
|
{
|
|
ticket_info->FindCurrentConf();
|
|
|
|
DbItemQuery iq;
|
|
iq.Limit(1);
|
|
iq.WhereParentId(request->dir_tab.back()->id);
|
|
db->GetItems(item_tab, iq); // !! chwilowo GetItems() nie zwraca kodow bledow
|
|
|
|
if( request->status != WINIX_ERR_OK )
|
|
{
|
|
request->status = WINIX_ERR_PERMISSION_DENIED;
|
|
return;
|
|
}
|
|
|
|
if( !item_tab.empty() )
|
|
ticket_info->item = item_tab[0];
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|