PageRenderTime 64ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/e107_plugins/poll/poll_class.php

https://github.com/CasperGemini/e107
PHP | 910 lines | 658 code | 149 blank | 103 comment | 109 complexity | f8341ed12d05a5a221a43cde09ebb0d1 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. * e107 website system
  4. *
  5. * Copyright (C) 2008-2013 e107 Inc (e107.org)
  6. * Released under the terms and conditions of the
  7. * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
  8. *
  9. */
  10. if (!defined('e107_INIT')) { exit; }
  11. include_lan(e_PLUGIN.'poll/languages/'.e_LANGUAGE.'.php');
  12. define('POLLCLASS', TRUE);
  13. define('POLL_MODE_COOKIE', 0);
  14. define('POLL_MODE_IP', 1);
  15. define('POLL_MODE_USERID', 2);
  16. class poll
  17. {
  18. var $pollRow;
  19. var $pollmode;
  20. var $barl = null;
  21. var $barr = null;
  22. var $bar = null;
  23. function __construct()
  24. {
  25. $this->barl = (file_exists(THEME.'images/barl.png') ? THEME_ABS.'images/barl.png' : e_PLUGIN_ABS.'poll/images/barl.png');
  26. $this->barr = (file_exists(THEME.'images/barr.png') ? THEME_ABS.'images/barr.png' : e_PLUGIN_ABS.'poll/images/barr.png');
  27. $this->bar = (file_exists(THEME.'images/bar.png') ? THEME_ABS.'images/bar.png' : e_PLUGIN_ABS.'poll/images/bar.png');
  28. }
  29. /*
  30. function remove_poll_cookies
  31. Remove unused poll cookies. See: http://krijnhoetmer.nl/stuff/javascript/maximum-cookies/ Thanks Fanat1k - bugtracker #4983
  32. no parameters
  33. */
  34. function remove_poll_cookies()
  35. {
  36. $arr_polls_cookies = array();
  37. foreach($_COOKIE as $cookie_name => $cookie_val)
  38. { // Collect poll cookies
  39. list($str, $int) = explode('_', $cookie_name);
  40. if (($str == 'poll') && is_numeric($int))
  41. { // Yes, its poll's cookie
  42. $arr_polls_cookies[] = $int;
  43. }
  44. }
  45. if (count($arr_polls_cookies) > 1)
  46. { // Remove all except first (assumption: there is always only one active poll)
  47. rsort($arr_polls_cookies);
  48. for($i = 1; $i < count($arr_polls_cookies); $i++)
  49. {
  50. cookie("poll_{$arr_polls_cookies[$i]}", "", (time() - 2592000));
  51. }
  52. }
  53. }
  54. /*
  55. function delete_poll
  56. parameter in: $existing - existing poll id to be deleted
  57. parameter out: language text string on succesful delete, nothing on failed deletion
  58. */
  59. function delete_poll($existing)
  60. {
  61. global $admin_log;
  62. $sql = e107::getDb();
  63. if ($sql->delete("polls", " poll_id='".intval($existing)."' "))
  64. {
  65. if (function_exists("admin_purge_related"))
  66. {
  67. admin_purge_related("poll", $existing);
  68. }
  69. $admin_log->log_event('POLL_01',LAN_AL_POLL_01.': '.$existing,'');
  70. //return POLL_ADLAN08;
  71. }
  72. }
  73. /*
  74. function submit_poll
  75. $mode = 1 :: poll is main poll
  76. $mode = 2 :: poll is forum poll
  77. returns message
  78. */
  79. function submit_poll($mode=1)
  80. {
  81. global $admin_log;
  82. $tp = e107::getParser();
  83. $sql = e107::getDb();
  84. $poll_title = $tp->toDB($_POST['poll_title']);
  85. $poll_comment = $tp->toDB($_POST['poll_comment']);
  86. $multipleChoice = intval($_POST['multipleChoice']);
  87. $showResults = intval($_POST['showResults']);
  88. $pollUserclass = intval($_POST['pollUserclass']);
  89. $storageMethod = intval($_POST['storageMethod']);
  90. $active_start = (!$_POST['startmonth'] || !$_POST['startday'] || !$_POST['startyear'] ? 0 : mktime (0, 0, 0, $_POST['startmonth'], $_POST['startday'], $_POST['startyear']));
  91. $active_end = (!$_POST['endmonth'] || !$_POST['endday'] || !$_POST['endyear'] ? 0 : mktime (0, 0, 0, $_POST['endmonth'], $_POST['endday'], $_POST['endyear']));
  92. $poll_options = '';
  93. $_POST['poll_option'] = array_filter($_POST['poll_option']);
  94. foreach ($_POST['poll_option'] as $key => $value)
  95. {
  96. $poll_options .= $tp->toDB($value).chr(1);
  97. }
  98. if (POLLACTION == 'edit' || vartrue($_POST['poll_id']))
  99. {
  100. $sql->update("polls", "poll_title='{$poll_title}',
  101. poll_options='{$poll_options}',
  102. poll_comment='{$poll_comment}',
  103. poll_type={$mode},
  104. poll_allow_multiple={$multipleChoice},
  105. poll_result_type={$showResults},
  106. poll_vote_userclass={$pollUserclass},
  107. poll_storage_method={$storageMethod}
  108. WHERE poll_id=".intval(POLLID));
  109. /* update poll results - bugtracker #1124 .... */
  110. $sql->select("polls", "poll_votes", "poll_id='".intval(POLLID)."' ");
  111. $foo = $sql->fetch();
  112. $voteA = explode(chr(1), $foo['poll_votes']);
  113. $opt = count($poll_option) - count($voteA);
  114. if ($opt)
  115. {
  116. for($a=0; $a<=$opt; $a++)
  117. {
  118. $foo['poll_votes'] .= '0'.chr(1);
  119. }
  120. $sql->update("polls", "poll_votes='".$foo['poll_votes']."' WHERE poll_id='".intval(POLLID)."' ");
  121. }
  122. $admin_log->log_event('POLL_02','ID: '.POLLID.' - '.$poll_title,'');
  123. //$message = POLLAN_45;
  124. }
  125. else
  126. {
  127. $votes = '';
  128. for($a=1; $a<=count($_POST['poll_option']); $a++)
  129. {
  130. $votes .= '0'.chr(1);
  131. }
  132. if ($mode == 1)
  133. {
  134. /* deactivate other polls */
  135. if ($sql->select("polls", "*", "poll_type=1 AND poll_vote_userclass!=255"))
  136. {
  137. $deacArray = $sql->db_getList();
  138. foreach ($deacArray as $deacpoll)
  139. {
  140. $sql->update("polls", "poll_end_datestamp='".time()."', poll_vote_userclass='255' WHERE poll_id=".$deacpoll['poll_id']);
  141. }
  142. }
  143. $ret = $sql->insert("polls", "'0', ".time().", ".intval($active_start).", ".intval($active_end).", ".ADMINID.", '{$poll_title}', '{$poll_options}', '{$votes}', '', '1', '".$tp->toDB($poll_comment)."', '".intval($multipleChoice)."', '".intval($showResults)."', '".intval($pollUserclass)."', '".intval($storageMethod)."'");
  144. $admin_log->log_event('POLL_03','ID: '.$ret.' - '.$poll_title,''); // Intentionally only log admin-entered polls
  145. }
  146. else
  147. {
  148. $sql->insert("polls", "'0', ".intval($_POST['iid']).", '0', '0', ".USERID.", '$poll_title', '$poll_options', '$votes', '', '2', '0', '".intval($multipleChoice)."', '0', '0', '".intval($storageMethod)."'");
  149. }
  150. }
  151. return $message;
  152. }
  153. function get_poll($query)
  154. {
  155. global $e107;
  156. $sql = e107::getDb();
  157. if ($sql->gen($query))
  158. {
  159. $pollArray = $sql->fetch();
  160. if (!check_class($pollArray['poll_vote_userclass']))
  161. {
  162. $POLLMODE = 'disallowed';
  163. }
  164. else
  165. {
  166. switch($pollArray['poll_storage_method'])
  167. {
  168. case POLL_MODE_COOKIE:
  169. $userid = '';
  170. $cookiename = 'poll_'.$pollArray['poll_id'];
  171. if (isset($_COOKIE[$cookiename]))
  172. {
  173. $POLLMODE = 'voted';
  174. }
  175. else
  176. {
  177. $POLLMODE = 'notvoted';
  178. }
  179. break;
  180. case POLL_MODE_IP:
  181. $userid = e107::getIPHandler()->getIP(FALSE);
  182. $voted_ids = explode('^', substr($pollArray['poll_ip'], 0, -1));
  183. if (in_array($userid, $voted_ids))
  184. {
  185. $POLLMODE = 'voted';
  186. }
  187. else
  188. {
  189. $POLLMODE = 'notvoted';
  190. }
  191. break;
  192. case POLL_MODE_USERID:
  193. if (!USER)
  194. {
  195. $POLLMODE = 'disallowed';
  196. }
  197. else
  198. {
  199. $userid = USERID;
  200. $voted_ids = explode('^', substr($pollArray['poll_ip'], 0, -1));
  201. if (in_array($userid, $voted_ids))
  202. {
  203. $POLLMODE = 'voted';
  204. }
  205. else
  206. {
  207. $POLLMODE = 'notvoted';
  208. }
  209. }
  210. break;
  211. }
  212. }
  213. }
  214. else
  215. {
  216. return FALSE;
  217. }
  218. if (isset($_POST['pollvote']) && $POLLMODE == 'notvoted' && ($POLLMODE != 'disallowed'))
  219. {
  220. if ($_POST['votea'])
  221. {
  222. // $sql -> db_Select("polls", "*", "poll_vote_userclass!=255 AND poll_type=1 ORDER BY poll_datestamp DESC LIMIT 0,1");
  223. $row = $pollArray;
  224. extract($row);
  225. $votes = explode(chr(1), $poll_votes);
  226. if (is_array($_POST['votea']))
  227. {
  228. /* multiple choice vote */
  229. foreach ($_POST['votea'] as $vote)
  230. {
  231. $vote = intval($vote);
  232. $votes[($vote-1)] ++;
  233. }
  234. }
  235. else
  236. {
  237. $votes[($_POST['votea']-1)] ++;
  238. }
  239. $optionArray = explode(chr(1), $pollArray['poll_options']);
  240. $optionArray = array_slice($optionArray, 0, -1);
  241. foreach ($optionArray as $k=>$v)
  242. {
  243. if (!$votes[$k])
  244. {
  245. $votes[$k] = 0;
  246. }
  247. }
  248. $votep = implode(chr(1), $votes);
  249. $pollArray['poll_votes'] = $votep;
  250. $sql->update("polls", "poll_votes = '$votep'".($pollArray['poll_storage_method'] != POLL_MODE_COOKIE ? ", poll_ip='".$poll_ip.$userid."^'" : '')." WHERE poll_id=".$poll_id);
  251. /*echo "
  252. <script type='text/javascript'>
  253. <!--
  254. setcook({$poll_id});
  255. //-->
  256. </script>
  257. ";
  258. */
  259. $poll_cookie_expire = time() + (3600 * 24 * 356 * 15); // FIXME cannot be used after 2023 (this year is the maxium unixstamp on 32 bit system)
  260. cookie('poll_'.$poll_id.'', $poll_id, $poll_cookie_expire);
  261. $POLLMODE = 'voted';
  262. }
  263. }
  264. $this->pollRow = $pollArray;
  265. $this->pollmode = $POLLMODE;
  266. }
  267. function render_poll($pollArray = "", $type = "menu", $POLLMODE = "", $returnMethod=FALSE)
  268. {
  269. $ns = e107::getRender();
  270. $tp = e107::getParser();
  271. $sql = e107::getDb();
  272. global $POLLSTYLE;
  273. switch ($POLLMODE)
  274. {
  275. case 'query' : // Show poll, register any vote
  276. if ($this->get_poll($pollArray) === FALSE)
  277. {
  278. return ''; // No display if no poll
  279. }
  280. $pollArray = $this->pollRow;
  281. $POLLMODE = $this->pollmode;
  282. break;
  283. case 'results' :
  284. if ($sql->gen($pollArray))
  285. {
  286. $pollArray = $sql->fetch();
  287. }
  288. break;
  289. }
  290. if ($type == 'preview')
  291. {
  292. $optionArray = array_filter($pollArray['poll_option']);
  293. $voteArray = array();
  294. $voteArray = array_pad($voteArray, count($optionArray), 0);
  295. $pollArray['poll_allow_multiple'] = $pollArray['multipleChoice'];
  296. }
  297. else if ($type == 'forum')
  298. {
  299. if (isset($_POST['fpreview']))
  300. {
  301. $pollArray['poll_allow_multiple'] = $pollArray['multipleChoice'];
  302. $optionArray = $pollArray['poll_option'];
  303. }
  304. else
  305. {
  306. $optionArray = explode(chr(1), $pollArray['poll_options']);
  307. $optionArray = array_slice($optionArray, 0, -1);
  308. }
  309. $voteArray = explode(chr(1), $pollArray['poll_votes']);
  310. // $voteArray = array_slice($voteArray, 0, -1);
  311. }
  312. else
  313. { // Get existing results
  314. $optionArray = explode(chr(1), $pollArray['poll_options']);
  315. $optionArray = array_slice($optionArray, 0, -1);
  316. $voteArray = explode(chr(1), $pollArray['poll_votes']);
  317. // $voteArray = array_slice($voteArray, 0, -1);
  318. }
  319. $voteTotal = array_sum($voteArray);
  320. $percentage = array();
  321. if (count($voteArray))
  322. {
  323. foreach ($voteArray as $votes)
  324. {
  325. if ($voteTotal > 0)
  326. {
  327. $percentage[] = round(($votes/$voteTotal) * 100, 2);
  328. }
  329. else
  330. {
  331. $percentage[] = 0;
  332. }
  333. }
  334. }
  335. /* get template */
  336. if (file_exists(THEME.'poll_template.php'))
  337. {
  338. require(THEME.'poll_template.php');
  339. }
  340. else if (!isset($POLL_NOTVOTED_START))
  341. {
  342. require(e_PLUGIN.'poll/templates/poll_template.php');
  343. }
  344. if(deftrue('BOOTSTRAP'))
  345. {
  346. if($type == 'forum')
  347. {
  348. require_once(e_PLUGIN."forum/templates/forum_poll_template.php");
  349. $POLL_FORUM_NOTVOTED_START = $FORUM_POLL_TEMPLATE['form']['start'];
  350. $POLL_FORUM_NOTVOTED_LOOP = $FORUM_POLL_TEMPLATE['form']['item'];
  351. $POLL_FORUM_NOTVOTED_END = $FORUM_POLL_TEMPLATE['form']['end'];
  352. $POLL_FORUM_VOTED_START = $FORUM_POLL_TEMPLATE['results']['start'];
  353. $POLL_FORUM_VOTED_LOOP = $FORUM_POLL_TEMPLATE['results']['item'];
  354. $POLL_FORUM_VOTED_END = $FORUM_POLL_TEMPLATE['results']['end'];
  355. }
  356. $POLL_NOTVOTED_START = $POLL_TEMPLATE['form']['start'];
  357. $POLL_NOTVOTED_LOOP = $POLL_TEMPLATE['form']['item'];
  358. $POLL_NOTVOTED_END = $POLL_TEMPLATE['form']['end'];
  359. $POLL_VOTED_START = $POLL_TEMPLATE['results']['start'];
  360. $POLL_VOTED_LOOP = $POLL_TEMPLATE['results']['item'];
  361. $POLL_VOTED_END = $POLL_TEMPLATE['results']['end'];
  362. }
  363. $preview = FALSE;
  364. if ($type == 'preview')
  365. {
  366. $POLLMODE = 'notvoted';
  367. }
  368. elseif ($type == 'forum')
  369. {
  370. $preview = TRUE;
  371. }
  372. $comment_total = 0;
  373. if ($pollArray['poll_comment'])
  374. { // Only get comments if they're allowed on poll. And we only need the count ATM
  375. $comment_total = $sql->count("comments", "(*)", "WHERE `comment_item_id`='".intval($pollArray['poll_id'])."' AND `comment_type`=4");
  376. }
  377. $sc = e107::getScBatch('poll');
  378. $sc->setVars($pollArray);
  379. $QUESTION = $tp->toHTML($pollArray['poll_title'], TRUE, "emotes_off, defs");
  380. $VOTE_TOTAL = POLLAN_31.": ".$voteTotal;
  381. $COMMENTS = ($pollArray['poll_comment'] ? " <a href='".e_HTTP."comment.php?comment.poll.".$pollArray['poll_id']."'>".POLLAN_27.": ".$comment_total."</a>" : "");
  382. $poll_count = $sql->count("polls", "(*)", "WHERE poll_id <= '".$pollArray['poll_id']."'");
  383. $OLDPOLLS = '';
  384. if ($poll_count > 1)
  385. {
  386. $OLDPOLLS = ($type == 'menu' ? "<a href='".e_PLUGIN_ABS."poll/oldpolls.php'>".POLLAN_28."</a>" : "");
  387. }
  388. $AUTHOR = POLLAN_35." ".($type == 'preview' || $type == 'forum' ? USERNAME : "<a href='".e_HTTP."user.php?id.".$pollArray['poll_admin_id']."'>".$pollArray['user_name']."</a>");
  389. switch ($POLLMODE)
  390. {
  391. case 'notvoted':
  392. $text = "<form method='post' action='".e_SELF.(e_QUERY ? "?".e_QUERY : "")."'>\n".preg_replace("/\{(.*?)\}/e", '$\1', ($type == "forum" ? $POLL_FORUM_NOTVOTED_START : $POLL_NOTVOTED_START));
  393. $count = 1;
  394. $sc->answerCount = 1;
  395. $alt = 0; // alternate style.
  396. $template = ($type == "forum") ? $POLL_FORUM_NOTVOTED_LOOP : $POLL_NOTVOTED_LOOP;
  397. foreach ($optionArray as $option)
  398. {
  399. $sc->answerOption = $option;
  400. // $MODE = ($mode) ? $mode : ""; /* debug */
  401. // $OPTIONBUTTON = ($pollArray['poll_allow_multiple'] ? "<input type='checkbox' name='votea[]' value='$count' />" : "<input type='radio' name='votea' value='$count' />");
  402. // $OPTION = $tp->toHTML($option, TRUE);
  403. // $OPTIONBUTTON = $tp->parseTemplate("{OPTIONBUTTON}",true);
  404. // $OPTION = $tp->parseTemplate("{OPTION}",true);
  405. // $OPTION = $tp->parseTemplate("{ANSWER}",true);
  406. $text .= $tp->parseTemplate($template, true, $sc);
  407. $count ++;
  408. $sc->answerCount++;
  409. }
  410. $SUBMITBUTTON = "<input class='button btn' type='submit' name='pollvote' value='".POLLAN_30."' />";
  411. if (('preview' == $type || $preview == TRUE) && strpos(e_SELF, "viewtopic") === FALSE)
  412. {
  413. $SUBMITBUTTON = "<input class='button btn e-tip' type='button' name='null' title='Disabled' value='".POLLAN_30."' />";
  414. }
  415. $text .= "\n".preg_replace("/\{(.*?)\}/e", '$\1', ($type == "forum" ? $POLL_FORUM_NOTVOTED_END : $POLL_NOTVOTED_END))."\n</form>";
  416. break;
  417. case 'voted':
  418. case 'results' :
  419. if ($pollArray['poll_result_type'] && !strstr(e_SELF, "comment.php"))
  420. {
  421. $text = "<div style='text-align: center;'><br /><br />".POLLAN_39."<br /><br /><a href='".e_HTTP."comment.php?comment.poll.".$pollArray['poll_id']."'>".POLLAN_40."</a></div><br /><br />";
  422. }
  423. else
  424. {
  425. $text = preg_replace("/\{(.*?)\}/e", '$\1', ($type == "forum" ? $POLL_FORUM_VOTED_START : $POLL_VOTED_START));
  426. $count = 0;
  427. foreach ($optionArray as $option)
  428. {
  429. $OPTION = $tp->toHTML($option, TRUE);
  430. $BAR = $this->generateBar($percentage[$count]);
  431. // $BAR = ($percentage[$count] ? "<div style='width: 100%'><div style='background-image: url($barl); width: 5px; height: 14px; float: left;'></div><div style='background-image: url($bar); width: ".min(intval($percentage[$count]), 90)."%; height: 14px; float: left;'></div><div style='background-image: url($barr); width: 5px; height: 14px; float: left;'></div></div>" : "");
  432. $PERCENTAGE = $percentage[$count]."%";
  433. $VOTES = POLLAN_31.": ".$voteArray[$count];
  434. $text .= preg_replace("/\{(.*?)\}/e", '$\1', ($type == "forum" ? $POLL_FORUM_VOTED_LOOP : $POLL_VOTED_LOOP));
  435. $count ++;
  436. }
  437. $text .= preg_replace("/\{(.*?)\}/e", '$\1', ($type == "forum" ? $POLL_FORUM_VOTED_END : $POLL_VOTED_END));
  438. }
  439. break;
  440. case 'disallowed':
  441. $text = preg_replace("/\{(.*?)\}/e", '$\1', $POLL_DISALLOWED_START);
  442. foreach ($optionArray as $option)
  443. {
  444. $MODE = $mode; /* debug */
  445. $OPTION = $tp->toHTML($option, TRUE);
  446. $text .= preg_replace("/\{(.*?)\}/e", '$\1', $POLL_DISALLOWED_LOOP);
  447. $count ++;
  448. }
  449. if ($pollArray['poll_vote_userclass'] == 253)
  450. {
  451. $DISALLOWMESSAGE = POLLAN_41;
  452. }
  453. elseif ($pollArray['poll_vote_userclass'] == 254)
  454. {
  455. $DISALLOWMESSAGE = POLLAN_42;
  456. }
  457. else
  458. {
  459. $DISALLOWMESSAGE = POLLAN_43;
  460. }
  461. $text .= preg_replace("/\{(.*?)\}/e", '$\1', $POLL_DISALLOWED_END);
  462. break;
  463. }
  464. if (!defined("POLLRENDERED")) define("POLLRENDERED", TRUE);
  465. $caption = (file_exists(THEME."images/poll_menu.png") ? "<img src='".THEME_ABS."images/poll_menu.png' alt='' /> ".POLLAN_MENU_CAPTION : POLLAN_MENU_CAPTION);
  466. if ($type == 'preview')
  467. {
  468. $caption = POLLAN_23.SEP."Preview"; // TODO LAN
  469. $text = "<div class='clearfix'>\n<div class='well span3'>".$text."</div></div>";
  470. }
  471. elseif ($type == 'forum')
  472. {
  473. $caption = LAN_4;
  474. }
  475. if ($returnMethod)
  476. {
  477. return $text;
  478. }
  479. else
  480. {
  481. $ns->tablerender($caption, $text, 'poll');
  482. }
  483. }
  484. function generateBar($perc)
  485. {
  486. if(deftrue('BOOTSTRAP',false))
  487. {
  488. $val = intval($perc);
  489. return '
  490. <div class="progress">
  491. <div class="bar progress-bar" role="progressbar" aria-valuenow="'.$val.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$val.'%;">
  492. <span class="sr-only">'.$val.'%</span>
  493. </div>
  494. </div>';
  495. }
  496. else
  497. {
  498. $barl = $this->barl;
  499. $barr = $this->barr;
  500. $bar = $this->bar;
  501. return ($perc ? "<div style='width: 100%'><div style='background-image: url($barl); width: 5px; height: 14px; float: left;'></div><div style='background-image: url($bar); width: ".min(intval($perc), 90)."%; height: 14px; float: left;'></div><div style='background-image: url($barr); width: 5px; height: 14px; float: left;'></div></div>" : "");
  502. }
  503. }
  504. /*
  505. function renderPollForm
  506. $mode = "admin" :: called from admin_config.php
  507. $mode = "forum" :: called from forum_post.php
  508. */
  509. /**
  510. * Render a Poll creation Form
  511. * @param $mode string - admin | forum | front
  512. */
  513. function renderPollForm($mode='admin')
  514. {
  515. $tp = e107::getParser();
  516. $frm = e107::getForm();
  517. // echo "MODE=".$mode;
  518. //XXX New v2.x default for front-end. Currently used by forum-post in bootstrap mode.
  519. // TODO Moc - Needs a more generic LAN rewrite when used on another area than forum
  520. if ($mode == 'front')
  521. {
  522. $text = "
  523. <div class='alert alert-info'>
  524. <small >".LAN_FORUM_3029."</small>
  525. </div>
  526. <div class='control-group'>
  527. <div>
  528. <input class='tbox input-xxlarge' placeholder='".LAN_FORUM_3030."' type='text' name='poll_title' size='70' value='".$tp->post_toForm(vartrue($_POST['poll_title']))."' maxlength='200' />
  529. </div>";
  530. $option_count = vartrue($_POST['poll_option']) ? count($_POST['poll_option']) : 2;
  531. $text .= "
  532. <div id='pollsection'>";
  533. for($count = 1; $count <= $option_count; $count++)
  534. {
  535. if ($count != 1 && $_POST['poll_option'][($count-1)] =="")
  536. {
  537. // break;
  538. }
  539. $opt = ($count==1) ? "id='pollopt' class='btn-group input-append' " : "";
  540. $text .="<span {$opt}><input placeholder='".LAN_FORUM_3031."' class='tbox' type='text' name='poll_option[]' size='40' value=\"".$_POST['poll_option'][($count-1)]."\" maxlength='200' />";
  541. $text .= "</span><br />";
  542. }
  543. $text .="</div>
  544. <div class='control-group'>
  545. <input class='btn' type='button' name='addoption' value='".LAN_FORUM_3032."' onclick=\"duplicateHTML('pollopt','pollsection')\" /><br />
  546. </div>
  547. </div>";
  548. //FIXME - get this looking good with Bootstrap CSS only.
  549. $opts = array(1 => LAN_YES, 0=> LAN_NO);
  550. // Set to IP address.. Can add a pref to Poll admin for 'default front-end storage method' if demand is there for it.
  551. $text .= "
  552. <div class='form-horizontal control-group'>
  553. <label class='control-label'>".LAN_FORUM_3033."</label>
  554. <div class='controls'>
  555. ". $frm->radio('multipleChoice',$opts, vartrue($_POST['multipleChoice'], 0) ).$frm->hidden('storageMethod',1)."
  556. </div>
  557. </div>
  558. ";
  559. return $text;
  560. /*
  561. $text .= "
  562. <div class='controls controls-row'>".POLL_506."
  563. <input type='radio' name='multi/pleChoice' value='1'".(vartrue($_POST['multipleChoice']) ? " checked='checked'" : "")." /> ".POLL_507."&nbsp;&nbsp;
  564. <input type='radio' name='multi/pleChoice' value='0'".(!$_POST['multipleChoice'] ? " checked='checked'" : "")." /> ".POLL_508."
  565. </div>";
  566. */
  567. //XXX Should NOT be decided by USER
  568. /*
  569. $text .= "
  570. <div>
  571. ".POLLAN_16."
  572. <input type='radio' name='storageMethod' value='0'".(!vartrue($_POST['storageMethod']) ? " checked='checked'" : "")." /> ".POLLAN_17."<br />
  573. <input type='radio' name='storageMethod' value='1'".($_POST['storageMethod'] == 1 ? " checked='checked'" : "")." /> ".POLLAN_18."<br />
  574. <input type='radio' name='storageMethod' value='2'".($_POST['storageMethod'] ==2 ? " checked='checked'" : "")." /> ".POLLAN_19."
  575. </div>
  576. ";
  577. */
  578. }
  579. //TODO Hardcoded FORUM code needs to be moved somewhere.
  580. if ($mode == 'forum')
  581. {
  582. $text = "
  583. <tr>
  584. <td colspan='2'><span class='smalltext'>".LAN_FORUM_3029."</span></td>
  585. </tr>
  586. <tr>
  587. <td style='width:20%'><div class='normaltext'>".LAN_FORUM_3030.": </div></td>
  588. <td style='width:80%'class='forumheader3'><input class='tbox' type='text' name='poll_title' size='70' value='".$tp->post_toForm(vartrue($_POST['poll_title']))."' maxlength='200' /></td>
  589. </tr>";
  590. $option_count = (count(vartrue($_POST['poll_option'])) ? count($_POST['poll_option']) : 1);
  591. $text .= "
  592. <tr>
  593. <td style='width:20%'>".LAN_FORUM_3031."</td>
  594. <td style='width:80%'>
  595. <div id='pollsection'>";
  596. for($count = 1; $count <= $option_count; $count++)
  597. {
  598. if ($count != 1 && $_POST['poll_option'][($count-1)] =="")
  599. {
  600. break;
  601. }
  602. $opt = ($count==1) ? "id='pollopt'" : "";
  603. $text .="<span {$opt}><input class='tbox' type='text' name='poll_option[]' size='40' value=\"".$_POST['poll_option'][($count-1)]."\" maxlength='200' />";
  604. $text .= "</span><br />";
  605. }
  606. $text .="
  607. </div>
  608. <input class='btn btn-default button' type='button' name='addoption' value='".LAN_FORUM_3032."' onclick=\"duplicateHTML('pollopt','pollsection')\" /><br />
  609. </td>
  610. </tr>
  611. <tr>
  612. <td style='width:20%'>".LAN_FORUM_3033."</td>
  613. <td style='width:80%'>
  614. <input type='radio' name='multipleChoice' value='1'".(vartrue($_POST['multipleChoice']) ? " checked='checked'" : "")." /> ".LAN_YES."&nbsp;&nbsp;
  615. <input type='radio' name='multipleChoice' value='0'".(!$_POST['multipleChoice'] ? " checked='checked'" : "")." /> ".LAN_NO."
  616. </td>
  617. </tr>
  618. <tr>
  619. <td style='width:30%'>".LAN_FORUM_3034."</td>
  620. <td>
  621. <input type='radio' name='storageMethod' value='0'".(!vartrue($_POST['storageMethod']) ? " checked='checked'" : "")." /> ".LAN_FORUM_3035."<br />
  622. <input type='radio' name='storageMethod' value='1'".($_POST['storageMethod'] == 1 ? " checked='checked'" : "")." /> ".LAN_FORUM_3036."<br />
  623. <input type='radio' name='storageMethod' value='2'".($_POST['storageMethod'] ==2 ? " checked='checked'" : "")." /> ".LAN_FORUM_3037."
  624. </td>
  625. </tr>
  626. ";
  627. return $text;
  628. }
  629. $formgo = e_SELF.(e_QUERY && !defined("RESET") && strpos(e_QUERY, 'delete') === FALSE ? "?".e_QUERY : "");
  630. $text = "<div style='text-align:center'>
  631. <form method='post' action='{$formgo}'>
  632. <table class='table adminform'>
  633. <colgroup>
  634. <col class='col-label' />
  635. <col class='col-control' />
  636. </colgroup>
  637. <tr>
  638. <td style='width:30%'><div class='normaltext'>".POLLAN_3.":</div></td>
  639. <td style='width:70%'>
  640. <input class='tbox input-xxlarge' type='text' name='poll_title' size='70' value='".$tp->post_toForm(varset($_POST['poll_title']))."' maxlength='200' />";
  641. $option_count = (varset($_POST['poll_option']) && count($_POST['poll_option']) ? count($_POST['poll_option']) : 2);
  642. $text .= "</td></tr><tr>
  643. <td style='width:30%;vertical-align:top'>".LAN_OPTIONS." :</td>
  644. <td style='width:70%'>
  645. <div id='pollsection'>";
  646. for($count = 1; $count <= $option_count; $count++)
  647. {
  648. $opt = ($count==1) ? "id='pollopt'" : "";
  649. $text .="<span class='form-inline' style='display:inline-block; padding-bottom:5px' {$opt}><input class='tbox input-large' type='text' name='poll_option[]' size='40' value=\"".$tp->post_toForm($_POST['poll_option'][($count-1)])."\" maxlength='200' />";
  650. $text .= "</span><br />";
  651. }
  652. $text .="</div><input class='btn' type='button' name='addoption' value='".POLLAN_8."' onclick=\"duplicateHTML('pollopt','pollsection')\" /><br />
  653. </td></tr>
  654. <tr>
  655. <td style='width:30%'>".POLLAN_9."</td>
  656. <td style='width:70%'>
  657. <input type='radio' name='multipleChoice' value='1'".(varset($_POST['multipleChoice']) ? " checked='checked'" : "")." /> ".POLLAN_10."&nbsp;&nbsp;
  658. <input type='radio' name='multipleChoice' value='0'".(!varset($_POST['multipleChoice']) ? " checked='checked'" : "")." /> ".POLLAN_11."
  659. </td>
  660. </tr>
  661. <tr>
  662. <td style='width:30%'>".POLLAN_12."</td>
  663. <td style='width:70%'>
  664. <input type='radio' name='showResults' value='0'".(!varset($_POST['showResults']) ? " checked='checked'" : "")." /> ".POLLAN_13."<br />
  665. <input type='radio' name='showResults' value='1'".(varset($_POST['showResults']) ? " checked='checked'" : "")." /> ".POLLAN_14."
  666. </td>
  667. </tr>
  668. <tr>
  669. <td style='width:30%'>".POLLAN_15."</td>";
  670. $uclass = (ADMIN) ? "" : "public,member,admin,classes,matchclass";
  671. $text .= "
  672. <td>".r_userclass("pollUserclass", vartrue($_POST['pollUserclass']), 'off', $uclass)."</td>
  673. </tr>
  674. <tr>
  675. <td style='width:30%'>".POLLAN_16."</td>
  676. <td>
  677. <input type='radio' name='storageMethod' value='0'".(!varset($_POST['storageMethod']) ? " checked='checked'" : "")." /> ".POLLAN_17."<br />
  678. <input type='radio' name='storageMethod' value='1'".(varset($_POST['storageMethod']) ==1 ? " checked='checked'" : "")." /> ".POLLAN_18."<br />
  679. <input type='radio' name='storageMethod' value='2'".(varset($_POST['storageMethod']) ==2 ? " checked='checked'" : "")." /> ".POLLAN_19."
  680. </td></tr>
  681. <tr>
  682. <td>".POLLAN_20.": </td><td>
  683. <input type='radio' name='poll_comment' value='1'".(varset($_POST['poll_comment']) ? " checked='checked'" : "")." /> ".POLLAN_10."
  684. <input type='radio' name='poll_comment' value='0'".(!varset($_POST['poll_comment']) ? " checked='checked'" : "")." /> ".POLLAN_11."
  685. </td>
  686. </tr>
  687. </table>
  688. <div class='buttons-bar center'>";
  689. if (isset($_POST['preview']) || varset($_POST['edit']))
  690. {
  691. // $text .= "<input type='submit' name='preview' value='".POLLAN_24."' /> ";
  692. $text .= $frm->admin_button('preview',POLLAN_24,'other');
  693. if (POLLACTION == 'edit')
  694. {
  695. $text .= $frm->admin_button('submit', LAN_UPDATE, 'update')."
  696. <input type='hidden' name='poll_id' value='".intval($_POST['poll_id'])."' /> ";
  697. }
  698. else
  699. {
  700. $text .= $frm->admin_button('submit','no-value','submit', LAN_CREATE);
  701. // $text .= "<input type='submit' name='submit' value='".POLLAN_23."' /> ";
  702. }
  703. }
  704. else
  705. {
  706. $text .= $frm->admin_button('preview','no-value','other',POLLAN_24);
  707. // $text .= "<input type='submit' name='preview' value='".POLLAN_24."' /> ";
  708. }
  709. if (defset('POLLID'))
  710. {
  711. $text .= $frm->admin_button('reset','no-value','reset',POLLAN_25);
  712. // $text .= "<input type='submit' name='reset' value='".POLLAN_25."' /> ";
  713. }
  714. $text .= "</div>
  715. </form>
  716. </div>";
  717. return $text;
  718. }
  719. }
  720. class poll_shortcodes extends e_shortcode
  721. {
  722. var $answerOption = array();
  723. var $answerCount;
  724. function sc_option($parm='')
  725. {
  726. return $this->answerOption;
  727. }
  728. function sc_optionbutton($parm='')
  729. {
  730. return ($this->var['poll_allow_multiple'] ? "<input type='checkbox' name='votea[]' value='$count' />" : "<input type='radio' name='votea' value='".$this->answerCount."' />");
  731. }
  732. function sc_question($parm = "")
  733. {
  734. $tp = e107::getParser();
  735. return $tp->toHTML($this->var['poll_title'], TRUE, "emotes_off, defs");
  736. }
  737. function sc_answer($parm='')
  738. {
  739. $frm = e107::getForm();
  740. $opt = array('label'=> $this->answerOption);
  741. return $frm->radio('votea', $this->answerCount,false, $opt);
  742. // $this->answerOption
  743. }
  744. }
  745. /*
  746. e107::js('inline', '
  747. function setcook(pollid){
  748. var name = "poll_"+pollid;
  749. var date = new Date();
  750. var value = pollid;
  751. date.setTime(date.getTime()+(365*24*60*60*1000));
  752. var expires = "; expires="+date.toGMTString();
  753. document.cookie = name+"="+value+expires+"; path=/";
  754. }
  755. ');*/
  756. ?>