############################################################################### # Karma.pl - YaBB Mod by Joseph Fung (Joseph@ComESutra.ORg) # # Modified by Richard Carr # # # ############################################################################### # YaBB: Yet another Bulletin Board # # Open-Source Project started by Zef Hemel (zef@zefnet.com) # # Software Version: YaBB 1 Gold # ############################################################################### sub getKarma { $sourceUser = shift; @karma = &getKarmaData($sourceUser); $karma[0] =~ s/[\n\r]//g; return $karma[0]; } sub getKarmaData { $sourceUser = shift; if (-e("$memberdir/$sourceUser.karma")) { open(FILE, "$memberdir/$sourceUser.karma"); @karma = ; close(FILE); } else { @karma = ("0\n"); } return @karma; } sub setKarma { $sourceUser = shift; $newKarmaValue = shift; @karma = &getKarmaData($sourceUser); $karma[0] = "$newKarmaValue\n"; open(FILE, ">$memberdir/$sourceUser.karma"); foreach $line (@karma) { print FILE "$line"; } close(FILE); } sub modifyKarma { if ($username eq "Guest") { &fatal_error("Only registered members can modify karma."); } $sourceUserID = $INFO{'username'}; if ($sourceUserID eq $username) { &fatal_error("You can not modify your own karma."); } if ($adminOnly == 1 && $settings[7] ne 'Administrator') { &fatal_error("Only Administrators can modify karma."); } $desiredAction = $INFO{'karmaAction'}; @thekarma = &getKarmaData($username); $modifiedEntry = -1; $newTimestamp = time; for ($i = 1; $i < scalar @thekarma; $i++) { ($targetUser, $targetAction, $timestamp) = split (/\|/, $thekarma[$i]); if ($targetUser eq $sourceUserID) { $modifiedEntry = $i; $timestamp =~ s/[\n\r]//g; #if in the bad time if (($newTimestamp-$timestamp) < $waitTime) { if ($desiredAction eq $targetAction && (($settings[7] ne 'Administrator') || $settings[7] eq 'Administrator' && $restrictAdmin == 1)) { &fatal_error("You have already given karma to this member today."); } #it's within the bad time but we're not doing the same action so can continue else { $newKarma = &getKarma ($sourceUserID); if ($desiredAction eq "smite") { $newKarma = $newKarma - 1; } elsif ($desiredAction eq "applaud") { $newKarma = $newKarma + 1; } &setKarma ($sourceUserID, $newKarma); } } #we're not in the bad time else { $newKarma = &getKarma ($sourceUserID); if ($desiredAction eq "smite") { $newKarma = $newKarma - 1; } elsif ($desiredAction eq "applaud") { $newKarma = $newKarma + 1; } &setKarma ($sourceUserID, $newKarma); } } }#end for if ($modifiedEntry == -1) { $modifiedEntry = scalar @thekarma; $newKarma = &getKarma ($sourceUserID); if ($desiredAction eq "smite") { $newKarma = $newKarma - 1; } elsif ($desiredAction eq "applaud") { $newKarma = $newKarma + 1; } &setKarma ($sourceUserID, $newKarma); } @thekarma[$modifiedEntry] = "$sourceUserID|$desiredAction|$newTimestamp\n"; open(FILE, ">$memberdir/$username.karma"); foreach $line (@thekarma) { print FILE $line; } close(FILE); #redirection back to whence thy came $backto = $INFO{'backto'}; if ($backto) { if ($backto eq 'display') { if (! $INFO{'num'}) { &karma_alert("You have successfully modified the user's karma.
To see the modified karma, click refresh after you click back."); } else { $yySetLocation = qq~$cgi&action=display&num=$INFO{'num'}&start=$INFO{'start'}&addview=no~; &redirectexit; } } elsif ($backto eq 'viewprofile') { $yySetLocation = qq~$cgi&action=viewprofile&username=$INFO{'username'}~; &redirectexit; } elsif ($backto eq 'im') { $yySetLocation = qq~$cgi&action=im~; &redirectexit; } elsif ($backto eq 'imoutbox') { $yySetLocation = qq~$cgi&action=imoutbox~; &redirectexit; } elsif ($backto eq 'imstore') { $yySetLocation = qq~$cgi&action=imstore~; &redirectexit; } else { &karma_alert("You have successfully modified the user's karma.
To see the modified karma, click refresh after you click back."); } } else { &karma_alert("You have successfully modified the user's karma.
To see the modified karma, click refresh after you click back."); } } sub karma_alert { local($e) = @_; $yytitle = "Karma Police"; &header; print <<"EOT";
$yytitle

$e

$txt{'250'}
EOT &footer; exit; } 1;