forked from NoahY/q2a-poll
-
Notifications
You must be signed in to change notification settings - Fork 3
/
qa-poll-admin.php
203 lines (180 loc) · 5.34 KB
/
qa-poll-admin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php
class qa_poll_admin
{
function option_default($option)
{
switch ($option) {
case 'permit_post_poll':
case 'permit_vote_poll':
return QA_PERMIT_USERS;
case 'poll_enable_subnav':
return true;
case 'poll_css':
return '#qa-poll-div {
background-color: #D9E3EA;
border: 1px solid #658296;
font-size: 12px;
padding: 10px;
}
#qa-poll-choices-title {
font-weight:bold;
margin-bottom:8px;
}
.qa-poll-choice {
clear:both;
padding:5px 0 5px 5px;
}
#qa-poll-choices > div:last-child {
padding-bottom:0px;
}
#qa-poll-choices > div:first-child {
padding-top:0px;
}
.qa-poll-choice-title {
line-height:12px;
margin-left:10px;
}
.qa-poll-votes {
max-width:500px;
height:10px;
margin-left:22px;
margin:5px 0 5px 22px;
}
.qa-poll-vote-block {
width:10px;
height:10px;
background-color:green;
}
.qa-poll-vote-block-empty {
width:10px;
height:10px;
}
.qa-poll-voted-button, .qa-poll-vote-button {
cursor:pointer;
width:12px;
height:12px;
float:left;
margin-top: 1px;
}
.qa-poll-disabled-button {
width:12px;
height:12px;
float:left;
margin-top: 1px;
background-image:url(^public/img/button_vote.png);
}
.qa-poll-voted-button {
background-image:url(^public/img/button_voted.png);
}
.qa-poll-vote-button {
background-image:url(^public/img/button_vote.png);
}
.qa-poll-vote-button:hover, .qa-poll-voted-button:hover {
background-image:url(^public/img/button_voting.png);
}';
default:
return null;
}
}
function allow_template($template)
{
return ($template != 'admin');
}
function admin_form(&$qa_content)
{
// Process form input
$ok = null;
if (qa_clicked('poll_save')) {
qa_db_query_sub(
'CREATE TABLE IF NOT EXISTS ^postmeta (
meta_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
post_id bigint(20) unsigned NOT NULL,
meta_key varchar(255) DEFAULT \'\',
meta_value longtext,
PRIMARY KEY (meta_id),
KEY post_id (post_id),
KEY meta_key (meta_key)
) ENGINE=MyISAM DEFAULT CHARSET=utf8'
);
qa_db_query_sub(
'CREATE TABLE IF NOT EXISTS ^polls (
id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
parentid bigint(20) unsigned NOT NULL,
votes longtext,
content varchar(255) DEFAULT \'\',
PRIMARY KEY (id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8'
);
qa_opt('poll_enable', (bool)qa_post_text('poll_enable'));
qa_opt('poll_enable_subnav', (bool)qa_post_text('poll_enable_subnav'));
qa_opt('poll_votes_hide', (bool)qa_post_text('poll_votes_hide'));
qa_opt('poll_votes_percent', (bool)qa_post_text('poll_votes_percent'));
qa_opt('poll_vote_change', (bool)qa_post_text('poll_vote_change'));
qa_opt('poll_update_on_vote', (bool)qa_post_text('poll_update_on_vote'));
qa_opt('poll_css', qa_post_text('poll_css'));
$ok = qa_lang('admin/options_saved');
} else if (qa_clicked('poll_reset')) {
foreach ($_POST as $i => $v) {
$def = $this->option_default($i);
if ($def !== null) {
qa_opt($i, $def);
}
}
$ok = qa_lang('admin/options_reset');
}
// Create the form for display
$fields = array();
$fields[] = array(
'label' => 'Enable polls',
'tags' => 'NAME="poll_enable"',
'value' => qa_opt('poll_enable'),
'type' => 'checkbox',
);
$fields[] = array(
'label' => 'Show poll link in questions sub-nav',
'tags' => 'NAME="poll_enable_subnav"',
'value' => qa_opt('poll_enable_subnav'),
'type' => 'checkbox',
);
$fields[] = array(
'label' => 'Allow users to change their votes',
'tags' => 'NAME="poll_vote_change"',
'value' => qa_opt('poll_vote_change'),
'type' => 'checkbox',
);
$fields[] = array(
'label' => 'Hide poll votes from users who haven\'t voted yet',
'tags' => 'NAME="poll_votes_hide"',
'value' => qa_opt('poll_votes_hide'),
'type' => 'checkbox',
);
$fields[] = array(
'label' => 'Show percent on poll votes',
'tags' => 'NAME="poll_votes_percent"',
'value' => qa_opt('poll_votes_percent'),
'type' => 'checkbox',
);
$fields[] = array(
'label' => 'Poll question stylesheet',
'tags' => 'NAME="poll_css"',
'value' => qa_opt('poll_css'),
'rows' => 20,
'type' => 'textarea',
'note' => '^ will be replaced by location of this plugin directory',
);
return array(
'ok' => ($ok && !isset($error)) ? $ok : null,
'fields' => $fields,
'buttons' => array(
array(
'label' => qa_lang_html('main/save_button'),
'tags' => 'NAME="poll_save"',
),
array(
'label' => qa_lang_html('admin/reset_options_button'),
'tags' => 'NAME="poll_reset"',
),
),
);
}
}