Scoop -- the swiss army chainsaw of content management
Front Page · Everything · News · Code · Help! · Wishlist · Project · Scoop Sites · Dev Notes · Latest CVS changes · Development Activities
2 boxes Boxes
By hurstdog , Section Code []
Posted on Sun Jan 14, 2001 at 12:00:00 PM PST
Here are the new boxes, after the changes I've made this weekend to the scoop code. The new poll_box allows you to use the new Search capabilites to search for polls, and it takes the load off your server for not using poll_listing(). The new comment_control box gets it so that you can change the comment listing, ratings, etc. on a poll and not have it give you the "poll '' not found" error.

I also made changes to default_template, make sure to add |STORY| into your default_template if you update to cvs. So without further ado, here are the boxes...
## poll_box

my $pollqid = shift @ARGS;
my $preview = 0;

my ($pollqid, $action) = $S->get_qid_to_show();
$preview = 1 if ($action eq 'preview');
return '' if ($pollqid == 0);

my $poll_hash = $S->get_poll_hash( $pollqid, $action );

# first get the poll form all set up except for the answers
my $poll_form = qq\|
    <!-- begin poll form -->
    <FORM ACTION="|rootdir|/" METHOD="POST">
    <INPUT TYPE="hidden" NAME="op" VALUE="view_poll">
    <INPUT TYPE="hidden" NAME="qid" VALUE="$poll_hash->{'qid'}">
    <INPUT type="hidden" name="ispoll" value="1">\|;

$poll_form .= "<b>$poll_hash->{'question'}</b><br>";

# here is where all the answer fields get filled in
my $answer_array = $S->get_poll_answers($poll_hash->{'qid'}, $action);

# now check if they have already voted or haven't logged in
my $row;
if ( $S->_can_vote($poll_hash->{'qid'}) ) {
    foreach $row ( @{$answer_array} ) {
        $poll_form .= qq\|
            <INPUT TYPE="radio" NAME="aid" VALUE="$row->{'aid'}"> $row-&
gt;{'answer'}<BR>\|;
    }
} else {
    my $total_votes = $poll_hash->{'voters'};

    if($total_votes == 0) {
        $total_votes = 1;  # so we don't get a divide by 0 error
    }

    $poll_form .= qq\|
        <TABLE BORDER=0 CELLPADDING=2 CELLSPACING=0>\|;

    foreach $row ( @{$answer_array} ) {
        my $percent = int($row->{'votes'} / $total_votes * 100);
        $poll_form .= qq\|
            <TR>
                <TD valign="top">|norm_font||dot||norm_font_end|</TD>
                <TD valign="top">|norm_font|$row->{'answer'}|norm_font_e
nd|</TD>
                <TD valign="top">|norm_font| $percent% |norm_font_end|</
TD>
            </TR>\|;
    }
    $poll_form .= qq\|
        </TABLE>\|;

}

# get the # of comments
my $comment_num = $S->poll_comment_num($poll_hash->{'qid'});

# only show the vote button if they havn't voted
if ( $S->_can_vote($poll_hash->{'qid'}) && ! $preview ) {
    $poll_form .= qq\|<BR><INPUT TYPE="submit" name="vote" VALUE="Vote"&
gt;\|;
}


# now finish up the form
my $op = $S->{CGI}->param('op');
my $comm_disp = ($op ne 'displaystory') ?
    qq{
    <TD>|norm_font|Votes: <b>$poll_hash->{'voters'}</b>|norm
_font_end|</TD>
    <TD ALIGN="center" WIDTH=15>|norm_font|\||norm_font_end|</TD>
    <TD ALIGN="right">|norm_font| Comments: <b>$comment_num</b>
|norm_font_end|</TD></TR>
    } :
    qq{
    <TD COLSPAN="3" ALIGN="center">|norm_font|Votes: <b>$poll_hash-&g
t;{'voters'}</b>|norm_font_end|</TD>
    };

$poll_form .= qq{
    </FORM>
    <!-- end poll form -->
    <P>
    |norm_font|
    <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 ALIGN="center">
    <TR>
        $comm_disp
    <TR> };

if( $preview ) {
    $poll_form .= qq{
    <TD>|norm_font|Results|norm_font_end|</TD>
    <TD ALIGN="center" WIDTH=15>|norm_font|\||norm_font_end|</TD>
    <TD ALIGN="right">|norm_font| Other Polls|norm_font_end|</TD><
/TR>
    };

} else {
    $poll_form .= qq{
    <TD>|norm_font|<a href="|rootdir|/?op=view_poll&qid=$poll_hash->{
'qid'}">Results</a>|norm_font_end|</TD>
    <TD ALIGN="center" WIDTH=15>|norm_font|\||norm_font_end|</TD>
    <TD ALIGN="right">|norm_font| <a href="|rootdir|/?op=search&type=pol
ls&search=Search">Other Polls</a>|norm_font_end|</TD></TR>
    };
}

