<?php

/***************************************************************************

 toprated.php
 -------------
 copyright : (C) 2002-2003 The ezContents Development Team

 ***************************************************************************/

/***************************************************************************
 The ezContents Development Team offers no warranties on this script.
 The owner/licensee of the script is solely responsible for any problems
 caused by installation of the script or use of the script.

 All copyright notices regarding ezContents must remain intact on the
 scripts and in the HTML for the scripts.

 For more info on ezContents,
 visit http://www.ezcontents.org/

/***************************************************************************

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the License which can be found within the
 *   zipped package.
 *
 ***************************************************************************/

global $HTTP_SERVER_VARS;
if ( (substr($HTTP_SERVER_VARS["PHP_SELF"],-11) == 'control.php') ||
	 (substr($HTTP_SERVER_VARS["PHP_SELF"],-10) == 'module.php') ||
	 (substr($HTTP_SERVER_VARS["PHP_SELF"],-16) == 'showcontents.php') ) {
	 require_once('./modules/moduleSec.php');
} else {
	require_once('../moduleSec.php');
}

if (!isset($GLOBALS["gsLanguage"])) { Header("Location: ".$GLOBALS["rootdp"]."module.php?link=".$GLOBALS["modules_home"]."toprated/toprated.php"); }

$module_subdirectory	= 'toprated';
$module_language_file	= 'toprated';
$module_script_name	= 'toprated';

include_once ($GLOBALS["language_home"].$GLOBALS["gsLanguage"]."/lang_admin.php");
include_once ($GLOBALS["language_home"].$GLOBALS["gsLanguage"]."/lang_main.php");
include_languagefile ($GLOBALS["modules_home"].'toprated/',$GLOBALS["gsLanguage"],"lang_toprated.php");

if (!isset($HTTP_POST_VARS["topgroupname"])) $HTTP_POST_VARS["topgroupname"] = $HTTP_GET_VARS["topgroupname"];
if (!isset($HTTP_POST_VARS["groupname"])) $HTTP_POST_VARS["groupname"] = $HTTP_GET_VARS["groupname"];
if (!isset($HTTP_POST_VARS["subgroupname"])) $HTTP_POST_VARS["subgroupname"] = $HTTP_GET_VARS["subgroupname"];

$SAVE_VARS["topgroupname"] = $HTTP_GET_VARS["topgroupname"];
$SAVE_VARS["groupname"] = $HTTP_GET_VARS["groupname"];
$SAVE_VARS["subgroupname"] = $HTTP_GET_VARS["subgroupname"];


?>
<table border="0" width="100%" cellspacing="<?php echo $cs; ?>" cellpadding="3" class="headercontent">
<tr><td class="header">
<?php echo $GLOBALS["tTopRatedTitle"]; ?>
</td></tr>
<tr><td class="tablecontent">
<?php

$strQuery = "SELECT * FROM ".$GLOBALS["eztbContents"]." WHERE ratingvotes>0 ";

if ($GLOBALS["gsLanguage"] == $GLOBALS["gsDefault_language"]) {
   $strQuery .= " AND language='".$GLOBALS["gsLanguage"]."' ORDER BY ratingtotal/ratingvotes DESC,contentname";
} else {
   $lOrder = '';
   if ($GLOBALS["gsLanguage"] > $GLOBALS["gsDefault_language"]) { $lOrder = ' DESC'; }
   $strQuery .= " AND (language='".$GLOBALS["gsLanguage"]."' OR language='".$GLOBALS["gsDefault_language"]."') ORDER BY ratingtotal/ratingvotes DESC,contentname,language".$lOrder;
}

if ($GLOBALS["toprated"]["countlimit"] == '') { $GLOBALS["toprated"]["countlimit"] = 10; }


$result = dbRetrieve($strQuery,true,0,$GLOBALS["toprated"]["countlimit"]);
$results_found = dbRowsReturned($result);
$results_displayed = 0;
if ($results_found != 0)
{
   ?><ol><?php
   $nContentName = '';
   while ($rsContent = dbFetch($result))
   {
      if (ModArticleSecurity($nContentName,$rsContent))
      {
         echo '<li>';
         if($GLOBALS["gsUseFrames"] == 'Y') {
            echo '<a href="'.BuildLink($rootdp.'showdetails.php').'&contentname='.$rsContent["contentname"].'" target="contents"'.BuildLinkMouseOver($rsContent["title"]).'>';
         } else {
            echo '<a href="'.BuildLink($rootdp.'control.php').'&contentname='.$rsContent["contentname"].'"'.BuildLinkMouseOver($rsContent["title"]).'>';
         }
         echo ShowHeader($rsContent);
         echo '</a><br />';
         ShowFooter($rsContent["updatedatevisible"],$rsContent["authorvisible"],$rsContent);
         echo '<p align="'.$GLOBALS["right"].'">';
         if (($GLOBALS["gsAllowRatings"] == 'Y') && ($rsContent["canrate"] == 'Y'))
         {
            if ($rsContent["ratingvotes"] != 0)
            {
               $nRating = round($rsContent["ratingtotal"] / $rsContent["ratingvotes"],2);
               $nRatingStars = floor($nRating);
               if ($nRatingStars > 0)
               {
                  if ($GLOBALS["gsRatingImage1"] != '')
                  {
                     $star = imagehtmltag($GLOBALS["image_home"],$GLOBALS["gsRatingImage1"],'',0,'');
                     echo str_repeat($star,$nRatingStars).'&nbsp;&nbsp;';
                  }
               }
               elseif ($nRatingStars < 0)
               {
                  if ($GLOBALS["gsRatingImage2"] != '')
                  {
                     $star = imagehtmltag($GLOBALS["image_home"],$GLOBALS["gsRatingImage2"],'',0,'');
                     echo str_repeat($star,abs($nRatingStars)).'&nbsp;&nbsp;';
                  }
               }
               echo $GLOBALS["tRating"].' '.$nRating;
            }
            else
            {
               echo $GLOBALS["tUnrated"];
            }
         }
         $results_displayed++;
      }
   } // end while
   ?></ol><?php
} // if ($results_found != 0)


if ($results_displayed == 0)
{
   ?>
   <center>
   <table border="1" cellpadding="1" cellspacing="0" align="center" valign="top" width="100%" class="headercontent">
       <tr><td class="tablecontent">&nbsp;<br /><?php echo $GLOBALS["eNoResults"]; ?><br />&nbsp;</td></tr>
   </table>
   </center>
   <?php
} // if ($results_displayed == 0)


dbFreeResult($result);


?>
</td></tr>
</table>
<?php


$HTTP_GET_VARS["topgroupname"] = $SAVE_VARS["topgroupname"];
$HTTP_GET_VARS["groupname"] = $SAVE_VARS["groupname"];
$HTTP_GET_VARS["subgroupname"] = $SAVE_VARS["subgroupname"];

?>
