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