Fifth pass at adding key files
This commit is contained in:
		
							
								
								
									
										406
									
								
								site/roadshow/rating/classes/database.class.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										406
									
								
								site/roadshow/rating/classes/database.class.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,406 @@
 | 
			
		||||
<?php
 | 
			
		||||
  //////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
  // Database Class 
 | 
			
		||||
  //============================================================================
 | 
			
		||||
  // Dependencies:
 | 
			
		||||
  //----------------------------------------------------------------------------
 | 
			
		||||
  // None
 | 
			
		||||
  //============================================================================
 | 
			
		||||
  // Modification History:
 | 
			
		||||
  //----------------------------------------------------------------------------
 | 
			
		||||
  // 2006-11-04: Created
 | 
			
		||||
  //////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
  class Database extends Error
 | 
			
		||||
  {
 | 
			
		||||
    ## CONSTANT VARIABLES
 | 
			
		||||
      const DB_TYPES = 'mysql,mysqli'; // NO SPACES!
 | 
			
		||||
    ## END CONSTANT VARIABLES
 | 
			
		||||
    
 | 
			
		||||
    ## PUBLIC VARIABLES
 | 
			
		||||
    ## END PUBLIC VARIABLES
 | 
			
		||||
    
 | 
			
		||||
    ## PRIVATE VARIABLES
 | 
			
		||||
      private static $host;
 | 
			
		||||
      private static $port;
 | 
			
		||||
      private static $database;
 | 
			
		||||
      private static $username;
 | 
			
		||||
      private static $password;
 | 
			
		||||
      private static $type;
 | 
			
		||||
      private static $connection;
 | 
			
		||||
      private static $savedQueries;
 | 
			
		||||
      private static $savedResults;
 | 
			
		||||
    ## END PRIVATE VARIABLES
 | 
			
		||||
    
 | 
			
		||||
    ## CONSTRUCTOR
 | 
			
		||||
    ## END CONSTRUCTOR
 | 
			
		||||
    
 | 
			
		||||
    ## DECONSTRUCTOR
 | 
			
		||||
    ## END DECONSTRUCTOR
 | 
			
		||||
    
 | 
			
		||||
    ## PUBLIC METHODS
 | 
			
		||||
      // Initialize the Variables
 | 
			
		||||
      // Does not return anything, but acts like a constructor for Static classes
 | 
			
		||||
      public static function Initialize($varType, $varHost, $varPort, $varDatabase, $varUsername, $varPassword)
 | 
			
		||||
      {
 | 
			
		||||
        Error::Initialize();
 | 
			
		||||
        
 | 
			
		||||
        if (!self::ValidDatabaseTypes($varType))
 | 
			
		||||
        {
 | 
			
		||||
          Error::LogError("Database Type Invalid", "Database Type must be one of: " . self::DB_TYPES);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        self::$host         = $varHost;
 | 
			
		||||
        self::$port         = $varPort;
 | 
			
		||||
        self::$type         = strtolower($varType);
 | 
			
		||||
        self::$database     = $varDatabase;
 | 
			
		||||
        self::$password     = $varPassword;
 | 
			
		||||
        self::$username     = $varUsername;
 | 
			
		||||
        self::$savedQueries = array();
 | 
			
		||||
        self::$savedResults = array();
 | 
			
		||||
        self::$connection   = self::ConnectToDatabase();
 | 
			
		||||
        
 | 
			
		||||
        self::SelectTheDatabase();
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // DeInitialize the Variables
 | 
			
		||||
      // Does not return anything, but acts like a destructor for Static classes
 | 
			
		||||
      public static function DeInitialize()
 | 
			
		||||
      {
 | 
			
		||||
        // Remove Saved Queries
 | 
			
		||||
        for ($saved = 0; $saved < sizeof(self::$savedQueries); $saved++)
 | 
			
		||||
        {
 | 
			
		||||
          unset(self::$savedQueries[$saved]);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        // Remove Saved Results
 | 
			
		||||
        for ($saved = 0; $saved < sizeof(self::$savedResults); $saved++)
 | 
			
		||||
        {
 | 
			
		||||
          unset(self::$savedResults[$saved]);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        // Close the Database Connection
 | 
			
		||||
        switch (self::$type)
 | 
			
		||||
        {
 | 
			
		||||
          case "mysql":
 | 
			
		||||
            @mysql_close(self::$connection) or Error::LogError("MySQL Failed to Close", mysql_error(self::$connection));
 | 
			
		||||
            break;
 | 
			
		||||
          case "mysqli":
 | 
			
		||||
            @mysqli_close(self::$connection) or Error::LogError("MySQL Failed to Close", mysqli_error(self::$connection));
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        // Destroy Variables
 | 
			
		||||
        self::$host         = null;
 | 
			
		||||
        self::$port         = null;
 | 
			
		||||
        self::$type         = null;
 | 
			
		||||
        self::$database     = null;
 | 
			
		||||
        self::$password     = null;
 | 
			
		||||
        self::$username     = null;
 | 
			
		||||
        self::$connection   = null;
 | 
			
		||||
        self::$savedQueries = null;
 | 
			
		||||
        self::$savedResults = null;
 | 
			
		||||
        Error::DeInitialize();
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // Database Types
 | 
			
		||||
      // Returns an array of database types
 | 
			
		||||
      public static function DatabaseTypes()
 | 
			
		||||
      {
 | 
			
		||||
        return split(",", self::DB_TYPES);
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // Build Order By
 | 
			
		||||
      // Returns the SQL Syntax for ORDER BY
 | 
			
		||||
      public static function BuildOrderBy($varColumnName, $varDirection)
 | 
			
		||||
      {
 | 
			
		||||
        $orderby = "";
 | 
			
		||||
        if (self::$connection)
 | 
			
		||||
        {
 | 
			
		||||
          switch (self::$type)
 | 
			
		||||
          {
 | 
			
		||||
            case "mysql":
 | 
			
		||||
            case "mysqli":
 | 
			
		||||
              $orderby = "ORDER BY `{$varColumnName}` {$varDirection}";
 | 
			
		||||
              break;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return $orderby;
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // Build Limit
 | 
			
		||||
      // Returns the SQL Syntax for LIMIT
 | 
			
		||||
      public static function BuildLimit($varStartingRow, $varNumberOfRows)
 | 
			
		||||
      {
 | 
			
		||||
        $limit = "";
 | 
			
		||||
        if (self::$connection)
 | 
			
		||||
        {
 | 
			
		||||
          switch (self::$type)
 | 
			
		||||
          {
 | 
			
		||||
            case "mysql":
 | 
			
		||||
            case "mysqli":
 | 
			
		||||
              $limit = "LIMIT {$varStartingRow}, {$varNumberOfRows}";
 | 
			
		||||
              break;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return $limit;
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // Execute SQL Query
 | 
			
		||||
      // Returns the result of the query, which is typically a resource id
 | 
			
		||||
      public static function ExecuteQuery($sql, $name)
 | 
			
		||||
      {
 | 
			
		||||
        if (self::$connection)
 | 
			
		||||
        {
 | 
			
		||||
          if (strlen(trim($name)) != 0)
 | 
			
		||||
          {
 | 
			
		||||
            switch (self::$type)
 | 
			
		||||
            {
 | 
			
		||||
              case "mysql":
 | 
			
		||||
                if (!array_key_exists($name, self::$savedQueries))
 | 
			
		||||
                {
 | 
			
		||||
                  self::$savedQueries[$name] = @mysql_query($sql, self::$connection) or Error::LogError("Query Failed", mysql_error(self::$connection));
 | 
			
		||||
                }
 | 
			
		||||
                break;
 | 
			
		||||
              case "mysqli":
 | 
			
		||||
                if (!array_key_exists($name, self::$savedQueries))
 | 
			
		||||
                {
 | 
			
		||||
                  self::$savedQueries[$name] = @mysqli_query(self::$connection, $sql) or Error::LogError("Query Failed", mysqli_error(self::$connection));
 | 
			
		||||
                }
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            return self::$savedQueries[$name];
 | 
			
		||||
          }
 | 
			
		||||
          else
 | 
			
		||||
          {
 | 
			
		||||
            Error::LogError("Execute Query Name Missing", "The name parameter was empty, please provide a name for the query.");
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return null;
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // Fetch Results
 | 
			
		||||
      // Returns an array of the query results
 | 
			
		||||
      public static function FetchResults($name)
 | 
			
		||||
      {
 | 
			
		||||
        $results = array();
 | 
			
		||||
        if (self::$connection)
 | 
			
		||||
        {
 | 
			
		||||
          if (strlen(trim($name)) != 0 && (array_key_exists($name, self::$savedQueries) || array_key_exists($name, self::$savedResults)))
 | 
			
		||||
          {
 | 
			
		||||
            if (array_key_exists($name, self::$savedQueries))
 | 
			
		||||
            {
 | 
			
		||||
              switch (self::$type)
 | 
			
		||||
              {
 | 
			
		||||
                case "mysql":
 | 
			
		||||
                  $row = 0;
 | 
			
		||||
                  while ($currentResult = @mysql_fetch_assoc(self::$savedQueries[$name]))
 | 
			
		||||
                  {
 | 
			
		||||
                    $col = 0;
 | 
			
		||||
                    foreach ($currentResult as $key => $value)
 | 
			
		||||
                    {
 | 
			
		||||
                      $results[$row][$col] = $value;
 | 
			
		||||
                      $results[$row][$key] = $value;
 | 
			
		||||
                      $col++;
 | 
			
		||||
                    }
 | 
			
		||||
                    
 | 
			
		||||
                    $row++;
 | 
			
		||||
                  }
 | 
			
		||||
                  break;
 | 
			
		||||
                case "mysqli":
 | 
			
		||||
                  $row = 0;
 | 
			
		||||
                  while ($currentResult = @mysqli_fetch_assoc(self::$savedQueries[$name]))
 | 
			
		||||
                  {
 | 
			
		||||
                    $col = 0;
 | 
			
		||||
                    foreach ($currentResult as $key => $value)
 | 
			
		||||
                    {
 | 
			
		||||
                      $results[$row][$col] = $value;
 | 
			
		||||
                      $results[$row][$key] = $value;
 | 
			
		||||
                      $col++;
 | 
			
		||||
                    }
 | 
			
		||||
                    
 | 
			
		||||
                    $row++;
 | 
			
		||||
                  }
 | 
			
		||||
                  break;
 | 
			
		||||
              }
 | 
			
		||||
            
 | 
			
		||||
              self::$savedResults[$name] = $results;
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
              $results = self::$savedResults[$name];
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
          else
 | 
			
		||||
          {
 | 
			
		||||
            if (strlen(trim($name)) == 0)
 | 
			
		||||
            {
 | 
			
		||||
              Error::LogError("Fetch Results Name Missing", "The name parameter was empty, the name is required so it knows which results to return.");
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
              Error::LogError("Fetch Results Name ('{$name}') Not Found", "The name provided did not have any query results associated with it.");
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return $results;
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // Free SQL Query Results
 | 
			
		||||
      // Returns nothing
 | 
			
		||||
      public static function FreeResults($name)
 | 
			
		||||
      {
 | 
			
		||||
        if (self::$connection)
 | 
			
		||||
        {
 | 
			
		||||
          if (strlen(trim($name)) != 0 && array_key_exists($name, self::$savedQueries))
 | 
			
		||||
          {
 | 
			
		||||
            switch (self::$type)
 | 
			
		||||
            {
 | 
			
		||||
              case "mysql":
 | 
			
		||||
                @mysql_free_result(self::$savedQueries[$name]) or Error::LogError("Free Results Error", mysql_error(self::$connection));
 | 
			
		||||
                unset(self::$savedQueries[$name]);
 | 
			
		||||
                break;
 | 
			
		||||
              case "mysqli":
 | 
			
		||||
                @mysqli_free_result(self::$savedQueries[$name]) or Error::LogError("Free Results Error", mysqli_error(self::$connection));
 | 
			
		||||
                unset(self::$savedQueries[$name]);
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
          else
 | 
			
		||||
          {
 | 
			
		||||
            if (strlen(trim($name)) == 0)
 | 
			
		||||
            {
 | 
			
		||||
              Error::LogError("Free Results Name Missing", "The name parameter was empty, the name is required so it knows which results to free up from memory.");
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
              Error::LogWarning("Free Results Name ('{$name}') Not Found", "The name provided did not have any query results associated with it.");
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // Remove Saved Results
 | 
			
		||||
      // Returns nothing
 | 
			
		||||
      public static function RemoveSavedResults($name)
 | 
			
		||||
      {
 | 
			
		||||
        if (strlen(trim($name)) != 0 && array_key_exists($name, self::$savedResults))
 | 
			
		||||
        {
 | 
			
		||||
          unset(self::$savedResults[$name]);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
          if (strlen(trim($name)) == 0)
 | 
			
		||||
          {
 | 
			
		||||
            Error::LogError("Remove Saved Result Name Missing", "The name parameter was empty, the name is required so it knows which query to remove.");
 | 
			
		||||
          }
 | 
			
		||||
          else
 | 
			
		||||
          {
 | 
			
		||||
            Error::LogWarning("Remove Saved Result Name ('{$name}') Not Found", "The name provided was not a saved query.");
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // Attempt Connect To Database
 | 
			
		||||
      // Returns true or false depending on if the connection failed or succeeded
 | 
			
		||||
      public static function AttemptConnectToDatabase($varType, $varHost, $varPort, $varDatabase, $varUsername, $varPassword)
 | 
			
		||||
      {
 | 
			
		||||
        self::$type       = $varType;
 | 
			
		||||
        self::$host       = $varHost;
 | 
			
		||||
        self::$port       = $varPort;
 | 
			
		||||
        self::$database   = $varDatabase;
 | 
			
		||||
        self::$username   = $varUsername;
 | 
			
		||||
        self::$password   = $varPassword;
 | 
			
		||||
        
 | 
			
		||||
        Error::ClearErrors();
 | 
			
		||||
        self::$connection = self::ConnectToDatabase();
 | 
			
		||||
        
 | 
			
		||||
        if (!Error::HasErrors())
 | 
			
		||||
        {
 | 
			
		||||
          return true;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
          return false;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // MySQL Version
 | 
			
		||||
      // Returns the mysql version number
 | 
			
		||||
      public static function MysqlVersion()
 | 
			
		||||
      {
 | 
			
		||||
        $version = "";
 | 
			
		||||
        if (self::$connection)
 | 
			
		||||
        {
 | 
			
		||||
          switch (self::$type)
 | 
			
		||||
          {
 | 
			
		||||
            case "mysql":
 | 
			
		||||
              $version = mysql_get_server_info(self::$connection);
 | 
			
		||||
              break;
 | 
			
		||||
            case "mysqli":
 | 
			
		||||
              $version = mysqli_get_server_info(self::$connection);
 | 
			
		||||
              break;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return $version;
 | 
			
		||||
      }
 | 
			
		||||
    ## END PUBLIC METHODS
 | 
			
		||||
    
 | 
			
		||||
    ## PRIVATE METHODS
 | 
			
		||||
      // Connect to Database
 | 
			
		||||
      // Returns the database connection resource
 | 
			
		||||
      private static function ConnectToDatabase()
 | 
			
		||||
      {
 | 
			
		||||
        $link = null;
 | 
			
		||||
        
 | 
			
		||||
        switch (self::$type)
 | 
			
		||||
        {
 | 
			
		||||
          case "mysql":
 | 
			
		||||
            if (strlen(trim(self::$port)) != 0)
 | 
			
		||||
            {
 | 
			
		||||
              $link = mysql_connect(self::$host . ":" . self::$port, self::$username, self::$password) or Error::LogError("Database Error", mysql_error());
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
              $link = mysql_connect(self::$host, self::$username, self::$password) or Error::LogError("Database Error", mysql_error());
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
          case "mysqli":
 | 
			
		||||
            $link = mysqli_connect(self::$host, self::$username, self::$password, self::$database, self::$port) or Error::LogError("Database Error", mysqli_connect_error());
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return $link;
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // Select the Database
 | 
			
		||||
      // Returns nothing
 | 
			
		||||
      private static function SelectTheDatabase()
 | 
			
		||||
      {
 | 
			
		||||
        switch (self::$type)
 | 
			
		||||
        {
 | 
			
		||||
          case "mysql":
 | 
			
		||||
            @mysql_select_db(self::$database, self::$connection) or Error::LogError("Database Selection", mysql_error(self::$connection));
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // Valid Database Types
 | 
			
		||||
      // Returns true or false depending on if the database type is valid
 | 
			
		||||
      private static function ValidDatabaseTypes($varType)
 | 
			
		||||
      {
 | 
			
		||||
        $types = split(',', str_replace(" ", "", self::DB_TYPES));
 | 
			
		||||
        
 | 
			
		||||
        return in_array($varType, $types);
 | 
			
		||||
      }
 | 
			
		||||
    ## END PRIVATE METHODS
 | 
			
		||||
    
 | 
			
		||||
    ## PROTECTED METHODS
 | 
			
		||||
    ## END PROTECTED METHODS
 | 
			
		||||
  }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										258
									
								
								site/roadshow/rating/classes/error.class.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										258
									
								
								site/roadshow/rating/classes/error.class.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,258 @@
 | 
			
		||||
<?php
 | 
			
		||||
  //////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
  // Error Class 
 | 
			
		||||
  //============================================================================
 | 
			
		||||
  // Dependencies:
 | 
			
		||||
  //----------------------------------------------------------------------------
 | 
			
		||||
  // none
 | 
			
		||||
  //============================================================================
 | 
			
		||||
  // Modification History:
 | 
			
		||||
  //----------------------------------------------------------------------------
 | 
			
		||||
  // 2006-11-04: Created
 | 
			
		||||
  //////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
  class Error
 | 
			
		||||
  {
 | 
			
		||||
    ## CONSTANT VARIABLES
 | 
			
		||||
    ## END CONSTANT VARIABLES
 | 
			
		||||
    
 | 
			
		||||
    ## PUBLIC VARIABLES
 | 
			
		||||
    ## END PUBLIC VARIABLES
 | 
			
		||||
    
 | 
			
		||||
    ## PRIVATE VARIABLES
 | 
			
		||||
      private static $title;
 | 
			
		||||
      private static $type;
 | 
			
		||||
      private static $description;
 | 
			
		||||
      private static $datetime;
 | 
			
		||||
      
 | 
			
		||||
      private static $numErrors;
 | 
			
		||||
      private static $numWarnings;
 | 
			
		||||
    ## END PRIVATE VARIABLES
 | 
			
		||||
    
 | 
			
		||||
    ## CONSTRUCTOR
 | 
			
		||||
    ## END CONSTRUCTOR
 | 
			
		||||
    
 | 
			
		||||
    ## DECONSTRUCTOR
 | 
			
		||||
    ## END DECONSTRUCTOR
 | 
			
		||||
    
 | 
			
		||||
    ## PUBLIC METHODS
 | 
			
		||||
      // Initialize the Variables
 | 
			
		||||
      // Does not return anything, but acts like a constructor for Static classes
 | 
			
		||||
      public static function Initialize()
 | 
			
		||||
      {
 | 
			
		||||
        self::$title       = array();
 | 
			
		||||
        self::$type        = array();
 | 
			
		||||
        self::$description = array();
 | 
			
		||||
        self::$datetime    = array();
 | 
			
		||||
        self::$numErrors   = 0;
 | 
			
		||||
        self::$numWarnings = 0;
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // DeInitialize the Variables
 | 
			
		||||
      // Does not return anything, but acts like a destructor for Static classes
 | 
			
		||||
      public static function DeInitialize()
 | 
			
		||||
      {
 | 
			
		||||
        self::$title       = null;
 | 
			
		||||
        self::$type        = null;
 | 
			
		||||
        self::$description = null;
 | 
			
		||||
        self::$datetime    = null;
 | 
			
		||||
        self::$numErrors   = null;
 | 
			
		||||
        self::$numWarnings = null;
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // Log Error Method (receives Name and Description)
 | 
			
		||||
      // Returns true or false depending on if the logging of the error was successful
 | 
			
		||||
      public static function LogError($varTitle, $varDescription)
 | 
			
		||||
      {
 | 
			
		||||
        // Check Parameters
 | 
			
		||||
        if (strlen(trim($varTitle)) != 0 && strlen(trim($varDescription)) != 0)
 | 
			
		||||
        {
 | 
			
		||||
          array_push(self::$title, $varTitle);
 | 
			
		||||
          array_push(self::$type, "ERROR");
 | 
			
		||||
          array_push(self::$description, $varDescription);
 | 
			
		||||
          array_push(self::$datetime, date("m/d/Y H:i:s"));
 | 
			
		||||
          self::$numErrors++;
 | 
			
		||||
          
 | 
			
		||||
          return true;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return false;
 | 
			
		||||
      }
 | 
			
		||||
    
 | 
			
		||||
      // Show Error Messages
 | 
			
		||||
      // Returns the Error Message Output (in HTML format)
 | 
			
		||||
      public static function ShowErrorMessages()
 | 
			
		||||
      {
 | 
			
		||||
        $output = "";
 | 
			
		||||
        
 | 
			
		||||
        // Check to see if 1 error occurred or more than one.
 | 
			
		||||
        if (self::$numErrors > 0)
 | 
			
		||||
        {
 | 
			
		||||
          if (self::$numErrors > 1)
 | 
			
		||||
          {
 | 
			
		||||
            $error = "ERRORS";
 | 
			
		||||
          }
 | 
			
		||||
          else
 | 
			
		||||
          {
 | 
			
		||||
            $error = "ERROR";
 | 
			
		||||
          }
 | 
			
		||||
          
 | 
			
		||||
          // Loop through Error Messages
 | 
			
		||||
          for ($i = 0; $i < sizeof(self::$title); $i++)
 | 
			
		||||
          {
 | 
			
		||||
            if (self::$type[$i] == "ERROR")
 | 
			
		||||
            {
 | 
			
		||||
              // Output each individual Error
 | 
			
		||||
              $output .= "    <div class=\"divErrorTitle\">\r\n" . 
 | 
			
		||||
                         "      " . self::$title[$i] . "\r\n" . 
 | 
			
		||||
                         "      <span class=\"spnErrorDateTime\">at " . self::$datetime[$i] . "</span>\r\n" .
 | 
			
		||||
                         "    </div>\r\n" .
 | 
			
		||||
                         "    <div class=\"divErrorDesc\">" . self::$description[$i] . "<br /><br /></div>\r\n";
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
          
 | 
			
		||||
          // Write Error Template Output
 | 
			
		||||
          $output  = "<div class=\"divErrorBox\">\r\n" .
 | 
			
		||||
                     "  <div class=\"divErrorBoxTitle\"><img src=\"icons/24-em-cross.png\" align=\"left\" /> {$error}:</div>\r\n" .
 | 
			
		||||
                     "  <div class=\"divErrors\">\r\n" . $output . "\r\n  </div>\r\n" .
 | 
			
		||||
                     "</div>\r\n";
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        // Return the Error Message Output
 | 
			
		||||
        return $output;
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // Retrieve Last Error
 | 
			
		||||
      // Returns the title and description of the last error in an array
 | 
			
		||||
      public static function RetrieveLastError()
 | 
			
		||||
      {
 | 
			
		||||
        $output = array();
 | 
			
		||||
        
 | 
			
		||||
        // Check to see if 1 error occurred or more than one.
 | 
			
		||||
        if (self::$numErrors > 0)
 | 
			
		||||
        {
 | 
			
		||||
          for ($i = sizeof(self::$title) - 1; $i >= 0; $i++)
 | 
			
		||||
          {
 | 
			
		||||
            if (self::$type[$i] == "ERROR")
 | 
			
		||||
            {
 | 
			
		||||
              array_push($output, self::$title[$i]);
 | 
			
		||||
              array_push($output, self::$description[$i]);
 | 
			
		||||
              break;
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return $output;
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // Clear Errors
 | 
			
		||||
      // Returns nothing
 | 
			
		||||
      public static function ClearErrors()
 | 
			
		||||
      {
 | 
			
		||||
        self::$numErrors   = 0;
 | 
			
		||||
        
 | 
			
		||||
        for ($i = 0; $i < sizeof(self::$type); $i++)
 | 
			
		||||
        {
 | 
			
		||||
          if (self::$type[$i] == "ERROR")
 | 
			
		||||
          {
 | 
			
		||||
            self::$title[$i]       = null;
 | 
			
		||||
            self::$type[$i]        = null;
 | 
			
		||||
            self::$description[$i] = null;
 | 
			
		||||
            self::$datetime[$i]    = null;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // Has Errors
 | 
			
		||||
      // Returns true or false on whether errors exist
 | 
			
		||||
      public static function HasErrors()
 | 
			
		||||
      {
 | 
			
		||||
        if (self::$numErrors > 0)
 | 
			
		||||
        {
 | 
			
		||||
          return true;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return false;
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // Log Warning Method (receives Name and Description)
 | 
			
		||||
      // Returns true or false depending on if logging the warning was successful
 | 
			
		||||
      public static function LogWarning($varTitle, $varDescription)
 | 
			
		||||
      {
 | 
			
		||||
        // Check Parameters
 | 
			
		||||
        if (strlen(trim($varTitle)) != 0 && strlen(trim($varDescription)) != 0)
 | 
			
		||||
        {
 | 
			
		||||
          array_push(self::$title, $varTitle);
 | 
			
		||||
          array_push(self::$type, "WARNING");
 | 
			
		||||
          array_push(self::$description, $varDescription);
 | 
			
		||||
          array_push(self::$datetime, date("m/d/Y H:i:s"));
 | 
			
		||||
          self::$numWarnings++;
 | 
			
		||||
          
 | 
			
		||||
          return true;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return false;
 | 
			
		||||
      }
 | 
			
		||||
    
 | 
			
		||||
      // Show Warning Messages
 | 
			
		||||
      // Returns the Warning Message Output (in HTML format)
 | 
			
		||||
      public static function ShowWarningMessages()
 | 
			
		||||
      {
 | 
			
		||||
        $output = "";
 | 
			
		||||
          
 | 
			
		||||
        // Check to see if 1 warning occurred or more than one.
 | 
			
		||||
        if (self::$numWarnings > 0)
 | 
			
		||||
        {
 | 
			
		||||
          if (self::$numWarnings > 1)
 | 
			
		||||
          {
 | 
			
		||||
            $warning = "WARNINGS";
 | 
			
		||||
          }
 | 
			
		||||
          else
 | 
			
		||||
          {
 | 
			
		||||
            $warning = "WARNING";
 | 
			
		||||
          }
 | 
			
		||||
          
 | 
			
		||||
          // Loop through Warning Messages
 | 
			
		||||
          for ($i = 0; $i < sizeof(self::$title); $i++)
 | 
			
		||||
          {
 | 
			
		||||
            if (self::$type[$i] == "WARNING")
 | 
			
		||||
            {
 | 
			
		||||
              // Output each individual Warning
 | 
			
		||||
              $output .= "    <div class=\"divWarningTitle\">\r\n" . 
 | 
			
		||||
                         "      " . self::$title[$i] . "\r\n" . 
 | 
			
		||||
                         "      <span class=\"spnWarningDateTime\">at " . self::$datetime[$i] . "</span>\r\n" .
 | 
			
		||||
                         "    </div>\r\n" .
 | 
			
		||||
                         "    <div class=\"divWarningDesc\">" . self::$description[$i] . "<br /><br /></div>\r\n";
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
          
 | 
			
		||||
          // Write Warning Template Output
 | 
			
		||||
          $output  = "<div id=\"divWarningBox\">\r\n" .
 | 
			
		||||
                     "  <div id=\"divWarningBoxTitle\"><img src=\"designs/icons/24-message-warn.png\" align=\"left\" /> {$warning}:</div>\r\n" .
 | 
			
		||||
                     "  <div id=\"divWarnings\">\r\n" . $output . "\r\n  </div>\r\n" .
 | 
			
		||||
                     "</div>\r\n";
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        // Return the Warning Message Output
 | 
			
		||||
        return $output;
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // Has Warnings
 | 
			
		||||
      // Returns true or false on whether there are any Warnings
 | 
			
		||||
      public static function HasWarnings()
 | 
			
		||||
      {
 | 
			
		||||
        if (self::$numWarnings > 0)
 | 
			
		||||
        {
 | 
			
		||||
          return true;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return false;
 | 
			
		||||
      }
 | 
			
		||||
    ## END PUBLIC METHODS
 | 
			
		||||
          
 | 
			
		||||
    ## PRIVATE METHODS
 | 
			
		||||
    ## END PRIVATE METHODS
 | 
			
		||||
    
 | 
			
		||||
    ## PROTECTED METHODS
 | 
			
		||||
    ## END PROTECTED METHODS
 | 
			
		||||
  }
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										7
									
								
								site/roadshow/rating/classes/include.all.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								site/roadshow/rating/classes/include.all.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
  require_once("error.class.php");
 | 
			
		||||
  require_once("database.class.php");
 | 
			
		||||
  require_once("rating.class.php");
 | 
			
		||||
  
 | 
			
		||||
  Database::Initialize("mysql", "192.168.1.10", "3306", "slowtwitch", "slowtwitch", "k9volqlAcpq");
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										279
									
								
								site/roadshow/rating/classes/rating.class.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										279
									
								
								site/roadshow/rating/classes/rating.class.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,279 @@
 | 
			
		||||
<?php
 | 
			
		||||
	class Rating
 | 
			
		||||
  {
 | 
			
		||||
    ## PRIVATE VARIABLES
 | 
			
		||||
    ## END PRIVATE VARIABLES
 | 
			
		||||
 | 
			
		||||
    ## PUBLIC METHODS
 | 
			
		||||
      // Output the Rating information
 | 
			
		||||
      // Returns a string of HTML
 | 
			
		||||
      public static function OutputRating($varParent, $varItem)
 | 
			
		||||
      {
 | 
			
		||||
        // Verify $varItem was provided
 | 
			
		||||
        if ($varItem != null && strlen(trim($varItem)) != 0 && $varParent != null && strlen(trim($varParent)) != 0)
 | 
			
		||||
        {
 | 
			
		||||
          // Check if Magic QUotes is ON
 | 
			
		||||
          if (!get_magic_quotes_gpc())
 | 
			
		||||
          {
 | 
			
		||||
            $varItem = addslashes($varItem);
 | 
			
		||||
            $varParent = addslashes($varParent);
 | 
			
		||||
          }
 | 
			
		||||
          
 | 
			
		||||
          // Information for the Output
 | 
			
		||||
          $averageStars = Rating::CalculateAverageRating($varParent, $varItem);
 | 
			
		||||
          
 | 
			
		||||
          // Check to see that the user has not already rated this item
 | 
			
		||||
          if (Rating::CheckRatingsByIp($varParent, $varItem) == 0)
 | 
			
		||||
          {
 | 
			
		||||
            $classes      = "rating " . Rating::ShowStars($averageStars);
 | 
			
		||||
            $cat_info	  = Rating::FetchCategoryInfo($varItem);
 | 
			
		||||
            
 | 
			
		||||
            // Write Output HTML for the Rating Data
 | 
			
		||||
            $output  = "\r\n";
 | 
			
		||||
            $output .= "<div style='clear:both;'>{$cat_info['rating_cat_name']}<br></div>\r\n";
 | 
			
		||||
            $output .= "<div style='display: inline;'><div style='float: left;'>{$cat_info['rating_cat_min']} </div><div style='float: left;'><ul class=\"{$classes}\" style='margin: 0px 0px 10px 0px;' id=\"{$varParent}_{$varItem}\">\r\n";
 | 
			
		||||
            $output .= "  <li class=\"one\"><a   href=\"javascript:RateItem('{$varParent}','{$varItem}', 1);\" title=\"1 Star\">1</a></li>\r\n";
 | 
			
		||||
            $output .= "  <li class=\"two\"><a   href=\"javascript:RateItem('{$varParent}','{$varItem}', 2);\" title=\"2 Stars\">2</a></li>\r\n";
 | 
			
		||||
            $output .= "  <li class=\"three\"><a href=\"javascript:RateItem('{$varParent}','{$varItem}', 3);\" title=\"3 Stars\">3</a></li>\r\n";
 | 
			
		||||
            $output .= "  <li class=\"four\"><a  href=\"javascript:RateItem('{$varParent}','{$varItem}', 4);\" title=\"4 Stars\">4</a></li>\r\n";
 | 
			
		||||
            $output .= "  <li class=\"five\"><a  href=\"javascript:RateItem('{$varParent}','{$varItem}', 5);\" title=\"5 Stars\">5</a></li>\r\n";
 | 
			
		||||
            $output .= "</ul></div><div style='float:left;'> {$cat_info['rating_cat_max']}</div></div>\r\n";
 | 
			
		||||
          }
 | 
			
		||||
          else
 | 
			
		||||
          {
 | 
			
		||||
            $classes      = "rated " . Rating::ShowStars($averageStars);
 | 
			
		||||
            $cat_info	  = Rating::FetchCategoryInfo($varItem);
 | 
			
		||||
            
 | 
			
		||||
            // Write Output HTML for the Rating Data
 | 
			
		||||
            $output  = "\r\n";
 | 
			
		||||
            $output .= "<div style='clear:both;'>{$cat_info['rating_cat_name']}<br></div>";
 | 
			
		||||
            $output .= "<div style='display: inline;'><div style='float: left;'>{$cat_info['rating_cat_min']} </div><div style='float: left;'><ul class=\"{$classes}\" id=\"{$varParent}_{$varItem}\" style='margin: 0px 0px 10px 0px;'>\r\n";
 | 
			
		||||
            $output .= "  <li class=\"one\">1</li>\r\n";
 | 
			
		||||
            $output .= "  <li class=\"two\">2</li>\r\n";
 | 
			
		||||
            $output .= "  <li class=\"three\">3</li>\r\n";
 | 
			
		||||
            $output .= "  <li class=\"four\">4</li>\r\n";
 | 
			
		||||
            $output .= "  <li class=\"five\">5</li>\r\n";
 | 
			
		||||
            $output .= "</ul></div><div style='float:left;'> {$cat_info['rating_cat_max']}</div></div>\r\n";
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
          $output = "";
 | 
			
		||||
          // This is a major issue. NO information can be retrieve if an item name is not passed.
 | 
			
		||||
          Error::LogError("Variable Missing", "You must provide the item name for this function to find the average.");
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return $output;
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      public static function OutputParentRating($varParent) 
 | 
			
		||||
      {
 | 
			
		||||
      	// Verify $varParent was provided
 | 
			
		||||
        if ($varParent != null && strlen(trim($varParent)) != 0)
 | 
			
		||||
        {
 | 
			
		||||
			// Check if Magic QUotes is ON
 | 
			
		||||
			if (!get_magic_quotes_gpc())
 | 
			
		||||
			{
 | 
			
		||||
				$varParent = addslashes($varParent);
 | 
			
		||||
			}
 | 
			
		||||
			  
 | 
			
		||||
			// Information for the Output
 | 
			
		||||
			$averageStars = Rating::CalculateAverageParentRating($varParent);
 | 
			
		||||
			  
 | 
			
		||||
			$classes      = "rated " . Rating::ShowStars($averageStars);
 | 
			
		||||
			//$parent_info	  = Rating::FetchParentInfo($varParent);
 | 
			
		||||
			
 | 
			
		||||
			// Write Output HTML for the Rating Data
 | 
			
		||||
			$output  = "\r\n";
 | 
			
		||||
			//$output .= "<div style='clear:both;'>Overall Rating</div>";
 | 
			
		||||
			$output .= "<div style='height: 16px; width: 80px; position: relative;'><ul class=\"{$classes}\" id=\"{$varParent}\" style='margin: 0px 0px 10px 0px;'>\r\n";
 | 
			
		||||
			$output .= "  <li class=\"one\">1</li>\r\n";
 | 
			
		||||
			$output .= "  <li class=\"two\">2</li>\r\n";
 | 
			
		||||
			$output .= "  <li class=\"three\">3</li>\r\n";
 | 
			
		||||
			$output .= "  <li class=\"four\">4</li>\r\n";
 | 
			
		||||
			$output .= "  <li class=\"five\">5</li>\r\n";
 | 
			
		||||
			$output .= "</ul></div>\r\n";
 | 
			
		||||
		}	
 | 
			
		||||
		else
 | 
			
		||||
        {
 | 
			
		||||
          	$output = "";
 | 
			
		||||
         	 // This is a major issue. NO information can be retrieve if an item name is not passed.
 | 
			
		||||
          	Error::LogError("Variable Missing", "You must provide the parent name for this function to find the average.");
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return $output;
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // Rate an Item
 | 
			
		||||
      // Returns the name/value pair of new class names and the item name
 | 
			
		||||
      public static function RateItem($varParent, $varItem, $varRating, $varClasses)
 | 
			
		||||
      {
 | 
			
		||||
        $newClassNames = $varClasses;
 | 
			
		||||
        
 | 
			
		||||
        // Verify $varName was provided
 | 
			
		||||
        if ($varParent != null && strlen(trim($varParent)) != 0
 | 
			
		||||
          && $varItem != null && strlen(trim($varItem)) != 0
 | 
			
		||||
          && $varRating != null && strlen(trim($varRating)) != 0 && is_numeric($varRating) 
 | 
			
		||||
          && $varClasses != null && strlen(trim($varClasses)) != 0)
 | 
			
		||||
        {
 | 
			
		||||
          // Check if Magic Quotes is ON
 | 
			
		||||
          if (!get_magic_quotes_gpc())
 | 
			
		||||
          {
 | 
			
		||||
            $varItem = addslashes($varItem);
 | 
			
		||||
            $varParent = addslashes($varParent);
 | 
			
		||||
          }
 | 
			
		||||
          
 | 
			
		||||
          // Check to see that the user has not already rated this item
 | 
			
		||||
          if (Rating::CheckRatingsByIp($varParent, $varItem) == 0)
 | 
			
		||||
          {
 | 
			
		||||
            $ipAddress = $_SERVER['REMOTE_ADDR'];
 | 
			
		||||
            $tempTime = time();
 | 
			
		||||
            
 | 
			
		||||
            Database::ExecuteQuery("INSERT INTO `gforum_FittersRating` (`rating_fitter_id`, `rating_category_id`, `rating_vote`, `rating_ip`, `rating_date`) VALUES ('{$varParent}', '{$varItem}', {$varRating}, '{$ipAddress}', '{$tempTime}')", "InsertRating");
 | 
			
		||||
            Database::FetchResults("InsertRating");
 | 
			
		||||
            Database::FreeResults("InsertRating");
 | 
			
		||||
            Database::RemoveSavedResults("InsertRating");
 | 
			
		||||
            
 | 
			
		||||
            // Information for the Output
 | 
			
		||||
            $averageStars    = Rating::CalculateAverageRating($varParent, $varItem);
 | 
			
		||||
            $newClassNames   = "rated " . Rating::ShowStars($averageStars);
 | 
			
		||||
            $averageStars  = Rating::CalculateAverageParentRating($varParent);
 | 
			
		||||
			$newClassParent         = "rated " . Rating::ShowStars($averageStars);
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
          // This is a major issue. NOT enough information was sent to log the item
 | 
			
		||||
          Error::LogError("Variable(s) Missing", "You must provide all of the information to log the rating of this item.");
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        // Build Name/Value Pair to return
 | 
			
		||||
        $nameValue = "classes={$newClassNames}&item={$varItem}&parent={$varParent}&parentClass={$newClassParent}";
 | 
			
		||||
        return $nameValue;
 | 
			
		||||
      }
 | 
			
		||||
    ## END PUBLIC METHODS
 | 
			
		||||
    
 | 
			
		||||
    ## PRIVATE METHODS
 | 
			
		||||
	  // Fetch Category Names & Min/Max Values    
 | 
			
		||||
	  private static function FetchCategoryInfo($varItem)
 | 
			
		||||
	  {
 | 
			
		||||
	    // Query Category Info for a specific Category ID
 | 
			
		||||
        Database::ExecuteQuery("SELECT * FROM `gforum_FittersRatingCategory` WHERE `rating_cat_id`='{$varItem}'", "CategoryInfo");
 | 
			
		||||
        $results = Database::FetchResults("CategoryInfo");
 | 
			
		||||
        Database::FreeResults("CategoryInfo");
 | 
			
		||||
        Database::RemoveSavedResults("CategoryInfo");
 | 
			
		||||
        
 | 
			
		||||
        return $results[0];
 | 
			
		||||
        
 | 
			
		||||
	  }
 | 
			
		||||
    
 | 
			
		||||
      // Calculate Average Rating
 | 
			
		||||
      // Returns the number of stars to show
 | 
			
		||||
      private static function CalculateAverageRating($varParent, $varItem)
 | 
			
		||||
      {
 | 
			
		||||
        $averageStars = 0;
 | 
			
		||||
        
 | 
			
		||||
        // Query Average Rating for a specific Item
 | 
			
		||||
        Database::ExecuteQuery("SELECT AVG(`rating_vote`) AS `averageRating` FROM `gforum_FittersRating` WHERE `rating_category_id`='{$varItem}' AND `rating_fitter_id`='{$varParent}'", "AverageRating");
 | 
			
		||||
        $results = Database::FetchResults("AverageRating");
 | 
			
		||||
        Database::FreeResults("AverageRating");
 | 
			
		||||
        Database::RemoveSavedResults("AverageRating");
 | 
			
		||||
        
 | 
			
		||||
        // Round the Average into a Whole Number
 | 
			
		||||
        if (sizeof($results) == 1)
 | 
			
		||||
        {
 | 
			
		||||
          if ($results[0]['averageRating'] != null)
 | 
			
		||||
          {
 | 
			
		||||
            $averageStars = round($results[0]["averageRating"], 0);
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
          // This is simply a warning, as it isn't vital if no results were found, as the item may be new.
 | 
			
		||||
          Error::LogWarning("Rating Data Missing", "No entries were found for '{$varName}', this might be the first entry.");
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return $averageStars;
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
            // Calculate Average Rating
 | 
			
		||||
      // Returns the number of stars to show
 | 
			
		||||
      private static function CalculateAverageParentRating($varParent)
 | 
			
		||||
      {
 | 
			
		||||
        $averageStars = 0;
 | 
			
		||||
        
 | 
			
		||||
        // Query Average Rating for a specific Item
 | 
			
		||||
        Database::ExecuteQuery("SELECT AVG(`rating_vote`) AS `averageRating` FROM `gforum_FittersRating` WHERE `rating_fitter_id`='{$varParent}'", "AverageRating");
 | 
			
		||||
        $results = Database::FetchResults("AverageRating");
 | 
			
		||||
        Database::FreeResults("AverageRating");
 | 
			
		||||
        Database::RemoveSavedResults("AverageRating");
 | 
			
		||||
        
 | 
			
		||||
        // Round the Average into a Whole Number
 | 
			
		||||
        if (sizeof($results) == 1)
 | 
			
		||||
        {
 | 
			
		||||
          if ($results[0]['averageRating'] != null)
 | 
			
		||||
          {
 | 
			
		||||
            $averageStars = round($results[0]["averageRating"], 0);
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
          // This is simply a warning, as it isn't vital if no results were found, as the item may be new.
 | 
			
		||||
          Error::LogWarning("Rating Data Missing", "No entries were found for '{$varName}', this might be the first entry.");
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return $averageStars;
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // Show Stars
 | 
			
		||||
      // Returns the class information for the number of stars to show
 | 
			
		||||
      private static function ShowStars($varStars)
 | 
			
		||||
      {
 | 
			
		||||
        // Select the Number of Stars Class
 | 
			
		||||
        switch ($varStars)
 | 
			
		||||
        {
 | 
			
		||||
          case 1:
 | 
			
		||||
            $classes .= "onestar";
 | 
			
		||||
            break;
 | 
			
		||||
          case 2:
 | 
			
		||||
            $classes .= "twostar";
 | 
			
		||||
            break;
 | 
			
		||||
          case 3:
 | 
			
		||||
            $classes .= "threestar";
 | 
			
		||||
            break;
 | 
			
		||||
          case 4:
 | 
			
		||||
            $classes .= "fourstar";
 | 
			
		||||
            break;
 | 
			
		||||
          case 5:
 | 
			
		||||
            $classes .= "fivestar";
 | 
			
		||||
            break;
 | 
			
		||||
          default:
 | 
			
		||||
            $classes .= "nostar";
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return $classes;
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      // Check Ratings By IP Address
 | 
			
		||||
      // Returns the number of ratings for an item by an ip address
 | 
			
		||||
      private static function CheckRatingsByIp($varParent, $varItem)
 | 
			
		||||
      {
 | 
			
		||||
        $ipAddress = $_SERVER['REMOTE_ADDR'];
 | 
			
		||||
        
 | 
			
		||||
        Database::ExecuteQuery("SELECT COUNT(*) AS `totalRatings` FROM `gforum_FittersRating` WHERE `rating_category_id`='{$varItem}' AND `rating_fitter_id`='{$varParent}' AND `rating_ip`='{$ipAddress}'", "AlreadyRated");
 | 
			
		||||
        $results = Database::FetchResults("AlreadyRated");
 | 
			
		||||
        Database::FreeResults("AlreadyRated");
 | 
			
		||||
        Database::RemoveSavedResults("AlreadyRated");
 | 
			
		||||
        
 | 
			
		||||
        // Check to see that the user has not already rated this item
 | 
			
		||||
        if ($results != null && $results[0]['totalRatings'] != null)
 | 
			
		||||
        {
 | 
			
		||||
          return $results[0]['totalRatings'];
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return 0;
 | 
			
		||||
      }
 | 
			
		||||
    ## END PRIVATE METHODS
 | 
			
		||||
  }
 | 
			
		||||
?> 
 | 
			
		||||
		Reference in New Issue
	
	Block a user