<?php
define('idDiGIR_fltCOP','$Id: DiGIR_fltCOP.php,v 1.14 2004/09/02 14:37:14 rdg Exp $');
if (defined('idDIGIR_VERSION_REQUEST'))
    return;
/*
* $Id: DiGIR_fltCOP.php,v 1.14 2004/09/02 14:37:14 rdg Exp $
*/
include_once("DiGIR_utils.php");

function escapeTerm($term)
{
    //escape any DIGIR_SQL_QUOTE characters.
    $res = str_replace(DIGIR_SQL_QUOTE,DIGIR_SQL_QUOTE_ESCAPE,$term);
    return $res;
}

//Implements a comparison operator
class filterCOP
{
    var $m_COPop;
    var $m_concept;
    var $m_conceptType;
    var $m_term;
    var $m_parent;
    var $m_nameSpace;
    //m_local indicates if the filter is local (from the provider
    //configuration) or not (from regular requests)
    var $m_local;
    //m_attrs is only used by local filters and stores the
    //xml attributes related to the concept (table, field, type)
    var $m_attrs;

    function filterCOP($copOP,$local=false)
    {
        $this->m_COPop = $copOP;
        $this->m_concept = op_NONE;
        $this->m_conceptType = RPNConceptType;  //or XMLConceptType
        $this->m_term = "";
        $this->m_parent = NULL;
        $this->m_nameSpace = "";
        $this->m_local = $local;
    }

    function setParent(&$parent)
    {
        $this->m_parent = &$parent;
    }

    function &getParent()
    {
        return $this->m_parent;
    }

    function setcontent($xml)
    {
        DebugMsg($xml);
        $this->m_term = $xml;
    }

    function parseRPN($aElements)
    {
        DebugMsg("____Add COP:".dumpArray($aElements));
        global $g_RPNCompAttrs;

        //find the term- it's the first element with a " in it.
        $i=0;
        $bFound = FALSE;
        while (($i<count($aElements)) && (!$bFound))
        {
            if (strpos($aElements[$i],"\"") === FALSE)
                $i++;
            else
                $bFound = TRUE;
        }
        $aterm = split("\"",$aElements[$i]);
        $this->m_term = $aterm[1];

        //now split out the attributes to determine the concept and
        //comparison operator
        for ($j=0; $j <= $i; $j++)
        {
            $attrs = split(" ",$aElements[$j]);
            $attrs = split("=",$attrs[1]);
            $a = (int) $attrs[0];
            switch ($a)
            {
            case 1:
                $this->m_concept = (int) $attrs[1];
                DebugMsg("set concept = $attrs[1]");
                break;
            case 2:
                $v = (int) $attrs[1];
                DebugMsg("set comparison to $v");
                $this->m_COPop = $g_RPNCompAttrs[$v];
                break;
            }
        }
    }

    function Dump($n)
    {
            $stab = ".";
            for ($i=0; $i<$n; $i++)
                    $stab = $stab.".";
            echo $stab."([".$this->m_nameSpace.":".
                $this->m_concept."] ".
                cpToText($this->m_COPop)." ";
            if (is_array($this->m_term))
            {
                echo "\n";
                foreach ($this->m_term as $k=>$t)
                {
                    echo "[".$k."]=".$t."\n";
                }
            }
            else
            {
                echo "\"".$this->m_term."\")\n";
            }
    }

