home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 April / PCWorld_2005-04_cd.bin / akce / web / unitednuke / unitednuke.exe / html / modules / Downloads / voteinclude.php < prev   
PHP Script  |  2004-01-10  |  4KB  |  114 lines

  1. <?php
  2.  
  3. /************************************************************************/
  4. /* PHP-NUKE: Web Portal System                                          */
  5. /* ===========================                                          */
  6. /*                                                                      */
  7. /* Copyright (c) 2002 by Francisco Burzi                                */
  8. /* http://phpnuke.org                                                   */
  9. /*                                                                      */
  10. /* Based on Journey Links Hack                                          */
  11. /* Copyright (c) 2000 by James Knickelbein                              */
  12. /* Journey Milwaukee (http://www.journeymilwaukee.com)                  */
  13. /*                                                                      */
  14. /* This program is free software. You can redistribute it and/or modify */
  15. /* it under the terms of the GNU General Public License as published by */
  16. /* the Free Software Foundation; either version 2 of the License.       */
  17. /************************************************************************/
  18.  
  19. if (!eregi("index.php", $_SERVER["PHP_SELF"])) {
  20.     die("You can't access this file directly...");
  21. }
  22.  
  23. $module_name = basename(dirname(__FILE__));
  24. require("modules/$module_name/d_config.php");  
  25. require_once("mainfile.php");
  26.  
  27. $outsidevotes = 0;
  28. $anonvotes = 0;
  29. $outsidevoteval = 0;
  30. $anonvoteval = 0;
  31. $regvoteval = 0;    
  32. $truecomments = $totalvotesDB;
  33. while($vrow = $db->sql_fetchrow($voteresult)) {
  34.     $ratingDB = intval($vrow['rating']);
  35.     $ratinguserDB = $vrow['ratinguser'];
  36.     $ratingcommentsDB = stripslashes($vrow['ratingcomments']);
  37.     if ($ratingcommentsDB=="") $truecomments--;
  38.     if ($ratinguserDB==$anonymous) {
  39.     $anonvotes++;
  40.     $anonvoteval += $ratingDB;
  41.     }
  42.     if ($useoutsidevoting == 1) {
  43.         if ($ratinguserDB=='outside') {
  44.         $outsidevotes++;
  45.         $outsidevoteval += $ratingDB;
  46.     }
  47.     } else { 
  48.     $outsidevotes = 0;
  49.     }
  50.     if ($ratinguserDB!=$anonymous && $ratinguserDB!="outside") { 
  51.     $regvoteval += $ratingDB;
  52.     }
  53. }
  54. $regvotes = $totalvotesDB - $anonvotes - $outsidevotes;
  55. if ($totalvotesDB == 0) { 
  56.     $finalrating = 0;
  57. } else if ($anonvotes == 0 && $regvotes == 0) {
  58.     /* Figure Outside Only Vote */
  59.     $finalrating = $outsidevoteval / $outsidevotes;
  60.     $finalrating = number_format($finalrating, 4); 
  61. } else if ($outsidevotes == 0 && $regvotes == 0) {
  62.     /* Figure Anon Only Vote */
  63.     $finalrating = $anonvoteval / $anonvotes;                  
  64.     $finalrating = number_format($finalrating, 4); 
  65. } else if ($outsidevotes == 0 && $anonvotes == 0) {
  66.     /* Figure Reg Only Vote */
  67.     $finalrating = $regvoteval / $regvotes;                  
  68.     $finalrating = number_format($finalrating, 4);                   
  69. } else if ($regvotes == 0 && $useoutsidevoting == 1 && $outsidevotes != 0 && $anonvotes != 0 ) {
  70.     /* Figure Reg and Anon Mix */
  71.     $avgAU = $anonvoteval / $anonvotes;
  72.     $avgOU = $outsidevoteval / $outsidevotes;              
  73.     if ($anonweight > $outsideweight ) {
  74.     /* Anon is 'standard weight' */
  75.     $newimpact = $anonweight / $outsideweight;
  76.     $impactAU = $anonvotes;
  77.     $impactOU = $outsidevotes / $newimpact;
  78.     $finalrating = ((($avgOU * $impactOU) + ($avgAU * $impactAU)) / ($impactAU + $impactOU));
  79.     $finalrating = number_format($finalrating, 4); 
  80.     } else {
  81.     /* Outside is 'standard weight' */
  82.     $newimpact = $outsideweight / $anonweight;
  83.     $impactOU = $outsidevotes;
  84.     $impactAU = $anonvotes / $newimpact;
  85.     $finalrating = ((($avgOU * $impactOU) + ($avgAU * $impactAU)) / ($impactAU + $impactOU));
  86.     $finalrating = number_format($finalrating, 4); 
  87.     }                            
  88. } else {
  89.     /* Registered User vs. Anonymous vs. Outside User Weight Calutions */
  90.     $impact = $anonweight;
  91.     $outsideimpact = $outsideweight;
  92.     if ($regvotes == 0) {
  93.     $regvotes = 0;
  94.     } else { 
  95.     $avgRU = $regvoteval / $regvotes;
  96.     }
  97.     if ($anonvotes == 0) {
  98.     $avgAU = 0;
  99.     } else {
  100.     $avgAU = $anonvoteval / $anonvotes;
  101.     }
  102.     if ($outsidevotes == 0 ) {
  103.     $avgOU = 0;
  104.     } else {
  105.     $avgOU = $outsidevoteval / $outsidevotes;
  106.     }
  107.     $impactRU = $regvotes;
  108.     $impactAU = $anonvotes / $impact;
  109.     $impactOU = $outsidevotes / $outsideimpact;
  110.     $finalrating = (($avgRU * $impactRU) + ($avgAU * $impactAU) + ($avgOU * $impactOU)) / ($impactRU + $impactAU + $impactOU);
  111.     $finalrating = number_format($finalrating, 4); 
  112. }
  113.  
  114. ?>