Skip to content

Commit

Permalink
Poll updates - new description field. View vote data by poll and inte…
Browse files Browse the repository at this point in the history
…rface improvements.
  • Loading branch information
mark0263 committed Feb 14, 2017
1 parent 2bdb1e2 commit 3b73391
Show file tree
Hide file tree
Showing 46 changed files with 1,375 additions and 928 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,4 +1,8 @@
## v1.6.6 (unreleased)
- Polls Enhancements
- Ability to view vote data per poll
- Description field added to each poll
- Admin interface improvements
- Forum - Sort mood dropwdown in alphabetical order
- Forum - Rounded corners on topic list hearders
- Forum - Moderators were not displayed when configured to display
Expand Down
175 changes: 90 additions & 85 deletions private/plugins/polls/functions.inc
Expand Up @@ -922,7 +922,7 @@ function POLLS_pollVote($pid, $showall = true, $displaytype = 0)

$retval = '';

$result = DB_query("SELECT topic,voters,commentcode,is_open,login_required,hideresults,owner_id "
$result = DB_query("SELECT topic,description,voters,commentcode,is_open,login_required,hideresults,owner_id "
. ",group_id,perm_owner,perm_group,perm_anon,perm_members "
. "FROM {$_TABLES['polltopics']} WHERE pid='".DB_escapeString($pid)."'" . COM_getPermSql('AND'));
$ntopics = DB_numRows($result);
Expand All @@ -947,10 +947,11 @@ function POLLS_pollVote($pid, $showall = true, $displaytype = 0)
'pquestions' => 'pollquestions.thtml',
'comments' => 'pollcomments.thtml'));
$poll->set_var('poll_id', $pid );
if ($nquestions > 1) {
// if ($nquestions > 1) {
$poll->set_var('poll_topic', $LANG25['34'] . " " . htmlspecialchars($P['topic']));
$poll->set_var('lang_question', $LANG25[31].':');
}
// }
$poll->set_var('poll_description', htmlspecialchars($P['description']));
$poll->set_var('num_votes', COM_numberFormat($P['voters']));
$poll->set_var('poll_vote_url', $_CONF['site_url']
. '/polls/index.php');
Expand Down Expand Up @@ -1010,7 +1011,6 @@ function POLLS_pollVote($pid, $showall = true, $displaytype = 0)
$Q = DB_fetchArray($questions);
$poll->set_var('poll_question', " ".$Q['question']);
$poll->set_var('question_id', $j);

$notification = "";
$filter = "";
if ($showall == false) {
Expand All @@ -1030,8 +1030,9 @@ function POLLS_pollVote($pid, $showall = true, $displaytype = 0)
for($i=0; $i<$nanswers; $i++) {
$A = DB_fetchArray($answers );
if (($j < count($aid)) && ($aid[$j] == $A['aid'])) {
$poll->set_var('selected', ' checked');
$poll->set_var('selected', ' checked="checked"');
}

$poll->set_var('answer_id', $A['aid']);
$poll->set_var('answer_text', $A['answer']);
$poll->parse('poll_answers', 'panswer', true);
Expand Down Expand Up @@ -1248,6 +1249,7 @@ function POLLS_saveVote($pid, $aid)
true
);
}

