-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathExport.xxm
315 lines (273 loc) · 9.39 KB
/
Export.xxm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
[[@Classes,txDefs,txSession,DataLank,txFilter,txFilterSql,]][[
if Context['x'].AsInteger=0 then
begin
Context.Include('dHead.xxmi',['Export']);
<h2>Export</h2>
[[#txForm('Export.xxm',[])]]
<input type="hidden" name="x" value="1" />
<b>Filename:</b><br />
<input type="text" name="filename" id="FileName1" value="" class="textfield" />
<br />
<b>Filter:</b><br />
if Session.FilterCache.Count<>0 then
begin
<<select name="filter1" id="FilterSel1" onchange="if(this.value=='') $('#FilterEx1').show(); else $('#FilterEx1').hide();">
<option value=""></option>>
for i:=0 to Session.FilterCache.Count-1 do
begin
<<option value="[[=Session.FilterCache[i]]]">>=Session.FilterCache[i]<</option>>
end;
<</select>
<br />>
end;
<<input type="text" name="filter2" id="FilterEx1" value="[[=Context['filter'].Value]]" class="textfield" />
<br />
<b>Include:</b><br />
<label><input type="checkbox" name="path" value="1" checked="1" />
Objects in path of filtered objects</label>
<br />
<label><input type="checkbox" name="children" value="1" />
Children of filtered objects,
<b>Attention:</b> don't select this option if the filter expression already includes all children of filtered objects
</label>
<br />
<label><input type="checkbox" name="refered" value="1" />
Referred objects outside of primary selection</label>
<br />
<div style="margin-top: 0em; margin-right: 0em; margin-bottom: 0em; margin-left: 2em;">
<label><input type="checkbox" name="refpath" value="1" checked="1" />
Objects in path of referred objects</label>
<br />
<label><input type="checkbox" name="refchildren" value="1" />
Children of refered objects</label>
<br />
</div>
<label><input type="checkbox" name="reports" value="1" />
Reports</label>
<br />
[[//TODO: filters, c/m userID, realm]]
[[//
<label><input type="checkbox" name="..." value="1" />
...</label>
<br />
]]
<br />
[[#txFormButton]]
</form>>
Context.Include('dFoot.xxmi');
end
else
begin
]][[!
var
IdsIn,IdsOut:TStringList;
procedure AddId(xot:char;xid:integer);
var
xx:string;
begin
if not(xid=0) then
begin
xx:=xot+IntToStr(xid);
if (IdsIn.IndexOf(xx)=-1) and (IdsOut.IndexOf(xx)=-1) then IdsIn.Add(xx);
end;
end;
var
DoChildren,DoPath,DoRefered,DoRefChildren,DoRefPath,DoReports:boolean;
f:TtxFilter;
fq:TtxSqlQueryFragments;
filter,x:string;
fs,y:UTF8String;
i,id:integer;
qr:TQueryResult;
xc:char;
const
XmlDateFmt='yyyy-mm-dd"T"hh:nn:ss';
]][[
filter:=Context['filter1'].Value;
if filter='' then filter:=Context['filter2'].Value;
//if filter='' then raise? true all?
f:=TtxFilter.Create;
fq:=TtxSqlQueryFragments.Create(itObj);
try
f.FilterExpression:=UTF8Encode(filter);
if f.ParseError<>'' then raise Exception.Create(f.ParseError);
fq.AddFilter(f);
fq.Fields:='Obj.id';//, Obj.pid, ObjType.id';
//TODO: rpView/rpEdit?
fq.Where:='Obj.rlm_id'+Session.Realms[rpView].SQL+' AND ('+fq.Where+')';
fs:=fq.SQL;
finally
f.Free;
fq.Free;
end;
DoChildren:=Context['children'].AsInteger=1;
DoPath:=Context['path'].AsInteger=1;
DoRefered:=Context['refered'].AsInteger=1;
DoRefChildren:=Context['refchildren'].AsInteger=1;
DoRefPath:=Context['refpath'].AsInteger=1;
DoReports:=Context['reports'].AsInteger=1;
IdsIn:=TStringList.Create;
IdsIn.Sorted:=true;
IdsOut:=TStringList.Create;
IdsOut.Sorted:=true;
try
//fill IdsIn with filter
qr:=TQueryResult.Create(Session.DbCon,fs,[]);
try
while qr.Read and Context.Connected do
IdsIn.Add('i'+IntToStr(qr.GetInt('id')));
finally
qr.Free;
end;
Context.ContentType:='text/xml';
x:=Context['filename'].Value;
if x<>'' then Context.DispositionAttach(x+'.xml');
//TODO: namespace, schema, encoding?
Context.SendHTML('<?xml version="1.0"?>'#13#10'<tx>'#13#10);
while (IdsIn.Count<>0) and Context.Connected do
begin
x:=IdsIn[0];
IdsIn.Delete(0);
IdsOut.Add(x);
id:=StrToInt(Copy(x,2,Length(x)-1));
xc:=x[1];
case xc of
'i'://item
begin
AddId('o',id);
if DoChildren then AddId('c',id);
if DoPath then AddId('p',DBSingleValue('SELECT pid FROM Obj WHERE id=?',[id],0));
end;
'r'://item refered to
begin
AddId('o',id);
if DoRefChildren then AddId('d',id);
if DoRefPath then AddId('p',DBSingleValue('SELECT pid FROM Obj WHERE id=?',[id],0));
end;
'p'://item in path
begin
AddId('o',id);
AddId('p',DBSingleValue('SELECT pid FROM Obj WHERE id=?',[id],0));
end;
'o'://object
begin
qr:=TQueryResult.Create(Session.DbCon,'SELECT * FROM Obj WHERE id=?',[id]);
try
AddId('u',qr.GetInt('objtype_id'));
]]
<Obj id="[[=id]]" pid="[[.pid]]" type="[[.objtype_id]]" weight="[[.weight]]" realm="[[.rlm_id]]">
<name>>.name<</name>
<desc><![CDATA[[[#qr['desc']]]]]></desc>
<url>>.url<</url>
<cre uid="[[.c_uid]]">>=FormatDateTime(XmlDateFmt,qr.GetDate('c_ts'))<</cre>
<mod uid="[[.m_uid]]">>=FormatDateTime(XmlDateFmt,qr.GetDate('m_ts'))<</mod>
[[
finally
qr.Free;
end;
qr:=TQueryResult.Create(Session.DbCon,'SELECT * FROM Tok WHERE obj_id=?',[id]);
try
while qr.Read and Context.Connected do
begin
AddId('v',qr.GetInt('toktype_id'));
]]
<Tok type="[[.toktype_id]]" weight="[[.weight]]">
<desc><![CDATA[[[#qr['desc']]]]]></desc>
<cre uid="[[.c_uid]]">>=FormatDateTime(XmlDateFmt,qr.GetDate('c_ts'))<</cre>
<mod uid="[[.m_uid]]">>=FormatDateTime(XmlDateFmt,qr.GetDate('m_ts'))<</mod>
</Tok>
[[
end;
finally
qr.Free;
end;
qr:=TQueryResult.Create(Session.DbCon,'SELECT * FROM Ref WHERE obj1_id=?',[id]);
try
while qr.Read and Context.Connected do
begin
AddId('w',qr.GetInt('reftype_id'));
if DoRefered then AddId('r',qr.GetInt('obj2_id'));
]]
<Ref rid="[[.obj2_id]]" type="[[.reftype_id]]" weight="[[.weight]]">
<desc><![CDATA[[[#qr['desc']]]]]></desc>
<cre uid="[[.c_uid]]">>=FormatDateTime(XmlDateFmt,qr.GetDate('c_ts'))<</cre>
<mod uid="[[.m_uid]]">>=FormatDateTime(XmlDateFmt,qr.GetDate('m_ts'))<</mod>
</Ref>
[[
//TODO: more data here of not include ref'd?
end;
finally
qr.Free;
end;
//if (x='i') and DoReports then
if DoReports then
begin
qr:=TQueryResult.Create(Session.DbCon,'SELECT * FROM Rpt WHERE obj_id=?',[id]);
try
while qr.Read and Context.Connected do
begin
AddId('v',qr.GetInt('toktype_id'));
AddId('w',qr.GetInt('reftype_id'));
if DoRefered then AddId('r',qr.GetInt('obj2_id'));
//TODO: Rpt.weight?
]]
<Rpt id="[[.id]]" uid="[[.uid]]" toktype="[[.toktype_id]]" reftype="[[.reftype_id]]" info="[[.obj2_id]]" weight="[[.weight]]">
<ts>>=FormatDateTime('yyyy-mm-dd"T"hh:nn:ss',qr.GetDate('ts'))<</ts>
<desc><![CDATA[[[#qr['desc']]]]]></desc>
</Rpt>
[[
//TODO: show extra info?
end;
finally
qr.Free;
end;
end;
]]
</Obj>
[[
end;
'c','d'://children, chilren if ref'd
begin
qr:=TQueryResult.Create(Session.DbCon,'SELECT id FROM Obj WHERE pid=?',[id]);
try
while qr.Read and Context.Connected do
begin
if xc='c' then AddId('i',qr.GetInt('id')) else AddId('r',qr.GetInt('id'));
AddId('u',qr.GetInt('objtype_id'));
end;
finally
qr.Free;
end;
end;
'u','v','w'://objtype,toktype,reftype
begin
case xc of
'u':y:='ObjType';
'v':y:='TokType';
'w':y:='RefType';
end;
qr:=TQueryResult.Create(Session.DbCon,'SELECT * FROM '+y+' WHERE id=?',[id]);
try
AddId(xc,qr.GetInt('pid'));
]]
<[[#y]] id="[[.id]]" pid="[[.pid]]" icon="[[.icon]]" weight="[[.weight]]">
<name>>.name<</name>
<system>>.system<</system>
<default>>.dft<</default>
<cre uid="[[.c_uid]]">>=FormatDateTime(XmlDateFmt,qr.GetDate('c_ts'))<</cre>
<mod uid="[[.m_uid]]">>=FormatDateTime(XmlDateFmt,qr.GetDate('m_ts'))<</mod>
</[[#y]]>
[[
finally
qr.Free;
end;
end;
//add new here
end;
end;
Context.SendHTML(#13#10'</tx>'#13#10);
finally
IdsIn.Free;
IdsOut.Free;
end;
end;