home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 May / INTERNET103.ISO / pc / software / windows / building / php_nuke / html / modules / downloads / voteinclude.php < prev   
Encoding:
PHP Script  |  2002-09-16  |  4.2 KB  |  107 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. $module_name = basename(dirname(__FILE__));
  20. require("modules/$module_name/d_config.php");  
  21. require_once("mainfile.php");
  22.  
  23. $outsidevotes = 0;
  24. $anonvotes = 0;
  25. $outsidevoteval = 0;
  26. $anonvoteval = 0;
  27. $regvoteval = 0;    
  28. $truecomments = $totalvotesDB;
  29. while(list($ratingDB, $ratinguserDB, $ratingcommentsDB)=sql_fetch_row($voteresult, $dbi)) {
  30.     if ($ratingcommentsDB=="") $truecomments--;
  31.     if ($ratinguserDB==$anonymous) {
  32.     $anonvotes++;
  33.     $anonvoteval += $ratingDB;
  34.     }
  35.     if ($useoutsidevoting == 1) {
  36.         if ($ratinguserDB=='outside') {
  37.         $outsidevotes++;
  38.         $outsidevoteval += $ratingDB;
  39.     }
  40.     } else { 
  41.     $outsidevotes = 0;
  42.     }
  43.     if ($ratinguserDB!=$anonymous && $ratinguserDB!="outside") { 
  44.     $regvoteval += $ratingDB;
  45.     }
  46. }
  47. $regvotes = $totalvotesDB - $anonvotes - $outsidevotes;
  48. if ($totalvotesDB == 0) { 
  49.     $finalrating = 0;
  50. } else if ($anonvotes == 0 && $regvotes == 0) {
  51.     /* Figure Outside Only Vote */
  52.     $finalrating = $outsidevoteval / $outsidevotes;
  53.     $finalrating = number_format($finalrating, 4); 
  54. } else if ($outsidevotes == 0 && $regvotes == 0) {
  55.     /* Figure Anon Only Vote */
  56.     $finalrating = $anonvoteval / $anonvotes;                  
  57.     $finalrating = number_format($finalrating, 4); 
  58. } else if ($outsidevotes == 0 && $anonvotes == 0) {
  59.     /* Figure Reg Only Vote */
  60.     $finalrating = $regvoteval / $regvotes;                  
  61.     $finalrating = number_format($finalrating, 4);                   
  62. } else if ($regvotes == 0 && $useoutsidevoting == 1 && $outsidevotes != 0 && $anonvotes != 0 ) {
  63.     /* Figure Reg and Anon Mix */
  64.     $avgAU = $anonvoteval / $anonvotes;
  65.     $avgOU = $outsidevoteval / $outsidevotes;              
  66.     if ($anonweight > $outsideweight ) {
  67.     /* Anon is 'standard weight' */
  68.     $newimpact = $anonweight / $outsideweight;
  69.     $impactAU = $anonvotes;
  70.     $impactOU = $outsidevotes / $newimpact;
  71.     $finalrating = ((($avgOU * $impactOU) + ($avgAU * $impactAU)) / ($impactAU + $impactOU));
  72.     $finalrating = number_format($finalrating, 4); 
  73.     } else {
  74.     /* Outside is 'standard weight' */
  75.     $newimpact = $outsideweight / $anonweight;
  76.     $impactOU = $outsidevotes;
  77.     $impactAU = $anonvotes / $newimpact;
  78.     $finalrating = ((($avgOU * $impactOU) + ($avgAU * $impactAU)) / ($impactAU + $impactOU));
  79.     $finalrating = number_format($finalrating, 4); 
  80.     }                            
  81. } else {
  82.     /* Registered User vs. Anonymous vs. Outside User Weight Calutions */
  83.     $impact = $anonweight;
  84.     $outsideimpact = $outsideweight;
  85.     if ($regvotes == 0) {
  86.     $regvotes = 0;
  87.     } else { 
  88.     $avgRU = $regvoteval / $regvotes;
  89.     }
  90.     if ($anonvotes == 0) {
  91.     $avgAU = 0;
  92.     } else {
  93.     $avgAU = $anonvoteval / $anonvotes;
  94.     }
  95.     if ($outsidevotes == 0 ) {
  96.     $avgOU = 0;
  97.     } else {
  98.     $avgOU = $outsidevoteval / $outsidevotes;
  99.     }
  100.     $impactRU = $regvotes;
  101.     $impactAU = $anonvotes / $impact;
  102.     $impactOU = $outsidevotes / $outsideimpact;
  103.     $finalrating = (($avgRU * $impactRU) + ($avgAU * $impactAU) + ($avgOU * $impactOU)) / ($impactRU + $impactAU + $impactOU);
  104.     $finalrating = number_format($finalrating, 4); 
  105. }
  106.  
  107. ?>