175 lines
3.3 KiB
C++
Executable File
175 lines
3.3 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 "content.h"
|
|
#include "../core/request.h"
|
|
#include "../core/error.h"
|
|
#include "../core/db.h"
|
|
#include "../core/mount.h"
|
|
#include "../core/data.h"
|
|
|
|
|
|
|
|
bool Content::FunEditTicketCheckAccess()
|
|
{
|
|
if( !request.CanEditTicket() )
|
|
{
|
|
request.status = WINIX_ERR_PERMISSION_DENIED;
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
void Content::EditTicketCheckFirstItem()
|
|
{
|
|
if( request.status != WINIX_ERR_OK )
|
|
return;
|
|
|
|
|
|
if( request.ticket.item_id == -1 )
|
|
{
|
|
// creating a new item (the item was deleted by a user)
|
|
|
|
Item item;
|
|
item.parent_id = request.dir_table.back()->id;
|
|
item.subject = request.dir_table.back()->subject;
|
|
item.type = Item::file;
|
|
item.privileges = 0644; // !! tymczasowo
|
|
SetUser(item);
|
|
PrepareUrl(item);
|
|
|
|
request.status = db.AddItem(item);
|
|
|
|
if( request.status == WINIX_ERR_OK )
|
|
{
|
|
log << log2 << "Content: added the first item with content for the ticket, item.id: " << item.id << logend;
|
|
request.ticket.item_id = item.id;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Content::EditTicketModTicket()
|
|
{
|
|
if( request.status != WINIX_ERR_OK )
|
|
return;
|
|
|
|
Ticket ticket;
|
|
ReadTicket(ticket);
|
|
|
|
request.ticket.type = ticket.type;
|
|
request.ticket.status = ticket.status;
|
|
request.ticket.priority = ticket.priority;
|
|
request.ticket.category = ticket.category;
|
|
request.ticket.expected = ticket.expected;
|
|
request.ticket.progress = ticket.progress;
|
|
|
|
request.status = db.EditTicketById(request.ticket);
|
|
}
|
|
|
|
|
|
|
|
void Content::EditTicketModDir()
|
|
{
|
|
if( request.status != WINIX_ERR_OK )
|
|
return;
|
|
|
|
// we don't modify the url
|
|
|
|
Item & dir = *request.dir_table.back();
|
|
bool edit_dir_subject = (dir.subject != request.item.subject);
|
|
|
|
if( edit_dir_subject )
|
|
{
|
|
dir.subject = request.item.subject;
|
|
request.status = db.EditItemById(dir, false);
|
|
}
|
|
}
|
|
|
|
|
|
void Content::EditTicketModFirstItem()
|
|
{
|
|
if( request.status != WINIX_ERR_OK )
|
|
return;
|
|
|
|
// modyfing the first item (the one with content)
|
|
ReadItemContentWithType(request.item);
|
|
|
|
Item item;
|
|
db.GetItemById(request.ticket.item_id, item);
|
|
item.subject = request.item.subject;
|
|
item.content = request.item.content;
|
|
item.content_type = request.item.content_type;
|
|
// the url doesn't matter
|
|
|
|
db.EditItemById(item, false);
|
|
}
|
|
|
|
|
|
|
|
void Content::PostFunEditTicketLogAndRedirect()
|
|
{
|
|
if( request.status == WINIX_ERR_OK )
|
|
{
|
|
log << log2 << "Content: edited a ticket" << logend;
|
|
RedirectToLastDir();
|
|
}
|
|
else
|
|
{
|
|
log << log1 << "Content: problem with editing a ticket, error code: "
|
|
<< request.status << logend;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Content::PostFunEditTicket()
|
|
{
|
|
if( !FunEditTicketCheckAccess() )
|
|
return;
|
|
|
|
|
|
ReadItem(request.item, Item::dir);
|
|
|
|
if( !FunCreateTicketCheckAbuse() )
|
|
{
|
|
ReadItemContentWithType(request.item); // for correctly displaying the form
|
|
return;
|
|
}
|
|
|
|
if( db.GetTicketByDirId(request.dir_table.back()->id, request.ticket) != WINIX_ERR_OK )
|
|
{
|
|
request.status = WINIX_ERR_PERMISSION_DENIED;
|
|
return;
|
|
}
|
|
|
|
EditTicketCheckFirstItem();
|
|
EditTicketModTicket();
|
|
EditTicketModDir();
|
|
EditTicketModFirstItem();
|
|
PostFunEditTicketLogAndRedirect();
|
|
}
|
|
|
|
|
|
|
|
void Content::FunEditTicket()
|
|
{
|
|
FunEditTicketCheckAccess();
|
|
|
|
db.GetItemById(request.ticket.item_id, request.item);
|
|
|
|
// the subject we get from the last directory
|
|
request.item.subject = request.dir_table.back()->subject;
|
|
}
|
|
|