if ( COM_isAnonUser() ) {
$userid = 1;
} else {
Expand Down Expand Up @@ -1287,7 +1289,7 @@ function POLLS_pollResults($pid, $scale=400, $order='', $mode='', $displaytype =
$_PO_CONF, $LANG01, $LANG_POLLS, $_COM_VERBOSE, $LANG25;

$retval = '';
$topic_sql = "SELECT topic,voters,is_open,hideresults,commentcode,owner_id,group_id,"
$topic_sql = "SELECT topic,description,voters,is_open,hideresults,commentcode,owner_id,group_id,"
. "perm_owner,perm_group,perm_members,perm_anon "
. "FROM {$_TABLES['polltopics']} WHERE pid='".DB_escapeString($pid)."'";
$result = DB_query($topic_sql);
Expand Down Expand Up @@ -1342,6 +1344,7 @@ function POLLS_pollResults($pid, $scale=400, $order='', $mode='', $displaytype =
'votes_num' => 'pollvotes_num.thtml' ));
$poll->set_var('layout_url', $_CONF['layout_url']);
$poll->set_var('poll_topic', htmlspecialchars($P['topic']));
$poll->set_var('poll_description',htmlspecialchars($P['description']));

$poll->set_var('poll_id', $pid);
$poll->set_var('num_votes', COM_numberFormat($P['voters']));
Expand Down Expand Up @@ -1378,12 +1381,14 @@ function POLLS_pollResults($pid, $scale=400, $order='', $mode='', $displaytype =
. "FROM {$_TABLES['pollanswers']} "
. "WHERE pid='".DB_escapeString($pid)."' and qid='".DB_escapeString($Q['qid'])."' "
. "ORDER BY $order";

$answers = DB_query ($answer_sql);
$nanswers = DB_numRows($answers);

$a_summ_sql = "SELECT SUM(votes) as votesumm FROM {$_TABLES['pollanswers']} "
. "WHERE pid='".DB_escapeString($pid)."' and qid='".DB_escapeString($Q['qid'])."' "
. "GROUP BY qid";

$a_summ = DB_query ($a_summ_sql);
$S = DB_fetchArray($a_summ);

Expand Down Expand Up @@ -1476,84 +1481,6 @@ function POLLS_pollResults($pid, $scale=400, $order='', $mode='', $displaytype =
return $retval;
}

/**
* Check if we already have a vote from this IP address
*
* @param string $pid Poll ID
* @param string $ip (optional) IP address
* @return boolean true: IP already voted; false: didn't
*
*/
function POLLS_ipAlreadyVoted($pid, $ip = '' )
{
global $_USER, $_TABLES;

$retval = false;

if(empty($ip )) {
$ip = $_SERVER['REMOTE_ADDR'];
}

if ( !COM_isAnonUser() ) {
if (DB_count($_TABLES['pollvoters'],
array('uid', 'pid'),
array( (int) $_USER['uid'], DB_escapeString($pid))) > 0) {
$retval = true;
} else {
$retval = false;
}
} elseif ($ip != '' && DB_count($_TABLES['pollvoters'],
array('ipaddress', 'pid'),
array(DB_escapeString($ip), DB_escapeString($pid))) > 0) {
$retval = true;
}

return $retval;
}

function POLLS_siteHeader($title='', $meta='')
{
global $_PO_CONF;

$retval = '';

switch( $_PO_CONF['displayblocks'] ) {
case 0 : // left only
case 2 :
$retval .= COM_siteHeader('menu',$title,$meta);
break;
case 1 : // right only
case 3 :
$retval .= COM_siteHeader('none',$title,$meta);
break;
default :
$retval .= COM_siteHeader('menu',$title,$meta);
break;
}
return $retval;
}

function POLLS_siteFooter() {
global $_CONF, $_PO_CONF;

$retval = '';

switch( $_PO_CONF['displayblocks'] ) {
case 0 : // left only
case 3 : // none
$retval .= COM_siteFooter();
break;
case 1 : // right only
case 2 : // left and right
$retval .= COM_siteFooter( true );
break;
default :
$retval .= COM_siteFooter();
break;
}
return $retval;
}

function POLLS_getListField($fieldname, $fieldvalue, $A, $icon_arr, $token)
{
global $_CONF, $LANG25, $LANG_ACCESS, $LANG_ADMIN, $_USER;
Expand Down Expand Up @@ -1608,7 +1535,9 @@ function POLLS_getListField($fieldname, $fieldvalue, $A, $icon_arr, $token)
break;

case 'voters':
$retval = COM_numberFormat ($A['voters']);
// add a link there to the list of voters
$url = $_CONF['site_admin_url'].'/plugins/polls/index.php?lv=x&amp;pid='.urlencode($A['pid']);
$retval = '<a href="'.$url.'">'.COM_numberFormat($A['voters']).'</a>';
break;

case 'delete':
Expand Down Expand Up @@ -1636,5 +1565,81 @@ function POLLS_getListField($fieldname, $fieldvalue, $A, $icon_arr, $token)
return $retval;
}

/**
* Check if we already have a vote from this IP address
*
* @param string $pid Poll ID
* @param string $ip (optional) IP address
* @return boolean true: IP already voted; false: didn't
*
*/
function POLLS_ipAlreadyVoted($pid, $ip = '' )
{
global $_USER, $_TABLES;

$retval = false;

if(empty($ip )) {
$ip = $_SERVER['REMOTE_ADDR'];
}

if ( !COM_isAnonUser() ) {
if (DB_count($_TABLES['pollvoters'],
array('uid', 'pid'),
array( (int) $_USER['uid'], DB_escapeString($pid))) > 0) {
$retval = true;
} else {
$retval = false;
}
} elseif ($ip != '' && DB_count($_TABLES['pollvoters'],
array('ipaddress', 'pid'),
array(DB_escapeString($ip), DB_escapeString($pid))) > 0) {
$retval = true;
}

return $retval;
}

function POLLS_siteHeader($title='', $meta='')
{
global $_PO_CONF;

$retval = '';

switch( $_PO_CONF['displayblocks'] ) {
case 0 : // left only
case 2 :
$retval .= COM_siteHeader('menu',$title,$meta);
break;
case 1 : // right only
case 3 :
$retval .= COM_siteHeader('none',$title,$meta);
break;
default :
$retval .= COM_siteHeader('menu',$title,$meta);
break;
}
return $retval;
}

function POLLS_siteFooter() {
global $_CONF, $_PO_CONF;

$retval = '';

switch( $_PO_CONF['displayblocks'] ) {
case 0 : // left only
case 3 : // none
$retval .= COM_siteFooter();
break;
case 1 : // right only
case 2 : // left and right
$retval .= COM_siteFooter( true );
break;
default :
$retval .= COM_siteFooter();
break;
}
return $retval;
}
?>
9 changes: 8 additions & 1 deletion private/plugins/polls/language/chinese_simplified_utf-8.php
Expand Up @@ -64,7 +64,14 @@
'pollhidden' => 'You have already voted. This poll results will only be shown when voting is closed.',
'start_poll' => 'Start Poll',
'deny_msg' => 'Access to this poll is denied. Either the poll has been moved/removed or you do not have sufficient permissions.',
'login_required' => "<a href=\"{$_CONF['site_url']}/users.php\" rel=\"nofollow\">Login</a> required to vote"
'login_required' => "<a href=\"{$_CONF['site_url']}/users.php\" rel=\"nofollow\">Login</a> required to vote",
'username' => 'Username',
'ipaddress' => 'IP Address',
'date_voted' => 'Date Voted',
'description' => 'Description',
'general' => 'General',
'poll_questions' => 'Poll Questions',
'permissions' => 'Permissions'
);

###############################################################################
Expand Down
9 changes: 8 additions & 1 deletion private/plugins/polls/language/chinese_traditional_utf-8.php
Expand Up @@ -64,7 +64,14 @@
'pollhidden' => 'You have already voted. This poll results will only be shown when voting is closed.',
'start_poll' => 'Start Poll',
'deny_msg' => 'Access to this poll is denied. Either the poll has been moved/removed or you do not have sufficient permissions.',
'login_required' => "<a href=\"{$_CONF['site_url']}/users.php\" rel=\"nofollow\">Login</a> required to vote"
'login_required' => "<a href=\"{$_CONF['site_url']}/users.php\" rel=\"nofollow\">Login</a> required to vote",
'username' => 'Username',
'ipaddress' => 'IP Address',
'date_voted' => 'Date Voted',
'description' => 'Description',
'general' => 'General',
'poll_questions' => 'Poll Questions',
'permissions' => 'Permissions'
);

