<?php
/*
######################      CWB\     #######################
############################################################
CWB PRO			$Name: release_version1_0_03112006 $
Revision		$Revision: 1.2 $
Author			$Author: lvalics $
Created 03/01/03        $Date: 2006/10/30 08:18:08 $
Writed by               GraFX (webmaster@grafxsoftware.com)
Scripts Home:           http://www.grafxsoftware.com
############################################################
*/

function arfsort( $arr, $rules ){
  $GLOBALS['__ARFSORT_LIST__'] = $rules;
  @uasort( $arr, 'arfsort_func' );
  return $arr;
}



function arfsort_func($a,$b) {
  foreach ($GLOBALS['__ARFSORT_LIST__'] as $f) {
   switch ($f[1]) { // switch on ascending or descending value
     case "d":
       ## Add number type sort
       if (is_numeric($a[$f[0]])) {
           if ($b[$f[0]] < $a[$f[0]]) $strc = -1;
           else if ($b[$f[0]] > $a[$f[0]]) $strc = 1;
           else $strc = 0;
       } else {
         $strc = strcmp($b[$f[0]],$a[$f[0]]);
       }
       if ( $strc != 0 ){
         return $strc;
       }
     break;
     default:
       if (is_numeric($a[$f[0]])) {
             if ($b[$f[0]] > $a[$f[0]]) $strc = -1;
             else if ($b[$f[0]] < $a[$f[0]]) $strc = 1;
             else $strc = 0;
         } else {
           $strc = strcmp($a[$f[0]],$b[$f[0]]);
         }
       if ($strc != 0){
         return $strc;
       }
     break;
   }
  }
  return 0;
}



// extended to allow sort direction per field sorted against
/*
function arfsort_func( $a, $b ){
  foreach( $GLOBALS['__ARFSORT_LIST__'] as $f ) {
   switch ($f[1]) { // switch on ascending or descending value
     case "d":
       $strc = strcmp( strtolower($b[$f[0]]), strtolower($a[$f[0]]) );
       if ( $strc != 0 ){
         return $strc;
       }
     break;
     default:
       $strc = strcmp( strtolower($a[$f[0]]), strtolower($b[$f[0]]) );
       if ( $strc != 0 ){
         return $strc;
       }
     break;
   }
  }
  return 0;
}
*/
?> 