示例#1
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;
    /*****DEBUG****/
    //error_log("in outputDetail dt = $dt value = ". print_r($value,true));
    $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 {
                            echo $value['id'];
                        }
                        closeTag('detail');
                        return;
                    }
                } else {
                    $attrs['direction'] = "to";
                    if ($dt === $relSrcDT) {
                        $attrs['useInverse'] = 'true';
                    }
                }
                openTag('detail', $attrs);
                outputRecord(loadRecord($value['id']), $reverse_pointers, $relationships, $depth + 1, $outputStub, $parentID);
                closeTag('detail');
            } else {
                if ($depth < $MAX_DEPTH) {
                    openTag('detail', $attrs);
                    outputRecord(loadRecord($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'];
                /*****DEBUG****/
                //error_log(" in outputDetail file = \n".print_r($file,true));
                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($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'];
                    }
                    /*****DEBUG****/
                    //error_log("value = ".$value." label = ".$TL[$value]['trm_Label']);
                    makeTag('detail', $attrs, $TL[$value]['trm_Label']);
                } else {
                    makeTag('detail', $attrs, replaceIllegalChars($value));
                }
            }
        }
    }
}
/**
 * Returns the content of template file as text with local IDs replaced by concept IDs or viseverse
 *
 * @param mixed $filename - name of template file
 * @param mixed $mode - 0 - to concept code, 1 - to local code
 */
