2007-02-01 15:56:06 +00:00
|
|
|
#include <applicat.h>
|
1998-12-10 16:25:48 +00:00
|
|
|
#include <expr.h>
|
|
|
|
#include <golem.h>
|
2007-12-06 16:01:03 +00:00
|
|
|
#include <netsock.h>
|
1998-12-10 16:25:48 +00:00
|
|
|
#include <recarray.h>
|
2007-02-01 15:56:06 +00:00
|
|
|
#include <relation.h>
|
|
|
|
#include <scanner.h>
|
2006-05-12 16:14:42 +00:00
|
|
|
#include <utility.h>
|
2007-12-06 16:01:03 +00:00
|
|
|
#include <xml.h>
|
1998-12-10 16:25:48 +00:00
|
|
|
|
2011-06-09 11:03:05 +00:00
|
|
|
#include <user.h>
|
|
|
|
|
1998-12-10 16:25:48 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TRecipient
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TRecipient : public TObject
|
|
|
|
{
|
|
|
|
TString _address;
|
|
|
|
TString _group;
|
|
|
|
TString _expr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
const TString& address() const { return _address; }
|
|
|
|
const TString& group() const { return _group; }
|
|
|
|
void add_expr(char op, const TString& expr);
|
|
|
|
bool can_receive(const TRectype& rec) const;
|
|
|
|
|
|
|
|
virtual bool ok() const
|
|
|
|
{ return _address.not_empty() && _expr.not_empty(); }
|
|
|
|
|
|
|
|
TRecipient(const TToken_string& str);
|
|
|
|
virtual ~TRecipient() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
TRecipient::TRecipient(const TToken_string& str)
|
|
|
|
{
|
|
|
|
str.get(0, _address);
|
|
|
|
str.get(1, _group);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TRecipient::add_expr(char op, const TString& expr)
|
|
|
|
{
|
|
|
|
if (_expr.not_empty())
|
2001-04-30 15:04:10 +00:00
|
|
|
_expr << (op == 'A' ? "&&" : "||");
|
1998-12-10 16:25:48 +00:00
|
|
|
|
|
|
|
if (expr.blank())
|
|
|
|
_expr << 1;
|
|
|
|
else
|
|
|
|
_expr << '(' << expr << ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TRecipient::can_receive(const TRectype& rec) const
|
|
|
|
{
|
|
|
|
TExpression e(_expr, _strexpr, TRUE);
|
2008-03-21 16:39:47 +00:00
|
|
|
TString val;
|
|
|
|
|
1998-12-10 16:25:48 +00:00
|
|
|
for (int v = 0; v < e.numvar(); v++)
|
|
|
|
{
|
2008-03-21 16:39:47 +00:00
|
|
|
const TFixed_string name(e.varname(v));
|
|
|
|
|
|
|
|
val.cut(0);
|
1998-12-10 16:25:48 +00:00
|
|
|
if (rec.exist(name))
|
2008-03-21 16:39:47 +00:00
|
|
|
val = rec.get(name);
|
1998-12-10 16:25:48 +00:00
|
|
|
else
|
2008-03-21 16:39:47 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
const TFieldref f(name, 0);
|
|
|
|
const int logicnum = table2logic(f.id());
|
|
|
|
|
|
|
|
if (logicnum > 0 && logicnum != rec.num())
|
|
|
|
{
|
|
|
|
TToken_string & rel = prefix().get_relation(rec.num(), logicnum);
|
|
|
|
if (rel.full())
|
|
|
|
{
|
|
|
|
TToken_string key;
|
|
|
|
FOR_EACH_TOKEN(rel, tok)
|
|
|
|
key.add(rec.get(tok));
|
|
|
|
const TRectype & joined_rec = cache().get(logicnum, key);
|
|
|
|
val = f.read(joined_rec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
val = f.read(rec);
|
|
|
|
}
|
|
|
|
e.setvar(name, val);
|
1998-12-10 16:25:48 +00:00
|
|
|
}
|
|
|
|
bool yes = e.as_bool();
|
|
|
|
return yes;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TPostman
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TPostman : public TObject
|
|
|
|
{
|
|
|
|
long _firm;
|
2013-12-13 09:33:44 +00:00
|
|
|
int _recipients_lognum;
|
1998-12-10 16:25:48 +00:00
|
|
|
TArray _recipient;
|
|
|
|
TAssoc_array _expr;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void test_firm();
|
|
|
|
|
|
|
|
TRecipient& recipient(int r) const
|
|
|
|
{ return (TRecipient&)_recipient[r]; }
|
|
|
|
|
|
|
|
void add_expr(const TString& addr,
|
|
|
|
char op, const TString& expr);
|
|
|
|
|
|
|
|
void load_filters();
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool can_dispatch_transaction(const TRectype& rec);
|
|
|
|
bool dispatch_transaction(const TRectype& rec,
|
|
|
|
const TFilename& name);
|
|
|
|
|
|
|
|
TExpression* get_filter_expr(const char* flt);
|
|
|
|
const char* get_filter(const char* flt);
|
|
|
|
bool user_can(const char* flt, const TRelation* rel);
|
|
|
|
|
|
|
|
TPostman();
|
|
|
|
virtual ~TPostman() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
void TPostman::test_firm()
|
|
|
|
{
|
|
|
|
const long firm = prefix().get_codditta();
|
|
|
|
if (firm != _firm)
|
|
|
|
{
|
|
|
|
_firm = firm;
|
2013-12-13 09:33:44 +00:00
|
|
|
_recipients_lognum = 0;
|
|
|
|
_recipient.destroy();
|
1998-12-10 16:25:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPostman::add_expr(const TString& addr,
|
|
|
|
char op, const TString& expr)
|
|
|
|
{
|
|
|
|
for (int r = _recipient.last(); r >= 0; r--)
|
|
|
|
{
|
|
|
|
TRecipient& rec = recipient(r);
|
|
|
|
if (rec.address() == addr)
|
|
|
|
{
|
|
|
|
rec.add_expr(op, expr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (rec.group() == addr)
|
|
|
|
rec.add_expr(op, expr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TPostman::can_dispatch_transaction(const TRectype& rec)
|
|
|
|
{
|
|
|
|
test_firm();
|
2013-12-13 09:33:44 +00:00
|
|
|
const int lognum = rec.num();
|
|
|
|
if (_recipients_lognum != lognum)
|
1998-12-10 16:25:48 +00:00
|
|
|
{
|
2013-12-13 09:33:44 +00:00
|
|
|
_recipients_lognum = lognum;
|
1998-12-10 16:25:48 +00:00
|
|
|
_recipient.destroy();
|
|
|
|
|
|
|
|
TConfig cfg(CONFIG_DITTA, "MailTransactions");
|
2001-04-30 15:04:10 +00:00
|
|
|
TAuto_token_string str;
|
1998-12-10 16:25:48 +00:00
|
|
|
TString addr, opr, expr;
|
|
|
|
|
|
|
|
// Costruisce la lista dei destinatari
|
|
|
|
for (int r = 0; cfg.exist("Recipient", r); r++)
|
|
|
|
{
|
|
|
|
str = cfg.get("Recipient", NULL, r);
|
2008-06-19 15:36:49 +00:00
|
|
|
expand_sys_vars(str);
|
1998-12-10 16:25:48 +00:00
|
|
|
TRecipient* rcp = new TRecipient(str);
|
|
|
|
_recipient.add(rcp);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Costruisce i filtri per i destinatari
|
|
|
|
for (int f = 0; cfg.exist("Filter", f); f++)
|
|
|
|
{
|
|
|
|
str = cfg.get("Filter", NULL, f);
|
2008-06-19 15:36:49 +00:00
|
|
|
expand_sys_vars(str);
|
|
|
|
|
1998-12-10 16:25:48 +00:00
|
|
|
const int num = str.get_int(1);
|
2013-12-13 09:33:44 +00:00
|
|
|
if (num != lognum) continue;
|
1998-12-10 16:25:48 +00:00
|
|
|
|
|
|
|
str.get(0, addr);
|
|
|
|
str.get(2, opr);
|
|
|
|
str.get(3, expr);
|
|
|
|
add_expr(addr, opr[0], expr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Elimina destinatari inutili
|
|
|
|
for (int d = _recipient.last(); d >= 0; d--)
|
|
|
|
{
|
|
|
|
if (!recipient(d).ok())
|
|
|
|
_recipient.destroy(d, TRUE);
|
|
|
|
}
|
|
|
|
}
|
2013-12-13 09:33:44 +00:00
|
|
|
return !_recipient.empty();
|
1998-12-10 16:25:48 +00:00
|
|
|
}
|
|
|
|
|
2007-12-06 16:01:03 +00:00
|
|
|
static int write_xml(TConfig& cfg, void* jolly)
|
|
|
|
{
|
|
|
|
TAssoc_array &vars = cfg.list_variables();
|
|
|
|
TXmlItem &item = *(TXmlItem *) jolly;
|
|
|
|
TToken_string tag(cfg.get_paragraph(), ',');
|
|
|
|
const int logicnum = tag.get_int();
|
|
|
|
const char * attr = logicnum > 0 ? "Field" : "Attr";
|
|
|
|
int rownum = tag.get_int();
|
|
|
|
|
|
|
|
if (logicnum > 0)
|
|
|
|
tag = "Record";
|
|
|
|
TXmlItem & child =item.AddChild(tag);
|
|
|
|
if (logicnum > 0)
|
|
|
|
{
|
|
|
|
child.SetAttr("LogicNumber", logicnum);
|
2008-04-24 07:35:22 +00:00
|
|
|
if (logicnum > LF_TAB)
|
|
|
|
child.SetAttr("TableName", logic2table(logicnum));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TString table;
|
|
|
|
|
|
|
|
FOR_EACH_ASSOC_STRING(vars, hobj, key, val)
|
|
|
|
if (logicnum <= LF_TAB && strcmp(key, "COD") == 0)
|
|
|
|
{
|
|
|
|
table = val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
child.SetAttr("TableName", table);
|
|
|
|
}
|
2007-12-06 16:01:03 +00:00
|
|
|
|
|
|
|
if (rownum > 0)
|
|
|
|
child.SetAttr("RowNumber", rownum);
|
|
|
|
}
|
|
|
|
|
|
|
|
TString s;
|
2008-04-24 07:35:22 +00:00
|
|
|
|
2007-12-06 16:01:03 +00:00
|
|
|
FOR_EACH_ASSOC_STRING(vars, hobj, key, val)
|
|
|
|
if (val && *val)
|
|
|
|
{
|
|
|
|
s = val;
|
|
|
|
if (s[0] == '"' && s.ends_with("\""))
|
|
|
|
{
|
|
|
|
s.rtrim(1);
|
|
|
|
s.ltrim(1);
|
|
|
|
}
|
|
|
|
s.trim();
|
|
|
|
if (TDate::isdate(s))
|
|
|
|
{
|
|
|
|
TDate date(s);
|
|
|
|
|
|
|
|
child.AddSoapInt(attr, date.date2ansi()).SetAttr("Name", key);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (real::is_natural(s))
|
|
|
|
child.AddSoapInt(attr, atoi(s)).SetAttr("Name", key);
|
|
|
|
else
|
|
|
|
child.AddSoapString(attr, s).SetAttr("Name", key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-12-10 16:25:48 +00:00
|
|
|
bool TPostman::dispatch_transaction(const TRectype& rec,
|
|
|
|
const TFilename& name)
|
|
|
|
{
|
|
|
|
bool ok = can_dispatch_transaction(rec);
|
|
|
|
if (ok)
|
|
|
|
{
|
2006-05-12 16:14:42 +00:00
|
|
|
TToken_string dest;
|
|
|
|
TToken_string file_dest;
|
2007-12-06 16:01:03 +00:00
|
|
|
TToken_string soap_dest;
|
2007-07-20 09:29:48 +00:00
|
|
|
TString last_error;
|
1998-12-10 16:25:48 +00:00
|
|
|
|
2006-05-12 16:14:42 +00:00
|
|
|
for (int r = 0; r < _recipient.items(); r++)
|
|
|
|
{
|
|
|
|
const TRecipient& a = recipient(r);
|
|
|
|
if (a.can_receive(rec))
|
|
|
|
{
|
2007-07-20 09:29:48 +00:00
|
|
|
const TString& addr = a.address();
|
2007-12-06 16:01:03 +00:00
|
|
|
if (addr.starts_with("http")) // Indirizzo http
|
2008-06-19 15:36:49 +00:00
|
|
|
soap_dest.add(addr); else
|
|
|
|
if (addr.find('@') > 0) // Indirizzo posta
|
|
|
|
dest.add(addr);
|
2006-05-12 16:14:42 +00:00
|
|
|
else
|
2007-07-20 09:29:48 +00:00
|
|
|
{
|
|
|
|
if (fexist(addr))
|
|
|
|
file_dest.add(addr);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (addr != last_error)
|
|
|
|
{
|
|
|
|
ok = error_box(FR("Non esiste la cartella di destinazione %s"), (const char*)addr);
|
|
|
|
last_error = addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-05-12 16:14:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dest.items() > 0)
|
|
|
|
{
|
|
|
|
TMail_message msg(dest.get(0));
|
|
|
|
for (const char* r = dest.get(1); r; r = dest.get())
|
|
|
|
msg.add_copy_recipient(r);
|
|
|
|
|
|
|
|
TString16 subject;
|
|
|
|
switch (rec.num())
|
|
|
|
{
|
2007-02-16 13:48:27 +00:00
|
|
|
case LF_TAB:
|
|
|
|
case LF_TABCOM:
|
|
|
|
case LF_TABGEN:
|
|
|
|
subject << rec.get("COD");
|
2013-12-13 09:33:44 +00:00
|
|
|
break;
|
|
|
|
case LF_TABMOD:
|
|
|
|
subject << '&' << rec.get("COD");
|
2007-02-16 13:48:27 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
subject << rec.num();
|
|
|
|
break;
|
2006-05-12 16:14:42 +00:00
|
|
|
}
|
|
|
|
msg.set_subject(subject);
|
|
|
|
|
|
|
|
TScanner trans(name);
|
|
|
|
while (trans.good())
|
|
|
|
{
|
|
|
|
TString& line = trans.line();
|
|
|
|
msg.add_line(line);
|
|
|
|
}
|
|
|
|
ok = msg.send(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file_dest.items() > 0)
|
|
|
|
{
|
2007-02-01 15:56:06 +00:00
|
|
|
TString16 basename;
|
2008-06-19 15:36:49 +00:00
|
|
|
const struct tm* tl = xvt_time_now();
|
2007-02-01 15:56:06 +00:00
|
|
|
basename.format("%02d%02d%02d_%02d%02d%02d_0",
|
|
|
|
tl->tm_year%100, tl->tm_mon+1, tl->tm_mday,
|
|
|
|
tl->tm_hour, tl->tm_min, tl->tm_sec);
|
|
|
|
|
|
|
|
FOR_EACH_TOKEN(file_dest, r)
|
|
|
|
{
|
2007-07-20 09:29:48 +00:00
|
|
|
TFilename output;
|
|
|
|
int retry = 0;
|
|
|
|
for (retry = 0; retry < 10; retry++) // Per ora tento solo 10 volte
|
|
|
|
{
|
|
|
|
output = r;
|
|
|
|
output.add(basename);
|
|
|
|
output << retry << ".ini";
|
|
|
|
if (!output.exist()) // Ho generato un nome buono
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (retry >= 10)
|
|
|
|
ok = false;
|
|
|
|
else
|
|
|
|
ok = fcopy(name, output);
|
2007-02-01 15:56:06 +00:00
|
|
|
}
|
2006-05-12 16:14:42 +00:00
|
|
|
}
|
2007-12-06 16:01:03 +00:00
|
|
|
|
|
|
|
if (soap_dest.items() > 0)
|
|
|
|
{
|
|
|
|
TConfig trans(name);
|
|
|
|
TXmlItem item;
|
|
|
|
TSocketClient socket;
|
|
|
|
char * buf = new char[1024 * 256];
|
2007-12-13 16:17:29 +00:00
|
|
|
|
|
|
|
ostrstream stream(buf, 1024 * 256);
|
2007-12-06 16:01:03 +00:00
|
|
|
bool ok = true;
|
|
|
|
|
2008-04-24 07:35:22 +00:00
|
|
|
item.SetTag("m:CampoTransaction");
|
2007-12-06 16:01:03 +00:00
|
|
|
trans.for_each_paragraph(write_xml, &item);
|
|
|
|
|
2008-04-24 07:35:22 +00:00
|
|
|
item.Write(stream, 2);
|
2007-12-06 16:01:03 +00:00
|
|
|
stream << '\0';
|
|
|
|
|
|
|
|
#ifdef DBG
|
|
|
|
TFilename name;
|
|
|
|
char hostname[256];
|
|
|
|
int len = strlen(buf);
|
|
|
|
|
|
|
|
len += 79;
|
|
|
|
xvt_sys_get_host_name(hostname, sizeof(hostname));
|
|
|
|
|
|
|
|
name.temp();
|
|
|
|
|
|
|
|
ofstream f(name);
|
|
|
|
|
|
|
|
f << "POST / HTTP/1.1\n"
|
|
|
|
<< "User-Agent: Campo\n"
|
|
|
|
<< "Host: " << hostname << "\n"
|
|
|
|
<< "Content-Type: text/xml; charset=utf-8\n"
|
|
|
|
<< "Content-length: " << len << "\n"
|
|
|
|
<< "SOAPAction: \"/\"\r\n\r\n"
|
2008-04-24 07:35:22 +00:00
|
|
|
<< "<SOAP-ENV:Envelope>\n<SOAP-ENV:Body>\r\n";
|
2007-12-06 16:01:03 +00:00
|
|
|
|
2008-04-24 07:35:22 +00:00
|
|
|
item.Write(f, 2);
|
2007-12-06 16:01:03 +00:00
|
|
|
|
2008-04-24 07:35:22 +00:00
|
|
|
f << "\n</SOAP-ENV:Body>\n</SOAP-ENV:Envelope>\r\n\r\n";
|
2007-12-06 16:01:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
FOR_EACH_TOKEN(soap_dest, r)
|
|
|
|
{
|
|
|
|
CONNID id = socket.QueryConnection("", r);
|
|
|
|
socket.HttpSoap(id, buf);
|
|
|
|
}
|
|
|
|
}
|
1998-12-10 16:25:48 +00:00
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPostman::load_filters()
|
|
|
|
{
|
|
|
|
TToken_string perm(4096, '\n');
|
|
|
|
TAuto_token_string row(80);
|
|
|
|
|
|
|
|
// Costruisce il nome dell'applicazione principale
|
2013-03-15 11:03:47 +00:00
|
|
|
const TApplication& ma = main_app();
|
|
|
|
TFilename app(ma.argv(0));
|
|
|
|
app = app.name_only();
|
1998-12-10 16:25:48 +00:00
|
|
|
|
2013-03-15 11:03:47 +00:00
|
|
|
for (int a = 1; a < ma.argc(); a++)
|
1998-12-10 16:25:48 +00:00
|
|
|
{
|
2013-03-15 11:03:47 +00:00
|
|
|
row = ma.argv(a); row.upper();
|
|
|
|
if (row[0] != '/' && row[1] != 'I')
|
1998-12-10 16:25:48 +00:00
|
|
|
app << ' ' << row;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stringhe delle espressioni i filtro
|
|
|
|
TAssoc_array expr;
|
|
|
|
|
|
|
|
// Scandisce l'albero degli utenti/gruppi
|
2011-06-09 11:03:05 +00:00
|
|
|
const TString_array& uag = user_and_groups();
|
|
|
|
FOR_EACH_ARRAY_ROW(uag, r, rec)
|
|
|
|
{
|
|
|
|
perm = rec->after(rec->separator()); // Permessi del nodo corrente
|
1998-12-10 16:25:48 +00:00
|
|
|
if (!perm.blank())
|
|
|
|
{
|
|
|
|
FOR_EACH_TOKEN(perm, tok)
|
|
|
|
{
|
|
|
|
row = tok;
|
|
|
|
const TString80 appmod = row.get(0);
|
|
|
|
const bool is_mod = appmod.len() == 2;
|
2001-04-30 15:04:10 +00:00
|
|
|
// Il programma oppure il modulo corrispondono
|
1998-12-10 16:25:48 +00:00
|
|
|
if ((is_mod && app.compare(appmod, 2, TRUE) == 0) ||
|
|
|
|
app.compare(appmod, -1, TRUE) == 0)
|
|
|
|
{
|
1999-06-18 15:35:05 +00:00
|
|
|
TString80 key = row.get(2); key.trim(); // Tipo di filtro
|
1998-12-10 16:25:48 +00:00
|
|
|
row = row.get(); row.trim(); // Espressione di filtro
|
|
|
|
if (key.not_empty() && row.not_empty() && row != "1")
|
|
|
|
{
|
|
|
|
key.upper();
|
|
|
|
TString* str = (TString*)expr.objptr(key);
|
|
|
|
if (str == NULL)
|
|
|
|
{
|
|
|
|
str = new TString(row); // Crea una nuova stringa
|
|
|
|
expr.add(key, str);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Somma alla stringa precendente
|
|
|
|
if (*str != "0") // Se sono FALSE lasciami stare
|
|
|
|
{
|
|
|
|
if (row != "0") // Se aggiungo qualcosa di non ovvio
|
|
|
|
{
|
|
|
|
str->insert("(", 0);
|
|
|
|
*str << ")AND(";
|
|
|
|
*str << row << ')';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*str = "0";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Trasforma le stringhe in espressioni
|
|
|
|
FOR_EACH_ASSOC_STRING(expr, hash, key, str)
|
|
|
|
{
|
2001-04-30 15:04:10 +00:00
|
|
|
TExpression* e = new TExpression(str, _strexpr, TRUE);
|
|
|
|
_expr.add(key, e);
|
1998-12-10 16:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Inserisce un elemento fasullo per segnalare l'avvenuta lettura
|
|
|
|
if (_expr.items() == 0)
|
|
|
|
_expr.add("", NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
TExpression* TPostman::get_filter_expr(const char* flt)
|
|
|
|
{
|
|
|
|
if (_expr.items() == 0)
|
|
|
|
load_filters();
|
|
|
|
TString80 f(flt); f.upper();
|
|
|
|
TExpression* e = (TExpression*)_expr.objptr(f);
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* TPostman::get_filter(const char* flt)
|
|
|
|
{
|
|
|
|
TExpression* e = get_filter_expr(flt);
|
|
|
|
return e ? e->string() : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TPostman::user_can(const char* flt, const TRelation* rel)
|
|
|
|
{
|
|
|
|
bool yes_he_can = TRUE;
|
|
|
|
TExpression* e = get_filter_expr(flt);
|
|
|
|
if (e != NULL)
|
|
|
|
{
|
|
|
|
if (rel != NULL)
|
|
|
|
{
|
|
|
|
for (int i = e->numvar()-1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
const TString& name = e->varname(i);
|
|
|
|
const TFieldref ref(name, 0);
|
|
|
|
const TString& val = ref.read(*rel);
|
|
|
|
e->setvar(name, val);
|
|
|
|
}
|
|
|
|
yes_he_can = e->as_bool();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (e->numvar() == 0)
|
|
|
|
yes_he_can = e->as_bool();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return yes_he_can;
|
|
|
|
}
|
|
|
|
|
2013-12-13 09:33:44 +00:00
|
|
|
TPostman::TPostman() : _firm(-1), _recipients_lognum(0)
|
1998-12-10 16:25:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TPostman& postman()
|
|
|
|
{
|
|
|
|
static TPostman* _postman = NULL;
|
|
|
|
if (_postman == NULL)
|
|
|
|
_postman = new TPostman;
|
|
|
|
return *_postman;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Public interface
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
bool can_dispatch_transaction(const TRectype& rec)
|
|
|
|
{
|
|
|
|
return postman().can_dispatch_transaction(rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool dispatch_transaction(const TRectype& rec, const TFilename& name)
|
|
|
|
{
|
|
|
|
return postman().dispatch_transaction(rec, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* get_user_filter(const char* flt)
|
|
|
|
{
|
|
|
|
return postman().get_filter(flt);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* get_user_read_filter()
|
|
|
|
{
|
|
|
|
return get_user_filter("Lettura");
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* get_user_write_filter()
|
|
|
|
{
|
|
|
|
return get_user_filter("Scrittura");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool user_can_read(const TRelation* rel)
|
|
|
|
{
|
|
|
|
return postman().user_can("Lettura", rel);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool user_can_write(const TRelation* rel)
|
|
|
|
{
|
|
|
|
return user_can_read(rel) && postman().user_can("Scrittura", rel);
|
|
|
|
}
|
|
|
|
|
2004-06-24 10:50:24 +00:00
|
|
|
bool user_can_delete(const TRelation* rel)
|
|
|
|
{
|
|
|
|
return user_can_write(rel) && postman().user_can("Eliminazione", rel);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool user_can_do(const char* azione, const TRelation* rel)
|
|
|
|
{
|
|
|
|
return postman().user_can(azione, rel);
|
|
|
|
}
|
1998-12-10 16:25:48 +00:00
|
|
|
|