230 lines
4.6 KiB
C++
Executable File
230 lines
4.6 KiB
C++
Executable File
/*
|
|
* This file is a part of CMSLU -- Content Management System like Unix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2008-2009, 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::FunCreateTicketCheckAccess()
|
|
{
|
|
if( !request.CanCreateTicket() )
|
|
{
|
|
request.status = Error::permission_denied;
|
|
return false;
|
|
}
|
|
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
bool Content::FunCreateTicketCheckAbuse(const Done & done)
|
|
{
|
|
if( !CheckRebus() )
|
|
{
|
|
request.status = Error::incorrect_rebus;
|
|
request.session->done = done;
|
|
request.session->done_status = Error::incorrect_rebus;
|
|
|
|
return false;
|
|
}
|
|
|
|
CheckGetPostTimes();
|
|
|
|
if( request.session->spam_score > 0 )
|
|
{
|
|
request.status = Error::spam;
|
|
request.session->done = done;
|
|
request.session->done_status = Error::spam;
|
|
|
|
log << log1 << "Content: ignoring due to suspected spamming" << logend;
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
void Content::ReadTicketType(Ticket & ticket)
|
|
{
|
|
static std::string temp;
|
|
|
|
request.PostVar("type", temp);
|
|
ticket.type = atoi(temp.c_str());
|
|
|
|
if( ticket.type >= data.mounts.pmount->param[Mount::par_ticket_type].arg.size() )
|
|
ticket.type = data.mounts.pmount->param[Mount::par_ticket_type].arg.size();
|
|
}
|
|
|
|
|
|
|
|
void Content::ReadTicketStatus(Ticket & ticket)
|
|
{
|
|
static std::string temp;
|
|
|
|
request.PostVar("status", temp);
|
|
ticket.status = atoi(temp.c_str());
|
|
|
|
if( ticket.status >= data.mounts.pmount->param[Mount::par_ticket_status].arg.size() )
|
|
ticket.status = data.mounts.pmount->param[Mount::par_ticket_status].arg.size();
|
|
}
|
|
|
|
|
|
|
|
void Content::ReadTicketPriority(Ticket & ticket)
|
|
{
|
|
static std::string temp;
|
|
|
|
request.PostVar("priority", temp);
|
|
ticket.priority = atoi(temp.c_str());
|
|
|
|
if( ticket.priority >= data.mounts.pmount->param[Mount::par_ticket_priority].arg.size() )
|
|
ticket.priority = data.mounts.pmount->param[Mount::par_ticket_priority].arg.size();
|
|
}
|
|
|
|
|
|
|
|
void Content::ReadTicketCategory(Ticket & ticket)
|
|
{
|
|
static std::string temp;
|
|
|
|
request.PostVar("category", temp);
|
|
ticket.category = atoi(temp.c_str());
|
|
|
|
if( ticket.category >= data.mounts.pmount->param[Mount::par_ticket_category].arg.size() )
|
|
ticket.category = data.mounts.pmount->param[Mount::par_ticket_category].arg.size();
|
|
}
|
|
|
|
|
|
void Content::ReadTicketExpected(Ticket & ticket)
|
|
{
|
|
static std::string temp;
|
|
|
|
request.PostVar("expected", temp);
|
|
ticket.expected = atoi(temp.c_str());
|
|
|
|
if( ticket.expected >= data.mounts.pmount->param[Mount::par_ticket_expected].arg.size() )
|
|
ticket.expected = data.mounts.pmount->param[Mount::par_ticket_expected].arg.size();
|
|
}
|
|
|
|
|
|
void Content::ReadTicketProgress(Ticket & ticket)
|
|
{
|
|
static std::string temp;
|
|
|
|
request.PostVar("progress", temp);
|
|
int p = atoi(temp.c_str());
|
|
|
|
if( p < 0 )
|
|
p = 0;
|
|
|
|
if( p > 100 )
|
|
p = 100;
|
|
|
|
ticket.progress = p;
|
|
}
|
|
|
|
|
|
|
|
void Content::ReadTicket(Ticket & ticket)
|
|
{
|
|
ticket.parent_id = request.dir_table.back()->id;
|
|
|
|
ReadTicketType(ticket);
|
|
ReadTicketStatus(ticket);
|
|
ReadTicketPriority(ticket);
|
|
ReadTicketCategory(ticket);
|
|
ReadTicketExpected(ticket);
|
|
ReadTicketProgress(ticket);
|
|
}
|
|
|
|
|
|
|
|
void Content::AddTicket()
|
|
{
|
|
static std::string temp;
|
|
|
|
request.ticket.dir_id = request.dir_table.back()->id; // a new directory created by Mkdir()
|
|
request.ticket.item_id = request.item.id; // this id is set by PostFunEmacsAdd()
|
|
|
|
request.session->done_status = db.AddTicket(request.ticket);
|
|
}
|
|
|
|
|
|
void Content::PostFunCreateTicketLogAndRedirect()
|
|
{
|
|
if( request.session->done_status == Error::ok )
|
|
{
|
|
request.session->done = Done::added_ticket;
|
|
|
|
log << log2 << "Content: added a new ticket" << logend;
|
|
RedirectToLastDir();
|
|
}
|
|
else
|
|
{
|
|
log << log1 << "Content: problem with adding a new ticket, error code:"
|
|
<< request.session->done_status << logend;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Content::PostFunCreateTicket()
|
|
{
|
|
if( !FunCreateTicketCheckAccess() )
|
|
return;
|
|
|
|
ReadItem(request.item, Item::dir);
|
|
ReadTicket(request.ticket);
|
|
request.item.privileges = 0777; // !! tymczasowo 777 aby wszyscy mogli wysylac posty
|
|
|
|
if( !FunCreateTicketCheckAbuse(Done::added_ticket) )
|
|
{
|
|
ReadItemContentWithType(request.item); // for correctly displaying the form
|
|
return;
|
|
}
|
|
|
|
Mkdir(request.item, true);
|
|
|
|
if( request.session->done_status == Error::ok )
|
|
{
|
|
ReadItemContentWithType(request.item);
|
|
request.item.type = Item::file;
|
|
request.item.privileges = 0644; // !! tymczasowo
|
|
request.item.parent_id = request.dir_table.back()->id;
|
|
PostFunEmacsAdd();
|
|
|
|
if( request.session->done_status == Error::ok )
|
|
AddTicket();
|
|
}
|
|
|
|
PostFunCreateTicketLogAndRedirect();
|
|
}
|
|
|
|
|
|
|
|
|
|
void Content::FunCreateTicket()
|
|
{
|
|
FunCreateTicketCheckAccess();
|
|
}
|
|
|
|
|
|
|
|
|