Bazaar Voting body<=

[<< Back]

login." unless $remote; my $bz = $dbh->selectrow_hashref("SELECT * FROM bzrs WHERE open='1' ". "ORDER BY datestart LIMIT 1"); return "No bazaar session is currently active." unless $bz; my $bzid = $bz->{'bzid'}; return "You aren't a voter for the current bazaar session." unless $dbh->selectrow_array("SELECT weight FROM bzrvoter WHERE bzid=? AND userid=?", undef, $bzid, $remote->{'userid'}); # load votes (if voter) my %votes; $sth = $dbh->prepare("SELECT u.user, v.coid, v.weight, c.cat, c.des, c.url, c.dateadd ". "FROM bzrvote v, contributed c, useridmap u ". "WHERE v.bzid=? AND v.userid=? AND v.coid=c.coid ". "AND u.userid=c.userid"); $sth->execute($bzid, $remote->{'userid'}); while (my $v = $sth->fetchrow_hashref) { $votes{$v->{'coid'}} = $v; } my @unvote; $sth = $dbh->prepare("SELECT u.user, c.coid, c.cat, c.des, c.url, c.dateadd ". "FROM contributed c, useridmap u ". "WHERE u.userid=c.userid AND c.dateadd > ? ". "AND c.userid <> ?"); $sth->execute($bz->{'datestart'}, $remote->{'userid'}); while (my $v = $sth->fetchrow_hashref) { next if defined $votes{$v->{'coid'}}; push @unvote, $v; } if (LJ::did_post()) { foreach my $id (keys %votes) { next if $POST{"weight_$id"} eq ""; my $new = int($POST{"weight_$id"}); $new = 0 if $new < 0; next if $POST{"weight_$id"} eq $votes{$id}->{'weight'}; $votes{$id}->{'weight'} = $new; $dbh->do("REPLACE INTO bzrvote (bzid, userid, coid, weight) VALUES (?,?,?,?)", undef, $bzid, $remote->{'userid'}, $id, $new); } foreach my $v (@unvote) { my $id = $v->{'coid'}; next if $POST{"weight_$id"} eq ""; # delete contribution (so much stupid crap get submitted, like: # "I gave my friend a code!") if ($POST{"weight_$id"} eq "d") { if (LJ::check_priv($dbh, $remote, "contrib_delete")) { $dbh->do("DELETE FROM contributed WHERE coid=?", undef, $id); $dbh->do("DELETE FROM contributedack WHERE coid=?", undef, $id); } $v->{'_deleted'} = 1; next; } $votes{$id} = $v; my $new = int($POST{"weight_$id"}); $new = 0 if $new < 0; $votes{$id}->{'weight'} = $new; $dbh->do("REPLACE INTO bzrvote (bzid, userid, coid, weight) VALUES (?,?,?,?)", undef, $bzid, $remote->{'userid'}, $id, $new); if ($new) { $dbh->do("INSERT IGNORE INTO contributedack (coid, ackuserid) VALUES (?,?)", undef, $v->{'coid'}, $remote->{'userid'}); } } # remove items that were just voted for @unvote = grep { ! $votes{$_->{'coid'}} && ! $_->{'_deleted'} } @unvote; if ($POST{'new_id'}) { my $c = $dbh->selectrow_hashref("SELECT u.user, c.coid, c.cat, c.des, c.url, c.dateadd ". "FROM contributed c, useridmap u WHERE c.coid=? ". "AND c.dateadd > DATE_SUB(NOW(), INTERVAL 60 DAY) ". "AND u.userid=c.userid", undef, $POST{'new_id'}); return "Error: invalid contribution ID. Either does not exist, or is too old." unless $c; return "Error: can't vote for your own contributions" if $c->{'user'} eq $remote->{'user'}; $c->{'weight'} = ($POST{'new_weight'}+0) || 1; $dbh->do("REPLACE INTO bzrvote (bzid, userid, coid, weight) VALUES (?,?,?,?)", undef, $bzid, $remote->{'userid'}, $c->{'coid'}, $c->{'weight'}); LJ::Contrib::ack($c->{'coid'}, $remote->{'userid'}); $votes{$c->{'coid'}} = $c; } } $ret .= "this bazaar session, you can add contributions you'd like to recognize here, and weight them all appropriately in regards to each other. p?>"; $ret .= "
"; $ret .= "\n"; my $tw = 0; foreach (values %votes) { $tw += $_->{'weight'}; } my $row = sub { my $v = shift; my $des = LJ::eall($v->{'des'}); if ($v->{'url'}) { $v->{'url'} = LJ::eall($v->{'url'}); $des = "$des"; } my $per = $v->{'weight'} ne "" ? sprintf("%0.02f%%", $v->{'weight'}*100/($tw||1)) : ""; $ret .= ""; }; # the ones that have been voted for, skipping zero weight foreach my $v (sort { $b->{'weight'} <=> $a->{'weight'} } values %votes) { next unless $v->{'weight'}; $row->($v); } $ret .= "\n"; $ret .= "\n"; # unweighted contributions if (@unvote) { $ret .= "\n"; foreach my $v (@unvote) { $row->($v); } $ret .= "\n"; } $ret .= "
ContributionWeight
[$v->{'coid'}] "; $ret .= LJ::ljuser($v->{'user'}) . ": "; $ret .= "$des
$v->{'cat'}, $v->{'dateadd'}
$per
New vote item: Contribution ID:
Contributions you haven't weighted:
(set to 0 to remove from this list)
"; return $ret; } _code?> <=body page?>