1
|
|
|
<?php |
2
|
|
|
/* Copyright (C) NAVER <http://www.navercorp.com> */ |
3
|
|
|
/** |
4
|
|
|
* @class pollController |
5
|
|
|
* @author NAVER ([email protected]) |
6
|
|
|
* @brief Controller class for poll module |
7
|
|
|
*/ |
8
|
|
|
class pollController extends poll |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @brief Initialization |
12
|
|
|
*/ |
13
|
|
|
function init() |
14
|
|
|
{ |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @brief after a qeustion is created in the popup window, register the question during the save time |
19
|
|
|
*/ |
20
|
|
|
function procPollInsert() |
21
|
|
|
{ |
22
|
|
|
$stop_date = Context::get('stop_date'); |
23
|
|
|
if($stop_date < date('Ymd')) |
24
|
|
|
{ |
25
|
|
|
$stop_date = date('YmdHis', $_SERVER['REQUEST_TIME']+60*60*24*365); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$logged_info = Context::get('logged_info'); |
29
|
|
|
$vars = Context::getRequestVars(); |
30
|
|
|
$args = new stdClass; |
31
|
|
|
$tmp_args = array(); |
32
|
|
|
|
33
|
|
|
unset($vars->_filter); |
34
|
|
|
unset($vars->error_return_url); |
35
|
|
|
unset($vars->stop_date); |
36
|
|
|
|
37
|
|
|
foreach($vars as $key => $val) |
38
|
|
|
{ |
39
|
|
|
if(stripos($key, 'tidx')) |
40
|
|
|
{ |
41
|
|
|
continue; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$tmp_arr = explode('_', $key); |
45
|
|
|
|
46
|
|
|
$poll_index = $tmp_arr[1]; |
47
|
|
|
if(!$poll_index) |
48
|
|
|
{ |
49
|
|
|
continue; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if(!trim($val)) |
53
|
|
|
{ |
54
|
|
|
continue; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if($tmp_args[$poll_index] == NULL) |
58
|
|
|
{ |
59
|
|
|
$tmp_args[$poll_index] = new stdClass; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if(!is_array($tmp_args[$poll_index]->item)) |
63
|
|
|
{ |
64
|
|
|
$tmp_args[$poll_index]->item = array(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
if($logged_info->is_admin != 'Y') |
68
|
|
|
{ |
69
|
|
|
$val = htmlspecialchars($val, ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
switch($tmp_arr[0]) |
73
|
|
|
{ |
74
|
|
|
case 'title': |
75
|
|
|
$tmp_args[$poll_index]->title = $val; |
76
|
|
|
break; |
77
|
|
|
case 'checkcount': |
78
|
|
|
$tmp_args[$poll_index]->checkcount = $val; |
79
|
|
|
break; |
80
|
|
|
case 'item': |
81
|
|
|
$tmp_args[$poll_index]->item[] = $val; |
82
|
|
|
break; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
foreach($tmp_args as $key => $val) |
87
|
|
|
{ |
88
|
|
|
if(!$val->checkcount) |
89
|
|
|
{ |
90
|
|
|
$val->checkcount = 1; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
if($val->title && count($val->item)) |
94
|
|
|
{ |
95
|
|
|
$args->poll[] = $val; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
if(!count($args->poll)) return new Object(-1, 'cmd_null_item'); |
100
|
|
|
|
101
|
|
|
$args->stop_date = $stop_date; |
102
|
|
|
|
103
|
|
|
// Configure the variables |
104
|
|
|
$poll_srl = getNextSequence(); |
105
|
|
|
$member_srl = $logged_info->member_srl?$logged_info->member_srl:0; |
106
|
|
|
|
107
|
|
|
$oDB = &DB::getInstance(); |
108
|
|
|
$oDB->begin(); |
109
|
|
|
|
110
|
|
|
// Register the poll |
111
|
|
|
$poll_args = new stdClass; |
112
|
|
|
$poll_args->poll_srl = $poll_srl; |
113
|
|
|
$poll_args->member_srl = $member_srl; |
114
|
|
|
$poll_args->list_order = $poll_srl*-1; |
115
|
|
|
$poll_args->stop_date = $args->stop_date; |
116
|
|
|
$poll_args->poll_count = 0; |
117
|
|
|
$output = executeQuery('poll.insertPoll', $poll_args); |
118
|
|
|
if(!$output->toBool()) |
119
|
|
|
{ |
120
|
|
|
$oDB->rollback(); |
121
|
|
|
return $output; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
// Individual poll registration |
125
|
|
|
foreach($args->poll as $key => $val) |
126
|
|
|
{ |
127
|
|
|
$title_args = new stdClass; |
128
|
|
|
$title_args->poll_srl = $poll_srl; |
129
|
|
|
$title_args->poll_index_srl = getNextSequence(); |
130
|
|
|
$title_args->title = $val->title; |
131
|
|
|
$title_args->checkcount = $val->checkcount; |
132
|
|
|
$title_args->poll_count = 0; |
133
|
|
|
$title_args->list_order = $title_args->poll_index_srl * -1; |
134
|
|
|
$title_args->member_srl = $member_srl; |
135
|
|
|
$title_args->upload_target_srl = $upload_target_srl; |
|
|
|
|
136
|
|
|
$output = executeQuery('poll.insertPollTitle', $title_args); |
137
|
|
|
if(!$output->toBool()) |
138
|
|
|
{ |
139
|
|
|
$oDB->rollback(); |
140
|
|
|
return $output; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
// Add the individual survey items |
144
|
|
|
foreach($val->item as $k => $v) |
145
|
|
|
{ |
146
|
|
|
$item_args = new stdClass; |
147
|
|
|
$item_args->poll_srl = $poll_srl; |
148
|
|
|
$item_args->poll_index_srl = $title_args->poll_index_srl; |
149
|
|
|
$item_args->title = $v; |
150
|
|
|
$item_args->poll_count = 0; |
151
|
|
|
$item_args->upload_target_srl = $upload_target_srl; |
152
|
|
|
$output = executeQuery('poll.insertPollItem', $item_args); |
153
|
|
|
if(!$output->toBool()) |
154
|
|
|
{ |
155
|
|
|
$oDB->rollback(); |
156
|
|
|
return $output; |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
$oDB->commit(); |
162
|
|
|
|
163
|
|
|
$this->add('poll_srl', $poll_srl); |
164
|
|
|
$this->setMessage('success_registed'); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @brief Accept the poll |
169
|
|
|
*/ |
170
|
|
|
function procPoll() |
171
|
|
|
{ |
172
|
|
|
$poll_srl = Context::get('poll_srl'); |
173
|
|
|
$poll_srl_indexes = Context::get('poll_srl_indexes'); |
174
|
|
|
$tmp_item_srls = explode(',',$poll_srl_indexes); |
175
|
|
|
for($i=0;$i<count($tmp_item_srls);$i++) |
|
|
|
|
176
|
|
|
{ |
177
|
|
|
$srl = (int)trim($tmp_item_srls[$i]); |
178
|
|
|
if(!$srl) continue; |
179
|
|
|
$item_srls[] = $srl; |
|
|
|
|
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
// If there is no response item, display an error |
183
|
|
|
if(!count($item_srls)) return new Object(-1, 'msg_check_poll_item'); |
|
|
|
|
184
|
|
|
// Make sure is the poll has already been taken |
185
|
|
|
$oPollModel = getModel('poll'); |
186
|
|
|
if($oPollModel->isPolled($poll_srl)) return new Object(-1, 'msg_already_poll'); |
187
|
|
|
|
188
|
|
|
$oDB = &DB::getInstance(); |
189
|
|
|
$oDB->begin(); |
190
|
|
|
|
191
|
|
|
$args = new stdClass; |
192
|
|
|
$args->poll_srl = $poll_srl; |
193
|
|
|
// Update all poll responses related to the post |
194
|
|
|
$output = executeQuery('poll.updatePoll', $args); |
|
|
|
|
195
|
|
|
$output = executeQuery('poll.updatePollTitle', $args); |
196
|
|
|
if(!$output->toBool()) |
197
|
|
|
{ |
198
|
|
|
$oDB->rollback(); |
199
|
|
|
return $output; |
200
|
|
|
} |
201
|
|
|
// Record each polls selected items |
202
|
|
|
$args->poll_item_srl = implode(',',$item_srls); |
203
|
|
|
$output = executeQuery('poll.updatePollItems', $args); |
204
|
|
|
if(!$output->toBool()) |
205
|
|
|
{ |
206
|
|
|
$oDB->rollback(); |
207
|
|
|
return $output; |
208
|
|
|
} |
209
|
|
|
// Log the respondent's information |
210
|
|
|
$log_args = new stdClass; |
211
|
|
|
$log_args->poll_srl = $poll_srl; |
212
|
|
|
|
213
|
|
|
$logged_info = Context::get('logged_info'); |
214
|
|
|
$member_srl = $logged_info->member_srl?$logged_info->member_srl:0; |
215
|
|
|
|
216
|
|
|
$log_args->member_srl = $member_srl; |
217
|
|
|
$log_args->ipaddress = $_SERVER['REMOTE_ADDR']; |
218
|
|
|
$output = executeQuery('poll.insertPollLog', $log_args); |
219
|
|
|
if(!$output->toBool()) |
220
|
|
|
{ |
221
|
|
|
$oDB->rollback(); |
222
|
|
|
return $output; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
$oDB->commit(); |
226
|
|
|
|
227
|
|
|
$skin = Context::get('skin'); |
228
|
|
View Code Duplication |
if(!$skin || !is_dir(_XE_PATH_ . 'modules/poll/skins/'.$skin)) $skin = 'default'; |
229
|
|
|
// Get tpl |
230
|
|
|
$tpl = $oPollModel->getPollHtml($poll_srl, '', $skin); |
231
|
|
|
|
232
|
|
|
$this->add('poll_srl', $poll_srl); |
233
|
|
|
$this->add('tpl',$tpl); |
234
|
|
|
$this->setMessage('success_poll'); |
235
|
|
|
|
236
|
|
|
$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispPollAdminConfig'); |
237
|
|
|
$this->setRedirectUrl($returnUrl); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @brief Preview the results |
242
|
|
|
*/ |
243
|
|
|
function procPollViewResult() |
244
|
|
|
{ |
245
|
|
|
$poll_srl = Context::get('poll_srl'); |
246
|
|
|
|
247
|
|
|
$skin = Context::get('skin'); |
248
|
|
View Code Duplication |
if(!$skin || !is_dir(_XE_PATH_ . 'modules/poll/skins/'.$skin)) $skin = 'default'; |
249
|
|
|
|
250
|
|
|
$oPollModel = getModel('poll'); |
251
|
|
|
$tpl = $oPollModel->getPollResultHtml($poll_srl, $skin); |
252
|
|
|
|
253
|
|
|
$this->add('poll_srl', $poll_srl); |
254
|
|
|
$this->add('tpl',$tpl); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* @brief poll list |
259
|
|
|
*/ |
260
|
|
|
function procPollGetList() |
261
|
|
|
{ |
262
|
|
|
if(!Context::get('is_logged')) return new Object(-1,'msg_not_permitted'); |
263
|
|
|
$pollSrls = Context::get('poll_srls'); |
264
|
|
|
if($pollSrls) $pollSrlList = explode(',', $pollSrls); |
265
|
|
|
|
266
|
|
|
global $lang; |
267
|
|
|
if(count($pollSrlList) > 0) |
268
|
|
|
{ |
269
|
|
|
$oPollAdminModel = getAdminModel('poll'); |
270
|
|
|
$args = new stdClass; |
271
|
|
|
$args->pollIndexSrlList = $pollSrlList; |
|
|
|
|
272
|
|
|
$output = $oPollAdminModel->getPollListWithMember($args); |
273
|
|
|
$pollList = $output->data; |
274
|
|
|
|
275
|
|
|
if(is_array($pollList)) |
276
|
|
|
{ |
277
|
|
|
foreach($pollList AS $key=>$value) |
278
|
|
|
{ |
279
|
|
|
if($value->checkcount == 1) $value->checkName = $lang->single_check; |
280
|
|
|
else $value->checkName = $lang->multi_check; |
281
|
|
|
} |
282
|
|
|
} |
283
|
|
|
} |
284
|
|
|
else |
285
|
|
|
{ |
286
|
|
|
$pollList = array(); |
287
|
|
|
$this->setMessage($lang->no_documents); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
$this->add('poll_list', $pollList); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* @brief A poll synchronization trigger when a new post is registered |
295
|
|
|
*/ |
296
|
|
|
function triggerInsertDocumentPoll(&$obj) |
297
|
|
|
{ |
298
|
|
|
$this->syncPoll($obj->document_srl, $obj->content); |
299
|
|
|
return new Object(); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* @brief A poll synchronization trigger when a new comment is registered |
304
|
|
|
*/ |
305
|
|
|
function triggerInsertCommentPoll(&$obj) |
306
|
|
|
{ |
307
|
|
|
$this->syncPoll($obj->comment_srl, $obj->content); |
308
|
|
|
return new Object(); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* @brief A poll synchronization trigger when a post is updated |
313
|
|
|
*/ |
314
|
|
|
function triggerUpdateDocumentPoll(&$obj) |
315
|
|
|
{ |
316
|
|
|
$this->syncPoll($obj->document_srl, $obj->content); |
317
|
|
|
return new Object(); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* @brief A poll synchronization trigger when a comment is updated |
322
|
|
|
*/ |
323
|
|
|
function triggerUpdateCommentPoll(&$obj) |
324
|
|
|
{ |
325
|
|
|
$this->syncPoll($obj->comment_srl, $obj->content); |
326
|
|
|
return new Object(); |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* @brief A poll deletion trigger when a post is removed |
331
|
|
|
*/ |
332
|
|
View Code Duplication |
function triggerDeleteDocumentPoll(&$obj) |
|
|
|
|
333
|
|
|
{ |
334
|
|
|
$document_srl = $obj->document_srl; |
335
|
|
|
if(!$document_srl) return new Object(); |
336
|
|
|
// Get the poll |
337
|
|
|
$args = new stdClass(); |
338
|
|
|
$args->upload_target_srl = $document_srl; |
339
|
|
|
$output = executeQuery('poll.getPollByTargetSrl', $args); |
340
|
|
|
if(!$output->data) return new Object(); |
341
|
|
|
|
342
|
|
|
$poll_srl = $output->data->poll_srl; |
343
|
|
|
if(!$poll_srl) return new Object(); |
344
|
|
|
|
345
|
|
|
$args->poll_srl = $poll_srl; |
346
|
|
|
|
347
|
|
|
$output = executeQuery('poll.deletePoll', $args); |
348
|
|
|
if(!$output->toBool()) return $output; |
349
|
|
|
|
350
|
|
|
$output = executeQuery('poll.deletePollItem', $args); |
351
|
|
|
if(!$output->toBool()) return $output; |
352
|
|
|
|
353
|
|
|
$output = executeQuery('poll.deletePollTitle', $args); |
354
|
|
|
if(!$output->toBool()) return $output; |
355
|
|
|
|
356
|
|
|
$output = executeQuery('poll.deletePollLog', $args); |
357
|
|
|
if(!$output->toBool()) return $output; |
358
|
|
|
|
359
|
|
|
return new Object(); |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* @brief A poll deletion trigger when a comment is removed |
364
|
|
|
*/ |
365
|
|
View Code Duplication |
function triggerDeleteCommentPoll(&$obj) |
|
|
|
|
366
|
|
|
{ |
367
|
|
|
$comment_srl = $obj->comment_srl; |
368
|
|
|
if(!$comment_srl) return new Object(); |
369
|
|
|
// Get the poll |
370
|
|
|
$args = new stdClass(); |
371
|
|
|
$args->upload_target_srl = $comment_srl; |
372
|
|
|
$output = executeQuery('poll.getPollByTargetSrl', $args); |
373
|
|
|
if(!$output->data) return new Object(); |
374
|
|
|
|
375
|
|
|
$poll_srl = $output->data->poll_srl; |
376
|
|
|
if(!$poll_srl) return new Object(); |
377
|
|
|
|
378
|
|
|
$args->poll_srl = $poll_srl; |
379
|
|
|
|
380
|
|
|
$output = executeQuery('poll.deletePoll', $args); |
381
|
|
|
if(!$output->toBool()) return $output; |
382
|
|
|
|
383
|
|
|
$output = executeQuery('poll.deletePollItem', $args); |
384
|
|
|
if(!$output->toBool()) return $output; |
385
|
|
|
|
386
|
|
|
$output = executeQuery('poll.deletePollTitle', $args); |
387
|
|
|
if(!$output->toBool()) return $output; |
388
|
|
|
|
389
|
|
|
$output = executeQuery('poll.deletePollLog', $args); |
390
|
|
|
if(!$output->toBool()) return $output; |
391
|
|
|
|
392
|
|
|
return new Object(); |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
/** |
396
|
|
|
* @brief As post content's poll is obtained, synchronize the poll using the document number |
397
|
|
|
*/ |
398
|
|
|
function syncPoll($upload_target_srl, $content) |
399
|
|
|
{ |
400
|
|
|
$match_cnt = preg_match_all('!<img([^\>]*)poll_srl=(["\']?)([0-9]*)(["\']?)([^\>]*?)\>!is',$content, $matches); |
401
|
|
|
for($i=0;$i<$match_cnt;$i++) |
402
|
|
|
{ |
403
|
|
|
$poll_srl = $matches[3][$i]; |
404
|
|
|
|
405
|
|
|
$args = new stdClass; |
406
|
|
|
$args->poll_srl = $poll_srl; |
407
|
|
|
$output = executeQuery('poll.getPoll', $args); |
408
|
|
|
$poll = $output->data; |
409
|
|
|
|
410
|
|
|
if($poll->upload_target_srl) continue; |
411
|
|
|
|
412
|
|
|
$args->upload_target_srl = $upload_target_srl; |
413
|
|
|
$output = executeQuery('poll.updatePollTarget', $args); |
|
|
|
|
414
|
|
|
$output = executeQuery('poll.updatePollTitleTarget', $args); |
|
|
|
|
415
|
|
|
$output = executeQuery('poll.updatePollItemTarget', $args); |
|
|
|
|
416
|
|
|
} |
417
|
|
|
} |
418
|
|
|
} |
419
|
|
|
/* End of file poll.controller.php */ |
420
|
|
|
/* Location: ./modules/poll/poll.controller.php */ |
421
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.