author | Dan |
Sat, 29 Nov 2008 01:14:25 -0500 | |
changeset 0 | e96ded22104a |
child 1 | 97507d2ca929 |
permissions | -rw-r--r-- |
0
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
1 |
<?php |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
2 |
/* |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
3 |
Plugin Name: Survey/Poll plugin |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
4 |
Plugin URI: http://enano.homelinux.org/Survey_plugin |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
5 |
Description: Adds a customizable poll to your sidebar. You can have any number of options, and the poll is randomly selected from a list of enabled polls. <b>Important:</b> When first loaded, this plugin creates the following tables in your Enano database: enano_polls, enano_poll_options, enano_poll_results |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
6 |
Author: Dan Fuhry |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
7 |
Version: 1.0.1 |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
8 |
Author URI: http://enano.homelinux.org/ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
9 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
10 |
Changelog: |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
11 |
9/27/06: |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
12 |
Updated to be valid XHTML 1.1 |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
13 |
11/2/07: |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
14 |
Made compatible with Loch Ness and later (oops!) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
15 |
*/ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
16 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
17 |
/* |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
18 |
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
19 |
* Version 1.0.1 (Loch Ness) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
20 |
* Copyright (C) 2006-2007 Dan Fuhry |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
21 |
* |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
22 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
23 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
24 |
* |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
25 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
26 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
27 |
*/ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
28 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
29 |
global $db, $session, $paths, $template, $plugins; // Common objects |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
30 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
31 |
// Uncomment this line once the plugin has been enabled for the first time and at least one page has been requested |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
32 |
define('ENANO_SURVEYOR_TABLES_CREATED', 'true'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
33 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
34 |
if(!defined('ENANO_SURVEYOR_TABLES_CREATED')) { |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
35 |
$e = $db->sql_query('CREATE TABLE IF NOT EXISTS '.table_prefix.'polls( |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
36 |
poll_id mediumint(5) NOT NULL auto_increment, |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
37 |
poll_question text, |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
38 |
end_time datetime, |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
39 |
enabled tinyint(1), |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
40 |
PRIMARY KEY (poll_id) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
41 |
);'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
42 |
if(!$e) $db->_die('Surveyor plugin: error creating table '.table_prefix.'polls.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
43 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
44 |
$e = $db->sql_query('CREATE TABLE IF NOT EXISTS '.table_prefix.'poll_options( |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
45 |
item_id mediumint(5) NOT NULL auto_increment, |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
46 |
poll_id mediumint(5) NOT NULL, |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
47 |
option_value text, |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
48 |
PRIMARY KEY (item_id) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
49 |
);'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
50 |
if(!$e) $db->_die('Surveyor plugin: error creating table '.table_prefix.'poll_options.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
51 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
52 |
$e = $db->sql_query('CREATE TABLE IF NOT EXISTS '.table_prefix.'poll_results( |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
53 |
poll_id mediumint(5), |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
54 |
item_id mediumint(5), |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
55 |
user_id mediumint(8), |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
56 |
ip_addr varchar(10) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
57 |
);'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
58 |
if(!$e) $db->_die('Surveyor plugin: error creating table '.table_prefix.'poll_results.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
59 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
60 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
61 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
62 |
class Surveyor_Plugin { |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
63 |
var $header_added; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
64 |
function html($pid = false) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
65 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
66 |
global $db, $session, $paths, $template, $plugins; // Common objects |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
67 |
$s = ''; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
68 |
if(is_int($pid)) $s = ' AND p.poll_id='.$pid; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
69 |
$ret = ''; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
70 |
if(!is_int($pid)) $ret .= '<div id="mdgVotePlugin" style="padding: 5px;">'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
71 |
$ret .= '<form id="survey" action="'.makeUrlNS('Special', 'SubmitVote').'" method="post"><div>'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
72 |
$q = $db->sql_query('SELECT p.poll_id AS pid,o.item_id AS oid,p.poll_question AS q,o.option_value AS v FROM '.table_prefix.'polls p, '.table_prefix.'poll_options o WHERE p.poll_id=o.poll_id AND p.enabled=1'.$s.';'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
73 |
if(!$q) $db->_die('An error occurred whilst selecting the poll data.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
74 |
$l = Array(); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
75 |
while($row = $db->fetchrow()) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
76 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
77 |
if(!isset($l[$row['q']])) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
78 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
79 |
$l[$row['q']] = Array(); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
80 |
$l[$row['q']]['pid'] = $row['pid']; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
81 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
82 |
$l[$row['q']][] = $row; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
83 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
84 |
if(sizeof($l) < 1) return 'No polls created yet'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
85 |
$ques = array_rand($l); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
86 |
$poll_id = $l[$ques]['pid']; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
87 |
unset($l[$ques]['pid']); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
88 |
if(!$poll_id) die_semicritical('Surveyor plugin error', 'Invalid poll ID: '.$poll_id); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
89 |
$q = $db->sql_query('SELECT * FROM '.table_prefix.'poll_results WHERE poll_id='.$poll_id.' AND ( ip_addr=\''.mysql_real_escape_string(ip2hex($_SERVER['REMOTE_ADDR'])).'\' OR user_id='.$session->user_id.' );'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
90 |
if(!$q) $db->_die('Error obtaining vote result information'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
91 |
if($db->numrows() > 0) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
92 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
93 |
if(!isset($_GET['results'])) $_GET['results'] = ''; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
94 |
$_REQUEST['poll_id'] = $poll_id.''; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
95 |
$_GET['poll_id'] = $poll_id.''; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
96 |
return __enanoVoteAjaxhandler(false); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
97 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
98 |
$ret .= '<input type="hidden" name="poll_id" value="'.$poll_id.'" />'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
99 |
$ret .= '<span style="font-weight: bold;">'.$ques.'</span><br />'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
100 |
foreach($l[$ques] as $o) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
101 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
102 |
$ret .= '<label><input type="radio" name="item_id" value="'.addslashes($o['oid']).'" /> '.$o['v'].'</label><br />'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
103 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
104 |
$ret .= '<br /><div style="text-align: center"><input type="button" value="Vote!" onclick="ajaxSubmitVote(); return false;" /> <input type="button" onclick="ajaxVoteResults(); return false;" value="View results" /></div>'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
105 |
$ret .= '</div></form>'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
106 |
if(!is_int($pid)) $ret .= '</div>'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
107 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
108 |
$template->add_header(' |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
109 |
<script type="text/javascript"> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
110 |
//<![CDATA[ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
111 |
function ajaxSubmitVote() |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
112 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
113 |
frm = document.forms.survey; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
114 |
radios = document.getElementsByTagName(\'input\'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
115 |
optlist = new Array(); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
116 |
j = 0; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
117 |
for(i=0;i<radios.length;i++) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
118 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
119 |
if(radios[i].name == \'item_id\') |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
120 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
121 |
optlist[j] = radios[i]; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
122 |
j++; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
123 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
124 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
125 |
val = \'enanoNuLl\'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
126 |
for(i=0;i<optlist.length;i++) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
127 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
128 |
if(optlist[i].checked) val = optlist[i].value; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
129 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
130 |
if(val==\'enanoNuLl\') { alert(\'Please select an option.\'); return; } |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
131 |
ajaxPost(\''.makeUrlNS('Special', 'SubmitVote', 'redirect=no').'\', \'poll_id=\'+frm.poll_id.value+unescape(\'%26\')+\'item_id=\'+val, function() { |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
132 |
if(ajax.readyState==4) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
133 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
134 |
ajaxVoteResults(); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
135 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
136 |
}); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
137 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
138 |
function ajaxVoteForm() |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
139 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
140 |
ajaxGet(\''.makeUrlNS('Special', 'SubmitVote', 'voteform\'+unescape(\'%26\')+\'poll_id='.$poll_id).'\', function() { |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
141 |
if(ajax.readyState==4) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
142 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
143 |
document.getElementById("mdgVotePlugin").innerHTML = ajax.responseText; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
144 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
145 |
}); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
146 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
147 |
function ajaxVoteResults() |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
148 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
149 |
ajaxGet(\''.makeUrlNS('Special', 'SubmitVote', 'results\'+unescape(\'%26\')+\'poll_id='.$poll_id).'\', function() { |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
150 |
if(ajax.readyState==4) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
151 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
152 |
document.getElementById("mdgVotePlugin").innerHTML = ajax.responseText; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
153 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
154 |
}); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
155 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
156 |
// ]]> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
157 |
</script> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
158 |
'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
159 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
160 |
return $ret; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
161 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
162 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
163 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
164 |
$plugins->attachHook('base_classes_initted', ' |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
165 |
$paths->add_page(Array( |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
166 |
\'name\'=>\'Submit a poll vote\', |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
167 |
\'urlname\'=>\'SubmitVote\', |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
168 |
\'namespace\'=>\'Special\', |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
169 |
\'special\'=>0,\'visible\'=>0,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\', |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
170 |
)); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
171 |
$paths->addAdminNode(\'Plugin configuration\', \'Manage polls\', \'PollEditor\'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
172 |
'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
173 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
174 |
function __mdgPluginDoSurvey() { |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
175 |
global $db, $session, $paths, $template, $plugins; // Common objects |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
176 |
$s = new Surveyor_Plugin(); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
177 |
$template->sidebar_widget('Poll', $s->html()); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
178 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
179 |
$plugins->attachHook('compile_template', '__mdgPluginDoSurvey();'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
180 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
181 |
function page_Special_SubmitVote() |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
182 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
183 |
echo __enanoVoteAjaxhandler(); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
184 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
185 |
function __enanoVoteAjaxhandler($allow_vote = true) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
186 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
187 |
global $db, $session, $paths, $template, $plugins; // Common objects |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
188 |
$ret = ''; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
189 |
if(!isset($_REQUEST['poll_id'])) { die_semicritical('Critical error in plugin', '$_REQUEST[\'poll_id\'] is not set'); $paths->main_page(); exit; } |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
190 |
if(!preg_match('/^([0-9]+)$/', $_REQUEST['poll_id'])) die('Hacking attempt'); // Prevents SQL injection from the URL |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
191 |
if(isset($_GET['results'])) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
192 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
193 |
$q = $db->sql_query('SELECT p.poll_id AS pid,o.item_id AS oid,p.poll_question AS q,o.option_value AS v FROM '.table_prefix.'polls p, '.table_prefix.'poll_options o WHERE p.poll_id=o.poll_id AND p.poll_id=\''.$_GET['poll_id'].'\';'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
194 |
$l = Array(); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
195 |
while($row = $db->fetchrow()) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
196 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
197 |
if(!isset($l[$row['q']])) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
198 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
199 |
$l[$row['q']] = Array(); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
200 |
$l[$row['q']]['pid'] = $row['pid']; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
201 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
202 |
$l[$row['q']][] = $row; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
203 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
204 |
// The reason we use array_rand() here? Simple - we used a WHERE clause to select only one poll, and since poll_id is |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
205 |
// a primary key, there is only one match in the polls table. Therefore, array_rand() effectively returns the first key in the array |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
206 |
$ques = array_rand($l); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
207 |
$poll_id = $l[$ques]['pid']; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
208 |
unset($l[$ques]['pid']); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
209 |
$results = Array(); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
210 |
foreach($l[$ques] as $o) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
211 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
212 |
$q = $db->sql_query('SELECT * FROM '.table_prefix.'poll_results WHERE poll_id='.$_GET['poll_id'].' AND item_id='.$o['oid'].';'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
213 |
if(!$q) $db->_die('The poll result data could not be selected.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
214 |
$results[$o['v']] = $db->numrows(); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
215 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
216 |
$k = array_keys($results); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
217 |
$total = 0; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
218 |
foreach($k as $key) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
219 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
220 |
$total = $total + $results[$key]; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
221 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
222 |
if($total==0) $total = 1; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
223 |
// Figure out the percentage, round it, and send the images |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
224 |
$ret .= '<table border="0" style="margin: 0; padding: 0; width: 100%;" cellspacing="0" cellpadding="0">'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
225 |
$ret .= '<tr><td colspan="2"><b>'.$ques.'</b></td></tr>'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
226 |
foreach($k as $key) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
227 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
228 |
$this_width = round(100*($results[$key] / $total)); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
229 |
if ( $this_width == 0 ) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
230 |
$this_width = 4; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
231 |
$ret .= '<tr> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
232 |
<td colspan="2">'.$key.'</td> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
233 |
</tr> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
234 |
<tr> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
235 |
<td style="padding: 0px 4px 0px 4px;"> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
236 |
<img alt="Poll bar" src="'.scriptPath.'/plugins/surveyor/poll-bar-left.png" |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
237 |
width="2" height="12" style="margin: 2px 0px 2px 0px; padding: 0;" hspace="0" |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
238 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
239 |
/><img alt="Poll bar" src="'.scriptPath.'/plugins/surveyor/poll-bar-middle.png" |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
240 |
width="'.$this_width.'" height="12" style="margin: 2px 0px 2px 0px; padding: 0;" hspace="0" |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
241 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
242 |
/><img alt="Poll bar" src="'.scriptPath.'/plugins/surveyor/poll-bar-right.png" |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
243 |
width="2" height="12" style="margin: 2px 0px 2px 0px; padding: 0;" hspace="0" /> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
244 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
245 |
</td> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
246 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
247 |
<td> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
248 |
['.$results[$key].'] |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
249 |
</td> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
250 |
</tr>'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
251 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
252 |
if($allow_vote) $ret .= '<tr><td colspan="2" style="text-align: center"><input type="button" value="Cast your vote" onclick="ajaxVoteForm(); return false;" /></td></tr>'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
253 |
$ret .= '</table>'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
254 |
} elseif(isset($_GET['voteform'])) { |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
255 |
$s = new Surveyor_Plugin(); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
256 |
$pid = (int)$_GET['poll_id']; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
257 |
$ret .= $s->html($pid); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
258 |
} else { |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
259 |
if(!isset($_POST['item_id']) || (isset($_POST['item_id']) && !preg_match('/^([0-9]+)$/', $_POST['item_id']))) die('Hacking attempt'); // Once again, ensure that only numbers are passed on the URL |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
260 |
if(isset($_GET['redirect']) && $_GET['redirect'] == 'no') |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
261 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
262 |
header('Content-type: text/plain'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
263 |
$q = $db->sql_query('SELECT * FROM '.table_prefix.'poll_results WHERE poll_id='.$_POST['poll_id'].' AND ( ip_addr=\''.mysql_real_escape_string(ip2hex($_SERVER['REMOTE_ADDR'])).'\' OR user_id='.$session->user_id.' );'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
264 |
if(!$q) $db->_die('Error obtaining vote result information'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
265 |
if($db->numrows() > 0) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
266 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
267 |
die('Looks like you already voted in this poll.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
268 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
269 |
$q = $db->sql_query('INSERT INTO '.table_prefix.'poll_results(poll_id,item_id,ip_addr,user_id) VALUES('.$_POST['poll_id'].', '.$_POST['item_id'].', \''.ip2hex($_SERVER['REMOTE_ADDR']).'\', '.$session->user_id.');'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
270 |
if(!$q) $db->_die('Your vote could not be inserted into the results table.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
271 |
$ret .= 'Your vote has been cast.'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
272 |
} else { |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
273 |
$paths->main_page(); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
274 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
275 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
276 |
return $ret; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
277 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
278 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
279 |
function page_Admin_PollEditor() |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
280 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
281 |
global $db, $session, $paths, $template, $plugins; if(!$session->sid_super || $session->user_level < 2) { header('Location: '.makeUrl($paths->nslist['Special'].'Administration'.urlSeparator.'noheaders')); die('Hacking attempt'); } |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
282 |
if(isset($_POST['newpoll_create'])) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
283 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
284 |
$date_string = $_POST['newpoll_year'].'-'.$_POST['newpoll_month'].'-'.$_POST['newpoll_day'].' '.$_POST['newpoll_hour'].':'.$_POST['newpoll_minute'].':00'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
285 |
if(isset($_POST['newpoll_never'])) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
286 |
$date_string = '9999-01-01 00:00:00'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
287 |
if(!$db->sql_query('INSERT INTO '.table_prefix.'polls(poll_question,enabled,end_time) VALUES(\''.mysql_real_escape_string($_POST['newpoll_name']).'\', 1, \''.$date_string.'\');')) $db->_die('The poll information could not be inserted.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
288 |
$q = $db->sql_query('SELECT poll_id FROM '.table_prefix.'polls WHERE poll_question=\''.mysql_real_escape_string($_POST['newpoll_name']).'\' AND end_time=\''.$date_string.'\';'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
289 |
if(!$q) $db->_die('The new poll ID could not be fetched.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
290 |
$r = $db->fetchrow(); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
291 |
if(!$db->sql_query('INSERT INTO '.table_prefix.'poll_options(poll_id,option_value) VALUES('.$r['poll_id'].', \'First option\')')) $db->_die('The default option data could not be inserted.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
292 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
293 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
294 |
echo '<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module'], true).'" method="post">'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
295 |
?> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
296 |
<h3>Create a new poll</h3> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
297 |
<p>Question: <input name="newpoll_name" type="text" /></p> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
298 |
<p>Ending time: |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
299 |
<select name="newpoll_month"> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
300 |
<option value="01">January</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
301 |
<option value="02">February</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
302 |
<option value="03">March</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
303 |
<option value="04">April</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
304 |
<option value="05">May</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
305 |
<option value="06">June</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
306 |
<option value="07">July</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
307 |
<option value="08">August</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
308 |
<option value="09">September</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
309 |
<option value="10">October</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
310 |
<option value="11">November</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
311 |
<option value="12">December</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
312 |
</select> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
313 |
<select name="newpoll_day"> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
314 |
<?php |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
315 |
// This would be too hard to write by hand, so let's use a simple for-loop to take care of it for us |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
316 |
for($i=1;$i<=31;$i++) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
317 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
318 |
if($i < 10) $t = '0'.$i; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
319 |
else $t = $i.''; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
320 |
echo '<option value="'.$t.'">'.$t.'</option>'."\n "; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
321 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
322 |
?> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
323 |
</select>, |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
324 |
<select name="newpoll_year"> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
325 |
<?php |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
326 |
// What the heck? Let's do it again :-D |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
327 |
for($i=2006;$i<=2026;$i++) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
328 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
329 |
echo '<option value="'.$i.'">'.$i.'</option>'."\n "; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
330 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
331 |
?> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
332 |
</select> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
333 |
<select name="newpoll_hour"> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
334 |
<?php |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
335 |
for($i=0;$i<=23;$i++) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
336 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
337 |
if($i < 10) $t = '0'.$i; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
338 |
else $t = $i.''; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
339 |
echo '<option value="'.$t.'">'.$t.'</option>'."\n "; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
340 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
341 |
?> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
342 |
</select>:<select name="newpoll_minute"> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
343 |
<?php |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
344 |
for($i=0;$i<=59;$i++) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
345 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
346 |
if($i < 10) $t = '0'.$i; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
347 |
else $t = $i.''; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
348 |
echo '<option value="'.$t.'">'.$t.'</option>'."\n "; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
349 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
350 |
?> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
351 |
</select><br /> <label><input type="checkbox" name="newpoll_never" />Never ends</label></p> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
352 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
353 |
<p><input type="submit" name="newpoll_create" value="Create poll" /></p> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
354 |
<?php |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
355 |
echo '</form>'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
356 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
357 |
$q = $db->sql_query('SELECT p.poll_id AS pid,o.item_id AS oid,p.poll_question AS q,o.option_value AS v,p.end_time,p.enabled FROM '.table_prefix.'polls p, '.table_prefix.'poll_options o WHERE p.poll_id=o.poll_id;'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
358 |
if(!$q) $db->_die('The poll information could not be selected.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
359 |
$l = Array(); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
360 |
while($row = $db->fetchrow()) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
361 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
362 |
if(!isset($l[$row['q']])) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
363 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
364 |
$l[$row['q']] = Array(); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
365 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
366 |
$l[$row['q']][] = $row; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
367 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
368 |
$k = array_keys($l); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
369 |
foreach ( $k as $key ) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
370 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
371 |
$c = $l[$key][0]; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
372 |
$poll_id = $c['pid']; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
373 |
$enabled = $c['enabled']; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
374 |
$ending_time = $c['end_time']; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
375 |
$year = substr($ending_time, 0, 4); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
376 |
$month = substr($ending_time, 5, 2); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
377 |
$day = substr($ending_time, 8, 2); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
378 |
$hour = substr($ending_time, 11, 2); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
379 |
$minute = substr($ending_time, 14, 2); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
380 |
if(isset($_POST['poll_'.$c['pid'].'_update'])) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
381 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
382 |
$date_string = $_POST['poll_'.$c['pid'].'_year'].'-'.$_POST['poll_'.$c['pid'].'_month'].'-'.$_POST['poll_'.$c['pid'].'_day'].' '.$_POST['poll_'.$c['pid'].'_hour'].':'.$_POST['poll_'.$c['pid'].'_minute'].':00'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
383 |
if(isset($_POST['poll_'.$c['pid'].'_never'])) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
384 |
$date_string = '9999-01-01 00:00:00'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
385 |
$en = isset($_POST['poll_'.$c['pid'].'_enabled']) ? '1' : '0'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
386 |
$q = $db->sql_query('UPDATE '.table_prefix.'polls SET enabled='.$en.',end_time=\''.$date_string.'\' WHERE poll_id='.$c['pid'].';'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
387 |
if(!$q) $db->_die('The poll data could not be updated.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
388 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
389 |
$q = $db->sql_query('SELECT p.poll_id AS pid,o.item_id AS oid,p.poll_question AS q,o.option_value AS v,p.end_time,p.enabled FROM '.table_prefix.'polls p, '.table_prefix.'poll_options o WHERE p.poll_id=o.poll_id;'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
390 |
if(!$q) $db->_die('The poll information could not be selected.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
391 |
$l = Array(); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
392 |
while($row = $db->fetchrow()) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
393 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
394 |
if(!isset($l[$row['q']])) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
395 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
396 |
$l[$row['q']] = Array(); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
397 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
398 |
$l[$row['q']][] = $row; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
399 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
400 |
$k = array_keys($l); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
401 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
402 |
echo '<h3>Information</h3><p>Poll updated successfully.</p>'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
403 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
404 |
if(isset($_POST['poll_'.$c['pid'].'_delete'])) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
405 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
406 |
// Safe to use the poll ID here because it's the primary key |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
407 |
if(!$db->sql_query('DELETE FROM '.table_prefix.'poll_results WHERE poll_id='.$c['pid'].';') ) $db->_die('The poll results could not be deleted.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
408 |
if(!$db->sql_query('DELETE FROM '.table_prefix.'poll_options WHERE poll_id='.$c['pid'].';') ) $db->_die('The poll options could not be deleted.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
409 |
if(!$db->sql_query('DELETE FROM '.table_prefix.'polls WHERE poll_id='.$c['pid'].';') ) $db->_die('The poll could not be deleted.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
410 |
unset($l[$key]); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
411 |
echo '<h3>Information</h3><p>Poll deleted.</p>'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
412 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
413 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
414 |
$k = array_keys($l); // Refresh the key list after any deletions that may have been done |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
415 |
foreach ( $k as $key ) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
416 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
417 |
if(isset($_POST['create_'.$l[$key][0]['pid']])) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
418 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
419 |
$str = mysql_real_escape_string($_POST['value_'.$l[$key][0]['pid']]); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
420 |
$q = $db->sql_query('INSERT INTO '.table_prefix.'poll_options(poll_id,option_value) VALUES('.$l[$key][0]['pid'].', \''.$str.'\');'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
421 |
if(!$q) $db->_die('The poll data could not be inserted.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
422 |
$q = $db->sql_query('SELECT o.item_id AS oid,option_value AS v, p.poll_id AS pid FROM '.table_prefix.'polls p, '.table_prefix.'poll_options o WHERE p.poll_id=o.poll_id AND option_value=\''.$str.'\';'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
423 |
if(!$q) $db->_die('The poll data could not be selected.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
424 |
$nr = $db->fetchrow(); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
425 |
$l[$key][] = $nr; // Fetches the option ID, which is needed for updating and deleting the poll option |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
426 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
427 |
echo '<hr /><h3>Poll: '.$key.'</h3>'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
428 |
echo '<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module'], true).'" method="post">'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
429 |
$poll_id = $l[$key][0]['pid']; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
430 |
$enabled = $l[$key][0]['enabled']; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
431 |
$ending_time = $l[$key][0]['end_time']; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
432 |
$year = substr($ending_time, 0, 4); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
433 |
$month = substr($ending_time, 5, 2); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
434 |
$day = substr($ending_time, 8, 2); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
435 |
$hour = substr($ending_time, 11, 2); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
436 |
$minute = substr($ending_time, 14, 2); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
437 |
?> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
438 |
<p>Ending time: |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
439 |
<select name="poll_<?php echo $poll_id; ?>_month"> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
440 |
<option<?php if($month=='01') echo ' selected="selected"'; ?> value="01">January</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
441 |
<option<?php if($month=='02') echo ' selected="selected"'; ?> value="02">February</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
442 |
<option<?php if($month=='03') echo ' selected="selected"'; ?> value="03">March</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
443 |
<option<?php if($month=='04') echo ' selected="selected"'; ?> value="04">April</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
444 |
<option<?php if($month=='05') echo ' selected="selected"'; ?> value="05">May</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
445 |
<option<?php if($month=='06') echo ' selected="selected"'; ?> value="06">June</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
446 |
<option<?php if($month=='07') echo ' selected="selected"'; ?> value="07">July</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
447 |
<option<?php if($month=='08') echo ' selected="selected"'; ?> value="08">August</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
448 |
<option<?php if($month=='09') echo ' selected="selected"'; ?> value="09">September</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
449 |
<option<?php if($month=='10') echo ' selected="selected"'; ?> value="10">October</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
450 |
<option<?php if($month=='11') echo ' selected="selected"'; ?> value="11">November</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
451 |
<option<?php if($month=='12') echo ' selected="selected"'; ?> value="12">December</option> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
452 |
</select> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
453 |
<select name="poll_<?php echo $poll_id; ?>_day"> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
454 |
<?php |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
455 |
// This would be too hard to write by hand, so let's use a simple for-loop to take care of it for us |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
456 |
for($i=1;$i<=31;$i++) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
457 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
458 |
if($i < 10) $t = '0'.$i; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
459 |
else $t = $i.''; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
460 |
echo '<option'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
461 |
if($t == $day) echo ' selected="selected"'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
462 |
echo ' value="'.$t.'">'.$t.'</option>'."\n "; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
463 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
464 |
?> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
465 |
</select>, |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
466 |
<select name="poll_<?php echo $poll_id; ?>_year"> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
467 |
<?php |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
468 |
// What the heck? Let's do it again :-D |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
469 |
for($i=2006;$i<=2026;$i++) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
470 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
471 |
echo '<option'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
472 |
if($i.'' == $year) echo ' selected="selected"'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
473 |
echo ' value="'.$i.'">'.$i.'</option>'."\n "; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
474 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
475 |
?> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
476 |
</select> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
477 |
<select name="poll_<?php echo $poll_id; ?>_hour"> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
478 |
<?php |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
479 |
for($i=0;$i<=23;$i++) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
480 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
481 |
if($i < 10) $t = '0'.$i; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
482 |
else $t = $i.''; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
483 |
echo '<option'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
484 |
if($t == $hour) echo ' selected="selected"'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
485 |
echo ' value="'.$t.'">'.$t.'</option>'."\n "; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
486 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
487 |
?> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
488 |
</select>:<select name="poll_<?php echo $poll_id; ?>_minute"> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
489 |
<?php |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
490 |
for($i=0;$i<=59;$i++) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
491 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
492 |
if($i < 10) $t = '0'.$i; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
493 |
else $t = $i.''; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
494 |
echo '<option'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
495 |
if($t == $minute) echo ' selected="selected"'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
496 |
echo ' value="'.$t.'">'.$t.'</option>'."\n "; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
497 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
498 |
?> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
499 |
</select><br /> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
500 |
<label><input<?php if($year=='9999' && $month=='01' && $day=='01' && $hour=='00' && $minute=='00') echo ' checked="checked"'; ?> type="checkbox" name="poll_<?php echo $poll_id; ?>_never" />Never ends</label></p> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
501 |
<p><label><input<?php if($enabled) echo ' checked="checked"'; ?> type="checkbox" name="poll_<?php echo $poll_id; ?>_enabled" /> Poll is enabled</label></p> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
502 |
<p><input type="submit" name="poll_<?php echo $poll_id; ?>_update" value="Update this poll" /> <input type="submit" name="poll_<?php echo $poll_id; ?>_delete" value="Delete this poll" /></p></p> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
503 |
<table border="0" width="100%" cellspacing="1" cellpadding="4"> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
504 |
<tr><th>Option value</th><th>Votes</th><th>Actions</th></tr> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
505 |
<?php |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
506 |
foreach($l[$key] as $row) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
507 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
508 |
if(isset($_POST['delete_'.$row['pid'].'_'.$row['oid']]) && sizeof($l[$key]) > 1) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
509 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
510 |
$q = $db->sql_query('DELETE FROM '.table_prefix.'poll_options WHERE poll_id='.$row['pid'].' AND item_id='.$row['oid'].';'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
511 |
if(!$q) $db->_die('The poll data could not be deleted.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
512 |
$q = $db->sql_query('DELETE FROM '.table_prefix.'poll_results WHERE poll_id='.$row['pid'].' AND item_id='.$row['oid'].';'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
513 |
if(!$q) $db->_die('The poll result data could not be deleted.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
514 |
echo '<tr><td colspan="3" style="text-align: center"><b>Item deleted.</b></tr>'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
515 |
} else { |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
516 |
if(isset($_POST['delete_'.$row['pid'].'_'.$row['oid']]) && sizeof($l[$key]) < 2) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
517 |
echo '<tr><td colspan="3" style="text-align: center"><b>You cannot delete the last option in a poll.<br />Instead, please use the "Update" button.</b></tr>'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
518 |
if(isset($_POST['update_'.$row['pid'].'_'.$row['oid']])) |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
519 |
{ |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
520 |
$q = $db->sql_query('UPDATE '.table_prefix.'poll_options SET option_value=\''.mysql_real_escape_string($_POST['value_'.$row['pid'].'_'.$row['oid']]).'\' WHERE poll_id='.$row['pid'].' AND item_id='.$row['oid'].';'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
521 |
if(!$q) $db->_die('The poll data could not be updated.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
522 |
$row['v'] = $_POST['value_'.$row['pid'].'_'.$row['oid']]; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
523 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
524 |
// Sorry guys, really, I hate to make a ton of queries here but there's really no other way to do this :'( |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
525 |
$q = $db->sql_query('SELECT * FROM '.table_prefix.'poll_results WHERE poll_id='.$row['pid'].' AND item_id='.$row['oid'].';'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
526 |
if(!$q) $db->_die('The poll result data could not be selected.'); |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
527 |
echo '<tr><td><input name="value_'.$row['pid'].'_'.$row['oid'].'" value="'.htmlspecialchars($row['v']).'" /></td><td>'.$db->numrows().'</td><td style="text-align: center"><input name="update_'.$row['pid'].'_'.$row['oid'].'" type="submit" value="Update" /> <input name="delete_'.$row['pid'].'_'.$row['oid'].'" type="submit" value="Delete" /></td></tr>'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
528 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
529 |
//$last_pid |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
530 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
531 |
?> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
532 |
<tr><td colspan="2"><input name="value_<?php echo $l[$key][0]['pid']; ?>" type="text" /></td><td style="text-align: center;"><input type="submit" name="create_<?php echo $l[$key][0]['pid']; ?>" value="Create option" /></td> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
533 |
</table> |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
534 |
<?php |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
535 |
echo '</form>'; |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
536 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
537 |
} |
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
538 |
|
e96ded22104a
First revision, moved around a bit but other than that mostly unchanged from the old version from stable.
Dan
parents:
diff
changeset
|
539 |
?> |