###############################################################################
Expand Down
9 changes: 8 additions & 1 deletion private/plugins/polls/language/czech.php
Expand Up @@ -66,7 +66,14 @@
'pollhidden' => 'You have already voted. This poll results will only be shown when voting is closed.',
'start_poll' => 'Zahaj hlasování',
'deny_msg' => 'Přístup k tomuto hlasování je odepřen. Buď bylo hlasování přesunuto či odstraněno nebo nemáte dostatečná práva.',
'login_required' => "<a href=\"{$_CONF['site_url']}/users.php\" rel=\"nofollow\">Login</a> required to vote"
'login_required' => "<a href=\"{$_CONF['site_url']}/users.php\" rel=\"nofollow\">Login</a> required to vote",
'username' => 'Username',
'ipaddress' => 'IP Address',
'date_voted' => 'Date Voted',
'description' => 'Description',
'general' => 'General',
'poll_questions' => 'Poll Questions',
'permissions' => 'Permissions'
);

###############################################################################
Expand Down
9 changes: 8 additions & 1 deletion private/plugins/polls/language/czech_utf-8.php
Expand Up @@ -66,7 +66,14 @@
'pollhidden' => 'You have already voted. This poll results will only be shown when voting is closed.',
'start_poll' => 'Zahaj hlasování',
'deny_msg' => 'Přístup k tomuto hlasování je odepřen. Buď bylo hlasování přesunuto či odstraněno nebo nemáte dostatečná práva.',
'login_required' => "<a href=\"{$_CONF['site_url']}/users.php\" rel=\"nofollow\">Login</a> required to vote"
'login_required' => "<a href=\"{$_CONF['site_url']}/users.php\" rel=\"nofollow\">Login</a> required to vote",
'username' => 'Username',
'ipaddress' => 'IP Address',
'date_voted' => 'Date Voted',
'description' => 'Description',
'general' => 'General',
'poll_questions' => 'Poll Questions',
'permissions' => 'Permissions'
);

