public static function addRealm($Rpath, $name, $customVals)
 {
     global $cfg;
     if (!is_numeric($Rpath)) {
         $Rpath = AuthUtil::getRealmIDFromPath($Rpath);
     }
     $db = Database::getInstance($cfg['Auth']['dsn']);
     $sql = "SELECT * FROM realms where parentid = ? AND name = ?";
     if (!$db->getRow($sql, array($Rpath, $name))) {
         $insert['name'] = $name;
         foreach ($cfg['Auth']['realmfields'] as $fieldName => $niceName) {
             if (array_key_exists($fieldName, $customVals)) {
                 $insert[$fieldName] = $customVals[$fieldName];
             }
         }
         $insert['realmid'] = '#id#';
         $insert['parentid'] = $Rpath;
         $Rpath = $db->insert('realms', $insert);
         AuthUtil::updateRedundantInfo(array($Rpath));
         return $Rpath;
     } else {
         return false;
     }
 }