        //this function generates a comparison operation expressed as a piece of SQL
        //e.g. (fieldName = 'term')
    function toSQL(&$Cfg)
    {
        global $g_cMultiTermDelimiter,$g_SQLDateFormat,$g_SQLWildCard,$g_cBoundingBoxDelimiter;
        $sql = "";

        if ($this->m_conceptType == XMLConceptType)
        {
            if ($this->m_local)
            {
                if (is_array($this->m_attrs))
                {
                    array_change_key_case($this->m_attrs, CASE_LOWER);
		    $isArray = 1;
                }

                if (!$isArray or !array_key_exists('table', $this->m_attrs) or 
                                 !array_key_exists('field', $this->m_attrs) or 
                                 !array_key_exists('type', $this->m_attrs))
                {
		  DebugMsg($this->m_attrs);
                    AppendError(DC_UNSUPPORTED_ACCESSPOINT,"Local filter terms need three attributes to work: table, field and type.  Check configuration information",DIAG_ERROR);
                    return "";
                }
                $id = 1000;
            }
            else
            {
                $id = $Cfg->getConceptByName($this->m_concept,$this->m_nameSpace);
            }
        }
        else
        {
            $id = $Cfg->getConceptByZid($this->m_concept);
        }

        if ($id < 0)
        {
            AppendError(DC_UNSUPPORTED_ACCESSPOINT,"Concept can not be mapped to database [".$this->m_concept."].  Check query and/or configuration information",DIAG_ERROR);
            return "";
        }

        if ($this->m_local)
        {
            $concept = array(typeNameToType($this->m_attrs['type']),
                             $this->m_attrs['table'],
                             $this->m_attrs['field']);
        }
        else
        {
            $concept = $Cfg->m_concepts[$id];
        }

        //a concept is an array of values
        //[0] = type_XXX enumeration
        //[1] = table
        //[2] = field (where multi field, contains array of fields)
        //[3] = name (for SQLSTUB is the number of reps of the inserted elements)
        //[4] = zid
        switch ($concept[0])
        {
        //numeric comparison types.  valid for floats and ints
        case type_NUMERIC:
            $stmp = $concept[1].".".$concept[2];
            if (is_null($this->m_term))
            {
                //special case: NULL comparison
                switch ($this->m_COPop)
                {
                    case cp_eq:
                        $sql = "(".$stmp." IS NULL)";
                        return $sql;
                        break;
                    case cp_neq:
                        if ($Cfg->minQueryTermLength == 0)
                        {
                            $sql = "(".$stmp." IS NOT NULL)";
                            return $sql;
                        }
                        else
                        {
                             AppendError(DC_QUERYTERMTOOSHORT,
                             "NOT NULL query attempted but not allowed",
                             DIAG_ERROR);
                             return "";
                        }
                        break;
                }
                AppendError(DC_COMPTYPENOTSUPPORTED,
                    "The comparison operator [".cpToText($this->m_COPop).
                    "] is not supported with a NULL term",
                    DIAG_ERROR);
                return "";
            }
            if ($this->m_COPop != cp_in)
                $ttmp = (float) $this->m_term;
            switch ($this->m_COPop)
            {
            case cp_undefined:
            case cp_eq:
                $sql = "(".$stmp." = ".$ttmp.")";
                return $sql;
                break;
            case cp_lt:
                $sql = "(".$stmp." < ".$ttmp.")";
                return $sql;
                break;
            case cp_lteq:
                $sql = "(".$stmp." <= ".$ttmp.")";
                return $sql;
                break;
            case cp_gteq:
                $sql = "(".$stmp." >= ".$ttmp.")";
                return $sql;
                break;
            case cp_gt:
                $sql = "(".$stmp." > ".$ttmp.")";
                return $sql;
                break;
            case cp_neq:
                $sql = "(".$stmp." <> ".$ttmp.")";
                return $sql;
                break;
            case cp_in:
                $atmp = null;
                if (is_array($this->m_term))
                    $atmp = $this->m_term;
                else
                    $atmp = split($g_cMultiTermDelimiter,$this->m_term);
                $termtmp = "";
                $nelements = count($atmp);
                for ($i=0; $i < $nelements; $i++)
                {
                    $ttmp = (float) $atmp[$i];
                    $termtmp = $termtmp.$ttmp;
                    if ($i < count($atmp)-1)
                        $termtmp .= ",";
                }
                $sql = "(".$stmp." IN (".$termtmp."))";
                return $sql;
                break;
            default:
                AppendError(DC_COMPTYPENOTSUPPORTED," The comparison operator [".cpToText($this->m_COPop)."] can not be used with this concept type [NUMERIC]",DIAG_ERROR);
                return "";
                break;
            }
            break;

        //text comparisons
        case type_TEXT:
        {
            $stmp = $concept[1].".".$concept[2];
            if (is_null($this->m_term))
            {
                DebugMsg("NULL comparison for $stmp");
                //special case: NULL comparison
                switch ($this->m_COPop)
                {
                    case cp_eq:
                        $sql = "(".$stmp." IS NULL)";
                        return $sql;
                        break;
                    case cp_neq:
                        if ($Cfg->minQueryTermLength == 0)
                        {
                            $sql = "(".$stmp." IS NOT NULL)";
                            return $sql;
                        }
                        else
                        {
                             AppendError(DC_QUERYTERMTOOSHORT,
                             "NOT NULL query attempted but not allowed",
                             DIAG_ERROR);
                             return "";
                        }
                        break;
                }
                AppendError(DC_COMPTYPENOTSUPPORTED,
                    "The comparison operator [".cpToText($this->m_COPop).
                    "] is not supported with a NULL term",
                    DIAG_ERROR);
                return "";
            }
            
            if (!is_null($this->m_term) and !is_array($this->m_term) and 
                (strlen($this->m_term) < $Cfg->minQueryTermLength) and
                (!in_array($this->m_COPop,array(cp_eq,cp_neq))))
            {
                //special case, term is not null, but still too short (too general)
                AppendError(DC_QUERYTERMTOOSHORT," The term [".$this->m_term."] is too general. Add more characters.",DIAG_ERROR);
                return "";
            }
            $termtmp = "";
            if ($this->m_COPop != cp_in)
                $termtmp = escapeTerm($this->m_term);
            if (!DIGIR_CASE_SENSITIVE_SEARCH)
            {
	        if (version_compare(phpversion(), "4.3.0", ">=") > 0)
		{
		    if (function_exists('mb_strtolower'))
                        $termtmp = mb_strtolower($termtmp, 'UTF-8');
                    else
                        $termtmp = strtolower($termtmp);
		}
	        else
		{
		    $flat_termtmp = $termtmp;
		    if (function_exists('mb_convert_encoding'))
                        $flat_termtmp = mb_convert_encoding($termtmp, 'ASCII', 'UTF-8');
		    if (count(unpack('C*', $termtmp)) <> count(unpack('C*', $flat_termtmp)))
                    {
                        //the test above should check if there are any diacriticals inside the term
                        AppendError(DC_INVALIDTERM," The term [".$this->m_term."] contains unsupported characters to be used in case insensitive searches with PHP versions lesser than 4.3.0.",DIAG_ERROR);
                        return "";
                    }
                    else
                    {
                        $termtmp = strtolower($termtmp);
                    }
                }

                $stmp = "LOWER(".$concept[1].".".$concept[2].")";
            }
            switch ($this->m_COPop)
            {
                case cp_eq:
                    $sql = "(".$stmp." = ".DIGIR_SQL_QUOTE.$termtmp.DIGIR_SQL_QUOTE.")";
                    return $sql;
                    break;
                case cp_lt:
                    $sql = "(".$stmp." < ".DIGIR_SQL_QUOTE.$termtmp.DIGIR_SQL_QUOTE.")";
                    return $sql;
                    break;
                case cp_lteq:
                    $sql = "(".$stmp." <= ".DIGIR_SQL_QUOTE.$termtmp.DIGIR_SQL_QUOTE.")";
                    return $sql;
                    break;
                case cp_gteq:
                    $sql = "(".$stmp." >= ".DIGIR_SQL_QUOTE.$termtmp.DIGIR_SQL_QUOTE.")";
                    return $sql;
                    break;
                case cp_gt:
                    $sql = "(".$stmp." > ".DIGIR_SQL_QUOTE.$termtmp.DIGIR_SQL_QUOTE.")";
                    return $sql;
                    break;
                case cp_neq:
                    $sql = "(".$stmp." <> ".DIGIR_SQL_QUOTE.$termtmp.DIGIR_SQL_QUOTE.")";
                    return $sql;
                    break;
                case cp_in:
                    $atmp = null;
                    if (is_array($this->m_term))
                        $atmp = $this->m_term;
                    else
                        $atmp = split($g_cMultiTermDelimiter,$this->m_term);
                    $termtmp = "";
                    $nelements = count($atmp);
                    for ($i=0; $i < $nelements; $i++)
                    {
                        $ttmp = escapeTerm($atmp[$i]);
                        $termtmp = $termtmp.DIGIR_SQL_QUOTE.$ttmp.DIGIR_SQL_QUOTE;
                        if ($i < count($atmp)-1)
                            $termtmp .= ",";
                    }
                    $sql = "(".$stmp." IN (".$termtmp."))";
                    return $sql;
                    break;
                case cp_undefined:
                case cp_like:
                    $__tmpcount = 0;
                    while ((strstr($stmp,"%%")!== FALSE) and ($__tmpcount < 10))
                    {
                        $termtmp = str_replace("%%","%",$termtmp);
                        $__tmpcount = $__tmpcount +1;
                    }
                    if (strlen($termtmp) < $Cfg->minQueryTermLength)
                    {
                        AppendError(DC_QUERYTERMTOOSHORT," The term [".$this->m_term."] is too general. Add more characters.",DIAG_ERROR);
                        return "";
                    }
                    if (strpos($termtmp,"%") === FALSE)
                        $termtmp = "%".$termtmp."%";
                    //replace the wild card chars
                    $termtmp = str_replace("%",$g_SQLWildCard,$termtmp);
                    $sql = "(".$stmp." LIKE ".DIGIR_SQL_QUOTE.$termtmp.DIGIR_SQL_QUOTE.")";
                    return $sql;
                    break;
                case cp_contains:  //SQL Server specific
                        $sql = " CONTAINS (".$stmp.",".DIGIR_SQL_QUOTE.$this->term.DIGIR_SQL_QUOTE.")";
                        return $sql;
                        break;
                case cp_freetext:        //SQL Server specific
                        $sql = " FREETEXT (".$stmp.",".DIGIR_SQL_QUOTE.$this->term.DIGIR_SQL_QUOTE.")";
                        return $sql;
                        break;
                case cp_matches:        //SQL Server specific
                        $sql = " MATCHES (".$stmp.",".DIGIR_SQL_QUOTE.$this->term.DIGIR_SQL_QUOTE.")";
                        return $sql;
                        break;
                default:
                        AppendError(DC_COMPTYPENOTSUPPORTED,"The comparison [".cpToText($this->m_COPop)."] is not supported by TEXT type",DIAG_ERROR);
                        return "";
                        break;
                }
                break;
            }
        case type_BBOUNDING:
            $atmp = split($g_cBoundingBoxDelimiter,$this->m_term);
            if (count($atmp) < 4)
            {
                AppendError(DC_INVALIDTERM,"The supplied term [".$this->m_term."] does not have the required number of sub elements for this type of concept [BBOUNDING]",DIAG_ERROR);
                return "";
            }
            $concept[2] = explode(',', $concept[2]);
            if (count($concept[2]) < 2)
            {
                AppendError(DC_BADCONCEPTMAP,"Concept map for the concept type [BBOUNDING] has too few elements- check configuration",DIAG_EROR);
            }
            switch ($this->m_COPop)
            {
            case cp_lt:
            case cp_lteq:
            case cp_gteq:
            case cp_gt:
                $sql = "((".$concept[1].".".$concept[2][0]." NOT BETWEEN ".$atmp[2]." AND ".$atmp[3].") AND (".$concept[1].".".$concept[2][1]." NOT BETWEEN ".$atmp[0]." AND ".$atmp[1]."))";
                return $sql;
                break;
            case cp_undefined:
            case cp_eq:
                $sql = "((".$concept[1].".".$concept[2][0]." BETWEEN ".$atmp[2]." AND ".$atmp[3].") AND (".$concept[1].".".$concept[2][1]." BETWEEN ".$atmp[0]." AND ".$atmp[1]."))";
                return $sql;
                break;
            default:
                AppendError(DC_COMPTYPENOTSUPPORTED,"The comparison operator [".cpToText($this->m_COPop)."] is not supported for this concept type [BBOUNDING]",DIAG_ERROR);
                return "";
                break;
            }
            break;
        case type_JULIANDAY:
            $atmp = JDtoDM((int) $this->m_term);
            switch ($this->m_COPop)
            {
            case cp_lt:
                $sql = "((".$concept[1].".".$concept[2][1]."<".$atmp[1].") OR ((".$concept[1].".".$concept[2][1]."=".$atmp[1].") AND (".$concept[1].".".$concept[2][0]."<".$atmp[0].")))";
                return $sql;
                break;
            case cp_lteq:
                $sql = "((".$concept[1].".".$concept[2][1]."<".$atmp[1].") OR ((".$concept[1].".".$concept[2][1]."=".$atmp[1].") AND (".$concept[1].".".$concept[2][0]."<=".$atmp[0].")))";
                return $sql;
                break;
            case cp_gteq:
                $sql = "((".$concept[1].".".$concept[2][1].">".$atmp[1].") OR ((".$concept[1].".".$concept[2][1]."=".$atmp[1].") AND (".$concept[1].".".$concept[2][0].">=".$atmp[0].")))";
                return $sql;
                break;
            case cp_gt:
                $sql = "((".$concept[1].".".$concept[2][1].">".$atmp[1].") OR ((".$concept[1].".".$concept[2][1]."=".$atmp[1].") AND (".$concept[1].".".$concept[2][0].">".$atmp[0].")))";
                return $sql;
                break;
            case cp_in:
                AppendError(DC_COMPTYPENOTSUPPORTED," IN operation attempted on Julian type.",DIAG_ERROR);
                return "";
                break;
            case cp_undefined:
            case cp_eq:
                $sql = "((".$concept[1].".".$concept[2][1]."=".$atmp[1].") AND (".$concept[1].".".$concept[2][0]."=".$atmp[0]."))";
                return $sql;
                break;
            default:
                AppendError(DC_COMPTYPENOTSUPPORTED," The comparison operator [".cpToText($this->m_COPop)."] is not supported by the JULIAN type",DIAG_ERROR);
                return "";
                break;
            }
            break;
        case type_DATETIME:
            $ctmp = $concept[1].".".$concept[2];
//            if ((is_null($this->m_term)) || (strlen($this->m_term) < 1))
            if (is_null($this->m_term))
            {
                //special case: NULL comparison
                switch ($this->m_COPop)
                {
                    case cp_eq:
                        $sql = "(".$ctmp." IS NULL)";
                        return $sql;
                        break;
                    case cp_neq:
                        if ($Cfg->minQueryTermLength == 0)
                        {
                            $sql = "(".$ctmp." IS NOT NULL)";
                            return $sql;
                        }
                        else
                        {
                             AppendError(DC_QUERYTERMTOOSHORT,
                             "NOT NULL query attempted but not allowed",
                             DIAG_ERROR);
                             return "";
                        }
                        break;
                }
                AppendError(DC_COMPTYPENOTSUPPORTED,
                    "The comparison operator [".cpToText($this->m_COPop).
                    "] is not supported with a NULL term",
                    DIAG_ERROR);
                return "";
            }
            $atmp = null;
            if (is_array($this->m_term))
                $atmp = $this->m_term;
            else
                $atmp = split($g_cMultiTermDelimiter,$this->m_term);

            $i=0;
            $stmp = "";
            $stmp2= "";
            $amerged = array();
            for ($i=0; $i < count($atmp); $i++)
            {
                $itmp = strtotime($atmp[$i]);
                if ($itmp == -1)
                {
                    AppendError(DC_INVALIDTERM,"[".$this->m_term."] could not be parsed to a DateTime type.",DIAG_ERROR);
                    return "";
                }
                $tfs = "%d-%b-%Y %T";
                array_push($amerged,DIGIR_SQL_DATEQUOTE.trim(strftime(DIGIR_TIME2SQL,$itmp)).DIGIR_SQL_DATEQUOTE);
            }
            $stmp = implode(",",$amerged);
            switch ($this->m_COPop)
            {
            case cp_lt:
                $sql = "(".$ctmp." < ".$stmp.")";
                return $sql;
                break;
            case cp_lteq:
                $sql = "(".$ctmp." <= ".$stmp.")";
                return $sql;
                break;
            case cp_gteq:
                $sql = "(".$ctmp." >= ".$stmp.")";
                return $sql;
                break;
            case cp_gt:
                $sql = "(".$ctmp." > ".$stmp.")";
                return $sql;
                break;
            case cp_in:
                $sql = "(".$ctmp." IN (".$stmp."))";
                return $sql;
                break;
            case cp_undefined:
            case cp_eq:
                $sql = "(".$ctmp." = ".$stmp.")";
                return $sql;
                break;
            default:
                AppendError(DC_COMPTYPENOTSUPPORTED,"The comparison [".cpToText($this->m_COPop)."] is not supported by DATETIME types",DIAG_ERROR);
                return "";
                break;
            }
            break;
        case type_SQLSTUB:
            $itmp = $concept[3];
            $cstmp = $concept[1].".".$concept[2];
            switch ($this->m_COPop)
            {
                case cp_lt:
                case cp_lteq:
                case cp_gteq:
                case cp_gt:
                case cp_in:
                case cp_undefined:
                case cp_eq:
                    $sql = MakeSQLStub($cstmp," ".cpToText($this->m_COPop)." ",$this->m_term,$itmp);
                    return $sql;
                    break;
                case cp_like:
                    $stmp = $this->m_term;
                    if (strpos($stmp,"%") === FALSE)
                        $stmp = $stmp;
                    else
                        $stmp = "%".$stmp."%";
                    $sql = MakeSQLStub($cstmp," ".cpToText($this->m_COPop)." ",$stmp,$itmp);
                    return $sql;
                    break;
                default:
                    AppendError(DC_COMPTYPENOTSUPPORTED," The comparison operator [".cpToText($this->m_COPop)."] is not supported by the SQLSTUB type",DIAG_ERROR);
                    return "";
                    break;
                }
                break;
            }
        return $sql;
        }