function convertTemplate($template, $mode)
{
    //1. get template content
    //2. find all texts within {}
    //3. find words within this text
    //4. split by .
    //5. find starting with "f"
    //6. get local DT ID - find Concept Code
    //7. replace
    //1. get template content
    if ($template == null || $template == '') {
        return array("error" => "Template is empty");
    }
    //2. find all texts within {} - expressions
    if (!preg_match_all('/\\{([^}]+)\\}/s', $template, $matches)) {
        return $template;
        // nothing to do -- no substitutions
    }
    $not_found_details = array();
    $replacements_exp = array();
    $len = count($matches[1]);
    for ($i = 0; $i < $len; ++$i) {
        $exp = $matches[1][$i];
        if (!trim($exp)) {
            continue;
        }
        //empty{}
        if (substr($exp, 0, 1) == "*" && substr($exp, -1) == "*") {
            continue;
        }
        //this is comment
        //3. find words within this text
        if (!preg_match_all('/(\\$([a-zA-Z_0-9.])+)/', $exp, $matches2)) {
            continue;
        }
        $replacements = array();
        foreach ($matches2[1] as $var) {
            //4. split by "."
            $parts = explode(".", $var);
            $parts2 = array();
            foreach ($parts as $part) {
                //5. find starting with "f"
                if (strpos($part, 'f') === 0) {
                    $prefix = 'f';
                } else {
                    if (strpos($part, '$f') === 0) {
                        $prefix = '$f';
                    } else {
                        $prefix = null;
                    }
                }
                if ($prefix) {
                    //6. get local DT ID - find Concept Code
                    $code = substr($part, strlen($prefix));
                    if (substr($part, -1) == 's') {
                        $suffix = 's';
                        $code = substr($code, 0, strlen($code) - 1);
                    } else {
                        if (endsWith($part, '_originalvalue')) {
                            $suffix = '_originalvalue';
                            $code = substr($code, 0, strlen($code) - strlen($suffix));
                        } else {
                            $suffix = "";
                        }
                    }
                    if ($mode == 0) {
                        $localID = $code;
                        if (strpos($localID, "_") === false) {
                            $conceptCode = getDetailTypeConceptID($localID);
                            $part = $prefix . str_replace("-", "_", $conceptCode) . $suffix;
                        }
                    } else {
                        $conceptCode = $code;
                        if (strpos($conceptCode, "_") !== false) {
                            $conceptCode = str_replace("_", "-", $conceptCode);
                            $localID = getDetailTypeLocalID($conceptCode);
                            if ($localID == null) {
                                //local code not found - it means that this detail is not in this database
                                array_push($not_found_details, $conceptCode);
                                $part = $prefix . "[[" . $conceptCode . "]]" . $suffix;
                            } else {
                                $part = $prefix . $localID . $suffix;
                            }
                        }
                    }
                }
                array_push($parts2, $part);
            }
            $new_var = implode(".", $parts2);
            if ($var != $new_var) {
                $replacements[$var] = $new_var;
            }
        }
        //for vars
        if (count($replacements) > 0) {
            $new_exp = "{" . array_str_replace(array_keys($replacements), array_values($replacements), $exp) . "}";
            if ($matches[0][$i] != $new_exp) {
                $replacements_exp[$matches[0][$i]] = $new_exp;
            }
        }
    }
    //for expressions
    if (count($replacements_exp) > 0) {
        $template = array_str_replace(array_keys($replacements_exp), array_values($replacements_exp), $template);
    }
    if ($mode == 1) {
        return array("template" => $template, "details_not_found" => $not_found_details);
    } else {
        return $template;
    }
}
function findTitleMaskEntries($rtyID, $dtyID)
{
    global $mysqli;
    $dtyID = getDetailTypeConceptID($dtyID);
    $ret = array();
    $query = "select rty_ID, rty_Name from defRecTypes where " . "((rty_TitleMask LIKE '%[{$dtyID}]%') OR " . "(rty_TitleMask LIKE '%.{$dtyID}]%') OR" . "(rty_TitleMask LIKE '%[{$dtyID}.%') OR" . "(rty_TitleMask LIKE '%.{$dtyID}.%'))";
    if ($rtyID) {
        $query .= " AND (rty_ID=" . $rtyID . ")";
    }
    $res = $mysqli->query($query);
    if ($res->num_rows > 0) {
        //$mysqli->affected_rows<1){
        while ($row = $res->fetch_object()) {
            $ret[$row->rty_ID] = $row->rty_Name;
        }
    }
    return $ret;
}
}
*/
// Converts all record and type codes into Concept
$arr = array();
if ($_POST["rectype"] == RT_BUG_REPORT) {
    //bug reporting already codes in global
    $arr = $_POST;
} else {
    foreach ($_POST as $key => $value) {
        $pos = strpos($key, "type:");
        if (is_numeric($pos) && $pos == 0) {
            //@todo we have to convert the content of fields as well -
            // since it may contain terms and references to other rectypes !!!1
            $typeid = substr($key, 5);
            //, $top-5);
            $newkey = getDetailTypeConceptID($typeid);
            if ($newkey) {
                $arr["type:" . $newkey] = $value;
            } else {
                print '({"error":"Can\'t find the global concept ID for field type #"' . $typeid . '"})';
                exit;
            }
        } else {
            $arr[$key] = $value;
        }
    }
    //for
    $newrectype = getRecTypeConceptID($_POST["rectype"]);
    if ($newrectype) {
        $arr["rectype"] = $newrectype;
    } else {
示例#5
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));
                }
            }
        }
    }
}
示例#6
0
/**
 * description
 * @global    type description of global variable usage in a function
 * @staticvar type [$varname] description of static variable usage in function
 * @param     type [$varname] description
 * @return    type description
 * @link      URL
 * @see       name of another element (function or object) used in this function
 * @throws    list of exceptions thrown in this code
 * @uses      code_element_name description of use
 */
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);
                outputRecordStub($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);
                    if ($file['fullpath'] && file_exists($file['fullpath'])) {
                        //backup file inot backup/user folder
                        $folder = HEURIST_UPLOAD_DIR . "backup/" . get_user_username() . "/";
                        $path_parts = pathinfo($file['fullpath']);
                        $file['URL'] = $path_parts['basename'];
                        $filename_bk = $folder . $file['URL'];
                        copy($file['fullpath'], $filename_bk);
                        unset($file['thumbURL']);
                    }
                }
                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);
                    outputRecordStub($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));
                }
            }
        }
    }
}