XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
poll.controller.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
8 class pollController extends poll
9 {
13  function init()
14  {
15  }
16 
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 BaseObject(-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 
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 BaseObject(-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 BaseObject(-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  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 
244  {
245  $poll_srl = Context::get('poll_srl');
246 
247  $skin = Context::get('skin');
248  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 
260  function procPollGetList()
261  {
262  if(!Context::get('is_logged')) return new BaseObject(-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 
297  {
298  $this->syncPoll($obj->document_srl, $obj->content);
299  return new BaseObject();
300  }
301 
306  {
307  $this->syncPoll($obj->comment_srl, $obj->content);
308  return new BaseObject();
309  }
310 
315  {
316  $this->syncPoll($obj->document_srl, $obj->content);
317  return new BaseObject();
318  }
319 
324  {
325  $this->syncPoll($obj->comment_srl, $obj->content);
326  return new BaseObject();
327  }
328 
333  {
334  $document_srl = $obj->document_srl;
335  if(!$document_srl) return new BaseObject();
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 BaseObject();
341 
342  $poll_srl = $output->data->poll_srl;
343  if(!$poll_srl) return new BaseObject();
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 BaseObject();
360  }
361 
366  {
367  $comment_srl = $obj->comment_srl;
368  if(!$comment_srl) return new BaseObject();
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 BaseObject();
374 
375  $poll_srl = $output->data->poll_srl;
376  if(!$poll_srl) return new BaseObject();
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 BaseObject();
393  }
394 
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 */
setMessage($message= 'success', $type=NULL)
$obj
Definition: ko.install.php:262
$output
Definition: ko.install.php:193
add($key, $val)
triggerDeleteDocumentPoll(&$obj)
A poll deletion trigger when a post is removed.
getNotEncodedUrl()
Definition: func.inc.php:316
procPollInsert()
after a qeustion is created in the popup window, register the question during the save time ...
procPollGetList()
poll list
$args
Definition: ko.install.php:185
triggerUpdateDocumentPoll(&$obj)
A poll synchronization trigger when a post is updated.
triggerInsertCommentPoll(&$obj)
A poll synchronization trigger when a new comment is registered.
setRedirectUrl($url= './', $output=NULL)
syncPoll($upload_target_srl, $content)
As post content&#39;s poll is obtained, synchronize the poll using the document number.
$document_srl
Definition: ko.install.php:279
getAdminModel($module_name)
Definition: func.inc.php:156
getInstance($db_type=NULL)
Definition: DB.class.php:142
procPollViewResult()
Preview the results.
const _XE_PATH_
Definition: config.inc.php:49
getNextSequence()
Definition: func.inc.php:236
getModel($module_name)
Definition: func.inc.php:145
triggerUpdateCommentPoll(&$obj)
A poll synchronization trigger when a comment is updated.
init()
Initialization.
procPoll()
Accept the poll.
triggerInsertDocumentPoll(&$obj)
A poll synchronization trigger when a new post is registered.
executeQuery($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:203
The parent class of the poll module.
Definition: poll.class.php:8
triggerDeleteCommentPoll(&$obj)
A poll deletion trigger when a comment is removed.
Controller class for poll module.
if(isset($_REQUEST['encode'])) if(isset($_REQUEST['decode'])) $lang
Definition: example.php:23