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