<?php

  /*

      functions.php

      Generally useful functions can be found in this script.
    
      Changelog:
        2006-01-14 dave: Cleaned up code for v1.0 release
  
      ## PAGE CONTAINS HANDYANDY MYSQL MODS ##
      ## Copyright (C) 2005 Andy Deakin (handyandy.org.uk) ##

      ----

      Copyright (C) 2004  Central Manchester CLC
      Copyright (C) 2004  Mark Harrison

      This program is free software; you can redistribute it and/or
      modify it under the terms of the GNU General Public License
      as published by the Free Software Foundation version 2.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.

      You should have received a copy of the GNU General Public License
      along with this program; if not, write to the Free Software
      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

  */

  // Security...
  if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__, '.php')) !== false) {
    header("location: index.php");
  }

  require_once "db.php";

  function get_closed_status($domain) {
    // Find the highest status (the terminal status) and treat it as closed
    $sql = "SELECT * FROM tbl_Statuses WHERE (domain=$domain AND
      active=1) OR domain=0 ORDER BY domain DESC,sortorder DESC";
    $statusesRS = db_recordset($sql);

    if (count($statusesRS) <= 2) {
      // 0 rows shouldn't happen
      // 1 row  == Ungraded (from domain 0)
      // 2 rows == Ungraded + 1 status for the domain (treat as open)
      // 3+ rows == more than 1 status for the domain (treat bottom one as
      // closed.
      $closedstatus = '-1';
    } else {
      $closedstatus = $statusesRS[0]['id'];
    }
    return $closedstatus;
  }

?>
