-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRealms.xxm
252 lines (235 loc) · 7.54 KB
/
Realms.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
[[@txDefs,DataLank,txSession,txTerms,]][[!var
IsAdmin,InView,InControl,SomeLimits:boolean;
qr:TQueryResult;
s,t,USelf:string;
id:integer;
const
ImgSuffix:array[boolean] of string=('0','1');
SetClear:array[boolean] of string=('s','c');
function BriefSQL(const sql:UTF8String):string;
var
i,l:integer;
begin
l:=Length(sql);
i:=4;//assert Copy(sql,1,4)='IN (';
while (i<=l) and (sql[i]<>')') do inc(i);
Result:=string(Copy(sql,4,i-3));
if i<l then
begin
Result:=Result+'*';
SomeLimits:=true;
end;
end;
]][[
IsAdmin:=Session.IsAdmin('realms');
Context.Include('dHead.xxmi',['Realms']);
<meta name="robots" content="nofollow" />
USelf:='Realms.xxm?a=';//TODO: from context?
SomeLimits:=false;
s:=Context['a'].Value;
if s<>'' then
case s[1] of
'r':Session.LoadRealmPermissions;//test
's':Session.SetViewRealm(true,StrToInt(Copy(s,2,Length(s)-1)));//set
'c':Session.SetViewRealm(false,StrToInt(Copy(s,2,Length(s)-1)));//clear
end;
if Session.Realms[rpView].Count=0 then Session.LoadRealmPermissions;
if IsAdmin then
begin
<<p class="buttons"><a href="fRealm.xxm" class="linkbutton">add...</a></p>>
end;
//TODO: fRealm.xxm fDelete.xxm?x=rm
<<table cellspacing="2" cellpadding="2" border="0" class="listtable">
<tr>
<th> </th>
<th>realm</th>
<th>description</th>
<th>system</th>
<th>viewable by</th>
<th>editable by</th>>
if Use_ObjPath then begin <<th>limit to</th>> end;
<<th> </th>
</tr>>
qr:=TQueryResult.Create(Session.DbCon,'SELECT * FROM Rlm WHERE id<>0 ORDER BY id',[]);
try
while qr.Read do
begin
id:=qr.GetInt('id');
InView:=true;
try
Session.HasRealmPermission(0,id,rpView);
except
on ERealmNotEditableByUser do InView:=false;
end;
InControl:=true;
try
Session.HasRealmPermission(0,id,rpEdit);
except
on ERealmNotEditableByUser do InControl:=false;
end;
//TODO: setting incontrol can edit/delete?
//TermLinks: default domain?
<<tr>
<td style="white-space:nowrap;">>
if IsAdmin {or InControl} then begin <<a href="fRealm.xxm?id=[[=id]]" class="linkbutton">edit</a> [[ end;
if IsAdmin {or InControl} then begin <<a href="fDelete.xxm?x=rm[[=id]]" class="linkbutton">delete</a> [[ end;
<</td>>
if IsAdmin or InControl then
begin
<<td onclick="return rlmToggle([[=id]]);">
<a href="[[=USelf]][[=SetClear[InView]]][[=id]]" id="toggle[[=id]]"><img src="img_check[[#ImgSuffix[InView]+'.'+globalImgExt+globalImgVer]]" width="16" height="16" [[#globalIconAlign]]/></a>>
end
else
begin
<<td>
<img src="img_trx.[[#globalImgExt+globalImgVer]]" width="16" height="16" [[#globalIconAlign]]/>>
end;
]] [[.name<<br />
<img src="img_trx.[[#globalImgExt+globalImgVer]]" width="16" height="16" [[#globalIconAlign]]/>
#[[=id]]
</td>
<td>>#TermStore.TermLinks(itRealm,id,0,qr.GetStr('desc'))]] </td>
<td><span class="sysref">>.system<</span> </td>
<td style="white-space:nowrap;">>
s:=qr.GetStr('view_expression');
if s='' then Context.SendHTML('–') else
begin
t:='?filter='+string(URLEncode(s));
<<span class="litref">>=s<</span><br />
<a href="Filter.xxm[[=t]]" class="linkbutton">filter</a>
<a href="FilterBuild.xxm[[=t]]" class="linkbutton">build</a>>
end;
<</td>
<td style="white-space:nowrap;">>
s:=qr.GetStr('edit_expression');
if s='' then Context.SendHTML('–') else
begin
t:='?filter='+string(URLEncode(s));
<<span class="litref">>=s<</span><br />
<a href="Filter.xxm[[=t]]" class="linkbutton">filter</a>
<a href="FilterBuild.xxm[[=t]]" class="linkbutton">build</a>>
end;
<</td>>
if Use_ObjPath then
begin
<<td style="white-space:nowrap;">>
s:=qr.GetStr('limit_expression');
if s='' then Context.SendHTML('–') else
begin
t:='?filter='+string(URLEncode(s));
<<span class="litref">>=s<</span><br />
<a href="Filter.xxm[[=t]]" class="linkbutton">filter</a>
<a href="FilterBuild.xxm[[=t]]" class="linkbutton">build</a>>
end;
<</td>>
end;
<<td>>Context.Include('d_cmw.xxmi',[],[qr,nil]);<</td>
</tr>>
end;
finally
qr.Free;
end;
id:=0;
InView:=true;
try
Session.HasRealmPermission(0,id,rpView);
except
on ERealmNotEditableByUser do InView:=false;
end;
//InControl:=Session.RealmPermission(rpEdit,id);
qr:=TQueryResult.Create(Session.DbCon,'SELECT * FROM Rlm WHERE id=0 ORDER BY id',[]);
try
<<tr>>
if IsAdmin then
begin
<<th style="text-align:left;font-weight:normal;"><a href="fRealm0.xxm" class="linkbutton">edit...</a></th>>
end
else
begin
<<th> </th>>
end;
<<th style="text-align:left;" onclick="return rlmToggle(0);">
<a href="[[=USelf]][[=SetClear[InView]]][[=id]]" id="toggle0"><img src="img_check[[#ImgSuffix[InView]+'.'+globalImgExt+globalImgVer]]" width="16" height="16" [[#globalIconAlign]]/></a>
Default realm<br />
<img src="img_trx.[[#globalImgExt+globalImgVer]]" width="16" height="16" [[#globalIconAlign]]/>
#0
</th>
<th style="text-align:left;font-weight:normal;">
View <b id="vList">>=BriefSQL(Session.Realms[rpView].SQL)<</b>
Control <b>>=BriefSQL(Session.Realms[rpEdit].SQL)<</b>
<br />
Uncheck all or <a href="[[=USelf]]reset">click here to reset defaults</a>.
</th>>
if qr.Read then
begin
<<th> </th>
<td style="white-space:nowrap;">>
s:=qr.GetStr('view_expression');
if s='' then Context.SendHTML('–') else
begin
t:='?filter='+string(URLEncode(s));
<<span class="litref">>=s<</span><br />
<a href="Filter.xxm[[=t]]" class="linkbutton">filter</a>
<a href="FilterBuild.xxm[[=t]]" class="linkbutton">build</a>>
end;
<</td>
<td style="white-space:nowrap;">>
s:=qr.GetStr('edit_expression');
if s='' then Context.SendHTML('–') else
begin
t:='?filter='+string(URLEncode(s));
<<span class="litref">>=s<</span><br />
<a href="Filter.xxm[[=t]]" class="linkbutton">filter</a>
<a href="FilterBuild.xxm[[=t]]" class="linkbutton">build</a>>
end;
<</td>>
if Use_ObjPath then
begin
<<td style="white-space:nowrap;">>
s:=qr.GetStr('limit_expression');
if s='' then Context.SendHTML('–') else
begin
t:='?filter='+string(URLEncode(s));
<<span class="litref">>=s<</span><br />
<a href="Filter.xxm[[=t]]" class="linkbutton">filter</a>
<a href="FilterBuild.xxm[[=t]]" class="linkbutton">build</a>>
end;
<</td>>
end;
<<th style="text-align:left;font-weight:normal;">>Context.Include('d_cmw.xxmi',[],[qr,nil]);<</th>>
end
else
begin
<<th colspan="[[if Use_ObjPath then Context.SendHTML('5') else Context.SendHTML('4');]]"> </th>>
end;
<</tr>
</table>
<script><!--
var rr=[[=Random(100000000)]];
function rlmToggle(r){
var a=document.getElementById("toggle"+r);
var b=a.href.split("=");
var c=b[1][0];
a.href=b[0]+"="+((c=="c")?"s":"c")+r;
a.children[0].src="aRealms.xxm?a="+c+r+"&rr="+(rr++)+"[[#txCallProtect]]";
document.getElementById("vList").textContent="(...)";
return false;
}
//--></script>>
finally
qr.Free;
end;
<<p class="buttons">>
if IsAdmin then
begin
<<a href="fRealm.xxm" class="linkbutton">add...</a>
<a href="FilterCount.xxm?realms=1" class="linkbutton">count...</a>
[[
end;
<<a href="Item.xxm?x=i[[=Session.UserID]]" class="linkbutton">user obj...</a>
</p>>
if SomeLimits then
begin
<<p><b>*:</b> some realm access has limits enforced.</p>>
end;
Context.Include('dFoot.xxmi');