205 lines
4.2 KiB
C++
Executable File
205 lines
4.2 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2008-2012, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include "editticket.h"
|
|
#include "functions/functions.h"
|
|
#include "sessiondata.h"
|
|
|
|
|
|
|
|
namespace Ticket
|
|
{
|
|
|
|
|
|
|
|
EditTicket::EditTicket()
|
|
{
|
|
fun.url = L"editticket";
|
|
}
|
|
|
|
|
|
void EditTicket::SetTDb(TDb * ptdb)
|
|
{
|
|
tdb = ptdb;
|
|
}
|
|
|
|
|
|
void EditTicket::SetTicketInfo(TicketInfo * pinfo)
|
|
{
|
|
ticket_info = pinfo;
|
|
}
|
|
|
|
|
|
|
|
bool EditTicket::HasAccess()
|
|
{
|
|
// not logged users cannot edit tickets
|
|
// !! we are waiting for the sticky bit
|
|
if( !cur->session->puser )
|
|
return false;
|
|
|
|
if( !cur->request->is_item || !system->HasWriteAccess(cur->request->item) )
|
|
return false;
|
|
|
|
if( cur->mount->type != ticket_info->mount_type_ticket )
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditTicket::ChangeTicket(Ticket & ticket, Item & item)
|
|
{
|
|
cur->request->status = tdb->RemoveAddTicket(ticket);
|
|
|
|
if( cur->request->status == WINIX_ERR_OK )
|
|
{
|
|
// sending notification
|
|
|
|
notify_msg.code = WINIX_NOTIFY_CODE_EDIT;
|
|
notify_msg.template_index = ticket_info->template_index;
|
|
notify_msg.dir_link = config->url_proto;
|
|
notify_msg.dir_link += config->base_url;// !! IMPROVE ME what about subdomains?
|
|
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 EditTicket::Submit(Ticket & ticket, Item & item)
|
|
{
|
|
if( functions->CheckAbuse() )
|
|
return;
|
|
|
|
// adding without notificating
|
|
cur->request->status = system->EditFile(item, old_url != item.url);
|
|
|
|
if( cur->request->status == WINIX_ERR_OK )
|
|
ChangeTicket(ticket, item);
|
|
|
|
if( cur->request->status == WINIX_ERR_OK )
|
|
{
|
|
log << log2 << "EditTicket: ticket modified" << logend;
|
|
RemoveTmpTicket();
|
|
system->RedirectTo(item);
|
|
}
|
|
else
|
|
{
|
|
log << log1 << "EditTicket: problem with editing a ticket, error code: "
|
|
<< cur->request->status << logend;
|
|
|
|
// !! add session log
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditTicket::RemoveTmpTicket()
|
|
{
|
|
SessionData * session_data = reinterpret_cast<SessionData*>(
|
|
cur->session->plugin_data.Get(ticket_info->plugin_id) );
|
|
|
|
long file_id = cur->request->item.id;
|
|
session_data->edit_ticket_map.erase(file_id);
|
|
session_data->edit_space_map.erase(file_id);
|
|
}
|
|
|
|
|
|
|
|
Ticket & EditTicket::PrepareTicket()
|
|
{
|
|
SessionData * session_data = reinterpret_cast<SessionData*>(
|
|
cur->session->plugin_data.Get(ticket_info->plugin_id) );
|
|
|
|
bool is_new;
|
|
long file_id = cur->request->item.id;
|
|
Ticket & ticket = session_data->GetTicket(file_id, session_data->edit_ticket_map, &is_new);
|
|
|
|
if( is_new )
|
|
tdb->GetTicket(file_id, ticket);
|
|
else
|
|
ticket.file_id = file_id;
|
|
|
|
return ticket;
|
|
}
|
|
|
|
|
|
|
|
PT::Space & EditTicket::PrepareSpace()
|
|
{
|
|
SessionData * session_data = reinterpret_cast<SessionData*>(
|
|
cur->session->plugin_data.Get(ticket_info->plugin_id) );
|
|
|
|
bool is_new;
|
|
long file_id = cur->request->item.id;
|
|
PT::Space & new_space = session_data->GetNewSpace(file_id, session_data->edit_space_map, &is_new);
|
|
|
|
if( is_new )
|
|
{
|
|
PT::Space * ticket_space = cur->request->item.meta.FindSpace(L"ticket");
|
|
|
|
if( ticket_space )
|
|
{
|
|
new_space = *ticket_space;
|
|
PT::Space & old_space = session_data->GetOldSpace(file_id, session_data->edit_space_map);
|
|
old_space = new_space;
|
|
}
|
|
}
|
|
|
|
return new_space;
|
|
}
|
|
|
|
|
|
void EditTicket::MakePost()
|
|
{
|
|
ticket_info->Clear();
|
|
ticket_info->FindCurrentConf();
|
|
|
|
Ticket & ticket = PrepareTicket();
|
|
PT::Space & meta = PrepareSpace();
|
|
Item & item = cur->request->item;
|
|
old_url = item.url;
|
|
ticket_info->ticket = &ticket;
|
|
ticket_info->item = &item;
|
|
|
|
ticket_info->ReadTicketParams(ticket, false, meta);
|
|
functions->ReadItem(item, Item::file);
|
|
|
|
ticket_info->CopyTicketSpace(meta, item);
|
|
|
|
if( !cur->request->IsPostVar(L"fileuploadsubmit") )
|
|
Submit(ticket, item);
|
|
}
|
|
|
|
|
|
|
|
void EditTicket::MakeGet()
|
|
{
|
|
ticket_info->Clear();
|
|
ticket_info->FindCurrentConf();
|
|
|
|
Ticket & ticket = PrepareTicket();
|
|
PT::Space & meta = PrepareSpace();
|
|
ticket_info->ticket = &ticket;
|
|
ticket_info->item = &cur->request->item;
|
|
|
|
// copy meta info to display correctly new files
|
|
ticket_info->CopyTicketSpace(meta, cur->request->item);
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|