$poll_form .= qq{
    </TABLE>
    |norm_font_end|
    <!-- end poll content -->};

## don't forget to tell them its a poll preview if it is
if( $preview ) {
    $title = "Poll Preview";
}

if ($poll_form) {
    return {content => qq{|norm_font|$poll_form|norm_font_end|}, title => $
title};
} else {
    return '';
}

# end poll_box
# comment_controls box
my $op = $S->{CGI}->param('op');
return '' unless ($op eq 'displaystory' \|\| $op eq 'comments' \|\| $op eq 'view_
poll');

my $sid = $S->{CGI}->param('sid');
my $pid = $S->{CGI}->param('pid');
my $cid = $S->{CGI}->param('cid');
my $qid = $S->{CGI}->param('qid');

my $form_extra;
my $anchor = qq{#$cid};
if ($cid) {
    $form_extra = qq{
    <INPUT TYPE="hidden" NAME="cid" VALUE="$cid">};
} elsif ($pid) {
    $form_extra = qq{
    <INPUT TYPE="hidden" NAME="pid" VALUE="$pid">};
}

my $commentmode_select = $S->_comment_mode_select();
my $comment_order_select = $S->_comment_order_select();
my $comment_rating_select = $S->_comment_rating_select();
my $rating_choice = $S->_comment_rating_choice();
my $comment_type_select = $S->_comment_type_select();

my $form_op = 'op';
my $form_op_value = $op;
my $id = 'sid';

if ( $qid ) {
    $form_op = 'op';
    $form_op_value = 'view_poll';
    $id = 'qid';
    $sid = $qid;
}

my $comment_sort = qq\|
        <FORM NAME="commentmode" ACTION="|rootdir|/$anchor" METHOD="post">
        <INPUT TYPE="hidden" NAME="$form_op" VALUE="$form_op_value">
        <INPUT TYPE="hidden" NAME="$id" VALUE="$sid">
        $form_extra
    <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 BGCOLOR="|box_content_bg|" ali
gn="center">

        <TR>
            <TD VALIGN="middle">
                |smallfont|View:
                <SMALL>
                    $comment_type_select
                </SMALL>
                Display:
                <SMALL>
                $commentmode_select
                </SMALL>
                Sort:
                <SMALL>
                $comment_rating_select
                </SMALL>
                <SMALL>
                $comment_order_select
                </SMALL>
\|;


if ($S->have_perm( 'comment_rate' )) {
    $comment_sort .= qq\|
    Rate?
    <SMALL>$rating_choice</SMALL>\|;
}

$comment_sort .= qq\|
<INPUT TYPE="submit" NAME="setcomments" VALUE="Set">
|smallfont_end|
</TD></TR>
</TABLE>
</FORM>\|;

$template =~ s/CELLSPACING=0>/CELLSPACING=0 ALIGN="center">/;

return { content => $comment_sort, template => $template };

# end comment_controls box
So those are the boxes that I changed.
-Andrew
< Vote counting race condition (Priority: LOW) | "Editorial" Polls >

Menu
· create account
· faq
· search
· report bugs
· Scoop Administrators Guide
· Scoop Box Exchange

Login
Make a new account
Username:
Password:

Related Links
· Scoop
· More on Boxes
· Also by hurstdog

Story Views
  33 Scoop users have viewed this story.

Display: Sort:
2 boxes | 2 comments (2 topical, 0 hidden)
Thanks (none / 0) (#1)
by dungmourice on Mon Jun 18, 2018 at 05:20:51 AM PST

I think that you need to check out this blog for some info on how to write an essay on national honor society I think that this could be really helpful for your future



kitchen remodeling queens (none / 0) (#2)
by Pervez on Sat Apr 13, 2019 at 01:26:36 PM PST

This information increases the lighting through which you can take notice of the truth. I favor these kinds of web site. Currently in addition click here kitchen remodeling queens Cheers pertaining to expressing helpful data.



2 boxes | 2 comments (2 topical, 0 hidden)
Display: Sort:

Hosted by ScoopHost.com Powered by Scoop
All trademarks and copyrights on this page are owned by their respective companies. Comments are owned by the Poster. The Rest © 1999 The Management

create account | faq | search