added: now plugin ticket uses a new horizontal table (plugins.ticket)

columns: dir_id, param, value
we are able to build complicated tickets 



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@664 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2010-10-19 00:31:20 +00:00
parent 33057acd62
commit 1b053c03ba
53 changed files with 1680 additions and 1902 deletions

View File

@@ -12,6 +12,8 @@
#include "ticketinfo.h"
#include "core/error.h"
#include "core/log.h"
#include "core/misc.h"
namespace Ticket
@@ -42,21 +44,31 @@ void TicketInfo::SetSystem(System * psystem)
system = psystem;
}
void TicketInfo::SetRequest(Request * prequest)
{
request = prequest;
}
void TicketInfo::Clear()
{
item.Clear();
is_ticket = false;
ticket.Clear();
ticket_tab.clear();
cur_conf_wrap = &cur_conf_wrap_empty;
cur_conf = &cur_conf_empty;
}
void TicketInfo::ReadTicket(long dir_id)
{
if( tdb->GetTicketByDirId(dir_id, ticket) == WINIX_ERR_OK )
if( tdb->GetTicket(dir_id, ticket) == WINIX_ERR_OK )
{
is_ticket = true;
db->GetItemById(ticket.item_id, item);
//db->GetItemById(ticket.item_id, item);
}
}
@@ -200,5 +212,89 @@ void TicketInfo::ReadTicketConf(bool skip_existing_configs)
}
void TicketInfo::FindCurrentConf()
{
if( !system->mounts.pmount )
return;
long dir_id = system->mounts.pmount->dir_id;
ConfTab::iterator i = conf_tab.find(dir_id);
if( i != conf_tab.end() )
{
cur_conf_wrap = &i->second;
cur_conf = &i->second.conf;
}
}
bool TicketInfo::CheckMinMaxValue(const TicketConf::TicketItem & ticket_item, Ticket::TicketParam & par)
{
if( ticket_item.type == TicketConf::TicketItem::TypeInteger )
{
if( par.value < ticket_item.integer_min )
par.value = ticket_item.integer_min;
if( par.value > ticket_item.integer_max )
par.value = ticket_item.integer_max;
}
else
if( ticket_item.type == TicketConf::TicketItem::TypeSelect )
{
for(size_t a=0 ; a<ticket_item.select.size() ; ++a)
{
if( ticket_item.select[a].id == par.value )
return true;
}
log << log1 << "Ticket: incorrect select's value, param: "
<< par.param << ", value: " << par.value << " (ignored)" << logend;
return false;
}
return true;
}
bool TicketInfo::CheckMinMaxValue(Ticket::TicketParam & par)
{
for(size_t i=0 ; i<cur_conf->tab.size() ; ++i)
{
if( par.param == cur_conf->tab[i].id )
return CheckMinMaxValue(cur_conf->tab[i], par);
}
log << log1 << "Ticket: unknown param: " << par.param << " (ignored)" << logend;
return false;
}
void TicketInfo::ReadTicketParams()
{
PostTab::iterator i;
const char parstr[] = "ticketparam"; // !! dodac do konfiga? i szablony tez niech bior<6F> z konfiga
size_t parlen = sizeof(parstr) / sizeof(char) - 1;
Ticket::TicketParam param;
ticket.par_tab.clear();
for(i=request->post_tab.begin() ; i!=request->post_tab.end() ; ++i)
{
if( IsSubString(parstr, i->first.c_str()) )
{
param.param = atoi(i->first.c_str() + parlen);
param.value = atoi(i->second.c_str());
if( CheckMinMaxValue(param) )
ticket.par_tab.push_back(param);
}
}
}
} // namespace