Ejemplo n.º 1
0
function loadSearch($args, $bare = false, $onlyIDs = false, $publicOnly = false)
{
    /*
     * Three basic steps are involved here:
     *
     * 1. Execute the query, which results in a list of record IDs
     *    (this step includes authentication, i.e. the results will be only
     *    those records visible to the user).
     *
     * 2. Load the core, public data for each record, whether it be from the
     *    cache or from the database.
     *
     * 3. Load the user-dependent data for each record (bookmark, tags, comments etc.).
     *    This step is optional - some applications may need only the core data.  In this
     *    case they should specify $bare = true.
     */
    if (!@$args["q"]) {
        return array("error" => "no query specified");
    }
    if (is_logged_in() && @$args["w"] === "bookmark") {
        $searchType = BOOKMARK;
    } else {
        $searchType = BOTH;
    }
    $fresh = !!@$args["f"];
    $noCache = @$args["nocache"] == 1;
    $query = REQUEST_to_query("select SQL_CALC_FOUND_ROWS rec_ID ", $searchType, $args, null, $publicOnly);
    $res = mysql_query($query);
    if (mysql_error()) {
    }
    $fres = mysql_query('select found_rows()');
    $resultCount = mysql_fetch_row($fres);
    $resultCount = $resultCount[0];
    if ($onlyIDs) {
        $row = mysql_fetch_assoc($res);
        $ids = "" . ($row["rec_ID"] ? $row["rec_ID"] : "");
        while ($row = mysql_fetch_assoc($res)) {
            $ids .= $row["rec_ID"] ? "," . $row["rec_ID"] : "";
        }
        return array("resultCount" => $resultCount, "recordCount" => strlen($ids) ? count(explode(",", $ids)) : 0, "recIDs" => $ids);
    } else {
        $recs = array();
        while ($row = mysql_fetch_assoc($res)) {
            if (mysql_error()) {
            }
            if ($noCache) {
                $record = loadRecord_NoCache($row["rec_ID"], $bare);
            } else {
                $record = loadRecord($row["rec_ID"], $fresh, $bare);
            }
            if (array_key_exists("error", $record)) {
                return array("error" => $record["error"]);
            }
            array_push($recs, $record);
        }
        return array("resultCount" => $resultCount, "recordCount" => count($recs), "records" => $recs);
    }
}
Ejemplo n.º 2
0
function outputDetail($dt, $value, $rt, $recInfos, $depth = 0, $outputStub, $parentID)
{
    global $DTN, $DTT, $TL, $RQS, $INV, $GEO_TYPES, $MAX_DEPTH, $INCLUDE_FILE_CONTENT, $SUPRESS_LOOPBACKS, $relTypDT;
    $attrs = array('id' => $dt, 'conceptID' => getDetailTypeConceptID($dt));
    if (array_key_exists($dt, $DTN)) {
        $attrs['type'] = $DTN[$dt];
    }
    if (array_key_exists($rt, $RQS) && array_key_exists($dt, $RQS[$rt])) {
        $attrs['name'] = $RQS[$rt][$dt];
    }
    if ($dt === $relTypDT && array_key_exists($value, $INV) && $INV[$value] && array_key_exists($INV[$value], $TL)) {
        //saw Enum change
        $attrs['inverse'] = $TL[$INV[$value]]['trm_Label'];
        $attrs['invTermConceptID'] = getTermConceptID($INV[$value]);
    }
    if (is_array($value)) {
        if (array_key_exists('id', $value)) {
            // record pointer
            $attrs['isRecordPointer'] = "true";
            if ($MAX_DEPTH == 0 && $outputStub) {
                openTag('detail', $attrs);
                $recinfo = loadRecord_NoCache($value['id'], true);
                outputRecordStub($recinfo);
                //$recInfos[$value['id']]['record']);
                closeTag('detail');
            } else {
                makeTag('detail', $attrs, $value['id']);
            }
        } else {
            if (array_key_exists('file', $value)) {
                $file = $value['file'];
                if (@$_REQUEST['includeresources'] == '1' && @$_REQUEST['mode'] == '1') {
                    $file = get_uploaded_file_info_internal($file['id'], false);
                    unset($file['thumbURL']);
                    if ($file['fullpath'] && file_exists($file['fullpath'])) {
                        //if path is relative then we copy file
                        if (@$file['ulf_FilePath'] == null || $file['ulf_FilePath'] == '' || substr($file['ulf_FilePath'], 1) != '/') {
                            //$path_parts = pathinfo($file['fullpath']);
                            //$dirname = $path_parts['dirname'].'/';
                            //copy file and create required folders
                            chdir(HEURIST_FILESTORE_DIR);
                            // relatively db root
                            $fpath = realpath($file['fullpath']);
                            $fpath = str_replace('\\', '/', $fpath);
                            recurse_copy(HEURIST_FILESTORE_DIR, HEURIST_FILESTORE_DIR . 'backup/' . HEURIST_DBNAME . '/', null, $fpath);
                            $file['URL'] = @$file['ulf_FilePath'] . @$file['ulf_FileName'];
                            //relative path to db root
                        } else {
                            //otherwise skip copy and use downloadURL
                            //$file['URL'] - it is already has  downloadFile or remote URL
                        }
                        /* this code is not use anymore - we copy the entire file_uploads folder
                                            // backup file into backup/user folder
                                            $folder = HEURIST_FILESTORE_DIR . "backup/" . get_user_username() . "/resources/";
                        
                                            if(!file_exists($folder) && !mkdir($folder, 0777, true)){
                                            print "<p class='error'>'Failed to create folder for file resources: ".$folder.'</p>';
                                            break;
                                            }
                        
                                            $path_parts = pathinfo($file['fullpath']);
                                            $file['URL'] = $path_parts['basename'];
                                            $filename_bk = $folder . $file['URL'];
                                            copy($file['fullpath'], $filename_bk);
                                            $file['URL'] = 'resources/'.$file['URL'];
                                            */
                    }
                }
                openTag('detail', $attrs);
                openTag('file');
                makeTag('id', null, $file['id']);
                makeTag('nonce', null, $file['nonce']);
                makeTag('origName', null, $file['origName']);
                if (@$file['mimeType']) {
                    makeTag('mimeType', null, $file['mimeType']);
                }
                if (@$file['fileSize']) {
                    makeTag('fileSize', array('units' => 'kB'), $file['fileSize']);
                }
                if (@$file['date']) {
                    makeTag('date', null, $file['date']);
                }
                if (@$file['description']) {
                    makeTag('description', null, $file['description']);
                }
                if (@$file['URL']) {
                    makeTag('url', null, $file['URL']);
                }
                if (@$file['thumbURL']) {
                    makeTag('thumbURL', null, $file['thumbURL']);
                }
                if ($INCLUDE_FILE_CONTENT !== false && $INCLUDE_FILE_CONTENT >= $depth) {
                    makeFileContentNode($file);
                }
                closeTag('file');
                closeTag('detail');
            } else {
                if (array_key_exists('geo', $value)) {
                    openTag('detail', $attrs);
                    openTag('geo');
                    makeTag('type', null, $GEO_TYPES[$value['geo']['type']]);
                    makeTag('wkt', null, $value['geo']['wkt']);
                    closeTag('geo');
                    closeTag('detail');
                }
            }
        }
    } else {
        if ($DTT[$dt] === 'date') {
            openTag('detail', $attrs);
            if (strpos($value, "|") === false) {
                outputDateDetail($attrs, $value);
            } else {
                outputTemporalDetail($attrs, $value);
            }
            closeTag('detail');
        } else {
            if ($DTT[$dt] === 'resource') {
                $attrs['isRecordPointer'] = "true";
                if ($MAX_DEPTH == 0 && $outputStub) {
                    openTag('detail', $attrs);
                    $recinfo = loadRecord_NoCache($value['id'], true);
                    outputRecordStub($recinfo);
                    //$recInfos[$value['id']]['record']);
                    closeTag('detail');
                } else {
                    makeTag('detail', $attrs, $value['id']);
                }
            } else {
                if (($DTT[$dt] === 'enum' || $DTT[$dt] === 'relationtype') && array_key_exists($value, $TL)) {
                    $attrs['termID'] = $value;
                    $attrs['termConceptID'] = getTermConceptID($value);
                    if (@$TL[$value]['trm_ParentTermID']) {
                        $attrs['ParentTerm'] = $TL[$TL[$value]['trm_ParentTermID']]['trm_Label'];
                    }
                    makeTag('detail', $attrs, $TL[$value]['trm_Label']);
                } else {
                    makeTag('detail', $attrs, replaceIllegalChars($value));
                }
            }
        }
    }
}
Ejemplo n.º 3
0
function outputDetail($dt, $value, $rt, &$reverse_pointers, &$relationships, $depth = 0, $outputStub, $parentID)
{
    global $DTN, $DTT, $TL, $RQS, $INV, $GEO_TYPES, $MAX_DEPTH, $INCLUDE_FILE_CONTENT, $SUPRESS_LOOPBACKS, $relTypDT, $relTrgDT, $relSrcDT;
    $attrs = array('id' => $dt, 'conceptID' => getDetailTypeConceptID($dt));
    if (array_key_exists($dt, $DTN)) {
        $attrs['type'] = $DTN[$dt];
    }
    if (array_key_exists($rt, $RQS) && array_key_exists($dt, $RQS[$rt])) {
        $attrs['name'] = $RQS[$rt][$dt];
    }
    if ($dt === $relTypDT && array_key_exists($value, $INV) && $INV[$value] && array_key_exists($INV[$value], $TL)) {
        //saw Enum change
        $attrs['inverse'] = $TL[$INV[$value]]['trm_Label'];
        $attrs['invTermConceptID'] = getTermConceptID($INV[$value]);
    }
    if (is_array($value)) {
        if (array_key_exists('id', $value)) {
            // record pointer
            if ($dt === $relSrcDT || $dt === $relTrgDT) {
                // in a relationship record don't expand from side
                if ($value['id'] == $parentID) {
                    $attrs['direction'] = "from";
                    if ($dt === $relTrgDT) {
                        $attrs['useInverse'] = 'true';
                    }
                    if ($SUPRESS_LOOPBACKS) {
                        openTag('detail', $attrs);
                        if ($outputStub) {
                            outputRecordStub(loadRecordStub($value['id']));
                        } else {
                            output($value['id']);
                        }
                        closeTag('detail');
                        return;
                    }
                } else {
                    $attrs['direction'] = "to";
                    if ($dt === $relSrcDT) {
                        $attrs['useInverse'] = 'true';
                    }
                }
                openTag('detail', $attrs);
                outputRecord(loadRecord_NoCache($value['id']), $reverse_pointers, $relationships, $depth + 1, $outputStub, $parentID);
                closeTag('detail');
            } else {
                if ($depth < $MAX_DEPTH) {
                    openTag('detail', $attrs);
                    outputRecord(loadRecord_NoCache($value['id']), $reverse_pointers, $relationships, $depth + 1, $outputStub, $parentID);
                    closeTag('detail');
                } else {
                    if ($outputStub) {
                        openTag('detail', $attrs);
                        outputRecordStub(loadRecordStub($value['id']));
                        closeTag('detail');
                    } else {
                        makeTag('detail', $attrs, $value['id']);
                    }
                }
            }
        } else {
            if (array_key_exists('file', $value)) {
                $file = $value['file'];
                openTag('detail', $attrs);
                openTag('file');
                makeTag('id', null, $file['id']);
                makeTag('nonce', null, $file['nonce']);
                makeTag('origName', null, $file['origName']);
                makeTag('type', null, $file['type']);
                makeTag('size', array('units' => 'kB'), $file['size']);
                makeTag('date', null, $file['date']);
                makeTag('description', null, $file['description']);
                makeTag('url', null, $file['URL']);
                makeTag('thumbURL', null, $file['thumbURL']);
                if ($INCLUDE_FILE_CONTENT) {
                    makeFileContentNode($file);
                }
                closeTag('file');
                closeTag('detail');
            } else {
                if (array_key_exists('geo', $value)) {
                    openTag('detail', $attrs);
                    openTag('geo');
                    makeTag('type', null, $GEO_TYPES[$value['geo']['type']]);
                    makeTag('wkt', null, $value['geo']['wkt']);
                    closeTag('geo');
                    closeTag('detail');
                }
            }
        }
    } else {
        if ($DTT[$dt] === 'date') {
            openTag('detail', $attrs);
            if (strpos($value, "|") === false) {
                outputDateDetail($attrs, $value);
            } else {
                outputTemporalDetail($attrs, $value);
            }
            closeTag('detail');
        } else {
            if ($DTT[$dt] === 'resource') {
                openTag('detail', $attrs);
                outputRecord(loadRecord_NoCache($value), $reverse_pointers, $relationships, $depth + 1, $outputStub, $parentID);
                closeTag('detail');
            } else {
                if (($DTT[$dt] === 'enum' || $DTT[$dt] === 'relationtype') && array_key_exists($value, $TL)) {
                    $attrs['termConceptID'] = getTermConceptID($value);
                    if (@$TL[$value]['trm_ParentTermID']) {
                        $attrs['ParentTerm'] = $TL[$TL[$value]['trm_ParentTermID']]['trm_Label'];
                    }
                    makeTag('detail', $attrs, $TL[$value]['trm_Label']);
                } else {
                    makeTag('detail', $attrs, replaceIllegalChars($value));
                }
            }
        }
    }
}