DCL
3.7.4
Loading...
Searching...
No Matches
Group.cpp
Go to the documentation of this file.
1
#include <
dcl/Config.h
>
2
3
#ifdef __WINNT__
4
#include <windows.h>
5
#endif
6
7
#include <
dcl/URI.h
>
8
9
#include "
HtmlPage.h
"
10
#include "
LinkUtility.h
"
11
#include "
User.h
"
12
13
#if __DCL_HAVE_THIS_FILE__
14
#undef __THIS_FILE__
15
static
const
char_t
__THIS_FILE__
[] =
__T
(
"fastpage/Group.cpp"
);
16
#endif
17
18
__DCL_BEGIN_NAMESPACE
19
/*
20
IMPLEMENT_CLASSINFO_EX(GroupListView, HtmlView)
21
22
GroupListView::GroupListView(HtmlPage* pPage)
23
: HtmlView(pPage)
24
{
25
__nParts = 5;
26
__nRows = 20;
27
__nShortComment = 20;
28
}
29
30
void GroupListView::init(SQLFields& fields)
31
__DCL_THROWS1(Exception*)
32
{
33
HtmlView::init(fields);
34
35
__mapParams.lookup(L"DETAIL", __strDetailPage);
36
__mapParams.lookup(L"WRITE", __strWritePage);
37
38
String rValue;
39
40
if (__mapParams.lookup(L"PARTS", rValue) && !rValue.isEmpty()) {
41
__nParts = Integer::parse(rValue, 10, __nParts);
42
if (__nParts < 5 || __nParts > 20)
43
__nParts = 5;
44
}
45
46
if (__mapParams.lookup(L"ROWS", rValue) && !rValue.isEmpty()) {
47
__nRows = Integer::parse(rValue, 10, __nRows);
48
if (__nRows <= 0)
49
__nRows = 20;
50
}
51
52
if (__mapParams.lookup(L"SHORT_COMMENT", rValue) && !rValue.isEmpty()) {
53
int n = Integer::parse(rValue, 10, __nShortComment);
54
if (n > 0)
55
__nShortComment = n;
56
}
57
}
58
59
void GroupListView::onPrint()
60
__DCL_THROWS1(Exception*)
61
{
62
Session& session = *(__pPage->session());
63
SQLQuery& q = session.__query;
64
ListedStringToStringArrayMap& mapQuery = session.__ctx.__queryMap;
65
66
int nCurrentPart = Integer::parse(getDefault(mapQuery, L"part"), 10, 1);
67
int nRows = __nRows;
68
69
String strDetailPage = __strDetailPage;
70
String strWritePage = __strWritePage;
71
String strThisPage = __pPage->__strPageID;
72
String strThisPageEnc;
73
74
String strCategoryID = getDefault(mapQuery, L"category");
75
String strSort = getDefault(mapQuery, L"sort");
76
// String strCriteria = getDefault(mapQuery, L"criteria");
77
String strName = getDefault(mapQuery, L"name");
78
79
String strWhere;
80
String strOrderBy;
81
82
if (session.isSysAdmin())
83
strWhere += L"G.GROUP_ID >= 0";
84
else {
85
int nCategoryID = Integer::parse(strCategoryID, 10, 0);
86
if (nCategoryID <= 0) {
87
// 일반 사용자는 시스템 그룹 카테고리를 볼 수 없다.
88
strCategoryID.clear();
89
}
90
91
strWhere += L"G.GROUP_ID > " + String::valueOf(SYSTEM_GROUP_ID_END);
92
}
93
94
if (!strCategoryID.isEmpty()) {
95
strWhere += L" AND G.CATEGORY_ID = " + strCategoryID;
96
strThisPage +="&category=" + strCategoryID;
97
}
98
else {
99
strCategoryID = L"1";
100
strWhere += L" AND G.CATEGORY_ID = 1";
101
}
102
103
if (!strName.isEmpty()) {
104
strWhere += L" AND (G.GROUP_NAME LIKE \'%" + strName + L"%\')";
105
strThisPage += L"&name=" + URLEncoder::encode(strName);
106
}
107
108
if (!strSort.isEmpty()) {
109
if (strSort == L"id" && session.isSysAdmin()) {
110
// 관리자만 GROUP_ID를 사용하여 소트할 수 있다.
111
strOrderBy = L" G.GROUP_ID ASC";
112
strThisPage += L"&sort=id";
113
}
114
else if (strSort == L"nuser") {
115
strOrderBy = L" G.NUSER DESC, G.GROUP_NAME ASC";
116
strThisPage += L"&sort=nuser";
117
}
118
// else if (strSort == L"nvisit") {
119
// strOrderBy = L" G.NVISIT_ALL DESC,";
120
// strThisPage += L"&sort=nvisit";
121
// }
122
// else if (strSort == L"nmsg") {
123
strOrderBy = L" G.NMESSAGE DESC, G.GROUP_NAME ASC";
124
strThisPage += L"&sort=nmsg";
125
}
126
}
127
128
if (strOrderBy.isEmpty())
129
strOrderBy = L" G.NUSER DESC, G.NMESSAGE DESC, G.GROUP_NAME ASC";
130
131
assign(L"DETAIL", strDetailPage);
132
assign(L"WRITE", strWritePage);
133
assign(L"SORT", strSort);
134
assign(L"CATEGORY", strCategoryID);
135
assign(L"GROUP_NAME", strName);
136
if (!session.isSysGuest()) {
137
TextTemplate& ADD = (*this)[L"ADD"];
138
ADD.assign(L"WRITE", strWritePage);
139
ADD.assign(L"CATEGORY_ID", strCategoryID);
140
assign(L"ADD", ADD);
141
}
142
else
143
assign(L"ADD", (*this)[L"NADD"]);
144
145
int nUsingRecord = nRows;
146
int nTotalRecord = nUsingRecord;
147
int nTotalPart = 1;
148
149
// nNo를 표시하기 위해서 조건에 만족하는 전체레코드의 개수가 항상 필요하다.
150
q.execute(
151
"SELECT COUNT(*) "
152
"\n FROM DCL_GROUP AS G"
153
"\n WHERE " + strWhere
154
);
155
q.fetch();
156
nTotalRecord = q.fields()[0].asInteger();
157
if (nTotalRecord == 0) {
158
assign(L"EMPTY", (*this)[L"EMPTY"]);
159
HtmlView::onPrint();
160
return;
161
}
162
163
__DCL_VERIFY(nTotalRecord > 0);
164
165
nTotalPart = nTotalRecord / nUsingRecord;
166
if (nTotalRecord % nUsingRecord)
167
nTotalPart++;
168
169
if (nCurrentPart <= 0 || nCurrentPart > nTotalPart)
170
nCurrentPart = nTotalPart;
171
172
String strThisPageEx = strThisPage;
173
if (nCurrentPart > 1)
174
strThisPageEx += L"&part=" + String::valueOf(nCurrentPart);
175
strThisPageEnc = URLEncoder::encode(strThisPageEx);
176
177
assign(L"_THIS", strThisPageEnc);
178
179
int nOffset = (nCurrentPart - 1) * nUsingRecord;
180
181
int nNo = nTotalRecord - ((nCurrentPart - 1) * nUsingRecord);
182
int nRow = 1;
183
184
TextTemplate& ROW = (*this)[L"ROW"];
185
186
String strSQL =
187
"SELECT G.GROUP_ID, G.SIGN_ID, G.GROUP_NAME, G.OWNER_ID"
188
", G.OPEN_TYPE, G.REGIST_DATE, G.COMMENT"
189
", G.TODAY_NUSER, G.TODAY_NVISIT, G.TODAY_NMESSAGE"
190
", G.NUSER, G.NVISIT, G.NMESSAGE"
191
", U.USER_NAME AS OWNER_NAME, U.NICKNAME AS OWNER_NICKNAME"
192
"\n FROM DCL_GROUP AS G"
193
"\n INNER JOIN DCL_USER AS U ON (G.OWNER_ID = U.USER_ID)"
194
"\n WHERE " + strWhere +
195
"\n ORDER BY " + strOrderBy +
196
"\n LIMIT " + String::valueOf(nUsingRecord) +
197
"\n OFFSET " + String::valueOf(nOffset);
198
199
__DCL_TRACE1(L"%ls\n", strSQL.data());
200
201
q.execute(strSQL);
202
q.fetch();
203
if (q.eof())
204
assign(L"EMPTY", (*this)[L"EMPTY"]);
205
else {
206
// if (__bNoAsc)
207
// nNo = 1;
208
209
do {
210
ROW.assign(q.fields(), L" ");
211
212
SQLField& field = q.fields().byName(L"COMMENT");
213
if (field.isNull()) {
214
ROW.assign(L"SHORT_COMMENT", L" ");
215
ROW.assign(L"COMMENT", L"");
216
}
217
else {
218
String strComment = field.asString();
219
if (strComment.isEmpty())
220
ROW.assign(L"SHORT_COMMENT", L" ");
221
else {
222
if (strComment.mbLength() > __nShortComment)
223
ROW.assign(L"SHORT_COMMENT", strComment.mbLeft(__nShortComment) + L"...");
224
else
225
ROW.assign(L"SHORT_COMMENT", strComment);
226
}
227
}
228
229
ROW.assign(L"NO", String::valueOf(nNo));
230
// if (__bNoAsc)
231
// nNo++;
232
// else
233
nNo--;
234
235
ROW.assign(L"DETAIL", strDetailPage);
236
ROW.assign(L"WRITE", strWritePage);
237
ROW.assign(L"_THIS", strThisPageEnc);
238
#ifdef __DCL_DEBUG
239
ROW.assign(L"_DHE", L"dhed");
240
#else
241
ROW.assign(L"_DHE", L"dhe");
242
#endif
243
append(L"ROW", ROW);
244
245
q.fetch();
246
} while(!q.eof());
247
248
TextTemplate* pPART_LINK = atP(L"PART_LINK");
249
if (pPART_LINK && nTotalPart > 1) {
250
PartLink pl(pPART_LINK, strThisPage, String());
251
pl.assign(this, nTotalPart, nCurrentPart, __nParts);
252
}
253
}
254
255
HtmlView::onPrint();
256
}
257
258
IMPLEMENT_CLASSINFO_EX(GroupWriteForm, FormView)
259
260
GroupWriteForm::GroupWriteForm(HtmlPage* pPage)
261
: FormView(pPage)
262
{
263
}
264
265
void GroupWriteForm::onPrint()
266
__DCL_THROWS1(Exception*)
267
{
268
Session& session = *(__pPage->session());
269
ListedStringToStringArrayMap& mapQuery = session.__ctx.__queryMap;
270
SQLQuery& q = session.__query;
271
272
String strListPage = getDefault(mapQuery, L"list");
273
if (!strListPage.isEmpty()) {
274
String strListPageEnc = URLEncoder::encode(strListPage);
275
assign(L"_LIST", strListPageEnc);
276
}
277
else
278
strListPage = __strListPage;
279
280
assign(L"LIST", strListPage);
281
282
// "category"가 있으면 새로운 그룹, 그렇지 않으면 수정
283
String strCategoryID = getDefault(mapQuery, L"category");
284
String strGroupID = getDefault(mapQuery, L"group");
285
286
#define CM_INVALID 0
287
#define CM_INSERT 1
288
#define CM_MODIFY 2
289
int nCM = CM_INVALID;
290
if (!strCategoryID.isEmpty()) {
291
// new
292
// CATEGORY_ID를 검사
293
int nCategoryID = Integer::parse(strCategoryID, 10, 0);
294
q.execute(
295
"SELECT CATEGORY_ID, CATEGORY_NAME"
296
"\n FROM DCL_GROUP_CATEGORY"
297
"\n WHERE CATEGORY_ID = " + String::valueOf(nCategoryID)
298
);
299
q.fetch();
300
if (!q.eof()) {
301
if (nCategoryID == SYSTEM_GROUP_CATEGORY && session.isSysAdmin())
302
nCM = CM_INSERT;
303
else if (nCategoryID >= DEFAULT_GROUP_CATEGORY && !session.isSysGuest())
304
nCM = CM_INSERT;
305
else {
306
// Permission Denied
307
__DCL_TRACE2(L"%d, %d\n", nCategoryID, session.__nRoleID);
308
}
309
}
310
else {
311
// invalid CATEGORY_ID
312
__DCL_TRACE1(L"invalid CATEGORY_ID: %d\n", nCategoryID);
313
}
314
}
315
else {
316
// modify
317
if (strGroupID.isEmpty()) {
318
if (session.isSysAdmin() || session.isMemberAdmin()) {
319
nCM = CM_MODIFY;
320
strGroupID = String::valueOf(__pPage->site()->nUserID);
321
}
322
}
323
else {
324
if (session.isSysAdmin())
325
nCM = CM_MODIFY;
326
}
327
}
328
329
if (nCM == CM_INVALID)
330
return;
331
else if (nCM == CM_INSERT) {
332
assign(q.fields(), L"");
333
}
334
else {
335
// CM_MODIFY
336
q.execute(
337
"SELECT G.GROUP_ID, G.CATEGORY_ID, G.SIGN_ID, G.GROUP_NAME"
338
", G.OPEN_TYPE, G.COMMENT"
339
", C.CATEGORY_NAME"
340
"\n FROM DCL_GROUP AS G"
341
"\n INNER JOIN DCL_GROUP_CATEGORY AS C ON (G.CATEGORY_ID = C.CATEGORY_ID)"
342
"\n WHERE G.GROUP_ID = " + strGroupID
343
);
344
q.fetch();
345
if (!q.eof())
346
assign(q.fields(), L"");
347
else
348
return;
349
}
350
351
FormView::onPrint();
352
}
353
354
void GroupWriteForm::onPost()
355
__DCL_THROWS1(Exception*)
356
{
357
}
358
359
IMPLEMENT_CLASSINFO_EX(GroupDetailView, HtmlView)
360
361
GroupDetailView::GroupDetailView(HtmlPage* pPage)
362
: HtmlView(pPage)
363
{
364
}
365
366
void GroupDetailView::init(SQLFields& fields)
367
__DCL_THROWS1(Exception*)
368
{
369
HtmlView::init(fields);
370
371
__mapParams.lookup(L"LIST", __strListPage);
372
__mapParams.lookup(L"WRITE", __strWritePage);
373
}
374
375
void GroupDetailView::onPrint()
376
__DCL_THROWS1(Exception*)
377
{
378
Session& session = *(__pPage->session());
379
ListedStringToStringArrayMap& mapQuery = session.__ctx.__queryMap;
380
SQLQuery& q = session.__query;
381
382
String strListPage = getDefault(mapQuery, L"list");
383
String strListPageEnc;
384
String strWritePage = __strWritePage;
385
if (strListPage.isEmpty())
386
strListPage = __strListPage;
387
388
strListPageEnc = URLEncoder::encode(strListPage);
389
390
assign(L"LIST", strListPage);
391
assign(L"_LIST", strListPageEnc);
392
assign(L"WRITE", strWritePage);
393
394
String strGroupIDs = mapQuery[L"group"].toString(L',', false);
395
396
TextTemplate& GROUP = (*this)[L"GROUP"];
397
TextTemplate& EMPTY = (*this)[L"EMPTY"];
398
399
if (strGroupIDs.isEmpty()) {
400
assign(L"EMPTY", EMPTY);
401
HtmlView::onPrint();
402
return;
403
}
404
405
q.execute(
406
"SELECT G.GROUP_ID, G.SIGN_ID, G.GROUP_NAME, G.OPEN_TYPE"
407
", G.REGIST_DATE, G.COMMENT"
408
", G.TODAY, G.TODAY_NUSER, G.TODAY_NVISIT, G.TODAY_NMESSAGE"
409
", G.NUSER, G.NVISIT, G.NMESSAGE"
410
", C.CATEGORY_NAME, U.USER_NAME AS OWNER_NAME"
411
"\n FROM DCL_GROUP AS G"
412
"\n INNER JOIN DCL_GROUP_CATEGORY AS C ON (G.CATEGORY_ID = C.CATEGORY_ID)"
413
"\n INNER JOIN DCL_USER AS U ON (G.OWNER_ID = U.USER_ID)"
414
"\n WHERE G.GROUP_ID IN (L" + strGroupIDs + L")"
415
"\n ORDER BY G.GROUP_ID ASC"
416
);
417
418
q.fetch();
419
if (q.eof())
420
assign(L"EMPTY", EMPTY);
421
else {
422
do {
423
GROUP.assign(q.fields(), L" ");
424
425
SQLField& field = q.fields().byName(L"COMMENT");
426
if (!field.isNull()) {
427
String strComment = field.asString();
428
if (!strComment.isEmpty())
429
strComment = Html::format(
430
strComment,
431
4, // TAB 문자를 4개의 ' '로 변환
432
String(), // 빈 문자열
433
"<br>"
434
);
435
else
436
strComment = L" ";
437
438
GROUP.assign(L"COMMENT", strComment);
439
}
440
441
GROUP.assign(L"LIST", strListPage);
442
GROUP.assign(L"_LIST", strListPageEnc);
443
GROUP.assign(L"WRITE", strWritePage);
444
append(L"GROUP", GROUP);
445
446
q.fetch();
447
} while(!q.eof());
448
}
449
HtmlView::onPrint();
450
}
451
452
IMPLEMENT_CLASSINFO_EX(GroupSearchForm, FormView)
453
454
GroupSearchForm::GroupSearchForm(HtmlPage* pPage)
455
: FormView(pPage)
456
{
457
}
458
459
void GroupSearchForm::onPrint()
460
__DCL_THROWS1(Exception*)
461
{
462
FormView::onPrint();
463
}
464
465
void GroupSearchForm::onPost()
466
__DCL_THROWS1(Exception*)
467
{
468
}
469
*/
470
471
__DCL_END_NAMESPACE
__THIS_FILE__
#define __THIS_FILE__
Definition
_trace.h:14
Config.h
char_t
wchar_t char_t
Definition
Config.h:247
HtmlPage.h
LinkUtility.h
__T
#define __T(str)
Definition
Object.h:60
URI.h
User.h
hse
HSAFastPage
Group.cpp
Generated by
1.14.0