<?php
        
/////////////////////////////////////////////////////////
        //
        //  AHNAR CSA3004 APT University of Malta
        //  Ian Bugeja 2005
        //
        //////////////////////////////////////////////////////////

      
class AHNAR_Tools
      
{
             public 
$maxage;
             public 
$minage;

             public function 
__construct()
             {
                  
$this->maxage 0;
                  
$this->minage 0;
             }

             public static function 
getArrow($color)
             {
                switch (
$color)
                {
                        case 
$bc "#00FF00"$c "#0000FF"; break; //green, blue
                        
case $bc "#FFFF00"$c "#FF0000"; break; //yellow, red
                        
case $bc "#fc6a08"$c "#0000FF"; break; //orange, blue
                        
case $bc "#FFFF00"$c "#FF0000"; break;
                }

                return  
"<nobr>&nbsp;<span style=\"font-size:xx-small; font-weight:bold; color:$c; background:$bc\">-&raquo;</span>&nbsp;</nobr>";
             }

             public function 
KeywordSort($keywords)   //sorts keywords
             
{
                
$this->maxage 0;
                
$this->minage 999;
                if (isset(
$keywords))
                {
                        foreach(
$keywords as $word)  //SORT THE ARRAY in descending order by update last, descending order by occurance
                        
{
                                
$occ[] = $word[1];  //array storing occurance
                                
$last[] = $word[2];  //array storing updated last
                                
if ($this->maxage $word[3]) $this->maxage $word[3]; //MAX Age
                                
if ($this->minage $word[3]) $this->minage $word[3]; //MIN Age
                        
}
                        
array_multisort($lastSORT_DESC$occSORT_DESC$keywords);   // Sorting Function
                
}

                return 
$keywords;
             }

             public static function 
redError($code$msg1$msg2="")
             {
                
header("Location: http://" $_SERVER['HTTP_HOST'] . "/error.php?ecod=$code&emsg1=$msg1&emsg2=$msg2");
                die();
             }

             public static function 
stopError($code$msg1)
             {
                if (
$code == 1) echo "-->";
                echo 
"<html><head><title>AHNAR error</title><link rel='stylesheet' href='ahnarstyle.css'></head>";
                echo 
"<body class='ahnarbody'>";
                echo 
"<h1 class='ahnarlarge'>AHNAR error<hr style='color:white'></h1>";
                echo 
"<br>";
                echo 
$msg1;
                echo 
"</body></html>";
                die(
"");
             }
      }
?>