    function toRPN(&$Cfg)
    {
        global $g_cMultiTermDelimiter,$g_MinTextLength,$g_SQLDateFormat,$g_SQLWildCard;
        $rpn = "";
        //a concept is an array of values
        //[0] = type_XXX enumeration
        //[1] = field.  Where multi field, contains array of fields
        //[2] = for SQLSTUB is the number of reps of the inserted elements
        $id = $Cfg->getConceptByName($this->m_concept);
        if ($id == NULL)
        {
            AppendError(DC_UNSUPPORTED_ACCESSPOINT,"Concept can not be mapped to database [".$this->m_concept."].  Check query and/or configuration information",DIAG_ERROR);
            return "";
        }
        $concept = $Cfg->m_concepts[$id];
        switch ($concept[0])
        {
            case type_NUMERIC:
            case type_TEXT:
            case type_JULIANDAY:
            case type_DATETIME:
            {
                if (strlen($this->m_length) < $g_MinTextLength)
                {
                    AppendError(DC_QUERYTERMTOOSHORT," The term [".$this->m_term."] is too general. Add more characters.",DIAG_ERROR);
                    return "";
                }
                $stmp = $concept[1];
                $termtmp = $this->m_term;
                switch ($this->m_COPop)
                {
                case cp_undefined:
                case cp_eq:
                    $rpn = "@attr 1=".$concept[4]." @attr 2=3 \"".$this->m_term."\"";
                    return $rpn;
                    break;
                case cp_lt:
                    $rpn = "@attr 1=".$concept[4]." @attr 2=1 \"".$this->m_term."\"";
                    return $rpn;
                    break;
                case cp_lteq:
                    $rpn = "@attr 1=".$concept[4]." @attr 2=2 \"".$this->m_term."\"";
                    return $rpn;
                    break;
                case cp_gteq:
                    $rpn = "@attr 1=".$concept[4]." @attr 2=4 \"".$this->m_term."\"";
                    return $rpn;
                    break;
                case cp_gt:
                    $rpn = "@attr 1=".$concept[4]." @attr 2=5 \"".$this->m_term."\"";
                    return $rpn;
                    break;
                case cp_neq:
                    $rpn = "@attr 1=".$concept[4]." @attr 2=6 \"".$this->m_term."\"";
                    return $rpn;
                    break;
                case cp_in:
                    $atmp = null;
                    if (is_array($this->m_term))
                        $atmp = $this->m_term;
                    else
                        $atmp = split($g_cMultiTermDelimiter,$this->m_term);
                    $termtmp = "";
                    for ($i=0; $i < count($atmp); $i++)
                    {
                        $termtmp = $termtmp.$atmp[$i];
                        if ($i < count($atmp)-1)
                            $termtmp += $termtmp.",";
                    }
                    $rpn = "@attr 1=".$concept[4]." @attr 2=8 \"".$this->m_term."\"";
                    return $rpn;
                    break;
                case cp_like:
                    if (strpos($termtmp,"%") === FALSE)
                        $termtmp = "%".$termtmp."%";
                    //replace the wild card chars
                    $termtmp = str_replace("%",$g_SQLWildCard,$termtmp);
                    $rpn = "@attr 1=".$concept[4]." @attr 2=8 \"".$this->m_term."\"";
                    return $rpn;
                    break;
                default:
                    AppendError(DC_COMPTYPENOTSUPPORTED,"The comparison [".cpToText($this->m_COPop)."] is not supported by TEXT type",DIAG_ERROR);
                    return "";
                    break;
                }
                break;
            }
        case type_BBOUNDING:
            $atmp = split($g_cBoundingBoxDelimiter,$this->m_term);
            if (count($atmp) < 4)
            {
                AppendError(DC_INVALIDTERM,"The supplied term [".$this->m_term."] does not have the required number of sub elements for this type of concept [BBOUNDING]",DIAG_ERROR);
                return "";
            }
            if (count($concept[2]) < 2)
            {
                AppendError(DC_BADCONCEPTMAP,"Concept map for the concept type [BBOUNDING] has too few elements- check configuration",DIAG_ERROR);
            }
            switch ($this->m_COPop)
            {
                case cp_lt:
                case cp_lteq:
                case cp_gteq:
                case cp_gt:
                    $rpn = "@attr 1=".$concept[4]." @attr 2=4 ";
                    $rpn = $rpn."\"".$atmp[0].",".$atmp[1].",".$atmp[2].",".$atmp[3]."\"";
                    return $rpn;
                    break;
                case cp_undefined:
                case cp_eq:
                    $rpn = "@attr 1=".$concept[4]." @attr 2=3 ";
                    $rpn = $rpn."\"".$atmp[0].",".$atmp[1].",".$atmp[2].",".$atmp[3]."\"";
                    return $rpn;
                    break;
                default:
                    AppendError(DC_COMPTYPENOTSUPPORTED,"The comparison operator [".cpToText($this->m_COPop)."] is not supported for this concept type [BBOUNDING]",DIAG_ERROR);
                    return "";
                    break;
            }
            break;
        }
    }
}

?>
