<BODY>
<?php 
if (empty($_GET['c']) && empty($_GET['k'])) {
    echo "<h3>You have to specify concepts ('c' param) and/or a keyword string ('k' param)</h3>";
} else {
    $matchImages = empty($_GET['i']) ? false : ($_GET['i'] != 0 ? true : false);
    $page = empty($_GET['p']) ? 1 : $_GET['p'];
    $pageSize = empty($_GET['s']) ? 36 : $_GET['s'];
    empty($_GET['c']) ? $catIDs = array() : ($catIDs = explode(",", $_GET['c']));
    empty($_GET['k']) ? $kwds = false : ($kwds = $_GET['k']);
    if (count($catIDs) <= 1) {
        $qCatIDs =& $catIDs;
    } else {
        $qCatIDs =& orderCatsForQuery($catIDs, $matchImages);
    }
    $objsquery = prepareObjsQuery($qCatIDs, $kwds, $matchImages, $page - 1, $pageSize);
    $catsquery = prepareResultsCatsQuery($qCatIDs, $kwds, $matchImages);
    echo "<h3>Objects Query:</h3><pre>" . $objsquery . "</pre>" . "<h3>Objects Query:</h3><pre>" . $catsquery . "</pre>";
}
echo '<hr><form method="get">
				<p>Enter Concept(s): <input type="text" name="c" maxlength="300" /></p>
				<p>Enter Keyword(s): <input type="text" name="k" maxlength="300" /></p>
				<p>With Images(s): <input type="checkbox" name="i" value="1" checked="true" /></p>
				<p>Page Num:  <input type="text" name="p" maxlength="10" /></p>
				<p>Page Size: <input type="text" name="s" maxlength="10" /></p>
				<input type="submit" value="Show Query" />
				</form>';
?>
</BODY>
</HTML>
function queryObjects($catIDs, $kwds, $tag, $user, $pageNum, $pageSize, $countsWithImages)
{
    //:boolean
    global $db;
    global $_DELPHI_PAGE_SIZE;
    if (empty($catIDs) && empty($kwds) && empty($tag)) {
        error_log("queryObjects() called with no categories or keywords");
        return false;
    }
    $retVal = array();
    if ($pageSize <= 0) {
        $pageSize = $_DELPHI_PAGE_SIZE;
    }
    $retVal['pageSize'] = $pageSize;
    if (count($catIDs) <= 1) {
        $qCatIDs =& $catIDs;
    } else {
        $qCatIDs =& orderCatsForQuery($catIDs, $countsWithImages);
    }
    //error_log( "queryObjects() Kwds: ".(empty($kwds)?"None":$kwds));
    //error_log( "queryObjects() Cats: ".(empty($qCatIDs)?"None":implode(",", $qCatIDs)));
    //$tqMain = buildMainQueryForTerm( $qCatIDs, 0, $kwds, $countsWithImages );
    $tqFull = prepareObjsQuery($qCatIDs, $kwds, $tag, $user, $countsWithImages, $pageNum, $pageSize);
    $objsresult =& $db->query($tqFull);
    if (PEAR::isError($objsresult)) {
        error_log("queryObjects() main Query error: " . $objsresult->getMessage());
        error_log("queryObjects() Query : " . $tqFull);
        return false;
    }
    //error_log( "queryObjects() Query : ".$tqFull);
    $tqFullCount = "SELECT FOUND_ROWS()";
    $fullCountResult =& $db->query($tqFullCount);
    if ($row = $fullCountResult->fetchRow(MDB2_FETCHMODE_ORDERED)) {
        $numResultsTotal = $row[0];
    } else {
        $numResultsTotal = 0;
    }
    $retVal['nObjs'] = $numResultsTotal;
    $retVal['nPages'] = $numResultsTotal == 0 ? 1 : ceil($numResultsTotal / $pageSize);
    $objs = array();
    while ($row = $objsresult->fetchRow()) {
        $item = array('id' => $row['id'], 'objnum' => $row['objnum'], 'name' => $row['name'], 'description' => $row['description'], 'img_path' => $row['img_path'], 'aspectRatio' => $row['img_ar']);
        $objs[] = $item;
    }
    $retVal['objects'] = $objs;
    return $retVal;
}