<?php
// File: $Id: voteinclude.php,v 1.10 2001/12/04 01:12:44 gregorrothfuss Exp $ $Name: $
// ----------------------------------------------------------------------
// POST-NUKE Content Management System
// Copyright (C) 2001 by the Post-Nuke Development Team.
// http://www.postnuke.com/
// ----------------------------------------------------------------------
// Based on:
// PHP-NUKE Web Portal System - http://phpnuke.org/
// Thatware - http://thatware.org/
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
// Original Author of file:
// Purpose of file:
// Based on Journey Links Hack
// Copyright (c) 2000 by James Knickelbein
// http://www.journeymilwaukee.com
// ----------------------------------------------------------------------
if (eregi("voteinclude.php", $PHP_SELF)) {
die ("You can't access this file directly...");
}
include(WHERE_IS_PERSO."config.php");
$outsidevotes = 0;
$anonvotes = 0;
$outsidevoteval = 0;
$anonvoteval = 0;
$regvoteval = 0;
$truecomments = $totalvotesDB;
// FTO Check EOF and databse error
if (!$voteresult) {
PN_DBMsgError($dbconn, __FILE__, __LINE__, "An error ocurred");
die();
}
while(!$voteresult->EOF) {
list($ratingDB, $ratinguserDB, $ratingcommentsDB) = $voteresult->fields;
$voteresult->MoveNext();
if ($ratingcommentsDB == "") {
--$truecomments;
}
if ($ratinguserDB == $anonymous) {
$anonvotes++;
$anonvoteval += $ratingDB;
}
if ($useoutsidevoting == 1) {
if ($ratinguserDB == 'outside') {
++$outsidevotes;
$outsidevoteval += $ratingDB;
}
} else {
$outsidevotes = 0;
}
if ($ratinguserDB != $anonymous && $ratinguserDB != "outside") {
$regvoteval += $ratingDB;
}
}
$regvotes = $totalvotesDB - $anonvotes - $outsidevotes;
if ($totalvotesDB == 0) {
$finalrating = 0;
} else if ($anonvotes == 0 && $regvotes == 0) {
/* Figure Outside Only Vote */
$finalrating = $outsidevoteval / $outsidevotes;
$finalrating = number_format($finalrating, 4);
} else if ($outsidevotes == 0 && $regvotes == 0) {
/* Figure Anon Only Vote */
$finalrating = $anonvoteval / $anonvotes;
$finalrating = number_format($finalrating, 4);
} else if ($outsidevotes == 0 && $anonvotes == 0) {
/* Figure Reg Only Vote */
$finalrating = $regvoteval / $regvotes;
$finalrating = number_format($finalrating, 4);
} else if ($regvotes == 0 && $useoutsidevoting == 1 && $outsidevotes != 0 && $anonvotes != 0 ) {
/* Figure Reg and Anon Mix */
$avgAU = $anonvoteval / $anonvotes;
$avgOU = $outsidevoteval / $outsidevotes;
if ($anonweight > $outsideweight ) {
/* Anon is 'standard weight' */
$newimpact = $anonweight / $outsideweight;
$impactAU = $anonvotes;
$impactOU = $outsidevotes / $newimpact;
$finalrating = ((($avgOU * $impactOU) + ($avgAU * $impactAU)) / ($impactAU + $impactOU));
$finalrating = number_format($finalrating, 4);
} else {
/* Outside is 'standard weight' */
$newimpact = $outsideweight / $anonweight;
$impactOU = $outsidevotes;
$impactAU = $anonvotes / $newimpact;
$finalrating = ((($avgOU * $impactOU) + ($avgAU * $impactAU)) / ($impactAU + $impactOU));
$finalrating = number_format($finalrating, 4);
}
} else {
/* Registered User vs. Anonymous vs. Outside User Weight Calutions */
$impact = $anonweight;
$outsideimpact = $outsideweight;
if ($regvotes == 0) {
$regvotes = 0;
} else {
$avgRU = $regvoteval / $regvotes;
}
if ($anonvotes == 0) {
$avgAU = 0;
} else {
$avgAU = $anonvoteval / $anonvotes;
}
if ($outsidevotes == 0 ) {
$avgOU = 0;
} else {
$avgOU = $outsidevoteval / $outsidevotes;
}
$impactRU = $regvotes;
$impactAU = $anonvotes / $impact;
$impactOU = $outsidevotes / $outsideimpact;
$finalrating = (($avgRU * $impactRU) + ($avgAU * $impactAU) + ($avgOU * $impactOU)) / ($impactRU + $impactAU + $impactOU);
$finalrating = number_format($finalrating, 4);
}
?>