Skip to content

Commit

Permalink
added buttons to close/open/delete poll
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahY committed Aug 2, 2012
1 parent 1bd2293 commit b52fa7c
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
2 changes: 1 addition & 1 deletion qa-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Plugin URI: https://github.com/NoahY/q2a-poll
Plugin Update Check URI: https://github.com/NoahY/q2a-poll/raw/master/qa-plugin.php
Plugin Description: Ask poll questions
Plugin Version: 1.5
Plugin Version: 2.0
Plugin Date: 2011-09-05
Plugin Author: NoahY
Plugin Author URI:
Expand Down
12 changes: 12 additions & 0 deletions qa-poll-lang-default.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@
return array(
'permit_post_poll' => 'Create polls',
'permit_vote_poll' => 'Vote on polls',
'permit_close_poll' => 'Close any poll',
'permit_delete_poll' => 'Delete any poll',
'permit_delete_poll' => 'Delete any poll',

'reopen_poll' => 'Reopen',
'reopen_poll_hover' => 'Reopen poll',
'close_poll' => 'Close',
'close_poll_hover' => 'Close poll',
'delete_poll' => 'Delete',
'delete_poll_hover' => 'Delete poll',

'poll_closed' => 'Poll closed',

'question_title' => '[poll]',
'comments' => '[poll]',
Expand Down
54 changes: 50 additions & 4 deletions qa-poll-layer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ function doctype(){
if($this->request == 'admin/permissions' && function_exists('qa_register_plugin_phrases') && qa_get_logged_in_level()>=QA_USER_LEVEL_ADMIN) {
$permits[] = 'permit_vote_poll';
$permits[] = 'permit_post_poll';
$permits[] = 'permit_close_poll';
$permits[] = 'permit_delete_poll';
foreach($permits as $optionname) {
$value = qa_opt($optionname);
$optionfield=array(
Expand Down Expand Up @@ -74,9 +76,22 @@ function doctype(){
$qid = $this->content['q_view']['raw']['postid'];
$author = $this->content['q_view']['raw']['userid'];

if(@$poll[$qid]) { // is a poll

if(isset($poll[$qid])) { // is a poll
$this->poll = $poll[$qid];

if(qa_post_text('poll_delete') && (!qa_user_permit_error('permit_delete_poll') || qa_get_logged_in_userid() == $author)) {
$this->deletePoll($qid);
$this->content['error'] = 'Poll deleted.';
return;
}
else if (qa_post_text('poll_close') && (!qa_user_permit_error('permit_close_poll') || qa_get_logged_in_userid() == $author)) {
$this->closePoll($qid);
}
else if (qa_post_text('poll_reopen') && (!qa_user_permit_error('permit_close_poll') || qa_get_logged_in_userid() == $author)) {
$this->reopenPoll($qid);
}


// add post elements

Expand Down Expand Up @@ -205,7 +220,7 @@ function getPollDiv($qid,$uid,$vid=null,$cancel=false) {

// do voting

if($vid && $uid && qa_permit_check('permit_vote_poll')) {
if($vid && $uid && qa_permit_check('permit_vote_poll') && $this->poll != 3) {
$vid = (int)$vid;
foreach ($answers as $idx => $answer) {
$votes = explode(',',$answer['votes']);
Expand Down Expand Up @@ -249,7 +264,7 @@ function getPollDiv($qid,$uid,$vid=null,$cancel=false) {

foreach ($answers as $idx => $answer) {

if(!$uid || !qa_permit_check('permit_vote_poll')) {
if(!$uid || !qa_permit_check('permit_vote_poll') || $this->poll > 9) {
$answers[$idx]['vote'] = '<div class="qa-poll-disabled-button" title="'.qa_html(qa_lang('polls/disabled_button')).'"></div>';
continue;
}
Expand Down Expand Up @@ -283,10 +298,41 @@ function getPollDiv($qid,$uid,$vid=null,$cancel=false) {

$out .= '</tr></table></div>';
}
if($this->poll > 9) { // poll closed
$out .= '<div class="qa-poll-closed">'.qa_lang('polls/poll_closed').'</div>';
if(!qa_user_permit_error('permit_close_poll') || qa_get_logged_in_userid() == $author)
$out .= '<input type="submit" class="qa-poll-button" title="'.qa_lang('polls/reopen_poll_hover').'" value="'.qa_lang('polls/reopen_poll').'" name="poll_reopen">';
}
else if(!qa_user_permit_error('permit_close_poll') || qa_get_logged_in_userid() == $author)
$out .= '<input type="submit" class="qa-poll-button" title="'.qa_lang('polls/close_poll_hover').'" value="'.qa_lang('polls/close_poll').'" name="poll_close">';
if(!qa_user_permit_error('permit_delete_poll') || qa_get_logged_in_userid() == $author)
$out .= '<input type="submit" class="qa-poll-button" title="'.qa_lang('polls/delete_poll_hover').'" value="'.qa_lang('polls/delete_poll').'" name="poll_delete">';

$out .= '</div>';

return $out;
}

function deletePoll($qid) {
qa_db_query_sub(
'DELETE FROM ^postmeta WHERE post_id=# AND meta_key=$',
$qid,'is_poll'
);
}
function closePoll($qid) {
qa_db_query_sub(
'UPDATE ^postmeta SET meta_value=# WHERE post_id=# AND meta_key=$',
10+$this->poll,$qid,'is_poll'
);
$this->poll = $this->poll+10;
}
function reopenPoll($qid) {
qa_db_query_sub(
'UPDATE ^postmeta SET meta_value=# WHERE post_id=# AND meta_key=$',
$this->poll-10,$qid,'is_poll'
);
$this->poll = $this->poll-10;
}

}

2 changes: 2 additions & 0 deletions qa-poll-overrides.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ function qa_get_permit_options() {
$permits = qa_get_permit_options_base();
$permits[] = 'permit_post_poll';
$permits[] = 'permit_vote_poll';
$permits[] = 'permit_close_poll';
$permits[] = 'permit_delete_poll';
return $permits;
}
function qa_get_request_content() {
Expand Down

0 comments on commit b52fa7c

Please sign in to comment.