###############################################################################
Expand Down
9 changes: 8 additions & 1 deletion private/plugins/polls/language/danish.php
Expand Up @@ -64,7 +64,14 @@
'pollhidden' => 'You have already voted. This poll results will only be shown when voting is closed.',
'start_poll' => 'Start Afstemning',
'deny_msg' => 'Access to this poll is denied. Either the poll has been moved/removed or you do not have sufficient permissions.',
'login_required' => "<a href=\"{$_CONF['site_url']}/users.php\" rel=\"nofollow\">Login</a> required to vote"
'login_required' => "<a href=\"{$_CONF['site_url']}/users.php\" rel=\"nofollow\">Login</a> required to vote",
'username' => 'Username',
'ipaddress' => 'IP Address',
'date_voted' => 'Date Voted',
'description' => 'Description',
'general' => 'General',
'poll_questions' => 'Poll Questions',
'permissions' => 'Permissions'
);

###############################################################################
Expand Down
9 changes: 8 additions & 1 deletion private/plugins/polls/language/danish_utf-8.php
Expand Up @@ -64,7 +64,14 @@
'pollhidden' => 'You have already voted. This poll results will only be shown when voting is closed.',
'start_poll' => 'Start Afstemning',
'deny_msg' => 'Access to this poll is denied. Either the poll has been moved/removed or you do not have sufficient permissions.',
'login_required' => "<a href=\"{$_CONF['site_url']}/users.php\" rel=\"nofollow\">Login</a> required to vote"
'login_required' => "<a href=\"{$_CONF['site_url']}/users.php\" rel=\"nofollow\">Login</a> required to vote",
'username' => 'Username',
'ipaddress' => 'IP Address',
'date_voted' => 'Date Voted',
'description' => 'Description',
'general' => 'General',
'poll_questions' => 'Poll Questions',
'permissions' => 'Permissions'
);

###############################################################################
Expand Down
9 changes: 8 additions & 1 deletion private/plugins/polls/language/dutch.php
Expand Up @@ -63,7 +63,14 @@
'pollhidden' => 'You have already voted. This poll results will only be shown when voting is closed.',
'start_poll' => 'Start Poll',
'deny_msg' => 'Access to this poll is denied. Either the poll has been moved/removed or you do not have sufficient permissions.',
'login_required' => "<a href=\"{$_CONF['site_url']}/users.php\" rel=\"nofollow\">Login</a> required to vote"
'login_required' => "<a href=\"{$_CONF['site_url']}/users.php\" rel=\"nofollow\">Login</a> required to vote",
'username' => 'Username',
'ipaddress' => 'IP Address',
'date_voted' => 'Date Voted',
'description' => 'Description',
'general' => 'General',
'poll_questions' => 'Poll Questions',
'permissions' => 'Permissions'
);

###############################################################################
Expand Down
9 changes: 8 additions & 1 deletion private/plugins/polls/language/dutch_utf-8.php
Expand Up @@ -63,7 +63,14 @@
'pollhidden' => 'You have already voted. This poll results will only be shown when voting is closed.',
'start_poll' => 'Vul Enquete in',
'deny_msg' => 'Access to this poll is denied. Either the poll has been moved/removed or you do not have sufficient permissions.',
'login_required' => "<a href=\"{$_CONF['site_url']}/users.php\" rel=\"nofollow\">Login</a> required to vote"
'login_required' => "<a href=\"{$_CONF['site_url']}/users.php\" rel=\"nofollow\">Login</a> required to vote",
'username' => 'Username',
'ipaddress' => 'IP Address',
'date_voted' => 'Date Voted',
'description' => 'Description',
'general' => 'General',
'poll_questions' => 'Poll Questions',
'permissions' => 'Permissions'
);

###############################################################################
Expand Down

0 comments on commit 3b73391

Please sign in to comment.