1
|
|
|
<?php |
2
|
|
|
/* Copyright (C) XEHub <https://www.xehub.io> */ |
3
|
|
|
/** |
4
|
|
|
* documentController class |
5
|
|
|
* document the module's controller class |
6
|
|
|
* |
7
|
|
|
* @author XEHub ([email protected]) |
8
|
|
|
* @package /modules/document |
9
|
|
|
* @version 0.1 |
10
|
|
|
*/ |
11
|
|
|
class documentController extends document |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Initialization |
15
|
|
|
* @return void |
16
|
|
|
*/ |
17
|
|
|
function init() |
18
|
|
|
{ |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Action to handle vote-up of the post (Up) |
23
|
|
|
* @return BaseObject |
24
|
|
|
*/ |
25
|
|
View Code Duplication |
function procDocumentVoteUp() |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
if(!Context::get('is_logged')) return new BaseObject(-1, 'msg_invalid_request'); |
28
|
|
|
|
29
|
|
|
$document_srl = Context::get('target_srl'); |
30
|
|
|
if(!$document_srl) return new BaseObject(-1, 'msg_invalid_request'); |
31
|
|
|
|
32
|
|
|
$oDocumentModel = getModel('document'); |
33
|
|
|
$oDocument = $oDocumentModel->getDocument($document_srl, false, false); |
34
|
|
|
$module_srl = $oDocument->get('module_srl'); |
35
|
|
|
if(!$module_srl) return new BaseObject(-1, 'msg_invalid_request'); |
36
|
|
|
|
37
|
|
|
$oModuleModel = getModel('module'); |
38
|
|
|
$document_config = $oModuleModel->getModulePartConfig('document',$module_srl); |
39
|
|
|
if($document_config->use_vote_up=='N') return new BaseObject(-1, 'msg_invalid_request'); |
40
|
|
|
|
41
|
|
|
$point = 1; |
42
|
|
|
$output = $this->updateVotedCount($document_srl, $point); |
43
|
|
|
$this->add('voted_count', $output->get('voted_count')); |
44
|
|
|
return $output; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* insert alias |
49
|
|
|
* @param int $module_srl |
50
|
|
|
* @param int $document_srl |
51
|
|
|
* @param string $alias_title |
52
|
|
|
* @return object |
53
|
|
|
*/ |
54
|
|
|
function insertAlias($module_srl, $document_srl, $alias_title) |
55
|
|
|
{ |
56
|
|
|
$args = new stdClass; |
57
|
|
|
$args->alias_srl = getNextSequence(); |
58
|
|
|
$args->module_srl = $module_srl; |
59
|
|
|
$args->document_srl = $document_srl; |
60
|
|
|
$args->alias_title = urldecode($alias_title); |
61
|
|
|
$query = "document.insertAlias"; |
62
|
|
|
$output = executeQuery($query, $args); |
63
|
|
|
return $output; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Action to handle vote-up of the post (Down) |
68
|
|
|
* @return BaseObject |
69
|
|
|
*/ |
70
|
|
View Code Duplication |
function procDocumentVoteDown() |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
if(!Context::get('is_logged')) return new BaseObject(-1, 'msg_invalid_request'); |
73
|
|
|
|
74
|
|
|
$document_srl = Context::get('target_srl'); |
75
|
|
|
if(!$document_srl) return new BaseObject(-1, 'msg_invalid_request'); |
76
|
|
|
|
77
|
|
|
$oDocumentModel = getModel('document'); |
78
|
|
|
$oDocument = $oDocumentModel->getDocument($document_srl, false, false); |
79
|
|
|
$module_srl = $oDocument->get('module_srl'); |
80
|
|
|
if(!$module_srl) return new BaseObject(-1, 'msg_invalid_request'); |
81
|
|
|
|
82
|
|
|
$oModuleModel = getModel('module'); |
83
|
|
|
$document_config = $oModuleModel->getModulePartConfig('document',$module_srl); |
84
|
|
|
if($document_config->use_vote_down=='N') return new BaseObject(-1, 'msg_invalid_request'); |
85
|
|
|
|
86
|
|
|
$point = -1; |
87
|
|
|
$output = $this->updateVotedCount($document_srl, $point); |
88
|
|
|
$this->add('blamed_count', $output->get('blamed_count')); |
89
|
|
|
return $output; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Action called when the post is reported by other member |
94
|
|
|
* @return void|BaseObject |
95
|
|
|
*/ |
96
|
|
View Code Duplication |
function procDocumentDeclare() |
|
|
|
|
97
|
|
|
{ |
98
|
|
|
if(!Context::get('is_logged')) return new BaseObject(-1, 'msg_invalid_request'); |
99
|
|
|
|
100
|
|
|
$document_srl = Context::get('target_srl'); |
101
|
|
|
if(!$document_srl) return new BaseObject(-1, 'msg_invalid_request'); |
102
|
|
|
|
103
|
|
|
return $this->declaredDocument($document_srl); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Delete alias when module deleted |
108
|
|
|
* @param int $module_srl |
109
|
|
|
* @return void |
110
|
|
|
*/ |
111
|
|
|
function deleteDocumentAliasByModule($module_srl) |
112
|
|
|
{ |
113
|
|
|
$args = new stdClass(); |
114
|
|
|
$args->module_srl = $module_srl; |
115
|
|
|
executeQuery("document.deleteAlias", $args); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Delete alias when document deleted |
120
|
|
|
* @param int $document_srl |
121
|
|
|
* @return void |
122
|
|
|
*/ |
123
|
|
|
function deleteDocumentAliasByDocument($document_srl) |
124
|
|
|
{ |
125
|
|
|
$args = new stdClass(); |
126
|
|
|
$args->document_srl = $document_srl; |
127
|
|
|
executeQuery("document.deleteAlias", $args); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Delete document history |
132
|
|
|
* @param int $history_srl |
133
|
|
|
* @param int $document_srl |
134
|
|
|
* @param int $module_srl |
135
|
|
|
* @return void |
136
|
|
|
*/ |
137
|
|
|
function deleteDocumentHistory($history_srl, $document_srl, $module_srl) |
138
|
|
|
{ |
139
|
|
|
$args = new stdClass(); |
140
|
|
|
$args->history_srl = $history_srl; |
141
|
|
|
$args->module_srl = $module_srl; |
142
|
|
|
$args->document_srl = $document_srl; |
143
|
|
|
if(!$args->history_srl && !$args->module_srl && !$args->document_srl) return; |
144
|
|
|
executeQuery("document.deleteHistory", $args); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* A trigger to delete all posts together when the module is deleted |
149
|
|
|
* @param object $obj |
150
|
|
|
* @return BaseObject |
151
|
|
|
*/ |
152
|
|
|
function triggerDeleteModuleDocuments(&$obj) |
153
|
|
|
{ |
154
|
|
|
$module_srl = $obj->module_srl; |
155
|
|
|
if(!$module_srl) return new BaseObject(); |
156
|
|
|
// Delete the document |
157
|
|
|
$oDocumentAdminController = getAdminController('document'); |
158
|
|
|
$output = $oDocumentAdminController->deleteModuleDocument($module_srl); |
159
|
|
|
if(!$output->toBool()) return $output; |
160
|
|
|
// Delete the category |
161
|
|
|
$oDocumentController = getController('document'); |
162
|
|
|
$output = $oDocumentController->deleteModuleCategory($module_srl); |
163
|
|
|
if(!$output->toBool()) return $output; |
164
|
|
|
// Delete extra key and variable, because module deleted |
165
|
|
|
$this->deleteDocumentExtraKeys($module_srl); |
166
|
|
|
|
167
|
|
|
// remove aliases |
168
|
|
|
$this->deleteDocumentAliasByModule($module_srl); |
169
|
|
|
|
170
|
|
|
// remove histories |
171
|
|
|
$this->deleteDocumentHistory(null, null, $module_srl); |
172
|
|
|
|
173
|
|
|
return new BaseObject(); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Grant a permisstion of the document |
178
|
|
|
* Available in the current connection with session value |
179
|
|
|
* @param int $document_srl |
180
|
|
|
* @return void |
181
|
|
|
*/ |
182
|
|
|
function addGrant($document_srl) |
183
|
|
|
{ |
184
|
|
|
$_SESSION['own_document'][$document_srl] = true; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Insert the document |
189
|
|
|
* @param object $obj |
190
|
|
|
* @param bool $manual_inserted |
191
|
|
|
* @param bool $isRestore |
192
|
|
|
* @return object |
193
|
|
|
*/ |
194
|
|
|
function insertDocument($obj, $manual_inserted = false, $isRestore = false, $isLatest = true) |
195
|
|
|
{ |
196
|
|
|
if(!$manual_inserted && !checkCSRF()) |
197
|
|
|
{ |
198
|
|
|
return new BaseObject(-1, 'msg_invalid_request'); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
// begin transaction |
202
|
|
|
$oDB = &DB::getInstance(); |
203
|
|
|
$oDB->begin(); |
204
|
|
|
// List variables |
205
|
|
|
if($obj->comment_status) $obj->commentStatus = $obj->comment_status; |
206
|
|
|
if(!$obj->commentStatus) $obj->commentStatus = 'DENY'; |
207
|
|
|
if($obj->commentStatus == 'DENY') $this->_checkCommentStatusForOldVersion($obj); |
208
|
|
|
if($obj->allow_trackback!='Y') $obj->allow_trackback = 'N'; |
209
|
|
View Code Duplication |
if($obj->homepage) |
210
|
|
|
{ |
211
|
|
|
$obj->homepage = escape($obj->homepage); |
212
|
|
|
if(!preg_match('/^[a-z]+:\/\//i',$obj->homepage)) |
213
|
|
|
{ |
214
|
|
|
$obj->homepage = 'http://'.$obj->homepage; |
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
if($obj->notify_message != 'Y') $obj->notify_message = 'N'; |
219
|
|
|
if(!$obj->email_address) $obj->email_address = ''; |
220
|
|
|
if(!$isRestore) $obj->ipaddress = $_SERVER['REMOTE_ADDR']; |
221
|
|
|
|
222
|
|
|
// can modify regdate only manager |
223
|
|
|
$grant = Context::get('grant'); |
224
|
|
|
if(!$grant->manager) |
225
|
|
|
{ |
226
|
|
|
unset($obj->regdate); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
// Serialize the $extra_vars, check the extra_vars type, because duplicate serialized avoid |
230
|
|
|
if(!is_string($obj->extra_vars)) $obj->extra_vars = serialize($obj->extra_vars); |
231
|
|
|
// Remove the columns for automatic saving |
232
|
|
|
unset($obj->_saved_doc_srl); |
233
|
|
|
unset($obj->_saved_doc_title); |
234
|
|
|
unset($obj->_saved_doc_content); |
235
|
|
|
unset($obj->_saved_doc_message); |
236
|
|
|
// Call a trigger (before) |
237
|
|
|
$output = ModuleHandler::triggerCall('document.insertDocument', 'before', $obj); |
238
|
|
|
if(!$output->toBool()) return $output; |
239
|
|
|
// Register it if no given document_srl exists |
240
|
|
View Code Duplication |
if(!$obj->document_srl) $obj->document_srl = getNextSequence(); |
241
|
|
|
elseif(!$manual_inserted && !$isRestore && !checkUserSequence($obj->document_srl)) return new BaseObject(-1, 'msg_not_permitted'); |
242
|
|
|
|
243
|
|
|
$oDocumentModel = getModel('document'); |
244
|
|
|
// Set to 0 if the category_srl doesn't exist |
245
|
|
|
if($obj->category_srl) |
246
|
|
|
{ |
247
|
|
|
$category_list = $oDocumentModel->getCategoryList($obj->module_srl); |
248
|
|
|
if(count($category_list) > 0 && !$category_list[$obj->category_srl]->grant) |
249
|
|
|
{ |
250
|
|
|
return new BaseObject(-1, 'msg_not_permitted'); |
251
|
|
|
} |
252
|
|
|
if(count($category_list) > 0 && !$category_list[$obj->category_srl]) $obj->category_srl = 0; |
253
|
|
|
} |
254
|
|
|
// Set the read counts and update order. |
255
|
|
|
if(!$obj->readed_count) $obj->readed_count = 0; |
256
|
|
|
if($isLatest) $obj->update_order = $obj->list_order = $obj->document_srl * -1; |
257
|
|
|
else $obj->update_order = $obj->list_order; |
258
|
|
|
// Check the status of password hash for manually inserting. Apply hashing for otherwise. |
259
|
|
|
if($obj->password && !$obj->password_is_hashed) |
260
|
|
|
{ |
261
|
|
|
$obj->password = getModel('member')->hashPassword($obj->password); |
|
|
|
|
262
|
|
|
} |
263
|
|
|
// Insert member's information only if the member is logged-in and not manually registered. |
264
|
|
|
$logged_info = Context::get('logged_info'); |
265
|
|
|
if(Context::get('is_logged') && !$manual_inserted && !$isRestore) |
266
|
|
|
{ |
267
|
|
|
$obj->member_srl = $logged_info->member_srl; |
268
|
|
|
|
269
|
|
|
// user_id, user_name and nick_name already encoded |
270
|
|
|
$obj->user_id = htmlspecialchars_decode($logged_info->user_id); |
271
|
|
|
$obj->user_name = htmlspecialchars_decode($logged_info->user_name); |
272
|
|
|
$obj->nick_name = htmlspecialchars_decode($logged_info->nick_name); |
273
|
|
|
$obj->email_address = $logged_info->email_address; |
274
|
|
|
$obj->homepage = $logged_info->homepage; |
275
|
|
|
} |
276
|
|
|
// If the tile is empty, extract string from the contents. |
277
|
|
|
$obj->title = htmlspecialchars($obj->title, ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
278
|
|
|
settype($obj->title, "string"); |
279
|
|
View Code Duplication |
if($obj->title == '') $obj->title = cut_str(trim(strip_tags(nl2br($obj->content))),20,'...'); |
280
|
|
|
// If no tile extracted from the contents, leave it untitled. |
281
|
|
|
if($obj->title == '') $obj->title = 'Untitled'; |
282
|
|
|
// Remove XE's own tags from the contents. |
283
|
|
|
$obj->content = preg_replace('!<\!--(Before|After)(Document|Comment)\(([0-9]+),([0-9]+)\)-->!is', '', $obj->content); |
284
|
|
View Code Duplication |
if(Mobile::isFromMobilePhone() && $obj->use_editor != 'Y') |
285
|
|
|
{ |
286
|
|
|
if($obj->use_html != 'Y') |
287
|
|
|
{ |
288
|
|
|
$obj->content = htmlspecialchars($obj->content, ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
289
|
|
|
} |
290
|
|
|
$obj->content = nl2br($obj->content); |
291
|
|
|
} |
292
|
|
|
// Remove iframe and script if not a top adminisrator in the session. |
293
|
|
|
if($logged_info->is_admin != 'Y') $obj->content = removeHackTag($obj->content); |
294
|
|
|
// An error appears if both log-in info and user name don't exist. |
295
|
|
|
if(!$logged_info->member_srl && !$obj->nick_name) return new BaseObject(-1,'msg_invalid_request'); |
296
|
|
|
|
297
|
|
|
$obj->lang_code = Context::getLangType(); |
298
|
|
|
// Insert data into the DB |
299
|
|
|
if(!$obj->status) $this->_checkDocumentStatusForOldVersion($obj); |
300
|
|
|
$output = executeQuery('document.insertDocument', $obj); |
301
|
|
|
if(!$output->toBool()) |
302
|
|
|
{ |
303
|
|
|
$oDB->rollback(); |
304
|
|
|
return $output; |
305
|
|
|
} |
306
|
|
|
// Insert extra variables if the document successfully inserted. |
307
|
|
|
$extra_keys = $oDocumentModel->getExtraKeys($obj->module_srl); |
308
|
|
View Code Duplication |
if(count($extra_keys)) |
309
|
|
|
{ |
310
|
|
|
foreach($extra_keys as $idx => $extra_item) |
311
|
|
|
{ |
312
|
|
|
$value = NULL; |
313
|
|
|
if(isset($obj->{'extra_vars'.$idx})) |
314
|
|
|
{ |
315
|
|
|
$tmp = $obj->{'extra_vars'.$idx}; |
316
|
|
|
if(is_array($tmp)) |
317
|
|
|
$value = implode('|@|', $tmp); |
318
|
|
|
else |
319
|
|
|
$value = trim($tmp); |
320
|
|
|
} |
321
|
|
|
else if(isset($obj->{$extra_item->name})) $value = trim($obj->{$extra_item->name}); |
322
|
|
|
if($value == NULL) continue; |
|
|
|
|
323
|
|
|
|
324
|
|
|
$this->insertDocumentExtraVar($obj->module_srl, $obj->document_srl, $idx, $value, $extra_item->eid); |
325
|
|
|
} |
326
|
|
|
} |
327
|
|
|
// Update the category if the category_srl exists. |
328
|
|
|
if($obj->category_srl) $this->updateCategoryCount($obj->module_srl, $obj->category_srl); |
329
|
|
|
// Call a trigger (after) |
330
|
|
View Code Duplication |
if($output->toBool()) |
331
|
|
|
{ |
332
|
|
|
$trigger_output = ModuleHandler::triggerCall('document.insertDocument', 'after', $obj); |
333
|
|
|
if(!$trigger_output->toBool()) |
334
|
|
|
{ |
335
|
|
|
$oDB->rollback(); |
336
|
|
|
return $trigger_output; |
337
|
|
|
} |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
// commit |
341
|
|
|
$oDB->commit(); |
342
|
|
|
|
343
|
|
|
// return |
344
|
|
|
if(!$manual_inserted) |
345
|
|
|
{ |
346
|
|
|
$this->addGrant($obj->document_srl); |
347
|
|
|
} |
348
|
|
|
$output->add('document_srl',$obj->document_srl); |
349
|
|
|
$output->add('category_srl',$obj->category_srl); |
350
|
|
|
|
351
|
|
|
return $output; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* Update the document |
356
|
|
|
* @param object $source_obj |
357
|
|
|
* @param object $obj |
358
|
|
|
* @param bool $manual_updated |
359
|
|
|
* @return object |
360
|
|
|
*/ |
361
|
|
|
function updateDocument($source_obj, $obj, $manual_updated = FALSE) |
362
|
|
|
{ |
363
|
|
|
$logged_info = Context::get('logged_info'); |
364
|
|
|
|
365
|
|
|
if(!$manual_updated && !checkCSRF()) |
366
|
|
|
{ |
367
|
|
|
return new BaseObject(-1, 'msg_invalid_request'); |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
if(!$source_obj->document_srl || !$obj->document_srl) return new BaseObject(-1,'msg_invalied_request'); |
371
|
|
|
if(!$obj->status && $obj->is_secret == 'Y') $obj->status = 'SECRET'; |
372
|
|
|
if(!$obj->status) $obj->status = 'PUBLIC'; |
373
|
|
|
|
374
|
|
|
// Call a trigger (before) |
375
|
|
|
$output = ModuleHandler::triggerCall('document.updateDocument', 'before', $obj); |
376
|
|
|
if(!$output->toBool()) return $output; |
377
|
|
|
|
378
|
|
|
// begin transaction |
379
|
|
|
$oDB = &DB::getInstance(); |
380
|
|
|
$oDB->begin(); |
381
|
|
|
|
382
|
|
|
$oModuleModel = getModel('module'); |
383
|
|
|
if(!$obj->module_srl) $obj->module_srl = $source_obj->get('module_srl'); |
384
|
|
|
$module_srl = $obj->module_srl; |
385
|
|
|
$document_config = $oModuleModel->getModulePartConfig('document', $module_srl); |
386
|
|
|
if(!$document_config) |
387
|
|
|
{ |
388
|
|
|
$document_config = new stdClass(); |
389
|
|
|
} |
390
|
|
|
if(!isset($document_config->use_history)) $document_config->use_history = 'N'; |
391
|
|
|
$bUseHistory = $document_config->use_history == 'Y' || $document_config->use_history == 'Trace'; |
392
|
|
|
|
393
|
|
|
if($bUseHistory) |
394
|
|
|
{ |
395
|
|
|
$args = new stdClass; |
396
|
|
|
$args->history_srl = getNextSequence(); |
397
|
|
|
$args->document_srl = $obj->document_srl; |
398
|
|
|
$args->module_srl = $module_srl; |
399
|
|
|
if($document_config->use_history == 'Y') $args->content = $source_obj->get('content'); |
400
|
|
|
$args->nick_name = $source_obj->get('nick_name'); |
401
|
|
|
$args->member_srl = $source_obj->get('member_srl'); |
402
|
|
|
$args->regdate = $source_obj->get('last_update'); |
403
|
|
|
$args->ipaddress = $_SERVER['REMOTE_ADDR']; |
404
|
|
|
$output = executeQuery("document.insertHistory", $args); |
|
|
|
|
405
|
|
|
} |
406
|
|
|
else |
407
|
|
|
{ |
408
|
|
|
$obj->ipaddress = $source_obj->get('ipaddress'); |
409
|
|
|
} |
410
|
|
|
// List variables |
411
|
|
|
if($obj->comment_status) $obj->commentStatus = $obj->comment_status; |
412
|
|
|
if(!$obj->commentStatus) $obj->commentStatus = 'DENY'; |
413
|
|
|
if($obj->commentStatus == 'DENY') $this->_checkCommentStatusForOldVersion($obj); |
414
|
|
|
if($obj->allow_trackback!='Y') $obj->allow_trackback = 'N'; |
415
|
|
View Code Duplication |
if($obj->homepage) |
416
|
|
|
{ |
417
|
|
|
$obj->homepage = escape($obj->homepage); |
418
|
|
|
if(!preg_match('/^[a-z]+:\/\//i',$obj->homepage)) |
419
|
|
|
{ |
420
|
|
|
$obj->homepage = 'http://'.$obj->homepage; |
421
|
|
|
} |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
if($obj->notify_message != 'Y') $obj->notify_message = 'N'; |
425
|
|
|
|
426
|
|
|
// can modify regdate only manager |
427
|
|
|
$grant = Context::get('grant'); |
428
|
|
|
if(!$grant->manager) |
429
|
|
|
{ |
430
|
|
|
unset($obj->regdate); |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
// Serialize the $extra_vars |
434
|
|
|
if(!is_string($obj->extra_vars)) $obj->extra_vars = serialize($obj->extra_vars); |
435
|
|
|
// Remove the columns for automatic saving |
436
|
|
|
unset($obj->_saved_doc_srl); |
437
|
|
|
unset($obj->_saved_doc_title); |
438
|
|
|
unset($obj->_saved_doc_content); |
439
|
|
|
unset($obj->_saved_doc_message); |
440
|
|
|
|
441
|
|
|
$oDocumentModel = getModel('document'); |
442
|
|
|
// Set the category_srl to 0 if the changed category is not exsiting. |
443
|
|
|
if($source_obj->get('category_srl')!=$obj->category_srl) |
444
|
|
|
{ |
445
|
|
|
$category_list = $oDocumentModel->getCategoryList($obj->module_srl); |
446
|
|
|
if(!$category_list[$obj->category_srl]) $obj->category_srl = 0; |
447
|
|
|
} |
448
|
|
|
// Change the update order |
449
|
|
|
$obj->update_order = getNextSequence() * -1; |
450
|
|
|
// Hash the password if it exists |
451
|
|
|
if($obj->password) |
452
|
|
|
{ |
453
|
|
|
$obj->password = getModel('member')->hashPassword($obj->password); |
|
|
|
|
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
// If an author is identical to the modifier or history is used, use the logged-in user's information. |
457
|
|
|
if(Context::get('is_logged') && !$manual_updated) |
458
|
|
|
{ |
459
|
|
|
if($source_obj->get('member_srl')==$logged_info->member_srl) |
460
|
|
|
{ |
461
|
|
|
$obj->member_srl = $logged_info->member_srl; |
462
|
|
|
$obj->user_name = htmlspecialchars_decode($logged_info->user_name); |
463
|
|
|
$obj->nick_name = htmlspecialchars_decode($logged_info->nick_name); |
464
|
|
|
$obj->email_address = $logged_info->email_address; |
465
|
|
|
$obj->homepage = $logged_info->homepage; |
466
|
|
|
} |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
// For the document written by logged-in user however no nick_name exists |
470
|
|
View Code Duplication |
if($source_obj->get('member_srl')&& !$obj->nick_name) |
471
|
|
|
{ |
472
|
|
|
$obj->member_srl = $source_obj->get('member_srl'); |
473
|
|
|
$obj->user_name = $source_obj->get('user_name'); |
474
|
|
|
$obj->nick_name = $source_obj->get('nick_name'); |
475
|
|
|
$obj->email_address = $source_obj->get('email_address'); |
476
|
|
|
$obj->homepage = $source_obj->get('homepage'); |
477
|
|
|
} |
478
|
|
|
// If the tile is empty, extract string from the contents. |
479
|
|
|
$obj->title = htmlspecialchars($obj->title, ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
480
|
|
|
settype($obj->title, "string"); |
481
|
|
View Code Duplication |
if($obj->title == '') $obj->title = cut_str(strip_tags($obj->content),20,'...'); |
482
|
|
|
// If no tile extracted from the contents, leave it untitled. |
483
|
|
|
if($obj->title == '') $obj->title = 'Untitled'; |
484
|
|
|
// Remove XE's own tags from the contents. |
485
|
|
|
$obj->content = preg_replace('!<\!--(Before|After)(Document|Comment)\(([0-9]+),([0-9]+)\)-->!is', '', $obj->content); |
486
|
|
View Code Duplication |
if(Mobile::isFromMobilePhone() && $obj->use_editor != 'Y') |
487
|
|
|
{ |
488
|
|
|
if($obj->use_html != 'Y') |
489
|
|
|
{ |
490
|
|
|
$obj->content = htmlspecialchars($obj->content, ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
491
|
|
|
} |
492
|
|
|
$obj->content = nl2br($obj->content); |
493
|
|
|
} |
494
|
|
|
// Change not extra vars but language code of the original document if document's lang_code is different from author's setting. |
495
|
|
|
if($source_obj->get('lang_code') != Context::getLangType()) |
496
|
|
|
{ |
497
|
|
|
// Change not extra vars but language code of the original document if document's lang_code doesn't exist. |
498
|
|
|
if(!$source_obj->get('lang_code')) |
499
|
|
|
{ |
500
|
|
|
$lang_code_args->document_srl = $source_obj->get('document_srl'); |
|
|
|
|
501
|
|
|
$lang_code_args->lang_code = Context::getLangType(); |
502
|
|
|
$output = executeQuery('document.updateDocumentsLangCode', $lang_code_args); |
|
|
|
|
503
|
|
|
} |
504
|
|
|
else |
505
|
|
|
{ |
506
|
|
|
$extra_content = new stdClass; |
507
|
|
|
$extra_content->title = $obj->title; |
508
|
|
|
$extra_content->content = $obj->content; |
509
|
|
|
|
510
|
|
|
$document_args = new stdClass; |
511
|
|
|
$document_args->document_srl = $source_obj->get('document_srl'); |
512
|
|
|
$document_output = executeQuery('document.getDocument', $document_args); |
513
|
|
|
$obj->title = $document_output->data->title; |
514
|
|
|
$obj->content = $document_output->data->content; |
515
|
|
|
} |
516
|
|
|
} |
517
|
|
|
// Remove iframe and script if not a top adminisrator in the session. |
518
|
|
|
if($logged_info->is_admin != 'Y') |
519
|
|
|
{ |
520
|
|
|
$obj->content = removeHackTag($obj->content); |
521
|
|
|
} |
522
|
|
|
// if temporary document, regdate is now setting |
523
|
|
|
if($source_obj->get('status') == $this->getConfigStatus('temp')) $obj->regdate = date('YmdHis'); |
524
|
|
|
|
525
|
|
|
// Insert data into the DB |
526
|
|
|
$output = executeQuery('document.updateDocument', $obj); |
527
|
|
|
if(!$output->toBool()) |
528
|
|
|
{ |
529
|
|
|
$oDB->rollback(); |
530
|
|
|
return $output; |
531
|
|
|
} |
532
|
|
|
// Remove all extra variables |
533
|
|
|
if(Context::get('act')!='procFileDelete') |
534
|
|
|
{ |
535
|
|
|
$this->deleteDocumentExtraVars($source_obj->get('module_srl'), $obj->document_srl, null, Context::getLangType()); |
536
|
|
|
// Insert extra variables if the document successfully inserted. |
537
|
|
|
$extra_keys = $oDocumentModel->getExtraKeys($obj->module_srl); |
538
|
|
View Code Duplication |
if(count($extra_keys)) |
539
|
|
|
{ |
540
|
|
|
foreach($extra_keys as $idx => $extra_item) |
541
|
|
|
{ |
542
|
|
|
$value = NULL; |
543
|
|
|
if(isset($obj->{'extra_vars'.$idx})) |
544
|
|
|
{ |
545
|
|
|
$tmp = $obj->{'extra_vars'.$idx}; |
546
|
|
|
if(is_array($tmp)) |
547
|
|
|
$value = implode('|@|', $tmp); |
548
|
|
|
else |
549
|
|
|
$value = trim($tmp); |
550
|
|
|
} |
551
|
|
|
else if(isset($obj->{$extra_item->name})) $value = trim($obj->{$extra_item->name}); |
552
|
|
|
if($value == NULL) continue; |
|
|
|
|
553
|
|
|
$this->insertDocumentExtraVar($obj->module_srl, $obj->document_srl, $idx, $value, $extra_item->eid); |
554
|
|
|
} |
555
|
|
|
} |
556
|
|
|
// Inert extra vars for multi-language support of title and contents. |
557
|
|
View Code Duplication |
if($extra_content->title) $this->insertDocumentExtraVar($obj->module_srl, $obj->document_srl, -1, $extra_content->title, 'title_'.Context::getLangType()); |
|
|
|
|
558
|
|
View Code Duplication |
if($extra_content->content) $this->insertDocumentExtraVar($obj->module_srl, $obj->document_srl, -2, $extra_content->content, 'content_'.Context::getLangType()); |
559
|
|
|
} |
560
|
|
|
// Update the category if the category_srl exists. |
561
|
|
|
if($source_obj->get('category_srl') != $obj->category_srl || $source_obj->get('module_srl') == $logged_info->member_srl) |
562
|
|
|
{ |
563
|
|
|
if($source_obj->get('category_srl') != $obj->category_srl) $this->updateCategoryCount($obj->module_srl, $source_obj->get('category_srl')); |
564
|
|
|
if($obj->category_srl) $this->updateCategoryCount($obj->module_srl, $obj->category_srl); |
565
|
|
|
} |
566
|
|
|
// Call a trigger (after) |
567
|
|
View Code Duplication |
if($output->toBool()) |
568
|
|
|
{ |
569
|
|
|
$trigger_output = ModuleHandler::triggerCall('document.updateDocument', 'after', $obj); |
570
|
|
|
if(!$trigger_output->toBool()) |
571
|
|
|
{ |
572
|
|
|
$oDB->rollback(); |
573
|
|
|
return $trigger_output; |
574
|
|
|
} |
575
|
|
|
} |
576
|
|
|
|
577
|
|
|
// commit |
578
|
|
|
$oDB->commit(); |
579
|
|
|
// Remove the thumbnail file |
580
|
|
|
FileHandler::removeDir(sprintf('files/thumbnails/%s',getNumberingPath($obj->document_srl, 3))); |
581
|
|
|
|
582
|
|
|
$output->add('document_srl',$obj->document_srl); |
583
|
|
|
//remove from cache |
584
|
|
|
$oCacheHandler = CacheHandler::getInstance('object'); |
585
|
|
View Code Duplication |
if($oCacheHandler->isSupport()) |
586
|
|
|
{ |
587
|
|
|
//remove document item from cache |
588
|
|
|
$cache_key = 'document_item:'. getNumberingPath($obj->document_srl) . $obj->document_srl; |
589
|
|
|
$oCacheHandler->delete($cache_key); |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
return $output; |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
/** |
596
|
|
|
* Deleting Documents |
597
|
|
|
* @param int $document_srl |
598
|
|
|
* @param bool $is_admin |
599
|
|
|
* @param bool $isEmptyTrash |
600
|
|
|
* @param documentItem $oDocument |
601
|
|
|
* @return object |
602
|
|
|
*/ |
603
|
|
|
function deleteDocument($document_srl, $is_admin = false, $isEmptyTrash = false, $oDocument = null) |
604
|
|
|
{ |
605
|
|
|
// Call a trigger (before) |
606
|
|
|
$trigger_obj = new stdClass(); |
607
|
|
|
$trigger_obj->document_srl = $document_srl; |
608
|
|
|
$output = ModuleHandler::triggerCall('document.deleteDocument', 'before', $trigger_obj); |
609
|
|
|
if(!$output->toBool()) return $output; |
610
|
|
|
|
611
|
|
|
// begin transaction |
612
|
|
|
$oDB = &DB::getInstance(); |
613
|
|
|
$oDB->begin(); |
614
|
|
|
|
615
|
|
|
if(!$isEmptyTrash) |
616
|
|
|
{ |
617
|
|
|
// get model object of the document |
618
|
|
|
$oDocumentModel = getModel('document'); |
619
|
|
|
// Check if the documnet exists |
620
|
|
|
$oDocument = $oDocumentModel->getDocument($document_srl, $is_admin); |
621
|
|
|
} |
622
|
|
|
else if($isEmptyTrash && $oDocument == null) return new BaseObject(-1, 'document is not exists'); |
623
|
|
|
|
624
|
|
|
if(!$oDocument->isExists() || $oDocument->document_srl != $document_srl) return new BaseObject(-1, 'msg_invalid_document'); |
625
|
|
|
// Check if a permossion is granted |
626
|
|
|
if(!$oDocument->isGranted()) return new BaseObject(-1, 'msg_not_permitted'); |
627
|
|
|
|
628
|
|
|
//if empty trash, document already deleted, therefore document not delete |
629
|
|
|
$args = new stdClass(); |
630
|
|
|
$args->document_srl = $document_srl; |
631
|
|
|
if(!$isEmptyTrash) |
632
|
|
|
{ |
633
|
|
|
// Delete the document |
634
|
|
|
$output = executeQuery('document.deleteDocument', $args); |
635
|
|
|
if(!$output->toBool()) |
636
|
|
|
{ |
637
|
|
|
$oDB->rollback(); |
638
|
|
|
return $output; |
639
|
|
|
} |
640
|
|
|
} |
641
|
|
|
|
642
|
|
|
$this->deleteDocumentAliasByDocument($document_srl); |
643
|
|
|
|
644
|
|
|
$this->deleteDocumentHistory(null, $document_srl, null); |
645
|
|
|
// Update category information if the category_srl exists. |
646
|
|
|
if($oDocument->get('category_srl')) $this->updateCategoryCount($oDocument->get('module_srl'),$oDocument->get('category_srl')); |
647
|
|
|
// Delete a declared list |
648
|
|
|
executeQuery('document.deleteDeclared', $args); |
649
|
|
|
// Delete extra variable |
650
|
|
|
$this->deleteDocumentExtraVars($oDocument->get('module_srl'), $oDocument->document_srl); |
651
|
|
|
|
652
|
|
|
//this |
653
|
|
|
// Call a trigger (after) |
654
|
|
View Code Duplication |
if($output->toBool()) |
655
|
|
|
{ |
656
|
|
|
$trigger_obj = $oDocument->getObjectVars(); |
657
|
|
|
$trigger_output = ModuleHandler::triggerCall('document.deleteDocument', 'after', $trigger_obj); |
658
|
|
|
if(!$trigger_output->toBool()) |
659
|
|
|
{ |
660
|
|
|
$oDB->rollback(); |
661
|
|
|
return $trigger_output; |
662
|
|
|
} |
663
|
|
|
} |
664
|
|
|
// declared document, log delete |
665
|
|
|
$this->_deleteDeclaredDocuments($args); |
|
|
|
|
666
|
|
|
$this->_deleteDocumentReadedLog($args); |
|
|
|
|
667
|
|
|
$this->_deleteDocumentVotedLog($args); |
|
|
|
|
668
|
|
|
|
669
|
|
|
// Remove the thumbnail file |
670
|
|
|
FileHandler::removeDir(sprintf('files/thumbnails/%s',getNumberingPath($document_srl, 3))); |
671
|
|
|
|
672
|
|
|
// commit |
673
|
|
|
$oDB->commit(); |
674
|
|
|
|
675
|
|
|
//remove from cache |
676
|
|
|
$oCacheHandler = CacheHandler::getInstance('object'); |
677
|
|
|
if($oCacheHandler->isSupport()) |
678
|
|
|
{ |
679
|
|
|
$cache_key = 'document_item:'. getNumberingPath($document_srl) . $document_srl; |
680
|
|
|
$oCacheHandler->delete($cache_key); |
681
|
|
|
} |
682
|
|
|
|
683
|
|
|
return $output; |
684
|
|
|
} |
685
|
|
|
|
686
|
|
|
/** |
687
|
|
|
* Delete declared document, log |
688
|
|
|
* @param string $documentSrls (ex: 1, 2,56, 88) |
689
|
|
|
* @return void |
690
|
|
|
*/ |
691
|
|
|
function _deleteDeclaredDocuments($documentSrls) |
692
|
|
|
{ |
693
|
|
|
executeQuery('document.deleteDeclaredDocuments', $documentSrls); |
|
|
|
|
694
|
|
|
executeQuery('document.deleteDocumentDeclaredLog', $documentSrls); |
|
|
|
|
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
/** |
698
|
|
|
* Delete readed log |
699
|
|
|
* @param string $documentSrls (ex: 1, 2,56, 88) |
700
|
|
|
* @return void |
701
|
|
|
*/ |
702
|
|
|
function _deleteDocumentReadedLog($documentSrls) |
703
|
|
|
{ |
704
|
|
|
executeQuery('document.deleteDocumentReadedLog', $documentSrls); |
|
|
|
|
705
|
|
|
} |
706
|
|
|
|
707
|
|
|
/** |
708
|
|
|
* Delete voted log |
709
|
|
|
* @param string $documentSrls (ex: 1, 2,56, 88) |
710
|
|
|
* @return void |
711
|
|
|
*/ |
712
|
|
|
function _deleteDocumentVotedLog($documentSrls) |
713
|
|
|
{ |
714
|
|
|
executeQuery('document.deleteDocumentVotedLog', $documentSrls); |
|
|
|
|
715
|
|
|
} |
716
|
|
|
|
717
|
|
|
/** |
718
|
|
|
* Move the doc into the trash |
719
|
|
|
* @param object $obj |
720
|
|
|
* @return object |
721
|
|
|
*/ |
722
|
|
|
function moveDocumentToTrash($obj) |
723
|
|
|
{ |
724
|
|
|
$trash_args = new stdClass(); |
725
|
|
|
// Get trash_srl if a given trash_srl doesn't exist |
726
|
|
|
if(!$obj->trash_srl) $trash_args->trash_srl = getNextSequence(); |
727
|
|
|
else $trash_args->trash_srl = $obj->trash_srl; |
728
|
|
|
// Get its module_srl which the document belongs to |
729
|
|
|
$oDocumentModel = getModel('document'); |
730
|
|
|
$oDocument = $oDocumentModel->getDocument($obj->document_srl); |
731
|
|
|
|
732
|
|
|
$trash_args->module_srl = $oDocument->get('module_srl'); |
733
|
|
|
$obj->module_srl = $oDocument->get('module_srl'); |
734
|
|
|
// Cannot throw data from the trash to the trash |
735
|
|
|
if($trash_args->module_srl == 0) return false; |
|
|
|
|
736
|
|
|
// Data setting |
737
|
|
|
$trash_args->document_srl = $obj->document_srl; |
738
|
|
|
$trash_args->description = $obj->description; |
739
|
|
|
// Insert member's information only if the member is logged-in and not manually registered. |
740
|
|
|
if(Context::get('is_logged')&&!$manual_inserted) |
|
|
|
|
741
|
|
|
{ |
742
|
|
|
$logged_info = Context::get('logged_info'); |
743
|
|
|
$trash_args->member_srl = $logged_info->member_srl; |
744
|
|
|
|
745
|
|
|
// user_id, user_name and nick_name already encoded |
746
|
|
|
$trash_args->user_id = htmlspecialchars_decode($logged_info->user_id); |
747
|
|
|
$trash_args->user_name = htmlspecialchars_decode($logged_info->user_name); |
748
|
|
|
$trash_args->nick_name = htmlspecialchars_decode($logged_info->nick_name); |
749
|
|
|
} |
750
|
|
|
// Date setting for updating documents |
751
|
|
|
$document_args = new stdClass; |
752
|
|
|
$document_args->module_srl = 0; |
753
|
|
|
$document_args->document_srl = $obj->document_srl; |
754
|
|
|
|
755
|
|
|
// begin transaction |
756
|
|
|
$oDB = &DB::getInstance(); |
757
|
|
|
$oDB->begin(); |
758
|
|
|
|
759
|
|
|
/*$output = executeQuery('document.insertTrash', $trash_args); |
760
|
|
|
if (!$output->toBool()) { |
761
|
|
|
$oDB->rollback(); |
762
|
|
|
return $output; |
763
|
|
|
}*/ |
764
|
|
|
|
765
|
|
|
// new trash module |
766
|
|
|
require_once(_XE_PATH_.'modules/trash/model/TrashVO.php'); |
767
|
|
|
$oTrashVO = new TrashVO(); |
768
|
|
|
$oTrashVO->setTrashSrl(getNextSequence()); |
769
|
|
|
$oTrashVO->setTitle($oDocument->variables['title']); |
770
|
|
|
$oTrashVO->setOriginModule('document'); |
771
|
|
|
$oTrashVO->setSerializedObject(serialize($oDocument->variables)); |
772
|
|
|
$oTrashVO->setDescription($obj->description); |
773
|
|
|
|
774
|
|
|
$oTrashAdminController = getAdminController('trash'); |
775
|
|
|
$output = $oTrashAdminController->insertTrash($oTrashVO); |
776
|
|
|
if(!$output->toBool()) |
777
|
|
|
{ |
778
|
|
|
$oDB->rollback(); |
779
|
|
|
return $output; |
780
|
|
|
} |
781
|
|
|
|
782
|
|
|
$output = executeQuery('document.deleteDocument', $trash_args); |
783
|
|
|
if(!$output->toBool()) |
784
|
|
|
{ |
785
|
|
|
$oDB->rollback(); |
786
|
|
|
return $output; |
787
|
|
|
} |
788
|
|
|
|
789
|
|
|
/*$output = executeQuery('document.updateDocument', $document_args); |
790
|
|
|
if (!$output->toBool()) { |
791
|
|
|
$oDB->rollback(); |
792
|
|
|
return $output; |
793
|
|
|
}*/ |
794
|
|
|
|
795
|
|
|
// update category |
796
|
|
|
if($oDocument->get('category_srl')) $this->updateCategoryCount($oDocument->get('module_srl'),$oDocument->get('category_srl')); |
797
|
|
|
|
798
|
|
|
// remove thumbnails |
799
|
|
|
FileHandler::removeDir(sprintf('files/thumbnails/%s',getNumberingPath($obj->document_srl, 3))); |
800
|
|
|
// Set the attachment to be invalid state |
801
|
|
View Code Duplication |
if($oDocument->hasUploadedFiles()) |
802
|
|
|
{ |
803
|
|
|
$args = new stdClass(); |
804
|
|
|
$args->upload_target_srl = $oDocument->document_srl; |
805
|
|
|
$args->isvalid = 'N'; |
806
|
|
|
executeQuery('file.updateFileValid', $args); |
807
|
|
|
} |
808
|
|
|
// Call a trigger (after) |
809
|
|
View Code Duplication |
if($output->toBool()) |
810
|
|
|
{ |
811
|
|
|
$trigger_output = ModuleHandler::triggerCall('document.moveDocumentToTrash', 'after', $obj); |
812
|
|
|
if(!$trigger_output->toBool()) |
813
|
|
|
{ |
814
|
|
|
$oDB->rollback(); |
815
|
|
|
return $trigger_output; |
816
|
|
|
} |
817
|
|
|
} |
818
|
|
|
|
819
|
|
|
// commit |
820
|
|
|
$oDB->commit(); |
821
|
|
|
|
822
|
|
|
// Clear cache |
823
|
|
|
$oCacheHandler = CacheHandler::getInstance('object'); |
824
|
|
View Code Duplication |
if($oCacheHandler->isSupport()) |
825
|
|
|
{ |
826
|
|
|
$cache_key = 'document_item:'. getNumberingPath($oDocument->document_srl) . $oDocument->document_srl; |
827
|
|
|
$oCacheHandler->delete($cache_key); |
828
|
|
|
} |
829
|
|
|
|
830
|
|
|
return $output; |
831
|
|
|
} |
832
|
|
|
|
833
|
|
|
/** |
834
|
|
|
* Update read counts of the document |
835
|
|
|
* @param documentItem $oDocument |
836
|
|
|
* @return bool|void |
837
|
|
|
*/ |
838
|
|
|
function updateReadedCount(&$oDocument) |
839
|
|
|
{ |
840
|
|
|
// Pass if Crawler access |
841
|
|
|
if(isCrawler()) return false; |
842
|
|
|
|
843
|
|
|
$document_srl = $oDocument->document_srl; |
844
|
|
|
$member_srl = $oDocument->get('member_srl'); |
845
|
|
|
$logged_info = Context::get('logged_info'); |
846
|
|
|
|
847
|
|
|
// Call a trigger when the read count is updated (before) |
848
|
|
|
$trigger_output = ModuleHandler::triggerCall('document.updateReadedCount', 'before', $oDocument); |
849
|
|
|
if(!$trigger_output->toBool()) return $trigger_output; |
850
|
|
|
|
851
|
|
|
// Pass if read count is increaded on the session information |
852
|
|
|
if($_SESSION['readed_document'][$document_srl]) return false; |
853
|
|
|
|
854
|
|
|
// Pass if the author's IP address is as same as visitor's. |
855
|
|
|
if($oDocument->get('ipaddress') == $_SERVER['REMOTE_ADDR']) |
856
|
|
|
{ |
857
|
|
|
$_SESSION['readed_document'][$document_srl] = true; |
858
|
|
|
return false; |
859
|
|
|
} |
860
|
|
|
// Pass ater registering sesscion if the author is a member and has same information as the currently logged-in user. |
861
|
|
|
if($member_srl && $logged_info->member_srl == $member_srl) |
862
|
|
|
{ |
863
|
|
|
$_SESSION['readed_document'][$document_srl] = true; |
864
|
|
|
return false; |
865
|
|
|
} |
866
|
|
|
|
867
|
|
|
$oDB = DB::getInstance(); |
868
|
|
|
$oDB->begin(); |
869
|
|
|
|
870
|
|
|
// Update read counts |
871
|
|
|
$args = new stdClass; |
872
|
|
|
$args->document_srl = $document_srl; |
873
|
|
|
$output = executeQuery('document.updateReadedCount', $args); |
|
|
|
|
874
|
|
|
|
875
|
|
|
// Call a trigger when the read count is updated (after) |
876
|
|
|
$trigger_output = ModuleHandler::triggerCall('document.updateReadedCount', 'after', $oDocument); |
877
|
|
|
if(!$trigger_output->toBool()) |
878
|
|
|
{ |
879
|
|
|
$oDB->rollback(); |
880
|
|
|
return $trigger_output; |
881
|
|
|
} |
882
|
|
|
|
883
|
|
|
$oDB->commit(); |
884
|
|
|
|
885
|
|
|
$oCacheHandler = CacheHandler::getInstance('object'); |
886
|
|
|
if($oCacheHandler->isSupport()) |
887
|
|
|
{ |
888
|
|
|
//remove document item from cache |
889
|
|
|
$cache_key = 'document_item:'. getNumberingPath($document_srl) . $document_srl; |
890
|
|
|
$oCacheHandler->delete($cache_key); |
891
|
|
|
} |
892
|
|
|
|
893
|
|
|
// Register session |
894
|
|
|
if(!$_SESSION['banned_document'][$document_srl]) |
895
|
|
|
{ |
896
|
|
|
$_SESSION['readed_document'][$document_srl] = true; |
897
|
|
|
} |
898
|
|
|
|
899
|
|
|
return TRUE; |
900
|
|
|
} |
901
|
|
|
|
902
|
|
|
/** |
903
|
|
|
* Insert extra variables into the document table |
904
|
|
|
* @param int $module_srl |
905
|
|
|
* @param int $var_idx |
906
|
|
|
* @param string $var_name |
907
|
|
|
* @param string $var_type |
908
|
|
|
* @param string $var_is_required |
909
|
|
|
* @param string $var_search |
910
|
|
|
* @param string $var_default |
911
|
|
|
* @param string $var_desc |
912
|
|
|
* @param int $eid |
913
|
|
|
* @return object |
914
|
|
|
*/ |
915
|
|
|
function insertDocumentExtraKey($module_srl, $var_idx, $var_name, $var_type, $var_is_required = 'N', $var_search = 'N', $var_default = '', $var_desc = '', $eid) |
916
|
|
|
{ |
917
|
|
|
if(!$module_srl || !$var_idx || !$var_name || !$var_type || !$eid) return new BaseObject(-1,'msg_invalid_request'); |
918
|
|
|
|
919
|
|
|
$obj = new stdClass(); |
920
|
|
|
$obj->module_srl = $module_srl; |
921
|
|
|
$obj->var_idx = $var_idx; |
922
|
|
|
$obj->var_name = $var_name; |
923
|
|
|
$obj->var_type = $var_type; |
924
|
|
|
$obj->var_is_required = $var_is_required=='Y'?'Y':'N'; |
925
|
|
|
$obj->var_search = $var_search=='Y'?'Y':'N'; |
926
|
|
|
$obj->var_default = $var_default; |
927
|
|
|
$obj->var_desc = $var_desc; |
928
|
|
|
$obj->eid = $eid; |
929
|
|
|
|
930
|
|
|
$output = executeQuery('document.getDocumentExtraKeys', $obj); |
931
|
|
|
if(!$output->data) |
932
|
|
|
{ |
933
|
|
|
$output = executeQuery('document.insertDocumentExtraKey', $obj); |
934
|
|
|
} |
935
|
|
|
else |
936
|
|
|
{ |
937
|
|
|
$output = executeQuery('document.updateDocumentExtraKey', $obj); |
|
|
|
|
938
|
|
|
// Update the extra var(eid) |
939
|
|
|
$output = executeQuery('document.updateDocumentExtraVar', $obj); |
940
|
|
|
} |
941
|
|
|
|
942
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE); |
943
|
|
|
if($oCacheHandler->isSupport()) |
944
|
|
|
{ |
945
|
|
|
$object_key = 'module_document_extra_keys:'.$module_srl; |
946
|
|
|
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key); |
947
|
|
|
$oCacheHandler->delete($cache_key); |
948
|
|
|
} |
949
|
|
|
|
950
|
|
|
return $output; |
951
|
|
|
} |
952
|
|
|
|
953
|
|
|
/** |
954
|
|
|
* Remove the extra variables of the documents |
955
|
|
|
* @param int $module_srl |
956
|
|
|
* @param int $var_idx |
957
|
|
|
* @return BaseObject |
958
|
|
|
*/ |
959
|
|
|
function deleteDocumentExtraKeys($module_srl, $var_idx = null) |
960
|
|
|
{ |
961
|
|
|
if(!$module_srl) return new BaseObject(-1,'msg_invalid_request'); |
962
|
|
|
$obj = new stdClass(); |
963
|
|
|
$obj->module_srl = $module_srl; |
964
|
|
|
if(!is_null($var_idx)) $obj->var_idx = $var_idx; |
965
|
|
|
|
966
|
|
|
$oDB = DB::getInstance(); |
967
|
|
|
$oDB->begin(); |
968
|
|
|
|
969
|
|
|
$output = $oDB->executeQuery('document.deleteDocumentExtraKeys', $obj); |
970
|
|
|
if(!$output->toBool()) |
971
|
|
|
{ |
972
|
|
|
$oDB->rollback(); |
973
|
|
|
return $output; |
974
|
|
|
} |
975
|
|
|
|
976
|
|
|
if($var_idx != NULL) |
|
|
|
|
977
|
|
|
{ |
978
|
|
|
$output = $oDB->executeQuery('document.updateDocumentExtraKeyIdxOrder', $obj); |
979
|
|
|
if(!$output->toBool()) |
980
|
|
|
{ |
981
|
|
|
$oDB->rollback(); |
982
|
|
|
return $output; |
983
|
|
|
} |
984
|
|
|
} |
985
|
|
|
|
986
|
|
|
$output = executeQuery('document.deleteDocumentExtraVars', $obj); |
987
|
|
|
if(!$output->toBool()) |
988
|
|
|
{ |
989
|
|
|
$oDB->rollback(); |
990
|
|
|
return $output; |
991
|
|
|
} |
992
|
|
|
|
993
|
|
|
if($var_idx != NULL) |
|
|
|
|
994
|
|
|
{ |
995
|
|
|
$output = $oDB->executeQuery('document.updateDocumentExtraVarIdxOrder', $obj); |
996
|
|
|
if(!$output->toBool()) |
997
|
|
|
{ |
998
|
|
|
$oDB->rollback(); |
999
|
|
|
return $output; |
1000
|
|
|
} |
1001
|
|
|
} |
1002
|
|
|
|
1003
|
|
|
$oDB->commit(); |
1004
|
|
|
|
1005
|
|
|
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE); |
1006
|
|
|
if($oCacheHandler->isSupport()) |
1007
|
|
|
{ |
1008
|
|
|
$object_key = 'module_document_extra_keys:'.$module_srl; |
1009
|
|
|
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key); |
1010
|
|
|
$oCacheHandler->delete($cache_key); |
1011
|
|
|
} |
1012
|
|
|
|
1013
|
|
|
return new BaseObject(); |
1014
|
|
|
} |
1015
|
|
|
|
1016
|
|
|
/** |
1017
|
|
|
* Insert extra vaiable to the documents table |
1018
|
|
|
* @param int $module_srl |
1019
|
|
|
* @param int $document_srl |
1020
|
|
|
* @param int $var_idx |
1021
|
|
|
* @param mixed $value |
1022
|
|
|
* @param int $eid |
1023
|
|
|
* @param string $lang_code |
1024
|
|
|
* @return BaseObject|void |
1025
|
|
|
*/ |
1026
|
|
|
function insertDocumentExtraVar($module_srl, $document_srl, $var_idx, $value, $eid = null, $lang_code = '') |
1027
|
|
|
{ |
1028
|
|
|
if(!$module_srl || !$document_srl || !$var_idx || !isset($value)) return new BaseObject(-1,'msg_invalid_request'); |
1029
|
|
|
if(!$lang_code) $lang_code = Context::getLangType(); |
1030
|
|
|
|
1031
|
|
|
$obj = new stdClass; |
1032
|
|
|
$obj->module_srl = $module_srl; |
1033
|
|
|
$obj->document_srl = $document_srl; |
1034
|
|
|
$obj->var_idx = $var_idx; |
1035
|
|
|
$obj->value = $value; |
1036
|
|
|
$obj->lang_code = $lang_code; |
1037
|
|
|
$obj->eid = $eid; |
1038
|
|
|
|
1039
|
|
|
executeQuery('document.insertDocumentExtraVar', $obj); |
1040
|
|
|
} |
1041
|
|
|
|
1042
|
|
|
/** |
1043
|
|
|
* Remove values of extra variable from the document |
1044
|
|
|
* @param int $module_srl |
1045
|
|
|
* @param int $document_srl |
1046
|
|
|
* @param int $var_idx |
1047
|
|
|
* @param string $lang_code |
1048
|
|
|
* @param int $eid |
1049
|
|
|
* @return $output |
|
|
|
|
1050
|
|
|
*/ |
1051
|
|
|
function deleteDocumentExtraVars($module_srl, $document_srl = null, $var_idx = null, $lang_code = null, $eid = null) |
1052
|
|
|
{ |
1053
|
|
|
$obj = new stdClass(); |
1054
|
|
|
$obj->module_srl = $module_srl; |
1055
|
|
|
if(!is_null($document_srl)) $obj->document_srl = $document_srl; |
1056
|
|
|
if(!is_null($var_idx)) $obj->var_idx = $var_idx; |
1057
|
|
|
if(!is_null($lang_code)) $obj->lang_code = $lang_code; |
1058
|
|
|
if(!is_null($eid)) $obj->eid = $eid; |
1059
|
|
|
$output = executeQuery('document.deleteDocumentExtraVars', $obj); |
1060
|
|
|
return $output; |
1061
|
|
|
} |
1062
|
|
|
|
1063
|
|
|
|
1064
|
|
|
/** |
1065
|
|
|
* Increase the number of vote-up of the document |
1066
|
|
|
* @param int $document_srl |
1067
|
|
|
* @param int $point |
1068
|
|
|
* @return BaseObject |
1069
|
|
|
*/ |
1070
|
|
|
function updateVotedCount($document_srl, $point = 1) |
1071
|
|
|
{ |
1072
|
|
|
if($point > 0) $failed_voted = 'failed_voted'; |
1073
|
|
|
else $failed_voted = 'failed_blamed'; |
1074
|
|
|
// Return fail if session already has information about votes |
1075
|
|
|
if($_SESSION['voted_document'][$document_srl]) |
1076
|
|
|
{ |
1077
|
|
|
return new BaseObject(-1, $failed_voted); |
1078
|
|
|
} |
1079
|
|
|
// Get the original document |
1080
|
|
|
$oDocumentModel = getModel('document'); |
1081
|
|
|
$oDocument = $oDocumentModel->getDocument($document_srl, false, false); |
1082
|
|
|
// Pass if the author's IP address is as same as visitor's. |
1083
|
|
|
if($oDocument->get('ipaddress') == $_SERVER['REMOTE_ADDR']) |
1084
|
|
|
{ |
1085
|
|
|
$_SESSION['voted_document'][$document_srl] = true; |
1086
|
|
|
return new BaseObject(-1, $failed_voted); |
1087
|
|
|
} |
1088
|
|
|
|
1089
|
|
|
// Create a member model object |
1090
|
|
|
$oMemberModel = getModel('member'); |
1091
|
|
|
$member_srl = $oMemberModel->getLoggedMemberSrl(); |
1092
|
|
|
|
1093
|
|
|
// Check if document's author is a member. |
1094
|
|
|
if($oDocument->get('member_srl')) |
1095
|
|
|
{ |
1096
|
|
|
// Pass after registering a session if author's information is same as the currently logged-in user's. |
1097
|
|
|
if($member_srl && $member_srl == abs($oDocument->get('member_srl'))) |
1098
|
|
|
{ |
1099
|
|
|
$_SESSION['voted_document'][$document_srl] = true; |
1100
|
|
|
return new BaseObject(-1, $failed_voted); |
1101
|
|
|
} |
1102
|
|
|
} |
1103
|
|
|
|
1104
|
|
|
// Use member_srl for logged-in members and IP address for non-members. |
1105
|
|
|
$args = new stdClass; |
1106
|
|
|
if($member_srl) |
1107
|
|
|
{ |
1108
|
|
|
$args->member_srl = $member_srl; |
1109
|
|
|
} |
1110
|
|
|
else |
1111
|
|
|
{ |
1112
|
|
|
$args->ipaddress = $_SERVER['REMOTE_ADDR']; |
1113
|
|
|
} |
1114
|
|
|
$args->document_srl = $document_srl; |
1115
|
|
|
$output = executeQuery('document.getDocumentVotedLogInfo', $args); |
1116
|
|
|
// Pass after registering a session if log information has vote-up logs |
1117
|
|
|
if($output->data->count) |
1118
|
|
|
{ |
1119
|
|
|
$_SESSION['voted_document'][$document_srl] = true; |
1120
|
|
|
return new BaseObject(-1, $failed_voted); |
1121
|
|
|
} |
1122
|
|
|
|
1123
|
|
|
// Call a trigger (before) |
1124
|
|
|
$trigger_obj = new stdClass; |
1125
|
|
|
$trigger_obj->member_srl = $oDocument->get('member_srl'); |
1126
|
|
|
$trigger_obj->module_srl = $oDocument->get('module_srl'); |
1127
|
|
|
$trigger_obj->document_srl = $oDocument->get('document_srl'); |
1128
|
|
|
$trigger_obj->update_target = ($point < 0) ? 'blamed_count' : 'voted_count'; |
1129
|
|
|
$trigger_obj->point = $point; |
1130
|
|
|
$trigger_obj->before_point = ($point < 0) ? $oDocument->get('blamed_count') : $oDocument->get('voted_count'); |
1131
|
|
|
$trigger_obj->after_point = $trigger_obj->before_point + $point; |
1132
|
|
|
$trigger_output = ModuleHandler::triggerCall('document.updateVotedCount', 'before', $trigger_obj); |
1133
|
|
|
if(!$trigger_output->toBool()) |
1134
|
|
|
{ |
1135
|
|
|
return $trigger_output; |
1136
|
|
|
} |
1137
|
|
|
|
1138
|
|
|
// begin transaction |
1139
|
|
|
$oDB = DB::getInstance(); |
1140
|
|
|
$oDB->begin(); |
1141
|
|
|
|
1142
|
|
|
// Update the voted count |
1143
|
|
View Code Duplication |
if($trigger_obj->update_target === 'blamed_count') |
1144
|
|
|
{ |
1145
|
|
|
$args->blamed_count = $trigger_obj->after_point; |
1146
|
|
|
$output = executeQuery('document.updateBlamedCount', $args); |
1147
|
|
|
} |
1148
|
|
|
else |
1149
|
|
|
{ |
1150
|
|
|
$args->voted_count = $trigger_obj->after_point; |
1151
|
|
|
$output = executeQuery('document.updateVotedCount', $args); |
1152
|
|
|
} |
1153
|
|
|
if(!$output->toBool()) return $output; |
1154
|
|
|
|
1155
|
|
|
// Leave logs |
1156
|
|
|
$args->point = $trigger_obj->point; |
1157
|
|
|
$output = executeQuery('document.insertDocumentVotedLog', $args); |
1158
|
|
|
if(!$output->toBool()) return $output; |
1159
|
|
|
|
1160
|
|
|
// Call a trigger (after) |
1161
|
|
|
$trigger_output = ModuleHandler::triggerCall('document.updateVotedCount', 'after', $trigger_obj); |
1162
|
|
|
if(!$trigger_output->toBool()) |
1163
|
|
|
{ |
1164
|
|
|
$oDB->rollback(); |
1165
|
|
|
return $trigger_output; |
1166
|
|
|
} |
1167
|
|
|
|
1168
|
|
|
$oDB->commit(); |
1169
|
|
|
|
1170
|
|
|
$oCacheHandler = CacheHandler::getInstance('object'); |
1171
|
|
|
if($oCacheHandler->isSupport()) |
1172
|
|
|
{ |
1173
|
|
|
//remove document item from cache |
1174
|
|
|
$cache_key = 'document_item:'. getNumberingPath($document_srl) . $document_srl; |
1175
|
|
|
$oCacheHandler->delete($cache_key); |
1176
|
|
|
} |
1177
|
|
|
|
1178
|
|
|
// Leave in the session information |
1179
|
|
|
$_SESSION['voted_document'][$document_srl] = true; |
1180
|
|
|
|
1181
|
|
|
// Return result |
1182
|
|
|
$output = new BaseObject(); |
1183
|
|
|
if($trigger_obj->update_target === 'voted_count') |
1184
|
|
|
{ |
1185
|
|
|
$output->setMessage('success_voted'); |
1186
|
|
|
$output->add('voted_count', $trigger_obj->after_point); |
1187
|
|
|
} |
1188
|
|
|
else |
1189
|
|
|
{ |
1190
|
|
|
$output->setMessage('success_blamed'); |
1191
|
|
|
$output->add('blamed_count', $trigger_obj->after_point); |
1192
|
|
|
} |
1193
|
|
|
|
1194
|
|
|
return $output; |
1195
|
|
|
} |
1196
|
|
|
|
1197
|
|
|
/** |
1198
|
|
|
* Report posts |
1199
|
|
|
* @param int $document_srl |
1200
|
|
|
* @return void|BaseObject |
1201
|
|
|
*/ |
1202
|
|
|
function declaredDocument($document_srl) |
1203
|
|
|
{ |
1204
|
|
|
// Fail if session information already has a reported document |
1205
|
|
|
if($_SESSION['declared_document'][$document_srl]) return new BaseObject(-1, 'failed_declared'); |
1206
|
|
|
|
1207
|
|
|
// Check if previously reported |
1208
|
|
|
$args = new stdClass(); |
1209
|
|
|
$args->document_srl = $document_srl; |
1210
|
|
|
$output = executeQuery('document.getDeclaredDocument', $args); |
1211
|
|
|
if(!$output->toBool()) return $output; |
1212
|
|
|
|
1213
|
|
|
$declared_count = ($output->data->declared_count) ? $output->data->declared_count : 0; |
1214
|
|
|
|
1215
|
|
|
$trigger_obj = new stdClass(); |
1216
|
|
|
$trigger_obj->document_srl = $document_srl; |
1217
|
|
|
$trigger_obj->declared_count = $declared_count; |
1218
|
|
|
|
1219
|
|
|
// Call a trigger (before) |
1220
|
|
|
$trigger_output = ModuleHandler::triggerCall('document.declaredDocument', 'before', $trigger_obj); |
1221
|
|
|
if(!$trigger_output->toBool()) |
1222
|
|
|
{ |
1223
|
|
|
return $trigger_output; |
1224
|
|
|
} |
1225
|
|
|
|
1226
|
|
|
// Get the original document |
1227
|
|
|
$oDocumentModel = getModel('document'); |
1228
|
|
|
$oDocument = $oDocumentModel->getDocument($document_srl, false, false); |
1229
|
|
|
|
1230
|
|
|
// Pass if the author's IP address is as same as visitor's. |
1231
|
|
View Code Duplication |
if($oDocument->get('ipaddress') == $_SERVER['REMOTE_ADDR']) { |
1232
|
|
|
$_SESSION['declared_document'][$document_srl] = true; |
1233
|
|
|
return new BaseObject(-1, 'failed_declared'); |
1234
|
|
|
} |
1235
|
|
|
|
1236
|
|
|
// Check if document's author is a member. |
1237
|
|
View Code Duplication |
if($oDocument->get('member_srl')) |
1238
|
|
|
{ |
1239
|
|
|
// Create a member model object |
1240
|
|
|
$oMemberModel = getModel('member'); |
1241
|
|
|
$member_srl = $oMemberModel->getLoggedMemberSrl(); |
1242
|
|
|
// Pass after registering a session if author's information is same as the currently logged-in user's. |
1243
|
|
|
if($member_srl && $member_srl == abs($oDocument->get('member_srl'))) |
1244
|
|
|
{ |
1245
|
|
|
$_SESSION['declared_document'][$document_srl] = true; |
1246
|
|
|
return new BaseObject(-1, 'failed_declared'); |
1247
|
|
|
} |
1248
|
|
|
} |
1249
|
|
|
|
1250
|
|
|
// Use member_srl for logged-in members and IP address for non-members. |
1251
|
|
|
$args = new stdClass; |
1252
|
|
|
if($member_srl) |
1253
|
|
|
{ |
1254
|
|
|
$args->member_srl = $member_srl; |
|
|
|
|
1255
|
|
|
} |
1256
|
|
|
else |
1257
|
|
|
{ |
1258
|
|
|
$args->ipaddress = $_SERVER['REMOTE_ADDR']; |
1259
|
|
|
} |
1260
|
|
|
|
1261
|
|
|
$args->document_srl = $document_srl; |
1262
|
|
|
$output = executeQuery('document.getDocumentDeclaredLogInfo', $args); |
1263
|
|
|
|
1264
|
|
|
// Pass after registering a sesson if reported/declared documents are in the logs. |
1265
|
|
|
if($output->data->count) |
1266
|
|
|
{ |
1267
|
|
|
$_SESSION['declared_document'][$document_srl] = true; |
1268
|
|
|
return new BaseObject(-1, 'failed_declared'); |
1269
|
|
|
} |
1270
|
|
|
|
1271
|
|
|
// begin transaction |
1272
|
|
|
$oDB = &DB::getInstance(); |
1273
|
|
|
$oDB->begin(); |
1274
|
|
|
|
1275
|
|
|
// Add the declared document |
1276
|
|
|
if($declared_count > 0) $output = executeQuery('document.updateDeclaredDocument', $args); |
1277
|
|
|
else $output = executeQuery('document.insertDeclaredDocument', $args); |
1278
|
|
|
if(!$output->toBool()) return $output; |
1279
|
|
|
// Leave logs |
1280
|
|
|
$output = executeQuery('document.insertDocumentDeclaredLog', $args); |
1281
|
|
|
if(!$output->toBool()) |
1282
|
|
|
{ |
1283
|
|
|
$oDB->rollback(); |
1284
|
|
|
return $output; |
1285
|
|
|
} |
1286
|
|
|
|
1287
|
|
|
$this->add('declared_count', $declared_count+1); |
1288
|
|
|
|
1289
|
|
|
// Call a trigger (after) |
1290
|
|
|
$trigger_obj->declared_count = $declared_count + 1; |
1291
|
|
|
$trigger_output = ModuleHandler::triggerCall('document.declaredDocument', 'after', $trigger_obj); |
1292
|
|
|
if(!$trigger_output->toBool()) |
1293
|
|
|
{ |
1294
|
|
|
$oDB->rollback(); |
1295
|
|
|
return $trigger_output; |
1296
|
|
|
} |
1297
|
|
|
|
1298
|
|
|
// commit |
1299
|
|
|
$oDB->commit(); |
1300
|
|
|
|
1301
|
|
|
// Leave in the session information |
1302
|
|
|
$_SESSION['declared_document'][$document_srl] = true; |
1303
|
|
|
|
1304
|
|
|
$this->setMessage('success_declared'); |
1305
|
|
|
} |
1306
|
|
|
|
1307
|
|
|
/** |
1308
|
|
|
* Increase the number of comments in the document |
1309
|
|
|
* Update modified date, modifier, and order with increasing comment count |
1310
|
|
|
* @param int $document_srl |
1311
|
|
|
* @param int $comment_count |
1312
|
|
|
* @param string $last_updater |
1313
|
|
|
* @param bool $comment_inserted |
1314
|
|
|
* @return object |
1315
|
|
|
*/ |
1316
|
|
|
function updateCommentCount($document_srl, $comment_count, $last_updater, $comment_inserted = false) |
1317
|
|
|
{ |
1318
|
|
|
$args = new stdClass(); |
1319
|
|
|
$args->document_srl = $document_srl; |
1320
|
|
|
$args->comment_count = $comment_count; |
1321
|
|
|
|
1322
|
|
|
if($comment_inserted) |
1323
|
|
|
{ |
1324
|
|
|
$args->update_order = -1*getNextSequence(); |
1325
|
|
|
$args->last_updater = $last_updater; |
1326
|
|
|
|
1327
|
|
|
$oCacheHandler = CacheHandler::getInstance('object'); |
1328
|
|
|
if($oCacheHandler->isSupport()) |
1329
|
|
|
{ |
1330
|
|
|
//remove document item from cache |
1331
|
|
|
$cache_key = 'document_item:'. getNumberingPath($document_srl) . $document_srl; |
1332
|
|
|
$oCacheHandler->delete($cache_key); |
1333
|
|
|
} |
1334
|
|
|
} |
1335
|
|
|
|
1336
|
|
|
return executeQuery('document.updateCommentCount', $args); |
1337
|
|
|
} |
1338
|
|
|
|
1339
|
|
|
/** |
1340
|
|
|
* Increase trackback count of the document |
1341
|
|
|
* @param int $document_srl |
1342
|
|
|
* @param int $trackback_count |
1343
|
|
|
* @return object |
1344
|
|
|
*/ |
1345
|
|
|
function updateTrackbackCount($document_srl, $trackback_count) |
1346
|
|
|
{ |
1347
|
|
|
$args = new stdClass; |
1348
|
|
|
$args->document_srl = $document_srl; |
1349
|
|
|
$args->trackback_count = $trackback_count; |
1350
|
|
|
|
1351
|
|
|
$oCacheHandler = CacheHandler::getInstance('object'); |
1352
|
|
|
if($oCacheHandler->isSupport()) |
1353
|
|
|
{ |
1354
|
|
|
//remove document item from cache |
1355
|
|
|
$cache_key = 'document_item:'. getNumberingPath($document_srl) . $document_srl; |
1356
|
|
|
$oCacheHandler->delete($cache_key); |
1357
|
|
|
} |
1358
|
|
|
|
1359
|
|
|
return executeQuery('document.updateTrackbackCount', $args); |
1360
|
|
|
} |
1361
|
|
|
|
1362
|
|
|
/** |
1363
|
|
|
* Add a category |
1364
|
|
|
* @param object $obj |
1365
|
|
|
* @return object |
1366
|
|
|
*/ |
1367
|
|
|
function insertCategory($obj) |
1368
|
|
|
{ |
1369
|
|
|
// Sort the order to display if a child category is added |
1370
|
|
|
if($obj->parent_srl) |
1371
|
|
|
{ |
1372
|
|
|
// Get its parent category |
1373
|
|
|
$oDocumentModel = getModel('document'); |
1374
|
|
|
$parent_category = $oDocumentModel->getCategory($obj->parent_srl); |
1375
|
|
|
$obj->list_order = $parent_category->list_order; |
1376
|
|
|
$this->updateCategoryListOrder($parent_category->module_srl, $parent_category->list_order+1); |
1377
|
|
|
if(!$obj->category_srl) $obj->category_srl = getNextSequence(); |
1378
|
|
|
} |
1379
|
|
|
else |
1380
|
|
|
{ |
1381
|
|
|
$obj->list_order = $obj->category_srl = getNextSequence(); |
1382
|
|
|
} |
1383
|
|
|
|
1384
|
|
|
$output = executeQuery('document.insertCategory', $obj); |
1385
|
|
|
if($output->toBool()) |
1386
|
|
|
{ |
1387
|
|
|
$output->add('category_srl', $obj->category_srl); |
1388
|
|
|
$this->makeCategoryFile($obj->module_srl); |
1389
|
|
|
} |
1390
|
|
|
|
1391
|
|
|
return $output; |
1392
|
|
|
} |
1393
|
|
|
|
1394
|
|
|
/** |
1395
|
|
|
* Increase list_count from a specific category |
1396
|
|
|
* @param int $module_srl |
1397
|
|
|
* @param int $list_order |
1398
|
|
|
* @return object |
1399
|
|
|
*/ |
1400
|
|
|
function updateCategoryListOrder($module_srl, $list_order) |
1401
|
|
|
{ |
1402
|
|
|
$args = new stdClass; |
1403
|
|
|
$args->module_srl = $module_srl; |
1404
|
|
|
$args->list_order = $list_order; |
1405
|
|
|
return executeQuery('document.updateCategoryOrder', $args); |
1406
|
|
|
} |
1407
|
|
|
|
1408
|
|
|
/** |
1409
|
|
|
* Update document_count in the category. |
1410
|
|
|
* @param int $module_srl |
1411
|
|
|
* @param int $category_srl |
1412
|
|
|
* @param int $document_count |
1413
|
|
|
* @return object |
1414
|
|
|
*/ |
1415
|
|
|
function updateCategoryCount($module_srl, $category_srl, $document_count = 0) |
1416
|
|
|
{ |
1417
|
|
|
// Create a document model object |
1418
|
|
|
$oDocumentModel = getModel('document'); |
1419
|
|
|
if(!$document_count) $document_count = $oDocumentModel->getCategoryDocumentCount($module_srl,$category_srl); |
1420
|
|
|
|
1421
|
|
|
$args = new stdClass; |
1422
|
|
|
$args->category_srl = $category_srl; |
1423
|
|
|
$args->document_count = $document_count; |
1424
|
|
|
$output = executeQuery('document.updateCategoryCount', $args); |
1425
|
|
|
if($output->toBool()) $this->makeCategoryFile($module_srl); |
1426
|
|
|
|
1427
|
|
|
return $output; |
1428
|
|
|
} |
1429
|
|
|
|
1430
|
|
|
/** |
1431
|
|
|
* Update category information |
1432
|
|
|
* @param object $obj |
1433
|
|
|
* @return object |
1434
|
|
|
*/ |
1435
|
|
|
function updateCategory($obj) |
1436
|
|
|
{ |
1437
|
|
|
$output = executeQuery('document.updateCategory', $obj); |
1438
|
|
|
if($output->toBool()) $this->makeCategoryFile($obj->module_srl); |
1439
|
|
|
return $output; |
1440
|
|
|
} |
1441
|
|
|
|
1442
|
|
|
/** |
1443
|
|
|
* Delete a category |
1444
|
|
|
* @param int $category_srl |
1445
|
|
|
* @return object |
1446
|
|
|
*/ |
1447
|
|
|
function deleteCategory($category_srl) |
1448
|
|
|
{ |
1449
|
|
|
$args = new stdClass(); |
1450
|
|
|
$args->category_srl = $category_srl; |
1451
|
|
|
$oDocumentModel = getModel('document'); |
1452
|
|
|
$category_info = $oDocumentModel->getCategory($category_srl); |
1453
|
|
|
// Display an error that the category cannot be deleted if it has a child |
1454
|
|
|
$output = executeQuery('document.getChildCategoryCount', $args); |
1455
|
|
|
if(!$output->toBool()) return $output; |
1456
|
|
|
if($output->data->count>0) return new BaseObject(-1, 'msg_cannot_delete_for_child'); |
1457
|
|
|
// Delete a category information |
1458
|
|
|
$output = executeQuery('document.deleteCategory', $args); |
1459
|
|
|
if(!$output->toBool()) return $output; |
1460
|
|
|
|
1461
|
|
|
$this->makeCategoryFile($category_info->module_srl); |
1462
|
|
|
// remvove cache |
1463
|
|
|
$oCacheHandler = CacheHandler::getInstance('object'); |
1464
|
|
|
if($oCacheHandler->isSupport()) |
1465
|
|
|
{ |
1466
|
|
|
$page = 0; |
1467
|
|
|
while(true) { |
1468
|
|
|
$args = new stdClass(); |
1469
|
|
|
$args->category_srl = $category_srl; |
1470
|
|
|
$args->list_count = 100; |
1471
|
|
|
$args->page = ++$page; |
1472
|
|
|
$output = executeQuery('document.getDocumentList', $args, array('document_srl')); |
1473
|
|
|
|
1474
|
|
|
if($output->data == array()) |
1475
|
|
|
break; |
1476
|
|
|
|
1477
|
|
|
foreach($output->data as $val) |
1478
|
|
|
{ |
1479
|
|
|
//remove document item from cache |
1480
|
|
|
$cache_key = 'document_item:'. getNumberingPath($val->document_srl) . $val->document_srl; |
1481
|
|
|
$oCacheHandler->delete($cache_key); |
1482
|
|
|
} |
1483
|
|
|
} |
1484
|
|
|
} |
1485
|
|
|
|
1486
|
|
|
// Update category_srl of the documents in the same category to 0 |
1487
|
|
|
$args = new stdClass(); |
1488
|
|
|
$args->target_category_srl = 0; |
1489
|
|
|
$args->source_category_srl = $category_srl; |
1490
|
|
|
$output = executeQuery('document.updateDocumentCategory', $args); |
1491
|
|
|
|
1492
|
|
|
return $output; |
1493
|
|
|
} |
1494
|
|
|
|
1495
|
|
|
/** |
1496
|
|
|
* Delete all categories in a module |
1497
|
|
|
* @param int $module_srl |
1498
|
|
|
* @return object |
1499
|
|
|
*/ |
1500
|
|
|
function deleteModuleCategory($module_srl) |
1501
|
|
|
{ |
1502
|
|
|
$args = new stdClass(); |
1503
|
|
|
$args->module_srl = $module_srl; |
1504
|
|
|
$output = executeQuery('document.deleteModuleCategory', $args); |
1505
|
|
|
return $output; |
1506
|
|
|
} |
1507
|
|
|
|
1508
|
|
|
/** |
1509
|
|
|
* Move the category level to higher |
1510
|
|
|
* @param int $category_srl |
1511
|
|
|
* @return BaseObject |
1512
|
|
|
*/ |
1513
|
|
|
function moveCategoryUp($category_srl) |
1514
|
|
|
{ |
1515
|
|
|
$oDocumentModel = getModel('document'); |
1516
|
|
|
// Get information of the selected category |
1517
|
|
|
$args = new stdClass; |
1518
|
|
|
$args->category_srl = $category_srl; |
1519
|
|
|
$output = executeQuery('document.getCategory', $args); |
1520
|
|
|
|
1521
|
|
|
$category = $output->data; |
1522
|
|
|
$list_order = $category->list_order; |
1523
|
|
|
$module_srl = $category->module_srl; |
1524
|
|
|
// Seek a full list of categories |
1525
|
|
|
$category_list = $oDocumentModel->getCategoryList($module_srl); |
1526
|
|
|
$category_srl_list = array_keys($category_list); |
1527
|
|
|
if(count($category_srl_list)<2) return new BaseObject(); |
1528
|
|
|
|
1529
|
|
|
$prev_category = NULL; |
1530
|
|
|
foreach($category_list as $key => $val) |
1531
|
|
|
{ |
1532
|
|
|
if($key==$category_srl) break; |
1533
|
|
|
$prev_category = $val; |
1534
|
|
|
} |
1535
|
|
|
// Return if the previous category doesn't exist |
1536
|
|
|
if(!$prev_category) return new BaseObject(-1,Context::getLang('msg_category_not_moved')); |
1537
|
|
|
// Return if the selected category is the top level |
1538
|
|
|
if($category_srl_list[0]==$category_srl) return new BaseObject(-1,Context::getLang('msg_category_not_moved')); |
1539
|
|
|
// Information of the selected category |
1540
|
|
|
$cur_args = new stdClass; |
1541
|
|
|
$cur_args->category_srl = $category_srl; |
1542
|
|
|
$cur_args->list_order = $prev_category->list_order; |
1543
|
|
|
$cur_args->title = $category->title; |
1544
|
|
|
$this->updateCategory($cur_args); |
1545
|
|
|
// Category information |
1546
|
|
|
$prev_args = new stdClass; |
1547
|
|
|
$prev_args->category_srl = $prev_category->category_srl; |
1548
|
|
|
$prev_args->list_order = $list_order; |
1549
|
|
|
$prev_args->title = $prev_category->title; |
1550
|
|
|
$this->updateCategory($prev_args); |
1551
|
|
|
|
1552
|
|
|
return new BaseObject(); |
1553
|
|
|
} |
1554
|
|
|
|
1555
|
|
|
/** |
1556
|
|
|
* Move the category down |
1557
|
|
|
* @param int $category_srl |
1558
|
|
|
* @return BaseObject |
1559
|
|
|
*/ |
1560
|
|
|
function moveCategoryDown($category_srl) |
1561
|
|
|
{ |
1562
|
|
|
$oDocumentModel = getModel('document'); |
1563
|
|
|
// Get information of the selected category |
1564
|
|
|
$args = new stdClass; |
1565
|
|
|
$args->category_srl = $category_srl; |
1566
|
|
|
$output = executeQuery('document.getCategory', $args); |
1567
|
|
|
|
1568
|
|
|
$category = $output->data; |
1569
|
|
|
$list_order = $category->list_order; |
1570
|
|
|
$module_srl = $category->module_srl; |
1571
|
|
|
// Seek a full list of categories |
1572
|
|
|
$category_list = $oDocumentModel->getCategoryList($module_srl); |
1573
|
|
|
$category_srl_list = array_keys($category_list); |
1574
|
|
|
if(count($category_srl_list)<2) return new BaseObject(); |
1575
|
|
|
|
1576
|
|
|
for($i=0;$i<count($category_srl_list);$i++) |
|
|
|
|
1577
|
|
|
{ |
1578
|
|
|
if($category_srl_list[$i]==$category_srl) break; |
1579
|
|
|
} |
1580
|
|
|
|
1581
|
|
|
$next_category_srl = $category_srl_list[$i+1]; |
1582
|
|
|
if(!$category_list[$next_category_srl]) return new BaseObject(-1,Context::getLang('msg_category_not_moved')); |
1583
|
|
|
$next_category = $category_list[$next_category_srl]; |
1584
|
|
|
// Information of the selected category |
1585
|
|
|
$cur_args = new stdClass; |
1586
|
|
|
$cur_args->category_srl = $category_srl; |
1587
|
|
|
$cur_args->list_order = $next_category->list_order; |
1588
|
|
|
$cur_args->title = $category->title; |
1589
|
|
|
$this->updateCategory($cur_args); |
1590
|
|
|
// Category information |
1591
|
|
|
$next_args = new stdClass; |
1592
|
|
|
$next_args->category_srl = $next_category->category_srl; |
1593
|
|
|
$next_args->list_order = $list_order; |
1594
|
|
|
$next_args->title = $next_category->title; |
1595
|
|
|
$this->updateCategory($next_args); |
1596
|
|
|
|
1597
|
|
|
return new BaseObject(); |
1598
|
|
|
} |
1599
|
|
|
|
1600
|
|
|
/** |
1601
|
|
|
* Add javascript codes into the header by checking values of document_extra_keys type, required and others |
1602
|
|
|
* @param int $module_srl |
1603
|
|
|
* @return void |
1604
|
|
|
*/ |
1605
|
|
|
function addXmlJsFilter($module_srl) |
1606
|
|
|
{ |
1607
|
|
|
$oDocumentModel = getModel('document'); |
1608
|
|
|
$extra_keys = $oDocumentModel->getExtraKeys($module_srl); |
1609
|
|
|
if(!count($extra_keys)) return; |
1610
|
|
|
|
1611
|
|
|
$js_code = array(); |
1612
|
|
|
$js_code[] = '<script>//<![CDATA['; |
1613
|
|
|
$js_code[] = '(function($){'; |
1614
|
|
|
$js_code[] = 'var validator = xe.getApp("validator")[0];'; |
1615
|
|
|
$js_code[] = 'if(!validator) return false;'; |
1616
|
|
|
|
1617
|
|
|
$logged_info = Context::get('logged_info'); |
|
|
|
|
1618
|
|
|
|
1619
|
|
|
foreach($extra_keys as $idx => $val) |
1620
|
|
|
{ |
1621
|
|
|
$idx = $val->idx; |
1622
|
|
|
if($val->type == 'kr_zip') |
1623
|
|
|
{ |
1624
|
|
|
$idx .= '[]'; |
1625
|
|
|
} |
1626
|
|
|
$name = str_ireplace(array('<script', '</script'), array('<scr" + "ipt', '</scr" + "ipt'), $val->name); |
1627
|
|
|
$js_code[] = sprintf('validator.cast("ADD_MESSAGE", ["extra_vars%s","%s"]);', $idx, $name); |
1628
|
|
|
if($val->is_required == 'Y') $js_code[] = sprintf('validator.cast("ADD_EXTRA_FIELD", ["extra_vars%s", { required:true }]);', $idx); |
1629
|
|
|
} |
1630
|
|
|
|
1631
|
|
|
$js_code[] = '})(jQuery);'; |
1632
|
|
|
$js_code[] = '//]]></script>'; |
1633
|
|
|
$js_code = implode("\n", $js_code); |
1634
|
|
|
|
1635
|
|
|
Context::addHtmlHeader($js_code); |
1636
|
|
|
} |
1637
|
|
|
|
1638
|
|
|
/** |
1639
|
|
|
* Add a category |
1640
|
|
|
* @param object $args |
1641
|
|
|
* @return void |
1642
|
|
|
*/ |
1643
|
|
|
function procDocumentInsertCategory($args = null) |
1644
|
|
|
{ |
1645
|
|
|
// List variables |
1646
|
|
|
if(!$args) $args = Context::gets('module_srl','category_srl','parent_srl','category_title','category_description','expand','group_srls','category_color','mid'); |
1647
|
|
|
$args->title = $args->category_title; |
1648
|
|
|
$args->description = $args->category_description; |
1649
|
|
|
$args->color = $args->category_color; |
1650
|
|
|
|
1651
|
|
|
if(!$args->module_srl && $args->mid) |
1652
|
|
|
{ |
1653
|
|
|
$mid = $args->mid; |
|
|
|
|
1654
|
|
|
unset($args->mid); |
1655
|
|
|
$args->module_srl = $this->module_srl; |
1656
|
|
|
} |
1657
|
|
|
// Check permissions |
1658
|
|
|
$oModuleModel = getModel('module'); |
1659
|
|
|
$columnList = array('module_srl', 'module'); |
1660
|
|
|
$module_info = $oModuleModel->getModuleInfoByModuleSrl($args->module_srl, $columnList); |
1661
|
|
|
$grant = $oModuleModel->getGrant($module_info, Context::get('logged_info')); |
1662
|
|
|
if(!$grant->manager) return new BaseObject(-1,'msg_not_permitted'); |
1663
|
|
|
|
1664
|
|
|
if($args->expand !="Y") $args->expand = "N"; |
1665
|
|
|
if(!is_array($args->group_srls)) $args->group_srls = str_replace('|@|',',',$args->group_srls); |
1666
|
|
|
else $args->group_srls = implode(',', $args->group_srls); |
1667
|
|
|
$args->parent_srl = (int)$args->parent_srl; |
1668
|
|
|
|
1669
|
|
|
$oDocumentModel = getModel('document'); |
1670
|
|
|
|
1671
|
|
|
$oDB = &DB::getInstance(); |
1672
|
|
|
$oDB->begin(); |
1673
|
|
|
// Check if already exists |
1674
|
|
|
if($args->category_srl) |
1675
|
|
|
{ |
1676
|
|
|
$category_info = $oDocumentModel->getCategory($args->category_srl); |
1677
|
|
|
if($category_info->category_srl != $args->category_srl) $args->category_srl = null; |
1678
|
|
|
} |
1679
|
|
|
// Update if exists |
1680
|
|
|
if($args->category_srl) |
1681
|
|
|
{ |
1682
|
|
|
$output = $this->updateCategory($args); |
1683
|
|
|
if(!$output->toBool()) |
1684
|
|
|
{ |
1685
|
|
|
$oDB->rollback(); |
1686
|
|
|
return $output; |
1687
|
|
|
} |
1688
|
|
|
// Insert if not exist |
1689
|
|
|
} |
1690
|
|
|
else |
1691
|
|
|
{ |
1692
|
|
|
$output = $this->insertCategory($args); |
1693
|
|
|
if(!$output->toBool()) |
1694
|
|
|
{ |
1695
|
|
|
$oDB->rollback(); |
1696
|
|
|
return $output; |
1697
|
|
|
} |
1698
|
|
|
} |
1699
|
|
|
// Update the xml file and get its location |
1700
|
|
|
$xml_file = $this->makeCategoryFile($args->module_srl); |
1701
|
|
|
|
1702
|
|
|
$oDB->commit(); |
1703
|
|
|
|
1704
|
|
|
$this->add('xml_file', $xml_file); |
1705
|
|
|
$this->add('module_srl', $args->module_srl); |
1706
|
|
|
$this->add('category_srl', $args->category_srl); |
1707
|
|
|
$this->add('parent_srl', $args->parent_srl); |
1708
|
|
|
|
1709
|
|
|
$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : Context::get('error_return_url'); |
1710
|
|
|
$this->setRedirectUrl($returnUrl); |
1711
|
|
|
} |
1712
|
|
|
|
1713
|
|
|
/** |
1714
|
|
|
* Move a category |
1715
|
|
|
* @return void |
1716
|
|
|
*/ |
1717
|
|
|
function procDocumentMoveCategory() |
1718
|
|
|
{ |
1719
|
|
|
$source_category_srl = Context::get('source_srl'); |
1720
|
|
|
// If parent_srl exists, be the first child |
1721
|
|
|
$parent_category_srl = Context::get('parent_srl'); |
1722
|
|
|
// If target_srl exists, be a sibling |
1723
|
|
|
$target_category_srl = Context::get('target_srl'); |
1724
|
|
|
|
1725
|
|
|
$oDocumentModel = getModel('document'); |
1726
|
|
|
$source_category = $oDocumentModel->getCategory($source_category_srl); |
1727
|
|
|
// Check permissions |
1728
|
|
|
$oModuleModel = getModel('module'); |
1729
|
|
|
$columnList = array('module_srl', 'module'); |
1730
|
|
|
$module_info = $oModuleModel->getModuleInfoByModuleSrl($source_category->module_srl, $columnList); |
1731
|
|
|
$grant = $oModuleModel->getGrant($module_info, Context::get('logged_info')); |
1732
|
|
|
if(!$grant->manager) return new BaseObject(-1,'msg_not_permitted'); |
1733
|
|
|
|
1734
|
|
|
// First child of the parent_category_srl |
1735
|
|
|
$source_args = new stdClass; |
1736
|
|
|
if($parent_category_srl > 0 || ($parent_category_srl == 0 && $target_category_srl == 0)) |
1737
|
|
|
{ |
1738
|
|
|
$parent_category = $oDocumentModel->getCategory($parent_category_srl); |
|
|
|
|
1739
|
|
|
|
1740
|
|
|
$args = new stdClass; |
1741
|
|
|
$args->module_srl = $source_category->module_srl; |
1742
|
|
|
$args->parent_srl = $parent_category_srl; |
1743
|
|
|
$output = executeQuery('document.getChildCategoryMinListOrder', $args); |
1744
|
|
|
|
1745
|
|
|
if(!$output->toBool()) return $output; |
1746
|
|
|
$args->list_order = (int)$output->data->list_order; |
1747
|
|
|
if(!$args->list_order) $args->list_order = 0; |
1748
|
|
|
$args->list_order--; |
1749
|
|
|
|
1750
|
|
|
$source_args->category_srl = $source_category_srl; |
1751
|
|
|
$source_args->parent_srl = $parent_category_srl; |
1752
|
|
|
$source_args->list_order = $args->list_order; |
1753
|
|
|
$output = $this->updateCategory($source_args); |
1754
|
|
|
if(!$output->toBool()) return $output; |
1755
|
|
|
// Sibling of the $target_category_srl |
1756
|
|
|
} |
1757
|
|
|
else if($target_category_srl > 0) |
1758
|
|
|
{ |
1759
|
|
|
$target_category = $oDocumentModel->getCategory($target_category_srl); |
1760
|
|
|
// Move all siblings of the $target_category down |
1761
|
|
|
$output = $this->updateCategoryListOrder($target_category->module_srl, $target_category->list_order+1); |
1762
|
|
|
if(!$output->toBool()) return $output; |
1763
|
|
|
|
1764
|
|
|
$source_args->category_srl = $source_category_srl; |
1765
|
|
|
$source_args->parent_srl = $target_category->parent_srl; |
1766
|
|
|
$source_args->list_order = $target_category->list_order+1; |
1767
|
|
|
$output = $this->updateCategory($source_args); |
1768
|
|
|
if(!$output->toBool()) return $output; |
1769
|
|
|
} |
1770
|
|
|
// Re-generate the xml file |
1771
|
|
|
$xml_file = $this->makeCategoryFile($source_category->module_srl); |
1772
|
|
|
// Variable settings |
1773
|
|
|
$this->add('xml_file', $xml_file); |
1774
|
|
|
$this->add('source_category_srl', $source_category_srl); |
1775
|
|
|
} |
1776
|
|
|
|
1777
|
|
|
/** |
1778
|
|
|
* Delete a category |
1779
|
|
|
* @return void |
1780
|
|
|
*/ |
1781
|
|
|
function procDocumentDeleteCategory() |
1782
|
|
|
{ |
1783
|
|
|
// List variables |
1784
|
|
|
$args = Context::gets('module_srl','category_srl'); |
1785
|
|
|
|
1786
|
|
|
$oDB = &DB::getInstance(); |
1787
|
|
|
$oDB->begin(); |
1788
|
|
|
// Check permissions |
1789
|
|
|
$oModuleModel = getModel('module'); |
1790
|
|
|
$columnList = array('module_srl', 'module'); |
1791
|
|
|
$module_info = $oModuleModel->getModuleInfoByModuleSrl($args->module_srl, $columnList); |
1792
|
|
|
$grant = $oModuleModel->getGrant($module_info, Context::get('logged_info')); |
1793
|
|
|
if(!$grant->manager) return new BaseObject(-1,'msg_not_permitted'); |
1794
|
|
|
|
1795
|
|
|
$oDocumentModel = getModel('document'); |
1796
|
|
|
// Get original information |
1797
|
|
|
$category_info = $oDocumentModel->getCategory($args->category_srl); |
1798
|
|
|
if($category_info->parent_srl) $parent_srl = $category_info->parent_srl; |
1799
|
|
|
// Display an error that the category cannot be deleted if it has a child node |
1800
|
|
|
if($oDocumentModel->getCategoryChlidCount($args->category_srl)) return new BaseObject(-1, 'msg_cannot_delete_for_child'); |
1801
|
|
|
// Remove from the DB |
1802
|
|
|
$output = $this->deleteCategory($args->category_srl); |
1803
|
|
|
if(!$output->toBool()) |
1804
|
|
|
{ |
1805
|
|
|
$oDB->rollback(); |
1806
|
|
|
return $output; |
1807
|
|
|
} |
1808
|
|
|
// Update the xml file and get its location |
1809
|
|
|
$xml_file = $this->makeCategoryFile($args->module_srl); |
1810
|
|
|
|
1811
|
|
|
$oDB->commit(); |
1812
|
|
|
|
1813
|
|
|
$this->add('xml_file', $xml_file); |
1814
|
|
|
$this->add('category_srl', $parent_srl); |
|
|
|
|
1815
|
|
|
$this->setMessage('success_deleted'); |
1816
|
|
|
} |
1817
|
|
|
|
1818
|
|
|
/** |
1819
|
|
|
* Xml files updated |
1820
|
|
|
* Occasionally the xml file is not generated after menu is configued on the admin page \n |
1821
|
|
|
* The administrator can manually update the file in this case \n |
1822
|
|
|
* Although the issue is not currently reproduced, it is unnecessay to remove. |
1823
|
|
|
* @return void |
1824
|
|
|
*/ |
1825
|
|
|
function procDocumentMakeXmlFile() |
1826
|
|
|
{ |
1827
|
|
|
// Check input values |
1828
|
|
|
$module_srl = Context::get('module_srl'); |
1829
|
|
|
// Check permissions |
1830
|
|
|
$oModuleModel = getModel('module'); |
1831
|
|
|
$columnList = array('module_srl', 'module'); |
1832
|
|
|
$module_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl, $columnList); |
1833
|
|
|
$grant = $oModuleModel->getGrant($module_info, Context::get('logged_info')); |
1834
|
|
|
if(!$grant->manager) return new BaseObject(-1,'msg_not_permitted'); |
1835
|
|
|
|
1836
|
|
|
$xml_file = $this->makeCategoryFile($module_srl); |
1837
|
|
|
// Set return value |
1838
|
|
|
$this->add('xml_file',$xml_file); |
1839
|
|
|
} |
1840
|
|
|
|
1841
|
|
|
/** |
1842
|
|
|
* Save the category in a cache file |
1843
|
|
|
* @param int $module_srl |
1844
|
|
|
* @return string |
1845
|
|
|
*/ |
1846
|
|
|
function makeCategoryFile($module_srl) |
1847
|
|
|
{ |
1848
|
|
|
// Return if there is no information you need for creating a cache file |
1849
|
|
|
if(!$module_srl) return false; |
1850
|
|
|
|
1851
|
|
|
$module_srl = (int)$module_srl; |
1852
|
|
|
|
1853
|
|
|
// Get module information (to obtain mid) |
1854
|
|
|
$oModuleModel = getModel('module'); |
1855
|
|
|
$columnList = array('module_srl', 'mid', 'site_srl'); |
1856
|
|
|
$module_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl, $columnList); |
1857
|
|
|
$mid = $module_info->mid; |
1858
|
|
|
|
1859
|
|
|
if(!is_dir('./files/cache/document_category')) FileHandler::makeDir('./files/cache/document_category'); |
1860
|
|
|
// Cache file's name |
1861
|
|
|
$xml_file = sprintf("./files/cache/document_category/%s.xml.php", $module_srl); |
1862
|
|
|
$php_file = sprintf("./files/cache/document_category/%s.php", $module_srl); |
1863
|
|
|
// Get a category list |
1864
|
|
|
$args = new stdClass(); |
1865
|
|
|
$args->module_srl = $module_srl; |
1866
|
|
|
$args->sort_index = 'list_order'; |
1867
|
|
|
$output = executeQueryArray('document.getCategoryList', $args); |
1868
|
|
|
|
1869
|
|
|
$category_list = $output->data; |
1870
|
|
|
|
1871
|
|
|
if(!is_array($category_list)) $category_list = array($category_list); |
1872
|
|
|
|
1873
|
|
|
$category_count = count($category_list); |
1874
|
|
|
for($i=0;$i<$category_count;$i++) |
1875
|
|
|
{ |
1876
|
|
|
$category_srl = $category_list[$i]->category_srl; |
1877
|
|
|
if(!preg_match('/^[0-9,]+$/', $category_list[$i]->group_srls)) $category_list[$i]->group_srls = ''; |
1878
|
|
|
$list[$category_srl] = $category_list[$i]; |
|
|
|
|
1879
|
|
|
} |
1880
|
|
|
// Create the xml file without node data if no data is obtained |
1881
|
|
View Code Duplication |
if(!$list) |
|
|
|
|
1882
|
|
|
{ |
1883
|
|
|
$xml_buff = "<root />"; |
1884
|
|
|
FileHandler::writeFile($xml_file, $xml_buff); |
1885
|
|
|
FileHandler::writeFile($php_file, '<?php if(!defined("__XE__")) exit(); ?>'); |
1886
|
|
|
return $xml_file; |
1887
|
|
|
} |
1888
|
|
|
// Change to an array if only a single data is obtained |
1889
|
|
|
if(!is_array($list)) $list = array($list); |
1890
|
|
|
// Create a tree for loop |
1891
|
|
|
foreach($list as $category_srl => $node) |
1892
|
|
|
{ |
1893
|
|
|
$node->mid = $mid; |
1894
|
|
|
$parent_srl = (int)$node->parent_srl; |
1895
|
|
|
$tree[$parent_srl][$category_srl] = $node; |
|
|
|
|
1896
|
|
|
} |
1897
|
|
|
// A common header to set permissions and groups of the cache file |
1898
|
|
|
$header_script = |
1899
|
|
|
'$lang_type = Context::getLangType(); '. |
1900
|
|
|
'$is_logged = Context::get(\'is_logged\'); '. |
1901
|
|
|
'$logged_info = Context::get(\'logged_info\'); '. |
1902
|
|
|
'if($is_logged) {'. |
1903
|
|
|
'if($logged_info->is_admin=="Y") $is_admin = true; '. |
1904
|
|
|
'else $is_admin = false; '. |
1905
|
|
|
'$group_srls = array_keys($logged_info->group_list); '. |
1906
|
|
|
'} else { '. |
1907
|
|
|
'$is_admin = false; '. |
1908
|
|
|
'$group_srsl = array(); '. |
1909
|
|
|
'} '."\n"; |
1910
|
|
|
|
1911
|
|
|
// Create the xml cache file (a separate session is needed for xml cache) |
1912
|
|
|
$xml_header_buff = ''; |
1913
|
|
|
$xml_body_buff = $this->getXmlTree($tree[0], $tree, $module_info->site_srl, $xml_header_buff); |
|
|
|
|
1914
|
|
|
$xml_buff = sprintf( |
1915
|
|
|
'<?php '. |
1916
|
|
|
'define(\'__XE__\', true); '. |
1917
|
|
|
'require_once(\''.FileHandler::getRealPath('./config/config.inc.php').'\'); '. |
1918
|
|
|
'$oContext = &Context::getInstance(); '. |
1919
|
|
|
'$oContext->init(); '. |
1920
|
|
|
'header("Content-Type: text/xml; charset=UTF-8"); '. |
1921
|
|
|
'header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); '. |
1922
|
|
|
'header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); '. |
1923
|
|
|
'header("Cache-Control: no-store, no-cache, must-revalidate"); '. |
1924
|
|
|
'header("Cache-Control: post-check=0, pre-check=0", false); '. |
1925
|
|
|
'header("Pragma: no-cache"); '. |
1926
|
|
|
'%s'. |
1927
|
|
|
'%s '. |
1928
|
|
|
'$oContext->close();'. |
1929
|
|
|
'?>'. |
1930
|
|
|
'<root>%s</root>', |
1931
|
|
|
$header_script, |
1932
|
|
|
$xml_header_buff, |
1933
|
|
|
$xml_body_buff |
1934
|
|
|
); |
1935
|
|
|
// Create php cache file |
1936
|
|
|
$php_header_buff = '$_titles = array();'; |
1937
|
|
|
$php_header_buff .= '$_descriptions = array();'; |
1938
|
|
|
$php_output = $this->getPhpCacheCode($tree[0], $tree, $module_info->site_srl, $php_header_buff); |
1939
|
|
|
$php_buff = sprintf( |
1940
|
|
|
'<?php '. |
1941
|
|
|
'if(!defined("__XE__")) exit(); '. |
1942
|
|
|
'%s'. |
1943
|
|
|
'%s'. |
1944
|
|
|
'$menu = new stdClass;'. |
1945
|
|
|
'$menu->list = array(%s); ', |
1946
|
|
|
$header_script, |
1947
|
|
|
$php_header_buff, |
1948
|
|
|
$php_output['buff'] |
1949
|
|
|
); |
1950
|
|
|
// Save File |
1951
|
|
|
FileHandler::writeFile($xml_file, $xml_buff); |
1952
|
|
|
FileHandler::writeFile($php_file, $php_buff); |
1953
|
|
|
return $xml_file; |
1954
|
|
|
} |
1955
|
|
|
|
1956
|
|
|
/** |
1957
|
|
|
* Create the xml data recursively referring to parent_srl |
1958
|
|
|
* In the menu xml file, node tag is nested and xml doc enables the admin page to have a menu\n |
1959
|
|
|
* (tree menu is implemented by reading xml file from the tree_menu.js) |
1960
|
|
|
* @param array $source_node |
1961
|
|
|
* @param array $tree |
1962
|
|
|
* @param int $site_srl |
1963
|
|
|
* @param string $xml_header_buff |
1964
|
|
|
* @return string |
1965
|
|
|
*/ |
1966
|
|
|
function getXmlTree($source_node, $tree, $site_srl, &$xml_header_buff) |
1967
|
|
|
{ |
1968
|
|
|
if(!$source_node) return; |
|
|
|
|
1969
|
|
|
|
1970
|
|
|
foreach($source_node as $category_srl => $node) |
1971
|
|
|
{ |
1972
|
|
|
$child_buff = ""; |
1973
|
|
|
// Get data of the child nodes |
1974
|
|
|
if($category_srl && $tree[$category_srl]) $child_buff = $this->getXmlTree($tree[$category_srl], $tree, $site_srl, $xml_header_buff); |
1975
|
|
|
// List variables |
1976
|
|
|
$expand = ($node->expand) ? $node->expand : 'N'; |
1977
|
|
|
$group_srls = ($node->group_srls) ? $node->group_srls : ''; |
1978
|
|
|
$mid = ($node->mid) ? $node->mid : ''; |
1979
|
|
|
$module_srl = ($node->module_srl) ? $node->parent_srl : ''; |
1980
|
|
|
$parent_srl = ($node->parent_srl) ? $node->parent_srl : ''; |
1981
|
|
|
$color = ($node->color) ? $node->color : ''; |
1982
|
|
|
$description = ($node->description) ? $node->description : ''; |
1983
|
|
|
// If node->group_srls value exists |
1984
|
|
|
if($group_srls) $group_check_code = sprintf('($is_admin==true||(is_array($group_srls)&&count(array_intersect($group_srls, array(%s)))))',$group_srls); |
1985
|
|
|
else $group_check_code = "true"; |
1986
|
|
|
|
1987
|
|
|
$title = $node->title; |
1988
|
|
|
$oModuleAdminModel = getAdminModel('module'); |
1989
|
|
|
|
1990
|
|
|
$langs = $oModuleAdminModel->getLangCode($site_srl, $title); |
1991
|
|
View Code Duplication |
if(count($langs)) |
1992
|
|
|
{ |
1993
|
|
|
foreach($langs as $key => $val) |
1994
|
|
|
{ |
1995
|
|
|
$xml_header_buff .= sprintf('$_titles[%d]["%s"] = %s; ', $category_srl, $key, var_export(str_replace('"','\\"',htmlspecialchars($val, ENT_COMPAT | ENT_HTML401, 'UTF-8', false)), true)); |
1996
|
|
|
} |
1997
|
|
|
} |
1998
|
|
|
|
1999
|
|
|
$langx = $oModuleAdminModel->getLangCode($site_srl, $description); |
2000
|
|
View Code Duplication |
if(count($langx)) |
2001
|
|
|
{ |
2002
|
|
|
foreach($langx as $key => $val) |
2003
|
|
|
{ |
2004
|
|
|
$xml_header_buff .= sprintf('$_descriptions[%d]["%s"] = %s; ', $category_srl, $key, var_export(str_replace('"','\\"',htmlspecialchars($val, ENT_COMPAT | ENT_HTML401, 'UTF-8', false)), true)); |
2005
|
|
|
} |
2006
|
|
|
} |
2007
|
|
|
|
2008
|
|
|
$attribute = sprintf( |
2009
|
|
|
'mid="%s" module_srl="%d" node_srl="%d" parent_srl="%d" category_srl="%d" text="<?php echo (%s?($_titles[%d][$lang_type]):"")?>" url=%s expand=%s color=%s description="<?php echo (%s?($_descriptions[%d][$lang_type]):"")?>" document_count="%d" ', |
2010
|
|
|
$mid, |
2011
|
|
|
$module_srl, |
2012
|
|
|
$category_srl, |
2013
|
|
|
$parent_srl, |
2014
|
|
|
$category_srl, |
2015
|
|
|
$group_check_code, |
2016
|
|
|
$category_srl, |
2017
|
|
|
var_export(getUrl('','mid',$node->mid,'category',$category_srl), true), |
2018
|
|
|
var_export($expand, true), |
2019
|
|
|
var_export($color, true), |
2020
|
|
|
$group_check_code, |
2021
|
|
|
$category_srl, |
2022
|
|
|
$node->document_count |
2023
|
|
|
); |
2024
|
|
|
|
2025
|
|
View Code Duplication |
if($child_buff) $buff .= sprintf('<node %s>%s</node>', $attribute, $child_buff); |
|
|
|
|
2026
|
|
|
else $buff .= sprintf('<node %s />', $attribute); |
2027
|
|
|
} |
2028
|
|
|
return $buff; |
2029
|
|
|
} |
2030
|
|
|
|
2031
|
|
|
/** |
2032
|
|
|
* Change sorted nodes in an array to the php code and then return |
2033
|
|
|
* When using menu on tpl, you can directly xml data. howver you may need javascrips additionally. |
2034
|
|
|
* Therefore, you can configure the menu info directly from php cache file, not through DB. |
2035
|
|
|
* You may include the cache in the ModuleHandler::displayContent() |
2036
|
|
|
* @param array $source_node |
2037
|
|
|
* @param array $tree |
2038
|
|
|
* @param int $site_srl |
2039
|
|
|
* @param string $php_header_buff |
2040
|
|
|
* @return array |
2041
|
|
|
*/ |
2042
|
|
|
function getPhpCacheCode($source_node, $tree, $site_srl, &$php_header_buff) |
2043
|
|
|
{ |
2044
|
|
|
$output = array("buff"=>"", "category_srl_list"=>array()); |
2045
|
|
|
if(!$source_node) return $output; |
|
|
|
|
2046
|
|
|
|
2047
|
|
|
// Set to an arraty for looping and then generate php script codes to be included |
2048
|
|
|
foreach($source_node as $category_srl => $node) |
2049
|
|
|
{ |
2050
|
|
|
// Get data from child nodes first if exist. |
2051
|
|
|
if($category_srl && $tree[$category_srl]){ |
2052
|
|
|
$child_output = $this->getPhpCacheCode($tree[$category_srl], $tree, $site_srl, $php_header_buff); |
2053
|
|
|
} else { |
2054
|
|
|
$child_output = array("buff"=>"", "category_srl_list"=>array()); |
2055
|
|
|
} |
2056
|
|
|
|
2057
|
|
|
// Set values into category_srl_list arrary if url of the current node is not empty |
2058
|
|
|
$child_output['category_srl_list'][] = $node->category_srl; |
2059
|
|
|
$output['category_srl_list'] = array_merge($output['category_srl_list'], $child_output['category_srl_list']); |
2060
|
|
|
|
2061
|
|
|
// If node->group_srls value exists |
2062
|
|
|
if($node->group_srls) { |
2063
|
|
|
$group_check_code = sprintf('($is_admin==true||(is_array($group_srls)&&count(array_intersect($group_srls, array(%s)))))',$node->group_srls); |
2064
|
|
|
} else { |
2065
|
|
|
$group_check_code = "true"; |
2066
|
|
|
} |
2067
|
|
|
|
2068
|
|
|
// List variables |
2069
|
|
|
$selected = '"' . implode('","', $child_output['category_srl_list']) . '"'; |
2070
|
|
|
$child_buff = $child_output['buff']; |
2071
|
|
|
$expand = $node->expand; |
2072
|
|
|
|
2073
|
|
|
$title = $node->title; |
2074
|
|
|
$description = $node->description; |
2075
|
|
|
$oModuleAdminModel = getAdminModel('module'); |
2076
|
|
|
$langs = $oModuleAdminModel->getLangCode($site_srl, $title); |
2077
|
|
|
|
2078
|
|
View Code Duplication |
if(count($langs)) |
2079
|
|
|
{ |
2080
|
|
|
foreach($langs as $key => $val) |
2081
|
|
|
{ |
2082
|
|
|
$val = htmlspecialchars($val, ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
2083
|
|
|
$php_header_buff .= sprintf( |
2084
|
|
|
'$_titles[%d]["%s"] = %s; ', |
2085
|
|
|
$category_srl, |
2086
|
|
|
$key, |
2087
|
|
|
var_export(str_replace('"','\\"', $val), true) |
2088
|
|
|
); |
2089
|
|
|
} |
2090
|
|
|
} |
2091
|
|
|
|
2092
|
|
|
$langx = $oModuleAdminModel->getLangCode($site_srl, $description); |
2093
|
|
|
|
2094
|
|
View Code Duplication |
if(count($langx)) |
2095
|
|
|
{ |
2096
|
|
|
foreach($langx as $key => $val) |
2097
|
|
|
{ |
2098
|
|
|
$val = htmlspecialchars($val, ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
2099
|
|
|
$php_header_buff .= sprintf( |
2100
|
|
|
'$_descriptions[%d]["%s"] = %s; ', |
2101
|
|
|
$category_srl, |
2102
|
|
|
$key, |
2103
|
|
|
var_export(str_replace('"','\\"', $val), true) |
2104
|
|
|
); |
2105
|
|
|
} |
2106
|
|
|
} |
2107
|
|
|
|
2108
|
|
|
// Create attributes(Use the category_srl_list to check whether to belong to the menu's node. It seems to be tricky but fast fast and powerful;) |
2109
|
|
|
$attribute = sprintf( |
2110
|
|
|
'"mid" => "%s", "module_srl" => "%d","node_srl"=>"%d","category_srl"=>"%d","parent_srl"=>"%d","text"=>$_titles[%d][$lang_type],"selected"=>(in_array(Context::get("category"),array(%s))?1:0),"expand"=>%s,"color"=>%s,"description"=>$_descriptions[%d][$lang_type],"list"=>array(%s),"document_count"=>"%d","grant"=>%s?true:false', |
2111
|
|
|
$node->mid, |
2112
|
|
|
$node->module_srl, |
2113
|
|
|
$node->category_srl, |
2114
|
|
|
$node->category_srl, |
2115
|
|
|
$node->parent_srl, |
2116
|
|
|
$node->category_srl, |
2117
|
|
|
$selected, |
2118
|
|
|
var_export($expand, true), |
2119
|
|
|
var_export($node->color, true), |
2120
|
|
|
$node->category_srl, |
2121
|
|
|
$child_buff, |
2122
|
|
|
$node->document_count, |
2123
|
|
|
$group_check_code |
2124
|
|
|
); |
2125
|
|
|
|
2126
|
|
|
// Generate buff data |
2127
|
|
|
$output['buff'] .= sprintf('%s=>array(%s),', $node->category_srl, $attribute); |
2128
|
|
|
} |
2129
|
|
|
|
2130
|
|
|
return $output; |
2131
|
|
|
} |
2132
|
|
|
|
2133
|
|
|
/** |
2134
|
|
|
* A method to add a pop-up menu which appears when clicking |
2135
|
|
|
* @param string $url |
2136
|
|
|
* @param string $str |
2137
|
|
|
* @param string $icon |
2138
|
|
|
* @param string $target |
2139
|
|
|
* @return void |
2140
|
|
|
*/ |
2141
|
|
View Code Duplication |
function addDocumentPopupMenu($url, $str, $icon = '', $target = 'self') |
|
|
|
|
2142
|
|
|
{ |
2143
|
|
|
$document_popup_menu_list = Context::get('document_popup_menu_list'); |
2144
|
|
|
if(!is_array($document_popup_menu_list)) $document_popup_menu_list = array(); |
2145
|
|
|
|
2146
|
|
|
$obj = new stdClass(); |
2147
|
|
|
$obj->url = $url; |
2148
|
|
|
$obj->str = $str; |
2149
|
|
|
$obj->icon = $icon; |
2150
|
|
|
$obj->target = $target; |
2151
|
|
|
$document_popup_menu_list[] = $obj; |
2152
|
|
|
|
2153
|
|
|
Context::set('document_popup_menu_list', $document_popup_menu_list); |
2154
|
|
|
} |
2155
|
|
|
|
2156
|
|
|
/** |
2157
|
|
|
* Saved in the session when an administrator selects a post |
2158
|
|
|
* @return void|BaseObject |
2159
|
|
|
*/ |
2160
|
|
|
function procDocumentAddCart() |
2161
|
|
|
{ |
2162
|
|
|
if(!Context::get('is_logged')) return new BaseObject(-1, 'msg_not_permitted'); |
2163
|
|
|
|
2164
|
|
|
// Get document_srl |
2165
|
|
|
$srls = explode(',',Context::get('srls')); |
2166
|
|
|
for($i = 0; $i < count($srls); $i++) |
|
|
|
|
2167
|
|
|
{ |
2168
|
|
|
$srl = trim($srls[$i]); |
2169
|
|
|
|
2170
|
|
|
if(!$srl) continue; |
2171
|
|
|
|
2172
|
|
|
$document_srls[] = $srl; |
|
|
|
|
2173
|
|
|
} |
2174
|
|
|
if(!count($document_srls)) return; |
|
|
|
|
2175
|
|
|
|
2176
|
|
|
// Get module_srl of the documents |
2177
|
|
|
$args = new stdClass; |
2178
|
|
|
$args->list_count = count($document_srls); |
2179
|
|
|
$args->document_srls = implode(',',$document_srls); |
2180
|
|
|
$args->order_type = 'asc'; |
2181
|
|
|
$output = executeQueryArray('document.getDocuments', $args); |
2182
|
|
|
if(!$output->data) return new BaseObject(); |
2183
|
|
|
|
2184
|
|
|
unset($document_srls); |
2185
|
|
|
foreach($output->data as $key => $val) |
2186
|
|
|
{ |
2187
|
|
|
$document_srls[$val->module_srl][] = $val->document_srl; |
2188
|
|
|
} |
2189
|
|
|
if(!$document_srls || !count($document_srls)) return new BaseObject(); |
|
|
|
|
2190
|
|
|
|
2191
|
|
|
// Check if each of module administrators exists. Top-level administator will have a permission to modify every document of all modules.(Even to modify temporarily saved or trashed documents) |
2192
|
|
|
$oModuleModel = getModel('module'); |
2193
|
|
|
$module_srls = array_keys($document_srls); |
2194
|
|
|
for($i=0;$i<count($module_srls);$i++) |
|
|
|
|
2195
|
|
|
{ |
2196
|
|
|
$module_srl = $module_srls[$i]; |
2197
|
|
|
$module_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl); |
2198
|
|
|
$logged_info = Context::get('logged_info'); |
2199
|
|
|
if($logged_info->is_admin != 'Y') |
2200
|
|
|
{ |
2201
|
|
|
if(!$module_info) |
2202
|
|
|
{ |
2203
|
|
|
unset($document_srls[$module_srl]); |
2204
|
|
|
continue; |
2205
|
|
|
} |
2206
|
|
|
$grant = $oModuleModel->getGrant($module_info, $logged_info); |
2207
|
|
|
if(!$grant->manager) |
2208
|
|
|
{ |
2209
|
|
|
unset($document_srls[$module_srl]); |
2210
|
|
|
continue; |
2211
|
|
|
} |
2212
|
|
|
} |
2213
|
|
|
} |
2214
|
|
|
if(!count($document_srls)) return new BaseObject(); |
2215
|
|
|
|
2216
|
|
|
foreach($document_srls as $module_srl => $documents) |
2217
|
|
|
{ |
2218
|
|
|
$cnt = count($documents); |
2219
|
|
|
for($i=0;$i<$cnt;$i++) |
2220
|
|
|
{ |
2221
|
|
|
$document_srl = (int)trim($documents[$i]); |
2222
|
|
|
if(!$document_srls) continue; |
|
|
|
|
2223
|
|
|
if($_SESSION['document_management'][$document_srl]) unset($_SESSION['document_management'][$document_srl]); |
2224
|
|
|
else $_SESSION['document_management'][$document_srl] = true; |
2225
|
|
|
} |
2226
|
|
|
} |
2227
|
|
|
} |
2228
|
|
|
|
2229
|
|
|
/** |
2230
|
|
|
* Move/ Delete the document in the seession |
2231
|
|
|
* @return void|BaseObject |
2232
|
|
|
*/ |
2233
|
|
|
function procDocumentManageCheckedDocument() |
2234
|
|
|
{ |
2235
|
|
|
@set_time_limit(0); |
|
|
|
|
2236
|
|
|
if(!Context::get('is_logged')) return new BaseObject(-1,'msg_not_permitted'); |
2237
|
|
|
|
2238
|
|
|
if(!checkCSRF()) |
2239
|
|
|
{ |
2240
|
|
|
return new BaseObject(-1, 'msg_invalid_request'); |
2241
|
|
|
} |
2242
|
|
|
|
2243
|
|
|
$type = Context::get('type'); |
2244
|
|
|
$target_module = Context::get('target_module_srl'); |
2245
|
|
|
$module_srl = Context::get('module_srl'); |
2246
|
|
|
if($target_module && !$module_srl) $module_srl = $target_module; |
2247
|
|
|
$category_srl = Context::get('target_category_srl'); |
2248
|
|
|
$message_content = strip_tags(Context::get('message_content')); |
2249
|
|
|
if($message_content) $message_content = nl2br($message_content); |
2250
|
|
|
|
2251
|
|
|
$cart = Context::get('cart'); |
2252
|
|
|
$document_srl_list = (!is_array($cart)) ? explode('|@|', $cart) : $cart; |
2253
|
|
|
|
2254
|
|
|
array_map(function ($value) { return (int)$value; }, $document_srl_list); |
2255
|
|
|
|
2256
|
|
|
$document_srl_count = count($document_srl_list); |
2257
|
|
|
|
2258
|
|
|
$oDocumentModel = getModel('document'); |
2259
|
|
|
$document_items = array(); |
2260
|
|
|
foreach($document_srl_list as $document_srl) |
2261
|
|
|
{ |
2262
|
|
|
$oDocument = $oDocumentModel->getDocument($document_srl); |
2263
|
|
|
$document_items[] = $oDocument; |
2264
|
|
|
if(!$oDocument->isGranted()) return $this->stop('msg_not_permitted'); |
2265
|
|
|
} |
2266
|
|
|
|
2267
|
|
|
// Send a message |
2268
|
|
|
if($message_content) |
2269
|
|
|
{ |
2270
|
|
|
|
2271
|
|
|
$oCommunicationController = getController('communication'); |
2272
|
|
|
|
2273
|
|
|
$logged_info = Context::get('logged_info'); |
2274
|
|
|
|
2275
|
|
|
$title = cut_str($message_content,10,'...'); |
2276
|
|
|
$sender_member_srl = $logged_info->member_srl; |
2277
|
|
|
|
2278
|
|
|
foreach($document_items as $oDocument) |
2279
|
|
|
{ |
2280
|
|
|
if(!$oDocument->get('member_srl') || $oDocument->get('member_srl')==$sender_member_srl) continue; |
2281
|
|
|
|
2282
|
|
|
if($type=='move') $purl = sprintf("<a href=\"%s\" target=\"_blank\">%s</a>", $oDocument->getPermanentUrl(), $oDocument->getPermanentUrl()); |
2283
|
|
|
else $purl = ""; |
2284
|
|
|
$content = sprintf("<div>%s</div><hr />%s<div style=\"font-weight:bold\">%s</div>%s",$message_content, $purl, $oDocument->getTitleText(), $oDocument->getContent(false, false, false)); |
2285
|
|
|
|
2286
|
|
|
$oCommunicationController->sendMessage($sender_member_srl, $oDocument->get('member_srl'), $title, $content, false); |
2287
|
|
|
} |
2288
|
|
|
} |
2289
|
|
|
// Set a spam-filer not to be filtered to spams |
2290
|
|
|
$oSpamController = getController('spamfilter'); |
2291
|
|
|
$oSpamController->setAvoidLog(); |
2292
|
|
|
|
2293
|
|
|
$oDocumentAdminController = getAdminController('document'); |
2294
|
|
|
if($type == 'move') |
2295
|
|
|
{ |
2296
|
|
|
if(!$module_srl) return new BaseObject(-1, 'fail_to_move'); |
2297
|
|
|
|
2298
|
|
|
$output = $oDocumentAdminController->moveDocumentModule($document_srl_list, $module_srl, $category_srl); |
2299
|
|
|
if(!$output->toBool()) return new BaseObject(-1, 'fail_to_move'); |
2300
|
|
|
|
2301
|
|
|
$msg_code = 'success_moved'; |
2302
|
|
|
|
2303
|
|
|
} |
2304
|
|
|
else if($type == 'copy') |
2305
|
|
|
{ |
2306
|
|
|
if(!$module_srl) return new BaseObject(-1, 'fail_to_move'); |
2307
|
|
|
|
2308
|
|
|
$output = $oDocumentAdminController->copyDocumentModule($document_srl_list, $module_srl, $category_srl); |
2309
|
|
|
if(!$output->toBool()) return new BaseObject(-1, 'fail_to_move'); |
2310
|
|
|
|
2311
|
|
|
$msg_code = 'success_copied'; |
2312
|
|
|
} |
2313
|
|
|
else if($type =='delete') |
2314
|
|
|
{ |
2315
|
|
|
$oDB = &DB::getInstance(); |
2316
|
|
|
$oDB->begin(); |
2317
|
|
View Code Duplication |
for($i=0;$i<$document_srl_count;$i++) |
2318
|
|
|
{ |
2319
|
|
|
$document_srl = $document_srl_list[$i]; |
2320
|
|
|
$output = $this->deleteDocument($document_srl, true); |
2321
|
|
|
if(!$output->toBool()) return new BaseObject(-1, 'fail_to_delete'); |
2322
|
|
|
} |
2323
|
|
|
$oDB->commit(); |
2324
|
|
|
$msg_code = 'success_deleted'; |
2325
|
|
|
} |
2326
|
|
|
else if($type == 'trash') |
2327
|
|
|
{ |
2328
|
|
|
$args = new stdClass(); |
2329
|
|
|
$args->description = $message_content; |
2330
|
|
|
|
2331
|
|
|
$oDB = &DB::getInstance(); |
2332
|
|
|
$oDB->begin(); |
2333
|
|
View Code Duplication |
for($i=0;$i<$document_srl_count;$i++) { |
2334
|
|
|
$args->document_srl = $document_srl_list[$i]; |
2335
|
|
|
$output = $this->moveDocumentToTrash($args); |
2336
|
|
|
if(!$output || !$output->toBool()) return new BaseObject(-1, 'fail_to_trash'); |
2337
|
|
|
} |
2338
|
|
|
$oDB->commit(); |
2339
|
|
|
$msg_code = 'success_trashed'; |
2340
|
|
|
} |
2341
|
|
|
else if($type == 'cancelDeclare') |
2342
|
|
|
{ |
2343
|
|
|
$args->document_srl = $document_srl_list; |
|
|
|
|
2344
|
|
|
$output = executeQuery('document.deleteDeclaredDocuments', $args); |
|
|
|
|
2345
|
|
|
$msg_code = 'success_declare_canceled'; |
2346
|
|
|
} |
2347
|
|
|
|
2348
|
|
|
$_SESSION['document_management'] = array(); |
2349
|
|
|
|
2350
|
|
|
$this->setMessage($msg_code); |
|
|
|
|
2351
|
|
|
|
2352
|
|
|
$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispDocumentAdminList'); |
2353
|
|
|
$this->setRedirectUrl($returnUrl); |
2354
|
|
|
} |
2355
|
|
|
|
2356
|
|
|
/** |
2357
|
|
|
* Insert document module config |
2358
|
|
|
* @return void |
2359
|
|
|
*/ |
2360
|
|
|
function procDocumentInsertModuleConfig() |
2361
|
|
|
{ |
2362
|
|
|
$module_srl = Context::get('target_module_srl'); |
2363
|
|
View Code Duplication |
if(preg_match('/^([0-9,]+)$/',$module_srl)) $module_srl = explode(',',$module_srl); |
2364
|
|
|
else $module_srl = array($module_srl); |
2365
|
|
|
|
2366
|
|
|
$document_config = new stdClass(); |
2367
|
|
|
$document_config->use_history = Context::get('use_history'); |
2368
|
|
|
if(!$document_config->use_history) $document_config->use_history = 'N'; |
2369
|
|
|
|
2370
|
|
|
$document_config->use_vote_up = Context::get('use_vote_up'); |
2371
|
|
|
if(!$document_config->use_vote_up) $document_config->use_vote_up = 'Y'; |
2372
|
|
|
|
2373
|
|
|
$document_config->use_vote_down = Context::get('use_vote_down'); |
2374
|
|
|
if(!$document_config->use_vote_down) $document_config->use_vote_down = 'Y'; |
2375
|
|
|
|
2376
|
|
|
$document_config->use_status = Context::get('use_status'); |
2377
|
|
|
|
2378
|
|
|
$oModuleController = getController('module'); |
2379
|
|
View Code Duplication |
for($i=0;$i<count($module_srl);$i++) |
|
|
|
|
2380
|
|
|
{ |
2381
|
|
|
$srl = trim($module_srl[$i]); |
2382
|
|
|
if(!$srl) continue; |
2383
|
|
|
$output = $oModuleController->insertModulePartConfig('document',$srl,$document_config); |
|
|
|
|
2384
|
|
|
} |
2385
|
|
|
$this->setError(-1); |
2386
|
|
|
$this->setMessage('success_updated', 'info'); |
2387
|
|
|
|
2388
|
|
|
$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispBoardAdminContent'); |
2389
|
|
|
$this->setRedirectUrl($returnUrl); |
2390
|
|
|
} |
2391
|
|
|
|
2392
|
|
|
/** |
2393
|
|
|
* Document temporary save |
2394
|
|
|
* @return void|BaseObject |
2395
|
|
|
*/ |
2396
|
|
|
function procDocumentTempSave() |
2397
|
|
|
{ |
2398
|
|
|
// Check login information |
2399
|
|
|
if(!Context::get('is_logged')) return new BaseObject(-1, 'msg_not_logged'); |
2400
|
|
|
$module_info = Context::get('module_info'); |
2401
|
|
|
$logged_info = Context::get('logged_info'); |
|
|
|
|
2402
|
|
|
|
2403
|
|
|
// Get form information |
2404
|
|
|
$obj = Context::getRequestVars(); |
2405
|
|
|
// Change the target module to log-in information |
2406
|
|
|
$obj->module_srl = $module_info->module_srl; |
|
|
|
|
2407
|
|
|
$obj->status = $this->getConfigStatus('temp'); |
|
|
|
|
2408
|
|
|
unset($obj->is_notice); |
2409
|
|
|
|
2410
|
|
|
// Extract from beginning part of contents in the guestbook |
2411
|
|
|
if(!$obj->title) |
2412
|
|
|
{ |
2413
|
|
|
$obj->title = cut_str(strip_tags($obj->content), 20, '...'); |
|
|
|
|
2414
|
|
|
} |
2415
|
|
|
|
2416
|
|
|
$oDocumentModel = getModel('document'); |
2417
|
|
|
$oDocumentController = getController('document'); |
2418
|
|
|
// Check if already exist geulinji |
2419
|
|
|
$oDocument = $oDocumentModel->getDocument($obj->document_srl, $this->grant->manager); |
|
|
|
|
2420
|
|
|
|
2421
|
|
|
// Update if already exists |
2422
|
|
|
if($oDocument->isExists() && $oDocument->document_srl == $obj->document_srl) |
2423
|
|
|
{ |
2424
|
|
|
if($oDocument->get('module_srl') != $obj->module_srl) |
2425
|
|
|
{ |
2426
|
|
|
return new BaseObject(-1, 'msg_invalid_request'); |
2427
|
|
|
} |
2428
|
|
|
if(!$oDocument->isGranted()) |
2429
|
|
|
{ |
2430
|
|
|
return new BaseObject(-1, 'msg_invalid_request'); |
2431
|
|
|
} |
2432
|
|
|
//if exist document status is already public, use temp status can point problem |
2433
|
|
|
$obj->status = $oDocument->get('status'); |
|
|
|
|
2434
|
|
|
$output = $oDocumentController->updateDocument($oDocument, $obj); |
|
|
|
|
2435
|
|
|
$msg_code = 'success_updated'; |
|
|
|
|
2436
|
|
|
// Otherwise, get a new |
2437
|
|
|
} |
2438
|
|
|
else |
2439
|
|
|
{ |
2440
|
|
|
$output = $oDocumentController->insertDocument($obj); |
2441
|
|
|
$msg_code = 'success_registed'; |
|
|
|
|
2442
|
|
|
$obj->document_srl = $output->get('document_srl'); |
2443
|
|
|
$oDocument = $oDocumentModel->getDocument($obj->document_srl, $this->grant->manager); |
2444
|
|
|
} |
2445
|
|
|
// Set the attachment to be invalid state |
2446
|
|
View Code Duplication |
if($oDocument->hasUploadedFiles()) |
2447
|
|
|
{ |
2448
|
|
|
$args = new stdClass; |
2449
|
|
|
$args->upload_target_srl = $oDocument->document_srl; |
2450
|
|
|
$args->isvalid = 'N'; |
2451
|
|
|
executeQuery('file.updateFileValid', $args); |
2452
|
|
|
} |
2453
|
|
|
|
2454
|
|
|
$this->setMessage('success_saved'); |
2455
|
|
|
$this->add('document_srl', $obj->document_srl); |
2456
|
|
|
} |
2457
|
|
|
|
2458
|
|
|
/** |
2459
|
|
|
* Return Document List for exec_xml |
2460
|
|
|
* @return void|BaseObject |
2461
|
|
|
*/ |
2462
|
|
|
function procDocumentGetList() |
2463
|
|
|
{ |
2464
|
|
|
if(!Context::get('is_logged')) return new BaseObject(-1,'msg_not_permitted'); |
2465
|
|
|
$documentSrls = Context::get('document_srls'); |
2466
|
|
|
if($documentSrls) $documentSrlList = explode(',', $documentSrls); |
2467
|
|
|
|
2468
|
|
|
if(count($documentSrlList) > 0) |
2469
|
|
|
{ |
2470
|
|
|
$oDocumentModel = getModel('document'); |
2471
|
|
|
$columnList = array('document_srl', 'title', 'nick_name', 'status'); |
2472
|
|
|
$documentList = $oDocumentModel->getDocuments($documentSrlList, $this->grant->is_admin, false, $columnList); |
|
|
|
|
2473
|
|
|
} |
2474
|
|
|
else |
2475
|
|
|
{ |
2476
|
|
|
global $lang; |
2477
|
|
|
$documentList = array(); |
2478
|
|
|
$this->setMessage($lang->no_documents); |
2479
|
|
|
} |
2480
|
|
|
$oSecurity = new Security($documentList); |
2481
|
|
|
$oSecurity->encodeHTML('..variables.'); |
2482
|
|
|
$this->add('document_list', $documentList); |
2483
|
|
|
} |
2484
|
|
|
|
2485
|
|
|
/** |
2486
|
|
|
* For old version, comment allow status check. |
2487
|
|
|
* @param object $obj |
2488
|
|
|
* @return void |
2489
|
|
|
*/ |
2490
|
|
|
function _checkCommentStatusForOldVersion(&$obj) |
2491
|
|
|
{ |
2492
|
|
|
if(!isset($obj->allow_comment)) $obj->allow_comment = 'N'; |
2493
|
|
|
if(!isset($obj->lock_comment)) $obj->lock_comment = 'N'; |
2494
|
|
|
|
2495
|
|
|
if($obj->allow_comment == 'Y' && $obj->lock_comment == 'N') $obj->commentStatus = 'ALLOW'; |
2496
|
|
|
else $obj->commentStatus = 'DENY'; |
2497
|
|
|
} |
2498
|
|
|
|
2499
|
|
|
/** |
2500
|
|
|
* For old version, document status check. |
2501
|
|
|
* @param object $obj |
2502
|
|
|
* @return void |
2503
|
|
|
*/ |
2504
|
|
|
function _checkDocumentStatusForOldVersion(&$obj) |
2505
|
|
|
{ |
2506
|
|
|
if(!$obj->status && $obj->is_secret == 'Y') $obj->status = $this->getConfigStatus('secret'); |
2507
|
|
|
if(!$obj->status && $obj->is_secret != 'Y') $obj->status = $this->getConfigStatus('public'); |
2508
|
|
|
} |
2509
|
|
|
|
2510
|
|
|
public function updateUploaedCount($documentSrlList) |
2511
|
|
|
{ |
2512
|
|
|
$oDocumentModel = getModel('document'); |
|
|
|
|
2513
|
|
|
$oFileModel = getModel('file'); |
2514
|
|
|
|
2515
|
|
|
if(is_array($documentSrlList)) |
2516
|
|
|
{ |
2517
|
|
|
$documentSrlList = array_unique($documentSrlList); |
2518
|
|
|
foreach($documentSrlList AS $key => $documentSrl) |
2519
|
|
|
{ |
2520
|
|
|
$fileCount = $oFileModel->getFilesCount($documentSrl); |
2521
|
|
|
$args = new stdClass(); |
2522
|
|
|
$args->document_srl = $documentSrl; |
2523
|
|
|
$args->uploaded_count = $fileCount; |
2524
|
|
|
executeQuery('document.updateUploadedCount', $args); |
2525
|
|
|
} |
2526
|
|
|
} |
2527
|
|
|
} |
2528
|
|
|
|
2529
|
|
|
/** |
2530
|
|
|
* Copy extra keys when module copied |
2531
|
|
|
* @param object $obj |
2532
|
|
|
* @return void |
2533
|
|
|
*/ |
2534
|
|
|
function triggerCopyModuleExtraKeys(&$obj) |
2535
|
|
|
{ |
2536
|
|
|
$oDocumentModel = getModel('document'); |
2537
|
|
|
$documentExtraKeys = $oDocumentModel->getExtraKeys($obj->originModuleSrl); |
2538
|
|
|
|
2539
|
|
|
if(is_array($documentExtraKeys) && is_array($obj->moduleSrlList)) |
2540
|
|
|
{ |
2541
|
|
|
$oDocumentController=getController('document'); |
2542
|
|
|
foreach($obj->moduleSrlList AS $key=>$value) |
2543
|
|
|
{ |
2544
|
|
View Code Duplication |
foreach($documentExtraKeys AS $extraItem) |
2545
|
|
|
{ |
2546
|
|
|
$oDocumentController->insertDocumentExtraKey($value, $extraItem->idx, $extraItem->name, $extraItem->type, $extraItem->is_required , $extraItem->search , $extraItem->default , $extraItem->desc, $extraItem->eid) ; |
2547
|
|
|
} |
2548
|
|
|
} |
2549
|
|
|
} |
2550
|
|
|
} |
2551
|
|
|
|
2552
|
|
View Code Duplication |
function triggerCopyModule(&$obj) |
|
|
|
|
2553
|
|
|
{ |
2554
|
|
|
$oModuleModel = getModel('module'); |
2555
|
|
|
$documentConfig = $oModuleModel->getModulePartConfig('document', $obj->originModuleSrl); |
2556
|
|
|
|
2557
|
|
|
$oModuleController = getController('module'); |
2558
|
|
|
if(is_array($obj->moduleSrlList)) |
2559
|
|
|
{ |
2560
|
|
|
foreach($obj->moduleSrlList AS $key=>$moduleSrl) |
2561
|
|
|
{ |
2562
|
|
|
$oModuleController->insertModulePartConfig('document', $moduleSrl, $documentConfig); |
2563
|
|
|
} |
2564
|
|
|
} |
2565
|
|
|
} |
2566
|
|
|
} |
2567
|
|
|
/* End of file document.controller.php */ |
2568
|
|
|
/* Location: ./modules/document/document.controller.php */ |
2569
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.