<?php
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); 
/**
* @version $Id: ps_perm.php,v 1.4 2005/01/27 19:33:40 soeren_nb Exp $
* @package mambo-phpShop
* Contains code from PHPShop(tm):
* 	@copyright (C) 2000 - 2004 Edikon Corporation (www.edikon.com)
*	Community: www.phpshop.org, forums.phpshop.org
* Conversion to Mambo and the rest:
* 	@copyright (C) 2004-2005 Soeren Eberhardt
*
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* mambo-phpShop is Free Software.
* mambo-phpShop comes with absolute no warranty.
*
* www.mambo-phpshop.net
*/

class ps_perm {

    // Can be easily extended
    // Another permissions array must then
    // be changed in ps_user.php!!
    var $permissions = array(
			   "shopper" 	=>  "1",
			   "demo" 	=>  "2",
			   "storeadmin" =>  "4",
			   "admin" 	=>  "8" 
			);
  /**************************************************************************
  ** name: check()
  ** created by:
  ** description: Validates the permission to do something.
  ** parameters:
  ** returns:
  ***************************************************************************/
  
   function check($perms) {

    // Parse all permissions in argument, comma separated
    // It is assumed auth_user only has one group per user.
    
    $auth = $_SESSION["auth"];
    
     if ($perms == "none") {
        return True;
     }
     else {
       $p1 = explode(",", $auth['perms']);
       $p2 = explode(",", $perms);
       while (list($key1, $value1) = each($p1)) {
         while (list($key2, $value2) = each($p2)) {
           if ($value1 == $value2) {
             return True;
           }
         }
       }
     }
     return False;    
        
    }
  /**************************************************************************
  ** name: is_registered_customer()
  ** created by: soeren
  ** description: Validates if someone is registered customer.
  **            by checking if one has a billing address
  ** parameters: user_id
  ** returns: true if the user has a BT address
  **          false if the user has none
  ***************************************************************************/
  function is_registered_customer($user_id) {
    
    $db_check = new ps_DB;
    $q  = "SELECT id from #__users WHERE ";
    $q .= "id='" . $user_id . "' ";
    $q .= "AND address_type='BT'";
    $db_check->query($q);
    // Query failed or not?
    if ($db_check->num_rows()) 
        return true;
    else        
        return false;
  }
  
  
}

?>
